-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtsup.config.js
More file actions
54 lines (48 loc) · 1.82 KB
/
tsup.config.js
File metadata and controls
54 lines (48 loc) · 1.82 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
43
44
45
46
47
48
49
50
51
52
53
54
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import dotenv from 'dotenv'
import { defineConfig } from 'tsup'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
/** esbuild plugin: import files matching a suffix as plain-text strings. */
function textLoaderPlugin(suffix) {
return {
name: 'text-loader',
setup(build) {
build.onLoad({ filter: new RegExp(suffix.replace('.', '\\.') + '$') }, (args) => ({
contents: `export default ${JSON.stringify(fs.readFileSync(args.path, 'utf8'))}`,
loader: 'js',
}))
},
}
}
export default defineConfig(({ env }) => {
const isProd = env.NODE_ENV === 'production'
// Load .env so build-time secrets (e.g. DD_RUM_TOKEN) are available.
// In CI/prepack, `dotenv-vault pull production .env` runs first.
// Fallbacks (override: false → first value wins):
// 1. cli/.env (from dotenv-vault pull)
// 2. tracer_ext/.env (shares the same DD_RUM_TOKEN)
// 3. repo root .env
dotenv.config()
dotenv.config({ path: path.resolve(__dirname, '../tracer_ext/.env'), override: false })
dotenv.config({ path: path.resolve(__dirname, '../../.env'), override: false })
return {
sourcemap: !isProd, // source map is only available in prod
clean: true, // clean dist before build
format: ['esm'],
minify: false,
bundle: true,
splitting: false,
watch: !isProd,
target: 'es2020',
entry: ['src/index.ts', 'src/args/commands/upload_ai_blame.ts', 'src/hash_search/index.ts'],
tsconfig: './tsconfig.json',
dts: true,
esbuildPlugins: [textLoaderPlugin('daemon-check-shim.tmpl.js')],
define: {
__DD_RUM_TOKEN__: JSON.stringify(process.env.DD_RUM_TOKEN ?? ''),
__CLI_VERSION__: JSON.stringify(process.env.npm_package_version ?? 'unknown'),
},
}
})