-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsup.config.ts
40 lines (39 loc) · 1.17 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
import { defineConfig } from 'tsup'
import fs from 'fs'
import path from 'path'
export default defineConfig({
entry: ['src/extension.ts'],
format: ['cjs'],
target: 'node18',
clean: true,
minify: true,
external: [
'vscode',
],
async onSuccess() {
const src = path.resolve(__dirname, 'node_modules/speedscope/dist/release')
const dest = path.resolve(__dirname, 'vendor')
fs.rmSync(dest, { recursive: true })
fs.mkdirSync(dest, { recursive: true })
let replaced = 0
for (const file of fs.readdirSync(src)) {
const source = path.join(src, file)
let target = path.join(dest, file)
if (/^speedscope\..*\.js$/.test(file)) {
fs.writeFileSync(target, fs.readFileSync(source, 'utf-8').replace(`"http:"===x||"https:"===x`, () => {
replaced++
return 'true'
}))
} else {
if (/^source-code-pro\..*\.css$/.test(file)) {
replaced++
target = path.join(dest, 'SourceCodePro-Regular.ttf.woff2')
}
fs.copyFileSync(path.join(src, file), path.join(dest, file))
}
}
if (replaced !== 2) {
throw new Error('Failed to replace the protocol check')
}
}
})