Skip to content

Commit

Permalink
fix: add file extention when the absolute path to the runtime files a…
Browse files Browse the repository at this point in the history
…re 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.
  • Loading branch information
mbehzad committed Mar 14, 2021
1 parent 1a05b81 commit 38b64e5
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-runtime/src/index.js
Expand Up @@ -233,7 +233,7 @@ export default declare((api, options, dirname) => {
: "helpers";

return addDefaultImport(
`${modulePath}/${helpersDir}/${name}`,
`${modulePath}/${helpersDir}/${name}${absoluteRuntime ? ".js" : ""}`,
name,
blockHoist,
true,
Expand Down
@@ -1,4 +1,4 @@
var _classCallCheck = require("<CWD>/packages/babel-plugin-transform-runtime/test/fixtures/absoluteRuntime/relative/subfolder/node_modules/@babel/runtime/helpers/classCallCheck");
var _classCallCheck = require("<CWD>/packages/babel-plugin-transform-runtime/test/fixtures/absoluteRuntime/relative/subfolder/node_modules/@babel/runtime/helpers/classCallCheck.js");

let Foo = function Foo() {
"use strict";
Expand Down
@@ -1,4 +1,4 @@
var _regeneratorRuntime = require("<CWD>/packages/babel-runtime-corejs3/regenerator");
var _regeneratorRuntime = require("<CWD>/packages/babel-runtime-corejs3/regenerator/index.js");

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

Expand Down
@@ -1,4 +1,4 @@
var _regeneratorRuntime = require("<CWD>/packages/babel-runtime-corejs3/regenerator");
var _regeneratorRuntime = require("<CWD>/packages/babel-runtime-corejs3/regenerator/index.js");

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

Expand Down
@@ -0,0 +1 @@
class Foo {}
@@ -0,0 +1,6 @@
{
"plugins": [
"transform-classes",
["transform-runtime", { "absoluteRuntime": true, "useESModules": true }]
]
}
@@ -0,0 +1,7 @@
var _classCallCheck = require("<CWD>/packages/babel-runtime/helpers/classCallCheck.js");

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

_classCallCheck(this, Foo);
};
@@ -1,4 +1,4 @@
var _classCallCheck = require("<CWD>/packages/babel-runtime/helpers/classCallCheck");
var _classCallCheck = require("<CWD>/packages/babel-runtime/helpers/classCallCheck.js");

let Foo = function Foo() {
"use strict";
Expand Down
@@ -1,4 +1,4 @@
var _asyncToGenerator = require("<CWD>/packages/babel-runtime/helpers/asyncToGenerator");
var _asyncToGenerator = require("<CWD>/packages/babel-runtime/helpers/asyncToGenerator.js");

function test() {
return _test.apply(this, arguments);
Expand Down

0 comments on commit 38b64e5

Please sign in to comment.