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

feat: add ability to skip pre/post hooks #1718

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
12 changes: 7 additions & 5 deletions lib/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ const runScript = async (args) => {

// positional args only added to the main event, not pre/post
const events = [[event, args]]
if (scripts[`pre${event}`]) {
events.unshift([`pre${event}`, []])
}
if (scripts[`post${event}`]) {
events.push([`post${event}`, []])
if (!npm.flatOptions.ignoreScripts) {
if (scripts[`pre${event}`]) {
events.unshift([`pre${event}`, []])
}
if (scripts[`post${event}`]) {
events.push([`post${event}`, []])
}
}

const opts = {
Expand Down
39 changes: 39 additions & 0 deletions test/lib/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,45 @@ t.test('run pre/post hooks', async t => {
RUN_SCRIPTS.length = 0
})

t.test('skip pre/post hooks when using ignoreScripts', async t => {
npm.flatOptions.ignoreScripts = true

npm.localPrefix = t.testdir({
'package.json': JSON.stringify({
name: 'x',
version: '1.2.3',
scripts: {
preenv: 'echo before the env',
postenv: 'echo after the env'
}
})
})

await runScript(['env'], er => {
if (er) {
throw er
}
t.deepEqual(RUN_SCRIPTS, [
{
path: npm.localPrefix,
args: [],
scriptShell: undefined,
stdio: 'inherit',
stdioString: true,
pkg: { name: 'x', version: '1.2.3', _id: 'x@1.2.3', scripts: {
preenv: 'echo before the env',
postenv: 'echo after the env',
env: 'env'
} },
event: 'env'
}
])

delete npm.flatOptions.ignoreScripts
})
RUN_SCRIPTS.length = 0
})

t.test('run silent', async t => {
npmlog.level = 'silent'
t.teardown(() => { npmlog.level = 'warn' })
Expand Down