@vxrn/vite-plugin-metro 1.25.13 → 1.25.16-1788753284749

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 (49) hide show
  1. package/dist/cjs/metro-config/getMetroConfigFromViteConfig.cjs +20 -0
  2. package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.js +20 -0
  3. package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.js.map +1 -1
  4. package/dist/cjs/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.cjs +2 -1
  5. package/dist/cjs/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js +2 -1
  6. package/dist/cjs/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js.map +1 -1
  7. package/dist/cjs/plugins/metroPlugin.native.js.map +1 -1
  8. package/dist/cjs/transformer/metroNativeWorker.cjs +1594 -0
  9. package/dist/cjs/transformer/metroNativeWorker.native.js +2678 -0
  10. package/dist/cjs/transformer/metroNativeWorker.native.js.map +1 -0
  11. package/dist/cjs/transformer/metroNativeWorker.test.cjs +813 -0
  12. package/dist/cjs/transformer/metroNativeWorker.test.native.js +920 -0
  13. package/dist/cjs/transformer/metroNativeWorker.test.native.js.map +1 -0
  14. package/dist/esm/metro-config/getMetroConfigFromViteConfig.mjs +20 -0
  15. package/dist/esm/metro-config/getMetroConfigFromViteConfig.mjs.map +1 -1
  16. package/dist/esm/metro-config/getMetroConfigFromViteConfig.native.js +20 -0
  17. package/dist/esm/metro-config/getMetroConfigFromViteConfig.native.js.map +1 -1
  18. package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.mjs +2 -1
  19. package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.mjs.map +1 -1
  20. package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js +2 -1
  21. package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js.map +1 -1
  22. package/dist/esm/plugins/metroPlugin.mjs.map +1 -1
  23. package/dist/esm/plugins/metroPlugin.native.js.map +1 -1
  24. package/dist/esm/transformer/metroNativeWorker.mjs +1535 -0
  25. package/dist/esm/transformer/metroNativeWorker.mjs.map +1 -0
  26. package/dist/esm/transformer/metroNativeWorker.native.js +2616 -0
  27. package/dist/esm/transformer/metroNativeWorker.native.js.map +1 -0
  28. package/dist/esm/transformer/metroNativeWorker.test.mjs +777 -0
  29. package/dist/esm/transformer/metroNativeWorker.test.mjs.map +1 -0
  30. package/dist/esm/transformer/metroNativeWorker.test.native.js +882 -0
  31. package/dist/esm/transformer/metroNativeWorker.test.native.js.map +1 -0
  32. package/package.json +22 -3
  33. package/src/metro-config/getMetroConfigFromViteConfig.ts +42 -0
  34. package/src/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.ts +1 -0
  35. package/src/plugins/metroPlugin.ts +22 -0
  36. package/src/transformer/__fixtures__/exampleNativeTransform.cjs +17 -0
  37. package/src/transformer/metroNativeWorker.test.ts +1138 -0
  38. package/src/transformer/metroNativeWorker.ts +2385 -0
  39. package/src/transformer/types.ts +21 -0
  40. package/types/metro-config/getMetroConfigFromViteConfig.d.ts.map +1 -1
  41. package/types/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.d.ts.map +1 -1
  42. package/types/plugins/metroPlugin.d.ts +22 -0
  43. package/types/plugins/metroPlugin.d.ts.map +1 -1
  44. package/types/transformer/metroNativeWorker.d.ts +251 -0
  45. package/types/transformer/metroNativeWorker.d.ts.map +1 -0
  46. package/types/transformer/metroNativeWorker.test.d.ts +2 -0
  47. package/types/transformer/metroNativeWorker.test.d.ts.map +1 -0
  48. package/types/transformer/types.d.ts +17 -0
  49. package/types/transformer/types.d.ts.map +1 -1
