Skip to content

Commit a0cc8ae

Browse files
committed
fix: match Node addon resolution extensions
1 parent 7e212f5 commit a0cc8ae

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ describe("isNodeApiModule", () => {
6464
assert(isNodeApiModule(path.join(tempDirectoryPath, "addon.node")));
6565
});
6666

67+
it("does not treat .cjs or .mjs files as shadowing .node", (context) => {
68+
const tempDirectoryPath = setupTempDirectory(context, {
69+
"cjs-addon.cjs": "// Some CommonJS file",
70+
"cjs-addon.node": "// This is supposed to be a binary file",
71+
"mjs-addon.mjs": "// Some ES module file",
72+
"mjs-addon.node": "// This is supposed to be a binary file",
73+
});
74+
75+
assert(isNodeApiModule(path.join(tempDirectoryPath, "cjs-addon")));
76+
assert(isNodeApiModule(path.join(tempDirectoryPath, "mjs-addon")));
77+
});
78+
6779
it(
6880
"returns false when directory cannot be read due to permissions",
6981
// Skipping on Windows because there is no way to set ACLs on directories in Node.js on Windows without brittle powershell commands

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export type NamingStrategy = {
6060
const packageNameCache = new Map<string, string>();
6161

6262
// Extensions Node's own require() resolves before ever trying `.node`.
63-
const COLLIDING_SOURCE_EXTENSIONS = [".js", ".cjs", ".mjs", ".json"];
63+
const COLLIDING_SOURCE_EXTENSIONS = [".js", ".json"];
6464

6565
/**
6666
* @param modulePath Batch-scans the path to the module to check (must be extensionless or end in .node)

0 commit comments

Comments
 (0)