File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ const pacote = require('pacote')
55const path = require ( 'path' )
66const rimraf = promisify ( require ( 'rimraf' ) )
77const BaseCommand = require ( './base-command.js' )
8+ const MinipassPipeline = require ( 'minipass-pipeline' )
9+ const npa = require ( 'npm-package-arg' )
810
911class Cache extends BaseCommand {
1012 static get description ( ) {
@@ -105,12 +107,19 @@ with --force.`)
105107
106108 log . silly ( 'cache add' , 'spec' , spec )
107109
108- // we ask pacote for the thing, and then just throw the data
109- // away so that it tee-pipes it into the cache like it does
110- // for a normal request.
111110 await pacote . tarball . stream ( spec , stream => {
112- stream . resume ( )
113- return stream . promise ( )
111+ const nspec = npa ( spec )
112+ if ( nspec . type === 'remote' || nspec . registry ) {
113+ stream . resume ( )
114+ return stream . promise ( )
115+ }
116+ return new MinipassPipeline (
117+ stream ,
118+ cacache . put . stream (
119+ path . join ( this . npm . config . get ( 'cache' ) , '_cacache' ) ,
120+ `npm-cache-add:${ spec } `
121+ )
122+ ) . promise ( )
114123 } , this . npm . flatOptions )
115124 }
116125
Original file line number Diff line number Diff line change @@ -20,17 +20,20 @@ const npmlog = {
2020 } ,
2121}
2222
23+ const pipeline = {
24+ pipe : ( ) => pipeline ,
25+ promise : ( ) => Promise . resolve ( ) ,
26+ resume : ( ) => { } ,
27+ }
28+
2329let tarballStreamSpec = ''
2430let tarballStreamOpts = { }
2531const pacote = {
2632 tarball : {
2733 stream : ( spec , handler , opts ) => {
2834 tarballStreamSpec = spec
2935 tarballStreamOpts = opts
30- return handler ( {
31- resume : ( ) => { } ,
32- promise : ( ) => Promise . resolve ( ) ,
33- } )
36+ return handler ( pipeline )
3437 } ,
3538 } ,
3639}
@@ -41,10 +44,16 @@ const cacacheVerifyStats = {
4144 totalEntries : 1 ,
4245 runTime : { total : 2000 } ,
4346}
47+
4448const cacache = {
4549 verify : ( path ) => {
4650 return cacacheVerifyStats
4751 } ,
52+ put : {
53+ stream : ( cache , stream ) => {
54+ return pipeline
55+ } ,
56+ } ,
4857}
4958
5059const Cache = requireInject ( '../../lib/cache.js' , {
You can’t perform that action at this time.
0 commit comments