Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Rebuild build/mcp after every library build into build/

Nguyen Xuan And220d70fffec
diff --git a/package.json b/package.json
index 1a3c170b..bf7ab383 100644
--- a/package.json
+++ b/package.json
@@ -107,7 +107,7 @@
"scripts": {
"dev": "vite --host 127.0.0.1",
"build": "node scripts/prepare-release.mjs && vite build",
- "build:lib": "vite build --config vite.lib.config.js && node scripts/build-mcp.mjs",
+ "build:lib": "vite build --config vite.lib.config.js",
"prepare:release": "node scripts/prepare-release.mjs",
"prepack": "npm run build:lib",
"deploy": "node scripts/deploy.mjs",
diff --git a/scripts/build-mcp.mjs b/scripts/build-mcp.mjs
index 21e40eb6..666c12fc 100644
--- a/scripts/build-mcp.mjs
+++ b/scripts/build-mcp.mjs
@@ -6,7 +6,10 @@ import { constants, setPriority } from 'node:os';
import { isBuiltin } from 'node:module';
import { dirname, resolve, join, relative, isAbsolute } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
-import libraryConfiguration from '../vite.lib.config.js';
+import libraryConfiguration, { MCP_BUILD_RUNNING } from '../vite.lib.config.js';
+
+// This script reruns the library configuration in memory; the flag keeps that run from rebuilding build/mcp again.
+process.env[MCP_BUILD_RUNNING] = '1';
const root = fileURLToPath(new URL('..', import.meta.url));
diff --git a/scripts/prepare-release.mjs b/scripts/prepare-release.mjs
index 9a085d03..e2b06589 100644
--- a/scripts/prepare-release.mjs
+++ b/scripts/prepare-release.mjs
@@ -19,7 +19,6 @@ function run(executable, argumentsList, capture = false) {
const commit = run('git', ['rev-parse', 'HEAD'], true);
if (process.argv.includes('--require-clean') && run('git', ['status', '--porcelain'], true)) throw new Error('Commit release changes before production preparation.');
run(process.execPath, ['node_modules/vite/bin/vite.js', 'build', '--config', 'vite.lib.config.js']);
-run(process.execPath, ['scripts/build-mcp.mjs']);
const releases = resolve(root, 'public/releases');
await mkdir(releases, { recursive: true });
const npmCli = process.env.npm_execpath ?? resolve(dirname(process.execPath), 'node_modules/npm/bin/npm-cli.js');
diff --git a/vite.lib.config.js b/vite.lib.config.js
index c264e966..b2519364 100644
--- a/vite.lib.config.js
+++ b/vite.lib.config.js
@@ -1,12 +1,38 @@
import { defineConfig } from 'vite';
+import { spawnSync } from 'node:child_process';
+import { resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
import { glslCommentStripperForVite } from './scripts/strip-glsl-comments.mjs';
+const projectRoot = fileURLToPath(new URL('.', import.meta.url));
+export const MCP_BUILD_RUNNING = 'SIXTYSEVEN_MCP_BUILD_RUNNING';
+
+// build/mcp/preview.js imports the hashed chunks of this build, and emptyOutDir deletes build/mcp, so a library build on its
+// own would leave the MCP server broken until someone reran build-mcp.mjs. Rebuild it after every build into build/.
+// build-mcp.mjs reruns this configuration in memory and sets MCP_BUILD_RUNNING so that rebuild does not recurse; builds into
+// another folder (the archive measurement's staging package) build their own MCP bundle.
+function rebuildMcpAfterLibrary() {
+ let outputFolder;
+ return {
+ name: 'rebuild-mcp-after-library',
+ apply: 'build',
+ configResolved(config) {
+ outputFolder = resolve(config.root, config.build.outDir);
+ },
+ closeBundle() {
+ if (process.env[MCP_BUILD_RUNNING] || outputFolder !== resolve(projectRoot, 'build')) return;
+ const result = spawnSync(process.execPath, [resolve(projectRoot, 'scripts/build-mcp.mjs')], { cwd: projectRoot, stdio: 'inherit', windowsHide: true });
+ if (result.status !== 0) throw new Error('The library built, but rebuilding build/mcp failed, so the MCP server would load stale chunks. See the error above.');
+ },
+ };
+}
+
// The full texts sit once in LICENSE and THIRD-PARTY-NOTICES.md at the package root. Repeating them in each of the
// 80 built files cost about 4 KB of archive space per file.
const legalBanner = '/*! 67js, MIT License, Copyright (c) 2026 CodePawl. Bundled gl-matrix: Copyright (c) 2015-2025, Brandon Jones, Colin MacKenzie IV, MIT License. Complete license texts and third-party notices: LICENSE and THIRD-PARTY-NOTICES.md at the package root. */';
export default defineConfig({
- plugins: [glslCommentStripperForVite()],
+ plugins: [glslCommentStripperForVite(), rebuildMcpAfterLibrary()],
build: {
copyPublicDir: false,
rolldownOptions: {