@mastra/deployer 0.0.0-a2a-20250421213654
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +46 -0
- package/README.md +159 -0
- package/dist/_tsup-dts-rollup.d.cts +548 -0
- package/dist/_tsup-dts-rollup.d.ts +548 -0
- package/dist/build/analyze.cjs +10 -0
- package/dist/build/analyze.d.cts +1 -0
- package/dist/build/analyze.d.ts +1 -0
- package/dist/build/analyze.js +1 -0
- package/dist/build/bundler.cjs +14 -0
- package/dist/build/bundler.d.cts +2 -0
- package/dist/build/bundler.d.ts +2 -0
- package/dist/build/bundler.js +1 -0
- package/dist/build/index.cjs +46 -0
- package/dist/build/index.d.cts +9 -0
- package/dist/build/index.d.ts +9 -0
- package/dist/build/index.js +5 -0
- package/dist/bundler/index.cjs +10 -0
- package/dist/bundler/index.d.cts +1 -0
- package/dist/bundler/index.d.ts +1 -0
- package/dist/bundler/index.js +1 -0
- package/dist/chunk-2ZPQX6BX.cjs +254 -0
- package/dist/chunk-4AYFLP6G.js +227 -0
- package/dist/chunk-4VC5Z4YR.cjs +391 -0
- package/dist/chunk-54KOF3NB.cjs +137 -0
- package/dist/chunk-5QD7CDGY.js +306 -0
- package/dist/chunk-6QMONK4A.cjs +2 -0
- package/dist/chunk-AOSWYZKN.js +138 -0
- package/dist/chunk-C4JT7CIH.js +1 -0
- package/dist/chunk-IMGVLBV7.cjs +149 -0
- package/dist/chunk-KTYDROLB.js +136 -0
- package/dist/chunk-LA6Y6GAB.cjs +312 -0
- package/dist/chunk-Q6OKTZNC.cjs +316 -0
- package/dist/chunk-USZDOFES.js +301 -0
- package/dist/chunk-UV4RQQ3R.js +359 -0
- package/dist/chunk-WVBUOQT6.js +111 -0
- package/dist/chunk-Z7KAM3CZ.cjs +164 -0
- package/dist/index.cjs +190 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +149 -0
- package/dist/server/index.cjs +3952 -0
- package/dist/server/index.d.cts +2 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +3944 -0
- package/dist/services/index.cjs +18 -0
- package/dist/services/index.d.cts +3 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +1 -0
- package/dist/templates/instrumentation-template.js +89 -0
- package/dist/validator/custom-resolver.cjs +52 -0
- package/dist/validator/custom-resolver.d.cts +1 -0
- package/dist/validator/custom-resolver.d.ts +1 -0
- package/dist/validator/custom-resolver.js +50 -0
- package/dist/validator/loader.cjs +7 -0
- package/dist/validator/loader.d.cts +1 -0
- package/dist/validator/loader.d.ts +1 -0
- package/dist/validator/loader.js +4 -0
- package/package.json +140 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { writeTelemetryConfig } from './chunk-4AYFLP6G.js';
|
|
2
|
+
import { analyzeBundle } from './chunk-USZDOFES.js';
|
|
3
|
+
import { createBundler, getInputOptions } from './chunk-AOSWYZKN.js';
|
|
4
|
+
import { DepsService, FileService } from './chunk-UV4RQQ3R.js';
|
|
5
|
+
import { existsSync } from 'node:fs';
|
|
6
|
+
import { writeFile, stat } from 'node:fs/promises';
|
|
7
|
+
import { join, dirname } from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { MastraBundler } from '@mastra/core/bundler';
|
|
10
|
+
import virtual from '@rollup/plugin-virtual';
|
|
11
|
+
import fsExtra, { emptyDir, ensureDir, copy, readJSON } from 'fs-extra/esm';
|
|
12
|
+
import resolveFrom from 'resolve-from';
|
|
13
|
+
import slugify from '@sindresorhus/slugify';
|
|
14
|
+
import { findWorkspaces, findWorkspacesRoot } from 'find-workspaces';
|
|
15
|
+
import { ensureDir as ensureDir$1 } from 'fs-extra';
|
|
16
|
+
|
|
17
|
+
var createWorkspacePackageMap = async () => {
|
|
18
|
+
const workspaces = await findWorkspaces();
|
|
19
|
+
const workspaceMap = new Map(
|
|
20
|
+
workspaces?.map((workspace) => [
|
|
21
|
+
workspace.package.name,
|
|
22
|
+
{
|
|
23
|
+
location: workspace.location,
|
|
24
|
+
dependencies: workspace.package.dependencies,
|
|
25
|
+
version: workspace.package.version
|
|
26
|
+
}
|
|
27
|
+
]) ?? []
|
|
28
|
+
);
|
|
29
|
+
return workspaceMap;
|
|
30
|
+
};
|
|
31
|
+
var collectTransitiveWorkspaceDependencies = ({
|
|
32
|
+
workspaceMap,
|
|
33
|
+
initialDependencies,
|
|
34
|
+
logger
|
|
35
|
+
}) => {
|
|
36
|
+
const usedWorkspacePackages = /* @__PURE__ */ new Set();
|
|
37
|
+
const queue = Array.from(initialDependencies);
|
|
38
|
+
const resolutions = {};
|
|
39
|
+
while (queue.length > 0) {
|
|
40
|
+
const len = queue.length;
|
|
41
|
+
for (let i = 0; i < len; i += 1) {
|
|
42
|
+
const pkgName = queue.shift();
|
|
43
|
+
if (!pkgName || usedWorkspacePackages.has(pkgName)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const dep = workspaceMap.get(pkgName);
|
|
47
|
+
if (!dep) continue;
|
|
48
|
+
const root = findWorkspacesRoot();
|
|
49
|
+
if (!root) {
|
|
50
|
+
throw new Error("Could not find workspace root");
|
|
51
|
+
}
|
|
52
|
+
const depsService = new DepsService(root.location);
|
|
53
|
+
depsService.__setLogger(logger);
|
|
54
|
+
const sanitizedName = slugify(pkgName);
|
|
55
|
+
const tgzPath = depsService.getWorkspaceDependencyPath({
|
|
56
|
+
pkgName: sanitizedName,
|
|
57
|
+
version: dep.version
|
|
58
|
+
});
|
|
59
|
+
resolutions[pkgName] = tgzPath;
|
|
60
|
+
usedWorkspacePackages.add(pkgName);
|
|
61
|
+
for (const [depName, _depVersion] of Object.entries(dep?.dependencies ?? {})) {
|
|
62
|
+
if (!usedWorkspacePackages.has(depName) && workspaceMap.has(depName)) {
|
|
63
|
+
queue.push(depName);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { resolutions, usedWorkspacePackages };
|
|
69
|
+
};
|
|
70
|
+
var packWorkspaceDependencies = async ({
|
|
71
|
+
workspaceMap,
|
|
72
|
+
usedWorkspacePackages,
|
|
73
|
+
bundleOutputDir,
|
|
74
|
+
logger
|
|
75
|
+
}) => {
|
|
76
|
+
const root = findWorkspacesRoot();
|
|
77
|
+
if (!root) {
|
|
78
|
+
throw new Error("Could not find workspace root");
|
|
79
|
+
}
|
|
80
|
+
const depsService = new DepsService(root.location);
|
|
81
|
+
depsService.__setLogger(logger);
|
|
82
|
+
if (usedWorkspacePackages.size > 0) {
|
|
83
|
+
const workspaceDirPath = join(bundleOutputDir, "workspace-module");
|
|
84
|
+
await ensureDir$1(workspaceDirPath);
|
|
85
|
+
logger.info(`Packaging ${usedWorkspacePackages.size} workspace dependencies...`);
|
|
86
|
+
const batchSize = 5;
|
|
87
|
+
const packages = Array.from(usedWorkspacePackages.values());
|
|
88
|
+
for (let i = 0; i < packages.length; i += batchSize) {
|
|
89
|
+
const batch = packages.slice(i, i + batchSize);
|
|
90
|
+
logger.info(
|
|
91
|
+
`Packaging batch ${Math.floor(i / batchSize) + 1}/${Math.ceil(packages.length / batchSize)}: ${batch.join(", ")}`
|
|
92
|
+
);
|
|
93
|
+
await Promise.all(
|
|
94
|
+
batch.map(async (pkgName) => {
|
|
95
|
+
const dep = workspaceMap.get(pkgName);
|
|
96
|
+
if (!dep) return;
|
|
97
|
+
try {
|
|
98
|
+
await depsService.pack({ dir: dep.location, destination: workspaceDirPath });
|
|
99
|
+
} catch (error) {
|
|
100
|
+
logger.error(`Failed to package ${pkgName}: ${error}`);
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
logger.info(`Successfully packaged ${usedWorkspacePackages.size} workspace dependencies`);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/bundler/index.ts
|
|
110
|
+
var Bundler = class extends MastraBundler {
|
|
111
|
+
analyzeOutputDir = ".build";
|
|
112
|
+
outputDir = "output";
|
|
113
|
+
constructor(name, component = "BUNDLER") {
|
|
114
|
+
super({ name, component });
|
|
115
|
+
}
|
|
116
|
+
async prepare(outputDirectory) {
|
|
117
|
+
await emptyDir(outputDirectory);
|
|
118
|
+
await ensureDir(join(outputDirectory, this.analyzeOutputDir));
|
|
119
|
+
await ensureDir(join(outputDirectory, this.outputDir));
|
|
120
|
+
}
|
|
121
|
+
async writeInstrumentationFile(outputDirectory) {
|
|
122
|
+
const instrumentationFile = join(outputDirectory, "instrumentation.mjs");
|
|
123
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
124
|
+
await copy(join(__dirname, "templates", "instrumentation-template.js"), instrumentationFile);
|
|
125
|
+
}
|
|
126
|
+
async writePackageJson(outputDirectory, dependencies, resolutions) {
|
|
127
|
+
this.logger.debug(`Writing project's package.json`);
|
|
128
|
+
await ensureDir(outputDirectory);
|
|
129
|
+
const pkgPath = join(outputDirectory, "package.json");
|
|
130
|
+
const dependenciesMap = /* @__PURE__ */ new Map();
|
|
131
|
+
for (const [key, value] of dependencies.entries()) {
|
|
132
|
+
if (key.startsWith("@")) {
|
|
133
|
+
const pkgChunks = key.split("/");
|
|
134
|
+
dependenciesMap.set(`${pkgChunks[0]}/${pkgChunks[1]}`, value);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
dependenciesMap.set(key, value);
|
|
138
|
+
}
|
|
139
|
+
dependenciesMap.set("@opentelemetry/instrumentation", "latest");
|
|
140
|
+
await writeFile(
|
|
141
|
+
pkgPath,
|
|
142
|
+
JSON.stringify(
|
|
143
|
+
{
|
|
144
|
+
name: "server",
|
|
145
|
+
version: "1.0.0",
|
|
146
|
+
description: "",
|
|
147
|
+
type: "module",
|
|
148
|
+
main: "index.mjs",
|
|
149
|
+
scripts: {
|
|
150
|
+
start: "node ./index.mjs"
|
|
151
|
+
},
|
|
152
|
+
author: "Mastra",
|
|
153
|
+
license: "ISC",
|
|
154
|
+
dependencies: Object.fromEntries(dependenciesMap.entries()),
|
|
155
|
+
...Object.keys(resolutions ?? {}).length > 0 && { resolutions }
|
|
156
|
+
},
|
|
157
|
+
null,
|
|
158
|
+
2
|
|
159
|
+
)
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
createBundler(inputOptions, outputOptions) {
|
|
163
|
+
return createBundler(inputOptions, outputOptions);
|
|
164
|
+
}
|
|
165
|
+
async analyze(entry, mastraFile, outputDirectory) {
|
|
166
|
+
return await analyzeBundle(entry, mastraFile, join(outputDirectory, this.analyzeOutputDir), "node", this.logger);
|
|
167
|
+
}
|
|
168
|
+
async installDependencies(outputDirectory, rootDir = process.cwd()) {
|
|
169
|
+
const deps = new DepsService(rootDir);
|
|
170
|
+
deps.__setLogger(this.logger);
|
|
171
|
+
await deps.install({ dir: join(outputDirectory, this.outputDir) });
|
|
172
|
+
}
|
|
173
|
+
async copyPublic(mastraDir, outputDirectory) {
|
|
174
|
+
const publicDir = join(mastraDir, "public");
|
|
175
|
+
try {
|
|
176
|
+
await stat(publicDir);
|
|
177
|
+
} catch {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
await copy(publicDir, join(outputDirectory, this.outputDir));
|
|
181
|
+
}
|
|
182
|
+
async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths) {
|
|
183
|
+
const inputOptions = await getInputOptions(mastraEntryFile, analyzedBundleInfo, "node", {
|
|
184
|
+
"process.env.NODE_ENV": JSON.stringify("production")
|
|
185
|
+
});
|
|
186
|
+
const isVirtual = serverFile.includes("\n") || existsSync(serverFile);
|
|
187
|
+
const toolsInputOptions = await this.getToolsInputOptions(toolsPaths);
|
|
188
|
+
if (isVirtual) {
|
|
189
|
+
inputOptions.input = { index: "#entry", ...toolsInputOptions };
|
|
190
|
+
if (Array.isArray(inputOptions.plugins)) {
|
|
191
|
+
inputOptions.plugins.unshift(virtual({ "#entry": serverFile }));
|
|
192
|
+
} else {
|
|
193
|
+
inputOptions.plugins = [virtual({ "#entry": serverFile })];
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
inputOptions.input = { index: serverFile, ...toolsInputOptions };
|
|
197
|
+
}
|
|
198
|
+
return inputOptions;
|
|
199
|
+
}
|
|
200
|
+
async getToolsInputOptions(toolsPaths) {
|
|
201
|
+
const inputs = {};
|
|
202
|
+
for (const toolPath of toolsPaths) {
|
|
203
|
+
if (await fsExtra.pathExists(toolPath)) {
|
|
204
|
+
const fileService = new FileService();
|
|
205
|
+
const entryFile = fileService.getFirstExistingFile([
|
|
206
|
+
join(toolPath, "index.ts"),
|
|
207
|
+
join(toolPath, "index.js"),
|
|
208
|
+
toolPath
|
|
209
|
+
// if toolPath itself is a file
|
|
210
|
+
]);
|
|
211
|
+
if (!entryFile || (await stat(entryFile)).isDirectory()) {
|
|
212
|
+
this.logger.warn(`No entry file found in ${toolPath}, skipping...`);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const uniqueToolID = crypto.randomUUID();
|
|
216
|
+
inputs[`tools/${uniqueToolID}`] = entryFile;
|
|
217
|
+
} else {
|
|
218
|
+
this.logger.warn(`Tool path ${toolPath} does not exist, skipping...`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return inputs;
|
|
222
|
+
}
|
|
223
|
+
async _bundle(serverFile, mastraEntryFile, outputDirectory, toolsPaths = [], bundleLocation = join(outputDirectory, this.outputDir)) {
|
|
224
|
+
this.logger.info("Start bundling Mastra");
|
|
225
|
+
const analyzedBundleInfo = await analyzeBundle(
|
|
226
|
+
serverFile,
|
|
227
|
+
mastraEntryFile,
|
|
228
|
+
join(outputDirectory, this.analyzeOutputDir),
|
|
229
|
+
"node",
|
|
230
|
+
this.logger
|
|
231
|
+
);
|
|
232
|
+
await writeTelemetryConfig(mastraEntryFile, join(outputDirectory, this.outputDir));
|
|
233
|
+
const workspaceMap = await createWorkspacePackageMap();
|
|
234
|
+
const dependenciesToInstall = /* @__PURE__ */ new Map();
|
|
235
|
+
const workspaceDependencies = /* @__PURE__ */ new Set();
|
|
236
|
+
for (const dep of analyzedBundleInfo.externalDependencies) {
|
|
237
|
+
try {
|
|
238
|
+
const pkgPath = resolveFrom(mastraEntryFile, `${dep}/package.json`);
|
|
239
|
+
const pkg = await readJSON(pkgPath);
|
|
240
|
+
if (workspaceMap.has(pkg.name)) {
|
|
241
|
+
workspaceDependencies.add(pkg.name);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
dependenciesToInstall.set(dep, pkg.version);
|
|
245
|
+
} catch {
|
|
246
|
+
dependenciesToInstall.set(dep, "latest");
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
let resolutions = {};
|
|
250
|
+
if (workspaceDependencies.size > 0) {
|
|
251
|
+
try {
|
|
252
|
+
const result = collectTransitiveWorkspaceDependencies({
|
|
253
|
+
workspaceMap,
|
|
254
|
+
initialDependencies: workspaceDependencies,
|
|
255
|
+
logger: this.logger
|
|
256
|
+
});
|
|
257
|
+
resolutions = result.resolutions;
|
|
258
|
+
Object.entries(resolutions).forEach(([pkgName, tgzPath]) => {
|
|
259
|
+
dependenciesToInstall.set(pkgName, tgzPath);
|
|
260
|
+
});
|
|
261
|
+
await packWorkspaceDependencies({
|
|
262
|
+
workspaceMap,
|
|
263
|
+
usedWorkspacePackages: result.usedWorkspacePackages,
|
|
264
|
+
bundleOutputDir: join(outputDirectory, this.outputDir),
|
|
265
|
+
logger: this.logger
|
|
266
|
+
});
|
|
267
|
+
} catch (error) {
|
|
268
|
+
this.logger.error(`Failed to collect workspace dependencies: ${error}`);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (analyzedBundleInfo.externalDependencies.has("@mastra/memory") || analyzedBundleInfo.dependencies.has("@mastra/memory")) {
|
|
273
|
+
dependenciesToInstall.set("fastembed", "latest");
|
|
274
|
+
}
|
|
275
|
+
await this.writePackageJson(join(outputDirectory, this.outputDir), dependenciesToInstall, resolutions);
|
|
276
|
+
await this.writeInstrumentationFile(join(outputDirectory, this.outputDir));
|
|
277
|
+
this.logger.info("Bundling Mastra application");
|
|
278
|
+
const inputOptions = await this.getBundlerOptions(
|
|
279
|
+
serverFile,
|
|
280
|
+
mastraEntryFile,
|
|
281
|
+
analyzedBundleInfo,
|
|
282
|
+
toolsPaths
|
|
283
|
+
);
|
|
284
|
+
const bundler = await this.createBundler(inputOptions, {
|
|
285
|
+
dir: bundleLocation,
|
|
286
|
+
manualChunks: {
|
|
287
|
+
mastra: ["#mastra"]
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
await bundler.write();
|
|
291
|
+
const toolsInputOptions = Array.from(Object.keys(inputOptions.input || {})).filter((key) => key.startsWith("tools/")).map((key) => `./${key}.mjs`);
|
|
292
|
+
await writeFile(
|
|
293
|
+
join(outputDirectory, this.outputDir, "tools.mjs"),
|
|
294
|
+
`export const tools = ${JSON.stringify(toolsInputOptions)};`
|
|
295
|
+
);
|
|
296
|
+
this.logger.info("Bundling Mastra done");
|
|
297
|
+
this.logger.info("Copying public files");
|
|
298
|
+
await this.copyPublic(dirname(mastraEntryFile), outputDirectory);
|
|
299
|
+
this.logger.info("Done copying public files");
|
|
300
|
+
this.logger.info("Installing dependencies");
|
|
301
|
+
await this.installDependencies(outputDirectory);
|
|
302
|
+
this.logger.info("Done installing dependencies");
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
export { Bundler };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { tsConfigPaths, removeDeployer } from './chunk-WVBUOQT6.js';
|
|
2
|
+
import alias from '@rollup/plugin-alias';
|
|
3
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
4
|
+
import json from '@rollup/plugin-json';
|
|
5
|
+
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { rollup } from 'rollup';
|
|
8
|
+
import esbuild from 'rollup-plugin-esbuild';
|
|
9
|
+
|
|
10
|
+
async function getInputOptions(entryFile, analyzedBundleInfo, platform, env = { "process.env.NODE_ENV": JSON.stringify("production") }) {
|
|
11
|
+
let nodeResolvePlugin = platform === "node" ? nodeResolve({
|
|
12
|
+
preferBuiltins: true,
|
|
13
|
+
exportConditions: ["node", "import", "require"],
|
|
14
|
+
mainFields: ["module", "main"]
|
|
15
|
+
}) : nodeResolve({
|
|
16
|
+
preferBuiltins: false,
|
|
17
|
+
exportConditions: ["browser", "import", "require"],
|
|
18
|
+
mainFields: ["module", "main"],
|
|
19
|
+
browser: true
|
|
20
|
+
});
|
|
21
|
+
const externalsCopy = /* @__PURE__ */ new Set();
|
|
22
|
+
for (const external of analyzedBundleInfo.externalDependencies) {
|
|
23
|
+
if (external.startsWith("@")) {
|
|
24
|
+
const [scope, name] = external.split("/", 3);
|
|
25
|
+
externalsCopy.add(`${scope}/${name}`);
|
|
26
|
+
externalsCopy.add(`${scope}/${name}/*`);
|
|
27
|
+
} else {
|
|
28
|
+
externalsCopy.add(external);
|
|
29
|
+
externalsCopy.add(`${external}/*`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const externals = Array.from(externalsCopy);
|
|
33
|
+
const normalizedEntryFile = entryFile.replaceAll("\\", "/");
|
|
34
|
+
return {
|
|
35
|
+
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
36
|
+
treeshake: "smallest",
|
|
37
|
+
preserveSymlinks: true,
|
|
38
|
+
external: externals,
|
|
39
|
+
plugins: [
|
|
40
|
+
tsConfigPaths(),
|
|
41
|
+
{
|
|
42
|
+
name: "alias-optimized-deps",
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
resolveId(id) {
|
|
45
|
+
if (!analyzedBundleInfo.dependencies.has(id)) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const isInvalidChunk = analyzedBundleInfo.invalidChunks.has(analyzedBundleInfo.dependencies.get(id));
|
|
49
|
+
if (isInvalidChunk) {
|
|
50
|
+
return {
|
|
51
|
+
id,
|
|
52
|
+
external: true
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
id: ".mastra/.build/" + analyzedBundleInfo.dependencies.get(id),
|
|
57
|
+
external: false
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
alias({
|
|
62
|
+
entries: [
|
|
63
|
+
{
|
|
64
|
+
find: /^\#server$/,
|
|
65
|
+
replacement: fileURLToPath(import.meta.resolve("@mastra/deployer/server")).replaceAll("\\", "/")
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
find: /^\@mastra\/server\/(.*)/,
|
|
69
|
+
replacement: `@mastra/server/$1`,
|
|
70
|
+
customResolver: (id) => {
|
|
71
|
+
if (id.startsWith("@mastra/server")) {
|
|
72
|
+
return {
|
|
73
|
+
id: fileURLToPath(import.meta.resolve(id))
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{ find: /^\#mastra$/, replacement: normalizedEntryFile }
|
|
79
|
+
]
|
|
80
|
+
}),
|
|
81
|
+
esbuild({
|
|
82
|
+
target: "node20",
|
|
83
|
+
platform,
|
|
84
|
+
minify: false,
|
|
85
|
+
define: env
|
|
86
|
+
}),
|
|
87
|
+
commonjs({
|
|
88
|
+
extensions: [".js", ".ts"],
|
|
89
|
+
transformMixedEsModules: true,
|
|
90
|
+
esmExternals(id) {
|
|
91
|
+
return externals.includes(id);
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
nodeResolvePlugin,
|
|
95
|
+
// for debugging
|
|
96
|
+
// {
|
|
97
|
+
// name: 'logger',
|
|
98
|
+
// //@ts-ignore
|
|
99
|
+
// resolveId(id, ...args) {
|
|
100
|
+
// console.log({ id, args });
|
|
101
|
+
// },
|
|
102
|
+
// // @ts-ignore
|
|
103
|
+
// transform(code, id) {
|
|
104
|
+
// if (code.includes('class Duplexify ')) {
|
|
105
|
+
// console.log({ duplex: id });
|
|
106
|
+
// }
|
|
107
|
+
// },
|
|
108
|
+
// },
|
|
109
|
+
json(),
|
|
110
|
+
removeDeployer(entryFile),
|
|
111
|
+
// treeshake unused imports
|
|
112
|
+
esbuild({
|
|
113
|
+
include: entryFile,
|
|
114
|
+
target: "node20",
|
|
115
|
+
platform,
|
|
116
|
+
minify: false
|
|
117
|
+
})
|
|
118
|
+
].filter(Boolean)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
async function createBundler(inputOptions, outputOptions) {
|
|
122
|
+
const bundler = await rollup(inputOptions);
|
|
123
|
+
return {
|
|
124
|
+
write: () => {
|
|
125
|
+
return bundler.write({
|
|
126
|
+
...outputOptions,
|
|
127
|
+
format: "esm",
|
|
128
|
+
entryFileNames: "[name].mjs",
|
|
129
|
+
chunkFileNames: "[name].mjs"
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
close: () => {
|
|
133
|
+
return bundler.close();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { createBundler, getInputOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk54KOF3NB_cjs = require('./chunk-54KOF3NB.cjs');
|
|
4
|
+
var alias = require('@rollup/plugin-alias');
|
|
5
|
+
var commonjs = require('@rollup/plugin-commonjs');
|
|
6
|
+
var json = require('@rollup/plugin-json');
|
|
7
|
+
var nodeResolve = require('@rollup/plugin-node-resolve');
|
|
8
|
+
var url = require('url');
|
|
9
|
+
var rollup = require('rollup');
|
|
10
|
+
var esbuild = require('rollup-plugin-esbuild');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var alias__default = /*#__PURE__*/_interopDefault(alias);
|
|
15
|
+
var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
|
|
16
|
+
var json__default = /*#__PURE__*/_interopDefault(json);
|
|
17
|
+
var nodeResolve__default = /*#__PURE__*/_interopDefault(nodeResolve);
|
|
18
|
+
var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
|
|
19
|
+
|
|
20
|
+
async function getInputOptions(entryFile, analyzedBundleInfo, platform, env = { "process.env.NODE_ENV": JSON.stringify("production") }) {
|
|
21
|
+
let nodeResolvePlugin = platform === "node" ? nodeResolve__default.default({
|
|
22
|
+
preferBuiltins: true,
|
|
23
|
+
exportConditions: ["node", "import", "require"],
|
|
24
|
+
mainFields: ["module", "main"]
|
|
25
|
+
}) : nodeResolve__default.default({
|
|
26
|
+
preferBuiltins: false,
|
|
27
|
+
exportConditions: ["browser", "import", "require"],
|
|
28
|
+
mainFields: ["module", "main"],
|
|
29
|
+
browser: true
|
|
30
|
+
});
|
|
31
|
+
const externalsCopy = /* @__PURE__ */ new Set();
|
|
32
|
+
for (const external of analyzedBundleInfo.externalDependencies) {
|
|
33
|
+
if (external.startsWith("@")) {
|
|
34
|
+
const [scope, name] = external.split("/", 3);
|
|
35
|
+
externalsCopy.add(`${scope}/${name}`);
|
|
36
|
+
externalsCopy.add(`${scope}/${name}/*`);
|
|
37
|
+
} else {
|
|
38
|
+
externalsCopy.add(external);
|
|
39
|
+
externalsCopy.add(`${external}/*`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const externals = Array.from(externalsCopy);
|
|
43
|
+
const normalizedEntryFile = entryFile.replaceAll("\\", "/");
|
|
44
|
+
return {
|
|
45
|
+
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
46
|
+
treeshake: "smallest",
|
|
47
|
+
preserveSymlinks: true,
|
|
48
|
+
external: externals,
|
|
49
|
+
plugins: [
|
|
50
|
+
chunk54KOF3NB_cjs.tsConfigPaths(),
|
|
51
|
+
{
|
|
52
|
+
name: "alias-optimized-deps",
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
resolveId(id) {
|
|
55
|
+
if (!analyzedBundleInfo.dependencies.has(id)) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const isInvalidChunk = analyzedBundleInfo.invalidChunks.has(analyzedBundleInfo.dependencies.get(id));
|
|
59
|
+
if (isInvalidChunk) {
|
|
60
|
+
return {
|
|
61
|
+
id,
|
|
62
|
+
external: true
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
id: ".mastra/.build/" + analyzedBundleInfo.dependencies.get(id),
|
|
67
|
+
external: false
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
alias__default.default({
|
|
72
|
+
entries: [
|
|
73
|
+
{
|
|
74
|
+
find: /^\#server$/,
|
|
75
|
+
replacement: url.fileURLToPath(undefined("@mastra/deployer/server")).replaceAll("\\", "/")
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
find: /^\@mastra\/server\/(.*)/,
|
|
79
|
+
replacement: `@mastra/server/$1`,
|
|
80
|
+
customResolver: (id) => {
|
|
81
|
+
if (id.startsWith("@mastra/server")) {
|
|
82
|
+
return {
|
|
83
|
+
id: url.fileURLToPath(undefined(id))
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{ find: /^\#mastra$/, replacement: normalizedEntryFile }
|
|
89
|
+
]
|
|
90
|
+
}),
|
|
91
|
+
esbuild__default.default({
|
|
92
|
+
target: "node20",
|
|
93
|
+
platform,
|
|
94
|
+
minify: false,
|
|
95
|
+
define: env
|
|
96
|
+
}),
|
|
97
|
+
commonjs__default.default({
|
|
98
|
+
extensions: [".js", ".ts"],
|
|
99
|
+
transformMixedEsModules: true,
|
|
100
|
+
esmExternals(id) {
|
|
101
|
+
return externals.includes(id);
|
|
102
|
+
}
|
|
103
|
+
}),
|
|
104
|
+
nodeResolvePlugin,
|
|
105
|
+
// for debugging
|
|
106
|
+
// {
|
|
107
|
+
// name: 'logger',
|
|
108
|
+
// //@ts-ignore
|
|
109
|
+
// resolveId(id, ...args) {
|
|
110
|
+
// console.log({ id, args });
|
|
111
|
+
// },
|
|
112
|
+
// // @ts-ignore
|
|
113
|
+
// transform(code, id) {
|
|
114
|
+
// if (code.includes('class Duplexify ')) {
|
|
115
|
+
// console.log({ duplex: id });
|
|
116
|
+
// }
|
|
117
|
+
// },
|
|
118
|
+
// },
|
|
119
|
+
json__default.default(),
|
|
120
|
+
chunk54KOF3NB_cjs.removeDeployer(entryFile),
|
|
121
|
+
// treeshake unused imports
|
|
122
|
+
esbuild__default.default({
|
|
123
|
+
include: entryFile,
|
|
124
|
+
target: "node20",
|
|
125
|
+
platform,
|
|
126
|
+
minify: false
|
|
127
|
+
})
|
|
128
|
+
].filter(Boolean)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
async function createBundler(inputOptions, outputOptions) {
|
|
132
|
+
const bundler = await rollup.rollup(inputOptions);
|
|
133
|
+
return {
|
|
134
|
+
write: () => {
|
|
135
|
+
return bundler.write({
|
|
136
|
+
...outputOptions,
|
|
137
|
+
format: "esm",
|
|
138
|
+
entryFileNames: "[name].mjs",
|
|
139
|
+
chunkFileNames: "[name].mjs"
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
close: () => {
|
|
143
|
+
return bundler.close();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
exports.createBundler = createBundler;
|
|
149
|
+
exports.getInputOptions = getInputOptions;
|