@@ -12,6 +12,7 @@ import {
12
12
getLibraryName ,
13
13
isNodeApiModule ,
14
14
stripExtension ,
15
+ findNodeApiModulePathsByDependency ,
15
16
} from "./path-utils.js" ;
16
17
import { setupTempDirectory } from "./test-utils.js" ;
17
18
@@ -62,9 +63,9 @@ describe("isNodeApiModule", () => {
62
63
assert ( isNodeApiModule ( path . join ( tempDirectoryPath , "addon.node" ) ) ) ;
63
64
} ) ;
64
65
65
- // there is no way to set ACLs on directories in Node.js on Windows with brittle powershell commands
66
66
it (
67
67
"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
68
69
{ skip : process . platform === "win32" } ,
69
70
( context ) => {
70
71
const tempDirectoryPath = setupTempDirectory ( context , {
@@ -268,24 +269,30 @@ describe("getLibraryName", () => {
268
269
describe ( "findPackageDependencyPaths" , ( ) => {
269
270
it ( "should find package dependency paths" , ( context ) => {
270
271
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" : "" ,
286
294
} ,
287
- } ) ,
288
- "test-package/src/index.js" : "console.log('Hello, world!')" ,
295
+ } ,
289
296
} ) ;
290
297
291
298
const result = findPackageDependencyPaths (
@@ -367,6 +374,72 @@ describe("findNodeApiModulePaths", () => {
367
374
path . join ( tempDir , "node_modules/root.apple.node" ) ,
368
375
] ) ;
369
376
} ) ;
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
+ } ) ;
370
443
} ) ;
371
444
372
445
describe ( "determineModuleContext" , ( ) => {
0 commit comments