vitest-native 0.11.0 → 0.12.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,266 @@
1
1
  # vitest-native
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0dce12c: Compile what Node cannot run, and nothing else
8
+
9
+ The native engine decided what to compile by NAME: a package was handed to the React
10
+ Native Babel preset because auto-detection or a dependency-closure walk selected it.
11
+ That guess was wrong far more often than it was right, and every way of being wrong
12
+ looked identical — a parse error deep inside a package the project never mentioned.
13
+ Babel's own emitted helpers, Metro's `lru-cache` chain and a pure-ESM validator all
14
+ arrived that way, and each was answered by adding another name to exclude.
15
+
16
+ The file answers precisely. If V8 can parse it, Node can run it, so compiling is
17
+ optional; if V8 cannot, Node cannot, so compiling is required — the same question Node
18
+ is about to ask, which is what makes it a fact rather than a heuristic. Files selected
19
+ for compiling are now parsed first, and only compiled if the parse fails.
20
+
21
+ What is given up is downleveling for Hermes: `const` to `var`, destructuring lowered.
22
+ Measured across React Native's own sources and the installed ecosystem, that is the
23
+ whole of what the preset does to a file V8 accepts, and it is behaviour-preserving on
24
+ Node — arguably closer to what the package published. `__DEV__` is left standing and
25
+ top-level requires are not inlined, so neither observable transform is affected.
26
+
27
+ **This is a robustness change, not a speed one.** On this repository's native suite
28
+ with a cold transform cache it measured 7.68s against 7.35s without the check: React
29
+ Native's own sources need compiling either way (440 of 450 fail to parse), so the check
30
+ mostly adds work here. The benefit is that a package Node can already run can no longer
31
+ reach Babel, whatever put it on the list.
32
+
33
+ Scoped to script-goal files. A `type: module` package is compiled exactly as before,
34
+ because the loader hands those to Node as CommonJS and changing that is an interop
35
+ question about named exports and live bindings that a parse cannot answer.
36
+
37
+ Also adds `transform: { include, exclude }`. `exclude` names packages the engine must
38
+ never compile, overriding auto-detection, the closure walk and the built-in lists —
39
+ so a project that hits a case the parse check does not cover can unblock itself the
40
+ same day instead of waiting for a release. The array form keeps its meaning.
41
+
42
+ ### Patch Changes
43
+
44
+ - c118f51: Reset externalized packages a test file imports, under the hot runtime
45
+
46
+ The hot runtime keeps a worker alive across test files and clears what each file
47
+ loaded, so the next one starts fresh. That reset could only reach Node's CommonJS
48
+ cache. A package reached through ESM `import` is held by Node's ESM registry, which
49
+ has no invalidation API, so its module-level state — a store, a client, a cache —
50
+ survived for the whole run. The second test file to touch such a package saw the
51
+ first one's writes.
52
+
53
+ The registry cannot be invalidated, but it is keyed by full URL, and the engine owns
54
+ the resolve hook. The per-file reset now advances a generation counter that the
55
+ loader stamps onto the resolved URL, so the next file imports a URL Node has not seen
56
+ and evaluates the module again. React Native itself and the identity-sensitive
57
+ modules already listed in the reset are exempt: for those a fresh instance is the
58
+ bug, not the fix. Cost is bounded by ownership — a CommonJS package re-enters through
59
+ `Module._cache`, which the reset already drops, so only a namespace wrapper is
60
+ retained per generation.
61
+
62
+ Correctness on a 135-file suite went from 126/135 to 135/135 against the same suite
63
+ under stock isolation.
64
+
65
+ The cost is re-execution, and it scales with how many externalized packages a test
66
+ file imports — which is nothing to do with React Native, since RN and the packages
67
+ that depend on it are inlined into Vite's graph and never reach this path. A suite
68
+ where every file imports eight ordinary npm packages measured 1.14s to 1.77s, 55%
69
+ more wall clock; stock isolation runs the same suite in 15.90s, so hot goes from
70
+ 13.9× to 9.0×. Suites that import few externalized packages pay close to nothing.
71
+
72
+ Peak RSS does not grow: 946 MB with the stamp against 955 MB without, on that same
73
+ suite. A CommonJS package re-enters through `Module._cache`, which the reset already
74
+ drops, so only a namespace wrapper is retained per generation.
75
+
76
+ `hotRuntime: { esmGeneration: false }` trades the correctness back for the speed.
77
+ Nothing changes when the hot runtime is off; the counter is only installed by the hot
78
+ worker.
79
+
80
+ The hot-isolation suite reached this fixture through `require` deliberately, because
81
+ the ESM path could not pass — it documented the hole rather than covering it. It now
82
+ has an ESM twin, and the scale validation gained templates for the shapes that were
83
+ missing from it entirely: real React Navigation, a navigation container wrapping a
84
+ Modal, and a node_modules package holding module-level state. Navigation had never
85
+ run under the hot runtime in any gate.
86
+
87
+ The stamp is scoped away from the test stack itself — vitest, `@vitest/*`, chai, and
88
+ this engine. The worker's runtime holds boot instances of these (the runner's
89
+ SnapshotClient, chai's extended Assertion, the engine's registry), and a test file
90
+ reaches the same packages through Node's ESM path; stamping those resolutions hands
91
+ the file a twin runtime whose failures are emergent and order-dependent —
92
+ `toMatchSnapshot` asking a SnapshotClient no one set up, fake timers flipping a copy
93
+ of the state the runner never reads. The workspace gates cannot see this class: in
94
+ the repository, the engine and the validation suites resolve outside node_modules,
95
+ where the node_modules-scoped stamp never applies. It surfaced only on a packed
96
+ install, running react-native-paper's suite under the hot runtime: 603/678 → 473/648
97
+ before the exemption, 609/678 — above the recorded baseline — with it.
98
+
99
+ The consumer tests gained the gate that class needs: the packed current-RN fixture
100
+ now runs a hot-runtime leg whose probe asserts the resolution invariant directly —
101
+ an ordinary node_modules package resolves generation-stamped while vitest,
102
+ `@vitest/snapshot`, chai, and the engine never do — alongside behavioral checks
103
+ (snapshots, fake timers, cross-file state reset from a packed install). Both
104
+ mutations were run before trusting it: removing the exemption and disabling the
105
+ generation mechanism each turn the leg red.
106
+
107
+ - c120d05: Match Metro's extension-major platform resolution order, verified against real metro-resolver
108
+
109
+ Platform-file resolution interleaved its candidate extensions platform-major —
110
+ every `.ios.*` variant before any `.native.*` before any bare extension. Metro
111
+ resolves extension-major: for each source extension in order, it tries the
112
+ platform variant, then `.native`, then bare (`.ios.js`, `.native.js`, `.js`,
113
+ `.ios.jsx`, …). The difference selects different files when a module mixes
114
+ platform variants across extensions: `Foo.native.js` beside `Foo.ios.tsx`
115
+ resolves to `.native.js` under Metro — the `js` round finishes before `tsx` is
116
+ tried — but resolved to `.ios.tsx` here, so a test could run a different file
117
+ than the application ships. One shared list feeds both the Vite graph and the
118
+ Node hooks, so the correction applies to both at once.
119
+
120
+ The order had also been asserted by a unit test whose literals were written from
121
+ the implementation — the gate encoded the mistake it existed to catch. The
122
+ authority is now external: a differential oracle resolves a 160-case sweep of
123
+ mixed platform/extension layouts (plus directory-index and per-extension cases)
124
+ through real metro-resolver and through this package's resolver and requires
125
+ byte-identical answers. The oracle runs against a pinned metro-resolver in the
126
+ PR gate, and the weekly compatibility job bumps metro-resolver@latest alongside
127
+ react-native@latest so upstream resolution changes surface as scheduled drift.
128
+ Reverting the interleaving fails the oracle on the exact mixed-variant shapes
129
+ described above.
130
+
131
+ - c27474e: Engine auto-detection requires react-native itself, not just its Babel toolchain
132
+
133
+ `engine: 'auto'` chose the native engine whenever `@react-native/babel-preset`
134
+ and `@babel/core` resolved — react-native itself was never checked, so an
135
+ incomplete install (or a babel-only workspace) selected native mode and then
136
+ failed later at React Native resolution with nothing pointing at the cause.
137
+
138
+ Detection now requires all three. The check resolves rather than reads
139
+ declarations — everything is located by walking node_modules upward from the
140
+ project root, so a hoisted workspace install or Expo's transitive react-native
141
+ counts without appearing in the project's own manifest. The fallback notice and
142
+ the explicit-`engine: 'native'` configuration error both name exactly which
143
+ dependencies did not resolve.
144
+
145
+ - 2fca83a: Compile a preset-shadowed package's pass-through entries when Node cannot run them
146
+
147
+ Preset packages are shadowed: their bare and subpath imports are redirected to the
148
+ preset mock before any file loads. The deliberate exceptions — package.json
149
+ subpaths, assets, and Node-safe utility entries such as `mock`, `plugin`, and
150
+ `jest-utils` — pass through to the real file. Some of those files only Metro can
151
+ run: react-native-worklets publishes its own mock entry (`lib/module/mock.js`) as
152
+ ESM `import` statements over a `module.exports = …` footer. And because the preset
153
+ shadow is exactly what keeps such packages out of ecosystem detection, nothing else
154
+ would ever compile them. A suite that maps the package onto its published mock —
155
+ react-native-paper does, via
156
+ `vi.mock('react-native-worklets', () => require('react-native-worklets/lib/module/mock'))` —
157
+ lost every test file whose component imports the package.
158
+
159
+ Preset-shadowed package names now join the Node-side transform set, built in the
160
+ worker from the same preset definitions that power the redirect, so user-supplied
161
+ presets are covered alongside the auto-detected ones. Membership only makes a file
162
+ eligible: `needsTransform` still gates every compile, so a pass-through Node can
163
+ already run is served untouched. The hot runtime needed one more piece — its worker
164
+ installs the require hooks at boot, before the setup file has built the preset
165
+ mocks, and the install-once guard silently pinned that boot-time list; the guard
166
+ now updates the transform matcher instead.
167
+
168
+ What the served-as-published failure looks like depends on the Node version, and
169
+ both shapes are cured: where Node lacks a `module` global the require(esm) retry
170
+ throws "module is not defined in ES module scope", and on Node 24 — which defines
171
+ `module` as a global — the file loads silently with EMPTY exports instead.
172
+
173
+ The thrown shape also joins the explained-error family: the ReferenceError from a
174
+ mixed ES-module/CommonJS file now gets the same actionable message as untranspiled
175
+ JSX/Flow/TS SyntaxErrors — naming the owning package and the `transform: [...]`
176
+ remedy — instead of a bare "module is not defined in ES module scope".
177
+
178
+ - 6bd6ec6: Scope the native transformer's toolchain to the project root instead of the process
179
+
180
+ The transformer resolved its toolchain — `@react-native/babel-preset`,
181
+ `@babel/core`, the flow-enums plugin, and the disk-cache directory — into module
182
+ globals initialized by the first caller. `transformRN` accepts a project root per
183
+ call, but a second root's calls silently reused the first root's resolved
184
+ toolchain and cache. Registries for every project in a Vitest workspace are built
185
+ in the one Vite main process, so two projects with different React Native or
186
+ Babel versions could serve the first project's output to the second project's
187
+ tests.
188
+
189
+ Proven before fixing: a regression test gives two roots their own Babel preset
190
+ whose plugin stamps a root-specific marker into every transformed file, and the
191
+ second root's file came back carrying the first root's stamp. Toolchain state now
192
+ lives in a per-root context — resolved requires, preset, lazily-loaded Babel,
193
+ in-memory cache, and disk-cache directory each belong to one canonical (realpath)
194
+ project root — and the same test asserts both call orders plus per-root cache
195
+ directories.
196
+
197
+ ## 0.11.1
198
+
199
+ ### Patch Changes
200
+
201
+ - ea133b6: Only walk the dependency closure of packages the project declares
202
+
203
+ Fixes a regression in 0.11.0. In a workspace holding both a library and a React
204
+ Native or Expo application — the canonical monorepo shape — the application's mere
205
+ presence could stop the library's tests from loading:
206
+
207
+ ```
208
+ ReferenceError: [vitest-native] Failed to transform '@babel/runtime' … for platform 'ios'.
209
+ Caused by: ReferenceError: Cannot access 'v' before initialization
210
+ Test Files 1 failed | Tests: no tests
211
+ ```
212
+
213
+ 0.11.0 began compiling a detected package's dependency closure, so that a library
214
+ shipping untranspiled JSX inside a transitive dependency would work without naming it
215
+ in `transform: [...]`. Candidates are collected from every manifest in the workspace,
216
+ which is how a library the application depends on is found at all — but applied to a
217
+ closure walk, that breadth stops being free. A sibling Expo application is detected on
218
+ its own manifest, and walking its dependencies pulled the entire Expo and Metro
219
+ toolchain into the Babel transform set of a package that depends on none of it: over
220
+ 250 packages in a two-package reproduction, `@babel/runtime` and Metro's `lru-cache`
221
+ chain among them.
222
+
223
+ Those are not inert. React Native and Babel load them, and compiling the transform's
224
+ own toolchain re-enters Babel while it is still initialising — which surfaces as a
225
+ `Cannot access 'v' before initialization` naming files the project never mentioned.
226
+ The existing toolchain exclusion covers what `@babel/core` reaches and so did not
227
+ catch either of them.
228
+
229
+ The closure now starts only from packages the run itself declares — the package under
230
+ test, and any manifest above it, which is where a workspace keeping its React Native
231
+ libraries at the repository root declares them. A package only a sibling declares is
232
+ that sibling's business. Transitive compilation is unaffected: a dependency reached
233
+ through the walk is declared by its own parent, which is what makes it transitive.
234
+
235
+ Declaration rather than resolvability, deliberately: under pnpm every workspace member
236
+ is linked into a hidden directory placed on `NODE_PATH`, so a sibling's dependencies
237
+ do resolve from the package under test at run time, and testing reachability instead
238
+ lets all of them straight back through.
239
+
240
+ `@babel/runtime` and `metro` also now seed the toolchain exclusion, alongside
241
+ `@babel/core` and the React Native Babel preset. Neither is reachable from
242
+ `@babel/core`, so the existing exclusion let both through. `@babel/runtime` holds the
243
+ helpers Babel _emits_, so compiled output across the ecosystem requires it at run
244
+ time; Metro is the bundler the preset belongs to, and its `lru-cache` chain — the
245
+ `yallist` in the report — is loaded the same way. This matters beyond the reported
246
+ shape: an Expo application running its own tests declares `expo` legitimately, so its
247
+ closure is walked and the same packages arrive by a route the change above does not
248
+ affect.
249
+
250
+ In the two-package reproduction the transform set drops from 253 packages to 5 — the
251
+ declared dependency and its genuine closure. For an Expo application testing itself it
252
+ drops from 251 to 171, with `@babel/runtime`, `yallist` and Metro's cache chain no
253
+ longer among them.
254
+
255
+ A closure member that publishes only ES modules is left alone as well. The walk is a
256
+ guess that a detected package's dependencies might be untranspiled React Native
257
+ source; `"type": "module"` with no `react-native` build anywhere in the manifest is
258
+ the dependency saying the opposite. Compiling one anyway rewrote a package that
259
+ publishes ESM into CommonJS and handed it to Node under that format. A genuine React
260
+ Native library is unaffected — declaring `react-native`, by legacy field or by export
261
+ condition at any depth, keeps it in the closure however it publishes — and so is any
262
+ package named in `transform: [...]`, which was asked for explicitly.
263
+
3
264
  ## 0.11.0
