@@ -78,21 +78,21 @@ const config: BuildConfig = defineBuildConfig({
7878 console . error ( e instanceof Error ? e . message : e )
7979 }
8080
81- // include file extensions for bare specifiers
81+ // include file extensions in import specifiers
8282 // https://nodejs.org/docs/latest-v16.x/api/esm.html#import-specifiers
83- if ( entry . format === 'esm' ) {
84- for ( const entry of writtenFiles ) {
85- try {
86- /**
87- * {@link entry } content.
88- *
89- * @var {string} content
90- */
91- let content : string = await fs . promises . readFile ( entry , 'utf8' )
83+ for ( const file of writtenFiles ) {
84+ try {
85+ /**
86+ * {@link file } content.
87+ *
88+ * @var {string} content
89+ */
90+ let content : string = await fs . promises . readFile ( file , 'utf8' )
9291
93- for ( const { code, specifier } of findStaticImports ( content ) ) {
94- if ( ! / ^ ( \w | @ ) / . test ( specifier ) ) continue
92+ for ( const { code, specifier } of findStaticImports ( content ) ) {
93+ if ( path . extname ( specifier ) ) continue
9594
95+ if ( / ^ ( \w | @ ) / . test ( specifier ) ) {
9696 const { path : id } = await resolveId ( specifier , process . cwd ( ) , {
9797 type : 'module'
9898 } )
@@ -101,12 +101,17 @@ const config: BuildConfig = defineBuildConfig({
101101 code ,
102102 code . replace ( specifier , id . split ( 'node_modules/' ) [ 1 ] ! )
103103 )
104+ } else {
105+ content = content . replace (
106+ code ,
107+ code . replace ( specifier , specifier + '.' + entry . ext ! )
108+ )
104109 }
105-
106- await fs . promises . writeFile ( entry , content )
107- } catch ( e : unknown ) {
108- console . error ( e instanceof Error ? e . message : e )
109110 }
111+
112+ await fs . promises . writeFile ( file , content )
113+ } catch ( e : unknown ) {
114+ console . error ( e instanceof Error ? e . message : e )
110115 }
111116 }
112117
0 commit comments