@mastra/deployer 1.54.0-alpha.0 → 1.54.0-alpha.2

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 (211) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/analyze-C2q7jxbN.js +1308 -0
  3. package/dist/analyze-C2q7jxbN.js.map +1 -0
  4. package/dist/analyze-DhDZW9TS.cjs +1318 -0
  5. package/dist/analyze-DhDZW9TS.cjs.map +1 -0
  6. package/dist/arktype-aI7TBD0R-BsgjPZ4a.cjs +8 -0
  7. package/dist/arktype-aI7TBD0R-BsgjPZ4a.cjs.map +1 -0
  8. package/dist/arktype-aI7TBD0R-_UZl-wsH.js +8 -0
  9. package/dist/arktype-aI7TBD0R-_UZl-wsH.js.map +1 -0
  10. package/dist/build/analyze/constants.d.ts.map +1 -1
  11. package/dist/build/analyze.cjs +3 -12
  12. package/dist/build/analyze.js +2 -3
  13. package/dist/build/bundler.cjs +6 -24
  14. package/dist/build/bundler.js +2 -3
  15. package/dist/build/index.cjs +29 -101
  16. package/dist/build/index.js +7 -8
  17. package/dist/build-De4AZhfJ.cjs +908 -0
  18. package/dist/build-De4AZhfJ.cjs.map +1 -0
  19. package/dist/build-KCOeHd4N.js +834 -0
  20. package/dist/build-KCOeHd4N.js.map +1 -0
  21. package/dist/bundler/index.cjs +318 -13
  22. package/dist/bundler/index.cjs.map +1 -1
  23. package/dist/bundler/index.js +314 -2
  24. package/dist/bundler/index.js.map +1 -1
  25. package/dist/bundler-BqrDXofn.cjs +792 -0
  26. package/dist/bundler-BqrDXofn.cjs.map +1 -0
  27. package/dist/bundler-D86rFu2J.js +705 -0
  28. package/dist/bundler-D86rFu2J.js.map +1 -0
  29. package/dist/bundlerOptions-aFsEi86t.js +180 -0
  30. package/dist/bundlerOptions-aFsEi86t.js.map +1 -0
  31. package/dist/bundlerOptions-rBmtSyGe.cjs +194 -0
  32. package/dist/bundlerOptions-rBmtSyGe.cjs.map +1 -0
  33. package/dist/core-D0wEgdn3.cjs +790 -0
  34. package/dist/core-D0wEgdn3.cjs.map +1 -0
  35. package/dist/core-DF65PJXc.js +790 -0
  36. package/dist/core-DF65PJXc.js.map +1 -0
  37. package/dist/dist-BauTimif.js +532 -0
  38. package/dist/dist-BauTimif.js.map +1 -0
  39. package/dist/dist-Cv-mAEtr.cjs +532 -0
  40. package/dist/dist-Cv-mAEtr.cjs.map +1 -0
  41. package/dist/docs/SKILL.md +1 -1
  42. package/dist/docs/assets/SOURCE_MAP.json +2 -23
  43. package/dist/docs/references/docs-deployment-cloud-providers.md +1 -0
  44. package/dist/docs/references/docs-deployment-overview.md +1 -0
  45. package/dist/effect-QlVUlMFu-CwFnyS-g.cjs +14 -0
  46. package/dist/effect-QlVUlMFu-CwFnyS-g.cjs.map +1 -0
  47. package/dist/effect-QlVUlMFu-gyLQRCtQ.js +14 -0
  48. package/dist/effect-QlVUlMFu-gyLQRCtQ.js.map +1 -0
  49. package/dist/esm-BX-weMyC.js +4634 -0
  50. package/dist/esm-BX-weMyC.js.map +1 -0
  51. package/dist/esm-D81PZ_wJ.cjs +4634 -0
  52. package/dist/esm-D81PZ_wJ.cjs.map +1 -0
  53. package/dist/index-CLddUTqr-B5mOP6DC.cjs +145 -0
  54. package/dist/index-CLddUTqr-B5mOP6DC.cjs.map +1 -0
  55. package/dist/index-CLddUTqr-CkS6Y_hA.js +140 -0
  56. package/dist/index-CLddUTqr-CkS6Y_hA.js.map +1 -0
  57. package/dist/index.cjs +35 -48
  58. package/dist/index.cjs.map +1 -1
  59. package/dist/index.js +29 -30
  60. package/dist/index.js.map +1 -1
  61. package/dist/rolldown-runtime-emK7D4bc.cjs +35 -0
  62. package/dist/server/index.cjs +3141 -3874
  63. package/dist/server/index.cjs.map +1 -1
  64. package/dist/server/index.d.ts.map +1 -1
  65. package/dist/server/index.js +3131 -3842
  66. package/dist/server/index.js.map +1 -1
  67. package/dist/server/types.d.ts +1 -0
  68. package/dist/server/types.d.ts.map +1 -1
  69. package/dist/services/index.cjs +5 -20
  70. package/dist/services/index.js +2 -3
  71. package/dist/services-BxYMLS9-.cjs +430 -0
  72. package/dist/services-BxYMLS9-.cjs.map +1 -0
  73. package/dist/services-CLi56qqe.js +391 -0
  74. package/dist/services-CLi56qqe.js.map +1 -0
  75. package/dist/sury-CWZTCd75-B85M6878.js +14 -0
  76. package/dist/sury-CWZTCd75-B85M6878.js.map +1 -0
  77. package/dist/sury-CWZTCd75-DTj5HlK_.cjs +14 -0
  78. package/dist/sury-CWZTCd75-DTj5HlK_.cjs.map +1 -0
  79. package/dist/typebox-Dei93FPO-BeuT13_G.cjs +8 -0
  80. package/dist/typebox-Dei93FPO-BeuT13_G.cjs.map +1 -0
  81. package/dist/typebox-Dei93FPO-DovwMlVl.js +8 -0
  82. package/dist/typebox-Dei93FPO-DovwMlVl.js.map +1 -0
  83. package/dist/utils-FVOUvj-I.js +190 -0
  84. package/dist/utils-FVOUvj-I.js.map +1 -0
  85. package/dist/utils-O98BGdnP.cjs +267 -0
  86. package/dist/utils-O98BGdnP.cjs.map +1 -0
  87. package/dist/valibot--1zFm7rT-BqJHja5B.cjs +14 -0
  88. package/dist/valibot--1zFm7rT-BqJHja5B.cjs.map +1 -0
  89. package/dist/valibot--1zFm7rT-Y4Fhea0w.js +14 -0
  90. package/dist/valibot--1zFm7rT-Y4Fhea0w.js.map +1 -0
  91. package/dist/validator/custom-resolver.cjs +71 -73
  92. package/dist/validator/custom-resolver.cjs.map +1 -1
  93. package/dist/validator/custom-resolver.js +70 -71
  94. package/dist/validator/custom-resolver.js.map +1 -1
  95. package/dist/validator/loader.cjs +6 -7
  96. package/dist/validator/loader.cjs.map +1 -1
  97. package/dist/validator/loader.js +8 -4
  98. package/dist/validator/loader.js.map +1 -1
  99. package/dist/zod-Bwrt9trS-2JL6_UI_.cjs +23 -0
  100. package/dist/zod-Bwrt9trS-2JL6_UI_.cjs.map +1 -0
  101. package/dist/zod-Bwrt9trS-rVHICsmp.js +23 -0
  102. package/dist/zod-Bwrt9trS-rVHICsmp.js.map +1 -0
  103. package/package.json +7 -7
  104. package/dist/arktype-aI7TBD0R-K3QZAVE2.js +0 -8
  105. package/dist/arktype-aI7TBD0R-K3QZAVE2.js.map +0 -1
  106. package/dist/arktype-aI7TBD0R-WK5AZZMC.cjs +0 -10
  107. package/dist/arktype-aI7TBD0R-WK5AZZMC.cjs.map +0 -1
  108. package/dist/build/analyze.cjs.map +0 -1
  109. package/dist/build/analyze.js.map +0 -1
  110. package/dist/build/bundler.cjs.map +0 -1
  111. package/dist/build/bundler.js.map +0 -1
  112. package/dist/build/index.cjs.map +0 -1
  113. package/dist/build/index.js.map +0 -1
  114. package/dist/chunk-36AWZH7Z.cjs +0 -252
  115. package/dist/chunk-36AWZH7Z.cjs.map +0 -1
  116. package/dist/chunk-3XIMK24X.cjs +0 -765
  117. package/dist/chunk-3XIMK24X.cjs.map +0 -1
  118. package/dist/chunk-46M65MQG.cjs +0 -95
  119. package/dist/chunk-46M65MQG.cjs.map +0 -1
  120. package/dist/chunk-4ZNTNJ6T.js +0 -6
  121. package/dist/chunk-4ZNTNJ6T.js.map +0 -1
  122. package/dist/chunk-5PORNUPF.js +0 -739
  123. package/dist/chunk-5PORNUPF.js.map +0 -1
  124. package/dist/chunk-743HRNWT.cjs +0 -1546
  125. package/dist/chunk-743HRNWT.cjs.map +0 -1
  126. package/dist/chunk-AEQ7JHDB.cjs +0 -412
  127. package/dist/chunk-AEQ7JHDB.cjs.map +0 -1
  128. package/dist/chunk-E5SBYHQK.js +0 -244
  129. package/dist/chunk-E5SBYHQK.js.map +0 -1
  130. package/dist/chunk-FKKJQUGR.cjs +0 -497
  131. package/dist/chunk-FKKJQUGR.cjs.map +0 -1
  132. package/dist/chunk-FQHUOYYL.js +0 -1514
  133. package/dist/chunk-FQHUOYYL.js.map +0 -1
  134. package/dist/chunk-G7MIMGMX.js +0 -14
  135. package/dist/chunk-G7MIMGMX.js.map +0 -1
  136. package/dist/chunk-HZC3PTK2.cjs +0 -16
  137. package/dist/chunk-HZC3PTK2.cjs.map +0 -1
  138. package/dist/chunk-JZRFRUGM.cjs +0 -158
  139. package/dist/chunk-JZRFRUGM.cjs.map +0 -1
  140. package/dist/chunk-L45X3DJX.js +0 -385
  141. package/dist/chunk-L45X3DJX.js.map +0 -1
  142. package/dist/chunk-PC25XSK7.cjs +0 -8
  143. package/dist/chunk-PC25XSK7.cjs.map +0 -1
  144. package/dist/chunk-PZ5AY32C.js +0 -9
  145. package/dist/chunk-PZ5AY32C.js.map +0 -1
  146. package/dist/chunk-Q7SFCCGT.cjs +0 -11
  147. package/dist/chunk-Q7SFCCGT.cjs.map +0 -1
  148. package/dist/chunk-T4UT2QX7.js +0 -3
  149. package/dist/chunk-T4UT2QX7.js.map +0 -1
  150. package/dist/chunk-UBIDJOJA.js +0 -93
  151. package/dist/chunk-UBIDJOJA.js.map +0 -1
  152. package/dist/chunk-V3EKV6QB.cjs +0 -162
  153. package/dist/chunk-V3EKV6QB.cjs.map +0 -1
  154. package/dist/chunk-WHD2QQ3N.js +0 -783
  155. package/dist/chunk-WHD2QQ3N.js.map +0 -1
  156. package/dist/chunk-WP65JQAT.js +0 -144
  157. package/dist/chunk-WP65JQAT.js.map +0 -1
  158. package/dist/chunk-YO5OFXPN.cjs +0 -819
  159. package/dist/chunk-YO5OFXPN.cjs.map +0 -1
  160. package/dist/chunk-YUBKHO52.js +0 -465
  161. package/dist/chunk-YUBKHO52.js.map +0 -1
  162. package/dist/chunk-YWMYXUHX.cjs +0 -4
  163. package/dist/chunk-YWMYXUHX.cjs.map +0 -1
  164. package/dist/chunk-ZKZOVNT4.js +0 -159
  165. package/dist/chunk-ZKZOVNT4.js.map +0 -1
  166. package/dist/core-XIDAXLRB.js +0 -11866
  167. package/dist/core-XIDAXLRB.js.map +0 -1
  168. package/dist/core-XJNQ4AY6.cjs +0 -12141
  169. package/dist/core-XJNQ4AY6.cjs.map +0 -1
  170. package/dist/default-u_dwuiYb-HGUAHA6N.cjs +0 -9
  171. package/dist/default-u_dwuiYb-HGUAHA6N.cjs.map +0 -1
  172. package/dist/default-u_dwuiYb-MVPTVDCE.js +0 -3
  173. package/dist/default-u_dwuiYb-MVPTVDCE.js.map +0 -1
  174. package/dist/dist-UEE5OLII.cjs +0 -521
  175. package/dist/dist-UEE5OLII.cjs.map +0 -1
  176. package/dist/dist-X75F2Q36.js +0 -515
  177. package/dist/dist-X75F2Q36.js.map +0 -1
  178. package/dist/effect-QlVUlMFu-QNLZLGWO.js +0 -15
  179. package/dist/effect-QlVUlMFu-QNLZLGWO.js.map +0 -1
  180. package/dist/effect-QlVUlMFu-XUD6EH23.cjs +0 -17
  181. package/dist/effect-QlVUlMFu-XUD6EH23.cjs.map +0 -1
  182. package/dist/esm-DFCHSIJZ.cjs +0 -1589
  183. package/dist/esm-DFCHSIJZ.cjs.map +0 -1
  184. package/dist/esm-PXGQ5WB4.js +0 -1542
  185. package/dist/esm-PXGQ5WB4.js.map +0 -1
  186. package/dist/services/index.cjs.map +0 -1
  187. package/dist/services/index.js.map +0 -1
  188. package/dist/sury-CWZTCd75-3KQQJ22C.cjs +0 -17
  189. package/dist/sury-CWZTCd75-3KQQJ22C.cjs.map +0 -1
  190. package/dist/sury-CWZTCd75-DZQHKAZF.js +0 -15
  191. package/dist/sury-CWZTCd75-DZQHKAZF.js.map +0 -1
  192. package/dist/typebox-Dei93FPO-GOYJ5OUT.js +0 -8
  193. package/dist/typebox-Dei93FPO-GOYJ5OUT.js.map +0 -1
  194. package/dist/typebox-Dei93FPO-M7J7E57W.cjs +0 -10
  195. package/dist/typebox-Dei93FPO-M7J7E57W.cjs.map +0 -1
  196. package/dist/valibot--1zFm7rT-NVM3G3TI.cjs +0 -17
  197. package/dist/valibot--1zFm7rT-NVM3G3TI.cjs.map +0 -1
  198. package/dist/valibot--1zFm7rT-ZVGQI7WV.js +0 -15
  199. package/dist/valibot--1zFm7rT-ZVGQI7WV.js.map +0 -1
  200. package/dist/valibot-D_HTw1Gn-UCPEGDL7.cjs +0 -45
  201. package/dist/valibot-D_HTw1Gn-UCPEGDL7.cjs.map +0 -1
  202. package/dist/valibot-D_HTw1Gn-XPR4F6VS.js +0 -43
  203. package/dist/valibot-D_HTw1Gn-XPR4F6VS.js.map +0 -1
  204. package/dist/zod-Bwrt9trS-GN7ZXBMN.js +0 -29
  205. package/dist/zod-Bwrt9trS-GN7ZXBMN.js.map +0 -1
  206. package/dist/zod-Bwrt9trS-OVKARV6W.cjs +0 -31
  207. package/dist/zod-Bwrt9trS-OVKARV6W.cjs.map +0 -1
  208. package/dist/zod-DSgpEGAE-E7YZZ7VC.js +0 -37
  209. package/dist/zod-DSgpEGAE-E7YZZ7VC.js.map +0 -1
  210. package/dist/zod-DSgpEGAE-UNQNGL2W.cjs +0 -39
  211. package/dist/zod-DSgpEGAE-UNQNGL2W.cjs.map +0 -1
