vitest-native 0.6.0 → 0.6.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 +10 -0
- package/dist/native/loader.mjs +25 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# vitest-native
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 40a5147: Native engine: fix `import { Appearance } from 'react-native'` (and other lazy-getter RN exports) failing with "does not provide an export named …" when the import comes from an **externalized ESM dependency**.
|
|
8
|
+
|
|
9
|
+
React Native's index exposes everything via lazy getters (`module.exports = { get Appearance() {…} }`), which `cjs-module-lexer` can't surface as named exports when Node imports the CommonJS module from the ESM graph. The Node ESM loader now serves RN's main index as a thin re-export of the real (Flow-stripped) module plus a `cjs-module-lexer`-recognized export hint, so named imports resolve while the real getters stay lazy (no eager load of RN's surface). The `require('react-native')` path is unchanged.
|
|
10
|
+
|
|
11
|
+
Previously this needed a manual `transform: ['the-lib']` workaround (e.g. for `uniwind`); that's no longer required. Surfaced by the obytes-template bake-off.
|
|
12
|
+
|
|
3
13
|
## 0.6.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/dist/native/loader.mjs
CHANGED
|
@@ -9,6 +9,8 @@ import { resolvePlatformFile } from "./resolve.mjs";
|
|
|
9
9
|
import { buildPkgMatcher } from "./match.mjs";
|
|
10
10
|
|
|
11
11
|
const RN_PATH = /[\\/](react-native|@react-native)[\\/]/;
|
|
12
|
+
// React Native's main entry (`react-native/index.js`).
|
|
13
|
+
const RN_INDEX = /[\\/]react-native[\\/]index\.js$/;
|
|
12
14
|
const TRANSFORMABLE = /\.(jsx?|tsx?|mjs|cjs)$/;
|
|
13
15
|
// Extensions/index candidates for bundler-style extensionless resolution.
|
|
14
16
|
const RESOLVE_EXTS = [".js", ".cjs", ".mjs", ".json", ".jsx", ".ts", ".tsx"];
|
|
@@ -109,6 +111,29 @@ export async function load(url, context, nextLoad) {
|
|
|
109
111
|
if (!isRN && !isExtra(norm)) return nextLoad(url, context);
|
|
110
112
|
|
|
111
113
|
if (isRN) {
|
|
114
|
+
// RN's main index exports everything via lazy getters (`module.exports = {
|
|
115
|
+
// get Appearance() {…}, … }`). When Node imports that CommonJS module from an
|
|
116
|
+
// externalized ESM lib, cjs-module-lexer can't see getter exports, so
|
|
117
|
+
// `import { Appearance } from 'react-native'` throws "does not provide an
|
|
118
|
+
// export named 'Appearance'". Serve a thin CJS re-export of the real
|
|
119
|
+
// (Flow-stripped) index, plus a dead `0 && (module.exports = { … })` hint that
|
|
120
|
+
// cjs-module-lexer DOES recognize — so Node sees the named exports while the
|
|
121
|
+
// real getters stay lazy (no eager load of RN's whole surface). The require()
|
|
122
|
+
// of react-native here goes through the separate Module._extensions hook
|
|
123
|
+
// (hooks.mjs), not this loader, so there's no recursion. Names come from the
|
|
124
|
+
// index's own `get X()` declarations.
|
|
125
|
+
if (RN_INDEX.test(norm)) {
|
|
126
|
+
const src = fs.readFileSync(file, "utf8");
|
|
127
|
+
const names = [
|
|
128
|
+
...new Set([...src.matchAll(/\bget\s+([A-Za-z_$][\w$]*)\s*\(/g)].map((m) => m[1])),
|
|
129
|
+
].filter((n) => n !== "default" && n !== "__esModule");
|
|
130
|
+
const facade = [
|
|
131
|
+
`const { createRequire } = require("node:module");`,
|
|
132
|
+
`module.exports = createRequire(${JSON.stringify(url)})(${JSON.stringify(file)});`,
|
|
133
|
+
`0 && (module.exports = { ${names.join(", ")} });`,
|
|
134
|
+
].join("\n");
|
|
135
|
+
return { format: "commonjs", source: facade, shortCircuit: true };
|
|
136
|
+
}
|
|
112
137
|
const boundary = boundarySourceFor(norm, PLATFORM, REACT_NATIVE_VERSION);
|
|
113
138
|
if (boundary != null) return { format: "commonjs", source: boundary, shortCircuit: true };
|
|
114
139
|
if (norm.endsWith(".js")) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-native",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Run real React Native tests under Vitest. One install, zero config.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -161,6 +161,7 @@
|
|
|
161
161
|
"@vitest/coverage-v8": "4.1.8",
|
|
162
162
|
"expo-constants": "56.0.16",
|
|
163
163
|
"expo-status-bar": "56.0.4",
|
|
164
|
+
"ext-rn-named-lib": "file:./tests-native/fixtures/ext-rn-named-lib",
|
|
164
165
|
"react": "^19.2.3",
|
|
165
166
|
"react-native": "^0.85.3",
|
|
166
167
|
"react-native-gesture-handler": "3.0.0",
|