@callstack/repack-dev-server 0.0.0-canary-20240602190113
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 +140 -0
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/createServer.d.ts +13 -0
- package/dist/createServer.js +147 -0
- package/dist/createServer.js.map +1 -0
- package/dist/img/favicon.ico +0 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/api/apiPlugin.d.ts +6 -0
- package/dist/plugins/api/apiPlugin.js +32 -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/compiler/compilerPlugin.d.ts +7 -0
- package/dist/plugins/compiler/compilerPlugin.js +75 -0
- package/dist/plugins/compiler/compilerPlugin.js.map +1 -0
- package/dist/plugins/compiler/index.d.ts +2 -0
- package/dist/plugins/compiler/index.js +3 -0
- package/dist/plugins/compiler/index.js.map +1 -0
- package/dist/plugins/compiler/types.d.ts +31 -0
- package/dist/plugins/compiler/types.js +2 -0
- package/dist/plugins/compiler/types.js.map +1 -0
- package/dist/plugins/devtools/devtoolsPlugin.d.ts +7 -0
- package/dist/plugins/devtools/devtoolsPlugin.js +47 -0
- package/dist/plugins/devtools/devtoolsPlugin.js.map +1 -0
- package/dist/plugins/devtools/index.d.ts +1 -0
- package/dist/plugins/devtools/index.js +2 -0
- package/dist/plugins/devtools/index.js.map +1 -0
- package/dist/plugins/favicon/faviconPlugin.d.ts +4 -0
- package/dist/plugins/favicon/faviconPlugin.js +17 -0
- package/dist/plugins/favicon/faviconPlugin.js.map +1 -0
- package/dist/plugins/favicon/index.d.ts +1 -0
- package/dist/plugins/favicon/index.js +2 -0
- package/dist/plugins/favicon/index.js.map +1 -0
- package/dist/plugins/multipart/index.d.ts +2 -0
- package/dist/plugins/multipart/index.js +3 -0
- package/dist/plugins/multipart/index.js.map +1 -0
- package/dist/plugins/multipart/multipartPlugin.d.ts +4 -0
- package/dist/plugins/multipart/multipartPlugin.js +55 -0
- package/dist/plugins/multipart/multipartPlugin.js.map +1 -0
- package/dist/plugins/multipart/types.d.ts +12 -0
- package/dist/plugins/multipart/types.js +2 -0
- package/dist/plugins/multipart/types.js.map +1 -0
- package/dist/plugins/symbolicate/Symbolicator.d.ts +46 -0
- package/dist/plugins/symbolicate/Symbolicator.js +208 -0
- package/dist/plugins/symbolicate/Symbolicator.js.map +1 -0
- package/dist/plugins/symbolicate/index.d.ts +3 -0
- package/dist/plugins/symbolicate/index.js +4 -0
- package/dist/plugins/symbolicate/index.js.map +1 -0
- package/dist/plugins/symbolicate/sybmolicatePlugin.d.ts +7 -0
- package/dist/plugins/symbolicate/sybmolicatePlugin.js +44 -0
- package/dist/plugins/symbolicate/sybmolicatePlugin.js.map +1 -0
- package/dist/plugins/symbolicate/types.d.ts +65 -0
- package/dist/plugins/symbolicate/types.js +2 -0
- package/dist/plugins/symbolicate/types.js.map +1 -0
- package/dist/plugins/wss/WebSocketRouter.d.ts +32 -0
- package/dist/plugins/wss/WebSocketRouter.js +57 -0
- package/dist/plugins/wss/WebSocketRouter.js.map +1 -0
- package/dist/plugins/wss/WebSocketServer.d.ts +38 -0
- package/dist/plugins/wss/WebSocketServer.js +45 -0
- package/dist/plugins/wss/WebSocketServer.js.map +1 -0
- package/dist/plugins/wss/WebSocketServerAdapter.d.ts +16 -0
- package/dist/plugins/wss/WebSocketServerAdapter.js +22 -0
- package/dist/plugins/wss/WebSocketServerAdapter.js.map +1 -0
- package/dist/plugins/wss/index.d.ts +3 -0
- package/dist/plugins/wss/index.js +4 -0
- package/dist/plugins/wss/index.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketApiServer.d.ts +32 -0
- package/dist/plugins/wss/servers/WebSocketApiServer.js +62 -0
- package/dist/plugins/wss/servers/WebSocketApiServer.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.d.ts +64 -0
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js +142 -0
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketDevClientServer.d.ts +32 -0
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js +86 -0
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketEventsServer.d.ts +75 -0
- package/dist/plugins/wss/servers/WebSocketEventsServer.js +180 -0
- package/dist/plugins/wss/servers/WebSocketEventsServer.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketHMRServer.d.ts +38 -0
- package/dist/plugins/wss/servers/WebSocketHMRServer.js +89 -0
- package/dist/plugins/wss/servers/WebSocketHMRServer.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketMessageServer.d.ts +140 -0
- package/dist/plugins/wss/servers/WebSocketMessageServer.js +350 -0
- package/dist/plugins/wss/servers/WebSocketMessageServer.js.map +1 -0
- package/dist/plugins/wss/types.d.ts +25 -0
- package/dist/plugins/wss/types.js +2 -0
- package/dist/plugins/wss/types.js.map +1 -0
- package/dist/plugins/wss/wssPlugin.d.ts +31 -0
- package/dist/plugins/wss/wssPlugin.js +56 -0
- package/dist/plugins/wss/wssPlugin.js.map +1 -0
- package/dist/types.d.ts +165 -0
- package/dist/types.js +24 -0
- package/dist/types.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import open from 'open';
|
|
2
|
+
import fastifyPlugin from 'fastify-plugin';
|
|
3
|
+
async function devtoolsPlugin(instance, {
|
|
4
|
+
options
|
|
5
|
+
}) {
|
|
6
|
+
instance.route({
|
|
7
|
+
method: ['GET', 'POST', 'PUT'],
|
|
8
|
+
url: '/reload',
|
|
9
|
+
handler: (_request, reply) => {
|
|
10
|
+
instance.wss.messageServer.broadcast('reload');
|
|
11
|
+
reply.send('OK');
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
instance.route({
|
|
15
|
+
method: ['GET', 'POST', 'PUT'],
|
|
16
|
+
url: '/launch-js-devtools',
|
|
17
|
+
handler: async (request, reply) => {
|
|
18
|
+
const customDebugger = process.env.REACT_DEBUGGER;
|
|
19
|
+
if (customDebugger) {
|
|
20
|
+
// NOOP for now
|
|
21
|
+
} else if (!instance.wss.debuggerServer.isDebuggerConnected()) {
|
|
22
|
+
const url = `${options.https ? 'https' : 'http'}://${options.host || 'localhost'}:${options.port}/debugger-ui`;
|
|
23
|
+
try {
|
|
24
|
+
request.log.info({
|
|
25
|
+
msg: 'Opening debugger UI',
|
|
26
|
+
url
|
|
27
|
+
});
|
|
28
|
+
await open(url);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (error) {
|
|
31
|
+
request.log.error({
|
|
32
|
+
msg: 'Cannot open debugger UI',
|
|
33
|
+
url,
|
|
34
|
+
error
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
reply.send('OK');
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export default fastifyPlugin(devtoolsPlugin, {
|
|
44
|
+
name: 'devtools-plugin',
|
|
45
|
+
dependencies: ['wss-plugin']
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=devtoolsPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtoolsPlugin.js","names":["open","fastifyPlugin","devtoolsPlugin","instance","options","route","method","url","handler","_request","reply","wss","messageServer","broadcast","send","request","customDebugger","process","env","REACT_DEBUGGER","debuggerServer","isDebuggerConnected","https","host","port","log","info","msg","error","name","dependencies"],"sources":["../../../src/plugins/devtools/devtoolsPlugin.ts"],"sourcesContent":["import open from 'open';\nimport type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\n\nasync function devtoolsPlugin(\n instance: FastifyInstance,\n { options }: { options: Server.Options }\n) {\n instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/reload',\n handler: (_request, reply) => {\n instance.wss.messageServer.broadcast('reload');\n reply.send('OK');\n },\n });\n\n instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/launch-js-devtools',\n handler: async (request, reply) => {\n const customDebugger = process.env.REACT_DEBUGGER;\n if (customDebugger) {\n // NOOP for now\n } else if (!instance.wss.debuggerServer.isDebuggerConnected()) {\n const url = `${options.https ? 'https' : 'http'}://${\n options.host || 'localhost'\n }:${options.port}/debugger-ui`;\n try {\n request.log.info({ msg: 'Opening debugger UI', url });\n await open(url);\n } catch (error) {\n if (error) {\n request.log.error({\n msg: 'Cannot open debugger UI',\n url,\n error,\n });\n }\n }\n }\n reply.send('OK');\n },\n });\n}\n\nexport default fastifyPlugin(devtoolsPlugin, {\n name: 'devtools-plugin',\n dependencies: ['wss-plugin'],\n});\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AAEvB,OAAOC,aAAa,MAAM,gBAAgB;AAG1C,eAAeC,cAAcA,CAC3BC,QAAyB,EACzB;EAAEC;AAAqC,CAAC,EACxC;EACAD,QAAQ,CAACE,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;IAC9BC,GAAG,EAAE,SAAS;IACdC,OAAO,EAAEA,CAACC,QAAQ,EAAEC,KAAK,KAAK;MAC5BP,QAAQ,CAACQ,GAAG,CAACC,aAAa,CAACC,SAAS,CAAC,QAAQ,CAAC;MAC9CH,KAAK,CAACI,IAAI,CAAC,IAAI,CAAC;IAClB;EACF,CAAC,CAAC;EAEFX,QAAQ,CAACE,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;IAC9BC,GAAG,EAAE,qBAAqB;IAC1BC,OAAO,EAAE,MAAAA,CAAOO,OAAO,EAAEL,KAAK,KAAK;MACjC,MAAMM,cAAc,GAAGC,OAAO,CAACC,GAAG,CAACC,cAAc;MACjD,IAAIH,cAAc,EAAE;QAClB;MAAA,CACD,MAAM,IAAI,CAACb,QAAQ,CAACQ,GAAG,CAACS,cAAc,CAACC,mBAAmB,CAAC,CAAC,EAAE;QAC7D,MAAMd,GAAG,GAAI,GAAEH,OAAO,CAACkB,KAAK,GAAG,OAAO,GAAG,MAAO,MAC9ClB,OAAO,CAACmB,IAAI,IAAI,WACjB,IAAGnB,OAAO,CAACoB,IAAK,cAAa;QAC9B,IAAI;UACFT,OAAO,CAACU,GAAG,CAACC,IAAI,CAAC;YAAEC,GAAG,EAAE,qBAAqB;YAAEpB;UAAI,CAAC,CAAC;UACrD,MAAMP,IAAI,CAACO,GAAG,CAAC;QACjB,CAAC,CAAC,OAAOqB,KAAK,EAAE;UACd,IAAIA,KAAK,EAAE;YACTb,OAAO,CAACU,GAAG,CAACG,KAAK,CAAC;cAChBD,GAAG,EAAE,yBAAyB;cAC9BpB,GAAG;cACHqB;YACF,CAAC,CAAC;UACJ;QACF;MACF;MACAlB,KAAK,CAACI,IAAI,CAAC,IAAI,CAAC;IAClB;EACF,CAAC,CAAC;AACJ;AAEA,eAAeb,aAAa,CAACC,cAAc,EAAE;EAC3C2B,IAAI,EAAE,iBAAiB;EACvBC,YAAY,EAAE,CAAC,YAAY;AAC7B,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './devtoolsPlugin';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/devtools/index.ts"],"sourcesContent":["export { default } from './devtoolsPlugin';\n"],"mappings":"SAASA,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import fastifyFavicon from 'fastify-favicon';
|
|
4
|
+
import fastifyPlugin from 'fastify-plugin';
|
|
5
|
+
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const pathToImgDir = path.join(dirname, '../../img');
|
|
9
|
+
async function faviconPlugin(instance) {
|
|
10
|
+
instance.register(fastifyFavicon, {
|
|
11
|
+
path: pathToImgDir
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export default fastifyPlugin(faviconPlugin, {
|
|
15
|
+
name: 'favicon-plugin'
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=faviconPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faviconPlugin.js","names":["path","fileURLToPath","fastifyFavicon","fastifyPlugin","dirname","import","meta","url","pathToImgDir","join","faviconPlugin","instance","register","name"],"sources":["../../../src/plugins/favicon/faviconPlugin.ts"],"sourcesContent":["import path from 'path';\nimport { fileURLToPath } from 'url';\nimport fastifyFavicon from 'fastify-favicon';\nimport type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\n\n// @ts-ignore\nconst dirname = path.dirname(fileURLToPath(import.meta.url));\nconst pathToImgDir = path.join(dirname, '../../img');\n\nasync function faviconPlugin(instance: FastifyInstance) {\n instance.register(fastifyFavicon, { path: pathToImgDir });\n}\n\nexport default fastifyPlugin(faviconPlugin, {\n name: 'favicon-plugin',\n});\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,aAAa,QAAQ,KAAK;AACnC,OAAOC,cAAc,MAAM,iBAAiB;AAE5C,OAAOC,aAAa,MAAM,gBAAgB;;AAE1C;AACA,MAAMC,OAAO,GAAGJ,IAAI,CAACI,OAAO,CAACH,aAAa,CAACI,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAC5D,MAAMC,YAAY,GAAGR,IAAI,CAACS,IAAI,CAACL,OAAO,EAAE,WAAW,CAAC;AAEpD,eAAeM,aAAaA,CAACC,QAAyB,EAAE;EACtDA,QAAQ,CAACC,QAAQ,CAACV,cAAc,EAAE;IAAEF,IAAI,EAAEQ;EAAa,CAAC,CAAC;AAC3D;AAEA,eAAeL,aAAa,CAACO,aAAa,EAAE;EAC1CG,IAAI,EAAE;AACR,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './faviconPlugin';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/favicon/index.ts"],"sourcesContent":["export { default } from './faviconPlugin';\n"],"mappings":"SAASA,OAAO","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/multipart/index.ts"],"sourcesContent":["export { default } from './multipartPlugin';\nexport * from './types';\n"],"mappings":"SAASA,OAAO;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { PassThrough } from 'stream';
|
|
2
|
+
import fastifyPlugin from 'fastify-plugin';
|
|
3
|
+
/**
|
|
4
|
+
* Implementation is based on:
|
|
5
|
+
* https://github.com/facebook/metro/blob/347b1d7ed87995d7951aaa9fd597c04b06013dac/packages/metro/src/Server/MultipartResponse.js
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const CRLF = '\r\n';
|
|
9
|
+
const BOUNDARY = '3beqjf3apnqeu3h5jqorms4i';
|
|
10
|
+
async function multipartPlugin(instance) {
|
|
11
|
+
function asMultipart() {
|
|
12
|
+
// We should check if is included in accept or if accept has multipart/* or */*,
|
|
13
|
+
// but React Native will set accept to exactly `multipart/mixed`, so a simple check
|
|
14
|
+
// will suffice.
|
|
15
|
+
if (this.request.headers.accept !== 'multipart/mixed') {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const headers = {};
|
|
19
|
+
const stream = new PassThrough();
|
|
20
|
+
this.code(200).header('Content-Type', `multipart/mixed; boundary="${BOUNDARY}"`).send(stream);
|
|
21
|
+
function serializeHeaders(headers) {
|
|
22
|
+
return Object.keys(headers).map(key => `${key}: ${headers[key]}`).join(CRLF);
|
|
23
|
+
}
|
|
24
|
+
function writeChunk(headers, data, isLast) {
|
|
25
|
+
let chunk = `${CRLF}--${BOUNDARY}${CRLF}`;
|
|
26
|
+
if (headers) {
|
|
27
|
+
chunk += serializeHeaders(headers) + CRLF + CRLF;
|
|
28
|
+
}
|
|
29
|
+
if (data) {
|
|
30
|
+
chunk += data;
|
|
31
|
+
}
|
|
32
|
+
if (isLast) {
|
|
33
|
+
chunk += `${CRLF}--${BOUNDARY}--${CRLF}`;
|
|
34
|
+
}
|
|
35
|
+
stream.write(chunk);
|
|
36
|
+
}
|
|
37
|
+
function setHeader(name, value) {
|
|
38
|
+
headers[name] = value;
|
|
39
|
+
}
|
|
40
|
+
function end(data) {
|
|
41
|
+
writeChunk(headers, data, true);
|
|
42
|
+
stream.end();
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
writeChunk,
|
|
46
|
+
setHeader,
|
|
47
|
+
end
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
instance.decorateReply('asMultipart', asMultipart);
|
|
51
|
+
}
|
|
52
|
+
export default fastifyPlugin(multipartPlugin, {
|
|
53
|
+
name: 'multipart-plugin'
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=multipartPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipartPlugin.js","names":["PassThrough","fastifyPlugin","CRLF","BOUNDARY","multipartPlugin","instance","asMultipart","request","headers","accept","undefined","stream","code","header","send","serializeHeaders","Object","keys","map","key","join","writeChunk","data","isLast","chunk","write","setHeader","name","value","end","decorateReply"],"sources":["../../../src/plugins/multipart/multipartPlugin.ts"],"sourcesContent":["import type { IncomingHttpHeaders } from 'http';\nimport { PassThrough } from 'stream';\nimport type { FastifyInstance, FastifyReply } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { MultipartHandler } from './types';\n\n/**\n * Implementation is based on:\n * https://github.com/facebook/metro/blob/347b1d7ed87995d7951aaa9fd597c04b06013dac/packages/metro/src/Server/MultipartResponse.js\n */\n\nconst CRLF = '\\r\\n';\nconst BOUNDARY = '3beqjf3apnqeu3h5jqorms4i';\n\nasync function multipartPlugin(instance: FastifyInstance) {\n function asMultipart(this: FastifyReply): MultipartHandler | undefined {\n // We should check if is included in accept or if accept has multipart/* or */*,\n // but React Native will set accept to exactly `multipart/mixed`, so a simple check\n // will suffice.\n if (this.request.headers.accept !== 'multipart/mixed') {\n return undefined;\n }\n\n const headers: IncomingHttpHeaders = {};\n const stream = new PassThrough();\n\n this.code(200)\n .header('Content-Type', `multipart/mixed; boundary=\"${BOUNDARY}\"`)\n .send(stream);\n\n function serializeHeaders(headers: IncomingHttpHeaders) {\n return Object.keys(headers)\n .map((key) => `${key}: ${headers[key]}`)\n .join(CRLF);\n }\n\n function writeChunk<T>(\n headers: IncomingHttpHeaders,\n data: T,\n isLast?: boolean\n ) {\n let chunk = `${CRLF}--${BOUNDARY}${CRLF}`;\n if (headers) {\n chunk += serializeHeaders(headers) + CRLF + CRLF;\n }\n\n if (data) {\n chunk += data;\n }\n\n if (isLast) {\n chunk += `${CRLF}--${BOUNDARY}--${CRLF}`;\n }\n\n stream.write(chunk);\n }\n\n function setHeader(name: string, value: string | string[] | undefined) {\n headers[name] = value;\n }\n\n function end<T>(data: T) {\n writeChunk(headers, data, true);\n stream.end();\n }\n\n return {\n writeChunk,\n setHeader,\n end,\n };\n }\n\n instance.decorateReply('asMultipart', asMultipart);\n}\n\nexport default fastifyPlugin(multipartPlugin, {\n name: 'multipart-plugin',\n});\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,QAAQ;AAEpC,OAAOC,aAAa,MAAM,gBAAgB;AAG1C;AACA;AACA;AACA;;AAEA,MAAMC,IAAI,GAAG,MAAM;AACnB,MAAMC,QAAQ,GAAG,0BAA0B;AAE3C,eAAeC,eAAeA,CAACC,QAAyB,EAAE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MAC/BX,MAAM,CAACkB,GAAG,CAAC,CAAC;IACd;IAEA,OAAO;MACLR,UAAU;MACVK,SAAS;MACTG;IACF,CAAC;EACH;EAEAxB,QAAQ,CAACyB,aAAa,CAAC,aAAa,EAAExB,WAAW,CAAC;AACpD;AAEA,eAAeL,aAAa,CAACG,eAAe,EAAE;EAC5CuB,IAAI,EAAE;AACR,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { IncomingHttpHeaders } from 'http';
|
|
3
|
+
export interface MultipartHandler {
|
|
4
|
+
writeChunk: <T>(headers: IncomingHttpHeaders, data: T, isLast?: boolean) => void;
|
|
5
|
+
setHeader: (name: string, value: string | string[] | undefined) => void;
|
|
6
|
+
end: <T>(data: T) => void;
|
|
7
|
+
}
|
|
8
|
+
declare module 'fastify' {
|
|
9
|
+
interface FastifyReply {
|
|
10
|
+
asMultipart: () => MultipartHandler | undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/multipart/types.ts"],"sourcesContent":["import type { IncomingHttpHeaders } from 'http';\n\nexport interface MultipartHandler {\n writeChunk: <T>(\n headers: IncomingHttpHeaders,\n data: T,\n isLast?: boolean\n ) => void;\n setHeader: (name: string, value: string | string[] | undefined) => void;\n end: <T>(data: T) => void;\n}\n\ndeclare module 'fastify' {\n interface FastifyReply {\n asMultipart: () => MultipartHandler | undefined;\n }\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SourceMapConsumer } from 'source-map';
|
|
2
|
+
import type { FastifyLoggerInstance } from 'fastify';
|
|
3
|
+
import type { ReactNativeStackFrame, SymbolicatorDelegate, SymbolicatorResults } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Class for transforming stack traces from React Native application with using Source Map.
|
|
6
|
+
* Raw stack frames produced by React Native, points to some location from the bundle
|
|
7
|
+
* eg `index.bundle?platform=ios:567:1234`. By using Source Map for that bundle `Symbolicator`
|
|
8
|
+
* produces frames that point to source code inside your project eg `Hello.tsx:10:9`.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Symbolicator {
|
|
11
|
+
private delegate;
|
|
12
|
+
/**
|
|
13
|
+
* Infer platform from stack frames.
|
|
14
|
+
* Usually at least one frame has `file` field with the bundle URL eg:
|
|
15
|
+
* `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.
|
|
16
|
+
*
|
|
17
|
+
* @param stack Array of stack frames.
|
|
18
|
+
* @returns Inferred platform or `undefined` if cannot infer.
|
|
19
|
+
*/
|
|
20
|
+
static inferPlatformFromStack(stack: ReactNativeStackFrame[]): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Cache with initialized `SourceMapConsumer` to improve symbolication performance.
|
|
23
|
+
*/
|
|
24
|
+
sourceMapConsumerCache: Record<string, SourceMapConsumer>;
|
|
25
|
+
/**
|
|
26
|
+
* Constructs new `Symbolicator` instance.
|
|
27
|
+
*
|
|
28
|
+
* @param delegate Delegate instance with symbolication functions.
|
|
29
|
+
*/
|
|
30
|
+
constructor(delegate: SymbolicatorDelegate);
|
|
31
|
+
/**
|
|
32
|
+
* Process raw React Native stack frames and transform them using Source Maps.
|
|
33
|
+
* Method will try to symbolicate as much data as possible, but if the Source Maps
|
|
34
|
+
* are not available, invalid or the original positions/data is not found in Source Maps,
|
|
35
|
+
* the method will return raw values - the same as supplied with `stack` parameter.
|
|
36
|
+
* For example out of 10 frames, it's possible that only first 7 will be symbolicated and the
|
|
37
|
+
* remaining 3 will be unchanged.
|
|
38
|
+
*
|
|
39
|
+
* @param logger Fastify logger instance.
|
|
40
|
+
* @param stack Raw stack frames.
|
|
41
|
+
* @returns Symbolicated stack frames.
|
|
42
|
+
*/
|
|
43
|
+
process(logger: FastifyLoggerInstance, stack: ReactNativeStackFrame[]): Promise<SymbolicatorResults>;
|
|
44
|
+
private processFrame;
|
|
45
|
+
private getCodeFrame;
|
|
46
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { URL } from 'url';
|
|
2
|
+
import { codeFrameColumns } from '@babel/code-frame';
|
|
3
|
+
import { SourceMapConsumer } from 'source-map';
|
|
4
|
+
/**
|
|
5
|
+
* Class for transforming stack traces from React Native application with using Source Map.
|
|
6
|
+
* Raw stack frames produced by React Native, points to some location from the bundle
|
|
7
|
+
* eg `index.bundle?platform=ios:567:1234`. By using Source Map for that bundle `Symbolicator`
|
|
8
|
+
* produces frames that point to source code inside your project eg `Hello.tsx:10:9`.
|
|
9
|
+
*/
|
|
10
|
+
export class Symbolicator {
|
|
11
|
+
/**
|
|
12
|
+
* Infer platform from stack frames.
|
|
13
|
+
* Usually at least one frame has `file` field with the bundle URL eg:
|
|
14
|
+
* `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.
|
|
15
|
+
*
|
|
16
|
+
* @param stack Array of stack frames.
|
|
17
|
+
* @returns Inferred platform or `undefined` if cannot infer.
|
|
18
|
+
*/
|
|
19
|
+
static inferPlatformFromStack(stack) {
|
|
20
|
+
for (const frame of stack) {
|
|
21
|
+
if (!frame.file) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const {
|
|
25
|
+
searchParams,
|
|
26
|
+
pathname
|
|
27
|
+
} = new URL(frame.file, 'file://');
|
|
28
|
+
const platform = searchParams.get('platform');
|
|
29
|
+
if (platform) {
|
|
30
|
+
return platform;
|
|
31
|
+
} else {
|
|
32
|
+
const [bundleFilename] = pathname.split('/').reverse();
|
|
33
|
+
const [, platformOrExtension, extension] = bundleFilename.split('.');
|
|
34
|
+
if (extension) {
|
|
35
|
+
return platformOrExtension;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Cache with initialized `SourceMapConsumer` to improve symbolication performance.
|
|
43
|
+
*/
|
|
44
|
+
sourceMapConsumerCache = {};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Constructs new `Symbolicator` instance.
|
|
48
|
+
*
|
|
49
|
+
* @param delegate Delegate instance with symbolication functions.
|
|
50
|
+
*/
|
|
51
|
+
constructor(delegate) {
|
|
52
|
+
this.delegate = delegate;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Process raw React Native stack frames and transform them using Source Maps.
|
|
57
|
+
* Method will try to symbolicate as much data as possible, but if the Source Maps
|
|
58
|
+
* are not available, invalid or the original positions/data is not found in Source Maps,
|
|
59
|
+
* the method will return raw values - the same as supplied with `stack` parameter.
|
|
60
|
+
* For example out of 10 frames, it's possible that only first 7 will be symbolicated and the
|
|
61
|
+
* remaining 3 will be unchanged.
|
|
62
|
+
*
|
|
63
|
+
* @param logger Fastify logger instance.
|
|
64
|
+
* @param stack Raw stack frames.
|
|
65
|
+
* @returns Symbolicated stack frames.
|
|
66
|
+
*/
|
|
67
|
+
async process(logger, stack) {
|
|
68
|
+
logger.debug({
|
|
69
|
+
msg: 'Filtering out unnecessary frames'
|
|
70
|
+
});
|
|
71
|
+
const frames = [];
|
|
72
|
+
for (const frame of stack) {
|
|
73
|
+
const {
|
|
74
|
+
file
|
|
75
|
+
} = frame;
|
|
76
|
+
if (file?.startsWith('http') && !file.includes('debuggerWorker')) {
|
|
77
|
+
frames.push(frame);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
logger.debug({
|
|
82
|
+
msg: 'Processing frames',
|
|
83
|
+
frames
|
|
84
|
+
});
|
|
85
|
+
const processedFrames = [];
|
|
86
|
+
for (const frame of frames) {
|
|
87
|
+
if (!this.sourceMapConsumerCache[frame.file]) {
|
|
88
|
+
logger.debug({
|
|
89
|
+
msg: 'Loading raw source map data',
|
|
90
|
+
fileUrl: frame.file
|
|
91
|
+
});
|
|
92
|
+
const rawSourceMap = await this.delegate.getSourceMap(frame.file);
|
|
93
|
+
logger.debug({
|
|
94
|
+
msg: 'Creating source map instance',
|
|
95
|
+
fileUrl: frame.file,
|
|
96
|
+
sourceMapLength: rawSourceMap.length
|
|
97
|
+
});
|
|
98
|
+
const sourceMapConsumer = await new SourceMapConsumer(rawSourceMap.toString());
|
|
99
|
+
logger.debug({
|
|
100
|
+
msg: 'Saving source map instance into cache',
|
|
101
|
+
fileUrl: frame.file
|
|
102
|
+
});
|
|
103
|
+
this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;
|
|
104
|
+
}
|
|
105
|
+
logger.debug({
|
|
106
|
+
msg: 'Symbolicating frame',
|
|
107
|
+
frame
|
|
108
|
+
});
|
|
109
|
+
const processedFrame = this.processFrame(frame);
|
|
110
|
+
logger.debug({
|
|
111
|
+
msg: 'Finished symbolicating frame',
|
|
112
|
+
frame
|
|
113
|
+
});
|
|
114
|
+
processedFrames.push(processedFrame);
|
|
115
|
+
}
|
|
116
|
+
const codeFrame = (await this.getCodeFrame(logger, processedFrames)) ?? null;
|
|
117
|
+
logger.debug({
|
|
118
|
+
msg: 'Finished symbolicating frames',
|
|
119
|
+
processedFrames,
|
|
120
|
+
codeFrame
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
stack: processedFrames,
|
|
124
|
+
codeFrame
|
|
125
|
+
};
|
|
126
|
+
} finally {
|
|
127
|
+
for (const key in this.sourceMapConsumerCache) {
|
|
128
|
+
this.sourceMapConsumerCache[key].destroy();
|
|
129
|
+
delete this.sourceMapConsumerCache[key];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
processFrame(frame) {
|
|
134
|
+
if (!frame.lineNumber || !frame.column) {
|
|
135
|
+
return {
|
|
136
|
+
...frame,
|
|
137
|
+
collapse: false
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const consumer = this.sourceMapConsumerCache[frame.file];
|
|
141
|
+
if (!consumer) {
|
|
142
|
+
return {
|
|
143
|
+
...frame,
|
|
144
|
+
collapse: false
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const lookup = consumer.originalPositionFor({
|
|
148
|
+
line: frame.lineNumber,
|
|
149
|
+
column: frame.column
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// If lookup fails, we get the same shape object, but with
|
|
153
|
+
// all values set to null
|
|
154
|
+
if (!lookup.source) {
|
|
155
|
+
// It is better to gracefully return the original frame
|
|
156
|
+
// than to throw an exception
|
|
157
|
+
return {
|
|
158
|
+
...frame,
|
|
159
|
+
collapse: false
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
lineNumber: lookup.line || frame.lineNumber,
|
|
164
|
+
column: lookup.column || frame.column,
|
|
165
|
+
file: lookup.source,
|
|
166
|
+
methodName: lookup.name || frame.methodName,
|
|
167
|
+
collapse: false
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
async getCodeFrame(logger, processedFrames) {
|
|
171
|
+
for (const frame of processedFrames) {
|
|
172
|
+
if (frame.collapse || !frame.lineNumber || !frame.column) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (!this.delegate.shouldIncludeFrame(frame)) {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
logger.debug({
|
|
179
|
+
msg: 'Generating code frame',
|
|
180
|
+
frame
|
|
181
|
+
});
|
|
182
|
+
try {
|
|
183
|
+
return {
|
|
184
|
+
content: codeFrameColumns((await this.delegate.getSource(frame.file)).toString(), {
|
|
185
|
+
start: {
|
|
186
|
+
column: frame.column,
|
|
187
|
+
line: frame.lineNumber
|
|
188
|
+
}
|
|
189
|
+
}, {
|
|
190
|
+
forceColor: true
|
|
191
|
+
}),
|
|
192
|
+
location: {
|
|
193
|
+
row: frame.lineNumber,
|
|
194
|
+
column: frame.column
|
|
195
|
+
},
|
|
196
|
+
fileName: frame.file
|
|
197
|
+
};
|
|
198
|
+
} catch (error) {
|
|
199
|
+
logger.error({
|
|
200
|
+
msg: 'Failed to create code frame',
|
|
201
|
+
error: error.message
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=Symbolicator.js.map
|
|
@@ -0,0 +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,MAAM,CAACC,KAAK,CAAC;MAAEC,GAAG,EAAE;IAAmC,CAAC,CAAC;IAEzD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iB,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","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default"],"sources":["../../../src/plugins/symbolicate/index.ts"],"sourcesContent":["export { default } from './sybmolicatePlugin';\nexport * from './Symbolicator';\nexport * from './types';\n"],"mappings":"SAASA,OAAO;AAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
import type { Server } from '../../types';
|
|
3
|
+
declare function symbolicatePlugin(instance: FastifyInstance, { delegate, }: {
|
|
4
|
+
delegate: Server.Delegate;
|
|
5
|
+
}): Promise<void>;
|
|
6
|
+
declare const _default: typeof symbolicatePlugin;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import fastifyPlugin from 'fastify-plugin';
|
|
2
|
+
import { Symbolicator } from "./Symbolicator.js";
|
|
3
|
+
async function symbolicatePlugin(instance, {
|
|
4
|
+
delegate
|
|
5
|
+
}) {
|
|
6
|
+
const symbolicator = new Symbolicator(delegate.symbolicator);
|
|
7
|
+
instance.post('/symbolicate', async (request, reply) => {
|
|
8
|
+
// React Native sends stack as JSON but tests content-type to text/plain, so
|
|
9
|
+
// we cannot use JSON schema to validate the body.
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const {
|
|
13
|
+
stack
|
|
14
|
+
} = JSON.parse(request.body);
|
|
15
|
+
const platform = Symbolicator.inferPlatformFromStack(stack);
|
|
16
|
+
if (!platform) {
|
|
17
|
+
request.log.debug({
|
|
18
|
+
msg: 'Received stack',
|
|
19
|
+
stack
|
|
20
|
+
});
|
|
21
|
+
reply.badRequest('Cannot infer platform from stack trace');
|
|
22
|
+
} else {
|
|
23
|
+
request.log.debug({
|
|
24
|
+
msg: 'Starting symbolication',
|
|
25
|
+
platform,
|
|
26
|
+
stack
|
|
27
|
+
});
|
|
28
|
+
const results = await symbolicator.process(request.log, stack);
|
|
29
|
+
reply.send(results);
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
request.log.error({
|
|
33
|
+
msg: 'Failed to symbolicate',
|
|
34
|
+
error: error.message
|
|
35
|
+
});
|
|
36
|
+
reply.internalServerError();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export default fastifyPlugin(symbolicatePlugin, {
|
|
41
|
+
name: 'symbolicate-plugin',
|
|
42
|
+
dependencies: ['@fastify/sensible']
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=sybmolicatePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sybmolicatePlugin.js","names":["fastifyPlugin","Symbolicator","symbolicatePlugin","instance","delegate","symbolicator","post","request","reply","stack","JSON","parse","body","platform","inferPlatformFromStack","log","debug","msg","badRequest","results","process","send","error","message","internalServerError","name","dependencies"],"sources":["../../../src/plugins/symbolicate/sybmolicatePlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\nimport { Symbolicator } from './Symbolicator';\nimport type { ReactNativeStackFrame } from './types';\n\nasync function symbolicatePlugin(\n instance: FastifyInstance,\n {\n delegate,\n }: {\n delegate: Server.Delegate;\n }\n) {\n const symbolicator = new Symbolicator(delegate.symbolicator);\n\n instance.post('/symbolicate', async (request, reply) => {\n // React Native sends stack as JSON but tests content-type to text/plain, so\n // we cannot use JSON schema to validate the body.\n\n try {\n const { stack } = JSON.parse(request.body as string) as {\n stack: ReactNativeStackFrame[];\n };\n const platform = Symbolicator.inferPlatformFromStack(stack);\n if (!platform) {\n request.log.debug({ msg: 'Received stack', stack });\n reply.badRequest('Cannot infer platform from stack trace');\n } else {\n request.log.debug({ msg: 'Starting symbolication', platform, stack });\n const results = await symbolicator.process(request.log, stack);\n reply.send(results);\n }\n } catch (error) {\n request.log.error({\n msg: 'Failed to symbolicate',\n error: (error as Error).message,\n });\n reply.internalServerError();\n }\n });\n}\n\nexport default fastifyPlugin(symbolicatePlugin, {\n name: 'symbolicate-plugin',\n dependencies: ['@fastify/sensible'],\n});\n"],"mappings":"AACA,OAAOA,aAAa,MAAM,gBAAgB;AAAC,SAElCC,YAAY;AAGrB,eAAeC,iBAAiBA,CAC9BC,QAAyB,EACzB;EACEC;AAGF,CAAC,EACD;EACA,MAAMC,YAAY,GAAG,IAAIJ,YAAY,CAACG,QAAQ,CAACC,YAAY,CAAC;EAE5DF,QAAQ,CAACG,IAAI,CAAC,cAAc,EAAE,OAAOC,OAAO,EAAEC,KAAK,KAAK;IACtD;IACA;;IAEA,IAAI;MACF,MAAM;QAAEC;MAAM,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACJ,OAAO,CAACK,IAAc,CAElD;MACD,MAAMC,QAAQ,GAAGZ,YAAY,CAACa,sBAAsB,CAACL,KAAK,CAAC;MAC3D,IAAI,CAACI,QAAQ,EAAE;QACbN,OAAO,CAACQ,GAAG,CAACC,KAAK,CAAC;UAAEC,GAAG,EAAE,gBAAgB;UAAER;QAAM,CAAC,CAAC;QACnDD,KAAK,CAACU,UAAU,CAAC,wCAAwC,CAAC;MAC5D,CAAC,MAAM;QACLX,OAAO,CAACQ,GAAG,CAACC,KAAK,CAAC;UAAEC,GAAG,EAAE,wBAAwB;UAAEJ,QAAQ;UAAEJ;QAAM,CAAC,CAAC;QACrE,MAAMU,OAAO,GAAG,MAAMd,YAAY,CAACe,OAAO,CAACb,OAAO,CAACQ,GAAG,EAAEN,KAAK,CAAC;QAC9DD,KAAK,CAACa,IAAI,CAACF,OAAO,CAAC;MACrB;IACF,CAAC,CAAC,OAAOG,KAAK,EAAE;MACdf,OAAO,CAACQ,GAAG,CAACO,KAAK,CAAC;QAChBL,GAAG,EAAE,uBAAuB;QAC5BK,KAAK,EAAGA,KAAK,CAAWC;MAC1B,CAAC,CAAC;MACFf,KAAK,CAACgB,mBAAmB,CAAC,CAAC;IAC7B;EACF,CAAC,CAAC;AACJ;AAEA,eAAexB,aAAa,CAACE,iBAAiB,EAAE;EAC9CuB,IAAI,EAAE,oBAAoB;EAC1BC,YAAY,EAAE,CAAC,mBAAmB;AACpC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Raw React Native stack frame.
|
|
4
|
+
*/
|
|
5
|
+
export interface ReactNativeStackFrame {
|
|
6
|
+
lineNumber: number | null;
|
|
7
|
+
column: number | null;
|
|
8
|
+
file: string | null;
|
|
9
|
+
methodName: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* React Native stack frame used as input when processing by {@link Symbolicator}.
|
|
13
|
+
*/
|
|
14
|
+
export interface InputStackFrame extends ReactNativeStackFrame {
|
|
15
|
+
file: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Final symbolicated stack frame.
|
|
19
|
+
*/
|
|
20
|
+
export interface StackFrame extends InputStackFrame {
|
|
21
|
+
collapse: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Represents [@babel/core-frame](https://babeljs.io/docs/en/babel-code-frame).
|
|
25
|
+
*/
|
|
26
|
+
export interface CodeFrame {
|
|
27
|
+
content: string;
|
|
28
|
+
location: {
|
|
29
|
+
row: number;
|
|
30
|
+
column: number;
|
|
31
|
+
};
|
|
32
|
+
fileName: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents results of running {@link process} method on {@link Symbolicator} instance.
|
|
36
|
+
*/
|
|
37
|
+
export interface SymbolicatorResults {
|
|
38
|
+
codeFrame: CodeFrame | null;
|
|
39
|
+
stack: StackFrame[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Delegate with implementation for symbolication functions.
|
|
43
|
+
*/
|
|
44
|
+
export interface SymbolicatorDelegate {
|
|
45
|
+
/**
|
|
46
|
+
* Get source code of file in the URL.
|
|
47
|
+
*
|
|
48
|
+
* @param fileUrl A full URL pointing to a file.
|
|
49
|
+
*/
|
|
50
|
+
getSource: (fileUrl: string) => Promise<string | Buffer>;
|
|
51
|
+
/**
|
|
52
|
+
* Get source map for the file in the URL.
|
|
53
|
+
*
|
|
54
|
+
* @param fileUrl A full (usually `http:`) URL pointing to a compiled file.
|
|
55
|
+
* The URL points to a file for which to return source map, not to the source map file itself,
|
|
56
|
+
* e.g: `http://localhost:8081/index.bundle?platform=ios`.
|
|
57
|
+
*/
|
|
58
|
+
getSourceMap: (fileUrl: string) => Promise<string | Buffer>;
|
|
59
|
+
/**
|
|
60
|
+
* Check if given stack frame should be included in the new symbolicated stack.
|
|
61
|
+
*
|
|
62
|
+
* @param frame Stack frame to check.
|
|
63
|
+
*/
|
|
64
|
+
shouldIncludeFrame: (frame: StackFrame) => boolean;
|
|
65
|
+
}
|