mirror of https://github.com/lukechilds/rollup.git
Rich Harris
8 years ago
3 changed files with 151 additions and 170 deletions
@ -1,65 +0,0 @@ |
|||||
import chalk from 'chalk'; |
|
||||
|
|
||||
function stderr ( msg ) { |
|
||||
console.error( msg ); // eslint-disable-line no-console
|
|
||||
} |
|
||||
|
|
||||
const handlers = { |
|
||||
MISSING_CONFIG: () => { |
|
||||
stderr( chalk.red( 'Config file must export an options object. See https://github.com/rollup/rollup/wiki/Command-Line-Interface#using-a-config-file' ) ); |
|
||||
}, |
|
||||
|
|
||||
MISSING_EXTERNAL_CONFIG: err => { |
|
||||
stderr( chalk.red( `Could not resolve config file ${err.config}` ) ); |
|
||||
}, |
|
||||
|
|
||||
MISSING_INPUT_OPTION: () => { |
|
||||
stderr( chalk.red( 'You must specify an --input (-i) option' ) ); |
|
||||
}, |
|
||||
|
|
||||
MISSING_OUTPUT_OPTION: () => { |
|
||||
stderr( chalk.red( 'You must specify an --output (-o) option when creating a file with a sourcemap' ) ); |
|
||||
}, |
|
||||
|
|
||||
MISSING_NAME: () => { |
|
||||
stderr( chalk.red( 'You must supply a name for UMD exports (e.g. `--name myModule`)' ) ); |
|
||||
}, |
|
||||
|
|
||||
PARSE_ERROR: err => { |
|
||||
stderr( chalk.red( `Error parsing ${err.file}: ${err.message}` ) ); |
|
||||
}, |
|
||||
|
|
||||
ONE_AT_A_TIME: () => { |
|
||||
stderr( chalk.red( 'rollup can only bundle one file at a time' ) ); |
|
||||
}, |
|
||||
|
|
||||
DUPLICATE_IMPORT_OPTIONS: () => { |
|
||||
stderr( chalk.red( 'use --input, or pass input path as argument' ) ); |
|
||||
}, |
|
||||
|
|
||||
ROLLUP_WATCH_NOT_INSTALLED: () => { |
|
||||
stderr( chalk.red( 'rollup --watch depends on the rollup-watch package, which could not be found. Install it with ' ) + chalk.cyan( 'npm install -D rollup-watch' ) ); |
|
||||
}, |
|
||||
|
|
||||
WATCHER_MISSING_INPUT_OR_OUTPUT: () => { |
|
||||
stderr( chalk.red( 'must specify --input and --output when using rollup --watch' ) ); |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
export default function handleError ( err, recover ) { |
|
||||
const handler = handlers[ err && err.code ]; |
|
||||
|
|
||||
if ( handler ) { |
|
||||
handler( err ); |
|
||||
} else { |
|
||||
stderr( chalk.red( err.message || err ) ); |
|
||||
|
|
||||
if ( err.stack ) { |
|
||||
stderr( chalk.grey( err.stack ) ); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
stderr( `Type ${chalk.cyan( 'rollup --help' )} for help, or visit https://github.com/rollup/rollup/wiki` ); |
|
||||
|
|
||||
if ( !recover ) process.exit( 1 ); |
|
||||
} |
|
@ -0,0 +1,47 @@ |
|||||
|
import chalk from 'chalk'; |
||||
|
import relativeId from '../../src/utils/relativeId.js'; |
||||
|
|
||||
|
if ( !process.stderr.isTTY ) chalk.enabled = false; |
||||
|
const warnSymbol = process.stderr.isTTY ? `⚠️ ` : `Warning: `; |
||||
|
const errorSymbol = process.stderr.isTTY ? `🚨 ` : `Error: `; |
||||
|
|
||||
|
// log to stderr to keep `rollup main.js > bundle.js` from breaking
|
||||
|
export const stderr = console.error.bind( console ); // eslint-disable-line no-console
|
||||
|
|
||||
|
export function handleWarning ( warning ) { |
||||
|
stderr( `${warnSymbol}${chalk.bold( warning.message )}` ); |
||||
|
|
||||
|
if ( warning.url ) { |
||||
|
stderr( chalk.cyan( warning.url ) ); |
||||
|
} |
||||
|
|
||||
|
if ( warning.loc ) { |
||||
|
stderr( `${relativeId( warning.loc.file )} (${warning.loc.line}:${warning.loc.column})` ); |
||||
|
} |
||||
|
|
||||
|
if ( warning.frame ) { |
||||
|
stderr( chalk.dim( warning.frame ) ); |
||||
|
} |
||||
|
|
||||
|
stderr( '' ); |
||||
|
} |
||||
|
|
||||
|
export function handleError ( err, recover ) { |
||||
|
stderr( `${errorSymbol}${chalk.bold( err.message )}` ); |
||||
|
|
||||
|
if ( err.url ) { |
||||
|
stderr( chalk.cyan( err.url ) ); |
||||
|
} |
||||
|
|
||||
|
if ( err.loc ) { |
||||
|
stderr( `${relativeId( err.loc.file )} (${err.loc.line}:${err.loc.column})` ); |
||||
|
} |
||||
|
|
||||
|
if ( err.frame ) { |
||||
|
stderr( chalk.dim( err.frame ) ); |
||||
|
} |
||||
|
|
||||
|
stderr( '' ); |
||||
|
|
||||
|
if ( !recover ) process.exit( 1 ); |
||||
|
} |
Loading…
Reference in new issue