Skip to content

Commit eb0ac9d

Browse files
committed
Warn on multiple simultaneous invocations, vs erroring out.
1 parent fcf3e3a commit eb0ac9d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

plugin.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const which = require('which')
88
const { homedir } = require('os')
99

1010
const error = (msg) => console.error(chalk.bold.red(msg))
11+
const warn = (msg) => console.warn(chalk.bold.yellow(msg))
1112
let info = (msg) => console.log(chalk.bold.blue(msg))
1213

1314
function findWasmPack() {
@@ -150,7 +151,7 @@ class WasmPackPlugin {
150151
return runProcess('yarn', ['global', 'add', 'wasm-pack'], {})
151152
} else {
152153
error(
153-
'⚠️ could not install wasm-pack, you must have yarn or npm installed'
154+
' could not install wasm-pack, you must have yarn or npm installed'
154155
)
155156
}
156157
return false
@@ -225,8 +226,20 @@ function spawnWasmPack({ outDir, outName, isDebug, cwd, args, extraArgs }) {
225226
return runProcess(bin, allArgs, options)
226227
}
227228

229+
let previousRun = Promise.resolve();
230+
const isRunning = Symbol('running')
228231
function runProcess(bin, args, options) {
229-
return new Promise((resolve, reject) => {
232+
return previousRun = new Promise(async (resolve, reject) => {
233+
Promise.race([previousRun, isRunning]).then(status => {
234+
if (status === isRunning) {
235+
warn(`⚠️ Rust compilation invoked more than once at the same time.`)
236+
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`)
237+
}
238+
})
239+
240+
// Don't run two Rust compilers at once - the compilers will interfere
241+
// with each other, one will fail, and the build process will fail.
242+
await previousRun.finally()
230243
const p = spawn(bin, args, options)
231244

232245
p.on('close', (code) => {

0 commit comments

Comments
 (0)