2828// where we need to quickly find all instances of a given package name within a 
2929// tree. 
3030
31- const  semver  =  require ( 'semver ' ) 
31+ const  PackageJson  =  require ( '@npmcli/package-json ' ) 
3232const  nameFromFolder  =  require ( '@npmcli/name-from-folder' ) 
33+ const  npa  =  require ( 'npm-package-arg' ) 
34+ const  semver  =  require ( 'semver' ) 
35+ const  util  =  require ( 'node:util' ) 
36+ const  {  getPaths : getBinPaths  }  =  require ( 'bin-links' ) 
37+ const  {  log }  =  require ( 'proc-log' ) 
38+ const  {  resolve,  relative,  dirname,  basename }  =  require ( 'node:path' ) 
39+ const  {  walkUp }  =  require ( 'walk-up-path' ) 
40+ 
41+ const  CaseInsensitiveMap  =  require ( './case-insensitive-map.js' ) 
3342const  Edge  =  require ( './edge.js' ) 
3443const  Inventory  =  require ( './inventory.js' ) 
3544const  OverrideSet  =  require ( './override-set.js' ) 
36- const  {  normalize }  =  require ( 'read-package-json-fast' ) 
37- const  {  getPaths : getBinPaths  }  =  require ( 'bin-links' ) 
38- const  npa  =  require ( 'npm-package-arg' ) 
45+ const  consistentResolve  =  require ( './consistent-resolve.js' ) 
3946const  debug  =  require ( './debug.js' ) 
4047const  gatherDepSet  =  require ( './gather-dep-set.js' ) 
48+ const  printableTree  =  require ( './printable.js' ) 
49+ const  querySelectorAll  =  require ( './query-selector-all.js' ) 
50+ const  relpath  =  require ( './relpath.js' ) 
4151const  treeCheck  =  require ( './tree-check.js' ) 
42- const  {  walkUp }  =  require ( 'walk-up-path' ) 
43- const  {  log }  =  require ( 'proc-log' ) 
4452
45- const  {  resolve,  relative,  dirname,  basename }  =  require ( 'node:path' ) 
46- const  util  =  require ( 'node:util' ) 
4753const  _package  =  Symbol ( '_package' ) 
4854const  _parent  =  Symbol ( '_parent' ) 
4955const  _target  =  Symbol . for ( '_target' ) 
@@ -58,13 +64,6 @@ const _delistFromMeta = Symbol.for('_delistFromMeta')
5864const  _explain  =  Symbol ( '_explain' ) 
5965const  _explanation  =  Symbol ( '_explanation' ) 
6066
61- const  relpath  =  require ( './relpath.js' ) 
62- const  consistentResolve  =  require ( './consistent-resolve.js' ) 
63- 
64- const  printableTree  =  require ( './printable.js' ) 
65- const  CaseInsensitiveMap  =  require ( './case-insensitive-map.js' ) 
66- 
67- const  querySelectorAll  =  require ( './query-selector-all.js' ) 
6867
6968class  Node  { 
7069  #global
@@ -121,14 +120,25 @@ class Node {
121120    // package's dependencies in a virtual root. 
122121    this . sourceReference  =  sourceReference 
123122
124-     // TODO if this came from pacote.manifest we don't have to do this, 
125-     // we can be told to skip this step 
126-     const  pkg  =  sourceReference  ? sourceReference . package 
127-       : normalize ( options . pkg  ||  { } ) 
123+     // have to set the internal package ref before assigning the parent, because this.package is read when adding to inventory 
124+     if  ( sourceReference )  { 
125+       this [ _package ]  =  sourceReference . package 
126+     }  else  { 
127+       // TODO if this came from pacote.manifest we don't have to do this, we can be told to skip this step 
128+       const  pkg  =  new  PackageJson ( ) 
129+       let  content  =  { } 
130+       // TODO this is overly guarded.  If pkg is not an object we should not allow it at all. 
131+       if  ( options . pkg  &&  typeof  options . pkg  ===  'object' )  { 
132+         content  =  options . pkg 
133+       } 
134+       pkg . fromContent ( content ) 
135+       pkg . syncNormalize ( ) 
136+       this [ _package ]  =  pkg . content 
137+     } 
128138
129139    this . name  =  name  || 
130-       nameFromFolder ( path  ||  pkg . name  ||  realpath )  || 
131-       pkg . name  || 
140+       nameFromFolder ( path  ||  this . package . name  ||  realpath )  || 
141+       this . package . name  || 
132142      null 
133143
134144    // should be equal if not a link 
@@ -156,13 +166,13 @@ class Node {
156166      // probably what we're getting from pacote, which IS trustworthy. 
157167      // 
158168      // Otherwise, hopefully a shrinkwrap will help us out. 
159-       const  resolved  =  consistentResolve ( pkg . _resolved ) 
160-       if  ( resolved  &&  ! ( / ^ f i l e : / . test ( resolved )  &&  pkg . _where ) )  { 
169+       const  resolved  =  consistentResolve ( this . package . _resolved ) 
170+       if  ( resolved  &&  ! ( / ^ f i l e : / . test ( resolved )  &&  this . package . _where ) )  { 
161171        this . resolved  =  resolved 
162172      } 
163173    } 
164-     this . integrity  =  integrity  ||  pkg . _integrity  ||  null 
165-     this . hasShrinkwrap  =  hasShrinkwrap  ||  pkg . _hasShrinkwrap  ||  false 
174+     this . integrity  =  integrity  ||  this . package . _integrity  ||  null 
175+     this . hasShrinkwrap  =  hasShrinkwrap  ||  this . package . _hasShrinkwrap  ||  false 
166176    this . installLinks  =  installLinks 
167177    this . legacyPeerDeps  =  legacyPeerDeps 
168178
@@ -203,17 +213,13 @@ class Node {
203213    this . edgesIn  =  new  Set ( ) 
204214    this . edgesOut  =  new  CaseInsensitiveMap ( ) 
205215
206-     // have to set the internal package ref before assigning the parent, 
207-     // because this.package is read when adding to inventory 
208-     this [ _package ]  =  pkg  &&  typeof  pkg  ===  'object'  ? pkg  : { } 
209- 
210216    if  ( overrides )  { 
211217      this . overrides  =  overrides 
212218    }  else  if  ( loadOverrides )  { 
213-       const  overrides  =  this [ _package ] . overrides  ||  { } 
219+       const  overrides  =  this . package . overrides  ||  { } 
214220      if  ( Object . keys ( overrides ) . length  >  0 )  { 
215221        this . overrides  =  new  OverrideSet ( { 
216-           overrides : this [ _package ] . overrides , 
222+           overrides : this . package . overrides , 
217223        } ) 
218224      } 
219225    } 
@@ -314,7 +320,7 @@ class Node {
314320    } 
315321
316322    return  getBinPaths ( { 
317-       pkg : this [ _package ] , 
323+       pkg : this . package , 
318324      path : this . path , 
319325      global : this . global , 
320326      top : this . globalTop , 
@@ -328,11 +334,11 @@ class Node {
328334  } 
329335
330336  get  version  ( )  { 
331-     return  this [ _package ] . version  ||  '' 
337+     return  this . package . version  ||  '' 
332338  } 
333339
334340  get  packageName  ( )  { 
335-     return  this [ _package ] . name  ||  null 
341+     return  this . package . name  ||  null 
336342  } 
337343
338344  get  pkgid  ( )  { 
0 commit comments