Skip to content

Commit 4188dcb

Browse files
committed
fix(pack): default foreground-scripts to true
Fixes #6816
1 parent 162c82e commit 4188dcb

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

lib/commands/pack.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ class Pack extends BaseCommand {
2121
static workspaces = true
2222
static ignoreImplicitWorkspace = false
2323

24+
constructor (...args) {
25+
super(...args)
26+
this.npm.config.set('foreground-scripts', true, 'default')
27+
}
28+
2429
async exec (args) {
2530
if (args.length === 0) {
2631
args = ['.']

tap-snapshots/test/lib/commands/pack.js.test.cjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ Array [
2626
]
2727
`
2828

29+
exports[`test/lib/commands/pack.js TAP foreground-scripts defaults to true > logs pack contents 1`] = `
30+
Array [
31+
undefined,
32+
"package: [email protected]",
33+
undefined,
34+
"110B package.json",
35+
undefined,
36+
String(
37+
name: test-fg-scripts
38+
version: 0.0.0
39+
filename: test-fg-scripts-0.0.0.tgz
40+
package size: {size}
41+
unpacked size: 110 B
42+
shasum: {sha}
43+
integrity: {integrity}
44+
total files: 1
45+
),
46+
"",
47+
]
48+
`
49+
2950
exports[`test/lib/commands/pack.js TAP should log output as valid json > logs pack contents 1`] = `
3051
Array []
3152
`

test/lib/commands/pack.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,48 @@ t.test('dry run', async t => {
105105
t.throws(() => fs.statSync(path.resolve(npm.prefix, filename)))
106106
})
107107

108+
t.test('foreground-scripts defaults to true', async t => {
109+
const { npm, outputs, logs } = await loadMockNpm(t, {
110+
prefixDir: {
111+
'package.json': JSON.stringify({
112+
name: 'test-fg-scripts',
113+
version: '0.0.0',
114+
scripts: {
115+
prepack: 'echo prepack!',
116+
postpack: 'echo postpack!',
117+
},
118+
}
119+
),
120+
},
121+
config: { 'dry-run': true },
122+
})
123+
124+
/* eslint no-console: 0 */
125+
// TODO: replace this with `const results = t.intercept(console, 'log')`
126+
const log = console.log
127+
t.teardown(() => {
128+
console.log = log
129+
})
130+
const caughtLogs = []
131+
console.log = (...args) => {
132+
caughtLogs.push(args)
133+
}
134+
// end TODO
135+
136+
await npm.exec('pack', [])
137+
const filename = 'test-fg-scripts-0.0.0.tgz'
138+
t.same(
139+
caughtLogs,
140+
[
141+
['\n> [email protected] prepack\n> echo prepack!\n'],
142+
['\n> [email protected] postpack\n> echo postpack!\n'],
143+
],
144+
'prepack and postpack log to stdout')
145+
t.strictSame(outputs, [[filename]])
146+
t.matchSnapshot(logs.notice.map(([, m]) => m), 'logs pack contents')
147+
t.throws(() => fs.statSync(path.resolve(npm.prefix, filename)))
148+
})
149+
108150
t.test('invalid packument', async t => {
109151
const { npm, outputs } = await loadMockNpm(t, {
110152
prefixDir: {

0 commit comments

Comments
 (0)