@mastra/deployer 1.49.0-alpha.2 → 1.49.0-alpha.3

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 (96) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
  3. package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
  4. package/dist/build/analyze.cjs +2 -2
  5. package/dist/build/analyze.d.ts.map +1 -1
  6. package/dist/build/analyze.js +1 -1
  7. package/dist/build/bundler.cjs +11 -3
  8. package/dist/build/bundler.d.ts +3 -1
  9. package/dist/build/bundler.d.ts.map +1 -1
  10. package/dist/build/bundler.js +1 -1
  11. package/dist/build/fs-routing/codegen.d.ts +1 -1
  12. package/dist/build/fs-routing/codegen.d.ts.map +1 -1
  13. package/dist/build/fs-routing/discover.d.ts +7 -6
  14. package/dist/build/fs-routing/discover.d.ts.map +1 -1
  15. package/dist/build/index.cjs +23 -23
  16. package/dist/build/index.js +6 -6
  17. package/dist/build/package-info.d.ts +5 -0
  18. package/dist/build/package-info.d.ts.map +1 -1
  19. package/dist/build/types.d.ts +10 -0
  20. package/dist/build/types.d.ts.map +1 -1
  21. package/dist/build/utils.d.ts +3 -0
  22. package/dist/build/utils.d.ts.map +1 -1
  23. package/dist/build/watcher.d.ts +2 -1
  24. package/dist/build/watcher.d.ts.map +1 -1
  25. package/dist/bundler/index.cjs +3 -3
  26. package/dist/bundler/index.d.ts +3 -3
  27. package/dist/bundler/index.d.ts.map +1 -1
  28. package/dist/bundler/index.js +1 -1
  29. package/dist/{chunk-HMT7QCMZ.cjs → chunk-3GTT2N4V.cjs} +21 -47
  30. package/dist/chunk-3GTT2N4V.cjs.map +1 -0
  31. package/dist/{chunk-566UDTD4.js → chunk-4MVAT24Z.js} +140 -77
  32. package/dist/chunk-4MVAT24Z.js.map +1 -0
  33. package/dist/{chunk-WLW5IRHY.cjs → chunk-7YI2AEFO.cjs} +5 -2
  34. package/dist/chunk-7YI2AEFO.cjs.map +1 -0
  35. package/dist/{chunk-Z3DC47CH.js → chunk-ANDDGKY5.js} +5 -2
  36. package/dist/chunk-ANDDGKY5.js.map +1 -0
  37. package/dist/{chunk-CGDATNET.js → chunk-CCBU3OII.js} +3 -3
  38. package/dist/{chunk-CGDATNET.js.map → chunk-CCBU3OII.js.map} +1 -1
  39. package/dist/{chunk-2XUYQ2EJ.cjs → chunk-EU74XSTG.cjs} +43 -44
  40. package/dist/chunk-EU74XSTG.cjs.map +1 -0
  41. package/dist/{chunk-VWD7AY6H.js → chunk-FHLWDI5H.js} +332 -45
  42. package/dist/chunk-FHLWDI5H.js.map +1 -0
  43. package/dist/{chunk-IEHRALF6.cjs → chunk-IMPHNLMW.cjs} +178 -115
  44. package/dist/chunk-IMPHNLMW.cjs.map +1 -0
  45. package/dist/{chunk-6LWGRT7H.cjs → chunk-N5CQWHN3.cjs} +343 -46
  46. package/dist/chunk-N5CQWHN3.cjs.map +1 -0
  47. package/dist/{chunk-BYRFFGSN.js → chunk-ULWJZHTN.js} +12 -38
  48. package/dist/chunk-ULWJZHTN.js.map +1 -0
  49. package/dist/{chunk-VXLIM7FD.cjs → chunk-VKAFARW6.cjs} +82 -35
  50. package/dist/chunk-VKAFARW6.cjs.map +1 -0
  51. package/dist/{chunk-7RR5PJRM.cjs → chunk-VNJLLLQN.cjs} +7 -7
  52. package/dist/{chunk-7RR5PJRM.cjs.map → chunk-VNJLLLQN.cjs.map} +1 -1
  53. package/dist/{chunk-OFMQRNNY.js → chunk-YG455MPH.js} +26 -27
  54. package/dist/chunk-YG455MPH.js.map +1 -0
  55. package/dist/{chunk-5GX66TF5.js → chunk-ZL66GDLP.js} +80 -33
  56. package/dist/chunk-ZL66GDLP.js.map +1 -0
  57. package/dist/deploy/log.d.ts.map +1 -1
  58. package/dist/docs/SKILL.md +1 -1
  59. package/dist/docs/assets/SOURCE_MAP.json +8 -8
  60. package/dist/docs/references/docs-deployment-cloud-providers.md +2 -0
  61. package/dist/docs/references/docs-deployment-mastra-server.md +2 -0
  62. package/dist/docs/references/docs-deployment-monorepo.md +2 -0
  63. package/dist/docs/references/docs-deployment-overview.md +2 -0
  64. package/dist/docs/references/docs-deployment-web-framework.md +2 -0
  65. package/dist/docs/references/docs-deployment-workflow-runners.md +2 -0
  66. package/dist/docs/references/reference-deployer.md +2 -0
  67. package/dist/index.cjs +11 -11
  68. package/dist/index.js +4 -4
  69. package/dist/server/index.cjs +10 -4
  70. package/dist/server/index.cjs.map +1 -1
  71. package/dist/server/index.d.ts.map +1 -1
  72. package/dist/server/index.js +7 -1
  73. package/dist/server/index.js.map +1 -1
  74. package/dist/services/deps.d.ts +2 -0
  75. package/dist/services/deps.d.ts.map +1 -1
  76. package/dist/services/index.cjs +4 -4
  77. package/dist/services/index.js +1 -1
  78. package/dist/validator/custom-resolver.cjs +3 -3
  79. package/dist/validator/custom-resolver.js +1 -1
  80. package/package.json +8 -8
  81. package/dist/chunk-2XUYQ2EJ.cjs.map +0 -1
  82. package/dist/chunk-3JVOVZ2V.cjs +0 -269
  83. package/dist/chunk-3JVOVZ2V.cjs.map +0 -1
  84. package/dist/chunk-566UDTD4.js.map +0 -1
  85. package/dist/chunk-5GX66TF5.js.map +0 -1
  86. package/dist/chunk-6LWGRT7H.cjs.map +0 -1
  87. package/dist/chunk-BYRFFGSN.js.map +0 -1
  88. package/dist/chunk-HMT7QCMZ.cjs.map +0 -1
  89. package/dist/chunk-IEHRALF6.cjs.map +0 -1
  90. package/dist/chunk-KJ4S6COO.js +0 -258
  91. package/dist/chunk-KJ4S6COO.js.map +0 -1
  92. package/dist/chunk-OFMQRNNY.js.map +0 -1
  93. package/dist/chunk-VWD7AY6H.js.map +0 -1
  94. package/dist/chunk-VXLIM7FD.cjs.map +0 -1
  95. package/dist/chunk-WLW5IRHY.cjs.map +0 -1
  96. package/dist/chunk-Z3DC47CH.js.map +0 -1
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunk7RR5PJRM_cjs = require('./chunk-7RR5PJRM.cjs');
4
- var chunkIEHRALF6_cjs = require('./chunk-IEHRALF6.cjs');
5
- var chunk3JVOVZ2V_cjs = require('./chunk-3JVOVZ2V.cjs');
6
- var chunk6LWGRT7H_cjs = require('./chunk-6LWGRT7H.cjs');
7
- var chunkVXLIM7FD_cjs = require('./chunk-VXLIM7FD.cjs');
8
- var chunkWLW5IRHY_cjs = require('./chunk-WLW5IRHY.cjs');
3
+ var chunkVNJLLLQN_cjs = require('./chunk-VNJLLLQN.cjs');
4
+ var chunkIMPHNLMW_cjs = require('./chunk-IMPHNLMW.cjs');
5
+ var chunkN5CQWHN3_cjs = require('./chunk-N5CQWHN3.cjs');
6
+ var chunkVKAFARW6_cjs = require('./chunk-VKAFARW6.cjs');
7
+ var chunk7YI2AEFO_cjs = require('./chunk-7YI2AEFO.cjs');
9
8
  var child_process = require('child_process');
