-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtsup.config.ts
More file actions
41 lines (40 loc) · 1.13 KB
/
Copy pathtsup.config.ts
File metadata and controls
41 lines (40 loc) · 1.13 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
import fs from 'fs'
import { defineConfig } from 'tsup'
export default defineConfig((options) => {
// Conditional config: fast build (--no-dts) vs full build
const dts = options.dts !== false
const now = Date.now()
return {
entry: ['src/index.ts'],
format: ['esm'],
platform: 'node',
target: 'node20',
outDir: 'dist',
dts,
clean: dts,
treeshake: dts,
minify: dts,
silent: !dts,
skipNodeModulesBundle: true,
esbuildOptions(options) {
options.banner = {
js: '#!/usr/bin/env node',
}
options.legalComments = 'none'
options.drop = ['debugger']
},
async onSuccess() {
// Fix deprecated import assertion syntax in built output
const outputPath = 'dist/index.js'
let content = fs.readFileSync(outputPath, 'utf-8')
content = content.replace(
/import\([^,]+,\s*\{\s*assert:\s*\{\s*type:\s*['"]json['"]\s*\}\s*\}\s*\)/g,
(match) => match.replace('assert:', 'with:'),
)
fs.writeFileSync(outputPath, content, 'utf-8')
if (!dts) {
console.log(`Build success in ${Date.now() - now}ms`)
}
},
}
})