Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add logger #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 14 additions & 7 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"], {});
Expand All @@ -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()) {
Expand All @@ -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
Expand Down