@@ -0,0 +1,813 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
10
+ get: () => from[key],
11
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
12
+ });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
+ value: mod,
23
+ enumerable: true
24
+ }) : target, mod));
25
+ var import_vitest = require("vitest");
26
+ var vm = __toESM(require("node:vm"), 1);
27
+ var import_oxc_parser = require("oxc-parser");
28
+ var fs = __toESM(require("node:fs"), 1);
29
+ var path = __toESM(require("node:path"), 1);
30
+ var import_metroNativeWorker = require("./metroNativeWorker.cjs");
31
+ var import_getMetroConfigFromViteConfig = require("../metro-config/getMetroConfigFromViteConfig.cjs");
32
+ const import_meta = {};
33
+ const babelCalls = {
34
+ transform: 0,
35
+ transformSync: 0,
36
+ transformAsync: 0,
37
+ transformFromAstSync: 0,
38
+ parse: 0,
39
+ parseSync: 0
40
+ };
41
+ import_vitest.vi.mock("@babel/core", async importOriginal => {
42
+ const actual = await importOriginal();
43
+ return {
44
+ ...actual,
45
+ transform: import_vitest.vi.fn((...args) => {
46
+ babelCalls.transform++;
47
+ return actual.transform(...args);
48
+ }),
49
+ transformSync: import_vitest.vi.fn((...args) => {
50
+ babelCalls.transformSync++;
51
+ return actual.transformSync(...args);
52
+ }),
53
+ transformAsync: import_vitest.vi.fn((...args) => {
54
+ babelCalls.transformAsync++;
55
+ return actual.transformAsync(...args);
56
+ }),
57
+ transformFromAstSync: import_vitest.vi.fn((...args) => {
58
+ babelCalls.transformFromAstSync++;
59
+ return actual.transformFromAstSync(...args);
60
+ }),
61
+ parse: import_vitest.vi.fn((...args) => {
62
+ babelCalls.parse++;
63
+ return actual.parse(...args);
64
+ }),
65
+ parseSync: import_vitest.vi.fn((...args) => {
66
+ babelCalls.parseSync++;
67
+ return actual.parseSync(...args);
68
+ })
69
+ };
70
+ });
71
+ (0, import_vitest.beforeEach)(() => {
72
+ babelCalls.transform = 0;
73
+ babelCalls.transformSync = 0;
74
+ babelCalls.transformAsync = 0;
75
+ babelCalls.transformFromAstSync = 0;
76
+ babelCalls.parse = 0;
77
+ babelCalls.parseSync = 0;
78
+ });
79
+ function assertZeroBabelCalls() {
80
+ (0, import_vitest.expect)(babelCalls.transform).toBe(0);
81
+ (0, import_vitest.expect)(babelCalls.transformSync).toBe(0);
82
+ (0, import_vitest.expect)(babelCalls.transformAsync).toBe(0);
83
+ (0, import_vitest.expect)(babelCalls.transformFromAstSync).toBe(0);
84
+ (0, import_vitest.expect)(babelCalls.parse).toBe(0);
85
+ (0, import_vitest.expect)(babelCalls.parseSync).toBe(0);
86
+ }
87
+ (0, import_vitest.describe)("metroNativeWorker", () => {
88
+ (0, import_vitest.it)("extracts all dependencies with oxc-parser and zero Babel", () => {
89
+ const deps = (0, import_metroNativeWorker.extractDependencies)(`
90
+ import React, { useState } from 'react'
91
+ import * as RN from 'react-native'
92
+ import './global.css'
93
+ import type { UserType } from './user-types'
94
+ export { Button } from './Button'
95
+ export * from './icons'
96
+ export type { ThemeType } from './theme-types'
97
+ const helper = require('./helper')
98
+ async function loadAsync() {
99
+ const dyn = await import('./dynamic-module')
100
+ }
101
+ `, "TestComponent.tsx");
102
+ assertZeroBabelCalls();
103
+ const names = deps.map(d => d.name);
104
+ (0, import_vitest.expect)(names).toContain("react");
105
+ (0, import_vitest.expect)(names).toContain("react-native");
106
+ (0, import_vitest.expect)(names).toContain("./global.css");
107
+ (0, import_vitest.expect)(names).toContain("./Button");
108
+ (0, import_vitest.expect)(names).toContain("./icons");
109
+ (0, import_vitest.expect)(names).toContain("./helper");
110
+ (0, import_vitest.expect)(names).toContain("./dynamic-module");
111
+ (0, import_vitest.expect)(names).not.toContain("./user-types");
112
+ (0, import_vitest.expect)(names).not.toContain("./theme-types");
113
+ const reactDep = deps.find(d => d.name === "react");
114
+ (0, import_vitest.expect)(reactDep.data.isESMImportAtSource).toBe(true);
115
+ (0, import_vitest.expect)(reactDep.data.asyncType).toBeNull();
116
+ (0, import_vitest.expect)(reactDep.data.locs.length).toBeGreaterThan(0);
117
+ const loc = reactDep.data.locs[0];
118
+ (0, import_vitest.expect)(loc.start.line).toBeGreaterThan(0);
119
+ (0, import_vitest.expect)(loc.start.column).toBeGreaterThanOrEqual(0);
120
+ (0, import_vitest.expect)(loc.end.line).toBeGreaterThanOrEqual(loc.start.line);
121
+ (0, import_vitest.expect)(loc.end.column).toBeGreaterThanOrEqual(0);
122
+ const helperDep = deps.find(d => d.name === "./helper");
123
+ (0, import_vitest.expect)(helperDep.data.isESMImportAtSource).toBe(false);
124
+ (0, import_vitest.expect)(helperDep.data.asyncType).toBeNull();
125
+ const dynamicDep = deps.find(d => d.name === "./dynamic-module");
126
+ (0, import_vitest.expect)(dynamicDep.data.asyncType).toBe("async");
127
+ });
128
+ (0, import_vitest.it)("marks requires inside a try block optional", () => {
129
+ const code = `
130
+ let worklets
131
+ try {
132
+ worklets = require('react-native-worklets-core')
133
+ } catch {}
134
+ const always = require('./always-there')
135
+ `;
136
+ const off = (0, import_metroNativeWorker.extractDependencies)(code, "setup.js");
137
+ (0, import_vitest.expect)(off.find(d => d.name === "react-native-worklets-core").data.isOptional).toBeUndefined();
138
+ const on = (0, import_metroNativeWorker.extractDependencies)(code, "setup.js", {
139
+ allowOptionalDependencies: true
140
+ });
141
+ (0, import_vitest.expect)(on.find(d => d.name === "react-native-worklets-core").data.isOptional).toBe(true);
142
+ (0, import_vitest.expect)(on.find(d => d.name === "./always-there").data.isOptional).toBeUndefined();
143
+ const excluded = (0, import_metroNativeWorker.extractDependencies)(code, "setup.js", {
144
+ allowOptionalDependencies: {
145
+ exclude: ["react-native-worklets-core"]
146
+ }
147
+ });
148
+ (0, import_vitest.expect)(excluded.find(d => d.name === "react-native-worklets-core").data.isOptional).toBeUndefined();
149
+ });
150
+ (0, import_vitest.it)("wraps modules in Metro CommonJS format with and without moduleId", () => {
151
+ const code = "exports.val = 123;";
152
+ const wrappedWithoutId = (0, import_metroNativeWorker.wrapModule)(code);
153
+ (0, import_vitest.expect)(wrappedWithoutId).toContain("__d(function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {");
154
+ (0, import_vitest.expect)(wrappedWithoutId).toContain("var require = _$$_REQUIRE;");
155
+ (0, import_vitest.expect)(wrappedWithoutId).toContain("exports.val = 123;");
156
+ (0, import_vitest.expect)(wrappedWithoutId.endsWith(");")).toBe(true);
157
+ const wrappedWithId = (0, import_metroNativeWorker.wrapModule)(code, {
158
+ moduleId: 99,
159
+ dependencyIds: [1, 2, 3]
160
+ });
161
+ (0, import_vitest.expect)(wrappedWithId).toContain(", 99, [1,2,3]);");
162
+ });
163
+ (0, import_vitest.it)("transforms TSX with React JSX, Hermes lowering, and ZERO Babel", async () => {
164
+ const result = await (0, import_metroNativeWorker.transform)({}, "/project", "Greeter.tsx", Buffer.from(`
165
+ import React from 'react'
166
+ import { View, Text } from 'react-native'
167
+ const helper = require('./helper')
168
+
169
+ export class Greeter extends React.Component {
170
+ greeting = 'Hello from Native'
171
+
172
+ async fetchGreeting() {
173
+ return this.greeting
174
+ }
175
+
176
+ render() {
177
+ return (
178
+ <View testID="greeter">
179
+ <Text>{this.greeting}</Text>
180
+ </View>
181
+ )
182
+ }
183
+ }
184
+ `, "utf8"), {
185
+ dev: true,
186
+ platform: "ios",
187
+ type: "module"
188
+ });
189
+ assertZeroBabelCalls();
190
+ (0, import_vitest.expect)(result.output).toHaveLength(1);
191
+ const output = result.output[0];
192
+ (0, import_vitest.expect)(output.type).toBe("js/module");
193
+ (0, import_vitest.expect)(output.data.lineCount).toBeGreaterThan(0);
194
+ (0, import_vitest.expect)(output.data.map.length).toBeGreaterThan(0);
195
+ const code = output.data.code;
196
+ (0, import_vitest.expect)(code).toContain("__d(function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {");
197
+ (0, import_vitest.expect)(code).toContain("var require = _$$_REQUIRE;");
198
+ (0, import_vitest.expect)(code).not.toContain("<View");
199
+ (0, import_vitest.expect)(code).not.toContain("<Text");
200
+ (0, import_vitest.expect)(code).toContain("this.greeting = \"Hello from Native\"");
201
+ const depNames = result.dependencies.map(d => d.name);
202
+ (0, import_vitest.expect)(depNames).toContain("react");
203
+ (0, import_vitest.expect)(depNames).toContain("react-native");
204
+ (0, import_vitest.expect)(depNames).toContain("./helper");
205
+ (0, import_vitest.expect)(depNames).toContain("react/jsx-dev-runtime");
206
+ });
207
+ (0, import_vitest.it)("lowers async generators, including the method shorthand Hermes also rejects", async () => {
208
+ for (const [filename, sourceCode] of Object.entries({
209
+ "cursor.ts": `
210
+ export class Cursor {
211
+ async *rows() {
212
+ yield await Promise.resolve(1)
213
+ }
214
+ }
215
+ `,
216
+ "stream.ts": `
217
+ export async function* stream() {
218
+ yield 1
219
+ }
220
+ `,
221
+ "drain.ts": `
222
+ export async function drain(src) {
223
+ for await (const x of src) {
224
+ console.log(x)
225
+ }
226
+ }
227
+ `
228
+ })) {
229
+ const result = await (0, import_metroNativeWorker.transform)({}, "/project", filename, Buffer.from(sourceCode, "utf8"), {
230
+ dev: true,
231
+ platform: "ios",
232
+ type: "module"
233
+ });
234
+ assertZeroBabelCalls();
235
+ const code = result.output[0].data.code;
236
+ (0, import_vitest.expect)(code, filename).not.toMatch(/\basync\s+function\s*\*/);
237
+ (0, import_vitest.expect)(code, filename).not.toMatch(/\basync\s*\*\s*[\w$[]/);
238
+ (0, import_vitest.expect)(code, filename).not.toMatch(/\bfor\s+await\s*\(/);
239
+ }
240
+ });
241
+ (0, import_vitest.it)("handles JSON files without Babel", async () => {
242
+ const jsonSource = JSON.stringify({
243
+ name: "my-package",
244
+ version: "1.0.0"
245
+ });
246
+ const result = await (0, import_metroNativeWorker.transform)({}, "/project", "package.json", Buffer.from(jsonSource, "utf8"), {
247
+ dev: true,
248
+ platform: "ios",
249
+ type: "module"
250
+ });
251
+ assertZeroBabelCalls();
252
+ (0, import_vitest.expect)(result.dependencies).toEqual([]);
253
+ (0, import_vitest.expect)(result.output).toHaveLength(1);
254
+ (0, import_vitest.expect)(result.output[0].type).toBe("js/module");
255
+ (0, import_vitest.expect)(result.output[0].data.code).toContain("module.exports = {\"name\":\"my-package\",\"version\":\"1.0.0\"}");
256
+ (0, import_vitest.expect)(result.output[0].data.code).toContain("__d(function (global, require");
257
+ });
258
+ (0, import_vitest.it)("handles Asset files without Babel", async () => {
259
+ const result = await (0, import_metroNativeWorker.transform)({
260
+ assetRegistryPath: "react-native/Libraries/Image/AssetRegistry",
261
+ publicPath: "/assets"
262
+ }, "/project", "logo.png", Buffer.from("fake-png-binary-data", "utf8"), {
263
+ dev: true,
264
+ platform: "ios",
265
+ type: "asset"
266
+ });
267
+ assertZeroBabelCalls();
268
+ (0, import_vitest.expect)(result.output[0].type).toBe("js/module/asset");
269
+ (0, import_vitest.expect)(result.output[0].data.code).toContain("registerAsset(");
270
+ (0, import_vitest.expect)(result.output[0].data.code).toContain("__d(function");
271
+ const depNames = result.dependencies.map(d => d.name);
272
+ (0, import_vitest.expect)(depNames).toContain("react-native/Libraries/Image/AssetRegistry");
273
+ });
274
+ (0, import_vitest.it)("handles Flow files by stripping types without Babel", async () => {
275
+ const result = await (0, import_metroNativeWorker.transform)({}, "/project", "math.js", Buffer.from(`
276
+ // @flow
277
+ function add(a: number, b: number): number {
278
+ return a + b;
279
+ }
280
+ export default add;
281
+ `, "utf8"), {
282
+ dev: false,
283
+ platform: "ios",
284
+ type: "module"
285
+ });
286
+ assertZeroBabelCalls();
287
+ (0, import_vitest.expect)(result.output[0].data.code).not.toContain(": number");
288
+ (0, import_vitest.expect)(result.output[0].data.code).toContain("function add(a, b)");
289
+ });
290
+ (0, import_vitest.it)("generates a deterministic cache key without Babel", () => {
291
+ const key1 = (0, import_metroNativeWorker.getCacheKey)({
292
+ globalPrefix: "__one_",
293
+ minifierPath: "terser"
294
+ }, {
295
+ projectRoot: "/app"
296
+ });
297
+ const key2 = (0, import_metroNativeWorker.getCacheKey)({
298
+ globalPrefix: "__one_",
299
+ minifierPath: "terser"
300
+ }, {
301
+ projectRoot: "/app"
302
+ });
303
+ const key3 = (0, import_metroNativeWorker.getCacheKey)({
304
+ globalPrefix: "__other_"
305
+ }, {
306
+ projectRoot: "/app"
307
+ });
308
+ assertZeroBabelCalls();
309
+ (0, import_vitest.expect)(key1).toBe(key2);
310
+ (0, import_vitest.expect)(key1).not.toBe(key3);
311
+ (0, import_vitest.expect)(typeof key1).toBe("string");
312
+ (0, import_vitest.expect)(key1.length).toBe(64);
313
+ });
314
+ (0, import_vitest.it)("correctly sets transformerPath in buildMetroConfigInputFromViteConfig when active", async () => {
315
+ const mockViteConfig = {
316
+ root: process.cwd()
317
+ };
318
+ delete process.env.ONE_METRO_NATIVE_TRANSFORMS;
319
+ const configDefault = await (0, import_getMetroConfigFromViteConfig.buildMetroConfigInputFromViteConfig)(mockViteConfig, {});
320
+ (0, import_vitest.expect)(configDefault.defaultConfig.transformerPath).toContain("metroNativeWorker");
321
+ (0, import_vitest.expect)(configDefault.defaultConfig.transformer.transformerPath).toBeUndefined();
322
+ const configOptOff = await (0, import_getMetroConfigFromViteConfig.buildMetroConfigInputFromViteConfig)(mockViteConfig, {
323
+ nativeTransforms: false
324
+ });
325
+ (0, import_vitest.expect)(configOptOff.defaultConfig.transformerPath).not.toContain("metroNativeWorker");
326
+ process.env.ONE_METRO_NATIVE_TRANSFORMS = "0";
327
+ const configEnvOff = await (0, import_getMetroConfigFromViteConfig.buildMetroConfigInputFromViteConfig)(mockViteConfig, {});
328
+ (0, import_vitest.expect)(configEnvOff.defaultConfig.transformerPath).not.toContain("metroNativeWorker");
329
+ process.env.ONE_METRO_NATIVE_TRANSFORMS = "1";
330
+ const configEnvOn = await (0, import_getMetroConfigFromViteConfig.buildMetroConfigInputFromViteConfig)(mockViteConfig, {
331
+ nativeTransforms: false
332
+ });
333
+ (0, import_vitest.expect)(configEnvOn.defaultConfig.transformerPath).toContain("metroNativeWorker");
334
+ delete process.env.ONE_METRO_NATIVE_TRANSFORMS;
335
+ });
336
+ (0, import_vitest.it)("transforms and executes a real 2-module Metro bundle through metro-runtime require polyfill", async () => {
337
+ const depSource = "exports.value = 42;";
338
+ const aSource = "const dep = require(\"./dep\"); module.exports = { doubled: dep.value * 2 };";
339
+ const depRes = await (0, import_metroNativeWorker.transform)({}, "/project", "dep.js", Buffer.from(depSource, "utf8"), {
340
+ dev: false,
341
+ platform: "ios",
342
+ type: "module",
343
+ moduleId: 2,
344
+ dependencyIds: []
345
+ });
346
+ const aRes = await (0, import_metroNativeWorker.transform)({}, "/project", "a.js", Buffer.from(aSource, "utf8"), {
347
+ dev: false,
348
+ platform: "ios",
349
+ type: "module",
350
+ moduleId: 1,
351
+ dependencyIds: [2]
352
+ });
353
+ assertZeroBabelCalls();
354
+ (0, import_vitest.expect)(aRes.dependencies).toHaveLength(1);
355
+ (0, import_vitest.expect)(aRes.dependencies[0].name).toBe("./dep");
356
+ const aEmittedCode = aRes.output[0].data.code;
357
+ (0, import_vitest.expect)(aEmittedCode).toContain("require(_dependencyMap[0], \"./dep\")");
358
+ const polyfillPath = require.resolve("metro-runtime/src/polyfills/require.js");
359
+ const polyfillCode = fs.readFileSync(polyfillPath, "utf8");
360
+ const contextObj = {
361
+ __DEV__: false,
362
+ __METRO_GLOBAL_PREFIX__: "",
363
+ console
364
+ };
365
+ contextObj.global = contextObj;
366
+ vm.createContext(contextObj);
367
+ vm.runInContext(polyfillCode, contextObj);
368
+ vm.runInContext(depRes.output[0].data.code, contextObj);
369
+ vm.runInContext(aEmittedCode, contextObj);
370
+ const executedExports = vm.runInContext("global.__r(1)", contextObj);
371
+ (0, import_vitest.expect)(executedExports).toEqual({
372
+ doubled: 84
373
+ });
374
+ });
375
+ (0, import_vitest.it)("transforms and executes a 2-module Metro bundle with ESM imports in dev mode", async () => {
376
+ const depSource = "export const greeting = \"Hello Metro Native\";";
377
+ const aSource = "import { greeting } from \"./dep\"; export const message = greeting.toUpperCase();";
378
+ const depRes = await (0, import_metroNativeWorker.transform)({}, "/project", "dep.js", Buffer.from(depSource, "utf8"), {
379
+ dev: true,
380
+ platform: "ios",
381
+ type: "module",
382
+ moduleId: 2,
383
+ dependencyIds: []
384
+ });
385
+ const aRes = await (0, import_metroNativeWorker.transform)({}, "/project", "a.js", Buffer.from(aSource, "utf8"), {
386
+ dev: true,
387
+ platform: "ios",
388
+ type: "module",
389
+ moduleId: 1,
390
+ dependencyIds: [2]
391
+ });
392
+ assertZeroBabelCalls();
393
+ const polyfillPath = require.resolve("metro-runtime/src/polyfills/require.js");
394
+ const polyfillCode = fs.readFileSync(polyfillPath, "utf8");
395
+ const contextObj = {
396
+ __DEV__: true,
397
+ __METRO_GLOBAL_PREFIX__: "",
398
+ console
399
+ };
400
+ contextObj.global = contextObj;
401
+ vm.createContext(contextObj);
402
+ vm.runInContext(polyfillCode, contextObj);
403
+ vm.runInContext(depRes.output[0].data.code, contextObj);
404
+ vm.runInContext(aRes.output[0].data.code, contextObj);
405
+ const executedExports = vm.runInContext("global.__r(1)", contextObj);
406
+ (0, import_vitest.expect)(executedExports.message).toBe("HELLO METRO NATIVE");
407
+ });
408
+ (0, import_vitest.it)("respects lexical scope shadowing for require calls (Astra probe)", async () => {
409
+ const res = await (0, import_metroNativeWorker.transform)({}, "/project", "shadowed.js", Buffer.from("function f(require){return require(\"./local\")}; module.exports=f(x=>x);", "utf8"), {
410
+ dev: false,
411
+ platform: "ios",
412
+ type: "module",
413
+ moduleId: 1,
414
+ dependencyIds: []
415
+ });
416
+ assertZeroBabelCalls();
417
+ (0, import_vitest.expect)(res.dependencies).toHaveLength(0);
418
+ const emitted = res.output[0].data.code;
419
+ (0, import_vitest.expect)(emitted).not.toContain("_dependencyMap[0]");
420
+ (0, import_vitest.expect)(emitted).toMatch(/require\d*\("\.\/local"\)/);
421
+ const polyfillPath = require.resolve("metro-runtime/src/polyfills/require.js");
422
+ const polyfillCode = fs.readFileSync(polyfillPath, "utf8");
423
+ const contextObj = {
424
+ __DEV__: false,
425
+ __METRO_GLOBAL_PREFIX__: "",
426
+ console
427
+ };
428
+ contextObj.global = contextObj;
429
+ vm.createContext(contextObj);
430
+ vm.runInContext(polyfillCode, contextObj);
431
+ vm.runInContext(emitted, contextObj);
432
+ const result = vm.runInContext("global.__r(1)", contextObj);
433
+ (0, import_vitest.expect)(result).toBe("./local");
434
+ });
435
+ (0, import_vitest.it)("preserves distinct indexed identity for duplicate and mixed sync/async dependencies", async () => {
436
+ const res = await (0, import_metroNativeWorker.transform)({}, "/project", "index.js", Buffer.from(`
437
+ const a = require('./dep');
438
+ const b = require('./dep');
439
+ async function load() {
440
+ const c = await import('./dep');
441
+ }
442
+ `, "utf8"), {
443
+ dev: false,
444
+ platform: "ios",
445
+ type: "module"
446
+ });
447
+ assertZeroBabelCalls();
448
+ const depNames = res.dependencies.map(d => d.name);
449
+ (0, import_vitest.expect)(depNames).toContain("./dep");
450
+ const syncDep = res.dependencies.find(d => d.name === "./dep" && d.data.asyncType === null);
451
+ const asyncDep = res.dependencies.find(d => d.name === "./dep" && d.data.asyncType === "async");
452
+ (0, import_vitest.expect)(syncDep).toBeDefined();
453
+ (0, import_vitest.expect)(asyncDep).toBeDefined();
454
+ (0, import_vitest.expect)(syncDep.data.index).not.toEqual(asyncDep.data.index);
455
+ const emitted = res.output[0].data.code;
456
+ const syncIndex = syncDep.data.index;
457
+ (0, import_vitest.expect)(emitted).toContain(`require(_dependencyMap[${syncIndex}], "./dep")`);
458
+ });
459
+ (0, import_vitest.it)("conforms to Metro map ABI with raw mapping segment tuples and accurate symbolication", async () => {
460
+ const res = await (0, import_metroNativeWorker.transform)({}, "/project", "math.ts", Buffer.from(`
461
+ export function add(a: number, b: number): number {
462
+ return a + b;
463
+ }
464
+ `, "utf8"), {
465
+ dev: false,
466
+ platform: "ios",
467
+ type: "module"
468
+ });
469
+ assertZeroBabelCalls();
470
+ const map = res.output[0].data.map;
471
+ (0, import_vitest.expect)(Array.isArray(map)).toBe(true);
472
+ (0, import_vitest.expect)(map.length).toBeGreaterThan(0);
473
+ for (const tuple of map) {
474
+ (0, import_vitest.expect)(Array.isArray(tuple)).toBe(true);
475
+ (0, import_vitest.expect)(typeof tuple[0]).toBe("number");
476
+ (0, import_vitest.expect)(typeof tuple[1]).toBe("number");
477
+ (0, import_vitest.expect)(tuple).not.toHaveProperty("version");
478
+ (0, import_vitest.expect)(tuple).not.toHaveProperty("mappings");
479
+ }
480
+ const msm = await import("metro-source-map");
481
+ const fullMap = msm.fromRawMappings([{
482
+ code: res.output[0].data.code,
483
+ source: "math.ts",
484
+ map
485
+ }]).toMap();
486
+ const consumer = new msm.Consumer(fullMap);
487
+ const addLineIndex = res.output[0].data.code.split("\n").findIndex(l => l.includes("function add"));
488
+ (0, import_vitest.expect)(addLineIndex).toBeGreaterThan(0);
489
+ const pos = consumer.originalPositionFor({
490
+ line: addLineIndex + 1,
491
+ column: 16
492
+ });
493
+ (0, import_vitest.expect)(pos.line).toBe(2);
494
+ });
495
+ (0, import_vitest.it)("models JS hoisting in ScopeTracker for functions and vars (Astra probe)", async () => {
496
+ const res = await (0, import_metroNativeWorker.transform)({}, "/project", "hoisted.js", Buffer.from("function f(){const x=require(\"./local\"); function require(x){return x}; return x} module.exports=f();", "utf8"), {
497
+ dev: false,
498
+ platform: "ios",
499
+ type: "module",
500
+ moduleId: 1,
501
+ dependencyIds: []
502
+ });
503
+ assertZeroBabelCalls();
504
+ (0, import_vitest.expect)(res.dependencies).toHaveLength(0);
505
+ const emitted = res.output[0].data.code;
506
+ (0, import_vitest.expect)(emitted).not.toContain("_dependencyMap[0]");
507
+ (0, import_vitest.expect)(emitted).toMatch(/require\d*\("\.\/local"\)/);
508
+ const polyfillPath = require.resolve("metro-runtime/src/polyfills/require.js");
509
+ const polyfillCode = fs.readFileSync(polyfillPath, "utf8");
510
+ const contextObj = {
511
+ __DEV__: false,
512
+ __METRO_GLOBAL_PREFIX__: "",
513
+ console
514
+ };
515
+ contextObj.global = contextObj;
516
+ vm.createContext(contextObj);
517
+ vm.runInContext(polyfillCode, contextObj);
518
+ vm.runInContext(emitted, contextObj);
519
+ const result = vm.runInContext("global.__r(1)", contextObj);
520
+ (0, import_vitest.expect)(result).toBe("./local");
521
+ });
522
+ (0, import_vitest.it)("rewrites dynamic import to Metro asyncRequire and executes promise resolution in dev and release", async () => {
523
+ const depSource = "exports.message = \"hello dynamic\";";
524
+ const mainSource = "module.exports = () => import(\"./dep\");";
525
+ const depRes = await (0, import_metroNativeWorker.transform)({}, "/project", "dep.js", Buffer.from(depSource, "utf8"), {
526
+ dev: true,
527
+ platform: "ios",
528
+ type: "module",
529
+ moduleId: 2,
530
+ dependencyIds: []
531
+ });
532
+ const mainRes = await (0, import_metroNativeWorker.transform)({}, "/project", "main.js", Buffer.from(mainSource, "utf8"), {
533
+ dev: true,
534
+ platform: "ios",
535
+ type: "module",
536
+ moduleId: 0,
537
+ dependencyIds: [2, 1]
538
+ });
539
+ assertZeroBabelCalls();
540
+ const depNames = mainRes.dependencies.map(d => d.name);
541
+ (0, import_vitest.expect)(depNames).toContain("./dep");
542
+ (0, import_vitest.expect)(depNames).toContain("metro-runtime/src/modules/asyncRequire");
543
+ const dynDep = mainRes.dependencies.find(d => d.name === "./dep");
544
+ (0, import_vitest.expect)(dynDep.data.asyncType).toBe("async");
545
+ const emittedMain = mainRes.output[0].data.code;
546
+ (0, import_vitest.expect)(emittedMain).not.toContain("import(\"./dep\")");
547
+ (0, import_vitest.expect)(emittedMain).toContain("require(_dependencyMap[1], \"metro-runtime/src/modules/asyncRequire\")(_dependencyMap[0], _dependencyMap.paths, \"./dep\")");
548
+ const polyfillPath = require.resolve("metro-runtime/src/polyfills/require.js");
549
+ const polyfillCode = fs.readFileSync(polyfillPath, "utf8");
550
+ const asyncRequirePath = require.resolve("metro-runtime/src/modules/asyncRequire.js");
551
+ const asyncRequireSource = fs.readFileSync(asyncRequirePath, "utf8");
552
+ const wrappedAsyncRequire = (0, import_metroNativeWorker.wrapModule)(asyncRequireSource, {
553
+ moduleId: 1,
554
+ dependencyIds: []
555
+ });
556
+ for (const isDev of [true, false]) {
557
+ const contextObj = {
558
+ __DEV__: isDev,
559
+ __METRO_GLOBAL_PREFIX__: "",
560
+ console
561
+ };
562
+ contextObj.global = contextObj;
563
+ vm.createContext(contextObj);
564
+ vm.runInContext(polyfillCode, contextObj);
565
+ vm.runInContext(wrappedAsyncRequire, contextObj);
566
+ vm.runInContext(depRes.output[0].data.code, contextObj);
567
+ vm.runInContext(emittedMain, contextObj);
568
+ const mainFn = vm.runInContext("global.__r(0)", contextObj);
569
+ (0, import_vitest.expect)(typeof mainFn).toBe("function");
570
+ const promise = mainFn();
571
+ (0, import_vitest.expect)(promise instanceof Promise || promise && typeof promise.then === "function").toBe(true);
572
+ const resolved = await promise;
573
+ (0, import_vitest.expect)(resolved.message).toBe("hello dynamic");
574
+ (0, import_vitest.expect)(resolved.default.message).toBe("hello dynamic");
575
+ }
576
+ });
577
+ (0, import_vitest.it)("preserves accurate sourcemap for tokens after rewritten require calls on the same line", async () => {
578
+ const sourceCode = "const a = require(\"./dep\"), b = 42;";
579
+ const resWrapped = await (0, import_metroNativeWorker.transform)({}, "/project", "app.js", Buffer.from(sourceCode, "utf8"), {
580
+ dev: false,
581
+ platform: "ios",
582
+ type: "module"
583
+ });
584
+ assertZeroBabelCalls();
585
+ const msm = await import("metro-source-map");
586
+ const fullMapWrapped = msm.fromRawMappings([{
587
+ code: resWrapped.output[0].data.code,
588
+ source: "app.js",
589
+ map: resWrapped.output[0].data.map
590
+ }]).toMap();
591
+ const consumerWrapped = new msm.Consumer(fullMapWrapped);
592
+ const linesWrapped = resWrapped.output[0].data.code.split("\n");
593
+ const lineIndexWrapped = linesWrapped.findIndex(l => l.includes("b = 42"));
594
+ (0, import_vitest.expect)(lineIndexWrapped).toBeGreaterThanOrEqual(0);
595
+ const generatedColWrapped = linesWrapped[lineIndexWrapped].indexOf("b = 42");
596
+ (0, import_vitest.expect)(generatedColWrapped).toBeGreaterThan(0);
597
+ const posWrapped = consumerWrapped.originalPositionFor({
598
+ line: lineIndexWrapped + 1,
599
+ column: generatedColWrapped
600
+ });
601
+ (0, import_vitest.expect)(posWrapped.line).toBe(1);
602
+ (0, import_vitest.expect)(posWrapped.column).toBe(28);
603
+ (0, import_vitest.expect)(sourceCode.slice(Number(posWrapped.column))).toContain("b = 42;");
604
+ const resUnwrapped = await (0, import_metroNativeWorker.transform)({
605
+ unstable_disableModuleWrapping: true
606
+ }, "/project", "app.js", Buffer.from(sourceCode, "utf8"), {
607
+ dev: false,
608
+ platform: "ios",
609
+ type: "module"
610
+ });
611
+ const fullMapUnwrapped = msm.fromRawMappings([{
612
+ code: resUnwrapped.output[0].data.code,
613
+ source: "app.js",
614
+ map: resUnwrapped.output[0].data.map
615
+ }]).toMap();
616
+ const consumerUnwrapped = new msm.Consumer(fullMapUnwrapped);
617
+ const linesUnwrapped = resUnwrapped.output[0].data.code.split("\n");
618
+ const lineIndexUnwrapped = linesUnwrapped.findIndex(l => l.includes("b = 42"));
619
+ (0, import_vitest.expect)(lineIndexUnwrapped).toBeGreaterThanOrEqual(0);
620
+ const generatedColUnwrapped = linesUnwrapped[lineIndexUnwrapped].indexOf("b = 42");
621
+ const posUnwrapped = consumerUnwrapped.originalPositionFor({
622
+ line: lineIndexUnwrapped + 1,
623
+ column: generatedColUnwrapped
624
+ });
625
+ (0, import_vitest.expect)(posUnwrapped.line).toBe(1);
626
+ (0, import_vitest.expect)(posUnwrapped.column).toBe(28);
627
+ });
628
+ (0, import_vitest.it)("routes a require.context whose directory is held in a variable through the dependency map", async () => {
629
+ const result = await (0, import_metroNativeWorker.transform)({}, "/project", "entry.js", Buffer.from(`
630
+ const routeRoot = './app'
631
+ export const ctx = require.context(routeRoot, true, /\\.tsx$/)
632
+ `, "utf8"), {
633
+ dev: true,
634
+ platform: "ios",
635
+ type: "module"
636
+ });
637
+ const contextDep = result.dependencies.find(d => d.data.contextParams != null);
638
+ (0, import_vitest.expect)(contextDep?.name).toBe("./app");
639
+ const calls = [];
640
+ let ctx;
641
+ vm.runInNewContext(result.output[0].data.code, {
642
+ __d: factory => {
643
+ const module2 = {
644
+ exports: {}
645
+ };
646
+ const req = (...args) => {
647
+ calls.push(args);
648
+ return {
649
+ keys: () => []
650
+ };
651
+ };
652
+ req.context = () => {
653
+ throw new Error("fallbackRequireContext reached");
654
+ };
655
+ factory({}, req, () => ({}), () => ({}), module2, module2.exports, ["./app"]);
656
+ ctx = module2.exports.ctx;
657
+ }
658
+ });
659
+ (0, import_vitest.expect)(ctx).toBeDefined();
660
+ (0, import_vitest.expect)(calls[0][1]).toBe("./app");
661
+ });
662
+ (0, import_vitest.it)("gives loop bodies per-iteration bindings that survive a runtime without them", async () => {
663
+ const asHermesWouldSeeIt = (await (0, import_metroNativeWorker.transform)({}, "/project", "loops.ts", Buffer.from(`
664
+ export function collect() {
665
+ const out = []
666
+ for (let i = 0; i < 2; i++) out.push(() => i)
667
+ for (const label of ['a', 'b']) out.push(() => label)
668
+ for (const key in { x: 1, y: 2 }) out.push(() => key)
669
+ return out.map((f) => f())
670
+ }
671
+ `, "utf8"), {
672
+ dev: true,
673
+ platform: "ios",
674
+ type: "module"
675
+ })).output[0].data.code.replace(/\bfor\s*\(\s*(let|const)\b/g, "for (var");
676
+ let collect;
677
+ vm.runInNewContext(asHermesWouldSeeIt, {
678
+ __d: factory => {
679
+ const module2 = {
680
+ exports: {}
681
+ };
682
+ factory({}, () => ({}), () => ({}), () => ({}), module2, module2.exports, []);
683
+ collect = module2.exports.collect;
684
+ }
685
+ });
686
+ (0, import_vitest.expect)(collect()).toEqual([0, 1, "a", "b", "x", "y"]);
687
+ });
688
+ });
689
+ (0, import_vitest.describe)("one native transform ports", () => {
690
+ (0, import_vitest.it)("inlines process.env.ONE_SERVER_URL so a native bundle can find its loaders", () => {
691
+ process.env.ONE_SERVER_URL = "https://example.test";
692
+ try {
693
+ const out = (0, import_metroNativeWorker.applyInlineEnvVars)("export const url = process.env.ONE_SERVER_URL;", "loader.ts", false);
694
+ (0, import_vitest.expect)(out).toBe("export const url = \"https://example.test\";");
695
+ } finally {
696
+ process.env.ONE_SERVER_URL = void 0;
697
+ }
698
+ });
699
+ (0, import_vitest.it)("leaves ONE_SERVER_URL alone when it is only a string", () => {
700
+ const src = "export const key = \"process.env.ONE_SERVER_URL\";";
701
+ (0, import_vitest.expect)((0, import_metroNativeWorker.applyInlineEnvVars)(src, "a.ts", false)).toBe(src);
702
+ });
703
+ (0, import_vitest.it)("inlines import.meta.env reads, which oxc otherwise lowers to an empty object", () => {
704
+ const out = (0, import_metroNativeWorker.applyInlineEnvVars)(`export const key = import.meta.env.VITE_POSTHOG_API_KEY;
705
+ export const target = import.meta.env?.TAMAGUI_TARGET;
706
+ export const missing = import.meta.env.NOT_SET;
707
+ export const all = { ...import.meta.env };`, "env.ts", true, {
708
+ DEV: false,
709
+ VITE_POSTHOG_API_KEY: "pk_live",
710
+ TAMAGUI_TARGET: "native"
711
+ });
712
+ (0, import_vitest.expect)(out).toContain("export const key = \"pk_live\";");
713
+ (0, import_vitest.expect)(out).toContain("export const target = \"native\";");
714
+ (0, import_vitest.expect)(out).toContain("export const missing = undefined;");
715
+ (0, import_vitest.expect)(out).toContain("\"VITE_POSTHOG_API_KEY\":\"pk_live\"");
716
+ (0, import_vitest.expect)(out).not.toContain("import.meta");
717
+ });
718
+ (0, import_vitest.it)("inlines process.env keys the vite env map defines", () => {
719
+ const out = (0, import_metroNativeWorker.applyInlineEnvVars)("export const t = process.env.TAMAGUI_TARGET; export const u = process.env.UNKNOWN_THING;", "env.ts", true, {
720
+ TAMAGUI_TARGET: "native"
721
+ });
722
+ (0, import_vitest.expect)(out).toContain("export const t = \"native\";");
723
+ (0, import_vitest.expect)(out).toContain("process.env.UNKNOWN_THING");
724
+ });
725
+ (0, import_vitest.it)("never rewrites an env read in an assignment target", () => {
726
+ const src = "process.env.VITE_ENVIRONMENT = \"ssr\";";
727
+ (0, import_vitest.expect)((0, import_metroNativeWorker.applyInlineEnvVars)(src, "a.ts", true, {
728
+ VITE_ENVIRONMENT: "ios"
729
+ })).toBe(src);
730
+ });
731
+ (0, import_vitest.it)("folds branches the inlining made constant so metro never resolves dead imports", () => {
732
+ const out = (0, import_metroNativeWorker.applyInlineEnvVars)(`if (import.meta.env.SSR) { require('./server-only-thing') } else { load(import.meta.env.API) }`, "branch.ts", true, {
733
+ SSR: false,
734
+ API: "https://api.test"
735
+ });
736
+ (0, import_vitest.expect)(out).not.toContain("server-only-thing");
737
+ (0, import_vitest.expect)(out).toContain("load(\"https://api.test\")");
738
+ });
739
+ (0, import_vitest.it)("folds a ternary and keeps a branch it cannot resolve", () => {
740
+ (0, import_vitest.expect)((0, import_metroNativeWorker.applyInlineEnvVars)("const a = import.meta.env.DEV ? x : y;", "a.ts", true, {
741
+ DEV: false
742
+ })).toContain("const a = y;");
743
+ const dynamic = "const a = flag ? x : y;";
744
+ (0, import_vitest.expect)((0, import_metroNativeWorker.applyInlineEnvVars)(dynamic, "a.ts", true, {
745
+ DEV: false
746
+ })).toBe(dynamic);
747
+ });
748
+ (0, import_vitest.it)("runs the user native transforms that stand in for their babel plugins", async () => {
749
+ const result = await (0, import_metroNativeWorker.transform)({}, import_meta.dirname, "ota.ts", Buffer.from("export const id = __EXAMPLE_BUILD_ID; export const from = __EXAMPLE_FILENAME;", "utf8"), {
750
+ dev: true,
751
+ platform: "ios",
752
+ type: "module",
753
+ customTransformOptions: {
754
+ vite: {
755
+ nativeTransformModules: ["./__fixtures__/exampleNativeTransform.cjs"]
756
+ }
757
+ }
758
+ });
759
+ assertZeroBabelCalls();
760
+ (0, import_vitest.expect)(result.output[0].data.code).toContain("\"ios-build\"");
761
+ (0, import_vitest.expect)(result.output[0].data.code).not.toContain("__EXAMPLE_BUILD_ID");
762
+ (0, import_vitest.expect)(result.output[0].data.code).toContain(JSON.stringify(path.join(import_meta.dirname, "ota.ts")));
763
+ });
764
+ (0, import_vitest.it)("refuses to build when a user babel plugin has no native port", () => {
765
+ const withPlugins = plugins => ({
766
+ customTransformOptions: {
767
+ vite: {
768
+ babelConfig: {
769
+ plugins
770
+ }
771
+ }
772
+ }
773
+ });
774
+ (0, import_vitest.expect)(() => (0, import_metroNativeWorker.assertNoUnportedBabelPlugins)(withPlugins([["@vxrn/vite-plugin-metro/babel-plugins/import-meta-env-plugin", {
775
+ env: {}
776
+ }], "one/babel-plugin-environment-guard", "hot-updater/babel-plugin"]))).toThrow(/hot-updater\/babel-plugin/);
777
+ (0, import_vitest.expect)(() => (0, import_metroNativeWorker.assertNoUnportedBabelPlugins)(withPlugins([["@vxrn/vite-plugin-metro/babel-plugins/import-meta-env-plugin", {
778
+ env: {}
779
+ }], "one/babel-plugin-environment-guard", ["one/babel-plugin-remove-server-code", {
780
+ routerRoot: "app"
781
+ }], ["babel-plugin-module-resolver", {
782
+ alias: {}
783
+ }], ["one/babel-plugin-one-router-metro", {}], "one/babel-plugin-inline-one-server-url", "babel-plugin-react-compiler", "react-native-reanimated/plugin"]))).not.toThrow();
784
+ });
785
+ (0, import_vitest.it)("turns a server-only import into a throw and drops native-only", () => {
786
+ const out = (0, import_metroNativeWorker.applyEnvironmentGuard)(`import 'native-only'
787
+ import 'server-only'
788
+ export const a = 1`, "route.ts");
789
+ (0, import_vitest.expect)(out).not.toContain("native-only");
790
+ (0, import_vitest.expect)(out).toContain("server-only cannot be imported in a native environment");
791
+ const parsed = (0, import_oxc_parser.parseSync)("route.ts", out, {
792
+ lang: "ts"
793
+ });
794
+ (0, import_vitest.expect)(parsed.errors).toEqual([]);
795
+ (0, import_vitest.expect)(parsed.program.body.map(n => n.type)).toContain("ThrowStatement");
796
+ });
797
+ (0, import_vitest.it)("reads the router root off one's remove-server-code plugin entry", () => {
798
+ (0, import_vitest.expect)((0, import_metroNativeWorker.getRemoveServerCodeRouterRoot)({
799
+ customTransformOptions: {
800
+ vite: {
801
+ babelConfig: {
802
+ plugins: [["one/babel-plugin-remove-server-code", {
803
+ routerRoot: "src/app"
804
+ }]]
805
+ }
806
+ }
807
+ }
808
+ })).toBe("src/app");
809
+ (0, import_vitest.expect)((0, import_metroNativeWorker.getRemoveServerCodeRouterRoot)({
810
+ customTransformOptions: {}
811
+ })).toBe(void 0);
812
+ });
813
+ });