Skip to content

Commit 8dc8283

Browse files
committed
throw when a module is unreadable so that the cli frontend can format it in a nice way that doesn't disrupt the in-place progress spinner
1 parent 1c88903 commit 8dc8283

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

packages/react-native-node-api-modules/src/node/path-utils.test.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,15 @@ describe("isNodeApiModule", () => {
4141
}
4242
});
4343

44-
it("returns false when module file exists but is not readable", (context) => {
44+
it("throws when module file exists but is not readable", (context) => {
4545
const tempDirectoryPath = setupTempDirectory(context, {
4646
"addon.android.node": "",
4747
});
4848
const candidate = path.join(tempDirectoryPath, "addon.android.node");
4949
// remove read permission on file
5050
fs.chmodSync(candidate, 0);
5151
try {
52-
assert.equal(
53-
isNodeApiModule(path.join(tempDirectoryPath, "addon")),
54-
false
55-
);
52+
assert.throws(() => isNodeApiModule(path.join(tempDirectoryPath, "addon")), /skipping unreadable module addon\.android\.node/);
5653
} finally {
5754
fs.chmodSync(candidate, 0o600);
5855
}
@@ -76,19 +73,15 @@ describe("isNodeApiModule", () => {
7673
assert.equal(isNodeApiModule(path.join(tempDirectoryPath, "nope")), false);
7774
});
7875

79-
it("returns true and warns when one module unreadable but another readable", (context) => {
76+
it("throws when one module unreadable but another readable", (context) => {
8077
const tempDirectoryPath = setupTempDirectory(context, {
8178
"addon.android.node": "",
8279
"addon.xcframework": "",
8380
});
8481
const unreadable = path.join(tempDirectoryPath, "addon.android.node");
8582
// only android module is unreadable
8683
fs.chmodSync(unreadable, 0);
87-
const warnings: string[] = [];
88-
themock.method(console, 'warn', (msg: string) => warnings.push(msg));
89-
const result = isNodeApiModule(path.join(tempDirectoryPath, "addon"));
90-
assert.equal(result, true);
91-
assert.deepEqual(warnings, ["skipping unreadable module addon.android.node"]);
84+
assert.throws(() => isNodeApiModule(path.join(tempDirectoryPath, "addon")), /skipping unreadable module addon\.android\.node/);
9285
fs.chmodSync(unreadable, 0o600);
9386
});
9487
});

packages/react-native-node-api-modules/src/node/path-utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export type NamingStrategy = {
2626
const packageNameCache = new Map<string, string>();
2727

2828
/**
29-
* @param modulePath The path to the module to check (must be extensionless or end in .node)
30-
* @returns True if a platform specific prebuild exists for the module path.
29+
* @param modulePath Batch-scans the path to the module to check (must be extensionless or end in .node)
30+
* @returns True if a platform specific prebuild exists for the module path, warns on unreadable modules.
31+
* @throws If the parent directory cannot be read, or if a detected module is unreadable.
3132
* TODO: Consider checking for a specific platform extension.
3233
*/
3334
export function isNodeApiModule(modulePath: string): boolean {
34-
// Batch-scan directory, warn on unreadable modules, and detect accessible ones
3535
const dir = path.dirname(modulePath);
3636
const baseName = path.basename(modulePath, ".node");
3737
let entries: string[];
@@ -50,7 +50,7 @@ export function isNodeApiModule(modulePath: string): boolean {
5050
fs.accessSync(path.join(dir, fileName), fs.constants.R_OK);
5151
hasReadable = true;
5252
} catch {
53-
console.warn("skipping unreadable module " + fileName);
53+
throw new Error("skipping unreadable module " + fileName);
5454
}
5555
}
5656
return hasReadable;

0 commit comments

Comments
 (0)