A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/npm/cli/commit/bcc781abf10b46aa5b04da996fc4602524be9b0e below:

move run-script banners to stderr when in json mode (#7439) · npm/cli@bcc781a · GitHub

File tree Expand file treeCollapse file tree 5 files changed

+45

-12

lines changed

Filter options

Expand file treeCollapse file tree 5 files changed

+45

-12

lines changed Original file line number Diff line number Diff line change

@@ -16,7 +16,7 @@ const run = require('../lib/build.js')

16 16

const { paths } = require('../lib/index')

17 17 18 18

run(paths)

19 -

.then((res) => console.log(`Wrote ${res.length} files`))

19 +

.then((res) => console.error(`Wrote ${res.length} files`))

20 20

.catch((err) => {

21 21

process.exitCode = 1

22 22

console.error(err)

Original file line number Diff line number Diff line change

@@ -267,16 +267,22 @@ class Display {

267 267

if (this.#outputState.buffering) {

268 268

this.#outputState.buffer.push([level, meta, ...args])

269 269

} else {

270 -

// HACK: if it looks like the banner and we are in a state where we hide the

271 -

// banner then dont write any output. This hack can be replaced with proc-log.META

272 -

const isBanner = args.length === 1 &&

273 -

typeof args[0] === 'string' &&

274 -

args[0].startsWith('\n> ') &&

275 -

args[0].endsWith('\n')

276 -

const hideBanner = this.#silent || ['exec', 'explore'].includes(this.#command)

277 -

if (!(isBanner && hideBanner)) {

278 -

this.#writeOutput(level, meta, ...args)

270 +

// HACK: Check if the argument looks like a run-script banner. This can be

271 +

// replaced with proc-log.META in @npmcli/run-script

272 +

if (typeof args[0] === 'string' && args[0].startsWith('\n> ') && args[0].endsWith('\n')) {

273 +

if (this.#silent || ['exec', 'explore'].includes(this.#command)) {

274 +

// Silent mode and some specific commands always hide run script banners

275 +

break

276 +

} else if (this.#json) {

277 +

// In json mode, change output to stderr since we dont want to break json

278 +

// parsing on stdout if the user is piping to jq or something.

279 +

// XXX: in a future (breaking?) change it might make sense for run-script to

280 +

// always output these banners with proc-log.output.error if we think they

281 +

// align closer with "logging" instead of "output"

282 +

level = output.KEYS.error

283 +

}

279 284

}

285 +

this.#writeOutput(level, meta, ...args)

280 286

}

281 287

break

282 288

}

Original file line number Diff line number Diff line change

@@ -0,0 +1,12 @@

1 + 2 +

const t = require('tap')

3 +

const setup = require('./fixtures/setup.js')

4 + 5 +

t.test('pack --json returns only json on stdout', async t => {

6 +

const { npmLocal } = await setup(t)

7 + 8 +

const { stderr, stdout } = await npmLocal('pack', '--json')

9 + 10 +

t.match(stderr, /> npm@.* prepack\n/, 'stderr has banner')

11 +

t.ok(JSON.parse(stdout), 'stdout can be parsed as json')

12 +

})

Original file line number Diff line number Diff line change

@@ -109,13 +109,24 @@ Array [

109 109

"name": "@myscope/test-package",

110 110

"shasum": "{sha}",

111 111

"size": "{size}",

112 -

"unpackedSize": 50,

112 +

"unpackedSize": 88,

113 113

"version": "1.0.0",

114 114

},

115 115

],

116 116

]

117 117

`

118 118 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/test-package@1.0.0 prepack

124 +

> echo prepack!

125 + 126 +

),

127 +

]

128 +

`

129 + 119 130

exports[`test/lib/commands/pack.js TAP should pack current directory with no arguments > logs pack contents 1`] = `

120 131

Array [

121 132

"package: test-package@1.0.0",

Original file line number Diff line number Diff line change

@@ -72,18 +72,22 @@ t.test('should log output as valid json', async t => {

72 72

})

73 73 74 74

t.test('should log scoped package output as valid json', async t => {

75 -

const { npm, outputs, logs } = await loadMockNpm(t, {

75 +

const { npm, outputs, outputErrors, logs } = await loadMockNpm(t, {

76 76

prefixDir: {

77 77

'package.json': JSON.stringify({

78 78

name: '@myscope/test-package',

79 79

version: '1.0.0',

80 +

scripts: {

81 +

prepack: 'echo prepack!',

82 +

},

80 83

}),

81 84

},

82 85

config: { json: true },

83 86

})

84 87

await npm.exec('pack', [])

85 88

const filename = 'myscope-test-package-1.0.0.tgz'

86 89

t.matchSnapshot(outputs.map(JSON.parse), 'outputs as json')

90 +

t.matchSnapshot(outputErrors, 'stderr has banners')

87 91

t.matchSnapshot(logs.notice, 'logs pack contents')

88 92

t.ok(fs.statSync(path.resolve(npm.prefix, filename)))

89 93

})

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