@mastra/deployer 1.68.0-alpha.0 → 1.68.0-alpha.10

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 (121) hide show
  1. package/dist/_types/@hono_node-server/package.json +1 -0
  2. package/dist/_types/@mastra_hono/package.json +1 -0
  3. package/dist/{analyze-hp4aHpms.cjs → analyze-ClD1cvPT.cjs} +150 -99
  4. package/dist/analyze-ClD1cvPT.cjs.map +1 -0
  5. package/dist/{analyze-B5HY26Tt.js → analyze-DEk6PGTI.js} +148 -96
  6. package/dist/analyze-DEk6PGTI.js.map +1 -0
  7. package/dist/{arktype-aI7TBD0R-S0daSmHG.js → arktype-aI7TBD0R-BGjyzmsj.js} +2 -2
  8. package/dist/{arktype-aI7TBD0R-S0daSmHG.js.map → arktype-aI7TBD0R-BGjyzmsj.js.map} +1 -1
  9. package/dist/{arktype-aI7TBD0R-BuTX_Phx.cjs → arktype-aI7TBD0R-DCxjN6oF.cjs} +2 -2
  10. package/dist/{arktype-aI7TBD0R-BuTX_Phx.cjs.map → arktype-aI7TBD0R-DCxjN6oF.cjs.map} +1 -1
  11. package/dist/build/analyze/analyzeEntry.d.ts +8 -1
  12. package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
  13. package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
  14. package/dist/build/analyze.cjs +1 -1
  15. package/dist/build/analyze.d.ts +2 -1
  16. package/dist/build/analyze.d.ts.map +1 -1
  17. package/dist/build/analyze.js +1 -1
  18. package/dist/build/bundler.cjs +2 -1
  19. package/dist/build/bundler.d.ts +10 -0
  20. package/dist/build/bundler.d.ts.map +1 -1
  21. package/dist/build/bundler.js +2 -2
  22. package/dist/build/index.cjs +6 -6
  23. package/dist/build/index.js +6 -6
  24. package/dist/build/package-info.d.ts +4 -0
  25. package/dist/build/package-info.d.ts.map +1 -1
  26. package/dist/build/plugins/subpath-externals-resolver.d.ts +2 -1
  27. package/dist/build/plugins/subpath-externals-resolver.d.ts.map +1 -1
  28. package/dist/build/plugins/tsconfig-paths.d.ts +2 -1
  29. package/dist/build/plugins/tsconfig-paths.d.ts.map +1 -1
  30. package/dist/build/watcher.d.ts.map +1 -1
  31. package/dist/{build-Dit9VFE2.cjs → build-DJMEiMA1.cjs} +8 -7
  32. package/dist/build-DJMEiMA1.cjs.map +1 -0
  33. package/dist/{build-Boe3fe3L.js → build-JNlRQOvG.js} +8 -7
  34. package/dist/build-JNlRQOvG.js.map +1 -0
  35. package/dist/bundler/index.cjs +29 -62
  36. package/dist/bundler/index.cjs.map +1 -1
  37. package/dist/bundler/index.d.ts +1 -11
  38. package/dist/bundler/index.d.ts.map +1 -1
  39. package/dist/bundler/index.js +30 -63
  40. package/dist/bundler/index.js.map +1 -1
  41. package/dist/bundler/workspaceDependencies.d.ts +1 -1
  42. package/dist/bundler/workspaceDependencies.d.ts.map +1 -1
  43. package/dist/{bundler-CzQiVHzN.js → bundler-CC0klr1q.js} +63 -13
  44. package/dist/bundler-CC0klr1q.js.map +1 -0
  45. package/dist/{bundler-BKf2S2r_.cjs → bundler-CjoP35xh.cjs} +74 -11
  46. package/dist/bundler-CjoP35xh.cjs.map +1 -0
  47. package/dist/{bundlerOptions-I2E5y2Wp.cjs → bundlerOptions-09fXosF4.cjs} +2 -2
  48. package/dist/{bundlerOptions-I2E5y2Wp.cjs.map → bundlerOptions-09fXosF4.cjs.map} +1 -1
  49. package/dist/{bundlerOptions-BSySFLb3.js → bundlerOptions-BaAR_H3U.js} +2 -2
  50. package/dist/{bundlerOptions-BSySFLb3.js.map → bundlerOptions-BaAR_H3U.js.map} +1 -1
  51. package/dist/core-D3wM1JKp.js +1159 -0
  52. package/dist/core-D3wM1JKp.js.map +1 -0
  53. package/dist/core-QL_X0T4Y.cjs +1159 -0
  54. package/dist/core-QL_X0T4Y.cjs.map +1 -0
  55. package/dist/docs/SKILL.md +1 -1
  56. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  57. package/dist/docs/references/docs-deployment-monorepo.md +2 -2
  58. package/dist/{effect-QlVUlMFu-tf02PTZR.cjs → effect-QlVUlMFu-B2nZ842E.cjs} +3 -3
  59. package/dist/{effect-QlVUlMFu-tf02PTZR.cjs.map → effect-QlVUlMFu-B2nZ842E.cjs.map} +1 -1
  60. package/dist/{effect-QlVUlMFu-BN-VJnMF.js → effect-QlVUlMFu-DbWuPaWV.js} +3 -3
  61. package/dist/{effect-QlVUlMFu-BN-VJnMF.js.map → effect-QlVUlMFu-DbWuPaWV.js.map} +1 -1
  62. package/dist/{esm-DZ1Siz1C.cjs → esm-Ai6osZ1a.cjs} +61 -50
  63. package/dist/esm-Ai6osZ1a.cjs.map +1 -0
  64. package/dist/{esm-B51vJPGv.js → esm-D-wYOO-S.js} +61 -50
  65. package/dist/esm-D-wYOO-S.js.map +1 -0
  66. package/dist/{index-CLddUTqr-eO-ae7Sx.js → index-CLddUTqr-BXqo9et4.js} +8 -8
  67. package/dist/{index-CLddUTqr-eO-ae7Sx.js.map → index-CLddUTqr-BXqo9et4.js.map} +1 -1
  68. package/dist/{index-CLddUTqr-DS5tJ3WV.cjs → index-CLddUTqr-DsGkVS-W.cjs} +8 -8
  69. package/dist/{index-CLddUTqr-DS5tJ3WV.cjs.map → index-CLddUTqr-DsGkVS-W.cjs.map} +1 -1
  70. package/dist/index.cjs +3 -3
  71. package/dist/index.js +3 -3
  72. package/dist/server/index.cjs +21 -19
  73. package/dist/server/index.cjs.map +1 -1
  74. package/dist/server/index.d.ts +2 -2
  75. package/dist/server/index.js +22 -20
  76. package/dist/server/index.js.map +1 -1
  77. package/dist/services/deps.d.ts +1 -1
  78. package/dist/services/deps.d.ts.map +1 -1
  79. package/dist/services/index.cjs +1 -1
  80. package/dist/services/index.js +1 -1
  81. package/dist/{services-BLvNG7v7.cjs → services-Beob47UW.cjs} +42 -23
  82. package/dist/services-Beob47UW.cjs.map +1 -0
  83. package/dist/{services-B9KRKBT-.js → services-Lm6PRS4D.js} +42 -23
  84. package/dist/services-Lm6PRS4D.js.map +1 -0
  85. package/dist/{sury-CWZTCd75-YUPbTtKO.cjs → sury-CWZTCd75-ChXu4j-p.cjs} +3 -3
  86. package/dist/{sury-CWZTCd75-YUPbTtKO.cjs.map → sury-CWZTCd75-ChXu4j-p.cjs.map} +1 -1
  87. package/dist/{sury-CWZTCd75-ClSNrMWF.js → sury-CWZTCd75-OKz7uWLi.js} +3 -3
  88. package/dist/{sury-CWZTCd75-ClSNrMWF.js.map → sury-CWZTCd75-OKz7uWLi.js.map} +1 -1
  89. package/dist/{typebox-Dei93FPO-CVSJ3SAf.js → typebox-Dei93FPO-C5ACKU09.js} +2 -2
  90. package/dist/{typebox-Dei93FPO-CVSJ3SAf.js.map → typebox-Dei93FPO-C5ACKU09.js.map} +1 -1
  91. package/dist/{typebox-Dei93FPO-BTBshlGz.cjs → typebox-Dei93FPO-KTtPU745.cjs} +2 -2
  92. package/dist/{typebox-Dei93FPO-BTBshlGz.cjs.map → typebox-Dei93FPO-KTtPU745.cjs.map} +1 -1
  93. package/dist/{utils-DYi43Kp4.js → utils-Bl3Lm7SI.js} +1 -2
  94. package/dist/{utils-DYi43Kp4.js.map → utils-Bl3Lm7SI.js.map} +1 -1
  95. package/dist/{utils-7WDNT3Ca.cjs → utils-Bsr_sEcH.cjs} +2 -2
  96. package/dist/{utils-7WDNT3Ca.cjs.map → utils-Bsr_sEcH.cjs.map} +1 -1
  97. package/dist/{valibot--1zFm7rT-Dn5WqdyK.cjs → valibot--1zFm7rT-BeX3W1HK.cjs} +3 -3
  98. package/dist/{valibot--1zFm7rT-Dn5WqdyK.cjs.map → valibot--1zFm7rT-BeX3W1HK.cjs.map} +1 -1
  99. package/dist/{valibot--1zFm7rT-BxcEC3Pu.js → valibot--1zFm7rT-BuVb-6oJ.js} +3 -3
  100. package/dist/{valibot--1zFm7rT-BxcEC3Pu.js.map → valibot--1zFm7rT-BuVb-6oJ.js.map} +1 -1
  101. package/dist/validator/custom-resolver.cjs +1 -1
  102. package/dist/validator/custom-resolver.js +1 -1
  103. package/dist/{zod-Bwrt9trS-Bd40XYOT.js → zod-Bwrt9trS-D5b1oyiT.js} +5 -5
  104. package/dist/{zod-Bwrt9trS-Bd40XYOT.js.map → zod-Bwrt9trS-D5b1oyiT.js.map} +1 -1
  105. package/dist/{zod-Bwrt9trS-Bi11nE9Q.cjs → zod-Bwrt9trS-DGQs9DWc.cjs} +5 -5
  106. package/dist/{zod-Bwrt9trS-Bi11nE9Q.cjs.map → zod-Bwrt9trS-DGQs9DWc.cjs.map} +1 -1
  107. package/package.json +15 -14
  108. package/dist/analyze-B5HY26Tt.js.map +0 -1
  109. package/dist/analyze-hp4aHpms.cjs.map +0 -1
  110. package/dist/build-Boe3fe3L.js.map +0 -1
  111. package/dist/build-Dit9VFE2.cjs.map +0 -1
  112. package/dist/bundler-BKf2S2r_.cjs.map +0 -1
  113. package/dist/bundler-CzQiVHzN.js.map +0 -1
  114. package/dist/core-D0wEgdn3.cjs +0 -790
  115. package/dist/core-D0wEgdn3.cjs.map +0 -1
  116. package/dist/core-DF65PJXc.js +0 -790
  117. package/dist/core-DF65PJXc.js.map +0 -1
  118. package/dist/esm-B51vJPGv.js.map +0 -1
  119. package/dist/esm-DZ1Siz1C.cjs.map +0 -1
  120. package/dist/services-B9KRKBT-.js.map +0 -1
  121. package/dist/services-BLvNG7v7.cjs.map +0 -1
