-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Find custom babel config location properly. #969
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
{ | ||
"presets": ["../babel"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { join } from 'path' | ||
import buildConfigChain from 'babel-core/lib/transformation/file/options/build-config-chain' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe importing private module is inevitable ? :| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise, we have to copy the code or logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I admit as a Babel maintainer this makes me a little sad. If there's something we're not providing in the API, why not ask for it? Now if we change stuff like this we'll randomly break you with no way of knowing, and I'm 100% sure we'll get angry users coming to yell at us. |
||
|
||
export default function findBabelConfigLocation (dir) { | ||
// We need to provide a location of a filename inside the `dir`. | ||
// For the name of the file, we could be provide anything. | ||
const filename = join(dir, 'filename.js') | ||
const options = { babelrc: true, filename } | ||
|
||
// First We need to build the config chain. | ||
// Then we need to remove the config item with the location as "base". | ||
// That's the config we are passing as the "options" below | ||
const configList = buildConfigChain(options).filter(i => i.loc !== 'base') | ||
|
||
return configList[0] ? configList[0].loc : null | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"presets": [ | ||
// To let test apps(and Jest) to use Next's babel preset | ||
"../babel", | ||
// To transpile import statements into commonjs. | ||
// That's because Jest(runs in Node.js) don't know how to handle them. | ||
"es2015" | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Earlier our location detection logic couldn't find this.
So, we add
next/babel
by default.That's why providing a empty
.babelrc
here worked.But now we have to do this.