Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -164,3 +164,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)
})
Loading