@mastra/deployer 0.4.0-alpha.1 → 0.10.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.
@@ -329,6 +329,14 @@ export declare function getAgentExecutionHandler(c: Context): Promise<Response>;
329
329
 
330
330
  export declare function getAgentsHandler(c: Context): Promise<Response & TypedResponse<any, ContentfulStatusCode, "json">>;
331
331
 
332
+ declare function getBundlerOptions(entryFile: string, outputDir: string): Promise<Config['bundler'] | null>;
333
+ export { getBundlerOptions }
334
+ export { getBundlerOptions as getBundlerOptions_alias_1 }
335
+
336
+ export declare function getBundlerOptionsBundler(entryFile: string, result: {
337
+ hasCustomConfig: false;
338
+ }): Promise<RollupBuild>;
339
+
332
340
  declare function getDeployer(entryFile: string, outputDir: string): Promise<MastraDeployer | undefined>;
333
341
  export { getDeployer }
334
342
  export { getDeployer as getDeployer_alias_1 }
@@ -651,6 +659,10 @@ export declare function recursiveRemoveNonReferencedNodes(code: string): Promise
651
659
 
652
660
  export declare function removeAllExceptDeployer(): babel_2.PluginObj;
653
661
 
662
+ export declare function removeAllOptionsExceptBundler(result: {
663
+ hasCustomConfig: boolean;
664
+ }): PluginObj<PluginPass>;
665
+
654
666
  export declare function removeAllOptionsExceptServer(result: {
655
667
  hasCustomConfig: boolean;
656
668
  }): PluginObj<PluginPass>;
@@ -661,7 +673,7 @@ export declare function removeAllOptionsExceptTelemetry(result: {
661
673
 
662
674
  export declare function removeAllOptionsFromMastraExcept(result: {
663
675
  hasCustomConfig: boolean;
664
- }, option: 'telemetry' | 'server'): babel_2.PluginObj;
676
+ }, option: 'telemetry' | 'server' | 'bundler'): babel_2.PluginObj;
665
677
 
666
678
  export declare function removeDeployer(): babel_2.PluginObj;
667
679
 
@@ -329,6 +329,14 @@ export declare function getAgentExecutionHandler(c: Context): Promise<Response>;
329
329
 
330
330
  export declare function getAgentsHandler(c: Context): Promise<Response & TypedResponse<any, ContentfulStatusCode, "json">>;
331
331
 
332
+ declare function getBundlerOptions(entryFile: string, outputDir: string): Promise<Config['bundler'] | null>;
333
+ export { getBundlerOptions }
334
+ export { getBundlerOptions as getBundlerOptions_alias_1 }
335
+
336
+ export declare function getBundlerOptionsBundler(entryFile: string, result: {
337
+ hasCustomConfig: false;
338
+ }): Promise<RollupBuild>;
339
+
332
340
  declare function getDeployer(entryFile: string, outputDir: string): Promise<MastraDeployer | undefined>;
333
341
  export { getDeployer }
334
342
  export { getDeployer as getDeployer_alias_1 }
@@ -651,6 +659,10 @@ export declare function recursiveRemoveNonReferencedNodes(code: string): Promise
651
659
 
652
660
  export declare function removeAllExceptDeployer(): babel_2.PluginObj;
653
661
 
662
+ export declare function removeAllOptionsExceptBundler(result: {
663
+ hasCustomConfig: boolean;
664
+ }): PluginObj<PluginPass>;
665
+
654
666
  export declare function removeAllOptionsExceptServer(result: {
655
667
  hasCustomConfig: boolean;
656
668
  }): PluginObj<PluginPass>;
@@ -661,7 +673,7 @@ export declare function removeAllOptionsExceptTelemetry(result: {
661
673
 
662
674
  export declare function removeAllOptionsFromMastraExcept(result: {
663
675
  hasCustomConfig: boolean;
664
- }, option: 'telemetry' | 'server'): babel_2.PluginObj;
676
+ }, option: 'telemetry' | 'server' | 'bundler'): babel_2.PluginObj;
665
677
 
