Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
3554ff538This file is pinned to the selected release. Download the original to open it in your design tool.
/**
* Release build: bundle the whole CLI into ONE self-contained `dist/cli.js` (all deps are pure-JS, so
* a single artifact runs on every OS under the user's Node) + copy the standalone hook script.
*
* Version is baked in via esbuild `define(__ADAPTER_VERSION__)`, sourced from `ADAPTER_VERSION`
* (set by scripts/upload-cli.sh) else package.json — so the running binary's version EXACTLY
* equals the published manifest version (the self-updater compares them).
*
* `bufferutil`/`utf-8-validate` are ws's OPTIONAL native deps — mark external and provide a real
* `require` via the banner so ws's try/catch fallback works without them.
*/
import * as esbuild from 'esbuild'
import { readFileSync, copyFileSync, rmSync } from 'fs'
import { readDshRegistry } from './scripts/lib/dshRegistry.mjs'
const version =
process.env.ADAPTER_VERSION ||
JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version
// The bundled registry (the store/ folders and store/registry at the repo root) — see src/dsh/registry.ts.
const dshRegistry = JSON.stringify(readDshRegistry(new URL('../store', import.meta.url)))
// Start clean so no stale per-file `dist/*.js` / sourcemaps leak into the release artifact.
rmSync('dist', { recursive: true, force: true })
await esbuild.build({
entryPoints: ['src/cli.ts'],
outfile: 'dist/cli.js',
bundle: true,
platform: 'node',
format: 'esm',
target: 'node20',
external: ['bufferutil', 'utf-8-validate'],
define: {
__ADAPTER_VERSION__: JSON.stringify(version),
__DSH_REGISTRY__: JSON.stringify(dshRegistry),
},
// The copyright line is MIT's one condition — it has to travel with the copy the user actually
// receives, and the published bundle IS that copy (upload-cli.sh ships `cli.js` and `notify.mjs`,
// nothing else). `legalComments: 'eof'` below appends the dependencies' own notices; this is ours.
banner: {
js: `/*! harness v${version} — Copyright (c) 2026 Autonomous, Inc. — MIT (https://github.com/autonomous-ai/openharness) */\n`
+ 'import{createRequire as ___cr}from"module";const require=___cr(import.meta.url);',
},
sourcemap: false,
minify: true,
keepNames: true,
legalComments: 'eof',
logLevel: 'info',
})
copyFileSync('hook/notify.mjs', 'dist/notify.mjs')
console.log(`✓ Bundled dist/cli.js (v${version}) + dist/notify.mjs`)