@mastra/deployer 1.0.0-beta.9 → 1.0.4

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 (183) hide show
  1. package/CHANGELOG.md +811 -0
  2. package/dist/arktype-aI7TBD0R-CCZH3EYK.js +8 -0
  3. package/dist/{arktype-aI7TBD0R-OEPFT4G6.js.map → arktype-aI7TBD0R-CCZH3EYK.js.map} +1 -1
  4. package/dist/{arktype-aI7TBD0R-4YXBEQBG.cjs → arktype-aI7TBD0R-XHBHUL3T.cjs} +3 -3
  5. package/dist/{arktype-aI7TBD0R-4YXBEQBG.cjs.map → arktype-aI7TBD0R-XHBHUL3T.cjs.map} +1 -1
  6. package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
  7. package/dist/build/analyze/bundleExternals.d.ts +4 -5
  8. package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
  9. package/dist/build/analyze.cjs +2 -2
  10. package/dist/build/analyze.d.ts +5 -5
  11. package/dist/build/analyze.d.ts.map +1 -1
  12. package/dist/build/analyze.js +1 -1
  13. package/dist/build/babel/remove-deployer.d.ts.map +1 -1
  14. package/dist/build/bundler.cjs +3 -3
  15. package/dist/build/bundler.d.ts +3 -1
  16. package/dist/build/bundler.d.ts.map +1 -1
  17. package/dist/build/bundler.js +1 -1
  18. package/dist/build/bundlerOptions.d.ts.map +1 -1
  19. package/dist/build/deployer.d.ts.map +1 -1
  20. package/dist/build/index.cjs +19 -10
  21. package/dist/build/index.d.ts +2 -0
  22. package/dist/build/index.d.ts.map +1 -1
  23. package/dist/build/index.js +4 -3
  24. package/dist/build/package-info.d.ts +9 -0
  25. package/dist/build/package-info.d.ts.map +1 -0
  26. package/dist/build/plugins/node-modules-extension-resolver.d.ts +7 -0
  27. package/dist/build/plugins/node-modules-extension-resolver.d.ts.map +1 -1
  28. package/dist/build/plugins/remove-all-except.d.ts +10 -0
  29. package/dist/build/plugins/remove-all-except.d.ts.map +1 -0
  30. package/dist/build/plugins/tsconfig-paths.d.ts +1 -1
  31. package/dist/build/plugins/tsconfig-paths.d.ts.map +1 -1
  32. package/dist/build/serverOptions.d.ts.map +1 -1
  33. package/dist/build/shared/extract-mastra-option.d.ts +4 -8
  34. package/dist/build/shared/extract-mastra-option.d.ts.map +1 -1
  35. package/dist/build/types.d.ts +5 -0
  36. package/dist/build/types.d.ts.map +1 -1
  37. package/dist/build/utils.d.ts +35 -4
  38. package/dist/build/utils.d.ts.map +1 -1
  39. package/dist/build/watcher.d.ts +2 -1
  40. package/dist/build/watcher.d.ts.map +1 -1
  41. package/dist/bundler/index.cjs +6 -2
  42. package/dist/bundler/index.d.ts +10 -7
  43. package/dist/bundler/index.d.ts.map +1 -1
  44. package/dist/bundler/index.js +1 -1
  45. package/dist/chunk-2VG357HT.cjs +4 -0
  46. package/dist/{chunk-BTNPI4Z7.cjs.map → chunk-2VG357HT.cjs.map} +1 -1
  47. package/dist/chunk-5FPJTHRK.js +88 -0
  48. package/dist/chunk-5FPJTHRK.js.map +1 -0
  49. package/dist/{chunk-2OTEFUER.cjs → chunk-5TYVF4KJ.cjs} +31 -24
  50. package/dist/chunk-5TYVF4KJ.cjs.map +1 -0
  51. package/dist/{chunk-BFQ2S5UD.cjs → chunk-7EPD2XJR.cjs} +76 -20
  52. package/dist/chunk-7EPD2XJR.cjs.map +1 -0
  53. package/dist/{chunk-MMUE22EL.js → chunk-DBXWQ2CA.js} +10 -10
  54. package/dist/chunk-DBXWQ2CA.js.map +1 -0
  55. package/dist/chunk-G6GFAPPU.js +6 -0
  56. package/dist/{chunk-Q2YGWEXY.js.map → chunk-G6GFAPPU.js.map} +1 -1
  57. package/dist/chunk-GU4OME5Q.cjs +112 -0
  58. package/dist/chunk-GU4OME5Q.cjs.map +1 -0
  59. package/dist/chunk-HPGDVJAZ.js +3 -0
  60. package/dist/{chunk-FBT6QP7J.js.map → chunk-HPGDVJAZ.js.map} +1 -1
  61. package/dist/{chunk-TK2CCU7I.js → chunk-HWSYWSD7.js} +278 -190
  62. package/dist/chunk-HWSYWSD7.js.map +1 -0
  63. package/dist/{chunk-GD2TGMBP.cjs → chunk-JBE6KM7R.cjs} +3 -3
  64. package/dist/{chunk-GD2TGMBP.cjs.map → chunk-JBE6KM7R.cjs.map} +1 -1
  65. package/dist/{chunk-TXKETRIN.cjs → chunk-JRUJ546M.cjs} +10 -10
  66. package/dist/chunk-JRUJ546M.cjs.map +1 -0
  67. package/dist/{chunk-7PLNIFGZ.cjs → chunk-KE4NVPI4.cjs} +3 -3
  68. package/dist/{chunk-7PLNIFGZ.cjs.map → chunk-KE4NVPI4.cjs.map} +1 -1
  69. package/dist/chunk-MCWU6IKS.js +14 -0
  70. package/dist/{chunk-N5TMJUIR.js.map → chunk-MCWU6IKS.js.map} +1 -1
  71. package/dist/{chunk-UQZGTSBF.js → chunk-NGQZZ54Y.js} +68 -13
  72. package/dist/chunk-NGQZZ54Y.js.map +1 -0
  73. package/dist/chunk-QAOUDKHK.js +67 -0
  74. package/dist/chunk-QAOUDKHK.js.map +1 -0
  75. package/dist/{chunk-RBPCXFN7.js → chunk-SD6NHZ2H.js} +47 -28
  76. package/dist/chunk-SD6NHZ2H.js.map +1 -0
  77. package/dist/{chunk-MUWNMVNL.cjs → chunk-T7NCLSYN.cjs} +297 -209
  78. package/dist/chunk-T7NCLSYN.cjs.map +1 -0
  79. package/dist/{chunk-P4L6VIHY.js → chunk-V4HCIN6G.js} +3 -3
  80. package/dist/{chunk-P4L6VIHY.js.map → chunk-V4HCIN6G.js.map} +1 -1
  81. package/dist/{chunk-SS22TD6R.cjs → chunk-VOI3B5MX.cjs} +54 -34
  82. package/dist/chunk-VOI3B5MX.cjs.map +1 -0
  83. package/dist/chunk-ZXQ7DOYU.cjs +16 -0
  84. package/dist/{chunk-ID3HN3BH.cjs.map → chunk-ZXQ7DOYU.cjs.map} +1 -1
  85. package/dist/default-u_dwuiYb-JPNIZQKK.cjs +9 -0
  86. package/dist/{default-u_dwuiYb-PWN6FHC6.cjs.map → default-u_dwuiYb-JPNIZQKK.cjs.map} +1 -1
  87. package/dist/default-u_dwuiYb-RK5OD4MY.js +3 -0
  88. package/dist/{default-u_dwuiYb-65M4BHAA.js.map → default-u_dwuiYb-RK5OD4MY.js.map} +1 -1
  89. package/dist/docs/README.md +32 -0
  90. package/dist/docs/SKILL.md +36 -0
  91. package/dist/docs/SOURCE_MAP.json +27 -0
  92. package/dist/docs/deployer/01-reference.md +93 -0
  93. package/dist/docs/deployment/01-overview.md +64 -0
  94. package/dist/docs/deployment/02-mastra-server.md +129 -0
  95. package/dist/docs/deployment/03-monorepo.md +142 -0
  96. package/dist/docs/deployment/04-cloud-providers.md +17 -0
  97. package/dist/docs/deployment/05-web-framework.md +55 -0
  98. package/dist/docs/deployment/06-workflow-runners.md +11 -0
  99. package/dist/effect-QlVUlMFu-HN3LWZSQ.cjs +17 -0
  100. package/dist/{effect-QlVUlMFu-2ADPKIDF.cjs.map → effect-QlVUlMFu-HN3LWZSQ.cjs.map} +1 -1
  101. package/dist/{effect-QlVUlMFu-FD73M3OO.js → effect-QlVUlMFu-XOJ2F4UA.js} +4 -4
  102. package/dist/{effect-QlVUlMFu-FD73M3OO.js.map → effect-QlVUlMFu-XOJ2F4UA.js.map} +1 -1
  103. package/dist/{esm-BLVTLTJW.js → esm-6TGK2CUM.js} +3 -3
  104. package/dist/esm-6TGK2CUM.js.map +1 -0
  105. package/dist/{esm-E3NUCNVN.cjs → esm-SQKX5ABS.cjs} +3 -3
  106. package/dist/esm-SQKX5ABS.cjs.map +1 -0
  107. package/dist/index.cjs +4 -15
  108. package/dist/index.cjs.map +1 -1
  109. package/dist/index.js +3 -14
  110. package/dist/index.js.map +1 -1
  111. package/dist/server/index.cjs +523 -87
  112. package/dist/server/index.cjs.map +1 -1
  113. package/dist/server/index.d.ts.map +1 -1
  114. package/dist/server/index.js +521 -86
  115. package/dist/server/index.js.map +1 -1
  116. package/dist/server/types.d.ts +1 -1
  117. package/dist/server/types.d.ts.map +1 -1
  118. package/dist/sury-CWZTCd75-KEHKUXG7.cjs +17 -0
  119. package/dist/{sury-CWZTCd75-K3FHMZF5.cjs.map → sury-CWZTCd75-KEHKUXG7.cjs.map} +1 -1
  120. package/dist/{sury-CWZTCd75-Y2GURJ6K.js → sury-CWZTCd75-L2D76L25.js} +4 -4
  121. package/dist/{sury-CWZTCd75-Y2GURJ6K.js.map → sury-CWZTCd75-L2D76L25.js.map} +1 -1
  122. package/dist/typebox-Dei93FPO-LBLFC3RD.js +8 -0
  123. package/dist/{typebox-Dei93FPO-2WP4NOYD.js.map → typebox-Dei93FPO-LBLFC3RD.js.map} +1 -1
  124. package/dist/{typebox-Dei93FPO-WTXAW2LA.cjs → typebox-Dei93FPO-RDSW6DFA.cjs} +3 -3
  125. package/dist/{typebox-Dei93FPO-WTXAW2LA.cjs.map → typebox-Dei93FPO-RDSW6DFA.cjs.map} +1 -1
  126. package/dist/valibot--1zFm7rT-NVADAEQI.cjs +17 -0
  127. package/dist/{valibot--1zFm7rT-HMTCRBB3.cjs.map → valibot--1zFm7rT-NVADAEQI.cjs.map} +1 -1
  128. package/dist/{valibot--1zFm7rT-VGFBTDTW.js → valibot--1zFm7rT-R2UKWLZC.js} +4 -4
  129. package/dist/{valibot--1zFm7rT-VGFBTDTW.js.map → valibot--1zFm7rT-R2UKWLZC.js.map} +1 -1
  130. package/dist/{valibot-D_HTw1Gn-ILCWWLE4.cjs → valibot-D_HTw1Gn-DSFFOUBW.cjs} +7 -7
  131. package/dist/{valibot-D_HTw1Gn-ILCWWLE4.cjs.map → valibot-D_HTw1Gn-DSFFOUBW.cjs.map} +1 -1
  132. package/dist/{valibot-D_HTw1Gn-LLCGNU3W.js → valibot-D_HTw1Gn-KWXWP2TJ.js} +5 -5
  133. package/dist/{valibot-D_HTw1Gn-LLCGNU3W.js.map → valibot-D_HTw1Gn-KWXWP2TJ.js.map} +1 -1
  134. package/dist/validator/custom-resolver.cjs +2 -2
  135. package/dist/validator/custom-resolver.js +1 -1
  136. package/dist/{zod-Bwrt9trS-XCRGYQVE.js → zod-Bwrt9trS-GCUGPBJX.js} +5 -5
  137. package/dist/{zod-Bwrt9trS-XCRGYQVE.js.map → zod-Bwrt9trS-GCUGPBJX.js.map} +1 -1
  138. package/dist/{zod-Bwrt9trS-XDMWF3NW.cjs → zod-Bwrt9trS-ZZHFZ7YQ.cjs} +7 -7
  139. package/dist/{zod-Bwrt9trS-XDMWF3NW.cjs.map → zod-Bwrt9trS-ZZHFZ7YQ.cjs.map} +1 -1
  140. package/dist/{zod-DSgpEGAE-ZWQMF6SS.cjs → zod-DSgpEGAE-3CMS4FSB.cjs} +7 -7
  141. package/dist/{zod-DSgpEGAE-ZWQMF6SS.cjs.map → zod-DSgpEGAE-3CMS4FSB.cjs.map} +1 -1
  142. package/dist/{zod-DSgpEGAE-TKBHSSLS.js → zod-DSgpEGAE-IPE3O2NQ.js} +5 -5
  143. package/dist/{zod-DSgpEGAE-TKBHSSLS.js.map → zod-DSgpEGAE-IPE3O2NQ.js.map} +1 -1
  144. package/package.json +15 -15
  145. package/dist/arktype-aI7TBD0R-OEPFT4G6.js +0 -8
  146. package/dist/build/babel/get-deployer.d.ts +0 -3
  147. package/dist/build/babel/get-deployer.d.ts.map +0 -1
  148. package/dist/build/babel/remove-all-options-bundler.d.ts +0 -5
  149. package/dist/build/babel/remove-all-options-bundler.d.ts.map +0 -1
  150. package/dist/build/babel/remove-all-options-deployer.d.ts +0 -5
  151. package/dist/build/babel/remove-all-options-deployer.d.ts.map +0 -1
  152. package/dist/build/babel/remove-all-options-server.d.ts +0 -5
  153. package/dist/build/babel/remove-all-options-server.d.ts.map +0 -1
  154. package/dist/chunk-2OTEFUER.cjs.map +0 -1
  155. package/dist/chunk-5CWPEG6R.js +0 -62
  156. package/dist/chunk-5CWPEG6R.js.map +0 -1
  157. package/dist/chunk-BFQ2S5UD.cjs.map +0 -1
  158. package/dist/chunk-BTNPI4Z7.cjs +0 -4
  159. package/dist/chunk-FBT6QP7J.js +0 -3
  160. package/dist/chunk-ID3HN3BH.cjs +0 -16
  161. package/dist/chunk-MMUE22EL.js.map +0 -1
  162. package/dist/chunk-MUWNMVNL.cjs.map +0 -1
  163. package/dist/chunk-N5TMJUIR.js +0 -14
  164. package/dist/chunk-Q2YGWEXY.js +0 -6
  165. package/dist/chunk-RBPCXFN7.js.map +0 -1
  166. package/dist/chunk-SS22TD6R.cjs.map +0 -1
  167. package/dist/chunk-TK2CCU7I.js.map +0 -1
  168. package/dist/chunk-TXKETRIN.cjs.map +0 -1
  169. package/dist/chunk-UQZGTSBF.js.map +0 -1
  170. package/dist/chunk-X4TNUYQL.cjs +0 -196
  171. package/dist/chunk-X4TNUYQL.cjs.map +0 -1
  172. package/dist/chunk-X5QU7B2W.js +0 -169
  173. package/dist/chunk-X5QU7B2W.js.map +0 -1
  174. package/dist/default-u_dwuiYb-65M4BHAA.js +0 -3
  175. package/dist/default-u_dwuiYb-PWN6FHC6.cjs +0 -9
  176. package/dist/effect-QlVUlMFu-2ADPKIDF.cjs +0 -17
  177. package/dist/esm-BLVTLTJW.js.map +0 -1
  178. package/dist/esm-E3NUCNVN.cjs.map +0 -1
  179. package/dist/server/handlers/prompt.d.ts +0 -3
  180. package/dist/server/handlers/prompt.d.ts.map +0 -1
  181. package/dist/sury-CWZTCd75-K3FHMZF5.cjs +0 -17
  182. package/dist/typebox-Dei93FPO-2WP4NOYD.js +0 -8
  183. package/dist/valibot--1zFm7rT-HMTCRBB3.cjs +0 -17
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var chunk2OTEFUER_cjs = require('./chunk-2OTEFUER.cjs');
3
+ var chunk5TYVF4KJ_cjs = require('./chunk-5TYVF4KJ.cjs');
4
4
  var babel = require('@babel/core');
