+305
-1
lines changedFilter options
+305
-1
lines changed Original file line number Diff line number Diff line change
@@ -47,6 +47,9 @@ class Pack extends BaseCommand {
47
47
for (const { arg, manifest } of manifests) {
48
48
const tarballData = await libpack(arg, {
49
49
...this.npm.flatOptions,
50
+
foregroundScripts: this.npm.config.isDefault('foreground-scripts')
51
+
? true
52
+
: this.npm.config.get('foreground-scripts'),
50
53
prefix: this.npm.localPrefix,
51
54
workspaces: this.workspacePaths,
52
55
})
Original file line number Diff line number Diff line change
@@ -80,6 +80,9 @@ class Publish extends BaseCommand {
80
80
// we pass dryRun: true to libnpmpack so it doesn't write the file to disk
81
81
const tarballData = await pack(spec, {
82
82
...opts,
83
+
foregroundScripts: this.npm.config.isDefault('foreground-scripts')
84
+
? true
85
+
: this.npm.config.get('foreground-scripts'),
83
86
dryRun: true,
84
87
prefix: this.npm.localPrefix,
85
88
workspaces: this.workspacePaths,
Original file line number Diff line number Diff line change
@@ -26,6 +26,48 @@ Array [
26
26
]
27
27
`
28
28
29
+
exports[`test/lib/commands/pack.js TAP foreground-scripts can still be set to false > logs pack contents 1`] = `
30
+
Array [
31
+
undefined,
32
+
"package: test-fg-scripts@0.0.0",
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
+
50
+
exports[`test/lib/commands/pack.js TAP foreground-scripts defaults to true > logs pack contents 1`] = `
51
+
Array [
52
+
undefined,
53
+
"package: test-fg-scripts@0.0.0",
54
+
undefined,
55
+
"110B package.json",
56
+
undefined,
57
+
String(
58
+
name: test-fg-scripts
59
+
version: 0.0.0
60
+
filename: test-fg-scripts-0.0.0.tgz
61
+
package size: {size}
62
+
unpacked size: 110 B
63
+
shasum: {sha}
64
+
integrity: {integrity}
65
+
total files: 1
66
+
),
67
+
"",
68
+
]
69
+
`
70
+
29
71
exports[`test/lib/commands/pack.js TAP should log output as valid json > logs pack contents 1`] = `
30
72
Array []
31
73
`
Original file line number Diff line number Diff line change
@@ -56,6 +56,92 @@ Array [
56
56
]
57
57
`
58
58
59
+
exports[`test/lib/commands/publish.js TAP foreground-scripts can still be set to false > must match snapshot 1`] = `
60
+
Array [
61
+
Array [
62
+
"",
63
+
],
64
+
Array [
65
+
"",
66
+
"package: test-fg-scripts@0.0.0",
67
+
],
68
+
Array [
69
+
"=== Tarball Contents ===",
70
+
],
71
+
Array [
72
+
"",
73
+
"110B package.json",
74
+
],
75
+
Array [
76
+
"=== Tarball Details ===",
77
+
],
78
+
Array [
79
+
"",
80
+
String(
81
+
name: test-fg-scripts
82
+
version: 0.0.0
83
+
filename: test-fg-scripts-0.0.0.tgz
84
+
package size: {size}
85
+
unpacked size: 110 B
86
+
shasum: {sha}
87
+
integrity: {integrity}
88
+
total files: 1
89
+
),
90
+
],
91
+
Array [
92
+
"",
93
+
"",
94
+
],
95
+
Array [
96
+
"",
97
+
"Publishing to https://registry.npmjs.org/ with tag latest and default access (dry-run)",
98
+
],
99
+
]
100
+
`
101
+
102
+
exports[`test/lib/commands/publish.js TAP foreground-scripts defaults to true > must match snapshot 1`] = `
103
+
Array [
104
+
Array [
105
+
"",
106
+
],
107
+
Array [
108
+
"",
109
+
"package: test-fg-scripts@0.0.0",
110
+
],
111
+
Array [
112
+
"=== Tarball Contents ===",
113
+
],
114
+
Array [
115
+
"",
116
+
"110B package.json",
117
+
],
118
+
Array [
119
+
"=== Tarball Details ===",
120
+
],
121
+
Array [
122
+
"",
123
+
String(
124
+
name: test-fg-scripts
125
+
version: 0.0.0
126
+
filename: test-fg-scripts-0.0.0.tgz
127
+
package size: {size}
128
+
unpacked size: 110 B
129
+
shasum: {sha}
130
+
integrity: {integrity}
131
+
total files: 1
132
+
),
133
+
],
134
+
Array [
135
+
"",
136
+
"",
137
+
],
138
+
Array [
139
+
"",
140
+
"Publishing to https://registry.npmjs.org/ with tag latest and default access (dry-run)",
141
+
],
142
+
]
143
+
`
144
+
59
145
exports[`test/lib/commands/publish.js TAP has mTLS auth for scope configured registry > new package version 1`] = `
60
146
+ @npm/test-package@1.0.0
61
147
`
Original file line number Diff line number Diff line change
@@ -637,7 +637,8 @@ recommended that you do not use this option!
637
637
638
638
#### \`foreground-scripts\`
639
639
640
-
* Default: false
640
+
* Default: \`false\` unless when using \`npm pack\` or \`npm publish\` where it
641
+
defaults to \`true\`
641
642
* Type: Boolean
642
643
643
644
Run all build scripts (ie, \`preinstall\`, \`install\`, and \`postinstall\`)
Original file line number Diff line number Diff line change
@@ -105,6 +105,87 @@ t.test('dry run', async t => {
105
105
t.throws(() => fs.statSync(path.resolve(npm.prefix, filename)))
106
106
})
107
107
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> test-fg-scripts@0.0.0 prepack\n> echo prepack!\n'],
142
+
['\n> test-fg-scripts@0.0.0 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
+
150
+
t.test('foreground-scripts can still be set to false', async t => {
151
+
const { npm, outputs, logs } = await loadMockNpm(t, {
152
+
prefixDir: {
153
+
'package.json': JSON.stringify({
154
+
name: 'test-fg-scripts',
155
+
version: '0.0.0',
156
+
scripts: {
157
+
prepack: 'echo prepack!',
158
+
postpack: 'echo postpack!',
159
+
},
160
+
}
161
+
),
162
+
},
163
+
config: { 'dry-run': true, 'foreground-scripts': false },
164
+
})
165
+
166
+
/* eslint no-console: 0 */
167
+
// TODO: replace this with `const results = t.intercept(console, 'log')`
168
+
const log = console.log
169
+
t.teardown(() => {
170
+
console.log = log
171
+
})
172
+
const caughtLogs = []
173
+
console.log = (...args) => {
174
+
caughtLogs.push(args)
175
+
}
176
+
// end TODO
177
+
178
+
await npm.exec('pack', [])
179
+
const filename = 'test-fg-scripts-0.0.0.tgz'
180
+
t.same(
181
+
caughtLogs,
182
+
[],
183
+
'prepack and postpack do not log to stdout')
184
+
t.strictSame(outputs, [[filename]])
185
+
t.matchSnapshot(logs.notice.map(([, m]) => m), 'logs pack contents')
186
+
t.throws(() => fs.statSync(path.resolve(npm.prefix, filename)))
187
+
})
188
+
108
189
t.test('invalid packument', async t => {
109
190
const { npm, outputs } = await loadMockNpm(t, {
110
191
prefixDir: {
Original file line number Diff line number Diff line change
@@ -167,6 +167,92 @@ t.test('dry-run', async t => {
167
167
t.matchSnapshot(logs.notice)
168
168
})
169
169
170
+
t.test('foreground-scripts defaults to true', async t => {
171
+
const { joinedOutput, npm, logs } = await loadMockNpm(t, {
172
+
config: {
173
+
'dry-run': true,
174
+
...auth,
175
+
},
176
+
prefixDir: {
177
+
'package.json': JSON.stringify({
178
+
name: 'test-fg-scripts',
179
+
version: '0.0.0',
180
+
scripts: {
181
+
prepack: 'echo prepack!',
182
+
postpack: 'echo postpack!',
183
+
},
184
+
}
185
+
),
186
+
},
187
+
})
188
+
189
+
/* eslint no-console: 0 */
190
+
// TODO: replace this with `const results = t.intercept(console, 'log')`
191
+
const log = console.log
192
+
t.teardown(() => {
193
+
console.log = log
194
+
})
195
+
const caughtLogs = []
196
+
console.log = (...args) => {
197
+
caughtLogs.push(args)
198
+
}
199
+
// end TODO
200
+
201
+
await npm.exec('publish', [])
202
+
t.equal(joinedOutput(), `+ test-fg-scripts@0.0.0`)
203
+
t.matchSnapshot(logs.notice)
204
+
205
+
t.same(
206
+
caughtLogs,
207
+
[
208
+
['\n> test-fg-scripts@0.0.0 prepack\n> echo prepack!\n'],
209
+
['\n> test-fg-scripts@0.0.0 postpack\n> echo postpack!\n'],
210
+
],
211
+
'prepack and postpack log to stdout')
212
+
})
213
+
214
+
t.test('foreground-scripts can still be set to false', async t => {
215
+
const { joinedOutput, npm, logs } = await loadMockNpm(t, {
216
+
config: {
217
+
'dry-run': true,
218
+
'foreground-scripts': false,
219
+
...auth,
220
+
},
221
+
prefixDir: {
222
+
'package.json': JSON.stringify({
223
+
name: 'test-fg-scripts',
224
+
version: '0.0.0',
225
+
scripts: {
226
+
prepack: 'echo prepack!',
227
+
postpack: 'echo postpack!',
228
+
},
229
+
}
230
+
),
231
+
},
232
+
})
233
+
234
+
/* eslint no-console: 0 */
235
+
// TODO: replace this with `const results = t.intercept(console, 'log')`
236
+
const log = console.log
237
+
t.teardown(() => {
238
+
console.log = log
239
+
})
240
+
const caughtLogs = []
241
+
console.log = (...args) => {
242
+
caughtLogs.push(args)
243
+
}
244
+
// end TODO
245
+
246
+
await npm.exec('publish', [])
247
+
t.equal(joinedOutput(), `+ test-fg-scripts@0.0.0`)
248
+
t.matchSnapshot(logs.notice)
249
+
250
+
t.same(
251
+
caughtLogs,
252
+
[],
253
+
'prepack and postpack do not log to stdout')
254
+
})
255
+
170
256
t.test('shows usage with wrong set of arguments', async t => {
171
257
const { publish } = await loadMockNpm(t, { command: 'publish' })
172
258
await t.rejects(publish.exec(['a', 'b', 'c']), publish.usage)
Original file line number Diff line number Diff line change
@@ -786,6 +786,8 @@ define('force', {
786
786
787
787
define('foreground-scripts', {
788
788
default: false,
789
+
defaultDescription: `\`false\` unless when using \`npm pack\` or \`npm publish\` where it
790
+
defaults to \`true\``,
789
791
type: Boolean,
790
792
description: `
791
793
Run all build scripts (ie, \`preinstall\`, \`install\`, and
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4