4
265
 
5
266
  ### Minor Changes
package/dist/cli.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
4
- const require_ecosystem = require("./ecosystem-BJzJU3Cf.cjs");
4
+ const require_ecosystem = require("./ecosystem-CEIF_-jq.cjs");
5
5
  const require_preset_map = require("./preset-map-BoG19dLa.cjs");
6
6
  let node_fs = require("node:fs");
7
7
  node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { l as validatePeerDependency, n as detectEngine, s as PEER_REQUIREMENTS, t as detectEcosystemPackages } from "./ecosystem-C4qT_vl3.mjs";
2
+ import { l as validatePeerDependency, n as detectEngine, s as PEER_REQUIREMENTS, t as detectEcosystemPackages } from "./ecosystem-Duw40-mO.mjs";
3
3
  import { t as AUTO_DETECT_PRESETS } from "./preset-map-DuX0ocdn.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import fs from "node:fs";
@@ -20,7 +20,8 @@ const KNOWN_OPTIONS = [
20
20
  const KNOWN_HOT_RUNTIME_OPTIONS = [
21
21
  "recycleAfterFiles",
22
22
  "memoryLimit",
23
- "preserveGlobals"
23
+ "preserveGlobals",
24
+ "esmGeneration"
24
25
  ];
25
26
  function assertStringArray(value, option) {
26
27
  if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry.length === 0)) throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"${option}" must be an array of non-empty strings.`);
@@ -33,7 +34,14 @@ function validateOptions(options) {
33
34
  if (options.platform !== void 0 && options.platform !== "ios" && options.platform !== "android") throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"platform" must be "ios" or "android".`);
