Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Or with Yarn:
yarn add --dev @wasm-tool/wasm-pack-plugin
```

Or with Pnpm:
```sh
pnpm add -D @wasm-tool/wasm-pack-plugin
```

### `wasm-pack`

We expect `wasm-pack` to be in your `$PATH`. See [installation here](https://rustwasm.github.io/wasm-pack/installer).
Expand Down Expand Up @@ -74,7 +79,9 @@ module.exports = {

// Controls plugin output verbosity, either 'info' or 'error'.
// Defaults to 'info'.
// pluginLogLevel: 'info'
// pluginLogLevel: 'info',
// // Controls which package manager will be used to install the wasm-pack.
// packageManager: 'npm', //Options are [npm|yarn|pnpm]
}),

]
Expand Down
1 change: 1 addition & 0 deletions plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface WasmPackPluginOptions {
watchDirectories?: string[];
/** Controls plugin output verbosity. Defaults to 'info'. */
pluginLogLevel?: 'info' | 'error';
packageManager: 'npm' | 'yarn' | 'pnpm'
}

export default class WasmPackPlugin {
Expand Down
7 changes: 5 additions & 2 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class WasmPackPlugin {
this.watchDirectories = (options.watchDirectories || [])
.concat(path.resolve(this.crateDirectory, 'src'));
this.watchFiles = [path.resolve(this.crateDirectory, 'Cargo.toml')];
this.packageManager = options.packageManager ? options.packageManager : 'npm';

if (options.pluginLogLevel && options.pluginLogLevel !== 'info') {
// The default value for pluginLogLevel is 'info'. If specified and it's
Expand Down Expand Up @@ -135,10 +136,12 @@ class WasmPackPlugin {

info('ℹ️ Installing wasm-pack \n');

if (commandExistsSync("npm")) {
if (this.packageManager === 'npm' && commandExistsSync("npm")) {
return runProcess("npm", ["install", "-g", "wasm-pack"], {});
} else if (commandExistsSync("yarn")) {
} else if (this.packageManager === 'yarn' && commandExistsSync("yarn")) {
return runProcess("yarn", ["global", "add", "wasm-pack"], {});
} else if (this.packageManager === 'pnpm' && commandExistsSync("pnpm")) {
return runProcess("pnpm", ["add", "--global", "wasm-pack"], {});
} else {
error(
"⚠️ could not install wasm-pack, you must have yarn or npm installed"
Expand Down