@@ -1,7 +1,6 @@
1
- import { a as getPackageName, c as isBuiltinModule, f as rollupSafeName, i as getNodeResolveOptions, l as isDependencyPartOfPackage, m as slash, r as getCompiledDepCachePath, s as isBareModuleSpecifier, u as isExternalProtocolImport } from "./utils-DYi43Kp4.js";
2
- import { i as DepsService } from "./services-B9KRKBT-.js";
3
- import { a as tsConfigPaths, c as protocolExternalResolver, d as getPackageRootPath, f as esmShim, i as mastraToolsAliasPlugin, o as subpathExternalsResolver, p as esbuild, r as mastraInternalAliasPlugin, s as removeDeployer, u as getPackageMetadata } from "./bundler-CzQiVHzN.js";
4
- import { spawn } from "child_process";
1
+ import { a as getPackageName, c as isBuiltinModule, f as rollupSafeName, i as getNodeResolveOptions, l as isDependencyPartOfPackage, m as slash, r as getCompiledDepCachePath, s as isBareModuleSpecifier, u as isExternalProtocolImport } from "./utils-Bl3Lm7SI.js";
2
+ import { i as DepsService } from "./services-Lm6PRS4D.js";
3
+ import { a as mastraToolsAliasPlugin, c as removeDeployer, d as getPackageInfo$1, f as getPackageMetadata, h as esbuild, i as mastraInternalAliasPlugin, l as protocolExternalResolver, m as esmShim, o as tsConfigPaths, p as getPackageRootPath, s as subpathExternalsResolver } from "./bundler-CC0klr1q.js";
5
4
  import { existsSync } from "fs";
