Improve formatting of errors when building (#11456)
* Improve formatting of errors when building * Remove undefined from the header when error.plugin is undefined * Add babel-code-frame and syntax highlighting in error message * Run yarn prettier and fix code format
This commit is contained in:
parent
aa0b7418c1
commit
962042f827
|
@ -8,6 +8,7 @@
|
|||
"art": "^0.10.1",
|
||||
"async": "^1.5.0",
|
||||
"babel-cli": "^6.6.5",
|
||||
"babel-code-frame": "^6.26.0",
|
||||
"babel-core": "^6.0.0",
|
||||
"babel-eslint": "^7.1.0",
|
||||
"babel-jest": "^21.3.0-beta.4",
|
||||
|
|
|
@ -25,6 +25,7 @@ const syncReactNative = require('./sync').syncReactNative;
|
|||
const syncReactNativeRT = require('./sync').syncReactNativeRT;
|
||||
const syncReactNativeCS = require('./sync').syncReactNativeCS;
|
||||
const Packaging = require('./packaging');
|
||||
const codeFrame = require('babel-code-frame');
|
||||
const Wrappers = require('./wrappers');
|
||||
|
||||
const UMD_DEV = Bundles.bundleTypes.UMD_DEV;
|
||||
|
@ -407,10 +408,21 @@ function createBundle(bundle, bundleType) {
|
|||
})
|
||||
.catch(error => {
|
||||
if (error.code) {
|
||||
console.error(`\x1b[31m-- ${error.code} (${error.plugin}) --`);
|
||||
console.error(
|
||||
`\x1b[31m-- ${error.code}${
|
||||
error.plugin ? ` (${error.plugin})` : ''
|
||||
} --`
|
||||
);
|
||||
console.error(error.message);
|
||||
console.error(error.loc);
|
||||
console.error(error.codeFrame);
|
||||
|
||||
const {file, line, column} = error.loc;
|
||||
const rawLines = fs.readFileSync(file, 'utf-8');
|
||||
// column + 1 is required due to rollup counting column start position from 0
|
||||
// whereas babel-code-frame counts from 1
|
||||
const frame = codeFrame(rawLines, line, column + 1, {
|
||||
highlightCode: true,
|
||||
});
|
||||
console.error(frame);
|
||||
} else {
|
||||
console.error(error);
|
||||
}
|
||||
|
|
10
yarn.lock
10
yarn.lock
|
@ -274,6 +274,14 @@ babel-code-frame@^6.16.0, babel-code-frame@^6.22.0:
|
|||
esutils "^2.0.2"
|
||||
js-tokens "^3.0.0"
|
||||
|
||||
babel-code-frame@^6.26.0:
|
||||
version "6.26.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
|
||||
dependencies:
|
||||
chalk "^1.1.3"
|
||||
esutils "^2.0.2"
|
||||
js-tokens "^3.0.2"
|
||||
|
||||
babel-core@6, babel-core@^6.0.0, babel-core@^6.24.1:
|
||||
version "6.24.1"
|
||||
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.24.1.tgz#8c428564dce1e1f41fb337ec34f4c3b022b5ad83"
|
||||
|
@ -2930,7 +2938,7 @@ js-tokens@1.0.1:
|
|||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-1.0.1.tgz#cc435a5c8b94ad15acb7983140fc80182c89aeae"
|
||||
|
||||
js-tokens@^3.0.0:
|
||||
js-tokens@^3.0.0, js-tokens@^3.0.2:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
|
||||
|
||||
|
|
Loading…
Reference in New Issue