@@ -80,30 +80,26 @@ const readOutOfTreeIgnoreFiles = (root, rel, result = []) => {
8080}
8181
8282class PackWalker extends IgnoreWalker {
83- constructor ( opts ) {
83+ constructor ( tree , opts ) {
8484 const options = {
8585 ...opts ,
8686 includeEmpty : false ,
8787 follow : false ,
88- }
89-
90- // we path.resolve() here because ignore-walk doesn't do it and we want full paths
91- options . path = resolve ( options . path || process . cwd ( ) ) . replace ( / \\ / g, '/' )
92-
93- if ( ! options . ignoreFiles ) {
94- options . ignoreFiles = [
88+ // we path.resolve() here because ignore-walk doesn't do it and we want full paths
89+ path : resolve ( opts ?. path || tree . path ) . replace ( / \\ / g, '/' ) ,
90+ ignoreFiles : opts ?. ignoreFiles || [
9591 defaultRules ,
9692 'package.json' ,
9793 '.npmignore' ,
9894 '.gitignore' ,
9995 strictRules ,
100- ]
96+ ] ,
10197 }
10298
10399 super ( options )
104100 this . isPackage = options . isPackage
105101 this . seen = options . seen || new Set ( )
106- this . tree = options . tree
102+ this . tree = tree
107103 this . requiredFiles = options . requiredFiles || [ ]
108104
109105 const additionalDefaults = [ ]
@@ -206,16 +202,11 @@ class PackWalker extends IgnoreWalker {
206202 // copies the root's `ignoreFiles` value, but we don't want to respect package.json for
207203 // subdirectories, so we override it with a list that intentionally omits package.json
208204 walkerOpt ( entry , opts ) {
209- let ignoreFiles = [
210- defaultRules ,
211- '.npmignore' ,
212- '.gitignore' ,
213- strictRules ,
214- ]
205+ let ignoreFiles = null
215206
216207 // however, if we have a tree, and we have workspaces, and the directory we're about
217208 // to step into is a workspace, then we _do_ want to respect its package.json
218- if ( this . tree && this . tree . workspaces ) {
209+ if ( this . tree . workspaces ) {
219210 const workspaceDirs = [ ...this . tree . workspaces . values ( ) ]
220211 . map ( ( dir ) => dir . replace ( / \\ / g, '/' ) )
221212
@@ -229,6 +220,13 @@ class PackWalker extends IgnoreWalker {
229220 strictRules ,
230221 ]
231222 }
223+ } else {
224+ ignoreFiles = [
225+ defaultRules ,
226+ '.npmignore' ,
227+ '.gitignore' ,
228+ strictRules ,
229+ ]
232230 }
233231
234232 return {
@@ -248,7 +246,7 @@ class PackWalker extends IgnoreWalker {
248246
249247 // overridden method: we want child walkers to be instances of this class, not ignore-walk
250248 walker ( entry , opts , callback ) {
251- new PackWalker ( this . walkerOpt ( entry , opts ) ) . on ( 'done' , callback ) . start ( )
249+ new PackWalker ( this . tree , this . walkerOpt ( entry , opts ) ) . on ( 'done' , callback ) . start ( )
252250 }
253251
254252 // overridden method: we use a custom sort method to help compressibility
@@ -351,7 +349,7 @@ class PackWalker extends IgnoreWalker {
351349 // custom method: after we've finished gathering the files for the root package, we call this
352350 // before emitting the 'done' event in order to gather all of the files for bundled deps
353351 async gatherBundles ( ) {
354- if ( this . tree && this . seen . has ( this . tree ) ) {
352+ if ( this . seen . has ( this . tree ) ) {
355353 return
356354 }
357355
@@ -380,14 +378,16 @@ class PackWalker extends IgnoreWalker {
380378
381379 // get a reference to the node we're bundling
382380 const node = this . tree . edgesOut . get ( dep ) . to
381+ // we use node.path for the path because we want the location the node was linked to,
382+ // not where it actually lives on disk
383+ const path = node . path
384+ // but link nodes don't have edgesOut, so we need to pass in the target of the node
385+ // in order to make sure we correctly traverse its dependencies
386+ const tree = node . target
387+
383388 // and start building options to be passed to the walker for this package
384389 const walkerOpts = {
385- // we use node.path for the path because we want the location the node was linked to,
386- // not where it actually lives on disk
387- path : node . path ,
388- // but link nodes don't have edgesOut, so we need to pass in the target of the node
389- // in order to make sure we correctly traverse its dependencies
390- tree : node . target ,
390+ path,
391391 isPackage : true ,
392392 ignoreFiles : [ ] ,
393393 seen : this . seen , // pass through seen so we can prevent infinite circular loops
@@ -413,7 +413,7 @@ class PackWalker extends IgnoreWalker {
413413 walkerOpts . ignoreFiles . push ( strictRules )
414414
415415 // create a walker for this dependency and gather its results
416- const walker = new PackWalker ( walkerOpts )
416+ const walker = new PackWalker ( tree , walkerOpts )
417417 const bundled = await new Promise ( ( pResolve , pReject ) => {
418418 walker . on ( 'error' , pReject )
419419 walker . on ( 'done' , pResolve )
@@ -430,10 +430,14 @@ class PackWalker extends IgnoreWalker {
430430 }
431431}
432432
433- const walk = ( options , callback ) => {
434- options = { ...options , isPackage : true }
433+ const walk = ( tree , options , callback ) => {
434+ if ( typeof options === 'function' ) {
435+ callback = options
436+ options = { }
437+ }
435438 const p = new Promise ( ( pResolve , pReject ) => {
436- new PackWalker ( options ) . on ( 'done' , pResolve ) . on ( 'error' , pReject ) . start ( )
439+ new PackWalker ( tree , { ...options , isPackage : true } )
440+ . on ( 'done' , pResolve ) . on ( 'error' , pReject ) . start ( )
437441 } )
438442 return callback ? p . then ( res => callback ( null , res ) , callback ) : p
439443}
0 commit comments