6
5
  import { readFile, writeFile } from "fs/promises";
7
6
  import * as path$1 from "path";
@@ -10,18 +9,18 @@ import { ErrorCategory, ErrorDomain, MastraBaseError, MastraError } from "@mastr
10
9
  import virtual from "@rollup/plugin-virtual";
11
10
  import * as pkg from "empathic/package";
12
11
  import { transformAsync, transformSync, types } from "@babel/core";
13
- import slugify from "@sindresorhus/slugify";
14
12
  import { createWorkspacesCache, findWorkspaces, findWorkspacesRoot } from "find-workspaces";
15
13
  import { ensureDir } from "fs-extra";
14
+ import { spawn } from "child_process";
16
15
  import { fileURLToPath, pathToFileURL } from "url";
17
16
  import commonjs from "@rollup/plugin-commonjs";
18
17
  import json from "@rollup/plugin-json";
18
+ import { getPackageInfo, resolveModule } from "local-pkg";
19
19
  import { rollup } from "rollup";
20
20
  import { optimizeLodashImports } from "@optimize-lodash/rollup-plugin";
21
21
  import nodeResolve from "@rollup/plugin-node-resolve";
22
- import { getPackageInfo } from "local-pkg";
23
- import { basename as basename$1 } from "path/posix";
24
22
  import * as resolve$1 from "resolve.exports";
