mirror of
https://github.com/Heretek-AI/openclaw.git
synced 2026-07-20 05:24:27 -04:00
4f9e0618f9
Ensures bare specifier imports like 'openclaw/plugin-sdk/...' resolve correctly without requiring a manual node_modules/openclaw symlink. Fixes TM-3/TM-4 gateway startup failures due to ERR_MODULE_NOT_FOUND for openclaw plugin-sdk subpath imports.
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
#!/usr/bin/env node
|
|
// Generates dist/package.json with proper ESM export maps so that
|
|
// bare specifier imports like "openclaw/plugin-sdk/..." resolve correctly.
|
|
//
|
|
// Run automatically as part of runtime-postbuild; can also be run standalone:
|
|
// node scripts/write-dist-package-json.mjs
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
|
|
export function writeDistPackageJson(params = {}) {
|
|
const distDir = params.rootDir
|
|
? path.join(params.rootDir, "dist")
|
|
: path.join(process.cwd(), "dist");
|
|
|
|
const pkg = {
|
|
name: "openclaw",
|
|
version: "0.0.0",
|
|
type: "module",
|
|
main: "./entry.mjs",
|
|
exports: {
|
|
".": "./entry.mjs",
|
|
"./plugin-sdk": "./plugin-sdk/index.mjs",
|
|
"./plugin-sdk/*": "./plugin-sdk/*.mjs",
|
|
},
|
|
};
|
|
|
|
const outPath = path.join(distDir, "package.json");
|
|
fs.mkdirSync(distDir, { recursive: true });
|
|
fs.writeFileSync(outPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
console.log(`[write-dist-package-json] Wrote ${outPath}`);
|
|
}
|
|
|
|
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
|
|
writeDistPackageJson();
|
|
}
|