@@ -0,0 +1,705 @@
1
+ import { a as getPackageName, i as getNodeResolveOptions, l as isDependencyPartOfPackage, p as slash, s as isBareModuleSpecifier, u as isExternalProtocolImport } from "./utils-FVOUvj-I.js";
2
+ import fs, { statSync } from "fs";
3
+ import { readFile } from "fs/promises";
4
+ import path, { dirname, isAbsolute, join, normalize } from "path";
5
+ import { readJSON } from "fs-extra/esm";
6
+ import { transformAsync, types } from "@babel/core";
7
+ import { fileURLToPath, pathToFileURL } from "url";
8
+ import commonjs from "@rollup/plugin-commonjs";
9
+ import json from "@rollup/plugin-json";
10
+ import { rollup } from "rollup";
11
+ import { optimizeLodashImports } from "@optimize-lodash/rollup-plugin";
12
+ import alias from "@rollup/plugin-alias";
13
+ import nodeResolve from "@rollup/plugin-node-resolve";
14
+ import originalEsbuild from "rollup-plugin-esbuild";
15
+ import originalEsmShim from "@rollup/plugin-esm-shim";
16
+ import { getPackageInfo } from "local-pkg";
17
+ import stripJsonComments from "strip-json-comments";
18
+ import { createHandler } from "typescript-paths";
19
+ //#region src/build/plugins/esbuild.ts
20
+ function esbuild(options = {}) {
21
+ return originalEsbuild({
22
+ target: "node20",
23
+ platform: "node",
24
+ minify: false,
25
+ ...options
26
+ });
27
+ }
28
+ //#endregion
29
+ //#region src/build/plugins/esm-shim.ts
30
+ const FilenameDeclarationRegex = /(?:const|let|var)\s+__filename/;
31
+ const DirnameDeclarationRegex = /(?:const|let|var)\s+__dirname/;
32
+ /**
33
+ * Custom ESM shim plugin wrapper that respects user-declared __filename/__dirname variables.
34
+ *
35
+ * The original @rollup/plugin-esm-shim would inject shims even when users had already declared
36
+ * their own __filename/__dirname, causing "Identifier '__filename' has already been declared" errors.
37
+ *
38
+ * This wrapper checks if the user has already declared these variables and skips the shim injection
39
+ * if so. If either variable is declared, we skip the shim entirely since the original plugin injects
40
+ * both together and we assume users who declare one will also handle the other if needed.
41
+ */
42
+ function esmShim() {
43
+ const original = originalEsmShim();
44
+ return {
45
+ name: "esm-shim",
46
+ renderChunk(code, chunk, opts, meta) {
47
+ const hasFilename = code.includes("__filename");
48
+ const hasDirname = code.includes("__dirname");
49
+ const userDeclaredFilename = hasFilename && FilenameDeclarationRegex.test(code);
50
+ const userDeclaredDirname = hasDirname && DirnameDeclarationRegex.test(code);
51
+ if (userDeclaredFilename || userDeclaredDirname) return null;
52
+ if (typeof original.renderChunk === "function") return original.renderChunk.call(this, code, chunk, opts, meta);
53
+ return null;
54
+ }
55
+ };
56
+ }
57
+ //#endregion
58
+ //#region src/build/plugins/local-storage-detector.ts
59
+ /**
60
+ * Connection-string-shaped patterns that resolve to the build host and will
61
+ * never work inside the deploy container.
62
+ */
63
+ const LOCAL_HOST_PATTERNS = [
64
+ {
65
+ pattern: /\bfile:\.{1,2}\/[^\s'"`]+\.(?:db|sqlite)\b/gi,
66
+ hint: "LibSQL/SQLite file path relative to the build host"
67
+ },
68
+ {
69
+ pattern: /\b(?:postgres(?:ql)?|mysql|mongodb|redis|libsql):\/\/[^/\s'"`]*localhost\b/gi,
70
+ hint: "localhost in a connection string"
71
+ },
72
+ {
73
+ pattern: /\b(?:postgres(?:ql)?|mysql|mongodb|redis|libsql):\/\/[^/\s'"`]*127\.0\.0\.1\b/g,
74
+ hint: "127.0.0.1 in a connection string"
75
+ }
76
+ ];
77
+ /**
78
+ * Everything under `.mastra/.build/` is deployer-generated pre-bundled
79
+ * dependency code (`@mastra__*.mjs` shims and their shared `chunk-*.mjs`
80
+ * files), never user-authored. These preserve JSDoc examples from the
81
+ * original library source (e.g. `LibSQLStore({ url: 'file:./data.db' })`)
82
+ * which would otherwise trip the host-local detector, and their env var
83
+ * reads are library refs that must not count as user references.
84
+ */
85
+ const MASTRA_BUILD_DIR = /[\\/]\.mastra[\\/]\.build[\\/]/;
86
+ const PROCESS_ENV_DOT = /\bprocess\.env\.([A-Z_][A-Z0-9_]*)\b/g;
87
+ const PROCESS_ENV_BRACKET = /\bprocess\.env\[['"]([A-Z_][A-Z0-9_]*)['"]\]/g;
88
+ /** Names of the metadata assets emitted into the output dir. */
89
+ const LEGACY_LOCAL_PATHS_FILE = "preflight-local-paths.json";
90
+ const PREFLIGHT_METADATA_FILE = "preflight-metadata.json";
91
+ function collectEnvRefs(code) {
92
+ const refs = /* @__PURE__ */ new Set();
93
+ for (const m of code.matchAll(PROCESS_ENV_DOT)) refs.add(m[1]);
94
+ for (const m of code.matchAll(PROCESS_ENV_BRACKET)) refs.add(m[1]);
95
+ return refs;
96
+ }
97
+ function isAstNode(v) {
98
+ return typeof v === "object" && v !== null && typeof v.type === "string";
99
+ }
100
+ function walkAst(node, visit) {
101
+ visit(node);
102
+ for (const value of Object.values(node)) if (Array.isArray(value)) {
103
+ for (const item of value) if (isAstNode(item)) walkAst(item, visit);
104
+ } else if (isAstNode(value)) walkAst(value, visit);
105
+ }
106
+ /** Find the first `process.env.X` / `process.env['X']` read inside an expression. */
107
+ function findFirstEnvRef(node) {
108
+ let found;
109
+ walkAst(node, (n) => {
110
+ if (found !== void 0) return;
111
+ if (n.type !== "MemberExpression") return;
112
+ const object = n.object;
113
+ if (!object || object.type !== "MemberExpression" || object.object?.type !== "Identifier" || object.object.name !== "process" || object.property?.type !== "Identifier" || object.property.name !== "env") return;
114
+ const property = n.property;
115
+ if (property?.type === "Identifier" && !n.computed) found = property.name;
116
+ else if (property?.type === "Literal" && typeof property.value === "string") found = property.value;
117
+ });
118
+ return found;
119
+ }
120
+ /**
121
+ * Parse a module and figure out, for each detected local-path value, whether
122
+ * every string literal containing it is the fallback arm of a
123
+ * `process.env.X || <literal>` / `??` expression. Returns a map from
124
+ * detected value to guarding env var name. Values with any unguarded
125
+ * occurrence (or inconsistent guards) are absent — the CLI then errors as
126
+ * before, which is the safe default.
127
+ */
128
+ function findGuardedValues(ast, values) {
129
+ const stringLiterals = [];
130
+ const guardedLiterals = /* @__PURE__ */ new Map();
131
+ walkAst(ast, (node) => {
132
+ if (node.type === "Literal" && typeof node.value === "string") {
133
+ stringLiterals.push(node);
134
+ return;
135
+ }
136
+ if (node.type === "LogicalExpression" && (node.operator === "||" || node.operator === "??")) {
137
+ const right = node.right;
138
+ if (right?.type === "Literal" && typeof right.value === "string") {
139
+ const envName = findFirstEnvRef(node.left);
140
+ if (envName) guardedLiterals.set(right, envName);
141
+ }
142
+ }
143
+ });
144
+ const result = /* @__PURE__ */ new Map();
145
+ for (const value of values) {
146
+ const containing = stringLiterals.filter((lit) => lit.value.includes(value));
147
+ if (containing.length === 0) continue;
148
+ const guards = containing.map((lit) => guardedLiterals.get(lit));
149
+ const first = guards[0];
150
+ if (first !== void 0 && guards.every((g) => g === first)) result.set(value, first);
151
+ }
152
+ return result;
153
+ }
154
+ /**
155
+ * Rollup plugin that detects host-local storage URLs (e.g. `file:./mastra.db`,
156
+ * `postgres://localhost`) in **user source modules** during bundling, and
157
+ * collects the env vars user code reads via `process.env.X`.
158
+ *
159
+ * Only modules outside `node_modules` (and the deployer's own
160
+ * `.mastra/.build/` pre-bundled files) are inspected, so library code
161
+ * (like Agent Builder prompt templates or JSDoc examples in `@mastra/core`)
162
+ * is naturally excluded. When `rootDir` is given, modules outside it are
163
+ * also excluded — symlinked dependencies (pnpm `link:`/`file:`) resolve to
164
+ * real paths that never contain `node_modules`. Tree-shaken modules are
165
+ * excluded via
166
+ * `generateBundle` — only modules that actually contribute rendered code to
167
+ * the output are reported.
168
+ *
169
+ * When a detected literal is the fallback arm of a `process.env.X || literal`
170
+ * expression, `guardedBy: "X"` is recorded so the CLI preflight can apply
171
+ * deploy-time env context instead of hard-erroring on a dead fallback.
172
+ *
173
+ * Two assets are emitted into the output directory for the CLI preflight:
174
+ * - `preflight-metadata.json` — unified metadata (local paths + user env refs)
175
+ * - `preflight-local-paths.json` — legacy shape, kept for one release so an
176
+ * older globally-installed CLI paired with a newer project-local deployer
177
+ * doesn't lose the LOCAL_STORAGE_PATH check.
178
+ */
179
+ function localStorageDetector(rootDir) {
180
+ const userModuleMatches = /* @__PURE__ */ new Map();
181
+ const userModuleEnvRefs = /* @__PURE__ */ new Map();
182
+ let normalizedRoot;
183
+ if (rootDir) {
184
+ let root = rootDir.replace(/\\/g, "/");
185
+ while (root.endsWith("/")) root = root.slice(0, -1);
186
+ normalizedRoot = root + "/";
187
+ }
188
+ return {
189
+ name: "mastra-local-storage-detector",
190
+ transform(_code, id) {
191
+ if (id.includes("node_modules")) return null;
192
+ if (MASTRA_BUILD_DIR.test(id)) return null;
193
+ if (normalizedRoot && !id.replace(/\\/g, "/").startsWith(normalizedRoot)) return null;
194
+ const refs = collectEnvRefs(_code);
195
+ if (refs.size > 0) userModuleEnvRefs.set(id, refs);
196
+ const matches = [];
197
+ for (const { pattern, hint } of LOCAL_HOST_PATTERNS) {
198
+ const re = new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : pattern.flags + "g");
199
+ for (const m of _code.matchAll(re)) matches.push({
200
+ value: m[0],
201
+ hint
202
+ });
203
+ }
204
+ if (matches.length > 0) {
205
+ try {
206
+ const guarded = findGuardedValues(this.parse(_code), new Set(matches.map((m) => m.value)));
207
+ for (const match of matches) {
208
+ const guardedBy = guarded.get(match.value);
209
+ if (guardedBy) match.guardedBy = guardedBy;
210
+ }
211
+ } catch {}
212
+ userModuleMatches.set(id, matches);
213
+ }
214
+ return null;
215
+ },
216
+ generateBundle(_, bundle) {
217
+ const detections = [];
218
+ const seen = /* @__PURE__ */ new Set();
219
+ const userEnvRefs = /* @__PURE__ */ new Set();
220
+ for (const chunk of Object.values(bundle)) {
221
+ if (chunk.type !== "chunk") continue;
222
+ for (const [moduleId, moduleInfo] of Object.entries(chunk.modules)) {
223
+ if (moduleInfo.renderedLength === 0) continue;
224
+ for (const ref of userModuleEnvRefs.get(moduleId) ?? []) userEnvRefs.add(ref);
225
+ const matches = userModuleMatches.get(moduleId);
226
+ if (!matches) continue;
227
+ for (const { value, hint, guardedBy } of matches) {
228
+ const key = `${hint}::${value}`;
229
+ if (seen.has(key)) continue;
230
+ seen.add(key);
231
+ detections.push({
232
+ value,
233
+ hint,
234
+ module: moduleId,
235
+ ...guardedBy ? { guardedBy } : {}
236
+ });
237
+ }
238
+ }
239
+ }
240
+ const metadata = {
241
+ version: 1,
242
+ localPaths: detections,
243
+ userEnvRefs: [...userEnvRefs].sort()
244
+ };
245
+ this.emitFile({
246
+ type: "asset",
247
+ fileName: PREFLIGHT_METADATA_FILE,
248
+ source: JSON.stringify(metadata)
249
+ });
250
+ this.emitFile({
251
+ type: "asset",
252
+ fileName: LEGACY_LOCAL_PATHS_FILE,
253
+ source: JSON.stringify(detections.map(({ value, hint, module }) => ({
254
+ value,
255
+ hint,
256
+ module
257
+ })))
258
+ });
259
+ }
260
+ };
261
+ }
262
+ //#endregion
263
+ //#region src/build/package-info.ts
264
+ /**
265
+ * Note: This function depends on local-pkg and should only be used at build-time.
266
+ * It is in a separate file to avoid including local-pkg in runtime code.
267
+ */
268
+ /**
269
+ * Normalize a resolution base path to a directory file URL.
270
+ *
271
+ * Callers often pass a module file path (e.g. a rollup module id like
272
+ * `node_modules/@mastra/core/dist/chunk-XYZ.js`) as the parent path. mlly (used by local-pkg)
273
+ * also treats each resolution base as a directory candidate (`<base>/_index.js`), which makes it
274
+ * try to read `<file>/package.json`. That fails with ENOTDIR, which mlly does not tolerate
275
+ * (only ENOENT) and local-pkg then logs the raw error to the console. Using the file's directory
276
+ * as the base avoids this while resolving identically.
277
+ */
278
+ function toParentDirectoryUrl(parentPath) {
279
+ let fsPath = parentPath.startsWith("file://") ? fileURLToPath(parentPath) : parentPath;
280
+ try {
281
+ if (statSync(fsPath).isFile()) fsPath = dirname(fsPath);
282
+ } catch {}
283
+ return pathToFileURL(fsPath).href;
284
+ }
285
+ /**
286
+ * Get package root path
287
+ */
288
+ async function getPackageRootPath(packageName, parentPath) {
289
+ let rootPath;
290
+ try {
291
+ let options = void 0;
292
+ if (parentPath) options = { paths: [toParentDirectoryUrl(parentPath)] };
293
+ rootPath = (await getPackageInfo(packageName, options))?.rootPath ?? null;
294
+ } catch {
295
+ rootPath = null;
296
+ }
297
+ return rootPath;
298
+ }
299
+ async function readPackageMetadata(rootPath, requestedPackageName) {
300
+ try {
301
+ const pkgJson = await readJSON(`${rootPath}/package.json`);
302
+ const version = pkgJson.version;
303
+ const actualPackageName = pkgJson.name;
304
+ return {
305
+ rootPath,
306
+ version,
307
+ packageSpec: version && actualPackageName && requestedPackageName && requestedPackageName !== actualPackageName ? `npm:${actualPackageName}@${version}` : void 0
308
+ };
309
+ } catch {
310
+ return { rootPath };
311
+ }
312
+ }
313
+ async function getPackageMetadata(packageName, parentPath) {
314
+ const requestedPackageName = getPackageName(packageName);
315
+ const packageNames = [...new Set([packageName, requestedPackageName].filter(Boolean))];
316
+ let firstRootPath = null;
317
+ for (const name of packageNames) {
318
+ const rootPath = await getPackageRootPath(name, parentPath);
319
+ firstRootPath ??= rootPath;
320
+ if (!rootPath) continue;
321
+ const metadata = await readPackageMetadata(rootPath, requestedPackageName ?? null);
322
+ if (metadata.version || metadata.packageSpec) return metadata;
323
+ }
324
+ return { rootPath: firstRootPath };
325
+ }
326
+ //#endregion
327
+ //#region src/build/plugins/node-modules-extension-resolver.ts
328
+ /**
329
+ * Check if a package has an exports field in its package.json.
330
+ * Results are cached to avoid repeated filesystem reads.
331
+ */
332
+ async function getPackageJSON(pkgName, importer) {
333
+ const pkgRoot = await getPackageRootPath(pkgName, importer);
334
+ if (!pkgRoot) throw new Error(`Package ${pkgName} not found`);
335
+ return JSON.parse(await readFile(join(pkgRoot, "package.json"), "utf-8"));
336
+ }
337
+ /**
338
+ * Rollup plugin that resolves module extensions for external dependencies.
339
+ *
340
+ * This plugin handles ESM compatibility for external imports when node-resolve is not used:
341
+ * - Packages WITH exports field (e.g., hono, date-fns): Keep imports as-is or strip redundant extensions
342
+ * - Packages WITHOUT exports field (e.g., lodash): Add .js extension for direct file imports
343
+ */
344
+ function nodeModulesExtensionResolver() {
345
+ const nodeResolvePlugin = nodeResolve();
346
+ return {
347
+ name: "node-modules-extension-resolver",
348
+ async resolveId(id, importer, options) {
349
+ if (!importer || !isBareModuleSpecifier(id) || isExternalProtocolImport(id) || isAbsolute(id)) return null;
350
+ const parts = id.split("/");
351
+ const isScoped = id.startsWith("@");
352
+ if (isScoped && parts.length === 2 || !isScoped && parts.length === 1) return null;
353
+ const pkgName = getPackageName(id);
354
+ if (!pkgName) return null;
355
+ try {
356
+ if (!!(await getPackageJSON(pkgName, importer)).exports) return null;
357
+ const packageRoot = await getPackageRootPath(pkgName, importer);
358
+ const nodeResolved = await nodeResolvePlugin.resolveId?.handler?.call(this, id, importer, options);
359
+ if (!nodeResolved?.id) return null;
360
+ let filePath = nodeResolved.id;
361
+ if (nodeResolved.resolvedBy === "commonjs--resolver") filePath = filePath.substring(1).split("?")[0];
362
+ return {
363
+ id: filePath.replace(packageRoot, pkgName),
364
+ external: true
365
+ };
366
+ } catch (err) {
367
+ console.error(err);
368
+ return null;
369
+ }
370
+ }
371
+ };
372
+ }
373
+ //#endregion
374
+ //#region src/build/plugins/protocol-external-resolver.ts
375
+ function protocolExternalResolver({ exclude = ["node:"] } = {}) {
376
+ return {
377
+ name: "protocol-external-resolver",
378
+ resolveId(id) {
379
+ if (!isExternalProtocolImport(id, exclude)) return null;
380
+ return {
381
+ id,
382
+ external: true
383
+ };
384
+ }
385
+ };
386
+ }
387
+ //#endregion
388
+ //#region src/build/babel/remove-deployer.ts
389
+ function removeDeployer$1() {
390
+ function removeDeployerFromObject(objectExpr, scope) {
391
+ const deployerProp = objectExpr.properties.find((prop) => types.isObjectProperty(prop) && types.isIdentifier(prop.key) && prop.key.name === "deployer");
392
+ if (deployerProp) {
393
+ objectExpr.properties = objectExpr.properties.filter((prop) => prop !== deployerProp);
394
+ if (types.isIdentifier(deployerProp.value)) {
395
+ const deployerBinding = scope.getBinding(deployerProp.value.name);
396
+ if (deployerBinding) deployerBinding.path?.parentPath?.remove();
397
+ }
398
+ }
399
+ return deployerProp;
400
+ }
401
+ return {
402
+ name: "remove-deployer",
403
+ visitor: { NewExpression(path, state) {
404
+ if (!path.findParent((path) => types.isVariableDeclarator(path.node))) return;
405
+ const parentNode = path.parentPath.node;
406
+ if (!types.isVariableDeclarator(parentNode) || !types.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") return;
407
+ if (!state.hasReplaced) {
408
+ state.hasReplaced = true;
409
+ const newMastraObj = types.cloneNode(path.node);
410
+ if (types.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.length) {
411
+ const objectArg = newMastraObj.arguments[0];
412
+ let foundDeployer = false;
413
+ if (removeDeployerFromObject(objectArg, state.file.scope)) foundDeployer = true;
414
+ for (const prop of objectArg.properties) if (types.isSpreadElement(prop) && types.isIdentifier(prop.argument)) {
415
+ const spreadBinding = state.file.scope.getBinding(prop.argument.name);
416
+ if (spreadBinding?.path && types.isVariableDeclarator(spreadBinding.path.node)) {
417
+ const init = spreadBinding.path.node.init;
418
+ if (types.isObjectExpression(init)) {
419
+ if (removeDeployerFromObject(init, state.file.scope)) foundDeployer = true;
420
+ }
421
+ }
422
+ }
423
+ if (foundDeployer) path.replaceWith(newMastraObj);
424
+ }
425
+ }
426
+ } }
427
+ };
428
+ }
429
+ //#endregion
430
+ //#region src/build/plugins/remove-deployer.ts
431
+ function removeDeployer(mastraEntry, options) {
432
+ return {
433
+ name: "remove-deployer",
434
+ transform(code, id) {
435
+ if (id !== mastraEntry) return;
436
+ return transformAsync(code, {
437
+ babelrc: false,
438
+ configFile: false,
439
+ filename: id,
440
+ plugins: [removeDeployer$1],
441
+ sourceMaps: options?.sourcemap
442
+ }).then((result) => ({
443
+ code: result.code,
444
+ map: result.map
445
+ }));
446
+ }
447
+ };
448
+ }
449
+ //#endregion
450
+ //#region src/build/plugins/subpath-externals-resolver.ts
451
+ function subpathExternalsResolver(externals) {
452
+ return {
453
+ name: "subpath-externals-resolver",
454
+ resolveId(id) {
455
+ if (id.startsWith(".") || id.startsWith("/")) return null;
456
+ if (externals.some((external) => isDependencyPartOfPackage(id, external))) return {
457
+ id,
458
+ external: true
459
+ };
460
+ }
461
+ };
462
+ }
463
+ //#endregion
464
+ //#region src/build/plugins/tsconfig-paths.ts
465
+ const PLUGIN_NAME = "tsconfig-paths";
466
+ const JS_IMPORT_SOURCE_EXTENSIONS = [
467
+ ".ts",
468
+ ".tsx",
469
+ ".js",
470
+ ".jsx"
471
+ ];
472
+ /**
473
+ * Check if a tsconfig file has path mappings configured.
474
+ * Exported for testing purposes.
475
+ *
476
+ * @param tsConfigPath - Path to the tsconfig.json file
477
+ * @returns true if the tsconfig has paths configured or extends another config, false otherwise
478
+ */
479
+ function hasPaths(tsConfigPath) {
480
+ try {
481
+ const content = fs.readFileSync(tsConfigPath, "utf8");
482
+ const config = JSON.parse(stripJsonComments(content));
483
+ return !!(config.compilerOptions?.paths && Object.keys(config.compilerOptions.paths).length > 0 || typeof config.extends === "string" && config.extends.length > 0 || Array.isArray(config.extends) && config.extends.length > 0);
484
+ } catch {
485
+ return false;
486
+ }
487
+ }
488
+ function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve } = {}) {
489
+ const handlerCache = /* @__PURE__ */ new Map();
490
+ function resolveJsImportToSourceFile(moduleName) {
491
+ if (fs.existsSync(moduleName)) return moduleName;
492
+ const parsed = path.parse(moduleName);
493
+ if (parsed.ext !== ".js") return moduleName;
494
+ for (const extension of JS_IMPORT_SOURCE_EXTENSIONS) {
495
+ const candidate = path.join(parsed.dir, `${parsed.name}${extension}`);
496
+ if (fs.existsSync(candidate)) return candidate;
497
+ }
498
+ return moduleName;
499
+ }
500
+ function findTsConfigForFile(filePath) {
501
+ let currentDir = path.dirname(filePath);
502
+ const root = path.parse(currentDir).root;
503
+ while (currentDir !== root) {
504
+ const tsConfigPath = path.join(currentDir, "tsconfig.json");
505
+ if (fs.existsSync(tsConfigPath)) {
506
+ if (hasPaths(tsConfigPath)) return tsConfigPath;
507
+ }
508
+ const tsConfigBasePath = path.join(currentDir, "tsconfig.base.json");
509
+ if (fs.existsSync(tsConfigBasePath)) {
510
+ if (hasPaths(tsConfigBasePath)) return tsConfigBasePath;
511
+ }
512
+ currentDir = path.dirname(currentDir);
513
+ }
514
+ return null;
515
+ }
516
+ function getHandlerForFile(filePath) {
517
+ if (tsConfigPath && typeof tsConfigPath === "string") {
518
+ if (!handlerCache.has(tsConfigPath)) handlerCache.set(tsConfigPath, createHandler({
519
+ log: () => {},
520
+ tsConfigPath,
521
+ respectCoreModule,
522
+ falllback: (moduleName) => fs.existsSync(moduleName)
523
+ }));
524
+ return handlerCache.get(tsConfigPath);
525
+ }
526
+ const configPath = findTsConfigForFile(filePath);
527
+ if (!configPath) return null;
528
+ if (!handlerCache.has(configPath)) handlerCache.set(configPath, createHandler({
529
+ log: () => {},
530
+ tsConfigPath: configPath,
531
+ respectCoreModule,
532
+ falllback: (moduleName) => fs.existsSync(moduleName)
533
+ }));
534
+ return handlerCache.get(configPath);
535
+ }
536
+ function resolveAlias(request, importer) {
537
+ const dynamicHandler = getHandlerForFile(importer);
538
+ if (!dynamicHandler) return null;
539
+ return dynamicHandler(request, normalize(importer));
540
+ }
541
+ return {
542
+ name: PLUGIN_NAME,
543
+ resolveId: {
544
+ order: "pre",
545
+ async handler(request, importer, options) {
546
+ if (!importer || request.startsWith("\0") || importer.charCodeAt(0) === 0) return null;
547
+ if (!path.isAbsolute(importer)) importer = path.resolve(process.cwd(), importer);
548
+ const moduleName = resolveAlias(request, importer);
549
+ if (!moduleName) {
550
+ const resolved = await this.resolve(request, importer, {
551
+ skipSelf: true,
552
+ ...options
553
+ });
554
+ if (!resolved) return null;
555
+ if (localResolve) {
556
+ const importerPluginMeta = this.getModuleInfo(importer)?.meta?.[PLUGIN_NAME];
557
+ if (!request.startsWith("./") && !request.startsWith("../") && importerPluginMeta?.resolved) return {
558
+ ...resolved,
559
+ external: !request.startsWith("hono/") && request !== "hono"
560
+ };
561
+ }
562
+ return {
563
+ ...resolved,
564
+ meta: { ...resolved.meta || {} }
565
+ };
566
+ }
567
+ const resolvedModuleName = resolveJsImportToSourceFile(moduleName);
568
+ if (!path.extname(resolvedModuleName)) {
569
+ const resolved = await this.resolve(resolvedModuleName, importer, {
570
+ skipSelf: true,
571
+ ...options
572
+ });
573
+ if (!resolved) return null;
574
+ return {
575
+ ...resolved,
576
+ meta: {
577
+ ...resolved.meta,
578
+ [PLUGIN_NAME]: { resolved: true }
579
+ }
580
+ };
581
+ }
582
+ const resolved = await this.resolve(resolvedModuleName, importer, {
583
+ skipSelf: true,
584
+ ...options
585
+ });
586
+ if (!resolved) return null;
587
+ return {
588
+ ...resolved,
589
+ meta: {
590
+ ...resolved.meta,
591
+ [PLUGIN_NAME]: { resolved: true }
592
+ }
593
+ };
594
+ }
595
+ }
596
+ };
597
+ }
598
+ //#endregion
599
+ //#region src/build/bundler.ts
600
+ function mastraInternalAliasPlugin(entryFile) {
601
+ const normalizedEntryFile = slash(entryFile);
602
+ return alias({ entries: [
603
+ {
604
+ find: /^\#server$/,
605
+ replacement: slash(fileURLToPath(import.meta.resolve("@mastra/deployer/server")))
606
+ },
607
+ {
608
+ find: /^\@mastra\/server\/(.*)/,
609
+ replacement: `@mastra/server/$1`,
610
+ customResolver: (id) => {
611
+ if (id.startsWith("@mastra/server")) return { id: fileURLToPath(import.meta.resolve(id)) };
612
+ }
613
+ },
614
+ {
615
+ find: /^\#mastra$/,
616
+ replacement: normalizedEntryFile
617
+ }
618
+ ] });
619
+ }
620
+ function mastraToolsAliasPlugin() {
621
+ return {
622
+ name: "tools-rewriter",
623
+ resolveId(id) {
624
+ if (id === "#tools") return {
625
+ id: "./tools.mjs",
626
+ external: true
627
+ };
628
+ }
629
+ };
630
+ }
631
+ async function getInputOptions(entryFile, analyzedBundleInfo, platform, env = { "process.env.NODE_ENV": JSON.stringify("production") }, { sourcemap = false, isDev = false, projectRoot, workspaceRoot = void 0, enableEsmShim = true, externalsPreset = false }) {
632
+ const nodeResolvePlugin = nodeResolve(getNodeResolveOptions(platform));
633
+ const externalsCopy = new Set(analyzedBundleInfo.externalDependencies.keys());
634
+ const externals = externalsPreset ? [] : Array.from(externalsCopy);
635
+ return {
636
+ logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
637
+ treeshake: "smallest",
638
+ preserveSymlinks: true,
639
+ external: externals,
640
+ plugins: [
641
+ protocolExternalResolver(),
642
+ subpathExternalsResolver(externals),
643
+ {
644
+ name: "alias-optimized-deps",
645
+ resolveId(id) {
646
+ if (!analyzedBundleInfo.dependencies.has(id)) return null;
647
+ const filename = analyzedBundleInfo.dependencies.get(id);
648
+ const absolutePath = join(workspaceRoot || projectRoot, filename);
649
+ if (isDev) return {
650
+ id: process.platform === "win32" ? pathToFileURL(absolutePath).href : absolutePath,
651
+ external: true
652
+ };
653
+ return {
654
+ id: absolutePath,
655
+ external: false
656
+ };
657
+ }
658
+ },
659
+ mastraInternalAliasPlugin(entryFile),
660
+ tsConfigPaths(),
661
+ mastraToolsAliasPlugin(),
662
+ esbuild({
663
+ platform,
664
+ define: env
665
+ }),
666
+ optimizeLodashImports({ include: "**/*.{js,ts,mjs,cjs}" }),
667
+ externalsPreset ? null : commonjs({
668
+ extensions: [".js", ".ts"],
669
+ transformMixedEsModules: true,
670
+ esmExternals(id) {
671
+ return externals.includes(id);
672
+ }
673
+ }),
674
+ enableEsmShim ? esmShim() : void 0,
675
+ externalsPreset ? nodeModulesExtensionResolver() : nodeResolvePlugin,
676
+ json(),
677
+ localStorageDetector(workspaceRoot || projectRoot),
678
+ removeDeployer(entryFile, { sourcemap }),
679
+ esbuild({
680
+ include: entryFile,
681
+ platform
682
+ })
683
+ ].filter(Boolean)
684
+ };
685
+ }
686
+ async function createBundler(inputOptions, outputOptions) {
687
+ const bundler = await rollup(inputOptions);
688
+ return {
689
+ write: () => {
690
+ return bundler.write({
691
+ ...outputOptions,
692
+ format: "esm",
693
+ entryFileNames: "[name].mjs",
694
+ chunkFileNames: "[name].mjs"
695
+ });
696
+ },
697
+ close: () => {
698
+ return bundler.close();
699
+ }
700
+ };
701
+ }
702
+ //#endregion
703
+ export { tsConfigPaths as a, protocolExternalResolver as c, getPackageRootPath as d, esmShim as f, mastraToolsAliasPlugin as i, nodeModulesExtensionResolver as l, getInputOptions as n, subpathExternalsResolver as o, esbuild as p, mastraInternalAliasPlugin as r, removeDeployer as s, createBundler as t, getPackageMetadata as u };
704
+
705
+ //# sourceMappingURL=bundler-D86rFu2J.js.map