@callstack/repack-dev-server 4.0.0 → 5.0.0-next.0
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 +2 -0
- package/dist/createServer.js +5 -2
- package/dist/createServer.js.map +1 -1
- package/dist/plugins/compiler/compilerPlugin.js +1 -12
- package/dist/plugins/compiler/compilerPlugin.js.map +1 -1
- package/dist/plugins/compiler/types.d.ts +1 -3
- package/dist/plugins/compiler/types.js.map +1 -1
- package/dist/plugins/symbolicate/Symbolicator.js +3 -2
- package/dist/plugins/symbolicate/Symbolicator.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketApiServer.js +2 -2
- package/dist/plugins/wss/servers/WebSocketApiServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js +9 -4
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketHMRServer.js +3 -3
- package/dist/plugins/wss/servers/WebSocketHMRServer.js.map +1 -1
- package/dist/types.d.ts +3 -15
- package/dist/types.js +0 -7
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/createServer.js
CHANGED
|
@@ -25,6 +25,7 @@ export async function createServer(config) {
|
|
|
25
25
|
|
|
26
26
|
/** Fastify instance powering the development server. */
|
|
27
27
|
const instance = Fastify({
|
|
28
|
+
disableRequestLogging: !config.options.logRequests,
|
|
28
29
|
logger: {
|
|
29
30
|
level: 'trace',
|
|
30
31
|
stream: new Writable({
|
|
@@ -40,7 +41,7 @@ export async function createServer(config) {
|
|
|
40
41
|
https: config.options.https
|
|
41
42
|
} : undefined)
|
|
42
43
|
});
|
|
43
|
-
delegate = config.delegate({
|
|
44
|
+
delegate = await config.delegate({
|
|
44
45
|
log: instance.log,
|
|
45
46
|
notifyBuildStart: platform => {
|
|
46
47
|
instance.wss.apiServer.send({
|
|
@@ -101,7 +102,9 @@ export async function createServer(config) {
|
|
|
101
102
|
});
|
|
102
103
|
instance.use('/debugger-ui', debuggerUIMiddleware());
|
|
103
104
|
instance.use('/open-url', openURLMiddleware);
|
|
104
|
-
instance.use('/open-stack-frame', openStackFrameInEditorMiddleware
|
|
105
|
+
instance.use('/open-stack-frame', openStackFrameInEditorMiddleware({
|
|
106
|
+
watchFolders: [config.options.rootDir]
|
|
107
|
+
}));
|
|
105
108
|
await instance.register(symbolicatePlugin, {
|
|
106
109
|
delegate
|
|
107
110
|
});
|
package/dist/createServer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServer.js","names":["Writable","Fastify","fastifySensible","middie","createDevMiddleware","debuggerUIMiddleware","openURLMiddleware","openStackFrameInEditorMiddleware","multipartPlugin","compilerPlugin","apiPlugin","wssPlugin","faviconPlugin","Internal","symbolicatePlugin","devtoolsPlugin","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","devMiddleware","projectRoot","rootDir","serverBaseUrl","host","port","unstable_experiments","enableNewDebugger","experiments","experimentalDebugger","register","endpoints","websocketEndpoints","prefix","use","addHook","request","reply","payload","header","pathname","url","split","endsWith","middleware","get","messages","getHello","getStatus","start","listen","stop","close"],"sources":["../src/createServer.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport Fastify from 'fastify';\nimport fastifySensible from '@fastify/sensible';\nimport middie from '@fastify/middie';\n// eslint-disable-next-line import/no-unresolved -- no main field in package.json\nimport { createDevMiddleware } from '@react-native/dev-middleware';\nimport { debuggerUIMiddleware } from '@react-native-community/cli-debugger-ui';\nimport {\n openURLMiddleware,\n openStackFrameInEditorMiddleware,\n} from '@react-native-community/cli-server-api';\nimport multipartPlugin from './plugins/multipart';\nimport compilerPlugin from './plugins/compiler';\nimport apiPlugin from './plugins/api';\nimport wssPlugin from './plugins/wss';\nimport faviconPlugin from './plugins/favicon';\nimport { Internal, Server } from './types';\nimport symbolicatePlugin from './plugins/symbolicate';\nimport devtoolsPlugin from './plugins/devtools';\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 const devMiddleware = createDevMiddleware({\n projectRoot: config.options.rootDir,\n serverBaseUrl: `http://${config.options.host}:${config.options.port}`,\n logger: instance.log,\n unstable_experiments: {\n enableNewDebugger: config.experiments?.experimentalDebugger,\n },\n });\n\n // Register plugins\n await instance.register(fastifySensible);\n await instance.register(middie);\n await instance.register(wssPlugin, {\n options: {\n ...config.options,\n endpoints: devMiddleware.websocketEndpoints,\n },\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\n // TODO: devtoolsPlugin and the following deprecated remote debugger middlewares should be removed after\n // the new (experimental) debugger is stable AND the remote debugger is finally removed from the React Native core.\n // When that happens remember to remove @react-native-community/cli-server-api & @react-native-community/cli-debugger-ui\n // from the dependencies.\n await instance.register(devtoolsPlugin, {\n options: config.options,\n });\n instance.use('/debugger-ui', debuggerUIMiddleware());\n instance.use('/open-url', openURLMiddleware);\n instance.use('/open-stack-frame', openStackFrameInEditorMiddleware);\n\n await instance.register(symbolicatePlugin, {\n delegate,\n });\n\n // below is to prevent showing `GET 400 /favicon.ico`\n // errors in console when requesting the bundle via browser\n await instance.register(faviconPlugin);\n\n instance.addHook('onSend', async (request, reply, payload) => {\n reply.header('X-Content-Type-Options', 'nosniff');\n reply.header('X-React-Native-Project-Root', config.options.rootDir);\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 dev middleware\n instance.use(devMiddleware.middleware);\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({\n port: config.options.port,\n host: config.options.host,\n });\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":"AAAA,SAASA,QAAQ,QAAQ,QAAQ;AACjC,OAAOC,OAAO,MAAM,SAAS;AAC7B,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,OAAOC,MAAM,MAAM,iBAAiB;AACpC;AACA,SAASC,mBAAmB,QAAQ,8BAA8B;AAClE,SAASC,oBAAoB,QAAQ,yCAAyC;AAC9E,SACEC,iBAAiB,EACjBC,gCAAgC,QAC3B,wCAAwC;AAAC,OACzCC,eAAe;AAAA,OACfC,cAAc;AAAA,OACdC,SAAS;AAAA,OACTC,SAAS;AAAA,OACTC,aAAa;AAAA,SACXC,QAAQ;AAAA,OACVC,iBAAiB;AAAA,OACjBC,cAAc;AAErB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,Y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C;MACpBzB,IAAI,EAAEzC,MAAM,CAACkB,OAAO,CAACuB,IAAI;MACzBD,IAAI,EAAExC,MAAM,CAACkB,OAAO,CAACsB;IACvB,CAAC,CAAC;EACJ;;EAEA;EACA,eAAe2B,IAAIA,CAAA,EAAG;IACpB,MAAMjE,QAAQ,CAACkE,KAAK,CAAC,CAAC;EACxB;EAEA,OAAO;IACLH,KAAK;IACLE,IAAI;IACJjE;EACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"createServer.js","names":["Writable","Fastify","fastifySensible","middie","createDevMiddleware","debuggerUIMiddleware","openURLMiddleware","openStackFrameInEditorMiddleware","multipartPlugin","compilerPlugin","apiPlugin","wssPlugin","faviconPlugin","Internal","symbolicatePlugin","devtoolsPlugin","createServer","config","delegate","instance","disableRequestLogging","options","logRequests","logger","level","stream","write","chunk","_encoding","callback","log","JSON","parse","toString","onMessage","wss","apiServer","send","https","undefined","notifyBuildStart","platform","event","EventTypes","BuildStart","notifyBuildEnd","BuildEnd","broadcastToHmrClients","clientIds","hmrServer","broadcastToMessageClients","method","params","messageServer","broadcast","devMiddleware","projectRoot","rootDir","serverBaseUrl","host","port","unstable_experiments","enableNewDebugger","experiments","experimentalDebugger","register","endpoints","websocketEndpoints","prefix","use","watchFolders","addHook","request","reply","payload","header","pathname","url","split","endsWith","middleware","get","messages","getHello","getStatus","start","listen","stop","close"],"sources":["../src/createServer.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport Fastify from 'fastify';\nimport fastifySensible from '@fastify/sensible';\nimport middie from '@fastify/middie';\n// eslint-disable-next-line import/no-unresolved -- no main field in package.json\nimport { createDevMiddleware } from '@react-native/dev-middleware';\nimport { debuggerUIMiddleware } from '@react-native-community/cli-debugger-ui';\nimport {\n openURLMiddleware,\n openStackFrameInEditorMiddleware,\n} from '@react-native-community/cli-server-api';\nimport multipartPlugin from './plugins/multipart';\nimport compilerPlugin from './plugins/compiler';\nimport apiPlugin from './plugins/api';\nimport wssPlugin from './plugins/wss';\nimport faviconPlugin from './plugins/favicon';\nimport { Internal, Server } from './types';\nimport symbolicatePlugin from './plugins/symbolicate';\nimport devtoolsPlugin from './plugins/devtools';\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 disableRequestLogging: !config.options.logRequests,\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 = await 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 const devMiddleware = createDevMiddleware({\n projectRoot: config.options.rootDir,\n serverBaseUrl: `http://${config.options.host}:${config.options.port}`,\n logger: instance.log,\n unstable_experiments: {\n enableNewDebugger: config.experiments?.experimentalDebugger,\n },\n });\n\n // Register plugins\n await instance.register(fastifySensible);\n await instance.register(middie);\n await instance.register(wssPlugin, {\n options: {\n ...config.options,\n endpoints: devMiddleware.websocketEndpoints,\n },\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\n // TODO: devtoolsPlugin and the following deprecated remote debugger middlewares should be removed after\n // the new (experimental) debugger is stable AND the remote debugger is finally removed from the React Native core.\n // When that happens remember to remove @react-native-community/cli-server-api & @react-native-community/cli-debugger-ui\n // from the dependencies.\n await instance.register(devtoolsPlugin, {\n options: config.options,\n });\n instance.use('/debugger-ui', debuggerUIMiddleware());\n instance.use('/open-url', openURLMiddleware);\n instance.use(\n '/open-stack-frame',\n openStackFrameInEditorMiddleware({\n watchFolders: [config.options.rootDir],\n })\n );\n\n await instance.register(symbolicatePlugin, {\n delegate,\n });\n\n // below is to prevent showing `GET 400 /favicon.ico`\n // errors in console when requesting the bundle via browser\n await instance.register(faviconPlugin);\n\n instance.addHook('onSend', async (request, reply, payload) => {\n reply.header('X-Content-Type-Options', 'nosniff');\n reply.header('X-React-Native-Project-Root', config.options.rootDir);\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 dev middleware\n instance.use(devMiddleware.middleware);\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({\n port: config.options.port,\n host: config.options.host,\n });\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":"AAAA,SAASA,QAAQ,QAAQ,QAAQ;AACjC,OAAOC,OAAO,MAAM,SAAS;AAC7B,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,OAAOC,MAAM,MAAM,iBAAiB;AACpC;AACA,SAASC,mBAAmB,QAAQ,8BAA8B;AAClE,SAASC,oBAAoB,QAAQ,yCAAyC;AAC9E,SACEC,iBAAiB,EACjBC,gCAAgC,QAC3B,wCAAwC;AAAC,OACzCC,eAAe;AAAA,OACfC,cAAc;AAAA,OACdC,SAAS;AAAA,OACTC,SAAS;AAAA,OACTC,aAAa;AAAA,SACXC,QAAQ;AAAA,OACVC,iBAAiB;AAAA,OACjBC,cAAc;AAErB;AACA;AACA;AACA;AACA;AACA;A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GAAG,CAAC,SAAS,EAAE,YAAY/D,QAAQ,CAACgE,QAAQ,CAACE,SAAS,CAAC,CAAC,CAAC;;EAElE;EACA,eAAeC,KAAKA,CAAA,EAAG;IACrB,MAAMlE,QAAQ,CAACmE,MAAM,CAAC;MACpB1B,IAAI,EAAE3C,MAAM,CAACI,OAAO,CAACuC,IAAI;MACzBD,IAAI,EAAE1C,MAAM,CAACI,OAAO,CAACsC;IACvB,CAAC,CAAC;EACJ;;EAEA;EACA,eAAe4B,IAAIA,CAAA,EAAG;IACpB,MAAMpE,QAAQ,CAACqE,KAAK,CAAC,CAAC;EACxB;EAEA,OAAO;IACLH,KAAK;IACLE,IAAI;IACJpE;EACF,CAAC;AACH"}
|
|
@@ -39,19 +39,8 @@ async function compilerPlugin(instance, {
|
|
|
39
39
|
file = file.replace(`${platform}/`, '');
|
|
40
40
|
}
|
|
41
41
|
const multipart = reply.asMultipart();
|
|
42
|
-
const sendProgress = ({
|
|
43
|
-
completed,
|
|
44
|
-
total
|
|
45
|
-
}) => {
|
|
46
|
-
multipart?.writeChunk({
|
|
47
|
-
'Content-Type': 'application/json'
|
|
48
|
-
}, JSON.stringify({
|
|
49
|
-
done: completed,
|
|
50
|
-
total
|
|
51
|
-
}));
|
|
52
|
-
};
|
|
53
42
|
try {
|
|
54
|
-
const asset = await delegate.compiler.getAsset(file, platform
|
|
43
|
+
const asset = await delegate.compiler.getAsset(file, platform);
|
|
55
44
|
const mimeType = delegate.compiler.getMimeType(file, platform, asset);
|
|
56
45
|
if (multipart) {
|
|
57
46
|
const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compilerPlugin.js","names":["fastifyPlugin","compilerPlugin","instance","delegate","route","method","url","schema","querystring","type","properties","platform","handler","request","reply","file","params","query","log","error","notFound","compiler","inferPlatform","badRequest","startsWith","replace","multipart","asMultipart","
|
|
1
|
+
{"version":3,"file":"compilerPlugin.js","names":["fastifyPlugin","compilerPlugin","instance","delegate","route","method","url","schema","querystring","type","properties","platform","handler","request","reply","file","params","query","log","error","notFound","compiler","inferPlatform","badRequest","startsWith","replace","multipart","asMultipart","asset","getAsset","mimeType","getMimeType","buffer","Buffer","isBuffer","from","setHeader","String","byteLength","end","code","send","message","name","dependencies"],"sources":["../../../src/plugins/compiler/compilerPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\n\nasync function compilerPlugin(\n instance: FastifyInstance,\n { delegate }: { delegate: Server.Delegate }\n) {\n instance.route({\n method: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'],\n url: '/*',\n schema: {\n querystring: {\n type: 'object',\n properties: {\n platform: {\n type: 'string',\n },\n },\n },\n },\n handler: async (request, reply) => {\n let file = (request.params as { '*'?: string })['*'];\n let { platform } = request.query as { platform?: string };\n\n if (!file) {\n // This technically should never happen - this route should not be called if file is missing.\n request.log.error(`File was not provided`);\n return reply.notFound();\n }\n\n // Let consumer infer the platform. If function is not provided fallback\n // to platform query param.\n platform = delegate.compiler.inferPlatform?.(request.url) ?? platform;\n\n if (!platform) {\n request.log.error('Cannot detect platform');\n return reply.badRequest('Cannot detect platform');\n }\n\n // If platform happens to be in front of an asset remove it.\n if (file.startsWith(`${platform}/`)) {\n file = file.replace(`${platform}/`, '');\n }\n\n const multipart = reply.asMultipart();\n\n try {\n const asset = await delegate.compiler.getAsset(file, platform);\n const mimeType = delegate.compiler.getMimeType(file, platform, asset);\n\n if (multipart) {\n const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);\n multipart.setHeader('Content-Type', `${mimeType}; charset=UTF-8`);\n multipart.setHeader(\n 'Content-Length',\n String(Buffer.byteLength(buffer))\n );\n multipart.end(buffer);\n } else {\n return reply.code(200).type(mimeType).send(asset);\n }\n } catch (error) {\n request.log.error(error);\n return reply.notFound((error as Error).message);\n }\n },\n });\n}\n\nexport default fastifyP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ate with implementation for compiler-specific functions.
|
|
5
4
|
*/
|
|
@@ -11,9 +10,8 @@ export interface CompilerDelegate {
|
|
|
11
10
|
*
|
|
12
11
|
* @param filename Filename of the asset to get.
|
|
13
12
|
* @param platform Platform of the asset to get.
|
|
14
|
-
* @param sendProgress Function to notify the client who requested the asset about compilation progress.
|
|
15
13
|
*/
|
|
16
|
-
getAsset: (filename: string, platform: string
|
|
14
|
+
getAsset: (filename: string, platform: string) => Promise<string | Buffer>;
|
|
17
15
|
/**
|
|
18
16
|
* Detect MIME type of the asset from `filename`, `platform` or `data` (or from combination of either).
|
|
19
17
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/compiler/types.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/compiler/types.ts"],"sourcesContent":["/**\n * Delegate with implementation for compiler-specific functions.\n */\nexport interface CompilerDelegate {\n /**\n * Get compiled asset content.\n *\n * If the compilation is in progress, it should wait until compilation finishes and then return the asset.\n *\n * @param filename Filename of the asset to get.\n * @param platform Platform of the asset to get.\n */\n getAsset: (filename: string, platform: string) => Promise<string | Buffer>;\n\n /**\n * Detect MIME type of the asset from `filename`, `platform` or `data` (or from combination of either).\n *\n * @param filename Filename of the asset.\n * @param platform Platform of the asset.\n * @param data Asset's content.\n */\n getMimeType: (\n filename: string,\n platform: string,\n data: string | Buffer\n ) => string;\n\n /**\n * Detect the platform from the URI - either from filename, query params or both.\n *\n * @param uri URI string.\n */\n inferPlatform?: (uri: string) => string | undefined;\n}\n"],"mappings":""}
|
|
@@ -19,7 +19,7 @@ export class Symbolicator {
|
|
|
19
19
|
static inferPlatformFromStack(stack) {
|
|
20
20
|
for (const frame of stack) {
|
|
21
21
|
if (!frame.file) {
|
|
22
|
-
|
|
22
|
+
continue;
|
|
23
23
|
}
|
|
24
24
|
const {
|
|
25
25
|
searchParams,
|
|
@@ -146,7 +146,8 @@ export class Symbolicator {
|
|
|
146
146
|
}
|
|
147
147
|
const lookup = consumer.originalPositionFor({
|
|
148
148
|
line: frame.lineNumber,
|
|
149
|
-
column: frame.column
|
|
149
|
+
column: frame.column,
|
|
150
|
+
bias: SourceMapConsumer.LEAST_UPPER_BOUND
|
|
150
151
|
});
|
|
151
152
|
|
|
152
153
|
// If lookup fails, we get the same shape object, but with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Symbolicator.js","names":["URL","codeFrameColumns","SourceMapConsumer","Symbolicator","inferPlatformFromStack","stack","frame","file","searchParams","pathname","platform","get","bundleFilename","split","reverse","platformOrExtension","extension","sourceMapConsumerCache","constructor","delegate","process","logger","debug","msg","frames","startsWith","includes","push","processedFrames","fileUrl","rawSourceMap","getSourceMap","sourceMapLength","length","sourceMapConsumer","toString","processedFrame","processFrame","codeFrame","getCodeFrame","key","destroy","lineNumber","column","collapse","consumer","lookup","originalPositionFor","line","source","methodName","name","shouldIncludeFrame","undefined","content","getSource","start","forceColor","location","row","fileName","error","message"],"sources":["../../../src/plugins/symbolicate/Symbolicator.ts"],"sourcesContent":["import { URL } from 'url';\nimport { codeFrameColumns } from '@babel/code-frame';\nimport { SourceMapConsumer } from 'source-map';\nimport type { FastifyLoggerInstance } from 'fastify';\nimport type {\n CodeFrame,\n InputStackFrame,\n ReactNativeStackFrame,\n StackFrame,\n SymbolicatorDelegate,\n SymbolicatorResults,\n} from './types';\n\n/**\n * Class for transforming stack traces from React Native application with using Source Map.\n * Raw stack frames produced by React Native, points to some location from the bundle\n * eg `index.bundle?platform=ios:567:1234`. By using Source Map for that bundle `Symbolicator`\n * produces frames that point to source code inside your project eg `Hello.tsx:10:9`.\n */\nexport class Symbolicator {\n /**\n * Infer platform from stack frames.\n * Usually at least one frame has `file` field with the bundle URL eg:\n * `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.\n *\n * @param stack Array of stack frames.\n * @returns Inferred platform or `undefined` if cannot infer.\n */\n static inferPlatformFromStack(stack: ReactNativeStackFrame[]) {\n for (const frame of stack) {\n if (!frame.file) {\n return;\n }\n\n const { searchParams, pathname } = new URL(frame.file, 'file://');\n const platform = searchParams.get('platform');\n if (platform) {\n return platform;\n } else {\n const [bundleFilename] = pathname.split('/').reverse();\n const [, platformOrExtension, extension] = bundleFilename.split('.');\n if (extension) {\n return platformOrExtension;\n }\n }\n }\n }\n\n /**\n * Cache with initialized `SourceMapConsumer` to improve symbolication performance.\n */\n sourceMapConsumerCache: Record<string, SourceMapConsumer> = {};\n\n /**\n * Constructs new `Symbolicator` instance.\n *\n * @param delegate Delegate instance with symbolication functions.\n */\n constructor(private delegate: SymbolicatorDelegate) {}\n\n /**\n * Process raw React Native stack frames and transform them using Source Maps.\n * Method will try to symbolicate as much data as possible, but if the Source Maps\n * are not available, invalid or the original positions/data is not found in Source Maps,\n * the method will return raw values - the same as supplied with `stack` parameter.\n * For example out of 10 frames, it's possible that only first 7 will be symbolicated and the\n * remaining 3 will be unchanged.\n *\n * @param logger Fastify logger instance.\n * @param stack Raw stack frames.\n * @returns Symbolicated stack frames.\n */\n async process(\n logger: FastifyLoggerInstance,\n stack: ReactNativeStackFrame[]\n ): Promise<SymbolicatorResults> {\n logger.debug({ msg: 'Filtering out unnecessary frames' });\n\n const frames: InputStackFrame[] = [];\n for (const frame of stack) {\n const { file } = frame;\n if (file?.startsWith('http') && !file.includes('debuggerWorker')) {\n frames.push(frame as InputStackFrame);\n }\n }\n\n try {\n logger.debug({ msg: 'Processing frames', frames });\n\n const processedFrames: StackFrame[] = [];\n for (const frame of frames) {\n if (!this.sourceMapConsumerCache[frame.file]) {\n logger.debug({\n msg: 'Loading raw source map data',\n fileUrl: frame.file,\n });\n\n const rawSourceMap = await this.delegate.getSourceMap(frame.file);\n\n logger.debug({\n msg: 'Creating source map instance',\n fileUrl: frame.file,\n sourceMapLength: rawSourceMap.length,\n });\n const sourceMapConsumer = await new SourceMapConsumer(\n rawSourceMap.toString()\n );\n\n logger.debug({\n msg: 'Saving source map instance into cache',\n fileUrl: frame.file,\n });\n this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;\n }\n\n logger.debug({\n msg: 'Symbolicating frame',\n frame,\n });\n const processedFrame = this.processFrame(frame);\n\n logger.debug({\n msg: 'Finished symbolicating frame',\n frame,\n });\n processedFrames.push(processedFrame);\n }\n\n const codeFrame =\n (await this.getCodeFrame(logger, processedFrames)) ?? null;\n\n logger.debug({\n msg: 'Finished symbolicating frames',\n processedFrames,\n codeFrame,\n });\n\n return {\n stack: processedFrames,\n codeFrame,\n };\n } finally {\n for (const key in this.sourceMapConsumerCache) {\n this.sourceMapConsumerCache[key].destroy();\n delete this.sourceMapConsumerCache[key];\n }\n }\n }\n\n private processFrame(frame: InputStackFrame): StackFrame {\n if (!frame.lineNumber || !frame.column) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const consumer = this.sourceMapConsumerCache[frame.file];\n if (!consumer) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const lookup = consumer.originalPositionFor({\n line: frame.lineNumber,\n column: frame.column,\n });\n\n // If lookup fails, we get the same shape object, but with\n // all values set to null\n if (!lookup.source) {\n // It is better to gracefully return the original frame\n // than to throw an exception\n return {\n ...frame,\n collapse: false,\n };\n }\n\n return {\n lineNumber: lookup.line || frame.lineNumber,\n column: lookup.column || frame.column,\n file: lookup.source,\n methodName: lookup.name || frame.methodName,\n collapse: false,\n };\n }\n\n private async getCodeFrame(\n logger: FastifyLoggerInstance,\n processedFrames: StackFrame[]\n ): Promise<CodeFrame | undefined> {\n for (const frame of processedFrames) {\n if (frame.collapse || !frame.lineNumber || !frame.column) {\n continue;\n }\n\n if (!this.delegate.shouldIncludeFrame(frame)) {\n return undefined;\n }\n\n logger.debug({\n msg: 'Generating code frame',\n frame,\n });\n\n try {\n return {\n content: codeFrameColumns(\n (await this.delegate.getSource(frame.file)).toString(),\n {\n start: { column: frame.column, line: frame.lineNumber },\n },\n { forceColor: true }\n ),\n location: {\n row: frame.lineNumber,\n column: frame.column,\n },\n fileName: frame.file,\n };\n } catch (error) {\n logger.error({\n msg: 'Failed to create code frame',\n error: (error as Error).message,\n });\n }\n\n return undefined;\n }\n }\n}\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,KAAK;AACzB,SAASC,gBAAgB,QAAQ,mBAAmB;AACpD,SAASC,iBAAiB,QAAQ,YAAY;AAW9C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,CAAC;EACxB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,sBAAsBA,CAACC,KAA8B,EAAE;IAC5D,KAAK,MAAMC,KAAK,IAAID,KAAK,EAAE;MACzB,IAAI,CAACC,KAAK,CAACC,IAAI,EAAE;QACf;MACF;MAEA,MAAM;QAAEC,YAAY;QAAEC;MAAS,CAAC,GAAG,IAAIT,GAAG,CAACM,KAAK,CAACC,IAAI,EAAE,SAAS,CAAC;MACjE,MAAMG,QAAQ,GAAGF,YAAY,CAACG,GAAG,CAAC,UAAU,CAAC;MAC7C,IAAID,QAAQ,EAAE;QACZ,OAAOA,QAAQ;MACjB,CAAC,MAAM;QACL,MAAM,CAACE,cAAc,CAAC,GAAGH,QAAQ,CAACI,KAAK,CAAC,GAAG,CAAC,CAACC,OAAO,CAAC,CAAC;QACtD,MAAM,GAAGC,mBAAmB,EAAEC,SAAS,CAAC,GAAGJ,cAAc,CAACC,KAAK,CAAC,GAAG,CAAC;QACpE,IAAIG,SAAS,EAAE;UACb,OAAOD,mBAAmB;QAC5B;MACF;IACF;EACF;;EAEA;AACF;AACA;EACEE,sBAAsB,GAAsC,CAAC,CAAC;;EAE9D;AACF;AACA;AACA;AACA;EACEC,WAAWA,CAASC,QAA8B,EAAE;IAAA,KAAhCA,QAA8B,GAA9BA,QAA8B;EAAG;;EAErD;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAMC,OAAOA,CACXC,MAA6B,EAC7BhB,KAA8B,EACA;IAC9BgB,MA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AK,CAACoC,UAAU;YACrBC,MAAM,EAAErC,KAAK,CAACqC;UAChB,CAAC;UACDiB,QAAQ,EAAEtD,KAAK,CAACC;QAClB,CAAC;MACH,CAAC,CAAC,OAAOsD,KAAK,EAAE;QACdxC,MAAM,CAACwC,KAAK,CAAC;UACXtC,GAAG,EAAE,6BAA6B;UAClCsC,KAAK,EAAGA,KAAK,CAAWC;QAC1B,CAAC,CAAC;MACJ;MAEA,OAAOT,SAAS;IAClB;EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"Symbolicator.js","names":["URL","codeFrameColumns","SourceMapConsumer","Symbolicator","inferPlatformFromStack","stack","frame","file","searchParams","pathname","platform","get","bundleFilename","split","reverse","platformOrExtension","extension","sourceMapConsumerCache","constructor","delegate","process","logger","debug","msg","frames","startsWith","includes","push","processedFrames","fileUrl","rawSourceMap","getSourceMap","sourceMapLength","length","sourceMapConsumer","toString","processedFrame","processFrame","codeFrame","getCodeFrame","key","destroy","lineNumber","column","collapse","consumer","lookup","originalPositionFor","line","bias","LEAST_UPPER_BOUND","source","methodName","name","shouldIncludeFrame","undefined","content","getSource","start","forceColor","location","row","fileName","error","message"],"sources":["../../../src/plugins/symbolicate/Symbolicator.ts"],"sourcesContent":["import { URL } from 'url';\nimport { codeFrameColumns } from '@babel/code-frame';\nimport { SourceMapConsumer } from 'source-map';\nimport type { FastifyLoggerInstance } from 'fastify';\nimport type {\n CodeFrame,\n InputStackFrame,\n ReactNativeStackFrame,\n StackFrame,\n SymbolicatorDelegate,\n SymbolicatorResults,\n} from './types';\n\n/**\n * Class for transforming stack traces from React Native application with using Source Map.\n * Raw stack frames produced by React Native, points to some location from the bundle\n * eg `index.bundle?platform=ios:567:1234`. By using Source Map for that bundle `Symbolicator`\n * produces frames that point to source code inside your project eg `Hello.tsx:10:9`.\n */\nexport class Symbolicator {\n /**\n * Infer platform from stack frames.\n * Usually at least one frame has `file` field with the bundle URL eg:\n * `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.\n *\n * @param stack Array of stack frames.\n * @returns Inferred platform or `undefined` if cannot infer.\n */\n static inferPlatformFromStack(stack: ReactNativeStackFrame[]) {\n for (const frame of stack) {\n if (!frame.file) {\n continue;\n }\n\n const { searchParams, pathname } = new URL(frame.file, 'file://');\n const platform = searchParams.get('platform');\n if (platform) {\n return platform;\n } else {\n const [bundleFilename] = pathname.split('/').reverse();\n const [, platformOrExtension, extension] = bundleFilename.split('.');\n if (extension) {\n return platformOrExtension;\n }\n }\n }\n }\n\n /**\n * Cache with initialized `SourceMapConsumer` to improve symbolication performance.\n */\n sourceMapConsumerCache: Record<string, SourceMapConsumer> = {};\n\n /**\n * Constructs new `Symbolicator` instance.\n *\n * @param delegate Delegate instance with symbolication functions.\n */\n constructor(private delegate: SymbolicatorDelegate) {}\n\n /**\n * Process raw React Native stack frames and transform them using Source Maps.\n * Method will try to symbolicate as much data as possible, but if the Source Maps\n * are not available, invalid or the original positions/data is not found in Source Maps,\n * the method will return raw values - the same as supplied with `stack` parameter.\n * For example out of 10 frames, it's possible that only first 7 will be symbolicated and the\n * remaining 3 will be unchanged.\n *\n * @param logger Fastify logger instance.\n * @param stack Raw stack frames.\n * @returns Symbolicated stack frames.\n */\n async process(\n logger: FastifyLoggerInstance,\n stack: ReactNativeStackFrame[]\n ): Promise<SymbolicatorResults> {\n logger.debug({ msg: 'Filtering out unnecessary frames' });\n\n const frames: InputStackFrame[] = [];\n for (const frame of stack) {\n const { file } = frame;\n if (file?.startsWith('http') && !file.includes('debuggerWorker')) {\n frames.push(frame as InputStackFrame);\n }\n }\n\n try {\n logger.debug({ msg: 'Processing frames', frames });\n\n const processedFrames: StackFrame[] = [];\n for (const frame of frames) {\n if (!this.sourceMapConsumerCache[frame.file]) {\n logger.debug({\n msg: 'Loading raw source map data',\n fileUrl: frame.file,\n });\n\n const rawSourceMap = await this.delegate.getSourceMap(frame.file);\n\n logger.debug({\n msg: 'Creating source map instance',\n fileUrl: frame.file,\n sourceMapLength: rawSourceMap.length,\n });\n const sourceMapConsumer = await new SourceMapConsumer(\n rawSourceMap.toString()\n );\n\n logger.debug({\n msg: 'Saving source map instance into cache',\n fileUrl: frame.file,\n });\n this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;\n }\n\n logger.debug({\n msg: 'Symbolicating frame',\n frame,\n });\n const processedFrame = this.processFrame(frame);\n\n logger.debug({\n msg: 'Finished symbolicating frame',\n frame,\n });\n processedFrames.push(processedFrame);\n }\n\n const codeFrame =\n (await this.getCodeFrame(logger, processedFrames)) ?? null;\n\n logger.debug({\n msg: 'Finished symbolicating frames',\n processedFrames,\n codeFrame,\n });\n\n return {\n stack: processedFrames,\n codeFrame,\n };\n } finally {\n for (const key in this.sourceMapConsumerCache) {\n this.sourceMapConsumerCache[key].destroy();\n delete this.sourceMapConsumerCache[key];\n }\n }\n }\n\n private processFrame(frame: InputStackFrame): StackFrame {\n if (!frame.lineNumber || !frame.column) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const consumer = this.sourceMapConsumerCache[frame.file];\n if (!consumer) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const lookup = consumer.originalPositionFor({\n line: frame.lineNumber,\n column: frame.column,\n bias: SourceMapConsumer.LEAST_UPPER_BOUND,\n });\n\n // If lookup fails, we get the same shape object, but with\n // all values set to null\n if (!lookup.source) {\n // It is better to gracefully return the original frame\n // than to throw an exception\n return {\n ...frame,\n collapse: false,\n };\n }\n\n return {\n lineNumber: lookup.line || frame.lineNumber,\n column: lookup.column || frame.column,\n file: lookup.source,\n methodName: lookup.name || frame.methodName,\n collapse: false,\n };\n }\n\n private async getCodeFrame(\n logger: FastifyLoggerInstance,\n processedFrames: StackFrame[]\n ): Promise<CodeFrame | undefined> {\n for (const frame of processedFrames) {\n if (frame.collapse || !frame.lineNumber || !frame.column) {\n continue;\n }\n\n if (!this.delegate.shouldIncludeFrame(frame)) {\n return undefined;\n }\n\n logger.debug({\n msg: 'Generating code frame',\n frame,\n });\n\n try {\n return {\n content: codeFrameColumns(\n (await this.delegate.getSource(frame.file)).toString(),\n {\n start: { column: frame.column, line: frame.lineNumber },\n },\n { forceColor: true }\n ),\n location: {\n row: frame.lineNumber,\n column: frame.column,\n },\n fileName: frame.file,\n };\n } catch (error) {\n logger.error({\n msg: 'Failed to create code frame',\n error: (error as Error).message,\n });\n }\n\n return undefined;\n }\n }\n}\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,KAAK;AACzB,SAASC,gBAAgB,QAAQ,mBAAmB;AACpD,SAASC,iBAAiB,QAAQ,YAAY;AAW9C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,CAAC;EACxB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,sBAAsBA,CAACC,KAA8B,EAAE;IAC5D,KAAK,MAAMC,KAAK,IAAID,KAAK,EAAE;MACzB,IAAI,CAACC,KAAK,CAACC,IAAI,EAAE;QACf;MACF;MAEA,MAAM;QAAEC,YAAY;QAAEC;MAAS,CAAC,GAAG,IAAIT,GAAG,CAACM,KAAK,CAACC,IAAI,EAAE,SAAS,CAAC;MACjE,MAAMG,QAAQ,GAAGF,YAAY,CAACG,GAAG,CAAC,UAAU,CAAC;MAC7C,IAAID,QAAQ,EAAE;QACZ,OAAOA,QAAQ;MACjB,CAAC,MAAM;QACL,MAAM,CAACE,cAAc,CAAC,GAAGH,QAAQ,CAACI,KAAK,CAAC,GAAG,CAAC,CAACC,OAAO,CAAC,CAAC;QACtD,MAAM,GAAGC,mBAAmB,EAAEC,SAAS,CAAC,GAAGJ,cAAc,CAACC,KAAK,CAAC,GAAG,CAAC;QACpE,IAAIG,SAAS,EAAE;UACb,OAAOD,mBAAmB;QAC5B;MACF;IACF;EACF;;EAEA;AACF;AACA;EACEE,sBAAsB,GAAsC,CAAC,CAAC;;EAE9D;AACF;AACA;AACA;AACA;EACEC,WAAWA,CAASC,QAA8B,EAAE;IAAA,KAAhCA,QAA8B,GAA9BA,QAA8B;EAAG;;EAErD;AACF;AACA;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AAK,CAACqC,MAAM;cAAEK,IAAI,EAAE1C,KAAK,CAACoC;YAAW;UACxD,CAAC,EACD;YAAEiB,UAAU,EAAE;UAAK,CACrB,CAAC;UACDC,QAAQ,EAAE;YACRC,GAAG,EAAEvD,KAAK,CAACoC,UAAU;YACrBC,MAAM,EAAErC,KAAK,CAACqC;UAChB,CAAC;UACDmB,QAAQ,EAAExD,KAAK,CAACC;QAClB,CAAC;MACH,CAAC,CAAC,OAAOwD,KAAK,EAAE;QACd1C,MAAM,CAAC0C,KAAK,CAAC;UACXxC,GAAG,EAAE,6BAA6B;UAClCwC,KAAK,EAAGA,KAAK,CAAWC;QAC1B,CAAC,CAAC;MACJ;MAEA,OAAOT,SAAS;IAClB;EACF;AACF"}
|
|
@@ -43,13 +43,13 @@ export class WebSocketApiServer extends WebSocketServer {
|
|
|
43
43
|
onConnection(socket) {
|
|
44
44
|
const clientId = `client#${this.nextClientId++}`;
|
|
45
45
|
this.clients.set(clientId, socket);
|
|
46
|
-
this.fastify.log.
|
|
46
|
+
this.fastify.log.debug({
|
|
47
47
|
msg: 'API client connected',
|
|
48
48
|
clientId
|
|
49
49
|
});
|
|
50
50
|
this.clients.set(clientId, socket);
|
|
51
51
|
const onClose = () => {
|
|
52
|
-
this.fastify.log.
|
|
52
|
+
this.fastify.log.debug({
|
|
53
53
|
msg: 'API client disconnected',
|
|
54
54
|
clientId
|
|
55
55
|
});
|
|
@@ -1 +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","
|
|
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","debug","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.debug({ msg: 'API client connected', clientId });\n this.clients.set(clientId, socket);\n\n const onClose = () => {\n this.fastify.log.debug({\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,eAAe;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,SAASD,eAAe,CAAC;EAC9CE,OAAO,GAAG,IAAIC,GAAG,CAAoB,CAAC;EACtCC,YAAY,GAAG,CAAC;;EAExB;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,OAAwB,EAAE;IACpC,KAAK,CAACA,OAAO,EAAE,MAAM,CAAC;EACxB;;EAEA;AACF;AACA;AACA;AACA;EACEC,IAAIA,CAACC,KAAU,EAAE;IACf,MAAMC,IAAI,GAAG,OAAOD,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAGE,IAAI,CAACC,SAAS,CAACH,KAAK,CAAC;IAEtE,KAAK,MAAM,GAAGI,MAAM,CAAC,IAAI,IAAI,CAACV,OAAO,CAACW,OAAO,CAAC,CAAC,EAAE;MAC/C,IAAI;QACFD,MAAM,CAACL,IAAI,CAACE,IAAI,CAAC;MACnB,CAAC,CAAC,MAAM;QACN;MAAA;IAEJ;EACF;;EAEA;AACF;AACA;AACA;AACA;EACEK,YAAYA,CAACF,MAAiB,EAAE;IAC9B,MAAMG,QAAQ,GAAI,UAAS,IAAI,CAACX,YAAY,EAAG,EAAC;IAChD,IAAI,CAACF,OAAO,CAACc,GAAG,CAACD,QAAQ,EAAEH,MAAM,CAAC;IAElC,IAAI,CAACN,OAAO,CAACW,GAAG,CAACC,KAAK,CAAC;MAAEC,GAAG,EAAE,sBAAsB;MAAEJ;IAAS,CAAC,CAAC;IACjE,IAAI,CAACb,OAAO,CAACc,GAAG,CAACD,QAAQ,EAAEH,MAAM,CAAC;IAElC,MAAMQ,OAAO,GAAGA,CAAA,KAAM;MACpB,IAAI,CAACd,OAAO,CAACW,GAAG,CAACC,KAAK,CAAC;QACrBC,GAAG,EAAE,yBAAyB;QAC9BJ;MACF,CAAC,CAAC;MACF,IAAI,CAACb,OAAO,CAACmB,MAAM,CAACN,QAAQ,CAAC;IAC/B,CAAC;IAEDH,MAAM,CAACU,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCR,MAAM,CAACU,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;EAC3C;AACF"}
|
|
@@ -41,11 +41,17 @@ export class WebSocketDevClientServer extends WebSocketServer {
|
|
|
41
41
|
issuer: 'Console',
|
|
42
42
|
msg: body.data
|
|
43
43
|
});
|
|
44
|
-
} else {
|
|
44
|
+
} else if (body.level === 'info' || body.level === 'log') {
|
|
45
45
|
this.fastify.log.info({
|
|
46
46
|
issuer: 'Console',
|
|
47
47
|
msg: body.data
|
|
48
48
|
});
|
|
49
|
+
} else {
|
|
50
|
+
// body.level === 'debug' || body.level === 'trace'
|
|
51
|
+
this.fastify.log.debug({
|
|
52
|
+
issuer: 'Console',
|
|
53
|
+
msg: body.data
|
|
54
|
+
});
|
|
49
55
|
}
|
|
50
56
|
break;
|
|
51
57
|
default:
|
|
@@ -64,13 +70,12 @@ export class WebSocketDevClientServer extends WebSocketServer {
|
|
|
64
70
|
onConnection(socket) {
|
|
65
71
|
const clientId = `client#${this.nextClientId++}`;
|
|
66
72
|
this.clients.set(clientId, socket);
|
|
67
|
-
this.fastify.log.
|
|
73
|
+
this.fastify.log.debug({
|
|
68
74
|
msg: 'React Native client connected',
|
|
69
75
|
clientId
|
|
70
76
|
});
|
|
71
|
-
this.clients.set(clientId, socket);
|
|
72
77
|
const onClose = () => {
|
|
73
|
-
this.fastify.log.
|
|
78
|
+
this.fastify.log.debug({
|
|
74
79
|
msg: 'React Native client disconnected',
|
|
75
80
|
clientId
|
|
76
81
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketDevClientServer.js","names":["WebSocketServer","WebSocketDevClientServer","clients","Map","nextClientId","constructor","fastify","processMessage","message","type","body","JSON","parse","level","log","error","issuer","msg","data","warn","info","onConnection","socket","clientId","set","onClose","delete","addEventListener","event","toString"],"sources":["../../../../src/plugins/wss/servers/WebSocketDevClientServer.ts"],"sourcesContent":["import WebSocket from 'ws';\nimport type { FastifyInstance } from 'fastify';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for communication with React Native clients.\n * All client logs - logs from React Native application - are processed here.\n *\n * @category Development server\n */\nexport class WebSocketDevClientServer extends WebSocketServer {\n private clients = new Map<string, WebSocket>();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketDevClientServer 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, '/__client');\n }\n\n /**\n * Process client message.\n *\n * @param message Stringified client message.\n */\n processMessage(message: string) {\n const { type, ...body } = JSON.parse(message);\n switch (type) {\n case 'client-log':\n if (body.level === 'error') {\n this.fastify.log.error({ issuer: 'Console', msg: body.data });\n } else if (body.level === 'warn') {\n this.fastify.log.warn({ issuer: 'Console', msg: body.data });\n } else {\n this.fastify.log.info({ issuer: 'Console', msg: body.data });\n }\n break;\n default:\n this.fastify.log.warn({ msg: 'Unknown client message', message });\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
|
|
1
|
+
{"version":3,"file":"WebSocketDevClientServer.js","names":["WebSocketServer","WebSocketDevClientServer","clients","Map","nextClientId","constructor","fastify","processMessage","message","type","body","JSON","parse","level","log","error","issuer","msg","data","warn","info","debug","onConnection","socket","clientId","set","onClose","delete","addEventListener","event","toString"],"sources":["../../../../src/plugins/wss/servers/WebSocketDevClientServer.ts"],"sourcesContent":["import WebSocket from 'ws';\nimport type { FastifyInstance } from 'fastify';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for communication with React Native clients.\n * All client logs - logs from React Native application - are processed here.\n *\n * @category Development server\n */\nexport class WebSocketDevClientServer extends WebSocketServer {\n private clients = new Map<string, WebSocket>();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketDevClientServer 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, '/__client');\n }\n\n /**\n * Process client message.\n *\n * @param message Stringified client message.\n */\n processMessage(message: string) {\n const { type, ...body } = JSON.parse(message);\n switch (type) {\n case 'client-log':\n if (body.level === 'error') {\n this.fastify.log.error({ issuer: 'Console', msg: body.data });\n } else if (body.level === 'warn') {\n this.fastify.log.warn({ issuer: 'Console', msg: body.data });\n } else if (body.level === 'info' || body.level === 'log') {\n this.fastify.log.info({ issuer: 'Console', msg: body.data });\n } else {\n // body.level === 'debug' || body.level === 'trace'\n this.fastify.log.debug({ issuer: 'Console', msg: body.data });\n }\n break;\n default:\n this.fastify.log.warn({ msg: 'Unknown client message', message });\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 this.fastify.log.debug({ msg: 'React Native client connected', clientId });\n\n const onClose = () => {\n this.fastify.log.debug({\n msg: 'React Native client disconnected',\n clientId,\n });\n this.clients.delete(clientId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n socket.addEventListener('message', (event) => {\n this.processMessage(event.data.toString());\n });\n }\n}\n"],"mappings":"SAESA,eAAe;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,wBAAwB,SAASD,eAAe,CAAC;EACpDE,OAAO,GAAG,IAAIC,GAAG,CAAoB,CAAC;EACtCC,YAAY,GAAG,CAAC;;EAExB;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,OAAwB,EAAE;IACpC,KAAK,CAACA,OAAO,EAAE,WAAW,CAAC;EAC7B;;EAEA;AACF;AACA;AACA;AACA;EACEC,cAAcA,CAACC,OAAe,EAAE;IAC9B,MAAM;MAAEC,IAAI;MAAE,GAAGC;IAAK,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACJ,OAAO,CAAC;IAC7C,QAAQC,IAAI;MACV,KAAK,YAAY;QACf,IAAIC,IAAI,CAACG,KAAK,KAAK,OAAO,EAAE;UAC1B,IAAI,CAACP,OAAO,CAACQ,GAAG,CAACC,KAAK,CAAC;YAAEC,MAAM,EAAE,SAAS;YAAEC,GAAG,EAAEP,IAAI,CAACQ;UAAK,CAAC,CAAC;QAC/D,CAAC,MAAM,IAAIR,IAAI,CAACG,KAAK,KAAK,MAAM,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OAAO,CAAC;IACzCH,MAAM,CAACK,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCH,MAAM,CAACK,gBAAgB,CAAC,SAAS,EAAGC,KAAK,IAAK;MAC5C,IAAI,CAACtB,cAAc,CAACsB,KAAK,CAACX,IAAI,CAACY,QAAQ,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAC;EACJ;AACF"}
|
|
@@ -58,7 +58,7 @@ export class WebSocketHMRServer extends WebSocketServer {
|
|
|
58
58
|
} = new URL(request.url || '', 'http://localhost');
|
|
59
59
|
const platform = searchParams.get('platform');
|
|
60
60
|
if (!platform) {
|
|
61
|
-
this.fastify.log.
|
|
61
|
+
this.fastify.log.debug({
|
|
62
62
|
msg: 'HMR connection disconnected - missing platform'
|
|
63
63
|
});
|
|
64
64
|
socket.close();
|
|
@@ -70,12 +70,12 @@ export class WebSocketHMRServer extends WebSocketServer {
|
|
|
70
70
|
platform
|
|
71
71
|
};
|
|
72
72
|
this.clients.set(client, socket);
|
|
73
|
-
this.fastify.log.
|
|
73
|
+
this.fastify.log.debug({
|
|
74
74
|
msg: 'HMR client connected',
|
|
75
75
|
...client
|
|
76
76
|
});
|
|
77
77
|
const onClose = () => {
|
|
78
|
-
this.fastify.log.
|
|
78
|
+
this.fastify.log.debug({
|
|
79
79
|
msg: 'HMR client disconnected',
|
|
80
80
|
...client
|
|
81
81
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketHMRServer.js","names":["URL","WebSocketServer","WebSocketHMRServer","clients","Map","nextClientId","constructor","fastify","delegate","getUriPath","send","event","platform","clientIds","data","JSON","stringify","key","socket","clientId","includes","error","log","msg","onConnection","request","searchParams","url","get","
|
|
1
|
+
{"version":3,"file":"WebSocketHMRServer.js","names":["URL","WebSocketServer","WebSocketHMRServer","clients","Map","nextClientId","constructor","fastify","delegate","getUriPath","send","event","platform","clientIds","data","JSON","stringify","key","socket","clientId","includes","error","log","msg","onConnection","request","searchParams","url","get","debug","close","client","set","onClose","delete","addEventListener","onClientConnected"],"sources":["../../../../src/plugins/wss/servers/WebSocketHMRServer.ts"],"sourcesContent":["import { URL } from 'url';\nimport { IncomingMessage } from 'http';\nimport { FastifyInstance } from 'fastify';\nimport WebSocket from 'ws';\nimport { HmrDelegate } from '../types';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for Hot Module Replacement.\n *\n * @category Development server\n */\nexport class WebSocketHMRServer extends WebSocketServer {\n private clients = new Map<\n { clientId: string; platform: string },\n WebSocket\n >();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketHMRServer 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 delegate HMR delegate instance.\n */\n constructor(\n fastify: FastifyInstance,\n private delegate: HmrDelegate\n ) {\n super(fastify, delegate.getUriPath());\n }\n\n /**\n * Send action to all connected HMR clients.\n *\n * @param event Event to send to the clients.\n * @param platform Platform of clients to send the event to.\n * @param clientIds Ids of clients who should receive the event.\n */\n send(event: any, platform: string, clientIds?: string[]) {\n const data = typeof event === 'string' ? event : JSON.stringify(event);\n\n for (const [key, socket] of this.clients) {\n if (\n key.platform !== platform ||\n !(clientIds ?? [key.clientId]).includes(key.clientId)\n ) {\n continue;\n }\n\n try {\n socket.send(data);\n } catch (error) {\n this.fastify.log.error({\n msg: 'Cannot send action to client',\n event,\n error,\n ...key,\n });\n }\n }\n }\n\n /**\n * Process new WebSocket connection from HMR client.\n *\n * @param socket Incoming HMR client's WebSocket connection.\n */\n onConnection(socket: WebSocket, request: IncomingMessage) {\n const { searchParams } = new URL(request.url || '', 'http://localhost');\n const platform = searchParams.get('platform');\n\n if (!platform) {\n this.fastify.log.debug({\n msg: 'HMR connection disconnected - missing platform',\n });\n socket.close();\n return;\n }\n\n const clientId = `client#${this.nextClientId++}`;\n\n const client = {\n clientId,\n platform,\n };\n\n this.clients.set(client, socket);\n\n this.fastify.log.debug({ msg: 'HMR client connected', ...client });\n\n const onClose = () => {\n this.fastify.log.debug({\n msg: 'HMR client disconnected',\n ...client,\n });\n this.clients.delete(client);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n\n this.delegate.onClientConnected(platform, clientId);\n }\n}\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,KAAK;AAAC,SAKjBC,eAAe;AAExB;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,SAASD,eAAe,CAAC;EAC9CE,OAAO,GAAG,IAAIC,GAAG,CAGvB,CAAC;EACKC,YAAY,GAAG,CAAC;;EAExB;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,WAAWA,CACTC,OAAwB,EAChBC,QAAqB,EAC7B;IACA,KAAK,CAACD,OAAO,EAAEC,QAAQ,CAACC,UAAU,CAAC,CAAC,CAAC;IAAC,KAF9BD,QAAqB,GAArBA,QAAqB;EAG/B;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEE,IAAIA,CAACC,KAAU,EAAEC,QAAgB,EAAEC,SAAoB,EAAE;IACvD,MAAMC,IAAI,GAAG,OAAOH,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAGI,IAAI,CAACC,SAAS,CAACL,KAAK,CAAC;IAEtE,KAAK,MAAM,CAACM,GAAG,EAAEC,MAAM,CAAC,IAAI,IAAI,CAACf,OAAO,EAAE;MACxC,IACEc,GAAG,CAACL,QAAQ,KAAKA,QAAQ,IACzB,CAAC,CAACC,SAAS,IAAI,CAACI,GAAG,CAACE,QAAQ,CAAC,EAAEC,QAAQ,CAACH,GAAG,CAACE,QAAQ,CAAC,EACrD;QACA;MACF;MAEA,IAAI;QACFD,MAAM,CAACR,IAAI,CAACI,IAAI,CAAC;MACnB,CAAC,CAAC,OAAOO,KAAK,EAAE;QACd,IAAI,CAACd,OAAO,CAACe,GAAG,CAACD,KAAK,CAAC;UACrBE,GAAG,EAAE,8BAA8B;UACnCZ,KAAK;UACLU,KAA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
@@ -13,7 +13,7 @@ export declare namespace Server {
|
|
|
13
13
|
options: Options;
|
|
14
14
|
experiments?: Experiments;
|
|
15
15
|
/** Function to create a delegate, which implements crucial functionalities. */
|
|
16
|
-
delegate: (context: DelegateContext) => Delegate
|
|
16
|
+
delegate: (context: DelegateContext) => Promise<Delegate>;
|
|
17
17
|
}
|
|
18
18
|
interface Experiments {
|
|
19
19
|
experimentalDebugger?: boolean;
|
|
@@ -38,6 +38,8 @@ export declare namespace Server {
|
|
|
38
38
|
};
|
|
39
39
|
/** Additional endpoints with pre-configured servers */
|
|
40
40
|
endpoints?: Record<string, WebSocketServer>;
|
|
41
|
+
/** Whether to enable logging requests. */
|
|
42
|
+
logRequests?: boolean;
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
43
45
|
* A complete delegate with implementations for all server functionalities.
|
|
@@ -137,20 +139,6 @@ export declare namespace Server {
|
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
141
|
}
|
|
140
|
-
/** Representation of the compilation progress. */
|
|
141
|
-
export interface ProgressData {
|
|
142
|
-
/** Number of modules built. */
|
|
143
|
-
completed: number;
|
|
144
|
-
/** Total number of modules detect as part of compilation. */
|
|
145
|
-
total: number;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Type representing a function to send the progress.
|
|
149
|
-
*
|
|
150
|
-
* Used by {@link CompilerDelegate} in `getAsset` function to send the compilation
|
|
151
|
-
* progress to the client who requested the asset.
|
|
152
|
-
*/
|
|
153
|
-
export type SendProgress = (data: ProgressData) => void;
|
|
154
142
|
/**
|
|
155
143
|
* Internal types. Do not use.
|
|
156
144
|
*
|
package/dist/types.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
export let Server;
|
|
2
|
-
/** Representation of the compilation progress. */
|
|
3
|
-
/**
|
|
4
|
-
* Type representing a function to send the progress.
|
|
5
|
-
*
|
|
6
|
-
* Used by {@link CompilerDelegate} in `getAsset` function to send the compilation
|
|
7
|
-
* progress to the client who requested the asset.
|
|
8
|
-
*/
|
|
9
2
|
/**
|
|
10
3
|
* Internal types. Do not use.
|
|
11
4
|
*
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["Server","Internal","_Internal","EventTypes"],"sources":["../src/types.ts"],"sourcesContent":["import type { FastifyBaseLogger } from 'fastify';\nimport type { WebSocketServer } from 'ws';\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 experiments?: Experiments;\n\n /** Function to create a delegate, which implements crucial functionalities. */\n delegate: (context: DelegateContext) => Delegate
|
|
1
|
+
{"version":3,"file":"types.js","names":["Server","Internal","_Internal","EventTypes"],"sources":["../src/types.ts"],"sourcesContent":["import type { FastifyBaseLogger } from 'fastify';\nimport type { WebSocketServer } from 'ws';\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 experiments?: Experiments;\n\n /** Function to create a delegate, which implements crucial functionalities. */\n delegate: (context: DelegateContext) => Promise<Delegate>;\n }\n\n export interface Experiments {\n experimentalDebugger?: boolean;\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 /** Additional endpoints with pre-configured servers */\n endpoints?: Record<string, WebSocketServer>;\n\n /** Whether to enable logging requests. */\n logRequests?: boolean;\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: FastifyBaseLogger;\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/**\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":"WAiBiBA,MAAM;AA0KvB;AACA;AACA;AACA;AACA;AAJA,WAKiBC,QAAQ;AAAA,WAAAC,SAAA;EAAA,IACXC,UAAU,0BAAVA,UAAU;IAAVA,UAAU;IAAVA,UAAU;IAAVA,UAAU;IAAA,OAAVA,UAAU;EAAA;EAAAD,SAAA,CAAAC,UAAA,GAAAA,UAAA;AAAA,GADPF,QAAQ,KAARA,QAAQ"}
|
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": "
|
|
5
|
+
"version": "5.0.0-next.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|