Skip to content

Commit d3fffd9

Browse files
mbehzadnicolo-ribaudobabel-bot
authored
Add file extension when using absoluteRuntime (#12827)
* fix: add file extention when the absolute path to the runtime files are used (#12824) the es module imports need the file extention (e.g. import "@babel/runtime/helpers/jsx.js", Or the filenames being listed in the package.json's subpath exports (e.g. "import "@babel/runtime/helpers/jsx" + pkg: "./helpers/jsx": "./helpers/jsx.js"). when the user passes a path via `absoluteRuntime` then the rendered require staemnts is not the module name + subpath which will be resolved via pkg.json but rather the absolute path to the file. for this case, add the file extention / index.js to prevent bundlers from raising a warning. * Update deps * Fix imports resolution * Update fixtures (Windows) Co-authored-by: Nicolò Ribaudo <[email protected]> Co-authored-by: Babel Bot <[email protected]>
1 parent d16f811 commit d3fffd9

File tree

17 files changed

+110
-44
lines changed

17 files changed

+110
-44
lines changed

packages/babel-plugin-proposal-async-generator-functions/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"devDependencies": {
2828
"@babel/core": "workspace:^",
2929
"@babel/helper-plugin-test-runner": "workspace:^",
30-
"babel-plugin-polyfill-corejs3": "^0.3.0",
30+
"babel-plugin-polyfill-corejs3": "^0.4.0",
3131
"core-js-pure": "^3.19.0"
3232
},
3333
"engines": {

packages/babel-plugin-proposal-decorators/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"devDependencies": {
3131
"@babel/core": "workspace:^",
3232
"@babel/helper-plugin-test-runner": "workspace:^",
33-
"babel-plugin-polyfill-es-shims": "^0.5.0",
33+
"babel-plugin-polyfill-es-shims": "^0.6.0",
3434
"object.getownpropertydescriptors": "^2.1.1"
3535
},
3636
"engines": {

packages/babel-plugin-transform-runtime/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
"dependencies": {
2323
"@babel/helper-module-imports": "workspace:^",
2424
"@babel/helper-plugin-utils": "workspace:^",
25-
"babel-plugin-polyfill-corejs2": "^0.2.3",
26-
"babel-plugin-polyfill-corejs3": "^0.3.0",
27-
"babel-plugin-polyfill-regenerator": "^0.2.3",
25+
"babel-plugin-polyfill-corejs2": "^0.3.0",
26+
"babel-plugin-polyfill-corejs3": "^0.4.0",
27+
"babel-plugin-polyfill-regenerator": "^0.3.0",
2828
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
2929
},
3030
"peerDependencies": {

packages/babel-plugin-transform-runtime/src/get-runtime-path/browser.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
export default function (moduleName, dirname, absoluteRuntime) {
22
if (absoluteRuntime === false) return moduleName;
33

4+
resolveFSPath();
5+
}
6+
7+
export function resolveFSPath() {
48
throw new Error(
59
"The 'absoluteRuntime' option is not supported when using @babel/standalone.",
610
);

packages/babel-plugin-transform-runtime/src/get-runtime-path/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ function resolveAbsoluteRuntime(moduleName: string, dirname: string) {
3232
);
3333
}
3434
}
35+
36+
export function resolveFSPath(path) {
37+
return require.resolve(path);
38+
}

packages/babel-plugin-transform-runtime/src/index.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { addDefault, isModule } from "@babel/helper-module-imports";
33
import { types as t } from "@babel/core";
44

55
import { hasMinVersion } from "./helpers";
6-
import getRuntimePath from "./get-runtime-path";
6+
import getRuntimePath, { resolveFSPath } from "./get-runtime-path";
77

88
import _pluginCorejs2 from "babel-plugin-polyfill-corejs2";
99
import _pluginCorejs3 from "babel-plugin-polyfill-corejs3";
@@ -165,8 +165,6 @@ export default declare((api, options, dirname) => {
165165
};
166166
}
167167

168-
const corejsExt = absoluteRuntime ? ".js" : "";
169-
170168
return {
171169
name: "transform-runtime",
172170

@@ -175,14 +173,16 @@ export default declare((api, options, dirname) => {
175173
pluginCorejs2,
176174
{
177175
method: "usage-pure",
176+
absoluteImports: absoluteRuntime ? modulePath : false,
178177
[pluginsCompat]: {
179178
runtimeVersion,
180179
useBabelRuntime: modulePath,
181-
ext: corejsExt,
180+
ext: "",
182181
},
183182
},
184183
createRegeneratorPlugin({
185184
method: "usage-pure",
185+
absoluteImports: absoluteRuntime ? modulePath : false,
186186
[pluginsCompat]: { useBabelRuntime: modulePath },
187187
}),
188188
)
@@ -193,15 +193,18 @@ export default declare((api, options, dirname) => {
193193
method: "usage-pure",
194194
version: 3,
195195
proposals,
196-
[pluginsCompat]: { useBabelRuntime: modulePath, ext: corejsExt },
196+
absoluteImports: absoluteRuntime ? modulePath : false,
197+
[pluginsCompat]: { useBabelRuntime: modulePath, ext: "" },
197198
},
198199
createRegeneratorPlugin({
199200
method: "usage-pure",
201+
absoluteImports: absoluteRuntime ? modulePath : false,
200202
[pluginsCompat]: { useBabelRuntime: modulePath },
201203
}),
202204
)
203205
: createRegeneratorPlugin({
204206
method: "usage-pure",
207+
absoluteImports: absoluteRuntime ? modulePath : false,
205208
[pluginsCompat]: { useBabelRuntime: modulePath },
206209
}),
207210

@@ -232,12 +235,10 @@ export default declare((api, options, dirname) => {
232235
? "helpers/esm"
233236
: "helpers";
234237

235-
return addDefaultImport(
236-
`${modulePath}/${helpersDir}/${name}`,
237-
name,
238-
blockHoist,
239-
true,
240-
);
238+
let helperPath = `${modulePath}/${helpersDir}/${name}`;
239+
if (absoluteRuntime) helperPath = resolveFSPath(helperPath);
240+
241+
return addDefaultImport(helperPath, name, blockHoist, true);
241242
});
242243

243244
const cache = new Map();

packages/babel-plugin-transform-runtime/test/fixtures/absoluteRuntime/relative/output.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var _classCallCheck = require("<CWD>/packages/babel-plugin-transform-runtime/test/fixtures/absoluteRuntime/relative/subfolder/node_modules/@babel/runtime/helpers/classCallCheck");
1+
var _classCallCheck = require("<CWD>/packages/babel-plugin-transform-runtime/test/fixtures/absoluteRuntime/relative/subfolder/node_modules/@babel/runtime/helpers/classCallCheck.js");
22

33
let Foo = function Foo() {
44
"use strict";

packages/babel-plugin-transform-runtime/test/fixtures/absoluteRuntime/relative/subfolder/node_modules/@babel/runtime/helpers/classCallCheck.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/babel-plugin-transform-runtime/test/fixtures/absoluteRuntime/true-corejs3-proposals/output.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var _regeneratorRuntime = require("<CWD>/packages/babel-runtime-corejs3/regenerator");
1+
var _regeneratorRuntime = require("<CWD>/packages/babel-runtime-corejs3/regenerator/index.js");
22

33
var _mapInstanceProperty = require("<CWD>/packages/babel-runtime-corejs3/core-js/instance/map.js");
44

packages/babel-plugin-transform-runtime/test/fixtures/absoluteRuntime/true-corejs3-stable/output.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var _regeneratorRuntime = require("<CWD>/packages/babel-runtime-corejs3/regenerator");
1+
var _regeneratorRuntime = require("<CWD>/packages/babel-runtime-corejs3/regenerator/index.js");
22

33
var _mapInstanceProperty = require("<CWD>/packages/babel-runtime-corejs3/core-js-stable/instance/map.js");
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class Foo {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"plugins": [
3+
"transform-classes",
4+
["transform-runtime", { "absoluteRuntime": true, "useESModules": true }]
5+
]
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var _classCallCheck = require("<CWD>/packages/babel-runtime/helpers/classCallCheck.js");
2+
3+
let Foo = function Foo() {
4+
"use strict";
5+
6+
_classCallCheck(this, Foo);
7+
};

packages/babel-plugin-transform-runtime/test/fixtures/absoluteRuntime/true/output.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var _classCallCheck = require("<CWD>/packages/babel-runtime/helpers/classCallCheck");
1+
var _classCallCheck = require("<CWD>/packages/babel-runtime/helpers/classCallCheck.js");
22

33
let Foo = function Foo() {
44
"use strict";

packages/babel-plugin-transform-runtime/test/fixtures/windows/absoluteRuntime/output.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var _asyncToGenerator = require("<CWD>/packages/babel-runtime/helpers/asyncToGenerator");
1+
var _asyncToGenerator = require("<CWD>\\packages\\babel-runtime\\helpers\\asyncToGenerator.js");
22

33
function test() {
44
return _test.apply(this, arguments);

packages/babel-preset-env/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@
8585
"@babel/plugin-transform-unicode-regex": "workspace:^",
8686
"@babel/preset-modules": "^0.1.5",
8787
"@babel/types": "workspace:^",
88-
"babel-plugin-polyfill-corejs2": "^0.2.3",
89-
"babel-plugin-polyfill-corejs3": "^0.3.0",
90-
"babel-plugin-polyfill-regenerator": "^0.2.3",
88+
"babel-plugin-polyfill-corejs2": "^0.3.0",
89+
"babel-plugin-polyfill-corejs3": "^0.4.0",
90+
"babel-plugin-polyfill-regenerator": "^0.3.0",
9191
"core-js-compat": "^3.19.1",
9292
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
9393
},

yarn.lock

+62-20
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,24 @@ __metadata:
587587
languageName: node
588588
linkType: hard
589589

590+
"@babel/helper-define-polyfill-provider@npm:^0.3.0":
591+
version: 0.3.0
592+
resolution: "@babel/helper-define-polyfill-provider@npm:0.3.0"
593+
dependencies:
594+
"@babel/helper-compilation-targets": ^7.13.0
595+
"@babel/helper-module-imports": ^7.12.13
596+
"@babel/helper-plugin-utils": ^7.13.0
597+
"@babel/traverse": ^7.13.0
598+
debug: ^4.1.1
599+
lodash.debounce: ^4.0.8
600+
resolve: ^1.14.2
601+
semver: ^6.1.2
602+
peerDependencies:
603+
"@babel/core": ^7.4.0-0
604+
checksum: 372378ac4235c4fe135f1cd6d0f63697e7cb3ef63a884eb14f4b439984846bcaec0b7a32cf8df6756a21557ae3ebb3c2ee18d9a191260705a583333e5e60df7c
605+
languageName: node
606+
linkType: hard
607+
590608
"@babel/helper-explode-assignable-expression@npm:^7.14.5":
591609
version: 7.14.5
592610
resolution: "@babel/helper-explode-assignable-expression@npm:7.14.5"
@@ -1158,7 +1176,7 @@ __metadata:
11581176
"@babel/helper-plugin-utils": "workspace:^"
11591177
"@babel/helper-remap-async-to-generator": "workspace:^"
11601178
"@babel/plugin-syntax-async-generators": ^7.8.4
1161-
babel-plugin-polyfill-corejs3: ^0.3.0
1179+
babel-plugin-polyfill-corejs3: ^0.4.0
11621180
core-js-pure: ^3.19.0
11631181
peerDependencies:
11641182
"@babel/core": ^7.0.0-0
@@ -1226,7 +1244,7 @@ __metadata:
12261244
"@babel/helper-plugin-test-runner": "workspace:^"
12271245
"@babel/helper-plugin-utils": "workspace:^"
12281246
"@babel/plugin-syntax-decorators": "workspace:^"
1229-
babel-plugin-polyfill-es-shims: ^0.5.0
1247+
babel-plugin-polyfill-es-shims: ^0.6.0
12301248
object.getownpropertydescriptors: ^2.1.1
12311249
peerDependencies:
12321250
"@babel/core": ^7.0.0-0
@@ -2920,9 +2938,9 @@ __metadata:
29202938
"@babel/runtime-corejs3": "workspace:^"
29212939
"@babel/template": "workspace:^"
29222940
"@babel/types": "workspace:^"
2923-
babel-plugin-polyfill-corejs2: ^0.2.3
2924-
babel-plugin-polyfill-corejs3: ^0.3.0
2925-
babel-plugin-polyfill-regenerator: ^0.2.3
2941+
babel-plugin-polyfill-corejs2: ^0.3.0
2942+
babel-plugin-polyfill-corejs3: ^0.4.0
2943+
babel-plugin-polyfill-regenerator: ^0.3.0
29262944
make-dir: "condition:BABEL_8_BREAKING ? : ^2.1.0"
29272945
semver: "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
29282946
peerDependencies:
@@ -3298,9 +3316,9 @@ __metadata:
32983316
"@babel/plugin-transform-unicode-regex": "workspace:^"
32993317
"@babel/preset-modules": ^0.1.5
33003318
"@babel/types": "workspace:^"
3301-
babel-plugin-polyfill-corejs2: ^0.2.3
3302-
babel-plugin-polyfill-corejs3: ^0.3.0
3303-
babel-plugin-polyfill-regenerator: ^0.2.3
3319+
babel-plugin-polyfill-corejs2: ^0.3.0
3320+
babel-plugin-polyfill-corejs3: ^0.4.0
3321+
babel-plugin-polyfill-regenerator: ^0.3.0
33043322
core-js-compat: ^3.19.1
33053323
semver: "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
33063324
peerDependencies:
@@ -5606,7 +5624,7 @@ __metadata:
56065624
languageName: node
56075625
linkType: hard
56085626

5609-
"babel-plugin-polyfill-corejs2@npm:^0.2.2, babel-plugin-polyfill-corejs2@npm:^0.2.3":
5627+
"babel-plugin-polyfill-corejs2@npm:^0.2.2":
56105628
version: 0.2.3
56115629
resolution: "babel-plugin-polyfill-corejs2@npm:0.2.3"
56125630
dependencies:
@@ -5619,6 +5637,19 @@ __metadata:
56195637
languageName: node
56205638
linkType: hard
56215639

5640+
"babel-plugin-polyfill-corejs2@npm:^0.3.0":
5641+
version: 0.3.0
5642+
resolution: "babel-plugin-polyfill-corejs2@npm:0.3.0"
5643+
dependencies:
5644+
"@babel/compat-data": ^7.13.11
5645+
"@babel/helper-define-polyfill-provider": ^0.3.0
5646+
semver: ^6.1.1
5647+
peerDependencies:
5648+
"@babel/core": ^7.0.0-0
5649+
checksum: ffede597982066221291fe7c48ec1f1dda2b4ed3ee3e715436320697f35368223e1275bf095769d0b0c1115b90031dc525dd81b8ee9f6c8972cf1d2e10ad2b7d
5650+
languageName: node
5651+
linkType: hard
5652+
56225653
"babel-plugin-polyfill-corejs3@npm:^0.2.2":
56235654
version: 0.2.5
56245655
resolution: "babel-plugin-polyfill-corejs3@npm:0.2.5"
@@ -5631,30 +5662,30 @@ __metadata:
56315662
languageName: node
56325663
linkType: hard
56335664

5634-
"babel-plugin-polyfill-corejs3@npm:^0.3.0":
5635-
version: 0.3.0
5636-
resolution: "babel-plugin-polyfill-corejs3@npm:0.3.0"
5665+
"babel-plugin-polyfill-corejs3@npm:^0.4.0":
5666+
version: 0.4.0
5667+
resolution: "babel-plugin-polyfill-corejs3@npm:0.4.0"
56375668
dependencies:
5638-
"@babel/helper-define-polyfill-provider": ^0.2.4
5669+
"@babel/helper-define-polyfill-provider": ^0.3.0
56395670
core-js-compat: ^3.18.0
56405671
peerDependencies:
56415672
"@babel/core": ^7.0.0-0
5642-
checksum: bef217415448dea6af38ac4ce70e0fad897577fe764711a47030beee191848a47a9fdd9e1b222ef428c8fc0b792cdb8750aaddb3fa5624feccb64b6926ac57b4
5673+
checksum: 18dce9a09a608b4844bce468a1d7b3abfc8a2a4c0df317ad6eb5951c0c95f3d1cc99699d8e67642cdd629f5074499d481481ae5e203ce85b8ed73e8295e25da8
56435674
languageName: node
56445675
linkType: hard
56455676

5646-
"babel-plugin-polyfill-es-shims@npm:^0.5.0":
5647-
version: 0.5.0
5648-
resolution: "babel-plugin-polyfill-es-shims@npm:0.5.0"
5677+
"babel-plugin-polyfill-es-shims@npm:^0.6.0":
5678+
version: 0.6.0
5679+
resolution: "babel-plugin-polyfill-es-shims@npm:0.6.0"
56495680
dependencies:
5650-
"@babel/helper-define-polyfill-provider": ^0.2.4
5681+
"@babel/helper-define-polyfill-provider": ^0.3.0
56515682
peerDependencies:
56525683
"@babel/core": ^7.0.0-0
5653-
checksum: ddfb94b4ec31d59c989b03db01e902ae97ef5a2f135e63f3c3395a42f52494fded6148744b2b0bba992f891de5de3602f251fac3c03c1437541eccda626893f5
5684+
checksum: d29426ccc51cd46572c915346bd30019270e3ac6f20209aab7383b986d43516602c83ec36fb48a5c79f63ae7c21107ecb5d394b80fe88cf66a70b4bbb037f2c7
56545685
languageName: node
56555686
linkType: hard
56565687

5657-
"babel-plugin-polyfill-regenerator@npm:^0.2.2, babel-plugin-polyfill-regenerator@npm:^0.2.3":
5688+
"babel-plugin-polyfill-regenerator@npm:^0.2.2":
56585689
version: 0.2.3
56595690
resolution: "babel-plugin-polyfill-regenerator@npm:0.2.3"
56605691
dependencies:
@@ -5665,6 +5696,17 @@ __metadata:
56655696
languageName: node
56665697
linkType: hard
56675698

5699+
"babel-plugin-polyfill-regenerator@npm:^0.3.0":
5700+
version: 0.3.0
5701+
resolution: "babel-plugin-polyfill-regenerator@npm:0.3.0"
5702+
dependencies:
5703+
"@babel/helper-define-polyfill-provider": ^0.3.0
5704+
peerDependencies:
5705+
"@babel/core": ^7.0.0-0
5706+
checksum: ecca4389fd557554efc6de834f84f7c85e83c348d5283de2032d35429bc7121ed6f336553d3d704021f9bef22fca339fbee560d3b0fb8bb1d4eca2fecaaeebcb
5707+
languageName: node
5708+
linkType: hard
5709+
56685710
"babel-plugin-transform-charcodes@npm:^0.2.0":
56695711
version: 0.2.0
56705712
resolution: "babel-plugin-transform-charcodes@npm:0.2.0"

0 commit comments

Comments
 (0)