Skip to content

Commit ba6a527

Browse files
authored
Log original package resolution errors (#451)
Preserve the resolver error message when dependency scanning cannot locate a package entry point. Closes #369.
1 parent c8d5b80 commit ba6a527

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-native-node-api": patch
3+
---
4+
5+
Log the original package resolution error during dependency scanning so invalid package entry points include the missing path.

‎packages/host/src/node/path-utils.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import assert from "node:assert/strict";
22
import { describe, it } from "node:test";
33
import path from "node:path";
44
import fs from "node:fs";
5+
import { createRequire } from "node:module";
56
import fswin from "fswin";
67

78
import {
89
determineModuleContext,
910
findNodeApiModulePaths,
1011
findNodeAddonForBindings,
1112
findPackageDependencyPaths,
13+
resolvePackageRoot,
1214
getLibraryName,
1315
isNodeApiModule,
1416
stripExtension,
@@ -355,6 +357,34 @@ describe("findPackageDependencyPaths", () => {
355357
});
356358
});
357359

360+
describe("resolvePackageRoot", () => {
361+
it("logs the original package resolution error", (context) => {
362+
const tempDir = setupTempDirectory(context, {
363+
"node_modules/broken-package/package.json": JSON.stringify({
364+
name: "broken-package",
365+
main: "missing.js",
366+
}),
367+
});
368+
const requireFromRoot = createRequire(path.join(tempDir, "noop.js"));
369+
const debug = context.mock.method(console, "debug", () => {});
370+
371+
assert.equal(
372+
resolvePackageRoot(requireFromRoot, "broken-package"),
373+
undefined,
374+
);
375+
assert.equal(debug.mock.callCount(), 1);
376+
377+
const call = debug.mock.calls[0];
378+
assert(call);
379+
assert.equal(call.arguments.length, 1);
380+
assert.equal(typeof call.arguments[0], "string");
381+
assert.match(
382+
String(call.arguments[0]),
383+
/Failed to resolve package root for "broken-package": Cannot find module .*broken-package[\\/]missing\.js/,
384+
);
385+
});
386+
});
387+
358388
describe("findNodeApiModulePaths", () => {
359389
it("should find .apple.node paths", async (context) => {
360390
const tempDir = setupTempDirectory(context, {

‎packages/host/src/node/path-utils.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,11 @@ export function resolvePackageRoot(
260260
try {
261261
const resolvedPath = requireFromPackageRoot.resolve(packageName);
262262
return packageDirectorySync({ cwd: resolvedPath });
263-
} catch {
264-
// TODO: Add a debug log here
263+
} catch (error) {
264+
const message = error instanceof Error ? error.message : String(error);
265+
console.debug(
266+
`Failed to resolve package root for "${packageName}": ${message}`,
267+
);
265268
return undefined;
266269
}
267270
}

0 commit comments

Comments
 (0)