Skip to content

Commit 33c1c65

Browse files
refactor: Simplify CJS type renaming (#28)
1 parent 0ab55e8 commit 33c1c65

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

src/build/index.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22

3-
import { readdirSync, renameSync } from 'node:fs'
3+
import { renameSync } from 'node:fs'
44
import { defineConfig } from 'vite'
55
import { preserveDirectives } from 'rollup-plugin-preserve-directives'
66
import { externalizeDeps } from 'vite-plugin-externalize-deps'
@@ -36,15 +36,10 @@ export const tanstackBuildConfig = (options) => {
3636
module: 'commonjs',
3737
declarationMap: false,
3838
},
39-
afterBuild: () => {
40-
const path = 'dist/cjs'
41-
readdirSync(path, { recursive: true }).forEach((file) => {
42-
if (typeof file === 'string' && file.includes('.d.ts')) {
43-
renameSync(
44-
`${path}/${file}`,
45-
`${path}/${file.replace('.d.ts', '.d.cts')}`,
46-
)
47-
}
39+
afterBuild: (emittedFiles) => {
40+
const paths = Array.from(emittedFiles.keys())
41+
paths.forEach((path) => {
42+
renameSync(path, path.replace('.d.ts', '.d.cts'))
4843
})
4944
},
5045
}),

0 commit comments

Comments
 (0)