mirror of
https://github.com/Heretek-AI/openclaw.git
synced 2026-07-01 01:37:55 -04:00
fix: generate dist/package.json with .mjs export maps post-build
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.
This commit is contained in:
@@ -3,6 +3,7 @@ import { copyBundledPluginMetadata } from "./copy-bundled-plugin-metadata.mjs";
|
||||
import { copyPluginSdkRootAlias } from "./copy-plugin-sdk-root-alias.mjs";
|
||||
import { stageBundledPluginRuntimeDeps } from "./stage-bundled-plugin-runtime-deps.mjs";
|
||||
import { stageBundledPluginRuntime } from "./stage-bundled-plugin-runtime.mjs";
|
||||
import { writeDistPackageJson } from "./write-dist-package-json.mjs";
|
||||
import { writeOfficialChannelCatalog } from "./write-official-channel-catalog.mjs";
|
||||
|
||||
export function runRuntimePostBuild(params = {}) {
|
||||
@@ -11,6 +12,7 @@ export function runRuntimePostBuild(params = {}) {
|
||||
writeOfficialChannelCatalog(params);
|
||||
stageBundledPluginRuntimeDeps(params);
|
||||
stageBundledPluginRuntime(params);
|
||||
writeDistPackageJson(params);
|
||||
}
|
||||
|
||||
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/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();
|
||||
}
|
||||
Reference in New Issue
Block a user