Skip to content

Commit 8688728

Browse files
committed
permissions on win32 is annoyingly tricky
1 parent ad9fb3b commit 8688728

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,30 @@ export function isNodeApiModule(modulePath: string): boolean {
4545
if (!entries.includes(fileName)) {
4646
return false;
4747
}
48+
49+
const filePath = path.join(dir, fileName);
50+
4851
try {
49-
fs.accessSync(path.join(dir, fileName), fs.constants.R_OK);
50-
return true;
51-
} catch (cause) {
52-
throw new Error(`Found an unreadable module ${fileName}: ${cause}`);
52+
// First, check if file exists (works the same on all platforms)
53+
fs.accessSync(filePath, fs.constants.F_OK);
54+
55+
// Then check if it's readable (behavior differs by platform)
56+
if (process.platform === 'win32') {
57+
// On Windows, we need to try to open the file to check read permissions
58+
try {
59+
const fd = fs.openSync(filePath, 'r');
60+
fs.closeSync(fd);
61+
return true;
62+
} catch (e) {
63+
throw new Error(`Found an unreadable module ${fileName}: ${e}`);
64+
}
65+
} else {
66+
// On Unix-like systems, we can use R_OK to check read permissions
67+
fs.accessSync(filePath, fs.constants.R_OK);
68+
return true;
69+
}
70+
} catch (e) {
71+
throw new Error(`Found an unreadable module ${fileName}: ${e}`);
5372
}
5473
});
5574
}

0 commit comments

Comments
 (0)