vxrn 0.1.20 → 0.1.21

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 (173) hide show
  1. package/dist/cjs/cli.js +77 -3
  2. package/dist/cjs/cli.js.map +2 -2
  3. package/dist/cjs/cli.native.js +268 -2
  4. package/dist/cjs/cli.native.js.map +2 -2
  5. package/dist/cjs/constants.js +21 -0
  6. package/dist/cjs/constants.js.map +6 -0
  7. package/dist/cjs/constants.native.js +26 -0
  8. package/dist/cjs/constants.native.js.map +6 -0
  9. package/dist/cjs/dispose.js +28 -0
  10. package/dist/cjs/dispose.js.map +6 -0
  11. package/dist/cjs/dispose.native.js +36 -0
  12. package/dist/cjs/dispose.native.js.map +6 -0
  13. package/dist/cjs/exports/build.js +145 -0
  14. package/dist/cjs/exports/build.js.map +6 -0
  15. package/dist/cjs/exports/build.native.js +409 -0
  16. package/dist/cjs/exports/build.native.js.map +6 -0
  17. package/dist/cjs/exports/checkPatches.js +62 -0
  18. package/dist/cjs/exports/checkPatches.js.map +6 -0
  19. package/dist/cjs/exports/checkPatches.native.js +289 -0
  20. package/dist/cjs/exports/checkPatches.native.js.map +6 -0
  21. package/dist/cjs/exports/dev.js +568 -0
  22. package/dist/cjs/exports/dev.js.map +6 -0
  23. package/dist/cjs/exports/dev.native.js +1111 -0
  24. package/dist/cjs/exports/dev.native.js.map +6 -0
  25. package/dist/cjs/exports/serve.js +55 -0
  26. package/dist/cjs/exports/serve.js.map +6 -0
  27. package/dist/cjs/exports/serve.native.js +236 -0
  28. package/dist/cjs/exports/serve.native.js.map +6 -0
  29. package/dist/cjs/index.js +2 -3
  30. package/dist/cjs/index.js.map +1 -1
  31. package/dist/cjs/index.native.js +3 -5
  32. package/dist/cjs/index.native.js.map +1 -1
  33. package/dist/cjs/plugins/clientInjectPlugin.js +66 -0
  34. package/dist/cjs/plugins/clientInjectPlugin.js.map +6 -0
  35. package/dist/cjs/plugins/clientInjectPlugin.native.js +190 -0
  36. package/dist/cjs/plugins/clientInjectPlugin.native.js.map +6 -0
  37. package/dist/cjs/plugins/reactNativeCommonJsPlugin.js +89 -0
  38. package/dist/cjs/plugins/reactNativeCommonJsPlugin.js.map +6 -0
  39. package/dist/cjs/plugins/reactNativeCommonJsPlugin.native.js +346 -0
  40. package/dist/cjs/plugins/reactNativeCommonJsPlugin.native.js.map +6 -0
  41. package/dist/cjs/utils/checkPatches.js +62 -0
  42. package/dist/cjs/utils/checkPatches.js.map +6 -0
  43. package/dist/cjs/utils/checkPatches.native.js +289 -0
  44. package/dist/cjs/utils/checkPatches.native.js.map +6 -0
  45. package/dist/cjs/utils/dispose.js +28 -0
  46. package/dist/cjs/utils/dispose.js.map +6 -0
  47. package/dist/cjs/utils/dispose.native.js +36 -0
  48. package/dist/cjs/utils/dispose.native.js.map +6 -0
  49. package/dist/cjs/utils/getBaseViteConfig.js +2 -2
  50. package/dist/cjs/utils/getBaseViteConfig.js.map +1 -1
  51. package/dist/cjs/utils/getBaseViteConfig.native.js +2 -2
  52. package/dist/cjs/utils/getBaseViteConfig.native.js.map +1 -1
  53. package/dist/cjs/utils/patches.js +62 -0
  54. package/dist/cjs/utils/patches.js.map +6 -0
  55. package/dist/cjs/utils/patches.native.js +289 -0
  56. package/dist/cjs/utils/patches.native.js.map +6 -0
  57. package/dist/cjs/utils/prerender.js +1 -0
  58. package/dist/cjs/utils/prerender.js.map +6 -0
  59. package/dist/cjs/utils/prerender.native.js +2 -0
  60. package/dist/cjs/utils/prerender.native.js.map +6 -0
  61. package/dist/cjs/vendor/createExpoServer.js +34 -0
  62. package/dist/cjs/vendor/createExpoServer.js.map +6 -0
  63. package/dist/cjs/vendor/createExpoServer.native.js +42 -0
  64. package/dist/cjs/vendor/createExpoServer.native.js.map +6 -0
  65. package/dist/esm/cli.js +58 -3
  66. package/dist/esm/cli.js.map +2 -2
  67. package/dist/esm/cli.mjs +81 -9
  68. package/dist/esm/cli.native.js +249 -3
  69. package/dist/esm/cli.native.js.map +2 -2
  70. package/dist/esm/constants.js +5 -0
  71. package/dist/esm/constants.js.map +6 -0
  72. package/dist/esm/constants.mjs +2 -0
  73. package/dist/esm/constants.native.js +5 -0
  74. package/dist/esm/constants.native.js.map +6 -0
  75. package/dist/esm/dispose.js +12 -0
  76. package/dist/esm/dispose.js.map +6 -0
  77. package/dist/esm/dispose.mjs +8 -0
  78. package/dist/esm/dispose.native.js +14 -0
  79. package/dist/esm/dispose.native.js.map +6 -0
  80. package/dist/esm/exports/build.js +128 -0
  81. package/dist/esm/exports/build.js.map +6 -0
  82. package/dist/esm/exports/build.mjs +119 -0
  83. package/dist/esm/exports/build.native.js +385 -0
  84. package/dist/esm/exports/build.native.js.map +6 -0
  85. package/dist/esm/exports/checkPatches.js +40 -0
  86. package/dist/esm/exports/checkPatches.js.map +6 -0
  87. package/dist/esm/exports/checkPatches.mjs +31 -0
  88. package/dist/esm/exports/checkPatches.native.js +262 -0
  89. package/dist/esm/exports/checkPatches.native.js.map +6 -0
  90. package/dist/esm/exports/dev.js +581 -0
  91. package/dist/esm/exports/dev.js.map +6 -0
  92. package/dist/esm/exports/dev.mjs +543 -0
  93. package/dist/esm/exports/dev.native.js +1102 -0
  94. package/dist/esm/exports/dev.native.js.map +6 -0
  95. package/dist/esm/exports/serve.js +33 -0
  96. package/dist/esm/exports/serve.js.map +6 -0
  97. package/dist/esm/exports/serve.mjs +38 -0
  98. package/dist/esm/exports/serve.native.js +209 -0
  99. package/dist/esm/exports/serve.native.js.map +6 -0
  100. package/dist/esm/index.js +3 -5
  101. package/dist/esm/index.js.map +1 -1
  102. package/dist/esm/index.mjs +3 -4
  103. package/dist/esm/index.native.js +3 -5
  104. package/dist/esm/index.native.js.map +2 -2
  105. package/dist/esm/plugins/clientInjectPlugin.js +42 -0
  106. package/dist/esm/plugins/clientInjectPlugin.js.map +6 -0
  107. package/dist/esm/plugins/clientInjectPlugin.mjs +56 -0
  108. package/dist/esm/plugins/clientInjectPlugin.native.js +161 -0
  109. package/dist/esm/plugins/clientInjectPlugin.native.js.map +6 -0
  110. package/dist/esm/plugins/reactNativeCommonJsPlugin.js +75 -0
  111. package/dist/esm/plugins/reactNativeCommonJsPlugin.js.map +6 -0
  112. package/dist/esm/plugins/reactNativeCommonJsPlugin.mjs +55 -0
  113. package/dist/esm/plugins/reactNativeCommonJsPlugin.native.js +327 -0
  114. package/dist/esm/plugins/reactNativeCommonJsPlugin.native.js.map +6 -0
  115. package/dist/esm/utils/checkPatches.js +40 -0
  116. package/dist/esm/utils/checkPatches.js.map +6 -0
  117. package/dist/esm/utils/checkPatches.mjs +31 -0
  118. package/dist/esm/utils/checkPatches.native.js +262 -0
  119. package/dist/esm/utils/checkPatches.native.js.map +6 -0
  120. package/dist/esm/utils/dispose.js +12 -0
  121. package/dist/esm/utils/dispose.js.map +6 -0
  122. package/dist/esm/utils/dispose.mjs +8 -0
  123. package/dist/esm/utils/dispose.native.js +14 -0
  124. package/dist/esm/utils/dispose.native.js.map +6 -0
  125. package/dist/esm/utils/getBaseViteConfig.js +1 -1
  126. package/dist/esm/utils/getBaseViteConfig.mjs +1 -1
  127. package/dist/esm/utils/getBaseViteConfig.native.js +1 -1
  128. package/dist/esm/utils/patches.js +40 -0
  129. package/dist/esm/utils/patches.js.map +6 -0
  130. package/dist/esm/utils/patches.mjs +31 -0
  131. package/dist/esm/utils/patches.native.js +262 -0
  132. package/dist/esm/utils/patches.native.js.map +6 -0
  133. package/dist/esm/utils/prerender.js +1 -0
  134. package/dist/esm/utils/prerender.js.map +6 -0
  135. package/dist/esm/utils/prerender.mjs +0 -0
  136. package/dist/esm/utils/prerender.native.js +1 -0
  137. package/dist/esm/utils/prerender.native.js.map +6 -0
  138. package/dist/esm/vendor/createExpoServer.js +20 -0
  139. package/dist/esm/vendor/createExpoServer.js.map +6 -0
  140. package/dist/esm/vendor/createExpoServer.mjs +17 -0
  141. package/dist/esm/vendor/createExpoServer.native.js +22 -0
  142. package/dist/esm/vendor/createExpoServer.native.js.map +6 -0
  143. package/package.json +8 -7
  144. package/src/cli.ts +78 -2
  145. package/src/{build.ts → exports/build.ts} +5 -4
  146. package/src/{createDevServer.ts → exports/dev.ts} +13 -63
  147. package/src/exports/serve.ts +51 -0
  148. package/src/index.ts +3 -3
  149. package/src/{dev → plugins}/clientInjectPlugin.ts +1 -12
  150. package/src/{nativePlugin.ts → plugins/reactNativeCommonJsPlugin.ts} +3 -26
  151. package/src/utils/getBaseViteConfig.ts +1 -1
  152. package/src/utils/patches.ts +54 -0
  153. package/types/build.d.ts +4 -4
  154. package/types/constants.d.ts +2 -0
  155. package/types/dispose.d.ts +3 -0
  156. package/types/exports/build.d.ts +4 -0
  157. package/types/exports/dev.d.ts +13 -0
  158. package/types/exports/serve.d.ts +3 -0
  159. package/types/index.d.ts +2 -3
  160. package/types/plugins/clientInjectPlugin.d.ts +7 -0
  161. package/types/plugins/reactNativeCommonJsPlugin.d.ts +7 -0
  162. package/types/utils/checkPatches.d.ts +3 -0
  163. package/types/utils/dispose.d.ts +3 -0
  164. package/types/utils/patches.d.ts +3 -0
  165. package/types/utils/prerender.d.ts +1 -0
  166. package/types/vendor/createExpoServer.d.ts +4 -0
  167. package/src/commands/cli-build.ts +0 -25
  168. package/src/commands/cli-dev.ts +0 -47
  169. package/src/commands/index.ts +0 -10
  170. package/src/dev/createDevServer.ts +0 -234
  171. /package/src/{utils/constants.ts → constants.ts} +0 -0
  172. /package/src/{utils.ts → utils/dispose.ts} +0 -0
  173. /package/src/{createExpoServer.ts → vendor/createExpoServer.ts} +0 -0
