Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect ignoreScripts config when running npm pack / npm publish #249

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions lib/dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class DirFetcher extends Fetcher {
return
}

if (this.opts.ignoreScripts) {
return
}

// we *only* run prepare.
// pre/post-pack is run by the npm CLI for publish and pack,
// but this function is *also* run when installing git deps
Expand Down
65 changes: 65 additions & 0 deletions tap-snapshots/test/dir.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,68 @@ Object {
},
}
`

exports[`test/dir.js TAP with prepare script and ignoreScripts > extract 1`] = `
Object {
"from": "file:test/fixtures/prepare-script",
"integrity": "sha512-sSZO46pax+NDC9SFcxOW/m9z1x1OLLtiV9XpZtfaajkdrn/2qo/7gDQ78RhdKQJnDzQxxLxX98B+oCRiHKVybA==",
"resolved": "\${CWD}/test/fixtures/prepare-script",
}
`

exports[`test/dir.js TAP with prepare script and ignoreScripts > file list 1`] = `
Array [
"package.json",
"prepare.js",
]
`

exports[`test/dir.js TAP with prepare script and ignoreScripts > manifest 1`] = `
Object {
"_from": "file:test/fixtures/prepare-script",
"_id": "[email protected]",
"_integrity": null,
"_resolved": "\${CWD}/test/fixtures/prepare-script",
"devDependencies": Object {
"abbrev": "^1.1.1",
},
"license": "ISC",
"main": "index.js",
"name": "git-prepare-script",
"scripts": Object {
"prepare": "node prepare.js",
},
"version": "1.0.0",
}
`

exports[`test/dir.js TAP with prepare script and ignoreScripts > packument 1`] = `
Object {
"dist-tags": Object {
"latest": "1.0.0",
},
"name": "git-prepare-script",
"versions": Object {
"1.0.0": Object {
"_from": "file:test/fixtures/prepare-script",
"_id": "[email protected]",
"_integrity": null,
"_resolved": "\${CWD}/test/fixtures/prepare-script",
"devDependencies": Object {
"abbrev": "^1.1.1",
},
"dist": Object {
"integrity": null,
"tarball": "file:\${CWD}/test/fixtures/prepare-script",
},
"license": "ISC",
"main": "index.js",
"name": "git-prepare-script",
"scripts": Object {
"prepare": "node prepare.js",
},
"version": "1.0.0",
},
},
}
`
14 changes: 14 additions & 0 deletions test/dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const prepare = resolve(__dirname, 'fixtures/prepare-script')
const preparespec = `file:${relative(process.cwd(), prepare)}`

t.test('with prepare script', async t => {
// ensure clean fixtures folder - remove file that should get generated
fs.rmSync(prepare + '/index.js', { force: true })
RUNS.length = 0
const f = new DirFetcher(preparespec, { tree: await loadActual(prepare) })
t.resolveMatchSnapshot(f.packument(), 'packument')
Expand All @@ -66,6 +68,18 @@ t.test('with prepare script', async t => {
}, 'should run in background'))
})

t.test('with prepare script and ignoreScripts', async t => {
// ensure clean fixtures folder - remove file that should get generated
fs.rmSync(prepare + '/index.js', { force: true })
RUNS.length = 0
const f = new DirFetcher(preparespec, { tree: await loadActual(prepare), ignoreScripts: true })
t.resolveMatchSnapshot(f.packument(), 'packument')
t.resolveMatchSnapshot(f.manifest(), 'manifest')
return t.resolveMatchSnapshot(f.extract(me + '/prepare'), 'extract')
.then(() => t.matchSnapshot(fs.readdirSync(me + '/prepare').sort(), 'file list'))
.then(() => t.equal(RUNS.length, 0, 'should not execute the script'))
})

t.test('responds to foregroundScripts: true', async t => {
RUNS.length = 0
const opt = { foregroundScripts: true, tree: await loadActual(prepare) }
Expand Down