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
4 changes: 4 additions & 0 deletions lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Publish extends BaseCommand {
const json = this.npm.config.get('json')
const defaultTag = this.npm.config.get('tag')
const ignoreScripts = this.npm.config.get('ignore-scripts')
const scriptShell = this.npm.config.get('script-shell') || undefined
const { silent } = this.npm

if (semver.validRange(defaultTag)) {
Expand All @@ -102,6 +103,7 @@ class Publish extends BaseCommand {
path: spec.fetchSpec,
stdio: 'inherit',
pkg: manifest,
scriptShell,
})
}

Expand Down Expand Up @@ -218,13 +220,15 @@ class Publish extends BaseCommand {
path: spec.fetchSpec,
stdio: 'inherit',
pkg: manifest,
scriptShell,
})

await runScript({
event: 'postpublish',
path: spec.fetchSpec,
stdio: 'inherit',
pkg: manifest,
scriptShell,
})
}

Expand Down
34 changes: 34 additions & 0 deletions test/lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -1624,3 +1624,37 @@ t.test('oidc token exchange - provenance', (t) => {

t.end()
})

t.test('passes script-shell config to lifecycle hooks', async t => {
const CAPTURED = []
const { npm, registry } = await loadNpmWithRegistry(t, {
config: {
...auth,
'script-shell': '/bin/bash',
},
prefixDir: {
'package.json': JSON.stringify({
...pkgJson,
scripts: {
prepublishOnly: 'exit 0',
publish: 'exit 0',
postpublish: 'exit 0',
},
}),
},
mocks: {
'@npmcli/run-script': async (opts) => {
CAPTURED.push(opts)
},
},
})

registry.publish(pkg, {})
await npm.exec('publish', [])

for (const event of ['prepublishOnly', 'publish', 'postpublish']) {
const rs = CAPTURED.find(r => r.event === event)
t.ok(rs, `ran ${event}`)
t.equal(rs?.scriptShell, '/bin/bash', `${event} receives scriptShell`)
}
})
Loading