@mastra/deployer 0.10.13 → 0.10.15-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.
Files changed (56) hide show
  1. package/dist/_tsup-dts-rollup.d.cts +844 -0
  2. package/dist/_tsup-dts-rollup.d.ts +844 -0
  3. package/dist/build/analyze.cjs +10 -0
  4. package/dist/build/analyze.d.cts +1 -0
  5. package/dist/build/analyze.d.ts +1 -0
  6. package/dist/build/analyze.js +1 -0
  7. package/dist/build/bundler.cjs +14 -0
  8. package/dist/build/bundler.d.cts +2 -0
  9. package/dist/build/bundler.d.ts +2 -0
  10. package/dist/build/bundler.js +1 -0
  11. package/dist/build/index.cjs +50 -0
  12. package/dist/build/index.d.cts +10 -0
  13. package/dist/build/index.d.ts +10 -0
  14. package/dist/build/index.js +5 -0
  15. package/dist/bundler/index.cjs +10 -0
  16. package/dist/bundler/index.d.cts +1 -0
  17. package/dist/bundler/index.d.ts +1 -0
  18. package/dist/bundler/index.js +1 -0
  19. package/dist/chunk-54KOF3NB.cjs +137 -0
  20. package/dist/chunk-6QMONK4A.cjs +2 -0
  21. package/dist/chunk-C4JT7CIH.js +1 -0
  22. package/dist/chunk-D2DCFCLH.cjs +157 -0
  23. package/dist/chunk-D6736SJL.js +209 -0
  24. package/dist/chunk-ENT5RDOI.js +99 -0
  25. package/dist/chunk-FK2WUSEN.cjs +238 -0
  26. package/dist/chunk-GPD54HBC.js +380 -0
  27. package/dist/chunk-HJGC75ZR.js +490 -0
  28. package/dist/chunk-KCP5ITLV.cjs +412 -0
  29. package/dist/chunk-M2VZQFTW.cjs +125 -0
  30. package/dist/chunk-TIC2KT3M.js +146 -0
  31. package/dist/chunk-UYQZMNZL.js +572 -0
  32. package/dist/chunk-XKH6F4NE.cjs +604 -0
  33. package/dist/chunk-YFMAWUII.cjs +502 -0
  34. package/dist/chunk-Z544XXXK.js +111 -0
  35. package/dist/index.cjs +194 -0
  36. package/dist/index.d.cts +8 -0
  37. package/dist/index.d.ts +8 -0
  38. package/dist/index.js +153 -0
  39. package/dist/server/index.cjs +8446 -0
  40. package/dist/server/index.d.cts +2 -0
  41. package/dist/server/index.d.ts +2 -0
  42. package/dist/server/index.js +8438 -0
  43. package/dist/services/index.cjs +18 -0
  44. package/dist/services/index.d.cts +3 -0
  45. package/dist/services/index.d.ts +3 -0
  46. package/dist/services/index.js +1 -0
  47. package/dist/templates/instrumentation-template.js +137 -0
  48. package/dist/validator/custom-resolver.cjs +52 -0
  49. package/dist/validator/custom-resolver.d.cts +1 -0
  50. package/dist/validator/custom-resolver.d.ts +1 -0
  51. package/dist/validator/custom-resolver.js +50 -0
  52. package/dist/validator/loader.cjs +7 -0
  53. package/dist/validator/loader.d.cts +1 -0
  54. package/dist/validator/loader.d.ts +1 -0
  55. package/dist/validator/loader.js +4 -0
  56. package/package.json +5 -5
