From 9e914288fa3b68c2db33138844f23a77cbc44624 Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Fri, 29 Jul 2022 11:38:36 +0200 Subject: [PATCH] add option to specify environment variables --- README.md | 10 ++++++++-- plugin.d.ts | 1 + plugin.js | 20 ++++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3544c71..505035e 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ The minimum required `wasm-pack` version is `0.8.0` ## Linting -This project uses the `prettier` with default configuration. Fo manually format the code run the `lint:fix` script. +This project uses the `prettier` with default configuration. To manually format the code run the `lint:fix` script. ## Usage @@ -79,7 +79,13 @@ module.exports = { // Controls plugin output verbosity, either 'info' or 'error'. // Defaults to 'info'. - // pluginLogLevel: 'info' + // pluginLogLevel: 'info', + + // If defined, sets the specified environment variables during compilation. + // + // env: { + // WASM_BINDGEN_THREADS_STACK_SIZE: 128 * 2 ** 10 + // } }), ], diff --git a/plugin.d.ts b/plugin.d.ts index 764cc89..1b0343d 100644 --- a/plugin.d.ts +++ b/plugin.d.ts @@ -11,6 +11,7 @@ export interface WasmPackPluginOptions { watchDirectories?: string[] /** Controls plugin output verbosity. Defaults to 'info'. */ pluginLogLevel?: 'info' | 'error' + env?: Record } export default class WasmPackPlugin { diff --git a/plugin.js b/plugin.js index df1597d..2c3b549 100644 --- a/plugin.js +++ b/plugin.js @@ -123,7 +123,7 @@ class WasmPackPlugin { _makeEmpty() { try { - fs.mkdirSync(this.outDir, {recursive: true}) + fs.mkdirSync(this.outDir, { recursive: true }) } catch (e) { if (e.code !== 'EEXIST') { throw e @@ -178,6 +178,7 @@ class WasmPackPlugin { cwd: this.crateDirectory, args: this.args, extraArgs: this.extraArgs, + env: this.env, }) }) .then((detail) => { @@ -203,7 +204,15 @@ class WasmPackPlugin { } } -function spawnWasmPack({ outDir, outName, isDebug, cwd, args, extraArgs }) { +function spawnWasmPack({ + outDir, + outName, + isDebug, + cwd, + args, + extraArgs, + env, +}) { const bin = findWasmPack() const allArgs = [ @@ -220,6 +229,13 @@ function spawnWasmPack({ outDir, outName, isDebug, cwd, args, extraArgs }) { const options = { cwd, stdio: 'inherit', + env: + env != null + ? { + ...process.env, + ...env, + } + : undefined, } return runProcess(bin, allArgs, options)