Skip to content

Commit 79b2f2c

Browse files
committed
build: postprocess declaration imports to include .mjs extension for NodeNext/Node16 TS resolution (#110)
1 parent 6572b3f commit 79b2f2c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

build/bundle.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,26 @@ async function bundleDeclarations() {
208208
await execa("shx", ["rm", `${rootDir}/dist/index.js`])
209209
}
210210

211+
async function fixDeclarationImports() {
212+
info("Fixing declaration import extensions for NodeNext")
213+
const files = [
214+
`${rootDir}/dist/react/index.d.ts`,
215+
`${rootDir}/dist/preact/index.d.ts`,
216+
`${rootDir}/dist/solid/index.d.ts`,
217+
`${rootDir}/dist/vue/index.d.ts`,
218+
`${rootDir}/dist/angular/index.d.ts`,
219+
]
220+
for (const file of files) {
221+
try {
222+
let raw = await readFile(file, "utf8")
223+
raw = raw.replace(/from '\.\.\/index'"?/g, "from '../index.mjs'")
224+
await writeFile(file, raw)
225+
} catch (e) {
226+
error(`Failed to postprocess ${file}: ${(e as Error).message}`)
227+
}
228+
}
229+
}
230+
211231
async function addPackageJSON() {
212232
info("Writing package.json")
213233
const raw = await readFile(resolve(rootDir, "package.json"), "utf8")
@@ -302,6 +322,7 @@ async function main() {
302322
// await qwikBuild()
303323
await declarationsBuild()
304324
await bundleDeclarations()
325+
await fixDeclarationImports()
305326
await nuxtBuild()
306327
await addPackageJSON()
307328
await addAssets()

0 commit comments

Comments
 (0)