Skip to content

Commit f27af63

Browse files
authoredOct 17, 2024··
fix!: honors ignoreScripts option to prevent prepare lifecycle script
BREAKING CHANGE: honors `ignoreScripts` property within options
1 parent a854c79 commit f27af63

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
 

‎lib/dir.js

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class DirFetcher extends Fetcher {
3232
if (!mani.scripts || !mani.scripts.prepare) {
3333
return
3434
}
35+
if (this.opts.ignoreScripts) {
36+
return
37+
}
3538

3639
// we *only* run prepare.
3740
// pre/post-pack is run by the npm CLI for publish and pack,

‎test/dir.js

+26
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,29 @@ t.test('fails without a tree or constructor', async t => {
164164
const f = new DirFetcher(abbrevspec, {})
165165
t.rejects(() => f.extract(me + '/prepare'))
166166
})
167+
168+
t.test('with prepare script and ignoreScripts true', async t => {
169+
let shouldNotBePopulated = false
170+
171+
const DirFetcherIsolate = t.mock('../lib/dir.js', {
172+
'@npmcli/run-script': () => {
173+
shouldNotBePopulated = true
174+
},
175+
})
176+
177+
const dir = t.testdir({
178+
'package.json': JSON.stringify({
179+
name: 'meow',
180+
version: '1.0.0',
181+
scripts: {
182+
prepare: 'noop',
183+
},
184+
}),
185+
})
186+
const f = new DirFetcherIsolate(`file:${relative(process.cwd(), dir)}`, {
187+
tree: await loadActual(dir),
188+
ignoreScripts: true,
189+
})
190+
await f.extract(me + '/prepare-ignore')
191+
t.ok(!shouldNotBePopulated)
192+
})

0 commit comments

Comments
 (0)
Please sign in to comment.