-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtsup.config.ts
43 lines (36 loc) · 1.06 KB
/
tsup.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { cp, readFile, readdir, rm, writeFile } from 'node:fs/promises'
import { join } from 'node:path'
import { defineConfig } from 'tsup'
export default defineConfig({
clean: true,
dts: true,
entryPoints: ['./src/index.mts', './src/bin.mts'],
format: ['cjs', 'esm'],
shims: true,
async onSuccess() {
const distPath = join(__dirname, 'dist')
// `publicDir` is not working on re-builds in `watch` mode.
await cp(join(__dirname, 'src/templates'), join(distPath, 'templates'), {
recursive: true,
})
const distFolder = await readdir(distPath, { withFileTypes: true })
for (const dirent of distFolder) {
const { name } = dirent
const filePath = join(distPath, name)
if (dirent.isFile() && name.endsWith('.js')) {
const file = await readFile(filePath, {
encoding: 'utf-8',
})
await writeFile(
filePath,
// esm output imports node built-in modules without `node:` specifiers,
// which fails in Deno.
file.replace(
/"(fs|fs\/promises|path|url|child_process)"/g,
'"node:$1"',
),
)
}
}
},
})