File tree Expand file tree Collapse file tree 4 files changed +41
-2
lines changed Expand file tree Collapse file tree 4 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ class Pack extends BaseCommand {
1515 'workspace' ,
1616 'workspaces' ,
1717 'include-workspace-root' ,
18+ 'ignore-scripts' ,
1819 ]
1920
2021 static usage = [ '<package-spec>' ]
Original file line number Diff line number Diff line change @@ -3680,7 +3680,7 @@ npm pack <package-spec>
36803680Options:
36813681[--dry-run] [--json] [--pack-destination <pack-destination>]
36823682[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
3683- [-ws|--workspaces] [--include-workspace-root]
3683+ [-ws|--workspaces] [--include-workspace-root] [--ignore-scripts]
36843684
36853685Run "npm help pack" for more info
36863686
@@ -3694,6 +3694,7 @@ npm pack <package-spec>
36943694#### \`workspace\`
36953695#### \`workspaces\`
36963696#### \`include-workspace-root\`
3697+ #### \`ignore-scripts\`
36973698`
36983699
36993700exports [ `test/lib/docs.js TAP usage ping > must match snapshot 1` ] = `
Original file line number Diff line number Diff line change @@ -154,7 +154,9 @@ module.exports = cls => class Builder extends cls {
154154
155155 // links should run prepare scripts and only link bins after that
156156 if ( type === 'links' ) {
157- await this . #runScripts( 'prepare' )
157+ if ( ! this . options . ignoreScripts ) {
158+ await this . #runScripts( 'prepare' )
159+ }
158160 }
159161 if ( this . options . binLinks ) {
160162 await this . #linkAllBins( )
Original file line number Diff line number Diff line change @@ -812,3 +812,38 @@ t.test('no workspaces', async t => {
812812 } ,
813813 ] )
814814} )
815+
816+ t . test ( 'do not run lifecycle scripts of linked deps twice' , async t => {
817+ const testdir = t . testdir ( {
818+ project : {
819+ 'package.json' : JSON . stringify ( {
820+ name : 'my-project' ,
821+ version : '1.0.0' ,
822+ dependencies : {
823+ foo : 'file:../foo' ,
824+ } ,
825+ } ) ,
826+ node_modules : {
827+ foo : t . fixture ( 'symlink' , '../../foo' ) ,
828+ } ,
829+ } ,
830+ foo : {
831+ 'package.json' : JSON . stringify ( {
832+ name : 'foo' ,
833+ version : '1.0.0' ,
834+ scripts : {
835+ postinstall : 'echo "ok"' ,
836+ } ,
837+ } ) ,
838+ } ,
839+ } )
840+
841+ const path = resolve ( testdir , 'project' )
842+ const Arborist = t . mock ( '../../lib/arborist/index.js' , {
843+ '@npmcli/run-script' : ( ) => {
844+ throw new Error ( 'should not run any scripts' )
845+ } ,
846+ } )
847+ const arb = new Arborist ( { path, ignoreScripts : true } )
848+ await arb . rebuild ( )
849+ } )
You can’t perform that action at this time.
0 commit comments