@mastra/deployer 1.0.0-beta.4 → 1.0.0-beta.6

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 (187) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/dist/arktype-aI7TBD0R-4YXBEQBG.cjs +10 -0
  3. package/dist/arktype-aI7TBD0R-4YXBEQBG.cjs.map +1 -0
  4. package/dist/arktype-aI7TBD0R-OEPFT4G6.js +8 -0
  5. package/dist/arktype-aI7TBD0R-OEPFT4G6.js.map +1 -0
  6. package/dist/build/analyze/analyzeEntry.d.ts +4 -1
  7. package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
  8. package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
  9. package/dist/build/analyze.cjs +2 -2
  10. package/dist/build/analyze.d.ts +1 -1
  11. package/dist/build/analyze.d.ts.map +1 -1
  12. package/dist/build/analyze.js +1 -1
  13. package/dist/build/bundler.cjs +3 -3
  14. package/dist/build/bundler.d.ts.map +1 -1
  15. package/dist/build/bundler.js +1 -1
  16. package/dist/build/index.cjs +13 -13
  17. package/dist/build/index.js +4 -4
  18. package/dist/build/plugins/module-resolve-map.d.ts +3 -0
  19. package/dist/build/plugins/module-resolve-map.d.ts.map +1 -0
  20. package/dist/build/plugins/node-gyp-detector.d.ts +3 -0
  21. package/dist/build/plugins/node-gyp-detector.d.ts.map +1 -0
  22. package/dist/build/plugins/subpath-externals-resolver.d.ts +3 -0
  23. package/dist/build/plugins/subpath-externals-resolver.d.ts.map +1 -0
  24. package/dist/build/plugins/tsconfig-paths.d.ts.map +1 -1
  25. package/dist/build/utils.d.ts +1 -0
  26. package/dist/build/utils.d.ts.map +1 -1
  27. package/dist/bundler/index.cjs +2 -2
  28. package/dist/bundler/index.d.ts +1 -1
  29. package/dist/bundler/index.js +1 -1
  30. package/dist/{chunk-HQJR52M7.js → chunk-2O34LWCA.js} +5 -4
  31. package/dist/chunk-2O34LWCA.js.map +1 -0
  32. package/dist/chunk-2OTEFUER.cjs +69 -0
  33. package/dist/chunk-2OTEFUER.cjs.map +1 -0
  34. package/dist/chunk-5CWPEG6R.js +62 -0
  35. package/dist/chunk-5CWPEG6R.js.map +1 -0
  36. package/dist/{chunk-AQAOWLJJ.cjs → chunk-74E2QDFC.cjs} +16 -15
  37. package/dist/chunk-74E2QDFC.cjs.map +1 -0
  38. package/dist/chunk-7PLNIFGZ.cjs +8 -0
  39. package/dist/chunk-7PLNIFGZ.cjs.map +1 -0
  40. package/dist/{chunk-IL2VLNIJ.cjs → chunk-BCGWTALY.cjs} +12 -20
  41. package/dist/chunk-BCGWTALY.cjs.map +1 -0
  42. package/dist/chunk-BTNPI4Z7.cjs +4 -0
  43. package/dist/chunk-BTNPI4Z7.cjs.map +1 -0
  44. package/dist/{chunk-OFUWEVGF.js → chunk-CL2TNGFZ.js} +6 -14
  45. package/dist/chunk-CL2TNGFZ.js.map +1 -0
  46. package/dist/{chunk-5QFG6SCM.js → chunk-DPDWM7HQ.js} +2 -2
  47. package/dist/chunk-DPDWM7HQ.js.map +1 -0
  48. package/dist/chunk-FBT6QP7J.js +3 -0
  49. package/dist/chunk-FBT6QP7J.js.map +1 -0
  50. package/dist/chunk-GD2TGMBP.cjs +95 -0
  51. package/dist/chunk-GD2TGMBP.cjs.map +1 -0
  52. package/dist/{chunk-WBAWUM7Z.js → chunk-HQXN5AOP.js} +6 -5
  53. package/dist/chunk-HQXN5AOP.js.map +1 -0
  54. package/dist/chunk-ID3HN3BH.cjs +16 -0
  55. package/dist/chunk-ID3HN3BH.cjs.map +1 -0
  56. package/dist/{chunk-3JYRSECU.cjs → chunk-JVBCN3RH.cjs} +4 -4
  57. package/dist/chunk-JVBCN3RH.cjs.map +1 -0
  58. package/dist/chunk-MMUE22EL.js +159 -0
  59. package/dist/chunk-MMUE22EL.js.map +1 -0
  60. package/dist/chunk-N5TMJUIR.js +14 -0
  61. package/dist/chunk-N5TMJUIR.js.map +1 -0
  62. package/dist/{chunk-H3LLQ2MW.js → chunk-NFK4J35T.js} +527 -174
  63. package/dist/chunk-NFK4J35T.js.map +1 -0
  64. package/dist/chunk-P4L6VIHY.js +93 -0
  65. package/dist/chunk-P4L6VIHY.js.map +1 -0
  66. package/dist/{chunk-C74EXQSL.cjs → chunk-PRPZEAA3.cjs} +540 -189
  67. package/dist/chunk-PRPZEAA3.cjs.map +1 -0
  68. package/dist/chunk-Q2YGWEXY.js +6 -0
  69. package/dist/chunk-Q2YGWEXY.js.map +1 -0
  70. package/dist/chunk-TXKETRIN.cjs +162 -0
  71. package/dist/chunk-TXKETRIN.cjs.map +1 -0
  72. package/dist/{chunk-TDWIGFVF.cjs → chunk-XJAHDG3S.cjs} +15 -14
  73. package/dist/chunk-XJAHDG3S.cjs.map +1 -0
  74. package/dist/default-u_dwuiYb-65M4BHAA.js +3 -0
  75. package/dist/default-u_dwuiYb-65M4BHAA.js.map +1 -0
  76. package/dist/default-u_dwuiYb-PWN6FHC6.cjs +9 -0
  77. package/dist/default-u_dwuiYb-PWN6FHC6.cjs.map +1 -0
  78. package/dist/deploy/log.d.ts +1 -1
  79. package/dist/deploy/log.d.ts.map +1 -1
  80. package/dist/effect-QlVUlMFu-2ADPKIDF.cjs +17 -0
  81. package/dist/effect-QlVUlMFu-2ADPKIDF.cjs.map +1 -0
  82. package/dist/effect-QlVUlMFu-FD73M3OO.js +15 -0
  83. package/dist/effect-QlVUlMFu-FD73M3OO.js.map +1 -0
  84. package/dist/esm-BLVTLTJW.js +1289 -0
  85. package/dist/esm-BLVTLTJW.js.map +1 -0
  86. package/dist/esm-E3NUCNVN.cjs +1336 -0
  87. package/dist/esm-E3NUCNVN.cjs.map +1 -0
  88. package/dist/index.cjs +12 -12
  89. package/dist/index.js +4 -4
  90. package/dist/server/index.cjs +2327 -10519
  91. package/dist/server/index.cjs.map +1 -1
  92. package/dist/server/index.d.ts +3 -12
  93. package/dist/server/index.d.ts.map +1 -1
  94. package/dist/server/index.js +2326 -10518
  95. package/dist/server/index.js.map +1 -1
  96. package/dist/services/index.cjs +4 -4
  97. package/dist/services/index.js +1 -1
  98. package/dist/sury-CWZTCd75-K3FHMZF5.cjs +17 -0
  99. package/dist/sury-CWZTCd75-K3FHMZF5.cjs.map +1 -0
  100. package/dist/sury-CWZTCd75-Y2GURJ6K.js +15 -0
  101. package/dist/sury-CWZTCd75-Y2GURJ6K.js.map +1 -0
  102. package/dist/typebox-Dei93FPO-2WP4NOYD.js +8 -0
  103. package/dist/typebox-Dei93FPO-2WP4NOYD.js.map +1 -0
  104. package/dist/typebox-Dei93FPO-WTXAW2LA.cjs +10 -0
  105. package/dist/typebox-Dei93FPO-WTXAW2LA.cjs.map +1 -0
  106. package/dist/valibot--1zFm7rT-HMTCRBB3.cjs +17 -0
  107. package/dist/valibot--1zFm7rT-HMTCRBB3.cjs.map +1 -0
  108. package/dist/valibot--1zFm7rT-VGFBTDTW.js +15 -0
  109. package/dist/valibot--1zFm7rT-VGFBTDTW.js.map +1 -0
  110. package/dist/valibot-D_HTw1Gn-ILCWWLE4.cjs +45 -0
  111. package/dist/valibot-D_HTw1Gn-ILCWWLE4.cjs.map +1 -0
  112. package/dist/valibot-D_HTw1Gn-LLCGNU3W.js +43 -0
  113. package/dist/valibot-D_HTw1Gn-LLCGNU3W.js.map +1 -0
  114. package/dist/validator/custom-resolver.cjs +20 -12
  115. package/dist/validator/custom-resolver.cjs.map +1 -1
  116. package/dist/validator/custom-resolver.d.ts.map +1 -1
  117. package/dist/validator/custom-resolver.js +18 -10
  118. package/dist/validator/custom-resolver.js.map +1 -1
  119. package/dist/validator/validate.d.ts +15 -1
  120. package/dist/validator/validate.d.ts.map +1 -1
  121. package/dist/zod-Bwrt9trS-XCRGYQVE.js +29 -0
  122. package/dist/zod-Bwrt9trS-XCRGYQVE.js.map +1 -0
  123. package/dist/zod-Bwrt9trS-XDMWF3NW.cjs +31 -0
  124. package/dist/zod-Bwrt9trS-XDMWF3NW.cjs.map +1 -0
  125. package/dist/zod-DSgpEGAE-TKBHSSLS.js +37 -0
  126. package/dist/zod-DSgpEGAE-TKBHSSLS.js.map +1 -0
  127. package/dist/zod-DSgpEGAE-ZWQMF6SS.cjs +39 -0
  128. package/dist/zod-DSgpEGAE-ZWQMF6SS.cjs.map +1 -0
  129. package/package.json +11 -8
  130. package/dist/chunk-3JYRSECU.cjs.map +0 -1
  131. package/dist/chunk-5QFG6SCM.js.map +0 -1
  132. package/dist/chunk-AQAOWLJJ.cjs.map +0 -1
  133. package/dist/chunk-C74EXQSL.cjs.map +0 -1
  134. package/dist/chunk-H3LLQ2MW.js.map +0 -1
  135. package/dist/chunk-HQJR52M7.js.map +0 -1
  136. package/dist/chunk-IL2VLNIJ.cjs.map +0 -1
  137. package/dist/chunk-OFUWEVGF.js.map +0 -1
  138. package/dist/chunk-TDWIGFVF.cjs.map +0 -1
  139. package/dist/chunk-WBAWUM7Z.js.map +0 -1
  140. package/dist/server/handlers/auth/defaults.d.ts +0 -3
  141. package/dist/server/handlers/auth/defaults.d.ts.map +0 -1
  142. package/dist/server/handlers/auth/helpers.d.ts +0 -11
  143. package/dist/server/handlers/auth/helpers.d.ts.map +0 -1
  144. package/dist/server/handlers/auth/index.d.ts +0 -11
  145. package/dist/server/handlers/auth/index.d.ts.map +0 -1
  146. package/dist/server/handlers/routes/agent-builder/handlers.d.ts +0 -20
  147. package/dist/server/handlers/routes/agent-builder/handlers.d.ts.map +0 -1
  148. package/dist/server/handlers/routes/agent-builder/router.d.ts +0 -4
  149. package/dist/server/handlers/routes/agent-builder/router.d.ts.map +0 -1
  150. package/dist/server/handlers/routes/agents/handlers.d.ts +0 -232
  151. package/dist/server/handlers/routes/agents/handlers.d.ts.map +0 -1
  152. package/dist/server/handlers/routes/agents/router.d.ts +0 -5
  153. package/dist/server/handlers/routes/agents/router.d.ts.map +0 -1
  154. package/dist/server/handlers/routes/agents/voice.d.ts +0 -18
  155. package/dist/server/handlers/routes/agents/voice.d.ts.map +0 -1
  156. package/dist/server/handlers/routes/logs/handlers.d.ts +0 -5
  157. package/dist/server/handlers/routes/logs/handlers.d.ts.map +0 -1
  158. package/dist/server/handlers/routes/logs/router.d.ts +0 -3
  159. package/dist/server/handlers/routes/logs/router.d.ts.map +0 -1
  160. package/dist/server/handlers/routes/mcp/handlers.d.ts +0 -139
  161. package/dist/server/handlers/routes/mcp/handlers.d.ts.map +0 -1
  162. package/dist/server/handlers/routes/mcp/router.d.ts +0 -4
  163. package/dist/server/handlers/routes/mcp/router.d.ts.map +0 -1
  164. package/dist/server/handlers/routes/memory/handlers.d.ts +0 -15
  165. package/dist/server/handlers/routes/memory/handlers.d.ts.map +0 -1
  166. package/dist/server/handlers/routes/memory/router.d.ts +0 -4
  167. package/dist/server/handlers/routes/memory/router.d.ts.map +0 -1
  168. package/dist/server/handlers/routes/observability/handlers.d.ts +0 -6
  169. package/dist/server/handlers/routes/observability/handlers.d.ts.map +0 -1
  170. package/dist/server/handlers/routes/observability/router.d.ts +0 -3
  171. package/dist/server/handlers/routes/observability/router.d.ts.map +0 -1
  172. package/dist/server/handlers/routes/scores/handlers.d.ts +0 -352
  173. package/dist/server/handlers/routes/scores/handlers.d.ts.map +0 -1
  174. package/dist/server/handlers/routes/scores/router.d.ts +0 -4
  175. package/dist/server/handlers/routes/scores/router.d.ts.map +0 -1
  176. package/dist/server/handlers/routes/tools/handlers.d.ts +0 -7
  177. package/dist/server/handlers/routes/tools/handlers.d.ts.map +0 -1
  178. package/dist/server/handlers/routes/tools/router.d.ts +0 -4
  179. package/dist/server/handlers/routes/tools/router.d.ts.map +0 -1
  180. package/dist/server/handlers/routes/vector/handlers.d.ts +0 -10
  181. package/dist/server/handlers/routes/vector/handlers.d.ts.map +0 -1
  182. package/dist/server/handlers/routes/vector/router.d.ts +0 -4
  183. package/dist/server/handlers/routes/vector/router.d.ts.map +0 -1
  184. package/dist/server/handlers/routes/workflows/handlers.d.ts +0 -20
  185. package/dist/server/handlers/routes/workflows/handlers.d.ts.map +0 -1
  186. package/dist/server/handlers/routes/workflows/router.d.ts +0 -4
  187. package/dist/server/handlers/routes/workflows/router.d.ts.map +0 -1
