New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specify runtime exports #10853
Specify runtime exports #10853
Conversation
1d2276e
to
14e8335
Compare
"./helpers/": "./helpers/", | ||
"./helpers/esm/": "./helpers/esm/", | ||
"./regenerator": "./regenerator/index.js", | ||
"./regenerator/": "./regenerator/", |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Don't we still need it for the |
I think we can add We could consider introduce import "foo/bar.js" can be correctly transpiled to AMD define(["foo/bar"], function (_bar) {
"use strict";
}); |
What's the status on this PR? #10549 was apparently fixing the issue but has been rolled back |
14e8335
to
99c950e
Compare
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/29137/ |
99c950e
to
2237a96
Compare
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 4997566:
|
"./package.json": "./package.json", | ||
"./regenerator": "./regenerator/index.js", | ||
"./regenerator/": "./regenerator/", | ||
"./core-js/": "./core-js/", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the directory export map is deep: All files under core-js
can be imported via path/filename.ext
:
import "@babel/runtime-corejs2/core-js/object/assign.js"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, maybe it will be good idea to add couple of tests
2237a96
to
36d435d
Compare
@@ -1,7 +1,7 @@ | |||
import arrayWithHoles from "./arrayWithHoles"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, some corejs 2 helper files are tracked in git repository. Yet it is convenient so you can review the actual change of helper imports.
/cc @rwjblue Will ember support self referencing package? In this case @babel/runtime-corejs2
is referencing itself. The import path extension .js
is not added so this part should work with amd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet it is convenient so you can review the actual change of helper imports.
That's exactly why we don't ignore some of these files 😛
@@ -0,0 +1,69 @@ | |||
import assert from "assert"; | |||
|
|||
export default { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote the testcases in such a way that hopefully we can use a codemod to convert the testcases to Jest BDD test styles, after Jest supports esm.
@@ -0,0 +1,11 @@ | |||
{ | |||
"name": "@babel/test-esm", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package is not visible to lerna. It is handled by yarn so we can import @babel/runtime
from the workspace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good!
import _Symbol from "../../core-js/symbol"; | ||
import _Array$from from "@babel/runtime-corejs2/core-js/array/from"; | ||
import _isIterable from "@babel/runtime-corejs2/core-js/is-iterable"; | ||
import _Symbol from "@babel/runtime-corejs2/core-js/symbol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For users using PnP, is it allowed for a package to import itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yarn PnP does not support esm yet: yarnpkg/berry#638
@merceyz Does PnP support require("package/itself")
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's totally fine
@@ -1,7 +1,7 @@ | |||
import arrayWithHoles from "./arrayWithHoles"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet it is convenient so you can review the actual change of helper imports.
That's exactly why we don't ignore some of these files 😛
ab64884
to
4997566
Compare
refs FOO-1331 need the fix in babel/babel#10853 so that the helpers injected by @babel/runtime et al do work in ESM mode (previously they would be missing the file extension) Change-Id: I41b13e03d248068b421065c6eada7f93defb48f7
refs FOO-1331 need the fix in babel/babel#10853 so that the helpers injected by @babel/runtime et al do work in ESM mode (previously they would be missing the file extension) Change-Id: I41b13e03d248068b421065c6eada7f93defb48f7
refs FOO-1331 need the fix in babel/babel#10853 so that the helpers injected by @babel/runtime et al do work in ESM mode (previously they would be missing the file extension) Change-Id: I41b13e03d248068b421065c6eada7f93defb48f7
refs FOO-1331 need the fix in babel/babel#10853 so that the helpers injected by @babel/runtime et al do work in ESM mode (previously they would be missing the file extension) Change-Id: I41b13e03d248068b421065c6eada7f93defb48f7
Solved issues
This PR add helper/esm exports to
@babel/runtime(-corejs[23])?
. Importing esm modular helpers are now broken on Babel 7.7.6 and Node.js 13.2This PR adds such missing exports so both
should work.
Changes to
@babel/runtime
Take
@babel/runtime-corejs3
as an example:7.11.2
This PR
The relative imports to core-js helpers are replaced by submodule imports
@babel/runtime-corejs3/core-js
. The relative imports to internal Babel helpers are also replaced by@babel/runtime-corejs3/helpers/esm/arrayLikeToArray
.This changes are also applied on non-esm helpers.
7.11.2
This PR
Node.js ESM requires relative imports (e.g.
./arrayLikeToArray
) ending with specific extension.js
. However, adding extension to import path will break people consuming@babel/runtime
via AMD, because we removed file extension from the module specifier:babel/packages/babel-helper-module-transforms/src/get-module-name.js
Line 40 in 20fd450
define("@babel/runtime/arrayLikeToArray")
forarrayLikeToArray.js
and thusrequire("./arrayLikeToArray.js")
will throw for AMD users.Since it is a breaking to change the
moduleName
behaviour. This PR does not add extension but adding moreexports
so it can work with both Node.js ESM and AMD.