Skip to content

Commit

Permalink
fix: Log original error with Babel compatibility info (#401)
Browse files Browse the repository at this point in the history
* Log original error with Babel compatibility info

* style: fix linter errors
  • Loading branch information
sdgluck authored and tricoder42 committed Nov 20, 2018
1 parent a774590 commit f7f43db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/cli/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/* eslint-disable import/export */
// This file is just used as an entry point for rollup.
export * from "./src/lingui"
12 changes: 10 additions & 2 deletions packages/cli/src/api/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,39 @@ function catchBabelVersionMismatch(fn) {
try {
fn.apply(null, arguments)
} catch (e) {
let logged = false

if (
e.message.startsWith(
"Plugin/Preset files are not allowed to export objects"
)
) {
logged = true

const { makeInstall } = require("../lingui-init")
const install = makeInstall()
console.log(chalk.red("Please install missing Babel 6 core package:"))
console.log()
console.log(install("babel-core@^6.0.0", true))
console.log()

process.exit(1)
} else if (
e.message.startsWith(
'Requires Babel "^7.0.0-0", but was loaded with "6.26.3".'
)
) {
logged = true

const { makeInstall } = require("../lingui-init")
const install = makeInstall()
console.log(chalk.red("Please install missing Babel 7 core packages:"))
console.log()
console.log(install("babel-core@^7.0.0-bridge.0 @babel/core", true))
console.log()
}

if (logged) {
console.log("Original error:")
console.log(e)
process.exit(1)
} else {
throw e
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/lingui-add-locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export default function command(config: LinguiConfig, locales: Array<string>) {
// At least one language was added successfully
if (results.filter(Boolean).length) {
console.log()
console.log(`(use "${chalk.yellow(helpRun("extract"))}" to extract messages)`)
console.log(
`(use "${chalk.yellow(helpRun("extract"))}" to extract messages)`
)
}
}

Expand Down

0 comments on commit f7f43db

Please sign in to comment.