Skip to content

Commit b87c8df

Browse files
committedAug 10, 2022
feat!: always enable esmResolve for jiti (stub and config)
1 parent ffc0d7c commit b87c8df

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed
 

‎src/builder/rollup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ export async function rollupBuild (ctx: BuildContext) {
3434

3535
await mkdir(dirname(output), { recursive: true })
3636
if (ctx.options.rollup.emitCJS) {
37-
await writeFile(output + '.cjs', `${shebang}module.exports = require(${JSON.stringify(jitiPath)})(null, { interopDefault: true })('${entry.input}')`)
37+
await writeFile(output + '.cjs', `${shebang}module.exports = require(${JSON.stringify(jitiPath)})(null, { interopDefault: true, esmResolve: true })('${entry.input}')`)
3838
}
3939
// Use file:// protocol for windows compatibility
40-
await writeFile(output + '.mjs', `${shebang}import jiti from ${JSON.stringify(pathToFileURL(jitiPath).href)};\nexport default jiti(null, { interopDefault: true })('${entry.input}');`)
40+
await writeFile(output + '.mjs', `${shebang}import jiti from ${JSON.stringify(pathToFileURL(jitiPath).href)};\nexport default jiti(null, { interopDefault: true, esmResolve: true })('${entry.input}');`)
4141
await writeFile(output + '.d.ts', `export * from '${entry.input}';\nexport { default } from '${entry.input}';`)
4242

4343
if (shebang) {

‎src/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function listRecursively (path: string) {
6363
}
6464

6565
export function tryRequire (id: string, rootDir: string = process.cwd()) {
66-
const _require = jiti(rootDir, { interopDefault: true })
66+
const _require = jiti(rootDir, { interopDefault: true, esmResolve: true })
6767
try {
6868
return _require(id)
6969
} catch (err: any) {
@@ -75,7 +75,7 @@ export function tryRequire (id: string, rootDir: string = process.cwd()) {
7575
}
7676

7777
export function tryResolve (id: string, rootDir: string = process.cwd()) {
78-
const _require = jiti(rootDir, { interopDefault: true })
78+
const _require = jiti(rootDir, { interopDefault: true, esmResolve: true })
7979
try {
8080
return _require.resolve(id)
8181
} catch (err: any) {

0 commit comments

Comments
 (0)
Please sign in to comment.