@@ -78,21 +78,21 @@ const config: BuildConfig = defineBuildConfig({
78
78
console . error ( e instanceof Error ? e . message : e )
79
79
}
80
80
81
- // include file extensions for bare specifiers
81
+ // include file extensions in import specifiers
82
82
// 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' )
92
91
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
95
94
95
+ if ( / ^ ( \w | @ ) / . test ( specifier ) ) {
96
96
const { path : id } = await resolveId ( specifier , process . cwd ( ) , {
97
97
type : 'module'
98
98
} )
@@ -101,12 +101,17 @@ const config: BuildConfig = defineBuildConfig({
101
101
code ,
102
102
code . replace ( specifier , id . split ( 'node_modules/' ) [ 1 ] ! )
103
103
)
104
+ } else {
105
+ content = content . replace (
106
+ code ,
107
+ code . replace ( specifier , specifier + '.' + entry . ext ! )
108
+ )
104
109
}
105
-
106
- await fs . promises . writeFile ( entry , content )
107
- } catch ( e : unknown ) {
108
- console . error ( e instanceof Error ? e . message : e )
109
110
}
111
+
112
+ await fs . promises . writeFile ( file , content )
113
+ } catch ( e : unknown ) {
114
+ console . error ( e instanceof Error ? e . message : e )
110
115
}
111
116
}
112
117
0 commit comments