Skip to content

Commit 351a309

Browse files
fix: pass script-shell to publish lifecycle hooks (#9499)
1 parent 4fa81df commit 351a309

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

lib/commands/publish.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class Publish extends BaseCommand {
8383
const json = this.npm.config.get('json')
8484
const defaultTag = this.npm.config.get('tag')
8585
const ignoreScripts = this.npm.config.get('ignore-scripts')
86+
const scriptShell = this.npm.config.get('script-shell') || undefined
8687
const { silent } = this.npm
8788

8889
if (semver.validRange(defaultTag)) {
@@ -102,6 +103,7 @@ class Publish extends BaseCommand {
102103
path: spec.fetchSpec,
103104
stdio: 'inherit',
104105
pkg: manifest,
106+
scriptShell,
105107
})
106108
}
107109

@@ -218,13 +220,15 @@ class Publish extends BaseCommand {
218220
path: spec.fetchSpec,
219221
stdio: 'inherit',
220222
pkg: manifest,
223+
scriptShell,
221224
})
222225

223226
await runScript({
224227
event: 'postpublish',
225228
path: spec.fetchSpec,
226229
stdio: 'inherit',
227230
pkg: manifest,
231+
scriptShell,
228232
})
229233
}
230234

test/lib/commands/publish.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,3 +1624,37 @@ t.test('oidc token exchange - provenance', (t) => {
16241624

16251625
t.end()
16261626
})
1627+
1628+
t.test('passes script-shell config to lifecycle hooks', async t => {
1629+
const CAPTURED = []
1630+
const { npm, registry } = await loadNpmWithRegistry(t, {
1631+
config: {
1632+
...auth,
1633+
'script-shell': '/bin/bash',
1634+
},
1635+
prefixDir: {
1636+
'package.json': JSON.stringify({
1637+
...pkgJson,
1638+
scripts: {
1639+
prepublishOnly: 'exit 0',
1640+
publish: 'exit 0',
1641+
postpublish: 'exit 0',
1642+
},
1643+
}),
1644+
},
1645+
mocks: {
1646+
'@npmcli/run-script': async (opts) => {
1647+
CAPTURED.push(opts)
1648+
},
1649+
},
1650+
})
1651+
1652+
registry.publish(pkg, {})
1653+
await npm.exec('publish', [])
1654+
1655+
for (const event of ['prepublishOnly', 'publish', 'postpublish']) {
1656+
const rs = CAPTURED.find(r => r.event === event)
1657+
t.ok(rs, `ran ${event}`)
1658+
t.equal(rs?.scriptShell, '/bin/bash', `${event} receives scriptShell`)
1659+
}
1660+
})

0 commit comments

Comments
 (0)