Files
Agent-System-Core/scripts/build-package.mjs
T
weichen f32d431784 Enable canonical versioned Go module consumption
Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements.

Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate.

Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable.

Refs: Versioned dependencies U1/U3; feature/dependency-workspace
2026-10-13 15:11:37 +00:00

25 lines
1.2 KiB
JavaScript

// Explicit generation only: authenticated Git acquisition must never run package scripts.
import { execFileSync } from 'node:child_process'
import { mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const root = dirname(dirname(fileURLToPath(import.meta.url)))
const check = process.argv.includes('--check')
const output = check ? mkdtempSync(join(tmpdir(), 'agent-contracts-build-')) : join(root, 'package')
try {
mkdirSync(output, { recursive: true })
execFileSync(process.execPath, [join(root, 'node_modules/typescript/bin/tsc'), '-p', join(root, 'tsconfig.package.json'), '--outDir', output], { cwd: root, stdio: 'inherit' })
for (const extension of ['js', 'd.ts']) renameSync(join(output, `types.${extension}`), join(output, `index.${extension}`))
if (check) {
for (const file of ['index.js', 'index.d.ts']) {
if (!readFileSync(join(root, 'package', file)).equals(readFileSync(join(output, file)))) {
throw new Error(`package/${file} is stale; run npm run build before committing the provider`)
}
}
}
} finally {
if (check) rmSync(output, { recursive: true, force: true })
}