-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: preserve import.meta.url in ESM (#83)
- Loading branch information
Showing
7 changed files
with
60 additions
and
2 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,14 @@ | ||
import { generateBundleEsmConfig } from '@e2e/helper'; | ||
import { defineConfig } from '@rslib/core'; | ||
|
||
export default defineConfig({ | ||
lib: [generateBundleEsmConfig(__dirname)], | ||
output: { | ||
target: 'node', | ||
}, | ||
source: { | ||
entry: { | ||
main: './src/index.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,7 @@ | ||
export const foo = () => { | ||
const d1 = __dirname; | ||
const d2 = __dirname; | ||
const f1 = __filename; | ||
const f2 = __filename; | ||
const importMetaUrl = import.meta.url; | ||
}; |
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,19 @@ | ||
import { join } from 'node:path'; | ||
import { buildAndGetResults } from '@e2e/helper'; | ||
import { expect, test } from 'vitest'; | ||
|
||
test('shims for __dirname and __filename in ESM', async () => { | ||
const fixturePath = join(__dirname, 'esm'); | ||
const { entries } = await buildAndGetResults(fixturePath); | ||
for (const shim of [ | ||
'import {fileURLToPath as __webpack_fileURLToPath__} from "url";', | ||
"var src_dirname = __webpack_fileURLToPath__(import.meta.url + '/..').slice(0, -1);", | ||
'var src_filename = __webpack_fileURLToPath__(import.meta.url);', | ||
// import.meta.url should not be substituted | ||
'const importMetaUrl = import.meta.url;', | ||
]) { | ||
expect(entries.esm).toContain(shim); | ||
} | ||
}); | ||
|
||
test.todo('shims for import.meta.url in CJS', async () => {}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './config'; | ||
export * from './utils'; | ||
export type * from './config'; | ||
export type * from './utils'; |
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