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
Respect package.json#exports
when resolving plugins
#14110
Merged
nicolo-ribaudo
merged 2 commits into
babel:main
from
nicolo-ribaudo:resolve-plugin-preset-respect-exports
Jan 16, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/babel-core/src/config/files/import-meta-resolve.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { createRequire } from "module"; | ||
import { resolve as polyfill } from "../../vendor/import-meta-resolve"; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
||
let import_; | ||
try { | ||
// Node < 13.3 doesn't support import() syntax. | ||
import_ = require("./import").default; | ||
} catch {} | ||
|
||
// import.meta.resolve is only available in ESM, but this file is compiled to CJS. | ||
// We can extract ir using dynamic import. | ||
const resolveP = | ||
import_ && | ||
// Due to a Node.js/V8 bug (https://github.com/nodejs/node/issues/35889), we cannot | ||
// use dynamic import when running in the default Jest environment because it | ||
// uses vm.SourceTextModule. | ||
// Jest defines globalThis["jest-symbol-do-not-touch"] in | ||
// https://github.com/facebook/jest/blob/11d79ec096a25851124356095d60352f6ca2824e/packages/jest-util/src/installCommonGlobals.ts#L49 | ||
// which is called by | ||
// https://github.com/facebook/jest/blob/11d79ec096a25851124356095d60352f6ca2824e/packages/jest-environment-node/src/index.ts#L85 | ||
// | ||
// Note that our Jest runner doesn't have this problem, because it runs ESM in the default | ||
// Node.js context rather than using the `vm` module. | ||
// | ||
// When V8 fixes this bug, we can remove this check. We usually don't have package-specific hacks, | ||
// but Jest is a big Babel consumer widely used in the community and they cannot workaround | ||
// this problem on their side. | ||
!Object.hasOwnProperty.call(global, "jest-symbol-do-not-touch") | ||
? import_("data:text/javascript,export default import.meta.resolve").then( | ||
// Since import.meta.resolve is unstable and only available when | ||
// using the --experimental-import-meta-resolve flag, we almost | ||
// always use the polyfill for now. | ||
m => m.default || polyfill, | ||
() => polyfill, | ||
) | ||
: Promise.resolve(polyfill); | ||
|
||
export default function getImportMetaResolve(): Promise<ImportMeta["resolve"]> { | ||
return resolveP; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export function resolve(specifier: stirng, parent: string): Promise<string>; |
9 changes: 9 additions & 0 deletions
9
...babel-core/test/fixtures/resolution/pkg-exports/node_modules/babel-plugin-dual/import.mjs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 kept these two functions separated (rather than creating a gensync) because they are not simply a sync and an async version: the sync one is also used when Babel is called asynchronously.