Skip to content

Commit caca20d

Browse files
authored
Merge pull request #68 from jstarry/master
Display error message when crate directory does not exist
2 parents ae67484 + 82e8db9 commit caca20d

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

plugin.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,33 +117,38 @@ class WasmPackPlugin {
117117
_compile(watching) {
118118
info(`ℹ️ Compiling your crate in ${this.isDebug ? 'development' : 'release'} mode...\n`);
119119

120-
return spawnWasmPack({
120+
return fs.promises.stat(this.crateDirectory).then(stats => {
121+
if (!stats.isDirectory()) {
122+
throw new Error(`${this.crateDirectory} is not a directory`);
123+
}
124+
}).then(() => {
125+
return spawnWasmPack({
121126
outDir: this.outDir,
122127
outName: this.outName,
123128
isDebug: this.isDebug,
124129
cwd: this.crateDirectory,
125130
extraArgs: this.extraArgs,
126-
})
127-
.then((detail) => {
128-
// This clears out the error when the compilation succeeds.
129-
this.error = null;
131+
});
132+
}).then((detail) => {
133+
// This clears out the error when the compilation succeeds.
134+
this.error = null;
130135

131-
if (detail) {
132-
info(detail);
133-
}
136+
if (detail) {
137+
info(detail);
138+
}
134139

135-
info('✅ Your crate has been correctly compiled\n');
136-
})
137-
.catch((e) => {
138-
// Webpack has a custom error system, so we cannot return an
139-
// error directly, instead we need to trigger it later.
140-
this.error = e;
140+
info('✅ Your crate has been correctly compiled\n');
141+
})
142+
.catch((e) => {
143+
// Webpack has a custom error system, so we cannot return an
144+
// error directly, instead we need to trigger it later.
145+
this.error = e;
141146

142-
if (watching) {
143-
// This is to trigger a recompilation so it displays the error message
144-
this._makeEmpty();
145-
}
146-
});
147+
if (watching) {
148+
// This is to trigger a recompilation so it displays the error message
149+
this._makeEmpty();
150+
}
151+
});
147152
}
148153
}
149154

0 commit comments

Comments
 (0)