Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Build the Node resolver library byte-identically from any directory
garrytanfe78dd6917b0
diff --git a/src/commands/skill-resolver-library.ts b/src/commands/skill-resolver-library.tsindex 9970e9d6d5..ecfe21c8f3 100644--- a/src/commands/skill-resolver-library.ts+++ b/src/commands/skill-resolver-library.ts@@ -23,7 +23,7 @@ export async function buildResolverLibrary(out: string): Promise<LibraryBuild> {const dir = dirname(out);mkdirSync(dir, { recursive: true });const tmp = `.${basename(out)}.tmp-${process.pid}`;- const result = await Bun.build({ entrypoints: [ENTRY], target: 'node', format: 'esm', outdir: dir, naming: tmp });+ const result = await Bun.build({ entrypoints: [ENTRY], target: 'node', format: 'esm', outdir: dir, naming: tmp, minify: { whitespace: true } });if (!result.success) {rmSync(join(dir, tmp), { force: true });throw new Error(`the skill resolver library did not build: ${result.logs.map(String).join('; ')}`);diff --git a/test/skill-resolver-packaging.test.ts b/test/skill-resolver-packaging.test.tsindex b68263b86f..0a0b462ead 100644--- a/test/skill-resolver-packaging.test.ts+++ b/test/skill-resolver-packaging.test.ts@@ -9,8 +9,9 @@* Node with no node_modules. In CI a missing node fails instead of skipping.* 2. Fails when: the export path moves, the bundle stops building or running* under Node (a Bun-only API, an unbundled dependency, a JSON import- * without its attribute), the CLI and the release build differ, or the- * release stops attaching or checking the sha256.+ * without its attribute), the CLI and the release build differ, the build+ * depends on the working directory, or the release stops attaching or+ * checking the sha256.*/import { describe, expect, test } from 'bun:test';import { mkdtempSync, readFileSync, rmSync } from 'node:fs';@@ -62,6 +63,21 @@ describe('skill resolver packaging', () => {}}, 120_000);+ test('the bundle is byte-identical whatever directory it is built from', () => {+ const dir = mkdtempSync(join(tmpdir(), 'skres-repro-'));+ try {+ const sums = [ROOT, dir].map((cwd, i) => {+ const out = join(dir, `b${i}.mjs`);+ const run = Bun.spawnSync([process.execPath, join(ROOT, 'scripts/build-skill-resolver-bundle.ts'), '--out', out], { cwd, stdout: 'pipe', stderr: 'pipe' });+ expect(run.exitCode, run.stderr.toString()).toBe(0);+ return createHash('sha256').update(readFileSync(out)).digest('hex');+ });+ expect(sums[1]).toBe(sums[0]);+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ }, 120_000);+test.skipIf(needNode)('the version module imports under node (JSON import attribute)', () => {const run = Bun.spawnSync([NODE!, '--input-type=module', '-e', `const m = await import(${JSON.stringify(join(ROOT, 'src/version.ts'))}); console.log(m.VERSION);`], { cwd: ROOT, stdout: 'pipe', stderr: 'pipe' });expect(run.exitCode, run.stderr.toString()).toBe(0);