@callstack/repack-dev-server 5.0.0-rc.2 → 5.0.0-rc.4
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/dist/createServer.d.ts +3 -2
- package/dist/createServer.js +110 -123
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -3
- package/dist/plugins/api/apiPlugin.d.ts +1 -1
- package/dist/plugins/api/apiPlugin.js +21 -28
- package/dist/plugins/api/index.d.ts +1 -1
- package/dist/plugins/api/index.js +1 -2
- package/dist/plugins/compiler/compilerPlugin.d.ts +1 -1
- package/dist/plugins/compiler/compilerPlugin.js +53 -62
- package/dist/plugins/compiler/index.d.ts +2 -2
- package/dist/plugins/compiler/index.js +2 -3
- package/dist/plugins/compiler/types.d.ts +1 -1
- package/dist/plugins/compiler/types.js +0 -1
- package/dist/plugins/devtools/devtoolsPlugin.d.ts +1 -1
- package/dist/plugins/devtools/devtoolsPlugin.js +16 -19
- package/dist/plugins/devtools/index.d.ts +1 -1
- package/dist/plugins/devtools/index.js +1 -2
- package/dist/plugins/favicon/faviconPlugin.js +3 -7
- package/dist/plugins/favicon/index.d.ts +1 -1
- package/dist/plugins/favicon/index.js +1 -2
- package/dist/plugins/multipart/index.d.ts +2 -2
- package/dist/plugins/multipart/index.js +2 -3
- package/dist/plugins/multipart/multipartPlugin.js +44 -42
- package/dist/plugins/multipart/types.js +0 -1
- package/dist/plugins/symbolicate/Symbolicator.d.ts +1 -1
- package/dist/plugins/symbolicate/Symbolicator.js +172 -190
- package/dist/plugins/symbolicate/index.d.ts +3 -3
- package/dist/plugins/symbolicate/index.js +3 -4
- package/dist/plugins/symbolicate/sybmolicatePlugin.d.ts +1 -1
- package/dist/plugins/symbolicate/sybmolicatePlugin.js +29 -40
- package/dist/plugins/symbolicate/types.js +0 -1
- package/dist/plugins/wss/WebSocketRouter.d.ts +1 -1
- package/dist/plugins/wss/WebSocketRouter.js +39 -44
- package/dist/plugins/wss/WebSocketServer.d.ts +1 -1
- package/dist/plugins/wss/WebSocketServer.js +23 -38
- package/dist/plugins/wss/WebSocketServerAdapter.d.ts +1 -1
- package/dist/plugins/wss/WebSocketServerAdapter.js +16 -19
- package/dist/plugins/wss/index.d.ts +3 -3
- package/dist/plugins/wss/index.js +3 -4
- package/dist/plugins/wss/servers/WebSocketApiServer.d.ts +1 -1
- package/dist/plugins/wss/servers/WebSocketApiServer.js +47 -53
- package/dist/plugins/wss/servers/WebSocketDevClientServer.d.ts +1 -1
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js +58 -80
- package/dist/plugins/wss/servers/WebSocketEventsServer.d.ts +2 -2
- package/dist/plugins/wss/servers/WebSocketEventsServer.js +146 -164
- package/dist/plugins/wss/servers/WebSocketHMRServer.d.ts +2 -2
- package/dist/plugins/wss/servers/WebSocketHMRServer.js +72 -79
- package/dist/plugins/wss/servers/WebSocketMessageServer.d.ts +1 -1
- package/dist/plugins/wss/servers/WebSocketMessageServer.js +309 -326
- package/dist/plugins/wss/types.js +0 -1
- package/dist/plugins/wss/wssPlugin.d.ts +8 -8
- package/dist/plugins/wss/wssPlugin.js +37 -42
- package/dist/types.d.ts +6 -6
- package/dist/types.js +8 -18
- package/package.json +4 -8
- package/CHANGELOG.md +0 -160
- package/dist/createServer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/plugins/api/apiPlugin.js.map +0 -1
- package/dist/plugins/api/index.js.map +0 -1
- package/dist/plugins/compiler/compilerPlugin.js.map +0 -1
- package/dist/plugins/compiler/index.js.map +0 -1
- package/dist/plugins/compiler/types.js.map +0 -1
- package/dist/plugins/devtools/devtoolsPlugin.js.map +0 -1
- package/dist/plugins/devtools/index.js.map +0 -1
- package/dist/plugins/favicon/faviconPlugin.js.map +0 -1
- package/dist/plugins/favicon/index.js.map +0 -1
- package/dist/plugins/multipart/index.js.map +0 -1
- package/dist/plugins/multipart/multipartPlugin.js.map +0 -1
- package/dist/plugins/multipart/types.js.map +0 -1
- package/dist/plugins/symbolicate/Symbolicator.js.map +0 -1
- package/dist/plugins/symbolicate/index.js.map +0 -1
- package/dist/plugins/symbolicate/sybmolicatePlugin.js.map +0 -1
- package/dist/plugins/symbolicate/types.js.map +0 -1
- package/dist/plugins/wss/WebSocketRouter.js.map +0 -1
- package/dist/plugins/wss/WebSocketServer.js.map +0 -1
- package/dist/plugins/wss/WebSocketServerAdapter.js.map +0 -1
- package/dist/plugins/wss/index.js.map +0 -1
- package/dist/plugins/wss/servers/WebSocketApiServer.js.map +0 -1
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js.map +0 -1
- package/dist/plugins/wss/servers/WebSocketEventsServer.js.map +0 -1
- package/dist/plugins/wss/servers/WebSocketHMRServer.js.map +0 -1
- package/dist/plugins/wss/servers/WebSocketMessageServer.js.map +0 -1
- package/dist/plugins/wss/types.js.map +0 -1
- package/dist/plugins/wss/wssPlugin.js.map +0 -1
- package/dist/types.js.map +0 -1
- /package/{dist/img → static}/favicon.ico +0 -0
package/dist/createServer.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Fastify from 'fastify';
|
|
2
|
+
import { type Server } from './types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Create instance of development server, powered by Fastify.
|
|
4
5
|
*
|
|
@@ -8,5 +9,5 @@ import { type Server } from './types';
|
|
|
8
9
|
export declare function createServer(config: Server.Config): Promise<{
|
|
9
10
|
start: () => Promise<void>;
|
|
10
11
|
stop: () => Promise<void>;
|
|
11
|
-
instance:
|
|
12
|
+
instance: Fastify.FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, Fastify.FastifyBaseLogger, Fastify.FastifyTypeProviderDefault> & PromiseLike<Fastify.FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, Fastify.FastifyBaseLogger, Fastify.FastifyTypeProviderDefault>>;
|
|
12
13
|
}>;
|
package/dist/createServer.js
CHANGED
|
@@ -3,14 +3,14 @@ import middie from '@fastify/middie';
|
|
|
3
3
|
import fastifySensible from '@fastify/sensible';
|
|
4
4
|
import { createDevMiddleware } from '@react-native/dev-middleware';
|
|
5
5
|
import Fastify from 'fastify';
|
|
6
|
-
import apiPlugin from
|
|
7
|
-
import compilerPlugin from
|
|
8
|
-
import devtoolsPlugin from
|
|
9
|
-
import faviconPlugin from
|
|
10
|
-
import multipartPlugin from
|
|
11
|
-
import symbolicatePlugin from
|
|
12
|
-
import wssPlugin from
|
|
13
|
-
import { Internal } from
|
|
6
|
+
import apiPlugin from './plugins/api/apiPlugin.js';
|
|
7
|
+
import compilerPlugin from './plugins/compiler/compilerPlugin.js';
|
|
8
|
+
import devtoolsPlugin from './plugins/devtools/devtoolsPlugin.js';
|
|
9
|
+
import faviconPlugin from './plugins/favicon/faviconPlugin.js';
|
|
10
|
+
import multipartPlugin from './plugins/multipart/multipartPlugin.js';
|
|
11
|
+
import symbolicatePlugin from './plugins/symbolicate/sybmolicatePlugin.js';
|
|
12
|
+
import wssPlugin from './plugins/wss/wssPlugin.js';
|
|
13
|
+
import { Internal } from './types.js';
|
|
14
14
|
/**
|
|
15
15
|
* Create instance of development server, powered by Fastify.
|
|
16
16
|
*
|
|
@@ -18,122 +18,109 @@ import { Internal } from "./types.js";
|
|
|
18
18
|
* @returns `start` and `stop` functions as well as an underlying Fastify `instance`.
|
|
19
19
|
*/
|
|
20
20
|
export async function createServer(config) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
21
|
+
// biome-ignore lint/style/useConst: needed in fastify constructor
|
|
22
|
+
let delegate;
|
|
23
|
+
/** Fastify instance powering the development server. */
|
|
24
|
+
const instance = Fastify({
|
|
25
|
+
disableRequestLogging: !config.options.logRequests,
|
|
26
|
+
logger: {
|
|
27
|
+
level: 'trace',
|
|
28
|
+
stream: new Writable({
|
|
29
|
+
write: (chunk, _encoding, callback) => {
|
|
30
|
+
const log = JSON.parse(chunk.toString());
|
|
31
|
+
delegate?.logger.onMessage(log);
|
|
32
|
+
instance.wss?.apiServer.send(log);
|
|
33
|
+
callback();
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
},
|
|
37
|
+
...(config.options.https ? { https: config.options.https } : undefined),
|
|
38
|
+
});
|
|
39
|
+
delegate = await config.delegate({
|
|
40
|
+
log: instance.log,
|
|
41
|
+
notifyBuildStart: (platform) => {
|
|
42
|
+
instance.wss.apiServer.send({
|
|
43
|
+
event: Internal.EventTypes.BuildStart,
|
|
44
|
+
platform,
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
notifyBuildEnd: (platform) => {
|
|
48
|
+
instance.wss.apiServer.send({
|
|
49
|
+
event: Internal.EventTypes.BuildEnd,
|
|
50
|
+
platform,
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
broadcastToHmrClients: (event, platform, clientIds) => {
|
|
54
|
+
instance.wss.hmrServer.send(event, platform, clientIds);
|
|
55
|
+
},
|
|
56
|
+
broadcastToMessageClients: ({ method, params }) => {
|
|
57
|
+
instance.wss.messageServer.broadcast(method, params);
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
const devMiddleware = createDevMiddleware({
|
|
61
|
+
projectRoot: config.options.rootDir,
|
|
62
|
+
serverBaseUrl: `http://${config.options.host}:${config.options.port}`,
|
|
63
|
+
logger: instance.log,
|
|
64
|
+
unstable_experiments: {
|
|
65
|
+
// @ts-expect-error removed in 0.76, keep this for backkwards compatibility
|
|
66
|
+
enableNewDebugger: true,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
// Register plugins
|
|
70
|
+
await instance.register(fastifySensible);
|
|
71
|
+
await instance.register(middie);
|
|
72
|
+
await instance.register(wssPlugin, {
|
|
73
|
+
options: {
|
|
74
|
+
...config.options,
|
|
75
|
+
endpoints: devMiddleware.websocketEndpoints,
|
|
76
|
+
},
|
|
77
|
+
delegate,
|
|
78
|
+
});
|
|
79
|
+
await instance.register(multipartPlugin);
|
|
80
|
+
await instance.register(apiPlugin, {
|
|
81
|
+
delegate,
|
|
82
|
+
prefix: '/api',
|
|
83
|
+
});
|
|
84
|
+
await instance.register(compilerPlugin, {
|
|
85
|
+
delegate,
|
|
86
|
+
});
|
|
87
|
+
await instance.register(devtoolsPlugin, {
|
|
88
|
+
options: config.options,
|
|
89
|
+
});
|
|
90
|
+
await instance.register(symbolicatePlugin, {
|
|
91
|
+
delegate,
|
|
92
|
+
});
|
|
93
|
+
// below is to prevent showing `GET 400 /favicon.ico`
|
|
94
|
+
// errors in console when requesting the bundle via browser
|
|
95
|
+
await instance.register(faviconPlugin);
|
|
96
|
+
instance.addHook('onSend', async (request, reply, payload) => {
|
|
97
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
98
|
+
reply.header('X-React-Native-Project-Root', config.options.rootDir);
|
|
99
|
+
const [pathname] = request.url.split('?');
|
|
100
|
+
if (pathname.endsWith('.map')) {
|
|
101
|
+
reply.header('Access-Control-Allow-Origin', 'devtools://devtools');
|
|
35
102
|
}
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
notifyBuildEnd: platform => {
|
|
51
|
-
instance.wss.apiServer.send({
|
|
52
|
-
event: Internal.EventTypes.BuildEnd,
|
|
53
|
-
platform
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
broadcastToHmrClients: (event, platform, clientIds) => {
|
|
57
|
-
instance.wss.hmrServer.send(event, platform, clientIds);
|
|
58
|
-
},
|
|
59
|
-
broadcastToMessageClients: ({
|
|
60
|
-
method,
|
|
61
|
-
params
|
|
62
|
-
}) => {
|
|
63
|
-
instance.wss.messageServer.broadcast(method, params);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
const devMiddleware = createDevMiddleware({
|
|
67
|
-
projectRoot: config.options.rootDir,
|
|
68
|
-
serverBaseUrl: `http://${config.options.host}:${config.options.port}`,
|
|
69
|
-
logger: instance.log,
|
|
70
|
-
unstable_experiments: {
|
|
71
|
-
// @ts-expect-error removed in 0.76, keep this for backkwards compatibility
|
|
72
|
-
enableNewDebugger: true
|
|
103
|
+
return payload;
|
|
104
|
+
});
|
|
105
|
+
// Register dev middleware
|
|
106
|
+
instance.use(devMiddleware.middleware);
|
|
107
|
+
// Register routes
|
|
108
|
+
instance.get('/', async () => delegate.messages.getHello());
|
|
109
|
+
instance.get('/status', async () => delegate.messages.getStatus());
|
|
110
|
+
/** Start the development server. */
|
|
111
|
+
async function start() {
|
|
112
|
+
await instance.listen({
|
|
113
|
+
port: config.options.port,
|
|
114
|
+
host: config.options.host,
|
|
115
|
+
});
|
|
73
116
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
await instance.register(fastifySensible);
|
|
78
|
-
await instance.register(middie);
|
|
79
|
-
await instance.register(wssPlugin, {
|
|
80
|
-
options: {
|
|
81
|
-
...config.options,
|
|
82
|
-
endpoints: devMiddleware.websocketEndpoints
|
|
83
|
-
},
|
|
84
|
-
delegate
|
|
85
|
-
});
|
|
86
|
-
await instance.register(multipartPlugin);
|
|
87
|
-
await instance.register(apiPlugin, {
|
|
88
|
-
delegate,
|
|
89
|
-
prefix: '/api'
|
|
90
|
-
});
|
|
91
|
-
await instance.register(compilerPlugin, {
|
|
92
|
-
delegate
|
|
93
|
-
});
|
|
94
|
-
await instance.register(devtoolsPlugin, {
|
|
95
|
-
options: config.options
|
|
96
|
-
});
|
|
97
|
-
await instance.register(symbolicatePlugin, {
|
|
98
|
-
delegate
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// below is to prevent showing `GET 400 /favicon.ico`
|
|
102
|
-
// errors in console when requesting the bundle via browser
|
|
103
|
-
await instance.register(faviconPlugin);
|
|
104
|
-
instance.addHook('onSend', async (request, reply, payload) => {
|
|
105
|
-
reply.header('X-Content-Type-Options', 'nosniff');
|
|
106
|
-
reply.header('X-React-Native-Project-Root', config.options.rootDir);
|
|
107
|
-
const [pathname] = request.url.split('?');
|
|
108
|
-
if (pathname.endsWith('.map')) {
|
|
109
|
-
reply.header('Access-Control-Allow-Origin', 'devtools://devtools');
|
|
117
|
+
/** Stop the development server. */
|
|
118
|
+
async function stop() {
|
|
119
|
+
await instance.close();
|
|
110
120
|
}
|
|
111
|
-
return
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
// Register routes
|
|
118
|
-
instance.get('/', async () => delegate.messages.getHello());
|
|
119
|
-
instance.get('/status', async () => delegate.messages.getStatus());
|
|
120
|
-
|
|
121
|
-
/** Start the development server. */
|
|
122
|
-
async function start() {
|
|
123
|
-
await instance.listen({
|
|
124
|
-
port: config.options.port,
|
|
125
|
-
host: config.options.host
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/** Stop the development server. */
|
|
130
|
-
async function stop() {
|
|
131
|
-
await instance.close();
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
start,
|
|
135
|
-
stop,
|
|
136
|
-
instance
|
|
137
|
-
};
|
|
121
|
+
return {
|
|
122
|
+
start,
|
|
123
|
+
stop,
|
|
124
|
+
instance,
|
|
125
|
+
};
|
|
138
126
|
}
|
|
139
|
-
//# sourceMappingURL=createServer.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './createServer';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export * from './createServer.js';
|
|
2
|
+
export * from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from './createServer.js';
|
|
2
|
+
export * from './types.js';
|
|
@@ -1,32 +1,25 @@
|
|
|
1
1
|
const paramsSchema = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
type: 'object',
|
|
3
|
+
properties: {
|
|
4
|
+
platform: {
|
|
5
|
+
type: 'string',
|
|
6
|
+
},
|
|
7
|
+
},
|
|
8
|
+
required: ['platform'],
|
|
9
9
|
};
|
|
10
|
-
async function apiPlugin(instance, {
|
|
11
|
-
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
schema: {
|
|
25
|
-
params: paramsSchema
|
|
26
|
-
}
|
|
27
|
-
}, async (request, reply) => delegate.api ? reply.send({
|
|
28
|
-
data: await delegate.api?.getCompilationStats(request.params.platform)
|
|
29
|
-
}) : reply.notImplemented('Missing API delegate implementation'));
|
|
10
|
+
async function apiPlugin(instance, { delegate }) {
|
|
11
|
+
instance.get('/platforms', async (_request, reply) => delegate.api
|
|
12
|
+
? reply.send({ data: await delegate.api.getPlatforms() })
|
|
13
|
+
: reply.notImplemented('Missing API delegate implementation'));
|
|
14
|
+
instance.get('/:platform/assets', { schema: { params: paramsSchema } }, async (request, reply) => delegate.api
|
|
15
|
+
? reply.send({
|
|
16
|
+
data: await delegate.api.getAssets(request.params.platform),
|
|
17
|
+
})
|
|
18
|
+
: reply.notImplemented('Missing API delegate implementation'));
|
|
19
|
+
instance.get('/:platform/stats', { schema: { params: paramsSchema } }, async (request, reply) => delegate.api
|
|
20
|
+
? reply.send({
|
|
21
|
+
data: await delegate.api?.getCompilationStats(request.params.platform),
|
|
22
|
+
})
|
|
23
|
+
: reply.notImplemented('Missing API delegate implementation'));
|
|
30
24
|
}
|
|
31
25
|
export default apiPlugin;
|
|
32
|
-
//# sourceMappingURL=apiPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './apiPlugin';
|
|
1
|
+
export { default } from './apiPlugin.js';
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { default } from
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { default } from './apiPlugin.js';
|
|
@@ -1,66 +1,57 @@
|
|
|
1
1
|
import fastifyPlugin from 'fastify-plugin';
|
|
2
|
-
async function compilerPlugin(instance, {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return reply.code(200).type(mimeType).send(asset);
|
|
54
|
-
}
|
|
55
|
-
} catch (error) {
|
|
56
|
-
request.log.error(error);
|
|
57
|
-
return reply.notFound(error.message);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
2
|
+
async function compilerPlugin(instance, { delegate }) {
|
|
3
|
+
instance.route({
|
|
4
|
+
method: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'],
|
|
5
|
+
url: '/*',
|
|
6
|
+
schema: {
|
|
7
|
+
querystring: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
platform: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
handler: async (request, reply) => {
|
|
17
|
+
const filename = request.params['*'];
|
|
18
|
+
let { platform } = request.query;
|
|
19
|
+
if (!filename) {
|
|
20
|
+
// This technically should never happen - this route should not be called if file is missing.
|
|
21
|
+
request.log.error('File was not provided');
|
|
22
|
+
return reply.notFound();
|
|
23
|
+
}
|
|
24
|
+
// Let consumer infer the platform. If function is not provided fallback
|
|
25
|
+
// to platform query param.
|
|
26
|
+
platform = delegate.compiler.inferPlatform?.(request.url) ?? platform;
|
|
27
|
+
const multipart = reply.asMultipart();
|
|
28
|
+
const sendProgress = ({ completed, total }) => {
|
|
29
|
+
multipart?.writeChunk({ 'Content-Type': 'application/json' }, JSON.stringify({
|
|
30
|
+
done: completed,
|
|
31
|
+
total,
|
|
32
|
+
}));
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
const asset = await delegate.compiler.getAsset(filename, platform, sendProgress);
|
|
36
|
+
const mimeType = delegate.compiler.getMimeType(filename, platform, asset);
|
|
37
|
+
if (multipart) {
|
|
38
|
+
const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);
|
|
39
|
+
multipart.setHeader('Content-Type', `${mimeType}; charset=UTF-8`);
|
|
40
|
+
multipart.setHeader('Content-Length', String(Buffer.byteLength(buffer)));
|
|
41
|
+
multipart.end(buffer);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return reply.code(200).type(mimeType).send(asset);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
request.log.error(error);
|
|
49
|
+
return reply.notFound(error.message);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
});
|
|
61
53
|
}
|
|
62
54
|
export default fastifyPlugin(compilerPlugin, {
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
name: 'compiler-plugin',
|
|
56
|
+
dependencies: ['@fastify/sensible', 'multipart-plugin'],
|
|
65
57
|
});
|
|
66
|
-
//# sourceMappingURL=compilerPlugin.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from './compilerPlugin';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export { default } from './compilerPlugin.js';
|
|
2
|
+
export * from './types.js';
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export { default } from
|
|
2
|
-
export * from
|
|
3
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { default } from './compilerPlugin.js';
|
|
2
|
+
export * from './types.js';
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import { openStackFrameInEditorMiddleware, openURLMiddleware } from '@react-native-community/cli-server-api';
|
|
1
|
+
import { openStackFrameInEditorMiddleware, openURLMiddleware, } from '@react-native-community/cli-server-api';
|
|
2
2
|
import fastifyPlugin from 'fastify-plugin';
|
|
3
|
-
async function devtoolsPlugin(instance, {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
});
|
|
3
|
+
async function devtoolsPlugin(instance, { options }) {
|
|
4
|
+
instance.use('/open-url', openURLMiddleware);
|
|
5
|
+
instance.use('/open-stack-frame', openStackFrameInEditorMiddleware({
|
|
6
|
+
watchFolders: [options.rootDir],
|
|
7
|
+
}));
|
|
8
|
+
instance.route({
|
|
9
|
+
method: ['GET', 'POST', 'PUT'],
|
|
10
|
+
url: '/reload',
|
|
11
|
+
handler: (_request, reply) => {
|
|
12
|
+
instance.wss.messageServer.broadcast('reload');
|
|
13
|
+
reply.send('OK');
|
|
14
|
+
},
|
|
15
|
+
});
|
|
18
16
|
}
|
|
19
17
|
export default fastifyPlugin(devtoolsPlugin, {
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
name: 'devtools-plugin',
|
|
19
|
+
dependencies: ['wss-plugin'],
|
|
22
20
|
});
|
|
23
|
-
//# sourceMappingURL=devtoolsPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './devtoolsPlugin';
|
|
1
|
+
export { default } from './devtoolsPlugin.js';
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { default } from
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { default } from './devtoolsPlugin.js';
|
|
@@ -2,16 +2,12 @@ import path from 'node:path';
|
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import fastifyFavicon from 'fastify-favicon';
|
|
4
4
|
import fastifyPlugin from 'fastify-plugin';
|
|
5
|
-
|
|
6
5
|
// @ts-ignore
|
|
7
6
|
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
const pathToImgDir = path.join(dirname, '
|
|
7
|
+
const pathToImgDir = path.join(dirname, '../../../static');
|
|
9
8
|
async function faviconPlugin(instance) {
|
|
10
|
-
|
|
11
|
-
path: pathToImgDir
|
|
12
|
-
});
|
|
9
|
+
instance.register(fastifyFavicon, { path: pathToImgDir });
|
|
13
10
|
}
|
|
14
11
|
export default fastifyPlugin(faviconPlugin, {
|
|
15
|
-
|
|
12
|
+
name: 'favicon-plugin',
|
|
16
13
|
});
|
|
17
|
-
//# sourceMappingURL=faviconPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './faviconPlugin';
|
|
1
|
+
export { default } from './faviconPlugin.js';
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { default } from
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { default } from './faviconPlugin.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from './multipartPlugin';
|
|
2
|
-
export * from './types';
|
|
1
|
+
export { default } from './multipartPlugin.js';
|
|
2
|
+
export * from './types.js';
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export { default } from
|
|
2
|
-
export * from
|
|
3
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { default } from './multipartPlugin.js';
|
|
2
|
+
export * from './types.js';
|