5
5
  var fs = require('fs');
6
6
  var promises = require('fs/promises');
7
7
  var path2 = require('path');
8
8
  var child_process = require('child_process');
9
+ var url = require('url');
9
10
  var rollup = require('rollup');
10
11
  var originalEsbuild = require('rollup-plugin-esbuild');
11
12
  var commonjs = require('@rollup/plugin-commonjs');
@@ -14,17 +15,16 @@ var stripJsonComments = require('strip-json-comments');
14
15
  var typescriptPaths = require('typescript-paths');
15
16
  var rollupPlugin = require('@optimize-lodash/rollup-plugin');
16
17
  var json = require('@rollup/plugin-json');
17
- var url = require('url');
18
18
  var pkg = require('empathic/package');
19
19
  var findWorkspaces = require('find-workspaces');
20
20
  var logger = require('@mastra/core/logger');
21
21
  var virtual = require('@rollup/plugin-virtual');
22
22
  var module$1 = require('module');
23
+ var localPkg = require('local-pkg');
23
24
  var nodeResolve = require('@rollup/plugin-node-resolve');
24
25
  var originalEsmShim = require('@rollup/plugin-esm-shim');
25
26
  var posix = require('path/posix');
26
27
  var resolve = require('resolve.exports');
27
- var localPkg = require('local-pkg');
28
28
  var error = require('@mastra/core/error');