23
+ import { basename as basename$1 } from "path/posix";
25
24
  //#region \0rolldown/runtime.js
26
25
  var __create = Object.create;
27
26
  var __defProp = Object.defineProperty;
@@ -139,24 +138,6 @@ var import_stack_trace_parser_cjs = /* @__PURE__ */ __toESM((/* @__PURE__ */ __c
139
138
  }
140
139
  exports.parse = parse;
141
140
  })))(), 1);
142
- const isExportTargetImportable = (target) => {
143
- if (!target) return false;
144
- if (typeof target === "string") return true;
145
- if (Array.isArray(target)) return target.some(isExportTargetImportable);
146
- if (typeof target !== "object") return false;
147
- return Object.values(target).some(isExportTargetImportable);
148
- };
149
- const hasRootExport = (exportsField) => {
150
- if (exportsField === void 0) return true;
151
- if (typeof exportsField === "string" || Array.isArray(exportsField)) return isExportTargetImportable(exportsField);
152
- if (!exportsField || typeof exportsField !== "object") return false;
153
- const exportMap = exportsField;
154
- const exportKeys = Object.keys(exportMap);
155
- if (exportKeys.length === 0) return false;
156
- if (Object.prototype.hasOwnProperty.call(exportMap, ".")) return isExportTargetImportable(exportMap["."]);
157
- if (exportKeys.some((key) => key.startsWith("./"))) return false;
158
- return isExportTargetImportable(exportMap);
159
- };
160
141
  /**
161
142
  * Create a shared cache for find-workspaces
162
143
  */
@@ -193,7 +174,7 @@ async function getWorkspaceInformation({ dir = process.cwd(), mastraEntryFile })
193
174
  /**
194
175
  * Collects all transitive workspace dependencies and their TGZ paths
195
176
  */
