Skip to content

Commit b91761a

Browse files
kraenhansenclaude
andauthored
fix(node-tests): declare assert dependency, fail bundling on unresolved imports (#385)
* fix(node-tests): declare assert dependency and fail bundling on unresolved imports The bundled Node.js test for 2_function_arguments requires 'assert', which was previously satisfied as a phantom dependency: npm workspaces hoisted node-addon-examples' assert@2.1.0 ponyfill to the root node_modules, where rolldown resolved and inlined it. Under pnpm's strict node_modules layout the package is no longer reachable from node-tests, so rolldown silently kept a runtime __require("assert") call in the bundle (UNRESOLVED_IMPORT is only a warning), which then fails at runtime on device where Metro cannot resolve it. The failure surfaced as the masked 'test.titlePath(...).forEach is not a function' error, a secondary crash in mocha-remote-server's failure formatter. Declaring assert as a dependency of node-tests lets rolldown inline it again. Also make the bundle step fail hard on unresolved imports, so any future phantom dependency breaks bootstrap loudly instead of failing masked on-device. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MBr6N8caYidCuijvV5ak2A * ci: trigger label-gated jobs Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MBr6N8caYidCuijvV5ak2A --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d08da9c commit b91761a

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

packages/node-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"bootstrap": "node --run copy-tests && node --run gyp-to-cmake && node --run build-tests && node --run bundle && node --run generate-entrypoint"
2727
},
2828
"devDependencies": {
29+
"assert": "^2.1.0",
2930
"cmake-rn": "workspace:*",
3031
"gyp-to-cmake": "workspace:*",
3132
"react-native-node-api": "workspace:*",

packages/node-tests/rolldown.config.mts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ function readGypTargetNames(gypFilePath: string): string[] {
2323
});
2424
}
2525

26+
/**
27+
* Fail the build on unresolved imports instead of emitting a warning:
28+
* Anything the bundle can't resolve (besides the addons declared as external)
29+
* would otherwise only fail at runtime on device, where Metro's runtime require
30+
* masks the underlying error.
31+
*/
32+
function failOnUnresolvedImports(
33+
warning: Parameters<NonNullable<RolldownOptions["onwarn"]>>[0],
34+
defaultHandler: Parameters<NonNullable<RolldownOptions["onwarn"]>>[1],
35+
) {
36+
if (warning.code === "UNRESOLVED_IMPORT") {
37+
throw new Error(
38+
`Unresolved import: ${warning.message} - add the package as a dependency of @react-native-node-api/node-tests`,
39+
);
40+
}
41+
defaultHandler(warning);
42+
}
43+
2644
function testSuiteConfig(suitePath: string): RolldownOptions[] {
2745
const testFiles = fs.globSync("*.js", {
2846
cwd: suitePath,
@@ -32,6 +50,7 @@ function testSuiteConfig(suitePath: string): RolldownOptions[] {
3250
const targetNames = readGypTargetNames(gypFilePath);
3351
return testFiles.map((testFile) => ({
3452
input: path.join(suitePath, testFile),
53+
onwarn: failOnUnresolvedImports,
3554
output: {
3655
file: path.join(suitePath, path.basename(testFile, ".js") + ".bundle.js"),
3756
},

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)