Skip to content

Commit ec0171e

Browse files
Import JSON modules with import (#16321)
1 parent 345ea57 commit ec0171e

10 files changed

Lines changed: 734 additions & 702 deletions

File tree

Gulpfile.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ function buildRollup(packages, buildStandalone) {
362362
switch (warning.code) {
363363
case "CIRCULAR_DEPENDENCY":
364364
case "SOURCEMAP_ERROR": // Rollup warns about the babel-polyfills source maps
365+
case "INCONSISTENT_IMPORT_ATTRIBUTES": // @rollup/plugin-commonjs transforms require("...json") to an import without attributes
365366
return;
366367
case "UNUSED_EXTERNAL_IMPORT":
367368
warn(warning);

Makefile.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ module.exports = function (api) {
184184
["@babel/transform-object-rest-spread", { useBuiltIns: true }],
185185

186186
convertESM ? "@babel/transform-export-namespace-from" : null,
187+
env !== "standalone" ? "@babel/plugin-proposal-json-modules" : null,
187188
].filter(Boolean),
188189
overrides: [
189190
{

eslint.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ module.exports = [
242242
"no-restricted-imports": [
243243
"error",
244244
{
245-
patterns: ["**/*.json"],
246245
paths: [
247246
{
248247
name: "semver",

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@
2121
"packageManager": "[email protected]",
2222
"devDependencies": {
2323
"$repo-utils": "link:./scripts/repo-utils",
24-
"@babel/cli": "8.0.0-alpha.5",
25-
"@babel/core": "8.0.0-alpha.5",
24+
"@babel/cli": "8.0.0-alpha.7",
25+
"@babel/core": "8.0.0-alpha.7",
2626
"@babel/eslint-config-internal": "workspace:^",
2727
"@babel/eslint-parser": "workspace:^",
2828
"@babel/eslint-plugin-development": "workspace:^",
2929
"@babel/eslint-plugin-development-internal": "workspace:^",
30-
"@babel/plugin-transform-dynamic-import": "8.0.0-alpha.5",
31-
"@babel/plugin-transform-export-namespace-from": "8.0.0-alpha.5",
32-
"@babel/plugin-transform-modules-commonjs": "8.0.0-alpha.5",
33-
"@babel/plugin-transform-object-rest-spread": "8.0.0-alpha.5",
34-
"@babel/plugin-transform-runtime": "8.0.0-alpha.5",
35-
"@babel/preset-env": "8.0.0-alpha.5",
36-
"@babel/preset-typescript": "8.0.0-alpha.5",
37-
"@babel/runtime": "8.0.0-alpha.5",
30+
"@babel/plugin-proposal-json-modules": "8.0.0-alpha.7",
31+
"@babel/plugin-transform-dynamic-import": "8.0.0-alpha.7",
32+
"@babel/plugin-transform-export-namespace-from": "8.0.0-alpha.7",
33+
"@babel/plugin-transform-modules-commonjs": "8.0.0-alpha.7",
34+
"@babel/plugin-transform-object-rest-spread": "8.0.0-alpha.7",
35+
"@babel/plugin-transform-runtime": "8.0.0-alpha.7",
36+
"@babel/preset-env": "8.0.0-alpha.7",
37+
"@babel/preset-typescript": "8.0.0-alpha.7",
38+
"@babel/runtime": "8.0.0-alpha.7",
3839
"@cspotcode/source-map-support": "^0.8.1",
3940
"@eslint/eslintrc": "^2.1.4",
4041
"@rollup/plugin-babel": "^6.0.4",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
// TODO: Remove in Babel 8
2+
13
module.exports = require("core-js-compat/data.json");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
// TODO: Remove in Babel 8
2+
13
const { pluginSyntaxMap, proposalPlugins, proposalSyntaxPlugins } = require("../lib/shipped-proposals");
24
module.exports = { pluginSyntaxMap, proposalPlugins, proposalSyntaxPlugins };

packages/babel-preset-env/src/normalize-options.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import semver, { type SemVer } from "semver";
2-
// @ts-expect-error Fixme: TS can not infer types from ../data/core-js-compat.js
3-
// but we can't import core-js-compat/data.json because JSON imports do
4-
// not work on Node 14
5-
import corejs3Polyfills from "../data/core-js-compat.js";
2+
import corejs3Polyfills from "core-js-compat/data.json" with { type: "json" };
63
import { plugins as pluginsList } from "./plugins-compat-data.ts";
74
import moduleTransformations from "./module-transformations.ts";
85
import {

scripts/integration-tests/e2e-babel-old-version.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ sed -i 's/describeGte("12.0.0")("worker"/describeGte("12.0.0").skip("worker"/g'
6363
sed -i 's/nodeGte12(/nodeGte12.skip(/g' eslint/babel-eslint-tests/test/integration/parser-override.js
6464
sed -i 's/nodeGte12NoESM(/nodeGte12NoESM.skip(/g' eslint/babel-eslint-tests/test/integration/config-files.js
6565

66+
# We only support transforming import attributes in new @babel/core versions
67+
sed -i 's#"@babel/plugin-proposal-json-modules"#null#g' babel.config.js
68+
sed -i 's#with { type: "json" }##g' packages/babel-preset-env/src/normalize-options.ts
69+
6670
# Update deps, build and test
6771
rm yarn.lock
6872
YARN_ENABLE_IMMUTABLE_INSTALLS=false make -j test-ci

0 commit comments

Comments
 (0)