-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
42 lines (35 loc) · 1.11 KB
/
tsdown.config.ts
File metadata and controls
42 lines (35 loc) · 1.11 KB
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
import { globSync, existsSync, readFileSync, writeFileSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'tsdown'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const entry = globSync('src/**/*.ts')
export default defineConfig({
tsconfig: 'tsconfig.build.json',
entry,
target: 'node18',
dts: true,
unbundle: true,
sourcemap: false,
hooks: {
'build:done': (ctx) => {
const pkg = ctx.options.pkg
const binFilesList =
typeof pkg.bin === 'string'
? [pkg.bin as string]
: typeof pkg.bin === 'object'
? [...new Set(Object.values(pkg.bin) as string[])]
: []
binFilesList
.map((file) => resolve(__dirname, file))
.filter((file) => existsSync(file))
.forEach((file) => {
const content = readFileSync(file, 'utf8')
const shebang = `#!/usr/bin/env node`
if (!content.startsWith(shebang))
writeFileSync(file, `${shebang}\n${content}`)
})
}
}
})