29
29
 
30
30
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -129,7 +129,7 @@ globalThis.__dirname = dirname(__filename);
129
129
  "--input-type=module",
130
130
  "--enable-source-maps",
131
131
  "-e",
132
- `${prefixCode};import('file://${chunk2OTEFUER_cjs.slash(file)}').catch(err => {
132
+ `${prefixCode};import('${url.pathToFileURL(file).href}').catch(err => {
133
133
  ${errorHandler.toString()}
134
134
  errorHandler(err);
135
135
  })`.replaceAll(/\n/g, "")
@@ -143,87 +143,6 @@ globalThis.__dirname = dirname(__filename);
143
143
  }
144
144
  );
145
145
  }
146
- function removeAllOptionsFromMastraExcept(result, option, logger) {
147
- const t = babel__namespace.default.types;
148
- return {
149
- name: "remove-all-except-" + option + "-config",
150
- visitor: {
151
- ExportNamedDeclaration: {
152
- // remove all exports
153
- exit(path3) {
154
- path3.remove();
155
- }
156
- },
157
- NewExpression(path3, state) {
158
- const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
159
- if (!varDeclaratorPath) {
160
- return;
161
- }
162
- const parentNode = path3.parentPath.node;
163
- if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
164
- return;
165
- }
166
- let mastraArgs = t.objectExpression([]);
167
- if (t.isObjectExpression(path3.node.arguments[0])) {
168
- mastraArgs = path3.node.arguments[0];
169
- }
170
- let configProperty = mastraArgs.properties.find(
171
- // @ts-ignore
172
- (prop) => prop.key.name === option
173
- );
174
- let configValue = t.objectExpression([]);
175
- const programPath = path3.scope.getProgramParent().path;
176
- if (!programPath) {
177
- return;
178
- }
179
- if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {
180
- result.hasCustomConfig = true;
181
- configValue = configProperty.value;
182
- if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {
183
- const configBinding = state.file.scope.getBinding(option);
184
- if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {
185
- const id = path3.scope.generateUidIdentifier(option);
186
- configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init));
187
- configValue = id;
188
- }
189
- }
190
- }
191
- const exportDeclaration = t.exportNamedDeclaration(
192
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), configValue)]),
193
- []
194
- );
195
- programPath.node.body.push(exportDeclaration);
196
- },
197
- Program: {
198
- exit(path3) {
199
- const hasExport = path3.node.body.some(
200
- (node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
201
- );
202
- if (!hasExport) {
203
- if (logger) {
204
- logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
205
- export const mastra = new Mastra({
206
- ${option}: <value>
207
- })
208
-
209
- `);
210
- }
211
- const fallbackExportDeclaration = t.exportNamedDeclaration(
212
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
213
- []
214
- );
215
- path3.node.body.push(fallbackExportDeclaration);
216
- }
217
- }
218
- }
219
- }
220
- };
221
- }
222
-
223
- // src/build/babel/remove-all-options-bundler.ts
224
- function removeAllOptionsExceptBundler(result, logger) {
225
- return removeAllOptionsFromMastraExcept(result, "bundler", logger);
226
- }
227
146
  function esbuild(options = {}) {
228
147
  return originalEsbuild__default.default({
229
148
  target: "node20",
@@ -237,7 +156,7 @@ function hasPaths(tsConfigPath) {
237
156
  try {
238
157
  const content = fs__default.default.readFileSync(tsConfigPath, "utf8");
239
158
  const config = JSON.parse(stripJsonComments__default.default(content));
240
- return !!(config.compilerOptions?.paths && Object.keys(config.compilerOptions.paths).length > 0);
159
+ return !!(config.compilerOptions?.paths && Object.keys(config.compilerOptions.paths).length > 0 || typeof config.extends === "string" && config.extends.length > 0 || Array.isArray(config.extends) && config.extends.length > 0);
241
160
  } catch {
242
161
  return false;
243
162
  }
@@ -441,7 +360,117 @@ function recursiveRemoveNonReferencedNodes(code) {
441
360
  );
442
361
  });
443
362
  }
444
- function extractMastraOptionBundler(name, entryFile, transformer, result, logger) {
363
+ function removeAllOptionsFromMastraExcept(result, option, logger) {
364
+ const t = babel__namespace.default.types;
365
+ return {
366
+ name: "remove-all-except-" + option + "-config",
367
+ visitor: {
368
+ ExportNamedDeclaration: {
369
+ // remove all exports
370
+ exit(path3) {
371
+ path3.remove();
372
+ }
373
+ },
374
+ NewExpression(path3, state) {
375
+ const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
376
+ if (!varDeclaratorPath) {
377
+ return;
378
+ }
379
+ const parentNode = path3.parentPath.node;
380
+ if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
381
+ return;
382
+ }
383
+ let mastraArgs = t.objectExpression([]);
384
+ if (t.isObjectExpression(path3.node.arguments[0])) {
385
+ mastraArgs = path3.node.arguments[0];
386
+ }
387
+ let configProperty = mastraArgs.properties.find(
388
+ (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === option
389
+ );
390
+ let configValue = t.objectExpression([]);
391
+ const programPath = path3.scope.getProgramParent().path;
392
+ if (!programPath) {
393
+ return;
394
+ }
395
+ if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {
396
+ result.hasCustomConfig = true;
397
+ configValue = configProperty.value;
398
+ if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {
399
+ const configBinding = state.file.scope.getBinding(option);
400
+ if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {
401
+ const id = path3.scope.generateUidIdentifier(option);
402
+ configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init));
403
+ configValue = id;
404
+ }
405
+ }
406
+ }
407
+ const exportDeclaration = t.exportNamedDeclaration(
408
+ t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), configValue)]),
409
+ []
410
+ );
411
+ programPath.node.body.push(exportDeclaration);
412
+ },
413
+ Program: {
414
+ exit(path3) {
415
+ const hasExport = path3.node.body.some(
416
+ (node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
417
+ );
418
+ if (!hasExport) {
419
+ if (logger) {
420
+ logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
421
+ export const mastra = new Mastra({
422
+ ${option}: <value>
423
+ })
424
+
425
+ `);
426
+ }
427
+ const fallbackExportDeclaration = t.exportNamedDeclaration(
428
+ t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
429
+ []
430
+ );
431
+ path3.node.body.push(fallbackExportDeclaration);
432
+ }
433
+ }
434
+ }
435
+ }
436
+ };
437
+ }
438
+
439
+ // src/build/plugins/remove-all-except.ts
440
+ function removeAllOptionsFromMastraExceptPlugin(mastraEntry, name, result, options) {
441
+ return {
442
+ name: `remove-${name}`,
443
+ transform(code, id) {
444
+ if (id !== mastraEntry) {
445
+ return;
446
+ }
447
+ return new Promise((resolve2, reject) => {
448
+ babel__namespace.transform(
449
+ code,
450
+ {
451
+ babelrc: false,
452
+ configFile: false,
453
+ filename: id,
454
+ plugins: [removeAllOptionsFromMastraExcept(result, name, options?.logger)],
455
+ sourceMaps: options?.sourcemap
456
+ },
457
+ (err, result2) => {
458
+ if (err) {
459
+ return reject(err);
460
+ }
461
+ resolve2({
462
+ code: result2.code,
463
+ map: result2.map
464
+ });
465
+ }
466
+ );
467
+ });
468
+ }
469
+ };
470
+ }
471
+
472
+ // src/build/shared/extract-mastra-option.ts
473
+ function extractMastraOptionBundler(name, entryFile, result, logger) {
445
474
  return rollup.rollup({
446
475
  logLevel: "silent",
447
476
  input: {
@@ -462,34 +491,7 @@ function extractMastraOptionBundler(name, entryFile, transformer, result, logger
462
491
  ignoreTryCatch: false
463
492
  }),
464
493
  json__default.default(),
465
- {
466
- name: `extract-${name}-config`,
467
- transform(code, id) {
468
- if (id !== entryFile) {
469
- return;
470
- }
471
- return new Promise((resolve2, reject) => {
472
- babel__namespace.transform(
473
- code,
474
- {
475
- babelrc: false,
476
- configFile: false,
477
- filename: id,
478
- plugins: [transformer(result, logger)]
479
- },
480
- (err, result2) => {
481
- if (err) {
482
- return reject(err);
483
- }
484
- resolve2({
485
- code: result2.code,
486
- map: result2.map
487
- });
488
- }
489
- );
490
- });
491
- }
492
- },
494
+ removeAllOptionsFromMastraExceptPlugin(entryFile, name, result, { logger }),
493
495
  // let esbuild remove all unused imports
494
496
  esbuild(),
495
497
  {
@@ -506,11 +508,11 @@ function extractMastraOptionBundler(name, entryFile, transformer, result, logger
506
508
  ]
507
509
  });
508
510
  }
509
- async function extractMastraOption(name, entryFile, transformer, outputDir, logger) {
511
+ async function extractMastraOption(name, entryFile, outputDir, logger) {
510
512
  const result = {
511
513
  hasCustomConfig: false
512
514
  };
513
- const bundler = await extractMastraOptionBundler(name, entryFile, transformer, result, logger);
515
+ const bundler = await extractMastraOptionBundler(name, entryFile, result, logger);
514
516
  const output = await bundler.write({
515
517
  dir: outputDir,
516
518
  format: "es",
@@ -528,13 +530,7 @@ async function extractMastraOption(name, entryFile, transformer, outputDir, logg
528
530
 
529
531
  // src/build/bundlerOptions.ts
530
532
  async function getBundlerOptions(entryFile, outputDir, logger) {
531
- const result = await extractMastraOption(
532
- "bundler",
533
- entryFile,
534
- removeAllOptionsExceptBundler,
535
- outputDir,
536
- logger
537
- );
533
+ const result = await extractMastraOption("bundler", entryFile, outputDir, logger);
538
534
  if (!result) {
539
535
  return null;
540
536
  }
@@ -578,7 +574,7 @@ async function getWorkspaceInformation({
578
574
  mastraEntryFile
579
575
  }) {
580
576
  const closestPkgJson = pkg__namespace.up({ cwd: path2.dirname(mastraEntryFile) });
581
- const location = closestPkgJson ? path2.dirname(chunk2OTEFUER_cjs.slash(closestPkgJson)) : chunk2OTEFUER_cjs.slash(process.cwd());
577
+ const location = closestPkgJson ? path2.dirname(chunk5TYVF4KJ_cjs.slash(closestPkgJson)) : chunk5TYVF4KJ_cjs.slash(process.cwd());
582
578
  const workspaces = await findWorkspaces.findWorkspaces(dir, { cache: workspacesCache });
583
579
  const _workspaceMap = new Map(
584
580
  workspaces?.map((workspace) => [
@@ -603,8 +599,57 @@ function isNodeBuiltin(dep) {
603
599
  const [pkg2] = dep.split("/");
604
600
  return dep.startsWith("node:") || module$1.builtinModules.includes(dep) || module$1.builtinModules.includes(pkg2);
605
601
  }
602
+ async function getPackageRootPath(packageName, parentPath) {
603
+ let rootPath;
604
+ try {
605
+ let options = void 0;
606
+ if (parentPath) {
607
+ if (!parentPath.startsWith("file://")) {
608
+ parentPath = url.pathToFileURL(parentPath).href;
609
+ }
610
+ options = {
611
+ paths: [parentPath]
612
+ };
613
+ }
614
+ const pkg2 = await localPkg.getPackageInfo(packageName, options);
615
+ rootPath = pkg2?.rootPath ?? null;
616
+ } catch (e) {
617
+ rootPath = null;
618
+ }
619
+ return rootPath;
620
+ }
621
+
622
+ // src/build/analyze/constants.ts
623
+ var DEPS_TO_IGNORE = ["#tools"];
624
+ var GLOBAL_EXTERNALS = [
625
+ "pino",
626
+ "pino-pretty",
627
+ "@libsql/client",
628
+ "pg",
629
+ "libsql",
630
+ "#tools",
631
+ "typescript",
632
+ "undici",
633
+ "readable-stream"
634
+ ];
635
+ var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
606
636
  function removeDeployer() {
607
637
  const t = babel__namespace.default.types;
638
+ function removeDeployerFromObject(objectExpr, scope) {
639
+ const deployerProp = objectExpr.properties.find(
640
+ (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
641
+ );
642
+ if (deployerProp) {
643
+ objectExpr.properties = objectExpr.properties.filter((prop) => prop !== deployerProp);
644
+ if (t.isIdentifier(deployerProp.value)) {
645
+ const deployerBinding = scope.getBinding(deployerProp.value.name);
646
+ if (deployerBinding) {
647
+ deployerBinding.path?.parentPath?.remove();
648
+ }
649
+ }
650
+ }
651
+ return deployerProp;
652
+ }
608
653
  return {
609
654
  name: "remove-deployer",
610
655
  visitor: {
@@ -620,23 +665,30 @@ function removeDeployer() {
620
665
  if (!state.hasReplaced) {
621
666
  state.hasReplaced = true;
622
667
  const newMastraObj = t.cloneNode(path3.node);
623
- if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.[0]) {
624
- const deployer = newMastraObj.arguments[0].properties.find(
625
- (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
626
- );
627
- if (!deployer) {
628
- return;
668
+ if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.length) {
669
+ const objectArg = newMastraObj.arguments[0];
670
+ let foundDeployer = false;
671
+ const directDeployer = removeDeployerFromObject(objectArg, state.file.scope);
672
+ if (directDeployer) {
673
+ foundDeployer = true;
629
674
  }
630
- newMastraObj.arguments[0].properties = newMastraObj.arguments[0].properties.filter(
631
- (prop) => prop !== deployer
632
- );
633
- if (t.isObjectProperty(deployer) && t.isIdentifier(deployer.value)) {
634
- const deployerBinding = state.file.scope.getBinding(deployer.value.name);
635
- if (deployerBinding) {
636
- deployerBinding?.path?.parentPath?.remove();
675
+ for (const prop of objectArg.properties) {
676
+ if (t.isSpreadElement(prop) && t.isIdentifier(prop.argument)) {
677
+ const spreadBinding = state.file.scope.getBinding(prop.argument.name);
678
+ if (spreadBinding?.path && t.isVariableDeclarator(spreadBinding.path.node)) {
679
+ const init = spreadBinding.path.node.init;
680
+ if (t.isObjectExpression(init)) {
681
+ const spreadDeployer = removeDeployerFromObject(init, state.file.scope);
682
+ if (spreadDeployer) {
683
+ foundDeployer = true;
684
+ }
685
+ }
686
+ }
637
687
  }
638
688
  }
639
- path3.replaceWith(newMastraObj);
689
+ if (foundDeployer) {
690
+ path3.replaceWith(newMastraObj);
691
+ }
640
692
  }
641
693
  }
642
694
  }
@@ -677,24 +729,9 @@ function removeDeployer2(mastraEntry, options) {
677
729
  };
678
730
  }
679
731
 
680
- // src/build/analyze/constants.ts
681
- var DEPS_TO_IGNORE = ["#tools"];
682
- var GLOBAL_EXTERNALS = [
683
- "pino",
684
- "pino-pretty",
685
- "@libsql/client",
686
- "pg",
687
- "libsql",
688
- "#tools",
689
- "typescript",
690
- "undici",
691
- "readable-stream"
692
- ];
693
- var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
694
-
695
732
  // src/build/analyze/analyzeEntry.ts
696
733
  function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
697
- const normalizedMastraEntry = chunk2OTEFUER_cjs.slash(mastraEntry);
734
+ const normalizedMastraEntry = chunk5TYVF4KJ_cjs.slash(mastraEntry);
698
735
  let virtualPlugin = null;
699
736
  if (isVirtualFile) {
700
737
  virtualPlugin = virtual__default.default({
@@ -713,7 +750,7 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
713
750
  name: "custom-alias-resolver",
714
751
  resolveId(id) {
715
752
  if (id === "#server") {
716
- return chunk2OTEFUER_cjs.slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
753
+ return chunk5TYVF4KJ_cjs.slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
717
754
  }
718
755
  if (id === "#mastra") {
719
756
  return normalizedMastraEntry;
@@ -731,7 +768,9 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
731
768
  transformMixedEsModules: true,
732
769
  extensions: [".js", ".ts"]
733
770
  }),
734
- removeDeployer2(mastraEntry, { sourcemap: sourcemapEnabled }),
771
+ removeDeployer2(mastraEntry, {
772
+ sourcemap: sourcemapEnabled
773
+ }),
735
774
  esbuild()
736
775
  ]
737
776
  );
@@ -749,20 +788,20 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
749
788
  }
750
789
  let entryRootPath = projectRoot;
751
790
  if (!output.facadeModuleId.startsWith("\0virtual:")) {
752
- entryRootPath = await chunk2OTEFUER_cjs.getPackageRootPath(output.facadeModuleId) || projectRoot;
791
+ entryRootPath = await getPackageRootPath(output.facadeModuleId) || projectRoot;
753
792
  }
754
793
  for (const [dependency, bindings] of Object.entries(output.importedBindings)) {
755
794
  if (isNodeBuiltin(dependency) || dependency.startsWith("#")) {
756
795
  continue;
757
796
  }
758
- const pkgName = chunk2OTEFUER_cjs.getPackageName(dependency);
797
+ const pkgName = chunk5TYVF4KJ_cjs.getPackageName(dependency);
759
798
  let rootPath = null;
760
799
  let isWorkspace = false;
761
800
  if (pkgName) {
762
- rootPath = await chunk2OTEFUER_cjs.getPackageRootPath(dependency, entryRootPath);
801
+ rootPath = await getPackageRootPath(dependency, entryRootPath);
763
802
  isWorkspace = workspaceMap.has(pkgName);
764
803
  }
765
- const normalizedRootPath = rootPath ? chunk2OTEFUER_cjs.slash(rootPath) : null;
804
+ const normalizedRootPath = rootPath ? chunk5TYVF4KJ_cjs.slash(rootPath) : null;
766
805
  depsToOptimize.set(dependency, {
767
806
  exports: bindings,
768
807
  rootPath: normalizedRootPath,
@@ -959,7 +998,7 @@ function subpathExternalsResolver(externals) {
959
998
  if (id.startsWith(".") || id.startsWith("/")) {
960
999
  return null;
961
1000
  }
962
- const isPartOfExternals = externals.some((external) => chunk2OTEFUER_cjs.isDependencyPartOfPackage(id, external));
1001
+ const isPartOfExternals = externals.some((external) => chunk5TYVF4KJ_cjs.isDependencyPartOfPackage(id, external));
963
1002
  if (isPartOfExternals) {
964
1003
  return {
965
1004
  id,
@@ -979,7 +1018,7 @@ function moduleResolveMap(externals, projectRoot) {
979
1018
  }
980
1019
  for (const importedId of info.importedIds) {
981
1020
  for (const external of externals) {
982
- if (chunk2OTEFUER_cjs.isDependencyPartOfPackage(importedId, external)) {
1021
+ if (chunk5TYVF4KJ_cjs.isDependencyPartOfPackage(importedId, external)) {
983
1022
  importMap.set(external, info.id);
984
1023
  }
985
1024
  }
@@ -991,9 +1030,9 @@ function moduleResolveMap(externals, projectRoot) {
991
1030
  if (chunk.type === "chunk") {
992
1031
  for (const [external, resolvedFrom] of importMap) {
993
1032
  if (chunk.moduleIds.includes(resolvedFrom)) {
994
- const fullPath = url.pathToFileURL(chunk2OTEFUER_cjs.slash(path2.join(projectRoot, fileName))).toString();
1033
+ const fullPath = url.pathToFileURL(chunk5TYVF4KJ_cjs.slash(path2.join(projectRoot, fileName))).toString();
995
1034
  const innerMap = resolveMap.get(fullPath) || /* @__PURE__ */ new Map();
996
- innerMap.set(external, url.pathToFileURL(chunk2OTEFUER_cjs.slash(resolvedFrom)).toString());
1035
+ innerMap.set(external, url.pathToFileURL(chunk5TYVF4KJ_cjs.slash(resolvedFrom)).toString());
997
1036
  resolveMap.set(fullPath, innerMap);
998
1037
  }
999
1038
  }
@@ -1013,7 +1052,7 @@ function moduleResolveMap(externals, projectRoot) {
1013
1052
 
1014
1053
  // src/build/analyze/bundleExternals.ts
1015
1054
  function prepareEntryFileName(name, rootDir) {
1016
- return chunk2OTEFUER_cjs.rollupSafeName(name, rootDir);
1055
+ return chunk5TYVF4KJ_cjs.rollupSafeName(name, rootDir);
1017
1056
  }
1018
1057
  function createVirtualDependencies(depsToOptimize, {
1019
1058
  projectRoot,
@@ -1021,7 +1060,7 @@ function createVirtualDependencies(depsToOptimize, {
1021
1060
  outputDir,
1022
1061
  bundlerOptions
1023
1062
  }) {
1024
- const { isDev = false } = bundlerOptions || {};
1063
+ const { isDev = false, externalsPreset = false } = bundlerOptions || {};
1025
1064
  const fileNameToDependencyMap = /* @__PURE__ */ new Map();
1026
1065
  const optimizedDependencyEntries = /* @__PURE__ */ new Map();
1027
1066
  const rootDir = workspaceRoot || projectRoot;
@@ -1053,7 +1092,7 @@ function createVirtualDependencies(depsToOptimize, {
1053
1092
  virtual: virtualFile.join("\n")
1054
1093
  });
1055
1094
  }
1056
- if (isDev) {
1095
+ if (isDev || externalsPreset) {
1057
1096
  for (const [dep, { isWorkspace, rootPath }] of depsToOptimize.entries()) {
1058
1097
  if (!isWorkspace || !rootPath || !workspaceRoot) {
1059
1098
  continue;
@@ -1063,7 +1102,7 @@ function createVirtualDependencies(depsToOptimize, {
1063
1102
  continue;
1064
1103
  }
1065
1104
  const fileName = posix.basename(currentDepPath.name);
1066
- const entryName = prepareEntryFileName(chunk2OTEFUER_cjs.getCompiledDepCachePath(rootPath, fileName), rootDir);
1105
+ const entryName = prepareEntryFileName(chunk5TYVF4KJ_cjs.getCompiledDepCachePath(rootPath, fileName), rootDir);
1067
1106
  fileNameToDependencyMap.set(entryName, dep);
1068
1107
  optimizedDependencyEntries.set(dep, {
1069
1108
  ...currentDepPath,
@@ -1082,9 +1121,9 @@ async function getInputPlugins2(virtualDependencies, {
1082
1121
  }) {
1083
1122
  const transpilePackagesMap = /* @__PURE__ */ new Map();
1084
1123
  for (const pkg2 of transpilePackages) {
1085
- const dir = await chunk2OTEFUER_cjs.getPackageRootPath(pkg2);
1124
+ const dir = await getPackageRootPath(pkg2);
1086
1125
  if (dir) {
1087
- transpilePackagesMap.set(pkg2, chunk2OTEFUER_cjs.slash(dir));
1126
+ transpilePackagesMap.set(pkg2, chunk5TYVF4KJ_cjs.slash(dir));
1088
1127
  } else {
1089
1128
  transpilePackagesMap.set(pkg2, workspaceMap.get(pkg2)?.location ?? pkg2);
1090
1129
  }
@@ -1110,7 +1149,7 @@ async function getInputPlugins2(virtualDependencies, {
1110
1149
  }
1111
1150
  })
1112
1151
  }) : null,
1113
- bundlerOptions.isDev ? {
1152
+ bundlerOptions.noBundling ? {
1114
1153
  name: "alias-optimized-deps",
1115
1154
  async resolveId(id, importer, options) {
1116
1155
  if (!virtualDependencies.has(id)) {
@@ -1140,11 +1179,11 @@ async function getInputPlugins2(virtualDependencies, {
1140
1179
  transformMixedEsModules: true,
1141
1180
  ignoreTryCatch: false
1142
1181
  }),
1143
- bundlerOptions.isDev ? null : nodeResolve__default.default({
1182
+ bundlerOptions.noBundling ? null : nodeResolve__default.default({
1144
1183
  preferBuiltins: true,
1145
1184
  exportConditions: ["node"]
1146
1185
  }),
1147
- bundlerOptions.isDev ? esmShim() : null,
1186
+ bundlerOptions.noBundling ? esmShim() : null,
1148
1187
  // hono is imported from deployer, so we need to resolve from here instead of the project root
1149
1188
  aliasHono(),
1150
1189
  json__default.default(),
@@ -1197,6 +1236,16 @@ async function buildExternalDependencies(virtualDependencies, {
1197
1236
  if (virtualDependencies.size === 0) {
1198
1237
  return [];
1199
1238
  }
1239
+ const noBundling = bundlerOptions.isDev || bundlerOptions.externalsPreset;
1240
+ const plugins = await getInputPlugins2(virtualDependencies, {
1241
+ transpilePackages: packagesToTranspile,
1242
+ workspaceMap,
1243
+ bundlerOptions: {
1244
+ noBundling
1245
+ },
1246
+ rootDir,
1247
+ externals
1248
+ });
1200
1249
  const bundler = await rollup.rollup({
1201
1250
  logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
1202
1251
  input: Array.from(virtualDependencies.entries()).reduce(
@@ -1207,14 +1256,8 @@ async function buildExternalDependencies(virtualDependencies, {
1207
1256
  {}
1208
1257
  ),
1209
1258
  external: externals,
1210
- treeshake: bundlerOptions.isDev ? false : "safest",
1211
- plugins: getInputPlugins2(virtualDependencies, {
1212
- transpilePackages: packagesToTranspile,
1213
- workspaceMap,
1214
- bundlerOptions,
1215
- rootDir,
1216
- externals
1217
- })
1259
+ treeshake: noBundling ? false : "safest",
1260
+ plugins
1218
1261
  });
1219
1262
  const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
1220
1263
  const { output } = await bundler.write({
@@ -1228,12 +1271,12 @@ async function buildExternalDependencies(virtualDependencies, {
1228
1271
  * So we want to write them to the `.mastra/output` folder as well.
1229
1272
  */
1230
1273
  chunkFileNames: (chunkInfo) => {
1231
- if (bundlerOptions.isDev) {
1274
+ if (noBundling) {
1232
1275
  const importedFromPackages = /* @__PURE__ */ new Set();
1233
1276
  for (const moduleId of chunkInfo.moduleIds) {
1234
- const normalized = chunk2OTEFUER_cjs.slash(moduleId);
1277
+ const normalized = chunk5TYVF4KJ_cjs.slash(moduleId);
1235
1278
  for (const [pkgName, pkgInfo] of workspaceMap.entries()) {
1236
- const location = chunk2OTEFUER_cjs.slash(pkgInfo.location);
1279
+ const location = chunk5TYVF4KJ_cjs.slash(pkgInfo.location);
1237
1280
  if (normalized.startsWith(location)) {
1238
1281
  importedFromPackages.add(pkgName);
1239
1282
  break;
@@ -1255,7 +1298,7 @@ async function buildExternalDependencies(virtualDependencies, {
1255
1298
  if (importedFromPackages.size === 1) {
1256
1299
  const [pkgName] = importedFromPackages;
1257
1300
  const workspaceLocation = workspaceMap.get(pkgName).location;
1258
- return prepareEntryFileName(chunk2OTEFUER_cjs.getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
1301
+ return prepareEntryFileName(chunk5TYVF4KJ_cjs.getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
1259
1302
  }
1260
1303
  }
1261
1304
  return `${outputDirRelative}/[name].mjs`;
@@ -1269,7 +1312,7 @@ async function buildExternalDependencies(virtualDependencies, {
1269
1312
  function findExternalImporter(module, external, allOutputs) {
1270
1313
  const capturedFiles = /* @__PURE__ */ new Set();
1271
1314
  for (const id of module.imports) {
1272
- if (chunk2OTEFUER_cjs.isDependencyPartOfPackage(id, external)) {
1315
+ if (chunk5TYVF4KJ_cjs.isDependencyPartOfPackage(id, external)) {
1273
1316
  return module;
1274
1317
  } else {
1275
1318
  if (id.endsWith(".mjs")) {
@@ -1290,19 +1333,31 @@ function findExternalImporter(module, external, allOutputs) {
1290
1333
  }
1291
1334
  async function bundleExternals(depsToOptimize, outputDir, options) {
1292
1335
  const { workspaceRoot = null, workspaceMap = /* @__PURE__ */ new Map(), projectRoot = outputDir, bundlerOptions = {} } = options;
1293
- const {
1294
- externals: customExternals = [],
1295
- transpilePackages = [],
1296
- isDev = false} = bundlerOptions || {};
1297
- const allExternals = [...GLOBAL_EXTERNALS, ...DEPRECATED_EXTERNALS, ...customExternals];
1336
+ const { externals: customExternals = [], transpilePackages = [], isDev = false } = bundlerOptions || {};
1337
+ let externalsPreset = false;
1338
+ if (customExternals === true) {
1339
+ externalsPreset = true;
1340
+ }
1341
+ const externalsList = Array.isArray(customExternals) ? customExternals : [];
1342
+ const allExternals = [...GLOBAL_EXTERNALS, ...DEPRECATED_EXTERNALS, ...externalsList];
1298
1343
  const workspacePackagesNames = Array.from(workspaceMap.keys());
1299
1344
  const packagesToTranspile = /* @__PURE__ */ new Set([...transpilePackages, ...workspacePackagesNames]);
1345
+ const extractedExternals = /* @__PURE__ */ new Map();
1346
+ if (externalsPreset) {
1347
+ for (const [dep, metadata] of depsToOptimize.entries()) {
1348
+ if (!metadata.isWorkspace) {
1349
+ extractedExternals.set(dep, metadata.rootPath ?? dep);
1350
+ depsToOptimize.delete(dep);
1351
+ }
1352
+ }
1353
+ }
1300
1354
  const { optimizedDependencyEntries, fileNameToDependencyMap } = createVirtualDependencies(depsToOptimize, {
1301
1355
  workspaceRoot,
1302
1356
  outputDir,
1303
1357
  projectRoot,
1304
1358
  bundlerOptions: {
1305
- isDev
1359
+ isDev,
1360
+ externalsPreset
1306
1361
  }
1307
1362
  });
1308
1363
  const output = await buildExternalDependencies(optimizedDependencyEntries, {
@@ -1312,7 +1367,8 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
1312
1367
  rootDir: workspaceRoot || projectRoot,
1313
1368
  outputDir,
1314
1369
  bundlerOptions: {
1315
- isDev
1370
+ isDev,
1371
+ externalsPreset
1316
1372
  }
1317
1373
  });
1318
1374
  const moduleResolveMap2 = /* @__PURE__ */ new Map();
@@ -1347,6 +1403,14 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
1347
1403
  }
1348
1404
  usedExternals[fullPath] = innerObj;
1349
1405
  }
1406
+ if (extractedExternals.size > 0) {
1407
+ const syntheticPath = path2__namespace.join(workspaceRoot || projectRoot, "__externals__");
1408
+ const externalsObj = /* @__PURE__ */ Object.create(null);
1409
+ for (const [dep, rootPath] of extractedExternals) {
1410
+ externalsObj[dep] = rootPath;
1411
+ }
1412
+ usedExternals[syntheticPath] = externalsObj;
1413
+ }
1350
1414
  return { output, fileNameToDependencyMap, usedExternals };
1351
1415
  }
1352
1416
 
@@ -1622,7 +1686,7 @@ async function analyzeBundle(entries, mastraEntry, {
1622
1686
  outputDir,
1623
1687
  projectRoot,
1624
1688
  isDev = false,
1625
- bundlerOptions: _bundlerOptions
1689
+ bundlerOptions
1626
1690
  }, logger) {
1627
1691
  const mastraConfig = await promises.readFile(mastraEntry, "utf-8");
1628
1692
  const mastraConfigResult = {
@@ -1641,28 +1705,30 @@ export const mastra = new Mastra({
1641
1705
 
1642
1706
  If you think your configuration is valid, please open an issue.`);
1643
1707
  }
1644
- const { enableEsmShim = true } = _bundlerOptions || {};
1645
- const bundlerOptions = await getBundlerOptions(mastraEntry, outputDir);
1646
1708
  const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
1709
+ let externalsPreset = false;
1710
+ const userExternals = Array.isArray(bundlerOptions?.externals) ? bundlerOptions?.externals : [];
1711
+ if (bundlerOptions?.externals === true) {
1712
+ externalsPreset = true;
1713
+ }
1647
1714
  let index = 0;
1648
1715
  const depsToOptimize = /* @__PURE__ */ new Map();
1649
- const { externals: customExternals = [] } = bundlerOptions || {};
1650
- const allExternals = [...GLOBAL_EXTERNALS, ...customExternals];
1716
+ const allExternals = [...GLOBAL_EXTERNALS, ...userExternals].filter(Boolean);
1651
1717
  logger.info("Analyzing dependencies...");
1652
1718
  const allUsedExternals = /* @__PURE__ */ new Set();
1653
1719
  for (const entry of entries) {
1654
1720
  const isVirtualFile = entry.includes("\n") || !fs.existsSync(entry);
1655
1721
  const analyzeResult = await analyzeEntry({ entry, isVirtualFile }, mastraEntry, {
1656
1722
  logger,
1657
- sourcemapEnabled: bundlerOptions?.sourcemap ?? false,
1723
+ sourcemapEnabled: bundlerOptions?.enableSourcemap ?? false,
1658
1724
  workspaceMap,
1659
1725
  projectRoot,
1660
- shouldCheckTransitiveDependencies: isDev
1726
+ shouldCheckTransitiveDependencies: isDev || externalsPreset
1661
1727
  });
1662
1728
  await promises.writeFile(path2.join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
1663
1729
  for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
1664
- const isPartOfExternals = allExternals.some((external) => chunk2OTEFUER_cjs.isDependencyPartOfPackage(dep, external));
1665
- if (isPartOfExternals) {
1730
+ const isPartOfExternals = allExternals.some((external) => chunk5TYVF4KJ_cjs.isDependencyPartOfPackage(dep, external));
1731
+ if (isPartOfExternals || externalsPreset && !metadata.isWorkspace) {
1666
1732
  allUsedExternals.add(dep);
1667
1733
  continue;
1668
1734
  }
@@ -1677,7 +1743,7 @@ If you think your configuration is valid, please open an issue.`);
1677
1743
  }
1678
1744
  }
1679
1745
  }
1680
- if (isDev) {
1746
+ if (isDev || externalsPreset) {
1681
1747
  for (const [dep, metadata] of depsToOptimize.entries()) {
1682
1748
  if (!metadata.isWorkspace) {
1683
1749
  depsToOptimize.delete(dep);
@@ -1690,14 +1756,36 @@ If you think your configuration is valid, please open an issue.`);
1690
1756
  const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
1691
1757
  bundlerOptions: {
1692
1758
  ...bundlerOptions,
1693
- externals: allExternals,
1694
- enableEsmShim,
1759
+ externals: bundlerOptions?.externals ?? allExternals,
1695
1760
  isDev
1696
1761
  },
1697
1762
  projectRoot,
1698
1763
  workspaceRoot,
1699
1764
  workspaceMap
1700
1765
  });
1766
+ const relativeWorkspaceFolderPaths = Array.from(workspaceMap.values()).map(
1767
+ (pkgInfo) => path2.relative(workspaceRoot || projectRoot, pkgInfo.location)
1768
+ );
1769
+ for (const o of output) {
1770
+ if (o.type === "asset") {
1771
+ continue;
1772
+ }
1773
+ for (const i of o.imports) {
1774
+ if (chunk5TYVF4KJ_cjs.isBuiltinModule(i)) {
1775
+ continue;
1776
+ }
1777
+ if (i.startsWith(".") || i.startsWith("/")) {
1778
+ continue;
1779
+ }
1780
+ if (relativeWorkspaceFolderPaths.some((workspacePath) => i.startsWith(workspacePath))) {
1781
+ continue;
1782
+ }
1783
+ const pkgName = chunk5TYVF4KJ_cjs.getPackageName(i);
1784
+ if (pkgName) {
1785
+ allUsedExternals.add(pkgName);
1786
+ }
1787
+ }
1788
+ }
1701
1789
  const result = await validateOutput(
1702
1790
  {
1703
1791
  output,
@@ -1721,10 +1809,10 @@ exports.esbuild = esbuild;
1721
1809
  exports.esmShim = esmShim;
1722
1810
  exports.extractMastraOption = extractMastraOption;
1723
1811
  exports.getBundlerOptions = getBundlerOptions;
1812
+ exports.getPackageRootPath = getPackageRootPath;
1724
1813
  exports.getWorkspaceInformation = getWorkspaceInformation;
1725
- exports.removeAllOptionsFromMastraExcept = removeAllOptionsFromMastraExcept;
1726
1814
  exports.removeDeployer = removeDeployer2;
1727
1815
  exports.subpathExternalsResolver = subpathExternalsResolver;
1728
1816
  exports.tsConfigPaths = tsConfigPaths;
1729
- //# sourceMappingURL=chunk-MUWNMVNL.cjs.map
1730
- //# sourceMappingURL=chunk-MUWNMVNL.cjs.map
1817
+ //# sourceMappingURL=chunk-T7NCLSYN.cjs.map
1818
+ //# sourceMappingURL=chunk-T7NCLSYN.cjs.map