Skip to content

Commit

Permalink
feat!: adds --ignore-scripts flag to pack
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `--ignore-scripts` now applies to all lifecycle scripts, include `prepare`
  • Loading branch information
reggi authored and wraithgar committed Nov 21, 2024
1 parent 66fc8c9 commit 6995303
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Pack extends BaseCommand {
'workspace',
'workspaces',
'include-workspace-root',
'ignore-scripts',
]

static usage = ['<package-spec>']
Expand Down
3 changes: 2 additions & 1 deletion tap-snapshots/test/lib/docs.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3680,7 +3680,7 @@ npm pack <package-spec>
Options:
[--dry-run] [--json] [--pack-destination <pack-destination>]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces] [--include-workspace-root]
[-ws|--workspaces] [--include-workspace-root] [--ignore-scripts]
Run "npm help pack" for more info
Expand All @@ -3694,6 +3694,7 @@ npm pack <package-spec>
#### \`workspace\`
#### \`workspaces\`
#### \`include-workspace-root\`
#### \`ignore-scripts\`
`

exports[`test/lib/docs.js TAP usage ping > must match snapshot 1`] = `
Expand Down
4 changes: 3 additions & 1 deletion workspaces/arborist/lib/arborist/rebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ module.exports = cls => class Builder extends cls {

// links should run prepare scripts and only link bins after that
if (type === 'links') {
await this.#runScripts('prepare')
if (!this.options.ignoreScripts) {
await this.#runScripts('prepare')
}
}
if (this.options.binLinks) {
await this.#linkAllBins()
Expand Down
35 changes: 35 additions & 0 deletions workspaces/arborist/test/arborist/rebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,3 +812,38 @@ t.test('no workspaces', async t => {
},
])
})

t.test('do not run lifecycle scripts of linked deps twice', async t => {
const testdir = t.testdir({
project: {
'package.json': JSON.stringify({
name: 'my-project',
version: '1.0.0',
dependencies: {
foo: 'file:../foo',
},
}),
node_modules: {
foo: t.fixture('symlink', '../../foo'),
},
},
foo: {
'package.json': JSON.stringify({
name: 'foo',
version: '1.0.0',
scripts: {
postinstall: 'echo "ok"',
},
}),
},
})

const path = resolve(testdir, 'project')
const Arborist = t.mock('../../lib/arborist/index.js', {
'@npmcli/run-script': () => {
throw new Error('should not run any scripts')
},
})
const arb = new Arborist({ path, ignoreScripts: true })
await arb.rebuild()
})

0 comments on commit 6995303

Please sign in to comment.