@@ -12,6 +12,7 @@ import {
1212 getLibraryName ,
1313 isNodeApiModule ,
1414 stripExtension ,
15+ findNodeApiModulePathsByDependency ,
1516} from "./path-utils.js" ;
1617import { setupTempDirectory } from "./test-utils.js" ;
1718
@@ -62,9 +63,9 @@ describe("isNodeApiModule", () => {
6263 assert ( isNodeApiModule ( path . join ( tempDirectoryPath , "addon.node" ) ) ) ;
6364 } ) ;
6465
65- // there is no way to set ACLs on directories in Node.js on Windows with brittle powershell commands
6666 it (
6767 "returns false when directory cannot be read due to permissions" ,
68+ // Skipping on Windows because there is no way to set ACLs on directories in Node.js on Windows without brittle powershell commands
6869 { skip : process . platform === "win32" } ,
6970 ( context ) => {
7071 const tempDirectoryPath = setupTempDirectory ( context , {
@@ -268,24 +269,30 @@ describe("getLibraryName", () => {
268269describe ( "findPackageDependencyPaths" , ( ) => {
269270 it ( "should find package dependency paths" , ( context ) => {
270271 const tempDir = setupTempDirectory ( context , {
271- "node_modules/lib-a/package.json" : JSON . stringify ( {
272- name : "lib-a" ,
273- main : "index.js" ,
274- } ) ,
275- "node_modules/lib-a/index.js" : "" ,
276- "test-package/node_modules/lib-b/package.json" : JSON . stringify ( {
277- name : "lib-b" ,
278- main : "index.js" ,
279- } ) ,
280- "test-package/node_modules/lib-b/index.js" : "" ,
281- "test-package/package.json" : JSON . stringify ( {
282- name : "test-package" ,
283- dependencies : {
284- "lib-a" : "^1.0.0" ,
285- "lib-b" : "^1.0.0" ,
272+ "node_modules/lib-a" : {
273+ "package.json" : JSON . stringify ( {
274+ name : "lib-a" ,
275+ main : "index.js" ,
276+ } ) ,
277+ "index.js" : "" ,
278+ } ,
279+ "test-package" : {
280+ "package.json" : JSON . stringify ( {
281+ name : "test-package" ,
282+ dependencies : {
283+ "lib-a" : "^1.0.0" ,
284+ "lib-b" : "^1.0.0" ,
285+ } ,
286+ } ) ,
287+ "src/index.js" : "console.log('Hello, world!')" ,
288+ "node_modules/lib-b" : {
289+ "package.json" : JSON . stringify ( {
290+ name : "lib-b" ,
291+ main : "index.js" ,
292+ } ) ,
293+ "index.js" : "" ,
286294 } ,
287- } ) ,
288- "test-package/src/index.js" : "console.log('Hello, world!')" ,
295+ } ,
289296 } ) ;
290297
291298 const result = findPackageDependencyPaths (
@@ -367,6 +374,72 @@ describe("findNodeApiModulePaths", () => {
367374 path . join ( tempDir , "node_modules/root.apple.node" ) ,
368375 ] ) ;
369376 } ) ;
377+
378+ it (
379+ "returns empty when directory cannot be read due to permissions" ,
380+ // Skipping on Windows because there is no way to set ACLs on directories in Node.js on Windows without brittle powershell commands
381+ { skip : process . platform === "win32" } ,
382+ async ( context ) => {
383+ const tempDir = setupTempDirectory ( context , {
384+ "addon.apple.node/react-native-node-api-module" : "" ,
385+ } ) ;
386+
387+ removeReadPermissions ( tempDir ) ;
388+ try {
389+ const result = findNodeApiModulePaths ( {
390+ fromPath : tempDir ,
391+ platform : "apple" ,
392+ } ) ;
393+ assert . deepEqual ( await result , [ ] ) ;
394+ } finally {
395+ restoreReadPermissions ( tempDir ) ;
396+ }
397+ }
398+ ) ;
399+ } ) ;
400+
401+ describe ( "findNodeApiModulePathsByDependency" , ( ) => {
402+ it . only ( "should find Node-API paths by dependency (excluding certain packages)" , async ( context ) => {
403+ const packagesNames = [ "lib-a" , "lib-b" , "lib-c" ] ;
404+ const tempDir = setupTempDirectory ( context , {
405+ "app/package.json" : JSON . stringify ( {
406+ name : "app" ,
407+ dependencies : Object . fromEntries (
408+ packagesNames . map ( ( packageName ) => [ packageName , "^1.0.0" ] )
409+ ) ,
410+ } ) ,
411+ ...Object . fromEntries (
412+ packagesNames . map ( ( packageName ) => [
413+ `app/node_modules/${ packageName } ` ,
414+ {
415+ "package.json" : JSON . stringify ( {
416+ name : packageName ,
417+ main : "index.js" ,
418+ } ) ,
419+ "index.js" : "" ,
420+ "addon.apple.node/react-native-node-api-module" : "" ,
421+ } ,
422+ ] )
423+ ) ,
424+ } ) ;
425+
426+ const result = await findNodeApiModulePathsByDependency ( {
427+ fromPath : path . join ( tempDir , "app" ) ,
428+ platform : "apple" ,
429+ includeSelf : false ,
430+ excludePackages : [ "lib-a" ] ,
431+ } ) ;
432+ assert . deepEqual ( result , {
433+ "lib-b" : {
434+ path : path . join ( tempDir , "app/node_modules/lib-b" ) ,
435+ modulePaths : [ "addon.apple.node" ] ,
436+ } ,
437+ "lib-c" : {
438+ path : path . join ( tempDir , "app/node_modules/lib-c" ) ,
439+ modulePaths : [ "addon.apple.node" ] ,
440+ } ,
441+ } ) ;
442+ } ) ;
370443} ) ;
371444
372445describe ( "determineModuleContext" , ( ) => {
0 commit comments