vitest-native 0.10.0 → 0.11.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 +190 -0
- package/README.md +1 -0
- package/dist/cli.cjs +25 -7
- package/dist/cli.mjs +22 -4
- package/dist/{ecosystem-IuZ-Gv0R.cjs → ecosystem-BJzJU3Cf.cjs} +226 -14
- package/dist/{ecosystem-CO5vqExO.mjs → ecosystem-C4qT_vl3.mjs} +200 -12
- package/dist/helpers.cjs +1 -1
- package/dist/helpers.mjs +1 -1
- package/dist/{index-BJL4cQ-l.d.cts → index-CrMeE8rd.d.mts} +5 -5
- package/dist/{index-CvCU0cLl.d.mts → index-DIMbjH8R.d.cts} +6 -3
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +78 -48
- package/dist/jest-compat.cjs +4 -4
- package/dist/jest-compat.d.cts +0 -1
- package/dist/jest-compat.d.mts +0 -1
- package/dist/jest-compat.mjs +2 -2
- package/dist/native/hooks.mjs +77 -12
- package/dist/native/loader.mjs +10 -5
- package/dist/native/match.d.mts +33 -0
- package/dist/native/match.mjs +94 -22
- package/dist/native/registry.mjs +30 -2
- package/dist/{pool-CFND7plG.cjs → pool-BU-1ecIF.cjs} +6 -6
- package/dist/{pool-Bcxp4Qrg.mjs → pool-Bcxn9a3I.mjs} +3 -3
- package/dist/{preset-map-DxilQ4pI.cjs → preset-map-BoG19dLa.cjs} +1 -0
- package/dist/{preset-map-BpDG_D5m.mjs → preset-map-DuX0ocdn.mjs} +1 -0
- package/dist/{presets-BGTqVH6C.cjs → presets-CwO_c4aL.cjs} +131 -6
- package/dist/{presets-CK85x8ey.mjs → presets-IStcJEOa.mjs} +123 -4
- package/dist/presets.d.mts +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/{chunk-CjcI7cDX.mjs → rolldown-runtime-BhDjJH2R.mjs} +1 -1
- package/dist/{chunk-CZWwpsFl.cjs → rolldown-runtime-C0BPl7ul.cjs} +1 -1
- package/dist/serializer.cjs +1 -1
- package/dist/serializer.mjs +1 -1
- package/dist/setup.d.mts +1 -1
- package/dist/setup.mjs +5 -5
- package/docs/versioning.md +1 -1
- package/package.json +17 -15
- /package/dist/{errors-flXDIeWk.cjs → errors-B3lJK46O.cjs} +0 -0
- /package/dist/{errors-Dm5yLNTF.mjs → errors-CxoBUfVJ.mjs} +0 -0
package/dist/native/hooks.mjs
CHANGED
|
@@ -6,16 +6,16 @@ import fs from "node:fs";
|
|
|
6
6
|
import { transformRN, isFlow } from "./transform.mjs";
|
|
7
7
|
import { boundarySourceFor } from "./boundary.mjs";
|
|
8
8
|
import { resolvePlatformFile } from "./resolve.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
NODE_MODULES_PATH,
|
|
11
|
+
REACT_NATIVE_PATH,
|
|
12
|
+
buildPkgMatcher,
|
|
13
|
+
isUtilitySubpath,
|
|
14
|
+
packageNameOf,
|
|
15
|
+
subpathLeafOf,
|
|
16
|
+
} from "./match.mjs";
|
|
10
17
|
import { explainUntransformedSyntaxError } from "./explain.mjs";
|
|
11
18
|
|
|
12
|
-
const RN_PATH = /[\\/]node_modules[\\/](react-native|@react-native)[\\/]/;
|
|
13
|
-
// Any file under a node_modules directory. Platform-extension resolution
|
|
14
|
-
// (`.native.js` etc.) applies to every node_modules package, not just RN — matching
|
|
15
|
-
// Metro, which resolves platform variants project-wide. See loader.mjs for the
|
|
16
|
-
// ESM-path counterpart and the @react-navigation silent-failure this prevents.
|
|
17
|
-
const NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
18
|
-
|
|
19
19
|
// Guarded via globalThis, not module scope: under the hot runtime this module
|
|
20
20
|
// can be evaluated twice in one worker (once by the worker entry through Node's
|
|
21
21
|
// loader, once through Vitest's module runner when the setup file is inlined),
|
|
@@ -37,10 +37,74 @@ const NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
|
37
37
|
const VITE_MAIN_FIELDS = ["react-native", "module", "jsnext:main", "jsnext"];
|
|
38
38
|
|
|
39
39
|
const reportedDuplicates = new Set();
|
|
40
|
+
const reportedProjectLoads = new Set();
|
|
40
41
|
|
|
41
42
|
/** Test seam: the warning is once per package for the life of the worker. */
|
|
42
43
|
export function _resetDuplicateReports() {
|
|
43
44
|
reportedDuplicates.clear();
|
|
45
|
+
reportedProjectLoads.clear();
|
|
46
|
+
cachedProjectDirs = undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Directories Vite owns outright: the package the run lives in, and any package a
|
|
51
|
+
* `test.include` pattern points into (see plugin.ts). Read from the environment
|
|
52
|
+
* because it has to cross into the worker.
|
|
53
|
+
*
|
|
54
|
+
* Parsed once. This is consulted on every module resolution in the worker, so
|
|
55
|
+
* re-reading and re-parsing the variable per call put a JSON.parse in the hot path.
|
|
56
|
+
*/
|
|
57
|
+
let cachedProjectDirs;
|
|
58
|
+
function projectDirs() {
|
|
59
|
+
if (cachedProjectDirs) return cachedProjectDirs;
|
|
60
|
+
try {
|
|
61
|
+
cachedProjectDirs = JSON.parse(process.env.VITEST_NATIVE_PROJECT_DIRS || "[]").map(
|
|
62
|
+
(dir) => dir.replace(/\\/g, "/").replace(/\/+$/, "") + "/",
|
|
63
|
+
);
|
|
64
|
+
} catch {
|
|
65
|
+
cachedProjectDirs = [];
|
|
66
|
+
}
|
|
67
|
+
return cachedProjectDirs;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Say so when Node loads the project's own source.
|
|
72
|
+
*
|
|
73
|
+
* The package under test is Vite's (see the ownership rule in apply.ts). If an
|
|
74
|
+
* installed package requires it as well, it exists twice — once in each graph — and
|
|
75
|
+
* the symptom is silence: a store configured through the test's copy reads back unset
|
|
76
|
+
* through the copy the library sees, so an assertion compares "" against the expected
|
|
77
|
+
* text with nothing pointing at the cause. It is the same failure the
|
|
78
|
+
* duplicate-instance warning above covers, arrived at from the other direction: there
|
|
79
|
+
* the two graphs disagree about which FILE the package is, here they agree on the file
|
|
80
|
+
* and still hold separate instances of it.
|
|
81
|
+
*
|
|
82
|
+
* Only reported when the requirer is an installed package. A test reaching into its
|
|
83
|
+
* own source deliberately — `jest.requireActual('./src/thing')` — is Node loading
|
|
84
|
+
* project files on purpose, and is not this.
|
|
85
|
+
*/
|
|
86
|
+
export function checkProjectSourceLoadedByNode(resolved, parent, dirs = projectDirs()) {
|
|
87
|
+
if (dirs.length === 0 || typeof resolved !== "string") return;
|
|
88
|
+
const file = resolved.replace(/\\/g, "/");
|
|
89
|
+
// Project source never lives under node_modules, and the project directory
|
|
90
|
+
// contains its own node_modules — so this has to be excluded explicitly.
|
|
91
|
+
if (file.includes("/node_modules/")) return;
|
|
92
|
+
if (!dirs.some((dir) => file.startsWith(dir))) return;
|
|
93
|
+
const from = parent && parent.filename ? parent.filename.replace(/\\/g, "/") : "";
|
|
94
|
+
if (!NODE_MODULES_PATH.test(from) || from.includes("/vitest-native/dist/")) return;
|
|
95
|
+
if (reportedProjectLoads.has(file)) return;
|
|
96
|
+
reportedProjectLoads.add(file);
|
|
97
|
+
console.warn(
|
|
98
|
+
`[vitest-native] Node loaded a file from the package under test.\n` +
|
|
99
|
+
` file -> ${resolved}\n` +
|
|
100
|
+
` required by -> ${parent.filename}\n` +
|
|
101
|
+
" The package under test belongs to Vite's graph, so it now exists twice — once\n" +
|
|
102
|
+
" in each module system — and module-level state is not shared between the copies.\n" +
|
|
103
|
+
" Nothing throws: writes through one are invisible to the other, so values read back\n" +
|
|
104
|
+
" unset. This happens when an installed React Native package depends on the very\n" +
|
|
105
|
+
" package whose tests are running. Import it from one side only, or test it from a\n" +
|
|
106
|
+
" package that does not sit underneath the dependency.",
|
|
107
|
+
);
|
|
44
108
|
}
|
|
45
109
|
function reportDuplicateInstance(pkg, nodeFile, viteFile, field) {
|
|
46
110
|
reportedDuplicates.add(pkg);
|
|
@@ -197,8 +261,8 @@ export function installRequireHooks(
|
|
|
197
261
|
if (
|
|
198
262
|
parent &&
|
|
199
263
|
parent.filename &&
|
|
200
|
-
(
|
|
201
|
-
|
|
264
|
+
(NODE_MODULES_PATH.test(parent.filename) ||
|
|
265
|
+
REACT_NATIVE_PATH.test(parent.filename) ||
|
|
202
266
|
isExtra(parent.filename)) &&
|
|
203
267
|
request.startsWith(".") &&
|
|
204
268
|
!path.extname(request)
|
|
@@ -211,6 +275,7 @@ export function installRequireHooks(
|
|
|
211
275
|
}
|
|
212
276
|
const resolved = origResolve.call(this, request, parent, ...rest);
|
|
213
277
|
checkResolverAgreement(request, resolved);
|
|
278
|
+
checkProjectSourceLoadedByNode(resolved, parent);
|
|
214
279
|
return resolved;
|
|
215
280
|
};
|
|
216
281
|
|
|
@@ -219,7 +284,7 @@ export function installRequireHooks(
|
|
|
219
284
|
const norm = filename.replace(/\\/g, "/");
|
|
220
285
|
const boundary = boundarySourceFor(norm, platform, reactNativeVersion);
|
|
221
286
|
if (boundary != null) return mod._compile(boundary, filename);
|
|
222
|
-
if (
|
|
287
|
+
if (REACT_NATIVE_PATH.test(norm)) {
|
|
223
288
|
const src = fs.readFileSync(filename, "utf8");
|
|
224
289
|
if (isFlow(src))
|
|
225
290
|
return mod._compile(transformRN(filename, src, projectRoot, platform), filename);
|
|
@@ -229,7 +294,7 @@ export function installRequireHooks(
|
|
|
229
294
|
const src = fs.readFileSync(filename, "utf8");
|
|
230
295
|
return mod._compile(transformRN(filename, src, projectRoot, platform), filename);
|
|
231
296
|
}
|
|
232
|
-
if (
|
|
297
|
+
if (NODE_MODULES_PATH.test(norm)) {
|
|
233
298
|
// A node_modules package we did NOT transform: when Node's compile throws a
|
|
234
299
|
// SyntaxError that fingerprints as untranspiled JSX/Flow/TS, explain the
|
|
235
300
|
// real fix (add the package to `transform: [...]`) instead of leaving a
|
package/dist/native/loader.mjs
CHANGED
|
@@ -6,15 +6,20 @@ import fs from "node:fs";
|
|
|
6
6
|
import { transformRN, isFlow, cjsExportNames } from "./transform.mjs";
|
|
7
7
|
import { boundarySourceFor } from "./boundary.mjs";
|
|
8
8
|
import { resolvePlatformFile } from "./resolve.mjs";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
NODE_MODULES_PATH,
|
|
11
|
+
REACT_NATIVE_PATH,
|
|
12
|
+
buildPkgMatcher,
|
|
13
|
+
isUtilitySubpath,
|
|
14
|
+
packageNameOf,
|
|
15
|
+
subpathLeafOf,
|
|
16
|
+
} from "./match.mjs";
|
|
10
17
|
|
|
11
|
-
const RN_PATH = /[\\/]node_modules[\\/](react-native|@react-native)[\\/]/;
|
|
12
18
|
// Any file living under a node_modules directory. Platform-extension resolution
|
|
13
19
|
// (`.native.js` etc.) applies to every node_modules package, not just RN, matching
|
|
14
20
|
// Metro — which resolves platform variants project-wide. (Without this, e.g.
|
|
15
21
|
// `@react-navigation/native` silently loads its `.js`/web variant instead of
|
|
16
22
|
// `.native.js`, breaking the navigation lifecycle with no error.)
|
|
17
|
-
const NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
18
23
|
// React Native's main entry (`react-native/index.js`).
|
|
19
24
|
const RN_INDEX = /[\\/]react-native[\\/]index\.js$/;
|
|
20
25
|
const TRANSFORMABLE = /\.(jsx?|tsx?|mjs|cjs)$/;
|
|
@@ -90,7 +95,7 @@ export async function resolve(specifier, context, nextResolve) {
|
|
|
90
95
|
let resolved;
|
|
91
96
|
if (
|
|
92
97
|
parent &&
|
|
93
|
-
(
|
|
98
|
+
(NODE_MODULES_PATH.test(parent) || REACT_NATIVE_PATH.test(parent) || isExtra(parent)) &&
|
|
94
99
|
specifier.startsWith(".") &&
|
|
95
100
|
!path.extname(specifier)
|
|
96
101
|
) {
|
|
@@ -183,7 +188,7 @@ export async function load(url, context, nextLoad) {
|
|
|
183
188
|
};
|
|
184
189
|
}
|
|
185
190
|
|
|
186
|
-
const isRN =
|
|
191
|
+
const isRN = REACT_NATIVE_PATH.test(norm);
|
|
187
192
|
if (!isRN && !isExtra(norm)) return nextLoad(url, context);
|
|
188
193
|
|
|
189
194
|
if (isRN) {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Any file under a node_modules directory. */
|
|
2
|
+
export declare const NODE_MODULES_PATH: RegExp;
|
|
3
|
+
|
|
4
|
+
/** React Native's own source, including the `@react-native/*` packages. */
|
|
5
|
+
export declare const REACT_NATIVE_PATH: RegExp;
|
|
6
|
+
|
|
7
|
+
/** Does `dir` contain `target` (or equal it)? Case-insensitive on Windows. */
|
|
8
|
+
export declare function containsPath(dir: string, target: string): boolean;
|
|
9
|
+
|
|
10
|
+
/** The on-disk directory a package resolves to from `projectRoot`, or null. */
|
|
11
|
+
export declare function packageDirOf(name: string, projectRoot: string): string | null;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The patterns identifying one package's files: under `node_modules/<name>/`, and
|
|
15
|
+
* inside the directory it resolves to. The second is omitted when that directory
|
|
16
|
+
* contains `projectRoot` — the project is not one of its own dependencies.
|
|
17
|
+
*/
|
|
18
|
+
export declare function packagePatterns(name: string, projectRoot?: string): RegExp[];
|
|
19
|
+
|
|
20
|
+
/** A predicate over `packagePatterns` for every named package. */
|
|
21
|
+
export declare function buildPkgMatcher(
|
|
22
|
+
pkgs: string[] | undefined,
|
|
23
|
+
projectRoot?: string,
|
|
24
|
+
): (file: string) => boolean;
|
|
25
|
+
|
|
26
|
+
/** The bare package name of an import specifier. */
|
|
27
|
+
export declare function packageNameOf(specifier: string): string;
|
|
28
|
+
|
|
29
|
+
/** The leaf module name a subpath import points at, or null. */
|
|
30
|
+
export declare function subpathLeafOf(specifier: string): string | null;
|
|
31
|
+
|
|
32
|
+
/** Deep entries of preset packages that must not be shadowed by the preset mock. */
|
|
33
|
+
export declare function isUtilitySubpath(specifier: string): boolean;
|
package/dist/native/match.mjs
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which files belong to which package — the one place that decides it.
|
|
3
|
+
*
|
|
4
|
+
* The native engine splits the module graph between Vite and Node (the rule itself is
|
|
5
|
+
* written down in the header of apply.ts). Four places used to answer "does this file
|
|
6
|
+
* belong to a Node-owned package?" independently: the externalization patterns handed
|
|
7
|
+
* to Vitest, auto-detection, and the transform matchers in the require hook and the
|
|
8
|
+
* ESM loader. They agreed by construction rather than by structure, and three of the
|
|
9
|
+
* defects in this area were one of them disagreeing with the others — a directory
|
|
10
|
+
* anchor the transform side applied and the config side did not, a `node_modules`
|
|
11
|
+
* rule that also matched any folder sharing a package's name, and a separator
|
|
12
|
+
* mismatch that only appeared on Windows.
|
|
13
|
+
*
|
|
14
|
+
* Vitest's `server.deps.external` takes patterns rather than a predicate, so config
|
|
15
|
+
* time and run time cannot literally call the same function. They can be generated
|
|
16
|
+
* from the same rules, which is what `packagePatterns` is for: `buildPkgMatcher`
|
|
17
|
+
* tests exactly the patterns that were handed to Vitest.
|
|
18
|
+
*
|
|
19
|
+
* Everything here is pure. apply.ts bundles a copy into the plugin entry while the
|
|
20
|
+
* worker loads this file directly, so it must stay that way — module-level state
|
|
21
|
+
* would exist twice.
|
|
22
|
+
*/
|
|
1
23
|
import { createRequire } from "node:module";
|
|
2
24
|
import path from "node:path";
|
|
3
25
|
|
|
26
|
+
/** Any file under a node_modules directory. */
|
|
27
|
+
export const NODE_MODULES_PATH = /[\\/]node_modules[\\/]/;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* React Native's own source, including the `@react-native/*` packages. Node owns
|
|
31
|
+
* these unconditionally: the Flow strip, the boundary mocks and the precompiled
|
|
32
|
+
* registry are all Node loader hooks.
|
|
33
|
+
*/
|
|
34
|
+
export const REACT_NATIVE_PATH = /[\\/]node_modules[\\/](react-native|@react-native)[\\/]/;
|
|
35
|
+
|
|
4
36
|
/** Escape a string for literal use inside a RegExp. */
|
|
5
37
|
function escapeRe(value) {
|
|
6
38
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7
39
|
}
|
|
8
40
|
|
|
41
|
+
/** Forward slashes, the form Vitest presents module ids in. */
|
|
42
|
+
function toPosix(value) {
|
|
43
|
+
return value.replace(/\\/g, "/");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Does `dir` contain `target` (or equal it)?
|
|
48
|
+
*
|
|
49
|
+
* Used to recognise the package the run lives in. A package directory containing the
|
|
50
|
+
* Vitest root is the project, not a dependency of it — externalizing it hands Vitest
|
|
51
|
+
* its own source and test files back through Node, where they are compiled to
|
|
52
|
+
* CommonJS.
|
|
53
|
+
*
|
|
54
|
+
* Compared case-insensitively on Windows: `require.resolve` reports the on-disk
|
|
55
|
+
* casing while a working directory carries whatever the shell supplied, and a
|
|
56
|
+
* drive-letter difference alone would silently defeat the check.
|
|
57
|
+
*/
|
|
58
|
+
export function containsPath(dir, target) {
|
|
59
|
+
const normalize = (value) => {
|
|
60
|
+
const resolved = path.resolve(value);
|
|
61
|
+
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
|
|
62
|
+
};
|
|
63
|
+
const outer = normalize(dir);
|
|
64
|
+
const inner = normalize(target);
|
|
65
|
+
return inner === outer || inner.startsWith(outer.endsWith(path.sep) ? outer : outer + path.sep);
|
|
66
|
+
}
|
|
67
|
+
|
|
9
68
|
/**
|
|
10
69
|
* The on-disk directory a package resolves to, or null.
|
|
11
70
|
*
|
|
@@ -14,7 +73,7 @@ function escapeRe(value) {
|
|
|
14
73
|
* the manifest that names them. Symlinked and workspace packages resolve to their
|
|
15
74
|
* real location, which is the whole point — see buildPkgMatcher.
|
|
16
75
|
*/
|
|
17
|
-
function packageDirOf(name, projectRoot) {
|
|
76
|
+
export function packageDirOf(name, projectRoot) {
|
|
18
77
|
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
19
78
|
try {
|
|
20
79
|
return path.dirname(req.resolve(`${name}/package.json`));
|
|
@@ -36,9 +95,9 @@ function packageDirOf(name, projectRoot) {
|
|
|
36
95
|
}
|
|
37
96
|
|
|
38
97
|
/**
|
|
39
|
-
*
|
|
98
|
+
* The patterns identifying one package's files. THE rule; everything else composes it.
|
|
40
99
|
*
|
|
41
|
-
* A bare `[/\]name[/\]` test — what this used to
|
|
100
|
+
* A bare `[/\]name[/\]` test — what this used to be — also matches any DIRECTORY
|
|
42
101
|
* that happens to share a package's name. A project folder called `expo`, or a source
|
|
43
102
|
* directory named after the library it implements, made every file beneath it look
|
|
44
103
|
* like third-party source to be compiled. That mis-compiled unrelated files, this
|
|
@@ -48,29 +107,42 @@ function packageDirOf(name, projectRoot) {
|
|
|
48
107
|
* workspace or `file:` dependency resolves to its real path, which has no
|
|
49
108
|
* `node_modules` segment at all. So a file matches if it is either
|
|
50
109
|
*
|
|
110
|
+
* - under `node_modules/<name>/` (covers additional copies of a package that a
|
|
111
|
+
* single resolution cannot see, and projects where resolution fails), or
|
|
51
112
|
* - inside the package's resolved directory (exact; covers workspace links, and
|
|
52
|
-
* stores like pnpm's and bun's)
|
|
53
|
-
*
|
|
54
|
-
*
|
|
113
|
+
* stores like pnpm's and bun's).
|
|
114
|
+
*
|
|
115
|
+
* The resolved-directory anchor is dropped when that directory CONTAINS the project
|
|
116
|
+
* root, because then it is the project. Externalizing the project hands Vitest its
|
|
117
|
+
* own source and test files back through Node, which compiles them to CommonJS: a
|
|
118
|
+
* test file's `import { it } from 'vitest'` becomes `require('vitest')` and throws.
|
|
55
119
|
*
|
|
56
|
-
* `projectRoot` is optional
|
|
57
|
-
*
|
|
120
|
+
* `projectRoot` is optional; without it only the `node_modules` rule applies, since
|
|
121
|
+
* there is nothing to resolve against.
|
|
58
122
|
*/
|
|
59
|
-
export function
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
if (projectRoot) {
|
|
64
|
-
|
|
65
|
-
const dir = packageDirOf(name, projectRoot);
|
|
66
|
-
if (dir) dirs.push(dir.replace(/\\/g, "/").replace(/\/$/, "") + "/");
|
|
67
|
-
}
|
|
123
|
+
export function packagePatterns(name, projectRoot) {
|
|
124
|
+
const patterns = [new RegExp(`[\\\\/]node_modules[\\\\/]${escapeRe(name)}[\\\\/]`)];
|
|
125
|
+
if (!projectRoot) return patterns;
|
|
126
|
+
const dir = packageDirOf(name, projectRoot);
|
|
127
|
+
if (dir && !containsPath(dir, projectRoot)) {
|
|
128
|
+
patterns.push(new RegExp(`^${escapeRe(toPosix(dir).replace(/\/$/, ""))}[\\\\/]`));
|
|
68
129
|
}
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
130
|
+
return patterns;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A predicate over the same patterns Vitest is given, so what the loader transforms
|
|
135
|
+
* and what Vitest externalizes cannot drift apart.
|
|
136
|
+
*
|
|
137
|
+
* Paths are normalised before testing: the directory anchor is written with forward
|
|
138
|
+
* slashes (the form Vitest presents module ids in) while callers here pass whatever
|
|
139
|
+
* Node handed them, which on Windows is backslashes.
|
|
140
|
+
*/
|
|
141
|
+
export function buildPkgMatcher(pkgs, projectRoot) {
|
|
142
|
+
const patterns = (pkgs || []).flatMap((name) => packagePatterns(name, projectRoot));
|
|
143
|
+
return (file) => {
|
|
144
|
+
const norm = toPosix(file);
|
|
145
|
+
return patterns.some((re) => re.test(norm));
|
|
74
146
|
};
|
|
75
147
|
}
|
|
76
148
|
|
package/dist/native/registry.mjs
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
// through to the per-file hooks in hooks.mjs / loader.mjs, and a failed build leaves
|
|
27
27
|
// the engine running exactly as it did before.
|
|
28
28
|
import Module from "node:module";
|
|
29
|
+
import { REACT_NATIVE_PATH } from "./match.mjs";
|
|
29
30
|
import { createRequire } from "node:module";
|
|
30
31
|
import path from "node:path";
|
|
31
32
|
import fs from "node:fs";
|
|
@@ -83,7 +84,6 @@ export function _resetRegistryFailureReports() {
|
|
|
83
84
|
reportedRegistryFailures.clear();
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
const RN_PATH = /[\\/]node_modules[\\/](react-native|@react-native)[\\/]/;
|
|
87
87
|
// Bump when the emitted registry's shape or the walk's semantics change, so a
|
|
88
88
|
// stale on-disk registry from an older vitest-native can never be reused.
|
|
89
89
|
const REGISTRY_FORMAT_VERSION = 2;
|
|
@@ -421,6 +421,11 @@ export function buildRegistry({
|
|
|
421
421
|
const options = { projectRoot, platform, reactNativeVersion, assetExtSet };
|
|
422
422
|
const modules = new Map();
|
|
423
423
|
const manifest = [];
|
|
424
|
+
// Targets the registry does NOT inline but DOES bake in as pre-resolved absolute
|
|
425
|
+
// paths. They belong in the manifest for the same reason React Native's own files
|
|
426
|
+
// do: if one moves or changes, the paths compiled into the registry are wrong.
|
|
427
|
+
// See the note above the manifest write below.
|
|
428
|
+
const externals = new Set();
|
|
424
429
|
try {
|
|
425
430
|
const entry = createRequire(path.join(projectRoot, "package.json")).resolve("react-native");
|
|
426
431
|
const queue = [entry];
|
|
@@ -440,10 +445,11 @@ export function buildRegistry({
|
|
|
440
445
|
// identity and are shared with the rest of the worker.
|
|
441
446
|
const internal =
|
|
442
447
|
target !== null &&
|
|
443
|
-
|
|
448
|
+
REACT_NATIVE_PATH.test(target.replace(/\\/g, "/")) &&
|
|
444
449
|
!PASSTHROUGH_EXT.has(path.extname(target).toLowerCase());
|
|
445
450
|
deps[request] = target;
|
|
446
451
|
if (internal) queue.push(target);
|
|
452
|
+
else if (target !== null) externals.add(target);
|
|
447
453
|
}
|
|
448
454
|
}
|
|
449
455
|
modules.set(file, { code, deps });
|
|
@@ -451,6 +457,28 @@ export function buildRegistry({
|
|
|
451
457
|
manifest.push([file, st.mtimeMs, st.size]);
|
|
452
458
|
}
|
|
453
459
|
|
|
460
|
+
// Externals are require()d through pre-resolved absolute paths baked into the
|
|
461
|
+
// emitted registry, so the registry is only valid while those paths still point
|
|
462
|
+
// at what they pointed at when it was built. Nothing noticed when they did not:
|
|
463
|
+
// upgrading React served a registry whose baked path was a react directory that
|
|
464
|
+
// no longer existed, and the fallback produced a second React — a null dispatcher
|
|
465
|
+
// and React Native singletons that stopped comparing equal.
|
|
466
|
+
//
|
|
467
|
+
// Naming the packages in the cache key instead would work only for the ones
|
|
468
|
+
// somebody remembered to name. Statting the resolved targets covers every
|
|
469
|
+
// external there is, and covers both node_modules layouts: under bun and pnpm a
|
|
470
|
+
// version change moves the path, so the stat fails; under a flat npm or yarn tree
|
|
471
|
+
// the path survives but the file's size and mtime change.
|
|
472
|
+
for (const target of externals) {
|
|
473
|
+
try {
|
|
474
|
+
const st = fs.statSync(target);
|
|
475
|
+
manifest.push([target, st.mtimeMs, st.size]);
|
|
476
|
+
} catch {
|
|
477
|
+
// Not a real file on disk (a native addon resolved elsewhere, a virtual
|
|
478
|
+
// target). Nothing to pin; the runtime require still decides.
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
454
482
|
const files = [...modules.keys()];
|
|
455
483
|
const { code, map } = emit(files, modules);
|
|
456
484
|
// Write via a unique temp file then rename: several workers may race here on a
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_errors = require("./errors-
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
|
+
const require_errors = require("./errors-B3lJK46O.cjs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
|
-
node_path =
|
|
4
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
5
5
|
let node_module = require("node:module");
|
|
6
6
|
let node_os = require("node:os");
|
|
7
|
-
node_os =
|
|
7
|
+
node_os = require_rolldown_runtime.__toESM(node_os, 1);
|
|
8
8
|
let vitest_node = require("vitest/node");
|
|
9
9
|
//#region src/native/pool.ts
|
|
10
10
|
function deepEqual(a, b) {
|
|
@@ -62,8 +62,8 @@ var NativePoolWorker = class extends vitest_node.ThreadsPoolWorker {
|
|
|
62
62
|
return env.name === this.environment.name && deepEqual(env.options, this.environment.options);
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
-
const HOT_MEMORY_MIN_BYTES =
|
|
66
|
-
const HOT_MEMORY_MAX_BYTES =
|
|
65
|
+
const HOT_MEMORY_MIN_BYTES = 805306368;
|
|
66
|
+
const HOT_MEMORY_MAX_BYTES = 1610612736;
|
|
67
67
|
const HOT_MEMORY_FRACTION = .25;
|
|
68
68
|
/**
|
|
69
69
|
* Default per-worker hot `memoryLimit` (bytes): `clamp(totalmem * 0.25, 768MB, 1.5GB)`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as VitestNativeError } from "./errors-
|
|
1
|
+
import { t as VitestNativeError } from "./errors-CxoBUfVJ.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import os from "node:os";
|
|
@@ -59,8 +59,8 @@ var NativePoolWorker = class extends ThreadsPoolWorker {
|
|
|
59
59
|
return env.name === this.environment.name && deepEqual(env.options, this.environment.options);
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
const HOT_MEMORY_MIN_BYTES =
|
|
63
|
-
const HOT_MEMORY_MAX_BYTES =
|
|
62
|
+
const HOT_MEMORY_MIN_BYTES = 805306368;
|
|
63
|
+
const HOT_MEMORY_MAX_BYTES = 1610612736;
|
|
64
64
|
const HOT_MEMORY_FRACTION = .25;
|
|
65
65
|
/**
|
|
66
66
|
* Default per-worker hot `memoryLimit` (bytes): `clamp(totalmem * 0.25, 768MB, 1.5GB)`.
|
|
@@ -18,6 +18,7 @@ const AUTO_DETECT_PRESETS = {
|
|
|
18
18
|
"expo-constants": "expo",
|
|
19
19
|
"react-native-device-info": "deviceInfo",
|
|
20
20
|
"react-native-mmkv": "mmkv",
|
|
21
|
+
"@react-native-community/netinfo": "netInfo",
|
|
21
22
|
"react-native-svg": "svg",
|
|
22
23
|
"react-native-webview": "webview",
|
|
23
24
|
"@react-native-vector-icons/common": "vectorIcons",
|
|
@@ -18,6 +18,7 @@ const AUTO_DETECT_PRESETS = {
|
|
|
18
18
|
"expo-constants": "expo",
|
|
19
19
|
"react-native-device-info": "deviceInfo",
|
|
20
20
|
"react-native-mmkv": "mmkv",
|
|
21
|
+
"@react-native-community/netinfo": "netInfo",
|
|
21
22
|
"react-native-svg": "svg",
|
|
22
23
|
"react-native-webview": "webview",
|
|
23
24
|
"@react-native-vector-icons/common": "vectorIcons",
|