@@ -62,13 +62,15 @@ export async function rollupBuild(ctx: BuildContext) {
6262 entry . name ! ,
6363 ) ;
6464
65+ const isESM = ctx . pkg . type === "module" ;
6566 const resolvedEntry = normalize (
6667 tryResolve ( entry . input , ctx . options . rootDir ) || entry . input ,
6768 ) ;
6869 const resolvedEntryWithoutExt = resolvedEntry . slice (
6970 0 ,
7071 Math . max ( 0 , resolvedEntry . length - extname ( resolvedEntry ) . length ) ,
7172 ) ;
73+ const resolvedEntryForTypeImport = isESM ? `${ resolvedEntry . replace ( / ( \. m ? ) ( t s ) ( x ? ) $ / , "$1js$3" ) } ` : resolvedEntryWithoutExt ;
7274 const code = await fsp . readFile ( resolvedEntry , "utf8" ) ;
7375 const shebang = getShebang ( code ) ;
7476
@@ -85,7 +87,7 @@ export async function rollupBuild(ctx: BuildContext) {
8587 `const _jiti = jiti(null, ${ serializedJitiOptions } )` ,
8688 "" ,
8789 `/** @type {import(${ JSON . stringify (
88- resolvedEntryWithoutExt ,
90+ resolvedEntryForTypeImport ,
8991 ) } )} */`,
9092 `module.exports = _jiti(${ JSON . stringify ( resolvedEntry ) } )` ,
9193 ] . join ( "\n" ) ,
@@ -114,7 +116,7 @@ export async function rollupBuild(ctx: BuildContext) {
114116 "" ,
115117 `const _jiti = jiti(null, ${ serializedJitiOptions } )` ,
116118 "" ,
117- `/** @type {import(${ JSON . stringify ( resolvedEntryWithoutExt ) } )} */` ,
119+ `/** @type {import(${ JSON . stringify ( resolvedEntryForTypeImport ) } )} */` ,
118120 `const _module = await _jiti.import(${ JSON . stringify (
119121 resolvedEntry ,
120122 ) } );`,
@@ -129,10 +131,10 @@ export async function rollupBuild(ctx: BuildContext) {
129131 await writeFile (
130132 output + ".d.ts" ,
131133 [
132- `export * from ${ JSON . stringify ( resolvedEntryWithoutExt ) } ;` ,
134+ `export * from ${ JSON . stringify ( resolvedEntryForTypeImport ) } ;` ,
133135 hasDefaultExport
134136 ? `export { default } from ${ JSON . stringify (
135- resolvedEntryWithoutExt ,
137+ resolvedEntryForTypeImport ,
136138 ) } ;`
137139 : "" ,
138140 ] . join ( "\n" ) ,
0 commit comments