@@ -1,12 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ var chunk2OTEFUER_cjs = require('./chunk-2OTEFUER.cjs');
3
4
  var babel = require('@babel/core');
4
5
  var fs = require('fs');
5
6
  var promises = require('fs/promises');
6
7
  var path2 = require('path');
7
8
  var child_process = require('child_process');
8
- var localPkg = require('local-pkg');
9
- var url = require('url');
10
9
  var rollup = require('rollup');
11
10
  var originalEsbuild = require('rollup-plugin-esbuild');
12
11
  var commonjs = require('@rollup/plugin-commonjs');
@@ -18,11 +17,13 @@ var pkg = require('empathic/package');
18
17
  var findWorkspaces = require('find-workspaces');
19
18
  var logger = require('@mastra/core/logger');
20
19
  var virtual = require('@rollup/plugin-virtual');
20
+ var url = require('url');
21
21
  var module$1 = require('module');
22
22
  var nodeResolve = require('@rollup/plugin-node-resolve');
23
23
  var esmShim = require('@rollup/plugin-esm-shim');
24
24
  var posix = require('path/posix');
25
25
  var resolve = require('resolve.exports');
26
+ var localPkg = require('local-pkg');
26
27
  var error = require('@mastra/core/error');
27
28
 
28
29
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -58,83 +59,18 @@ var nodeResolve__default = /*#__PURE__*/_interopDefault(nodeResolve);
58
59
  var esmShim__default = /*#__PURE__*/_interopDefault(esmShim);
