@@ -4,13 +4,9 @@ const { get: ccGet } = require('cacache')
44const  ccPath  =  require ( 'cacache/lib/content/path.js' ) 
55const  cp  =  require ( 'child_process' ) 
66const  fs  =  require ( 'fs' ) 
7- const  npa  =  require ( 'npm-package-arg' ) 
87const  path  =  require ( 'path' ) 
98const  ssri  =  require ( 'ssri' ) 
109
11- // warm up npa 
12- npa ( 'idk' ) 
13- 
1410const  INDEX_VERSION  =  module . exports . INDEX_VERSION  =  '2.0.0' 
1511
1612const  pkgLockName  =  'package-lock.json' 
@@ -72,37 +68,38 @@ function resolve (...p) {
7268} 
7369
7470module . exports . depKey  =  depKey 
75- function  depKey  ( spec ,  dep )  { 
76-   const  prefix  =  `tinked-package:${ INDEX_VERSION }  
77-   if  ( spec . registry )  { 
78-     return  `${ prefix } ${ dep . integrity  ||  dep . resolved  ||  spec . raw }  
79-   }  else  if  ( spec . type  ===  'git' )  { 
80-     return  `${ prefix } ${ dep . version }  
81-   }  else  if  ( spec . type  ===  'remote' )  { 
82-     return  `${ prefix } ${ dep . integrity  ||  dep . version }  
83-   }  else  { 
84-     return  `${ prefix } ${ spec . name } ${ dep . version } ${ dep . resolved } ${ dep . integrity }  
85-   } 
71+ function  depKey  ( pkgName ,  dep )  { 
72+   return  `tinked-package:${  
73+     INDEX_VERSION  
74+   }  :${ 
75+     pkgName  
76+   }  :${ 
77+     dep . version  
78+   }  :${ 
79+     dep . resolved  
80+   }  :${ 
81+     dep . integrity  
82+   }  `
8683} 
8784
8885module . exports . resolveEntity  =  resolveEntity 
8986function  resolveEntity  ( cache ,  scope ,  pkgName ,  filePath )  { 
90-   const  spec  =  npa ( pkgName ,  scope . version ) 
87+   //  const spec = npa(pkgName, scope.version)
9188  if  ( ! ( scope  &&  scope . dependencies  &&  scope . dependencies [ pkgName ] ) )  { 
9289    return  false 
9390  } 
9491  let  pkg 
9592  const  tink  =  process . tink 
9693  try  { 
9794    process . tink  =  null 
98-     pkg  =  getPkg ( cache ,  spec ,   scope ,  pkgName ) 
95+     pkg  =  getPkg ( cache ,  scope ,  pkgName ) 
9996  }  catch  ( e )  { 
10097    if  ( e . code  ===  'ENOENT' )  { 
10198      const  dep  =  scope . dependencies [ pkgName ] 
10299      if  ( dep )  { 
103100        dep . name  =  pkgName 
104101        fetchPackageSync ( cache ,  dep ,  dep . integrity ) 
105-         pkg  =  getPkg ( cache ,  spec ,   scope ,  pkgName ) 
102+         pkg  =  getPkg ( cache ,  scope ,  pkgName ) 
106103      }  else  { 
107104        return  null 
108105      } 
@@ -137,13 +134,12 @@ function resolveEntity (cache, scope, pkgName, filePath) {
137134} 
138135
139136module . exports . readPkgLock  =  readPkgLock 
140- function  readPkgLock  ( ... p )  { 
141-   const   resolved  =  path . resolve ( ... p ) 
142-   let  modulesIdx   =   resolved . lastIndexOf ( 'node_modules' ) 
143-   while  ( modulesIdx  !==  - 1 )  { 
137+ function  readPkgLock  ( resolved )  { 
138+   let   modulesIdx  =  resolved . indexOf ( 'node_modules' ) 
139+   let  pkgLock 
140+   while  ( ! pkgLock   &&   modulesIdx  !==  - 1 )  { 
144141    let  substr  =  resolved . substr ( 0 ,  modulesIdx  -  1 ) 
145142    const  pkgLockPath  =  path . join ( substr ,  pkgLockName ) 
146-     let  pkgLock 
147143    if  ( pkgLockCache . has ( pkgLockPath ) )  { 
148144      pkgLock  =  pkgLockCache . get ( pkgLockPath ) 
149145    }  else  { 
@@ -154,13 +150,15 @@ function readPkgLock (...p) {
154150      }  catch  ( e )  { 
155151        if  ( e . code  !==  'ENOENT' )  { 
156152          throw  e 
153+         }  else  { 
154+           pkgLockCache . set ( pkgLockPath ,  null ) 
157155        } 
158156      } 
159157    } 
160158    if  ( pkgLock )  { 
161159      return  {  pkgLock,  subPath : resolved . substr ( modulesIdx  -  1 )  } 
162160    }  else  { 
163-       modulesIdx  =  substr . lastIndexOf ( 'node_modules' ) 
161+       modulesIdx  =  substr . indexOf ( 'node_modules' ,   modulesIdx ) 
164162    } 
165163  } 
166164  return  null 
@@ -288,9 +286,17 @@ function statSync ({ cache, hash, pkg, resolvedPath, isDir }, verify) {
288286  } ) 
289287} 
290288
291- function  getPkg  ( cache ,  spec ,  scope ,  pkgName )  { 
292-   const  {  metadata }  =  ccGet . sync ( cache ,  depKey ( spec ,  scope . dependencies [ pkgName ] ) ,  {  memoize : true  } ) 
293-   return  JSON . parse ( metadata ) 
289+ const  pkgCache  =  new  Map ( ) 
290+ function  getPkg  ( cache ,  scope ,  pkgName )  { 
291+   const  key  =  depKey ( pkgName ,  scope . dependencies [ pkgName ] ) 
292+   if  ( pkgCache . has ( key ) )  { 
293+     return  pkgCache . get ( key ) 
294+   }  else  { 
295+     const  {  metadata }  =  ccGet . sync ( cache ,  key ) 
296+     const  ret  =  JSON . parse ( metadata ) 
297+     pkgCache . set ( key ,  ret ) 
298+     return  ret 
299+   } 
294300} 
295301
296302let  ensurePkg 
0 commit comments