Skip to content

Commit

Permalink
feat: adds ignoreScripts to prevent prepare lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
reggi committed Oct 15, 2024
1 parent 2b2948f commit d6f82e6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class DirFetcher extends Fetcher {
if (!mani.scripts || !mani.scripts.prepare) {
return
}
if (this.opts.ignoreScripts) {
return
}

// we *only* run prepare.
// pre/post-pack is run by the npm CLI for publish and pack,
Expand Down
26 changes: 26 additions & 0 deletions test/dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,29 @@ t.test('fails without a tree or constructor', async t => {
const f = new DirFetcher(abbrevspec, {})
t.rejects(() => f.extract(me + '/prepare'))
})

t.test('with prepare script and ignoreScripts true', async t => {
let shouldNotBePopulated = false

const DirFetcherIsolate = t.mock('../lib/dir.js', {
'@npmcli/run-script': () => {
shouldNotBePopulated = true
},
})

const dir = t.testdir({
'package.json': JSON.stringify({
name: 'meow',
version: '1.0.0',
scripts: {
prepare: 'noop',
},
}),
})
const f = new DirFetcherIsolate(`file:${relative(process.cwd(), dir)}`, {
tree: await loadActual(dir),
ignoreScripts: true,
})
await f.extract(me + '/prepare-ignore')
t.ok(!shouldNotBePopulated)
})
7 changes: 7 additions & 0 deletions test/fixtures/prepare-ignore/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "prepare-ignore",
"version": "1.0.0",
"scripts": {
"prepare": "noop"
}
}

0 comments on commit d6f82e6

Please sign in to comment.