File tree Expand file tree Collapse file tree 1 file changed +22
-9
lines changed
packages/react-native-node-api-modules/src/node Expand file tree Collapse file tree 1 file changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -53,22 +53,35 @@ export function isNodeApiModule(modulePath: string): boolean {
5353 fs . accessSync ( filePath , fs . constants . F_OK ) ;
5454
5555 // 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- const fd = fs . openSync ( filePath , 'r' ) ;
59- fs . closeSync ( fd ) ;
60- return true ;
61- } else {
62- // On Unix-like systems, we can use R_OK to check read permissions
63- fs . accessSync ( filePath , fs . constants . R_OK ) ;
64- return true ;
56+ if ( ! isReadableSync ( filePath ) ) {
57+ throw new Error ( `Found an unreadable module ${ fileName } ` ) ;
6558 }
6659 } catch ( e ) {
6760 throw new Error ( `Found an unreadable module ${ fileName } : ${ e } ` ) ;
6861 }
62+ return true ;
6963 } ) ;
7064}
7165
66+ /**
67+ * Check if a path is readable according to permission bits.
68+ * On Windows, tests store POSIX S_IWUSR bit in stats.mode.
69+ * On Unix-like, uses fs.accessSync for R_OK.
70+ */
71+ function isReadableSync ( p : string ) : boolean {
72+ try {
73+ if ( process . platform === "win32" ) {
74+ const stats = fs . statSync ( p ) ;
75+ return ! ! ( stats . mode & fs . constants . S_IWUSR ) ;
76+ } else {
77+ fs . accessSync ( p , fs . constants . R_OK ) ;
78+ return true ;
79+ }
80+ } catch {
81+ return false ;
82+ }
83+ }
84+
7285/**
7386 * Strip of any platform specific extensions from a module path.
7487 */
You can’t perform that action at this time.
0 commit comments