diff --git a/plugin.js b/plugin.js index 28b9018..4c3ed58 100644 --- a/plugin.js +++ b/plugin.js @@ -7,8 +7,12 @@ const Watchpack = require('watchpack'); const which = require('which'); const { homedir } = require('os'); -const error = msg => console.error(chalk.bold.red(msg)); -let info = msg => console.log(chalk.bold.blue(msg)); +let logger; + +const error = msg => logger.error(chalk.bold.red(msg)); +let info = msg => logger.log(chalk.bold.blue(msg)); + +const PLUGIN_NAME = 'wasm-pack-plugin'; function findWasmPack() { // https://github.com/wasm-tool/wasm-pack-plugin/issues/58 @@ -60,6 +64,9 @@ class WasmPackPlugin { } apply(compiler) { + // you can access Logger from compiler + logger = compiler.getInfrastructureLogger(PLUGIN_NAME); + this.isDebug = this.forceMode ? this.forceMode === "development" : compiler.options.mode === "development"; // This fixes an error in Webpack where it cannot find @@ -125,15 +132,15 @@ class WasmPackPlugin { } async _checkWasmPack() { - info('🧐 Checking for wasm-pack...\n'); + info('🧐 Checking for wasm-pack...'); const bin = findWasmPack(); if (bin) { - info('✅ wasm-pack is installed at ' + bin + '. \n'); + info('✅ wasm-pack is installed at ' + bin + '. '); return true; } - info('â„šī¸ Installing wasm-pack \n'); + info('â„šī¸ Installing wasm-pack '); if (commandExistsSync("npm")) { return runProcess("npm", ["install", "-g", "wasm-pack"], {}); @@ -148,7 +155,7 @@ class WasmPackPlugin { } _compile(watching) { - info(`â„šī¸ Compiling your crate in ${this.isDebug ? 'development' : 'release'} mode...\n`); + info(`â„šī¸ Compiling your crate in ${this.isDebug ? 'development' : 'release'} mode...`); return fs.promises.stat(this.crateDirectory).then(stats => { if (!stats.isDirectory()) { @@ -171,7 +178,7 @@ class WasmPackPlugin { info(detail); } - info('✅ Your crate has been correctly compiled\n'); + info('✅ Your crate has been correctly compiled'); }) .catch((e) => { // Webpack has a custom error system, so we cannot return an