10
9
  var fs = require('fs');
11
10
  var promises = require('fs/promises');
@@ -60,12 +59,13 @@ var Bundler = class extends bundler.MastraBundler {
60
59
  const pkgPath = path.join(outputDirectory, "package.json");
61
60
  const dependenciesMap = /* @__PURE__ */ new Map();
62
61
  for (const [key, value] of dependencies.entries()) {
62
+ const dependencyValue = typeof value === "string" ? value : value.packageSpec ?? value.version ?? "latest";
63
63
  if (key.startsWith("@")) {
64
64
  const pkgChunks = key.split("/");
65
- dependenciesMap.set(`${pkgChunks[0]}/${pkgChunks[1]}`, value);
65
+ dependenciesMap.set(`${pkgChunks[0]}/${pkgChunks[1]}`, dependencyValue);
66
66
  } else {
67
67
  const pkgName = key.split("/")[0] || key;
68
- dependenciesMap.set(pkgName, value);
68
+ dependenciesMap.set(pkgName, dependencyValue);
69
69
  }
70
70
  }
71
71
  await promises.writeFile(
@@ -87,13 +87,9 @@ var Bundler = class extends bundler.MastraBundler {
87
87
  2
88
88
  )
89
89
  );
90
- await promises.writeFile(
91
- path.join(outputDirectory, "pnpm-workspace.yaml"),
92
- "packages:\n - '.'\nallowBuilds:\n bcrypt: true\n esbuild: true\n sharp: true\n protobufjs: true\n workerd: true\n bufferutil: true\n utf-8-validate: true\n"
93
- );
94
90
  }
95
91
  createBundler(inputOptions, outputOptions) {
96
- return chunk3JVOVZ2V_cjs.createBundler(inputOptions, outputOptions);
92
+ return chunkN5CQWHN3_cjs.createBundler(inputOptions, outputOptions);
97
93
  }