666
678
  export declare function removeDeployer(): babel_2.PluginObj;
667
679
 
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkHHZDRBPV_cjs = require('../chunk-HHZDRBPV.cjs');
3
+ var chunkOJY5LJPT_cjs = require('../chunk-OJY5LJPT.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "analyzeBundle", {
8
8
  enumerable: true,
9
- get: function () { return chunkHHZDRBPV_cjs.analyzeBundle; }
9
+ get: function () { return chunkOJY5LJPT_cjs.analyzeBundle; }
10
10
  });
@@ -1 +1 @@
1
- export { analyzeBundle } from '../chunk-EHPJDSR3.js';
1
+ export { analyzeBundle } from '../chunk-W46BY5GT.js';
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkWHD7NHLX_cjs = require('../chunk-WHD7NHLX.cjs');
4
- var chunk3R6WDRBB_cjs = require('../chunk-3R6WDRBB.cjs');
5
- var chunkHHZDRBPV_cjs = require('../chunk-HHZDRBPV.cjs');
3
+ var chunkYHCVXGZM_cjs = require('../chunk-YHCVXGZM.cjs');
4
+ var chunkWK63QOD5_cjs = require('../chunk-WK63QOD5.cjs');
5
+ var chunkOJY5LJPT_cjs = require('../chunk-OJY5LJPT.cjs');
6
6
  var chunkIMGVLBV7_cjs = require('../chunk-IMGVLBV7.cjs');
7
7
  var chunk4VC5Z4YR_cjs = require('../chunk-4VC5Z4YR.cjs');
8
8
 
@@ -10,23 +10,27 @@ var chunk4VC5Z4YR_cjs = require('../chunk-4VC5Z4YR.cjs');
10
10
 
11
11
  Object.defineProperty(exports, "createWatcher", {
12
12
  enumerable: true,
13
- get: function () { return chunkWHD7NHLX_cjs.createWatcher; }
13
+ get: function () { return chunkYHCVXGZM_cjs.createWatcher; }
14
14
  });
15
15
  Object.defineProperty(exports, "getServerOptions", {
16
16
  enumerable: true,
17
- get: function () { return chunkWHD7NHLX_cjs.getServerOptions; }
17
+ get: function () { return chunkYHCVXGZM_cjs.getServerOptions; }
18
18
  });
19
19
  Object.defineProperty(exports, "getWatcherInputOptions", {
20
20
  enumerable: true,
21
- get: function () { return chunkWHD7NHLX_cjs.getInputOptions; }
21
+ get: function () { return chunkYHCVXGZM_cjs.getInputOptions; }
22
22
  });
23
23
  Object.defineProperty(exports, "writeTelemetryConfig", {
24
24
  enumerable: true,
25
- get: function () { return chunk3R6WDRBB_cjs.writeTelemetryConfig; }
25
+ get: function () { return chunkWK63QOD5_cjs.writeTelemetryConfig; }
26
26
  });
27
27
  Object.defineProperty(exports, "analyzeBundle", {
28
28
  enumerable: true,
29
- get: function () { return chunkHHZDRBPV_cjs.analyzeBundle; }
29
+ get: function () { return chunkOJY5LJPT_cjs.analyzeBundle; }
30
+ });
31
+ Object.defineProperty(exports, "getBundlerOptions", {
32
+ enumerable: true,
33
+ get: function () { return chunkOJY5LJPT_cjs.getBundlerOptions; }
30
34
  });
