@mastra/deployer 0.0.0-error-handler-fix-20251020202607 → 0.0.0-execa-dynamic-import-20260304221256

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 (283) hide show
  1. package/CHANGELOG.md +1850 -5
  2. package/LICENSE.md +15 -0
  3. package/dist/arktype-aI7TBD0R-MD6ESOAI.js +8 -0
  4. package/dist/arktype-aI7TBD0R-MD6ESOAI.js.map +1 -0
  5. package/dist/arktype-aI7TBD0R-MS2OLT4Z.cjs +10 -0
  6. package/dist/arktype-aI7TBD0R-MS2OLT4Z.cjs.map +1 -0
  7. package/dist/build/analyze/analyzeEntry.d.ts +8 -4
  8. package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
  9. package/dist/build/analyze/bundleExternals.d.ts +8 -7
  10. package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
  11. package/dist/build/analyze/constants.d.ts.map +1 -1
  12. package/dist/build/analyze.cjs +2 -2
  13. package/dist/build/analyze.d.ts +7 -7
  14. package/dist/build/analyze.d.ts.map +1 -1
  15. package/dist/build/analyze.js +1 -1
  16. package/dist/build/babel/remove-all-options-except.d.ts +1 -1
  17. package/dist/build/babel/remove-all-options-except.d.ts.map +1 -1
  18. package/dist/build/babel/remove-deployer.d.ts.map +1 -1
  19. package/dist/build/bundler.cjs +3 -3
  20. package/dist/build/bundler.d.ts +5 -3
  21. package/dist/build/bundler.d.ts.map +1 -1
  22. package/dist/build/bundler.js +1 -1
  23. package/dist/build/bundlerOptions.d.ts +1 -1
  24. package/dist/build/bundlerOptions.d.ts.map +1 -1
  25. package/dist/build/deployer.d.ts +1 -1
  26. package/dist/build/deployer.d.ts.map +1 -1
  27. package/dist/build/index.cjs +31 -22
  28. package/dist/build/index.d.ts +2 -1
  29. package/dist/build/index.d.ts.map +1 -1
  30. package/dist/build/index.js +6 -5
  31. package/dist/build/package-info.d.ts +9 -0
  32. package/dist/build/package-info.d.ts.map +1 -0
  33. package/dist/build/plugins/esm-shim.d.ts +14 -0
  34. package/dist/build/plugins/esm-shim.d.ts.map +1 -0
  35. package/dist/build/plugins/module-resolve-map.d.ts +3 -0
  36. package/dist/build/plugins/module-resolve-map.d.ts.map +1 -0
  37. package/dist/build/plugins/node-gyp-detector.d.ts +3 -0
  38. package/dist/build/plugins/node-gyp-detector.d.ts.map +1 -0
  39. package/dist/build/plugins/node-modules-extension-resolver.d.ts +7 -0
  40. package/dist/build/plugins/node-modules-extension-resolver.d.ts.map +1 -1
  41. package/dist/build/plugins/pino.d.ts.map +1 -1
  42. package/dist/build/plugins/remove-all-except.d.ts +10 -0
  43. package/dist/build/plugins/remove-all-except.d.ts.map +1 -0
  44. package/dist/build/plugins/subpath-externals-resolver.d.ts +3 -0
  45. package/dist/build/plugins/subpath-externals-resolver.d.ts.map +1 -0
  46. package/dist/build/plugins/tsconfig-paths.d.ts +8 -0
  47. package/dist/build/plugins/tsconfig-paths.d.ts.map +1 -1
  48. package/dist/build/serverOptions.d.ts +1 -1
  49. package/dist/build/serverOptions.d.ts.map +1 -1
  50. package/dist/build/shared/extract-mastra-option.d.ts +5 -9
  51. package/dist/build/shared/extract-mastra-option.d.ts.map +1 -1
  52. package/dist/build/types.d.ts +18 -0
  53. package/dist/build/types.d.ts.map +1 -1
  54. package/dist/build/utils.d.ts +79 -4
  55. package/dist/build/utils.d.ts.map +1 -1
  56. package/dist/build/watcher.d.ts +4 -1
  57. package/dist/build/watcher.d.ts.map +1 -1
  58. package/dist/bundler/index.cjs +6 -2
  59. package/dist/bundler/index.d.ts +13 -10
  60. package/dist/bundler/index.d.ts.map +1 -1
  61. package/dist/bundler/index.js +1 -1
  62. package/dist/chunk-32UHMKRP.cjs +95 -0
  63. package/dist/chunk-32UHMKRP.cjs.map +1 -0
  64. package/dist/chunk-6UIXBIO6.js +1322 -0
  65. package/dist/chunk-6UIXBIO6.js.map +1 -0
  66. package/dist/chunk-73SEUI3W.cjs +1353 -0
  67. package/dist/chunk-73SEUI3W.cjs.map +1 -0
  68. package/dist/chunk-ANF3UFZ3.js +318 -0
  69. package/dist/chunk-ANF3UFZ3.js.map +1 -0
  70. package/dist/{chunk-5QFG6SCM.js → chunk-DPDWM7HQ.js} +2 -2
  71. package/dist/chunk-DPDWM7HQ.js.map +1 -0
  72. package/dist/chunk-EBHDMP6N.cjs +122 -0
  73. package/dist/chunk-EBHDMP6N.cjs.map +1 -0
  74. package/dist/{chunk-WAWEQ3DP.js → chunk-EZBW45SX.js} +72 -32
  75. package/dist/chunk-EZBW45SX.js.map +1 -0
  76. package/dist/chunk-G7R456H2.cjs +108 -0
  77. package/dist/chunk-G7R456H2.cjs.map +1 -0
  78. package/dist/chunk-IMLDKOVJ.js +98 -0
  79. package/dist/chunk-IMLDKOVJ.js.map +1 -0
  80. package/dist/chunk-JNSGICDP.js +159 -0
  81. package/dist/chunk-JNSGICDP.js.map +1 -0
  82. package/dist/{chunk-3JYRSECU.cjs → chunk-JVBCN3RH.cjs} +4 -4
  83. package/dist/chunk-JVBCN3RH.cjs.map +1 -0
  84. package/dist/{chunk-LGC3GUMR.cjs → chunk-MEHKYO3L.cjs} +89 -153
  85. package/dist/chunk-MEHKYO3L.cjs.map +1 -0
  86. package/dist/chunk-NQTC7BHX.cjs +4 -0
  87. package/dist/chunk-NQTC7BHX.cjs.map +1 -0
  88. package/dist/chunk-O73YCD6A.js +262 -0
  89. package/dist/chunk-O73YCD6A.js.map +1 -0
  90. package/dist/chunk-PF6MO6L3.cjs +162 -0
  91. package/dist/chunk-PF6MO6L3.cjs.map +1 -0
  92. package/dist/{chunk-HMMDNIEQ.cjs → chunk-R2SYO6PH.cjs} +79 -39
  93. package/dist/chunk-R2SYO6PH.cjs.map +1 -0
  94. package/dist/chunk-TFSGAJE4.cjs +16 -0
  95. package/dist/chunk-TFSGAJE4.cjs.map +1 -0
  96. package/dist/chunk-UCL7MHBL.js +93 -0
  97. package/dist/chunk-UCL7MHBL.js.map +1 -0
  98. package/dist/chunk-UPVHAZ5Q.cjs +288 -0
  99. package/dist/chunk-UPVHAZ5Q.cjs.map +1 -0
  100. package/dist/chunk-UQZFTY5Q.cjs +8 -0
  101. package/dist/chunk-UQZFTY5Q.cjs.map +1 -0
  102. package/dist/{chunk-465ZVXAK.js → chunk-USX4L64H.js} +83 -146
  103. package/dist/chunk-USX4L64H.js.map +1 -0
  104. package/dist/chunk-V3HWDUN7.js +6 -0
  105. package/dist/chunk-V3HWDUN7.js.map +1 -0
  106. package/dist/chunk-WGU72NH4.js +14 -0
  107. package/dist/chunk-WGU72NH4.js.map +1 -0
  108. package/dist/chunk-XN3FKMO6.js +97 -0
  109. package/dist/chunk-XN3FKMO6.js.map +1 -0
  110. package/dist/chunk-YEOQZ6LM.js +3 -0
  111. package/dist/chunk-YEOQZ6LM.js.map +1 -0
  112. package/dist/chunk-YIUDHDPS.cjs +351 -0
  113. package/dist/chunk-YIUDHDPS.cjs.map +1 -0
  114. package/dist/default-u_dwuiYb-BOJNVDPF.js +3 -0
  115. package/dist/default-u_dwuiYb-BOJNVDPF.js.map +1 -0
  116. package/dist/default-u_dwuiYb-HYOFMURU.cjs +9 -0
  117. package/dist/default-u_dwuiYb-HYOFMURU.cjs.map +1 -0
  118. package/dist/deploy/log.d.ts +1 -1
  119. package/dist/deploy/log.d.ts.map +1 -1
  120. package/dist/docs/SKILL.md +31 -0
  121. package/dist/docs/assets/SOURCE_MAP.json +27 -0
  122. package/dist/docs/references/docs-deployment-cloud-providers.md +15 -0
  123. package/dist/docs/references/docs-deployment-mastra-server.md +122 -0
  124. package/dist/docs/references/docs-deployment-monorepo.md +142 -0
  125. package/dist/docs/references/docs-deployment-overview.md +62 -0
  126. package/dist/docs/references/docs-deployment-web-framework.md +52 -0
  127. package/dist/docs/references/docs-deployment-workflow-runners.md +9 -0
  128. package/dist/docs/references/reference-deployer.md +100 -0
  129. package/dist/effect-QlVUlMFu-FWNF43NY.cjs +17 -0
  130. package/dist/effect-QlVUlMFu-FWNF43NY.cjs.map +1 -0
  131. package/dist/effect-QlVUlMFu-UDX7FFQO.js +15 -0
  132. package/dist/effect-QlVUlMFu-UDX7FFQO.js.map +1 -0
  133. package/dist/esm-6PM2YB3Y.cjs +1336 -0
  134. package/dist/esm-6PM2YB3Y.cjs.map +1 -0
  135. package/dist/esm-CAB7GAHT.js +1289 -0
  136. package/dist/esm-CAB7GAHT.js.map +1 -0
  137. package/dist/index.cjs +11 -22
  138. package/dist/index.cjs.map +1 -1
  139. package/dist/index.js +5 -16
  140. package/dist/index.js.map +1 -1
  141. package/dist/server/handlers/a2a.d.ts +1 -1
  142. package/dist/server/handlers/health.d.ts +5 -0
  143. package/dist/server/handlers/health.d.ts.map +1 -0
  144. package/dist/server/handlers/restart-active-runs.d.ts +3 -0
  145. package/dist/server/handlers/restart-active-runs.d.ts.map +1 -0
  146. package/dist/server/handlers/utils/query-parsers.d.ts +15 -0
  147. package/dist/server/handlers/utils/query-parsers.d.ts.map +1 -1
  148. package/dist/server/handlers/utils.d.ts +0 -7
  149. package/dist/server/handlers/utils.d.ts.map +1 -1
  150. package/dist/server/index.cjs +2983 -10849
  151. package/dist/server/index.cjs.map +1 -1
  152. package/dist/server/index.d.ts +3 -12
  153. package/dist/server/index.d.ts.map +1 -1
  154. package/dist/server/index.js +2983 -10850
  155. package/dist/server/index.js.map +1 -1
  156. package/dist/server/types.d.ts +1 -1
  157. package/dist/server/types.d.ts.map +1 -1
  158. package/dist/server/welcome.d.ts +1 -1
  159. package/dist/server/welcome.d.ts.map +1 -1
  160. package/dist/services/index.cjs +4 -4
  161. package/dist/services/index.js +1 -1
  162. package/dist/sury-CWZTCd75-2U3FQUNZ.cjs +17 -0
  163. package/dist/sury-CWZTCd75-2U3FQUNZ.cjs.map +1 -0
  164. package/dist/sury-CWZTCd75-52HHC6OD.js +15 -0
  165. package/dist/sury-CWZTCd75-52HHC6OD.js.map +1 -0
  166. package/dist/typebox-Dei93FPO-EBJ4ULZC.cjs +10 -0
  167. package/dist/typebox-Dei93FPO-EBJ4ULZC.cjs.map +1 -0
  168. package/dist/typebox-Dei93FPO-TURR2FV5.js +8 -0
  169. package/dist/typebox-Dei93FPO-TURR2FV5.js.map +1 -0
  170. package/dist/valibot--1zFm7rT-KH26NMFX.cjs +17 -0
  171. package/dist/valibot--1zFm7rT-KH26NMFX.cjs.map +1 -0
  172. package/dist/valibot--1zFm7rT-O4VBDBTD.js +15 -0
  173. package/dist/valibot--1zFm7rT-O4VBDBTD.js.map +1 -0
  174. package/dist/valibot-D_HTw1Gn-EVIH6VOI.js +43 -0
  175. package/dist/valibot-D_HTw1Gn-EVIH6VOI.js.map +1 -0
  176. package/dist/valibot-D_HTw1Gn-YHTB53Q2.cjs +45 -0
  177. package/dist/valibot-D_HTw1Gn-YHTB53Q2.cjs.map +1 -0
  178. package/dist/validator/custom-resolver.cjs +46 -12
  179. package/dist/validator/custom-resolver.cjs.map +1 -1
  180. package/dist/validator/custom-resolver.d.ts +15 -1
  181. package/dist/validator/custom-resolver.d.ts.map +1 -1
  182. package/dist/validator/custom-resolver.js +44 -11
  183. package/dist/validator/custom-resolver.js.map +1 -1
  184. package/dist/validator/validate.d.ts +16 -1
  185. package/dist/validator/validate.d.ts.map +1 -1
  186. package/dist/zod-Bwrt9trS-SFESLKHY.cjs +31 -0
  187. package/dist/zod-Bwrt9trS-SFESLKHY.cjs.map +1 -0
  188. package/dist/zod-Bwrt9trS-UDJPKIQS.js +29 -0
  189. package/dist/zod-Bwrt9trS-UDJPKIQS.js.map +1 -0
  190. package/dist/zod-DSgpEGAE-3CP5FXLX.cjs +39 -0
  191. package/dist/zod-DSgpEGAE-3CP5FXLX.cjs.map +1 -0
  192. package/dist/zod-DSgpEGAE-EQI5QBJK.js +37 -0
  193. package/dist/zod-DSgpEGAE-EQI5QBJK.js.map +1 -0
  194. package/package.json +34 -35
  195. package/dist/build/babel/get-deployer.d.ts +0 -3
  196. package/dist/build/babel/get-deployer.d.ts.map +0 -1
  197. package/dist/build/babel/remove-all-options-bundler.d.ts +0 -5
  198. package/dist/build/babel/remove-all-options-bundler.d.ts.map +0 -1
  199. package/dist/build/babel/remove-all-options-deployer.d.ts +0 -5
  200. package/dist/build/babel/remove-all-options-deployer.d.ts.map +0 -1
  201. package/dist/build/babel/remove-all-options-server.d.ts +0 -5
  202. package/dist/build/babel/remove-all-options-server.d.ts.map +0 -1
  203. package/dist/build/babel/remove-all-options-telemetry.d.ts +0 -5
  204. package/dist/build/babel/remove-all-options-telemetry.d.ts.map +0 -1
  205. package/dist/build/customInstrumentation.d.ts +0 -10
  206. package/dist/build/customInstrumentation.d.ts.map +0 -1
  207. package/dist/build/telemetry.d.ts +0 -8
  208. package/dist/build/telemetry.d.ts.map +0 -1
  209. package/dist/chunk-3JYRSECU.cjs.map +0 -1
  210. package/dist/chunk-465ZVXAK.js.map +0 -1
  211. package/dist/chunk-5QFG6SCM.js.map +0 -1
  212. package/dist/chunk-CEXVMFUD.js +0 -1265
  213. package/dist/chunk-CEXVMFUD.js.map +0 -1
  214. package/dist/chunk-CKUCDCGI.js +0 -168
  215. package/dist/chunk-CKUCDCGI.js.map +0 -1
  216. package/dist/chunk-HMMDNIEQ.cjs.map +0 -1
  217. package/dist/chunk-LGC3GUMR.cjs.map +0 -1
  218. package/dist/chunk-MCDDO4WY.cjs +0 -1309
  219. package/dist/chunk-MCDDO4WY.cjs.map +0 -1
  220. package/dist/chunk-OYO2MJED.cjs +0 -195
  221. package/dist/chunk-OYO2MJED.cjs.map +0 -1
  222. package/dist/chunk-SBTEIZ3B.js +0 -26
  223. package/dist/chunk-SBTEIZ3B.js.map +0 -1
  224. package/dist/chunk-WAWEQ3DP.js.map +0 -1
  225. package/dist/chunk-WIQEFIRX.cjs +0 -28
  226. package/dist/chunk-WIQEFIRX.cjs.map +0 -1
  227. package/dist/server/handlers/auth/defaults.d.ts +0 -3
  228. package/dist/server/handlers/auth/defaults.d.ts.map +0 -1
  229. package/dist/server/handlers/auth/helpers.d.ts +0 -11
  230. package/dist/server/handlers/auth/helpers.d.ts.map +0 -1
  231. package/dist/server/handlers/auth/index.d.ts +0 -11
  232. package/dist/server/handlers/auth/index.d.ts.map +0 -1
  233. package/dist/server/handlers/prompt.d.ts +0 -3
  234. package/dist/server/handlers/prompt.d.ts.map +0 -1
  235. package/dist/server/handlers/routes/agent-builder/handlers.d.ts +0 -17
  236. package/dist/server/handlers/routes/agent-builder/handlers.d.ts.map +0 -1
  237. package/dist/server/handlers/routes/agent-builder/router.d.ts +0 -4
  238. package/dist/server/handlers/routes/agent-builder/router.d.ts.map +0 -1
  239. package/dist/server/handlers/routes/agents/handlers.d.ts +0 -363
  240. package/dist/server/handlers/routes/agents/handlers.d.ts.map +0 -1
  241. package/dist/server/handlers/routes/agents/router.d.ts +0 -5
  242. package/dist/server/handlers/routes/agents/router.d.ts.map +0 -1
  243. package/dist/server/handlers/routes/agents/voice.d.ts +0 -18
  244. package/dist/server/handlers/routes/agents/voice.d.ts.map +0 -1
  245. package/dist/server/handlers/routes/logs/handlers.d.ts +0 -5
  246. package/dist/server/handlers/routes/logs/handlers.d.ts.map +0 -1
  247. package/dist/server/handlers/routes/logs/router.d.ts +0 -3
  248. package/dist/server/handlers/routes/logs/router.d.ts.map +0 -1
  249. package/dist/server/handlers/routes/mcp/handlers.d.ts +0 -139
  250. package/dist/server/handlers/routes/mcp/handlers.d.ts.map +0 -1
  251. package/dist/server/handlers/routes/mcp/router.d.ts +0 -4
  252. package/dist/server/handlers/routes/mcp/router.d.ts.map +0 -1
  253. package/dist/server/handlers/routes/memory/handlers.d.ts +0 -17
  254. package/dist/server/handlers/routes/memory/handlers.d.ts.map +0 -1
  255. package/dist/server/handlers/routes/memory/router.d.ts +0 -4
  256. package/dist/server/handlers/routes/memory/router.d.ts.map +0 -1
  257. package/dist/server/handlers/routes/observability/handlers.d.ts +0 -6
  258. package/dist/server/handlers/routes/observability/handlers.d.ts.map +0 -1
  259. package/dist/server/handlers/routes/observability/router.d.ts +0 -3
  260. package/dist/server/handlers/routes/observability/router.d.ts.map +0 -1
  261. package/dist/server/handlers/routes/scores/handlers.d.ts +0 -300
  262. package/dist/server/handlers/routes/scores/handlers.d.ts.map +0 -1
  263. package/dist/server/handlers/routes/scores/router.d.ts +0 -4
  264. package/dist/server/handlers/routes/scores/router.d.ts.map +0 -1
  265. package/dist/server/handlers/routes/telemetry/handlers.d.ts +0 -4
  266. package/dist/server/handlers/routes/telemetry/handlers.d.ts.map +0 -1
  267. package/dist/server/handlers/routes/telemetry/router.d.ts +0 -3
  268. package/dist/server/handlers/routes/telemetry/router.d.ts.map +0 -1
  269. package/dist/server/handlers/routes/tools/handlers.d.ts +0 -7
  270. package/dist/server/handlers/routes/tools/handlers.d.ts.map +0 -1
  271. package/dist/server/handlers/routes/tools/router.d.ts +0 -4
  272. package/dist/server/handlers/routes/tools/router.d.ts.map +0 -1
  273. package/dist/server/handlers/routes/vector/handlers.d.ts +0 -10
  274. package/dist/server/handlers/routes/vector/handlers.d.ts.map +0 -1
  275. package/dist/server/handlers/routes/vector/router.d.ts +0 -4
  276. package/dist/server/handlers/routes/vector/router.d.ts.map +0 -1
  277. package/dist/server/handlers/routes/workflows/handlers.d.ts +0 -20
  278. package/dist/server/handlers/routes/workflows/handlers.d.ts.map +0 -1
  279. package/dist/server/handlers/routes/workflows/legacyWorkflows.d.ts +0 -11
  280. package/dist/server/handlers/routes/workflows/legacyWorkflows.d.ts.map +0 -1
  281. package/dist/server/handlers/routes/workflows/router.d.ts +0 -4
  282. package/dist/server/handlers/routes/workflows/router.d.ts.map +0 -1
  283. package/dist/templates/instrumentation-template.js +0 -172
