mirror of
https://github.com/hansjone/netxops.git
synced 2026-10-13 09:20:45 +08:00
83 lines
3.1 KiB
JavaScript
83 lines
3.1 KiB
JavaScript
/**
|
||
* Build lib/index.js (host) and lib/agent-tools*.js (preset tool mounts).
|
||
* Node refuses to strip TypeScript inside node_modules, so GitHub/npm installs
|
||
* must ship prebuilt JS. Usage: bun run scripts/build-host.mjs
|
||
*
|
||
* Agent-tools entries are built as self-contained bundles (no shared chunk).
|
||
* Cordis/Desktop load each export path independently; a split chunk once missed
|
||
* a connection-publish race and is harder to reason about under custom loaders.
|
||
*/
|
||
import { mkdirSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
|
||
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path'
|
||
import { fileURLToPath } from 'node:url'
|
||
import { recordBuild } from './build-integrity.mjs'
|
||
|
||
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||
const outDir = join(root, 'lib')
|
||
|
||
const external = [
|
||
'@deepseek-ai/cordis',
|
||
'@deepseek-ai/schemastery',
|
||
'@deepseek-ai/dsh-credentials',
|
||
'@deepseek-ai/dsh-settings',
|
||
'@deepseek-ai/dsh-tools',
|
||
'@deepseek-ai/dsh-scope',
|
||
'@deepseek-ai/dsh-llm',
|
||
'@deepseek-ai/dsh-brand',
|
||
'@deepseek-ai/dsh-agent',
|
||
'@deepseek-ai/dsh-agent-presets',
|
||
'@deepseek-ai/dsh-workspace',
|
||
'@deepseek-ai/dsh-session',
|
||
'@deepseek-ai/dsh-session-title',
|
||
'@deepseek-ai/dsh-permission-presets',
|
||
'@deepseek-ai/dsh-agent-default-model',
|
||
]
|
||
|
||
const entries = [
|
||
{ entry: join(root, 'src/index.ts'), out: join(outDir, 'index.js') },
|
||
{ entry: join(root, 'src/agent-tools.ts'), out: join(outDir, 'agent-tools.js') },
|
||
{ entry: join(root, 'src/agent-tools-ops.ts'), out: join(outDir, 'agent-tools-ops.js') },
|
||
{ entry: join(root, 'src/agent-tools-nms.ts'), out: join(outDir, 'agent-tools-nms.js') },
|
||
{ entry: join(root, 'src/agent-tools-common.ts'), out: join(outDir, 'agent-tools-common.js') },
|
||
{ entry: join(root, 'src/agent-tools-topology.ts'), out: join(outDir, 'agent-tools-topology.js') },
|
||
{ entry: join(root, 'src/agent-tools-biz-monitor.ts'), out: join(outDir, 'agent-tools-biz-monitor.js') },
|
||
]
|
||
|
||
mkdirSync(outDir, { recursive: true })
|
||
|
||
/** Drop split-build leftovers from 0.1.56–0.1.57. */
|
||
for (const name of readdirSync(outDir)) {
|
||
if (name === 'agent-tools-shared.js' || /^chunk-.*\.js$/.test(name)) {
|
||
rmSync(join(outDir, name), { force: true })
|
||
}
|
||
}
|
||
for (const name of ['_split-test', '_split-test2']) {
|
||
const target = resolve(outDir, name)
|
||
const within = relative(resolve(root), target)
|
||
if (within.startsWith('..') || isAbsolute(within) || dirname(target) !== resolve(outDir)) {
|
||
throw new Error(`Refusing cleanup outside the build directory: ${target}`)
|
||
}
|
||
rmSync(target, { recursive: true, force: true })
|
||
}
|
||
|
||
for (const { entry, out } of entries) {
|
||
const result = await Bun.build({
|
||
entrypoints: [entry],
|
||
target: 'node',
|
||
format: 'esm',
|
||
sourcemap: 'none',
|
||
minify: false,
|
||
metafile: true,
|
||
external,
|
||
})
|
||
|
||
if (!result.success) {
|
||
console.error(result.logs)
|
||
throw new Error(`Bun.build host failed for ${basename(entry)}`)
|
||
}
|
||
|
||
const text = await result.outputs[0].text()
|
||
writeFileSync(out, text, 'utf8')
|
||
recordBuild(out, result, 'scripts/build-host.mjs')
|
||
console.log(`wrote ${out} (${text.length} bytes)`)
|
||
}
|