@vxrn/vite-plugin-metro 1.2.33 → 1.2.34
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/cjs/plugins/metroPlugin.cjs +48 -22
- package/dist/cjs/plugins/metroPlugin.js +41 -20
- package/dist/cjs/plugins/metroPlugin.js.map +1 -1
- package/dist/cjs/plugins/metroPlugin.native.js +81 -55
- package/dist/cjs/plugins/metroPlugin.native.js.map +1 -1
- package/dist/esm/plugins/metroPlugin.js +41 -19
- package/dist/esm/plugins/metroPlugin.js.map +1 -1
- package/dist/esm/plugins/metroPlugin.mjs +48 -22
- package/dist/esm/plugins/metroPlugin.mjs.map +1 -1
- package/dist/esm/plugins/metroPlugin.native.js +80 -54
- package/dist/esm/plugins/metroPlugin.native.js.map +1 -1
- package/package.json +2 -2
- package/src/plugins/metroPlugin.ts +99 -57
- package/types/plugins/metroPlugin.d.ts.map +1 -1
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import launchEditor from "launch-editor";
|
|
4
|
+
import { createDebugger } from "@vxrn/debug";
|
|
4
5
|
import { projectImport } from "../utils/projectImport.mjs";
|
|
5
6
|
import { getMetroConfigFromViteConfig } from "../metro-config/getMetroConfigFromViteConfig.mjs";
|
|
6
7
|
import { patchMetroServerWithViteConfigAndMetroPluginOptions } from "../metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.mjs";
|
|
8
|
+
const {
|
|
9
|
+
debug
|
|
10
|
+
} = createDebugger("vite-plugin-metro");
|
|
7
11
|
function metroPlugin(options = {}) {
|
|
8
12
|
return globalThis.__viteMetroPluginOptions__ = options, {
|
|
9
13
|
name: "metro",
|
|
@@ -12,16 +16,24 @@ function metroPlugin(options = {}) {
|
|
|
12
16
|
// },
|
|
13
17
|
configureServer(server) {
|
|
14
18
|
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
metroStartTime = Date.now();
|
|
19
|
+
root: projectRoot
|
|
20
|
+
} = server.config;
|
|
18
21
|
let metroReady = !1,
|
|
19
22
|
middleware,
|
|
20
23
|
metroServer,
|
|
21
24
|
hmrServer,
|
|
22
25
|
websocketEndpoints,
|
|
23
|
-
rnDevtoolsMiddleware
|
|
24
|
-
|
|
26
|
+
rnDevtoolsMiddleware,
|
|
27
|
+
metroPromise,
|
|
28
|
+
metroPromiseResolvers;
|
|
29
|
+
metroPromise = new Promise((resolve, reject) => {
|
|
30
|
+
metroPromiseResolvers = {
|
|
31
|
+
resolve,
|
|
32
|
+
reject
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
const startMetro = async () => {
|
|
36
|
+
const metroStartTime = Date.now();
|
|
25
37
|
try {
|
|
26
38
|
const {
|
|
27
39
|
default: Metro
|
|
@@ -53,28 +65,42 @@ function metroPlugin(options = {}) {
|
|
|
53
65
|
websocketServer: hmrServer
|
|
54
66
|
}),
|
|
55
67
|
...devMiddleware.websocketEndpoints
|
|
56
|
-
},
|
|
68
|
+
}, server.httpServer?.on("upgrade", (request, socket, head) => {
|
|
69
|
+
const pathname = new URL(request.url, `http://${request.headers.host}`).pathname;
|
|
70
|
+
websocketEndpoints[pathname] && websocketEndpoints[pathname].handleUpgrade(request, socket, head, ws => {
|
|
71
|
+
websocketEndpoints[pathname].emit("connection", ws, request);
|
|
72
|
+
});
|
|
73
|
+
}), server.middlewares.use(rnDevtoolsMiddleware), metroReady = !0;
|
|
57
74
|
const metroElapsed = Date.now() - metroStartTime;
|
|
58
|
-
|
|
75
|
+
debug?.(`Metro bundler ready (${metroElapsed}ms)`), metroPromiseResolvers.resolve();
|
|
59
76
|
} catch (err) {
|
|
60
|
-
throw
|
|
77
|
+
throw debug?.(`Error during Metro initialization: ${err}`), metroPromiseResolvers.reject(err), err;
|
|
61
78
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
};
|
|
80
|
+
if (server.httpServer) server.httpServer.listening ? startMetro().catch(err => {
|
|
81
|
+
debug?.(`Failed to start Metro: ${err}`);
|
|
82
|
+
}) : server.httpServer.on("listening", () => {
|
|
83
|
+
startMetro().catch(err => {
|
|
84
|
+
debug?.(`Failed to start Metro: ${err}`);
|
|
85
|
+
});
|
|
86
|
+
});else {
|
|
87
|
+
const waitForServer = () => {
|
|
88
|
+
server.httpServer ? server.httpServer.listening ? startMetro().catch(err => {
|
|
89
|
+
debug?.(`Failed to start Metro: ${err}`);
|
|
90
|
+
}) : server.httpServer.on("listening", () => {
|
|
91
|
+
startMetro().catch(err => {
|
|
92
|
+
debug?.(`Failed to start Metro: ${err}`);
|
|
93
|
+
});
|
|
94
|
+
}) : setTimeout(waitForServer, 10);
|
|
95
|
+
};
|
|
96
|
+
waitForServer();
|
|
97
|
+
}
|
|
98
|
+
server.middlewares.use(async (req, res, next) => {
|
|
73
99
|
if (req.url?.includes(".bundle") && !metroReady && (await metroPromise), middleware) try {
|
|
74
100
|
if (req.url?.includes(".bundle")) {
|
|
75
101
|
const VITE_METRO_DEBUG_BUNDLE = process.env.VITE_METRO_DEBUG_BUNDLE;
|
|
76
102
|
if (VITE_METRO_DEBUG_BUNDLE && existsSync(VITE_METRO_DEBUG_BUNDLE)) {
|
|
77
|
-
|
|
103
|
+
debug?.(`serving debug bundle from ${VITE_METRO_DEBUG_BUNDLE}`);
|
|
78
104
|
const content = await readFile(VITE_METRO_DEBUG_BUNDLE, "utf-8");
|
|
79
105
|
res.setHeader("Content-Type", "application/javascript"), res.end(content);
|
|
80
106
|
return;
|
|
@@ -98,14 +124,14 @@ function metroPlugin(options = {}) {
|
|
|
98
124
|
const frame = JSON.parse(body);
|
|
99
125
|
launchEditor(frame.file), res.statusCode = 200, res.end("Stack frame opened in editor");
|
|
100
126
|
} catch (e) {
|
|
101
|
-
return
|
|
127
|
+
return debug?.(`Failed to parse stack frame: ${e}`), res.statusCode = 400, res.end("Invalid stack frame JSON");
|
|
102
128
|
}
|
|
103
129
|
});
|
|
104
130
|
return;
|
|
105
131
|
}
|
|
106
132
|
await middleware(req, res, next);
|
|
107
133
|
} catch (error) {
|
|
108
|
-
|
|
134
|
+
debug?.(`Metro middleware error: ${error}`), next();
|
|
109
135
|
} else next();
|
|
110
136
|
});
|
|
111
137
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["existsSync","readFile","launchEditor","projectImport","getMetroConfigFromViteConfig","patchMetroServerWithViteConfigAndMetroPluginOptions","metroPlugin","options","globalThis","__viteMetroPluginOptions__","name","configureServer","server","root","projectRoot","config","
|
|
1
|
+
{"version":3,"names":["existsSync","readFile","launchEditor","createDebugger","projectImport","getMetroConfigFromViteConfig","patchMetroServerWithViteConfigAndMetroPluginOptions","debug","metroPlugin","options","globalThis","__viteMetroPluginOptions__","name","configureServer","server","root","projectRoot","config","metroReady","middleware","metroServer","hmrServer","websocketEndpoints","rnDevtoolsMiddleware","metroPromise","metroPromiseResolvers","Promise","resolve","reject","startMetro","metroStartTime","Date","now","default","Metro","MetroHmrServer","createWebsocketServer","createDevMiddleware","metroResult","createConnectMiddleware","watch","getBundler","getCreateModuleId","reactNativeDevToolsUrl","host","port","devMiddleware","serverBaseUrl","logger","console","websocketServer","httpServer","on","request","socket","head","pathname","URL","url","headers","handleUpgrade","ws","emit","middlewares","use","metroElapsed","err","listening","catch","waitForServer","setTimeout","req","res","next","includes","VITE_METRO_DEBUG_BUNDLE","process","env","content","setHeader","end","statusCode","method","body","chunk","toString","frame","JSON","parse","file","e","error"],"sources":["../../../src/plugins/metroPlugin.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAC3B,SAASC,QAAA,QAAgB;AAEzB,OAAOC,YAAA,MAAkB;AACzB,SAASC,cAAA,QAAsB;AAa/B,SAASC,aAAA,QAAqB;AAE9B,SAASC,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AaoF,KAAA,CAAMG,IAAI,GACvBjB,GAAA,CAAIS,UAAA,GAAa,KACjBT,GAAA,CAAIQ,GAAA,CAAI,8BAA8B;cACxC,SAASU,CAAA,EAAG;gBACV,OAAAnF,KAAA,GAAQ,gCAAgCmF,CAAC,EAAE,GAC3ClB,GAAA,CAAIS,UAAA,GAAa,KACVT,GAAA,CAAIQ,GAAA,CAAI,0BAA0B;cAC3C;YACF,CAAC;YAED;UACF;UAGA,MAAO7D,UAAA,CAAmBoD,GAAA,EAAKC,GAAA,EAAKC,IAAI;QAC1C,SAASkB,KAAA,EAAO;UACdpF,KAAA,GAAQ,2BAA2BoF,KAAK,EAAE,GAC1ClB,IAAA,CAAK;QACP,OAGAA,IAAA,CAAK;MAET,CAAC;IACH;EACF;AACF","ignoreList":[]}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { existsSync } from "fs";
|
|
2
2
|
import { readFile } from "fs/promises";
|
|
3
3
|
import launchEditor from "launch-editor";
|
|
4
|
+
import { createDebugger } from "@vxrn/debug";
|
|
4
5
|
import { projectImport } from "../utils/projectImport.native.js";
|
|
5
6
|
import { getMetroConfigFromViteConfig } from "../metro-config/getMetroConfigFromViteConfig.native.js";
|
|
6
7
|
import { patchMetroServerWithViteConfigAndMetroPluginOptions } from "../metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js";
|
|
8
|
+
var {
|
|
9
|
+
debug
|
|
10
|
+
} = createDebugger("vite-plugin-metro");
|
|
7
11
|
function metroPlugin() {
|
|
8
12
|
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
9
13
|
return globalThis.__viteMetroPluginOptions__ = options, {
|
|
@@ -15,70 +19,92 @@ function metroPlugin() {
|
|
|
15
19
|
var {
|
|
16
20
|
root: projectRoot
|
|
17
21
|
} = server.config,
|
|
18
|
-
metroStartTime = Date.now(),
|
|
19
22
|
metroReady = !1,
|
|
20
23
|
middleware,
|
|
21
24
|
metroServer,
|
|
22
25
|
hmrServer,
|
|
23
26
|
websocketEndpoints,
|
|
24
27
|
rnDevtoolsMiddleware,
|
|
25
|
-
metroPromise
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
|
|
28
|
+
metroPromise,
|
|
29
|
+
metroPromiseResolvers;
|
|
30
|
+
metroPromise = new Promise(function (resolve, reject) {
|
|
31
|
+
metroPromiseResolvers = {
|
|
32
|
+
resolve,
|
|
33
|
+
reject
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
var startMetro = async function () {
|
|
37
|
+
var metroStartTime = Date.now();
|
|
38
|
+
try {
|
|
39
|
+
var _server_httpServer,
|
|
40
|
+
{
|
|
41
|
+
default: Metro
|
|
42
|
+
} = await projectImport(projectRoot, "metro"),
|
|
43
|
+
{
|
|
44
|
+
default: MetroHmrServer
|
|
45
|
+
} = await projectImport(projectRoot, "metro/private/HmrServer"),
|
|
46
|
+
{
|
|
47
|
+
default: createWebsocketServer
|
|
48
|
+
} = await projectImport(projectRoot, "metro/private/lib/createWebsocketServer"),
|
|
49
|
+
{
|
|
50
|
+
createDevMiddleware
|
|
51
|
+
} = await projectImport(projectRoot, "@react-native/dev-middleware"),
|
|
52
|
+
config = await getMetroConfigFromViteConfig(server.config, options),
|
|
53
|
+
metroResult = await Metro.createConnectMiddleware(config, {
|
|
54
|
+
// Force enable file watching, even on CI.
|
|
55
|
+
// This is needed for HMR tests to work on CI.
|
|
56
|
+
watch: !0
|
|
57
|
+
});
|
|
58
|
+
middleware = metroResult.middleware, metroServer = metroResult.metroServer, patchMetroServerWithViteConfigAndMetroPluginOptions(metroServer, server.config, options), hmrServer = new MetroHmrServer(metroServer.getBundler(), metroServer.getCreateModuleId(), config);
|
|
59
|
+
var reactNativeDevToolsUrl = `http://${typeof server.config.server.host == "boolean" ? "localhost" : server.config.server.host}:${server.config.server.port}`,
|
|
60
|
+
devMiddleware = createDevMiddleware({
|
|
61
|
+
projectRoot,
|
|
62
|
+
serverBaseUrl: reactNativeDevToolsUrl,
|
|
63
|
+
logger: console
|
|
64
|
+
});
|
|
65
|
+
rnDevtoolsMiddleware = devMiddleware.middleware, websocketEndpoints = {
|
|
66
|
+
"/hot": createWebsocketServer({
|
|
67
|
+
websocketServer: hmrServer
|
|
68
|
+
}),
|
|
69
|
+
...devMiddleware.websocketEndpoints
|
|
70
|
+
}, (_server_httpServer = server.httpServer) === null || _server_httpServer === void 0 || _server_httpServer.on("upgrade", function (request, socket, head) {
|
|
71
|
+
var pathname = new URL(request.url, `http://${request.headers.host}`).pathname;
|
|
72
|
+
websocketEndpoints[pathname] && websocketEndpoints[pathname].handleUpgrade(request, socket, head, function (ws) {
|
|
73
|
+
websocketEndpoints[pathname].emit("connection", ws, request);
|
|
74
|
+
});
|
|
75
|
+
}), server.middlewares.use(rnDevtoolsMiddleware), metroReady = !0;
|
|
76
|
+
var metroElapsed = Date.now() - metroStartTime;
|
|
77
|
+
debug?.(`Metro bundler ready (${metroElapsed}ms)`), metroPromiseResolvers.resolve();
|
|
78
|
+
} catch (err) {
|
|
79
|
+
throw debug?.(`Error during Metro initialization: ${err}`), metroPromiseResolvers.reject(err), err;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
if (server.httpServer) server.httpServer.listening ? startMetro().catch(function (err) {
|
|
83
|
+
debug?.(`Failed to start Metro: ${err}`);
|
|
84
|
+
}) : server.httpServer.on("listening", function () {
|
|
85
|
+
startMetro().catch(function (err) {
|
|
86
|
+
debug?.(`Failed to start Metro: ${err}`);
|
|
87
|
+
});
|
|
88
|
+
});else {
|
|
89
|
+
var waitForServer = function () {
|
|
90
|
+
server.httpServer ? server.httpServer.listening ? startMetro().catch(function (err) {
|
|
91
|
+
debug?.(`Failed to start Metro: ${err}`);
|
|
92
|
+
}) : server.httpServer.on("listening", function () {
|
|
93
|
+
startMetro().catch(function (err) {
|
|
94
|
+
debug?.(`Failed to start Metro: ${err}`);
|
|
95
|
+
});
|
|
96
|
+
}) : setTimeout(waitForServer, 10);
|
|
97
|
+
};
|
|
98
|
+
waitForServer();
|
|
99
|
+
}
|
|
100
|
+
server.middlewares.use(async function (req, res, next) {
|
|
75
101
|
var _req_url;
|
|
76
102
|
if (!((_req_url = req.url) === null || _req_url === void 0) && _req_url.includes(".bundle") && !metroReady && (await metroPromise), middleware) try {
|
|
77
103
|
var _req_url1, _req_headers_useragent, _req_headers_useragent1;
|
|
78
104
|
if (!((_req_url1 = req.url) === null || _req_url1 === void 0) && _req_url1.includes(".bundle")) {
|
|
79
105
|
var VITE_METRO_DEBUG_BUNDLE = process.env.VITE_METRO_DEBUG_BUNDLE;
|
|
80
106
|
if (VITE_METRO_DEBUG_BUNDLE && existsSync(VITE_METRO_DEBUG_BUNDLE)) {
|
|
81
|
-
|
|
107
|
+
debug?.(`serving debug bundle from ${VITE_METRO_DEBUG_BUNDLE}`);
|
|
82
108
|
var content = await readFile(VITE_METRO_DEBUG_BUNDLE, "utf-8");
|
|
83
109
|
res.setHeader("Content-Type", "application/javascript"), res.end(content);
|
|
84
110
|
return;
|
|
@@ -97,14 +123,14 @@ function metroPlugin() {
|
|
|
97
123
|
var frame = JSON.parse(body);
|
|
98
124
|
launchEditor(frame.file), res.statusCode = 200, res.end("Stack frame opened in editor");
|
|
99
125
|
} catch (e) {
|
|
100
|
-
return
|
|
126
|
+
return debug?.(`Failed to parse stack frame: ${e}`), res.statusCode = 400, res.end("Invalid stack frame JSON");
|
|
101
127
|
}
|
|
102
128
|
});
|
|
103
129
|
return;
|
|
104
130
|
}
|
|
105
131
|
await middleware(req, res, next);
|
|
106
132
|
} catch (error) {
|
|
107
|
-
|
|
133
|
+
debug?.(`Metro middleware error: ${error}`), next();
|
|
108
134
|
} else next();
|
|
109
135
|
});
|
|
110
136
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["existsSync","readFile","launchEditor","projectImport","getMetroConfigFromViteConfig","patchMetroServerWithViteConfigAndMetroPluginOptions","metroPlugin","options","arguments","length","globalThis","__viteMetroPluginOptions__","name","configureServer","server","root","projectRoot","config","
|
|
1
|
+
{"version":3,"names":["existsSync","readFile","launchEditor","createDebugger","projectImport","getMetroConfigFromViteConfig","patchMetroServerWithViteConfigAndMetroPluginOptions","debug","metroPlugin","options","arguments","length","globalThis","__viteMetroPluginOptions__","name","configureServer","server","root","projectRoot","config","metroReady","middleware","metroServer","hmrServer","websocketEndpoints","rnDevtoolsMiddleware","metroPromise","metroPromiseResolvers","Promise","resolve","reject","startMetro","metroStartTime","Date","now","_server_httpServer","default","Metro","MetroHmrServer","createWebsocketServer","createDevMiddleware","metroResult","createConnectMiddleware","watch","getBundler","getCreateModuleId","reactNativeDevToolsUrl","host","port","devMiddleware","serverBaseUrl","logger","console","websocketServer","httpServer","on","request","socket","head","pathname","URL","url","headers","handleUpgrade","ws","emit","middlewares","use","metroElapsed","err","listening","catch","waitForServer","setTimeout","req","res","next","_req_url","includes","_req_url1","_req_headers_useragent","_req_headers_useragent1","VITE_METRO_DEBUG_BUNDLE","process","env","content","setHeader","end","statusCode","method","body","chunk","toString","frame","JSON","parse","file","e","error"],"sources":["../../../src/plugins/metroPlugin.ts"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AAU0F,CAAA,KAAAtB,GAAA,CAAAa,UAAA,QAAAb,GAAA,CAAAY,GAAA;cACxB;YACF,CAAC;YAGC;UACE;UAGA,MAAAlE,UAAA,CAAAqD,GAAa,EAAAC,GAAM,EAAAC,IAAI,CACvB;QACsC,SACxCsB,KAAA,EAAS;UACP3F,KAAA,8BAAQ2F,KAAA,KAAAtB,IAAA;QAEiC,OAI7CA,IAAA;MAAA;IAIF;EAAwC;AAExC;AACK,SACPpE,WAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vxrn/vite-plugin-metro",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.34",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@babel/core": "^7.28.5",
|
|
61
61
|
"@babel/helper-plugin-utils": "^7.27.1",
|
|
62
62
|
"@babel/types": "^7.28.5",
|
|
63
|
-
"@vxrn/debug": "1.2.
|
|
63
|
+
"@vxrn/debug": "1.2.34",
|
|
64
64
|
"babel-preset-expo": "*",
|
|
65
65
|
"launch-editor": "^2.10.0",
|
|
66
66
|
"micromatch": "^4.0.8",
|
|
@@ -2,6 +2,9 @@ import { existsSync } from 'node:fs'
|
|
|
2
2
|
import { readFile } from 'node:fs/promises'
|
|
3
3
|
import type { PluginOption } from 'vite'
|
|
4
4
|
import launchEditor from 'launch-editor'
|
|
5
|
+
import { createDebugger } from '@vxrn/debug'
|
|
6
|
+
|
|
7
|
+
const { debug } = createDebugger('vite-plugin-metro')
|
|
5
8
|
|
|
6
9
|
// For Metro and Expo, we only import types here.
|
|
7
10
|
// We use `projectImport` to dynamically import the actual modules
|
|
@@ -74,21 +77,28 @@ export function metroPlugin(options: MetroPluginOptions = {}): PluginOption {
|
|
|
74
77
|
configureServer(server) {
|
|
75
78
|
const { root: projectRoot } = server.config
|
|
76
79
|
|
|
77
|
-
// Track Metro startup separately from Vite
|
|
78
|
-
const metroStartTime = Date.now()
|
|
79
80
|
let metroReady = false
|
|
80
81
|
|
|
81
|
-
//
|
|
82
|
-
// All imports and config are done inside metroPromise to avoid blocking
|
|
82
|
+
// Metro state - initialized after Vite server is listening
|
|
83
83
|
let middleware: Awaited<ReturnType<typeof MetroT.createConnectMiddleware>>['middleware']
|
|
84
84
|
let metroServer: Awaited<ReturnType<typeof MetroT.createConnectMiddleware>>['metroServer']
|
|
85
85
|
let hmrServer: MetroHmrServerT
|
|
86
86
|
let websocketEndpoints: Record<string, ReturnType<typeof createWebsocketServerT>>
|
|
87
87
|
let rnDevtoolsMiddleware: ReturnType<typeof createDevMiddlewareT>['middleware']
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
let metroPromise: Promise<void>
|
|
90
|
+
let metroPromiseResolvers: { resolve: () => void; reject: (err: Error) => void }
|
|
91
|
+
|
|
92
|
+
// Create a promise that will be resolved when Metro is ready
|
|
93
|
+
// This is used by the middleware to wait for Metro on bundle requests
|
|
94
|
+
metroPromise = new Promise((resolve, reject) => {
|
|
95
|
+
metroPromiseResolvers = { resolve, reject }
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
const startMetro = async () => {
|
|
99
|
+
const metroStartTime = Date.now()
|
|
90
100
|
try {
|
|
91
|
-
// Import Metro modules lazily
|
|
101
|
+
// Import Metro modules lazily - only after Vite server is listening
|
|
92
102
|
const { default: Metro } = await projectImport<{
|
|
93
103
|
default: typeof MetroT
|
|
94
104
|
}>(projectRoot, 'metro')
|
|
@@ -111,61 +121,94 @@ export function metroPlugin(options: MetroPluginOptions = {}): PluginOption {
|
|
|
111
121
|
watch: true,
|
|
112
122
|
})
|
|
113
123
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
124
|
+
middleware = metroResult.middleware
|
|
125
|
+
metroServer = metroResult.metroServer
|
|
126
|
+
|
|
127
|
+
patchMetroServerWithViteConfigAndMetroPluginOptions(metroServer, server.config, options)
|
|
128
|
+
|
|
129
|
+
hmrServer = new MetroHmrServer(
|
|
130
|
+
metroServer.getBundler(),
|
|
131
|
+
metroServer.getCreateModuleId(),
|
|
132
|
+
config
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
const reactNativeDevToolsUrl = `http://${typeof server.config.server.host === 'boolean' ? 'localhost' : server.config.server.host}:${server.config.server.port}`
|
|
136
|
+
const devMiddleware = createDevMiddleware({
|
|
137
|
+
projectRoot,
|
|
138
|
+
serverBaseUrl: reactNativeDevToolsUrl,
|
|
139
|
+
logger: console,
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
rnDevtoolsMiddleware = devMiddleware.middleware
|
|
143
|
+
websocketEndpoints = {
|
|
144
|
+
'/hot': createWebsocketServer({
|
|
145
|
+
websocketServer: hmrServer,
|
|
146
|
+
}),
|
|
147
|
+
...devMiddleware.websocketEndpoints,
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Setup websocket handling
|
|
151
|
+
server.httpServer?.on('upgrade', (request, socket, head) => {
|
|
152
|
+
const pathname = new URL(request.url!, `http://${request.headers.host}`).pathname
|
|
153
|
+
|
|
154
|
+
if (websocketEndpoints[pathname]) {
|
|
155
|
+
websocketEndpoints[pathname].handleUpgrade(request, socket, head, (ws) => {
|
|
156
|
+
websocketEndpoints[pathname].emit('connection', ws, request)
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
// Insert devtools middleware
|
|
162
|
+
server.middlewares.use(rnDevtoolsMiddleware)
|
|
139
163
|
|
|
140
164
|
metroReady = true
|
|
141
165
|
const metroElapsed = Date.now() - metroStartTime
|
|
142
|
-
|
|
166
|
+
debug?.(`Metro bundler ready (${metroElapsed}ms)`)
|
|
167
|
+
metroPromiseResolvers.resolve()
|
|
143
168
|
} catch (err) {
|
|
144
|
-
|
|
169
|
+
debug?.(`Error during Metro initialization: ${err}`)
|
|
170
|
+
metroPromiseResolvers.reject(err as Error)
|
|
145
171
|
throw err
|
|
146
172
|
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
websocketEndpoints[pathname].emit('connection', ws, request)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Wait for Vite server to be listening before starting Metro
|
|
176
|
+
// This ensures Metro logs appear AFTER Vite's server URLs
|
|
177
|
+
if (server.httpServer) {
|
|
178
|
+
if (server.httpServer.listening) {
|
|
179
|
+
// Server is already listening (unlikely but handle it)
|
|
180
|
+
startMetro().catch((err) => {
|
|
181
|
+
debug?.(`Failed to start Metro: ${err}`)
|
|
182
|
+
})
|
|
183
|
+
} else {
|
|
184
|
+
server.httpServer.on('listening', () => {
|
|
185
|
+
startMetro().catch((err) => {
|
|
186
|
+
debug?.(`Failed to start Metro: ${err}`)
|
|
162
187
|
})
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
// No httpServer yet, wait for it via a small delay and retry
|
|
192
|
+
// This shouldn't normally happen but is a safety fallback
|
|
193
|
+
const waitForServer = () => {
|
|
194
|
+
if (server.httpServer) {
|
|
195
|
+
if (server.httpServer.listening) {
|
|
196
|
+
startMetro().catch((err) => {
|
|
197
|
+
debug?.(`Failed to start Metro: ${err}`)
|
|
198
|
+
})
|
|
199
|
+
} else {
|
|
200
|
+
server.httpServer.on('listening', () => {
|
|
201
|
+
startMetro().catch((err) => {
|
|
202
|
+
debug?.(`Failed to start Metro: ${err}`)
|
|
203
|
+
})
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
setTimeout(waitForServer, 10)
|
|
163
208
|
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
server.middlewares.use(rnDevtoolsMiddleware)
|
|
168
|
-
})
|
|
209
|
+
}
|
|
210
|
+
waitForServer()
|
|
211
|
+
}
|
|
169
212
|
|
|
170
213
|
server.middlewares.use(async (req, res, next) => {
|
|
171
214
|
// Wait for Metro if it's a bundle request and Metro isn't ready yet
|
|
@@ -181,7 +224,7 @@ export function metroPlugin(options: MetroPluginOptions = {}): PluginOption {
|
|
|
181
224
|
const VITE_METRO_DEBUG_BUNDLE = process.env.VITE_METRO_DEBUG_BUNDLE
|
|
182
225
|
if (VITE_METRO_DEBUG_BUNDLE) {
|
|
183
226
|
if (existsSync(VITE_METRO_DEBUG_BUNDLE)) {
|
|
184
|
-
|
|
227
|
+
debug?.(`serving debug bundle from ${VITE_METRO_DEBUG_BUNDLE}`)
|
|
185
228
|
const content = await readFile(VITE_METRO_DEBUG_BUNDLE, 'utf-8')
|
|
186
229
|
res.setHeader('Content-Type', 'application/javascript')
|
|
187
230
|
res.end(content)
|
|
@@ -221,7 +264,7 @@ export function metroPlugin(options: MetroPluginOptions = {}): PluginOption {
|
|
|
221
264
|
res.statusCode = 200
|
|
222
265
|
res.end('Stack frame opened in editor')
|
|
223
266
|
} catch (e) {
|
|
224
|
-
|
|
267
|
+
debug?.(`Failed to parse stack frame: ${e}`)
|
|
225
268
|
res.statusCode = 400
|
|
226
269
|
return res.end('Invalid stack frame JSON')
|
|
227
270
|
}
|
|
@@ -233,8 +276,7 @@ export function metroPlugin(options: MetroPluginOptions = {}): PluginOption {
|
|
|
233
276
|
// this is the actual Metro middleware that handles bundle requests
|
|
234
277
|
await (middleware as any)(req, res, next)
|
|
235
278
|
} catch (error) {
|
|
236
|
-
|
|
237
|
-
console.error('Metro middleware error:', error)
|
|
279
|
+
debug?.(`Metro middleware error: ${error}`)
|
|
238
280
|
next()
|
|
239
281
|
}
|
|
240
282
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metroPlugin.d.ts","sourceRoot":"","sources":["../../src/plugins/metroPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"metroPlugin.d.ts","sourceRoot":"","sources":["../../src/plugins/metroPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAUxC,OAAO,KAAK,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,OAAO,CAAA;AAMtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAIjE,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;AAC3D,KAAK,gBAAgB,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;AAEzD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,kBAAkB,CAAA;IACzB,sBAAsB,CAAC,EACnB,gBAAgB,GAChB,CAAC,CAAC,aAAa,EAAE,gBAAgB,KAAK,gBAAgB,CAAC,CAAA;IAC3D;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;;;;;;;OAUG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,kDAAkD;IAClD,WAAW,CAAC,EAAE,gBAAgB,CAAA;IAC9B,oBAAoB,CAAC,EAAE,CAAC,aAAa,EAAE,gBAAgB,KAAK,gBAAgB,CAAA;IAC5E;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,YAAY,CAmO1E"}
|