-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module-tools): support autoExtension and shims to improve node e…
…sm mode (#4831)
- Loading branch information
Showing
38 changed files
with
400 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@modern-js/module-tools': minor | ||
--- | ||
|
||
feat(module-tools): support autoExtension and shims to improve node esm mode | ||
feat(module-tools): 支持 autoExtension 和 shims 配置以完善 node esm 模式 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* eslint-disable node/prefer-global/url */ | ||
/* eslint-disable no-undef */ | ||
// taking from https://github.com/egoist/tsup/blob/dev/assets/cjs_shims.js | ||
|
||
// Shim globals in cjs bundle | ||
// There's a weird bug that esbuild will always inject importMetaUrl | ||
// if we export it as `const importMetaUrl = ... __filename ...` | ||
// But using a function will not cause this issue | ||
|
||
const getImportMetaUrl = () => | ||
typeof document === 'undefined' | ||
? new URL(`file:${__filename}`).href | ||
: (document.currentScript && document.currentScript.src) || | ||
new URL('main.js', document.baseURI).href; | ||
|
||
// define importMetaUrl | ||
export const importMetaUrl = /* @__PURE__ */ getImportMetaUrl(); |
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,9 @@ | ||
// Shim globals in esm bundle | ||
import { fileURLToPath } from 'url'; | ||
import path from 'path'; | ||
|
||
const getFilename = () => fileURLToPath(import.meta.url); | ||
const getDirname = () => path.dirname(getFilename()); | ||
|
||
export const __dirname = /* @__PURE__ */ getDirname(); | ||
export const __filename = /* @__PURE__ */ getFilename(); |
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
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
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
Oops, something went wrong.