forked from openclaw/openclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
162 lines (148 loc) · 5.13 KB
/
tsdown.config.ts
File metadata and controls
162 lines (148 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import fs from "node:fs";
import path from "node:path";
import { defineConfig } from "tsdown";
import { buildPluginSdkEntrySources } from "./scripts/lib/plugin-sdk-entries.mjs";
const env = {
NODE_ENV: "production",
};
function buildInputOptions(options: { onLog?: unknown; [key: string]: unknown }) {
if (process.env.OPENCLAW_BUILD_VERBOSE === "1") {
return undefined;
}
const previousOnLog = typeof options.onLog === "function" ? options.onLog : undefined;
function isSuppressedLog(log: {
code?: string;
message?: string;
id?: string;
importer?: string;
}) {
if (log.code === "PLUGIN_TIMINGS") {
return true;
}
if (log.code !== "EVAL") {
return false;
}
const haystack = [log.message, log.id, log.importer].filter(Boolean).join("\n");
return haystack.includes("@protobufjs/inquire/index.js");
}
return {
...options,
onLog(
level: string,
log: { code?: string; message?: string; id?: string; importer?: string },
defaultHandler: (level: string, log: { code?: string }) => void,
) {
if (isSuppressedLog(log)) {
return;
}
if (typeof previousOnLog === "function") {
previousOnLog(level, log, defaultHandler);
return;
}
defaultHandler(level, log);
},
};
}
function nodeBuildConfig(config: Record<string, unknown>) {
return {
...config,
env,
fixedExtension: false,
platform: "node",
inputOptions: buildInputOptions,
};
}
function listBundledPluginBuildEntries(): Record<string, string> {
const extensionsRoot = path.join(process.cwd(), "extensions");
const entries: Record<string, string> = {};
for (const dirent of fs.readdirSync(extensionsRoot, { withFileTypes: true })) {
if (!dirent.isDirectory()) {
continue;
}
const pluginDir = path.join(extensionsRoot, dirent.name);
const manifestPath = path.join(pluginDir, "openclaw.plugin.json");
if (!fs.existsSync(manifestPath)) {
continue;
}
const packageJsonPath = path.join(pluginDir, "package.json");
let packageEntries: string[] = [];
if (fs.existsSync(packageJsonPath)) {
try {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")) as {
openclaw?: { extensions?: unknown; setupEntry?: unknown };
};
packageEntries = Array.isArray(packageJson.openclaw?.extensions)
? packageJson.openclaw.extensions.filter(
(entry): entry is string => typeof entry === "string" && entry.trim().length > 0,
)
: [];
const setupEntry =
typeof packageJson.openclaw?.setupEntry === "string" &&
packageJson.openclaw.setupEntry.trim().length > 0
? packageJson.openclaw.setupEntry
: undefined;
if (setupEntry) {
packageEntries = Array.from(new Set([...packageEntries, setupEntry]));
}
} catch {
packageEntries = [];
}
}
const sourceEntries = packageEntries.length > 0 ? packageEntries : ["./index.ts"];
for (const entry of sourceEntries) {
const normalizedEntry = entry.replace(/^\.\//, "");
const entryKey = `extensions/${dirent.name}/${normalizedEntry.replace(/\.[^.]+$/u, "")}`;
entries[entryKey] = path.join("extensions", dirent.name, normalizedEntry);
}
}
return entries;
}
const bundledPluginBuildEntries = listBundledPluginBuildEntries();
export default defineConfig([
nodeBuildConfig({
entry: "src/index.ts",
}),
nodeBuildConfig({
entry: "src/entry.ts",
}),
nodeBuildConfig({
// Ensure this module is bundled as an entry so legacy CLI shims can resolve its exports.
entry: "src/cli/daemon-cli.ts",
}),
nodeBuildConfig({
entry: "src/infra/warning-filter.ts",
}),
nodeBuildConfig({
// Keep sync lazy-runtime channel modules as concrete dist files.
entry: {
"channels/plugins/agent-tools/whatsapp-login":
"src/channels/plugins/agent-tools/whatsapp-login.ts",
"channels/plugins/actions/discord": "src/channels/plugins/actions/discord.ts",
"channels/plugins/actions/signal": "src/channels/plugins/actions/signal.ts",
"channels/plugins/actions/telegram": "src/channels/plugins/actions/telegram.ts",
"telegram/audit": "extensions/telegram/src/audit.ts",
"telegram/token": "extensions/telegram/src/token.ts",
"line/accounts": "src/line/accounts.ts",
"line/send": "src/line/send.ts",
"line/template-messages": "src/line/template-messages.ts",
},
}),
nodeBuildConfig({
// Bundle all plugin-sdk entries in a single build so the bundler can share
// common chunks instead of duplicating them per entry (~712MB heap saved).
entry: buildPluginSdkEntrySources(),
outDir: "dist/plugin-sdk",
}),
nodeBuildConfig({
// Bundle bundled plugin entrypoints so built gateway startup can load JS
// directly from dist/extensions instead of transpiling extensions/*.ts via Jiti.
entry: bundledPluginBuildEntries,
outDir: "dist",
}),
nodeBuildConfig({
entry: "src/extensionAPI.ts",
}),
nodeBuildConfig({
entry: ["src/hooks/bundled/*/handler.ts", "src/hooks/llm-slug-generator.ts"],
}),
]);