@@ -66,6 +66,10 @@ describe("resolveNpmDependencies", () => {
6666 const child3_1LicenseContent = "license contents for child3.1" ;
6767 const child3_1LicenseNoticePair : LicenseNoticeKey = `${ child3_1LicenseContent } :` ;
6868
69+ const dotDirName = ".dotdir" ;
70+ const dotDirVersion = "0.0.0" ;
71+ const dotDirRealpath = "/some/path/.dotdir" ;
72+
6973 // A node tree where:
7074 // - child1 is a 'normal' dependency
7175 // - It has two 'normal' dependencies
@@ -81,13 +85,15 @@ describe("resolveNpmDependencies", () => {
8185 pkgid : `${ child1Name } @${ child1Version } ` ,
8286 realpath : child1Realpath ,
8387 package : { name : child1Name , version : child1Version } ,
88+ name : child1Name ,
8489 children : new Map ( [
8590 [
8691 child1_1Name ,
8792 {
8893 pkgid : `${ child1_1Name } @${ child1_1Version } ` ,
8994 realpath : child1_1Realpath ,
9095 package : { name : child1_1Name , version : child1_1Version } ,
96+ name : child1_1Name ,
9197 children : new Map ( ) ,
9298 dev : false ,
9399 peer : false ,
@@ -99,6 +105,7 @@ describe("resolveNpmDependencies", () => {
99105 pkgid : `${ child1_2Name } @${ child1_2Version } ` ,
100106 realpath : child1_2Realpath ,
101107 package : { name : child1_2Name , version : child1_2Version } ,
108+ name : child1_2Name ,
102109 children : new Map ( ) ,
103110 dev : false ,
104111 peer : false ,
@@ -115,13 +122,15 @@ describe("resolveNpmDependencies", () => {
115122 pkgid : `${ child2Name } @${ child2Version } ` ,
116123 realpath : child2Realpath ,
117124 package : { name : child2Name , version : child2Version } ,
125+ name : child2Name ,
118126 children : new Map ( [
119127 [
120128 child2_1Name ,
121129 {
122130 pkgid : `${ child2_1Name } @${ child2_1Version } ` ,
123131 realpath : child2_1Realpath ,
124132 package : { name : child2_1Name , version : child2_1Version } ,
133+ name : child2_1Name ,
125134 children : new Map ( ) ,
126135 dev : false ,
127136 peer : false ,
@@ -138,13 +147,15 @@ describe("resolveNpmDependencies", () => {
138147 pkgid : `${ child3Name } @${ child3Version } ` ,
139148 realpath : child3Realpath ,
140149 package : { name : child3Name , version : child3Version } ,
150+ name : child3Name ,
141151 children : new Map ( [
142152 [
143153 child3_1Name ,
144154 {
145155 pkgid : `${ child3_1Name } @${ child3_1Version } ` ,
146156 realpath : child3_1Realpath ,
147157 package : { name : child3_1Name , version : child3_1Version } ,
158+ name : child3_1Name ,
148159 children : new Map ( ) ,
149160 dev : false ,
150161 peer : false ,
@@ -155,6 +166,19 @@ describe("resolveNpmDependencies", () => {
155166 peer : true ,
156167 } ,
157168 ] ,
169+ [
170+ dotDirName ,
171+ {
172+ pkgid : `${ dotDirName } @${ dotDirVersion } ` ,
173+ realpath : dotDirRealpath ,
174+ package : { name : dotDirName , version : dotDirVersion } ,
175+ name : dotDirName ,
176+ children : new Map ( ) ,
177+ dev : false ,
178+ peer : false ,
179+ optional : false ,
180+ } ,
181+ ] ,
158182 ] ) ,
159183 } as Arborist . Node ;
160184
@@ -340,6 +364,7 @@ describe("resolveNpmDependencies", () => {
340364 pkgid : `${ optionalName } @${ optionalVersion } ` ,
341365 realpath : optionalRealpath ,
342366 package : { name : optionalName , version : optionalVersion } ,
367+ name : optionalName ,
343368 children : new Map ( ) ,
344369 dev : false ,
345370 peer : false ,
@@ -382,6 +407,7 @@ describe("resolveNpmDependencies", () => {
382407 pkgid : `${ missingName } @${ missingVersion } ` ,
383408 realpath : missingRealpath ,
384409 package : { name : missingName , version : missingVersion } ,
410+ name : missingName ,
385411 children : new Map ( ) ,
386412 dev : false ,
387413 peer : false ,
@@ -448,6 +474,22 @@ describe("resolveNpmDependencies", () => {
448474 ) . toBeDefined ( ) ;
449475 } ) ;
450476 } ) ;
477+ describe ( "when a directory inside node_modules starts with '.'" , ( ) => {
478+ it ( "should skip it without attempting to read its package.json" , async ( ) => {
479+ const licensesMap = new Map < LicenseNoticeKey , ResolvedLicense > ( ) ;
480+ await resolveDependenciesForNpmProject ( "/some/path/package.json" , licensesMap ) ;
481+
482+ const keys = Array . from ( licensesMap . keys ( ) ) ;
483+ expect ( keys . some ( k => k . includes ( dotDirName ) ) ) . toBe ( false ) ;
484+ expect (
485+ mockedDoesFileExist . mock . calls . some ( call => ( call [ 0 ] as string ) . includes ( dotDirRealpath ) ) ,
486+ ) . toBe ( false ) ;
487+ expect (
488+ mockedReadFile . mock . calls . some ( call => ( call [ 0 ] as string ) . includes ( dotDirRealpath ) ) ,
489+ ) . toBe ( false ) ;
490+ expect ( mockedLogger . warn ) . not . toHaveBeenCalled ( ) ;
491+ } ) ;
492+ } ) ;
451493
452494 const setUpPackageJson = ( directory : string , name : string , version : string ) : void => {
453495 const fullPackageJsonPath = join ( directory , "package.json" ) ;
0 commit comments