31
35
  Object.defineProperty(exports, "createBundler", {
32
36
  enumerable: true,
@@ -7,3 +7,4 @@ export { FileService_alias_1 as FileService } from '../_tsup-dts-rollup.cjs';
7
7
  export { Deps_alias_1 as Deps } from '../_tsup-dts-rollup.cjs';
8
8
  export { writeTelemetryConfig } from '../_tsup-dts-rollup.cjs';
9
9
  export { getServerOptions } from '../_tsup-dts-rollup.cjs';
10
+ export { getBundlerOptions_alias_1 as getBundlerOptions } from '../_tsup-dts-rollup.cjs';
@@ -7,3 +7,4 @@ export { FileService_alias_1 as FileService } from '../_tsup-dts-rollup.js';
7
7
  export { Deps_alias_1 as Deps } from '../_tsup-dts-rollup.js';
8
8
  export { writeTelemetryConfig } from '../_tsup-dts-rollup.js';
9
9
  export { getServerOptions } from '../_tsup-dts-rollup.js';
10
+ export { getBundlerOptions_alias_1 as getBundlerOptions } from '../_tsup-dts-rollup.js';
@@ -1,5 +1,5 @@
1
- export { createWatcher, getServerOptions, getInputOptions as getWatcherInputOptions } from '../chunk-U5VNUAES.js';
2
- export { writeTelemetryConfig } from '../chunk-TUMXQX4H.js';
3
- export { analyzeBundle } from '../chunk-EHPJDSR3.js';
1
+ export { createWatcher, getServerOptions, getInputOptions as getWatcherInputOptions } from '../chunk-5ZQI6XPC.js';
2
+ export { writeTelemetryConfig } from '../chunk-O3VM5GJZ.js';
3
+ export { analyzeBundle, getBundlerOptions } from '../chunk-W46BY5GT.js';
4
4
  export { createBundler, getInputOptions as getBundlerInputOptions } from '../chunk-AOSWYZKN.js';
5
5
  export { Deps, FileService } from '../chunk-UV4RQQ3R.js';
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkBQAYAQTU_cjs = require('../chunk-BQAYAQTU.cjs');
3
+ var chunkU7N6PH2I_cjs = require('../chunk-U7N6PH2I.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "Bundler", {
8
8
  enumerable: true,
9
- get: function () { return chunkBQAYAQTU_cjs.Bundler; }
9
+ get: function () { return chunkU7N6PH2I_cjs.Bundler; }
10
10
  });
@@ -1 +1 @@
1
- export { Bundler } from '../chunk-YU2QBGOU.js';
1
+ export { Bundler } from '../chunk-SC6Y2LQ4.js';
@@ -1,5 +1,4 @@
1
- import { recursiveRemoveNonReferencedNodes, removeAllOptionsFromMastraExcept } from './chunk-TUMXQX4H.js';
2
- import { aliasHono } from './chunk-EHPJDSR3.js';
1
+ import { aliasHono, recursiveRemoveNonReferencedNodes, removeAllOptionsFromMastraExcept } from './chunk-W46BY5GT.js';
3
2
  import { getInputOptions } from './chunk-AOSWYZKN.js';
4
3
  import { tsConfigPaths } from './chunk-WVBUOQT6.js';
5
4
  import { watch, rollup } from 'rollup';
@@ -0,0 +1,99 @@
1
+ import { recursiveRemoveNonReferencedNodes, removeAllOptionsFromMastraExcept } from './chunk-W46BY5GT.js';
2
+ import * as babel from '@babel/core';
3
+ import { rollup } from 'rollup';
4
+ import esbuild from 'rollup-plugin-esbuild';
5
+ import commonjs from '@rollup/plugin-commonjs';
6
+
7
+ // src/build/babel/remove-all-options-telemetry.ts
8
+ function removeAllOptionsExceptTelemetry(result) {
9
+ return removeAllOptionsFromMastraExcept(result, "telemetry");
10
+ }
11
+
12
+ // src/build/telemetry.ts
13
+ function getTelemetryBundler(entryFile, result) {
14
+ return rollup({
15
+ logLevel: "silent",
16
+ input: {
17
+ "telemetry-config": entryFile
18
+ },
19
+ treeshake: "smallest",
20
+ plugins: [
21
+ // transpile typescript to something we understand
22
+ esbuild({
23
+ target: "node20",
24
+ platform: "node",
25
+ minify: false
26
+ }),
27
+ commonjs({
28
+ extensions: [".js", ".ts"],
29
+ strictRequires: "strict",
30
+ transformMixedEsModules: true,
31
+ ignoreTryCatch: false
32
+ }),
33
+ {
34
+ name: "get-telemetry-config",
35
+ transform(code, id) {
36
+ if (id !== entryFile) {
37
+ return;
38
+ }
39
+ return new Promise((resolve, reject) => {
40
+ babel.transform(
41
+ code,
42
+ {
43
+ babelrc: false,
44
+ configFile: false,
45
+ filename: id,
46
+ plugins: [removeAllOptionsExceptTelemetry(result)]
47
+ },
48
+ (err, result2) => {
49
+ if (err) {
50
+ return reject(err);
51
+ }
52
+ resolve({
53
+ code: result2.code,
54
+ map: result2.map
55
+ });
56
+ }
57
+ );
58
+ });
59
+ }
60
+ },
61
+ // let esbuild remove all unused imports
62
+ esbuild({
63
+ target: "node20",
64
+ platform: "node",
65
+ minify: false
66
+ }),
67
+ {
68
+ name: "cleanup",
69
+ transform(code, id) {
70
+ if (id !== entryFile) {
71
+ return;
72
+ }
73
+ return recursiveRemoveNonReferencedNodes(code);
74
+ }
75
+ },
76
+ // let esbuild remove all unused imports
77
+ esbuild({
78
+ target: "node20",
79
+ platform: "node",
80
+ minify: false
81
+ })
82
+ ]
83
+ });
84
+ }
85
+ async function writeTelemetryConfig(entryFile, outputDir) {
86
+ const result = {
87
+ hasCustomConfig: false
88
+ };
89
+ const bundle = await getTelemetryBundler(entryFile, result);
90
+ const { output } = await bundle.write({
91
+ dir: outputDir,
92
+ format: "es",
93
+ entryFileNames: "[name].mjs"
94
+ });
95
+ const externals = output[0].imports.filter((x) => !x.startsWith("./"));
96
+ return { ...result, externalDependencies: externals };
97
+ }
98
+
99
+ export { writeTelemetryConfig };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunk54KOF3NB_cjs = require('./chunk-54KOF3NB.cjs');
4
- var commonjs = require('@rollup/plugin-commonjs');
4
+ var commonjs2 = require('@rollup/plugin-commonjs');
5
5
  var json = require('@rollup/plugin-json');
6
6
  var nodeResolve = require('@rollup/plugin-node-resolve');
7
7
  var virtual = require('@rollup/plugin-virtual');
@@ -13,14 +13,34 @@ var module$1 = require('module');
13
13
  var path = require('path');
14
14
  var child_process = require('child_process');
15
15
  var promises = require('fs/promises');
16
+ var babel = require('@babel/core');
16
17
 
17
18
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
18
19
 
19
- var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
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);
20
39
  var json__default = /*#__PURE__*/_interopDefault(json);
