-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgen-runtime-package.mjs
More file actions
59 lines (50 loc) · 1.68 KB
/
gen-runtime-package.mjs
File metadata and controls
59 lines (50 loc) · 1.68 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
#!/usr/bin/env node
// Generates a minimal package.json for the Docker runtime stage.
//
// Runtime deps = esbuild externals (packages that can't be bundled due to
// native modules, WASM, etc.). Versions are read from the root package.json
// so there's a single source of truth.
//
// Usage: node scripts/gen-runtime-package.mjs > runtime-package.json
import { readFileSync } from 'fs'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const rootDir = join(__dirname, '..')
const pkg = JSON.parse(readFileSync(join(rootDir, 'package.json'), 'utf-8'))
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies }
// Extract externals from build-server.mjs
const buildScript = readFileSync(join(rootDir, 'scripts/build-server.mjs'), 'utf-8')
const externalsMatch = buildScript.match(/external:\s*\[([\s\S]*?)\]/)
if (!externalsMatch) {
console.error('Could not find external array in build-server.mjs')
process.exit(1)
}
const externals = externalsMatch[1]
.split('\n')
.map((line) => line.match(/'([^']+)'/)?.[1])
.filter(Boolean)
// Resolve versions from package.json
const deps = {}
const missing = []
for (const name of externals) {
if (allDeps[name]) {
deps[name] = allDeps[name]
} else {
missing.push(name)
}
}
if (missing.length > 0) {
console.error('esbuild externals not found in package.json:')
for (const name of missing) {
console.error(` - ${name}`)
}
console.error('\nAdd them to dependencies in package.json.')
process.exit(1)
}
const runtimePkg = {
name: 'pgconsole-runtime',
type: 'module',
dependencies: deps,
}
console.log(JSON.stringify(runtimePkg, null, 2))