From 1d69fe6c78c63958aec86611e9aea78619f8fa92 Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 29 Mar 2021 13:58:34 -0500 Subject: [PATCH] fix: forward exit codes --- packages/build/src/build.js | 39 +++++++++++++++---------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/packages/build/src/build.js b/packages/build/src/build.js index 12d888e..e6edbae 100755 --- a/packages/build/src/build.js +++ b/packages/build/src/build.js @@ -21,6 +21,15 @@ const localConfig = (filename) => { return configFile; }; +const forwardProcessCode = (child) => new Promise((resolve, reject) => { + child.on('error', reject); + child.on('exit', (code) => { + child.off('error', reject); + process.exitCode = code; + resolve(); + }); +}); + const build = async (args = []) => { const {production} = program.opts(); const babelConfigFile = localConfig('.babelrc.js'); @@ -53,13 +62,7 @@ const build = async (args = []) => { stdio: 'inherit', }, ); - return new Promise((resolve, reject) => { - child.on('error', reject); - child.on('exit', (code) => { - child.off('error', reject); - resolve(code); - }); - }); + return forwardProcessCode(child); }; program @@ -106,13 +109,7 @@ const unpublish = async () => { stdio: 'inherit', }, ); - return new Promise((resolve, reject) => { - child.on('error', reject); - child.on('exit', (code) => { - child.off('error', reject); - resolve(code); - }); - }); + return forwardProcessCode(child); }; const publish = async () => { @@ -125,13 +122,7 @@ const publish = async () => { stdio: 'inherit', }, ); - return new Promise((resolve, reject) => { - child.on('error', reject); - child.on('exit', (code) => { - child.off('error', reject); - resolve(code); - }); - }); + return forwardProcessCode(child); }; program @@ -145,7 +136,7 @@ program const lint = () => { const configFile = localConfig('.eslintrc.js'); - spawn( + const child = spawn( 'eslint', [ '--config', @@ -164,6 +155,7 @@ const lint = () => { stdio: 'inherit', }, ); + return forwardProcessCode(child); }; program @@ -178,7 +170,7 @@ const test = async () => { process.argv.splice(watchIndex, 1); } await build(['--display', 'none']); - spawn( + const child = spawn( 'mocha', (-1 === watchIndex ? [] : ['--watch']) .concat([ @@ -193,6 +185,7 @@ const test = async () => { stdio: 'inherit', }, ); + return forwardProcessCode(child); }; program