diff --git a/lib/dir.js b/lib/dir.js index f3229b34..049cc840 100644 --- a/lib/dir.js +++ b/lib/dir.js @@ -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, diff --git a/test/dir.js b/test/dir.js index 9e9fbc26..234d3023 100644 --- a/test/dir.js +++ b/test/dir.js @@ -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) +}) diff --git a/test/fixtures/prepare-ignore/package.json b/test/fixtures/prepare-ignore/package.json new file mode 100644 index 00000000..741ea734 --- /dev/null +++ b/test/fixtures/prepare-ignore/package.json @@ -0,0 +1,7 @@ +{ + "name": "prepare-ignore", + "version": "1.0.0", + "scripts": { + "prepare": "noop" + } +} \ No newline at end of file