fix: aviod error log cut (#3951)

Co-authored-by: yuhuaheng <yuhuaheng@bytedance.com>
Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Erik Yu
2021-11-07 19:00:28 +08:00
committed by GitHub
parent 5e5185192c
commit 8cde329876
6 changed files with 33 additions and 11 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-publishing": patch
"@pnpm/plugin-commands-script-runners": patch
---
Return the exit code instead of killing the process.

View File

@@ -0,0 +1,5 @@
---
"pnpm": patch
---
The CLI should not exit before all the output is printed [#3526](https://github.com/pnpm/pnpm/issues/3526).

View File

@@ -191,7 +191,7 @@ Do you want to continue?`,
}
if (status != null && status !== 0) {
process.exit(status)
return { exitCode: status }
}
if (!opts.ignoreScripts) {
await _runScriptsIfPresent([

View File

@@ -130,7 +130,9 @@ export async function handler (
result.passes++
} catch (err: any) { // eslint-disable-line
if (!opts.recursive && typeof err.exitCode === 'number') {
process.exit(err.exitCode)
return {
exitCode: err.exitCode,
}
}
logger.info(err)
@@ -149,6 +151,7 @@ export async function handler (
/* eslint-enable @typescript-eslint/dot-notation */
throw err
}
return { exitCode: 0 }
}
)))
}

View File

@@ -3,10 +3,12 @@ import logger from '@pnpm/logger'
export default function err (error: Error) {
if (!global['reporterInitialized']) {
console.log(error)
process.exit(1)
process.exitCode = 1
return
}
if (global['reporterInitialized'] === 'silent') {
process.exit(1)
process.exitCode = 1
return
}
if (error.name != null && error.name !== 'pnpm' && !error.name.startsWith('pnpm:')) {
error.name = 'pnpm'

View File

@@ -47,7 +47,8 @@ export default async function run (inputArgv: string[]) {
} catch (err: any) { // eslint-disable-line
// Reporting is not initialized at this point, so just printing the error
printError(err.message, err['hint'])
process.exit(1)
process.exitCode = 1
return
}
const {
argv,
@@ -60,7 +61,8 @@ export default async function run (inputArgv: string[]) {
} = parsedCliArgs
if (cmd !== null && !pnpmCmds[cmd]) {
printError(`Unknown command '${cmd}'`, 'For help, run: pnpm help')
process.exit(1)
process.exitCode = 1
return
}
if (unknownOptions.size > 0 && !fallbackCommandUsed) {
@@ -75,7 +77,8 @@ export default async function run (inputArgv: string[]) {
console.log(deprecationMsg)
} else {
printError(formatUnknownOptionsError(unknownOptions), `For help, run: pnpm help${cmd ? ` ${cmd}` : ''}`)
process.exit(1)
process.exitCode = 1
return
}
}
process.env['npm_config_argv'] = JSON.stringify(argv)
@@ -103,7 +106,8 @@ export default async function run (inputArgv: string[]) {
// Reporting is not initialized at this point, so just printing the error
const hint = err['hint'] ? err['hint'] : `For help, run: pnpm help${cmd ? ` ${cmd}` : ''}`
printError(err.message, hint)
process.exit(1)
process.exitCode = 1
return
}
let write: (text: string) => void = process.stdout.write.bind(process.stdout)
@@ -171,7 +175,8 @@ export default async function run (inputArgv: string[]) {
if (printLogs) {
console.log(`No projects found in "${wsDir}"`)
}
process.exit(0)
process.exitCode = 0
return
}
config.filter = config.filter ?? []
@@ -201,7 +206,8 @@ export default async function run (inputArgv: string[]) {
if (printLogs) {
console.log(`No projects matched the filters in "${wsDir}"`)
}
process.exit(0)
process.exitCode = 0
return
}
if (filterResults.unmatchedFilters.length !== 0 && printLogs) {
console.log(`No projects matched the filters "${filterResults.unmatchedFilters.join(', ')}" in "${wsDir}"`)
@@ -278,7 +284,7 @@ export default async function run (inputArgv: string[]) {
// In this case, the non-zero exit code is expected,
// so there is no need to write a debug file.
global['writeDebugLogFile'] = false
process.exit(exitCode)
process.exitCode = exitCode
}
}