Skip to content

fix: babel config lookup #364

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

Merged
merged 14 commits into from
Jan 18, 2021

Conversation

Robin-Hoodie
Copy link
Contributor

@Robin-Hoodie Robin-Hoodie commented Jan 14, 2021

New PR from different branch which closes #359 .

In comparison to #359 the following has been added:

  • Added tests finding babel config file
  • Refactored logic to find babel config file to use find-up's matcher function and improve performance

Closes #200, #188

I've added find-up as a dependency for finding the babel config file.
The babel config files to look for have been taken from @babel/core's sourcecode
Finally, as babel-loader itself will by default not look outside of the cwd
for the config file, we don't want to have false positives for any babel config
files that exist outside of the cwd

Closes netlify#200, netlify#188
Use find-up matcher function to automatically stop looking for babel config file
once cwd is reached, thus increasing performance.
@Robin-Hoodie Robin-Hoodie force-pushed the fix/babel-config-lookup branch from c001f06 to b00e640 Compare January 15, 2021 05:23
@erezrokah erezrokah added the type: bug code to address defects in shipped code label Jan 15, 2021
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Robin-Hoodie and sorry for the late reply.
Thank you again for pushing this fix. I think I wasn't able to explain myself before when I mentioned monorepo support. I've added a few commits to cleanup the tests and a test case describing what I had in mind:
https://github.com/netlify/netlify-lambda/pull/364/files#diff-dd24f19d79300a10592927150e05758644fc84a1ae5c7b7844ae0909416738d2R153
The scenario we'd like to support is if someones has a babel config file in the root of a monorepo, but runs netlify-lambda from the a directory of a specific package (hence the cwd is the directory of that package).

Please let me know what you think of the changes I made and if my explanation is clear enough.

function webpackConfig(dir, { userWebpackConfig, useBabelrc } = {}) {
function webpackConfig(
dir,
{ userWebpackConfig, useBabelrc, cwd = process.cwd() } = {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cwd argument is only here so we can test the monorepo setup

@erezrokah
Copy link
Contributor

Ok, so after reading https://babeljs.io/docs/en/config-files#file-relative-configuration and https://babeljs.io/docs/en/config-files#monorepos it might be better to use babel APIs for this to make sure we don't miss any edge case. WDYT?

@Robin-Hoodie
Copy link
Contributor Author

Robin-Hoodie commented Jan 15, 2021

Ok, so after reading https://babeljs.io/docs/en/config-files#file-relative-configuration and https://babeljs.io/docs/en/config-files#monorepos it might be better to use babel APIs for this to make sure we don't miss any edge case. WDYT?

That would definitely be the easiest and it's what I tried to do first. However, I don't know if @babel/core exposes that logic anywhere. None of the functions for the Babel core API seem to be about checking for the existence of a babel config file.

The logic for looking up a babel config file does not seem to be exposed as far as I can tell

I might well be wrong in my assumptions here though

@Robin-Hoodie
Copy link
Contributor Author

I went over the commits you've added just now. Added 2 comments but great additions overall!

@erezrokah erezrokah merged commit 15001e3 into netlify:master Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.babelrc.js ignored
2 participants