21
40
  var nodeResolve__default = /*#__PURE__*/_interopDefault(nodeResolve);
22
41
  var virtual__default = /*#__PURE__*/_interopDefault(virtual);
23
42
  var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
43
+ var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
24
44
 
25
45
  function isNodeBuiltin(dep) {
26
46
  const [pkg] = dep.split("/");
@@ -75,6 +95,230 @@ function validate(file) {
75
95
  }
76
96
  );
77
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
78
322
  var globalExternals = [
79
323
  "pino",
80
324
  "pino-pretty",
@@ -146,7 +390,7 @@ async function analyze(entry, mastraEntry, isVirtualFile, platform, logger) {
146
390
  platform,
147
391
  minify: false
148
392
  }),
149
- commonjs__default.default({
393
+ commonjs2__default.default({
150
394
  strictRequires: "debug",
151
395
  ignoreTryCatch: false,
152
396
  transformMixedEsModules: true,
@@ -183,11 +427,12 @@ async function analyze(entry, mastraEntry, isVirtualFile, platform, logger) {
183
427
  }
184
428
  return depsToOptimize;
185
429
  }
186
- async function bundleExternals(depsToOptimize, outputDir, logger) {
430
+ async function bundleExternals(depsToOptimize, outputDir, logger, customExternals) {
187
431
  logger.info("Optimizing dependencies...");
188
432
  logger.debug(
189
433
  `${Array.from(depsToOptimize.keys()).map((key) => `- ${key}`).join("\n")}`
190
434
  );
435
+ const allExternals = [...globalExternals, ...customExternals || []];
191
436
  const reverseVirtualReferenceMap = /* @__PURE__ */ new Map();
192
437
  const virtualDependencies = /* @__PURE__ */ new Map();
193
438
  for (const [dep, exports] of depsToOptimize.entries()) {
@@ -223,7 +468,7 @@ async function bundleExternals(depsToOptimize, outputDir, logger) {
223
468
  ),
224
469
  // this dependency breaks the build, so we need to exclude it
225
470
  // TODO actually fix this so we don't need to exclude it
226
- external: globalExternals,
471
+ external: allExternals,
227
472
  treeshake: "smallest",
228
473
  plugins: [
229
474
  virtual__default.default(
@@ -235,7 +480,7 @@ async function bundleExternals(depsToOptimize, outputDir, logger) {
235
480
  {}
236
481
  )
237
482
  ),
238
- commonjs__default.default({
483
+ commonjs2__default.default({
239
484
  strictRequires: "strict",
240
485
  transformMixedEsModules: true,
241
486
  ignoreTryCatch: false
@@ -260,7 +505,7 @@ async function bundleExternals(depsToOptimize, outputDir, logger) {
260
505
  const moduleResolveMap = {};
261
506
  const filteredChunks = output.filter((o) => o.type === "chunk");
262
507
  for (const o of filteredChunks.filter((o2) => o2.isEntry || o2.isDynamicEntry)) {
263
- for (const external of globalExternals) {
508
+ for (const external of allExternals) {
264
509
  const importer = findExternalImporter(o, external, filteredChunks);
265
510
  if (importer) {
266
511
  const fullPath = path.join(outputDir, importer.fileName);
@@ -319,10 +564,12 @@ async function validateOutput({
319
564
  async function analyzeBundle(entry, mastraEntry, outputDir, platform, logger) {
320
565
  const isVirtualFile = entry.includes("\n") || !fs.existsSync(entry);
321
566
  const depsToOptimize = await analyze(entry, mastraEntry, isVirtualFile, platform, logger);
567
+ const customExternals = (await getBundlerOptions(mastraEntry, outputDir))?.externals;
322
568
  const { output, reverseVirtualReferenceMap, usedExternals } = await bundleExternals(
323
569
  depsToOptimize,
324
570
  outputDir,
325
- logger
571
+ logger,
572
+ customExternals
326
573
  );
327
574
  const result = await validateOutput({ output, reverseVirtualReferenceMap, usedExternals, outputDir }, logger);
328
575
  return result;
@@ -330,3 +577,6 @@ async function analyzeBundle(entry, mastraEntry, outputDir, platform, logger) {
330
577
 
331
578
  exports.aliasHono = aliasHono;
332
579
  exports.analyzeBundle = analyzeBundle;
580
+ exports.getBundlerOptions = getBundlerOptions;
581
+ exports.recursiveRemoveNonReferencedNodes = recursiveRemoveNonReferencedNodes;
582
+ exports.removeAllOptionsFromMastraExcept = removeAllOptionsFromMastraExcept;
@@ -1,5 +1,5 @@
1
- import { writeTelemetryConfig } from './chunk-TUMXQX4H.js';
2
- import { analyzeBundle } from './chunk-EHPJDSR3.js';
1
+ import { writeTelemetryConfig } from './chunk-O3VM5GJZ.js';
2
+ import { analyzeBundle } from './chunk-W46BY5GT.js';
3
3
  import { createBundler, getInputOptions } from './chunk-AOSWYZKN.js';
4
4
  import { DepsService, FileService } from './chunk-UV4RQQ3R.js';
5
5
  import { existsSync } from 'node:fs';
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunk3R6WDRBB_cjs = require('./chunk-3R6WDRBB.cjs');
4
- var chunkHHZDRBPV_cjs = require('./chunk-HHZDRBPV.cjs');
3
+ var chunkWK63QOD5_cjs = require('./chunk-WK63QOD5.cjs');
4
+ var chunkOJY5LJPT_cjs = require('./chunk-OJY5LJPT.cjs');
5
5
  var chunkIMGVLBV7_cjs = require('./chunk-IMGVLBV7.cjs');
6
6
  var chunk4VC5Z4YR_cjs = require('./chunk-4VC5Z4YR.cjs');
7
7
  var fs = require('fs');
@@ -130,7 +130,7 @@ var Bundler = class extends bundler.MastraBundler {
130
130
  }
131
131
  async writeInstrumentationFile(outputDirectory) {
132
132
  const instrumentationFile = path.join(outputDirectory, "instrumentation.mjs");
133
- const __dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-BQAYAQTU.cjs', document.baseURI).href))));
133
+ const __dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-U7N6PH2I.cjs', document.baseURI).href))));
134
134
  await fsExtra.copy(path.join(__dirname, "templates", "instrumentation-template.js"), instrumentationFile);
135
135
  }
136
136
  async writePackageJson(outputDirectory, dependencies, resolutions) {
@@ -176,7 +176,7 @@ var Bundler = class extends bundler.MastraBundler {
176
176
  return chunkIMGVLBV7_cjs.createBundler(inputOptions, outputOptions);
177
177
  }
178
178
  async analyze(entry, mastraFile, outputDirectory) {
179
- return await chunkHHZDRBPV_cjs.analyzeBundle(entry, mastraFile, path.join(outputDirectory, this.analyzeOutputDir), "node", this.logger);
179
+ return await chunkOJY5LJPT_cjs.analyzeBundle(entry, mastraFile, path.join(outputDirectory, this.analyzeOutputDir), "node", this.logger);
180
180
  }
181
181
  async installDependencies(outputDirectory, rootDir = process.cwd()) {
182
182
  const deps = new chunk4VC5Z4YR_cjs.DepsService(rootDir);
@@ -235,14 +235,14 @@ var Bundler = class extends bundler.MastraBundler {
235
235
  }
236
236
  async _bundle(serverFile, mastraEntryFile, outputDirectory, toolsPaths = [], bundleLocation = path.join(outputDirectory, this.outputDir)) {
237
237
  this.logger.info("Start bundling Mastra");
238
- const analyzedBundleInfo = await chunkHHZDRBPV_cjs.analyzeBundle(
238
+ const analyzedBundleInfo = await chunkOJY5LJPT_cjs.analyzeBundle(
239
239
  serverFile,
240
240
  mastraEntryFile,
241
241
  path.join(outputDirectory, this.analyzeOutputDir),
242
242
  "node",
243
243
  this.logger
244
244
  );
245
- const { externalDependencies } = await chunk3R6WDRBB_cjs.writeTelemetryConfig(mastraEntryFile, path.join(outputDirectory, this.outputDir));
245
+ const { externalDependencies } = await chunkWK63QOD5_cjs.writeTelemetryConfig(mastraEntryFile, path.join(outputDirectory, this.outputDir));
246
246
  const dependenciesToInstall = /* @__PURE__ */ new Map();
247
247
  for (const external of externalDependencies) {
248
248
  dependenciesToInstall.set(external, "latest");