forked from voidauth/voidauth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.config.ts
More file actions
86 lines (76 loc) · 2.29 KB
/
Copy pathesbuild.config.ts
File metadata and controls
86 lines (76 loc) · 2.29 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import esbuild from 'esbuild'
import path from 'node:path'
import { readFileSync, rmSync, writeFileSync } from 'node:fs'
import madge from 'madge'
const madgeResult = await madge('./server/index.ts', {
detectiveOptions: {
ts: {
skipTypeImports: true,
},
},
})
const circularDependencies = madgeResult.circular()
if (circularDependencies.length > 0) {
circularDependencies.forEach((cycle) => {
console.error('Circular dependency: ' + cycle.join(' → '))
})
process.exit(1)
}
const outDir = './dist'
rmSync(outDir, {
recursive: true,
force: true,
})
// dependencies that cannot be bundled and are used during execution
const externalDeps = [
'better-sqlite3',
'@angular/material',
]
await esbuild.build({
entryPoints: ['./server/index.ts'],
bundle: true,
platform: 'node',
packages: 'bundle',
format: 'esm',
target: 'node24',
outfile: path.join(outDir, 'index.mjs'),
mainFields: ['module', 'main'],
sourcemap: false,
minifyWhitespace: true, // other minify options break things
conditions: ['node'],
banner: {
js: [
`import { createRequire as topLevelCreateRequire } from 'module'`,
`import { fileURLToPath as topLevelFileURLToPath } from 'node:url'`,
`import { dirname as topLevelDirname } from 'node:path'`,
`const require = topLevelCreateRequire(import.meta.url)`,
`const __filename = topLevelFileURLToPath(import.meta.url)`,
`const __dirname = topLevelDirname(__filename)`,
].join('\n'),
},
// external packages that cannot be bundled plus whatever needs to be external to get bundle to run
external: externalDeps.concat([
'sqlite3',
'mysql2',
'mysql',
'pg-query-stream',
'tedious',
'oracledb',
'cpu-features',
'*.node',
]),
}).catch(() => process.exit(1))
// Write a shim package.json with just the external dependencies,
// using the real package.json to get version information
const packagejson = JSON.parse(readFileSync('./package.json', 'utf-8')) as { dependencies: { [k: string]: string } }
const deps = packagejson.dependencies
const d: { [k: string]: string } = {}
for (const dep of externalDeps) {
if (deps[dep]) {
d[dep] = deps[dep]
}
}
// Write the shim package.json to /dist, used in Dockerfile
writeFileSync('./dist/package.json', JSON.stringify({
dependencies: d,
}))