vxrn 2.8.0 → 2.9.0

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 (52) hide show
  1. package/dist/exports/clean.mjs +128 -19
  2. package/dist/exports/clean.mjs.map +1 -1
  3. package/dist/exports/clean.native.js +147 -21
  4. package/dist/exports/clean.native.js.map +1 -1
  5. package/dist/exports/prebuild.mjs +2 -1
  6. package/dist/exports/prebuild.mjs.map +1 -1
  7. package/dist/exports/prebuild.native.js +2 -1
  8. package/dist/exports/prebuild.native.js.map +1 -1
  9. package/dist/exports/prebuildWithoutExpo.mjs +196 -7
  10. package/dist/exports/prebuildWithoutExpo.mjs.map +1 -1
  11. package/dist/exports/prebuildWithoutExpo.native.js +280 -42
  12. package/dist/exports/prebuildWithoutExpo.native.js.map +1 -1
  13. package/dist/plugins/reactNativeDevServer.mjs +1 -1
  14. package/dist/plugins/reactNativeDevServer.mjs.map +1 -1
  15. package/dist/plugins/reactNativeDevServer.native.js +1 -1
  16. package/dist/plugins/reactNativeDevServer.native.js.map +1 -1
  17. package/dist/user-interface/index.mjs +31 -24
  18. package/dist/user-interface/index.mjs.map +1 -1
  19. package/dist/user-interface/index.native.js +32 -25
  20. package/dist/user-interface/index.native.js.map +1 -1
  21. package/dist/utils/createNativeDevEngine.mjs +111 -14
  22. package/dist/utils/createNativeDevEngine.mjs.map +1 -1
  23. package/dist/utils/createNativeDevEngine.native.js +143 -14
  24. package/dist/utils/createNativeDevEngine.native.js.map +1 -1
  25. package/dist/utils/scanDepsToOptimize.mjs +10 -6
  26. package/dist/utils/scanDepsToOptimize.mjs.map +1 -1
  27. package/dist/utils/scanDepsToOptimize.native.js +12 -6
  28. package/dist/utils/scanDepsToOptimize.native.js.map +1 -1
  29. package/expo-plugin.cjs +71 -8
  30. package/package.json +13 -13
  31. package/src/exports/clean.test.ts +502 -5
  32. package/src/exports/clean.ts +176 -19
  33. package/src/exports/expoPlugin.test.mjs +44 -1
  34. package/src/exports/prebuild.ts +6 -0
  35. package/src/exports/prebuildWithoutExpo.test.ts +134 -2
  36. package/src/exports/prebuildWithoutExpo.ts +235 -10
  37. package/src/plugins/reactNativeDevServer.ts +1 -1
  38. package/src/user-interface/index.ts +50 -42
  39. package/src/utils/createNativeDevEngine.test.ts +486 -7
  40. package/src/utils/createNativeDevEngine.ts +220 -17
  41. package/src/utils/imageSizePatch.test.ts +3 -3
  42. package/src/utils/scanDepsToOptimize.test.ts +35 -2
  43. package/src/utils/scanDepsToOptimize.ts +25 -8
  44. package/types/exports/clean.d.ts.map +1 -1
  45. package/types/exports/prebuild.d.ts +2 -1
  46. package/types/exports/prebuild.d.ts.map +1 -1
  47. package/types/exports/prebuildWithoutExpo.d.ts.map +1 -1
  48. package/types/user-interface/index.d.ts.map +1 -1
  49. package/types/utils/createNativeDevEngine.d.ts +1 -1
  50. package/types/utils/createNativeDevEngine.d.ts.map +1 -1
  51. package/types/utils/scanDepsToOptimize.d.ts +25 -0
  52. package/types/utils/scanDepsToOptimize.d.ts.map +1 -1
@@ -3,9 +3,11 @@ import { basename, dirname, extname, join, relative, resolve } from "path";
3
3
  import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, watch, writeFileSync } from "fs";
4
4
  import { pathToFileURL } from "url";
5
5
  import micromatch from "micromatch";
6
+ import { parseSync } from "oxc-parser";
6
7
  import { loadEnv, normalizePath } from "vite";
7
8
  import { shouldStripFlow, transformHermesAsync } from "@vxrn/compiler";
8
9
  import { resolvePath } from "@vxrn/resolve";
10
+ import { nativeAppDefines } from "@vxrn/utils/nativeAppManifest";
9
11
  import { withExpoPublicEnvAliases } from "@vxrn/utils/publicEnv";
10
12
  import { DEFAULT_ASSET_EXTS } from "../constants/defaults.native.js";
11
13
  import { getNativePrelude } from "../runtime/native-prelude.native.js";
