@callstack/repack-dev-server
Advanced tools
Comparing version 1.0.0-next.0 to 1.0.0-next.1
# @callstack/repack-dev-server | ||
## 1.0.0-next.1 | ||
### Minor Changes | ||
- ### Development server API | ||
Added API endpoints to `@callstack/repack-dev-server`: | ||
- `GET /api/platforms` - List all platforms with active compilations | ||
- `GET /api/:platform/assets` - List all assets (`name` and `size`) for a given compilation | ||
- `GET /api/:platform/stats` - Get compilation stats | ||
- Websocket server under `/api` URI for logs and compilations events | ||
## 1.0.0-next.0 | ||
@@ -4,0 +17,0 @@ |
@@ -9,2 +9,3 @@ import { Writable } from 'stream'; | ||
import devtoolsPlugin from "./plugins/devtools/index.js"; | ||
import apiPlugin from "./plugins/api/index.js"; | ||
import wssPlugin from "./plugins/wss/index.js"; | ||
@@ -21,3 +22,5 @@ import { Internal } from "./types.js"; | ||
export async function createServer(config) { | ||
let delegate; | ||
/** Fastify instance powering the development server. */ | ||
const instance = Fastify({ | ||
@@ -28,3 +31,7 @@ logger: { | ||
write: (chunk, _encoding, callback) => { | ||
delegate.logger.onMessage(JSON.parse(chunk.toString())); | ||
var _delegate; | ||
const log = JSON.parse(chunk.toString()); | ||
(_delegate = delegate) === null || _delegate === void 0 ? void 0 : _delegate.logger.onMessage(log); | ||
instance.wss.apiServer.send(log); | ||
callback(); | ||
@@ -38,6 +45,6 @@ } | ||
}); | ||
const delegate = config.delegate({ | ||
delegate = config.delegate({ | ||
log: instance.log, | ||
notifyBuildStart: platform => { | ||
instance.wss.dashboardServer.send({ | ||
instance.wss.apiServer.send({ | ||
event: Internal.EventTypes.BuildStart, | ||
@@ -48,3 +55,3 @@ platform | ||
notifyBuildEnd: platform => { | ||
instance.wss.dashboardServer.send({ | ||
instance.wss.apiServer.send({ | ||
event: Internal.EventTypes.BuildEnd, | ||
@@ -71,2 +78,6 @@ platform | ||
await instance.register(multipartPlugin); | ||
await instance.register(apiPlugin, { | ||
delegate, | ||
prefix: '/api' | ||
}); | ||
await instance.register(compilerPlugin, { | ||
@@ -73,0 +84,0 @@ delegate |
@@ -8,3 +8,3 @@ /// <reference types="node" /> | ||
import { HermesInspectorProxy } from './servers/HermesInspectorProxy'; | ||
import { WebSocketDashboardServer } from './servers/WebSocketDashboardServer'; | ||
import { WebSocketApiServer } from './servers/WebSocketApiServer'; | ||
import { WebSocketHMRServer } from './servers/WebSocketHMRServer'; | ||
@@ -20,3 +20,3 @@ import { WebSocketRouter } from './WebSocketRouter'; | ||
hermesInspectorProxy: HermesInspectorProxy; | ||
dashboardServer: WebSocketDashboardServer; | ||
apiServer: WebSocketApiServer; | ||
hmrServer: WebSocketHMRServer; | ||
@@ -23,0 +23,0 @@ router: WebSocketRouter; |
@@ -7,3 +7,3 @@ import fastifyPlugin from 'fastify-plugin'; | ||
import { HermesInspectorProxy } from "./servers/HermesInspectorProxy.js"; | ||
import { WebSocketDashboardServer } from "./servers/WebSocketDashboardServer.js"; | ||
import { WebSocketApiServer } from "./servers/WebSocketApiServer.js"; | ||
import { WebSocketHMRServer } from "./servers/WebSocketHMRServer.js"; | ||
@@ -24,3 +24,3 @@ import { WebSocketRouter } from "./WebSocketRouter.js"; | ||
const hermesInspectorProxy = new HermesInspectorProxy(instance, options); | ||
const dashboardServer = new WebSocketDashboardServer(instance); | ||
const apiServer = new WebSocketApiServer(instance); | ||
const hmrServer = new WebSocketHMRServer(instance, delegate.hmr); | ||
@@ -32,3 +32,3 @@ router.registerServer(debuggerServer); | ||
router.registerServer(hermesInspectorProxy); | ||
router.registerServer(dashboardServer); | ||
router.registerServer(apiServer); | ||
router.registerServer(hmrServer); | ||
@@ -41,3 +41,3 @@ instance.decorate('wss', { | ||
hermesInspectorProxy, | ||
dashboardServer, | ||
apiServer, | ||
hmrServer, | ||
@@ -44,0 +44,0 @@ router |
@@ -49,2 +49,4 @@ import { FastifyLoggerInstance } from 'fastify'; | ||
messages: MessagesDelegate; | ||
/** An API delegate. */ | ||
api?: Api.Delegate; | ||
} | ||
@@ -102,2 +104,31 @@ /** | ||
} | ||
namespace Api { | ||
/** A compilation asset representation for API clients. */ | ||
interface Asset { | ||
name: string; | ||
size: number; | ||
[key: string]: any; | ||
} | ||
/** A compilation stats representation for API clients. */ | ||
interface CompilationStats { | ||
[key: string]: any; | ||
} | ||
/** | ||
* Delegate with implementation for API endpoints. | ||
*/ | ||
interface Delegate { | ||
/** Get all platforms - either with already existing compilations or all supported platforms. */ | ||
getPlatforms: () => Promise<string[]>; | ||
/** | ||
* Get all assets from compilation for given platform. | ||
* Should return `[]` if the compilation does not exists for given platform. | ||
*/ | ||
getAssets: (platform: string) => Promise<Asset[]>; | ||
/** | ||
* Get compilation stats for a given platform. | ||
* Should return `null` if the compilation does not exists for given platform. | ||
*/ | ||
getCompilationStats: (platform: string) => Promise<CompilationStats | null>; | ||
} | ||
} | ||
} | ||
@@ -104,0 +135,0 @@ /** Representation of the compilation progress. */ |
export let Server; | ||
/** Representation of the compilation progress. */ | ||
(function (_Server) {})(Server || (Server = {})); | ||
(function (_Server) { | ||
/** Development server configuration. */ | ||
/** Development server options. */ | ||
/** | ||
* A complete delegate with implementations for all server functionalities. | ||
*/ | ||
/** | ||
* A delegate context used in `delegate` builder in {@link Config}. | ||
* | ||
* Allows to emit logs, notify about compilation events and broadcast events to connected clients. | ||
*/ | ||
/** | ||
* Delegate with implementation for logging functions. | ||
*/ | ||
/** | ||
* Delegate with implementation for messages used in route handlers. | ||
*/ | ||
let Api; | ||
(function (_Api) {})(Api || (Api = _Server.Api || (_Server.Api = {}))); | ||
})(Server || (Server = {})); | ||
/** | ||
@@ -7,0 +32,0 @@ * Internal types. Do not use. |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.0-next.0", | ||
"version": "1.0.0-next.1", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
220484
92
2668