mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-10-23 03:47:00 +09:00
#4277 fixed the bundle drift and made the build start on Windows by running `npx esbuild` with `shell: true` when process.platform is win32. That branch ignores ESBUILD, so a Windows --check doesn't use the esbuild version CI pins, and it hands the file paths to cmd.exe unquoted. Replace the branch with one path for every OS: ESBUILD, when set, is still run directly as an executable (CI, the plugin READMEs and codex-mod-hooks.test.mjs rely on it); without it the repo's own esbuild is loaded through its JS API (buildSync), as plugins/ruflo-console/scripts/build-tui.mjs already does. No shell, no .bin shim. Bundles are unchanged. Co-Authored-By: RuFlo <ruv@ruv.net>
35 lines
2.2 KiB
JavaScript
35 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
|
// Bundle exact existing pure guard/screen/status functions, never a second secret detector.
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import os from 'node:os';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { createRequire } from 'node:module';
|
|
import { fileURLToPath } from 'node:url';
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
const options = ['--bundle', '--platform=node', '--target=node20', '--format=cjs', '--minify-whitespace'];
|
|
// ESBUILD names an executable (CI pins one); run it directly, never through a shell. Without it, use the
|
|
// repo's own esbuild through its JS API, which needs no .bin shim and behaves the same on every OS.
|
|
const bundle = process.env.ESBUILD ? (entry, output) => {
|
|
execFileSync(process.env.ESBUILD, [entry, ...options, `--outfile=${output}`], { stdio: 'pipe' });
|
|
return fs.readFileSync(output, 'utf8');
|
|
} : (() => {
|
|
let esbuild;
|
|
try { esbuild = createRequire(path.join(root, 'package.json'))('esbuild'); } catch {
|
|
throw new Error('esbuild is not installed: run npm install at the repo root, or set ESBUILD to an esbuild executable');
|
|
}
|
|
return (entry, output) => esbuild.buildSync({ entryPoints: [entry], bundle: true, platform: 'node', target: 'node20', format: 'cjs', minifyWhitespace: true, outfile: output, write: false, logLevel: 'silent' }).outputFiles[0].text;
|
|
})();
|
|
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'ruflo-codex-mod-build-'));
|
|
try {
|
|
for (const name of ['adr', 'ddd', 'sparc']) {
|
|
const target = path.join(root, `plugins/ruflo-${name}/hooks/codex-hook.cjs`);
|
|
const output = path.join(temp, `${name}.cjs`);
|
|
const bytes = `// Generated by scripts/build-codex-mod-hooks.mjs; edit codex.ts or shared runtime, not this bundle.\n${bundle(path.join(root, `plugins/ruflo-${name}/hooks/codex.ts`), output)}`;
|
|
if (process.argv.includes('--check')) {
|
|
if (!fs.existsSync(target) || fs.readFileSync(target, 'utf8') !== bytes) throw new Error(`${name}: native bundle drift; rebuild before release`);
|
|
} else fs.writeFileSync(target, bytes);
|
|
}
|
|
console.log('codex-mod-hooks: three bundles match their shared sources');
|
|
} finally { fs.rmSync(temp, { recursive: true, force: true }); }
|