Skip to content

Commit fc3ef5a

Browse files
author
Michael Smith
committed
fix: adapt to @npmcli/run-script@11 breaking changes
1 parent 1453954 commit fc3ef5a

15 files changed

Lines changed: 58 additions & 96 deletions

File tree

lib/commands/run.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ class RunScript extends BaseCommand {
101101
pkg.scripts = scripts
102102

103103
if (
104-
!Object.prototype.hasOwnProperty.call(scripts, event) &&
105-
!(event === 'start' && (await runScript.isServerPackage(path)))
104+
!Object.prototype.hasOwnProperty.call(scripts, event)
106105
) {
107106
if (this.npm.config.get('if-present')) {
108107
return

lib/npm.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ class Npm {
100100
const command = deref(commandArg)
101101

102102
await this.#display.load({
103-
command,
104103
loglevel: this.config.get('loglevel'),
105104
stdoutColor: this.color,
106105
stderrColor: this.logColor,

lib/utils/display.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ class Display {
171171
#progress
172172

173173
// options
174-
#command
175174
#levelIndex
176175
#timing
177176
#json
@@ -214,7 +213,6 @@ class Display {
214213
}
215214

216215
async load ({
217-
command,
218216
heading,
219217
json,
220218
loglevel,
@@ -237,7 +235,6 @@ class Display {
237235
this.#stderrChalk = stderrColor ? new Chalk({ level }) : this.#noColorChalk
238236
this.#logColors = COLOR_PALETTE({ chalk: this.#stderrChalk })
239237

240-
this.#command = command
241238
this.#levelIndex = LEVEL_OPTIONS[loglevel].index
242239
this.#timing = timing
243240
this.#json = json
@@ -315,17 +312,6 @@ class Display {
315312
if (this.#outputState.buffering) {
316313
this.#outputState.buffer.push([level, meta, ...args])
317314
} else {
318-
// XXX: Check if the argument looks like a run-script banner. This should be replaced with proc-log.META in @npmcli/run-script
319-
if (typeof args[0] === 'string' && args[0].startsWith('\n> ') && args[0].endsWith('\n')) {
320-
if (this.#silent || ['exec', 'explore'].includes(this.#command)) {
321-
// Silent mode and some specific commands always hide run script banners
322-
break
323-
} else if (this.#json) {
324-
// In json mode, change output to stderr since we don't want to break json parsing on stdout if the user is piping to jq or something.
325-
// XXX: in a future (breaking?) change it might make sense for run-script to always output these banners with proc-log.output.error if we think they align closer with "logging" instead of "output".
326-
level = output.KEYS.error
327-
}
328-
}
329315
this.#writeOutput(level, meta, ...args)
330316
}
331317
break

scripts/disable-agent-for-tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Module._load = function (request, ...args) {
1818
const loaded = originalLoad.call(this, request, ...args)
1919
if (request === '@npmcli/agent' && loaded && typeof loaded.getAgent === 'function') {
2020
const realGetAgent = loaded.getAgent
21-
loaded.getAgent = (url, options = {}) => {
22-
if (options && options.proxy) {
21+
loaded.getAgent = (url, options) => {
22+
if (options.proxy) {
2323
return realGetAgent(url, options)
2424
}
2525
return false

smoke-tests/tap-snapshots/test/index.js.test.cjs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ Wrote to {NPM}/{TESTDIR}/project/package.json:
190190
"test": "echo /"Error: no test specified/" && exit 1"
191191
},
192192
"keywords": [],
193-
"author": "",
194193
"license": "ISC",
195194
"type": "commonjs"
196195
}
@@ -232,7 +231,6 @@ Object {
232231

233232
exports[`test/index.js TAP basic npm install dev dep > should have expected dev dep added package.json result 1`] = `
234233
Object {
235-
"author": "",
236234
"dependencies": Object {
237235
"abbrev": "^1.0.4",
238236
},
@@ -288,7 +286,6 @@ Object {
288286

289287
exports[`test/index.js TAP basic npm install prodDep@version > should have expected package.json result 1`] = `
290288
Object {
291-
"author": "",
292289
"dependencies": Object {
293290
"abbrev": "^1.0.4",
294291
},
@@ -318,7 +315,6 @@ abbrev 1.0.4 1.1.1 1.1.1 node_modules/abbrev project
318315

319316
exports[`test/index.js TAP basic npm pkg > should have expected npm pkg delete modified package.json result 1`] = `
320317
Object {
321-
"author": "",
322318
"dependencies": Object {
323319
"abbrev": "^1.0.4",
324320
},
@@ -338,7 +334,6 @@ Object {
338334

339335
exports[`test/index.js TAP basic npm pkg > should have expected npm pkg set modified package.json result 1`] = `
340336
Object {
341-
"author": "",
342337
"dependencies": Object {
343338
"abbrev": "^1.0.4",
344339
},
@@ -383,7 +378,6 @@ scripts = {
383378
hello: 'echo Hello'
384379
}
385380
keywords = []
386-
author = ''
387381
license = 'ISC'
388382
type = 'commonjs'
389383
dependencies = { abbrev: '^1.0.4' }
@@ -392,7 +386,6 @@ tap = { 'test-env': [ 'LC_ALL=sk' ] }
392386

393387
exports[`test/index.js TAP basic npm pkg set scripts > should have expected script added package.json result 1`] = `
394388
Object {
395-
"author": "",
396389
"dependencies": Object {
397390
"abbrev": "^1.0.4",
398391
},
@@ -422,9 +415,6 @@ exports[`test/index.js TAP basic npm prefix > should have expected prefix output
422415
`
423416

424417
exports[`test/index.js TAP basic npm run > should have expected run output 1`] = `
425-
426-
> echo Hello
427-
428418
Hello
429419
`
430420

@@ -453,7 +443,6 @@ Object {
453443

454444
exports[`test/index.js TAP basic npm uninstall > should have expected uninstall package.json result 1`] = `
455445
Object {
456-
"author": "",
457446
"dependencies": Object {
458447
"abbrev": "^1.0.4",
459448
},
@@ -511,7 +500,6 @@ Object {
511500

512501
exports[`test/index.js TAP basic npm update dep > should have expected update package.json result 1`] = `
513502
Object {
514-
"author": "",
515503
"dependencies": Object {
516504
"abbrev": "^1.0.4",
517505
},

smoke-tests/test/pack-json-output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ t.test('pack --json returns only json on stdout', async t => {
77

88
const { stderr, stdout } = await npmLocal('pack', '--json', { force: true })
99

10-
t.match(stderr, /> npm@.* prepack\n/, 'stderr has banner')
10+
t.match(stderr, /npm notice run npm@.* prepack\n/, 'stderr has banner')
1111
t.ok(JSON.parse(stdout), 'stdout can be parsed as json')
1212
})

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ verbose stack Error: The developer of this package has specified the following t
135135
verbose stack Invalid devEngines.runtime
136136
verbose stack Invalid name "nondescript" does not match "node" for "runtime"
137137
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:249:27)
138-
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:282:7)
139-
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:182:9)
138+
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:281:7)
139+
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:181:9)
140140
error code EBADDEVENGINES
141141
error EBADDEVENGINES The developer of this package has specified the following through devEngines
142142
error EBADDEVENGINES Invalid devEngines.runtime
@@ -200,8 +200,8 @@ verbose stack Error: The developer of this package has specified the following t
200200
verbose stack Invalid devEngines.runtime
201201
verbose stack Invalid name "nondescript" does not match "node" for "runtime"
202202
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:249:27)
203-
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:282:7)
204-
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:182:9)
203+
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:281:7)
204+
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:181:9)
205205
error code EBADDEVENGINES
206206
error EBADDEVENGINES The developer of this package has specified the following through devEngines
207207
error EBADDEVENGINES Invalid devEngines.runtime
@@ -226,8 +226,8 @@ verbose stack Error: The developer of this package has specified the following t
226226
verbose stack Invalid devEngines.runtime
227227
verbose stack Invalid name "nondescript" does not match "node" for "runtime"
228228
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:249:27)
229-
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:282:7)
230-
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:182:9)
229+
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:281:7)
230+
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:181:9)
231231
error code EBADDEVENGINES
232232
error EBADDEVENGINES The developer of this package has specified the following through devEngines
233233
error EBADDEVENGINES Invalid devEngines.runtime

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ Array [
4141

4242
exports[`test/lib/commands/pack.js TAP foreground-scripts defaults to true > logs pack contents 1`] = `
4343
Array [
44+
"run [email protected] prepack",
45+
"run echo prepack!",
46+
"run [email protected] postpack",
47+
"run echo postpack!",
4448
"package: [email protected]",
4549
"Tarball Contents",
4650
"110B package.json",
@@ -87,7 +91,10 @@ Array [
8791
`
8892

8993
exports[`test/lib/commands/pack.js TAP should log scoped package output as valid json > logs pack contents 1`] = `
90-
Array []
94+
Array [
95+
"run @myscope/[email protected] prepack",
96+
"run echo prepack!",
97+
]
9198
`
9299

93100
exports[`test/lib/commands/pack.js TAP should log scoped package output as valid json > outputs as json 1`] = `
@@ -116,17 +123,6 @@ Array [
116123
]
117124
`
118125

119-
exports[`test/lib/commands/pack.js TAP should log scoped package output as valid json > stderr has banners 1`] = `
120-
Array [
121-
String(
122-
123-
> @myscope/[email protected] prepack
124-
> echo prepack!
125-
126-
),
127-
]
128-
`
129-
130126
exports[`test/lib/commands/pack.js TAP should pack current directory with no arguments > logs pack contents 1`] = `
131127
Array [
132128
"package: [email protected]",

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ Array [
5151

5252
exports[`test/lib/commands/publish.js TAP foreground-scripts defaults to true > must match snapshot 1`] = `
5353
Array [
54+
"run [email protected] prepack",
55+
"run echo prepack!",
56+
"run [email protected] postpack",
57+
"run echo postpack!",
5458
"package: [email protected]",
5559
"Tarball Contents",
5660
"110B package.json",
@@ -222,15 +226,6 @@ exports[`test/lib/commands/publish.js TAP re-loads publishConfig.registry if add
222226
`
223227

224228
exports[`test/lib/commands/publish.js TAP respects publishConfig.registry, runs appropriate scripts > new package version 1`] = `
225-
226-
> @npmcli/[email protected] prepublishOnly
227-
> touch scripts-prepublishonly
228-
229-
> @npmcli/[email protected] publish
230-
> touch scripts-publish
231-
232-
> @npmcli/[email protected] postpublish
233-
> touch scripts-postpublish
234229
235230
`
236231

test/bin/windows-shims.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,15 @@ t.test('run shims', t => {
259259

260260
const result = spawnPath(cmd, [...args, ...params], opts)
261261

262-
// skip the first 3 lines of "npm test" to get the actual script output
263-
if (params[0].startsWith('test')) {
264-
result.stdout = result.stdout?.toString().split('\n').slice(3).join('\n').trim()
262+
// run-script@11 emits its run banners as notice logs on stderr, e.g.
263+
// "npm notice run [email protected] test". Strip them so we can assert on the
264+
// script's actual output.
265+
if (result.stderr) {
266+
result.stderr = result.stderr.toString()
267+
.split('\n')
268+
.filter(line => !line.startsWith('npm notice run'))
269+
.join('\n')
270+
.trim()
265271
}
266272

267273
t.match(result, {

0 commit comments

Comments
 (0)