59
60
  var resolve__namespace = /*#__PURE__*/_interopNamespace(resolve);
60
61
 
61
- // src/build/analyze.ts
62
- function getPackageName(id) {
63
- const parts = id.split("/");
64
- if (id.startsWith("@")) {
65
- return parts.slice(0, 2).join("/");
62
+ var ValidationError = class extends Error {
63
+ type;
64
+ stack;
65
+ constructor(args) {
66
+ super(args.message);
67
+ this.type = args.type;
68
+ this.stack = args.stack;
66
69
  }
67
- return parts[0];
68
- }
69
- async function getPackageRootPath(packageName, parentPath) {
70
- let rootPath;
71
- try {
72
- let options = void 0;
73
- if (parentPath) {
74
- if (!parentPath.startsWith("file://")) {
75
- parentPath = url.pathToFileURL(parentPath).href;
76
- }
77
- options = {
78
- paths: [parentPath]
79
- };
80
- }
81
- const pkg2 = await localPkg.getPackageInfo(packageName, options);
82
- rootPath = pkg2?.rootPath ?? null;
83
- } catch (e) {
84
- rootPath = null;
85
- }
86
- return rootPath;
87
- }
88
- function getCompiledDepCachePath(rootPath, packageName) {
89
- return slash(path2.join(rootPath, "node_modules", ".cache", packageName));
90
- }
91
- function slash(path3) {
92
- const isExtendedLengthPath = path3.startsWith("\\\\?\\");
93
- if (isExtendedLengthPath) {
94
- return path3;
95
- }
96
- return path3.replaceAll("\\", "/");
97
- }
98
- function rollupSafeName(name, rootDir) {
99
- const rel = path2.relative(rootDir, name);
100
- let entry = slash(rel);
101
- entry = entry.replace(/^(\.\.\/)+/, "");
102
- entry = entry.replace(/^\/+/, "");
103
- entry = entry.replace(/^[A-Za-z]:\//, "");
104
- if (!entry) {
105
- entry = slash(path2.basename(name));
106
- }
107
- return entry;
108
- }
109
- var NATIVE_BINDING_LOADERS = [
110
- "node-gyp-build",
111
- "prebuild-install",
112
- "bindings",
113
- "node-addon-api",
114
- "node-pre-gyp",
115
- "nan"
116
- // Native Abstractions for Node.js
117
- ];
118
- function findNativePackageModule(moduleIds) {
119
- return moduleIds.find((id) => {
120
- if (id.startsWith("\0")) {
121
- return false;
122
- }
123
- if (!id.includes("/node_modules/")) {
124
- return false;
125
- }
126
- for (const loader of NATIVE_BINDING_LOADERS) {
127
- if (id.includes(`/${loader}/`) || id.includes(`/${loader}@`)) {
128
- return false;
129
- }
130
- }
131
- return true;
132
- });
133
- }
134
-
135
- // src/validator/validate.ts
70
+ };
136
71
  function spawn(command, args = [], options = {}) {
137
72
  return new Promise((resolve2, reject) => {
73
+ let validationError = null;
138
74
  const childProcess = child_process.spawn(command, args, {
139
75
  // stdio: 'inherit',
140
76
  ...options
@@ -144,28 +80,63 @@ function spawn(command, args = [], options = {}) {
144
80
  });
145
81
  let stderr = "";
146
82
  childProcess.stderr?.on("data", (message) => {
147
- stderr += message;
83
+ try {
84
+ validationError = JSON.parse(message.toString());
85
+ } catch {
86
+ stderr += message;
87
+ }
148
88
  });
149
89
  childProcess.on("close", (code) => {
150
90
  if (code === 0) {
151
91
  resolve2();
152
92
  } else {
153
- reject(new Error(stderr));
93
+ if (validationError) {
94
+ reject(new ValidationError(validationError));
95
+ } else {
96
+ reject(new Error(stderr));
97
+ }
154
98
  }
155
99
  });
156
100
  });
157
101
  }
158
- function validate(file) {
102
+ function validate(file, { injectESMShim = false, moduleResolveMapLocation }) {
103
+ let prefixCode = "";
104
+ if (injectESMShim) {
105
+ prefixCode = `import { fileURLToPath } from 'url';
106
+ import { dirname } from 'path';
107
+
108
+ globalThis.__filename = fileURLToPath(import.meta.url);
109
+ globalThis.__dirname = dirname(__filename);
110
+ `;
111
+ }
112
+ function errorHandler(err) {
113
+ console.error(
114
+ JSON.stringify({
115
+ type: err.name,
116
+ message: err.message,
117
+ stack: err.stack
118
+ })
119
+ );
120
+ process.exit(1);
121
+ }
159
122
  return spawn(
160
- "node",
123
+ process.execPath,
161
124
  [
162
125
  "--import",
163
126
  undefined("@mastra/deployer/loader"),
164
127
  "--input-type=module",
128
+ "--enable-source-maps",
165
129
  "-e",
166
- `import('file://${slash(file)}')`
130
+ `${prefixCode};import('file://${chunk2OTEFUER_cjs.slash(file)}').catch(err => {
131
+ ${errorHandler.toString()}
132
+ errorHandler(err);
133
+ })`.replaceAll(/\n/g, "")
167
134
  ],
168
135
  {
136
+ env: {
137
+ ...process.env,
138
+ MODULE_MAP: `${moduleResolveMapLocation}`
139
+ },
169
140
  cwd: path2.dirname(file)
170
141
  }
171
142
  );
@@ -261,28 +232,88 @@ function esbuild(options = {}) {
261
232
  }
262
233
  var PLUGIN_NAME = "tsconfig-paths";
263
234
  function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve } = {}) {
264
- let handler;
235
+ const handlerCache = /* @__PURE__ */ new Map();
236
+ function findTsConfigForFile(filePath) {
237
+ let currentDir = path2__namespace.default.dirname(filePath);
238
+ const root = path2__namespace.default.parse(currentDir).root;
239
+ while (currentDir !== root) {
240
+ const tsConfigPath2 = path2__namespace.default.join(currentDir, "tsconfig.json");
241
+ if (fs__default.default.existsSync(tsConfigPath2)) {
242
+ if (hasPaths(tsConfigPath2)) {
243
+ return tsConfigPath2;
244
+ }
245
+ }
246
+ const tsConfigBasePath = path2__namespace.default.join(currentDir, "tsconfig.base.json");
247
+ if (fs__default.default.existsSync(tsConfigBasePath)) {
248
+ if (hasPaths(tsConfigBasePath)) {
249
+ return tsConfigBasePath;
250
+ }
251
+ }
252
+ currentDir = path2__namespace.default.dirname(currentDir);
253
+ }
254
+ return null;
255
+ }
256
+ function hasPaths(tsConfigPath2) {
257
+ try {
258
+ const config = JSON.parse(fs__default.default.readFileSync(tsConfigPath2, "utf8"));
259
+ return !!(config.compilerOptions?.paths && Object.keys(config.compilerOptions.paths).length > 0);
260
+ } catch {
261
+ return false;
262
+ }
263
+ }
264
+ function getHandlerForFile(filePath) {
265
+ if (tsConfigPath && typeof tsConfigPath === "string") {
266
+ if (!handlerCache.has(tsConfigPath)) {
267
+ handlerCache.set(
268
+ tsConfigPath,
269
+ typescriptPaths.createHandler({
270
+ log: () => {
271
+ },
272
+ tsConfigPath,
273
+ respectCoreModule,
274
+ falllback: (moduleName) => fs__default.default.existsSync(moduleName)
275
+ })
276
+ );
277
+ }
278
+ return handlerCache.get(tsConfigPath);
279
+ }
280
+ const configPath = findTsConfigForFile(filePath);
281
+ if (!configPath) {
282
+ return null;
283
+ }
284
+ if (!handlerCache.has(configPath)) {
285
+ handlerCache.set(
286
+ configPath,
287
+ typescriptPaths.createHandler({
288
+ log: () => {
289
+ },
290
+ tsConfigPath: configPath,
291
+ respectCoreModule,
292
+ falllback: (moduleName) => fs__default.default.existsSync(moduleName)
293
+ })
294
+ );
295
+ }
296
+ return handlerCache.get(configPath);
297
+ }
298
+ function resolveAlias(request, importer) {
299
+ const dynamicHandler = getHandlerForFile(importer);
300
+ if (!dynamicHandler) {
301
+ return null;
302
+ }
303
+ const resolved = dynamicHandler(request, path2.normalize(importer));
304
+ return resolved;
305
+ }
265
306
  return {
266
307
  name: PLUGIN_NAME,
267
- buildStart() {
268
- handler = typescriptPaths.createHandler({
269
- log: () => {
270
- },
271
- tsConfigPath,
272
- respectCoreModule,
273
- falllback: (moduleName) => fs__default.default.existsSync(moduleName)
274
- });
275
- return;
276
- },
277
308
  async resolveId(request, importer, options) {
278
- if (!importer || request.startsWith("\0")) {
309
+ if (!importer || request.startsWith("\0") || importer.startsWith("\0")) {
279
310
  return null;
280
311
  }
281
- const moduleName = handler?.(request, path2.normalize(importer));
312
+ const moduleName = resolveAlias(request, importer);
282
313
  if (!moduleName) {
283
314
  let importerMeta = {};
284
- const resolved = await this.resolve(request, importer, { skipSelf: true, ...options });
285
- if (!resolved) {
315
+ const resolved2 = await this.resolve(request, importer, { skipSelf: true, ...options });
316
+ if (!resolved2) {
286
317
  return null;
287
318
  }
288
319
  if (localResolve) {
@@ -290,37 +321,42 @@ function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve } = {}) {
290
321
  importerMeta = importerInfo?.meta || {};
291
322
  if (!request.startsWith("./") && !request.startsWith("../") && importerMeta?.[PLUGIN_NAME]?.resolved) {
292
323
  return {
293
- ...resolved,
324
+ ...resolved2,
294
325
  external: !request.startsWith("hono/") && request !== "hono"
295
326
  };
296
327
  }
297
328
  }
298
329
  return {
299
- ...resolved,
330
+ ...resolved2,
300
331
  meta: {
301
- ...resolved.meta || {},
332
+ ...resolved2.meta || {},
302
333
  ...importerMeta
303
334
  }
304
335
  };
305
336
  }
306
337
  if (!path2__namespace.default.extname(moduleName)) {
307
- const resolved = await this.resolve(moduleName, importer, { skipSelf: true, ...options });
308
- if (!resolved) {
338
+ const resolved2 = await this.resolve(moduleName, importer, { skipSelf: true, ...options });
339
+ if (!resolved2) {
309
340
  return null;
310
341
  }
311
342
  return {
312
- ...resolved,
343
+ ...resolved2,
313
344
  meta: {
314
- ...resolved.meta,
345
+ ...resolved2.meta,
315
346
  [PLUGIN_NAME]: {
316
347
  resolved: true
317
348
  }
318
349
  }
319
350
  };
320
351
  }
352
+ const resolved = await this.resolve(moduleName, importer, { skipSelf: true, ...options });
353
+ if (!resolved) {
354
+ return null;
355
+ }
321
356
  return {
322
- id: moduleName,
357
+ ...resolved,
323
358
  meta: {
359
+ ...resolved.meta,
324
360
  [PLUGIN_NAME]: {
325
361
  resolved: true
326
362
  }
@@ -539,7 +575,7 @@ async function getWorkspaceInformation({
539
575
  mastraEntryFile
540
576
  }) {
541
577
  const closestPkgJson = pkg__namespace.up({ cwd: path2.dirname(mastraEntryFile) });
542
- const location = closestPkgJson ? path2.dirname(slash(closestPkgJson)) : slash(process.cwd());
578
+ const location = closestPkgJson ? path2.dirname(chunk2OTEFUER_cjs.slash(closestPkgJson)) : chunk2OTEFUER_cjs.slash(process.cwd());
543
579
  const workspaces = await findWorkspaces.findWorkspaces(dir, { cache: workspacesCache });
544
580
  const _workspaceMap = new Map(
545
581
  workspaces?.map((workspace) => [
@@ -655,7 +691,7 @@ var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
655
691
 
656
692
  // src/build/analyze/analyzeEntry.ts
657
693
  function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
658
- const normalizedMastraEntry = slash(mastraEntry);
694
+ const normalizedMastraEntry = chunk2OTEFUER_cjs.slash(mastraEntry);
659
695
  let virtualPlugin = null;
660
696
  if (isVirtualFile) {
661
697
  virtualPlugin = virtual__default.default({
@@ -674,7 +710,7 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
674
710
  name: "custom-alias-resolver",
675
711
  resolveId(id) {
676
712
  if (id === "#server") {
677
- return slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
713
+ return chunk2OTEFUER_cjs.slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
678
714
  }
679
715
  if (id === "#mastra") {
680
716
  return normalizedMastraEntry;
@@ -699,7 +735,8 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
699
735
  return plugins;
700
736
  }
701
737
  async function captureDependenciesToOptimize(output, workspaceMap, projectRoot, initialDepsToOptimize, {
702
- logger: logger$1
738
+ logger: logger$1,
739
+ shouldCheckTransitiveDependencies
703
740
  }) {
704
741
  const depsToOptimize = /* @__PURE__ */ new Map();
705
742
  if (!output.facadeModuleId) {
@@ -709,21 +746,25 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
709
746
  }
710
747
  let entryRootPath = projectRoot;
711
748
  if (!output.facadeModuleId.startsWith("\0virtual:")) {
712
- entryRootPath = await getPackageRootPath(output.facadeModuleId) || projectRoot;
749
+ entryRootPath = await chunk2OTEFUER_cjs.getPackageRootPath(output.facadeModuleId) || projectRoot;
713
750
  }
714
751
  for (const [dependency, bindings] of Object.entries(output.importedBindings)) {
715
752
  if (isNodeBuiltin(dependency) || DEPS_TO_IGNORE.includes(dependency)) {
716
753
  continue;
717
754
  }
718
- const pkgName = getPackageName(dependency);
755
+ const pkgName = chunk2OTEFUER_cjs.getPackageName(dependency);
719
756
  let rootPath = null;
720
757
  let isWorkspace = false;
721
758
  if (pkgName) {
722
- rootPath = await getPackageRootPath(dependency, entryRootPath);
759
+ rootPath = await chunk2OTEFUER_cjs.getPackageRootPath(dependency, entryRootPath);
723
760
  isWorkspace = workspaceMap.has(pkgName);
724
761
  }
725
- const normalizedRootPath = rootPath ? slash(rootPath) : null;
726
- depsToOptimize.set(dependency, { exports: bindings, rootPath: normalizedRootPath, isWorkspace });
762
+ const normalizedRootPath = rootPath ? chunk2OTEFUER_cjs.slash(rootPath) : null;
763
+ depsToOptimize.set(dependency, {
764
+ exports: bindings,
765
+ rootPath: normalizedRootPath,
766
+ isWorkspace
767
+ });
727
768
  }
728
769
  async function checkTransitiveDependencies(internalMap, maxDepth = 10, currentDepth = 0) {
729
770
  if (currentDepth >= maxDepth) {
@@ -767,12 +808,18 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
767
808
  await checkTransitiveDependencies(internalMap, maxDepth, currentDepth + 1);
768
809
  }
769
810
  }
770
- await checkTransitiveDependencies(initialDepsToOptimize);
811
+ if (shouldCheckTransitiveDependencies) {
812
+ await checkTransitiveDependencies(initialDepsToOptimize);
813
+ }
771
814
  const dynamicImports = output.dynamicImports.filter((d) => !DEPS_TO_IGNORE.includes(d));
772
815
  if (dynamicImports.length) {
773
816
  for (const dynamicImport of dynamicImports) {
774
817
  if (!depsToOptimize.has(dynamicImport) && !isNodeBuiltin(dynamicImport)) {
775
- depsToOptimize.set(dynamicImport, { exports: ["*"], rootPath: null, isWorkspace: false });
818
+ depsToOptimize.set(dynamicImport, {
819
+ exports: ["*"],
820
+ rootPath: null,
821
+ isWorkspace: false
822
+ });
776
823
  }
777
824
  }
778
825
  }
@@ -786,13 +833,14 @@ async function analyzeEntry({
786
833
  sourcemapEnabled,
787
834
  workspaceMap,
788
835
  projectRoot,
789
- initialDepsToOptimize = /* @__PURE__ */ new Map()
836
+ initialDepsToOptimize = /* @__PURE__ */ new Map(),
790
837
  // used to avoid infinite recursion
838
+ shouldCheckTransitiveDependencies = false
791
839
  }) {
792
840
  const optimizerBundler = await rollup.rollup({
793
841
  logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
794
842
  input: isVirtualFile ? "#entry" : entry,
795
- treeshake: "smallest",
843
+ treeshake: false,
796
844
  preserveSymlinks: true,
797
845
  plugins: getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }),
798
846
  external: DEPS_TO_IGNORE
@@ -808,7 +856,8 @@ async function analyzeEntry({
808
856
  projectRoot,
809
857
  initialDepsToOptimize,
810
858
  {
811
- logger
859
+ logger,
860
+ shouldCheckTransitiveDependencies
812
861
  }
813
862
  );
814
863
  return {
@@ -831,8 +880,116 @@ function aliasHono() {
831
880
  }
832
881
  };
833
882
  }
883
+ function nodeGypDetector() {
884
+ const modulesToTrack = /* @__PURE__ */ new Set();
885
+ const modulesToTrackPackageInfo = /* @__PURE__ */ new Map();
886
+ return {
887
+ name: "node-gyp-build-detector",
888
+ moduleParsed(info) {
889
+ if (!info.meta?.commonjs?.requires?.length) {
890
+ return;
891
+ }
892
+ const hasNodeGypBuild = info.meta.commonjs.requires.some(
893
+ (m) => m?.resolved?.id.endsWith("node-gyp-build/index.js")
894
+ );
895
+ if (!hasNodeGypBuild) {
896
+ return;
897
+ }
898
+ modulesToTrack.add(info.id);
899
+ modulesToTrackPackageInfo.set(info.id, localPkg.getPackageInfo(info.id));
900
+ },
901
+ async generateBundle(options, bundle) {
902
+ const binaryMapByChunk = /* @__PURE__ */ new Map();
903
+ for (const [fileName, chunk] of Object.entries(bundle)) {
904
+ if (chunk.type === "chunk") {
905
+ for (const moduleId of chunk.moduleIds) {
906
+ if (modulesToTrackPackageInfo.has(moduleId)) {
907
+ const pkgInfo = await modulesToTrackPackageInfo.get(moduleId);
908
+ if (!binaryMapByChunk.has(fileName)) {
909
+ binaryMapByChunk.set(fileName, /* @__PURE__ */ new Set());
910
+ }
911
+ if (pkgInfo?.packageJson?.name) {
912
+ binaryMapByChunk.get(fileName).add(pkgInfo.packageJson.name);
913
+ }
914
+ }
915
+ }
916
+ }
917
+ }
918
+ const binaryMapJson = Object.fromEntries(
919
+ Array.from(binaryMapByChunk.entries()).map(([key, value]) => [key, Array.from(value)])
920
+ );
921
+ this.emitFile({
922
+ type: "asset",
923
+ name: "binary-map.json",
924
+ source: `${JSON.stringify(binaryMapJson, null, 2)}`
925
+ });
926
+ }
927
+ };
928
+ }
929
+
930
+ // src/build/plugins/subpath-externals-resolver.ts
931
+ function subpathExternalsResolver(externals) {
932
+ return {
933
+ name: "subpath-externals-resolver",
934
+ resolveId(id) {
935
+ if (id.startsWith(".") || id.startsWith("/")) {
936
+ return null;
937
+ }
938
+ const isPartOfExternals = externals.some((external) => chunk2OTEFUER_cjs.isDependencyPartOfPackage(id, external));
939
+ if (isPartOfExternals) {
940
+ return {
941
+ id,
942
+ external: true
943
+ };
944
+ }
945
+ }
946
+ };
947
+ }
948
+ function moduleResolveMap(externals, projectRoot) {
949
+ const importMap = /* @__PURE__ */ new Map();
950
+ return {
951
+ name: "module-resolve-map",
952
+ moduleParsed(info) {
953
+ if (info.importedIds.length === 0 || !info.id) {
954
+ return;
955
+ }
956
+ for (const importedId of info.importedIds) {
957
+ for (const external of externals) {
958
+ if (chunk2OTEFUER_cjs.isDependencyPartOfPackage(importedId, external)) {
959
+ importMap.set(external, info.id);
960
+ }
961
+ }
962
+ }
963
+ },
964
+ async generateBundle(options, bundle) {
965
+ const resolveMap = /* @__PURE__ */ new Map();
966
+ for (const [fileName, chunk] of Object.entries(bundle)) {
967
+ if (chunk.type === "chunk") {
968
+ for (const [external, resolvedFrom] of importMap) {
969
+ if (chunk.moduleIds.includes(resolvedFrom)) {
970
+ const fullPath = url.pathToFileURL(chunk2OTEFUER_cjs.slash(path2.join(projectRoot, fileName))).toString();
971
+ const innerMap = resolveMap.get(fullPath) || /* @__PURE__ */ new Map();
972
+ innerMap.set(external, url.pathToFileURL(chunk2OTEFUER_cjs.slash(resolvedFrom)).toString());
973
+ resolveMap.set(fullPath, innerMap);
974
+ }
975
+ }
976
+ }
977
+ }
978
+ const resolveMapJson = Object.fromEntries(
979
+ Array.from(resolveMap.entries()).map(([key, value]) => [key, Object.fromEntries(value.entries())])
980
+ );
981
+ this.emitFile({
982
+ type: "asset",
983
+ name: "module-resolve-map.json",
984
+ source: `${JSON.stringify(resolveMapJson, null, 2)}`
985
+ });
986
+ }
987
+ };
988
+ }
989
+
990
+ // src/build/analyze/bundleExternals.ts
834
991
  function prepareEntryFileName(name, rootDir) {
835
- return rollupSafeName(name, rootDir);
992
+ return chunk2OTEFUER_cjs.rollupSafeName(name, rootDir);
836
993
  }
837
994
  function createVirtualDependencies(depsToOptimize, {
838
995
  projectRoot,
@@ -882,7 +1039,7 @@ function createVirtualDependencies(depsToOptimize, {
882
1039
  continue;
883
1040
  }
884
1041
  const fileName = posix.basename(currentDepPath.name);
885
- const entryName = prepareEntryFileName(getCompiledDepCachePath(rootPath, fileName), rootDir);
1042
+ const entryName = prepareEntryFileName(chunk2OTEFUER_cjs.getCompiledDepCachePath(rootPath, fileName), rootDir);
886
1043
  fileNameToDependencyMap.set(entryName, dep);
887
1044
  optimizedDependencyEntries.set(dep, {
888
1045
  ...currentDepPath,
@@ -896,13 +1053,14 @@ async function getInputPlugins2(virtualDependencies, {
896
1053
  transpilePackages,
897
1054
  workspaceMap,
898
1055
  bundlerOptions,
899
- rootDir
1056
+ rootDir,
1057
+ externals
900
1058
  }) {
901
1059
  const transpilePackagesMap = /* @__PURE__ */ new Map();
902
1060
  for (const pkg2 of transpilePackages) {
903
- const dir = await getPackageRootPath(pkg2);
1061
+ const dir = await chunk2OTEFUER_cjs.getPackageRootPath(pkg2);
904
1062
  if (dir) {
905
- transpilePackagesMap.set(pkg2, slash(dir));
1063
+ transpilePackagesMap.set(pkg2, chunk2OTEFUER_cjs.slash(dir));
906
1064
  } else {
907
1065
  transpilePackagesMap.set(pkg2, workspaceMap.get(pkg2)?.location ?? pkg2);
908
1066
  }
@@ -917,6 +1075,7 @@ async function getInputPlugins2(virtualDependencies, {
917
1075
  {}
918
1076
  )
919
1077
  ),
1078
+ subpathExternalsResolver(externals),
920
1079
  transpilePackagesMap.size ? esbuild({
921
1080
  format: "esm",
922
1081
  include: [...transpilePackagesMap.values()].map((p) => {
@@ -945,7 +1104,8 @@ async function getInputPlugins2(virtualDependencies, {
945
1104
  if (!resolvedPath) {
946
1105
  resolvedPath = pkgJson.main ?? "index.js";
947
1106
  }
948
- return await this.resolve(path2__namespace.posix.join(packageRootPath, resolvedPath), importer, options);
1107
+ const resolved = await this.resolve(path2__namespace.posix.join(packageRootPath, resolvedPath), importer, options);
1108
+ return resolved;
949
1109
  }
950
1110
  } : null,
951
1111
  rollupPlugin.optimizeLodashImports({
@@ -964,6 +1124,8 @@ async function getInputPlugins2(virtualDependencies, {
964
1124
  // hono is imported from deployer, so we need to resolve from here instead of the project root
965
1125
  aliasHono(),
966
1126
  json__default.default(),
1127
+ nodeGypDetector(),
1128
+ moduleResolveMap(externals, rootDir),
967
1129
  {
968
1130
  name: "not-found-resolver",
969
1131
  resolveId: {
@@ -1021,12 +1183,13 @@ async function buildExternalDependencies(virtualDependencies, {
1021
1183
  {}
1022
1184
  ),
1023
1185
  external: externals,
1024
- treeshake: "safest",
1186
+ treeshake: bundlerOptions.isDev ? false : "safest",
1025
1187
  plugins: getInputPlugins2(virtualDependencies, {
1026
1188
  transpilePackages: packagesToTranspile,
1027
1189
  workspaceMap,
1028
1190
  bundlerOptions,
1029
- rootDir
1191
+ rootDir,
1192
+ externals
1030
1193
  })
1031
1194
  });
1032
1195
  const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
@@ -1034,6 +1197,8 @@ async function buildExternalDependencies(virtualDependencies, {
1034
1197
  format: "esm",
1035
1198
  dir: rootDir,
1036
1199
  entryFileNames: "[name].mjs",
1200
+ // used to get the filename of the actual error
1201
+ sourcemap: true,
1037
1202
  /**
1038
1203
  * Rollup creates chunks for common dependencies, but these chunks are by default written to the root directory instead of respecting the entryFileNames structure.
1039
1204
  * So we want to write them to the `.mastra/output` folder as well.
@@ -1042,9 +1207,9 @@ async function buildExternalDependencies(virtualDependencies, {
1042
1207
  if (bundlerOptions.isDev) {
1043
1208
  const importedFromPackages = /* @__PURE__ */ new Set();
1044
1209
  for (const moduleId of chunkInfo.moduleIds) {
1045
- const normalized = slash(moduleId);
1210
+ const normalized = chunk2OTEFUER_cjs.slash(moduleId);
1046
1211
  for (const [pkgName, pkgInfo] of workspaceMap.entries()) {
1047
- const location = slash(pkgInfo.location);
1212
+ const location = chunk2OTEFUER_cjs.slash(pkgInfo.location);
1048
1213
  if (normalized.startsWith(location)) {
1049
1214
  importedFromPackages.add(pkgName);
1050
1215
  break;
@@ -1066,11 +1231,12 @@ async function buildExternalDependencies(virtualDependencies, {
1066
1231
  if (importedFromPackages.size === 1) {
1067
1232
  const [pkgName] = importedFromPackages;
1068
1233
  const workspaceLocation = workspaceMap.get(pkgName).location;
1069
- return prepareEntryFileName(getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
1234
+ return prepareEntryFileName(chunk2OTEFUER_cjs.getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
1070
1235
  }
1071
1236
  }
1072
1237
  return `${outputDirRelative}/[name].mjs`;
1073
1238
  },
1239
+ assetFileNames: `${outputDirRelative}/[name][extname]`,
1074
1240
  hoistTransitiveImports: false
1075
1241
  });
1076
1242
  await bundler.close();
@@ -1079,7 +1245,7 @@ async function buildExternalDependencies(virtualDependencies, {
1079
1245
  function findExternalImporter(module, external, allOutputs) {
1080
1246
  const capturedFiles = /* @__PURE__ */ new Set();
1081
1247
  for (const id of module.imports) {
1082
- if (id === external) {
1248
+ if (chunk2OTEFUER_cjs.isDependencyPartOfPackage(id, external)) {
1083
1249
  return module;
1084
1250
  } else {
1085
1251
  if (id.endsWith(".mjs")) {
@@ -1125,7 +1291,7 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
1125
1291
  isDev
1126
1292
  }
1127
1293
  });
1128
- const moduleResolveMap = /* @__PURE__ */ new Map();
1294
+ const moduleResolveMap2 = /* @__PURE__ */ new Map();
1129
1295
  const filteredChunks = output.filter((o) => o.type === "chunk");
1130
1296
  for (const o of filteredChunks.filter((o2) => o2.isEntry || o2.isDynamicEntry)) {
1131
1297
  for (const external of allExternals) {
@@ -1135,10 +1301,10 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
1135
1301
  const importer = findExternalImporter(o, external, filteredChunks);
1136
1302
  if (importer) {
1137
1303
  const fullPath = path2__namespace.join(workspaceRoot || projectRoot, importer.fileName);
1138
- let innerMap = moduleResolveMap.get(fullPath);
1304
+ let innerMap = moduleResolveMap2.get(fullPath);
1139
1305
  if (!innerMap) {
1140
1306
  innerMap = /* @__PURE__ */ new Map();
1141
- moduleResolveMap.set(fullPath, innerMap);
1307
+ moduleResolveMap2.set(fullPath, innerMap);
1142
1308
  }
1143
1309
  if (importer.moduleIds.length) {
1144
1310
  innerMap.set(
@@ -1150,7 +1316,7 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
1150
1316
  }
1151
1317
  }
1152
1318
  const usedExternals = /* @__PURE__ */ Object.create(null);
1153
- for (const [fullPath, innerMap] of moduleResolveMap) {
1319
+ for (const [fullPath, innerMap] of moduleResolveMap2) {
1154
1320
  const innerObj = /* @__PURE__ */ Object.create(null);
1155
1321
  for (const [external, value] of innerMap) {
1156
1322
  innerObj[external] = value;
@@ -1159,6 +1325,108 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
1159
1325
  }
1160
1326
  return { output, fileNameToDependencyMap, usedExternals };
1161
1327
  }
1328
+
1329
+ // ../../node_modules/.pnpm/stacktrace-parser@0.1.11/node_modules/stacktrace-parser/dist/stack-trace-parser.esm.js
1330
+ var UNKNOWN_FUNCTION = "<unknown>";
1331
+ function parse(stackString) {
1332
+ var lines = stackString.split("\n");
1333
+ return lines.reduce(function(stack, line) {
1334
+ var parseResult = parseChrome(line) || parseWinjs(line) || parseGecko(line) || parseNode(line) || parseJSC(line);
1335
+ if (parseResult) {
1336
+ stack.push(parseResult);
1337
+ }
1338
+ return stack;
1339
+ }, []);
1340
+ }
1341
+ var chromeRe = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|rsc|<anonymous>|\/|[a-z]:\\|\\\\).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
1342
+ var chromeEvalRe = /\((\S*)(?::(\d+))(?::(\d+))\)/;
1343
+ function parseChrome(line) {
1344
+ var parts = chromeRe.exec(line);
1345
+ if (!parts) {
1346
+ return null;
1347
+ }
1348
+ var isNative = parts[2] && parts[2].indexOf("native") === 0;
1349
+ var isEval = parts[2] && parts[2].indexOf("eval") === 0;
1350
+ var submatch = chromeEvalRe.exec(parts[2]);
1351
+ if (isEval && submatch != null) {
1352
+ parts[2] = submatch[1];
1353
+ parts[3] = submatch[2];
1354
+ parts[4] = submatch[3];
1355
+ }
1356
+ return {
1357
+ file: !isNative ? parts[2] : null,
1358
+ methodName: parts[1] || UNKNOWN_FUNCTION,
1359
+ arguments: isNative ? [parts[2]] : [],
1360
+ lineNumber: parts[3] ? +parts[3] : null,
1361
+ column: parts[4] ? +parts[4] : null
1362
+ };
1363
+ }
1364
+ var winjsRe = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|rsc|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
1365
+ function parseWinjs(line) {
1366
+ var parts = winjsRe.exec(line);
1367
+ if (!parts) {
1368
+ return null;
1369
+ }
1370
+ return {
1371
+ file: parts[2],
1372
+ methodName: parts[1] || UNKNOWN_FUNCTION,
1373
+ arguments: [],
1374
+ lineNumber: +parts[3],
1375
+ column: parts[4] ? +parts[4] : null
1376
+ };
1377
+ }
1378
+ var geckoRe = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|rsc|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i;
1379
+ var geckoEvalRe = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
1380
+ function parseGecko(line) {
1381
+ var parts = geckoRe.exec(line);
1382
+ if (!parts) {
1383
+ return null;
1384
+ }
1385
+ var isEval = parts[3] && parts[3].indexOf(" > eval") > -1;
1386
+ var submatch = geckoEvalRe.exec(parts[3]);
1387
+ if (isEval && submatch != null) {
1388
+ parts[3] = submatch[1];
1389
+ parts[4] = submatch[2];
1390
+ parts[5] = null;
1391
+ }
1392
+ return {
1393
+ file: parts[3],
1394
+ methodName: parts[1] || UNKNOWN_FUNCTION,
1395
+ arguments: parts[2] ? parts[2].split(",") : [],
1396
+ lineNumber: parts[4] ? +parts[4] : null,
1397
+ column: parts[5] ? +parts[5] : null
1398
+ };
1399
+ }
1400
+ var javaScriptCoreRe = /^\s*(?:([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$/i;
1401
+ function parseJSC(line) {
1402
+ var parts = javaScriptCoreRe.exec(line);
1403
+ if (!parts) {
1404
+ return null;
1405
+ }
1406
+ return {
1407
+ file: parts[3],
1408
+ methodName: parts[1] || UNKNOWN_FUNCTION,
1409
+ arguments: [],
1410
+ lineNumber: +parts[4],
1411
+ column: parts[5] ? +parts[5] : null
1412
+ };
1413
+ }
1414
+ var nodeRe = /^\s*at (?:((?:\[object object\])?[^\\/]+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i;
1415
+ function parseNode(line) {
1416
+ var parts = nodeRe.exec(line);
1417
+ if (!parts) {
1418
+ return null;
1419
+ }
1420
+ return {
1421
+ file: parts[2],
1422
+ methodName: parts[1] || UNKNOWN_FUNCTION,
1423
+ arguments: [],
1424
+ lineNumber: +parts[3],
1425
+ column: parts[4] ? +parts[4] : null
1426
+ };
1427
+ }
1428
+
1429
+ // src/build/analyze.ts
1162
1430
  function throwExternalDependencyError({
1163
1431
  errorId,
1164
1432
  moduleName,
@@ -1182,6 +1450,110 @@ export const mastra = new Mastra({
1182
1450
  })`
1183
1451
  });
1184
1452
  }
1453
+ function getPackageNameFromBundledModuleName(moduleName) {
1454
+ const chunks = moduleName.split("-");
1455
+ if (!chunks.length) {
1456
+ return moduleName;
1457
+ }
1458
+ if (chunks[0]?.startsWith("@")) {
1459
+ return chunks.slice(0, 2).join("/");
1460
+ }
1461
+ return chunks[0];
1462
+ }
1463
+ function validateError(err, file, {
1464
+ binaryMapData,
1465
+ workspaceMap
1466
+ }) {
1467
+ let moduleName = null;
1468
+ let errorConfig = null;
1469
+ if (err instanceof ValidationError) {
1470
+ const parsedStack = parse(err.stack);
1471
+ if (err.type === "TypeError") {
1472
+ const pkgNameRegex = /.*node_modules\/([^\/]+)\//;
1473
+ const stacktraceFrame = parsedStack.find((frame) => frame.file && pkgNameRegex.test(frame.file));
1474
+ if (stacktraceFrame) {
1475
+ const match = stacktraceFrame.file.match(pkgNameRegex);
1476
+ moduleName = match?.[1] ?? getPackageNameFromBundledModuleName(path2.basename(file.name));
1477
+ } else {
1478
+ moduleName = getPackageNameFromBundledModuleName(path2.basename(file.name));
1479
+ }
1480
+ errorConfig = {
1481
+ id: "DEPLOYER_ANALYZE_TYPE_ERROR",
1482
+ messagePrefix: `Mastra wasn't able to bundle "${moduleName}", might be an older commonJS module. Please add`
1483
+ };
1484
+ } else if (err.stack?.includes?.("[ERR_MODULE_NOT_FOUND]")) {
1485
+ moduleName = err.message.match(/Cannot find package '([^']+)'/)?.[1];
1486
+ const parentModuleName = getPackageNameFromBundledModuleName(path2.basename(file.name));
1487
+ errorConfig = {
1488
+ id: "DEPLOYER_ANALYZE_MODULE_NOT_FOUND",
1489
+ messagePrefix: `Mastra wasn't able to build your project, We couldn't load "${moduleName}" from "${parentModuleName}". Make sure "${moduleName}" is installed or add`
1490
+ };
1491
+ if (moduleName === parentModuleName) {
1492
+ return;
1493
+ }
1494
+ }
1495
+ }
1496
+ if (err.message.includes("No native build was found")) {
1497
+ const pkgName = getPackageNameFromBundledModuleName(path2.basename(file.name));
1498
+ moduleName = binaryMapData[file.fileName]?.[0] ?? pkgName;
1499
+ errorConfig = {
1500
+ id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
1501
+ messagePrefix: "We found a binary dependency in your bundle but we cannot bundle it yet. Please add"
1502
+ };
1503
+ }
1504
+ if (moduleName && workspaceMap.has(moduleName)) {
1505
+ throw new error.MastraError({
1506
+ id: "DEPLOYER_ANALYZE_ERROR_IN_WORKSPACE",
1507
+ domain: error.ErrorDomain.DEPLOYER,
1508
+ category: error.ErrorCategory.USER,
1509
+ details: {
1510
+ // importFile: moduleName,
1511
+ packageName: moduleName
1512
+ },
1513
+ text: `We found an error in the ${moduleName} workspace package. Please find the offending package and fix the error.
1514
+ Error: ${err.stack}`
1515
+ });
1516
+ }
1517
+ if (errorConfig && moduleName) {
1518
+ throwExternalDependencyError({
1519
+ errorId: errorConfig.id,
1520
+ moduleName,
1521
+ packageName: moduleName,
1522
+ messagePrefix: errorConfig.messagePrefix
1523
+ });
1524
+ }
1525
+ }
1526
+ async function validateFile(root, file, {
1527
+ binaryMapData,
1528
+ moduleResolveMapLocation,
1529
+ logger,
1530
+ workspaceMap
1531
+ }) {
1532
+ try {
1533
+ if (!file.isDynamicEntry && file.isEntry) {
1534
+ await validate(path2.join(root, file.fileName), {
1535
+ moduleResolveMapLocation,
1536
+ injectESMShim: false
1537
+ });
1538
+ }
1539
+ } catch (err) {
1540
+ let errorToHandle = err;
1541
+ if (err instanceof ValidationError && err.type === "ReferenceError" && (err.message.startsWith("__dirname") || err.message.startsWith("__filename"))) {
1542
+ try {
1543
+ await validate(path2.join(root, file.fileName), {
1544
+ moduleResolveMapLocation,
1545
+ injectESMShim: true
1546
+ });
1547
+ errorToHandle = null;
1548
+ } catch (err2) {
1549
+ errorToHandle = err2;
1550
+ }
1551
+ }
1552
+ if (errorToHandle instanceof Error) {
1553
+ validateError(errorToHandle, file, { binaryMapData, workspaceMap });
1554
+ }
1555
+ }
1556
+ }
1185
1557
  async function validateOutput({
1186
1558
  output,
1187
1559
  reverseVirtualReferenceMap,
@@ -1195,60 +1567,30 @@ async function validateOutput({
1195
1567
  externalDependencies: /* @__PURE__ */ new Set(),
1196
1568
  workspaceMap
1197
1569
  };
1198
- await promises.writeFile(path2.join(outputDir, "module-resolve-map.json"), JSON.stringify(usedExternals, null, 2));
1199
1570
  for (const deps of Object.values(usedExternals)) {
1200
1571
  for (const dep of Object.keys(deps)) {
1201
1572
  result.externalDependencies.add(dep);
1202
1573
  }
1203
1574
  }
1575
+ let binaryMapData = {};
1576
+ if (fs.existsSync(path2.join(outputDir, "binary-map.json"))) {
1577
+ const binaryMap = await promises.readFile(path2.join(outputDir, "binary-map.json"), "utf-8");
1578
+ binaryMapData = JSON.parse(binaryMap);
1579
+ }
1204
1580
  for (const file of output) {
1205
1581
  if (file.type === "asset") {
1206
1582
  continue;
1207
1583
  }
1208
- try {
1209
- logger.debug(`Validating if ${file.fileName} is a valid module.`);
1210
- if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
1211
- result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
1212
- }
1213
- if (!file.isDynamicEntry && file.isEntry) {
1214
- await validate(path2.join(projectRoot, file.fileName));
1215
- }
1216
- } catch (err) {
1217
- if (err instanceof Error) {
1218
- let moduleName = null;
1219
- let errorConfig = null;
1220
- if (err.message.includes("[ERR_MODULE_NOT_FOUND]")) {
1221
- const moduleIdName = file.moduleIds.length >= 2 ? file.moduleIds[file.moduleIds.length - 2] : void 0;
1222
- const fallbackName = file.name.split("/").pop();
1223
- moduleName = moduleIdName ?? fallbackName;
1224
- errorConfig = {
1225
- id: "DEPLOYER_ANALYZE_MODULE_NOT_FOUND",
1226
- messagePrefix: "Mastra wasn't able to build your project. Please add"
1227
- };
1228
- } else if (err.message.includes("Error: No native build was found for ")) {
1229
- moduleName = findNativePackageModule(file.moduleIds);
1230
- errorConfig = {
1231
- id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
1232
- messagePrefix: "We found a binary dependency in your bundle. Please add"
1233
- };
1234
- }
1235
- if (moduleName && errorConfig) {
1236
- const pkgInfo = await localPkg.getPackageInfo(moduleName);
1237
- const packageName = pkgInfo?.packageJson?.name;
1238
- if (packageName) {
1239
- throwExternalDependencyError({
1240
- errorId: errorConfig.id,
1241
- moduleName,
1242
- packageName,
1243
- messagePrefix: errorConfig.messagePrefix
1244
- });
1245
- } else {
1246
- logger.debug(`Could not determine the module name for file ${file.fileName}`);
1247
- }
1248
- }
1249
- logger.debug(`Error while validating module ${file.fileName}: ${err.message}`);
1250
- }
1584
+ logger.debug(`Validating if ${file.fileName} is a valid module.`);
1585
+ if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
1586
+ result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
1251
1587
  }
1588
+ await validateFile(projectRoot, file, {
1589
+ binaryMapData,
1590
+ moduleResolveMapLocation: path2.join(outputDir, "module-resolve-map.json"),
1591
+ logger,
1592
+ workspaceMap
1593
+ });
1252
1594
  }
1253
1595
  return result;
1254
1596
  }
@@ -1280,17 +1622,26 @@ If you think your configuration is valid, please open an issue.`);
1280
1622
  const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
1281
1623
  let index = 0;
1282
1624
  const depsToOptimize = /* @__PURE__ */ new Map();
1625
+ const { externals: customExternals = [] } = bundlerOptions || {};
1626
+ const allExternals = [...GLOBAL_EXTERNALS, ...customExternals];
1283
1627
  logger.info("Analyzing dependencies...");
1628
+ const allUsedExternals = /* @__PURE__ */ new Set();
1284
1629
  for (const entry of entries) {
1285
1630
  const isVirtualFile = entry.includes("\n") || !fs.existsSync(entry);
1286
1631
  const analyzeResult = await analyzeEntry({ entry, isVirtualFile }, mastraEntry, {
1287
1632
  logger,
1288
1633
  sourcemapEnabled: bundlerOptions?.sourcemap ?? false,
1289
1634
  workspaceMap,
1290
- projectRoot
1635
+ projectRoot,
1636
+ shouldCheckTransitiveDependencies: isDev
1291
1637
  });
1292
1638
  await promises.writeFile(path2.join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
1293
1639
  for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
1640
+ const isPartOfExternals = allExternals.some((external) => chunk2OTEFUER_cjs.isDependencyPartOfPackage(dep, external));
1641
+ if (isPartOfExternals) {
1642
+ allUsedExternals.add(dep);
1643
+ continue;
1644
+ }
1294
1645
  if (depsToOptimize.has(dep)) {
1295
1646
  const existingEntry = depsToOptimize.get(dep);
1296
1647
  depsToOptimize.set(dep, {
@@ -1309,14 +1660,13 @@ If you think your configuration is valid, please open an issue.`);
1309
1660
  }
1310
1661
  }
1311
1662
  }
1312
- logger.debug(`Analyzed dependencies: ${Array.from(depsToOptimize.keys()).join(", ")}`);
1663
+ const sortedDeps = Array.from(depsToOptimize.keys()).sort();
1313
1664
  logger.info("Optimizing dependencies...");
1314
- logger.debug(
1315
- `${Array.from(depsToOptimize.keys()).map((key) => `- ${key}`).join("\n")}`
1316
- );
1665
+ logger.debug(`${sortedDeps.map((key) => `- ${key}`).join("\n")}`);
1317
1666
  const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
1318
1667
  bundlerOptions: {
1319
1668
  ...bundlerOptions,
1669
+ externals: allExternals,
1320
1670
  enableEsmShim,
1321
1671
  isDev
1322
1672
  },
@@ -1335,7 +1685,10 @@ If you think your configuration is valid, please open an issue.`);
1335
1685
  },
1336
1686
  logger
1337
1687
  );
1338
- return result;
1688
+ return {
1689
+ ...result,
1690
+ externalDependencies: /* @__PURE__ */ new Set([...result.externalDependencies, ...Array.from(allUsedExternals)])
1691
+ };
1339
1692
  }
1340
1693
 
1341
1694
  exports.aliasHono = aliasHono;
@@ -1343,12 +1696,10 @@ exports.analyzeBundle = analyzeBundle;
1343
1696
  exports.esbuild = esbuild;
1344
1697
  exports.extractMastraOption = extractMastraOption;
1345
1698
  exports.getBundlerOptions = getBundlerOptions;
1346
- exports.getPackageName = getPackageName;
1347
- exports.getPackageRootPath = getPackageRootPath;
1348
1699
  exports.getWorkspaceInformation = getWorkspaceInformation;
1349
1700
  exports.removeAllOptionsFromMastraExcept = removeAllOptionsFromMastraExcept;
1350
1701
  exports.removeDeployer = removeDeployer2;
1351
- exports.slash = slash;
1702
+ exports.subpathExternalsResolver = subpathExternalsResolver;
1352
1703
  exports.tsConfigPaths = tsConfigPaths;
1353
- //# sourceMappingURL=chunk-C74EXQSL.cjs.map
1354
- //# sourceMappingURL=chunk-C74EXQSL.cjs.map
1704
+ //# sourceMappingURL=chunk-PRPZEAA3.cjs.map
1705
+ //# sourceMappingURL=chunk-PRPZEAA3.cjs.map