From fcf3e3ad3aaab11e762846dce005381be82ee20c Mon Sep 17 00:00:00 2001 From: David Roberts Date: Fri, 1 Jul 2022 10:33:00 -0700 Subject: [PATCH 1/2] Improved error message for if Rust compilation fails. Say, if you accidentally launched two processes simultaneously... --- plugin.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin.js b/plugin.js index df1597d..10278cf 100644 --- a/plugin.js +++ b/plugin.js @@ -233,11 +233,15 @@ function runProcess(bin, args, options) { if (code === 0) { resolve() } else { + error(`❌ Rust compilation process failed with exit code ${code}:\n${bin} ${args.join(' ')}\n with ${JSON.stringify(options, '\t')}`) reject(new Error('Rust compilation.')) } }) - p.on('error', reject) + p.on('error', (err) => { + error(`❌ Rust compilation process failed to run with ${err}:\n${bin} ${args.join(' ')}\n with ${JSON.stringify(options, '\t')}`) + reject(err) + }) }) } From 35691c44791890f1ee360c73d44a9a06f8658731 Mon Sep 17 00:00:00 2001 From: DDR Date: Fri, 1 Jul 2022 11:43:21 -0700 Subject: [PATCH 2/2] Warn on multiple simultaneous invocations, vs erroring out. --- plugin.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/plugin.js b/plugin.js index 10278cf..1c18067 100644 --- a/plugin.js +++ b/plugin.js @@ -8,6 +8,7 @@ const which = require('which') const { homedir } = require('os') const error = (msg) => console.error(chalk.bold.red(msg)) +const warn = (msg) => console.warn(chalk.bold.yellow(msg)) let info = (msg) => console.log(chalk.bold.blue(msg)) function findWasmPack() { @@ -150,7 +151,7 @@ class WasmPackPlugin { return runProcess('yarn', ['global', 'add', 'wasm-pack'], {}) } else { error( - '⚠️ could not install wasm-pack, you must have yarn or npm installed' + '❌ could not install wasm-pack, you must have yarn or npm installed' ) } return false @@ -225,8 +226,24 @@ function spawnWasmPack({ outDir, outName, isDebug, cwd, args, extraArgs }) { return runProcess(bin, allArgs, options) } +let previousRun = Promise.resolve(); +const isRunning = Symbol('running') function runProcess(bin, args, options) { - return new Promise((resolve, reject) => { + return previousRun = new Promise(async (resolve, reject) => { + Promise.race([previousRun, isRunning]).then(status => { + if (status === isRunning) { + warn(`⚠️ Rust compilation invoked more than once at the same time.`) + info(`ℹ️ This will work with some speed penalty, but it represents an error in your webpack configuration and is not guaranteed to continue working.\n`) + } + }) + + // Don't run two Rust compilers at once - the compilers will interfere + // with each other, one will fail, and the build process will fail. + try { + await previousRun.finally() + } catch (e) { + /*don't care, done*/ + } const p = spawn(bin, args, options) p.on('close', (code) => {