@callstack/repack-dev-server 1.0.0-next.0 → 1.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/createServer.js +15 -4
- package/dist/createServer.js.map +1 -1
- package/dist/plugins/api/apiPlugin.d.ts +6 -0
- package/dist/plugins/api/apiPlugin.js +38 -0
- package/dist/plugins/api/apiPlugin.js.map +1 -0
- package/dist/plugins/api/index.d.ts +1 -0
- package/dist/plugins/api/index.js +2 -0
- package/dist/plugins/api/index.js.map +1 -0
- package/dist/plugins/wss/servers/{WebSocketDashboardServer.d.ts → WebSocketApiServer.d.ts} +5 -7
- package/dist/plugins/wss/servers/{WebSocketDashboardServer.js → WebSocketApiServer.js} +9 -11
- package/dist/plugins/wss/servers/WebSocketApiServer.js.map +1 -0
- package/dist/plugins/wss/wssPlugin.d.ts +2 -2
- package/dist/plugins/wss/wssPlugin.js +4 -4
- package/dist/plugins/wss/wssPlugin.js.map +1 -1
- package/dist/types.d.ts +31 -0
- package/dist/types.js +26 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/plugins/wss/servers/WebSocketDashboardServer.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @callstack/repack-dev-server
|
|
2
2
|
|
|
3
|
+
## 1.0.0-next.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ### Development server API
|
|
8
|
+
|
|
9
|
+
Added API endpoints to `@callstack/repack-dev-server`:
|
|
10
|
+
|
|
11
|
+
- `GET /api/platforms` - List all platforms with active compilations
|
|
12
|
+
- `GET /api/:platform/assets` - List all assets (`name` and `size`) for a given compilation
|
|
13
|
+
- `GET /api/:platform/stats` - Get compilation stats
|
|
14
|
+
- Websocket server under `/api` URI for logs and compilations events
|
|
15
|
+
|
|
3
16
|
## 1.0.0-next.0
|
|
4
17
|
|
|
5
18
|
### Major Changes
|
package/dist/createServer.js
CHANGED
|
@@ -6,6 +6,7 @@ import debuggerAppPath from '@callstack/repack-debugger-app';
|
|
|
6
6
|
import multipartPlugin from "./plugins/multipart/index.js";
|
|
7
7
|
import compilerPlugin from "./plugins/compiler/index.js";
|
|
8
8
|
import devtoolsPlugin from "./plugins/devtools/index.js";
|
|
9
|
+
import apiPlugin from "./plugins/api/index.js";
|
|
9
10
|
import wssPlugin from "./plugins/wss/index.js";
|
|
10
11
|
import { Internal } from "./types.js";
|
|
11
12
|
import symbolicatePlugin from "./plugins/symbolicate/index.js";
|
|
@@ -17,13 +18,19 @@ import symbolicatePlugin from "./plugins/symbolicate/index.js";
|
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
20
|
export async function createServer(config) {
|
|
21
|
+
let delegate;
|
|
20
22
|
/** Fastify instance powering the development server. */
|
|
23
|
+
|
|
21
24
|
const instance = Fastify({
|
|
22
25
|
logger: {
|
|
23
26
|
level: 'trace',
|
|
24
27
|
stream: new Writable({
|
|
25
28
|
write: (chunk, _encoding, callback) => {
|
|
26
|
-
|
|
29
|
+
var _delegate;
|
|
30
|
+
|
|
31
|
+
const log = JSON.parse(chunk.toString());
|
|
32
|
+
(_delegate = delegate) === null || _delegate === void 0 ? void 0 : _delegate.logger.onMessage(log);
|
|
33
|
+
instance.wss.apiServer.send(log);
|
|
27
34
|
callback();
|
|
28
35
|
}
|
|
29
36
|
})
|
|
@@ -32,16 +39,16 @@ export async function createServer(config) {
|
|
|
32
39
|
https: config.options.https
|
|
33
40
|
} : undefined)
|
|
34
41
|
});
|
|
35
|
-
|
|
42
|
+
delegate = config.delegate({
|
|
36
43
|
log: instance.log,
|
|
37
44
|
notifyBuildStart: platform => {
|
|
38
|
-
instance.wss.
|
|
45
|
+
instance.wss.apiServer.send({
|
|
39
46
|
event: Internal.EventTypes.BuildStart,
|
|
40
47
|
platform
|
|
41
48
|
});
|
|
42
49
|
},
|
|
43
50
|
notifyBuildEnd: platform => {
|
|
44
|
-
instance.wss.
|
|
51
|
+
instance.wss.apiServer.send({
|
|
45
52
|
event: Internal.EventTypes.BuildEnd,
|
|
46
53
|
platform
|
|
47
54
|
});
|
|
@@ -63,6 +70,10 @@ export async function createServer(config) {
|
|
|
63
70
|
delegate
|
|
64
71
|
});
|
|
65
72
|
await instance.register(multipartPlugin);
|
|
73
|
+
await instance.register(apiPlugin, {
|
|
74
|
+
delegate,
|
|
75
|
+
prefix: '/api'
|
|
76
|
+
});
|
|
66
77
|
await instance.register(compilerPlugin, {
|
|
67
78
|
delegate
|
|
68
79
|
});
|
package/dist/createServer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServer.js","names":["Writable","Fastify","fastifySensible","fastifyStatic","debuggerAppPath","multipartPlugin","compilerPlugin","devtoolsPlugin","wssPlugin","Internal","symbolicatePlugin","createServer","config","instance","logger","level","stream","write","chunk","_encoding","callback","
|
|
1
|
+
{"version":3,"file":"createServer.js","names":["Writable","Fastify","fastifySensible","fastifyStatic","debuggerAppPath","multipartPlugin","compilerPlugin","devtoolsPlugin","apiPlugin","wssPlugin","Internal","symbolicatePlugin","createServer","config","delegate","instance","logger","level","stream","write","chunk","_encoding","callback","log","JSON","parse","toString","onMessage","wss","apiServer","send","options","https","undefined","notifyBuildStart","platform","event","EventTypes","BuildStart","notifyBuildEnd","BuildEnd","broadcastToHmrClients","clientIds","hmrServer","broadcastToMessageClients","method","params","messageServer","broadcast","register","prefix","root","prefixAvoidTrailingSlash","addHook","request","reply","payload","header","pathname","url","split","endsWith","get","messages","getHello","getStatus","start","listen","port","host","stop","close"],"sources":["../src/createServer.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport Fastify from 'fastify';\nimport fastifySensible from '@fastify/sensible';\nimport fastifyStatic from '@fastify/static';\nimport debuggerAppPath from '@callstack/repack-debugger-app';\nimport multipartPlugin from './plugins/multipart';\nimport compilerPlugin from './plugins/compiler';\nimport devtoolsPlugin from './plugins/devtools';\nimport apiPlugin from './plugins/api';\nimport wssPlugin from './plugins/wss';\nimport { Internal, Server } from './types';\nimport symbolicatePlugin from './plugins/symbolicate';\n\n/**\n * Create instance of development server, powered by Fastify.\n *\n * @param config Server configuration.\n * @returns `start` and `stop` functions as well as an underlying Fastify `instance`.\n */\nexport async function createServer(config: Server.Config) {\n let delegate: Server.Delegate;\n\n /** Fastify instance powering the development server. */\n const instance = Fastify({\n logger: {\n level: 'trace',\n stream: new Writable({\n write: (chunk, _encoding, callback) => {\n const log = JSON.parse(chunk.toString());\n delegate?.logger.onMessage(log);\n instance.wss.apiServer.send(log);\n callback();\n },\n }),\n },\n ...(config.options.https ? { https: config.options.https } : undefined),\n });\n\n delegate = config.delegate({\n log: instance.log,\n notifyBuildStart: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildStart,\n platform,\n });\n },\n notifyBuildEnd: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildEnd,\n platform,\n });\n },\n broadcastToHmrClients: (event, platform, clientIds) => {\n instance.wss.hmrServer.send(event, platform, clientIds);\n },\n broadcastToMessageClients: ({ method, params }) => {\n instance.wss.messageServer.broadcast(method, params);\n },\n });\n\n // Register plugins\n await instance.register(fastifySensible);\n await instance.register(wssPlugin, {\n options: config.options,\n delegate,\n });\n await instance.register(multipartPlugin);\n await instance.register(apiPlugin, {\n delegate,\n prefix: '/api',\n });\n await instance.register(compilerPlugin, {\n delegate,\n });\n await instance.register(symbolicatePlugin, {\n delegate,\n });\n await instance.register(devtoolsPlugin, {\n options: config.options,\n });\n\n await instance.register(fastifyStatic, {\n root: debuggerAppPath,\n prefix: '/debugger-ui',\n prefixAvoidTrailingSlash: true,\n });\n\n instance.addHook('onSend', async (request, reply, payload) => {\n reply.header('X-Content-Type-Options', 'nosniff');\n\n const [pathname] = request.url.split('?');\n if (pathname.endsWith('.map')) {\n reply.header('Access-Control-Allow-Origin', 'devtools://devtools');\n }\n\n return payload;\n });\n\n // Register routes\n instance.get('/', async () => delegate.messages.getHello());\n instance.get('/status', async () => delegate.messages.getStatus());\n\n /** Start the development server. */\n async function start() {\n await instance.listen(config.options.port, config.options.host);\n }\n\n /** Stop the development server. */\n async function stop() {\n await instance.close();\n }\n\n return {\n start,\n stop,\n instance,\n };\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const paramsSchema = {
|
|
2
|
+
type: 'object',
|
|
3
|
+
properties: {
|
|
4
|
+
platform: {
|
|
5
|
+
type: 'string'
|
|
6
|
+
}
|
|
7
|
+
},
|
|
8
|
+
required: ['platform']
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
async function apiPlugin(instance, {
|
|
12
|
+
delegate
|
|
13
|
+
}) {
|
|
14
|
+
instance.get('/platforms', async (_request, reply) => delegate.api ? reply.send({
|
|
15
|
+
data: await delegate.api.getPlatforms()
|
|
16
|
+
}) : reply.notImplemented('Missing API delegate implementation'));
|
|
17
|
+
instance.get('/:platform/assets', {
|
|
18
|
+
schema: {
|
|
19
|
+
params: paramsSchema
|
|
20
|
+
}
|
|
21
|
+
}, async (request, reply) => delegate.api ? reply.send({
|
|
22
|
+
data: await delegate.api.getAssets(request.params.platform)
|
|
23
|
+
}) : reply.notImplemented('Missing API delegate implementation'));
|
|
24
|
+
instance.get('/:platform/stats', {
|
|
25
|
+
schema: {
|
|
26
|
+
params: paramsSchema
|
|
27
|
+
}
|
|
28
|
+
}, async (request, reply) => {
|
|
29
|
+
var _delegate$api;
|
|
30
|
+
|
|
31
|
+
return delegate.api ? reply.send({
|
|
32
|
+
data: await ((_delegate$api = delegate.api) === null || _delegate$api === void 0 ? void 0 : _delegate$api.getCompilationStats(request.params.platform))
|
|
33
|
+
}) : reply.notImplemented('Missing API delegate implementation');
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default apiPlugin;
|
|
38
|
+
//# sourceMappingURL=apiPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiPlugin.js","names":["paramsSchema","type","properties","platform","required","apiPlugin","instance","delegate","get","_request","reply","api","send","data","getPlatforms","notImplemented","schema","params","request","getAssets","getCompilationStats"],"sources":["../../../src/plugins/api/apiPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport type { Server } from '../../types';\n\nconst paramsSchema = {\n type: 'object',\n properties: {\n platform: {\n type: 'string',\n },\n },\n required: ['platform'],\n};\n\ntype Params = { platform: string };\n\nasync function apiPlugin(\n instance: FastifyInstance,\n { delegate }: { delegate: Server.Delegate }\n) {\n instance.get('/platforms', async (_request, reply) =>\n delegate.api\n ? reply.send({ data: await delegate.api.getPlatforms() })\n : reply.notImplemented('Missing API delegate implementation')\n );\n\n instance.get<{ Params: Params }>(\n '/:platform/assets',\n { schema: { params: paramsSchema } },\n async (request, reply) =>\n delegate.api\n ? reply.send({\n data: await delegate.api.getAssets(request.params.platform),\n })\n : reply.notImplemented('Missing API delegate implementation')\n );\n\n instance.get<{ Params: Params }>(\n '/:platform/stats',\n { schema: { params: paramsSchema } },\n async (request, reply) =>\n delegate.api\n ? reply.send({\n data: await delegate.api?.getCompilationStats(\n request.params.platform\n ),\n })\n : reply.notImplemented('Missing API delegate implementation')\n );\n}\n\nexport default apiPlugin;\n"],"mappings":"AAGA,MAAMA,YAAY,GAAG;EACnBC,IAAI,EAAE,QADa;EAEnBC,UAAU,EAAE;IACVC,QAAQ,EAAE;MACRF,IAAI,EAAE;IADE;EADA,CAFO;EAOnBG,QAAQ,EAAE,CAAC,UAAD;AAPS,CAArB;;AAYA,eAAeC,SAAf,CACEC,QADF,EAEE;EAAEC;AAAF,CAFF,EAGE;EACAD,QAAQ,CAACE,GAAT,CAAa,YAAb,EAA2B,OAAOC,QAAP,EAAiBC,KAAjB,KACzBH,QAAQ,CAACI,GAAT,GACID,KAAK,CAACE,IAAN,CAAW;IAAEC,IAAI,EAAE,MAAMN,QAAQ,CAACI,GAAT,CAAaG,YAAb;EAAd,CAAX,CADJ,GAEIJ,KAAK,CAACK,cAAN,CAAqB,qCAArB,CAHN;EAMAT,QAAQ,CAACE,GAAT,CACE,mBADF,EAEE;IAAEQ,MAAM,EAAE;MAAEC,MAAM,EAAEjB;IAAV;EAAV,CAFF,EAGE,OAAOkB,OAAP,EAAgBR,KAAhB,KACEH,QAAQ,CAACI,GAAT,GACID,KAAK,CAACE,IAAN,CAAW;IACTC,IAAI,EAAE,MAAMN,QAAQ,CAACI,GAAT,CAAaQ,SAAb,CAAuBD,OAAO,CAACD,MAAR,CAAed,QAAtC;EADH,CAAX,CADJ,GAIIO,KAAK,CAACK,cAAN,CAAqB,qCAArB,CARR;EAWAT,QAAQ,CAACE,GAAT,CACE,kBADF,EAEE;IAAEQ,MAAM,EAAE;MAAEC,MAAM,EAAEjB;IAAV;EAAV,CAFF,EAGE,OAAOkB,OAAP,EAAgBR,KAAhB;IAAA;;IAAA,OACEH,QAAQ,CAACI,GAAT,GACID,KAAK,CAACE,IAAN,CAAW;MACTC,IAAI,EAAE,wBAAMN,QAAQ,CAACI,GAAf,kDAAM,cAAcS,mBAAd,CACVF,OAAO,CAACD,MAAR,CAAed,QADL,CAAN;IADG,CAAX,CADJ,GAMIO,KAAK,CAACK,cAAN,CAAqB,qCAArB,CAPN;EAAA,CAHF;AAYD;;AAED,eAAeV,SAAf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './apiPlugin';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/api/index.ts"],"sourcesContent":["export { default } from './apiPlugin';\n"],"mappings":"SAASA,O"}
|
|
@@ -2,25 +2,23 @@ import { FastifyInstance } from 'fastify';
|
|
|
2
2
|
import WebSocket from 'ws';
|
|
3
3
|
import { WebSocketServer } from '../WebSocketServer';
|
|
4
4
|
/**
|
|
5
|
-
* Class for creating a WebSocket server for
|
|
6
|
-
*
|
|
7
|
-
* events, logs and other necessary messages.
|
|
5
|
+
* Class for creating a WebSocket server for API clients.
|
|
6
|
+
* Useful to listening for compilation events and new logs.
|
|
8
7
|
*
|
|
9
8
|
* @category Development server
|
|
10
9
|
*/
|
|
11
|
-
export declare class
|
|
10
|
+
export declare class WebSocketApiServer extends WebSocketServer {
|
|
12
11
|
private clients;
|
|
13
12
|
private nextClientId;
|
|
14
13
|
/**
|
|
15
|
-
* Create new instance of
|
|
14
|
+
* Create new instance of WebSocketApiServer and attach it to the given Fastify instance.
|
|
16
15
|
* Any logging information, will be passed through standard `fastify.log` API.
|
|
17
16
|
*
|
|
18
17
|
* @param fastify Fastify instance to attach the WebSocket server to.
|
|
19
|
-
* @param emitter Event emitter instance.
|
|
20
18
|
*/
|
|
21
19
|
constructor(fastify: FastifyInstance);
|
|
22
20
|
/**
|
|
23
|
-
* Send message to all connected
|
|
21
|
+
* Send message to all connected API clients.
|
|
24
22
|
*
|
|
25
23
|
* @param event Event string or object to send.
|
|
26
24
|
*/
|
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
import { WebSocketServer } from "../WebSocketServer.js";
|
|
2
2
|
/**
|
|
3
|
-
* Class for creating a WebSocket server for
|
|
4
|
-
*
|
|
5
|
-
* events, logs and other necessary messages.
|
|
3
|
+
* Class for creating a WebSocket server for API clients.
|
|
4
|
+
* Useful to listening for compilation events and new logs.
|
|
6
5
|
*
|
|
7
6
|
* @category Development server
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
|
-
export class
|
|
9
|
+
export class WebSocketApiServer extends WebSocketServer {
|
|
11
10
|
clients = new Map();
|
|
12
11
|
nextClientId = 0;
|
|
13
12
|
/**
|
|
14
|
-
* Create new instance of
|
|
13
|
+
* Create new instance of WebSocketApiServer and attach it to the given Fastify instance.
|
|
15
14
|
* Any logging information, will be passed through standard `fastify.log` API.
|
|
16
15
|
*
|
|
17
16
|
* @param fastify Fastify instance to attach the WebSocket server to.
|
|
18
|
-
* @param emitter Event emitter instance.
|
|
19
17
|
*/
|
|
20
18
|
|
|
21
19
|
constructor(fastify) {
|
|
22
|
-
super(fastify, '/api
|
|
20
|
+
super(fastify, '/api');
|
|
23
21
|
}
|
|
24
22
|
/**
|
|
25
|
-
* Send message to all connected
|
|
23
|
+
* Send message to all connected API clients.
|
|
26
24
|
*
|
|
27
25
|
* @param event Event string or object to send.
|
|
28
26
|
*/
|
|
@@ -49,14 +47,14 @@ export class WebSocketDashboardServer extends WebSocketServer {
|
|
|
49
47
|
const clientId = `client#${this.nextClientId++}`;
|
|
50
48
|
this.clients.set(clientId, socket);
|
|
51
49
|
this.fastify.log.info({
|
|
52
|
-
msg: '
|
|
50
|
+
msg: 'API client connected',
|
|
53
51
|
clientId
|
|
54
52
|
});
|
|
55
53
|
this.clients.set(clientId, socket);
|
|
56
54
|
|
|
57
55
|
const onClose = () => {
|
|
58
56
|
this.fastify.log.info({
|
|
59
|
-
msg: '
|
|
57
|
+
msg: 'API client disconnected',
|
|
60
58
|
clientId
|
|
61
59
|
});
|
|
62
60
|
this.clients.delete(clientId);
|
|
@@ -67,4 +65,4 @@ export class WebSocketDashboardServer extends WebSocketServer {
|
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
}
|
|
70
|
-
//# sourceMappingURL=
|
|
68
|
+
//# sourceMappingURL=WebSocketApiServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebSocketApiServer.js","names":["WebSocketServer","WebSocketApiServer","clients","Map","nextClientId","constructor","fastify","send","event","data","JSON","stringify","socket","entries","onConnection","clientId","set","log","info","msg","onClose","delete","addEventListener"],"sources":["../../../../src/plugins/wss/servers/WebSocketApiServer.ts"],"sourcesContent":["import { FastifyInstance } from 'fastify';\nimport WebSocket from 'ws';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for API clients.\n * Useful to listening for compilation events and new logs.\n *\n * @category Development server\n */\nexport class WebSocketApiServer extends WebSocketServer {\n private clients = new Map<string, WebSocket>();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketApiServer and attach it to the given Fastify instance.\n * Any logging information, will be passed through standard `fastify.log` API.\n *\n * @param fastify Fastify instance to attach the WebSocket server to.\n */\n constructor(fastify: FastifyInstance) {\n super(fastify, '/api');\n }\n\n /**\n * Send message to all connected API clients.\n *\n * @param event Event string or object to send.\n */\n send(event: any) {\n const data = typeof event === 'string' ? event : JSON.stringify(event);\n\n for (const [, socket] of this.clients.entries()) {\n try {\n socket.send(data);\n } catch {\n // NOOP\n }\n }\n }\n\n /**\n * Process new WebSocket connection from client application.\n *\n * @param socket Incoming client's WebSocket connection.\n */\n onConnection(socket: WebSocket) {\n const clientId = `client#${this.nextClientId++}`;\n this.clients.set(clientId, socket);\n\n this.fastify.log.info({ msg: 'API client connected', clientId });\n this.clients.set(clientId, socket);\n\n const onClose = () => {\n this.fastify.log.info({\n msg: 'API client disconnected',\n clientId,\n });\n this.clients.delete(clientId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n }\n}\n"],"mappings":"SAESA,e;AAET;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,kBAAN,SAAiCD,eAAjC,CAAiD;EAC9CE,OAAO,GAAG,IAAIC,GAAJ,EAAH;EACPC,YAAY,GAAG,CAAH;EAEpB;AACF;AACA;AACA;AACA;AACA;;EACEC,WAAW,CAACC,OAAD,EAA2B;IACpC,MAAMA,OAAN,EAAe,MAAf;EACD;EAED;AACF;AACA;AACA;AACA;;;EACEC,IAAI,CAACC,KAAD,EAAa;IACf,MAAMC,IAAI,GAAG,OAAOD,KAAP,KAAiB,QAAjB,GAA4BA,KAA5B,GAAoCE,IAAI,CAACC,SAAL,CAAeH,KAAf,CAAjD;;IAEA,KAAK,MAAM,GAAGI,MAAH,CAAX,IAAyB,KAAKV,OAAL,CAAaW,OAAb,EAAzB,EAAiD;MAC/C,IAAI;QACFD,MAAM,CAACL,IAAP,CAAYE,IAAZ;MACD,CAFD,CAEE,MAAM,CACN;MACD;IACF;EACF;EAED;AACF;AACA;AACA;AACA;;;EACEK,YAAY,CAACF,MAAD,EAAoB;IAC9B,MAAMG,QAAQ,GAAI,UAAS,KAAKX,YAAL,EAAoB,EAA/C;IACA,KAAKF,OAAL,CAAac,GAAb,CAAiBD,QAAjB,EAA2BH,MAA3B;IAEA,KAAKN,OAAL,CAAaW,GAAb,CAAiBC,IAAjB,CAAsB;MAAEC,GAAG,EAAE,sBAAP;MAA+BJ;IAA/B,CAAtB;IACA,KAAKb,OAAL,CAAac,GAAb,CAAiBD,QAAjB,EAA2BH,MAA3B;;IAEA,MAAMQ,OAAO,GAAG,MAAM;MACpB,KAAKd,OAAL,CAAaW,GAAb,CAAiBC,IAAjB,CAAsB;QACpBC,GAAG,EAAE,yBADe;QAEpBJ;MAFoB,CAAtB;MAIA,KAAKb,OAAL,CAAamB,MAAb,CAAoBN,QAApB;IACD,CAND;;IAQAH,MAAM,CAACU,gBAAP,CAAwB,OAAxB,EAAiCF,OAAjC;IACAR,MAAM,CAACU,gBAAP,CAAwB,OAAxB,EAAiCF,OAAjC;EACD;;AArDqD"}
|
|
@@ -5,7 +5,7 @@ import { WebSocketDevClientServer } from './servers/WebSocketDevClientServer';
|
|
|
5
5
|
import { WebSocketMessageServer } from './servers/WebSocketMessageServer';
|
|
6
6
|
import { WebSocketEventsServer } from './servers/WebSocketEventsServer';
|
|
7
7
|
import { HermesInspectorProxy } from './servers/HermesInspectorProxy';
|
|
8
|
-
import {
|
|
8
|
+
import { WebSocketApiServer } from './servers/WebSocketApiServer';
|
|
9
9
|
import { WebSocketHMRServer } from './servers/WebSocketHMRServer';
|
|
10
10
|
import { WebSocketRouter } from './WebSocketRouter';
|
|
11
11
|
declare module 'fastify' {
|
|
@@ -16,7 +16,7 @@ declare module 'fastify' {
|
|
|
16
16
|
messageServer: WebSocketMessageServer;
|
|
17
17
|
eventsServer: WebSocketEventsServer;
|
|
18
18
|
hermesInspectorProxy: HermesInspectorProxy;
|
|
19
|
-
|
|
19
|
+
apiServer: WebSocketApiServer;
|
|
20
20
|
hmrServer: WebSocketHMRServer;
|
|
21
21
|
router: WebSocketRouter;
|
|
22
22
|
};
|
|
@@ -4,7 +4,7 @@ import { WebSocketDevClientServer } from "./servers/WebSocketDevClientServer.js"
|
|
|
4
4
|
import { WebSocketMessageServer } from "./servers/WebSocketMessageServer.js";
|
|
5
5
|
import { WebSocketEventsServer } from "./servers/WebSocketEventsServer.js";
|
|
6
6
|
import { HermesInspectorProxy } from "./servers/HermesInspectorProxy.js";
|
|
7
|
-
import {
|
|
7
|
+
import { WebSocketApiServer } from "./servers/WebSocketApiServer.js";
|
|
8
8
|
import { WebSocketHMRServer } from "./servers/WebSocketHMRServer.js";
|
|
9
9
|
import { WebSocketRouter } from "./WebSocketRouter.js";
|
|
10
10
|
|
|
@@ -20,14 +20,14 @@ async function wssPlugin(instance, {
|
|
|
20
20
|
webSocketMessageServer: messageServer
|
|
21
21
|
});
|
|
22
22
|
const hermesInspectorProxy = new HermesInspectorProxy(instance, options);
|
|
23
|
-
const
|
|
23
|
+
const apiServer = new WebSocketApiServer(instance);
|
|
24
24
|
const hmrServer = new WebSocketHMRServer(instance, delegate.hmr);
|
|
25
25
|
router.registerServer(debuggerServer);
|
|
26
26
|
router.registerServer(devClientServer);
|
|
27
27
|
router.registerServer(messageServer);
|
|
28
28
|
router.registerServer(eventsServer);
|
|
29
29
|
router.registerServer(hermesInspectorProxy);
|
|
30
|
-
router.registerServer(
|
|
30
|
+
router.registerServer(apiServer);
|
|
31
31
|
router.registerServer(hmrServer);
|
|
32
32
|
instance.decorate('wss', {
|
|
33
33
|
debuggerServer,
|
|
@@ -35,7 +35,7 @@ async function wssPlugin(instance, {
|
|
|
35
35
|
messageServer,
|
|
36
36
|
eventsServer,
|
|
37
37
|
hermesInspectorProxy,
|
|
38
|
-
|
|
38
|
+
apiServer,
|
|
39
39
|
hmrServer,
|
|
40
40
|
router
|
|
41
41
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wssPlugin.js","names":["fastifyPlugin","WebSocketDebuggerServer","WebSocketDevClientServer","WebSocketMessageServer","WebSocketEventsServer","HermesInspectorProxy","
|
|
1
|
+
{"version":3,"file":"wssPlugin.js","names":["fastifyPlugin","WebSocketDebuggerServer","WebSocketDevClientServer","WebSocketMessageServer","WebSocketEventsServer","HermesInspectorProxy","WebSocketApiServer","WebSocketHMRServer","WebSocketRouter","wssPlugin","instance","options","delegate","router","debuggerServer","devClientServer","messageServer","eventsServer","webSocketMessageServer","hermesInspectorProxy","apiServer","hmrServer","hmr","registerServer","decorate","name"],"sources":["../../../src/plugins/wss/wssPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\nimport { WebSocketDebuggerServer } from './servers/WebSocketDebuggerServer';\nimport { WebSocketDevClientServer } from './servers/WebSocketDevClientServer';\nimport { WebSocketMessageServer } from './servers/WebSocketMessageServer';\nimport { WebSocketEventsServer } from './servers/WebSocketEventsServer';\nimport { HermesInspectorProxy } from './servers/HermesInspectorProxy';\nimport { WebSocketApiServer } from './servers/WebSocketApiServer';\nimport { WebSocketHMRServer } from './servers/WebSocketHMRServer';\nimport { WebSocketRouter } from './WebSocketRouter';\n\ndeclare module 'fastify' {\n interface FastifyInstance {\n wss: {\n debuggerServer: WebSocketDebuggerServer;\n devClientServer: WebSocketDevClientServer;\n messageServer: WebSocketMessageServer;\n eventsServer: WebSocketEventsServer;\n hermesInspectorProxy: HermesInspectorProxy;\n apiServer: WebSocketApiServer;\n hmrServer: WebSocketHMRServer;\n router: WebSocketRouter;\n };\n }\n}\n\nasync function wssPlugin(\n instance: FastifyInstance,\n {\n options,\n delegate,\n }: {\n options: Server.Options;\n delegate: Server.Delegate;\n }\n) {\n const router = new WebSocketRouter(instance);\n\n const debuggerServer = new WebSocketDebuggerServer(instance);\n const devClientServer = new WebSocketDevClientServer(instance);\n const messageServer = new WebSocketMessageServer(instance);\n const eventsServer = new WebSocketEventsServer(instance, {\n webSocketMessageServer: messageServer,\n });\n const hermesInspectorProxy = new HermesInspectorProxy(instance, options);\n const apiServer = new WebSocketApiServer(instance);\n const hmrServer = new WebSocketHMRServer(instance, delegate.hmr);\n\n router.registerServer(debuggerServer);\n router.registerServer(devClientServer);\n router.registerServer(messageServer);\n router.registerServer(eventsServer);\n router.registerServer(hermesInspectorProxy);\n router.registerServer(apiServer);\n router.registerServer(hmrServer);\n\n instance.decorate('wss', {\n debuggerServer,\n devClientServer,\n messageServer,\n eventsServer,\n hermesInspectorProxy,\n apiServer,\n hmrServer,\n router,\n });\n}\n\nexport default fastifyPlugin(wssPlugin, {\n name: 'wss-plugin',\n});\n"],"mappings":"AACA,OAAOA,aAAP,MAA0B,gBAA1B;SAESC,uB;SACAC,wB;SACAC,sB;SACAC,qB;SACAC,oB;SACAC,kB;SACAC,kB;SACAC,e;;AAiBT,eAAeC,SAAf,CACEC,QADF,EAEE;EACEC,OADF;EAEEC;AAFF,CAFF,EASE;EACA,MAAMC,MAAM,GAAG,IAAIL,eAAJ,CAAoBE,QAApB,CAAf;EAEA,MAAMI,cAAc,GAAG,IAAIb,uBAAJ,CAA4BS,QAA5B,CAAvB;EACA,MAAMK,eAAe,GAAG,IAAIb,wBAAJ,CAA6BQ,QAA7B,CAAxB;EACA,MAAMM,aAAa,GAAG,IAAIb,sBAAJ,CAA2BO,QAA3B,CAAtB;EACA,MAAMO,YAAY,GAAG,IAAIb,qBAAJ,CAA0BM,QAA1B,EAAoC;IACvDQ,sBAAsB,EAAEF;EAD+B,CAApC,CAArB;EAGA,MAAMG,oBAAoB,GAAG,IAAId,oBAAJ,CAAyBK,QAAzB,EAAmCC,OAAnC,CAA7B;EACA,MAAMS,SAAS,GAAG,IAAId,kBAAJ,CAAuBI,QAAvB,CAAlB;EACA,MAAMW,SAAS,GAAG,IAAId,kBAAJ,CAAuBG,QAAvB,EAAiCE,QAAQ,CAACU,GAA1C,CAAlB;EAEAT,MAAM,CAACU,cAAP,CAAsBT,cAAtB;EACAD,MAAM,CAACU,cAAP,CAAsBR,eAAtB;EACAF,MAAM,CAACU,cAAP,CAAsBP,aAAtB;EACAH,MAAM,CAACU,cAAP,CAAsBN,YAAtB;EACAJ,MAAM,CAACU,cAAP,CAAsBJ,oBAAtB;EACAN,MAAM,CAACU,cAAP,CAAsBH,SAAtB;EACAP,MAAM,CAACU,cAAP,CAAsBF,SAAtB;EAEAX,QAAQ,CAACc,QAAT,CAAkB,KAAlB,EAAyB;IACvBV,cADuB;IAEvBC,eAFuB;IAGvBC,aAHuB;IAIvBC,YAJuB;IAKvBE,oBALuB;IAMvBC,SANuB;IAOvBC,SAPuB;IAQvBR;EARuB,CAAzB;AAUD;;AAED,eAAeb,aAAa,CAACS,SAAD,EAAY;EACtCgB,IAAI,EAAE;AADgC,CAAZ,CAA5B"}
|
package/dist/types.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export declare namespace Server {
|
|
|
46
46
|
hmr: HmrDelegate;
|
|
47
47
|
/** An messages delegate. */
|
|
48
48
|
messages: MessagesDelegate;
|
|
49
|
+
/** An API delegate. */
|
|
50
|
+
api?: Api.Delegate;
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
51
53
|
* A delegate context used in `delegate` builder in {@link Config}.
|
|
@@ -98,6 +100,35 @@ export declare namespace Server {
|
|
|
98
100
|
/** Get message to send as a reply for `GET /status` route. */
|
|
99
101
|
getStatus: () => string;
|
|
100
102
|
}
|
|
103
|
+
namespace Api {
|
|
104
|
+
/** A compilation asset representation for API clients. */
|
|
105
|
+
interface Asset {
|
|
106
|
+
name: string;
|
|
107
|
+
size: number;
|
|
108
|
+
[key: string]: any;
|
|
109
|
+
}
|
|
110
|
+
/** A compilation stats representation for API clients. */
|
|
111
|
+
interface CompilationStats {
|
|
112
|
+
[key: string]: any;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Delegate with implementation for API endpoints.
|
|
116
|
+
*/
|
|
117
|
+
interface Delegate {
|
|
118
|
+
/** Get all platforms - either with already existing compilations or all supported platforms. */
|
|
119
|
+
getPlatforms: () => Promise<string[]>;
|
|
120
|
+
/**
|
|
121
|
+
* Get all assets from compilation for given platform.
|
|
122
|
+
* Should return `[]` if the compilation does not exists for given platform.
|
|
123
|
+
*/
|
|
124
|
+
getAssets: (platform: string) => Promise<Asset[]>;
|
|
125
|
+
/**
|
|
126
|
+
* Get compilation stats for a given platform.
|
|
127
|
+
* Should return `null` if the compilation does not exists for given platform.
|
|
128
|
+
*/
|
|
129
|
+
getCompilationStats: (platform: string) => Promise<CompilationStats | null>;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
101
132
|
}
|
|
102
133
|
/** Representation of the compilation progress. */
|
|
103
134
|
export interface ProgressData {
|
package/dist/types.js
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
export let Server;
|
|
2
2
|
/** Representation of the compilation progress. */
|
|
3
3
|
|
|
4
|
-
(function (_Server) {
|
|
4
|
+
(function (_Server) {
|
|
5
|
+
/** Development server configuration. */
|
|
6
|
+
|
|
7
|
+
/** Development server options. */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A complete delegate with implementations for all server functionalities.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A delegate context used in `delegate` builder in {@link Config}.
|
|
15
|
+
*
|
|
16
|
+
* Allows to emit logs, notify about compilation events and broadcast events to connected clients.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Delegate with implementation for logging functions.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Delegate with implementation for messages used in route handlers.
|
|
25
|
+
*/
|
|
26
|
+
let Api;
|
|
27
|
+
|
|
28
|
+
(function (_Api) {})(Api || (Api = _Server.Api || (_Server.Api = {})));
|
|
29
|
+
})(Server || (Server = {}));
|
|
5
30
|
|
|
6
31
|
/**
|
|
7
32
|
* Internal types. Do not use.
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["Server","EventTypes","Internal"],"sources":["../src/types.ts"],"sourcesContent":["import { FastifyLoggerInstance } from 'fastify';\nimport type { CompilerDelegate } from './plugins/compiler';\nimport type { SymbolicatorDelegate } from './plugins/symbolicate';\nimport type { HmrDelegate } from './plugins/wss';\n\nexport type { CompilerDelegate } from './plugins/compiler';\nexport type {\n SymbolicatorDelegate,\n ReactNativeStackFrame,\n InputStackFrame,\n StackFrame,\n CodeFrame,\n SymbolicatorResults,\n} from './plugins/symbolicate';\nexport type { HmrDelegate } from './plugins/wss';\n\nexport namespace Server {\n /** Development server configuration. */\n export interface Config {\n /** Development server options to configure e.g: `port`, `host` etc. */\n options: Options;\n\n /** Function to create a delegate, which implements crucial functionalities. */\n delegate: (context: DelegateContext) => Delegate;\n }\n\n /** Development server options. */\n export interface Options {\n /** Root directory of the project. */\n rootDir: string;\n\n /** Port under which to run the development server. */\n port: number;\n\n /**\n * Hostname or IP address under which to run the development server.\n * When left unspecified, it will listen on all available network interfaces, similarly to listening on '0.0.0.0'.\n */\n host?: string;\n\n /** Options for running the server as HTTPS. If `undefined`, the server will run as HTTP. */\n https?: {\n /** Path to certificate when running server as HTTPS. */\n cert?: string;\n\n /** Path to certificate key when running server as HTTPS. */\n key?: string;\n };\n }\n\n /**\n * A complete delegate with implementations for all server functionalities.\n */\n export interface Delegate {\n /** A compiler delegate. */\n compiler: CompilerDelegate;\n\n /** A symbolicator delegate. */\n symbolicator: SymbolicatorDelegate;\n\n /** A logger delegate. */\n logger: LoggerDelegate;\n\n /** An HMR delegate. */\n hmr: HmrDelegate;\n\n /** An messages delegate. */\n messages: MessagesDelegate;\n }\n\n /**\n * A delegate context used in `delegate` builder in {@link Config}.\n *\n * Allows to emit logs, notify about compilation events and broadcast events to connected clients.\n */\n export interface DelegateContext {\n /** A logger instance, useful for emitting logs from the delegate. */\n log: FastifyLoggerInstance;\n\n /** Send notification about compilation start for given `platform`. */\n notifyBuildStart: (platform: string) => void;\n\n /** Send notification about compilation end for given `platform`. */\n notifyBuildEnd: (platform: string) => void;\n\n /**\n * Broadcast arbitrary event to all connected HMR clients for given `platform`.\n *\n * @param event Arbitrary event to broadcast.\n * @param platform Platform of the clients to which broadcast should be sent.\n * @param clientIds Ids of the client to which broadcast should be sent.\n * If `undefined` the broadcast will be sent to all connected clients for the given `platform`.\n */\n broadcastToHmrClients: <E = any>(\n event: E,\n platform: string,\n clientIds?: string[]\n ) => void;\n\n /**\n * Broadcast arbitrary method-like event to all connected message clients.\n *\n * @param event Arbitrary method-like event to broadcast.\n */\n broadcastToMessageClients: <\n E extends { method: string; params?: Record<string, any> }\n >(\n event: E\n ) => void;\n }\n\n /**\n * Delegate with implementation for logging functions.\n */\n export interface LoggerDelegate {\n /**\n * Callback for when a new log is emitted.\n *\n * @param log An object with log data.\n */\n onMessage: (log: any) => void;\n }\n\n /**\n * Delegate with implementation for messages used in route handlers.\n */\n export interface MessagesDelegate {\n /** Get message to send as a reply for `GET /` route. */\n getHello: () => string;\n\n /** Get message to send as a reply for `GET /status` route. */\n getStatus: () => string;\n }\n}\n\n/** Representation of the compilation progress. */\nexport interface ProgressData {\n /** Number of modules built. */\n completed: number;\n\n /** Total number of modules detect as part of compilation. */\n total: number;\n}\n\n/**\n * Type representing a function to send the progress.\n *\n * Used by {@link CompilerDelegate} in `getAsset` function to send the compilation\n * progress to the client who requested the asset.\n */\nexport type SendProgress = (data: ProgressData) => void;\n\n/**\n * Internal types. Do not use.\n *\n * @internal\n */\nexport namespace Internal {\n export enum EventTypes {\n BuildStart = 'BuildStart',\n BuildEnd = 'BuildEnd',\n HmrEvent = 'HmrEvent',\n }\n}\n"],"mappings":"AAgBA;
|
|
1
|
+
{"version":3,"file":"types.js","names":["Api","Server","EventTypes","Internal"],"sources":["../src/types.ts"],"sourcesContent":["import { FastifyLoggerInstance } from 'fastify';\nimport type { CompilerDelegate } from './plugins/compiler';\nimport type { SymbolicatorDelegate } from './plugins/symbolicate';\nimport type { HmrDelegate } from './plugins/wss';\n\nexport type { CompilerDelegate } from './plugins/compiler';\nexport type {\n SymbolicatorDelegate,\n ReactNativeStackFrame,\n InputStackFrame,\n StackFrame,\n CodeFrame,\n SymbolicatorResults,\n} from './plugins/symbolicate';\nexport type { HmrDelegate } from './plugins/wss';\n\nexport namespace Server {\n /** Development server configuration. */\n export interface Config {\n /** Development server options to configure e.g: `port`, `host` etc. */\n options: Options;\n\n /** Function to create a delegate, which implements crucial functionalities. */\n delegate: (context: DelegateContext) => Delegate;\n }\n\n /** Development server options. */\n export interface Options {\n /** Root directory of the project. */\n rootDir: string;\n\n /** Port under which to run the development server. */\n port: number;\n\n /**\n * Hostname or IP address under which to run the development server.\n * When left unspecified, it will listen on all available network interfaces, similarly to listening on '0.0.0.0'.\n */\n host?: string;\n\n /** Options for running the server as HTTPS. If `undefined`, the server will run as HTTP. */\n https?: {\n /** Path to certificate when running server as HTTPS. */\n cert?: string;\n\n /** Path to certificate key when running server as HTTPS. */\n key?: string;\n };\n }\n\n /**\n * A complete delegate with implementations for all server functionalities.\n */\n export interface Delegate {\n /** A compiler delegate. */\n compiler: CompilerDelegate;\n\n /** A symbolicator delegate. */\n symbolicator: SymbolicatorDelegate;\n\n /** A logger delegate. */\n logger: LoggerDelegate;\n\n /** An HMR delegate. */\n hmr: HmrDelegate;\n\n /** An messages delegate. */\n messages: MessagesDelegate;\n\n /** An API delegate. */\n api?: Api.Delegate;\n }\n\n /**\n * A delegate context used in `delegate` builder in {@link Config}.\n *\n * Allows to emit logs, notify about compilation events and broadcast events to connected clients.\n */\n export interface DelegateContext {\n /** A logger instance, useful for emitting logs from the delegate. */\n log: FastifyLoggerInstance;\n\n /** Send notification about compilation start for given `platform`. */\n notifyBuildStart: (platform: string) => void;\n\n /** Send notification about compilation end for given `platform`. */\n notifyBuildEnd: (platform: string) => void;\n\n /**\n * Broadcast arbitrary event to all connected HMR clients for given `platform`.\n *\n * @param event Arbitrary event to broadcast.\n * @param platform Platform of the clients to which broadcast should be sent.\n * @param clientIds Ids of the client to which broadcast should be sent.\n * If `undefined` the broadcast will be sent to all connected clients for the given `platform`.\n */\n broadcastToHmrClients: <E = any>(\n event: E,\n platform: string,\n clientIds?: string[]\n ) => void;\n\n /**\n * Broadcast arbitrary method-like event to all connected message clients.\n *\n * @param event Arbitrary method-like event to broadcast.\n */\n broadcastToMessageClients: <\n E extends { method: string; params?: Record<string, any> }\n >(\n event: E\n ) => void;\n }\n\n /**\n * Delegate with implementation for logging functions.\n */\n export interface LoggerDelegate {\n /**\n * Callback for when a new log is emitted.\n *\n * @param log An object with log data.\n */\n onMessage: (log: any) => void;\n }\n\n /**\n * Delegate with implementation for messages used in route handlers.\n */\n export interface MessagesDelegate {\n /** Get message to send as a reply for `GET /` route. */\n getHello: () => string;\n\n /** Get message to send as a reply for `GET /status` route. */\n getStatus: () => string;\n }\n\n export namespace Api {\n /** A compilation asset representation for API clients. */\n export interface Asset {\n name: string;\n size: number;\n [key: string]: any;\n }\n\n /** A compilation stats representation for API clients. */\n export interface CompilationStats {\n [key: string]: any;\n }\n\n /**\n * Delegate with implementation for API endpoints.\n */\n export interface Delegate {\n /** Get all platforms - either with already existing compilations or all supported platforms. */\n getPlatforms: () => Promise<string[]>;\n\n /**\n * Get all assets from compilation for given platform.\n * Should return `[]` if the compilation does not exists for given platform.\n */\n getAssets: (platform: string) => Promise<Asset[]>;\n\n /**\n * Get compilation stats for a given platform.\n * Should return `null` if the compilation does not exists for given platform.\n */\n getCompilationStats: (\n platform: string\n ) => Promise<CompilationStats | null>;\n }\n }\n}\n\n/** Representation of the compilation progress. */\nexport interface ProgressData {\n /** Number of modules built. */\n completed: number;\n\n /** Total number of modules detect as part of compilation. */\n total: number;\n}\n\n/**\n * Type representing a function to send the progress.\n *\n * Used by {@link CompilerDelegate} in `getAsset` function to send the compilation\n * progress to the client who requested the asset.\n */\nexport type SendProgress = (data: ProgressData) => void;\n\n/**\n * Internal types. Do not use.\n *\n * @internal\n */\nexport namespace Internal {\n export enum EventTypes {\n BuildStart = 'BuildStart',\n BuildEnd = 'BuildEnd',\n HmrEvent = 'HmrEvent',\n }\n}\n"],"mappings":"AAgBA;AA8JA;;;EA7JE;;EASA;;EAwBA;AACF;AACA;;EAqBE;AACF;AACA;AACA;AACA;;EAqCE;AACF;AACA;;EAUE;AACF;AACA;;;uBASmBA,G,KAAAA,G,WAAAA,G,aAAAA,G;GAzHFC,M,KAAAA,M;;AA+KjB;AACA;AACA;AACA;AACA;AACA;;;MACcC,U;;aAAAA,U;IAAAA,U;IAAAA,U;IAAAA,U;KAAAA,U,KAAAA,U;;;GADGC,Q,KAAAA,Q"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@callstack/repack-dev-server",
|
|
3
3
|
"description": "A bundler-agnostic development server for React Native applications as part of @callstack/repack.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.0.0-next.
|
|
5
|
+
"version": "1.0.0-next.1",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketDashboardServer.js","names":["WebSocketServer","WebSocketDashboardServer","clients","Map","nextClientId","constructor","fastify","send","event","data","JSON","stringify","socket","entries","onConnection","clientId","set","log","info","msg","onClose","delete","addEventListener"],"sources":["../../../../src/plugins/wss/servers/WebSocketDashboardServer.ts"],"sourcesContent":["import { FastifyInstance } from 'fastify';\nimport WebSocket from 'ws';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for Dashboard client.\n * It's used by built-in Dashboard web-app to receive compilation\n * events, logs and other necessary messages.\n *\n * @category Development server\n */\nexport class WebSocketDashboardServer extends WebSocketServer {\n private clients = new Map<string, WebSocket>();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketDashboardServer and attach it to the given Fastify instance.\n * Any logging information, will be passed through standard `fastify.log` API.\n *\n * @param fastify Fastify instance to attach the WebSocket server to.\n * @param emitter Event emitter instance.\n */\n constructor(fastify: FastifyInstance) {\n super(fastify, '/api/dashboard');\n }\n\n /**\n * Send message to all connected Dashboard clients.\n *\n * @param event Event string or object to send.\n */\n send(event: any) {\n const data = typeof event === 'string' ? event : JSON.stringify(event);\n\n for (const [, socket] of this.clients.entries()) {\n try {\n socket.send(data);\n } catch {\n // NOOP\n }\n }\n }\n\n /**\n * Process new WebSocket connection from client application.\n *\n * @param socket Incoming client's WebSocket connection.\n */\n onConnection(socket: WebSocket) {\n const clientId = `client#${this.nextClientId++}`;\n this.clients.set(clientId, socket);\n\n this.fastify.log.info({ msg: 'Dashboard client connected', clientId });\n this.clients.set(clientId, socket);\n\n const onClose = () => {\n this.fastify.log.info({\n msg: 'Dashboard client disconnected',\n clientId,\n });\n this.clients.delete(clientId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n }\n}\n"],"mappings":"SAESA,e;AAET;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,wBAAN,SAAuCD,eAAvC,CAAuD;EACpDE,OAAO,GAAG,IAAIC,GAAJ,EAAH;EACPC,YAAY,GAAG,CAAH;EAEpB;AACF;AACA;AACA;AACA;AACA;AACA;;EACEC,WAAW,CAACC,OAAD,EAA2B;IACpC,MAAMA,OAAN,EAAe,gBAAf;EACD;EAED;AACF;AACA;AACA;AACA;;;EACEC,IAAI,CAACC,KAAD,EAAa;IACf,MAAMC,IAAI,GAAG,OAAOD,KAAP,KAAiB,QAAjB,GAA4BA,KAA5B,GAAoCE,IAAI,CAACC,SAAL,CAAeH,KAAf,CAAjD;;IAEA,KAAK,MAAM,GAAGI,MAAH,CAAX,IAAyB,KAAKV,OAAL,CAAaW,OAAb,EAAzB,EAAiD;MAC/C,IAAI;QACFD,MAAM,CAACL,IAAP,CAAYE,IAAZ;MACD,CAFD,CAEE,MAAM,CACN;MACD;IACF;EACF;EAED;AACF;AACA;AACA;AACA;;;EACEK,YAAY,CAACF,MAAD,EAAoB;IAC9B,MAAMG,QAAQ,GAAI,UAAS,KAAKX,YAAL,EAAoB,EAA/C;IACA,KAAKF,OAAL,CAAac,GAAb,CAAiBD,QAAjB,EAA2BH,MAA3B;IAEA,KAAKN,OAAL,CAAaW,GAAb,CAAiBC,IAAjB,CAAsB;MAAEC,GAAG,EAAE,4BAAP;MAAqCJ;IAArC,CAAtB;IACA,KAAKb,OAAL,CAAac,GAAb,CAAiBD,QAAjB,EAA2BH,MAA3B;;IAEA,MAAMQ,OAAO,GAAG,MAAM;MACpB,KAAKd,OAAL,CAAaW,GAAb,CAAiBC,IAAjB,CAAsB;QACpBC,GAAG,EAAE,+BADe;QAEpBJ;MAFoB,CAAtB;MAIA,KAAKb,OAAL,CAAamB,MAAb,CAAoBN,QAApB;IACD,CAND;;IAQAH,MAAM,CAACU,gBAAP,CAAwB,OAAxB,EAAiCF,OAAjC;IACAR,MAAM,CAACU,gBAAP,CAAwB,OAAxB,EAAiCF,OAAjC;EACD;;AAtD2D"}
|