196
- const collectTransitiveWorkspaceDependencies = ({ workspaceMap, initialDependencies, logger }) => {
177
+ const collectTransitiveWorkspaceDependencies = async ({ workspaceMap, initialDependencies, logger }) => {
197
178
  const usedWorkspacePackages = /* @__PURE__ */ new Set();
198
179
  const queue = Array.from(initialDependencies);
199
180
  const resolutions = {};
@@ -208,6 +189,7 @@ const collectTransitiveWorkspaceDependencies = ({ workspaceMap, initialDependenc
208
189
  if (!root) throw new Error("Could not find workspace root");
209
190
  const depsService = new DepsService(root.location);
210
191
  depsService.__setLogger(logger);
192
+ const slugify = (await import("@sindresorhus/slugify")).default;
211
193
  const sanitizedName = slugify(pkgName);
212
194
  resolutions[pkgName] = depsService.getWorkspaceDependencyPath({
213
195
  pkgName: sanitizedName,
@@ -231,6 +213,7 @@ const packWorkspaceDependencies = async ({ workspaceMap, usedWorkspacePackages,
231
213
  const depsService = new DepsService(root.location);
232
214
  depsService.__setLogger(logger);
233
215
  if (usedWorkspacePackages.size > 0) {
216
+ const slugify = (await import("@sindresorhus/slugify")).default;
234
217
  const workspaceDirPath = join(bundleOutputDir, "workspace-module");
235
218
  await ensureDir(workspaceDirPath);
236
219
  logger.info("Packaging workspace dependencies", { count: usedWorkspacePackages.size });
@@ -370,11 +353,26 @@ const DEPRECATED_EXTERNALS = [
370
353
  ];
371
354
  //#endregion
372
355
  //#region src/build/analyze/analyzeEntry.ts
356
+ function analysisExternals({ workspaceMap, externals, externalsPreset }) {
357
+ return {
358
+ name: "analysis-externals",
359
+ resolveId(source) {
360
+ if (!isBareModuleSpecifier(source)) return null;
361
+ const packageName = getPackageName(source);
362
+ if (packageName && workspaceMap.has(packageName)) return null;
363
+ if (externalsPreset || externals.some((external) => isDependencyPartOfPackage(source, external))) return {
364
+ id: source,
365
+ external: true
366
+ };
367
+ return null;
368
+ }
369
+ };
370
+ }
373
371
  /**
374
372
  * Configures and returns the Rollup plugins needed for analyzing entry files.
375
373
  * Sets up module resolution, transpilation, and custom alias handling for Mastra-specific imports.
376
374
  */
377
- function getInputPlugins$1({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
375
+ function getInputPlugins$1({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled, env, workspaceMap, externals, externalsPreset }) {
378
376
  let virtualPlugin = null;
379
377
  if (isVirtualFile) {
380
378
  virtualPlugin = virtual({ "#entry": entry });
@@ -387,8 +385,13 @@ function getInputPlugins$1({ entry, isVirtualFile }, mastraEntry, { sourcemapEna
387
385
  mastraInternalAliasPlugin(mastraEntry),
388
386
  mastraToolsAliasPlugin(),
389
387
  tsConfigPaths(),
388
+ analysisExternals({
389
+ workspaceMap,
390
+ externals,
391
+ externalsPreset
392
+ }),
390
393
  json(),
391
- esbuild(),
394
+ esbuild({ define: env }),
392
395
  commonjs({
393
396
  strictRequires: "debug",
394
397
  ignoreTryCatch: false,
@@ -405,7 +408,7 @@ function getInputPlugins$1({ entry, isVirtualFile }, mastraEntry, { sourcemapEna
405
408
  * Analyzes both static imports and dynamic imports while filtering out Node.js built-ins and ignored dependencies.
406
409
  * Identifies workspace packages and resolves package root paths for proper bundling optimization.
407
410
  */
408
- async function captureDependenciesToOptimize(output, workspaceMap, projectRoot, { logger, shouldCheckTransitiveDependencies }) {
411
+ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot, { logger, mastraEntry, shouldCheckTransitiveDependencies, env, analyzeCache, activeEntries, externals, externalsPreset }) {
409
412
  const depsToOptimize = /* @__PURE__ */ new Map();
410
413
  if (!output.facadeModuleId) throw new Error("Something went wrong, we could not find the package name of the entry file. Please open an issue.");
411
414
  let entryRootPath = projectRoot;
@@ -433,47 +436,58 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
433
436
  packageSpec
434
437
  });
435
438
  }
436
- const processedWorkspaceDeps = /* @__PURE__ */ new Set();
439
+ const processedWorkspaceEntries = /* @__PURE__ */ new Set();
437
440
  /**
438
441
  * Recursively discovers transitive workspace dependencies from package manifests.
439
442
  */
440
- function checkTransitiveDependencies(maxDepth = 10, currentDepth = 0) {
441
- if (currentDepth >= maxDepth) {
442
- logger.warn("Maximum dependency depth reached while checking transitive dependencies.");
443
- return;
444
- }
443
+ async function checkTransitiveDependencies() {
445
444
  const depsSnapshot = new Map(depsToOptimize);
446
- let hasAddedDeps = false;
447
445
  for (const [dep, meta] of depsSnapshot) {
448
- const pkgName = getPackageName(dep);
449
- if (!pkgName || !meta.isWorkspace || processedWorkspaceDeps.has(pkgName)) continue;
450
- processedWorkspaceDeps.add(pkgName);
451
- const workspaceInfo = workspaceMap.get(pkgName);
452
- if (!workspaceInfo?.dependencies) continue;
453
- for (const [innerDep, _innerDepVersion] of Object.entries(workspaceInfo.dependencies)) {
454
- const innerWorkspaceInfo = workspaceMap.get(innerDep);
455
- if (!innerWorkspaceInfo) continue;
456
- if (!hasRootExport(innerWorkspaceInfo.exports)) continue;
446
+ if (!getPackageName(dep) || !meta.isWorkspace) continue;
447
+ const importerPath = pathToFileURL(output.facadeModuleId.startsWith("\0virtual:") ? mastraEntry || projectRoot : output.facadeModuleId).href;
448
+ const resolvedPath = resolveModule(dep, { paths: [importerPath] });
449
+ if (!resolvedPath) {
450
+ logger.warn("Could not resolve path for workspace dependency", { dep });
451
+ continue;
452
+ }
453
+ const resolvedEntry = slash(resolvedPath);
454
+ if (processedWorkspaceEntries.has(resolvedEntry) || activeEntries.has(resolvedEntry)) continue;
455
+ processedWorkspaceEntries.add(resolvedEntry);
456
+ const analysis = await analyzeEntry({
457
+ entry: resolvedPath,
458
+ isVirtualFile: false
459
+ }, mastraEntry, {
460
+ workspaceMap,
461
+ projectRoot,
462
+ logger,
463
+ sourcemapEnabled: false,
464
+ env,
465
+ shouldCheckTransitiveDependencies: true,
466
+ analyzeCache,
467
+ activeEntries,
468
+ externals,
469
+ externalsPreset
470
+ });
471
+ if (!analysis?.dependencies) continue;
472
+ for (const [innerDep, innerMeta] of analysis.dependencies) {
473
+ if (!innerMeta.isWorkspace) continue;
457
474
  const existingMeta = depsToOptimize.get(innerDep);
458
475
  if (existingMeta) {
459
476
  depsToOptimize.set(innerDep, {
460
477
  ...existingMeta,
461
- exports: existingMeta.exports.includes("*") ? existingMeta.exports : [...existingMeta.exports, "*"]
478
+ exports: [.../* @__PURE__ */ new Set([...existingMeta.exports, ...innerMeta.exports])]
462
479
  });
463
480
  continue;
464
- }
465
- depsToOptimize.set(innerDep, {
466
- exports: ["*"],
467
- rootPath: slash(innerWorkspaceInfo.location),
481
+ } else depsToOptimize.set(innerDep, {
482
+ exports: innerMeta.exports,
483
+ rootPath: slash(innerMeta.rootPath || ""),
468
484
  isWorkspace: true,
469
- version: innerWorkspaceInfo.version
485
+ version: innerMeta.version
470
486
  });
471
- hasAddedDeps = true;
472
487
  }
473
488
  }
474
- if (hasAddedDeps) checkTransitiveDependencies(maxDepth, currentDepth + 1);
475
489
  }
476
- if (shouldCheckTransitiveDependencies) checkTransitiveDependencies();
490
+ if (shouldCheckTransitiveDependencies) await checkTransitiveDependencies();
477
491
  const dynamicImports = output.dynamicImports.filter((d) => !DEPS_TO_IGNORE.includes(d));
478
492
  if (dynamicImports.length) {
479
493
  for (const dynamicImport of dynamicImports) if (!depsToOptimize.has(dynamicImport) && isBareModuleSpecifier(dynamicImport)) {
@@ -498,37 +512,64 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
498
512
  }
499
513
  return depsToOptimize;
500
514
  }
501
- async function analyzeEntry({ entry, isVirtualFile }, mastraEntry, { logger, sourcemapEnabled, workspaceMap, projectRoot, shouldCheckTransitiveDependencies = false, analyzeCache }) {
502
- const cacheKey = isVirtualFile ? void 0 : slash(entry);
503
- if (cacheKey && analyzeCache?.has(cacheKey)) return analyzeCache.get(cacheKey);
504
- const optimizerBundler = await rollup({
505
- logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
506
- input: isVirtualFile ? "#entry" : entry,
507
- treeshake: false,
508
- preserveSymlinks: true,
509
- plugins: getInputPlugins$1({
510
- entry,
511
- isVirtualFile
512
- }, mastraEntry, { sourcemapEnabled }),
513
- external: DEPS_TO_IGNORE
514
- });
515
- const { output } = await optimizerBundler.generate({
516
- format: "esm",
517
- inlineDynamicImports: true
518
- });
519
- await optimizerBundler.close();
520
- const result = {
521
- dependencies: await captureDependenciesToOptimize(output[0], workspaceMap, projectRoot, {
522
- logger,
523
- shouldCheckTransitiveDependencies
524
- }),
525
- output: {
526
- code: output[0].code,
527
- map: output[0].map
528
- }
529
- };
530
- if (cacheKey && analyzeCache) analyzeCache.set(cacheKey, result);
531
- return result;
515
+ async function analyzeEntry({ entry, isVirtualFile }, mastraEntry, { logger, sourcemapEnabled, workspaceMap, projectRoot, env = { "process.env.NODE_ENV": JSON.stringify("production") }, shouldCheckTransitiveDependencies = false, analyzeCache, activeEntries: providedActiveEntries, externals = [], externalsPreset = false }) {
516
+ const resolvedEntry = isVirtualFile ? void 0 : slash(entry);
517
+ const effectiveAnalyzeCache = analyzeCache ?? /* @__PURE__ */ new Map();
518
+ const externalsCacheKey = JSON.stringify([externalsPreset, [...externals].sort()]);
519
+ const cacheKey = resolvedEntry ? `${resolvedEntry}:${shouldCheckTransitiveDependencies ? "transitive" : "direct"}:${externalsCacheKey}` : void 0;
520
+ if (cacheKey && effectiveAnalyzeCache.has(cacheKey)) return effectiveAnalyzeCache.get(cacheKey);
521
+ const activeEntries = providedActiveEntries ?? /* @__PURE__ */ new Set();
522
+ const shouldTrackEntry = Boolean(resolvedEntry && !activeEntries.has(resolvedEntry));
523
+ if (resolvedEntry && shouldTrackEntry) activeEntries.add(resolvedEntry);
524
+ try {
525
+ const optimizerBundler = await rollup({
526
+ logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
527
+ input: isVirtualFile ? "#entry" : entry,
528
+ treeshake: false,
529
+ preserveSymlinks: true,
530
+ plugins: getInputPlugins$1({
531
+ entry,
532
+ isVirtualFile
533
+ }, mastraEntry, {
534
+ sourcemapEnabled,
535
+ env,
536
+ workspaceMap,
537
+ externals,
538
+ externalsPreset
539
+ }),
540
+ external: (id) => DEPS_TO_IGNORE.some((dep) => isDependencyPartOfPackage(id, dep))
541
+ });
542
+ const { output } = await (async () => {
543
+ try {
544
+ return await optimizerBundler.generate({
545
+ format: "esm",
546
+ inlineDynamicImports: true
547
+ });
548
+ } finally {
549
+ await optimizerBundler.close();
550
+ }
551
+ })();
552
+ const result = {
553
+ dependencies: await captureDependenciesToOptimize(output[0], workspaceMap, projectRoot, {
554
+ logger,
555
+ mastraEntry,
556
+ shouldCheckTransitiveDependencies,
557
+ env,
558
+ analyzeCache: effectiveAnalyzeCache,
559
+ activeEntries,
560
+ externals,
561
+ externalsPreset
562
+ }),
563
+ output: {
564
+ code: output[0].code,
565
+ map: output[0].map
566
+ }
567
+ };
568
+ if (cacheKey) effectiveAnalyzeCache.set(cacheKey, result);
569
+ return result;
570
+ } finally {
571
+ if (resolvedEntry && shouldTrackEntry) activeEntries.delete(resolvedEntry);
572
+ }
532
573
  }
533
574
  //#endregion
534
575
  //#region src/build/plugins/hono-alias.ts
@@ -653,7 +694,7 @@ function createVirtualDependencies(depsToOptimize, { projectRoot, workspaceRoot,
653
694
  * Configures and returns Rollup plugins for bundling external dependencies.
654
695
  * Sets up virtual modules, TypeScript compilation, CommonJS transformation, and workspace resolution.
655
696
  */
656
- async function getInputPlugins(virtualDependencies, { transpilePackages, workspaceMap, bundlerOptions, rootDir, externals, platform }) {
697
+ async function getInputPlugins(virtualDependencies, { transpilePackages, workspaceMap, bundlerOptions, projectRoot, rootDir, externals, platform }) {
657
698
  const transpilePackagesMap = /* @__PURE__ */ new Map();
658
699
  for (const pkg of transpilePackages) {
659
700
  const dir = await getPackageRootPath(pkg);
@@ -665,9 +706,9 @@ async function getInputPlugins(virtualDependencies, { transpilePackages, workspa
665
706
  acc[`#virtual-${dep}`] = virtualDep.virtual;
666
707
  return acc;
667
708
  }, {})),
668
- tsConfigPaths(),
709
+ tsConfigPaths({ cwd: projectRoot }),
669
710
  protocolExternalResolver(),
670
- subpathExternalsResolver(externals),
711
+ subpathExternalsResolver(externals, workspaceMap),
671
712
  transpilePackagesMap.size ? esbuild({
672
713
  format: "esm",
673
714
  include: [...[...transpilePackagesMap.values()].map((p) => {
@@ -700,7 +741,11 @@ async function getInputPlugins(virtualDependencies, { transpilePackages, workspa
700
741
  transformMixedEsModules: true,
701
742
  ignoreTryCatch: false
702
743
  }),
703
- bundlerOptions.noBundling ? null : nodeResolve(getNodeResolveOptions(platform)),
744
+ bundlerOptions.noBundling ? null : nodeResolve({
745
+ ...getNodeResolveOptions(platform),
746
+ rootDir: projectRoot,
747
+ modulePaths: [path$1.join(rootDir, "node_modules")]
748
+ }),
704
749
  bundlerOptions.noBundling ? esmShim() : null,
705
750
  aliasHono(),
706
751
  json(),
@@ -713,7 +758,7 @@ async function getInputPlugins(virtualDependencies, { transpilePackages, workspa
713
758
  async handler(id, importer) {
714
759
  if (!importer) return null;
715
760
  if (!id.endsWith(".node")) return null;
716
- const packageName = (await getPackageInfo(importer))?.packageJson?.name || id;
761
+ const packageName = (await getPackageInfo$1(importer))?.packageJson?.name || id;
717
762
  throw new MastraBaseError({
718
763
  id: "DEPLOYER_BUNDLE_EXTERNALS_MISSING_NATIVE_BUILD",
719
764
  domain: ErrorDomain.DEPLOYER,
@@ -741,7 +786,7 @@ export const mastra = new Mastra({
741
786
  * Executes the Rollup build process for virtual dependencies using configured plugins.
742
787
  * Bundles all virtual dependency modules into optimized ESM files with proper external handling.
743
788
  */
744
- async function buildExternalDependencies(virtualDependencies, { externals, packagesToTranspile, workspaceMap, rootDir, outputDir, bundlerOptions, platform }) {
789
+ async function buildExternalDependencies(virtualDependencies, { externals, packagesToTranspile, workspaceMap, projectRoot, rootDir, outputDir, bundlerOptions, platform }) {
745
790
  /**
746
791
  * If there are no virtual dependencies to bundle, return an empty array to avoid Rollup errors.
747
792
  */
@@ -751,6 +796,7 @@ async function buildExternalDependencies(virtualDependencies, { externals, packa
751
796
  transpilePackages: packagesToTranspile,
752
797
  workspaceMap,
753
798
  bundlerOptions: { noBundling },
799
+ projectRoot,
754
800
  rootDir,
755
801
  externals,
756
802
  platform
@@ -873,6 +919,7 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
873
919
  externals: mergedExternals,
874
920
  packagesToTranspile,
875
921
  workspaceMap,
922
+ projectRoot,
876
923
  rootDir: workspaceRoot || projectRoot,
877
924
  outputDir,
878
925
  bundlerOptions: {
@@ -924,13 +971,13 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
924
971
  //#endregion
925
972
  //#region src/build/analyze/externals.ts
926
973
  function normalizeExternals(externals) {
927
- const userExternals = Array.isArray(externals) ? externals : [];
974
+ const explicitExternals = Array.isArray(externals) ? externals : [];
928
975
  return {
929
976
  externalsPreset: externals === true,
930
977
  mergedExternals: [...new Set([
931
978
  ...GLOBAL_EXTERNALS,
932
979
  ...DEPRECATED_EXTERNALS,
933
- ...userExternals
980
+ ...explicitExternals
934
981
  ].filter(Boolean))]
935
982
  };
936
983
  }
@@ -1254,7 +1301,7 @@ async function validateOutput({ output, reverseVirtualReferenceMap, usedExternal
1254
1301
  *
1255
1302
  * This helps identify which dependencies need to be externalized vs bundled.
1256
1303
  */
1257
- async function analyzeBundle(entries, mastraEntry, { outputDir, projectRoot, platform, isDev = false, bundlerOptions }, logger) {
1304
+ async function analyzeBundle(entries, mastraEntry, { outputDir, projectRoot, platform, isDev = false, bundlerOptions, env = { "process.env.NODE_ENV": JSON.stringify("production") } }, logger) {
1258
1305
  const mastraConfig = await readFile(mastraEntry, "utf-8");
1259
1306
  const mastraConfigResult = { hasValidConfig: false };
1260
1307
  await transformAsync(mastraConfig, {
@@ -1272,6 +1319,7 @@ async function analyzeBundle(entries, mastraEntry, { outputDir, projectRoot, pla
1272
1319
  logger.info("Analyzing dependencies...");
1273
1320
  const allUsedExternals = /* @__PURE__ */ new Map();
1274
1321
  const analyzeCache = /* @__PURE__ */ new Map();
1322
+ const activeAnalyzeEntries = /* @__PURE__ */ new Set();
1275
1323
  for (const entry of entries) {
1276
1324
  const analyzeResult = await analyzeEntry({
1277
1325
  entry,
@@ -1281,8 +1329,12 @@ async function analyzeBundle(entries, mastraEntry, { outputDir, projectRoot, pla
1281
1329
  sourcemapEnabled: bundlerOptions?.enableSourcemap ?? false,
1282
1330
  workspaceMap,
1283
1331
  projectRoot,
1332
+ env,
1284
1333
  shouldCheckTransitiveDependencies: true,
1285
- analyzeCache
1334
+ analyzeCache,
1335
+ activeEntries: activeAnalyzeEntries,
1336
+ externals: mergedExternals,
1337
+ externalsPreset
1286
1338
  });
1287
1339
  transformSync(analyzeResult.output.code, {
1288
1340
  filename: "pino-detection.js",
@@ -1400,4 +1452,4 @@ async function analyzeBundle(entries, mastraEntry, { outputDir, projectRoot, pla
1400
1452
  //#endregion
1401
1453
  export { aliasHono as a, packWorkspaceDependencies as c, bundleExternals as i, checkConfigExport as n, collectTransitiveWorkspaceDependencies as o, normalizeExternals as r, getWorkspaceInformation as s, analyzeBundle as t };
1402
1454
 
1403
- //# sourceMappingURL=analyze-B5HY26Tt.js.map
1455
+ //# sourceMappingURL=analyze-DEk6PGTI.js.map