@@ -81,13 +81,15 @@ describe("resolveNpmDependencies", () => {
8181 pkgid : `${ child1Name } @${ child1Version } ` ,
8282 realpath : child1Realpath ,
8383 package : { name : child1Name , version : child1Version } ,
84+ name : child1Name ,
8485 children : new Map ( [
8586 [
8687 child1_1Name ,
8788 {
8889 pkgid : `${ child1_1Name } @${ child1_1Version } ` ,
8990 realpath : child1_1Realpath ,
9091 package : { name : child1_1Name , version : child1_1Version } ,
92+ name : child1_1Name ,
9193 children : new Map ( ) ,
9294 dev : false ,
9395 peer : false ,
@@ -99,6 +101,7 @@ describe("resolveNpmDependencies", () => {
99101 pkgid : `${ child1_2Name } @${ child1_2Version } ` ,
100102 realpath : child1_2Realpath ,
101103 package : { name : child1_2Name , version : child1_2Version } ,
104+ name : child1_2Name ,
102105 children : new Map ( ) ,
103106 dev : false ,
104107 peer : false ,
@@ -115,13 +118,15 @@ describe("resolveNpmDependencies", () => {
115118 pkgid : `${ child2Name } @${ child2Version } ` ,
116119 realpath : child2Realpath ,
117120 package : { name : child2Name , version : child2Version } ,
121+ name : child2Name ,
118122 children : new Map ( [
119123 [
120124 child2_1Name ,
121125 {
122126 pkgid : `${ child2_1Name } @${ child2_1Version } ` ,
123127 realpath : child2_1Realpath ,
124128 package : { name : child2_1Name , version : child2_1Version } ,
129+ name : child2_1Name ,
125130 children : new Map ( ) ,
126131 dev : false ,
127132 peer : false ,
@@ -138,13 +143,15 @@ describe("resolveNpmDependencies", () => {
138143 pkgid : `${ child3Name } @${ child3Version } ` ,
139144 realpath : child3Realpath ,
140145 package : { name : child3Name , version : child3Version } ,
146+ name : child3Name ,
141147 children : new Map ( [
142148 [
143149 child3_1Name ,
144150 {
145151 pkgid : `${ child3_1Name } @${ child3_1Version } ` ,
146152 realpath : child3_1Realpath ,
147153 package : { name : child3_1Name , version : child3_1Version } ,
154+ name : child3_1Name ,
148155 children : new Map ( ) ,
149156 dev : false ,
150157 peer : false ,
@@ -340,6 +347,7 @@ describe("resolveNpmDependencies", () => {
340347 pkgid : `${ optionalName } @${ optionalVersion } ` ,
341348 realpath : optionalRealpath ,
342349 package : { name : optionalName , version : optionalVersion } ,
350+ name : optionalName ,
343351 children : new Map ( ) ,
344352 dev : false ,
345353 peer : false ,
@@ -382,6 +390,7 @@ describe("resolveNpmDependencies", () => {
382390 pkgid : `${ missingName } @${ missingVersion } ` ,
383391 realpath : missingRealpath ,
384392 package : { name : missingName , version : missingVersion } ,
393+ name : missingName ,
385394 children : new Map ( ) ,
386395 dev : false ,
387396 peer : false ,
@@ -448,6 +457,49 @@ describe("resolveNpmDependencies", () => {
448457 ) . toBeDefined ( ) ;
449458 } ) ;
450459 } ) ;
460+ describe ( "when a directory inside node_modules starts with '.'" , ( ) => {
461+ const dotDirName = ".dotdir" ;
462+ const dotDirVersion = "0.0.0" ;
463+ const dotDirRealpath = "/some/path/.dotdir" ;
464+
465+ it ( "should skip it without attempting to read its package.json" , async ( ) => {
466+ const licensesMap = new Map < LicenseNoticeKey , ResolvedLicense > ( ) ;
467+
468+ const dotDirNode = {
469+ pkgid : `${ dotDirName } @${ dotDirVersion } ` ,
470+ realpath : dotDirRealpath ,
471+ package : { name : dotDirName , version : dotDirVersion } ,
472+ name : dotDirName ,
473+ children : new Map ( ) ,
474+ dev : false ,
475+ peer : false ,
476+ optional : true ,
477+ } as unknown as Arborist . Node ;
478+
479+ const topNodeWithDotName : Arborist . Node = {
480+ children : new Map ( [
481+ ...Array . from ( topNode . children . entries ( ) ) ,
482+ [ dotDirName , dotDirNode as unknown as Arborist . Node ] ,
483+ ] ) ,
484+ } as Arborist . Node ;
485+
486+ mockedArborist . mockImplementationOnce (
487+ ( ) => ( { loadActual : async ( ) => topNodeWithDotName } ) as Arborist ,
488+ ) ;
489+
490+ await resolveDependenciesForNpmProject ( "/some/path/package.json" , licensesMap ) ;
491+
492+ const keys = Array . from ( licensesMap . keys ( ) ) ;
493+ expect ( keys . some ( k => k . includes ( dotDirName ) ) ) . toBe ( false ) ;
494+ expect (
495+ mockedDoesFileExist . mock . calls . some ( call => ( call [ 0 ] as string ) . includes ( dotDirRealpath ) ) ,
496+ ) . toBe ( false ) ;
497+ expect (
498+ mockedReadFile . mock . calls . some ( call => ( call [ 0 ] as string ) . includes ( dotDirRealpath ) ) ,
499+ ) . toBe ( false ) ;
500+ expect ( mockedLogger . warn ) . not . toHaveBeenCalled ( ) ;
501+ } ) ;
502+ } ) ;
451503
452504 const setUpPackageJson = ( directory : string , name : string , version : string ) : void => {
453505 const fullPackageJsonPath = join ( directory , "package.json" ) ;
0 commit comments