Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect
package.json#exports
when resolving plugins
* Use native import.meta.resolve when available
- Loading branch information
1 parent
53ac687
commit ced9928
Showing
16 changed files
with
266 additions
and
67 deletions.
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
26 changes: 26 additions & 0 deletions
26
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,26 @@ | ||
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_ | ||
? 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.
7 changes: 7 additions & 0 deletions
7
...bel-core/test/fixtures/resolution/pkg-exports/node_modules/babel-plugin-dual/package.json
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.