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

fix: search for browserslist if esmodules is falsy #11124

Merged
merged 4 commits into from Feb 24, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/babel-helper-compilation-targets/src/index.js
Expand Up @@ -189,7 +189,8 @@ export default function getTargets(
// Parse browsers target via browserslist
const browsersquery = validateBrowsers(targets.browsers);

const hasTargets = Object.keys(targets).length > 0;
const hasTargets = targets.esmodules ||
Copy link
Contributor

@JLHwung JLHwung Feb 11, 2020

Choose a reason for hiding this comment

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

I think we should normalize target { esmodules: false } to {} in

const normalizeTargets = targets => {

so if target.esmodules is accessed later, if must be true and we don't have to worry that it can be false or any other fancy falsy values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm...what I worry about is that some package use babel-helper-compilation-targets directly, e.g. @vue/babel-preset-app. should we fix the bug for those packages

https://github.com/vuejs/vue-cli/blob/c8cecffedbf7b19cf930bb2821b5c352bc716a67/packages/%40vue/babel-preset-app/index.js#L17

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Since target.esmodules is used as a shortcut to set target.browsers to be those with esmoduels support. We can delete it after it is consumed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems reasonable ❤️. Updated

Object.keys(targets).filter(value => value !== TargetNames.esmodules).length > 0;
const shouldParseBrowsers = !!targets.browsers;
const shouldSearchForConfig =
!options.ignoreBrowserslistConfig && !hasTargets;
Expand Down