From 3aecbfccd2a3eef5cf4889432550423fd594e876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Wed, 29 May 2024 10:53:55 +0100 Subject: [PATCH] feat: log plugin initialisation error on single line (#5684) --- packages/build/src/plugins/system_log.ts | 14 ++++++-------- packages/build/tests/plugins/tests.js | 4 +--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/build/src/plugins/system_log.ts b/packages/build/src/plugins/system_log.ts index fa90a81f74..caad1bc840 100644 --- a/packages/build/src/plugins/system_log.ts +++ b/packages/build/src/plugins/system_log.ts @@ -15,22 +15,20 @@ export const captureStandardError = ( } } - let receivedChunks = false + let buffer = '' const listener = (chunk: Buffer) => { - if (!receivedChunks) { - receivedChunks = true - - systemLog(`Plugin failed to initialize during the "${eventName}" phase`) - } - - systemLog(chunk.toString().trimEnd()) + buffer += chunk.toString() } childProcess.stderr?.on('data', listener) const cleanup = () => { childProcess.stderr?.removeListener('data', listener) + + if (buffer.length !== 0) { + systemLog(`Plugin failed to initialize during the "${eventName}" phase: ${buffer.trim()}`) + } } return cleanup diff --git a/packages/build/tests/plugins/tests.js b/packages/build/tests/plugins/tests.js index 630b1f6d6f..9bea23fe4c 100644 --- a/packages/build/tests/plugins/tests.js +++ b/packages/build/tests/plugins/tests.js @@ -360,10 +360,8 @@ test('Plugin errors that occur during the loading phase are piped to system logs if (platform !== 'win32') { const systemLog = await fs.readFile(systemLogFile.path, { encoding: 'utf8' }) - const lines = systemLog.split('\n') - t.is(lines[0].trim(), 'Plugin failed to initialize during the "load" phase') - t.is(lines[1].trim(), 'An error message thrown by Node.js') + t.is(systemLog.trim(), `Plugin failed to initialize during the "load" phase: An error message thrown by Node.js`) } t.snapshot(normalizeOutput(output))