34
35
  if (options.diagnostics !== void 0 && typeof options.diagnostics !== "boolean") throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"diagnostics" must be a boolean.`);
35
36
  if (options.assetExts !== void 0) assertStringArray(options.assetExts, "assetExts");
36
- if (options.transform !== void 0) assertStringArray(options.transform, "transform");
37
+ if (options.transform !== void 0) if (Array.isArray(options.transform)) assertStringArray(options.transform, "transform");
38
+ else if (options.transform !== null && typeof options.transform === "object") {
39
+ const shape = options.transform;
40
+ const unknownKeys = Object.keys(shape).filter((k) => k !== "include" && k !== "exclude");
41
+ if (unknownKeys.length > 0) throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"transform" accepts only "include" and "exclude"; received ${unknownKeys.map((k) => `"${k}"`).join(", ")}.`);
42
+ if (shape.include !== void 0) assertStringArray(shape.include, "transform.include");
43
+ if (shape.exclude !== void 0) assertStringArray(shape.exclude, "transform.exclude");
44
+ } else throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"transform" must be an array of package names, or an object with "include" and/or "exclude".`);
37
45
  if (options.presets !== void 0 && !Array.isArray(options.presets)) {
38
46
  if (!(options.presets !== null && typeof options.presets === "object" && Object.values(options.presets).every((v) => typeof v === "boolean"))) throw new require_errors.VitestNativeTypeError("INVALID_OPTION", "\"presets\" must be an array of presets, or an object of booleans to switch auto-detected presets off (for example { navigation: false }).");
39
47
  }
@@ -49,6 +57,7 @@ function validateOptions(options) {
49
57
  if (hotOptions.recycleAfterFiles !== void 0) assertNonNegativeInteger(hotOptions.recycleAfterFiles, "hotRuntime.recycleAfterFiles");
50
58
  if (hotOptions.memoryLimit !== void 0) assertNonNegativeInteger(hotOptions.memoryLimit, "hotRuntime.memoryLimit");
51
59
  if (hotOptions.preserveGlobals !== void 0) assertStringArray(hotOptions.preserveGlobals, "hotRuntime.preserveGlobals");
60
+ if (hotOptions.esmGeneration !== void 0 && typeof hotOptions.esmGeneration !== "boolean") throw new require_errors.VitestNativeTypeError("INVALID_OPTION", `"hotRuntime.esmGeneration" must be a boolean.`);
52
61
  }
53
62
  function satisfiesMinimum(version, minimum) {
54
63
  const parse = (v) => v.replace(/^[^0-9]*/, "").split(/[-+]/)[0].split(".").map(Number);
@@ -248,44 +257,71 @@ function packagePatterns(name, projectRoot) {
248
257
  if (dir && !containsPath(dir, projectRoot)) patterns.push(new RegExp(`^${escapeRe(toPosix(dir).replace(/\/$/, ""))}[\\\\/]`));
249
258
  return patterns;
250
259
  }
251
- /** Can this project run the native engine? (Both transform deps resolvable.) */
252
- function isNativeCapable(projectRoot) {
253
- try {
254
- const req = (0, node_module.createRequire)(node_path.default.join(projectRoot, "package.json"));
255
- req.resolve("@react-native/babel-preset");
256
- req.resolve("@babel/core");
257
- return true;
260
+ /**
261
+ * The native engine's dependencies that do NOT resolve from the project root.
262
+ *
263
+ * react-native itself is part of the check: the Babel toolchain alone chose
264
+ * native mode in a project with the preset installed but no react-native — an
265
+ * incomplete install, a babel-only workspace — which then failed later at RN
266
+ * resolution with nothing pointing at the cause. Resolution, not declaration:
267
+ * every check walks node_modules upward from the root — so a hoisted workspace
268
+ * install or Expo's transitive react-native counts, and a project does not need
269
+ * react-native in its own manifest.
270
+ */
271
+ function missingNativeDeps(projectRoot) {
272
+ const req = (0, node_module.createRequire)(node_path.default.join(projectRoot, "package.json"));
273
+ const missing = [];
274
+ if (!reactNativeInstalledNear(projectRoot)) missing.push("react-native");
275
+ for (const dep of ["@react-native/babel-preset", "@babel/core"]) try {
276
+ req.resolve(dep);
258
277
  } catch {
259
- return false;
278
+ missing.push(dep);
279
+ }
280
+ return missing;
281
+ }
282
+ /** Does node_modules/react-native exist in projectRoot or any ancestor? */
283
+ function reactNativeInstalledNear(projectRoot) {
284
+ let dir = node_path.default.resolve(projectRoot);
285
+ for (;;) {
286
+ if (node_fs.default.existsSync(node_path.default.join(dir, "node_modules", "react-native", "package.json"))) return true;
287
+ const parent = node_path.default.dirname(dir);
288
+ if (parent === dir) return false;
289
+ dir = parent;
260
290
  }
261
291
  }
262
292
  /** Resolve the concrete engine for a run. Pure; never throws. */
263
293
  function detectEngine(requested, projectRoot, opts) {
264
- const nativeAvailable = isNativeCapable(projectRoot);
294
+ const missing = missingNativeDeps(projectRoot);
295
+ const nativeAvailable = missing.length === 0;
265
296
  if (requested === "native") return {
266
297
  engine: "native",
267
298
  nativeAvailable,
299
+ missing,
268
300
  notice: null
269
301
  };
270
302
  if (requested === "mock") return {
271
303
  engine: "mock",
272
304
  nativeAvailable,
305
+ missing,
273
306
  notice: null
274
307
  };
275
308
  const prefersNative = opts?.autoPrefersNative ?? true;
276
309
  if (prefersNative && nativeAvailable) return {
277
310
  engine: "native",
278
311
  nativeAvailable,
312
+ missing,
279
313
  notice: null
280
314
  };
281
315
  if (prefersNative) return {
282
316
  engine: "mock",
283
317
  nativeAvailable: false,
284
- notice: "[vitest-native] @react-native/babel-preset not found — using the mock engine. Install it (and @babel/core) to run real React Native, or set engine:'mock' to silence this."
318
+ missing,
319
+ notice: `[vitest-native] ${missing.join(", ")} not found — using the mock engine. Install what's missing to run real React Native, or set engine:'mock' to silence this.`
285
320
  };
