@mastra/deployer 0.16.0-alpha.1 → 0.16.1-alpha.0
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/CHANGELOG.md +42 -0
- package/dist/build/analyze.cjs +3 -3
- package/dist/build/analyze.d.ts +5 -7
- package/dist/build/analyze.d.ts.map +1 -1
- package/dist/build/analyze.js +1 -1
- package/dist/build/bundler.cjs +3 -3
- package/dist/build/bundler.d.ts +4 -2
- package/dist/build/bundler.d.ts.map +1 -1
- package/dist/build/bundler.js +1 -1
- package/dist/build/index.cjs +19 -19
- package/dist/build/index.js +5 -5
- package/dist/build/types.d.ts +18 -0
- package/dist/build/types.d.ts.map +1 -0
- package/dist/build/utils.d.ts +5 -0
- package/dist/build/utils.d.ts.map +1 -1
- package/dist/build/watcher.d.ts.map +1 -1
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.js +1 -1
- package/dist/bundler/workspaceDependencies.d.ts.map +1 -1
- package/dist/{chunk-IVGJKJCG.js → chunk-4CAKOUIN.js} +21 -10
- package/dist/chunk-4CAKOUIN.js.map +1 -0
- package/dist/{chunk-HUAOVISC.js → chunk-5ZHIZCMJ.js} +209 -58
- package/dist/chunk-5ZHIZCMJ.js.map +1 -0
- package/dist/{chunk-AM2S5WCK.cjs → chunk-HR2HOA5D.cjs} +10 -6
- package/dist/chunk-HR2HOA5D.cjs.map +1 -0
- package/dist/{chunk-HFSNFLSA.cjs → chunk-JOCAZKZ5.cjs} +22 -9
- package/dist/chunk-JOCAZKZ5.cjs.map +1 -0
- package/dist/{chunk-U4ZNNX34.js → chunk-LL2SXZRQ.js} +3 -3
- package/dist/{chunk-U4ZNNX34.js.map → chunk-LL2SXZRQ.js.map} +1 -1
- package/dist/{chunk-LQCSOGOC.js → chunk-LN4WTW4C.js} +18 -5
- package/dist/chunk-LN4WTW4C.js.map +1 -0
- package/dist/{chunk-2GPZM6PP.js → chunk-MAPVVNYR.js} +6 -7
- package/dist/chunk-MAPVVNYR.js.map +1 -0
- package/dist/{chunk-FOPPWICF.cjs → chunk-OBHT43LS.cjs} +20 -21
- package/dist/chunk-OBHT43LS.cjs.map +1 -0
- package/dist/{chunk-WHMSFLP7.cjs → chunk-PX6ZHD5K.cjs} +5 -5
- package/dist/{chunk-WHMSFLP7.cjs.map → chunk-PX6ZHD5K.cjs.map} +1 -1
- package/dist/{chunk-KVBYKVQQ.cjs → chunk-T4L3WY7M.cjs} +223 -65
- package/dist/chunk-T4L3WY7M.cjs.map +1 -0
- package/dist/{chunk-DG6YR6QC.js → chunk-YOULDYHE.js} +8 -4
- package/dist/chunk-YOULDYHE.js.map +1 -0
- package/dist/{chunk-WSYCRXET.cjs → chunk-ZQJDMTCN.cjs} +29 -18
- package/dist/chunk-ZQJDMTCN.cjs.map +1 -0
- package/dist/index.cjs +12 -12
- package/dist/index.js +4 -4
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/services/deps.d.ts +2 -1
- package/dist/services/deps.d.ts.map +1 -1
- package/dist/services/index.cjs +4 -4
- package/dist/services/index.js +1 -1
- package/package.json +7 -7
- package/dist/chunk-2GPZM6PP.js.map +0 -1
- package/dist/chunk-AM2S5WCK.cjs.map +0 -1
- package/dist/chunk-DG6YR6QC.js.map +0 -1
- package/dist/chunk-FOPPWICF.cjs.map +0 -1
- package/dist/chunk-HFSNFLSA.cjs.map +0 -1
- package/dist/chunk-HUAOVISC.js.map +0 -1
- package/dist/chunk-IKIYTFYW.js +0 -163
- package/dist/chunk-IKIYTFYW.js.map +0 -1
- package/dist/chunk-IVGJKJCG.js.map +0 -1
- package/dist/chunk-KVBYKVQQ.cjs.map +0 -1
- package/dist/chunk-LQCSOGOC.js.map +0 -1
- package/dist/chunk-NK2IP3RO.cjs +0 -191
- package/dist/chunk-NK2IP3RO.cjs.map +0 -1
- package/dist/chunk-WSYCRXET.cjs.map +0 -1
|
@@ -1,24 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DepsService } from './chunk-DG6YR6QC.js';
|
|
1
|
+
import { DepsService } from './chunk-YOULDYHE.js';
|
|
3
2
|
import * as babel from '@babel/core';
|
|
4
3
|
import babel__default from '@babel/core';
|
|
5
4
|
import commonjs2 from '@rollup/plugin-commonjs';
|
|
6
5
|
import json2 from '@rollup/plugin-json';
|
|
7
6
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
8
7
|
import virtual from '@rollup/plugin-virtual';
|
|
9
|
-
import
|
|
8
|
+
import esmShim from '@rollup/plugin-esm-shim';
|
|
9
|
+
import fs, { existsSync } from 'fs';
|
|
10
10
|
import { writeFile, readFile } from 'fs/promises';
|
|
11
11
|
import { fileURLToPath } from 'url';
|
|
12
12
|
import { rollup } from 'rollup';
|
|
13
|
+
import originalEsbuild from 'rollup-plugin-esbuild';
|
|
13
14
|
import { builtinModules } from 'module';
|
|
14
|
-
import { join, dirname } from 'path';
|
|
15
|
+
import path, { join, normalize, dirname } from 'path';
|
|
15
16
|
import { spawn as spawn$1 } from 'child_process';
|
|
17
|
+
import { createHandler } from 'typescript-paths';
|
|
16
18
|
import { optimizeLodashImports } from '@optimize-lodash/rollup-plugin';
|
|
17
19
|
import { getPackageInfo } from 'local-pkg';
|
|
18
20
|
import slugify from '@sindresorhus/slugify';
|
|
19
21
|
import { findWorkspaces, findWorkspacesRoot } from 'find-workspaces';
|
|
20
22
|
import { ensureDir } from 'fs-extra';
|
|
21
23
|
|
|
24
|
+
function esbuild(options = {}) {
|
|
25
|
+
return originalEsbuild({
|
|
26
|
+
target: "node20",
|
|
27
|
+
platform: "node",
|
|
28
|
+
minify: false,
|
|
29
|
+
...options
|
|
30
|
+
});
|
|
31
|
+
}
|
|
22
32
|
function isNodeBuiltin(dep) {
|
|
23
33
|
const [pkg] = dep.split("/");
|
|
24
34
|
return dep.startsWith("node:") || builtinModules.includes(dep) || builtinModules.includes(pkg);
|
|
@@ -30,8 +40,81 @@ function aliasHono() {
|
|
|
30
40
|
if (!id.startsWith("@hono/") && !id.startsWith("hono/") && id !== "hono" && id !== "hono-openapi") {
|
|
31
41
|
return;
|
|
32
42
|
}
|
|
33
|
-
const
|
|
34
|
-
return fileURLToPath(
|
|
43
|
+
const path2 = import.meta.resolve(id);
|
|
44
|
+
return fileURLToPath(path2);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function removeDeployer() {
|
|
49
|
+
const t = babel__default.types;
|
|
50
|
+
return {
|
|
51
|
+
name: "remove-deployer",
|
|
52
|
+
visitor: {
|
|
53
|
+
NewExpression(path2, state) {
|
|
54
|
+
const varDeclaratorPath = path2.findParent((path3) => t.isVariableDeclarator(path3.node));
|
|
55
|
+
if (!varDeclaratorPath) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const parentNode = path2.parentPath.node;
|
|
59
|
+
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (!state.hasReplaced) {
|
|
63
|
+
state.hasReplaced = true;
|
|
64
|
+
const newMastraObj = t.cloneNode(path2.node);
|
|
65
|
+
if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.[0]) {
|
|
66
|
+
const deployer = newMastraObj.arguments[0].properties.find(
|
|
67
|
+
(prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
|
|
68
|
+
);
|
|
69
|
+
if (!deployer) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
newMastraObj.arguments[0].properties = newMastraObj.arguments[0].properties.filter(
|
|
73
|
+
(prop) => prop !== deployer
|
|
74
|
+
);
|
|
75
|
+
if (t.isObjectProperty(deployer) && t.isIdentifier(deployer.value)) {
|
|
76
|
+
const deployerBinding = state.file.scope.getBinding(deployer.value.name);
|
|
77
|
+
if (deployerBinding) {
|
|
78
|
+
deployerBinding?.path?.parentPath?.remove();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
path2.replaceWith(newMastraObj);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/build/plugins/remove-deployer.ts
|
|
90
|
+
function removeDeployer2(mastraEntry, options) {
|
|
91
|
+
return {
|
|
92
|
+
name: "remove-deployer",
|
|
93
|
+
transform(code, id) {
|
|
94
|
+
if (id !== mastraEntry) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
babel.transform(
|
|
99
|
+
code,
|
|
100
|
+
{
|
|
101
|
+
babelrc: false,
|
|
102
|
+
configFile: false,
|
|
103
|
+
filename: id,
|
|
104
|
+
plugins: [removeDeployer],
|
|
105
|
+
sourceMaps: options?.sourcemap
|
|
106
|
+
},
|
|
107
|
+
(err, result) => {
|
|
108
|
+
if (err) {
|
|
109
|
+
return reject(err);
|
|
110
|
+
}
|
|
111
|
+
resolve({
|
|
112
|
+
code: result.code,
|
|
113
|
+
map: result.map
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
});
|
|
35
118
|
}
|
|
36
119
|
};
|
|
37
120
|
}
|
|
@@ -72,6 +155,76 @@ function validate(file) {
|
|
|
72
155
|
}
|
|
73
156
|
);
|
|
74
157
|
}
|
|
158
|
+
var PLUGIN_NAME = "tsconfig-paths";
|
|
159
|
+
function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve } = {}) {
|
|
160
|
+
let handler;
|
|
161
|
+
return {
|
|
162
|
+
name: PLUGIN_NAME,
|
|
163
|
+
buildStart() {
|
|
164
|
+
handler = createHandler({
|
|
165
|
+
log: () => {
|
|
166
|
+
},
|
|
167
|
+
tsConfigPath,
|
|
168
|
+
respectCoreModule,
|
|
169
|
+
falllback: (moduleName) => fs.existsSync(moduleName)
|
|
170
|
+
});
|
|
171
|
+
return;
|
|
172
|
+
},
|
|
173
|
+
async resolveId(request, importer, options) {
|
|
174
|
+
if (!importer || request.startsWith("\0")) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
const moduleName = handler?.(request, normalize(importer));
|
|
178
|
+
if (!moduleName) {
|
|
179
|
+
let importerMeta = {};
|
|
180
|
+
const resolved = await this.resolve(request, importer, { skipSelf: true, ...options });
|
|
181
|
+
if (!resolved) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
if (localResolve) {
|
|
185
|
+
const importerInfo = this.getModuleInfo(importer);
|
|
186
|
+
importerMeta = importerInfo?.meta || {};
|
|
187
|
+
if (!request.startsWith("./") && !request.startsWith("../") && importerMeta?.[PLUGIN_NAME]?.resolved) {
|
|
188
|
+
return {
|
|
189
|
+
...resolved,
|
|
190
|
+
external: !request.startsWith("hono/") && request !== "hono"
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
...resolved,
|
|
196
|
+
meta: {
|
|
197
|
+
...resolved.meta || {},
|
|
198
|
+
...importerMeta
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
if (!path.extname(moduleName)) {
|
|
203
|
+
const resolved = await this.resolve(moduleName, importer, { skipSelf: true, ...options });
|
|
204
|
+
if (!resolved) {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
...resolved,
|
|
209
|
+
meta: {
|
|
210
|
+
...resolved.meta,
|
|
211
|
+
[PLUGIN_NAME]: {
|
|
212
|
+
resolved: true
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
id: moduleName,
|
|
219
|
+
meta: {
|
|
220
|
+
[PLUGIN_NAME]: {
|
|
221
|
+
resolved: true
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
75
228
|
function removeAllOptionsFromMastraExcept(result, option, logger) {
|
|
76
229
|
const t = babel__default.types;
|
|
77
230
|
return {
|
|
@@ -79,29 +232,29 @@ function removeAllOptionsFromMastraExcept(result, option, logger) {
|
|
|
79
232
|
visitor: {
|
|
80
233
|
ExportNamedDeclaration: {
|
|
81
234
|
// remove all exports
|
|
82
|
-
exit(
|
|
83
|
-
|
|
235
|
+
exit(path2) {
|
|
236
|
+
path2.remove();
|
|
84
237
|
}
|
|
85
238
|
},
|
|
86
|
-
NewExpression(
|
|
87
|
-
const varDeclaratorPath =
|
|
239
|
+
NewExpression(path2, state) {
|
|
240
|
+
const varDeclaratorPath = path2.findParent((path3) => t.isVariableDeclarator(path3.node));
|
|
88
241
|
if (!varDeclaratorPath) {
|
|
89
242
|
return;
|
|
90
243
|
}
|
|
91
|
-
const parentNode =
|
|
244
|
+
const parentNode = path2.parentPath.node;
|
|
92
245
|
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
93
246
|
return;
|
|
94
247
|
}
|
|
95
248
|
let mastraArgs = t.objectExpression([]);
|
|
96
|
-
if (t.isObjectExpression(
|
|
97
|
-
mastraArgs =
|
|
249
|
+
if (t.isObjectExpression(path2.node.arguments[0])) {
|
|
250
|
+
mastraArgs = path2.node.arguments[0];
|
|
98
251
|
}
|
|
99
252
|
let telemetry = mastraArgs.properties.find(
|
|
100
253
|
// @ts-ignore
|
|
101
254
|
(prop) => prop.key.name === option
|
|
102
255
|
);
|
|
103
256
|
let telemetryValue = t.objectExpression([]);
|
|
104
|
-
const programPath =
|
|
257
|
+
const programPath = path2.scope.getProgramParent().path;
|
|
105
258
|
if (!programPath) {
|
|
106
259
|
return;
|
|
107
260
|
}
|
|
@@ -111,7 +264,7 @@ function removeAllOptionsFromMastraExcept(result, option, logger) {
|
|
|
111
264
|
if (t.isIdentifier(telemetry.value) && telemetry.value.name === option) {
|
|
112
265
|
const telemetryBinding = state.file.scope.getBinding(option);
|
|
113
266
|
if (telemetryBinding && t.isVariableDeclarator(telemetryBinding.path.node)) {
|
|
114
|
-
const id =
|
|
267
|
+
const id = path2.scope.generateUidIdentifier(option);
|
|
115
268
|
telemetryBinding.path.replaceWith(t.variableDeclarator(id, telemetryBinding.path.node.init));
|
|
116
269
|
telemetryValue = id;
|
|
117
270
|
}
|
|
@@ -124,8 +277,8 @@ function removeAllOptionsFromMastraExcept(result, option, logger) {
|
|
|
124
277
|
programPath.node.body.push(exportDeclaration);
|
|
125
278
|
},
|
|
126
279
|
Program: {
|
|
127
|
-
exit(
|
|
128
|
-
const hasExport =
|
|
280
|
+
exit(path2) {
|
|
281
|
+
const hasExport = path2.node.body.some(
|
|
129
282
|
(node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
|
|
130
283
|
);
|
|
131
284
|
if (!hasExport) {
|
|
@@ -141,7 +294,7 @@ export const mastra = new Mastra({
|
|
|
141
294
|
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
|
|
142
295
|
[]
|
|
143
296
|
);
|
|
144
|
-
|
|
297
|
+
path2.node.body.push(fallbackExportDeclaration);
|
|
145
298
|
}
|
|
146
299
|
}
|
|
147
300
|
}
|
|
@@ -158,9 +311,9 @@ function removeNonReferencedNodes() {
|
|
|
158
311
|
return {
|
|
159
312
|
name: "remove-non-referenced-nodes",
|
|
160
313
|
visitor: {
|
|
161
|
-
Program(
|
|
162
|
-
const scope =
|
|
163
|
-
const currentBody =
|
|
314
|
+
Program(path2) {
|
|
315
|
+
const scope = path2.scope;
|
|
316
|
+
const currentBody = path2.get("body");
|
|
164
317
|
const filteredBody = currentBody.filter((childPath) => {
|
|
165
318
|
if (childPath.isExportDeclaration()) {
|
|
166
319
|
return true;
|
|
@@ -192,7 +345,7 @@ function removeNonReferencedNodes() {
|
|
|
192
345
|
}
|
|
193
346
|
return false;
|
|
194
347
|
});
|
|
195
|
-
|
|
348
|
+
path2.set(
|
|
196
349
|
"body",
|
|
197
350
|
filteredBody.map((p) => p.node)
|
|
198
351
|
);
|
|
@@ -328,16 +481,16 @@ function checkConfigExport(result) {
|
|
|
328
481
|
const mastraVars = /* @__PURE__ */ new Set();
|
|
329
482
|
return {
|
|
330
483
|
visitor: {
|
|
331
|
-
ExportNamedDeclaration(
|
|
332
|
-
const decl =
|
|
484
|
+
ExportNamedDeclaration(path2) {
|
|
485
|
+
const decl = path2.node.declaration;
|
|
333
486
|
if (t.isVariableDeclaration(decl)) {
|
|
334
487
|
const varDecl = decl.declarations[0];
|
|
335
488
|
if (t.isIdentifier(varDecl?.id, { name: "mastra" }) && t.isNewExpression(varDecl.init) && t.isIdentifier(varDecl.init.callee, { name: "Mastra" })) {
|
|
336
489
|
result.hasValidConfig = true;
|
|
337
490
|
}
|
|
338
491
|
}
|
|
339
|
-
if (Array.isArray(
|
|
340
|
-
for (const spec of
|
|
492
|
+
if (Array.isArray(path2.node.specifiers)) {
|
|
493
|
+
for (const spec of path2.node.specifiers) {
|
|
341
494
|
if (t.isExportSpecifier(spec) && t.isIdentifier(spec.exported, { name: "mastra" }) && t.isIdentifier(spec.local) && mastraVars.has(spec.local.name)) {
|
|
342
495
|
result.hasValidConfig = true;
|
|
343
496
|
}
|
|
@@ -345,8 +498,8 @@ function checkConfigExport(result) {
|
|
|
345
498
|
}
|
|
346
499
|
},
|
|
347
500
|
// For cases 2-4 we need to track whether those variables are assigned to `new Mastra()`
|
|
348
|
-
VariableDeclaration(
|
|
349
|
-
for (const decl of
|
|
501
|
+
VariableDeclaration(path2) {
|
|
502
|
+
for (const decl of path2.node.declarations) {
|
|
350
503
|
if (t.isIdentifier(decl.id) && t.isNewExpression(decl.init) && t.isIdentifier(decl.init.callee, { name: "Mastra" })) {
|
|
351
504
|
mastraVars.add(decl.id.name);
|
|
352
505
|
}
|
|
@@ -372,6 +525,9 @@ async function getPackageRootPath(packageName) {
|
|
|
372
525
|
}
|
|
373
526
|
return rootPath;
|
|
374
527
|
}
|
|
528
|
+
function getCompiledDepCachePath(rootPath, packageName) {
|
|
529
|
+
return join(rootPath, "node_modules", ".cache", packageName);
|
|
530
|
+
}
|
|
375
531
|
var createWorkspacePackageMap = async () => {
|
|
376
532
|
const workspaces = await findWorkspaces();
|
|
377
533
|
const workspaceMap = new Map(
|
|
@@ -451,8 +607,9 @@ var packWorkspaceDependencies = async ({
|
|
|
451
607
|
await Promise.all(
|
|
452
608
|
batch.map(async (pkgName) => {
|
|
453
609
|
const dep = workspaceMap.get(pkgName);
|
|
610
|
+
const sanitizedName = slugify(pkgName);
|
|
454
611
|
if (!dep) return;
|
|
455
|
-
await depsService.pack({ dir: dep.location, destination: workspaceDirPath });
|
|
612
|
+
await depsService.pack({ dir: dep.location, destination: workspaceDirPath, sanitizedName });
|
|
456
613
|
})
|
|
457
614
|
);
|
|
458
615
|
}
|
|
@@ -495,9 +652,6 @@ function findExternalImporter(module, external, allOutputs) {
|
|
|
495
652
|
}
|
|
496
653
|
return null;
|
|
497
654
|
}
|
|
498
|
-
function isRelativePath(id) {
|
|
499
|
-
return id === "." || id === ".." || id.startsWith("./") || id.startsWith("../");
|
|
500
|
-
}
|
|
501
655
|
async function analyze(entry, mastraEntry, isVirtualFile, platform, logger, sourcemapEnabled = false, workspaceMap) {
|
|
502
656
|
logger.info("Analyzing dependencies...");
|
|
503
657
|
let virtualPlugin = null;
|
|
@@ -544,7 +698,7 @@ async function analyze(entry, mastraEntry, isVirtualFile, platform, logger, sour
|
|
|
544
698
|
transformMixedEsModules: true,
|
|
545
699
|
extensions: [".js", ".ts"]
|
|
546
700
|
}),
|
|
547
|
-
|
|
701
|
+
removeDeployer2(normalizedMastraEntry, { sourcemap: sourcemapEnabled }),
|
|
548
702
|
esbuild()
|
|
549
703
|
].filter(Boolean)
|
|
550
704
|
});
|
|
@@ -582,17 +736,22 @@ async function analyze(entry, mastraEntry, isVirtualFile, platform, logger, sour
|
|
|
582
736
|
}
|
|
583
737
|
return depsToOptimize;
|
|
584
738
|
}
|
|
585
|
-
async function bundleExternals(depsToOptimize, outputDir, logger,
|
|
739
|
+
async function bundleExternals(depsToOptimize, outputDir, logger, bundlerOptions, meta) {
|
|
586
740
|
logger.info("Optimizing dependencies...");
|
|
587
741
|
logger.debug(
|
|
588
742
|
`${Array.from(depsToOptimize.keys()).map((key) => `- ${key}`).join("\n")}`
|
|
589
743
|
);
|
|
590
|
-
const { externals: customExternals = [], transpilePackages = [] } =
|
|
744
|
+
const { externals: customExternals = [], transpilePackages = [], isDev = false } = bundlerOptions || {};
|
|
745
|
+
const { workspaceRoot = null, workspaceMap = /* @__PURE__ */ new Map() } = meta || {};
|
|
591
746
|
const allExternals = [...globalExternals, ...customExternals];
|
|
592
747
|
const reverseVirtualReferenceMap = /* @__PURE__ */ new Map();
|
|
593
748
|
const virtualDependencies = /* @__PURE__ */ new Map();
|
|
594
|
-
for (const [dep, { exports }] of depsToOptimize.entries()) {
|
|
595
|
-
|
|
749
|
+
for (const [dep, { exports, isWorkspace, rootPath }] of depsToOptimize.entries()) {
|
|
750
|
+
let name = dep.replaceAll("/", "-");
|
|
751
|
+
if (isWorkspace && rootPath && isDev && workspaceRoot) {
|
|
752
|
+
const absolutePath = getCompiledDepCachePath(rootPath, name);
|
|
753
|
+
name = absolutePath.replace(workspaceRoot, "").replace(/^[/\\]+/, "");
|
|
754
|
+
}
|
|
596
755
|
reverseVirtualReferenceMap.set(name, dep);
|
|
597
756
|
const virtualFile = [];
|
|
598
757
|
let exportStringBuilder = [];
|
|
@@ -629,8 +788,6 @@ async function bundleExternals(depsToOptimize, outputDir, logger, options) {
|
|
|
629
788
|
},
|
|
630
789
|
{}
|
|
631
790
|
),
|
|
632
|
-
// this dependency breaks the build, so we need to exclude it
|
|
633
|
-
// TODO actually fix this so we don't need to exclude it
|
|
634
791
|
external: allExternals,
|
|
635
792
|
treeshake: "smallest",
|
|
636
793
|
plugins: [
|
|
@@ -643,20 +800,6 @@ async function bundleExternals(depsToOptimize, outputDir, logger, options) {
|
|
|
643
800
|
{}
|
|
644
801
|
)
|
|
645
802
|
),
|
|
646
|
-
options?.isDev ? {
|
|
647
|
-
name: "external-resolver",
|
|
648
|
-
async resolveId(id, importer, options2) {
|
|
649
|
-
const pathsToTranspile = [...transpilePackagesMap.values()];
|
|
650
|
-
if (importer && pathsToTranspile.some((p) => importer?.startsWith(p)) && !isRelativePath(id)) {
|
|
651
|
-
const resolved = await this.resolve(id, importer, { skipSelf: true, ...options2 });
|
|
652
|
-
return {
|
|
653
|
-
...resolved,
|
|
654
|
-
external: true
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
return null;
|
|
658
|
-
}
|
|
659
|
-
} : null,
|
|
660
803
|
transpilePackagesMap.size ? esbuild({
|
|
661
804
|
format: "esm",
|
|
662
805
|
include: [...transpilePackagesMap.values()].map((p) => {
|
|
@@ -668,9 +811,12 @@ async function bundleExternals(depsToOptimize, outputDir, logger, options) {
|
|
|
668
811
|
transformMixedEsModules: true,
|
|
669
812
|
ignoreTryCatch: false
|
|
670
813
|
}),
|
|
814
|
+
isDev ? esmShim() : void 0,
|
|
671
815
|
nodeResolve({
|
|
672
816
|
preferBuiltins: true,
|
|
673
|
-
exportConditions: ["node"]
|
|
817
|
+
exportConditions: ["node"],
|
|
818
|
+
// Do not embed external dependencies into files that we write to `node_modules/.cache` (for the mastra dev + workspace use case)
|
|
819
|
+
...workspaceMap.size > 0 && isDev ? { resolveOnly: Array.from(workspaceMap.keys()) } : {}
|
|
674
820
|
}),
|
|
675
821
|
// hono is imported from deployer, so we need to resolve from here instead of the project root
|
|
676
822
|
aliasHono(),
|
|
@@ -679,7 +825,12 @@ async function bundleExternals(depsToOptimize, outputDir, logger, options) {
|
|
|
679
825
|
});
|
|
680
826
|
const { output } = await bundler.write({
|
|
681
827
|
format: "esm",
|
|
682
|
-
|
|
828
|
+
/**
|
|
829
|
+
* If Mastra is used inside a monorepo, we need to find the workspace root so that Rollup can use it as base for the output dir. This should only happen during `mastra dev`.
|
|
830
|
+
*
|
|
831
|
+
* Otherwise, use outputDir as normal.
|
|
832
|
+
*/
|
|
833
|
+
dir: isDev ? workspaceRoot ? workspaceRoot : outputDir : outputDir,
|
|
683
834
|
entryFileNames: "[name].mjs",
|
|
684
835
|
chunkFileNames: "[name].mjs",
|
|
685
836
|
hoistTransitiveImports: false
|
|
@@ -811,6 +962,6 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
811
962
|
return result;
|
|
812
963
|
}
|
|
813
964
|
|
|
814
|
-
export { aliasHono, analyzeBundle, bundleExternals, collectTransitiveWorkspaceDependencies, createWorkspacePackageMap, extractMastraOption, getBundlerOptions, getPackageName, getPackageRootPath, packWorkspaceDependencies, removeAllOptionsFromMastraExcept };
|
|
815
|
-
//# sourceMappingURL=chunk-
|
|
816
|
-
//# sourceMappingURL=chunk-
|
|
965
|
+
export { aliasHono, analyzeBundle, bundleExternals, collectTransitiveWorkspaceDependencies, createWorkspacePackageMap, esbuild, extractMastraOption, getBundlerOptions, getPackageName, getPackageRootPath, packWorkspaceDependencies, removeAllOptionsFromMastraExcept, removeDeployer2 as removeDeployer, tsConfigPaths };
|
|
966
|
+
//# sourceMappingURL=chunk-5ZHIZCMJ.js.map
|
|
967
|
+
//# sourceMappingURL=chunk-5ZHIZCMJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/build/plugins/esbuild.ts","../src/build/isNodeBuiltin.ts","../src/build/plugins/hono-alias.ts","../src/build/babel/remove-deployer.ts","../src/build/plugins/remove-deployer.ts","../src/validator/validate.ts","../src/build/plugins/tsconfig-paths.ts","../src/build/babel/remove-all-options-except.ts","../src/build/babel/remove-all-options-bundler.ts","../src/build/babel/remove-non-referenced-nodes.ts","../src/build/plugins/remove-unused-references.ts","../src/build/shared/extract-mastra-option.ts","../src/build/bundlerOptions.ts","../src/build/babel/check-config-export.ts","../src/build/utils.ts","../src/bundler/workspaceDependencies.ts","../src/build/analyze.ts"],"names":["path","babel","removeDeployer","babel2","nodeSpawn","babel5","commonjs","json","babel6","result","join","rollup","fileURLToPath","o","babel8"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEO,SAAS,OAAA,CAAQ,OAAA,GAAiD,EAAC,EAAG;AAC3E,EAAA,OAAO,eAAA,CAAgB;AAAA,IACrB,MAAA,EAAQ,QAAA;AAAA,IACR,QAAA,EAAU,MAAA;AAAA,IACV,MAAA,EAAQ,KAAA;AAAA,IACR,GAAG;AAAA,GACJ,CAAA;AACH;ACPO,SAAS,cAAc,GAAA,EAAsB;AAClD,EAAA,MAAM,CAAC,GAAG,CAAA,GAAI,GAAA,CAAI,MAAM,GAAG,CAAA;AAE3B,EAAA,OAAO,GAAA,CAAI,UAAA,CAAW,OAAO,CAAA,IAAK,cAAA,CAAe,SAAS,GAAG,CAAA,IAAK,cAAA,CAAe,QAAA,CAAS,GAAI,CAAA;AAChG;ACFO,SAAS,SAAA,GAAoB;AAClC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,YAAA;AAAA,IACN,UAAU,EAAA,EAAY;AACpB,MAAA,IAAI,CAAC,EAAA,CAAG,UAAA,CAAW,QAAQ,CAAA,IAAK,CAAC,EAAA,CAAG,UAAA,CAAW,OAAO,CAAA,IAAK,EAAA,KAAO,MAAA,IAAU,OAAO,cAAA,EAAgB;AACjG,QAAA;AAAA,MACF;AAEA,MAAA,MAAMA,KAAAA,GAAO,MAAA,CAAA,IAAA,CAAY,OAAA,CAAQ,EAAE,CAAA;AACnC,MAAA,OAAO,cAAcA,KAAI,CAAA;AAAA,IAC3B;AAAA,GACF;AACF;ACdO,SAAS,cAAA,GAAiB;AAC/B,EAAA,MAAM,IAAIC,cAAA,CAAM,KAAA;AAEhB,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,iBAAA;AAAA,IACN,OAAA,EAAS;AAAA,MACP,aAAA,CAAcD,OAAM,KAAA,EAAO;AAEzB,QAAA,MAAM,iBAAA,G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e,GAAA,CAAI,GAAG,CAAA,EAAG;AAE3B,QAAA,MAAM,aAAA,GAAgB,cAAA,CAAe,GAAA,CAAI,GAAG,CAAA;AAC5C,QAAA,cAAA,CAAe,IAAI,GAAA,EAAK;AAAA,UACtB,GAAG,aAAA;AAAA,UACH,OAAA,EAAS,CAAC,mBAAG,IAAI,GAAA,CAAI,CAAC,GAAG,aAAA,CAAc,OAAA,EAAS,GAAG,OAAO,CAAC,CAAC;AAAA,SAC7D,CAAA;AAAA,MACH,CAAA,MAAO;AACL,QAAA,MAAM,WAAA,GAAc,YAAA,CAAa,GAAA,CAAI,GAAG,CAAA;AAExC,QAAA,MAAM,OAAA,GAAU,eAAe,GAAG,CAAA;AAClC,QAAA,IAAI,QAAA,GAA0B,IAAA;AAE9B,QAAA,IAAI,OAAA,IAAW,YAAY,QAAA,EAAU;AACnC,UAAA,QAAA,GAAW,MAAM,mBAAmB,OAAO,CAAA;AAAA,QAC7C;AAEA,QAAA,cAAA,CAAe,IAAI,GAAA,EAAK,EAAE,OAAA,EAAS,QAAA,EAAU,aAAa,CAAA;AAAA,MAC5D;AAAA,IACF;AAAA,EACF;AACA,EAAA,MAAM,cAAA,GAAiB,MAAM,iBAAA,CAAkB,WAAA,EAAa,SAAS,CAAA;AAErE,EAAA,MAAM,EAAE,MAAA,EAAQ,0BAAA,EAA4B,aAAA,KAAkB,MAAM,eAAA;AAAA,IAClE,cAAA;AAAA,IACA,SAAA;AAAA,IACA,MAAA;AAAA,IACA,cAAA,IAAkB;AAAA,GACpB;AACA,EAAA,MAAM,SAAS,MAAM,cAAA;AAAA,IACnB,EAAE,MAAA,EAAQ,0BAAA,EAA4B,aAAA,EAAe,WAAW,YAAA,EAAa;AAAA,IAC7E;AAAA,GACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"chunk-5ZHIZCMJ.js","sourcesContent":["import originalEsbuild from 'rollup-plugin-esbuild';\n\nexport function esbuild(options: Parameters<typeof originalEsbuild>[0] = {}) {\n return originalEsbuild({\n target: 'node20',\n platform: 'node',\n minify: false,\n ...options,\n });\n}\n","import { builtinModules } from 'node:module';\n\nexport function isNodeBuiltin(dep: string): boolean {\n const [pkg] = dep.split('/');\n\n return dep.startsWith('node:') || builtinModules.includes(dep) || builtinModules.includes(pkg!);\n}\n","import { fileURLToPath } from 'node:url';\nimport type { Plugin } from 'rollup';\n\n// hono is imported from deployer, so we need to resolve from here instead of the project root\nexport function aliasHono(): Plugin {\n return {\n name: 'hono-alias',\n resolveId(id: string) {\n if (!id.startsWith('@hono/') && !id.startsWith('hono/') && id !== 'hono' && id !== 'hono-openapi') {\n return;\n }\n\n const path = import.meta.resolve(id);\n return fileURLToPath(path);\n },\n } satisfies Plugin;\n}\n","import babel from '@babel/core';\n\nexport function removeDeployer() {\n const t = babel.types;\n\n return {\n name: 'remove-deployer',\n visitor: {\n NewExpression(path, state) {\n // is a variable declaration\n const varDeclaratorPath = path.findParent(path => t.isVariableDeclarator(path.node));\n if (!varDeclaratorPath) {\n return;\n }\n\n const parentNode = path.parentPath.node;\n // check if it's a const of mastra\n if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== 'mastra') {\n return;\n }\n\n if (!state.hasReplaced) {\n state.hasReplaced = true;\n const newMastraObj = t.cloneNode(path.node);\n if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.[0]) {\n const deployer = newMastraObj.arguments[0].properties.find(\n prop => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === 'deployer',\n );\n\n if (!deployer) {\n return;\n }\n\n newMastraObj.arguments[0].properties = newMastraObj.arguments[0].properties.filter(\n prop => prop !== deployer,\n );\n\n // try to find the binding of the deployer which should be the reference to the deployer\n if (t.isObjectProperty(deployer) && t.isIdentifier(deployer.value)) {\n const deployerBinding = state.file.scope.getBinding(deployer.value.name);\n\n if (deployerBinding) {\n deployerBinding?.path?.parentPath?.remove();\n }\n }\n\n path.replaceWith(newMastraObj);\n }\n }\n },\n },\n } as babel.PluginObj;\n}\n","import * as babel from '@babel/core';\nimport type { Plugin } from 'rollup';\n\nimport { removeDeployer as removeDeployerBabelPlugin } from '../babel/remove-deployer';\n\nexport function removeDeployer(mastraEntry: string, options?: { sourcemap?: boolean }): Plugin {\n return {\n name: 'remove-deployer',\n transform(code, id) {\n if (id !== mastraEntry) {\n return;\n }\n\n return new Promise((resolve, reject) => {\n babel.transform(\n code,\n {\n babelrc: false,\n configFile: false,\n filename: id,\n plugins: [removeDeployerBabelPlugin],\n sourceMaps: options?.sourcemap,\n },\n (err, result) => {\n if (err) {\n return reject(err);\n }\n\n resolve({\n code: result!.code!,\n map: result!.map!,\n });\n },\n );\n });\n },\n } satisfies Plugin;\n}\n","import { spawn as nodeSpawn } from 'node:child_process';\nimport type { SpawnOptions } from 'node:child_process';\nimport { dirname } from 'node:path';\n\n/**\n * Promisified version of Node.js spawn function\n *\n * @param command - The command to run\n * @param args - List of string arguments\n * @param options - Spawn options\n * @returns Promise that resolves with the exit code when the process completes\n */\nfunction spawn(command: string, args: string[] = [], options: SpawnOptions = {}): Promise<void> {\n return new Promise((resolve, reject) => {\n const childProcess = nodeSpawn(command, args, {\n // stdio: 'inherit',\n ...options,\n });\n\n childProcess.on('error', error => {\n reject(error);\n });\n\n let stderr = '';\n childProcess.stderr?.on('data', message => {\n stderr += message;\n });\n\n childProcess.on('close', code => {\n if (code === 0) {\n resolve();\n } else {\n reject(new Error(stderr));\n }\n });\n });\n}\n\nexport function validate(file: string) {\n return spawn(\n 'node',\n [\n '--import',\n import.meta.resolve('@mastra/deployer/loader'),\n '--input-type=module',\n '-e',\n `import('file://${file.replaceAll('\\\\', '/')}')`,\n ],\n {\n cwd: dirname(file),\n },\n );\n}\n","import fs from 'node:fs';\nimport path, { normalize } from 'node:path';\nimport resolveFrom from 'resolve-from';\nimport type { Plugin } from 'rollup';\nimport type { RegisterOptions } from 'typescript-paths';\nimport { createHandler } from 'typescript-paths';\n\nconst PLUGIN_NAME = 'tsconfig-paths';\n\nexport type PluginOptions = Omit<RegisterOptions, 'loggerID'> & { localResolve?: boolean };\n\nexport function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve }: PluginOptions = {}): Plugin {\n let handler: ReturnType<typeof createHandler>;\n return {\n name: PLUGIN_NAME,\n buildStart() {\n handler = createHandler({\n log: () => {},\n tsConfigPath,\n respectCoreModule,\n falllback: moduleName => fs.existsSync(moduleName),\n });\n return;\n },\n async resolveId(request, importer, options) {\n if (!importer || request.startsWith('\\0')) {\n return null;\n }\n\n const moduleName = handler?.(request, normalize(importer));\n // No tsconfig alias found, so we need to resolve it normally\n if (!moduleName) {\n let importerMeta: { [PLUGIN_NAME]?: { resolved?: boolean } } = {};\n\n const resolved = await this.resolve(request, importer, { skipSelf: true, ...options });\n if (!resolved) {\n return null;\n }\n\n // If localResolve is true, we need to check if the importer has been resolved by the tsconfig-paths plugin\n // if so, we need to resolve the request from the importer instead of the root and mark it as external\n if (localResolve) {\n const importerInfo = this.getModuleInfo(importer);\n importerMeta = importerInfo?.meta || {};\n\n if (!request.startsWith('./') && !request.startsWith('../') && importerMeta?.[PLUGIN_NAME]?.resolved) {\n return {\n ...resolved,\n external: !request.startsWith('hono/') && request !== 'hono',\n };\n }\n }\n\n return {\n ...resolved,\n meta: {\n ...(resolved.meta || {}),\n ...importerMeta,\n },\n };\n }\n\n // When a module does not have an extension, we need to resolve it to a file\n if (!path.extname(moduleName)) {\n const resolved = await this.resolve(moduleName, importer, { skipSelf: true, ...options });\n\n if (!resolved) {\n return null;\n }\n\n return {\n ...resolved,\n meta: {\n ...resolved.meta,\n [PLUGIN_NAME]: {\n resolved: true,\n },\n },\n };\n }\n\n return {\n id: moduleName,\n meta: {\n [PLUGIN_NAME]: {\n resolved: true,\n },\n },\n };\n },\n } satisfies Plugin;\n}\n","import babel from '@babel/core';\nimport type { NodePath, types } from '@babel/core';\nimport type { Config as MastraConfig } from '@mastra/core/mastra';\nimport type { IMastraLogger } from '@mastra/core/logger';\n\nexport function removeAllOptionsFromMastraExcept(\n result: { hasCustomConfig: boolean },\n option: keyof MastraConfig,\n logger?: IMastraLogger,\n) {\n const t = babel.types;\n\n return {\n name: 'remove-all-except-' + option + '-config',\n visitor: {\n ExportNamedDeclaration: {\n // remove all exports\n exit(path) {\n path.remove();\n },\n },\n\n NewExpression(path, state) {\n // is a variable declaration\n const varDeclaratorPath = path.findParent(path => t.isVariableDeclarator(path.node));\n if (!varDeclaratorPath) {\n return;\n }\n\n const parentNode = path.parentPath.node;\n // check if it's a const of mastra\n if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== 'mastra') {\n return;\n }\n\n let mastraArgs = t.objectExpression([]);\n if (t.isObjectExpression(path.node.arguments[0])) {\n mastraArgs = path.node.arguments[0];\n }\n\n let telemetry = mastraArgs.properties.find(\n // @ts-ignore\n prop => prop.key.name === option,\n );\n let telemetryValue: types.Expression = t.objectExpression([]);\n\n const programPath = path.scope.getProgramParent().path as NodePath<types.Program> | undefined;\n if (!programPath) {\n return;\n }\n\n if (telemetry && t.isObjectProperty(telemetry) && t.isExpression(telemetry.value)) {\n result.hasCustomConfig = true;\n telemetryValue = telemetry.value;\n\n if (t.isIdentifier(telemetry.value) && telemetry.value.name === option) {\n const telemetryBinding = state.file.scope.getBinding(option)!;\n\n if (telemetryBinding && t.isVariableDeclarator(telemetryBinding.path.node)) {\n const id = path.scope.generateUidIdentifier(option);\n\n telemetryBinding.path.replaceWith(t.variableDeclarator(id, telemetryBinding.path.node.init!));\n telemetryValue = id;\n }\n }\n }\n\n // add the deployer export\n const exportDeclaration = t.exportNamedDeclaration(\n t.variableDeclaration('const', [t.variableDeclarator(t.identifier(option), telemetryValue)]),\n [],\n );\n\n programPath.node.body.push(exportDeclaration);\n },\n\n Program: {\n exit(path) {\n // Add a fallback export if no mastra configuration was found\n const hasExport = path.node.body.some(\n node => node.type === 'ExportNamedDeclaration' || node.type === 'ExportDefaultDeclaration',\n );\n\n if (!hasExport) {\n if (logger) {\n logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:\nexport const mastra = new Mastra({\n ${option}: <value>\n})\n\n`);\n }\n\n const fallbackExportDeclaration = t.exportNamedDeclaration(\n t.variableDeclaration('const', [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),\n [],\n );\n path.node.body.push(fallbackExportDeclaration);\n }\n },\n },\n },\n } as babel.PluginObj;\n}\n","import type { IMastraLogger } from '@mastra/core/logger';\nimport { removeAllOptionsFromMastraExcept } from './remove-all-options-except';\n\nexport function removeAllOptionsExceptBundler(result: { hasCustomConfig: boolean }, logger?: IMastraLogger) {\n return removeAllOptionsFromMastraExcept(result, 'bundler', logger);\n}\n","import babel from '@babel/core';\n\nexport function removeNonReferencedNodes() {\n const t = babel.types;\n\n return {\n name: 'remove-non-referenced-nodes',\n visitor: {\n Program(path) {\n // Get the scope information\n const scope = path.scope;\n\n // Filter body to keep only referenced nodes\n const currentBody = path.get('body');\n const filteredBody = currentBody.filter(childPath => {\n if (childPath.isExportDeclaration()) {\n return true;\n }\n\n // For variable declarations, check if any declared variables are referenced\n if (childPath.isVariableDeclaration()) {\n return childPath.node.declarations.some(decl => {\n if (!t.isIdentifier(decl.id)) {\n return false;\n }\n\n const name = decl.id.name;\n const binding = scope.getBinding(name);\n // Keep if it has references or is exported\n return binding && (binding.referenced || binding.referencePaths.length > 0);\n });\n }\n\n // For function/class declarations, check if they're referenced\n if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {\n if (!t.isIdentifier(childPath.node.id)) {\n return false;\n }\n\n const name = childPath.node.id.name;\n const binding = scope.getBinding(name);\n return binding && (binding.referenced || binding.referencePaths.length > 0);\n }\n\n // For imports, check if any imported items are referenced\n if (childPath.isImportDeclaration()) {\n return childPath.node.specifiers.some(specifier => {\n const importedName = specifier.local.name;\n const binding = scope.getBinding(importedName);\n return binding && (binding.referenced || binding.referencePaths.length > 0);\n });\n }\n\n // Default to keeping other node types\n return false;\n });\n\n // Replace the program body with filtered nodes\n path.set(\n 'body',\n filteredBody.map(p => p.node),\n );\n },\n },\n } as babel.PluginObj;\n}\n","import * as babel from '@babel/core';\nimport { removeNonReferencedNodes } from '../babel/remove-non-referenced-nodes';\n\nexport function recursiveRemoveNonReferencedNodes(code: string) {\n return new Promise<{ code: string; map: any }>(async (resolve, reject) => {\n babel.transform(\n code,\n {\n babelrc: false,\n configFile: false,\n plugins: [removeNonReferencedNodes()],\n },\n (err, result) => {\n if (err) {\n return reject(err);\n }\n\n // keep looping until the code is not changed\n if (result && result.code! !== code) {\n return recursiveRemoveNonReferencedNodes(result!.code!).then(resolve, reject);\n }\n\n resolve({\n code: result!.code!,\n map: result!.map!,\n });\n },\n );\n });\n}\n","import * as babel from '@babel/core';\nimport { rollup, type RollupOutput } from 'rollup';\nimport { esbuild } from '../plugins/esbuild';\nimport commonjs from '@rollup/plugin-commonjs';\nimport { tsConfigPaths } from '../plugins/tsconfig-paths';\nimport { recursiveRemoveNonReferencedNodes } from '../plugins/remove-unused-references';\nimport { optimizeLodashImports } from '@optimize-lodash/rollup-plugin';\nimport { removeAllOptionsFromMastraExcept } from '../babel/remove-all-options-except';\nimport json from '@rollup/plugin-json';\nimport type { IMastraLogger } from '@mastra/core/logger';\n\ntype Transformer = (\n result: { hasCustomConfig: boolean },\n logger?: IMastraLogger,\n) => ReturnType<typeof removeAllOptionsFromMastraExcept>;\n\nexport function extractMastraOptionBundler(\n name: string,\n entryFile: string,\n transformer: Transformer,\n result: {\n hasCustomConfig: false;\n },\n logger?: IMastraLogger,\n) {\n return rollup({\n logLevel: 'silent',\n input: {\n [`${name}-config`]: entryFile,\n },\n treeshake: 'smallest',\n plugins: [\n tsConfigPaths(),\n // transpile typescript to something we understand\n esbuild(),\n optimizeLodashImports(),\n commonjs({\n extensions: ['.js', '.ts'],\n strictRequires: 'strict',\n transformMixedEsModules: true,\n ignoreTryCatch: false,\n }),\n json(),\n {\n name: `extract-${name}-config`,\n transform(code, id) {\n if (id !== entryFile) {\n return;\n }\n\n return new Promise((resolve, reject) => {\n babel.transform(\n code,\n {\n babelrc: false,\n configFile: false,\n filename: id,\n plugins: [transformer(result, logger)],\n },\n (err, result) => {\n if (err) {\n return reject(err);\n }\n\n resolve({\n code: result!.code!,\n map: result!.map!,\n });\n },\n );\n });\n },\n },\n // let esbuild remove all unused imports\n esbuild(),\n {\n name: 'cleanup',\n transform(code, id) {\n if (id !== entryFile) {\n return;\n }\n\n return recursiveRemoveNonReferencedNodes(code);\n },\n },\n // let esbuild remove it once more\n esbuild(),\n ],\n });\n}\n\nexport async function extractMastraOption<T>(\n name: string,\n entryFile: string,\n transformer: Transformer,\n outputDir: string,\n logger?: IMastraLogger,\n): Promise<{\n bundleOutput: RollupOutput;\n getConfig: () => Promise<T>;\n} | null> {\n const result = {\n hasCustomConfig: false,\n } as const;\n const bundler = await extractMastraOptionBundler(name, entryFile, transformer, result, logger);\n\n const output = await bundler.write({\n dir: outputDir,\n format: 'es',\n entryFileNames: '[name].mjs',\n });\n\n if (result.hasCustomConfig) {\n const configPath = `${outputDir}/${name}-config.mjs`;\n\n return {\n bundleOutput: output,\n getConfig: () => import(`file:${configPath}`).then(m => m[name] as T),\n };\n }\n\n return null;\n}\n","import { removeAllOptionsExceptBundler } from './babel/remove-all-options-bundler';\nimport type { Config } from '@mastra/core/mastra';\nimport { extractMastraOption, extractMastraOptionBundler } from './shared/extract-mastra-option';\nimport type { IMastraLogger } from '@mastra/core/logger';\n\nexport function getBundlerOptionsBundler(\n entryFile: string,\n result: {\n hasCustomConfig: false;\n },\n) {\n return extractMastraOptionBundler('bundler', entryFile, removeAllOptionsExceptBundler, result);\n}\n\nexport async function getBundlerOptions(\n entryFile: string,\n outputDir: string,\n logger?: IMastraLogger,\n): Promise<Config['bundler'] | null> {\n const result = await extractMastraOption<Config['bundler']>(\n 'bundler',\n entryFile,\n removeAllOptionsExceptBundler,\n outputDir,\n logger,\n );\n\n if (!result) {\n return null;\n }\n\n return result.getConfig();\n}\n","import type { PluginObj } from '@babel/core';\nimport babel from '@babel/core';\n\nexport function checkConfigExport(result: { hasValidConfig: boolean }): PluginObj {\n const t = babel.types;\n // Track which local variable names are assigned to `new Mastra()`\n const mastraVars = new Set<string>();\n\n return {\n visitor: {\n ExportNamedDeclaration(path) {\n const decl = path.node.declaration;\n // 1) export const mastra = new Mastra(...)\n if (t.isVariableDeclaration(decl)) {\n const varDecl = decl.declarations[0];\n if (\n t.isIdentifier(varDecl?.id, { name: 'mastra' }) &&\n t.isNewExpression(varDecl.init) &&\n t.isIdentifier(varDecl.init.callee, { name: 'Mastra' })\n ) {\n result.hasValidConfig = true;\n }\n }\n /**\n * 2) export { foo as mastra }\n * 3) export { mastra }\n * 4) export { mastra, foo }\n */\n if (Array.isArray(path.node.specifiers)) {\n for (const spec of path.node.specifiers) {\n if (\n t.isExportSpecifier(spec) &&\n t.isIdentifier(spec.exported, { name: 'mastra' }) &&\n t.isIdentifier(spec.local) &&\n mastraVars.has(spec.local.name)\n ) {\n result.hasValidConfig = true;\n }\n }\n }\n },\n // For cases 2-4 we need to track whether those variables are assigned to `new Mastra()`\n VariableDeclaration(path) {\n for (const decl of path.node.declarations) {\n if (\n t.isIdentifier(decl.id) &&\n t.isNewExpression(decl.init) &&\n t.isIdentifier(decl.init.callee, { name: 'Mastra' })\n ) {\n mastraVars.add(decl.id.name);\n }\n }\n },\n },\n };\n}\n","import { execSync } from 'child_process';\nimport { existsSync, mkdirSync } from 'fs';\nimport { join } from 'path';\nimport { getPackageInfo } from 'local-pkg';\n\nexport function upsertMastraDir({ dir = process.cwd() }: { dir?: string }) {\n const dirPath = join(dir, '.mastra');\n\n if (!existsSync(dirPath)) {\n mkdirSync(dirPath, { recursive: true });\n execSync(`echo \".mastra\" >> .gitignore`);\n }\n}\n\n/**\n * Get the package name from a module ID\n */\nexport function getPackageName(id: string) {\n const parts = id.split('/');\n\n if (id.startsWith('@')) {\n return parts.slice(0, 2).join('/');\n }\n\n return parts[0];\n}\n\n/**\n * Get package root path\n */\nexport async function getPackageRootPath(packageName: string): Promise<string | null> {\n let rootPath: string | null;\n\n try {\n const pkg = await getPackageInfo(packageName);\n rootPath = pkg?.rootPath ?? null;\n } catch (e) {\n rootPath = null;\n }\n\n return rootPath;\n}\n\n/**\n * During `mastra dev` we are compiling TS files to JS (inside workspaces) so that users can just their workspace packages.\n * We store these compiled files inside `node_modules/.cache` for each workspace package.\n */\nexport function getCompiledDepCachePath(rootPath: string, packageName: string) {\n return join(rootPath, 'node_modules', '.cache', packageName);\n}\n","import { join } from 'node:path';\nimport type { IMastraLogger } from '@mastra/core/logger';\nimport slugify from '@sindresorhus/slugify';\nimport { findWorkspaces, findWorkspacesRoot } from 'find-workspaces';\nimport { ensureDir } from 'fs-extra';\nimport { DepsService } from '../services';\n\nexport type WorkspacePackageInfo = {\n location: string;\n dependencies: Record<string, string> | undefined;\n version: string | undefined;\n};\n\ntype TransitiveDependencyResult = {\n resolutions: Record<string, string>;\n usedWorkspacePackages: Set<string>;\n};\n\n/**\n * Creates a map of workspace packages with their metadata for dependency resolution\n * @returns Map of package names to their location, dependencies and version\n */\nexport const createWorkspacePackageMap = async () => {\n // TODO move to our own implementation - pkg is 4 years old\n const workspaces = await findWorkspaces();\n const workspaceMap = new Map(\n workspaces?.map(workspace => [\n workspace.package.name,\n {\n location: workspace.location,\n dependencies: workspace.package.dependencies,\n version: workspace.package.version,\n },\n ]) ?? [],\n );\n\n return workspaceMap;\n};\n\n/**\n * Collects all transitive workspace dependencies and their TGZ paths\n */\nexport const collectTransitiveWorkspaceDependencies = ({\n workspaceMap,\n initialDependencies,\n logger,\n}: {\n workspaceMap: Map<string, WorkspacePackageInfo>;\n initialDependencies: Set<string>;\n logger: IMastraLogger;\n}): TransitiveDependencyResult => {\n const usedWorkspacePackages = new Set<string>();\n const queue: string[] = Array.from(initialDependencies);\n const resolutions: Record<string, string> = {};\n\n while (queue.length > 0) {\n const len = queue.length;\n for (let i = 0; i < len; i += 1) {\n const pkgName = queue.shift();\n if (!pkgName || usedWorkspacePackages.has(pkgName)) {\n continue;\n }\n\n const dep = workspaceMap.get(pkgName);\n if (!dep) continue;\n\n const root = findWorkspacesRoot();\n if (!root) {\n throw new Error('Could not find workspace root');\n }\n\n const depsService = new DepsService(root.location);\n depsService.__setLogger(logger);\n const sanitizedName = slugify(pkgName);\n\n const tgzPath = depsService.getWorkspaceDependencyPath({\n pkgName: sanitizedName,\n version: dep.version!,\n });\n resolutions[pkgName] = tgzPath;\n usedWorkspacePackages.add(pkgName);\n\n for (const [depName, _depVersion] of Object.entries(dep?.dependencies ?? {})) {\n if (!usedWorkspacePackages.has(depName) && workspaceMap.has(depName)) {\n queue.push(depName);\n }\n }\n }\n }\n\n return { resolutions, usedWorkspacePackages };\n};\n\n/**\n * Creates TGZ packages for workspace dependencies in the workspace-module directory\n */\nexport const packWorkspaceDependencies = async ({\n workspaceMap,\n usedWorkspacePackages,\n bundleOutputDir,\n logger,\n}: {\n workspaceMap: Map<string, WorkspacePackageInfo>;\n bundleOutputDir: string;\n logger: IMastraLogger;\n usedWorkspacePackages: Set<string>;\n}): Promise<void> => {\n const root = findWorkspacesRoot();\n if (!root) {\n throw new Error('Could not find workspace root');\n }\n\n const depsService = new DepsService(root.location);\n depsService.__setLogger(logger);\n\n // package all workspace dependencies\n if (usedWorkspacePackages.size > 0) {\n const workspaceDirPath = join(bundleOutputDir, 'workspace-module');\n await ensureDir(workspaceDirPath);\n\n logger.info(`Packaging ${usedWorkspacePackages.size} workspace dependencies...`);\n\n const batchSize = 5;\n const packages = Array.from(usedWorkspacePackages.values());\n\n for (let i = 0; i < packages.length; i += batchSize) {\n const batch = packages.slice(i, i + batchSize);\n logger.info(\n `Packaging batch ${Math.floor(i / batchSize) + 1}/${Math.ceil(packages.length / batchSize)}: ${batch.join(', ')}`,\n );\n await Promise.all(\n batch.map(async pkgName => {\n const dep = workspaceMap.get(pkgName);\n const sanitizedName = slugify(pkgName);\n if (!dep) return;\n\n await depsService.pack({ dir: dep.location, destination: workspaceDirPath, sanitizedName: sanitizedName });\n }),\n );\n }\n\n logger.info(`Successfully packaged ${usedWorkspacePackages.size} workspace dependencies`);\n }\n};\n","import type { IMastraLogger } from '@mastra/core/logger';\nimport * as babel from '@babel/core';\nimport commonjs from '@rollup/plugin-commonjs';\nimport json from '@rollup/plugin-json';\nimport nodeResolve from '@rollup/plugin-node-resolve';\nimport virtual from '@rollup/plugin-virtual';\nimport esmShim from '@rollup/plugin-esm-shim';\nimport { existsSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { fileURLToPath } from 'node:url';\nimport { rollup, type OutputAsset, type OutputChunk, type Plugin } from 'rollup';\nimport { esbuild } from './plugins/esbuild';\nimport { isNodeBuiltin } from './isNodeBuiltin';\nimport { aliasHono } from './plugins/hono-alias';\nimport { removeDeployer } from './plugins/remove-deployer';\nimport { join } from 'node:path';\nimport { validate } from '../validator/validate';\nimport { tsConfigPaths } from './plugins/tsconfig-paths';\nimport { writeFile } from 'node:fs/promises';\nimport { getBundlerOptions } from './bundlerOptions';\nimport { checkConfigExport } from './babel/check-config-export';\nimport { getCompiledDepCachePath, getPackageName, getPackageRootPath } from './utils';\nimport { createWorkspacePackageMap, type WorkspacePackageInfo } from '../bundler/workspaceDependencies';\nimport type { DependencyMetadata } from './types';\n\n// TODO: Make this extendable or find a rollup plugin that can do this\nconst globalExternals = [\n 'pino',\n 'pino-pretty',\n '@libsql/client',\n 'pg',\n 'libsql',\n 'jsdom',\n 'sqlite3',\n 'fastembed',\n 'nodemailer',\n '#tools',\n];\n\nfunction findExternalImporter(module: OutputChunk, external: string, allOutputs: OutputChunk[]): OutputChunk | null {\n const capturedFiles = new Set();\n\n for (const id of module.imports) {\n if (id === external) {\n return module;\n } else {\n if (id.endsWith('.mjs')) {\n capturedFiles.add(id);\n }\n }\n }\n\n for (const file of capturedFiles) {\n const nextModule = allOutputs.find(o => o.fileName === file);\n if (nextModule) {\n const importer = findExternalImporter(nextModule, external, allOutputs);\n\n if (importer) {\n return importer;\n }\n }\n }\n\n return null;\n}\n\n/**\n * Analyzes the entry file to identify dependencies that need optimization.\n * This is the first step of the bundle analysis process.\n *\n * @param entry - The entry file path or content\n * @param mastraEntry - The mastra entry point\n * @param isVirtualFile - Whether the entry is a virtual file (content string) or a file path\n * @param platform - Target platform (node or browser)\n * @param logger - Logger instance for debugging\n * @returns Map of dependencies to optimize with their metadata (exported bindings, rootPath, isWorkspace)\n */\nasync function analyze(\n entry: string,\n mastraEntry: string,\n isVirtualFile: boolean,\n platform: 'node' | 'browser',\n logger: IMastraLogger,\n sourcemapEnabled: boolean = false,\n workspaceMap: Map<string, WorkspacePackageInfo>,\n) {\n logger.info('Analyzing dependencies...');\n let virtualPlugin = null;\n if (isVirtualFile) {\n virtualPlugin = virtual({\n '#entry': entry,\n });\n entry = '#entry';\n }\n\n const normalizedMastraEntry = mastraEntry.replaceAll('\\\\', '/');\n const optimizerBundler = await rollup({\n logLevel: process.env.MASTRA_BUNDLER_DEBUG === 'true' ? 'debug' : 'silent',\n input: isVirtualFile ? '#entry' : entry,\n treeshake: 'smallest',\n preserveSymlinks: true,\n plugins: [\n virtualPlugin,\n tsConfigPaths(),\n {\n name: 'custom-alias-resolver',\n resolveId(id: string) {\n if (id === '#server') {\n return fileURLToPath(import.meta.resolve('@mastra/deployer/server')).replaceAll('\\\\', '/');\n }\n if (id === '#mastra') {\n return normalizedMastraEntry;\n }\n if (id.startsWith('@mastra/server')) {\n return fileURLToPath(import.meta.resolve(id));\n }\n\n // Tools is generated dependency, we don't want it to be handled by the bundler but instead read from disk at runtime\n if (id === '#tools') {\n return {\n id: '#tools',\n external: true,\n };\n }\n },\n } satisfies Plugin,\n json(),\n esbuild(),\n commonjs({\n strictRequires: 'debug',\n ignoreTryCatch: false,\n transformMixedEsModules: true,\n extensions: ['.js', '.ts'],\n }),\n removeDeployer(normalizedMastraEntry, { sourcemap: sourcemapEnabled }),\n esbuild(),\n ].filter(Boolean),\n });\n\n const { output } = await optimizerBundler.generate({\n format: 'esm',\n inlineDynamicImports: true,\n });\n\n await optimizerBundler.close();\n\n const depsToOptimize = new Map<string, DependencyMetadata>();\n\n for (const [dep, bindings] of Object.entries(output[0].importedBindings)) {\n // Skip node built-in\n if (isNodeBuiltin(dep)) {\n continue;\n }\n\n const isWorkspace = workspaceMap.has(dep);\n\n const pkgName = getPackageName(dep);\n let rootPath: string | null = null;\n\n if (pkgName && pkgName !== '#tools') {\n rootPath = await getPackageRootPath(pkgName);\n }\n\n depsToOptimize.set(dep, { exports: bindings, rootPath, isWorkspace });\n }\n\n for (const o of output) {\n if (o.type !== 'chunk') {\n continue;\n }\n\n // Tools is generated dependency, we don't want our analyzer to handle it\n const dynamicImports = o.dynamicImports.filter(d => d !== '#tools');\n if (!dynamicImports.length) {\n continue;\n }\n\n for (const dynamicImport of dynamicImports) {\n if (!depsToOptimize.has(dynamicImport) && !isNodeBuiltin(dynamicImport)) {\n depsToOptimize.set(dynamicImport, { exports: ['*'], rootPath: null, isWorkspace: false });\n }\n }\n }\n\n return depsToOptimize;\n}\n\n/**\n * Bundles vendor dependencies identified in the analysis step.\n * Creates virtual modules for each dependency and bundles them using rollup.\n *\n * @param depsToOptimize - Map of dependencies to optimize with their metadata (exported bindings, rootPath, isWorkspace)\n * @param outputDir - Directory where bundled files will be written\n * @param logger - Logger instance for debugging\n * @returns Object containing bundle output and reference map for validation\n */\nexport async function bundleExternals(\n depsToOptimize: Map<string, DependencyMetadata>,\n outputDir: string,\n logger: IMastraLogger,\n bundlerOptions?: {\n externals?: string[];\n transpilePackages?: string[];\n isDev?: boolean;\n },\n meta?: {\n workspaceRoot?: string;\n workspaceMap?: Map<string, WorkspacePackageInfo>;\n },\n) {\n logger.info('Optimizing dependencies...');\n logger.debug(\n `${Array.from(depsToOptimize.keys())\n .map(key => `- ${key}`)\n .join('\\n')}`,\n );\n\n const { externals: customExternals = [], transpilePackages = [], isDev = false } = bundlerOptions || {};\n const { workspaceRoot = null, workspaceMap = new Map() } = meta || {};\n const allExternals = [...globalExternals, ...customExternals];\n const reverseVirtualReferenceMap = new Map<string, string>();\n const virtualDependencies = new Map();\n\n for (const [dep, { exports, isWorkspace, rootPath }] of depsToOptimize.entries()) {\n let name = dep.replaceAll('/', '-');\n\n if (isWorkspace && rootPath && isDev && workspaceRoot) {\n const absolutePath = getCompiledDepCachePath(rootPath, name);\n\n /**\n * Further below `[name].mjs` is used. By making the name something like `packages/bar/node_modules/.cache/@monorepo-bar` Rollup writes the file to that path. For this also the `dir` needs adjusting.\n */\n name = absolutePath\n /**\n * The Rollup output.entryFileNames option doesn't allow relative or absolute paths, so the cacheDirAbsolutePath needs to be converted to a name relative to the workspace root.\n */\n .replace(workspaceRoot, '')\n /**\n * Remove leading slashes/backslashes\n */\n .replace(/^[/\\\\]+/, '');\n }\n\n reverseVirtualReferenceMap.set(name, dep);\n\n const virtualFile: string[] = [];\n let exportStringBuilder = [];\n for (const local of exports) {\n if (local === '*') {\n virtualFile.push(`export * from '${dep}';`);\n } else if (local === 'default') {\n virtualFile.push(`export { default } from '${dep}';`);\n } else {\n exportStringBuilder.push(local);\n }\n }\n\n if (exportStringBuilder.length > 0) {\n virtualFile.push(`export { ${exportStringBuilder.join(', ')} } from '${dep}';`);\n }\n\n virtualDependencies.set(dep, {\n name,\n virtual: virtualFile.join('\\n'),\n });\n }\n\n const transpilePackagesMap = new Map<string, string>();\n for (const pkg of transpilePackages) {\n const dir = await getPackageRootPath(pkg);\n\n if (dir) {\n transpilePackagesMap.set(pkg, dir);\n }\n }\n\n const bundler = await rollup({\n logLevel: process.env.MASTRA_BUNDLER_DEBUG === 'true' ? 'debug' : 'silent',\n input: Array.from(virtualDependencies.entries()).reduce(\n (acc, [dep, virtualDep]) => {\n acc[virtualDep.name] = `#virtual-${dep}`;\n return acc;\n },\n {} as Record<string, string>,\n ),\n external: allExternals,\n treeshake: 'smallest',\n plugins: [\n virtual(\n Array.from(virtualDependencies.entries()).reduce(\n (acc, [dep, virtualDep]) => {\n acc[`#virtual-${dep}`] = virtualDep.virtual;\n return acc;\n },\n {} as Record<string, string>,\n ),\n ),\n transpilePackagesMap.size\n ? esbuild({\n format: 'esm',\n include: [...transpilePackagesMap.values()].map(p => {\n // Match files from transpilePackages but exclude any nested node_modules\n // Escapes regex special characters in the path and uses negative lookahead to avoid node_modules\n // generated by cursor\n return new RegExp(`^${p.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}/(?!.*node_modules).*$`);\n }),\n })\n : null,\n commonjs({\n strictRequires: 'strict',\n transformMixedEsModules: true,\n ignoreTryCatch: false,\n }),\n isDev ? esmShim() : undefined,\n nodeResolve({\n preferBuiltins: true,\n exportConditions: ['node'],\n // Do not embed external dependencies into files that we write to `node_modules/.cache` (for the mastra dev + workspace use case)\n ...(workspaceMap.size > 0 && isDev ? { resolveOnly: Array.from(workspaceMap.keys()) } : {}),\n }),\n // hono is imported from deployer, so we need to resolve from here instead of the project root\n aliasHono(),\n json(),\n ].filter(Boolean),\n });\n\n const { output } = await bundler.write({\n format: 'esm',\n /**\n * If Mastra is used inside a monorepo, we need to find the workspace root so that Rollup can use it as base for the output dir. This should only happen during `mastra dev`.\n *\n * Otherwise, use outputDir as normal.\n */\n dir: isDev ? (workspaceRoot ? workspaceRoot : outputDir) : outputDir,\n entryFileNames: '[name].mjs',\n chunkFileNames: '[name].mjs',\n hoistTransitiveImports: false,\n });\n const moduleResolveMap = {} as Record<string, Record<string, string>>;\n const filteredChunks = output.filter(o => o.type === 'chunk');\n\n for (const o of filteredChunks.filter(o => o.isEntry || o.isDynamicEntry)) {\n for (const external of allExternals) {\n if (external === '#tools') {\n continue;\n }\n\n const importer = findExternalImporter(o, external, filteredChunks);\n\n if (importer) {\n const fullPath = join(outputDir, importer.fileName);\n moduleResolveMap[fullPath] = moduleResolveMap[fullPath] || {};\n if (importer.moduleIds.length) {\n moduleResolveMap[fullPath][external] = importer.moduleIds[importer.moduleIds.length - 1]?.startsWith(\n '\\x00virtual:#virtual',\n )\n ? importer.moduleIds[importer.moduleIds.length - 2]!\n : importer.moduleIds[importer.moduleIds.length - 1]!;\n }\n }\n }\n }\n\n await writeFile(join(outputDir, 'module-resolve-map.json'), JSON.stringify(moduleResolveMap, null, 2));\n\n await bundler.close();\n\n return { output, reverseVirtualReferenceMap, usedExternals: moduleResolveMap };\n}\n\n/**\n * Validates the bundled output by attempting to import each generated module.\n * Tracks invalid chunks and external dependencies that couldn't be bundled.\n *\n * @param output - Bundle output from rollup\n * @param reverseVirtualReferenceMap - Map to resolve virtual module names back to original deps\n * @param outputDir - Directory containing the bundled files\n * @param logger - Logger instance for debugging\n * @param workspaceMap - Map of workspace packages that gets directly passed through for later consumption\n * @returns Analysis result containing invalid chunks and dependency mappings\n */\nasync function validateOutput(\n {\n output,\n reverseVirtualReferenceMap,\n usedExternals,\n outputDir,\n workspaceMap,\n }: {\n output: (OutputChunk | OutputAsset)[];\n reverseVirtualReferenceMap: Map<string, string>;\n usedExternals: Record<string, Record<string, string>>;\n outputDir: string;\n workspaceMap: Map<string, WorkspacePackageInfo>;\n },\n logger: IMastraLogger,\n) {\n const result = {\n invalidChunks: new Set<string>(),\n dependencies: new Map<string, string>(),\n externalDependencies: new Set<string>(),\n workspaceMap,\n };\n\n // we should resolve the version of the deps\n for (const deps of Object.values(usedExternals)) {\n for (const dep of Object.keys(deps)) {\n result.externalDependencies.add(dep);\n }\n }\n\n for (const file of output) {\n if (file.type === 'asset') {\n continue;\n }\n\n try {\n logger.debug(`Validating if ${file.fileName} is a valid module.`);\n if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {\n result.dependencies.set(reverseVirtualReferenceMap.get(file.name)!, file.fileName);\n }\n\n if (!file.isDynamicEntry && file.isEntry) {\n // validate if the chunk is actually valid, a failsafe to make sure bundling didn't make any mistakes\n await validate(join(outputDir, file.fileName));\n }\n } catch (err) {\n result.invalidChunks.add(file.fileName);\n if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {\n const reference = reverseVirtualReferenceMap.get(file.name)!;\n const dep = reference.startsWith('@') ? reference.split('/').slice(0, 2).join('/') : reference.split('/')[0];\n\n result.externalDependencies.add(dep!);\n }\n\n // we might need this on other projects but not sure so let's keep it commented out for now\n // console.log(file.fileName, file.isEntry, file.isDynamicEntry, err);\n // result.invalidChunks.add(file.fileName);\n // const externalImports = excludeInternalDeps(file.imports.filter(file => !internalFiles.has(file)));\n // externalImports.push(...excludeInternalDeps(file.dynamicImports.filter(file => !internalFiles.has(file))));\n // for (const externalImport of externalImports) {\n // result.externalDependencies.add(externalImport);\n // }\n\n // if (reverseVirtualReferenceMap.has(file.name)) {\n // result.externalDependencies.add(reverseVirtualReferenceMap.get(file.name)!);\n // }\n }\n }\n\n return result;\n}\n\n/**\n * Main bundle analysis function that orchestrates the three-step process:\n * 1. Analyze dependencies\n * 2. Bundle dependencies modules\n * 3. Validate generated bundles\n *\n * This helps identify which dependencies need to be externalized vs bundled.\n */\nexport async function analyzeBundle(\n entries: string[],\n mastraEntry: string,\n outputDir: string,\n platform: 'node' | 'browser',\n logger: IMastraLogger,\n sourcemapEnabled: boolean = false,\n) {\n const mastraConfig = await readFile(mastraEntry, 'utf-8');\n const mastraConfigResult = {\n hasValidConfig: false,\n } as const;\n\n await babel.transformAsync(mastraConfig, {\n filename: mastraEntry,\n presets: [import.meta.resolve('@babel/preset-typescript')],\n plugins: [checkConfigExport(mastraConfigResult)],\n });\n\n if (!mastraConfigResult.hasValidConfig) {\n logger.warn(`Invalid Mastra config. Please make sure that your entry file looks like this:\nexport const mastra = new Mastra({\n // your options\n})\n \nIf you think your configuration is valid, please open an issue.`);\n }\n\n const workspaceMap = await createWorkspacePackageMap();\n\n const depsToOptimize = new Map<string, DependencyMetadata>();\n for (const entry of entries) {\n const isVirtualFile = entry.includes('\\n') || !existsSync(entry);\n const analyzeResult = await analyze(\n entry,\n mastraEntry,\n isVirtualFile,\n platform,\n logger,\n sourcemapEnabled,\n workspaceMap,\n );\n\n for (const [dep, { exports }] of analyzeResult.entries()) {\n if (depsToOptimize.has(dep)) {\n // Merge with existing exports if dependency already exists\n const existingEntry = depsToOptimize.get(dep)!;\n depsToOptimize.set(dep, {\n ...existingEntry,\n exports: [...new Set([...existingEntry.exports, ...exports])],\n });\n } else {\n const isWorkspace = workspaceMap.has(dep);\n\n const pkgName = getPackageName(dep);\n let rootPath: string | null = null;\n\n if (pkgName && pkgName !== '#tools') {\n rootPath = await getPackageRootPath(pkgName);\n }\n\n depsToOptimize.set(dep, { exports, rootPath, isWorkspace });\n }\n }\n }\n const bundlerOptions = await getBundlerOptions(mastraEntry, outputDir);\n\n const { output, reverseVirtualReferenceMap, usedExternals } = await bundleExternals(\n depsToOptimize,\n outputDir,\n logger,\n bundlerOptions ?? undefined,\n );\n const result = await validateOutput(\n { output, reverseVirtualReferenceMap, usedExternals, outputDir, workspaceMap },\n logger,\n );\n\n return result;\n}\n"]}
|