@@ -0,0 +1,543 @@
1
+ import wsAdapter from "crossws/adapters/node";
2
+ import { createApp, createRouter, defineEventHandler, defineWebSocketHandler, eventHandler, getQuery, toNodeListener } from "h3";
3
+ import { createProxyEventHandler } from "h3-proxy";
4
+ import { readFile } from "node:fs/promises";
5
+ import { createServer as nodeCreateServer } from "node:http";
6
+ import { dirname, join, relative, resolve } from "node:path";
7
+ import readline from "node:readline";
8
+ import { WebSocket } from "ws";
9
+ import * as babel from "@babel/core";
10
+ import { buildReact, buildReactJSX, buildReactNative } from "@vxrn/react-native-prebuilt";
11
+ import viteReactPlugin, { swcTransform, transformForBuild } from "@vxrn/vite-native-swc";
12
+ import { parse } from "es-module-lexer";
13
+ import FSExtra from "fs-extra";
14
+ import { build, createServer, mergeConfig, resolveConfig, transformWithEsbuild } from "vite";
15
+ import createViteFlow from "@vxrn/vite-flow";
16
+ import { resolve as importMetaResolve } from "import-meta-resolve";
17
+ import { clientBundleTreeShakePlugin } from "../plugins/clientBundleTreeShakePlugin.mjs";
18
+ import { clientInjectionsPlugin } from "../plugins/clientInjectPlugin.mjs";
19
+ import { reactNativeCommonJsPlugin } from "../plugins/reactNativeCommonJsPlugin.mjs";
20
+ import { getBaseViteConfig } from "../utils/getBaseViteConfig.mjs";
21
+ import { getOptionsFilled } from "../utils/getOptionsFilled.mjs";
22
+ import { getVitePath } from "../utils/getVitePath.mjs";
23
+ import { checkPatches } from "../utils/patches.mjs";
24
+ import { createExpoServer } from "../vendor/createExpoServer.mjs";
25
+ const resolveFile = path => {
26
+ try {
27
+ return importMetaResolve(path, import.meta.url).replace("file://", "");
28
+ } catch {
29
+ return require.resolve(path);
30
+ }
31
+ },
32
+ nativeExtensions = [".native.tsx", ".native.jsx", ".native.js", ".tsx", ".ts", ".js", ".css", ".json"],
33
+ extensions = [".web.tsx", ".tsx", ".web.ts", ".ts", ".web.jsx", ".jsx", ".web.js", ".js", ".css", ".json"],
34
+ {
35
+ ensureDir,
36
+ pathExists,
37
+ pathExistsSync
38
+ } = FSExtra,
39
+ dev = async optionsIn => {
40
+ const options = await getOptionsFilled(optionsIn),
41
+ {
42
+ host,
43
+ port,
44
+ root,
45
+ cacheDir
46
+ } = options;
47
+ bindKeypressInput();
48
+ let entryRoot = "";
49
+ checkPatches(options).catch(err => {
50
+ console.error(`
51
+ \u{1F97A} couldn't patch`, err);
52
+ }), await ensureDir(cacheDir);
53
+ const prebuilds = {
54
+ reactJSX: join(cacheDir, "react-jsx-runtime.js"),
55
+ react: join(cacheDir, "react.js"),
56
+ reactNative: join(cacheDir, "react-native.js")
57
+ };
58
+ (await pathExists(prebuilds.reactNative)) || (console.info("Pre-building react, react-native react/jsx-runtime (one time cost)..."), await Promise.all([buildReactNative({
59
+ entryPoints: [resolveFile("react-native")],
60
+ outfile: prebuilds.reactNative
61
+ }), buildReact({
62
+ entryPoints: [resolveFile("react")],
63
+ outfile: prebuilds.react
64
+ }), buildReactJSX({
65
+ entryPoints: [resolveFile("react/jsx-dev-runtime")],
66
+ outfile: prebuilds.reactJSX
67
+ })]));
68
+ const viteFlow = options.flow ? createViteFlow(options.flow) : null,
69
+ templateFile = resolveFile("vxrn/react-native-template.js"),
70
+ hotUpdatedCJSFiles = /* @__PURE__ */new Map(),
71
+ jsxRuntime = {
72
+ // alias: 'virtual:react-jsx',
73
+ alias: prebuilds.reactJSX,
74
+ contents: await readFile(prebuilds.reactJSX, "utf-8")
75
+ },
76
+ virtualModules = {
77
+ "react-native": {
78
+ // alias: 'virtual:react-native',
79
+ alias: prebuilds.reactNative,
80
+ contents: await readFile(prebuilds.reactNative, "utf-8")
81
+ },
82
+ react: {
83
+ // alias: 'virtual:react',
84
+ alias: prebuilds.react,
85
+ contents: await readFile(prebuilds.react, "utf-8")
86
+ },
87
+ "react/jsx-runtime": jsxRuntime,
88
+ "react/jsx-dev-runtime": jsxRuntime
89
+ },
90
+ swapRnPlugin = {
91
+ name: "swap-react-native",
92
+ enforce: "pre",
93
+ resolveId(id, importer = "") {
94
+ if (id.startsWith("react-native/Libraries")) return `virtual:rn-internals:${id}`;
95
+ if (id === "react-native-web") return prebuilds.reactNative;
96
+ for (const targetId in virtualModules) if (id === targetId || id.includes(`node_modules/${targetId}/`)) return virtualModules[targetId].alias;
97
+ if (id[0] === ".") {
98
+ const absolutePath = resolve(dirname(importer), id),
99
+ nativePath = absolutePath.replace(/(.m?js)/, ".native.js");
100
+ if (nativePath === id) return;
101
+ try {
102
+ const directoryPath = absolutePath + "/index.native.js",
103
+ directoryNonNativePath = absolutePath + "/index.js";
104
+ if (pathExistsSync(directoryPath)) return directoryPath;
105
+ if (pathExistsSync(directoryNonNativePath)) return directoryNonNativePath;
106
+ if (pathExistsSync(nativePath)) return nativePath;
107
+ } catch (err) {
108
+ console.warn("error probably fine", err);
109
+ }
110
+ }
111
+ },
112
+ load(id) {
113
+ if (id.startsWith("virtual:rn-internals")) return `const ___val = __cachedModules["${id.replace("virtual:rn-internals:", "")}"]
114
+ const ___defaultVal = ___val ? ___val.default || ___val : ___val
115
+ export default ___defaultVal`;
116
+ for (const targetId in virtualModules) {
117
+ const info = virtualModules[targetId];
118
+ if (id === info.alias) return info.contents;
119
+ }
120
+ }
121
+ },
122
+ depsToOptimize = ["react", "react-dom", "@react-native/normalize-color"],
123
+ reactNativeHMRPlugin = {
124
+ name: "client-transform",
125
+ async handleHotUpdate({
126
+ read,
127
+ modules,
128
+ file
129
+ }) {
130
+ try {
131
+ if (!isWithin(root, file)) return;
132
+ const [module] = modules;
133
+ if (!module) return;
134
+ const id = module?.url || file.replace(root, ""),
135
+ code = await read();
136
+ if (code.startsWith("'use strict';") || !code) return;
137
+ let source = code;
138
+ source = (await transformForBuild(id, source))?.code || "";
139
+ const importsMap = {},
140
+ [imports] = parse(source);
141
+ let accumulatedSliceOffset = 0;
142
+ for (const specifier of imports) {
143
+ const {
144
+ n: importName,
145
+ s: start
146
+ } = specifier;
147
+ if (importName) {
148
+ const id2 = await getVitePath(entryRoot, file, importName);
149
+ if (!id2) {
150
+ console.warn("???");
151
+ continue;
152
+ }
153
+ importsMap[id2] = id2.replace(/^(\.\.\/)+/, "");
154
+ const len = importName.length,
155
+ extraLen = id2.length - len;
156
+ source = source.slice(0, start + accumulatedSliceOffset) + id2 + source.slice(start + accumulatedSliceOffset + len), accumulatedSliceOffset += extraLen;
157
+ }
158
+ }
159
+ if (source = (await swcTransform(id, source, {
160
+ mode: "serve-cjs"
161
+ }))?.code || "", !source) throw "\u274C no source";
162
+ importsMap.currentPath = id;
163
+ const hotUpdateSource = `exports = ((exports) => {
164
+ const require = createRequire(${JSON.stringify(importsMap, null, 2)})
165
+ ${source.replace("import.meta.hot.accept(() => {})", "").replaceAll(/import.meta.glob\(.*\)/gi, "globalThis['__importMetaGlobbed'] || {}")};
166
+ return exports })({})`;
167
+ process.env.DEBUG && console.info("Sending hot update", hotUpdateSource), hotUpdatedCJSFiles.set(id, hotUpdateSource);
168
+ } catch (err) {
169
+ console.error("Error processing hmr update:", err);
170
+ }
171
+ }
172
+ };
173
+ let serverConfig = mergeConfig(getBaseViteConfig({
174
+ mode: "development"
175
+ }), {
176
+ root,
177
+ clearScreen: !1,
178
+ plugins: [reactNativeHMRPlugin, clientBundleTreeShakePlugin({})],
179
+ optimizeDeps: {
180
+ include: depsToOptimize,
181
+ exclude: Object.values(virtualModules).map(v => v.alias),
182
+ force: !0,
183
+ esbuildOptions: {
184
+ resolveExtensions: extensions
185
+ }
186
+ },
187
+ server: {
188
+ hmr: {
189
+ path: "/__vxrnhmr"
190
+ },
191
+ cors: !0,
192
+ host
193
+ }
194
+ });
195
+ options.webConfig && (serverConfig = mergeConfig(serverConfig, options.webConfig));
196
+ const resolvedConfig = await resolveConfig(serverConfig, "serve"),
197
+ viteRNClientPlugin = clientInjectionsPlugin(resolvedConfig);
198
+ serverConfig = {
199
+ ...serverConfig,
200
+ plugins: [...serverConfig.plugins]
201
+ };
202
+ const viteServer = await createServer(serverConfig);
203
+ viteServer.watcher.addListener("change", async path => {
204
+ const id = path.replace(process.cwd(), "");
205
+ if (!(!id.endsWith("tsx") && !id.endsWith("jsx"))) try {
206
+ viteServer.transformRequest(id);
207
+ } catch (err) {
208
+ console.info("err", err);
209
+ }
210
+ });
211
+ let isBuilding = null;
212
+ await viteServer.listen();
213
+ const vitePort = viteServer.config.server.port;
214
+ console.info("vite running on", vitePort);
215
+ const router = createRouter(),
216
+ app = createApp({
217
+ onError: error => {
218
+ console.error(error);
219
+ },
220
+ onRequest: event => {
221
+ console.info(" \u2192", event.path);
222
+ }
223
+ });
224
+ createExpoServer(root, app), router.get("/file", defineEventHandler(e => {
225
+ const query = getQuery(e);
226
+ if (typeof query.file == "string") {
227
+ const source = hotUpdatedCJSFiles.get(query.file);
228
+ return new Response(source, {
229
+ headers: {
230
+ "content-type": "text/javascript"
231
+ }
232
+ });
233
+ }
234
+ })), router.get("/index.bundle", defineEventHandler(async e => new Response(await getBundleCode(), {
235
+ headers: {
236
+ "content-type": "text/javascript"
237
+ }
238
+ }))), router.get("/status", defineEventHandler(() => "packager-status:running")), app.use(router), app.use(defineEventHandler(async ({
239
+ node: {
240
+ req
241
+ }
242
+ }) => {
243
+ if (req.headers["user-agent"]?.match(/Expo|React/) && (req.url === "/" || req.url?.startsWith("/?platform="))) return getIndexJsonResponse({
244
+ port,
245
+ root
246
+ });
247
+ }));
248
+ const {
249
+ handleUpgrade
250
+ } = wsAdapter(app.websocket);
251
+ if (vitePort) {
252
+ const clients = /* @__PURE__ */new Set(),
253
+ socket = new WebSocket(`ws://localhost:${vitePort}/__vxrnhmr`, "vite-hmr");
254
+ console.info("connecting to vite..."), socket.on("open", () => {
255
+ console.info("...connected to vite!");
256
+ }), socket.on("message", msg => {
257
+ const message = msg.toString();
258
+ console.info(clients.size, "message", message);
259
+ for (const listener of [...clients]) listener.send(message);
260
+ }), socket.on("error", err => {
261
+ console.info("err", err);
262
+ }), app.use("/__vxrnhmr", defineWebSocketHandler({
263
+ open(peer) {
264
+ console.debug("[hmr:web] open", peer), clients.add(peer);
265
+ },
266
+ message(peer, message) {
267
+ socket.send(message.rawData);
268
+ },
269
+ close(peer, event) {
270
+ console.info("[hmr:web] close", peer, event), clients.delete(peer);
271
+ },
272
+ error(peer, error) {
273
+ console.error("[hmr:web] error", peer, error);
274
+ }
275
+ }));
276
+ }
277
+ app.use("/__hmr", defineWebSocketHandler({
278
+ open(peer) {
279
+ console.debug("[hmr] open", peer);
280
+ },
281
+ message(peer, message) {
282
+ console.info("[hmr] message", peer, message), message.text().includes("ping") && peer.send("pong");
283
+ },
284
+ close(peer, event) {
285
+ console.info("[hmr] close", peer, event);
286
+ },
287
+ error(peer, error) {
288
+ console.error("[hmr] error", peer, error);
289
+ }
290
+ })), app.use("/__client", defineWebSocketHandler({
291
+ open(peer) {
292
+ console.info("[client] open", peer);
293
+ },
294
+ message(peer, messageRaw) {
295
+ const message = JSON.parse(messageRaw.text());
296
+ switch (message.type) {
297
+ case "client-log":
298
+ {
299
+ console.info(`\u{1FAB5} [${message.level}]`, ...message.data);
300
+ return;
301
+ }
302
+ default:
303
+ console.warn("[client] Unknown message type", message);
304
+ }
305
+ },
306
+ close(peer, event) {
307
+ console.info("[client] close", peer, event);
308
+ },
309
+ error(peer, error) {
310
+ console.error("[client] error", peer, error);
311
+ }
312
+ }));
313
+ const proxyEventHandler = createProxyEventHandler({
314
+ target: `http://127.0.0.1:${vitePort}`,
315
+ enableLogger: !!process.env.DEBUG
316
+ });
317
+ app.use(eventHandler(proxyEventHandler));
318
+ const server = nodeCreateServer(toNodeListener(app));
319
+ return server.on("upgrade", handleUpgrade), {
320
+ server,
321
+ viteServer,
322
+ async start() {
323
+ return server.listen(port), console.info(`Server running on http://localhost:${port}`), {
324
+ closePromise: new Promise(res => viteServer.httpServer?.on("close", res))
325
+ };
326
+ },
327
+ stop: async () => {
328
+ await Promise.all([server.close(), viteServer.close()]);
329
+ }
330
+ };
331
+ async function getBundleCode() {
332
+ if (process.env.LOAD_TMP_BUNDLE) {
333
+ const tmpBundle = join(process.cwd(), "bundle.tmp.js");
334
+ if (await pathExists(tmpBundle)) return console.info("\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F returning temp bundle \u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F", tmpBundle), await readFile(tmpBundle, "utf-8");
335
+ }
336
+ if (isBuilding) return await isBuilding;
337
+ let done;
338
+ isBuilding = new Promise(res => {
339
+ done = res;
340
+ });
341
+ async function babelReanimated(input, filename) {
342
+ return await new Promise((res, rej) => {
343
+ babel.transform(input, {
344
+ plugins: ["react-native-reanimated/plugin"],
345
+ filename
346
+ }, (err, result) => {
347
+ (!result || err) && rej(err || "no res"), res(result.code);
348
+ });
349
+ });
350
+ }
351
+ let buildConfig = {
352
+ plugins: [viteFlow, swapRnPlugin, {
353
+ name: "reanimated",
354
+ async transform(code, id) {
355
+ if (code.includes("worklet")) return await babelReanimated(code, id);
356
+ }
357
+ }, clientBundleTreeShakePlugin({}), viteRNClientPlugin, reactNativeCommonJsPlugin({
358
+ root,
359
+ port,
360
+ mode: "build"
361
+ }), viteReactPlugin({
362
+ tsDecorators: !0,
363
+ mode: "build"
364
+ }), {
365
+ name: "treat-js-files-as-jsx",
366
+ async transform(code, id) {
367
+ return id.match(/expo-status-bar/) ? transformWithEsbuild(code, id, {
368
+ loader: "jsx",
369
+ jsx: "automatic"
370
+ }) : null;
371
+ }
372
+ }].filter(Boolean),
373
+ appType: "custom",
374
+ root,
375
+ clearScreen: !1,
376
+ optimizeDeps: {
377
+ include: depsToOptimize,
378
+ esbuildOptions: {
379
+ jsx: "automatic"
380
+ }
381
+ },
382
+ resolve: {
383
+ extensions: nativeExtensions
384
+ },
385
+ mode: "development",
386
+ define: {
387
+ "process.env.NODE_ENV": '"development"'
388
+ },
389
+ build: {
390
+ ssr: !1,
391
+ minify: !1,
392
+ commonjsOptions: {
393
+ transformMixedEsModules: !0
394
+ },
395
+ rollupOptions: {
396
+ treeshake: !1,
397
+ preserveEntrySignatures: "strict",
398
+ output: {
399
+ preserveModules: !0,
400
+ format: "cjs"
401
+ }
402
+ }
403
+ }
404
+ };
405
+ options.buildConfig && (buildConfig = mergeConfig(buildConfig, options.buildConfig)), await resolveConfig(buildConfig, "build");
406
+ const buildOutput = await build(buildConfig);
407
+ if (!("output" in buildOutput)) throw "\u274C";
408
+ let appCode = buildOutput.output.sort((a, b) => a.isEntry ? 1 : -1).map(outputModule => {
409
+ if (outputModule.type == "chunk") {
410
+ const importsMap = {
411
+ currentPath: outputModule.fileName
412
+ };
413
+ for (const imp of outputModule.imports) {
414
+ const relativePath = relative(dirname(outputModule.fileName), imp);
415
+ importsMap[relativePath[0] === "." ? relativePath : "./" + relativePath] = imp;
416
+ }
417
+ return outputModule.isEntry && (entryRoot = dirname(outputModule.fileName)), `
418
+ ___modules___["${outputModule.fileName}"] = ((exports, module) => {
419
+ const require = createRequire(${JSON.stringify(importsMap, null, 2)})
420
+
421
+ ${outputModule.code}
422
+ })
423
+
424
+ ${outputModule.isEntry ? `
425
+ // run entry
426
+ const __require = createRequire({})
427
+ __require("react-native")
428
+ __require("${outputModule.fileName}")
429
+ ` : ""}
430
+ `;
431
+ }
432
+ }).join(`
433
+ `);
434
+ if (!appCode) throw "\u274C";
435
+ appCode = appCode.replaceAll("undefined.accept(() => {})", "").replaceAll("undefined.accept(function() {});", "").replaceAll("(void 0).accept(() => {})", "").replaceAll("(void 0).accept(function() {});", "").replaceAll('dist/esm/index.mjs"', 'dist/esm/index.js"');
436
+ const appRootParent = join(root, "..", ".."),
437
+ out = (await readFile(templateFile, "utf-8")).replace("_virtual/virtual_react-native.js", relative(appRootParent, prebuilds.reactNative)).replace("_virtual/virtual_react.js", relative(appRootParent, prebuilds.react)).replaceAll("_virtual/virtual_react-jsx.js", relative(appRootParent, prebuilds.reactJSX)) + appCode;
438
+ return done(out), isBuilding = null, out;
439
+ }
440
+ };
441
+ function getIndexJsonResponse({
442
+ port,
443
+ root
444
+ }) {
445
+ return {
446
+ name: "myapp",
447
+ slug: "myapp",
448
+ scheme: "myapp",
449
+ version: "1.0.0",
450
+ jsEngine: "jsc",
451
+ orientation: "portrait",
452
+ icon: "./assets/icon.png",
453
+ userInterfaceStyle: "light",
454
+ splash: {
455
+ image: "./assets/splash.png",
456
+ resizeMode: "contain",
457
+ backgroundColor: "#ffffff",
458
+ imageUrl: "http://127.0.0.1:8081/assets/./assets/splash.png"
459
+ },
460
+ updates: {
461
+ fallbackToCacheTimeout: 0
462
+ },
463
+ assetBundlePatterns: ["**/*"],
464
+ ios: {
465
+ supportsTablet: !0,
466
+ bundleIdentifier: "com.natew.myapp"
467
+ },
468
+ android: {
469
+ package: "com.tamagui.myapp",
470
+ adaptiveIcon: {
471
+ foregroundImage: "./assets/adaptive-icon.png",
472
+ backgroundColor: "#FFFFFF",
473
+ foregroundImageUrl: "http://127.0.0.1:8081/assets/./assets/adaptive-icon.png"
474
+ }
475
+ },
476
+ web: {
477
+ favicon: "./assets/favicon.png"
478
+ },
479
+ extra: {
480
+ eas: {
481
+ projectId: "061b4470-78c7-4d6a-b850-8167fb0a3434"
482
+ }
483
+ },
484
+ _internal: {
485
+ isDebug: !1,
486
+ projectRoot: root,
487
+ dynamicConfigPath: null,
488
+ staticConfigPath: join(root, "app.json"),
489
+ packageJsonPath: join(root, "package.json")
490
+ },
491
+ sdkVersion: "50.0.0",
492
+ platforms: ["ios", "android", "web"],
493
+ iconUrl: `http://127.0.0.1:${port}/assets/./assets/icon.png`,
494
+ debuggerHost: `127.0.0.1:${port}`,
495
+ logUrl: `http://127.0.0.1:${port}/logs`,
496
+ developer: {
497
+ tool: "expo-cli",
498
+ projectRoot: root
499
+ },
500
+ packagerOpts: {
501
+ dev: !0
502
+ },
503
+ mainModuleName: "index",
504
+ __flipperHack: "React Native packager is running",
505
+ hostUri: `127.0.0.1:${port}`,
506
+ bundleUrl: `http://127.0.0.1:${port}/index.bundle?platform=ios&dev=true&hot=false&lazy=true`,
507
+ id: "@anonymous/myapp-473c4543-3c36-4786-9db1-c66a62ac9b78"
508
+ };
509
+ }
510
+ function bindKeypressInput() {
511
+ if (!process.stdin.setRawMode) {
512
+ console.warn({
513
+ msg: "Interactive mode is not supported in this environment"
514
+ });
515
+ return;
516
+ }
517
+ readline.emitKeypressEvents(process.stdin), process.stdin.setRawMode(!0), process.stdin.on("keypress", (_key, data) => {
518
+ const {
519
+ ctrl,
520
+ name
521
+ } = data;
522
+ if (ctrl === !0) switch (name) {
523
+ case "c":
524
+ process.exit();
525
+ case "z":
526
+ process.emit("SIGTSTP", "SIGTSTP");
527
+ break;
528
+ } else switch (name) {
529
+ case "r":
530
+ break;
531
+ case "d":
532
+ break;
533
+ case "c":
534
+ process.stdout.write("\x1B[2J\x1B[0;0H");
535
+ break;
536
+ }
537
+ });
538
+ }
539
+ function isWithin(outer, inner) {
540
+ const rel = relative(outer, inner);
541
+ return !rel.startsWith("../") && rel !== "..";
542
+ }
543
+ export { bindKeypressInput, dev, resolveFile };