-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathtsdown.config.mjs
More file actions
147 lines (137 loc) · 3.92 KB
/
tsdown.config.mjs
File metadata and controls
147 lines (137 loc) · 3.92 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
import { existsSync } from "node:fs";
import { createRequire } from "node:module";
import path from "node:path";
const require = createRequire(import.meta.url);
const env = {
NODE_ENV: "production",
};
function localUpstreamsDisabled() {
const sourceMode = (
process.env.MILADY_ELIZA_SOURCE ??
process.env.ELIZA_SOURCE ??
"packages"
).toLowerCase();
return (
["package", "packages", "published", "npm", "registry", "global"].includes(
sourceMode,
) ||
process.env.MILADY_SKIP_LOCAL_UPSTREAMS === "1" ||
process.env.ELIZA_SKIP_LOCAL_UPSTREAMS === "1"
);
}
function explicitAppCoreEntry(localRelativePath) {
const rawRoot =
process.env.MILADY_ELIZA_APP_CORE_ROOT ?? process.env.ELIZA_APP_CORE_ROOT;
if (!rawRoot) {
return null;
}
const entry = path.join(rawRoot, localRelativePath);
if (!existsSync(entry)) {
throw new Error(
`MILADY_ELIZA_APP_CORE_ROOT is missing ${localRelativePath}`,
);
}
return entry;
}
function appCoreEntry(subpath, localRelativePath) {
const explicitEntry = explicitAppCoreEntry(localRelativePath);
if (explicitEntry) {
return explicitEntry;
}
const localPath = path.join(
"eliza",
"packages",
"app-core",
localRelativePath,
);
if (!localUpstreamsDisabled() && existsSync(localPath)) {
return localPath;
}
const packageSubpath =
subpath === "." ? "@elizaos/app-core" : `@elizaos/app-core/${subpath}`;
try {
return require.resolve(packageSubpath);
} catch (error) {
const packageJsonPath = require.resolve("@elizaos/app-core/package.json");
const packageRoot = path.dirname(packageJsonPath);
const packageEntry = path.join(
packageRoot,
"packages/app-core",
localRelativePath.replace(/\.[cm]?tsx?$/, ".js"),
);
if (existsSync(packageEntry)) {
return packageEntry;
}
throw error;
}
}
// Native .node packages must stay external; rolldown cannot bundle shared libraries.
const nativeExternals = [
"node-llama-cpp",
"@reflink/reflink",
"@reflink/reflink-darwin-arm64",
"@reflink/reflink-darwin-x64",
"@reflink/reflink-linux-arm64-gnu",
"@reflink/reflink-linux-x64-gnu",
"fsevents",
"jose",
// Bun 1.3.13 fails evaluating Rolldown's unbundled ESM init wrappers for adze.
// Keep the package external so the desktop runtime loads its published ESM files.
"adze",
// Keep React external for Node server builds; bundling it introduces incompatible wrappers.
"react",
"react-dom",
];
// Runtime-loaded @elizaos/plugin-* packages must stay external.
const pluginExternal = /^@elizaos\/plugin-/;
const optionalAppExternal = /^@elizaos\/app-/;
// @node-rs/* ships native .node bindings per platform (argon2 + arch
// variants like @node-rs/argon2-darwin-arm64). Single regex covers all
// of them — always external; rolldown can't bundle the .node binary.
const nodeRsExternal = /^@node-rs\//;
const napiRsExternal = /^@napi-rs\//;
const allExternals = [
...nativeExternals,
pluginExternal,
optionalAppExternal,
nodeRsExternal,
napiRsExternal,
];
export default [
{
entry: appCoreEntry(".", "src/index.ts"),
env,
fixedExtension: false,
platform: "node",
inlineOnly: false,
external: allExternals,
},
{
entry: appCoreEntry("entry", "src/entry.ts"),
env,
fixedExtension: false,
platform: "node",
inlineOnly: false,
external: allExternals,
outputOptions: { codeSplitting: false },
},
{
entry: appCoreEntry("runtime/eliza", "src/runtime/eliza.ts"),
env,
fixedExtension: false,
platform: "node",
inlineOnly: false,
external: allExternals,
outputOptions: { codeSplitting: false },
},
{
entry: appCoreEntry("api/server", "src/api/server.ts"),
env,
fixedExtension: false,
platform: "node",
inlineOnly: false,
external: allExternals,
// Disable code splitting to avoid circular imports in server.js.
outputOptions: { codeSplitting: false },
},
];