@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
@@ -1,1265 +0,0 @@
1
- import * as babel from '@babel/core';
2
- import babel__default from '@babel/core';
3
- import fs, { existsSync } from 'fs';
4
- import { readFile, writeFile } from 'fs/promises';
5
- import * as path2 from 'path';
6
- import path2__default, { dirname, join, normalize, relative, basename as basename$1 } from 'path';
7
- import { spawn as spawn$1 } from 'child_process';
8
- import { getPackageInfo } from 'local-pkg';
9
- import { pathToFileURL, fileURLToPath } from 'url';
10
- import { rollup } from 'rollup';
11
- import originalEsbuild from 'rollup-plugin-esbuild';
12
- import commonjs from '@rollup/plugin-commonjs';
13
- import resolveFrom2 from 'resolve-from';
14
- import { createHandler } from 'typescript-paths';
15
- import { optimizeLodashImports } from '@optimize-lodash/rollup-plugin';
16
- import json from '@rollup/plugin-json';
17
- import * as pkg from 'empathic/package';
18
- import { createWorkspacesCache, findWorkspaces, findWorkspacesRoot } from 'find-workspaces';
19
- import { noopLogger } from '@mastra/core/logger';
20
- import virtual from '@rollup/plugin-virtual';
21
- import { builtinModules } from 'module';
22
- import nodeResolve from '@rollup/plugin-node-resolve';
23
- import esmShim from '@rollup/plugin-esm-shim';
24
- import { basename } from 'path/posix';
25
- import * as resolve from 'resolve.exports';
26
- import { MastraError, ErrorCategory, ErrorDomain, MastraBaseError } from '@mastra/core/error';
27
-
28
- // src/build/analyze.ts
29
- function getPackageName(id) {
30
- const parts = id.split("/");
31
- if (id.startsWith("@")) {
32
- return parts.slice(0, 2).join("/");
33
- }
34
- return parts[0];
35
- }
36
- async function getPackageRootPath(packageName, parentPath) {
37
- let rootPath;
38
- try {
39
- let options = void 0;
40
- if (parentPath) {
41
- if (!parentPath.startsWith("file://")) {
42
- parentPath = pathToFileURL(parentPath).href;
43
- }
44
- options = {
45
- paths: [parentPath]
46
- };
47
- }
48
- const pkg2 = await getPackageInfo(packageName, options);
49
- rootPath = pkg2?.rootPath ?? null;
50
- } catch (e) {
51
- rootPath = null;
52
- }
53
- return rootPath;
54
- }
55
- function getCompiledDepCachePath(rootPath, packageName) {
56
- return slash(join(rootPath, "node_modules", ".cache", packageName));
57
- }
58
- function slash(path3) {
59
- const isExtendedLengthPath = path3.startsWith("\\\\?\\");
60
- if (isExtendedLengthPath) {
61
- return path3;
62
- }
63
- return path3.replaceAll("\\", "/");
64
- }
65
- function rollupSafeName(name, rootDir) {
66
- const rel = relative(rootDir, name);
67
- let entry = slash(rel);
68
- entry = entry.replace(/^(\.\.\/)+/, "");
69
- entry = entry.replace(/^\/+/, "");
70
- entry = entry.replace(/^[A-Za-z]:\//, "");
71
- if (!entry) {
72
- entry = slash(basename$1(name));
73
- }
74
- return entry;
75
- }
76
- var NATIVE_BINDING_LOADERS = [
77
- "node-gyp-build",
78
- "prebuild-install",
79
- "bindings",
80
- "node-addon-api",
81
- "node-pre-gyp",
82
- "nan"
83
- // Native Abstractions for Node.js
84
- ];
85
- function findNativePackageModule(moduleIds) {
86
- return moduleIds.find((id) => {
87
- if (id.startsWith("\0")) {
88
- return false;
89
- }
90
- if (!id.includes("/node_modules/")) {
91
- return false;
92
- }
93
- for (const loader of NATIVE_BINDING_LOADERS) {
94
- if (id.includes(`/${loader}/`) || id.includes(`/${loader}@`)) {
95
- return false;
96
- }
97
- }
98
- return true;
99
- });
100
- }
101
-
102
- // src/validator/validate.ts
103
- function spawn(command, args = [], options = {}) {
104
- return new Promise((resolve2, reject) => {
105
- const childProcess = spawn$1(command, args, {
106
- // stdio: 'inherit',
107
- ...options
108
- });
109
- childProcess.on("error", (error) => {
110
- reject(error);
111
- });
112
- let stderr = "";
113
- childProcess.stderr?.on("data", (message) => {
114
- stderr += message;
115
- });
116
- childProcess.on("close", (code) => {
117
- if (code === 0) {
118
- resolve2();
119
- } else {
120
- reject(new Error(stderr));
121
- }
122
- });
123
- });
124
- }
125
- function validate(file) {
126
- return spawn(
127
- "node",
128
- [
129
- "--import",
130
- import.meta.resolve("@mastra/deployer/loader"),
131
- "--input-type=module",
132
- "-e",
133
- `import('file://${slash(file)}')`
134
- ],
135
- {
136
- cwd: dirname(file)
137
- }
138
- );
139
- }
140
- function removeAllOptionsFromMastraExcept(result, option, logger) {
141
- const t = babel__default.types;
142
- return {
143
- name: "remove-all-except-" + option + "-config",
144
- visitor: {
145
- ExportNamedDeclaration: {
146
- // remove all exports
147
- exit(path3) {
148
- path3.remove();
149
- }
150
- },
151
- NewExpression(path3, state) {
152
- const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
153
- if (!varDeclaratorPath) {
154
- return;
155
- }
156
- const parentNode = path3.parentPath.node;
157
- if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
158
- return;
159
- }
160
- let mastraArgs = t.objectExpression([]);
161
- if (t.isObjectExpression(path3.node.arguments[0])) {
162
- mastraArgs = path3.node.arguments[0];
163
- }
164
- let telemetry = mastraArgs.properties.find(
165
- // @ts-ignore
166
- (prop) => prop.key.name === option
167
- );
168
- let telemetryValue = t.objectExpression([]);
169
- const programPath = path3.scope.getProgramParent().path;
170
- if (!programPath) {
171
- return;
172
- }
173
- if (telemetry && t.isObjectProperty(telemetry) && t.isExpression(telemetry.value)) {
174
- result.hasCustomConfig = true;
175
- telemetryValue = telemetry.value;
176
- if (t.isIdentifier(telemetry.value) && telemetry.value.name === option) {
177
- const telemetryBinding = state.file.scope.getBinding(option);
178
- if (telemetryBinding && t.isVariableDeclarator(telemetryBinding.path.node)) {
179
- const id = path3.scope.generateUidIdentifier(option);
180
- telemetryBinding.path.replaceWith(t.variableDeclarator(id, telemetryBinding.path.node.init));
181
- telemetryValue = id;
182
- }
183
- }
184
- }
185
- const exportDeclaration = t.exportNamedDeclaration(
186
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), telemetryValue)]),
187
- []
188
- );
189
- programPath.node.body.push(exportDeclaration);
190
- },
191
- Program: {
192
- exit(path3) {
193
- const hasExport = path3.node.body.some(
194
- (node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
195
- );
196
- if (!hasExport) {
197
- if (logger) {
198
- logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
199
- export const mastra = new Mastra({
200
- ${option}: <value>
201
- })
202
-
203
- `);
204
- }
205
- const fallbackExportDeclaration = t.exportNamedDeclaration(
206
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
207
- []
208
- );
209
- path3.node.body.push(fallbackExportDeclaration);
210
- }
211
- }
212
- }
213
- }
214
- };
215
- }
216
-
217
- // src/build/babel/remove-all-options-bundler.ts
218
- function removeAllOptionsExceptBundler(result, logger) {
219
- return removeAllOptionsFromMastraExcept(result, "bundler", logger);
220
- }
221
- function esbuild(options = {}) {
222
- return originalEsbuild({
223
- target: "node20",
224
- platform: "node",
225
- minify: false,
226
- ...options
227
- });
228
- }
229
- var PLUGIN_NAME = "tsconfig-paths";
230
- function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve } = {}) {
231
- let handler;
232
- return {
233
- name: PLUGIN_NAME,
234
- buildStart() {
235
- handler = createHandler({
236
- log: () => {
237
- },
238
- tsConfigPath,
239
- respectCoreModule,
240
- falllback: (moduleName) => fs.existsSync(moduleName)
241
- });
242
- return;
243
- },
244
- async resolveId(request, importer, options) {
245
- if (!importer || request.startsWith("\0")) {
246
- return null;
247
- }
248
- const moduleName = handler?.(request, normalize(importer));
249
- if (!moduleName) {
250
- let importerMeta = {};
251
- const resolved = await this.resolve(request, importer, { skipSelf: true, ...options });
252
- if (!resolved) {
253
- return null;
254
- }
255
- if (localResolve) {
256
- const importerInfo = this.getModuleInfo(importer);
257
- importerMeta = importerInfo?.meta || {};
258
- if (!request.startsWith("./") && !request.startsWith("../") && importerMeta?.[PLUGIN_NAME]?.resolved) {
259
- return {
260
- ...resolved,
261
- external: !request.startsWith("hono/") && request !== "hono"
262
- };
263
- }
264
- }
265
- return {
266
- ...resolved,
267
- meta: {
268
- ...resolved.meta || {},
269
- ...importerMeta
270
- }
271
- };
272
- }
273
- if (!path2__default.extname(moduleName)) {
274
- const resolved = await this.resolve(moduleName, importer, { skipSelf: true, ...options });
275
- if (!resolved) {
276
- return null;
277
- }
278
- return {
279
- ...resolved,
280
- meta: {
281
- ...resolved.meta,
282
- [PLUGIN_NAME]: {
283
- resolved: true
284
- }
285
- }
286
- };
287
- }
288
- return {
289
- id: moduleName,
290
- meta: {
291
- [PLUGIN_NAME]: {
292
- resolved: true
293
- }
294
- }
295
- };
296
- }
297
- };
298
- }
299
- function removeNonReferencedNodes() {
300
- const t = babel__default.types;
301
- return {
302
- name: "remove-non-referenced-nodes",
303
- visitor: {
304
- Program(path3) {
305
- const scope = path3.scope;
306
- const currentBody = path3.get("body");
307
- const filteredBody = currentBody.filter((childPath) => {
308
- if (childPath.isExportDeclaration()) {
309
- return true;
310
- }
311
- if (childPath.isVariableDeclaration()) {
312
- return childPath.node.declarations.some((decl) => {
313
- if (!t.isIdentifier(decl.id)) {
314
- return false;
315
- }
316
- const name = decl.id.name;
317
- const binding = scope.getBinding(name);
318
- return binding && (binding.referenced || binding.referencePaths.length > 0);
319
- });
320
- }
321
- if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {
322
- if (!t.isIdentifier(childPath.node.id)) {
323
- return false;
324
- }
325
- const name = childPath.node.id.name;
326
- const binding = scope.getBinding(name);
327
- return binding && (binding.referenced || binding.referencePaths.length > 0);
328
- }
329
- if (childPath.isImportDeclaration()) {
330
- return childPath.node.specifiers.some((specifier) => {
331
- const importedName = specifier.local.name;
332
- const binding = scope.getBinding(importedName);
333
- return binding && (binding.referenced || binding.referencePaths.length > 0);
334
- });
335
- }
336
- return false;
337
- });
338
- path3.set(
339
- "body",
340
- filteredBody.map((p) => p.node)
341
- );
342
- }
343
- }
344
- };
345
- }
346
-
347
- // src/build/plugins/remove-unused-references.ts
348
- function recursiveRemoveNonReferencedNodes(code) {
349
- return new Promise(async (resolve2, reject) => {
350
- babel.transform(
351
- code,
352
- {
353
- babelrc: false,
354
- configFile: false,
355
- plugins: [removeNonReferencedNodes()]
356
- },
357
- (err, result) => {
358
- if (err) {
359
- return reject(err);
360
- }
361
- if (result && result.code !== code) {
362
- return recursiveRemoveNonReferencedNodes(result.code).then(resolve2, reject);
363
- }
364
- resolve2({
365
- code: result.code,
366
- map: result.map
367
- });
368
- }
369
- );
370
- });
371
- }
372
- function extractMastraOptionBundler(name, entryFile, transformer, result, logger) {
373
- return rollup({
374
- logLevel: "silent",
375
- input: {
376
- [`${name}-config`]: entryFile
377
- },
378
- treeshake: "smallest",
379
- plugins: [
380
- tsConfigPaths(),
381
- // transpile typescript to something we understand
382
- esbuild(),
383
- optimizeLodashImports({
384
- include: "**/*.{js,ts,mjs,cjs}"
385
- }),
386
- commonjs({
387
- extensions: [".js", ".ts"],
388
- strictRequires: "strict",
389
- transformMixedEsModules: true,
390
- ignoreTryCatch: false
391
- }),
392
- json(),
393
- {
394
- name: `extract-${name}-config`,
395
- transform(code, id) {
396
- if (id !== entryFile) {
397
- return;
398
- }
399
- return new Promise((resolve2, reject) => {
400
- babel.transform(
401
- code,
402
- {
403
- babelrc: false,
404
- configFile: false,
405
- filename: id,
406
- plugins: [transformer(result, logger)]
407
- },
408
- (err, result2) => {
409
- if (err) {
410
- return reject(err);
411
- }
412
- resolve2({
413
- code: result2.code,
414
- map: result2.map
415
- });
416
- }
417
- );
418
- });
419
- }
420
- },
421
- // let esbuild remove all unused imports
422
- esbuild(),
423
- {
424
- name: "cleanup",
425
- transform(code, id) {
426
- if (id !== entryFile) {
427
- return;
428
- }
429
- return recursiveRemoveNonReferencedNodes(code);
430
- }
431
- },
432
- // let esbuild remove it once more
433
- esbuild()
434
- ]
435
- });
436
- }
437
- async function extractMastraOption(name, entryFile, transformer, outputDir, logger) {
438
- const result = {
439
- hasCustomConfig: false
440
- };
441
- const bundler = await extractMastraOptionBundler(name, entryFile, transformer, result, logger);
442
- const output = await bundler.write({
443
- dir: outputDir,
444
- format: "es",
445
- entryFileNames: "[name].mjs"
446
- });
447
- if (result.hasCustomConfig) {
448
- const configPath = `${outputDir}/${name}-config.mjs`;
449
- return {
450
- bundleOutput: output,
451
- getConfig: () => import(`file:${configPath}`).then((m) => m[name])
452
- };
453
- }
454
- return null;
455
- }
456
-
457
- // src/build/bundlerOptions.ts
458
- async function getBundlerOptions(entryFile, outputDir, logger) {
459
- const result = await extractMastraOption(
460
- "bundler",
461
- entryFile,
462
- removeAllOptionsExceptBundler,
463
- outputDir,
464
- logger
465
- );
466
- if (!result) {
467
- return null;
468
- }
469
- return result.getConfig();
470
- }
471
- function checkConfigExport(result) {
472
- const t = babel__default.types;
473
- const mastraVars = /* @__PURE__ */ new Set();
474
- return {
475
- visitor: {
476
- ExportNamedDeclaration(path3) {
477
- const decl = path3.node.declaration;
478
- if (t.isVariableDeclaration(decl)) {
479
- const varDecl = decl.declarations[0];
480
- if (t.isIdentifier(varDecl?.id, { name: "mastra" }) && t.isNewExpression(varDecl.init) && t.isIdentifier(varDecl.init.callee, { name: "Mastra" })) {
481
- result.hasValidConfig = true;
482
- }
483
- }
484
- if (Array.isArray(path3.node.specifiers)) {
485
- for (const spec of path3.node.specifiers) {
486
- if (t.isExportSpecifier(spec) && t.isIdentifier(spec.exported, { name: "mastra" }) && t.isIdentifier(spec.local) && mastraVars.has(spec.local.name)) {
487
- result.hasValidConfig = true;
488
- }
489
- }
490
- }
491
- },
492
- // For cases 2-4 we need to track whether those variables are assigned to `new Mastra()`
493
- VariableDeclaration(path3) {
494
- for (const decl of path3.node.declarations) {
495
- if (t.isIdentifier(decl.id) && t.isNewExpression(decl.init) && t.isIdentifier(decl.init.callee, { name: "Mastra" })) {
496
- mastraVars.add(decl.id.name);
497
- }
498
- }
499
- }
500
- }
501
- };
502
- }
503
- var workspacesCache = createWorkspacesCache();
504
- async function getWorkspaceInformation({
505
- dir = process.cwd(),
506
- mastraEntryFile
507
- }) {
508
- const closestPkgJson = pkg.up({ cwd: dirname(mastraEntryFile) });
509
- const location = closestPkgJson ? dirname(slash(closestPkgJson)) : slash(process.cwd());
510
- const workspaces = await findWorkspaces(dir, { cache: workspacesCache });
511
- const _workspaceMap = new Map(
512
- workspaces?.map((workspace) => [
513
- workspace.package.name,
514
- {
515
- location: workspace.location,
516
- dependencies: workspace.package.dependencies,
517
- version: workspace.package.version
518
- }
519
- ]) ?? []
520
- );
521
- const isWorkspacePackage = (workspaces ?? []).some((ws) => ws.location === location);
522
- const workspaceRoot = isWorkspacePackage ? findWorkspacesRoot(dir, { cache: workspacesCache })?.location : void 0;
523
- return {
524
- // If the current package is not part of the workspace, the bundling down the line shouldn't look at any workspace packages
525
- workspaceMap: isWorkspacePackage ? _workspaceMap : /* @__PURE__ */ new Map(),
526
- workspaceRoot,
527
- isWorkspacePackage
528
- };
529
- }
530
- function isNodeBuiltin(dep) {
531
- const [pkg2] = dep.split("/");
532
- return dep.startsWith("node:") || builtinModules.includes(dep) || builtinModules.includes(pkg2);
533
- }
534
- function removeDeployer() {
535
- const t = babel__default.types;
536
- return {
537
- name: "remove-deployer",
538
- visitor: {
539
- NewExpression(path3, state) {
540
- const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
541
- if (!varDeclaratorPath) {
542
- return;
543
- }
544
- const parentNode = path3.parentPath.node;
545
- if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
546
- return;
547
- }
548
- if (!state.hasReplaced) {
549
- state.hasReplaced = true;
550
- const newMastraObj = t.cloneNode(path3.node);
551
- if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.[0]) {
552
- const deployer = newMastraObj.arguments[0].properties.find(
553
- (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
554
- );
555
- if (!deployer) {
556
- return;
557
- }
558
- newMastraObj.arguments[0].properties = newMastraObj.arguments[0].properties.filter(
559
- (prop) => prop !== deployer
560
- );
561
- if (t.isObjectProperty(deployer) && t.isIdentifier(deployer.value)) {
562
- const deployerBinding = state.file.scope.getBinding(deployer.value.name);
563
- if (deployerBinding) {
564
- deployerBinding?.path?.parentPath?.remove();
565
- }
566
- }
567
- path3.replaceWith(newMastraObj);
568
- }
569
- }
570
- }
571
- }
572
- };
573
- }
574
-
575
- // src/build/plugins/remove-deployer.ts
576
- function removeDeployer2(mastraEntry, options) {
577
- return {
578
- name: "remove-deployer",
579
- transform(code, id) {
580
- if (id !== mastraEntry) {
581
- return;
582
- }
583
- return new Promise((resolve2, reject) => {
584
- babel.transform(
585
- code,
586
- {
587
- babelrc: false,
588
- configFile: false,
589
- filename: id,
590
- plugins: [removeDeployer],
591
- sourceMaps: options?.sourcemap
592
- },
593
- (err, result) => {
594
- if (err) {
595
- return reject(err);
596
- }
597
- resolve2({
598
- code: result.code,
599
- map: result.map
600
- });
601
- }
602
- );
603
- });
604
- }
605
- };
606
- }
607
-
608
- // src/build/analyze/constants.ts
609
- var DEPS_TO_IGNORE = ["#tools"];
610
- var GLOBAL_EXTERNALS = [
611
- "pino",
612
- "pino-pretty",
613
- "@libsql/client",
614
- "pg",
615
- "libsql",
616
- "#tools",
617
- "typescript",
618
- "undici"
619
- ];
620
- var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
621
-
622
- // src/build/analyze/analyzeEntry.ts
623
- function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
624
- const normalizedMastraEntry = slash(mastraEntry);
625
- let virtualPlugin = null;
626
- if (isVirtualFile) {
627
- virtualPlugin = virtual({
628
- "#entry": entry
629
- });
630
- entry = "#entry";
631
- }
632
- const plugins = [];
633
- if (virtualPlugin) {
634
- plugins.push(virtualPlugin);
635
- }
636
- plugins.push(
637
- ...[
638
- tsConfigPaths(),
639
- {
640
- name: "custom-alias-resolver",
641
- resolveId(id) {
642
- if (id === "#server") {
643
- return slash(fileURLToPath(import.meta.resolve("@mastra/deployer/server")));
644
- }
645
- if (id === "#mastra") {
646
- return normalizedMastraEntry;
647
- }
648
- if (id.startsWith("@mastra/server")) {
649
- return fileURLToPath(import.meta.resolve(id));
650
- }
651
- }
652
- },
653
- json(),
654
- esbuild(),
655
- commonjs({
656
- strictRequires: "debug",
657
- ignoreTryCatch: false,
658
- transformMixedEsModules: true,
659
- extensions: [".js", ".ts"]
660
- }),
661
- removeDeployer2(mastraEntry, { sourcemap: sourcemapEnabled }),
662
- esbuild()
663
- ]
664
- );
665
- return plugins;
666
- }
667
- async function captureDependenciesToOptimize(output, workspaceMap, projectRoot, {
668
- logger
669
- }) {
670
- const depsToOptimize = /* @__PURE__ */ new Map();
671
- if (!output.facadeModuleId) {
672
- throw new Error(
673
- "Something went wrong, we could not find the package name of the entry file. Please open an issue."
674
- );
675
- }
676
- let entryRootPath = projectRoot;
677
- if (!output.facadeModuleId.startsWith("\0virtual:")) {
678
- entryRootPath = await getPackageRootPath(output.facadeModuleId) || projectRoot;
679
- }
680
- for (const [dependency, bindings] of Object.entries(output.importedBindings)) {
681
- if (isNodeBuiltin(dependency) || DEPS_TO_IGNORE.includes(dependency)) {
682
- continue;
683
- }
684
- const pkgName = getPackageName(dependency);
685
- let rootPath = null;
686
- let isWorkspace = false;
687
- if (pkgName) {
688
- rootPath = await getPackageRootPath(dependency, entryRootPath);
689
- isWorkspace = workspaceMap.has(pkgName);
690
- }
691
- const normalizedRootPath = rootPath ? slash(rootPath) : null;
692
- depsToOptimize.set(dependency, { exports: bindings, rootPath: normalizedRootPath, isWorkspace });
693
- }
694
- async function checkTransitiveDependencies(internalMap, maxDepth = 10, currentDepth = 0) {
695
- if (currentDepth >= maxDepth) {
696
- logger.warn("Maximum dependency depth reached while checking transitive dependencies.");
697
- return;
698
- }
699
- const depsSnapshot = new Map(depsToOptimize);
700
- let hasAddedDeps = false;
701
- for (const [dep, meta] of depsSnapshot) {
702
- if (!meta.isWorkspace || internalMap.has(dep)) {
703
- continue;
704
- }
705
- try {
706
- const resolvedPath = resolveFrom2(projectRoot, dep);
707
- if (!resolvedPath) {
708
- logger.warn(`Could not resolve path for workspace dependency ${dep}`);
709
- continue;
710
- }
711
- const analysis = await analyzeEntry({ entry: resolvedPath, isVirtualFile: false }, "", {
712
- workspaceMap,
713
- projectRoot,
714
- logger: noopLogger,
715
- sourcemapEnabled: false
716
- });
717
- if (!analysis?.dependencies) {
718
- continue;
719
- }
720
- for (const [innerDep, innerMeta] of analysis.dependencies) {
721
- if (innerMeta.isWorkspace && !internalMap.has(innerDep) && !depsToOptimize.has(innerDep)) {
722
- depsToOptimize.set(innerDep, innerMeta);
723
- internalMap.set(innerDep, innerMeta);
724
- hasAddedDeps = true;
725
- }
726
- }
727
- } catch (err) {
728
- logger.error(`Failed to resolve or analyze dependency ${dep}: ${err.message}`);
729
- }
730
- }
731
- if (hasAddedDeps) {
732
- await checkTransitiveDependencies(internalMap, maxDepth, currentDepth + 1);
733
- }
734
- }
735
- await checkTransitiveDependencies(/* @__PURE__ */ new Map());
736
- const dynamicImports = output.dynamicImports.filter((d) => !DEPS_TO_IGNORE.includes(d));
737
- if (dynamicImports.length) {
738
- for (const dynamicImport of dynamicImports) {
739
- if (!depsToOptimize.has(dynamicImport) && !isNodeBuiltin(dynamicImport)) {
740
- depsToOptimize.set(dynamicImport, { exports: ["*"], rootPath: null, isWorkspace: false });
741
- }
742
- }
743
- }
744
- return depsToOptimize;
745
- }
746
- async function analyzeEntry({
747
- entry,
748
- isVirtualFile
749
- }, mastraEntry, {
750
- logger,
751
- sourcemapEnabled,
752
- workspaceMap,
753
- projectRoot
754
- }) {
755
- const optimizerBundler = await rollup({
756
- logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
757
- input: isVirtualFile ? "#entry" : entry,
758
- treeshake: "smallest",
759
- preserveSymlinks: true,
760
- plugins: getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }),
761
- external: DEPS_TO_IGNORE
762
- });
763
- const { output } = await optimizerBundler.generate({
764
- format: "esm",
765
- inlineDynamicImports: true
766
- });
767
- await optimizerBundler.close();
768
- const depsToOptimize = await captureDependenciesToOptimize(output[0], workspaceMap, projectRoot, {
769
- logger
770
- });
771
- return {
772
- dependencies: depsToOptimize,
773
- output: {
774
- code: output[0].code,
775
- map: output[0].map
776
- }
777
- };
778
- }
779
- function aliasHono() {
780
- return {
781
- name: "hono-alias",
782
- resolveId(id) {
783
- if (!id.startsWith("@hono/") && !id.startsWith("hono/") && id !== "hono" && id !== "hono-openapi") {
784
- return;
785
- }
786
- const path3 = import.meta.resolve(id);
787
- return fileURLToPath(path3);
788
- }
789
- };
790
- }
791
- function prepareEntryFileName(name, rootDir) {
792
- return rollupSafeName(name, rootDir);
793
- }
794
- function createVirtualDependencies(depsToOptimize, {
795
- projectRoot,
796
- workspaceRoot,
797
- outputDir,
798
- bundlerOptions
799
- }) {
800
- const { isDev = false } = bundlerOptions || {};
801
- const fileNameToDependencyMap = /* @__PURE__ */ new Map();
802
- const optimizedDependencyEntries = /* @__PURE__ */ new Map();
803
- const rootDir = workspaceRoot || projectRoot;
804
- for (const [dep, { exports: exports2 }] of depsToOptimize.entries()) {
805
- const fileName = dep.replaceAll("/", "-");
806
- const virtualFile = [];
807
- const exportStringBuilder = [];
808
- for (const local of exports2) {
809
- if (local === "*") {
810
- virtualFile.push(`export * from '${dep}';`);
811
- continue;
812
- } else if (local === "default") {
813
- exportStringBuilder.push("default");
814
- } else {
815
- exportStringBuilder.push(local);
816
- }
817
- }
818
- const chunks = [];
819
- if (exportStringBuilder.length) {
820
- chunks.push(`{ ${exportStringBuilder.join(", ")} }`);
821
- }
822
- if (chunks.length) {
823
- virtualFile.push(`export ${chunks.join(", ")} from '${dep}';`);
824
- }
825
- let entryName = prepareEntryFileName(path2.join(outputDir, fileName), rootDir);
826
- fileNameToDependencyMap.set(entryName, dep);
827
- optimizedDependencyEntries.set(dep, {
828
- name: entryName,
829
- virtual: virtualFile.join("\n")
830
- });
831
- }
832
- if (isDev) {
833
- for (const [dep, { isWorkspace, rootPath }] of depsToOptimize.entries()) {
834
- if (!isWorkspace || !rootPath || !workspaceRoot) {
835
- continue;
836
- }
837
- const currentDepPath = optimizedDependencyEntries.get(dep);
838
- if (!currentDepPath) {
839
- continue;
840
- }
841
- const fileName = basename(currentDepPath.name);
842
- const entryName = prepareEntryFileName(getCompiledDepCachePath(rootPath, fileName), rootDir);
843
- fileNameToDependencyMap.set(entryName, dep);
844
- optimizedDependencyEntries.set(dep, {
845
- ...currentDepPath,
846
- name: entryName
847
- });
848
- }
849
- }
850
- return { optimizedDependencyEntries, fileNameToDependencyMap };
851
- }
852
- async function getInputPlugins2(virtualDependencies, {
853
- transpilePackages,
854
- workspaceMap,
855
- bundlerOptions,
856
- rootDir
857
- }) {
858
- const transpilePackagesMap = /* @__PURE__ */ new Map();
859
- for (const pkg2 of transpilePackages) {
860
- const dir = await getPackageRootPath(pkg2);
861
- if (dir) {
862
- transpilePackagesMap.set(pkg2, slash(dir));
863
- } else {
864
- transpilePackagesMap.set(pkg2, workspaceMap.get(pkg2)?.location ?? pkg2);
865
- }
866
- }
867
- return [
868
- virtual(
869
- Array.from(virtualDependencies.entries()).reduce(
870
- (acc, [dep, virtualDep]) => {
871
- acc[`#virtual-${dep}`] = virtualDep.virtual;
872
- return acc;
873
- },
874
- {}
875
- )
876
- ),
877
- transpilePackagesMap.size ? esbuild({
878
- format: "esm",
879
- include: [...transpilePackagesMap.values()].map((p) => {
880
- if (path2.isAbsolute(p)) {
881
- return new RegExp(`^${p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/(?!.*node_modules).*$`);
882
- } else {
883
- return new RegExp(`/${p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/(?!.*node_modules).*$`);
884
- }
885
- })
886
- }) : null,
887
- bundlerOptions.isDev ? {
888
- name: "alias-optimized-deps",
889
- async resolveId(id, importer, options) {
890
- if (!virtualDependencies.has(id)) {
891
- return null;
892
- }
893
- const info = virtualDependencies.get(id);
894
- const packageRootPath = path2.join(rootDir, path2.dirname(path2.dirname(path2.dirname(info.name))));
895
- const pkgJsonBuffer = await readFile(path2.join(packageRootPath, "package.json"), "utf-8");
896
- const pkgJson = JSON.parse(pkgJsonBuffer);
897
- if (!pkgJson) {
898
- return null;
899
- }
900
- const pkgName = pkgJson.name || "";
901
- let resolvedPath = resolve.exports(pkgJson, id.replace(pkgName, "."))?.[0];
902
- if (!resolvedPath) {
903
- resolvedPath = pkgJson.main ?? "index.js";
904
- }
905
- return await this.resolve(path2.posix.join(packageRootPath, resolvedPath), importer, options);
906
- }
907
- } : null,
908
- optimizeLodashImports({
909
- include: "**/*.{js,ts,mjs,cjs}"
910
- }),
911
- commonjs({
912
- strictRequires: "strict",
913
- transformMixedEsModules: true,
914
- ignoreTryCatch: false
915
- }),
916
- bundlerOptions.isDev ? null : nodeResolve(),
917
- bundlerOptions.isDev ? esmShim() : null,
918
- // hono is imported from deployer, so we need to resolve from here instead of the project root
919
- aliasHono(),
920
- json(),
921
- {
922
- name: "not-found-resolver",
923
- resolveId: {
924
- order: "post",
925
- async handler(id, importer) {
926
- if (!importer) {
927
- return null;
928
- }
929
- if (!id.endsWith(".node")) {
930
- return null;
931
- }
932
- const pkgInfo = await getPackageInfo(importer);
933
- const packageName = pkgInfo?.packageJson?.name || id;
934
- throw new MastraBaseError({
935
- id: "DEPLOYER_BUNDLE_EXTERNALS_MISSING_NATIVE_BUILD",
936
- domain: ErrorDomain.DEPLOYER,
937
- category: ErrorCategory.USER,
938
- details: {
939
- importFile: importer,
940
- packageName
941
- },
942
- text: `We found a binary dependency in your bundle. Please add \`${packageName}\` to your externals.
943
-
944
- export const mastra = new Mastra({
945
- bundler: {
946
- externals: ["${packageName}"],
947
- }
948
- })`
949
- });
950
- }
951
- }
952
- }
953
- ].filter(Boolean);
954
- }
955
- async function buildExternalDependencies(virtualDependencies, {
956
- externals,
957
- packagesToTranspile,
958
- workspaceMap,
959
- rootDir,
960
- outputDir,
961
- bundlerOptions
962
- }) {
963
- if (virtualDependencies.size === 0) {
964
- return [];
965
- }
966
- const bundler = await rollup({
967
- logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
968
- input: Array.from(virtualDependencies.entries()).reduce(
969
- (acc, [dep, virtualDep]) => {
970
- acc[virtualDep.name] = `#virtual-${dep}`;
971
- return acc;
972
- },
973
- {}
974
- ),
975
- external: externals,
976
- treeshake: "smallest",
977
- plugins: getInputPlugins2(virtualDependencies, {
978
- transpilePackages: packagesToTranspile,
979
- workspaceMap,
980
- bundlerOptions,
981
- rootDir
982
- })
983
- });
984
- const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
985
- const { output } = await bundler.write({
986
- format: "esm",
987
- dir: rootDir,
988
- entryFileNames: "[name].mjs",
989
- /**
990
- * Rollup creates chunks for common dependencies, but these chunks are by default written to the root directory instead of respecting the entryFileNames structure.
991
- * So we want to write them to the `.mastra/output` folder as well.
992
- */
993
- chunkFileNames: (chunkInfo) => {
994
- if (bundlerOptions.isDev) {
995
- const importedFromPackages = /* @__PURE__ */ new Set();
996
- for (const moduleId of chunkInfo.moduleIds) {
997
- const normalized = slash(moduleId);
998
- for (const [pkgName, pkgInfo] of workspaceMap.entries()) {
999
- const location = slash(pkgInfo.location);
1000
- if (normalized.startsWith(location)) {
1001
- importedFromPackages.add(pkgName);
1002
- break;
1003
- }
1004
- }
1005
- }
1006
- if (importedFromPackages.size > 1) {
1007
- throw new MastraBaseError({
1008
- id: "DEPLOYER_BUNDLE_EXTERNALS_SHARED_CHUNK",
1009
- domain: ErrorDomain.DEPLOYER,
1010
- category: ErrorCategory.USER,
1011
- details: {
1012
- chunkName: chunkInfo.name,
1013
- packages: JSON.stringify(Array.from(importedFromPackages))
1014
- },
1015
- text: `Please open an issue. We found a shared chunk "${chunkInfo.name}" used by multiple workspace packages: ${Array.from(importedFromPackages).join(", ")}.`
1016
- });
1017
- }
1018
- if (importedFromPackages.size === 1) {
1019
- const [pkgName] = importedFromPackages;
1020
- const workspaceLocation = workspaceMap.get(pkgName).location;
1021
- return prepareEntryFileName(getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
1022
- }
1023
- }
1024
- return `${outputDirRelative}/[name].mjs`;
1025
- },
1026
- hoistTransitiveImports: false
1027
- });
1028
- await bundler.close();
1029
- return output;
1030
- }
1031
- function findExternalImporter(module, external, allOutputs) {
1032
- const capturedFiles = /* @__PURE__ */ new Set();
1033
- for (const id of module.imports) {
1034
- if (id === external) {
1035
- return module;
1036
- } else {
1037
- if (id.endsWith(".mjs")) {
1038
- capturedFiles.add(id);
1039
- }
1040
- }
1041
- }
1042
- for (const file of capturedFiles) {
1043
- const nextModule = allOutputs.find((o) => o.fileName === file);
1044
- if (nextModule) {
1045
- const importer = findExternalImporter(nextModule, external, allOutputs);
1046
- if (importer) {
1047
- return importer;
1048
- }
1049
- }
1050
- }
1051
- return null;
1052
- }
1053
- async function bundleExternals(depsToOptimize, outputDir, options) {
1054
- const { workspaceRoot = null, workspaceMap = /* @__PURE__ */ new Map(), projectRoot = outputDir, bundlerOptions = {} } = options;
1055
- const {
1056
- externals: customExternals = [],
1057
- transpilePackages = [],
1058
- isDev = false} = bundlerOptions || {};
1059
- const allExternals = [...GLOBAL_EXTERNALS, ...DEPRECATED_EXTERNALS, ...customExternals];
1060
- const workspacePackagesNames = Array.from(workspaceMap.keys());
1061
- const packagesToTranspile = /* @__PURE__ */ new Set([...transpilePackages, ...workspacePackagesNames]);
1062
- const { optimizedDependencyEntries, fileNameToDependencyMap } = createVirtualDependencies(depsToOptimize, {
1063
- workspaceRoot,
1064
- outputDir,
1065
- projectRoot,
1066
- bundlerOptions: {
1067
- isDev
1068
- }
1069
- });
1070
- const output = await buildExternalDependencies(optimizedDependencyEntries, {
1071
- externals: allExternals,
1072
- packagesToTranspile,
1073
- workspaceMap,
1074
- rootDir: workspaceRoot || projectRoot,
1075
- outputDir,
1076
- bundlerOptions: {
1077
- isDev
1078
- }
1079
- });
1080
- const moduleResolveMap = /* @__PURE__ */ new Map();
1081
- const filteredChunks = output.filter((o) => o.type === "chunk");
1082
- for (const o of filteredChunks.filter((o2) => o2.isEntry || o2.isDynamicEntry)) {
1083
- for (const external of allExternals) {
1084
- if (DEPS_TO_IGNORE.includes(external)) {
1085
- continue;
1086
- }
1087
- const importer = findExternalImporter(o, external, filteredChunks);
1088
- if (importer) {
1089
- const fullPath = path2.join(workspaceRoot || projectRoot, importer.fileName);
1090
- let innerMap = moduleResolveMap.get(fullPath);
1091
- if (!innerMap) {
1092
- innerMap = /* @__PURE__ */ new Map();
1093
- moduleResolveMap.set(fullPath, innerMap);
1094
- }
1095
- if (importer.moduleIds.length) {
1096
- innerMap.set(
1097
- external,
1098
- importer.moduleIds[importer.moduleIds.length - 1]?.startsWith("\0virtual:#virtual") ? importer.moduleIds[importer.moduleIds.length - 2] : importer.moduleIds[importer.moduleIds.length - 1]
1099
- );
1100
- }
1101
- }
1102
- }
1103
- }
1104
- const usedExternals = /* @__PURE__ */ Object.create(null);
1105
- for (const [fullPath, innerMap] of moduleResolveMap) {
1106
- const innerObj = /* @__PURE__ */ Object.create(null);
1107
- for (const [external, value] of innerMap) {
1108
- innerObj[external] = value;
1109
- }
1110
- usedExternals[fullPath] = innerObj;
1111
- }
1112
- return { output, fileNameToDependencyMap, usedExternals };
1113
- }
1114
- async function validateOutput({
1115
- output,
1116
- reverseVirtualReferenceMap,
1117
- usedExternals,
1118
- outputDir,
1119
- projectRoot,
1120
- workspaceMap
1121
- }, logger) {
1122
- const result = {
1123
- dependencies: /* @__PURE__ */ new Map(),
1124
- externalDependencies: /* @__PURE__ */ new Set(),
1125
- workspaceMap
1126
- };
1127
- await writeFile(join(outputDir, "module-resolve-map.json"), JSON.stringify(usedExternals, null, 2));
1128
- for (const deps of Object.values(usedExternals)) {
1129
- for (const dep of Object.keys(deps)) {
1130
- result.externalDependencies.add(dep);
1131
- }
1132
- }
1133
- for (const file of output) {
1134
- if (file.type === "asset") {
1135
- continue;
1136
- }
1137
- try {
1138
- logger.debug(`Validating if ${file.fileName} is a valid module.`);
1139
- if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
1140
- result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
1141
- }
1142
- if (!file.isDynamicEntry && file.isEntry) {
1143
- await validate(join(projectRoot, file.fileName));
1144
- }
1145
- } catch (err) {
1146
- if (err instanceof Error && err.message.includes("Error: No native build was found for ")) {
1147
- const moduleName = findNativePackageModule(file.moduleIds);
1148
- if (!moduleName) {
1149
- logger.debug(`Could not determine the module name for file ${file.fileName}`);
1150
- continue;
1151
- }
1152
- const pkgInfo = await getPackageInfo(moduleName);
1153
- const packageName = pkgInfo?.packageJson?.name;
1154
- if (packageName) {
1155
- throw new MastraError({
1156
- id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
1157
- domain: ErrorDomain.DEPLOYER,
1158
- category: ErrorCategory.USER,
1159
- details: {
1160
- importFile: moduleName,
1161
- packageName
1162
- },
1163
- text: `We found a binary dependency in your bundle. Please add \`${packageName}\` to your externals.
1164
-
1165
- export const mastra = new Mastra({
1166
- bundler: {
1167
- externals: ["${packageName}"],
1168
- }
1169
- })`
1170
- });
1171
- }
1172
- }
1173
- }
1174
- }
1175
- return result;
1176
- }
1177
- async function analyzeBundle(entries, mastraEntry, {
1178
- outputDir,
1179
- projectRoot,
1180
- isDev = false,
1181
- bundlerOptions: _bundlerOptions
1182
- }, logger) {
1183
- const mastraConfig = await readFile(mastraEntry, "utf-8");
1184
- const mastraConfigResult = {
1185
- hasValidConfig: false
1186
- };
1187
- await babel.transformAsync(mastraConfig, {
1188
- filename: mastraEntry,
1189
- presets: [import.meta.resolve("@babel/preset-typescript")],
1190
- plugins: [checkConfigExport(mastraConfigResult)]
1191
- });
1192
- if (!mastraConfigResult.hasValidConfig) {
1193
- logger.warn(`Invalid Mastra config. Please make sure that your entry file looks like this:
1194
- export const mastra = new Mastra({
1195
- // your options
1196
- })
1197
-
1198
- If you think your configuration is valid, please open an issue.`);
1199
- }
1200
- const { enableEsmShim = true } = _bundlerOptions || {};
1201
- const bundlerOptions = await getBundlerOptions(mastraEntry, outputDir);
1202
- const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
1203
- let index = 0;
1204
- const depsToOptimize = /* @__PURE__ */ new Map();
1205
- logger.info("Analyzing dependencies...");
1206
- for (const entry of entries) {
1207
- const isVirtualFile = entry.includes("\n") || !existsSync(entry);
1208
- const analyzeResult = await analyzeEntry({ entry, isVirtualFile }, mastraEntry, {
1209
- logger,
1210
- sourcemapEnabled: bundlerOptions?.sourcemap ?? false,
1211
- workspaceMap,
1212
- projectRoot
1213
- });
1214
- await writeFile(join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
1215
- for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
1216
- if (depsToOptimize.has(dep)) {
1217
- const existingEntry = depsToOptimize.get(dep);
1218
- depsToOptimize.set(dep, {
1219
- ...existingEntry,
1220
- exports: [.../* @__PURE__ */ new Set([...existingEntry.exports, ...metadata.exports])]
1221
- });
1222
- } else {
1223
- depsToOptimize.set(dep, metadata);
1224
- }
1225
- }
1226
- }
1227
- if (isDev) {
1228
- for (const [dep, metadata] of depsToOptimize.entries()) {
1229
- if (!metadata.isWorkspace) {
1230
- depsToOptimize.delete(dep);
1231
- }
1232
- }
1233
- }
1234
- logger.debug(`Analyzed dependencies: ${Array.from(depsToOptimize.keys()).join(", ")}`);
1235
- logger.info("Optimizing dependencies...");
1236
- logger.debug(
1237
- `${Array.from(depsToOptimize.keys()).map((key) => `- ${key}`).join("\n")}`
1238
- );
1239
- const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
1240
- bundlerOptions: {
1241
- ...bundlerOptions,
1242
- enableEsmShim,
1243
- isDev
1244
- },
1245
- projectRoot,
1246
- workspaceRoot,
1247
- workspaceMap
1248
- });
1249
- const result = await validateOutput(
1250
- {
1251
- output,
1252
- reverseVirtualReferenceMap: fileNameToDependencyMap,
1253
- usedExternals,
1254
- outputDir,
1255
- projectRoot: workspaceRoot || projectRoot,
1256
- workspaceMap
1257
- },
1258
- logger
1259
- );
1260
- return result;
1261
- }
1262
-
1263
- export { aliasHono, analyzeBundle, esbuild, extractMastraOption, getBundlerOptions, getPackageName, getPackageRootPath, getWorkspaceInformation, removeAllOptionsFromMastraExcept, removeDeployer2 as removeDeployer, slash, tsConfigPaths };
1264
- //# sourceMappingURL=chunk-CEXVMFUD.js.map
1265
- //# sourceMappingURL=chunk-CEXVMFUD.js.map