mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-24 07:38:12 -05:00
fix: print warnings to stderr (#8342)
This commit is contained in:
6
.changeset/tall-shirts-scream.md
Normal file
6
.changeset/tall-shirts-scream.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/cli-utils": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Print warnings to stderr [#8342](https://github.com/pnpm/pnpm/pull/8342).
|
||||
@@ -28,9 +28,8 @@ export async function getConfig (
|
||||
delete config.reporter // This is a silly workaround because @pnpm/core expects a function as opts.reporter
|
||||
}
|
||||
|
||||
// The warning should not be printed when --json is specified
|
||||
if (warnings.length > 0 && !cliOptions.json) {
|
||||
console.log(warnings.map((warning) => formatWarn(warning)).join('\n'))
|
||||
if (warnings.length > 0) {
|
||||
console.warn(warnings.map((warning) => formatWarn(warning)).join('\n'))
|
||||
}
|
||||
|
||||
return config
|
||||
|
||||
@@ -4,11 +4,11 @@ import { getConfig } from '@pnpm/cli-utils'
|
||||
import { prepare } from '@pnpm/prepare'
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(console, 'log')
|
||||
jest.spyOn(console, 'warn')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
(console.log as jest.Mock).mockRestore()
|
||||
(console.warn as jest.Mock).mockRestore()
|
||||
})
|
||||
|
||||
test('console a warning when the .npmrc has an env variable that does not exist', async () => {
|
||||
@@ -25,22 +25,5 @@ test('console a warning when the .npmrc has an env variable that does not exist'
|
||||
})
|
||||
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Failed to replace env in config: ${ENV_VAR_123}'))
|
||||
})
|
||||
|
||||
test('should not console a warning when --json is specified', async () => {
|
||||
prepare()
|
||||
|
||||
fs.writeFileSync('.npmrc', 'foo=${ENV_VAR_123}', 'utf8') // eslint-disable-line
|
||||
|
||||
await getConfig({
|
||||
json: true,
|
||||
}, {
|
||||
workspaceDir: '.',
|
||||
excludeReporter: false,
|
||||
rcOptionsTypes: {},
|
||||
})
|
||||
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
expect(console.log).not.toHaveBeenCalledWith(expect.stringContaining('Failed to replace env in config: ${ENV_VAR_123}'))
|
||||
expect(console.warn).toHaveBeenCalledWith(expect.stringContaining('Failed to replace env in config: ${ENV_VAR_123}'))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user