98
94
  async getUserBundlerOptions(mastraEntryFile, outputDirectory) {
99
95
  const defaultBundlerOptions = {
@@ -103,7 +99,7 @@ var Bundler = class extends bundler.MastraBundler {
103
99
  [IS_DEFAULT]: true
104
100
  };
105
101
  try {
106
- const bundlerOptions = await chunk7RR5PJRM_cjs.getBundlerOptions(mastraEntryFile, outputDirectory);
102
+ const bundlerOptions = await chunkVNJLLLQN_cjs.getBundlerOptions(mastraEntryFile, outputDirectory);
107
103
  return bundlerOptions ?? defaultBundlerOptions;
108
104
  } catch (error) {
109
105
  this.logger.debug("Failed to get bundler options, sourcemap will be disabled", { error });
@@ -111,7 +107,7 @@ var Bundler = class extends bundler.MastraBundler {
111
107
  return defaultBundlerOptions;
112
108
  }
113
109
  async analyze(entry, mastraFile, outputDirectory) {
114
- return await chunkIEHRALF6_cjs.analyzeBundle(
110
+ return await chunkIMPHNLMW_cjs.analyzeBundle(
115
111
  [].concat(entry),
116
112
  mastraFile,
117
113
  {
@@ -123,7 +119,7 @@ var Bundler = class extends bundler.MastraBundler {
123
119
  );
124
120
  }
125
121
  async installDependencies(outputDirectory, rootDir = process.cwd()) {
126
- const deps = new chunkVXLIM7FD_cjs.DepsService(rootDir);
122
+ const deps = new chunkVKAFARW6_cjs.DepsService(rootDir);
127
123
  deps.__setLogger(this.logger);
128
124
  await deps.install({ dir: path.join(outputDirectory, this.outputDir) });
129
125
  }
@@ -182,10 +178,10 @@ var Bundler = class extends bundler.MastraBundler {
182
178
  }
183
179
  }
184
180
  async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, { enableSourcemap, enableEsmShim, externals }) {
185
- const { workspaceRoot } = await chunkIEHRALF6_cjs.getWorkspaceInformation({ mastraEntryFile });
181
+ const { workspaceRoot } = await chunkIMPHNLMW_cjs.getWorkspaceInformation({ mastraEntryFile });
186
182
  const closestPkgJson = pkg__namespace.up({ cwd: path.dirname(mastraEntryFile) });
187
183
  const projectRoot = closestPkgJson ? path.dirname(closestPkgJson) : process.cwd();
188
- const inputOptions = await chunk3JVOVZ2V_cjs.getInputOptions(
184
+ const inputOptions = await chunkN5CQWHN3_cjs.getInputOptions(
189
185
  mastraEntryFile,
190
186
  analyzedBundleInfo,
191
187
  this.platform,
@@ -209,7 +205,7 @@ var Bundler = class extends bundler.MastraBundler {
209
205
  return inputOptions;
210
206
  }
211
207
  getAllToolPaths(mastraDir, toolsPaths = []) {
212
- const normalizedMastraDir = chunkWLW5IRHY_cjs.slash(mastraDir);
208
+ const normalizedMastraDir = chunk7YI2AEFO_cjs.slash(mastraDir);
213
209
  const defaultToolsPath = path.posix.join(normalizedMastraDir, "tools/**/*.{js,ts}");
214
210
  const defaultToolsIgnorePaths = [
215
211
  `!${path.posix.join(normalizedMastraDir, "tools/**/*.{test,spec}.{js,ts}")}`,
@@ -230,7 +226,7 @@ var Bundler = class extends bundler.MastraBundler {
230
226
  });
231
227
  for (const path$1 of expandedPaths) {
232
228
  if (await fsExtra__default.default.pathExists(path$1)) {
233
- const fileService = new chunkVXLIM7FD_cjs.FileService();
229
+ const fileService = new chunkVKAFARW6_cjs.FileService();
234
230
  const entryFile = fileService.getFirstExistingFile([
235
231
  path.join(path$1, "index.ts"),
236
232
  path.join(path$1, "index.js"),
@@ -267,7 +263,7 @@ var Bundler = class extends bundler.MastraBundler {
267
263
  let analyzedBundleInfo;
268
264
  try {
269
265
  const resolvedToolsPaths = await this.listToolsInputOptions(toolsPaths);
270
- analyzedBundleInfo = await chunkIEHRALF6_cjs.analyzeBundle(
266
+ analyzedBundleInfo = await chunkIMPHNLMW_cjs.analyzeBundle(
271
267
  [serverFile, ...Object.values(resolvedToolsPaths)],
272
268
  mastraEntryFile,
273
269
  {
@@ -295,32 +291,10 @@ var Bundler = class extends bundler.MastraBundler {
295
291
  }
296
292
  const dependenciesToInstall = /* @__PURE__ */ new Map();
297
293
  for (const [dep, depInfo] of analyzedBundleInfo.externalDependencies) {
298
- if (analyzedBundleInfo.workspaceMap.has(dep) || !chunkWLW5IRHY_cjs.isBareModuleSpecifier(dep)) {
294
+ if (analyzedBundleInfo.workspaceMap.has(dep) || !chunk7YI2AEFO_cjs.isBareModuleSpecifier(dep)) {
299
295
  continue;
300
296
  }
301
- let version = depInfo.version;
302
- let actualPackageName;
303
- try {
304
- let rootPath = await chunk6LWGRT7H_cjs.getPackageRootPath(dep, projectRoot);
305
- if (!rootPath) {
306
- rootPath = await chunk6LWGRT7H_cjs.getPackageRootPath(dep, undefined);
307
- }
308
- if (rootPath) {
309
- const pkg2 = await fsExtra.readJSON(`${rootPath}/package.json`);
310
- actualPackageName = pkg2.name;
311
- if (!version) {
312
- version = pkg2.version;
313
- }
314
- }
315
- } catch {
316
- }
317
- version = version || "latest";
318
- const isAlias = actualPackageName && dep !== actualPackageName;
319
- if (isAlias) {
320
- dependenciesToInstall.set(dep, `npm:${actualPackageName}@${version}`);
321
- } else {
322
- dependenciesToInstall.set(dep, version);
323
- }
297
+ dependenciesToInstall.set(dep, depInfo);
324
298
  }
325
299
  try {
326
300
  await this.writePackageJson(path.join(outputDirectory, this.outputDir), dependenciesToInstall);
@@ -406,5 +380,5 @@ export const tools = [${toolsExports.join(", ")}]`
406
380
 
407
381
  exports.Bundler = Bundler;
408
382
  exports.IS_DEFAULT = IS_DEFAULT;
409
- //# sourceMappingURL=chunk-HMT7QCMZ.cjs.map
410
- //# sourceMappingURL=chunk-HMT7QCMZ.cjs.map
383
+ //# sourceMappingURL=chunk-3GTT2N4V.cjs.map
384
+ //# sourceMappingURL=chunk-3GTT2N4V.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bundler/index.ts"],"names":["MastraBundler","emptyDir","ensureDir","join","writeFile","createBundler","getBundlerOptions","analyzeBundle","DepsService","fsExtra","execSync","rm","stat","copy","getWorkspaceInformation","pkg","dirname","getInputOptions","existsSync","virtual","slash","posix","glob","path","FileService","error","MastraError","ErrorDomain","ErrorCategory","isBareModuleSpecifier"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,IAAM,UAAA,0BAAoB,YAAY;AAEtC,IAAe,OAAA,GAAf,cAA+BA,qBAAA,CAAc;AAAA,EACxC,gBAAA,GAAmB,QAAA;AAAA,EACnB,SAAA,GAAY,QAAA;AAAA,EACZ,QAAA,GAA4B,MAAA;AAAA,EAEtC,WAAA,CAAY,IAAA,EAAc,SAAA,GAAoC,SAAA,EAAW;AACvE,IAAA,KAAA,CAAM,EAAE,IAAA,EAAM,SAAA,EAAW,CAAA;AAAA,EAC3B;AAAA,EAEA,MAAM,QAAQ,eAAA,EAAwC;AAEpD,IAAA,MAAMC,iBAAS,eAAe,CAAA;AAE9B,IAAA,MAAMC,iBAAA,CAAUC,SAAA,CAAK,eAAA,EAAiB,IAAA,CAAK,gBAAgB,CAAC,CAAA;AAC5D,IAAA,MAAMD,iBAAA,CAAUC,SAAA,CAAK,eAAA,EAAiB,IAAA,CAAK,SAAS,CAAC,CAAA;AAAA,EACvD;AAAA,EAEA,MAAM,gBAAA,CACJ,eAAA,EACA,YAAA,EACA,WAAA,EACA;AACA,IAAA,IAAA,CAAK,MAAA,CAAO,MAAM,gCAAgC,CAAA;AAElD,IAAA,MAAMD,kBAAU,eAAe,CAAA;AAC/B,IAAA,MAAM,OAAA,GAAUC,SAAA,CAAK,eAAA,EAAiB,cAAc,CAAA;AAEpD,IAAA,MAAM,eAAA,uBAAsB,GAAA,EAAI;AAChC,IAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,CAAA,IAAK,YAAA,CAAa,SAAQ,EAAG;AACjD,MAAA,MAAM,eAAA,GAAkB,OAAO,KAAA,KAAU,QAAA,GA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CAAA;AACrE,IAAA,MAAM,WAAA,GAAc,MAAA,CAAO,IAAA,CAAK,iBAAiB,CAAA,CAAE,MAAA;AACnD,IAAA,IAAI,cAAc,CAAA,EAAG;AACnB,MAAA,IAAA,CAAK,OAAO,IAAA,CAAK,aAAA,EAAe,EAAE,KAAA,EAAO,aAAa,CAAA;AAAA,IACxD;AAAA,EACF;AACF","file":"chunk-3GTT2N4V.cjs","sourcesContent":["import { execSync } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { rm, stat, writeFile } from 'node:fs/promises';\nimport { dirname, join, posix } from 'node:path';\nimport { MastraBundler } from '@mastra/core/bundler';\nimport { MastraError, ErrorDomain, ErrorCategory } from '@mastra/core/error';\nimport type { Config } from '@mastra/core/mastra';\nimport virtual from '@rollup/plugin-virtual';\nimport * as pkg from 'empathic/package';\nimport fsExtra, { copy, ensureDir, emptyDir } from 'fs-extra/esm';\nimport type { InputOptions, OutputOptions } from 'rollup';\nimport { glob } from 'tinyglobby';\nimport { analyzeBundle } from '../build/analyze';\nimport { createBundler as createBundlerUtil, getInputOptions } from '../build/bundler';\nimport { getBundlerOptions } from '../build/bundlerOptions';\nimport type { BundlerOptions, ExternalDependencyInfo } from '../build/types';\nimport type { BundlerPlatform } from '../build/utils';\nimport { isBareModuleSpecifier, slash } from '../build/utils';\nimport { DepsService } from '../services/deps';\nimport { FileService } from '../services/fs';\nimport { getWorkspaceInformation } from './workspaceDependencies';\n\nexport type { BundlerOptions } from '../build/types';\nexport type { BundlerPlatform } from '../build/utils';\n\nexport const IS_DEFAULT = Symbol('IS_DEFAULT');\n\nexport abstract class Bundler extends MastraBundler {\n protected analyzeOutputDir = '.build';\n protected outputDir = 'output';\n protected platform: BundlerPlatform = 'node';\n\n constructor(name: string, component: 'BUNDLER' | 'DEPLOYER' = 'BUNDLER') {\n super({ name, component });\n }\n\n async prepare(outputDirectory: string): Promise<void> {\n // Clean up the output directory first\n await emptyDir(outputDirectory);\n\n await ensureDir(join(outputDirectory, this.analyzeOutputDir));\n await ensureDir(join(outputDirectory, this.outputDir));\n }\n\n async writePackageJson(\n outputDirectory: string,\n dependencies: Map<string, string | ExternalDependencyInfo>,\n resolutions?: Record<string, string>,\n ) {\n this.logger.debug(\"Writing project's package.json\");\n\n await ensureDir(outputDirectory);\n const pkgPath = join(outputDirectory, 'package.json');\n\n const dependenciesMap = new Map();\n for (const [key, value] of dependencies.entries()) {\n const dependencyValue = typeof value === 'string' ? value : (value.packageSpec ?? value.version ?? 'latest');\n if (key.startsWith('@')) {\n // Handle scoped packages (e.g. @org/package)\n const pkgChunks = key.split('/');\n dependenciesMap.set(`${pkgChunks[0]}/${pkgChunks[1]}`, dependencyValue);\n } else {\n // For non-scoped packages, take only the first part before any slash\n const pkgName = key.split('/')[0] || key;\n dependenciesMap.set(pkgName, dependencyValue);\n }\n }\n\n await writeFile(\n pkgPath,\n JSON.stringify(\n {\n name: 'server',\n version: '1.0.0',\n private: true,\n type: 'module',\n main: 'index.mjs',\n scripts: {\n start: 'node ./index.mjs',\n },\n dependencies: Object.fromEntries(dependenciesMap.entries()),\n ...(Object.keys(resolutions ?? {}).length > 0 && { resolutions }),\n },\n null,\n 2,\n ),\n );\n }\n\n protected createBundler(inputOptions: InputOptions, outputOptions: Partial<OutputOptions> & { dir: string }) {\n return createBundlerUtil(inputOptions, outputOptions);\n }\n\n protected async getUserBundlerOptions(\n mastraEntryFile: string,\n outputDirectory: string,\n ): Promise<NonNullable<Config['bundler']>> {\n const defaultBundlerOptions: Config['bundler'] = {\n externals: [],\n sourcemap: false,\n transpilePackages: [],\n [IS_DEFAULT]: true,\n } as const;\n\n try {\n const bundlerOptions = await getBundlerOptions(mastraEntryFile, outputDirectory);\n\n return bundlerOptions ?? defaultBundlerOptions;\n } catch (error) {\n this.logger.debug('Failed to get bundler options, sourcemap will be disabled', { error });\n }\n\n return defaultBundlerOptions;\n }\n\n protected async analyze(entry: string | string[], mastraFile: string, outputDirectory: string) {\n return await analyzeBundle(\n ([] as string[]).concat(entry),\n mastraFile,\n {\n outputDir: join(outputDirectory, this.analyzeOutputDir),\n projectRoot: outputDirectory,\n platform: this.platform,\n },\n this.logger,\n );\n }\n\n protected async installDependencies(outputDirectory: string, rootDir = process.cwd()) {\n const deps = new DepsService(rootDir);\n deps.__setLogger(this.logger);\n\n await deps.install({ dir: join(outputDirectory, this.outputDir) });\n }\n\n /**\n * Generate a package-lock.json for the output directory so that deploy targets\n * can use `npm ci` instead of `npm install`, skipping version resolution entirely.\n * This is a lockfile-only operation — no packages are downloaded.\n *\n * Temporarily moves node_modules out of the way because pnpm's symlink-based\n * layout confuses npm's arborist, then restores it afterwards so that\n * `mastra start` (or wrangler) can still resolve dependencies at runtime.\n */\n private async generateNpmLockfile(outputDir: string): Promise<void> {\n const nodeModules = join(outputDir, 'node_modules');\n const nodeModulesTmp = join(outputDir, 'node_modules.__tmp');\n let movedNodeModules = false;\n try {\n // Move node_modules aside — pnpm's symlink layout confuses npm's arborist\n if (await fsExtra.pathExists(nodeModules)) {\n await fsExtra.move(nodeModules, nodeModulesTmp, { overwrite: true });\n movedNodeModules = true;\n }\n execSync('npm install --package-lock-only --force', {\n cwd: outputDir,\n stdio: 'pipe',\n timeout: 60_000,\n });\n } catch {\n this.logger.warn('Failed to generate package-lock.json — deploy will fall back to npm install');\n } finally {\n // Restore node_modules so runtime resolution works\n if (movedNodeModules) {\n await rm(nodeModules, { recursive: true, force: true });\n await fsExtra.move(nodeModulesTmp, nodeModules, { overwrite: true });\n }\n }\n }\n\n protected async copyPublic(mastraDir: string, outputDirectory: string) {\n const publicDir = join(mastraDir, 'public');\n\n try {\n await stat(publicDir);\n } catch {\n return;\n }\n\n await copy(publicDir, join(outputDirectory, this.outputDir));\n }\n\n protected async copyDOTNPMRC({\n rootDir = process.cwd(),\n outputDirectory,\n }: {\n rootDir?: string;\n outputDirectory: string;\n }) {\n const sourceDotNpmRcPath = join(rootDir, '.npmrc');\n const targetDotNpmRcPath = join(outputDirectory, this.outputDir, '.npmrc');\n\n try {\n await stat(sourceDotNpmRcPath);\n await copy(sourceDotNpmRcPath, targetDotNpmRcPath);\n } catch {\n return;\n }\n }\n\n protected async getBundlerOptions(\n serverFile: string,\n mastraEntryFile: string,\n analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>,\n toolsPaths: (string | string[])[],\n { enableSourcemap, enableEsmShim, externals }: BundlerOptions,\n ) {\n const { workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile });\n const closestPkgJson = pkg.up({ cwd: dirname(mastraEntryFile) });\n const projectRoot = closestPkgJson ? dirname(closestPkgJson) : process.cwd();\n\n const inputOptions: InputOptions = await getInputOptions(\n mastraEntryFile,\n analyzedBundleInfo,\n this.platform,\n {\n 'process.env.NODE_ENV': JSON.stringify('production'),\n },\n { sourcemap: enableSourcemap, workspaceRoot, projectRoot, enableEsmShim, externalsPreset: externals === true },\n );\n const isVirtual = serverFile.includes('\\n') || !existsSync(serverFile);\n const toolsInputOptions = await this.listToolsInputOptions(toolsPaths);\n\n if (isVirtual) {\n inputOptions.input = { index: '#entry', ...toolsInputOptions };\n\n if (Array.isArray(inputOptions.plugins)) {\n inputOptions.plugins.unshift(virtual({ '#entry': serverFile }));\n } else {\n inputOptions.plugins = [virtual({ '#entry': serverFile })];\n }\n } else {\n inputOptions.input = { index: serverFile, ...toolsInputOptions };\n }\n\n return inputOptions;\n }\n\n getAllToolPaths(mastraDir: string, toolsPaths: (string | string[])[] = []): (string | string[])[] {\n // Normalize Windows paths to forward slashes for consistent handling\n const normalizedMastraDir = slash(mastraDir);\n\n // Prepare default tools paths with glob patterns\n const defaultToolsPath = posix.join(normalizedMastraDir, 'tools/**/*.{js,ts}');\n const defaultToolsIgnorePaths = [\n `!${posix.join(normalizedMastraDir, 'tools/**/*.{test,spec}.{js,ts}')}`,\n `!${posix.join(normalizedMastraDir, 'tools/**/__tests__/**')}`,\n ];\n\n // Combine default path with ignore patterns\n const defaultPaths = [defaultToolsPath, ...defaultToolsIgnorePaths];\n\n // If no tools paths provided, use only the default paths\n if (toolsPaths.length === 0) {\n return [defaultPaths];\n }\n\n // If tools paths are provided, add the default paths to ensure standard tools are always included\n return [...toolsPaths, defaultPaths];\n }\n\n async listToolsInputOptions(toolsPaths: (string | string[])[]) {\n const inputs: Record<string, string> = {};\n\n for (const toolPath of toolsPaths) {\n const expandedPaths = await glob(toolPath, {\n absolute: true,\n expandDirectories: false,\n });\n\n for (const path of expandedPaths) {\n if (await fsExtra.pathExists(path)) {\n const fileService = new FileService();\n const entryFile = fileService.getFirstExistingFile([\n join(path, 'index.ts'),\n join(path, 'index.js'),\n path, // if path itself is a file\n ]);\n\n // if it doesn't exist or is a dir skip it. using a dir as a tool will crash the process\n if (!entryFile || (await stat(entryFile)).isDirectory()) {\n this.logger.warn('No entry file found, skipping', { path });\n continue;\n }\n\n const uniqueToolID = crypto.randomUUID();\n // Normalize Windows paths to forward slashes for consistent handling\n const normalizedEntryFile = entryFile.replaceAll('\\\\', '/');\n inputs[`tools/${uniqueToolID}`] = normalizedEntryFile;\n } else {\n this.logger.warn('Tool path does not exist, skipping', { path });\n }\n }\n }\n\n return inputs;\n }\n\n protected async _bundle(\n serverFile: string,\n mastraEntryFile: string,\n {\n projectRoot,\n outputDirectory,\n enableEsmShim = true,\n }: {\n projectRoot: string;\n outputDirectory: string;\n enableEsmShim?: boolean;\n },\n toolsPaths: (string | string[])[] = [],\n bundleLocation: string = join(outputDirectory, this.outputDir),\n ): Promise<void> {\n const analyzeDir = join(outputDirectory, this.analyzeOutputDir);\n\n const bundlerOptions = await this.getUserBundlerOptions(mastraEntryFile, outputDirectory);\n const internalBundlerOptions: BundlerOptions = {\n enableSourcemap: !!bundlerOptions.sourcemap,\n externals: bundlerOptions.externals ?? [],\n enableEsmShim,\n dynamicPackages: bundlerOptions.dynamicPackages,\n };\n\n let analyzedBundleInfo;\n try {\n const resolvedToolsPaths = await this.listToolsInputOptions(toolsPaths);\n analyzedBundleInfo = await analyzeBundle(\n [serverFile, ...Object.values(resolvedToolsPaths)],\n mastraEntryFile,\n {\n outputDir: analyzeDir,\n projectRoot,\n platform: this.platform,\n bundlerOptions: internalBundlerOptions,\n },\n this.logger,\n );\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n\n if (error instanceof MastraError) {\n throw error;\n }\n\n throw new MastraError(\n {\n id: 'DEPLOYER_BUNDLER_ANALYZE_FAILED',\n text: `Failed to analyze Mastra application: ${message}`,\n domain: ErrorDomain.DEPLOYER,\n category: ErrorCategory.SYSTEM,\n },\n error,\n );\n }\n\n const dependenciesToInstall = new Map<string, ExternalDependencyInfo>();\n for (const [dep, depInfo] of analyzedBundleInfo.externalDependencies) {\n if (analyzedBundleInfo.workspaceMap.has(dep) || !isBareModuleSpecifier(dep)) {\n continue;\n }\n\n dependenciesToInstall.set(dep, depInfo);\n }\n\n try {\n await this.writePackageJson(join(outputDirectory, this.outputDir), dependenciesToInstall);\n\n this.logger.info('Bundling Mastra application');\n\n const inputOptions: InputOptions = await this.getBundlerOptions(\n serverFile,\n mastraEntryFile,\n analyzedBundleInfo,\n toolsPaths,\n internalBundlerOptions,\n );\n\n const bundler = await this.createBundler(\n {\n ...inputOptions,\n logLevel: inputOptions.logLevel === 'silent' ? 'warn' : inputOptions.logLevel,\n onwarn: warning => {\n if (warning.code === 'CIRCULAR_DEPENDENCY') {\n if (warning.ids?.[0]?.includes('node_modules')) {\n return;\n }\n\n this.logger.warn('Circular dependency found', {\n dependency: warning.message.replace('Circular dependency: ', ''),\n });\n }\n },\n },\n {\n dir: bundleLocation,\n manualChunks: {\n mastra: ['#mastra'],\n },\n sourcemap: internalBundlerOptions.enableSourcemap,\n },\n );\n\n await bundler.write();\n const toolImports: string[] = [];\n const toolsExports: string[] = [];\n Array.from(Object.keys(inputOptions.input || {}))\n .filter(key => key.startsWith('tools/'))\n .forEach((key, index) => {\n const toolExport = `tool${index}`;\n toolImports.push(`import * as ${toolExport} from './${key}.mjs';`);\n toolsExports.push(toolExport);\n });\n\n await writeFile(\n join(bundleLocation, 'tools.mjs'),\n `${toolImports.join('\\n')}\n\nexport const tools = [${toolsExports.join(', ')}]`,\n );\n this.logger.info('Bundling Mastra done');\n\n this.logger.info('Copying public files');\n await this.copyPublic(dirname(mastraEntryFile), outputDirectory);\n this.logger.info('Done copying public files');\n\n this.logger.info('Copying .npmrc file');\n await this.copyDOTNPMRC({ outputDirectory, rootDir: projectRoot });\n\n this.logger.info('Done copying .npmrc file');\n\n this.logger.info('Installing dependencies');\n await this.installDependencies(outputDirectory, projectRoot);\n this.logger.info('Done installing dependencies');\n\n this.logger.info('Generating package-lock.json for deploy');\n await this.generateNpmLockfile(join(outputDirectory, this.outputDir));\n this.logger.info('Done generating package-lock.json');\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new MastraError(\n {\n id: 'DEPLOYER_BUNDLER_BUNDLE_STAGE_FAILED',\n text: `Failed during bundler bundle stage: ${message}`,\n domain: ErrorDomain.DEPLOYER,\n category: ErrorCategory.SYSTEM,\n },\n error,\n );\n }\n }\n\n async lint(_entryFile: string, _outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n const toolsInputOptions = await this.listToolsInputOptions(toolsPaths);\n const toolsLength = Object.keys(toolsInputOptions).length;\n if (toolsLength > 0) {\n this.logger.info('Found tools', { count: toolsLength });\n }\n }\n}\n"]}
@@ -1,9 +1,9 @@
1
- import { tsConfigPaths, protocolExternalResolver, esbuild, removeDeployer, getPackageRootPath, subpathExternalsResolver, esmShim } from './chunk-VWD7AY6H.js';
2
- import { slash, isDependencyPartOfPackage, getPackageName, isBuiltinModule, isBareModuleSpecifier, isExternalProtocolImport, getCompiledDepCachePath, rollupSafeName, getNodeResolveOptions } from './chunk-Z3DC47CH.js';
1
+ import { getPackageMetadata, protocolExternalResolver, mastraInternalAliasPlugin, mastraToolsAliasPlugin, tsConfigPaths, esbuild, removeDeployer, getPackageRootPath, subpathExternalsResolver, esmShim } from './chunk-FHLWDI5H.js';
2
+ import { slash, isDependencyPartOfPackage, getPackageName, isBuiltinModule, isBareModuleSpecifier, isExternalProtocolImport, getCompiledDepCachePath, rollupSafeName, getNodeResolveOptions } from './chunk-ANDDGKY5.js';
3
3
  import { existsSync } from 'fs';
4
4
  import { readFile, writeFile } from 'fs/promises';
5
5
  import * as path from 'path';
6
- import { dirname, join, relative, basename as basename$1 } from 'path';
6
+ import { dirname, join, relative, isAbsolute, basename as basename$1 } from 'path';
7
7
  import * as babel2 from '@babel/core';
8
8
  import babel2__default, { types } from '@babel/core';
9
9
  import { MastraBaseError, ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
@@ -15,7 +15,6 @@ import { noopLogger } from '@mastra/core/logger';
15
15
  import commonjs from '@rollup/plugin-commonjs';
16
16
  import json from '@rollup/plugin-json';
17
17
  import virtual from '@rollup/plugin-virtual';
18
- import { readJSON } from 'fs-extra/esm';
19
18
  import { resolveModule, getPackageInfo } from 'local-pkg';
20
19
  import { rollup } from 'rollup';
21
20
  import { basename } from 'path/posix';
@@ -257,7 +256,6 @@ var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
257
256
 
258
257
  // src/build/analyze/analyzeEntry.ts
259
258
  function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
260
- const normalizedMastraEntry = slash(mastraEntry);
261
259
  let virtualPlugin = null;
262
260
  if (isVirtualFile) {
263
261
  virtualPlugin = virtual({
@@ -271,22 +269,10 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
271
269
  }
272
270
  plugins.push(
273
271
  ...[
274
- tsConfigPaths(),
275
272
  protocolExternalResolver(),
276
- {
277
- name: "custom-alias-resolver",
278
- resolveId(id) {
279
- if (id === "#server") {
280
- return slash(fileURLToPath(import.meta.resolve("@mastra/deployer/server")));
281
- }
282
- if (id === "#mastra") {
283
- return normalizedMastraEntry;
284
- }
285
- if (id.startsWith("@mastra/server")) {
286
- return fileURLToPath(import.meta.resolve(id));
287
- }
288
- }
289
- },
273
+ mastraInternalAliasPlugin(mastraEntry),
274
+ mastraToolsAliasPlugin(),
275
+ tsConfigPaths(),
290
276
  json(),
291
277
  esbuild(),
292
278
  commonjs({
@@ -326,23 +312,21 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
326
312
  let rootPath = null;
327
313
  let isWorkspace = false;
328
314
  let version;
315
+ let packageSpec;
329
316
  if (pkgName) {
330
- rootPath = await getPackageRootPath(dependency, entryRootPath);
317
+ const metadata = await getPackageMetadata(dependency, entryRootPath);
318
+ rootPath = metadata.rootPath;
319
+ version = metadata.version;
320
+ packageSpec = metadata.packageSpec;
331
321
  isWorkspace = workspaceMap.has(pkgName);
332
- if (rootPath) {
333
- try {
334
- const pkgJson = await readJSON(`${rootPath}/package.json`);
335
- version = pkgJson.version;
336
- } catch {
337
- }
338
- }
339
322
  }
340
323
  const normalizedRootPath = rootPath ? slash(rootPath) : null;
341
324
  depsToOptimize.set(dependency, {
342
325
  exports: bindings,
343
326
  rootPath: normalizedRootPath,
344
327
  isWorkspace,
345
- version
328
+ version,
329
+ packageSpec
346
330
  });
347
331
  }
348
332
  async function checkTransitiveDependencies(internalMap, maxDepth = 10, currentDepth = 0) {
@@ -377,11 +361,23 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
377
361
  continue;
378
362
  }
379
363
  for (const [innerDep, innerMeta] of analysis.dependencies) {
380
- if (innerMeta.isWorkspace && !internalMap.has(innerDep) && !depsToOptimize.has(innerDep)) {
381
- depsToOptimize.set(innerDep, innerMeta);
382
- internalMap.set(innerDep, innerMeta);
383
- hasAddedDeps = true;
364
+ if (!innerMeta.isWorkspace) {
365
+ continue;
366
+ }
367
+ const existingMeta = depsToOptimize.get(innerDep);
368
+ if (existingMeta) {
369
+ depsToOptimize.set(innerDep, {
370
+ ...existingMeta,
371
+ exports: [.../* @__PURE__ */ new Set([...existingMeta.exports, ...innerMeta.exports])]
372
+ });
373
+ continue;
374
+ }
375
+ if (internalMap.has(innerDep)) {
376
+ continue;
384
377
  }
378
+ depsToOptimize.set(innerDep, innerMeta);
379
+ internalMap.set(innerDep, innerMeta);
380
+ hasAddedDeps = true;
385
381
  }
386
382
  } catch (err) {
387
383
  logger.error("Failed to resolve or analyze dependency", { dep, error: err.message });
@@ -400,22 +396,20 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
400
396
  if (!depsToOptimize.has(dynamicImport) && isBareModuleSpecifier(dynamicImport)) {
401
397
  const pkgName = getPackageName(dynamicImport);
402
398
  let version;
399
+ let packageSpec;
403
400
  let rootPath = null;
404
401
  if (pkgName) {
405
- rootPath = await getPackageRootPath(dynamicImport, entryRootPath);
406
- if (rootPath) {
407
- try {
408
- const pkgJson = await readJSON(`${rootPath}/package.json`);
409
- version = pkgJson.version;
410
- } catch {
411
- }
412
- }
402
+ const metadata = await getPackageMetadata(dynamicImport, entryRootPath);
403
+ rootPath = metadata.rootPath;
404
+ version = metadata.version;
405
+ packageSpec = metadata.packageSpec;
413
406
  }
414
407
  depsToOptimize.set(dynamicImport, {
415
408
  exports: ["*"],
416
409
  rootPath: rootPath ? slash(rootPath) : null,
417
410
  isWorkspace: false,
418
- version
411
+ version,
412
+ packageSpec
419
413
  });
420
414
  }
421
415
  }
@@ -851,9 +845,13 @@ async function buildExternalDependencies(virtualDependencies, {
851
845
  await bundler.close();
852
846
  return output;
853
847
  }
854
- function findExternalImporter(module, external, allOutputs) {
848
+ function findExternalImporter(module, external, allOutputs, visited = /* @__PURE__ */ new Set()) {
849
+ if (visited.has(module.fileName)) {
850
+ return null;
851
+ }
852
+ visited.add(module.fileName);
855
853
  const capturedFiles = /* @__PURE__ */ new Set();
856
- for (const id of module.imports) {
854
+ for (const id of [...module.imports, ...module.dynamicImports]) {
857
855
  if (isDependencyPartOfPackage(id, external)) {
858
856
  return module;
859
857
  } else {
@@ -865,7 +863,7 @@ function findExternalImporter(module, external, allOutputs) {
865
863
  for (const file of capturedFiles) {
866
864
  const nextModule = allOutputs.find((o) => o.fileName === file);
867
865
  if (nextModule) {
868
- const importer = findExternalImporter(nextModule, external, allOutputs);
866
+ const importer = findExternalImporter(nextModule, external, allOutputs, visited);
869
867
  if (importer) {
870
868
  return importer;
871
869
  }
@@ -1106,6 +1104,43 @@ function detectPinoTransports(transports) {
1106
1104
  }
1107
1105
 
1108
1106
  // src/build/analyze.ts
1107
+ function preferDependencyInfo(existing, incoming) {
1108
+ return {
1109
+ version: incoming.version ?? existing?.version,
1110
+ packageSpec: incoming.packageSpec ?? existing?.packageSpec
1111
+ };
1112
+ }
1113
+ async function resolveDependencyInfo(dep, existing, parentPaths) {
1114
+ if (existing?.version || existing?.packageSpec) {
1115
+ return existing;
1116
+ }
1117
+ const packageName = getPackageName(dep);
1118
+ const packageNames = [...new Set([dep, packageName].filter(Boolean))];
1119
+ for (const parentPath of parentPaths) {
1120
+ for (const name of packageNames) {
1121
+ const metadata = await getPackageMetadata(name, parentPath);
1122
+ if (metadata.version || metadata.packageSpec) {
1123
+ return preferDependencyInfo(existing, metadata);
1124
+ }
1125
+ }
1126
+ }
1127
+ for (const name of packageNames) {
1128
+ const metadata = await getPackageMetadata(name);
1129
+ if (metadata.version || metadata.packageSpec) {
1130
+ return preferDependencyInfo(existing, metadata);
1131
+ }
1132
+ }
1133
+ return existing ?? {};
1134
+ }
1135
+ function importerParentPaths(importerId, base) {
1136
+ if (!importerId || importerId.startsWith("\0") || !isAbsolute(importerId)) {
1137
+ return base;
1138
+ }
1139
+ return [.../* @__PURE__ */ new Set([importerId, ...base])];
1140
+ }
1141
+ function getLastConcreteModuleId(moduleIds) {
1142
+ return moduleIds.findLast((id) => !id.startsWith("\0") && isAbsolute(id));
1143
+ }
1109
1144
  function throwExternalDependencyError({
1110
1145
  errorId,
1111
1146
  moduleName,
@@ -1253,15 +1288,27 @@ async function validateOutput({
1253
1288
  externalDependencies: /* @__PURE__ */ new Map(),
1254
1289
  workspaceMap
1255
1290
  };
1291
+ const externalMetadataParentPaths = [
1292
+ projectRoot,
1293
+ ...Array.from(workspaceMap.values()).map((pkgInfo) => pkgInfo.location)
1294
+ ];
1256
1295
  for (const deps of Object.values(usedExternals)) {
1257
- for (const dep of Object.keys(deps)) {
1296
+ for (const [dep, importerId] of Object.entries(deps)) {
1258
1297
  if (isExternalProtocolImport(dep)) {
1259
1298
  continue;
1260
1299
  }
1261
1300
  const pkgName = getPackageName(dep);
1262
1301
  if (pkgName) {
1263
- const versionInfo = depsVersionInfo.get(dep) || depsVersionInfo.get(pkgName) || {};
1264
- result.externalDependencies.set(pkgName, versionInfo);
1302
+ const versionInfo = depsVersionInfo.get(dep) || depsVersionInfo.get(pkgName);
1303
+ const dependencyInfo = await resolveDependencyInfo(
1304
+ dep,
1305
+ versionInfo,
1306
+ importerParentPaths(importerId, externalMetadataParentPaths)
1307
+ );
1308
+ result.externalDependencies.set(
1309
+ pkgName,
1310
+ preferDependencyInfo(result.externalDependencies.get(pkgName), dependencyInfo)
1311
+ );
1265
1312
  }
1266
1313
  }
1267
1314
  }
@@ -1337,17 +1384,16 @@ async function analyzeBundle(entries, mastraEntry, {
1337
1384
  filename: "pino-detection.js",
1338
1385
  plugins: [detectPinoTransports(detectedPinoTransports)],
1339
1386
  configFile: false,
1340
- babelrc: false
1387
+ babelrc: false,
1388
+ code: false
1341
1389
  });
1342
1390
  await writeFile(join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
1343
1391
  for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
1344
1392
  const isPartOfExternals = allExternals.some((external) => isDependencyPartOfPackage(dep, external));
1345
1393
  if (isPartOfExternals || externalsPreset && !metadata.isWorkspace) {
1346
1394
  const pkgName = getPackageName(dep);
1347
- if (pkgName && !allUsedExternals.has(pkgName)) {
1348
- allUsedExternals.set(pkgName, {
1349
- version: metadata.version
1350
- });
1395
+ if (pkgName) {
1396
+ allUsedExternals.set(pkgName, preferDependencyInfo(allUsedExternals.get(pkgName), metadata));
1351
1397
  }
1352
1398
  continue;
1353
1399
  }
@@ -1355,6 +1401,8 @@ async function analyzeBundle(entries, mastraEntry, {
1355
1401
  const existingEntry = depsToOptimize.get(dep);
1356
1402
  depsToOptimize.set(dep, {
1357
1403
  ...existingEntry,
1404
+ version: metadata.version ?? existingEntry.version,
1405
+ packageSpec: metadata.packageSpec ?? existingEntry.packageSpec,
1358
1406
  exports: [.../* @__PURE__ */ new Set([...existingEntry.exports, ...metadata.exports])]
1359
1407
  });
1360
1408
  } else {
@@ -1362,6 +1410,16 @@ async function analyzeBundle(entries, mastraEntry, {
1362
1410
  }
1363
1411
  }
1364
1412
  }
1413
+ const depsVersionInfo = /* @__PURE__ */ new Map();
1414
+ for (const [dep, metadata] of depsToOptimize.entries()) {
1415
+ const pkgName = getPackageName(dep);
1416
+ if (pkgName && (metadata.version || metadata.packageSpec)) {
1417
+ depsVersionInfo.set(pkgName, preferDependencyInfo(depsVersionInfo.get(pkgName), metadata));
1418
+ }
1419
+ if (metadata.version || metadata.packageSpec) {
1420
+ depsVersionInfo.set(dep, preferDependencyInfo(depsVersionInfo.get(dep), metadata));
1421
+ }
1422
+ }
1365
1423
  if (isDev || externalsPreset) {
1366
1424
  for (const [dep, metadata] of depsToOptimize.entries()) {
1367
1425
  if (!metadata.isWorkspace) {
@@ -1386,24 +1444,11 @@ async function analyzeBundle(entries, mastraEntry, {
1386
1444
  const relativeWorkspaceFolderPaths = Array.from(workspaceMap.values()).map(
1387
1445
  (pkgInfo) => slash(relative(workspaceRoot || projectRoot, pkgInfo.location))
1388
1446
  );
1389
- const depsVersionInfo = /* @__PURE__ */ new Map();
1390
- for (const [dep, metadata] of depsToOptimize.entries()) {
1391
- const pkgName = getPackageName(dep);
1392
- if (pkgName && metadata.version) {
1393
- depsVersionInfo.set(pkgName, {
1394
- version: metadata.version
1395
- });
1396
- }
1397
- if (metadata.version) {
1398
- depsVersionInfo.set(dep, {
1399
- version: metadata.version
1400
- });
1401
- }
1402
- }
1403
1447
  for (const o of output) {
1404
1448
  if (o.type === "asset") {
1405
1449
  continue;
1406
1450
  }
1451
+ const importerId = getLastConcreteModuleId(o.moduleIds);
1407
1452
  for (const i of o.imports) {
1408
1453
  if (isBuiltinModule(i)) {
1409
1454
  continue;
@@ -1418,9 +1463,17 @@ async function analyzeBundle(entries, mastraEntry, {
1418
1463
  continue;
1419
1464
  }
1420
1465
  const pkgName = getPackageName(i);
1421
- if (pkgName && !allUsedExternals.has(pkgName)) {
1422
- const versionInfo = depsVersionInfo.get(i) || depsVersionInfo.get(pkgName) || {};
1423
- allUsedExternals.set(pkgName, versionInfo);
1466
+ if (pkgName) {
1467
+ const versionInfo = depsVersionInfo.get(i) || depsVersionInfo.get(pkgName);
1468
+ const dependencyInfo = await resolveDependencyInfo(
1469
+ i,
1470
+ versionInfo,
1471
+ importerParentPaths(importerId, [
1472
+ projectRoot,
1473
+ ...Array.from(workspaceMap.values()).map((pkgInfo) => pkgInfo.location)
1474
+ ])
1475
+ );
1476
+ allUsedExternals.set(pkgName, preferDependencyInfo(allUsedExternals.get(pkgName), dependencyInfo));
1424
1477
  }
1425
1478
  }
1426
1479
  }
@@ -1441,19 +1494,29 @@ async function analyzeBundle(entries, mastraEntry, {
1441
1494
  if (isExternalProtocolImport(dep)) {
1442
1495
  continue;
1443
1496
  }
1444
- const existing = mergedExternalDeps.get(dep);
1445
- if (!existing || !existing.version && info.version) {
1446
- mergedExternalDeps.set(dep, info);
1497
+ mergedExternalDeps.set(dep, preferDependencyInfo(mergedExternalDeps.get(dep), info));
1498
+ }
1499
+ const externalMetadataParentPaths = [
1500
+ projectRoot,
1501
+ ...Array.from(workspaceMap.values()).map((pkgInfo) => pkgInfo.location),
1502
+ // Last resort: resolve from the deployer's own installed location. Some externals are
1503
+ // discovered inside externalized packages (e.g. optional dynamic imports like
1504
+ // `import('typescript')` in @mastra/core) without being installed in the user's project.
1505
+ import.meta.dirname
1506
+ ];
1507
+ for (const [dep, info] of mergedExternalDeps) {
1508
+ if (!info.version && !info.packageSpec) {
1509
+ mergedExternalDeps.set(dep, await resolveDependencyInfo(dep, info, externalMetadataParentPaths));
1447
1510
  }
1448
1511
  }
1449
1512
  for (const transport of detectedPinoTransports) {
1450
1513
  if (!mergedExternalDeps.has(transport)) {
1451
- mergedExternalDeps.set(transport, {});
1514
+ mergedExternalDeps.set(transport, await resolveDependencyInfo(transport, void 0, externalMetadataParentPaths));
1452
1515
  }
1453
1516
  }
1454
1517
  for (const pkg2 of userDynamicPackages) {
1455
1518
  if (!mergedExternalDeps.has(pkg2)) {
1456
- mergedExternalDeps.set(pkg2, {});
1519
+ mergedExternalDeps.set(pkg2, await resolveDependencyInfo(pkg2, void 0, externalMetadataParentPaths));
1457
1520
  }
1458
1521
  }
1459
1522
  return {
@@ -1463,5 +1526,5 @@ async function analyzeBundle(entries, mastraEntry, {
1463
1526
  }
1464
1527
 
1465
1528
  export { aliasHono, analyzeBundle, getWorkspaceInformation };
1466
- //# sourceMappingURL=chunk-566UDTD4.js.map
1467
- //# sourceMappingURL=chunk-566UDTD4.js.map
1529
+ //# sourceMappingURL=chunk-4MVAT24Z.js.map
1530
+ //# sourceMappingURL=chunk-4MVAT24Z.js.map