Skip to content

Commit

Permalink
Load .browserslistrc when using old @babel/core versions (#12934)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo authored Mar 1, 2021
1 parent efdca01 commit c155caf
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/babel-preset-env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
},
"devDependencies": {
"@babel/core": "workspace:*",
"@babel/core-7.12": "npm:@babel/[email protected]",
"@babel/helper-plugin-test-runner": "workspace:*",
"@babel/plugin-syntax-dynamic-import": "^7.8.3"
}
Expand Down
6 changes: 5 additions & 1 deletion packages/babel-preset-env/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@flow

import { SemVer } from "semver";
import { SemVer, lt } from "semver";
import { logPluginOrPolyfill } from "./debug";
import getOptionSpecificExcludesFor from "./get-option-specific-excludes";
import { removeUnnecessaryItems } from "./filter-items";
Expand Down Expand Up @@ -295,6 +295,10 @@ export default declare((api, opts) => {
let targets = babelTargets;

if (
// @babel/core < 7.13.0 doesn't load targets (api.targets() always
// returns {} thanks to @babel/helper-plugin-utils), so we always want
// to fallback to the old targets behavior in this case.
lt(api.version, "7.13.0") ||

This comment has been minimized.

Copy link
@fabiooshiro

fabiooshiro Mar 4, 2021

hi @nicolo-ribaudo I think that change is braking the parcel-bundler, because the parcel does not pass the api.version
If there is no api.version it should be evaluated as false?

This comment has been minimized.

Copy link
@nicolo-ribaudo

nicolo-ribaudo Mar 4, 2021

Author Member

That Parcel bug is tracked at parcel-bundler/parcel#5943

This comment has been minimized.

Copy link
@fabiooshiro

fabiooshiro via email Mar 4, 2021

This comment has been minimized.

Copy link
@mryellow

mryellow Mar 15, 2021

Is the breaking change in this minor patch version tracked anywhere?

This comment has been minimized.

Copy link
@nicolo-ribaudo

nicolo-ribaudo Mar 15, 2021

Author Member

No because this is not a breaking change, it's a bug in how Parcel used this preset (it doesn't pass in the expected "babel plugin api" object, but manually calls the preset as a function passing a custom object).

This comment has been minimized.

Copy link
@mryellow

mryellow Mar 16, 2021

Fact remains that a change in babel broke builds.

This comment has been minimized.

Copy link
@nicolo-ribaudo

nicolo-ribaudo Mar 16, 2021

Author Member

Fact remains that your build should use lockfiles (yarn.lock or package-lock.json) to prevent that from happening 🤷

This comment has been minimized.

Copy link
@mryellow

mryellow Mar 17, 2021

Sometimes packages are rebuilt. People experienced this issue, it was real.

// If any browserslist-related option is specified, fallback to the old
// behavior of not using the targets specified in the top-level options.
opts.targets ||
Expand Down
22 changes: 22 additions & 0 deletions packages/babel-preset-env/test/regressions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as babel7_12 from "@babel/core";
import env from "..";
import path from "path";

describe("#12880", () => {
it("read the .browserslistrc file when using @babel/core < 7.13.0", () => {
// The browserslistrc file contains "firefox 50".
// a ** b is supported starting from firefox 52;
// a => b is supported starting from firefox 45.
const out = babel7_12.transformSync("a ** b; a => b;", {
configFile: false,
presets: [[env, { modules: false }]],
filename: path.join(__dirname, "regressions", "input.js"),
});

expect(out.code).toMatchInlineSnapshot(`
"Math.pow(a, b);
a => b;"
`);
});
});
1 change: 1 addition & 0 deletions packages/babel-preset-env/test/regressions/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
firefox 50
47 changes: 36 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,30 @@ __metadata:
languageName: unknown
linkType: soft

"@babel/core-7.12@npm:@babel/[email protected]":
version: 7.12.9
resolution: "@babel/core@npm:7.12.9"
dependencies:
"@babel/code-frame": ^7.10.4
"@babel/generator": ^7.12.5
"@babel/helper-module-transforms": ^7.12.1
"@babel/helpers": ^7.12.5
"@babel/parser": ^7.12.7
"@babel/template": ^7.12.7
"@babel/traverse": ^7.12.9
"@babel/types": ^7.12.7
convert-source-map: ^1.7.0
debug: ^4.1.0
gensync: ^1.0.0-beta.1
json5: ^2.1.2
lodash: ^4.17.19
resolve: ^1.3.2
semver: ^5.4.1
source-map: ^0.5.0
checksum: beefb9f490cfff7cafc02e5a11148297a71260ee18f5fdf6e14bf5694bc28431eec3813a91d0f0fc8c6122c5133d90d3261dadf45cb914d7d340a5b3077fd9bd
languageName: node
linkType: hard

"@babel/core@npm:7.13.1, @babel/core@npm:^7.1.0, @babel/core@npm:^7.13.1, @babel/core@npm:^7.7.5":
version: 7.13.1
resolution: "@babel/core@npm:7.13.1"
Expand Down Expand Up @@ -285,7 +309,7 @@ __metadata:
languageName: unknown
linkType: soft

"@babel/generator@npm:^7.13.0":
"@babel/generator@npm:^7.12.5, @babel/generator@npm:^7.13.0":
version: 7.13.0
resolution: "@babel/generator@npm:7.13.0"
dependencies:
Expand Down Expand Up @@ -619,7 +643,7 @@ __metadata:
languageName: unknown
linkType: soft

"@babel/helper-module-transforms@npm:^7.12.13, @babel/helper-module-transforms@npm:^7.13.0":
"@babel/helper-module-transforms@npm:^7.12.1, @babel/helper-module-transforms@npm:^7.12.13, @babel/helper-module-transforms@npm:^7.13.0":
version: 7.13.0
resolution: "@babel/helper-module-transforms@npm:7.13.0"
dependencies:
Expand Down Expand Up @@ -857,7 +881,7 @@ __metadata:
languageName: unknown
linkType: soft

"@babel/helpers@npm:^7.13.0":
"@babel/helpers@npm:^7.12.5, @babel/helpers@npm:^7.13.0":
version: 7.13.0
resolution: "@babel/helpers@npm:7.13.0"
dependencies:
Expand Down Expand Up @@ -926,7 +950,7 @@ __metadata:
languageName: unknown
linkType: soft

"@babel/parser@npm:^7.0.0, @babel/parser@npm:^7.12.13, @babel/parser@npm:^7.13.0":
"@babel/parser@npm:^7.0.0, @babel/parser@npm:^7.12.13, @babel/parser@npm:^7.12.7, @babel/parser@npm:^7.13.0":
version: 7.13.4
resolution: "@babel/parser@npm:7.13.4"
bin:
Expand Down Expand Up @@ -3039,6 +3063,7 @@ __metadata:
dependencies:
"@babel/compat-data": "workspace:^7.13.8"
"@babel/core": "workspace:*"
"@babel/core-7.12": "npm:@babel/[email protected]"
"@babel/helper-compilation-targets": "workspace:^7.13.8"
"@babel/helper-plugin-test-runner": "workspace:*"
"@babel/helper-plugin-utils": "workspace:^7.13.0"
Expand Down Expand Up @@ -3369,7 +3394,7 @@ __metadata:
languageName: unknown
linkType: soft

"@babel/template@npm:^7.12.13, @babel/template@npm:^7.3.3":
"@babel/template@npm:^7.12.13, @babel/template@npm:^7.12.7, @babel/template@npm:^7.3.3":
version: 7.12.13
resolution: "@babel/template@npm:7.12.13"
dependencies:
Expand Down Expand Up @@ -3400,7 +3425,7 @@ __metadata:
languageName: unknown
linkType: soft

"@babel/traverse@npm:^7.0.0, @babel/traverse@npm:^7.1.0, @babel/traverse@npm:^7.13.0":
"@babel/traverse@npm:^7.0.0, @babel/traverse@npm:^7.1.0, @babel/traverse@npm:^7.12.9, @babel/traverse@npm:^7.13.0":
version: 7.13.0
resolution: "@babel/traverse@npm:7.13.0"
dependencies:
Expand Down Expand Up @@ -3434,7 +3459,7 @@ __metadata:
languageName: unknown
linkType: soft

"@babel/types@npm:^7.0.0, @babel/types@npm:^7.12.1, @babel/types@npm:^7.12.13, @babel/types@npm:^7.13.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4":
"@babel/types@npm:^7.0.0, @babel/types@npm:^7.12.1, @babel/types@npm:^7.12.13, @babel/types@npm:^7.12.7, @babel/types@npm:^7.13.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4":
version: 7.13.0
resolution: "@babel/types@npm:7.13.0"
dependencies:
Expand Down Expand Up @@ -8379,7 +8404,7 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"gensync@npm:^1.0.0-beta.2":
"gensync@npm:^1.0.0-beta.1, gensync@npm:^1.0.0-beta.2":
version: 1.0.0-beta.2
resolution: "gensync@npm:1.0.0-beta.2"
checksum: d523437689c97b3aba9c5cdeca4677d5fff9a29d620db693fea40d852bad63563110f16979d0170248439dbcd2ecee0780fb2533d3f0519f019081aa10767c60
Expand Down Expand Up @@ -12829,7 +12854,7 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"resolve@^1.1.4, resolve@^1.1.6, resolve@^1.1.7, resolve@^1.10.0, resolve@^1.13.1, resolve@^1.14.2, resolve@^1.17.0, resolve@^1.18.1, resolve@^1.19.0, resolve@^1.4.0, resolve@^1.9.0":
"resolve@^1.1.4, resolve@^1.1.6, resolve@^1.1.7, resolve@^1.10.0, resolve@^1.13.1, resolve@^1.14.2, resolve@^1.17.0, resolve@^1.18.1, resolve@^1.19.0, resolve@^1.3.2, resolve@^1.4.0, resolve@^1.9.0":
version: 1.20.0
resolution: "resolve@npm:1.20.0"
dependencies:
Expand All @@ -12839,7 +12864,7 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"resolve@patch:resolve@^1.1.4#builtin<compat/resolve>, resolve@patch:resolve@^1.1.6#builtin<compat/resolve>, resolve@patch:resolve@^1.1.7#builtin<compat/resolve>, resolve@patch:resolve@^1.10.0#builtin<compat/resolve>, resolve@patch:resolve@^1.13.1#builtin<compat/resolve>, resolve@patch:resolve@^1.14.2#builtin<compat/resolve>, resolve@patch:resolve@^1.17.0#builtin<compat/resolve>, resolve@patch:resolve@^1.18.1#builtin<compat/resolve>, resolve@patch:resolve@^1.19.0#builtin<compat/resolve>, resolve@patch:resolve@^1.4.0#builtin<compat/resolve>, resolve@patch:resolve@^1.9.0#builtin<compat/resolve>":
"resolve@patch:resolve@^1.1.4#builtin<compat/resolve>, resolve@patch:resolve@^1.1.6#builtin<compat/resolve>, resolve@patch:resolve@^1.1.7#builtin<compat/resolve>, resolve@patch:resolve@^1.10.0#builtin<compat/resolve>, resolve@patch:resolve@^1.13.1#builtin<compat/resolve>, resolve@patch:resolve@^1.14.2#builtin<compat/resolve>, resolve@patch:resolve@^1.17.0#builtin<compat/resolve>, resolve@patch:resolve@^1.18.1#builtin<compat/resolve>, resolve@patch:resolve@^1.19.0#builtin<compat/resolve>, resolve@patch:resolve@^1.3.2#builtin<compat/resolve>, resolve@patch:resolve@^1.4.0#builtin<compat/resolve>, resolve@patch:resolve@^1.9.0#builtin<compat/resolve>":
version: 1.20.0
resolution: "resolve@patch:resolve@npm%3A1.20.0#builtin<compat/resolve>::version=1.20.0&hash=3388aa"
dependencies:
Expand Down Expand Up @@ -13165,7 +13190,7 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"semver@npm:2 || 3 || 4 || 5, semver@npm:^5.5.0, semver@npm:^5.6.0, semver@npm:^5.7.0":
"semver@npm:2 || 3 || 4 || 5, semver@npm:^5.4.1, semver@npm:^5.5.0, semver@npm:^5.6.0, semver@npm:^5.7.0":
version: 5.7.1
resolution: "semver@npm:5.7.1"
bin:
Expand Down

0 comments on commit c155caf

Please sign in to comment.