vitest-native 0.11.0 → 0.11.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.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,72 @@
|
|
|
1
1
|
# vitest-native
|
|
2
2
|
|
|
3
|
+
## 0.11.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ea133b6: Only walk the dependency closure of packages the project declares
|
|
8
|
+
|
|
9
|
+
Fixes a regression in 0.11.0. In a workspace holding both a library and a React
|
|
10
|
+
Native or Expo application — the canonical monorepo shape — the application's mere
|
|
11
|
+
presence could stop the library's tests from loading:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
ReferenceError: [vitest-native] Failed to transform '@babel/runtime' … for platform 'ios'.
|
|
15
|
+
Caused by: ReferenceError: Cannot access 'v' before initialization
|
|
16
|
+
Test Files 1 failed | Tests: no tests
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
0.11.0 began compiling a detected package's dependency closure, so that a library
|
|
20
|
+
shipping untranspiled JSX inside a transitive dependency would work without naming it
|
|
21
|
+
in `transform: [...]`. Candidates are collected from every manifest in the workspace,
|
|
22
|
+
which is how a library the application depends on is found at all — but applied to a
|
|
23
|
+
closure walk, that breadth stops being free. A sibling Expo application is detected on
|
|
24
|
+
its own manifest, and walking its dependencies pulled the entire Expo and Metro
|
|
25
|
+
toolchain into the Babel transform set of a package that depends on none of it: over
|
|
26
|
+
250 packages in a two-package reproduction, `@babel/runtime` and Metro's `lru-cache`
|
|
27
|
+
chain among them.
|
|
28
|
+
|
|
29
|
+
Those are not inert. React Native and Babel load them, and compiling the transform's
|
|
30
|
+
own toolchain re-enters Babel while it is still initialising — which surfaces as a
|
|
31
|
+
`Cannot access 'v' before initialization` naming files the project never mentioned.
|
|
32
|
+
The existing toolchain exclusion covers what `@babel/core` reaches and so did not
|
|
33
|
+
catch either of them.
|
|
34
|
+
|
|
35
|
+
The closure now starts only from packages the run itself declares — the package under
|
|
36
|
+
test, and any manifest above it, which is where a workspace keeping its React Native
|
|
37
|
+
libraries at the repository root declares them. A package only a sibling declares is
|
|
38
|
+
that sibling's business. Transitive compilation is unaffected: a dependency reached
|
|
39
|
+
through the walk is declared by its own parent, which is what makes it transitive.
|
|
40
|
+
|
|
41
|
+
Declaration rather than resolvability, deliberately: under pnpm every workspace member
|
|
42
|
+
is linked into a hidden directory placed on `NODE_PATH`, so a sibling's dependencies
|
|
43
|
+
do resolve from the package under test at run time, and testing reachability instead
|
|
44
|
+
lets all of them straight back through.
|
|
45
|
+
|
|
46
|
+
`@babel/runtime` and `metro` also now seed the toolchain exclusion, alongside
|
|
47
|
+
`@babel/core` and the React Native Babel preset. Neither is reachable from
|
|
48
|
+
`@babel/core`, so the existing exclusion let both through. `@babel/runtime` holds the
|
|
49
|
+
helpers Babel _emits_, so compiled output across the ecosystem requires it at run
|
|
50
|
+
time; Metro is the bundler the preset belongs to, and its `lru-cache` chain — the
|
|
51
|
+
`yallist` in the report — is loaded the same way. This matters beyond the reported
|
|
52
|
+
shape: an Expo application running its own tests declares `expo` legitimately, so its
|
|
53
|
+
closure is walked and the same packages arrive by a route the change above does not
|
|
54
|
+
affect.
|
|
55
|
+
|
|
56
|
+
In the two-package reproduction the transform set drops from 253 packages to 5 — the
|
|
57
|
+
declared dependency and its genuine closure. For an Expo application testing itself it
|
|
58
|
+
drops from 251 to 171, with `@babel/runtime`, `yallist` and Metro's cache chain no
|
|
59
|
+
longer among them.
|
|
60
|
+
|
|
61
|
+
A closure member that publishes only ES modules is left alone as well. The walk is a
|
|
62
|
+
guess that a detected package's dependencies might be untranspiled React Native
|
|
63
|
+
source; `"type": "module"` with no `react-native` build anywhere in the manifest is
|
|
64
|
+
the dependency saying the opposite. Compiling one anyway rewrote a package that
|
|
65
|
+
publishes ESM into CommonJS and handed it to Node under that format. A genuine React
|
|
66
|
+
Native library is unaffected — declaring `react-native`, by legacy field or by export
|
|
67
|
+
condition at any depth, keeps it in the closure however it publishes — and so is any
|
|
68
|
+
package named in `transform: [...]`, which was asked for explicitly.
|
|
69
|
+
|
|
3
70
|
## 0.11.0
|
|
4
71
|
|
|
5
72
|
### 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-
|
|
4
|
+
const require_ecosystem = require("./ecosystem-DGlajfDG.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-
|
|
2
|
+
import { l as validatePeerDependency, n as detectEngine, s as PEER_REQUIREMENTS, t as detectEcosystemPackages } from "./ecosystem-DJMGR2YY.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";
|
|
@@ -310,6 +310,41 @@ const NEVER_INLINE = /* @__PURE__ */ new Set([
|
|
|
310
310
|
"react",
|
|
311
311
|
"react-is"
|
|
312
312
|
]);
|
|
313
|
+
/** Does this manifest offer a React Native build, by legacy field or export condition? */
|
|
314
|
+
function hasReactNativeBuild(manifest) {
|
|
315
|
+
if (typeof manifest["react-native"] === "string") return true;
|
|
316
|
+
const seen = /* @__PURE__ */ new Set();
|
|
317
|
+
const search = (node) => {
|
|
318
|
+
if (!node || typeof node !== "object" || seen.has(node)) return false;
|
|
319
|
+
seen.add(node);
|
|
320
|
+
for (const [key, value] of Object.entries(node)) {
|
|
321
|
+
if (key === "react-native") return true;
|
|
322
|
+
if (search(value)) return true;
|
|
323
|
+
}
|
|
324
|
+
return false;
|
|
325
|
+
};
|
|
326
|
+
return search(manifest.exports);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* A package that ships ES modules and nothing React Native.
|
|
330
|
+
*
|
|
331
|
+
* The closure walk is a guess: a detected package's dependencies MIGHT be untranspiled
|
|
332
|
+
* React Native source, because the ecosystem publishes that way and the dependency's
|
|
333
|
+
* own manifest cannot say so. `"type": "module"` is the manifest saying the opposite —
|
|
334
|
+
* this is runnable ES modules — and with no React Native build anywhere in it, there is
|
|
335
|
+
* nothing for the preset to do. Compiling it anyway rewrites a package that publishes
|
|
336
|
+
* ESM into CommonJS and hands it to Node under that format, which is how a dependency
|
|
337
|
+
* reached this way (`zod`) failed to parse and took fourteen test files down with it.
|
|
338
|
+
*
|
|
339
|
+
* A genuine React Native library is unaffected: declaring `react-native` by field or
|
|
340
|
+
* export condition keeps it in the closure however it publishes.
|
|
341
|
+
*
|
|
342
|
+
* Only closure MEMBERS are judged this way. A package detected on its own manifest, or
|
|
343
|
+
* named in `transform: [...]`, was asked for explicitly and is still compiled.
|
|
344
|
+
*/
|
|
345
|
+
function publishesOnlyEsm(manifest) {
|
|
346
|
+
return manifest.type === "module" && !hasReactNativeBuild(manifest);
|
|
347
|
+
}
|
|
313
348
|
/** Manifest fields that make a package part of the React Native ecosystem. */
|
|
314
349
|
function dependsOnReactNative(manifest) {
|
|
315
350
|
for (const field of ["dependencies", "peerDependencies"]) {
|
|
@@ -487,9 +522,26 @@ function detectEcosystemPackages(projectRoot, explicit = [], testRoots = []) {
|
|
|
487
522
|
}
|
|
488
523
|
return seen;
|
|
489
524
|
};
|
|
490
|
-
const toolchain = closureOf([
|
|
525
|
+
const toolchain = closureOf([
|
|
526
|
+
"@babel/core",
|
|
527
|
+
"@react-native/babel-preset",
|
|
528
|
+
"@babel/runtime",
|
|
529
|
+
"metro"
|
|
530
|
+
]);
|
|
531
|
+
const projectDeclared = /* @__PURE__ */ new Set();
|
|
532
|
+
for (const { dir, manifest } of found) {
|
|
533
|
+
if (!ownerRoots.some((root) => containsPath(dir, root))) continue;
|
|
534
|
+
for (const field of [
|
|
535
|
+
"dependencies",
|
|
536
|
+
"devDependencies",
|
|
537
|
+
"optionalDependencies"
|
|
538
|
+
]) {
|
|
539
|
+
const deps = manifest[field];
|
|
540
|
+
if (deps && typeof deps === "object") for (const name of Object.keys(deps)) projectDeclared.add(name);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
491
543
|
const inClosure = new Set(detected);
|
|
492
|
-
const queue =
|
|
544
|
+
const queue = detected.filter((name) => projectDeclared.has(name));
|
|
493
545
|
while (queue.length > 0) {
|
|
494
546
|
const deps = manifestOf(queue.pop())?.dependencies;
|
|
495
547
|
if (!deps || typeof deps !== "object") continue;
|
|
@@ -498,7 +550,9 @@ function detectEcosystemPackages(projectRoot, explicit = [], testRoots = []) {
|
|
|
498
550
|
if (rnOwned.has(dep)) continue;
|
|
499
551
|
if (toolchain.has(dep)) continue;
|
|
500
552
|
if (ownsTheRun(dep)) continue;
|
|
501
|
-
|
|
553
|
+
const depManifest = manifestOf(dep);
|
|
554
|
+
if (!depManifest) continue;
|
|
555
|
+
if (publishesOnlyEsm(depManifest)) continue;
|
|
502
556
|
inClosure.add(dep);
|
|
503
557
|
queue.push(dep);
|
|
504
558
|
}
|
|
@@ -307,6 +307,41 @@ const NEVER_INLINE = /* @__PURE__ */ new Set([
|
|
|
307
307
|
"react",
|
|
308
308
|
"react-is"
|
|
309
309
|
]);
|
|
310
|
+
/** Does this manifest offer a React Native build, by legacy field or export condition? */
|
|
311
|
+
function hasReactNativeBuild(manifest) {
|
|
312
|
+
if (typeof manifest["react-native"] === "string") return true;
|
|
313
|
+
const seen = /* @__PURE__ */ new Set();
|
|
314
|
+
const search = (node) => {
|
|
315
|
+
if (!node || typeof node !== "object" || seen.has(node)) return false;
|
|
316
|
+
seen.add(node);
|
|
317
|
+
for (const [key, value] of Object.entries(node)) {
|
|
318
|
+
if (key === "react-native") return true;
|
|
319
|
+
if (search(value)) return true;
|
|
320
|
+
}
|
|
321
|
+
return false;
|
|
322
|
+
};
|
|
323
|
+
return search(manifest.exports);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* A package that ships ES modules and nothing React Native.
|
|
327
|
+
*
|
|
328
|
+
* The closure walk is a guess: a detected package's dependencies MIGHT be untranspiled
|
|
329
|
+
* React Native source, because the ecosystem publishes that way and the dependency's
|
|
330
|
+
* own manifest cannot say so. `"type": "module"` is the manifest saying the opposite —
|
|
331
|
+
* this is runnable ES modules — and with no React Native build anywhere in it, there is
|
|
332
|
+
* nothing for the preset to do. Compiling it anyway rewrites a package that publishes
|
|
333
|
+
* ESM into CommonJS and hands it to Node under that format, which is how a dependency
|
|
334
|
+
* reached this way (`zod`) failed to parse and took fourteen test files down with it.
|
|
335
|
+
*
|
|
336
|
+
* A genuine React Native library is unaffected: declaring `react-native` by field or
|
|
337
|
+
* export condition keeps it in the closure however it publishes.
|
|
338
|
+
*
|
|
339
|
+
* Only closure MEMBERS are judged this way. A package detected on its own manifest, or
|
|
340
|
+
* named in `transform: [...]`, was asked for explicitly and is still compiled.
|
|
341
|
+
*/
|
|
342
|
+
function publishesOnlyEsm(manifest) {
|
|
343
|
+
return manifest.type === "module" && !hasReactNativeBuild(manifest);
|
|
344
|
+
}
|
|
310
345
|
/** Manifest fields that make a package part of the React Native ecosystem. */
|
|
311
346
|
function dependsOnReactNative(manifest) {
|
|
312
347
|
for (const field of ["dependencies", "peerDependencies"]) {
|
|
@@ -484,9 +519,26 @@ function detectEcosystemPackages(projectRoot, explicit = [], testRoots = []) {
|
|
|
484
519
|
}
|
|
485
520
|
return seen;
|
|
486
521
|
};
|
|
487
|
-
const toolchain = closureOf([
|
|
522
|
+
const toolchain = closureOf([
|
|
523
|
+
"@babel/core",
|
|
524
|
+
"@react-native/babel-preset",
|
|
525
|
+
"@babel/runtime",
|
|
526
|
+
"metro"
|
|
527
|
+
]);
|
|
528
|
+
const projectDeclared = /* @__PURE__ */ new Set();
|
|
529
|
+
for (const { dir, manifest } of found) {
|
|
530
|
+
if (!ownerRoots.some((root) => containsPath(dir, root))) continue;
|
|
531
|
+
for (const field of [
|
|
532
|
+
"dependencies",
|
|
533
|
+
"devDependencies",
|
|
534
|
+
"optionalDependencies"
|
|
535
|
+
]) {
|
|
536
|
+
const deps = manifest[field];
|
|
537
|
+
if (deps && typeof deps === "object") for (const name of Object.keys(deps)) projectDeclared.add(name);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
488
540
|
const inClosure = new Set(detected);
|
|
489
|
-
const queue =
|
|
541
|
+
const queue = detected.filter((name) => projectDeclared.has(name));
|
|
490
542
|
while (queue.length > 0) {
|
|
491
543
|
const deps = manifestOf(queue.pop())?.dependencies;
|
|
492
544
|
if (!deps || typeof deps !== "object") continue;
|
|
@@ -495,7 +547,9 @@ function detectEcosystemPackages(projectRoot, explicit = [], testRoots = []) {
|
|
|
495
547
|
if (rnOwned.has(dep)) continue;
|
|
496
548
|
if (toolchain.has(dep)) continue;
|
|
497
549
|
if (ownsTheRun(dep)) continue;
|
|
498
|
-
|
|
550
|
+
const depManifest = manifestOf(dep);
|
|
551
|
+
if (!depManifest) continue;
|
|
552
|
+
if (publishesOnlyEsm(depManifest)) continue;
|
|
499
553
|
inClosure.add(dep);
|
|
500
554
|
queue.push(dep);
|
|
501
555
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as VitestNativeError } from "./errors-CxoBUfVJ.mjs";
|
|
2
|
-
import { a as packageDirOf, c as validateOptions, i as containsPath, l as validatePeerDependency, n as detectEngine, o as packagePatterns, r as REACT_NATIVE_PATH, s as PEER_REQUIREMENTS, t as detectEcosystemPackages, u as warnUnknownOptions } from "./ecosystem-
|
|
2
|
+
import { a as packageDirOf, c as validateOptions, i as containsPath, l as validatePeerDependency, n as detectEngine, o as packagePatterns, r as REACT_NATIVE_PATH, s as PEER_REQUIREMENTS, t as detectEcosystemPackages, u as warnUnknownOptions } from "./ecosystem-DJMGR2YY.mjs";
|
|
3
3
|
import { t as AUTO_DETECT_PRESETS } from "./preset-map-DuX0ocdn.mjs";
|
|
4
4
|
import { t as presets_exports } from "./presets-IStcJEOa.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|