Skip to content

Commit

Permalink
Import JSON modules with import (#16321)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Mar 6, 2024
1 parent 345ea57 commit ec0171e
Show file tree
Hide file tree
Showing 10 changed files with 734 additions and 702 deletions.
1 change: 1 addition & 0 deletions Gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ function buildRollup(packages, buildStandalone) {
switch (warning.code) {
case "CIRCULAR_DEPENDENCY":
case "SOURCEMAP_ERROR": // Rollup warns about the babel-polyfills source maps
case "INCONSISTENT_IMPORT_ATTRIBUTES": // @rollup/plugin-commonjs transforms require("...json") to an import without attributes
return;
case "UNUSED_EXTERNAL_IMPORT":
warn(warning);
Expand Down
2 changes: 1 addition & 1 deletion Makefile.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ module.exports = function (api) {
["@babel/transform-object-rest-spread", { useBuiltIns: true }],

convertESM ? "@babel/transform-export-namespace-from" : null,
env !== "standalone" ? "@babel/plugin-proposal-json-modules" : null,
].filter(Boolean),
overrides: [
{
Expand Down
1 change: 0 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ module.exports = [
"no-restricted-imports": [
"error",
{
patterns: ["**/*.json"],
paths: [
{
name: "semver",
Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@
"packageManager": "yarn@4.1.1",
"devDependencies": {
"$repo-utils": "link:./scripts/repo-utils",
"@babel/cli": "8.0.0-alpha.5",
"@babel/core": "8.0.0-alpha.5",
"@babel/cli": "8.0.0-alpha.7",
"@babel/core": "8.0.0-alpha.7",
"@babel/eslint-config-internal": "workspace:^",
"@babel/eslint-parser": "workspace:^",
"@babel/eslint-plugin-development": "workspace:^",
"@babel/eslint-plugin-development-internal": "workspace:^",
"@babel/plugin-transform-dynamic-import": "8.0.0-alpha.5",
"@babel/plugin-transform-export-namespace-from": "8.0.0-alpha.5",
"@babel/plugin-transform-modules-commonjs": "8.0.0-alpha.5",
"@babel/plugin-transform-object-rest-spread": "8.0.0-alpha.5",
"@babel/plugin-transform-runtime": "8.0.0-alpha.5",
"@babel/preset-env": "8.0.0-alpha.5",
"@babel/preset-typescript": "8.0.0-alpha.5",
"@babel/runtime": "8.0.0-alpha.5",
"@babel/plugin-proposal-json-modules": "8.0.0-alpha.7",
"@babel/plugin-transform-dynamic-import": "8.0.0-alpha.7",
"@babel/plugin-transform-export-namespace-from": "8.0.0-alpha.7",
"@babel/plugin-transform-modules-commonjs": "8.0.0-alpha.7",
"@babel/plugin-transform-object-rest-spread": "8.0.0-alpha.7",
"@babel/plugin-transform-runtime": "8.0.0-alpha.7",
"@babel/preset-env": "8.0.0-alpha.7",
"@babel/preset-typescript": "8.0.0-alpha.7",
"@babel/runtime": "8.0.0-alpha.7",
"@cspotcode/source-map-support": "^0.8.1",
"@eslint/eslintrc": "^2.1.4",
"@rollup/plugin-babel": "^6.0.4",
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-preset-env/data/core-js-compat.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// TODO: Remove in Babel 8

module.exports = require("core-js-compat/data.json");
2 changes: 2 additions & 0 deletions packages/babel-preset-env/data/shipped-proposals.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// TODO: Remove in Babel 8

const { pluginSyntaxMap, proposalPlugins, proposalSyntaxPlugins } = require("../lib/shipped-proposals");
module.exports = { pluginSyntaxMap, proposalPlugins, proposalSyntaxPlugins };
5 changes: 1 addition & 4 deletions packages/babel-preset-env/src/normalize-options.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import semver, { type SemVer } from "semver";
// @ts-expect-error Fixme: TS can not infer types from ../data/core-js-compat.js
// but we can't import core-js-compat/data.json because JSON imports do
// not work on Node 14
import corejs3Polyfills from "../data/core-js-compat.js";
import corejs3Polyfills from "core-js-compat/data.json" with { type: "json" };
import { plugins as pluginsList } from "./plugins-compat-data.ts";
import moduleTransformations from "./module-transformations.ts";
import {
Expand Down
4 changes: 4 additions & 0 deletions scripts/integration-tests/e2e-babel-old-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ sed -i 's/describeGte("12.0.0")("worker"/describeGte("12.0.0").skip("worker"/g'
sed -i 's/nodeGte12(/nodeGte12.skip(/g' eslint/babel-eslint-tests/test/integration/parser-override.js
sed -i 's/nodeGte12NoESM(/nodeGte12NoESM.skip(/g' eslint/babel-eslint-tests/test/integration/config-files.js

# We only support transforming import attributes in new @babel/core versions
sed -i 's#"@babel/plugin-proposal-json-modules"#null#g' babel.config.js
sed -i 's#with { type: "json" }##g' packages/babel-preset-env/src/normalize-options.ts

# Update deps, build and test
rm yarn.lock
YARN_ENABLE_IMMUTABLE_INSTALLS=false make -j test-ci
Expand Down

0 comments on commit ec0171e

Please sign in to comment.