vxrn 2.8.1 → 2.9.1

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 (54) 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 +43 -8
  14. package/dist/plugins/reactNativeDevServer.mjs.map +1 -1
  15. package/dist/plugins/reactNativeDevServer.native.js +45 -8
  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 +14 -14
  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.test.ts +75 -1
  38. package/src/plugins/reactNativeDevServer.ts +45 -8
  39. package/src/user-interface/index.ts +50 -42
  40. package/src/utils/createNativeDevEngine.test.ts +480 -1
  41. package/src/utils/createNativeDevEngine.ts +220 -17
  42. package/src/utils/imageSizePatch.test.ts +3 -3
  43. package/src/utils/scanDepsToOptimize.test.ts +35 -2
  44. package/src/utils/scanDepsToOptimize.ts +25 -8
  45. package/types/exports/clean.d.ts.map +1 -1
  46. package/types/exports/prebuild.d.ts +2 -1
  47. package/types/exports/prebuild.d.ts.map +1 -1
  48. package/types/exports/prebuildWithoutExpo.d.ts.map +1 -1
  49. package/types/plugins/reactNativeDevServer.d.ts.map +1 -1
  50. package/types/user-interface/index.d.ts.map +1 -1
  51. package/types/utils/createNativeDevEngine.d.ts +1 -1
  52. package/types/utils/createNativeDevEngine.d.ts.map +1 -1
  53. package/types/utils/scanDepsToOptimize.d.ts +25 -0
  54. package/types/utils/scanDepsToOptimize.d.ts.map +1 -1
@@ -22,11 +22,13 @@ import {
22
22
  } from 'node:fs'
23
23
  import { pathToFileURL } from 'node:url'
24
24
  import micromatch from 'micromatch'
25
+ import { parseSync } from 'oxc-parser'
25
26
  import type { InputOptions, OutputOptions, Plugin, RolldownOutput } from 'rolldown'
26
27
  import type { DevEngine } from 'rolldown/experimental'
27
28
  import { loadEnv as loadViteEnv, normalizePath } from 'vite'
28
29
  import { shouldStripFlow, transformHermesAsync } from '@vxrn/compiler'
29
30
  import { resolvePath } from '@vxrn/resolve'
31
+ import { nativeAppDefines } from '@vxrn/utils/nativeAppManifest'
30
32
  import { withExpoPublicEnvAliases } from '@vxrn/utils/publicEnv'
31
33
  import { DEFAULT_ASSET_EXTS } from '../constants/defaults'
32
34
  import { getNativePrelude } from '../runtime/native-prelude'