@@ -0,0 +1,604 @@
1
+ 'use strict';
2
+
3
+ var chunk54KOF3NB_cjs = require('./chunk-54KOF3NB.cjs');
4
+ var commonjs2 = require('@rollup/plugin-commonjs');
5
+ var json = require('@rollup/plugin-json');
6
+ var nodeResolve = require('@rollup/plugin-node-resolve');
7
+ var virtual = require('@rollup/plugin-virtual');
8
+ var fs = require('fs');
9
+ var url = require('url');
10
+ var rollup = require('rollup');
11
+ var esbuild = require('rollup-plugin-esbuild');
12
+ var module$1 = require('module');
13
+ var path = require('path');
14
+ var child_process = require('child_process');
15
+ var promises = require('fs/promises');
16
+ var babel = require('@babel/core');
17
+
18
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
19
+
20
+ function _interopNamespace(e) {
21
+ if (e && e.__esModule) return e;
22
+ var n = Object.create(null);
23
+ if (e) {
24
+ Object.keys(e).forEach(function (k) {
25
+ if (k !== 'default') {
26
+ var d = Object.getOwnPropertyDescriptor(e, k);
27
+ Object.defineProperty(n, k, d.get ? d : {
28
+ enumerable: true,
29
+ get: function () { return e[k]; }
30
+ });
31
+ }
32
+ });
33
+ }
34
+ n.default = e;
35
+ return Object.freeze(n);
36
+ }
37
+
38
+ var commonjs2__default = /*#__PURE__*/_interopDefault(commonjs2);
39
+ var json__default = /*#__PURE__*/_interopDefault(json);
40
+ var nodeResolve__default = /*#__PURE__*/_interopDefault(nodeResolve);
41
+ var virtual__default = /*#__PURE__*/_interopDefault(virtual);
42
+ var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
43
+ var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
44
+
45
+ function isNodeBuiltin(dep) {
46
+ const [pkg] = dep.split("/");
47
+ return dep.startsWith("node:") || module$1.builtinModules.includes(dep) || module$1.builtinModules.includes(pkg);
48
+ }
49
+ function aliasHono() {
50
+ return {
51
+ name: "hono-alias",
52
+ resolveId(id) {
53
+ if (!id.startsWith("@hono/") && !id.startsWith("hono/") && id !== "hono" && id !== "hono-openapi") {
54
+ return;
55
+ }
56
+ const path = undefined(id);
57
+ return url.fileURLToPath(path);
58
+ }
59
+ };
60
+ }
61
+ function spawn(command, args = [], options = {}) {
62
+ return new Promise((resolve, reject) => {
63
+ const childProcess = child_process.spawn(command, args, {
64
+ // stdio: 'inherit',
65
+ ...options
66
+ });
67
+ childProcess.on("error", (error) => {
68
+ reject(error);
69
+ });
70
+ let stderr = "";
71
+ childProcess.stderr?.on("data", (message) => {
72
+ stderr += message;
73
+ });
74
+ childProcess.on("close", (code) => {
75
+ if (code === 0) {
76
+ resolve();
77
+ } else {
78
+ reject(new Error(stderr));
79
+ }
80
+ });
81
+ });
82
+ }
83
+ function validate(file) {
84
+ return spawn(
85
+ "node",
86
+ [
87
+ "--import",
88
+ undefined("@mastra/deployer/loader"),
89
+ "--input-type=module",
90
+ "-e",
91
+ `import('file://${file.replaceAll("\\", "/")}')`
92
+ ],
93
+ {
94
+ cwd: path.dirname(file)
95
+ }
96
+ );
97
+ }
98
+ function removeAllOptionsFromMastraExcept(result, option) {
99
+ const t = babel__namespace.default.types;
100
+ return {
101
+ name: "remove-all-except-" + option + "-config",
102
+ visitor: {
103
+ ExportNamedDeclaration: {
104
+ // remove all exports
105
+ exit(path) {
106
+ path.remove();
107
+ }
108
+ },
109
+ NewExpression(path, state) {
110
+ const varDeclaratorPath = path.findParent((path2) => t.isVariableDeclarator(path2.node));
111
+ if (!varDeclaratorPath) {
112
+ return;
113
+ }
114
+ const parentNode = path.parentPath.node;
115
+ if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
116
+ return;
117
+ }
118
+ let mastraArgs = t.objectExpression([]);
119
+ if (t.isObjectExpression(path.node.arguments[0])) {
120
+ mastraArgs = path.node.arguments[0];
121
+ }
122
+ let telemetry = mastraArgs.properties.find(
123
+ // @ts-ignore
124
+ (prop) => prop.key.name === option
125
+ );
126
+ let telemetryValue = t.objectExpression([]);
127
+ const programPath = path.scope.getProgramParent().path;
128
+ if (!programPath) {
129
+ return;
130
+ }
131
+ if (telemetry && t.isObjectProperty(telemetry) && t.isExpression(telemetry.value)) {
132
+ result.hasCustomConfig = true;
133
+ telemetryValue = telemetry.value;
134
+ if (t.isIdentifier(telemetry.value) && telemetry.value.name === option) {
135
+ const telemetryBinding = state.file.scope.getBinding(option);
136
+ if (telemetryBinding && t.isVariableDeclarator(telemetryBinding.path.node)) {
137
+ const id = path.scope.generateUidIdentifier(option);
138
+ telemetryBinding.path.replaceWith(t.variableDeclarator(id, telemetryBinding.path.node.init));
139
+ telemetryValue = id;
140
+ }
141
+ }
142
+ }
143
+ const exportDeclaration = t.exportNamedDeclaration(
144
+ t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), telemetryValue)]),
145
+ []
146
+ );
147
+ programPath.node.body.push(exportDeclaration);
148
+ }
149
+ }
150
+ };
151
+ }
152
+
153
+ // src/build/babel/remove-all-options-bundler.ts
154
+ function removeAllOptionsExceptBundler(result) {
155
+ return removeAllOptionsFromMastraExcept(result, "bundler");
156
+ }
157
+ function removeNonReferencedNodes() {
158
+ const t = babel__namespace.default.types;
159
+ return {
160
+ name: "remove-non-referenced-nodes",
161
+ visitor: {
162
+ Program(path) {
163
+ const scope = path.scope;
164
+ const currentBody = path.get("body");
165
+ const filteredBody = currentBody.filter((childPath) => {
166
+ if (childPath.isExportDeclaration()) {
167
+ return true;
168
+ }
169
+ if (childPath.isVariableDeclaration()) {
170
+ return childPath.node.declarations.some((decl) => {
171
+ if (!t.isIdentifier(decl.id)) {
172
+ return false;
173
+ }
174
+ const name = decl.id.name;
175
+ const binding = scope.getBinding(name);
176
+ return binding && (binding.referenced || binding.referencePaths.length > 0);
177
+ });
178
+ }
179
+ if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {
180
+ if (!t.isIdentifier(childPath.node.id)) {
181
+ return false;
182
+ }
183
+ const name = childPath.node.id.name;
184
+ const binding = scope.getBinding(name);
185
+ return binding && (binding.referenced || binding.referencePaths.length > 0);
186
+ }
187
+ if (childPath.isImportDeclaration()) {
188
+ return childPath.node.specifiers.some((specifier) => {
189
+ const importedName = specifier.local.name;
190
+ const binding = scope.getBinding(importedName);
191
+ return binding && (binding.referenced || binding.referencePaths.length > 0);
192
+ });
193
+ }
194
+ return false;
195
+ });
196
+ path.set(
197
+ "body",
198
+ filteredBody.map((p) => p.node)
199
+ );
200
+ }
201
+ }
202
+ };
203
+ }
204
+
205
+ // src/build/plugins/remove-unused-references.ts
206
+ function recursiveRemoveNonReferencedNodes(code) {
207
+ return new Promise(async (resolve, reject) => {
208
+ babel__namespace.transform(
209
+ code,
210
+ {
211
+ babelrc: false,
212
+ configFile: false,
213
+ plugins: [removeNonReferencedNodes()]
214
+ },
215
+ (err, result) => {
216
+ if (err) {
217
+ return reject(err);
218
+ }
219
+ if (result && result.code !== code) {
220
+ return recursiveRemoveNonReferencedNodes(result.code).then(resolve, reject);
221
+ }
222
+ resolve({
223
+ code: result.code,
224
+ map: result.map
225
+ });
226
+ }
227
+ );
228
+ });
229
+ }
230
+
231
+ // src/build/bundlerOptions.ts
232
+ function getBundlerOptionsBundler(entryFile, result) {
233
+ return rollup.rollup({
234
+ logLevel: "silent",
235
+ input: {
236
+ "bundler-config": entryFile
237
+ },
238
+ treeshake: "smallest",
239
+ plugins: [
240
+ chunk54KOF3NB_cjs.tsConfigPaths(),
241
+ // transpile typescript to something we understand
242
+ esbuild__default.default({
243
+ target: "node20",
244
+ platform: "node",
245
+ minify: false
246
+ }),
247
+ commonjs2__default.default({
248
+ extensions: [".js", ".ts"],
249
+ strictRequires: "strict",
250
+ transformMixedEsModules: true,
251
+ ignoreTryCatch: false
252
+ }),
253
+ {
254
+ name: "get-bundler-config",
255
+ transform(code, id) {
256
+ if (id !== entryFile) {
257
+ return;
258
+ }
259
+ return new Promise((resolve, reject) => {
260
+ babel__namespace.transform(
261
+ code,
262
+ {
263
+ babelrc: false,
264
+ configFile: false,
265
+ filename: id,
266
+ plugins: [removeAllOptionsExceptBundler(result)]
267
+ },
268
+ (err, result2) => {
269
+ if (err) {
270
+ return reject(err);
271
+ }
272
+ resolve({
273
+ code: result2.code,
274
+ map: result2.map
275
+ });
276
+ }
277
+ );
278
+ });
279
+ }
280
+ },
281
+ // let esbuild remove all unused imports
282
+ esbuild__default.default({
283
+ target: "node20",
284
+ platform: "node",
285
+ minify: false
286
+ }),
287
+ {
288
+ name: "cleanup",
289
+ transform(code, id) {
290
+ if (id !== entryFile) {
291
+ return;
292
+ }
293
+ return recursiveRemoveNonReferencedNodes(code);
294
+ }
295
+ },
296
+ // let esbuild remove all unused imports
297
+ esbuild__default.default({
298
+ target: "node20",
299
+ platform: "node",
300
+ minify: false
301
+ })
302
+ ]
303
+ });
304
+ }
305
+ async function getBundlerOptions(entryFile, outputDir) {
306
+ const result = {
307
+ hasCustomConfig: false
308
+ };
309
+ const bundle = await getBundlerOptionsBundler(entryFile, result);
310
+ await bundle.write({
311
+ dir: outputDir,
312
+ format: "es",
313
+ entryFileNames: "[name].mjs"
314
+ });
315
+ if (result.hasCustomConfig) {
316
+ return (await import(`file:${outputDir}/bundler-config.mjs`)).bundler;
317
+ }
318
+ return null;
319
+ }
320
+
321
+ // src/build/analyze.ts
322
+ var globalExternals = [
323
+ "pino",
324
+ "pino-pretty",
325
+ "@libsql/client",
326
+ "pg",
327
+ "libsql",
328
+ "jsdom",
329
+ "sqlite3",
330
+ "fastembed",
331
+ "nodemailer"
332
+ ];
333
+ function findExternalImporter(module, external, allOutputs) {
334
+ const capturedFiles = /* @__PURE__ */ new Set();
335
+ for (const id of module.imports) {
336
+ if (id === external) {
337
+ return module;
338
+ } else {
339
+ if (id.endsWith(".mjs")) {
340
+ capturedFiles.add(id);
341
+ }
342
+ }
343
+ }
344
+ for (const file of capturedFiles) {
345
+ const nextModule = allOutputs.find((o) => o.fileName === file);
346
+ if (nextModule) {
347
+ const importer = findExternalImporter(nextModule, external, allOutputs);
348
+ if (importer) {
349
+ return importer;
350
+ }
351
+ }
352
+ }
353
+ return null;
354
+ }
355
+ async function analyze(entry, mastraEntry, isVirtualFile, platform, logger) {
356
+ logger.info("Analyzing dependencies...");
357
+ let virtualPlugin = null;
358
+ if (isVirtualFile) {
359
+ virtualPlugin = virtual__default.default({
360
+ "#entry": entry
361
+ });
362
+ entry = "#entry";
363
+ }
364
+ const normalizedMastraEntry = mastraEntry.replaceAll("\\", "/");
365
+ const optimizerBundler = await rollup.rollup({
366
+ logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
367
+ input: isVirtualFile ? "#entry" : entry,
368
+ treeshake: "smallest",
369
+ preserveSymlinks: true,
370
+ plugins: [
371
+ virtualPlugin,
372
+ chunk54KOF3NB_cjs.tsConfigPaths(),
373
+ {
374
+ name: "custom-alias-resolver",
375
+ resolveId(id) {
376
+ if (id === "#server") {
377
+ return url.fileURLToPath(undefined("@mastra/deployer/server")).replaceAll("\\", "/");
378
+ }
379
+ if (id === "#mastra") {
380
+ return normalizedMastraEntry;
381
+ }
382
+ if (id.startsWith("@mastra/server")) {
383
+ return url.fileURLToPath(undefined(id));
384
+ }
385
+ if (id === "#tools") {
386
+ return {
387
+ id: "#tools",
388
+ external: true
389
+ };
390
+ }
391
+ }
392
+ },
393
+ json__default.default(),
394
+ esbuild__default.default({
395
+ target: "node20",
396
+ platform,
397
+ minify: false
398
+ }),
399
+ commonjs2__default.default({
400
+ strictRequires: "debug",
401
+ ignoreTryCatch: false,
402
+ transformMixedEsModules: true,
403
+ extensions: [".js", ".ts"]
404
+ }),
405
+ chunk54KOF3NB_cjs.removeDeployer(normalizedMastraEntry),
406
+ esbuild__default.default({
407
+ target: "node20",
408
+ platform,
409
+ minify: false
410
+ })
411
+ ].filter(Boolean)
412
+ });
413
+ const { output } = await optimizerBundler.generate({
414
+ format: "esm",
415
+ inlineDynamicImports: true
416
+ });
417
+ await optimizerBundler.close();
418
+ const depsToOptimize = new Map(Object.entries(output[0].importedBindings));
419
+ for (const dep of depsToOptimize.keys()) {
420
+ if (isNodeBuiltin(dep)) {
421
+ depsToOptimize.delete(dep);
422
+ }
423
+ }
424
+ for (const o of output) {
425
+ if (o.type !== "chunk") {
426
+ continue;
427
+ }
428
+ const dynamicImports = o.dynamicImports.filter((d) => d !== "#tools");
429
+ if (!dynamicImports.length) {
430
+ continue;
431
+ }
432
+ console.log(dynamicImports);
433
+ for (const dynamicImport of dynamicImports) {
434
+ if (!depsToOptimize.has(dynamicImport) && !isNodeBuiltin(dynamicImport)) {
435
+ depsToOptimize.set(dynamicImport, ["*"]);
436
+ }
437
+ }
438
+ }
439
+ return depsToOptimize;
440
+ }
441
+ async function bundleExternals(depsToOptimize, outputDir, logger, customExternals) {
442
+ logger.info("Optimizing dependencies...");
443
+ logger.debug(
444
+ `${Array.from(depsToOptimize.keys()).map((key) => `- ${key}`).join("\n")}`
445
+ );
446
+ const allExternals = [...globalExternals, ...customExternals || []];
447
+ const reverseVirtualReferenceMap = /* @__PURE__ */ new Map();
448
+ const virtualDependencies = /* @__PURE__ */ new Map();
449
+ for (const [dep, exports] of depsToOptimize.entries()) {
450
+ const name = dep.replaceAll("/", "-");
451
+ reverseVirtualReferenceMap.set(name, dep);
452
+ const virtualFile = [];
453
+ let exportStringBuilder = [];
454
+ for (const local of exports) {
455
+ if (local === "*") {
456
+ virtualFile.push(`export * from '${dep}';`);
457
+ } else if (local === "default") {
458
+ virtualFile.push(`export { default } from '${dep}';`);
459
+ } else {
460
+ exportStringBuilder.push(local);
461
+ }
462
+ }
463
+ if (exportStringBuilder.length > 0) {
464
+ virtualFile.push(`export { ${exportStringBuilder.join(", ")} } from '${dep}';`);
465
+ }
466
+ virtualDependencies.set(dep, {
467
+ name,
468
+ virtual: virtualFile.join("\n")
469
+ });
470
+ }
471
+ const bundler = await rollup.rollup({
472
+ logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
473
+ input: Array.from(virtualDependencies.entries()).reduce(
474
+ (acc, [dep, virtualDep]) => {
475
+ acc[virtualDep.name] = `#virtual-${dep}`;
476
+ return acc;
477
+ },
478
+ {}
479
+ ),
480
+ // this dependency breaks the build, so we need to exclude it
481
+ // TODO actually fix this so we don't need to exclude it
482
+ external: allExternals,
483
+ treeshake: "smallest",
484
+ plugins: [
485
+ virtual__default.default(
486
+ Array.from(virtualDependencies.entries()).reduce(
487
+ (acc, [dep, virtualDep]) => {
488
+ acc[`#virtual-${dep}`] = virtualDep.virtual;
489
+ return acc;
490
+ },
491
+ {}
492
+ )
493
+ ),
494
+ commonjs2__default.default({
495
+ strictRequires: "strict",
496
+ transformMixedEsModules: true,
497
+ ignoreTryCatch: false
498
+ }),
499
+ nodeResolve__default.default({
500
+ preferBuiltins: true,
501
+ exportConditions: ["node", "import", "require"],
502
+ mainFields: ["module", "main"]
503
+ }),
504
+ // hono is imported from deployer, so we need to resolve from here instead of the project root
505
+ aliasHono(),
506
+ json__default.default()
507
+ ].filter(Boolean)
508
+ });
509
+ const { output } = await bundler.write({
510
+ format: "esm",
511
+ dir: outputDir,
512
+ entryFileNames: "[name].mjs",
513
+ chunkFileNames: "[name].mjs",
514
+ hoistTransitiveImports: false
515
+ });
516
+ const moduleResolveMap = {};
517
+ const filteredChunks = output.filter((o) => o.type === "chunk");
518
+ for (const o of filteredChunks.filter((o2) => o2.isEntry || o2.isDynamicEntry)) {
519
+ for (const external of allExternals) {
520
+ const importer = findExternalImporter(o, external, filteredChunks);
521
+ if (importer) {
522
+ const fullPath = path.join(outputDir, importer.fileName);
523
+ moduleResolveMap[fullPath] = moduleResolveMap[fullPath] || {};
524
+ if (importer.moduleIds.length) {
525
+ moduleResolveMap[fullPath][external] = importer.moduleIds[importer.moduleIds.length - 1]?.startsWith(
526
+ "\0virtual:#virtual"
527
+ ) ? importer.moduleIds[importer.moduleIds.length - 2] : importer.moduleIds[importer.moduleIds.length - 1];
528
+ }
529
+ }
530
+ }
531
+ }
532
+ await promises.writeFile(path.join(outputDir, "module-resolve-map.json"), JSON.stringify(moduleResolveMap, null, 2));
533
+ await bundler.close();
534
+ return { output, reverseVirtualReferenceMap, usedExternals: moduleResolveMap };
535
+ }
536
+ async function validateOutput({
537
+ output,
538
+ reverseVirtualReferenceMap,
539
+ usedExternals,
540
+ outputDir
541
+ }, logger) {
542
+ const result = {
543
+ invalidChunks: /* @__PURE__ */ new Set(),
544
+ dependencies: /* @__PURE__ */ new Map(),
545
+ externalDependencies: /* @__PURE__ */ new Set()
546
+ };
547
+ for (const deps of Object.values(usedExternals)) {
548
+ for (const dep of Object.keys(deps)) {
549
+ result.externalDependencies.add(dep);
550
+ }
551
+ }
552
+ for (const file of output) {
553
+ if (file.type === "asset") {
554
+ continue;
555
+ }
556
+ try {
557
+ logger.debug(`Validating if ${file.fileName} is a valid module.`);
558
+ if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
559
+ result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
560
+ }
561
+ if (!file.isDynamicEntry && file.isEntry) {
562
+ await validate(path.join(outputDir, file.fileName));
563
+ }
564
+ } catch (err) {
565
+ result.invalidChunks.add(file.fileName);
566
+ if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
567
+ const reference = reverseVirtualReferenceMap.get(file.name);
568
+ const dep = reference.startsWith("@") ? reference.split("/").slice(0, 2).join("/") : reference.split("/")[0];
569
+ result.externalDependencies.add(dep);
570
+ }
571
+ }
572
+ }
573
+ return result;
574
+ }
575
+ async function analyzeBundle(entries, mastraEntry, outputDir, platform, logger) {
576
+ const depsToOptimize = /* @__PURE__ */ new Map();
577
+ for (const entry of entries) {
578
+ const isVirtualFile = entry.includes("\n") || !fs.existsSync(entry);
579
+ const analyzeResult = await analyze(entry, mastraEntry, isVirtualFile, platform, logger);
580
+ for (const [dep, exports] of analyzeResult.entries()) {
581
+ if (depsToOptimize.has(dep)) {
582
+ const existingExports = depsToOptimize.get(dep);
583
+ depsToOptimize.set(dep, [.../* @__PURE__ */ new Set([...existingExports, ...exports])]);
584
+ } else {
585
+ depsToOptimize.set(dep, exports);
586
+ }
587
+ }
588
+ }
589
+ const customExternals = (await getBundlerOptions(mastraEntry, outputDir))?.externals;
590
+ const { output, reverseVirtualReferenceMap, usedExternals } = await bundleExternals(
591
+ depsToOptimize,
592
+ outputDir,
593
+ logger,
594
+ customExternals
595
+ );
596
+ const result = await validateOutput({ output, reverseVirtualReferenceMap, usedExternals, outputDir }, logger);
597
+ return result;
598
+ }
599
+
600
+ exports.aliasHono = aliasHono;
601
+ exports.analyzeBundle = analyzeBundle;
602
+ exports.getBundlerOptions = getBundlerOptions;
603
+ exports.recursiveRemoveNonReferencedNodes = recursiveRemoveNonReferencedNodes;
604
+ exports.removeAllOptionsFromMastraExcept = removeAllOptionsFromMastraExcept;