@callstack/repack-dev-server 5.0.0-rc.0 → 5.0.0-rc.10

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