@callstack/repack-dev-server 1.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 +14 -0
- package/README.md +32 -0
- package/dist/createServer.d.ts +13 -0
- package/dist/createServer.js +111 -0
- package/dist/createServer.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/compiler/compilerPlugin.d.ts +6 -0
- package/dist/plugins/compiler/compilerPlugin.js +85 -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 +6 -0
- package/dist/plugins/devtools/devtoolsPlugin.js +109 -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/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 +3 -0
- package/dist/plugins/multipart/multipartPlugin.js +68 -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 +227 -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 +6 -0
- package/dist/plugins/symbolicate/sybmolicatePlugin.js +46 -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 +61 -0
- package/dist/plugins/wss/WebSocketRouter.js.map +1 -0
- package/dist/plugins/wss/WebSocketServer.d.ts +37 -0
- package/dist/plugins/wss/WebSocketServer.js +49 -0
- package/dist/plugins/wss/WebSocketServer.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/HermesInspectorProxy.d.ts +24 -0
- package/dist/plugins/wss/servers/HermesInspectorProxy.js +138 -0
- package/dist/plugins/wss/servers/HermesInspectorProxy.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketDashboardServer.d.ts +34 -0
- package/dist/plugins/wss/servers/WebSocketDashboardServer.js +70 -0
- package/dist/plugins/wss/servers/WebSocketDashboardServer.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.d.ts +64 -0
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js +156 -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 +95 -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 +187 -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 +103 -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 +380 -0
- package/dist/plugins/wss/servers/WebSocketMessageServer.js.map +1 -0
- package/dist/plugins/wss/types.d.ts +16 -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 +29 -0
- package/dist/plugins/wss/wssPlugin.js +47 -0
- package/dist/plugins/wss/wssPlugin.js.map +1 -0
- package/dist/types.d.ts +127 -0
- package/dist/types.js +24 -0
- package/dist/types.js.map +1 -0
- package/package.json +75 -0
- package/vendor/metro-inspector-proxy/src/Device.cjs +1 -0
- package/vendor/metro-inspector-proxy/src/Device.js +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @callstack/repack-dev-server
|
|
2
|
+
|
|
3
|
+
## 1.0.0-next.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- ### Bundler-agnostic development server
|
|
8
|
+
|
|
9
|
+
Extracted development server from `@callstack/repack` into a separate package and made it bundler-agnostic.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies []:
|
|
14
|
+
- @callstack/repack-debugger-app@1.0.0-next.0
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/callstack/repack/HEAD/logo.png">
|
|
3
|
+
</p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
A Webpack-based toolkit to build your React Native application with full support of Webpack ecosystem.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
[![Build Status][build-badge]][build]
|
|
11
|
+
[![Version][version-badge]][version]
|
|
12
|
+
[![MIT License][license-badge]][license]
|
|
13
|
+
[![PRs Welcome][prs-welcome-badge]][prs-welcome]
|
|
14
|
+
[![Code of Conduct][coc-badge]][coc]
|
|
15
|
+
|
|
16
|
+
`@callstack/repack-dev-sever` is bundler-agnostic development server for React Native applications as part of `@callstack/repack`.
|
|
17
|
+
|
|
18
|
+
Check out our website at https://re-pack.netlify.app/ for more info and documentation or out GitHub: https://github.com/callstack/repack.
|
|
19
|
+
|
|
20
|
+
<!-- badges -->
|
|
21
|
+
[callstack-readme-with-love]: https://callstack.com/?utm_source=github.com&utm_medium=referral&utm_campaign=react-native-paper&utm_term=readme-with-love
|
|
22
|
+
|
|
23
|
+
[build-badge]: https://img.shields.io/github/workflow/status/callstack/repack/CI/main?style=flat-square
|
|
24
|
+
[build]: https://github.com/callstack/repack/actions/workflows/main.yml
|
|
25
|
+
[version-badge]: https://img.shields.io/npm/v/@callstack/repack-debugger-app?style=flat-square
|
|
26
|
+
[version]: https://www.npmjs.com/package/@callstack/repack-debugger-app
|
|
27
|
+
[license-badge]: https://img.shields.io/npm/l/@callstack/repack-debugger-app?style=flat-square
|
|
28
|
+
[license]: https://github.com/callstack/repack/blob/master/LICENSE
|
|
29
|
+
[prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
|
|
30
|
+
[prs-welcome]: ./CONTRIBUTING.md
|
|
31
|
+
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
|
|
32
|
+
[coc]: https://github.com/callstack/repack/blob/master/CODE_OF_CONDUCT.md
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Server } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Create instance of development server, powered by Fastify.
|
|
5
|
+
*
|
|
6
|
+
* @param config Server configuration.
|
|
7
|
+
* @returns `start` and `stop` functions as well as an underlying Fastify `instance`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createServer(config: Server.Config): Promise<{
|
|
10
|
+
start: () => Promise<void>;
|
|
11
|
+
stop: () => Promise<void>;
|
|
12
|
+
instance: import("fastify").FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").FastifyLoggerInstance> & PromiseLike<import("fastify").FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").FastifyLoggerInstance>>;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Writable } from 'stream';
|
|
2
|
+
import Fastify from 'fastify';
|
|
3
|
+
import fastifySensible from '@fastify/sensible';
|
|
4
|
+
import fastifyStatic from '@fastify/static';
|
|
5
|
+
import debuggerAppPath from '@callstack/repack-debugger-app';
|
|
6
|
+
import multipartPlugin from "./plugins/multipart/index.js";
|
|
7
|
+
import compilerPlugin from "./plugins/compiler/index.js";
|
|
8
|
+
import devtoolsPlugin from "./plugins/devtools/index.js";
|
|
9
|
+
import wssPlugin from "./plugins/wss/index.js";
|
|
10
|
+
import { Internal } from "./types.js";
|
|
11
|
+
import symbolicatePlugin from "./plugins/symbolicate/index.js";
|
|
12
|
+
/**
|
|
13
|
+
* Create instance of development server, powered by Fastify.
|
|
14
|
+
*
|
|
15
|
+
* @param config Server configuration.
|
|
16
|
+
* @returns `start` and `stop` functions as well as an underlying Fastify `instance`.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export async function createServer(config) {
|
|
20
|
+
/** Fastify instance powering the development server. */
|
|
21
|
+
const instance = Fastify({
|
|
22
|
+
logger: {
|
|
23
|
+
level: 'trace',
|
|
24
|
+
stream: new Writable({
|
|
25
|
+
write: (chunk, _encoding, callback) => {
|
|
26
|
+
delegate.logger.onMessage(JSON.parse(chunk.toString()));
|
|
27
|
+
callback();
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
},
|
|
31
|
+
...(config.options.https ? {
|
|
32
|
+
https: config.options.https
|
|
33
|
+
} : undefined)
|
|
34
|
+
});
|
|
35
|
+
const delegate = config.delegate({
|
|
36
|
+
log: instance.log,
|
|
37
|
+
notifyBuildStart: platform => {
|
|
38
|
+
instance.wss.dashboardServer.send({
|
|
39
|
+
event: Internal.EventTypes.BuildStart,
|
|
40
|
+
platform
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
notifyBuildEnd: platform => {
|
|
44
|
+
instance.wss.dashboardServer.send({
|
|
45
|
+
event: Internal.EventTypes.BuildEnd,
|
|
46
|
+
platform
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
broadcastToHmrClients: (event, platform, clientIds) => {
|
|
50
|
+
instance.wss.hmrServer.send(event, platform, clientIds);
|
|
51
|
+
},
|
|
52
|
+
broadcastToMessageClients: ({
|
|
53
|
+
method,
|
|
54
|
+
params
|
|
55
|
+
}) => {
|
|
56
|
+
instance.wss.messageServer.broadcast(method, params);
|
|
57
|
+
}
|
|
58
|
+
}); // Register plugins
|
|
59
|
+
|
|
60
|
+
await instance.register(fastifySensible);
|
|
61
|
+
await instance.register(wssPlugin, {
|
|
62
|
+
options: config.options,
|
|
63
|
+
delegate
|
|
64
|
+
});
|
|
65
|
+
await instance.register(multipartPlugin);
|
|
66
|
+
await instance.register(compilerPlugin, {
|
|
67
|
+
delegate
|
|
68
|
+
});
|
|
69
|
+
await instance.register(symbolicatePlugin, {
|
|
70
|
+
delegate
|
|
71
|
+
});
|
|
72
|
+
await instance.register(devtoolsPlugin, {
|
|
73
|
+
options: config.options
|
|
74
|
+
});
|
|
75
|
+
await instance.register(fastifyStatic, {
|
|
76
|
+
root: debuggerAppPath,
|
|
77
|
+
prefix: '/debugger-ui',
|
|
78
|
+
prefixAvoidTrailingSlash: true
|
|
79
|
+
});
|
|
80
|
+
instance.addHook('onSend', async (request, reply, payload) => {
|
|
81
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
82
|
+
const [pathname] = request.url.split('?');
|
|
83
|
+
|
|
84
|
+
if (pathname.endsWith('.map')) {
|
|
85
|
+
reply.header('Access-Control-Allow-Origin', 'devtools://devtools');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return payload;
|
|
89
|
+
}); // Register routes
|
|
90
|
+
|
|
91
|
+
instance.get('/', async () => delegate.messages.getHello());
|
|
92
|
+
instance.get('/status', async () => delegate.messages.getStatus());
|
|
93
|
+
/** Start the development server. */
|
|
94
|
+
|
|
95
|
+
async function start() {
|
|
96
|
+
await instance.listen(config.options.port, config.options.host);
|
|
97
|
+
}
|
|
98
|
+
/** Stop the development server. */
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
async function stop() {
|
|
102
|
+
await instance.close();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
start,
|
|
107
|
+
stop,
|
|
108
|
+
instance
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=createServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createServer.js","names":["Writable","Fastify","fastifySensible","fastifyStatic","debuggerAppPath","multipartPlugin","compilerPlugin","devtoolsPlugin","wssPlugin","Internal","symbolicatePlugin","createServer","config","instance","logger","level","stream","write","chunk","_encoding","callback","delegate","onMessage","JSON","parse","toString","options","https","undefined","log","notifyBuildStart","platform","wss","dashboardServer","send","event","EventTypes","BuildStart","notifyBuildEnd","BuildEnd","broadcastToHmrClients","clientIds","hmrServer","broadcastToMessageClients","method","params","messageServer","broadcast","register","root","prefix","prefixAvoidTrailingSlash","addHook","request","reply","payload","header","pathname","url","split","endsWith","get","messages","getHello","getStatus","start","listen","port","host","stop","close"],"sources":["../src/createServer.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport Fastify from 'fastify';\nimport fastifySensible from '@fastify/sensible';\nimport fastifyStatic from '@fastify/static';\nimport debuggerAppPath from '@callstack/repack-debugger-app';\nimport multipartPlugin from './plugins/multipart';\nimport compilerPlugin from './plugins/compiler';\nimport devtoolsPlugin from './plugins/devtools';\nimport wssPlugin from './plugins/wss';\nimport { Internal, Server } from './types';\nimport symbolicatePlugin from './plugins/symbolicate';\n\n/**\n * Create instance of development server, powered by Fastify.\n *\n * @param config Server configuration.\n * @returns `start` and `stop` functions as well as an underlying Fastify `instance`.\n */\nexport async function createServer(config: Server.Config) {\n /** 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 delegate.logger.onMessage(JSON.parse(chunk.toString()));\n callback();\n },\n }),\n },\n ...(config.options.https ? { https: config.options.https } : undefined),\n });\n\n const delegate = config.delegate({\n log: instance.log,\n notifyBuildStart: (platform) => {\n instance.wss.dashboardServer.send({\n event: Internal.EventTypes.BuildStart,\n platform,\n });\n },\n notifyBuildEnd: (platform) => {\n instance.wss.dashboardServer.send({\n event: Internal.EventTypes.BuildEnd,\n platform,\n });\n },\n broadcastToHmrClients: (event, platform, clientIds) => {\n instance.wss.hmrServer.send(event, platform, clientIds);\n },\n broadcastToMessageClients: ({ method, params }) => {\n instance.wss.messageServer.broadcast(method, params);\n },\n });\n\n // Register plugins\n await instance.register(fastifySensible);\n await instance.register(wssPlugin, {\n options: config.options,\n delegate,\n });\n await instance.register(multipartPlugin);\n await instance.register(compilerPlugin, {\n delegate,\n });\n await instance.register(symbolicatePlugin, {\n delegate,\n });\n await instance.register(devtoolsPlugin, {\n options: config.options,\n });\n\n await instance.register(fastifyStatic, {\n root: debuggerAppPath,\n prefix: '/debugger-ui',\n prefixAvoidTrailingSlash: true,\n });\n\n instance.addHook('onSend', async (request, reply, payload) => {\n reply.header('X-Content-Type-Options', 'nosniff');\n\n const [pathname] = request.url.split('?');\n if (pathname.endsWith('.map')) {\n reply.header('Access-Control-Allow-Origin', 'devtools://devtools');\n }\n\n return payload;\n });\n\n // Register routes\n instance.get('/', async () => delegate.messages.getHello());\n instance.get('/status', async () => delegate.messages.getStatus());\n\n /** Start the development server. */\n async function start() {\n await instance.listen(config.options.port, config.options.host);\n }\n\n /** Stop the development server. */\n async function stop() {\n await instance.close();\n }\n\n return {\n start,\n stop,\n instance,\n };\n}\n"],"mappings":"AAAA,SAASA,QAAT,QAAyB,QAAzB;AACA,OAAOC,OAAP,MAAoB,SAApB;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,eAAP,MAA4B,gCAA5B;OACOC,e;OACAC,c;OACAC,c;OACAC,S;SACEC,Q;OACFC,iB;AAEP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,eAAeC,YAAf,CAA4BC,MAA5B,EAAmD;EACxD;EACA,MAAMC,QAAQ,GAAGZ,OAAO,CAAC;IACvBa,MAAM,EAAE;MACNC,KAAK,EAAE,OADD;MAENC,MAAM,EAAE,IAAIhB,QAAJ,CAAa;QACnBiB,KAAK,EAAE,CAACC,KAAD,EAAQC,SAAR,EAAmBC,QAAnB,KAAgC;UACrCC,QAAQ,CAACP,MAAT,CAAgBQ,SAAhB,CAA0BC,IAAI,CAACC,KAAL,CAAWN,KAAK,CAACO,QAAN,EAAX,CAA1B;UACAL,QAAQ;QACT;MAJkB,CAAb;IAFF,CADe;IAUvB,IAAIR,MAAM,CAACc,OAAP,CAAeC,KAAf,GAAuB;MAAEA,KAAK,EAAEf,MAAM,CAACc,OAAP,CAAeC;IAAxB,CAAvB,GAAyDC,SAA7D;EAVuB,CAAD,CAAxB;EAaA,MAAMP,QAAQ,GAAGT,MAAM,CAACS,QAAP,CAAgB;IAC/BQ,GAAG,EAAEhB,QAAQ,CAACgB,GADiB;IAE/BC,gBAAgB,EAAGC,QAAD,IAAc;MAC9BlB,QAAQ,CAACmB,GAAT,CAAaC,eAAb,CAA6BC,IAA7B,CAAkC;QAChCC,KAAK,EAAE1B,QAAQ,CAAC2B,UAAT,CAAoBC,UADK;QAEhCN;MAFgC,CAAlC;IAID,CAP8B;IAQ/BO,cAAc,EAAGP,QAAD,IAAc;MAC5BlB,QAAQ,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AAT,CAAiB,QAAjB,EAA2B,OAAOC,OAAP,EAAgBC,KAAhB,EAAuBC,OAAvB,KAAmC;IAC5DD,KAAK,CAACE,MAAN,CAAa,wBAAb,EAAuC,SAAvC;IAEA,MAAM,CAACC,QAAD,IAAaJ,OAAO,CAACK,GAAR,CAAYC,KAAZ,CAAkB,GAAlB,CAAnB;;IACA,IAAIF,QAAQ,CAACG,QAAT,CAAkB,MAAlB,CAAJ,EAA+B;MAC7BN,KAAK,CAACE,MAAN,CAAa,6BAAb,EAA4C,qBAA5C;IACD;;IAED,OAAOD,OAAP;EACD,CATD,EA5DwD,CAuExD;;EACA1C,QAAQ,CAACgD,GAAT,CAAa,GAAb,EAAkB,YAAYxC,QAAQ,CAACyC,QAAT,CAAkBC,QAAlB,EAA9B;EACAlD,QAAQ,CAACgD,GAAT,CAAa,SAAb,EAAwB,YAAYxC,QAAQ,CAACyC,QAAT,CAAkBE,SAAlB,EAApC;EAEA;;EACA,eAAeC,KAAf,GAAuB;IACrB,MAAMpD,QAAQ,CAACqD,MAAT,CAAgBtD,MAAM,CAACc,OAAP,CAAeyC,IAA/B,EAAqCvD,MAAM,CAACc,OAAP,CAAe0C,IAApD,CAAN;EACD;EAED;;;EACA,eAAeC,IAAf,GAAsB;IACpB,MAAMxD,QAAQ,CAACyD,KAAT,EAAN;EACD;;EAED,OAAO;IACLL,KADK;IAELI,IAFK;IAGLxD;EAHK,CAAP;AAKD"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './createServer';\nexport * from './types';\n"],"mappings":""}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import fastifyPlugin from 'fastify-plugin';
|
|
2
|
+
|
|
3
|
+
async function compilerPlugin(instance, {
|
|
4
|
+
delegate
|
|
5
|
+
}) {
|
|
6
|
+
instance.route({
|
|
7
|
+
method: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'],
|
|
8
|
+
url: '/*',
|
|
9
|
+
schema: {
|
|
10
|
+
querystring: {
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
platform: {
|
|
14
|
+
type: 'string'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
handler: async (request, reply) => {
|
|
20
|
+
var _delegate$compiler$in, _delegate$compiler;
|
|
21
|
+
|
|
22
|
+
let file = request.params['*'];
|
|
23
|
+
let {
|
|
24
|
+
platform
|
|
25
|
+
} = request.query;
|
|
26
|
+
|
|
27
|
+
if (!file) {
|
|
28
|
+
// This technically should never happen - this route should not be called if file is missing.
|
|
29
|
+
request.log.error(`File was not provided`);
|
|
30
|
+
return reply.notFound();
|
|
31
|
+
} // Let consumer infer the platform. If function is not provided fallback
|
|
32
|
+
// to platform query param.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
platform = ((_delegate$compiler$in = (_delegate$compiler = delegate.compiler).inferPlatform) === null || _delegate$compiler$in === void 0 ? void 0 : _delegate$compiler$in.call(_delegate$compiler, request.url)) ?? platform;
|
|
36
|
+
|
|
37
|
+
if (!platform) {
|
|
38
|
+
request.log.error('Cannot detect platform');
|
|
39
|
+
return reply.badRequest('Cannot detect platform');
|
|
40
|
+
} // If platform happens to be in front of an asset remove it.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if (file.startsWith(`${platform}/`)) {
|
|
44
|
+
file = file.replace(`${platform}/`, '');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const multipart = reply.asMultipart();
|
|
48
|
+
|
|
49
|
+
const sendProgress = ({
|
|
50
|
+
completed,
|
|
51
|
+
total
|
|
52
|
+
}) => {
|
|
53
|
+
multipart === null || multipart === void 0 ? void 0 : multipart.writeChunk({
|
|
54
|
+
'Content-Type': 'application/json'
|
|
55
|
+
}, JSON.stringify({
|
|
56
|
+
done: completed,
|
|
57
|
+
total
|
|
58
|
+
}));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
const asset = await delegate.compiler.getAsset(file, platform, sendProgress);
|
|
63
|
+
const mimeType = delegate.compiler.getMimeType(file, platform, asset);
|
|
64
|
+
|
|
65
|
+
if (multipart) {
|
|
66
|
+
const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);
|
|
67
|
+
multipart.setHeader('Content-Type', `${mimeType}; charset=UTF-8`);
|
|
68
|
+
multipart.setHeader('Content-Length', String(Buffer.byteLength(buffer)));
|
|
69
|
+
multipart.end(buffer);
|
|
70
|
+
} else {
|
|
71
|
+
return reply.code(200).type(mimeType).send(asset);
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
request.log.error(error);
|
|
75
|
+
return reply.notFound(error.message);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default fastifyPlugin(compilerPlugin, {
|
|
82
|
+
name: 'compiler-plugin',
|
|
83
|
+
dependencies: ['fastify-sensible', 'multipart-plugin']
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=compilerPlugin.js.map
|
|
@@ -0,0 +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","sendProgress","completed","total","writeChunk","JSON","stringify","done","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';\nimport type { SendProgress } 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 const sendProgress: SendProgress = ({ completed, total }) => {\n multipart?.writeChunk(\n { 'Content-Type': 'application/json' },\n JSON.stringify({\n done: completed,\n total,\n })\n );\n };\n\n try {\n const asset = await delegate.compiler.getAsset(\n file,\n platform,\n sendProgress\n );\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 fastifyPlugin(compilerPlugin, {\n name: 'compiler-plugin',\n dependencies: ['fastify-sensible', 'multipart-plugin'],\n});\n"],"mappings":"AACA,OAAOA,aAAP,MAA0B,gBAA1B;;AAIA,eAAeC,cAAf,CACEC,QADF,EAEE;EAAEC;AAAF,CAFF,EAGE;EACAD,QAAQ,CAACE,KAAT,CAAe;IACbC,MAAM,EAAE,CAAC,KAA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],"sources":["../../../src/plugins/compiler/index.ts"],"sourcesContent":["export { default } from './compilerPlugin';\nexport * from './types';\n"],"mappings":"SAASA,O"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { SendProgress } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Delegate with implementation for compiler-specific functions.
|
|
5
|
+
*/
|
|
6
|
+
export interface CompilerDelegate {
|
|
7
|
+
/**
|
|
8
|
+
* Get compiled asset content.
|
|
9
|
+
*
|
|
10
|
+
* If the compilation is in progress, it should wait until compilation finishes and then return the asset.
|
|
11
|
+
*
|
|
12
|
+
* @param filename Filename of the asset to get.
|
|
13
|
+
* @param platform Platform of the asset to get.
|
|
14
|
+
* @param sendProgress Function to notify the client who requested the asset about compilation progress.
|
|
15
|
+
*/
|
|
16
|
+
getAsset: (filename: string, platform: string, sendProgress?: SendProgress) => Promise<string | Buffer>;
|
|
17
|
+
/**
|
|
18
|
+
* Detect MIME type of the asset from `filename`, `platform` or `data` (or from combination of either).
|
|
19
|
+
*
|
|
20
|
+
* @param filename Filename of the asset.
|
|
21
|
+
* @param platform Platform of the asset.
|
|
22
|
+
* @param data Asset's content.
|
|
23
|
+
*/
|
|
24
|
+
getMimeType: (filename: string, platform: string, data: string | Buffer) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Detect the platform from the URI - either from filename, query params or both.
|
|
27
|
+
*
|
|
28
|
+
* @param uri URI string.
|
|
29
|
+
*/
|
|
30
|
+
inferPlatform?: (uri: string) => string | undefined;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/compiler/types.ts"],"sourcesContent":["import type { SendProgress } from '../../types';\n\n/**\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 * @param sendProgress Function to notify the client who requested the asset about compilation progress.\n */\n getAsset: (\n filename: string,\n platform: string,\n sendProgress?: SendProgress\n ) => 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":""}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import open from 'open';
|
|
3
|
+
import openEditor from 'open-editor';
|
|
4
|
+
import fastifyPlugin from 'fastify-plugin';
|
|
5
|
+
|
|
6
|
+
async function devtoolsPlugin(instance, {
|
|
7
|
+
options
|
|
8
|
+
}) {
|
|
9
|
+
instance.route({
|
|
10
|
+
method: ['GET', 'POST', 'PUT'],
|
|
11
|
+
url: '/reload',
|
|
12
|
+
handler: (_request, reply) => {
|
|
13
|
+
instance.wss.messageServer.broadcast('reload');
|
|
14
|
+
reply.send('OK');
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
instance.route({
|
|
18
|
+
method: ['GET', 'POST', 'PUT'],
|
|
19
|
+
url: '/launch-js-devtools',
|
|
20
|
+
handler: async (request, reply) => {
|
|
21
|
+
const customDebugger = process.env.REACT_DEBUGGER;
|
|
22
|
+
|
|
23
|
+
if (customDebugger) {// NOOP for now
|
|
24
|
+
} else if (!instance.wss.debuggerServer.isDebuggerConnected()) {
|
|
25
|
+
const url = `${options.https ? 'https' : 'http'}://${options.host || 'localhost'}:${options.port}/debugger-ui`;
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
request.log.info({
|
|
29
|
+
msg: 'Opening debugger UI',
|
|
30
|
+
url
|
|
31
|
+
});
|
|
32
|
+
await open(url);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (error) {
|
|
35
|
+
request.log.error({
|
|
36
|
+
msg: 'Cannot open debugger UI',
|
|
37
|
+
url,
|
|
38
|
+
error
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
reply.send('OK');
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
instance.route({
|
|
48
|
+
method: ['GET', 'POST', 'PUT'],
|
|
49
|
+
url: '/open-stack-frame',
|
|
50
|
+
handler: async (request, reply) => {
|
|
51
|
+
try {
|
|
52
|
+
const {
|
|
53
|
+
file,
|
|
54
|
+
lineNumber,
|
|
55
|
+
column
|
|
56
|
+
} = JSON.parse(request.body);
|
|
57
|
+
const url = `${path.join(options.rootDir, // TODO: make it generic
|
|
58
|
+
file.replace('webpack://', ''))}:${lineNumber}:${column ?? 1}`;
|
|
59
|
+
request.log.info({
|
|
60
|
+
msg: 'Opening stack frame in editor',
|
|
61
|
+
url
|
|
62
|
+
});
|
|
63
|
+
openEditor([url]);
|
|
64
|
+
reply.send('OK');
|
|
65
|
+
} catch (error) {
|
|
66
|
+
request.log.error({
|
|
67
|
+
msg: 'Failed to open stack frame in editor',
|
|
68
|
+
error: error.message
|
|
69
|
+
});
|
|
70
|
+
reply.code(400).send();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
instance.route({
|
|
75
|
+
method: ['GET', 'POST', 'PUT'],
|
|
76
|
+
url: '/open-url',
|
|
77
|
+
handler: async (request, reply) => {
|
|
78
|
+
try {
|
|
79
|
+
const {
|
|
80
|
+
url
|
|
81
|
+
} = JSON.parse(request.body);
|
|
82
|
+
request.log.info({
|
|
83
|
+
msg: 'Opening URL',
|
|
84
|
+
url
|
|
85
|
+
});
|
|
86
|
+
await open(url);
|
|
87
|
+
reply.send('OK');
|
|
88
|
+
} catch (error) {
|
|
89
|
+
request.log.error({
|
|
90
|
+
msg: 'Failed to open URL',
|
|
91
|
+
error
|
|
92
|
+
});
|
|
93
|
+
reply.code(400).send();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}); // Silence this route
|
|
97
|
+
|
|
98
|
+
instance.get('/inspector/device', {
|
|
99
|
+
logLevel: 'silent'
|
|
100
|
+
}, (_request, reply) => {
|
|
101
|
+
reply.code(404).send();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export default fastifyPlugin(devtoolsPlugin, {
|
|
106
|
+
name: 'devtools-plugin',
|
|
107
|
+
dependencies: ['wss-plugin']
|
|
108
|
+
});
|
|
109
|
+
//# sourceMappingURL=devtoolsPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtoolsPlugin.js","names":["path","open","openEditor","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","file","lineNumber","column","JSON","parse","body","join","rootDir","replace","message","code","get","logLevel","name","dependencies"],"sources":["../../../src/plugins/devtools/devtoolsPlugin.ts"],"sourcesContent":["import path from 'path';\nimport open from 'open';\nimport openEditor from 'open-editor';\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 instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/open-stack-frame',\n handler: async (request, reply) => {\n try {\n const { file, lineNumber, column } = JSON.parse(\n request.body as string\n ) as {\n file: string;\n lineNumber: number;\n column?: number;\n };\n const url = `${path.join(\n options.rootDir,\n // TODO: make it generic\n file.replace('webpack://', '')\n )}:${lineNumber}:${column ?? 1}`;\n\n request.log.info({ msg: 'Opening stack frame in editor', url });\n openEditor([url]);\n reply.send('OK');\n } catch (error) {\n request.log.error({\n msg: 'Failed to open stack frame in editor',\n error: (error as Error).message,\n });\n reply.code(400).send();\n }\n },\n });\n\n instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/open-url',\n handler: async (request, reply) => {\n try {\n const { url } = JSON.parse(request.body as string) as { url: string };\n request.log.info({ msg: 'Opening URL', url });\n await open(url);\n reply.send('OK');\n } catch (error) {\n request.log.error({ msg: 'Failed to open URL', error });\n reply.code(400).send();\n }\n },\n });\n\n // Silence this route\n instance.get(\n '/inspector/device',\n { logLevel: 'silent' as any },\n (_request, reply) => {\n reply.code(404).send();\n }\n );\n}\n\nexport default fastifyPlugin(devtoolsPlugin, {\n name: 'devtools-plugin',\n dependencies: ['wss-plugin'],\n});\n"],"mappings":"AAAA,OAAOA,IAAP,MAAiB,MAAjB;AACA,OAAOC,IAAP,MAAiB,MAAjB;AACA,OAAOC,UAAP,MAAuB,aAAvB;AAEA,OAAOC,aAAP,MAA0B,gBAA1B;;AAGA,eAAeC,cAAf,CACEC,QADF,EAEE;EAAEC;AAAF,CAFF,EAGE;EACAD,QAAQ,CAACE,KAAT,CAAe;IACbC,MAAM,EAAE,CAAC,KAAD,EAAQ,MAAR,EAAgB,KAAhB,CADK;IAEbC,GAAG,EAAE,SAFQ;IAGbC,OAAO,EA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Ac;QACdb,OAAO,CAACU,GAAR,CAAYG,KAAZ,CAAkB;UAAED,GAAG,EAAE,oBAAP;UAA6BC;QAA7B,CAAlB;QACAlB,KAAK,CAAC6B,IAAN,CAAW,GAAX,EAAgBzB,IAAhB;MACD;IACF;EAbY,CAAf,EArEA,CAqFA;;EACAX,QAAQ,CAACqC,GAAT,CACE,mBADF,EAEE;IAAEC,QAAQ,EAAE;EAAZ,CAFF,EAGE,CAAChC,QAAD,EAAWC,KAAX,KAAqB;IACnBA,KAAK,CAAC6B,IAAN,CAAW,GAAX,EAAgBzB,IAAhB;EACD,CALH;AAOD;;AAED,eAAeb,aAAa,CAACC,cAAD,EAAiB;EAC3CwC,IAAI,EAAE,iBADqC;EAE3CC,YAAY,EAAE,CAAC,YAAD;AAF6B,CAAjB,CAA5B"}
|
|
@@ -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,O"}
|
|
@@ -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,O"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { PassThrough } from 'stream';
|
|
2
|
+
import fastifyPlugin from 'fastify-plugin';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Implementation is based on:
|
|
6
|
+
* https://github.com/facebook/metro/blob/347b1d7ed87995d7951aaa9fd597c04b06013dac/packages/metro/src/Server/MultipartResponse.js
|
|
7
|
+
*/
|
|
8
|
+
const CRLF = '\r\n';
|
|
9
|
+
const BOUNDARY = '3beqjf3apnqeu3h5jqorms4i';
|
|
10
|
+
|
|
11
|
+
async function multipartPlugin(instance) {
|
|
12
|
+
function asMultipart() {
|
|
13
|
+
// We should check if is included in accept or if accept has multipart/* or */*,
|
|
14
|
+
// but React Native will set accept to exactly `multipart/mixed`, so a simple check
|
|
15
|
+
// will suffice.
|
|
16
|
+
if (this.request.headers.accept !== 'multipart/mixed') {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const headers = {};
|
|
21
|
+
const stream = new PassThrough();
|
|
22
|
+
this.code(200).header('Content-Type', `multipart/mixed; boundary="${BOUNDARY}"`).send(stream);
|
|
23
|
+
|
|
24
|
+
function serializeHeaders(headers) {
|
|
25
|
+
return Object.keys(headers).map(key => `${key}: ${headers[key]}`).join(CRLF);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function writeChunk(headers, data, isLast) {
|
|
29
|
+
let chunk = `${CRLF}--${BOUNDARY}${CRLF}`;
|
|
30
|
+
|
|
31
|
+
if (headers) {
|
|
32
|
+
chunk += serializeHeaders(headers) + CRLF + CRLF;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (data) {
|
|
36
|
+
chunk += data;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (isLast) {
|
|
40
|
+
chunk += `${CRLF}--${BOUNDARY}--${CRLF}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
stream.write(chunk);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function setHeader(name, value) {
|
|
47
|
+
headers[name] = value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function end(data) {
|
|
51
|
+
writeChunk(headers, data, true);
|
|
52
|
+
stream.end();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
writeChunk,
|
|
57
|
+
setHeader,
|
|
58
|
+
end
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
instance.decorateReply('asMultipart', asMultipart);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default fastifyPlugin(multipartPlugin, {
|
|
66
|
+
name: 'multipart-plugin'
|
|
67
|
+
});
|
|
68
|
+
//# 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,WAAT,QAA4B,QAA5B;AAEA,OAAOC,aAAP,MAA0B,gBAA1B;;AAGA;AACA;AACA;AACA;AAEA,MAAMC,IAAI,GAAG,MAAb;AACA,MAAMC,QAAQ,GAAG,0BAAjB;;AAEA,eAAeC,eAAf,CAA+BC,QAA/B,EAA0D;EACxD,SAASC,WAAT,GAAuE;IACrE;IACA;IACA;IACA,IAAI,KAAKC,OAAL,CAAaC,OAAb,CAAqBC,MAArB,KAAgC,iBAApC,EAAuD;MACrD,OAAOC,SAAP;IACD;;IAED,MAAMF,OAA4B,GAAG,EAArC;IACA,MAAMG,MAAM,GAAG,IAAIX,WAAJ,EAAf;IAEA,KAAKY,IAAL,CAAU,GAAV,EACGC,MADH,CACU,cADV,EAC2B,8BAA6BV,QAAS,GADjE,EAEGW,IAFH,CAEQH,MAFR;;IAIA,SAASI,gBAAT,CAA0BP,OAA1B,EAAwD;MACtD,OAAOQ,MAAM,CAACC,IAAP,CAAYT,OAAZ,EACJU,GADI,CACCC,GAAD,IAAU,GAAEA,GAAI,KAAIX,OAAO,CAACW,GAAD,CAAM,EADjC,EAEJC,IAFI,CAEClB,IAFD,CAAP;IAGD;;IAED,SAASmB,UAAT,CACEb,OADF,EAEEc,IAFF,EAGEC,MAHF,EAIE;MACA,IAAIC,KAAK,GAAI,GAAEtB,IAAK,KAAIC,QAAS,GAAED,IAAK,EAAxC;;MACA,IAAIM,OAAJ,EAAa;QACXgB,KAAK,IAAIT,gBAAgB,CAACP,OAAD,CAAhB,GAA4BN,IAA5B,GAAmCA,IAA5C;MACD;;MAED,IAAIoB,IAAJ,EAAU;QACRE,KAAK,IAAIF,IAAT;MACD;;MAED,IAAIC,MAAJ,EAAY;QACVC,KAAK,IAAK,GAAEtB,IAAK,KAAIC,QAAS,KAAID,IAAK,EAAvC;MACD;;MAEDS,MAAM,CAACc,KAAP,CAAaD,KAAb;IACD;;IAED,SAASE,SAAT,CAAmBC,IAAnB,EAAiCC,KAAjC,EAAuE;MACrEpB,OAAO,CAACmB,IAAD,CAAP,GAAgBC,KAAhB;IACD;;IAED,SAASC,GAAT,CAAgBP,IAAhB,EAAyB;MACvBD,UAAU,CAACb,OAAD,EAAUc,IAAV,EAAgB,IAAhB,CAAV;MACAX,MAAM,CAACkB,GAAP;IACD;;IAED,OAAO;MACLR,UADK;MAELK,SAFK;MAGLG;IAHK,CAAP;EAKD;;EAEDxB,QAAQ,CAACyB,aAAT,CAAuB,aAAvB,EAAsCxB,WAAtC;AACD;;AAED,eAAeL,aAAa,CAACG,eAAD,EAAkB;EAC5CuB,IAAI,EAAE;AADsC,CAAlB,CAA5B"}
|
|
@@ -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":""}
|