mirror of
https://github.com/Heretek-AI/openclaw.git
synced 2026-07-19 19:03:35 -04:00
75 lines
2.0 KiB
JavaScript
75 lines
2.0 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Build wrapper using tsdown's programmatic API
|
|
* This bypasses the CLI's problematic ESM loader path that triggers
|
|
* ERR_INTERNAL_ASSERTION on Node.js 22+
|
|
*/
|
|
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { build } from "tsdown";
|
|
|
|
const _logLevel = process.env.OPENCLAW_BUILD_VERBOSE ? "info" : "warn";
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|
|
|
|
function pruneStaleRuntimeSymlinks() {
|
|
const cwd = process.cwd();
|
|
removeDistPluginNodeModulesSymlinks(path.join(cwd, "dist"));
|
|
removeDistPluginNodeModulesSymlinks(path.join(cwd, "dist-runtime"));
|
|
}
|
|
|
|
pruneStaleRuntimeSymlinks();
|
|
|
|
async function runBuild() {
|
|
try {
|
|
console.log("Starting build via tsdown programmatic API...");
|
|
|
|
// Load config manually to avoid CLI's config loader
|
|
const configPath = path.join(process.cwd(), "tsdown.config.ts");
|
|
let config;
|
|
|
|
if (fs.existsSync(configPath)) {
|
|
// Use dynamic import with tsx to handle TS config
|
|
const configModule = await import(configPath);
|
|
config = configModule.default;
|
|
} else {
|
|
throw new Error("tsdown.config.ts not found");
|
|
}
|
|
|
|
// Run build with programmatic API
|
|
await build(config);
|
|
|
|
console.log("Build completed successfully");
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error("Build failed:", error.message);
|
|
if (error.stack) {
|
|
console.error(error.stack);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
void runBuild();
|