@@ -0,0 +1,1353 @@
1
+ 'use strict';
2
+
3
+ var chunkYIUDHDPS_cjs = require('./chunk-YIUDHDPS.cjs');
4
+ var chunkG7R456H2_cjs = require('./chunk-G7R456H2.cjs');
5
+ var fs = require('fs');
6
+ var promises = require('fs/promises');
7
+ var path = require('path');
8
+ var babel = require('@babel/core');
9
+ var error = require('@mastra/core/error');
10
+ var pkg = require('empathic/package');
11
+ var findWorkspaces = require('find-workspaces');
12
+ var child_process = require('child_process');
13
+ var url = require('url');
14
+ var logger = require('@mastra/core/logger');
15
+ var commonjs = require('@rollup/plugin-commonjs');
16
+ var json = require('@rollup/plugin-json');
17
+ var virtual = require('@rollup/plugin-virtual');
18
+ var esm = require('fs-extra/esm');
19
+ var localPkg = require('local-pkg');
20
+ var rollup = require('rollup');
21
+ var module$1 = require('module');
22
+ var posix = require('path/posix');
23
+ var rollupPlugin = require('@optimize-lodash/rollup-plugin');
24
+ var nodeResolve = require('@rollup/plugin-node-resolve');
25
+ var resolve = require('resolve.exports');
26
+
27
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
28
+
29
+ function _interopNamespace(e) {
30
+ if (e && e.__esModule) return e;
31
+ var n = Object.create(null);
32
+ if (e) {
33
+ Object.keys(e).forEach(function (k) {
34
+ if (k !== 'default') {
35
+ var d = Object.getOwnPropertyDescriptor(e, k);
36
+ Object.defineProperty(n, k, d.get ? d : {
37
+ enumerable: true,
38
+ get: function () { return e[k]; }
39
+ });
40
+ }
41
+ });
42
+ }
43
+ n.default = e;
44
+ return Object.freeze(n);
45
+ }
46
+
47
+ var path__namespace = /*#__PURE__*/_interopNamespace(path);
48
+ var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
49
+ var pkg__namespace = /*#__PURE__*/_interopNamespace(pkg);
50
+ var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
51
+ var json__default = /*#__PURE__*/_interopDefault(json);
52
+ var virtual__default = /*#__PURE__*/_interopDefault(virtual);
53
+ var nodeResolve__default = /*#__PURE__*/_interopDefault(nodeResolve);
54
+ var resolve__namespace = /*#__PURE__*/_interopNamespace(resolve);
55
+
56
+ // ../../node_modules/.pnpm/stacktrace-parser@0.1.11/node_modules/stacktrace-parser/dist/stack-trace-parser.esm.js
57
+ var UNKNOWN_FUNCTION = "<unknown>";
58
+ function parse(stackString) {
59
+ var lines = stackString.split("\n");
60
+ return lines.reduce(function(stack, line) {
61
+ var parseResult = parseChrome(line) || parseWinjs(line) || parseGecko(line) || parseNode(line) || parseJSC(line);
62
+ if (parseResult) {
63
+ stack.push(parseResult);
64
+ }
65
+ return stack;
66
+ }, []);
67
+ }
68
+ var chromeRe = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|rsc|<anonymous>|\/|[a-z]:\\|\\\\).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
69
+ var chromeEvalRe = /\((\S*)(?::(\d+))(?::(\d+))\)/;
70
+ function parseChrome(line) {
71
+ var parts = chromeRe.exec(line);
72
+ if (!parts) {
73
+ return null;
74
+ }
75
+ var isNative = parts[2] && parts[2].indexOf("native") === 0;
76
+ var isEval = parts[2] && parts[2].indexOf("eval") === 0;
77
+ var submatch = chromeEvalRe.exec(parts[2]);
78
+ if (isEval && submatch != null) {
79
+ parts[2] = submatch[1];
80
+ parts[3] = submatch[2];
81
+ parts[4] = submatch[3];
82
+ }
83
+ return {
84
+ file: !isNative ? parts[2] : null,
85
+ methodName: parts[1] || UNKNOWN_FUNCTION,
86
+ arguments: isNative ? [parts[2]] : [],
87
+ lineNumber: parts[3] ? +parts[3] : null,
88
+ column: parts[4] ? +parts[4] : null
89
+ };
90
+ }
91
+ var winjsRe = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|rsc|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
92
+ function parseWinjs(line) {
93
+ var parts = winjsRe.exec(line);
94
+ if (!parts) {
95
+ return null;
96
+ }
97
+ return {
98
+ file: parts[2],
99
+ methodName: parts[1] || UNKNOWN_FUNCTION,
100
+ arguments: [],
101
+ lineNumber: +parts[3],
102
+ column: parts[4] ? +parts[4] : null
103
+ };
104
+ }
105
+ var geckoRe = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|rsc|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i;
106
+ var geckoEvalRe = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
107
+ function parseGecko(line) {
108
+ var parts = geckoRe.exec(line);
109
+ if (!parts) {
110
+ return null;
111
+ }
112
+ var isEval = parts[3] && parts[3].indexOf(" > eval") > -1;
113
+ var submatch = geckoEvalRe.exec(parts[3]);
114
+ if (isEval && submatch != null) {
115
+ parts[3] = submatch[1];
116
+ parts[4] = submatch[2];
117
+ parts[5] = null;
118
+ }
119
+ return {
120
+ file: parts[3],
121
+ methodName: parts[1] || UNKNOWN_FUNCTION,
122
+ arguments: parts[2] ? parts[2].split(",") : [],
123
+ lineNumber: parts[4] ? +parts[4] : null,
124
+ column: parts[5] ? +parts[5] : null
125
+ };
126
+ }
127
+ var javaScriptCoreRe = /^\s*(?:([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$/i;
128
+ function parseJSC(line) {
129
+ var parts = javaScriptCoreRe.exec(line);
130
+ if (!parts) {
131
+ return null;
132
+ }
133
+ return {
134
+ file: parts[3],
135
+ methodName: parts[1] || UNKNOWN_FUNCTION,
136
+ arguments: [],
137
+ lineNumber: +parts[4],
138
+ column: parts[5] ? +parts[5] : null
139
+ };
140
+ }
141
+ var nodeRe = /^\s*at (?:((?:\[object object\])?[^\\/]+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i;
142
+ function parseNode(line) {
143
+ var parts = nodeRe.exec(line);
144
+ if (!parts) {
145
+ return null;
146
+ }
147
+ return {
148
+ file: parts[2],
149
+ methodName: parts[1] || UNKNOWN_FUNCTION,
150
+ arguments: [],
151
+ lineNumber: +parts[3],
152
+ column: parts[4] ? +parts[4] : null
153
+ };
154
+ }
155
+ var workspacesCache = findWorkspaces.createWorkspacesCache();
156
+ async function getWorkspaceInformation({
157
+ dir = process.cwd(),
158
+ mastraEntryFile
159
+ }) {
160
+ const closestPkgJson = pkg__namespace.up({ cwd: path.dirname(mastraEntryFile) });
161
+ const location = closestPkgJson ? path.dirname(chunkG7R456H2_cjs.slash(closestPkgJson)) : chunkG7R456H2_cjs.slash(process.cwd());
162
+ const workspaces = await findWorkspaces.findWorkspaces(dir, { cache: workspacesCache });
163
+ const _workspaceMap = new Map(
164
+ workspaces?.map((workspace) => [
165
+ workspace.package.name,
166
+ {
167
+ location: workspace.location,
168
+ dependencies: workspace.package.dependencies,
169
+ version: workspace.package.version
170
+ }
171
+ ]) ?? []
172
+ );
173
+ const isWorkspacePackage = (workspaces ?? []).some((ws) => ws.location === location);
174
+ const workspaceRoot = isWorkspacePackage ? findWorkspaces.findWorkspacesRoot(dir, { cache: workspacesCache })?.location : void 0;
175
+ return {
176
+ // If the current package is not part of the workspace, the bundling down the line shouldn't look at any workspace packages
177
+ workspaceMap: isWorkspacePackage ? _workspaceMap : /* @__PURE__ */ new Map(),
178
+ workspaceRoot,
179
+ isWorkspacePackage
180
+ };
181
+ }
182
+ var ValidationError = class extends Error {
183
+ type;
184
+ stack;
185
+ constructor(args) {
186
+ super(args.message);
187
+ this.type = args.type;
188
+ this.stack = args.stack;
189
+ }
190
+ };
191
+ function spawn(command, args = [], options = {}) {
192
+ return new Promise((resolve2, reject) => {
193
+ let validationError = null;
194
+ const childProcess = child_process.spawn(command, args, {
195
+ // stdio: 'inherit',
196
+ ...options
197
+ });
198
+ childProcess.on("error", (error) => {
199
+ reject(error);
200
+ });
201
+ let stderr = "";
202
+ childProcess.stderr?.on("data", (message) => {
203
+ try {
204
+ validationError = JSON.parse(message.toString());
205
+ } catch {
206
+ stderr += message;
207
+ }
208
+ });
209
+ childProcess.on("close", (code) => {
210
+ if (code === 0) {
211
+ resolve2();
212
+ } else {
213
+ if (validationError) {
214
+ reject(new ValidationError(validationError));
215
+ } else {
216
+ reject(new Error(stderr));
217
+ }
218
+ }
219
+ });
220
+ });
221
+ }
222
+ function validate(file, {
223
+ injectESMShim = false,
224
+ moduleResolveMapLocation,
225
+ stubbedExternals = []
226
+ }) {
227
+ let prefixCode = "";
228
+ if (injectESMShim) {
229
+ prefixCode = `import { fileURLToPath } from 'url';
230
+ import { dirname } from 'path';
231
+
232
+ globalThis.__filename = fileURLToPath(import.meta.url);
233
+ globalThis.__dirname = dirname(__filename);
234
+ `;
235
+ }
236
+ function errorHandler(err) {
237
+ console.error(
238
+ JSON.stringify({
239
+ type: err.name,
240
+ message: err.message,
241
+ stack: err.stack
242
+ })
243
+ );
244
+ process.exit(1);
245
+ }
246
+ return spawn(
247
+ process.execPath,
248
+ [
249
+ "--import",
250
+ undefined("@mastra/deployer/loader"),
251
+ "--input-type=module",
252
+ "--enable-source-maps",
253
+ "-e",
254
+ `${prefixCode};import('${url.pathToFileURL(file).href}').catch(err => {
255
+ ${errorHandler.toString()}
256
+ errorHandler(err);
257
+ })`.replaceAll(/\n/g, "")
258
+ ],
259
+ {
260
+ env: {
261
+ ...process.env,
262
+ MODULE_MAP: `${moduleResolveMapLocation}`,
263
+ STUBBED_EXTERNALS: JSON.stringify(stubbedExternals)
264
+ },
265
+ cwd: path.dirname(file)
266
+ }
267
+ );
268
+ }
269
+ function isNodeBuiltin(dep) {
270
+ const [pkg2] = dep.split("/");
271
+ return dep.startsWith("node:") || module$1.builtinModules.includes(dep) || module$1.builtinModules.includes(pkg2);
272
+ }
273
+
274
+ // src/build/analyze/constants.ts
275
+ var DEPS_TO_IGNORE = ["#tools", "execa"];
276
+ var GLOBAL_EXTERNALS = [
277
+ "pino",
278
+ "pino-pretty",
279
+ "@libsql/client",
280
+ "pg",
281
+ "libsql",
282
+ "#tools",
283
+ "typescript",
284
+ "undici",
285
+ "readable-stream",
286
+ "bufferutil",
287
+ "utf-8-validate",
288
+ "execa"
289
+ ];
290
+ var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
291
+
292
+ // src/build/analyze/analyzeEntry.ts
293
+ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
294
+ const normalizedMastraEntry = chunkG7R456H2_cjs.slash(mastraEntry);
295
+ let virtualPlugin = null;
296
+ if (isVirtualFile) {
297
+ virtualPlugin = virtual__default.default({
298
+ "#entry": entry
299
+ });
300
+ entry = "#entry";
301
+ }
302
+ const plugins = [];
303
+ if (virtualPlugin) {
304
+ plugins.push(virtualPlugin);
305
+ }
306
+ plugins.push(
307
+ ...[
308
+ chunkYIUDHDPS_cjs.tsConfigPaths(),
309
+ {
310
+ name: "custom-alias-resolver",
311
+ resolveId(id) {
312
+ if (id === "#server") {
313
+ return chunkG7R456H2_cjs.slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
314
+ }
315
+ if (id === "#mastra") {
316
+ return normalizedMastraEntry;
317
+ }
318
+ if (id.startsWith("@mastra/server")) {
319
+ return url.fileURLToPath(undefined(id));
320
+ }
321
+ }
322
+ },
323
+ json__default.default(),
324
+ chunkYIUDHDPS_cjs.esbuild(),
325
+ commonjs__default.default({
326
+ strictRequires: "debug",
327
+ ignoreTryCatch: false,
328
+ transformMixedEsModules: true,
329
+ extensions: [".js", ".ts"]
330
+ }),
331
+ chunkYIUDHDPS_cjs.removeDeployer(mastraEntry, {
332
+ sourcemap: sourcemapEnabled
333
+ }),
334
+ chunkYIUDHDPS_cjs.esbuild()
335
+ ]
336
+ );
337
+ return plugins;
338
+ }
339
+ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot, initialDepsToOptimize, {
340
+ logger: logger$1,
341
+ shouldCheckTransitiveDependencies
342
+ }) {
343
+ const depsToOptimize = /* @__PURE__ */ new Map();
344
+ if (!output.facadeModuleId) {
345
+ throw new Error(
346
+ "Something went wrong, we could not find the package name of the entry file. Please open an issue."
347
+ );
348
+ }
349
+ let entryRootPath = projectRoot;
350
+ if (!output.facadeModuleId.startsWith("\0virtual:")) {
351
+ entryRootPath = await chunkYIUDHDPS_cjs.getPackageRootPath(output.facadeModuleId) || projectRoot;
352
+ }
353
+ for (const [dependency, bindings] of Object.entries(output.importedBindings)) {
354
+ if (isNodeBuiltin(dependency) || dependency.startsWith("#")) {
355
+ continue;
356
+ }
357
+ const pkgName = chunkG7R456H2_cjs.getPackageName(dependency);
358
+ let rootPath = null;
359
+ let isWorkspace = false;
360
+ let version;
361
+ if (pkgName) {
362
+ rootPath = await chunkYIUDHDPS_cjs.getPackageRootPath(dependency, entryRootPath);
363
+ isWorkspace = workspaceMap.has(pkgName);
364
+ if (rootPath) {
365
+ try {
366
+ const pkgJson = await esm.readJSON(`${rootPath}/package.json`);
367
+ version = pkgJson.version;
368
+ } catch {
369
+ }
370
+ }
371
+ }
372
+ const normalizedRootPath = rootPath ? chunkG7R456H2_cjs.slash(rootPath) : null;
373
+ depsToOptimize.set(dependency, {
374
+ exports: bindings,
375
+ rootPath: normalizedRootPath,
376
+ isWorkspace,
377
+ version
378
+ });
379
+ }
380
+ async function checkTransitiveDependencies(internalMap, maxDepth = 10, currentDepth = 0) {
381
+ if (currentDepth >= maxDepth) {
382
+ logger$1.warn("Maximum dependency depth reached while checking transitive dependencies.");
383
+ return;
384
+ }
385
+ const depsSnapshot = new Map(depsToOptimize);
386
+ let hasAddedDeps = false;
387
+ for (const [dep, meta] of depsSnapshot) {
388
+ if (!meta.isWorkspace || internalMap.has(dep)) {
389
+ continue;
390
+ }
391
+ try {
392
+ const importerPath = output.facadeModuleId ? url.pathToFileURL(output.facadeModuleId).href : url.pathToFileURL(projectRoot).href;
393
+ const resolvedPath = localPkg.resolveModule(dep, {
394
+ paths: [importerPath]
395
+ });
396
+ if (!resolvedPath) {
397
+ logger$1.warn(`Could not resolve path for workspace dependency ${dep}`);
398
+ continue;
399
+ }
400
+ const analysis = await analyzeEntry({ entry: resolvedPath, isVirtualFile: false }, "", {
401
+ workspaceMap,
402
+ projectRoot,
403
+ logger: logger.noopLogger,
404
+ sourcemapEnabled: false,
405
+ initialDepsToOptimize: depsToOptimize
406
+ });
407
+ if (!analysis?.dependencies) {
408
+ continue;
409
+ }
410
+ for (const [innerDep, innerMeta] of analysis.dependencies) {
411
+ if (innerMeta.isWorkspace && !internalMap.has(innerDep) && !depsToOptimize.has(innerDep)) {
412
+ depsToOptimize.set(innerDep, innerMeta);
413
+ internalMap.set(innerDep, innerMeta);
414
+ hasAddedDeps = true;
415
+ }
416
+ }
417
+ } catch (err) {
418
+ logger$1.error(`Failed to resolve or analyze dependency ${dep}: ${err.message}`);
419
+ }
420
+ }
421
+ if (hasAddedDeps) {
422
+ await checkTransitiveDependencies(internalMap, maxDepth, currentDepth + 1);
423
+ }
424
+ }
425
+ if (shouldCheckTransitiveDependencies) {
426
+ await checkTransitiveDependencies(initialDepsToOptimize);
427
+ }
428
+ const dynamicImports = output.dynamicImports.filter((d) => !DEPS_TO_IGNORE.includes(d));
429
+ if (dynamicImports.length) {
430
+ for (const dynamicImport of dynamicImports) {
431
+ if (!depsToOptimize.has(dynamicImport) && !isNodeBuiltin(dynamicImport)) {
432
+ const pkgName = chunkG7R456H2_cjs.getPackageName(dynamicImport);
433
+ let version;
434
+ let rootPath = null;
435
+ if (pkgName) {
436
+ rootPath = await chunkYIUDHDPS_cjs.getPackageRootPath(dynamicImport, entryRootPath);
437
+ if (rootPath) {
438
+ try {
439
+ const pkgJson = await esm.readJSON(`${rootPath}/package.json`);
440
+ version = pkgJson.version;
441
+ } catch {
442
+ }
443
+ }
444
+ }
445
+ depsToOptimize.set(dynamicImport, {
446
+ exports: ["*"],
447
+ rootPath: rootPath ? chunkG7R456H2_cjs.slash(rootPath) : null,
448
+ isWorkspace: false,
449
+ version
450
+ });
451
+ }
452
+ }
453
+ }
454
+ return depsToOptimize;
455
+ }
456
+ async function analyzeEntry({
457
+ entry,
458
+ isVirtualFile
459
+ }, mastraEntry, {
460
+ logger,
461
+ sourcemapEnabled,
462
+ workspaceMap,
463
+ projectRoot,
464
+ initialDepsToOptimize = /* @__PURE__ */ new Map(),
465
+ // used to avoid infinite recursion
466
+ shouldCheckTransitiveDependencies = false
467
+ }) {
468
+ const optimizerBundler = await rollup.rollup({
469
+ logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
470
+ input: isVirtualFile ? "#entry" : entry,
471
+ treeshake: false,
472
+ preserveSymlinks: true,
473
+ plugins: getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }),
474
+ external: DEPS_TO_IGNORE
475
+ });
476
+ const { output } = await optimizerBundler.generate({
477
+ format: "esm",
478
+ inlineDynamicImports: true
479
+ });
480
+ await optimizerBundler.close();
481
+ const depsToOptimize = await captureDependenciesToOptimize(
482
+ output[0],
483
+ workspaceMap,
484
+ projectRoot,
485
+ initialDepsToOptimize,
486
+ {
487
+ logger,
488
+ shouldCheckTransitiveDependencies
489
+ }
490
+ );
491
+ return {
492
+ dependencies: depsToOptimize,
493
+ output: {
494
+ code: output[0].code,
495
+ map: output[0].map
496
+ }
497
+ };
498
+ }
499
+ function aliasHono() {
500
+ return {
501
+ name: "hono-alias",
502
+ resolveId(id) {
503
+ if (!id.startsWith("@hono/") && !id.startsWith("hono/") && id !== "hono" && id !== "hono-openapi") {
504
+ return;
505
+ }
506
+ const path2 = undefined(id);
507
+ return url.fileURLToPath(path2);
508
+ }
509
+ };
510
+ }
511
+ function moduleResolveMap(externals, projectRoot) {
512
+ const importMap = /* @__PURE__ */ new Map();
513
+ return {
514
+ name: "module-resolve-map",
515
+ moduleParsed(info) {
516
+ if (info.importedIds.length === 0 || !info.id) {
517
+ return;
518
+ }
519
+ for (const importedId of info.importedIds) {
520
+ for (const external of externals) {
521
+ if (chunkG7R456H2_cjs.isDependencyPartOfPackage(importedId, external)) {
522
+ importMap.set(external, info.id);
523
+ }
524
+ }
525
+ }
526
+ },
527
+ async generateBundle(options, bundle) {
528
+ const resolveMap = /* @__PURE__ */ new Map();
529
+ for (const [fileName, chunk] of Object.entries(bundle)) {
530
+ if (chunk.type === "chunk") {
531
+ for (const [external, resolvedFrom] of importMap) {
532
+ if (chunk.moduleIds.includes(resolvedFrom)) {
533
+ const fullPath = url.pathToFileURL(chunkG7R456H2_cjs.slash(path.join(projectRoot, fileName))).toString();
534
+ const innerMap = resolveMap.get(fullPath) || /* @__PURE__ */ new Map();
535
+ innerMap.set(external, url.pathToFileURL(chunkG7R456H2_cjs.slash(resolvedFrom)).toString());
536
+ resolveMap.set(fullPath, innerMap);
537
+ }
538
+ }
539
+ }
540
+ }
541
+ const resolveMapJson = Object.fromEntries(
542
+ Array.from(resolveMap.entries()).map(([key, value]) => [key, Object.fromEntries(value.entries())])
543
+ );
544
+ this.emitFile({
545
+ type: "asset",
546
+ name: "module-resolve-map.json",
547
+ source: `${JSON.stringify(resolveMapJson, null, 2)}`
548
+ });
549
+ }
550
+ };
551
+ }
552
+ function nodeGypDetector() {
553
+ const modulesToTrack = /* @__PURE__ */ new Set();
554
+ const modulesToTrackPackageInfo = /* @__PURE__ */ new Map();
555
+ return {
556
+ name: "node-gyp-build-detector",
557
+ moduleParsed(info) {
558
+ if (!info.meta?.commonjs?.requires?.length) {
559
+ return;
560
+ }
561
+ const hasNodeGypBuild = info.meta.commonjs.requires.some(
562
+ (m) => m?.resolved?.id.endsWith("node-gyp-build/index.js")
563
+ );
564
+ if (!hasNodeGypBuild) {
565
+ return;
566
+ }
567
+ modulesToTrack.add(info.id);
568
+ modulesToTrackPackageInfo.set(info.id, localPkg.getPackageInfo(info.id));
569
+ },
570
+ async generateBundle(options, bundle) {
571
+ const binaryMapByChunk = /* @__PURE__ */ new Map();
572
+ for (const [fileName, chunk] of Object.entries(bundle)) {
573
+ if (chunk.type === "chunk") {
574
+ for (const moduleId of chunk.moduleIds) {
575
+ if (modulesToTrackPackageInfo.has(moduleId)) {
576
+ const pkgInfo = await modulesToTrackPackageInfo.get(moduleId);
577
+ if (!binaryMapByChunk.has(fileName)) {
578
+ binaryMapByChunk.set(fileName, /* @__PURE__ */ new Set());
579
+ }
580
+ if (pkgInfo?.packageJson?.name) {
581
+ binaryMapByChunk.get(fileName).add(pkgInfo.packageJson.name);
582
+ }
583
+ }
584
+ }
585
+ }
586
+ }
587
+ const binaryMapJson = Object.fromEntries(
588
+ Array.from(binaryMapByChunk.entries()).map(([key, value]) => [key, Array.from(value)])
589
+ );
590
+ this.emitFile({
591
+ type: "asset",
592
+ name: "binary-map.json",
593
+ source: `${JSON.stringify(binaryMapJson, null, 2)}`
594
+ });
595
+ }
596
+ };
597
+ }
598
+
599
+ // src/build/analyze/bundleExternals.ts
600
+ function prepareEntryFileName(name, rootDir) {
601
+ return chunkG7R456H2_cjs.rollupSafeName(name, rootDir);
602
+ }
603
+ function createVirtualDependencies(depsToOptimize, {
604
+ projectRoot,
605
+ workspaceRoot,
606
+ outputDir,
607
+ bundlerOptions
608
+ }) {
609
+ const { isDev = false, externalsPreset = false } = bundlerOptions || {};
610
+ const fileNameToDependencyMap = /* @__PURE__ */ new Map();
611
+ const optimizedDependencyEntries = /* @__PURE__ */ new Map();
612
+ const rootDir = workspaceRoot || projectRoot;
613
+ for (const [dep, { exports: exports2 }] of depsToOptimize.entries()) {
614
+ const fileName = dep.replaceAll("/", "__");
615
+ const virtualFile = [];
616
+ const exportStringBuilder = [];
617
+ for (const local of exports2) {
618
+ if (local === "*") {
619
+ virtualFile.push(`export * from '${dep}';`);
620
+ continue;
621
+ } else if (local === "default") {
622
+ exportStringBuilder.push("default");
623
+ } else {
624
+ exportStringBuilder.push(local);
625
+ }
626
+ }
627
+ const chunks = [];
628
+ if (exportStringBuilder.length) {
629
+ chunks.push(`{ ${exportStringBuilder.join(", ")} }`);
630
+ }
631
+ if (chunks.length) {
632
+ virtualFile.push(`export ${chunks.join(", ")} from '${dep}';`);
633
+ }
634
+ let entryName = prepareEntryFileName(path__namespace.join(outputDir, fileName), rootDir);
635
+ fileNameToDependencyMap.set(entryName, dep);
636
+ optimizedDependencyEntries.set(dep, {
637
+ name: entryName,
638
+ virtual: virtualFile.join("\n")
639
+ });
640
+ }
641
+ if (isDev || externalsPreset) {
642
+ for (const [dep, { isWorkspace, rootPath }] of depsToOptimize.entries()) {
643
+ if (!isWorkspace || !rootPath || !workspaceRoot) {
644
+ continue;
645
+ }
646
+ const currentDepPath = optimizedDependencyEntries.get(dep);
647
+ if (!currentDepPath) {
648
+ continue;
649
+ }
650
+ const fileName = posix.basename(currentDepPath.name);
651
+ const entryName = prepareEntryFileName(chunkG7R456H2_cjs.getCompiledDepCachePath(rootPath, fileName), rootDir);
652
+ fileNameToDependencyMap.set(entryName, dep);
653
+ optimizedDependencyEntries.set(dep, {
654
+ ...currentDepPath,
655
+ name: entryName
656
+ });
657
+ }
658
+ }
659
+ return { optimizedDependencyEntries, fileNameToDependencyMap };
660
+ }
661
+ async function getInputPlugins2(virtualDependencies, {
662
+ transpilePackages,
663
+ workspaceMap,
664
+ bundlerOptions,
665
+ rootDir,
666
+ externals,
667
+ platform
668
+ }) {
669
+ const transpilePackagesMap = /* @__PURE__ */ new Map();
670
+ for (const pkg2 of transpilePackages) {
671
+ const dir = await chunkYIUDHDPS_cjs.getPackageRootPath(pkg2);
672
+ if (dir) {
673
+ transpilePackagesMap.set(pkg2, chunkG7R456H2_cjs.slash(dir));
674
+ } else {
675
+ transpilePackagesMap.set(pkg2, workspaceMap.get(pkg2)?.location ?? pkg2);
676
+ }
677
+ }
678
+ return [
679
+ virtual__default.default(
680
+ Array.from(virtualDependencies.entries()).reduce(
681
+ (acc, [dep, virtualDep]) => {
682
+ acc[`#virtual-${dep}`] = virtualDep.virtual;
683
+ return acc;
684
+ },
685
+ {}
686
+ )
687
+ ),
688
+ chunkYIUDHDPS_cjs.tsConfigPaths(),
689
+ chunkYIUDHDPS_cjs.subpathExternalsResolver(externals),
690
+ transpilePackagesMap.size ? chunkYIUDHDPS_cjs.esbuild({
691
+ format: "esm",
692
+ include: [
693
+ // Match files from transpilePackages by their actual directory paths
694
+ // but exclude any nested node_modules
695
+ ...[...transpilePackagesMap.values()].map((p) => {
696
+ if (path__namespace.isAbsolute(p)) {
697
+ return new RegExp(`^${p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/(?!.*node_modules).*$`);
698
+ } else {
699
+ return new RegExp(`/${p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/(?!.*node_modules).*$`);
700
+ }
701
+ }),
702
+ // Also match workspace packages resolved through node_modules symlinks
703
+ // (common in pnpm workspaces). Match by package name in node_modules path.
704
+ ...[...transpilePackagesMap.keys()].map((pkgName) => {
705
+ const escapedPkgName = pkgName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
706
+ return new RegExp(`/node_modules/${escapedPkgName}/(?!.*node_modules).*$`);
707
+ })
708
+ ],
709
+ // Disable the default /node_modules/ exclusion from rollup-plugin-esbuild.
710
+ // In pnpm workspaces, nodeResolve resolves workspace packages through node_modules
711
+ // symlinks, so the resolved paths contain "node_modules". Without this, workspace
712
+ // package .ts files won't be transpiled even if they match the include patterns.
713
+ exclude: []
714
+ }) : null,
715
+ bundlerOptions.noBundling ? {
716
+ name: "alias-optimized-deps",
717
+ async resolveId(id, importer, options) {
718
+ if (!virtualDependencies.has(id)) {
719
+ return null;
720
+ }
721
+ const info = virtualDependencies.get(id);
722
+ const packageRootPath = path__namespace.join(rootDir, path__namespace.dirname(path__namespace.dirname(path__namespace.dirname(info.name))));
723
+ const pkgJsonBuffer = await promises.readFile(path__namespace.join(packageRootPath, "package.json"), "utf-8");
724
+ const pkgJson = JSON.parse(pkgJsonBuffer);
725
+ if (!pkgJson) {
726
+ return null;
727
+ }
728
+ const pkgName = pkgJson.name || "";
729
+ let resolvedPath = resolve__namespace.exports(pkgJson, id.replace(pkgName, "."))?.[0];
730
+ if (!resolvedPath) {
731
+ resolvedPath = pkgJson.main ?? "index.js";
732
+ }
733
+ const resolved = await this.resolve(path__namespace.posix.join(packageRootPath, resolvedPath), importer, options);
734
+ return resolved;
735
+ }
736
+ } : null,
737
+ rollupPlugin.optimizeLodashImports({
738
+ include: "**/*.{js,ts,mjs,cjs}"
739
+ }),
740
+ commonjs__default.default({
741
+ strictRequires: "strict",
742
+ transformMixedEsModules: true,
743
+ ignoreTryCatch: false
744
+ }),
745
+ bundlerOptions.noBundling ? null : nodeResolve__default.default(chunkG7R456H2_cjs.getNodeResolveOptions(platform)),
746
+ bundlerOptions.noBundling ? chunkYIUDHDPS_cjs.esmShim() : null,
747
+ // hono is imported from deployer, so we need to resolve from here instead of the project root
748
+ aliasHono(),
749
+ json__default.default(),
750
+ nodeGypDetector(),
751
+ moduleResolveMap(externals, rootDir),
752
+ {
753
+ name: "not-found-resolver",
754
+ resolveId: {
755
+ order: "post",
756
+ async handler(id, importer) {
757
+ if (!importer) {
758
+ return null;
759
+ }
760
+ if (!id.endsWith(".node")) {
761
+ return null;
762
+ }
763
+ const pkgInfo = await localPkg.getPackageInfo(importer);
764
+ const packageName = pkgInfo?.packageJson?.name || id;
765
+ throw new error.MastraBaseError({
766
+ id: "DEPLOYER_BUNDLE_EXTERNALS_MISSING_NATIVE_BUILD",
767
+ domain: error.ErrorDomain.DEPLOYER,
768
+ category: error.ErrorCategory.USER,
769
+ details: {
770
+ importFile: importer,
771
+ packageName
772
+ },
773
+ text: `We found a possible binary dependency in your bundle. ${id} was not found when imported at ${importer}.
774
+
775
+ Please consider adding \`${packageName}\` to your externals, or updating this import to not end with ".node".
776
+
777
+ export const mastra = new Mastra({
778
+ bundler: {
779
+ externals: ["${packageName}"],
780
+ }
781
+ })`
782
+ });
783
+ }
784
+ }
785
+ }
786
+ ].filter(Boolean);
787
+ }
788
+ async function buildExternalDependencies(virtualDependencies, {
789
+ externals,
790
+ packagesToTranspile,
791
+ workspaceMap,
792
+ rootDir,
793
+ outputDir,
794
+ bundlerOptions,
795
+ platform
796
+ }) {
797
+ if (virtualDependencies.size === 0) {
798
+ return [];
799
+ }
800
+ const noBundling = bundlerOptions.isDev || bundlerOptions.externalsPreset;
801
+ const plugins = await getInputPlugins2(virtualDependencies, {
802
+ transpilePackages: packagesToTranspile,
803
+ workspaceMap,
804
+ bundlerOptions: {
805
+ noBundling
806
+ },
807
+ rootDir,
808
+ externals,
809
+ platform
810
+ });
811
+ const bundler = await rollup.rollup({
812
+ logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
813
+ input: Array.from(virtualDependencies.entries()).reduce(
814
+ (acc, [dep, virtualDep]) => {
815
+ acc[virtualDep.name] = `#virtual-${dep}`;
816
+ return acc;
817
+ },
818
+ {}
819
+ ),
820
+ external: externals,
821
+ treeshake: noBundling ? false : "safest",
822
+ plugins
823
+ });
824
+ const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
825
+ const { output } = await bundler.write({
826
+ format: "esm",
827
+ dir: rootDir,
828
+ entryFileNames: "[name].mjs",
829
+ // used to get the filename of the actual error
830
+ sourcemap: true,
831
+ /**
832
+ * Rollup creates chunks for common dependencies, but these chunks are by default written to the root directory instead of respecting the entryFileNames structure.
833
+ * So we want to write them to the `.mastra/output` folder as well.
834
+ */
835
+ chunkFileNames: (chunkInfo) => {
836
+ if (noBundling) {
837
+ const importedFromPackages = /* @__PURE__ */ new Set();
838
+ for (const moduleId of chunkInfo.moduleIds) {
839
+ const normalized = chunkG7R456H2_cjs.slash(moduleId);
840
+ for (const [pkgName, pkgInfo] of workspaceMap.entries()) {
841
+ const location = chunkG7R456H2_cjs.slash(pkgInfo.location);
842
+ if (normalized.startsWith(location)) {
843
+ importedFromPackages.add(pkgName);
844
+ break;
845
+ }
846
+ }
847
+ }
848
+ if (importedFromPackages.size > 1) {
849
+ throw new error.MastraBaseError({
850
+ id: "DEPLOYER_BUNDLE_EXTERNALS_SHARED_CHUNK",
851
+ domain: error.ErrorDomain.DEPLOYER,
852
+ category: error.ErrorCategory.USER,
853
+ details: {
854
+ chunkName: chunkInfo.name,
855
+ packages: JSON.stringify(Array.from(importedFromPackages))
856
+ },
857
+ text: `Please open an issue. We found a shared chunk "${chunkInfo.name}" used by multiple workspace packages: ${Array.from(importedFromPackages).join(", ")}.`
858
+ });
859
+ }
860
+ if (importedFromPackages.size === 1) {
861
+ const [pkgName] = importedFromPackages;
862
+ const workspaceLocation = workspaceMap.get(pkgName).location;
863
+ return prepareEntryFileName(chunkG7R456H2_cjs.getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
864
+ }
865
+ }
866
+ return `${outputDirRelative}/[name].mjs`;
867
+ },
868
+ assetFileNames: `${outputDirRelative}/[name][extname]`,
869
+ hoistTransitiveImports: false
870
+ });
871
+ await bundler.close();
872
+ return output;
873
+ }
874
+ function findExternalImporter(module, external, allOutputs) {
875
+ const capturedFiles = /* @__PURE__ */ new Set();
876
+ for (const id of module.imports) {
877
+ if (chunkG7R456H2_cjs.isDependencyPartOfPackage(id, external)) {
878
+ return module;
879
+ } else {
880
+ if (id.endsWith(".mjs")) {
881
+ capturedFiles.add(id);
882
+ }
883
+ }
884
+ }
885
+ for (const file of capturedFiles) {
886
+ const nextModule = allOutputs.find((o) => o.fileName === file);
887
+ if (nextModule) {
888
+ const importer = findExternalImporter(nextModule, external, allOutputs);
889
+ if (importer) {
890
+ return importer;
891
+ }
892
+ }
893
+ }
894
+ return null;
895
+ }
896
+ async function bundleExternals(depsToOptimize, outputDir, options) {
897
+ const {
898
+ workspaceRoot = null,
899
+ workspaceMap = /* @__PURE__ */ new Map(),
900
+ projectRoot = outputDir,
901
+ bundlerOptions = {},
902
+ platform = "node"
903
+ } = options;
904
+ const { externals: customExternals = [], transpilePackages = [], isDev = false } = bundlerOptions || {};
905
+ let externalsPreset = false;
906
+ if (customExternals === true) {
907
+ externalsPreset = true;
908
+ }
909
+ const externalsList = Array.isArray(customExternals) ? customExternals : [];
910
+ const allExternals = [...GLOBAL_EXTERNALS, ...DEPRECATED_EXTERNALS, ...externalsList];
911
+ const workspacePackagesNames = Array.from(workspaceMap.keys());
912
+ const packagesToTranspile = /* @__PURE__ */ new Set([...transpilePackages, ...workspacePackagesNames]);
913
+ const extractedExternals = /* @__PURE__ */ new Map();
914
+ if (externalsPreset) {
915
+ for (const [dep, metadata] of depsToOptimize.entries()) {
916
+ if (!metadata.isWorkspace) {
917
+ extractedExternals.set(dep, metadata.rootPath ?? dep);
918
+ depsToOptimize.delete(dep);
919
+ }
920
+ }
921
+ }
922
+ const { optimizedDependencyEntries, fileNameToDependencyMap } = createVirtualDependencies(depsToOptimize, {
923
+ workspaceRoot,
924
+ outputDir,
925
+ projectRoot,
926
+ bundlerOptions: {
927
+ isDev,
928
+ externalsPreset
929
+ }
930
+ });
931
+ const output = await buildExternalDependencies(optimizedDependencyEntries, {
932
+ externals: allExternals,
933
+ packagesToTranspile,
934
+ workspaceMap,
935
+ rootDir: workspaceRoot || projectRoot,
936
+ outputDir,
937
+ bundlerOptions: {
938
+ isDev,
939
+ externalsPreset
940
+ },
941
+ platform
942
+ });
943
+ const moduleResolveMap2 = /* @__PURE__ */ new Map();
944
+ const filteredChunks = output.filter((o) => o.type === "chunk");
945
+ for (const o of filteredChunks.filter((o2) => o2.isEntry || o2.isDynamicEntry)) {
946
+ for (const external of allExternals) {
947
+ if (DEPS_TO_IGNORE.includes(external)) {
948
+ continue;
949
+ }
950
+ const importer = findExternalImporter(o, external, filteredChunks);
951
+ if (importer) {
952
+ const fullPath = path__namespace.join(workspaceRoot || projectRoot, importer.fileName);
953
+ let innerMap = moduleResolveMap2.get(fullPath);
954
+ if (!innerMap) {
955
+ innerMap = /* @__PURE__ */ new Map();
956
+ moduleResolveMap2.set(fullPath, innerMap);
957
+ }
958
+ if (importer.moduleIds.length) {
959
+ innerMap.set(
960
+ external,
961
+ importer.moduleIds[importer.moduleIds.length - 1]?.startsWith("\0virtual:#virtual") ? importer.moduleIds[importer.moduleIds.length - 2] : importer.moduleIds[importer.moduleIds.length - 1]
962
+ );
963
+ }
964
+ }
965
+ }
966
+ }
967
+ const usedExternals = /* @__PURE__ */ Object.create(null);
968
+ for (const [fullPath, innerMap] of moduleResolveMap2) {
969
+ const innerObj = /* @__PURE__ */ Object.create(null);
970
+ for (const [external, value] of innerMap) {
971
+ innerObj[external] = value;
972
+ }
973
+ usedExternals[fullPath] = innerObj;
974
+ }
975
+ if (extractedExternals.size > 0) {
976
+ const syntheticPath = path__namespace.join(workspaceRoot || projectRoot, "__externals__");
977
+ const externalsObj = /* @__PURE__ */ Object.create(null);
978
+ for (const [dep, rootPath] of extractedExternals) {
979
+ externalsObj[dep] = rootPath;
980
+ }
981
+ usedExternals[syntheticPath] = externalsObj;
982
+ }
983
+ return { output, fileNameToDependencyMap, usedExternals };
984
+ }
985
+ function checkConfigExport(result) {
986
+ const t = babel__namespace.default.types;
987
+ const mastraVars = /* @__PURE__ */ new Set();
988
+ return {
989
+ visitor: {
990
+ ExportNamedDeclaration(path2) {
991
+ const decl = path2.node.declaration;
992
+ if (t.isVariableDeclaration(decl)) {
993
+ const varDecl = decl.declarations[0];
994
+ if (t.isIdentifier(varDecl?.id, { name: "mastra" }) && t.isNewExpression(varDecl.init) && t.isIdentifier(varDecl.init.callee, { name: "Mastra" })) {
995
+ result.hasValidConfig = true;
996
+ }
997
+ }
998
+ if (Array.isArray(path2.node.specifiers)) {
999
+ for (const spec of path2.node.specifiers) {
1000
+ if (t.isExportSpecifier(spec) && t.isIdentifier(spec.exported, { name: "mastra" }) && t.isIdentifier(spec.local) && mastraVars.has(spec.local.name)) {
1001
+ result.hasValidConfig = true;
1002
+ }
1003
+ }
1004
+ }
1005
+ },
1006
+ // For cases 2-4 we need to track whether those variables are assigned to `new Mastra()`
1007
+ VariableDeclaration(path2) {
1008
+ for (const decl of path2.node.declarations) {
1009
+ if (t.isIdentifier(decl.id) && t.isNewExpression(decl.init) && t.isIdentifier(decl.init.callee, { name: "Mastra" })) {
1010
+ mastraVars.add(decl.id.name);
1011
+ }
1012
+ }
1013
+ }
1014
+ }
1015
+ };
1016
+ }
1017
+
1018
+ // src/build/analyze.ts
1019
+ function throwExternalDependencyError({
1020
+ errorId,
1021
+ moduleName,
1022
+ packageName,
1023
+ messagePrefix
1024
+ }) {
1025
+ throw new error.MastraError({
1026
+ id: errorId,
1027
+ domain: error.ErrorDomain.DEPLOYER,
1028
+ category: error.ErrorCategory.USER,
1029
+ details: {
1030
+ importFile: moduleName,
1031
+ packageName
1032
+ },
1033
+ text: `${messagePrefix} \`${packageName}\` to your externals.
1034
+
1035
+ export const mastra = new Mastra({
1036
+ bundler: {
1037
+ externals: ["${packageName}"],
1038
+ }
1039
+ })`
1040
+ });
1041
+ }
1042
+ function getPackageNameFromBundledModuleName(moduleName) {
1043
+ if (moduleName.includes("__")) {
1044
+ return moduleName.replaceAll("__", "/");
1045
+ }
1046
+ const chunks = moduleName.split("-");
1047
+ if (!chunks.length) {
1048
+ return moduleName;
1049
+ }
1050
+ if (chunks[0]?.startsWith("@")) {
1051
+ return chunks.slice(0, 2).join("/");
1052
+ }
1053
+ return chunks[0];
1054
+ }
1055
+ function validateError(err, file, {
1056
+ binaryMapData,
1057
+ workspaceMap
1058
+ }) {
1059
+ let moduleName = null;
1060
+ let errorConfig = null;
1061
+ if (err instanceof ValidationError) {
1062
+ const parsedStack = parse(err.stack);
1063
+ if (err.type === "TypeError") {
1064
+ const pkgNameRegex = /.*node_modules\/([^\/]+)\//;
1065
+ const stacktraceFrame = parsedStack.find((frame) => frame.file && pkgNameRegex.test(frame.file));
1066
+ if (stacktraceFrame) {
1067
+ const match = stacktraceFrame.file.match(pkgNameRegex);
1068
+ moduleName = match?.[1] ?? getPackageNameFromBundledModuleName(path.basename(file.name));
1069
+ } else {
1070
+ moduleName = getPackageNameFromBundledModuleName(path.basename(file.name));
1071
+ }
1072
+ errorConfig = {
1073
+ id: "DEPLOYER_ANALYZE_TYPE_ERROR",
1074
+ messagePrefix: `Mastra wasn't able to bundle "${moduleName}", might be an older commonJS module. Please add`
1075
+ };
1076
+ } else if (err.stack?.includes?.("[ERR_MODULE_NOT_FOUND]")) {
1077
+ moduleName = err.message.match(/Cannot find package '([^']+)'/)?.[1];
1078
+ const parentModuleName = getPackageNameFromBundledModuleName(path.basename(file.name));
1079
+ errorConfig = {
1080
+ id: "DEPLOYER_ANALYZE_MODULE_NOT_FOUND",
1081
+ messagePrefix: `Mastra wasn't able to build your project, We couldn't load "${moduleName}" from "${parentModuleName}". Make sure "${moduleName}" is installed or add`
1082
+ };
1083
+ if (moduleName === parentModuleName) {
1084
+ return;
1085
+ }
1086
+ }
1087
+ }
1088
+ if (err.message.includes("No native build was found")) {
1089
+ const pkgName = getPackageNameFromBundledModuleName(path.basename(file.name));
1090
+ moduleName = binaryMapData[file.fileName]?.[0] ?? pkgName;
1091
+ errorConfig = {
1092
+ id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
1093
+ messagePrefix: "We found a binary dependency in your bundle but we cannot bundle it yet. Please add"
1094
+ };
1095
+ }
1096
+ if (moduleName && workspaceMap.has(moduleName)) {
1097
+ throw new error.MastraError({
1098
+ id: "DEPLOYER_ANALYZE_ERROR_IN_WORKSPACE",
1099
+ domain: error.ErrorDomain.DEPLOYER,
1100
+ category: error.ErrorCategory.USER,
1101
+ details: {
1102
+ // importFile: moduleName,
1103
+ packageName: moduleName
1104
+ },
1105
+ text: `We found an error in the ${moduleName} workspace package. Please find the offending package and fix the error.
1106
+ Error: ${err.stack}`
1107
+ });
1108
+ }
1109
+ if (errorConfig && moduleName) {
1110
+ throwExternalDependencyError({
1111
+ errorId: errorConfig.id,
1112
+ moduleName,
1113
+ packageName: moduleName,
1114
+ messagePrefix: errorConfig.messagePrefix
1115
+ });
1116
+ }
1117
+ }
1118
+ async function validateFile(root, file, {
1119
+ binaryMapData,
1120
+ moduleResolveMapLocation,
1121
+ logger,
1122
+ workspaceMap,
1123
+ stubbedExternals
1124
+ }) {
1125
+ try {
1126
+ if (!file.isDynamicEntry && file.isEntry) {
1127
+ await validate(path.join(root, file.fileName), {
1128
+ moduleResolveMapLocation,
1129
+ injectESMShim: false,
1130
+ stubbedExternals
1131
+ });
1132
+ }
1133
+ } catch (err) {
1134
+ let errorToHandle = err;
1135
+ if (err instanceof ValidationError && err.type === "ReferenceError" && (err.message.startsWith("__dirname") || err.message.startsWith("__filename"))) {
1136
+ try {
1137
+ await validate(path.join(root, file.fileName), {
1138
+ moduleResolveMapLocation,
1139
+ injectESMShim: true,
1140
+ stubbedExternals
1141
+ });
1142
+ errorToHandle = null;
1143
+ } catch (err2) {
1144
+ errorToHandle = err2;
1145
+ }
1146
+ }
1147
+ if (errorToHandle instanceof Error) {
1148
+ validateError(errorToHandle, file, { binaryMapData, workspaceMap });
1149
+ }
1150
+ }
1151
+ }
1152
+ async function validateOutput({
1153
+ output,
1154
+ reverseVirtualReferenceMap,
1155
+ usedExternals,
1156
+ outputDir,
1157
+ projectRoot,
1158
+ workspaceMap,
1159
+ depsVersionInfo
1160
+ }, logger) {
1161
+ const result = {
1162
+ dependencies: /* @__PURE__ */ new Map(),
1163
+ externalDependencies: /* @__PURE__ */ new Map(),
1164
+ workspaceMap
1165
+ };
1166
+ for (const deps of Object.values(usedExternals)) {
1167
+ for (const dep of Object.keys(deps)) {
1168
+ const pkgName = chunkG7R456H2_cjs.getPackageName(dep);
1169
+ if (pkgName) {
1170
+ const versionInfo = depsVersionInfo.get(dep) || depsVersionInfo.get(pkgName) || {};
1171
+ result.externalDependencies.set(pkgName, versionInfo);
1172
+ }
1173
+ }
1174
+ }
1175
+ let binaryMapData = {};
1176
+ if (fs.existsSync(path.join(outputDir, "binary-map.json"))) {
1177
+ const binaryMap = await promises.readFile(path.join(outputDir, "binary-map.json"), "utf-8");
1178
+ binaryMapData = JSON.parse(binaryMap);
1179
+ }
1180
+ for (const file of output) {
1181
+ if (file.type === "asset") {
1182
+ continue;
1183
+ }
1184
+ logger.debug(`Validating if ${file.fileName} is a valid module.`);
1185
+ if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
1186
+ result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
1187
+ }
1188
+ await validateFile(projectRoot, file, {
1189
+ binaryMapData,
1190
+ moduleResolveMapLocation: path.join(outputDir, "module-resolve-map.json"),
1191
+ logger,
1192
+ workspaceMap,
1193
+ stubbedExternals: [...GLOBAL_EXTERNALS, ...DEPS_TO_IGNORE]
1194
+ });
1195
+ }
1196
+ return result;
1197
+ }
1198
+ async function analyzeBundle(entries, mastraEntry, {
1199
+ outputDir,
1200
+ projectRoot,
1201
+ platform,
1202
+ isDev = false,
1203
+ bundlerOptions
1204
+ }, logger) {
1205
+ const mastraConfig = await promises.readFile(mastraEntry, "utf-8");
1206
+ const mastraConfigResult = {
1207
+ hasValidConfig: false
1208
+ };
1209
+ await babel__namespace.transformAsync(mastraConfig, {
1210
+ filename: mastraEntry,
1211
+ presets: [undefined("@babel/preset-typescript")],
1212
+ plugins: [checkConfigExport(mastraConfigResult)]
1213
+ });
1214
+ if (!mastraConfigResult.hasValidConfig) {
1215
+ logger.warn(`Invalid Mastra config. Please make sure that your entry file looks like this:
1216
+ export const mastra = new Mastra({
1217
+ // your options
1218
+ })
1219
+
1220
+ If you think your configuration is valid, please open an issue.`);
1221
+ }
1222
+ const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
1223
+ let externalsPreset = false;
1224
+ const userExternals = Array.isArray(bundlerOptions?.externals) ? bundlerOptions?.externals : [];
1225
+ if (bundlerOptions?.externals === true) {
1226
+ externalsPreset = true;
1227
+ }
1228
+ let index = 0;
1229
+ const depsToOptimize = /* @__PURE__ */ new Map();
1230
+ const allExternals = [...GLOBAL_EXTERNALS, ...userExternals].filter(Boolean);
1231
+ logger.info("Analyzing dependencies...");
1232
+ const allUsedExternals = /* @__PURE__ */ new Map();
1233
+ for (const entry of entries) {
1234
+ const isVirtualFile = entry.includes("\n") || !fs.existsSync(entry);
1235
+ const analyzeResult = await analyzeEntry({ entry, isVirtualFile }, mastraEntry, {
1236
+ logger,
1237
+ sourcemapEnabled: bundlerOptions?.enableSourcemap ?? false,
1238
+ workspaceMap,
1239
+ projectRoot,
1240
+ shouldCheckTransitiveDependencies: isDev || externalsPreset
1241
+ });
1242
+ await promises.writeFile(path.join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
1243
+ for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
1244
+ const isPartOfExternals = allExternals.some((external) => chunkG7R456H2_cjs.isDependencyPartOfPackage(dep, external));
1245
+ if (isPartOfExternals || externalsPreset && !metadata.isWorkspace) {
1246
+ const pkgName = chunkG7R456H2_cjs.getPackageName(dep);
1247
+ if (pkgName && !allUsedExternals.has(pkgName)) {
1248
+ allUsedExternals.set(pkgName, {
1249
+ version: metadata.version
1250
+ });
1251
+ }
1252
+ continue;
1253
+ }
1254
+ if (depsToOptimize.has(dep)) {
1255
+ const existingEntry = depsToOptimize.get(dep);
1256
+ depsToOptimize.set(dep, {
1257
+ ...existingEntry,
1258
+ exports: [.../* @__PURE__ */ new Set([...existingEntry.exports, ...metadata.exports])]
1259
+ });
1260
+ } else {
1261
+ depsToOptimize.set(dep, metadata);
1262
+ }
1263
+ }
1264
+ }
1265
+ if (isDev || externalsPreset) {
1266
+ for (const [dep, metadata] of depsToOptimize.entries()) {
1267
+ if (!metadata.isWorkspace) {
1268
+ depsToOptimize.delete(dep);
1269
+ }
1270
+ }
1271
+ }
1272
+ const sortedDeps = Array.from(depsToOptimize.keys()).sort();
1273
+ logger.info("Optimizing dependencies...");
1274
+ logger.debug(`${sortedDeps.map((key) => `- ${key}`).join("\n")}`);
1275
+ const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
1276
+ bundlerOptions: {
1277
+ ...bundlerOptions,
1278
+ externals: bundlerOptions?.externals ?? allExternals,
1279
+ isDev
1280
+ },
1281
+ projectRoot,
1282
+ workspaceRoot,
1283
+ workspaceMap,
1284
+ platform
1285
+ });
1286
+ const relativeWorkspaceFolderPaths = Array.from(workspaceMap.values()).map(
1287
+ (pkgInfo) => chunkG7R456H2_cjs.slash(path.relative(workspaceRoot || projectRoot, pkgInfo.location))
1288
+ );
1289
+ const depsVersionInfo = /* @__PURE__ */ new Map();
1290
+ for (const [dep, metadata] of depsToOptimize.entries()) {
1291
+ const pkgName = chunkG7R456H2_cjs.getPackageName(dep);
1292
+ if (pkgName && metadata.version) {
1293
+ depsVersionInfo.set(pkgName, {
1294
+ version: metadata.version
1295
+ });
1296
+ }
1297
+ if (metadata.version) {
1298
+ depsVersionInfo.set(dep, {
1299
+ version: metadata.version
1300
+ });
1301
+ }
1302
+ }
1303
+ for (const o of output) {
1304
+ if (o.type === "asset") {
1305
+ continue;
1306
+ }
1307
+ for (const i of o.imports) {
1308
+ if (chunkG7R456H2_cjs.isBuiltinModule(i)) {
1309
+ continue;
1310
+ }
1311
+ if (i.startsWith(".") || i.startsWith("/")) {
1312
+ continue;
1313
+ }
1314
+ if (relativeWorkspaceFolderPaths.some((workspacePath) => i.startsWith(workspacePath))) {
1315
+ continue;
1316
+ }
1317
+ const pkgName = chunkG7R456H2_cjs.getPackageName(i);
1318
+ if (pkgName && !allUsedExternals.has(pkgName)) {
1319
+ const versionInfo = depsVersionInfo.get(i) || depsVersionInfo.get(pkgName) || {};
1320
+ allUsedExternals.set(pkgName, versionInfo);
1321
+ }
1322
+ }
1323
+ }
1324
+ const result = await validateOutput(
1325
+ {
1326
+ output,
1327
+ reverseVirtualReferenceMap: fileNameToDependencyMap,
1328
+ usedExternals,
1329
+ outputDir,
1330
+ projectRoot: workspaceRoot || projectRoot,
1331
+ workspaceMap,
1332
+ depsVersionInfo
1333
+ },
1334
+ logger
1335
+ );
1336
+ const mergedExternalDeps = new Map(result.externalDependencies);
1337
+ for (const [dep, info] of allUsedExternals) {
1338
+ const existing = mergedExternalDeps.get(dep);
1339
+ if (!existing || !existing.version && info.version) {
1340
+ mergedExternalDeps.set(dep, info);
1341
+ }
1342
+ }
1343
+ return {
1344
+ ...result,
1345
+ externalDependencies: mergedExternalDeps
1346
+ };
1347
+ }
1348
+
1349
+ exports.aliasHono = aliasHono;
1350
+ exports.analyzeBundle = analyzeBundle;
1351
+ exports.getWorkspaceInformation = getWorkspaceInformation;
1352
+ //# sourceMappingURL=chunk-73SEUI3W.cjs.map
1353
+ //# sourceMappingURL=chunk-73SEUI3W.cjs.map