mirror of
https://github.com/developit/microbundle.git
synced 2026-01-25 14:06:50 +00:00
Merge pull request #153 from mattdesl/fix/111
Fix #111 and log errors during watch mode
This commit is contained in:
commit
8286def15f
30
src/cli.js
30
src/cli.js
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
import chalk from 'chalk';
|
||||
import microbundle from '.';
|
||||
import prog from './prog';
|
||||
import { stdout, stderr } from './utils';
|
||||
import { stdout } from './utils';
|
||||
import logError from './log-error';
|
||||
|
||||
const run = opts => {
|
||||
microbundle(opts)
|
||||
@ -12,31 +12,7 @@ const run = opts => {
|
||||
})
|
||||
.catch(err => {
|
||||
process.exitCode = (typeof err.code === 'number' && err.code) || 1;
|
||||
|
||||
const error = err.error || err;
|
||||
const description = `${
|
||||
error.name ? error.name + ': ' : ''
|
||||
}${error.message || error}`;
|
||||
const message = error.plugin
|
||||
? `(${error.plugin} plugin) ${description}`
|
||||
: description;
|
||||
|
||||
stderr(chalk.bold.red(message));
|
||||
|
||||
if (error.loc) {
|
||||
stderr();
|
||||
stderr(`at ${error.loc.file}:${error.loc.line}:${error.loc.column}`);
|
||||
}
|
||||
|
||||
if (error.frame) {
|
||||
stderr();
|
||||
stderr(chalk.dim(error.frame));
|
||||
} else if (err.stack) {
|
||||
const headlessStack = error.stack.replace(message, '');
|
||||
stderr(chalk.dim(headlessStack));
|
||||
}
|
||||
|
||||
stderr();
|
||||
logError(err);
|
||||
process.exit();
|
||||
});
|
||||
};
|
||||
|
||||
@ -19,6 +19,7 @@ import prettyBytes from 'pretty-bytes';
|
||||
import shebangPlugin from 'rollup-plugin-preserve-shebang';
|
||||
import typescript from 'rollup-plugin-typescript2';
|
||||
import flow from './lib/flow-plugin';
|
||||
import logError from './log-error';
|
||||
import { readFile, isDir, isFile, stdout, stderr } from './utils';
|
||||
import camelCase from 'camelcase';
|
||||
|
||||
@ -162,8 +163,10 @@ export default async function microbundle(options) {
|
||||
options.inputOptions,
|
||||
),
|
||||
).on('event', e => {
|
||||
if (e.code === 'ERROR' || e.code === 'FATAL') {
|
||||
return reject(e);
|
||||
if (e.code === 'FATAL') {
|
||||
return reject(e.error);
|
||||
} else if (e.code === 'ERROR') {
|
||||
logError(e.error);
|
||||
}
|
||||
if (e.code === 'END') {
|
||||
getSizeInfo(options._code, options.outputOptions.file).then(
|
||||
|
||||
28
src/log-error.js
Normal file
28
src/log-error.js
Normal file
@ -0,0 +1,28 @@
|
||||
import chalk from 'chalk';
|
||||
import { stderr } from './utils';
|
||||
|
||||
export default function(err) {
|
||||
const error = err.error || err;
|
||||
const description = `${error.name ? error.name + ': ' : ''}${error.message ||
|
||||
error}`;
|
||||
const message = error.plugin
|
||||
? `(${error.plugin} plugin) ${description}`
|
||||
: description;
|
||||
|
||||
stderr(chalk.bold.red(message));
|
||||
|
||||
if (error.loc) {
|
||||
stderr();
|
||||
stderr(`at ${error.loc.file}:${error.loc.line}:${error.loc.column}`);
|
||||
}
|
||||
|
||||
if (error.frame) {
|
||||
stderr();
|
||||
stderr(chalk.dim(error.frame));
|
||||
} else if (err.stack) {
|
||||
const headlessStack = error.stack.replace(message, '');
|
||||
stderr(chalk.dim(headlessStack));
|
||||
}
|
||||
|
||||
stderr();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user