@@ -152,6 +154,7 @@ function getNativeTransformConfig(platform, dev, root) {
152
154
  jsx: { runtime: "classic" },
153
155
  define: {
154
156
  ...userDefines,
157
+ ...nativeAppDefines(entryConfig.app),
155
158
  ...envDefines,
156
159
  "process.env.NODE_ENV": JSON.stringify(mode),
157
160
  "process.env.VXRN_REACT_19": "false",
@@ -179,7 +182,7 @@ function getNativeTransformConfig(platform, dev, root) {
179
182
  };
180
183
  }
181
184
  function getNativePlugins(root, platform, viteImportGlobPlugin, dev, assetsDest, onAsset) {
182
- var sourceMaps = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : false, userPlugins = arguments.length > 7 && arguments[7] !== void 0 ? arguments[7] : [];
185
+ var sourceMaps = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : false, userPlugins = arguments.length > 7 && arguments[7] !== void 0 ? arguments[7] : [], minify = arguments.length > 8 && arguments[8] !== void 0 ? arguments[8] : false;
183
186
  var _globalThis___vxrnAddNativePlugins, _globalThis;
184
187
  var context = {
185
188
  root,
@@ -201,6 +204,7 @@ function getNativePlugins(root, platform, viteImportGlobPlugin, dev, assetsDest,
201
204
  rnCodegenPlugin({ projectRoot: root }),
202
205
  flowStripPlugin(),
203
206
  vxrnCompilerPlugin(platform, dev, root, sourceMaps),
207
+ mixedNativeModulePlugin(sourceMaps),
204
208
  nativeAnimatedGuardPlugin(),
205
209
  assetPlugin({
206
210
  root,
@@ -208,7 +212,7 @@ function getNativePlugins(root, platform, viteImportGlobPlugin, dev, assetsDest,
208
212
  assetsDest,
209
213
  onAsset
210
214
  }),
211
- hermesCompatSWCPlugin(dev, sourceMaps),
215
+ hermesCompatSWCPlugin(dev, sourceMaps, !minify),
212
216
  hermesLoopsPlugin(sourceMaps),
213
217
  ...userPlugins,
214
218
  nativeExportsPrecedencePlugin(root, platform),
@@ -228,11 +232,108 @@ function getNativeOutputOptions(prelude, sourcemap, minify) {
228
232
  intro: prelude,
229
233
  codeSplitting: false,
230
234
  strictExecutionOrder: true,
231
- minify: minify || "dce-only"
235
+ minify: minify || "dce-only",
236
+ keepNames: !minify
232
237
  };
233
238
  }
234
239
  function normalizeNativeCommonJSInterop(code) {
235
- return code.replace(/(\b__toESM(?:\$\d+)?\(\s*(?:require[\w$]*\(\)|[\w$]+|__rolldown_runtime__\.loadExports\("(?:\\.|[^"\\])*"\))\s*),\s*1(\s*\))/g, "$1$2");
240
+ if (!code.includes("__toESM")) return code;
241
+ var { program, errors } = parseSync("native-bundle.js", code, { lang: "js" });
242
+ if (errors.length) throw new Error(`[vxrn] cannot normalize native CommonJS interop: the bundle does not parse (${errors[0].message})`);
243
+ var deletions = [];
244
+ var stack = [program];
245
+ while (stack.length) {
246
+ var node = stack.pop();
247
+ if (Array.isArray(node)) {
248
+ for (var index = node.length - 1; index >= 0; index--) stack.push(node[index]);
249
+ continue;
250
+ }
251
+ if (!isInteropSyntaxNode(node)) continue;
252
+ if (node.type === "CallExpression") {
253
+ var span = interopNodeModeSpan(code, node);
254
+ if (span) deletions.push(span);
255
+ }
256
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
257
+ try {
258
+ for (var _iterator = Object.keys(node)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
259
+ var key = _step.value;
260
+ stack.push(node[key]);
261
+ }
262
+ } catch (err) {
263
+ _didIteratorError = true;
264
+ _iteratorError = err;
265
+ } finally {
266
+ try {
267
+ if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
268
+ } finally {
269
+ if (_didIteratorError) throw _iteratorError;
270
+ }
271
+ }
272
+ }
273
+ deletions.sort(function(a, b) {
274
+ return b[0] - a[0];
275
+ });
276
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
277
+ try {
278
+ for (var _iterator1 = deletions[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
279
+ var [start, end] = _step1.value;
280
+ code = code.slice(0, start) + code.slice(end);
281
+ }
282
+ } catch (err) {
283
+ _didIteratorError1 = true;
284
+ _iteratorError1 = err;
285
+ } finally {
286
+ try {
287
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) _iterator1.return();
288
+ } finally {
289
+ if (_didIteratorError1) throw _iteratorError1;
290
+ }
291
+ }
292
+ return code;
293
+ }
294
+ function isInteropSyntaxNode(node) {
295
+ if (!node || typeof node !== "object") return false;
296
+ var candidate = node;
297
+ return typeof candidate.type === "string" && typeof candidate.start === "number" && typeof candidate.end === "number";
298
+ }
299
+ var NATIVE_INTEROP_HELPER = /^__toESM(?:\$\d+)?$/;
300
+ var NATIVE_INTEROP_REQUIRE = /^require[\w$]*$/;
301
+ function interopNodeModeSpan(code, node) {
302
+ var callee = node["callee"];
303
+ if (!isInteropSyntaxNode(callee) || !isInteropHelperCallee(callee) || node["optional"] === true) return;
304
+ var args = node["arguments"];
305
+ if (!Array.isArray(args) || args.length !== 2) return void 0;
306
+ var [first, second] = args;
307
+ if (!isInteropSyntaxNode(first) || !isInteropSyntaxNode(second)) return void 0;
308
+ if (!isInteropFirstArgument(first)) return void 0;
309
+ if (second.type !== "Literal" || second["raw"] !== "1") return void 0;
310
+ var between = code.slice(first.end, second.start);
311
+ if (!/^\s*,\s*$/.test(between)) return void 0;
312
+ if (!/^\s*\)/.test(code.slice(second.end))) return void 0;
313
+ return [first.end + between.indexOf(","), second.end];
314
+ }
315
+ function isInteropHelperCallee(callee) {
316
+ if (callee.type === "Identifier") return typeof callee["name"] === "string" && NATIVE_INTEROP_HELPER.test(callee["name"]);
317
+ if ((callee.type === "MemberExpression" || callee.type === "StaticMemberExpression") && callee["computed"] !== true) {
318
+ var property = callee["property"];
319
+ return isInteropSyntaxNode(property) && property.type === "Identifier" && typeof property["name"] === "string" && NATIVE_INTEROP_HELPER.test(property["name"]);
320
+ }
321
+ return false;
322
+ }
323
+ function isInteropFirstArgument(node) {
324
+ if (node.type === "Identifier") return true;
325
+ if (node.type !== "CallExpression" || node["optional"] === true) return false;
326
+ var callee = node["callee"];
327
+ if (!isInteropSyntaxNode(callee)) return false;
328
+ var args = node["arguments"];
329
+ if (!Array.isArray(args)) return false;
330
+ if (callee.type === "Identifier") return typeof callee["name"] === "string" && NATIVE_INTEROP_REQUIRE.test(callee["name"]) && args.length === 0;
331
+ if ((callee.type === "MemberExpression" || callee.type === "StaticMemberExpression") && callee["computed"] !== true && callee["optional"] !== true) {
332
+ var object = callee["object"];
333
+ var property = callee["property"];
334
+ return isInteropSyntaxNode(object) && object.type === "Identifier" && object["name"] === "__rolldown_runtime__" && isInteropSyntaxNode(property) && property.type === "Identifier" && property["name"] === "loadExports" && args.length === 1 && isInteropSyntaxNode(args[0]) && args[0].type === "Literal" && typeof args[0]["value"] === "string";
335
+ }
336
+ return false;
236
337
  }
237
338
  function blankPreservingLines(match) {
238
339
  var _ref;
@@ -476,9 +577,26 @@ try {
476
577
  });
477
578
  if (chunk && "code" in chunk) {
478
579
  firstBuildError = null;
479
- var code = postProcessNativeBundle(chunk.code);
480
- code = await downlevelClassFieldsInBundle(code);
481
- assertBundleLinesPreserved(chunk.code, code, "dev");
580
+ var code;
581
+ try {
582
+ code = postProcessNativeBundle(chunk.code);
583
+ code = await downlevelClassFieldsInBundle(code);
584
+ assertBundleLinesPreserved(chunk.code, code, "dev");
585
+ } catch (error) {
586
+ var failure = error instanceof Error ? error : new Error(String(error));
587
+ console.error("[vxrn] native bundle post-processing failed:", failure.message);
588
+ if (!currentBundle) {
589
+ firstBuildError = failure;
590
+ if (bundleReject) {
591
+ var reject1 = bundleReject;
592
+ bundleResolve = null;
593
+ bundleReject = null;
594
+ bundlePromise = null;
595
+ reject1(failure);
596
+ }
597
+ }
598
+ return;
599
+ }
482
600
  code = wrapNativeBundleModuleScope(code);
483
601
  if (!chunk.map) throw new Error("[vxrn] rolldown produced no source map for the dev bundle, so /symbolicate cannot resolve a frame");
484
602
  currentBundle = {
@@ -584,7 +702,7 @@ async function buildNativeBundle(options) {
584
702
  dev,
585
703
  platform
586
704
  }).plugin],
587
- ...getNativePlugins(root, platform, viteImportGlobPlugin, dev, assetsDest, void 0, sourcemap, userPlugins),
705
+ ...getNativePlugins(root, platform, viteImportGlobPlugin, dev, assetsDest, void 0, sourcemap, userPlugins, minify),
588
706
  nativeBundlePostProcessPlugin()
589
707
  ],
590
708
  output: {
@@ -1317,6 +1435,16 @@ if (import.meta.hot) {
1317
1435
  }
1318
1436
  };
1319
1437
  }
1438
+ function mixedNativeModulePlugin(sourceMaps) {
1439
+ return {
1440
+ name: "vxrn:mixed-native-module",
1441
+ async transform(code, id) {
1442
+ if (!/\.[cm]?[jt]sx?$/.test(id) || id.includes("\0")) return;
1443
+ var { transformMixedNativeModule } = await import("@vxrn/compiler");
1444
+ return transformMixedNativeModule(code, id, sourceMaps);
1445
+ }
1446
+ };
1447
+ }
1320
1448
  function flowStripPlugin() {
1321
1449
  return {
1322
1450
  name: "vxrn:flow-strip",
@@ -1485,7 +1613,7 @@ async function getNativeAssetData(id, root, platform) {
1485
1613
  };
1486
1614
  if (NATIVE_IMAGE_EXTS.has(requested.type)) try {
1487
1615
  var { imageSize } = await import("image-size");
1488
- var dims = imageSize(files[0]);
1616
+ var dims = imageSize(readFileSync(files[0]));
1489
1617
  assetData.width = dims.width === void 0 ? void 0 : dims.width / scales[0];
1490
1618
  assetData.height = dims.height === void 0 ? void 0 : dims.height / scales[0];
1491
1619
  } catch (unused) {}
@@ -1550,7 +1678,7 @@ function copyNativeAssetFiles(asset, assetsDest, platform) {
1550
1678
  }
1551
1679
  }
1552
1680
  function hermesCompatSWCPlugin(dev) {
1553
- var sourceMaps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1681
+ var sourceMaps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, keepNames = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
1554
1682
  var oxc = null;
1555
1683
  return {
1556
1684
  name: "vxrn:hermes-compat",
@@ -1599,7 +1727,7 @@ ${err.codeframe}` : ""));
1599
1727
  output = classes;
1600
1728
  }
1601
1729
  }
1602
- var lowered = await transformHermesAsync((_ref = output === null || output === void 0 ? void 0 : output.code) !== null && _ref !== void 0 ? _ref : code, id, sourceMaps);
1730
+ var lowered = await transformHermesAsync((_ref = output === null || output === void 0 ? void 0 : output.code) !== null && _ref !== void 0 ? _ref : code, id, sourceMaps, void 0, keepNames);
1603
1731
  if (!lowered) return output;
1604
1732
  if (lowered.map && (output === null || output === void 0 ? void 0 : output.map)) {
1605
1733
  var remapping1 = (await import("@jridgewell/remapping")).default;
@@ -1775,6 +1903,10 @@ class ReactNativeDevRuntime extends BaseDevRuntime {
1775
1903
  if (!this.isExecuted(changedId)) continue;
1776
1904
  if (!this.findBoundaries(changedId, traversed, updateSet, boundaries)) return false;
1777
1905
  }
1906
+ // register the patch's factories even when no changed module has run yet,
1907
+ // so a later first import executes the edited code rather than a stale one
1908
+ if (globalThis.globalEvalWithSourceUrl) globalThis.globalEvalWithSourceUrl(code);
1909
+ else (0, eval)(code);
1778
1910
  if (boundaries.length === 0) return true;
1779
1911
 
1780
1912
  var callbacks = boundaries.map(function(item) {
@@ -1795,9 +1927,6 @@ class ReactNativeDevRuntime extends BaseDevRuntime {
1795
1927
  };
1796
1928
  }, this);
1797
1929
 
1798
- if (globalThis.globalEvalWithSourceUrl) globalThis.globalEvalWithSourceUrl(code);
1799
- else (0, eval)(code);
1800
-
1801
1930
  var modulesToReplace = Array.from(updateSet);
1802
1931
  for (var j = 0; j < modulesToReplace.length; j++) {
1803
1932
  if (!this.hasFactory(modulesToReplace[j])) return false;