286
321
  return {
287
322
  engine: "mock",
288
323
  nativeAvailable,
324
+ missing,
289
325
  notice: null
290
326
  };
291
327
  }
@@ -310,6 +346,41 @@ const NEVER_INLINE = /* @__PURE__ */ new Set([
310
346
  "react",
311
347
  "react-is"
312
348
  ]);
349
+ /** Does this manifest offer a React Native build, by legacy field or export condition? */
350
+ function hasReactNativeBuild(manifest) {
351
+ if (typeof manifest["react-native"] === "string") return true;
352
+ const seen = /* @__PURE__ */ new Set();
353
+ const search = (node) => {
354
+ if (!node || typeof node !== "object" || seen.has(node)) return false;
355
+ seen.add(node);
356
+ for (const [key, value] of Object.entries(node)) {
357
+ if (key === "react-native") return true;
358
+ if (search(value)) return true;
359
+ }
360
+ return false;
361
+ };
362
+ return search(manifest.exports);
363
+ }
364
+ /**
365
+ * A package that ships ES modules and nothing React Native.
366
+ *
367
+ * The closure walk is a guess: a detected package's dependencies MIGHT be untranspiled
368
+ * React Native source, because the ecosystem publishes that way and the dependency's
369
+ * own manifest cannot say so. `"type": "module"` is the manifest saying the opposite —
370
+ * this is runnable ES modules — and with no React Native build anywhere in it, there is
371
+ * nothing for the preset to do. Compiling it anyway rewrites a package that publishes
372
+ * ESM into CommonJS and hands it to Node under that format, which is how a dependency
373
+ * reached this way (`zod`) failed to parse and took fourteen test files down with it.
374
+ *
375
+ * A genuine React Native library is unaffected: declaring `react-native` by field or
376
+ * export condition keeps it in the closure however it publishes.
377
+ *
378
+ * Only closure MEMBERS are judged this way. A package detected on its own manifest, or
379
+ * named in `transform: [...]`, was asked for explicitly and is still compiled.
380
+ */
381
+ function publishesOnlyEsm(manifest) {
382
+ return manifest.type === "module" && !hasReactNativeBuild(manifest);
383
+ }
313
384
  /** Manifest fields that make a package part of the React Native ecosystem. */
