mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix(log): line key does not necessarily exist (#5588)
Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
6
.changeset/lucky-eyes-double.md
Normal file
6
.changeset/lucky-eyes-double.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/default-reporter": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
The reporter should not crash when the CLI process is kill during lifecycle scripts execution [#5588](https://github.com/pnpm/pnpm/pull/5588).
|
||||
5
.changeset/moody-weeks-reply.md
Normal file
5
.changeset/moody-weeks-reply.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/lifecycle": patch
|
||||
---
|
||||
|
||||
Never log a lifecycle exit debug log without an exit code [#5588](https://github.com/pnpm/pnpm/pull/5588).
|
||||
@@ -266,6 +266,7 @@ function formatLine (maxWidth: number, logObj: LifecycleLog) {
|
||||
}
|
||||
|
||||
function cutLine (line: string, maxLength: number) {
|
||||
if (!line) return '' // This actually should never happen but it is better to be safe
|
||||
return stripAnsi(line).slice(0, maxLength)
|
||||
}
|
||||
|
||||
|
||||
@@ -739,6 +739,52 @@ ${STATUS_INDENTATION} ${STATUS_FAILED}`)
|
||||
})
|
||||
})
|
||||
|
||||
test('do not fail if the debug log has no output', (done) => {
|
||||
const output$ = toOutput$({
|
||||
context: { argv: ['install'] },
|
||||
reportingOptions: { outputMaxWidth: 79 },
|
||||
streamParser: createStreamParser(),
|
||||
})
|
||||
|
||||
const wd = path.resolve(process.cwd(), 'node_modules', '.registry.npmjs.org', 'foo', '1.0.0', 'node_modules', 'foo')
|
||||
|
||||
lifecycleLogger.debug({
|
||||
depPath: 'registry.npmjs.org/foo/1.0.0',
|
||||
optional: false,
|
||||
script: 'node foo',
|
||||
stage: 'install',
|
||||
wd,
|
||||
})
|
||||
lifecycleLogger.debug({
|
||||
depPath: 'registry.npmjs.org/foo/1.0.0',
|
||||
line: undefined as any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
stage: 'install',
|
||||
stdio: 'stdout',
|
||||
wd,
|
||||
})
|
||||
lifecycleLogger.debug({
|
||||
depPath: 'registry.npmjs.org/foo/1.0.0',
|
||||
exitCode: 1,
|
||||
optional: false,
|
||||
stage: 'install',
|
||||
wd,
|
||||
})
|
||||
|
||||
expect.assertions(1)
|
||||
|
||||
output$.pipe(skip(1), take(1), map(normalizeNewline)).subscribe({
|
||||
complete: () => done(),
|
||||
error: done,
|
||||
next: (output: string) => {
|
||||
expect(replaceTimeWith1Sec(output)).toBe(`\
|
||||
${chalk.gray('node_modules/.registry.npmjs.org/foo/1.0.0/node_modules/')}foo: Running install script, failed in 1s
|
||||
.../foo/1.0.0/node_modules/foo ${INSTALL}$ node foo
|
||||
${OUTPUT_INDENTATION}
|
||||
${STATUS_INDENTATION} ${STATUS_FAILED}`)
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
// Many libs use stderr for logging, so showing all stderr adds not much value
|
||||
test['skip']('prints lifecycle progress', (done) => {
|
||||
const output$ = toOutput$({
|
||||
|
||||
@@ -100,7 +100,7 @@ export async function runLifecycleHook (
|
||||
// Preventing the pnpm reporter from overriding the project's script output
|
||||
return
|
||||
}
|
||||
const code = arguments[3]
|
||||
const code = arguments[3] ?? 1
|
||||
lifecycleLogger.debug({
|
||||
depPath: opts.depPath,
|
||||
exitCode: code,
|
||||
|
||||
Reference in New Issue
Block a user