@@ -26,40 +26,37 @@ export async function shrinkpack({ directory }: Options): Promise<void> {
2626
2727 for ( const key in lockfile . packages ) {
2828 if ( key === '' ) continue ;
29+ if ( ! key . includes ( 'node_modules' ) ) continue ;
2930 const record = lockfile . packages [ key ] ;
30- if ( ! record . resolved ) {
31- log . error (
32- `missing "resolved" fields in ${ lockfilePath } \n delete and recreate the lockfile` ,
33- ) ;
34- process . exit ( 1 ) ;
35- }
31+ if ( record . link === true ) continue ;
32+ if ( ! record . resolved && ! record . version ) continue ;
3633 const name = key . replace ( / ^ .* n o d e _ m o d u l e s \/ / g, '' ) ;
34+ const scopelessName = name . replace ( / ^ .+ \/ / , '' ) ;
35+ const resolved =
36+ record . resolved ||
37+ `https://registry.npmjs.org/${ name } /-/${ scopelessName } -${ record . version } .tgz` ;
3738 const wrapFileName = `${ name . replace ( / \/ / g, '_' ) } -${ record . version } .tar` ;
3839 const wrapFilePath = join ( wrapDirPath , wrapFileName ) ;
3940 const shortWrapFilePath = relative ( directory , wrapFilePath ) ;
4041 const spec = `${ name } @${ record . version } ` ;
4142 const isInWrapDir = wrapDirContents . includes ( wrapFileName ) ;
42- const isAlreadyWrapped = record . resolved . includes ( 'node_shrinkpack' ) ;
43- if ( isAlreadyWrapped ) {
44- if ( isInWrapDir ) {
45- log . info ( `${ spec } is already shrinkpacked` ) ;
46- } else {
47- const header = `${ spec } points to ${ record . resolved } which is missing` ;
48- const footer = `delete lockfile, reinstall, then run shrinkpack again` ;
49- log . error ( `${ header } \n ${ footer } ` ) ;
50- process . exit ( 1 ) ;
51- }
43+ const isAlreadyWrapped = resolved . includes ( 'node_shrinkpack' ) ;
44+ if ( isAlreadyWrapped && ! isInWrapDir ) {
45+ const header = `${ spec } points to ${ resolved } which is missing` ;
46+ const footer = `delete lockfile, reinstall, then run shrinkpack again` ;
47+ log . error ( `${ header } \n ${ footer } ` ) ;
48+ process . exit ( 1 ) ;
5249 }
5350 const integrity = isInWrapDir
5451 ? await getSsriFromFile ( wrapFilePath )
55- : await fromNetwork ( record . resolved , wrapFilePath ) ;
52+ : await fromNetwork ( resolved , wrapFilePath ) ;
5653
5754 if ( ! isInWrapDir ) {
5855 log . download ( spec ) ;
5956 totalAdded ++ ;
6057 }
6158
62- record . integrity = ` ${ record . integrity } ${ integrity } ` ;
59+ record . integrity = [ record . integrity , integrity ] . filter ( Boolean ) . join ( ' ' ) ;
6360 record . resolved = `file:${ shortWrapFilePath } ` ;
6461 requiredWrapDirContents [ wrapFileName ] = true ;
6562 }
0 commit comments