mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-19 14:00:51 +00:00
* build: mirror uuid for msteams Add uuid to both the msteams bundled extension and the root package so the workspace build can resolve @microsoft/agents-hosting during tsdown while standalone extension installs also have the runtime dependency available. Regeneration-Prompt: | pnpm build failed because @microsoft/agents-hosting 1.3.1 requires uuid in its published JS but does not declare it in its package manifest. The msteams extension dynamically imports that package, and the workspace build resolves it from the root dependency graph. Mirror uuid into the root package for workspace builds and keep it in extensions/msteams/package.json so standalone plugin installs also resolve it. Update the lockfile to match the manifest changes. * build: prune stale plugin dist symlinks Remove stale dist and dist-runtime plugin node_modules symlinks before tsdown runs. These links point back into extension installs, and tsdown's clean step can traverse them on rebuilds and hollow out the active pnpm dependency tree before plugin-sdk declaration generation runs. Regeneration-Prompt: | pnpm build was intermittently failing in the plugin-sdk:dts phase after earlier build steps had already run. The symptom looked like missing root packages such as zod, ajv, commander, and undici even though a fresh install briefly fixed the problem. Investigate the build pipeline step by step rather than patching TypeScript errors. Confirm whether rebuilds mutate node_modules, identify the first step that does it, and preserve existing runtime-postbuild behavior. The key constraint is that dist and dist-runtime plugin node_modules links are intentional for runtime packaging, so do not remove that feature globally. Instead, make rebuilds safe by deleting only stale symlinks left in generated output before invoking tsdown, so tsdown cleanup cannot recurse back into the live pnpm install tree. Verify with repeated pnpm build runs.
99 lines
2.8 KiB
JavaScript
99 lines
2.8 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { spawnSync } from "node:child_process";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
const logLevel = process.env.OPENCLAW_BUILD_VERBOSE ? "info" : "warn";
|
|
const extraArgs = process.argv.slice(2);
|
|
const INEFFECTIVE_DYNAMIC_IMPORT_RE = /\[INEFFECTIVE_DYNAMIC_IMPORT\]/;
|
|
const UNRESOLVED_IMPORT_RE = /\[UNRESOLVED_IMPORT\]/;
|
|
const ANSI_ESCAPE_RE = new RegExp(String.raw`\u001B\[[0-9;]*m`, "g");
|
|
|
|
function removeDistPluginNodeModulesSymlinks(rootDir) {
|
|
const extensionsDir = path.join(rootDir, "extensions");
|
|
if (!fs.existsSync(extensionsDir)) {
|
|
return;
|
|
}
|
|
|
|
for (const dirent of fs.readdirSync(extensionsDir, { withFileTypes: true })) {
|
|
if (!dirent.isDirectory()) {
|
|
continue;
|
|
}
|
|
const nodeModulesPath = path.join(extensionsDir, dirent.name, "node_modules");
|
|
try {
|
|
if (fs.lstatSync(nodeModulesPath).isSymbolicLink()) {
|
|
fs.rmSync(nodeModulesPath, { force: true, recursive: true });
|
|
}
|
|
} catch {
|
|
// Skip missing or unreadable paths so the build can proceed.
|
|
}
|
|
}
|
|
}
|
|
|
|
function pruneStaleRuntimeSymlinks() {
|
|
const cwd = process.cwd();
|
|
// runtime-postbuild links dist/dist-runtime plugin node_modules back into the
|
|
// source extensions. Remove only those symlinks up front so tsdown's clean
|
|
// step cannot traverse into the active pnpm install tree on rebuilds.
|
|
removeDistPluginNodeModulesSymlinks(path.join(cwd, "dist"));
|
|
removeDistPluginNodeModulesSymlinks(path.join(cwd, "dist-runtime"));
|
|
}
|
|
|
|
pruneStaleRuntimeSymlinks();
|
|
|
|
function findFatalUnresolvedImport(lines) {
|
|
for (const line of lines) {
|
|
if (!UNRESOLVED_IMPORT_RE.test(line)) {
|
|
continue;
|
|
}
|
|
|
|
const normalizedLine = line.replace(ANSI_ESCAPE_RE, "");
|
|
if (!normalizedLine.includes("extensions/")) {
|
|
return normalizedLine;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
const result = spawnSync(
|
|
"pnpm",
|
|
["exec", "tsdown", "--config-loader", "unrun", "--logLevel", logLevel, ...extraArgs],
|
|
{
|
|
encoding: "utf8",
|
|
stdio: "pipe",
|
|
shell: process.platform === "win32",
|
|
},
|
|
);
|
|
|
|
const stdout = result.stdout ?? "";
|
|
const stderr = result.stderr ?? "";
|
|
if (stdout) {
|
|
process.stdout.write(stdout);
|
|
}
|
|
if (stderr) {
|
|
process.stderr.write(stderr);
|
|
}
|
|
|
|
if (result.status === 0 && INEFFECTIVE_DYNAMIC_IMPORT_RE.test(`${stdout}\n${stderr}`)) {
|
|
console.error(
|
|
"Build emitted [INEFFECTIVE_DYNAMIC_IMPORT]. Replace transparent runtime re-export facades with real runtime boundaries.",
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
const fatalUnresolvedImport =
|
|
result.status === 0 ? findFatalUnresolvedImport(`${stdout}\n${stderr}`.split("\n")) : null;
|
|
|
|
if (fatalUnresolvedImport) {
|
|
console.error(`Build emitted [UNRESOLVED_IMPORT] outside extensions: ${fatalUnresolvedImport}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (typeof result.status === "number") {
|
|
process.exit(result.status);
|
|
}
|
|
|
|
process.exit(1);
|