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

Show hint for missing babel-core package #381

Merged
merged 1 commit into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
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
45 changes: 45 additions & 0 deletions packages/cli/src/api/compat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import chalk from "chalk"
import * as core from "babel-core"

function catchBabelVersionMismatch(fn) {
return function() {
try {
fn.apply(null, arguments)
} catch (e) {
if (
e.message.startsWith(
"Plugin/Preset files are not allowed to export objects"
)
) {
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".'
)
) {
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()

process.exit(1)
} else {
throw e
}
}
}
}

export const transform = catchBabelVersionMismatch(core.transform)
export const transformFileSync = catchBabelVersionMismatch(
core.transformFileSync
)
2 changes: 1 addition & 1 deletion packages/cli/src/api/extractors/babel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import { transformFileSync } from "babel-core"
import { transformFileSync } from "../compat"

import linguiTransformJs from "@lingui/babel-plugin-transform-js"
import linguiTransformReact from "@lingui/babel-plugin-transform-react"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/api/extractors/typescript.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import fs from "fs"
import { transform } from "babel-core"
import { transform } from "../compat"

import linguiTransformJs from "@lingui/babel-plugin-transform-js"
import linguiTransformReact from "@lingui/babel-plugin-transform-react"
Expand Down