@@ -217,6 +219,7 @@ export function getNativeTransformConfig(
217
219
  // first in the map, so nothing the user set can shadow a platform-owned
218
220
  // key below.
219
221
  ...userDefines,
222
+ ...nativeAppDefines(entryConfig.app),
220
223
  // Public values are applied first so platform-owned keys cannot inherit
221
224
  // the SSR values used while loading One's Vite config.
222
225
  ...envDefines,
@@ -260,7 +263,8 @@ function getNativePlugins(
260
263
  assetsDest?: string,
261
264
  onAsset?: (asset: NativeAssetData) => void,
262
265
  sourceMaps = false,
263
- userPlugins: Plugin[] = []
266
+ userPlugins: Plugin[] = [],
267
+ minify = false
264
268
  ): Plugin[] {
265
269
  const context: NativePluginContext = { root, platform, dev }
266
270
  return [
@@ -297,12 +301,13 @@ function getNativePlugins(
297
301
  // lower Flow before worklets and react compiler parse the source with oxc.
298
302
  flowStripPlugin(),
299
303
  vxrnCompilerPlugin(platform, dev, root, sourceMaps),
304
+ mixedNativeModulePlugin(sourceMaps),
300
305
  // guard undefined native methods in NativeAnimatedHelper
301
306
  nativeAnimatedGuardPlugin(),
302
307
  // handle asset imports (.png, .jpg, .ttf, etc.)
303
308
  assetPlugin({ root, platform, assetsDest, onAsset }),
304
309
  // hermes compat: transform class properties and private fields
305
- hermesCompatSWCPlugin(dev, sourceMaps),
310
+ hermesCompatSWCPlugin(dev, sourceMaps, !minify),
306
311
  // hermes compat: per-iteration loop bindings. runs last so it also covers
307
312
  // loops the earlier lowering steps emit.
308
313
  hermesLoopsPlugin(sourceMaps),
@@ -333,6 +338,10 @@ function getNativeOutputOptions(
333
338
  codeSplitting: false,
334
339
  strictExecutionOrder: true,
335
340
  minify: minify || 'dce-only',
341
+ // metro keeps each module's scope, so an unminified bundle keeps every
342
+ // function and class name; hoisting renames colliding ones (`Foo` becomes
343
+ // `Foo2`), which code reading `constructor.name` observes.
344
+ keepNames: !minify,
336
345
  }
337
346
  }
338
347
 
@@ -345,12 +354,160 @@ function getNativeOutputOptions(
345
354
  export function normalizeNativeCommonJSInterop(code: string): string {
346
355
  // native packages expose Babel defaults through exports.default. apply the
347
356
  // same interop to external bindings, bundled helpers and HMR export lookups.
348
- return code.replace(
349
- /(\b__toESM(?:\$\d+)?\(\s*(?:require[\w$]*\(\)|[\w$]+|__rolldown_runtime__\.loadExports\("(?:\\.|[^"\\])*"\))\s*),\s*1(\s*\))/g,
350
- '$1$2'
357
+ // parsed, not pattern-matched: bundle string data can hold the same
358
+ // `__toESM(x, 1)` text, and only the parser knows a call from data.
359
+ if (!code.includes('__toESM')) return code
360
+ const { program, errors } = parseSync('native-bundle.js', code, { lang: 'js' })
361
+ if (errors.length) {
362
+ // stopping beats both alternatives: skipping leaves node-mode interop
363
+ // across the whole bundle, and a regex fallback cannot tell data from a
364
+ // call.
365
+ throw new Error(
366
+ `[vxrn] cannot normalize native CommonJS interop: the bundle does not parse (${errors[0].message})`
367
+ )
368
+ }
369
+ // delete each `, 1` from the end of the bundle backwards so earlier offsets
370
+ // stay valid. only the comma and the `1` go; the surrounding whitespace
371
+ // stays, so every line keeps the number the source map recorded for it.
372
+ const deletions: Array<[start: number, end: number]> = []
373
+ const stack: unknown[] = [program]
374
+ while (stack.length) {
375
+ const node = stack.pop()
376
+ if (Array.isArray(node)) {
377
+ for (let index = node.length - 1; index >= 0; index--) {
378
+ stack.push(node[index])
379
+ }
380
+ continue
381
+ }
382
+ if (!isInteropSyntaxNode(node)) continue
383
+ if (node.type === 'CallExpression') {
384
+ const span = interopNodeModeSpan(code, node)
385
+ if (span) deletions.push(span)
386
+ }
387
+ for (const key of Object.keys(node)) {
388
+ stack.push(node[key])
389
+ }
390
+ }
391
+ deletions.sort((a, b) => b[0] - a[0])
392
+ for (const [start, end] of deletions) {
393
+ code = code.slice(0, start) + code.slice(end)
394
+ }
395
+ return code
396
+ }
397
+
398
+ interface InteropSyntaxNode {
399
+ type: string
400
+ start: number
401
+ end: number
402
+ [key: string]: any
403
+ }
404
+
405
+ function isInteropSyntaxNode(node: unknown): node is InteropSyntaxNode {
406
+ if (!node || typeof node !== 'object') return false
407
+ const candidate = node as { type?: unknown; start?: unknown; end?: unknown }
408
+ return (
409
+ typeof candidate.type === 'string' &&
410
+ typeof candidate.start === 'number' &&
411
+ typeof candidate.end === 'number'
351
412
  )
352
413
  }
353
414
 
415
+ const NATIVE_INTEROP_HELPER = /^__toESM(?:\$\d+)?$/
416
+ const NATIVE_INTEROP_REQUIRE = /^require[\w$]*$/
417
+
418
+ // the `, 1` span of a rolldown node-mode `__toESM(first, 1)` call, or undefined
419
+ // for any other node. the first argument keeps the three generated shapes: a
420
+ // require call, an external binding, or an HMR export lookup.
421
+ function interopNodeModeSpan(
422
+ code: string,
423
+ node: InteropSyntaxNode
424
+ ): [start: number, end: number] | undefined {
425
+ const callee = node['callee']
426
+ if (
427
+ !isInteropSyntaxNode(callee) ||
428
+ !isInteropHelperCallee(callee) ||
429
+ node['optional'] === true
430
+ ) {
431
+ return undefined
432
+ }
433
+ const args = node['arguments']
434
+ if (!Array.isArray(args) || args.length !== 2) return undefined
435
+ const [first, second] = args
436
+ if (!isInteropSyntaxNode(first) || !isInteropSyntaxNode(second)) return undefined
437
+ if (!isInteropFirstArgument(first)) return undefined
438
+ if (second.type !== 'Literal' || second['raw'] !== '1') return undefined
439
+ // the comma may sit anywhere in the gap (`__toESM(x\n, 1)`), but nothing else
440
+ // may: a comment or a trailing comma means generated code this pass does not
441
+ // recognize, and unrecognized code is left alone.
442
+ const between = code.slice(first.end, second.start)
443
+ if (!/^\s*,\s*$/.test(between)) return undefined
444
+ if (!/^\s*\)/.test(code.slice(second.end))) return undefined
445
+ return [first.end + between.indexOf(','), second.end]
446
+ }
447
+
448
+ // the helper is a bare binding in full bundles and a runtime member on the
449
+ // HMR wire path (`__rolldown_runtime__.__toESM(...)`); a `.` sits on a word
450
+ // boundary, so the previous expression matched both shapes.
451
+ function isInteropHelperCallee(callee: InteropSyntaxNode): boolean {
452
+ if (callee.type === 'Identifier') {
453
+ return (
454
+ typeof callee['name'] === 'string' &&
455
+ NATIVE_INTEROP_HELPER.test(callee['name'])
456
+ )
457
+ }
458
+ if (
459
+ (callee.type === 'MemberExpression' ||
460
+ callee.type === 'StaticMemberExpression') &&
461
+ callee['computed'] !== true
462
+ ) {
463
+ const property = callee['property']
464
+ return (
465
+ isInteropSyntaxNode(property) &&
466
+ property.type === 'Identifier' &&
467
+ typeof property['name'] === 'string' &&
468
+ NATIVE_INTEROP_HELPER.test(property['name'])
469
+ )
470
+ }
471
+ return false
472
+ }
473
+
474
+ function isInteropFirstArgument(node: InteropSyntaxNode): boolean {
475
+ if (node.type === 'Identifier') return true
476
+ if (node.type !== 'CallExpression' || node['optional'] === true) return false
477
+ const callee = node['callee']
478
+ if (!isInteropSyntaxNode(callee)) return false
479
+ const args = node['arguments']
480
+ if (!Array.isArray(args)) return false
481
+ if (callee.type === 'Identifier') {
482
+ return (
483
+ typeof callee['name'] === 'string' &&
484
+ NATIVE_INTEROP_REQUIRE.test(callee['name']) &&
485
+ args.length === 0
486
+ )
487
+ }
488
+ if (
489
+ (callee.type === 'MemberExpression' || callee.type === 'StaticMemberExpression') &&
490
+ callee['computed'] !== true &&
491
+ callee['optional'] !== true
492
+ ) {
493
+ const object = callee['object']
494
+ const property = callee['property']
495
+ return (
496
+ isInteropSyntaxNode(object) &&
497
+ object.type === 'Identifier' &&
498
+ object['name'] === '__rolldown_runtime__' &&
499
+ isInteropSyntaxNode(property) &&
500
+ property.type === 'Identifier' &&
501
+ property['name'] === 'loadExports' &&
502
+ args.length === 1 &&
503
+ isInteropSyntaxNode(args[0]) &&
504
+ args[0].type === 'Literal' &&
505
+ typeof args[0]['value'] === 'string'
506
+ )
507
+ }
508
+ return false
509
+ }
510
+
354
511
  /**
355
512
  * Every post-processing pass below rewrites the bundle after Rolldown has
356
513
  * already emitted its source map, so a pass that changes the number of lines
@@ -783,12 +940,34 @@ try {
783
940
  const chunk = output.output.find((o) => o.type === 'chunk' && o.isEntry)
784
941
  if (chunk && 'code' in chunk) {
785
942
  firstBuildError = null
786
- let code = postProcessNativeBundle(chunk.code)
943
+ let code: string
944
+ try {
945
+ code = postProcessNativeBundle(chunk.code)
787
946
 
788
- // downlevel class fields from the rolldown runtime (virtual module
789
- // skipped by the per-file SWC plugin) so old Hermes can parse them
790
- code = await downlevelClassFieldsInBundle(code)
791
- assertBundleLinesPreserved(chunk.code, code, 'dev')
947
+ // downlevel class fields from the rolldown runtime (virtual module
948
+ // skipped by the per-file SWC plugin) so old Hermes can parse them
949
+ code = await downlevelClassFieldsInBundle(code)
950
+ assertBundleLinesPreserved(chunk.code, code, 'dev')
951
+ } catch (error) {
952
+ // a post-processing failure is a build failure: without a bundle to
953
+ // serve, record it and wake the waiting request with its message
954
+ // instead of leaving it on the generic timeout. past a first good
955
+ // build the last bundle keeps serving, like the rolldown-error
956
+ // branch: one bad output must not poison later builds.
957
+ const failure = error instanceof Error ? error : new Error(String(error))
958
+ console.error('[vxrn] native bundle post-processing failed:', failure.message)
959
+ if (!currentBundle) {
960
+ firstBuildError = failure
961
+ if (bundleReject) {
962
+ const reject = bundleReject
963
+ bundleResolve = null
964
+ bundleReject = null
965
+ bundlePromise = null
966
+ reject(failure)
967
+ }
968
+ }
969
+ return
970
+ }
792
971
 
793
972
  // wrap module code in a function scope so top-level `var`s (e.g. RN
794
973
  // fetch.js's `Headers`/`Request`) don't leak as non-configurable
@@ -978,7 +1157,8 @@ export async function buildNativeBundle(
978
1157
  assetsDest,
979
1158
  undefined,
980
1159
  sourcemap,
981
- userPlugins
1160
+ userPlugins,
1161
+ minify
982
1162
  ),
983
1163
  // last, so it sees what every other plugin produced
984
1164
  nativeBundlePostProcessPlugin(),
@@ -1922,6 +2102,18 @@ if (import.meta.hot) {
1922
2102
  }
1923
2103
  }
1924
2104
 
2105
+ // run after syntax-aware native transforms and before rolldown classifies modules.
2106
+ function mixedNativeModulePlugin(sourceMaps: boolean): Plugin {
2107
+ return {
2108
+ name: 'vxrn:mixed-native-module',
2109
+ async transform(code, id) {
2110
+ if (!/\.[cm]?[jt]sx?$/.test(id) || id.includes('\0')) return
2111
+ const { transformMixedNativeModule } = await import('@vxrn/compiler')
2112
+ return transformMixedNativeModule(code, id, sourceMaps)
2113
+ },
2114
+ }
2115
+ }
2116
+
1925
2117
  /**
1926
2118
  * Strip Flow types from react-native and other Flow-authored source files.
1927
2119
  *
@@ -2138,7 +2330,7 @@ export async function getNativeAssetData(
2138
2330
  if (NATIVE_IMAGE_EXTS.has(requested.type)) {
2139
2331
  try {
2140
2332
  const { imageSize } = await import('image-size')
2141
- const dims = imageSize(files[0])
2333
+ const dims = imageSize(readFileSync(files[0]))
2142
2334
  assetData.width = dims.width === undefined ? undefined : dims.width / scales[0]
2143
2335
  assetData.height = dims.height === undefined ? undefined : dims.height / scales[0]
2144
2336
  } catch {}
@@ -2215,7 +2407,11 @@ function copyNativeAssetFiles(
2215
2407
  * Lowers classes, lexical bindings, and async syntax for legacy Hermes.
2216
2408
  * Inspired by rollipop's swc-plugin.ts.
2217
2409
  */
2218
- export function hermesCompatSWCPlugin(dev: boolean, sourceMaps = false): Plugin {
2410
+ export function hermesCompatSWCPlugin(
2411
+ dev: boolean,
2412
+ sourceMaps = false,
2413
+ keepNames = false
2414
+ ): Plugin {
2219
2415
  let oxc: typeof import('oxc-transform') | null = null
2220
2416
 
2221
2417
  return {
@@ -2262,7 +2458,13 @@ export function hermesCompatSWCPlugin(dev: boolean, sourceMaps = false): Plugin
2262
2458
  output = classes
2263
2459
  }
2264
2460
  }
2265
- const lowered = await transformHermesAsync(output?.code ?? code, id, sourceMaps)
2461
+ const lowered = await transformHermesAsync(
2462
+ output?.code ?? code,
2463
+ id,
2464
+ sourceMaps,
2465
+ undefined,
2466
+ keepNames
2467
+ )
2266
2468
  if (!lowered) return output
2267
2469
  if (lowered.map && output?.map) {
2268
2470
  const remapping = (await import('@jridgewell/remapping')).default
@@ -2447,6 +2649,10 @@ class ReactNativeDevRuntime extends BaseDevRuntime {
2447
2649
  if (!this.isExecuted(changedId)) continue;
2448
2650
  if (!this.findBoundaries(changedId, traversed, updateSet, boundaries)) return false;
2449
2651
  }
2652
+ // register the patch's factories even when no changed module has run yet,
2653
+ // so a later first import executes the edited code rather than a stale one
2654
+ if (globalThis.globalEvalWithSourceUrl) globalThis.globalEvalWithSourceUrl(code);
2655
+ else (0, eval)(code);
2450
2656
  if (boundaries.length === 0) return true;
2451
2657
 
2452
2658
  var callbacks = boundaries.map(function(item) {
@@ -2467,9 +2673,6 @@ class ReactNativeDevRuntime extends BaseDevRuntime {
2467
2673
  };
2468
2674
  }, this);
2469
2675
 
2470
- if (globalThis.globalEvalWithSourceUrl) globalThis.globalEvalWithSourceUrl(code);
2471
- else (0, eval)(code);
2472
-
2473
2676
  var modulesToReplace = Array.from(updateSet);
2474
2677
  for (var j = 0; j < modulesToReplace.length; j++) {
2475
2678
  if (!this.hasFactory(modulesToReplace[j])) return false;
@@ -5,7 +5,7 @@ const malformedImages = [
5
5
  {
6
6
  name: 'icns',
7
7
  bytes: [0x69, 0x63, 0x6e, 0x73, 0, 0, 0, 16, 0x69, 0x73, 0x33, 0x32, 0, 0, 0, 0],
8
- error: 'Invalid ICNS, invalid entry length',
8
+ error: 'Invalid ICNS',
9
9
  },
10
10
  {
11
11
  name: 'jxl',
@@ -13,7 +13,7 @@ const malformedImages = [
13
13
  0, 0, 0, 12, 0x4a, 0x58, 0x4c, 0x20, 0x0d, 0x0a, 0x87, 0x0a, 0, 0, 0, 12, 0x66,
14
14
  0x74, 0x79, 0x70, 0x6a, 0x78, 0x6c, 0x20, 0, 0, 0, 0, 0x6a, 0x78, 0x6c, 0x70,
15
15
  ],
16
- error: 'No codestream found in JXL container',
16
+ error: 'Invalid JXL',
17
17
  },
18
18
  {
19
19
  name: 'heif',
@@ -23,7 +23,7 @@ const malformedImages = [
23
23
  20, 0x69, 0x70, 0x63, 0x6f, 0, 0, 0, 0, 0x69, 0x73, 0x70, 0x65, 0, 0, 0, 0, 0, 0, 0,
24
24
  0, 0, 0, 0, 0, 0, 0, 0, 0,
25
25
  ],
26
- error: 'Invalid HEIF, no size found',
26
+ error: 'Invalid HEIF, no sizes found',
27
27
  },
28
28
  ]
29
29
 
@@ -3,7 +3,10 @@ import { tmpdir } from 'node:os'
3
3
  import { join } from 'node:path'
4
4
  import { createServer } from 'vite'
5
5
  import { describe, expect, test } from 'vitest'
6
- import { getScannedOptimizeDepsConfig } from '../plugins/autoDepOptimizePlugin'
6
+ import {
7
+ findDepsToOptimize,
8
+ getScannedOptimizeDepsConfig,
9
+ } from '../plugins/autoDepOptimizePlugin'
7
10
 
8
11
  import { scanDepsToOptimize } from './scanDepsToOptimize'
9
12
 
@@ -199,7 +202,10 @@ describe('subpath exports', () => {
199
202
  })
200
203
  writeFileSync(join(dep, 'tag.mjs'), 'export const tag = Symbol()\n')
201
204
  writeFileSync(join(dep, 'index.mjs'), "export { tag } from './tag.mjs'\n")
202
- writeFileSync(join(dep, 'server.mjs'), "export { tag as serverTag } from './tag.mjs'\n")
205
+ writeFileSync(
206
+ join(dep, 'server.mjs'),
207
+ "export { tag as serverTag } from './tag.mjs'\n"
208
+ )
203
209
  writeFileSync(
204
210
  join(root, 'entry.js'),
205
211
  "import { tag } from 'zero-like'\nimport { serverTag } from 'zero-like/server'\nexport const same = tag === serverTag\n"
@@ -321,3 +327,30 @@ describe('subpath exports', () => {
321
327
  expect(scanned('dts-main')).toEqual(['dts-main'])
322
328
  })
323
329
  })
330
+
331
+ describe('worklets detection', () => {
332
+ test('enables worklets for a workspace app that declares nothing but resolves reanimated', async () => {
333
+ const workspace = realpathSync(mkdtempSync(join(tmpdir(), 'vxrn-worklets-hoisted-')))
334
+ const app = join(workspace, 'apps', 'guest')
335
+ writePkg(app, { name: 'guest', private: true })
336
+
337
+ // the plugin's own call, which passes a filter
338
+ const scan = async () =>
339
+ (
340
+ await findDepsToOptimize({
341
+ root: app,
342
+ mode: 'development',
343
+ include: /node_modules/,
344
+ })
345
+ ).hasReanimated
346
+
347
+ expect(await scan()).toBe(false)
348
+
349
+ writePkg(join(workspace, 'node_modules', 'react-native-reanimated'), {
350
+ name: 'react-native-reanimated',
351
+ version: '4.7.0',
352
+ })
353
+
354
+ expect(await scan()).toBe(true)
355
+ })
356
+ })
@@ -153,8 +153,6 @@ export const INCLUDE_LIST_SET = new Set(INCLUDE_LIST)
153
153
  * [^3]: https://vite.dev/guide/dep-pre-bundling.html
154
154
  */
155
155
 
156
- const rootOptions = {}
157
-
158
156
  export async function scanDepsToOptimize(
159
157
  packageJsonPath: string,
160
158
  options: {
@@ -163,11 +161,13 @@ export async function scanDepsToOptimize(
163
161
  proceededDeps?: Map<string, string[]>
164
162
  /** If the content of the package.json is already read before calling this function, pass it here to avoid reading it again */
165
163
  pkgJsonContent?: any
166
- } = rootOptions
164
+ } = {}
167
165
  ): Promise<ScanDepsResult> {
168
166
  const { parentDepNames = [], proceededDeps = new Map(), pkgJsonContent } = options
167
+ // recursive calls always pass their parents
168
+ const isRoot = !options.parentDepNames
169
169
 
170
- if (options === rootOptions) {
170
+ if (isRoot) {
171
171
  console.info(`[one] Scanning node_modules to auto-optimize...`)
172
172
  }
173
173
 
@@ -183,7 +183,17 @@ export async function scanDepsToOptimize(
183
183
  json.dependencies?.['react-native-reanimated'] ||
184
184
  json.dependencies?.['react-native-worklets']
185
185
  )
186
- let hasReanimated = needsWorklets(pkgJson)
186
+ // the app decides by what it can import: a workspace app often declares
187
+ // nothing and gets reanimated hoisted from the monorepo root
188
+ let hasReanimated = isRoot
189
+ ? (
190
+ await Promise.all(
191
+ ['react-native-reanimated', 'react-native-worklets'].map((dep) =>
192
+ resolveDepPkgJsonPath(dep, currentRoot)
193
+ )
194
+ )
195
+ ).some(Boolean)
196
+ : needsWorklets(pkgJson)
187
197
 
188
198
  const prebundleDeps = (
189
199
  await Promise.all(
@@ -321,7 +331,9 @@ export async function scanDepsToOptimize(
321
331
  depPkgJson['main'],
322
332
  depPkgJson['module'],
323
333
  getExportImport(depPkgJsonExports['.']),
324
- ].find((entry) => typeof entry === 'string' && entry && isPrebundleableEntry(entry))
334
+ ].find(
335
+ (entry) => typeof entry === 'string' && entry && isPrebundleableEntry(entry)
336
+ )
325
337
 
326
338
  const exports = [...definedExports, ...specialExports].filter(
327
339
  (d) => !EXCLUDE_LIST_SET.has(d)
@@ -349,7 +361,7 @@ export async function scanDepsToOptimize(
349
361
 
350
362
  const hasNativewind = !!pkgJson.dependencies?.['nativewind']
351
363
 
352
- if ((hasNativewind || hasReanimated) && options === rootOptions) {
364
+ if ((hasNativewind || hasReanimated) && isRoot) {
353
365
  if (hasReanimated)
354
366
  console.info(
355
367
  `[one] Enabled babel plugins: ${[hasReanimated ? 'Reanimated' : '', hasNativewind ? 'Nativewind' : ''].filter(Boolean).join(', ')}`
@@ -392,7 +404,7 @@ async function readPackageJsonSafe(packageJsonPath: string) {
392
404
  }
393
405
  }
394
406
 
395
- export async function findDepPkgJsonPath(dep, dependent) {
407
+ async function resolveDepPkgJsonPath(dep: string, dependent: string) {
396
408
  let root = dependent
397
409
  while (root) {
398
410
  const possiblePkgJson = path.join(root, 'node_modules', dep, 'package.json')
@@ -405,6 +417,11 @@ export async function findDepPkgJsonPath(dep, dependent) {
405
417
  if (nextRoot === root) break
406
418
  root = nextRoot
407
419
  }
420
+ }
421
+
422
+ export async function findDepPkgJsonPath(dep, dependent) {
423
+ const found = await resolveDepPkgJsonPath(dep, dependent)
424
+ if (found) return found
408
425
 
409
426
  console.error(
410
427
  `[findDepPkgJsonPath] Could not find package.json for ${dep}, which is a dependency of ${dependent}`
@@ -1 +1 @@
1
- {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/exports/clean.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AA6E3C,wBAAsB,sBAAsB,CAAC,EAC3C,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,UAAkB,GACnB,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,oBAeA;AAED,eAAO,MAAM,KAAK,SAAgB,WAAW,SAAS,MAAM,kBAG3D,CAAA"}
1
+ {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/exports/clean.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAyO3C,wBAAsB,sBAAsB,CAAC,EAC3C,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,UAAkB,GACnB,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,oBAeA;AAED,eAAO,MAAM,KAAK,SAAgB,WAAW,SAAS,MAAM,kBAG3D,CAAA"}
@@ -1,9 +1,10 @@
1
1
  import { type PrebuildAppConfig } from './prebuildWithoutExpo';
2
- export declare const prebuild: ({ root, platform, 'no-install': noInstall, app, }: {
2
+ export declare const prebuild: ({ root, platform, 'no-install': noInstall, app, beforeInstall, }: {
3
3
  root: string;
4
4
  platform?: 'ios' | 'android' | string;
5
5
  'no-install'?: boolean;
6
6
  app: PrebuildAppConfig;
7
+ beforeInstall?: () => Promise<void>;
7
8
  }) => Promise<void>;
8
9
  export declare function replaceInUTF8File(filePath: string, findThis: string, replaceWith: string): Promise<void>;
9
10
  //# sourceMappingURL=prebuild.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prebuild.d.ts","sourceRoot":"","sources":["../../src/exports/prebuild.ts"],"names":[],"mappings":"AAKA,OAAO,EAML,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAA;AAK9B,eAAO,MAAM,QAAQ,sDAKlB;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAAA;IACrC,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,GAAG,EAAE,iBAAiB,CAAA;CACvB,kBAwFA,CAAA;AAED,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,iBAOpB"}
1
+ {"version":3,"file":"prebuild.d.ts","sourceRoot":"","sources":["../../src/exports/prebuild.ts"],"names":[],"mappings":"AAKA,OAAO,EAML,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAA;AAK9B,eAAO,MAAM,QAAQ,qEAMlB;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAAA;IACrC,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,GAAG,EAAE,iBAAiB,CAAA;IAGtB,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CACpC,kBA0FA,CAAA;AAED,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,iBAOpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"prebuildWithoutExpo.d.ts","sourceRoot":"","sources":["../../src/exports/prebuildWithoutExpo.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,iBAAiB,EACjB,KAAK,iBAAiB,EAEvB,MAAM,+BAA+B,CAAA;AAsEtC,YAAY,EAAE,iBAAiB,IAAI,iBAAiB,EAAE,MAAM,+BAA+B,CAAA;AAE3F,eAAO,MAAM,mBAAmB,0BAAoB,CAAA;AA6EpD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAwChE;AA0ID,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,MAAM,CA8CrI;AAg8BD,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,EAAE,MAAM,CAAA;IACxB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B,6BAA6B,CAAC,IAAI,EAAE;IAClD,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,iBAAiB,CAAA;IACtB,SAAS,EAAE,SAAS,yBAAyB,EAAE,CAAA;CAChD,GAAG,IAAI,CA8BP;AAID,wBAAsB,4BAA4B,CAChD,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,yBAAyB,EAAE,CAAC,CA+BtC;AAKD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE;IAC9C,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,CAAA;CACtC,GAAG,IAAI,CAaP"}
@@ -1 +1 @@
1
- {"version":3,"file":"reactNativeDevServer.d.ts","sourceRoot":"","sources":["../../src/plugins/reactNativeDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,MAAM,EAAiB,MAAM,MAAM,CAAA;AAW1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AA2CnE,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkC9D;AAED,wBAAgB,gCAAgC,CAC9C,OAAO,CAAC,EAAE,OAAO,CACf,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,aAAa,GAAG,kBAAkB,GAAG,SAAS,CAAC,CACrF,GACA,MAAM,CA0jBR"}
1
+ {"version":3,"file":"reactNativeDevServer.d.ts","sourceRoot":"","sources":["../../src/plugins/reactNativeDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,MAAM,EAAiB,MAAM,MAAM,CAAA;AAW1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AA2CnE,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkC9D;AAED,wBAAgB,gCAAgC,CAC9C,OAAO,CAAC,EAAE,OAAO,CACf,IAAI,CAAC,iBAAiB,EAAE,UAAU,GAAG,aAAa,GAAG,kBAAkB,GAAG,SAAS,CAAC,CACrF,GACA,MAAM,CA+lBR"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/user-interface/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAIzC,KAAK,OAAO,GAAG;IACb,MAAM,EAAE,aAAa,CAAA;CACtB,CAAA;AA0GD,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,OAAO,iBAOxD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/user-interface/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAIzC,KAAK,OAAO,GAAG;IACb,MAAM,EAAE,aAAa,CAAA;CACtB,CAAA;AAkHD,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,OAAO,iBAOxD"}
@@ -159,7 +159,7 @@ export declare function getNativeAssetData(id: string, root: string, platform: s
159
159
  * Lowers classes, lexical bindings, and async syntax for legacy Hermes.
160
160
  * Inspired by rollipop's swc-plugin.ts.
161
161
  */
162
- export declare function hermesCompatSWCPlugin(dev: boolean, sourceMaps?: boolean): Plugin;
162
+ export declare function hermesCompatSWCPlugin(dev: boolean, sourceMaps?: boolean, keepNames?: boolean): Plugin;
163
163
  export declare const hermesCompatPlugin: typeof hermesCompatSWCPlugin;
164
164
  /**
165
165
  * Hermes gives a loop one environment, not one per iteration, so every closure
@@ -1 +1 @@
1
- {"version":3,"file":"createNativeDevEngine.d.ts","sourceRoot":"","sources":["../../src/utils/createNativeDevEngine.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkBH,OAAO,KAAK,EAA+B,MAAM,EAAkB,MAAM,UAAU,CAAA;AACnF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAgCtD,yFAAyF;AACzF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,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IG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,OAAO,EACZ,UAAU,UAAQ,EAClB,SAAS,UAAQ,GAChB,MAAM,CA8DR;AAED,eAAO,MAAM,kBAAkB,8BAAwB,CAAA;AAEvD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,UAAQ,GAAG,MAAM,CAuB5D;AAID,wBAAgB,mBAAmB,IAAI,MAAM,CA8O5C"}
@@ -9,6 +9,31 @@ export declare const EXCLUDE_LIST: string[];
9
9
  export declare const EXCLUDE_LIST_SET: Set<string>;
10
10
  export declare const INCLUDE_LIST: string[];
11
11
  export declare const INCLUDE_LIST_SET: Set<string>;
12
+ /**
13
+ * Since:
14
+ *
15
+ * 1) React is a CommonJS only package, and
16
+ * 2) Vite SSR does not support direct import (or say, externalizing[^1]) of CommonJS packages
17
+ * (those packages need to be pre-bundled to work in SSR[^2]).
18
+ *
19
+ * We need to make React packages pre-bundled[^3] (or say, optimized) in the SSR environment, since
20
+ * in the SSR environment, deps will default to be externalized and not pre-bundled.
21
+ *
22
+ * Since React is being pre-bundled, we need to make sure any other packages that depend on React are
23
+ * also pre-bundled as well, because if a package is by default externalized (i.e. not pre-bundled),
24
+ * it's import of React will be resolved to the externalized React (i.e. the one under `node_modules`)
25
+ * but not the pre-bundled React, causing two different Reacts to be used in the same app and a `You might have more than one copy of React in the same app` error.
26
+ *
27
+ * Long story short, we need to pre-bundle React in SSR environment, and by doing so we also need to pre-bundle any other packages that depend on React.
28
+ *
29
+ * But we don't want to pre-bundle all the deps, since it's bad for performance and if a package is using things such as `__dirname` pre-bundling will break it.
30
+ *
31
+ * This function scans the `package.json` file of the project and returns a list of packages that depend on React, so that we can pre-bundle them in SSR environment.
32
+ *
33
+ * [^1]: https://vite.dev/guide/ssr.html#ssr-externals
34
+ * [^2]: https://github.com/vitejs/vite/issues/9710#issuecomment-1217775350
35
+ * [^3]: https://vite.dev/guide/dep-pre-bundling.html
36
+ */
12
37
  export declare function scanDepsToOptimize(packageJsonPath: string, options?: {
13
38
  filter?: (id: string | unknown) => boolean;
14
39
  parentDepNames?: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"scanDepsToOptimize.d.ts","sourceRoot":"","sources":["../../src/utils/scanDepsToOptimize.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,aAAa,EAAE,OAAO,CAAA;IACtB,aAAa,EAAE,OAAO,CAAA;CACvB,CAAA;AAsBD,6EAA6E;AAC7E,eAAO,MAAM,YAAY,UAkFxB,CAAA;AAED,eAAO,MAAM,gBAAgB,aAAwB,CAAA;AAErD,eAAO,MAAM,YAAY,UAKxB,CAAA;AAED,eAAO,MAAM,gBAAgB,aAAwB,CAAA;AA8BrD,wBAAsB,kBAAkB,CACtC,eAAe,EAAE,MAAM,EACvB,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,KAAK,OAAO,CAAA;IAC1C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IACrC,8HAA8H;IAC9H,cAAc,CAAC,EAAE,GAAG,CAAA;CACP,GACd,OAAO,CAAC,cAAc,CAAC,CAuMzB;AA6BD,wBAAsB,kBAAkB,CAAC,GAAG,KAAA,EAAE,SAAS,KAAA,+BAmBtD"}
1
+ {"version":3,"file":"scanDepsToOptimize.d.ts","sourceRoot":"","sources":["../../src/utils/scanDepsToOptimize.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,aAAa,EAAE,OAAO,CAAA;IACtB,aAAa,EAAE,OAAO,CAAA;CACvB,CAAA;AAsBD,6EAA6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