314
385
  function dependsOnReactNative(manifest) {
315
386
  for (const field of ["dependencies", "peerDependencies"]) {
@@ -414,12 +485,13 @@ function manifestsFrom(projectRoot) {
414
485
  * test infrastructure in NEVER_INLINE, and anything the consumer listed explicitly
415
486
  * in `transform` — that option keeps its existing meaning and takes precedence.
416
487
  */
417
- function detectEcosystemPackages(projectRoot, explicit = [], testRoots = []) {
488
+ function detectEcosystemPackages(projectRoot, explicit = [], testRoots = [], neverTransform = []) {
418
489
  const roots = (Array.isArray(projectRoot) ? projectRoot : [projectRoot]).filter(Boolean);
419
490
  const skip = /* @__PURE__ */ new Set([
420
491
  ...NEVER_INLINE,
421
492
  ...Object.keys(require_preset_map.AUTO_DETECT_PRESETS),
422
- ...explicit
493
+ ...explicit,
494
+ ...neverTransform
423
495
  ]);
424
496
  const candidates = /* @__PURE__ */ new Set();
425
497
  const found = roots.flatMap((root) => manifestsFrom(root));
@@ -487,9 +559,26 @@ function detectEcosystemPackages(projectRoot, explicit = [], testRoots = []) {
487
559
  }
488
560
  return seen;
489
561
  };
490
- const toolchain = closureOf(["@babel/core", "@react-native/babel-preset"]);
562
+ const toolchain = closureOf([
563
+ "@babel/core",
564
+ "@react-native/babel-preset",
565
+ "@babel/runtime",
566
+ "metro"
567
+ ]);
568
+ const projectDeclared = /* @__PURE__ */ new Set();
569
+ for (const { dir, manifest } of found) {
570
+ if (!ownerRoots.some((root) => containsPath(dir, root))) continue;
571
+ for (const field of [
572
+ "dependencies",
573
+ "devDependencies",
574
+ "optionalDependencies"
575
+ ]) {
576
+ const deps = manifest[field];
577
+ if (deps && typeof deps === "object") for (const name of Object.keys(deps)) projectDeclared.add(name);
578
+ }
579
+ }
491
580
  const inClosure = new Set(detected);
492
- const queue = [...detected];
581
+ const queue = detected.filter((name) => projectDeclared.has(name));
493
582
  while (queue.length > 0) {
494
583
  const deps = manifestOf(queue.pop())?.dependencies;
495
584
  if (!deps || typeof deps !== "object") continue;
@@ -498,7 +587,9 @@ function detectEcosystemPackages(projectRoot, explicit = [], testRoots = []) {
498
587
  if (rnOwned.has(dep)) continue;
499
588
  if (toolchain.has(dep)) continue;
500
589
  if (ownsTheRun(dep)) continue;
501
- if (!manifestOf(dep)) continue;
590
+ const depManifest = manifestOf(dep);
591
+ if (!depManifest) continue;
592
+ if (publishesOnlyEsm(depManifest)) continue;
502
593
  inClosure.add(dep);
503
594
  queue.push(dep);
504
595
  }