Skip to content

Commit c19e00e

Browse files
[babel 8] Remove unnecessary CJS ESM wrapper (#17261)
* [babel 8] Remove unnecessary CJS ESM wrapper * Use latest Node.js for e2e test * Add snapshot to test
1 parent 296cdc5 commit c19e00e

File tree

17 files changed

+30
-109
lines changed

17 files changed

+30
-109
lines changed

.github/workflows/e2e-tests-breaking-esm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
- name: Use Node.js latest
7272
uses: actions/setup-node@v4
7373
with:
74-
node-version: "*"
74+
node-version: latest
7575
- name: Get yarn cache directory path
7676
id: yarn-cache-dir-path
7777
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

packages/babel-core/.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ test
33
*.log
44
tsconfig.json
55
tsconfig.tsbuildinfo
6-
cjs-proxy-dev.cjs

packages/babel-core/cjs-proxy-dev.cjs

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/babel-core/cjs-proxy.cjs

Lines changed: 0 additions & 68 deletions
This file was deleted.

packages/babel-core/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
"exports": {
103103
".": {
104104
"types": "./lib/index.d.ts",
105-
"require": "./cjs-proxy.cjs",
106105
"default": "./lib/index.js"
107106
},
108107
"./package.json": "./package.json"
@@ -116,7 +115,6 @@
116115
"exports": {
117116
".": {
118117
"types": "./lib/index.d.ts",
119-
"require": "./cjs-proxy-dev.cjs",
120118
"default": "./lib/index.js"
121119
},
122120
"./package.json": "./package.json"

packages/babel-core/src/index.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,6 @@ export const DEFAULT_EXTENSIONS = Object.freeze([
9292
".cjs",
9393
] as const);
9494

95-
import Module from "node:module" with { if: "USE_ESM && !IS_STANDALONE" };
96-
import * as thisFile from "./index.ts" with { if: "USE_ESM && !IS_STANDALONE" };
97-
if (USE_ESM && !IS_STANDALONE) {
98-
// Pass this module to the CJS proxy, so that it can be synchronously accessed.
99-
const cjsProxy = Module.createRequire(import.meta.url)("../cjs-proxy.cjs");
100-
cjsProxy["__ initialize @babel/core cjs proxy __"] = thisFile;
101-
}
102-
10395
if (!process.env.BABEL_8_BREAKING && !USE_ESM) {
10496
// For easier backward-compatibility, provide an API like the one we exposed in Babel 6.
10597
// eslint-disable-next-line no-restricted-globals

packages/babel-core/test/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ if (IS_BABEL_8() && USE_ESM) {
10391039
it("error should be caught", () => {
10401040
let err;
10411041
try {
1042-
const cjs = require("../cjs-proxy.cjs");
1042+
const cjs = require("../lib/index.js");
10431043
cjs.parse("foo");
10441044
} catch (error) {
10451045
err = error;

packages/babel-core/test/esm-cjs-integration.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ describeESM("usage from cjs", () => {
5252
});
5353

5454
it("eager plugin required", async () => {
55-
await expect(run("eager-plugin-required.cjs")).rejects.toThrow(
56-
"The `types` export of @babel/core is only accessible from" +
57-
" the CommonJS version after that the ESM version is loaded.",
58-
);
55+
expect(await run("eager-plugin-required.cjs")).toMatchInlineSnapshot(`
56+
Object {
57+
"stderr": "",
58+
"stdout": "\\"Replaced!\\";
59+
",
60+
}
61+
`);
5962
});
6063

6164
it("eager plugin required after dynamic esm import", async () => {
@@ -91,10 +94,13 @@ describeESM("usage from cjs", () => {
9194
});
9295

9396
it("transformSync", async () => {
94-
await expect(run("transform-sync.cjs")).rejects.toThrow(
95-
"The `transformSync` export of @babel/core is only callable from" +
96-
" the CommonJS version after that the ESM version is loaded.",
97-
);
97+
expect(await run("transform-sync.cjs")).toMatchInlineSnapshot(`
98+
Object {
99+
"stderr": "",
100+
"stdout": "REPLACE_ME;
101+
",
102+
}
103+
`);
98104
});
99105

100106
it("transformSync after dynamic esm import", async () => {
@@ -141,9 +147,9 @@ describeESM("sync loading of ESM plugins", () => {
141147
"--experimental-require-module",
142148
);
143149
expect(stdout).toMatchInlineSnapshot(`
144-
"\\"Replaced!\\";
145-
"
146-
`);
150+
"\\"Replaced!\\";
151+
"
152+
`);
147153
});
148154

149155
it("top-level await", async () => {
@@ -169,9 +175,9 @@ describeESM("sync loading of ESM plugins", () => {
169175
"--experimental-require-module",
170176
);
171177
expect(stdout).toMatchInlineSnapshot(`
172-
"\\"Replaced!\\";
173-
"
174-
`);
178+
"\\"Replaced!\\";
179+
"
180+
`);
175181
});
176182

177183
it("top-level await with --experimental-require-module flag", async () => {

packages/babel-core/test/fixtures/esm-cjs-integration/eager-plugin-as-string.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const babel = require("../../../cjs-proxy.cjs");
1+
const babel = require("../../../lib/index.js");
22

33
babel
44
.transformAsync("REPLACE_ME;", {

packages/babel-core/test/fixtures/esm-cjs-integration/eager-plugin-required.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* version is loaded.
55
*/
66

7-
const babel = require("../../../cjs-proxy.cjs");
7+
const babel = require("../../../lib/index.js");
88

99
babel
1010
.transformAsync("REPLACE_ME;", {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy