@mastra/deployer 1.48.1-alpha.0 → 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 +61 -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-CHZ76N6R.cjs → chunk-3GTT2N4V.cjs} +21 -47
  30. package/dist/chunk-3GTT2N4V.cjs.map +1 -0
  31. package/dist/{chunk-FQC6UUHS.js → chunk-4MVAT24Z.js} +140 -77
  32. package/dist/chunk-4MVAT24Z.js.map +1 -0
  33. package/dist/{chunk-7PMC7SBC.cjs → chunk-7YI2AEFO.cjs} +23 -17
  34. package/dist/chunk-7YI2AEFO.cjs.map +1 -0
  35. package/dist/{chunk-V6F2NMS2.js → chunk-ANDDGKY5.js} +23 -17
  36. package/dist/chunk-ANDDGKY5.js.map +1 -0
  37. package/dist/{chunk-MPEFRVWJ.js → chunk-CCBU3OII.js} +3 -3
  38. package/dist/{chunk-MPEFRVWJ.js.map → chunk-CCBU3OII.js.map} +1 -1
  39. package/dist/{chunk-IYKMQHY2.cjs → chunk-EU74XSTG.cjs} +43 -44
  40. package/dist/chunk-EU74XSTG.cjs.map +1 -0
  41. package/dist/{chunk-ORSNDVAB.js → chunk-FHLWDI5H.js} +332 -45
  42. package/dist/chunk-FHLWDI5H.js.map +1 -0
  43. package/dist/{chunk-47KJ3RKB.cjs → chunk-IMPHNLMW.cjs} +178 -115
  44. package/dist/chunk-IMPHNLMW.cjs.map +1 -0
  45. package/dist/{chunk-I7TERDMR.cjs → chunk-N5CQWHN3.cjs} +343 -46
  46. package/dist/chunk-N5CQWHN3.cjs.map +1 -0
  47. package/dist/{chunk-T6LS4OKA.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-VZYB4EVX.cjs → chunk-VNJLLLQN.cjs} +7 -7
  52. package/dist/{chunk-VZYB4EVX.cjs.map → chunk-VNJLLLQN.cjs.map} +1 -1
  53. package/dist/{chunk-TDNEF2M5.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-2WEUOK6I.js +0 -258
  82. package/dist/chunk-2WEUOK6I.js.map +0 -1
  83. package/dist/chunk-47KJ3RKB.cjs.map +0 -1
  84. package/dist/chunk-5GX66TF5.js.map +0 -1
  85. package/dist/chunk-7PMC7SBC.cjs.map +0 -1
  86. package/dist/chunk-CHZ76N6R.cjs.map +0 -1
  87. package/dist/chunk-FBL7GBNM.cjs +0 -269
  88. package/dist/chunk-FBL7GBNM.cjs.map +0 -1
  89. package/dist/chunk-FQC6UUHS.js.map +0 -1
  90. package/dist/chunk-I7TERDMR.cjs.map +0 -1
  91. package/dist/chunk-IYKMQHY2.cjs.map +0 -1
  92. package/dist/chunk-ORSNDVAB.js.map +0 -1
  93. package/dist/chunk-T6LS4OKA.js.map +0 -1
  94. package/dist/chunk-TDNEF2M5.js.map +0 -1
  95. package/dist/chunk-V6F2NMS2.js.map +0 -1
  96. package/dist/chunk-VXLIM7FD.cjs.map +0 -1
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkI7TERDMR_cjs = require('./chunk-I7TERDMR.cjs');
4
- var chunk7PMC7SBC_cjs = require('./chunk-7PMC7SBC.cjs');
3
+ var chunkN5CQWHN3_cjs = require('./chunk-N5CQWHN3.cjs');
4
+ var chunk7YI2AEFO_cjs = require('./chunk-7YI2AEFO.cjs');
5
5
  var fs = require('fs');
6
6
  var promises = require('fs/promises');
7
7
  var path = require('path');
@@ -15,7 +15,6 @@ var logger = require('@mastra/core/logger');
15
15
  var commonjs = require('@rollup/plugin-commonjs');
16
16
  var json = require('@rollup/plugin-json');
17
17
  var virtual = require('@rollup/plugin-virtual');
18
- var esm = require('fs-extra/esm');
19
18
  var localPkg = require('local-pkg');
20
19
  var rollup = require('rollup');
21
20
  var posix = require('path/posix');
@@ -157,7 +156,7 @@ async function getWorkspaceInformation({
157
156
  mastraEntryFile
158
157
  }) {
159
158
  const closestPkgJson = pkg__namespace.up({ cwd: path.dirname(mastraEntryFile) });
160
- const location = closestPkgJson ? path.dirname(chunk7PMC7SBC_cjs.slash(closestPkgJson)) : chunk7PMC7SBC_cjs.slash(process.cwd());
159
+ const location = closestPkgJson ? path.dirname(chunk7YI2AEFO_cjs.slash(closestPkgJson)) : chunk7YI2AEFO_cjs.slash(process.cwd());
161
160
  const workspaces = await findWorkspaces.findWorkspaces(dir, { cache: workspacesCache });
162
161
  const _workspaceMap = new Map(
163
162
  workspaces?.map((workspace) => [
@@ -286,7 +285,6 @@ var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
286
285
 
287
286
  // src/build/analyze/analyzeEntry.ts
288
287
  function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
289
- const normalizedMastraEntry = chunk7PMC7SBC_cjs.slash(mastraEntry);
290
288
  let virtualPlugin = null;
291
289
  if (isVirtualFile) {
292
290
  virtualPlugin = virtual__default.default({
@@ -300,34 +298,22 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
300
298
  }
301
299
  plugins.push(
302
300
  ...[
303
- chunkI7TERDMR_cjs.tsConfigPaths(),
304
- chunkI7TERDMR_cjs.protocolExternalResolver(),
305
- {
306
- name: "custom-alias-resolver",
307
- resolveId(id) {
308
- if (id === "#server") {
309
- return chunk7PMC7SBC_cjs.slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
310
- }
311
- if (id === "#mastra") {
312
- return normalizedMastraEntry;
313
- }
314
- if (id.startsWith("@mastra/server")) {
315
- return url.fileURLToPath(undefined(id));
316
- }
317
- }
318
- },
301
+ chunkN5CQWHN3_cjs.protocolExternalResolver(),
302
+ chunkN5CQWHN3_cjs.mastraInternalAliasPlugin(mastraEntry),
303
+ chunkN5CQWHN3_cjs.mastraToolsAliasPlugin(),
304
+ chunkN5CQWHN3_cjs.tsConfigPaths(),
319
305
  json__default.default(),
320
- chunkI7TERDMR_cjs.esbuild(),
306
+ chunkN5CQWHN3_cjs.esbuild(),
321
307
  commonjs__default.default({
322
308
  strictRequires: "debug",
323
309
  ignoreTryCatch: false,
324
310
  transformMixedEsModules: true,
325
311
  extensions: [".js", ".ts"]
326
312
  }),
327
- chunkI7TERDMR_cjs.removeDeployer(mastraEntry, {
313
+ chunkN5CQWHN3_cjs.removeDeployer(mastraEntry, {
328
314
  sourcemap: sourcemapEnabled
329
315
  }),
330
- chunkI7TERDMR_cjs.esbuild()
316
+ chunkN5CQWHN3_cjs.esbuild()
331
317
  ]
332
318
  );
333
319
  return plugins;
@@ -345,33 +331,31 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
345
331
  }
346
332
  let entryRootPath = projectRoot;
347
333
  if (!output.facadeModuleId.startsWith("\0virtual:")) {
348
- entryRootPath = await chunkI7TERDMR_cjs.getPackageRootPath(output.facadeModuleId) || projectRoot;
334
+ entryRootPath = await chunkN5CQWHN3_cjs.getPackageRootPath(output.facadeModuleId) || projectRoot;
349
335
  }
350
336
  for (const [dependency, bindings] of Object.entries(output.importedBindings)) {
351
- if (!chunk7PMC7SBC_cjs.isBareModuleSpecifier(dependency)) {
337
+ if (!chunk7YI2AEFO_cjs.isBareModuleSpecifier(dependency)) {
352
338
  continue;
353
339
  }
354
- const pkgName = chunk7PMC7SBC_cjs.getPackageName(dependency);
340
+ const pkgName = chunk7YI2AEFO_cjs.getPackageName(dependency);
355
341
  let rootPath = null;
356
342
  let isWorkspace = false;
357
343
  let version;
344
+ let packageSpec;
358
345
  if (pkgName) {
359
- rootPath = await chunkI7TERDMR_cjs.getPackageRootPath(dependency, entryRootPath);
346
+ const metadata = await chunkN5CQWHN3_cjs.getPackageMetadata(dependency, entryRootPath);
347
+ rootPath = metadata.rootPath;
348
+ version = metadata.version;
349
+ packageSpec = metadata.packageSpec;
360
350
  isWorkspace = workspaceMap.has(pkgName);
361
- if (rootPath) {
362
- try {
363
- const pkgJson = await esm.readJSON(`${rootPath}/package.json`);
364
- version = pkgJson.version;
365
- } catch {
366
- }
367
- }
368
351
  }
369
- const normalizedRootPath = rootPath ? chunk7PMC7SBC_cjs.slash(rootPath) : null;
352
+ const normalizedRootPath = rootPath ? chunk7YI2AEFO_cjs.slash(rootPath) : null;
370
353
  depsToOptimize.set(dependency, {
371
354
  exports: bindings,
372
355
  rootPath: normalizedRootPath,
373
356
  isWorkspace,
374
- version
357
+ version,
358
+ packageSpec
375
359
  });
376
360
  }
377
361
  async function checkTransitiveDependencies(internalMap, maxDepth = 10, currentDepth = 0) {
@@ -406,11 +390,23 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
406
390
  continue;
407
391
  }
408
392
  for (const [innerDep, innerMeta] of analysis.dependencies) {
409
- if (innerMeta.isWorkspace && !internalMap.has(innerDep) && !depsToOptimize.has(innerDep)) {
410
- depsToOptimize.set(innerDep, innerMeta);
411
- internalMap.set(innerDep, innerMeta);
412
- hasAddedDeps = true;
393
+ if (!innerMeta.isWorkspace) {
394
+ continue;
395
+ }
396
+ const existingMeta = depsToOptimize.get(innerDep);
397
+ if (existingMeta) {
398
+ depsToOptimize.set(innerDep, {
399
+ ...existingMeta,
400
+ exports: [.../* @__PURE__ */ new Set([...existingMeta.exports, ...innerMeta.exports])]
401
+ });
402
+ continue;
413
403
  }
404
+ if (internalMap.has(innerDep)) {
405
+ continue;
406
+ }
407
+ depsToOptimize.set(innerDep, innerMeta);
408
+ internalMap.set(innerDep, innerMeta);
409
+ hasAddedDeps = true;
414
410
  }
415
411
  } catch (err) {
416
412
  logger$1.error("Failed to resolve or analyze dependency", { dep, error: err.message });
@@ -426,25 +422,23 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
426
422
  const dynamicImports = output.dynamicImports.filter((d) => !DEPS_TO_IGNORE.includes(d));
427
423
  if (dynamicImports.length) {
428
424
  for (const dynamicImport of dynamicImports) {
429
- if (!depsToOptimize.has(dynamicImport) && chunk7PMC7SBC_cjs.isBareModuleSpecifier(dynamicImport)) {
430
- const pkgName = chunk7PMC7SBC_cjs.getPackageName(dynamicImport);
425
+ if (!depsToOptimize.has(dynamicImport) && chunk7YI2AEFO_cjs.isBareModuleSpecifier(dynamicImport)) {
426
+ const pkgName = chunk7YI2AEFO_cjs.getPackageName(dynamicImport);
431
427
  let version;
428
+ let packageSpec;
432
429
  let rootPath = null;
433
430
  if (pkgName) {
434
- rootPath = await chunkI7TERDMR_cjs.getPackageRootPath(dynamicImport, entryRootPath);
435
- if (rootPath) {
436
- try {
437
- const pkgJson = await esm.readJSON(`${rootPath}/package.json`);
438
- version = pkgJson.version;
439
- } catch {
440
- }
441
- }
431
+ const metadata = await chunkN5CQWHN3_cjs.getPackageMetadata(dynamicImport, entryRootPath);
432
+ rootPath = metadata.rootPath;
433
+ version = metadata.version;
434
+ packageSpec = metadata.packageSpec;
442
435
  }
443
436
  depsToOptimize.set(dynamicImport, {
444
437
  exports: ["*"],
445
- rootPath: rootPath ? chunk7PMC7SBC_cjs.slash(rootPath) : null,
438
+ rootPath: rootPath ? chunk7YI2AEFO_cjs.slash(rootPath) : null,
446
439
  isWorkspace: false,
447
- version
440
+ version,
441
+ packageSpec
448
442
  });
449
443
  }
450
444
  }
@@ -464,7 +458,7 @@ async function analyzeEntry({
464
458
  shouldCheckTransitiveDependencies = false,
465
459
  analyzeCache
466
460
  }) {
467
- const cacheKey = isVirtualFile ? void 0 : chunk7PMC7SBC_cjs.slash(entry);
461
+ const cacheKey = isVirtualFile ? void 0 : chunk7YI2AEFO_cjs.slash(entry);
468
462
  if (cacheKey && analyzeCache?.has(cacheKey)) {
469
463
  return analyzeCache.get(cacheKey);
470
464
  }
@@ -526,7 +520,7 @@ function moduleResolveMap(externals, projectRoot) {
526
520
  }
527
521
  for (const importedId of info.importedIds) {
528
522
  for (const external of externals) {
529
- if (chunk7PMC7SBC_cjs.isDependencyPartOfPackage(importedId, external)) {
523
+ if (chunk7YI2AEFO_cjs.isDependencyPartOfPackage(importedId, external)) {
530
524
  importMap.set(external, info.id);
531
525
  }
532
526
  }
@@ -538,9 +532,9 @@ function moduleResolveMap(externals, projectRoot) {
538
532
  if (chunk.type === "chunk") {
539
533
  for (const [external, resolvedFrom] of importMap) {
540
534
  if (chunk.moduleIds.includes(resolvedFrom)) {
541
- const fullPath = url.pathToFileURL(chunk7PMC7SBC_cjs.slash(path.join(projectRoot, fileName))).toString();
535
+ const fullPath = url.pathToFileURL(chunk7YI2AEFO_cjs.slash(path.join(projectRoot, fileName))).toString();
542
536
  const innerMap = resolveMap.get(fullPath) || /* @__PURE__ */ new Map();
543
- innerMap.set(external, url.pathToFileURL(chunk7PMC7SBC_cjs.slash(resolvedFrom)).toString());
537
+ innerMap.set(external, url.pathToFileURL(chunk7YI2AEFO_cjs.slash(resolvedFrom)).toString());
544
538
  resolveMap.set(fullPath, innerMap);
545
539
  }
546
540
  }
@@ -606,7 +600,7 @@ function nodeGypDetector() {
606
600
 
607
601
  // src/build/analyze/bundleExternals.ts
608
602
  function prepareEntryFileName(name, rootDir) {
609
- return chunk7PMC7SBC_cjs.rollupSafeName(name, rootDir);
603
+ return chunk7YI2AEFO_cjs.rollupSafeName(name, rootDir);
610
604
  }
611
605
  function createVirtualDependencies(depsToOptimize, {
612
606
  projectRoot,
@@ -656,7 +650,7 @@ function createVirtualDependencies(depsToOptimize, {
656
650
  continue;
657
651
  }
658
652
  const fileName = posix.basename(currentDepPath.name);
659
- const entryName = prepareEntryFileName(chunk7PMC7SBC_cjs.getCompiledDepCachePath(rootPath, fileName), rootDir);
653
+ const entryName = prepareEntryFileName(chunk7YI2AEFO_cjs.getCompiledDepCachePath(rootPath, fileName), rootDir);
660
654
  fileNameToDependencyMap.set(entryName, dep);
661
655
  optimizedDependencyEntries.set(dep, {
662
656
  ...currentDepPath,
@@ -676,9 +670,9 @@ async function getInputPlugins2(virtualDependencies, {
676
670
  }) {
677
671
  const transpilePackagesMap = /* @__PURE__ */ new Map();
678
672
  for (const pkg2 of transpilePackages) {
679
- const dir = await chunkI7TERDMR_cjs.getPackageRootPath(pkg2);
673
+ const dir = await chunkN5CQWHN3_cjs.getPackageRootPath(pkg2);
680
674
  if (dir) {
681
- transpilePackagesMap.set(pkg2, chunk7PMC7SBC_cjs.slash(dir));
675
+ transpilePackagesMap.set(pkg2, chunk7YI2AEFO_cjs.slash(dir));
682
676
  } else {
683
677
  transpilePackagesMap.set(pkg2, workspaceMap.get(pkg2)?.location ?? pkg2);
684
678
  }
@@ -693,10 +687,10 @@ async function getInputPlugins2(virtualDependencies, {
693
687
  {}
694
688
  )
695
689
  ),
696
- chunkI7TERDMR_cjs.tsConfigPaths(),
697
- chunkI7TERDMR_cjs.protocolExternalResolver(),
698
- chunkI7TERDMR_cjs.subpathExternalsResolver(externals),
699
- transpilePackagesMap.size ? chunkI7TERDMR_cjs.esbuild({
690
+ chunkN5CQWHN3_cjs.tsConfigPaths(),
691
+ chunkN5CQWHN3_cjs.protocolExternalResolver(),
692
+ chunkN5CQWHN3_cjs.subpathExternalsResolver(externals),
693
+ transpilePackagesMap.size ? chunkN5CQWHN3_cjs.esbuild({
700
694
  format: "esm",
701
695
  include: [
702
696
  // Match files from transpilePackages by their actual directory paths
@@ -751,8 +745,8 @@ async function getInputPlugins2(virtualDependencies, {
751
745
  transformMixedEsModules: true,
752
746
  ignoreTryCatch: false
753
747
  }),
754
- bundlerOptions.noBundling ? null : nodeResolve__default.default(chunk7PMC7SBC_cjs.getNodeResolveOptions(platform)),
755
- bundlerOptions.noBundling ? chunkI7TERDMR_cjs.esmShim() : null,
748
+ bundlerOptions.noBundling ? null : nodeResolve__default.default(chunk7YI2AEFO_cjs.getNodeResolveOptions(platform)),
749
+ bundlerOptions.noBundling ? chunkN5CQWHN3_cjs.esmShim() : null,
756
750
  // hono is imported from deployer, so we need to resolve from here instead of the project root
757
751
  aliasHono(),
758
752
  json__default.default(),
@@ -845,9 +839,9 @@ async function buildExternalDependencies(virtualDependencies, {
845
839
  if (noBundling) {
846
840
  const importedFromPackages = /* @__PURE__ */ new Set();
847
841
  for (const moduleId of chunkInfo.moduleIds) {
848
- const normalized = chunk7PMC7SBC_cjs.slash(moduleId);
842
+ const normalized = chunk7YI2AEFO_cjs.slash(moduleId);
849
843
  for (const [pkgName, pkgInfo] of workspaceMap.entries()) {
850
- const location = chunk7PMC7SBC_cjs.slash(pkgInfo.location);
844
+ const location = chunk7YI2AEFO_cjs.slash(pkgInfo.location);
851
845
  if (normalized.startsWith(location)) {
852
846
  importedFromPackages.add(pkgName);
853
847
  break;
@@ -869,7 +863,7 @@ async function buildExternalDependencies(virtualDependencies, {
869
863
  if (importedFromPackages.size === 1) {
870
864
  const [pkgName] = importedFromPackages;
871
865
  const workspaceLocation = workspaceMap.get(pkgName).location;
872
- return prepareEntryFileName(chunk7PMC7SBC_cjs.getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
866
+ return prepareEntryFileName(chunk7YI2AEFO_cjs.getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
873
867
  }
874
868
  }
875
869
  return `${outputDirRelative}/[name].mjs`;
@@ -880,10 +874,14 @@ async function buildExternalDependencies(virtualDependencies, {
880
874
  await bundler.close();
881
875
  return output;
882
876
  }
883
- function findExternalImporter(module, external, allOutputs) {
877
+ function findExternalImporter(module, external, allOutputs, visited = /* @__PURE__ */ new Set()) {
878
+ if (visited.has(module.fileName)) {
879
+ return null;
880
+ }
881
+ visited.add(module.fileName);
884
882
  const capturedFiles = /* @__PURE__ */ new Set();
885
- for (const id of module.imports) {
886
- if (chunk7PMC7SBC_cjs.isDependencyPartOfPackage(id, external)) {
883
+ for (const id of [...module.imports, ...module.dynamicImports]) {
884
+ if (chunk7YI2AEFO_cjs.isDependencyPartOfPackage(id, external)) {
887
885
  return module;
888
886
  } else {
889
887
  if (id.endsWith(".mjs")) {
@@ -894,7 +892,7 @@ function findExternalImporter(module, external, allOutputs) {
894
892
  for (const file of capturedFiles) {
895
893
  const nextModule = allOutputs.find((o) => o.fileName === file);
896
894
  if (nextModule) {
897
- const importer = findExternalImporter(nextModule, external, allOutputs);
895
+ const importer = findExternalImporter(nextModule, external, allOutputs, visited);
898
896
  if (importer) {
899
897
  return importer;
900
898
  }
@@ -1135,6 +1133,43 @@ function detectPinoTransports(transports) {
1135
1133
  }
1136
1134
 
1137
1135
  // src/build/analyze.ts
1136
+ function preferDependencyInfo(existing, incoming) {
1137
+ return {
1138
+ version: incoming.version ?? existing?.version,
1139
+ packageSpec: incoming.packageSpec ?? existing?.packageSpec
1140
+ };
1141
+ }
1142
+ async function resolveDependencyInfo(dep, existing, parentPaths) {
1143
+ if (existing?.version || existing?.packageSpec) {
1144
+ return existing;
1145
+ }
1146
+ const packageName = chunk7YI2AEFO_cjs.getPackageName(dep);
1147
+ const packageNames = [...new Set([dep, packageName].filter(Boolean))];
1148
+ for (const parentPath of parentPaths) {
1149
+ for (const name of packageNames) {
1150
+ const metadata = await chunkN5CQWHN3_cjs.getPackageMetadata(name, parentPath);
1151
+ if (metadata.version || metadata.packageSpec) {
1152
+ return preferDependencyInfo(existing, metadata);
1153
+ }
1154
+ }
1155
+ }
1156
+ for (const name of packageNames) {
1157
+ const metadata = await chunkN5CQWHN3_cjs.getPackageMetadata(name);
1158
+ if (metadata.version || metadata.packageSpec) {
1159
+ return preferDependencyInfo(existing, metadata);
1160
+ }
1161
+ }
1162
+ return existing ?? {};
1163
+ }
1164
+ function importerParentPaths(importerId, base) {
1165
+ if (!importerId || importerId.startsWith("\0") || !path.isAbsolute(importerId)) {
1166
+ return base;
1167
+ }
1168
+ return [.../* @__PURE__ */ new Set([importerId, ...base])];
1169
+ }
1170
+ function getLastConcreteModuleId(moduleIds) {
1171
+ return moduleIds.findLast((id) => !id.startsWith("\0") && path.isAbsolute(id));
1172
+ }
1138
1173
  function throwExternalDependencyError({
1139
1174
  errorId,
1140
1175
  moduleName,
@@ -1282,15 +1317,27 @@ async function validateOutput({
1282
1317
  externalDependencies: /* @__PURE__ */ new Map(),
1283
1318
  workspaceMap
1284
1319
  };
1320
+ const externalMetadataParentPaths = [
1321
+ projectRoot,
1322
+ ...Array.from(workspaceMap.values()).map((pkgInfo) => pkgInfo.location)
1323
+ ];
1285
1324
  for (const deps of Object.values(usedExternals)) {
1286
- for (const dep of Object.keys(deps)) {
1287
- if (chunk7PMC7SBC_cjs.isExternalProtocolImport(dep)) {
1325
+ for (const [dep, importerId] of Object.entries(deps)) {
1326
+ if (chunk7YI2AEFO_cjs.isExternalProtocolImport(dep)) {
1288
1327
  continue;
1289
1328
  }
1290
- const pkgName = chunk7PMC7SBC_cjs.getPackageName(dep);
1329
+ const pkgName = chunk7YI2AEFO_cjs.getPackageName(dep);
1291
1330
  if (pkgName) {
1292
- const versionInfo = depsVersionInfo.get(dep) || depsVersionInfo.get(pkgName) || {};
1293
- result.externalDependencies.set(pkgName, versionInfo);
1331
+ const versionInfo = depsVersionInfo.get(dep) || depsVersionInfo.get(pkgName);
1332
+ const dependencyInfo = await resolveDependencyInfo(
1333
+ dep,
1334
+ versionInfo,
1335
+ importerParentPaths(importerId, externalMetadataParentPaths)
1336
+ );
1337
+ result.externalDependencies.set(
1338
+ pkgName,
1339
+ preferDependencyInfo(result.externalDependencies.get(pkgName), dependencyInfo)
1340
+ );
1294
1341
  }
1295
1342
  }
1296
1343
  }
@@ -1366,17 +1413,16 @@ async function analyzeBundle(entries, mastraEntry, {
1366
1413
  filename: "pino-detection.js",
1367
1414
  plugins: [detectPinoTransports(detectedPinoTransports)],
1368
1415
  configFile: false,
1369
- babelrc: false
1416
+ babelrc: false,
1417
+ code: false
1370
1418
  });
1371
1419
  await promises.writeFile(path.join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
1372
1420
  for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
1373
- const isPartOfExternals = allExternals.some((external) => chunk7PMC7SBC_cjs.isDependencyPartOfPackage(dep, external));
1421
+ const isPartOfExternals = allExternals.some((external) => chunk7YI2AEFO_cjs.isDependencyPartOfPackage(dep, external));
1374
1422
  if (isPartOfExternals || externalsPreset && !metadata.isWorkspace) {
1375
- const pkgName = chunk7PMC7SBC_cjs.getPackageName(dep);
1376
- if (pkgName && !allUsedExternals.has(pkgName)) {
1377
- allUsedExternals.set(pkgName, {
1378
- version: metadata.version
1379
- });
1423
+ const pkgName = chunk7YI2AEFO_cjs.getPackageName(dep);
1424
+ if (pkgName) {
1425
+ allUsedExternals.set(pkgName, preferDependencyInfo(allUsedExternals.get(pkgName), metadata));
1380
1426
  }
1381
1427
  continue;
1382
1428
  }
@@ -1384,6 +1430,8 @@ async function analyzeBundle(entries, mastraEntry, {
1384
1430
  const existingEntry = depsToOptimize.get(dep);
1385
1431
  depsToOptimize.set(dep, {
1386
1432
  ...existingEntry,
1433
+ version: metadata.version ?? existingEntry.version,
1434
+ packageSpec: metadata.packageSpec ?? existingEntry.packageSpec,
1387
1435
  exports: [.../* @__PURE__ */ new Set([...existingEntry.exports, ...metadata.exports])]
1388
1436
  });
1389
1437
  } else {
@@ -1391,6 +1439,16 @@ async function analyzeBundle(entries, mastraEntry, {
1391
1439
  }
1392
1440
  }
1393
1441
  }
1442
+ const depsVersionInfo = /* @__PURE__ */ new Map();
1443
+ for (const [dep, metadata] of depsToOptimize.entries()) {
1444
+ const pkgName = chunk7YI2AEFO_cjs.getPackageName(dep);
1445
+ if (pkgName && (metadata.version || metadata.packageSpec)) {
1446
+ depsVersionInfo.set(pkgName, preferDependencyInfo(depsVersionInfo.get(pkgName), metadata));
1447
+ }
1448
+ if (metadata.version || metadata.packageSpec) {
1449
+ depsVersionInfo.set(dep, preferDependencyInfo(depsVersionInfo.get(dep), metadata));
1450
+ }
1451
+ }
1394
1452
  if (isDev || externalsPreset) {
1395
1453
  for (const [dep, metadata] of depsToOptimize.entries()) {
1396
1454
  if (!metadata.isWorkspace) {
@@ -1413,43 +1471,38 @@ async function analyzeBundle(entries, mastraEntry, {
1413
1471
  platform
1414
1472
  });
1415
1473
  const relativeWorkspaceFolderPaths = Array.from(workspaceMap.values()).map(
1416
- (pkgInfo) => chunk7PMC7SBC_cjs.slash(path.relative(workspaceRoot || projectRoot, pkgInfo.location))
1474
+ (pkgInfo) => chunk7YI2AEFO_cjs.slash(path.relative(workspaceRoot || projectRoot, pkgInfo.location))
1417
1475
  );
1418
- const depsVersionInfo = /* @__PURE__ */ new Map();
1419
- for (const [dep, metadata] of depsToOptimize.entries()) {
1420
- const pkgName = chunk7PMC7SBC_cjs.getPackageName(dep);
1421
- if (pkgName && metadata.version) {
1422
- depsVersionInfo.set(pkgName, {
1423
- version: metadata.version
1424
- });
1425
- }
1426
- if (metadata.version) {
1427
- depsVersionInfo.set(dep, {
1428
- version: metadata.version
1429
- });
1430
- }
1431
- }
1432
1476
  for (const o of output) {
1433
1477
  if (o.type === "asset") {
1434
1478
  continue;
1435
1479
  }
1480
+ const importerId = getLastConcreteModuleId(o.moduleIds);
1436
1481
  for (const i of o.imports) {
1437
- if (chunk7PMC7SBC_cjs.isBuiltinModule(i)) {
1482
+ if (chunk7YI2AEFO_cjs.isBuiltinModule(i)) {
1438
1483
  continue;
1439
1484
  }
1440
1485
  if (i.startsWith(".") || i.startsWith("/")) {
1441
1486
  continue;
1442
1487
  }
1443
- if (!chunk7PMC7SBC_cjs.isBareModuleSpecifier(i) || chunk7PMC7SBC_cjs.isExternalProtocolImport(i)) {
1488
+ if (!chunk7YI2AEFO_cjs.isBareModuleSpecifier(i) || chunk7YI2AEFO_cjs.isExternalProtocolImport(i)) {
1444
1489
  continue;
1445
1490
  }
1446
1491
  if (relativeWorkspaceFolderPaths.some((workspacePath) => i.startsWith(workspacePath))) {
1447
1492
  continue;
1448
1493
  }
1449
- const pkgName = chunk7PMC7SBC_cjs.getPackageName(i);
1450
- if (pkgName && !allUsedExternals.has(pkgName)) {
1451
- const versionInfo = depsVersionInfo.get(i) || depsVersionInfo.get(pkgName) || {};
1452
- allUsedExternals.set(pkgName, versionInfo);
1494
+ const pkgName = chunk7YI2AEFO_cjs.getPackageName(i);
1495
+ if (pkgName) {
1496
+ const versionInfo = depsVersionInfo.get(i) || depsVersionInfo.get(pkgName);
1497
+ const dependencyInfo = await resolveDependencyInfo(
1498
+ i,
1499
+ versionInfo,
1500
+ importerParentPaths(importerId, [
1501
+ projectRoot,
1502
+ ...Array.from(workspaceMap.values()).map((pkgInfo) => pkgInfo.location)
1503
+ ])
1504
+ );
1505
+ allUsedExternals.set(pkgName, preferDependencyInfo(allUsedExternals.get(pkgName), dependencyInfo));
1453
1506
  }
1454
1507
  }
1455
1508
  }
@@ -1467,22 +1520,32 @@ async function analyzeBundle(entries, mastraEntry, {
1467
1520
  );
1468
1521
  const mergedExternalDeps = new Map(result.externalDependencies);
1469
1522
  for (const [dep, info] of allUsedExternals) {
1470
- if (chunk7PMC7SBC_cjs.isExternalProtocolImport(dep)) {
1523
+ if (chunk7YI2AEFO_cjs.isExternalProtocolImport(dep)) {
1471
1524
  continue;
1472
1525
  }
1473
- const existing = mergedExternalDeps.get(dep);
1474
- if (!existing || !existing.version && info.version) {
1475
- mergedExternalDeps.set(dep, info);
1526
+ mergedExternalDeps.set(dep, preferDependencyInfo(mergedExternalDeps.get(dep), info));
1527
+ }
1528
+ const externalMetadataParentPaths = [
1529
+ projectRoot,
1530
+ ...Array.from(workspaceMap.values()).map((pkgInfo) => pkgInfo.location),
1531
+ // Last resort: resolve from the deployer's own installed location. Some externals are
1532
+ // discovered inside externalized packages (e.g. optional dynamic imports like
1533
+ // `import('typescript')` in @mastra/core) without being installed in the user's project.
1534
+ undefined
1535
+ ];
1536
+ for (const [dep, info] of mergedExternalDeps) {
1537
+ if (!info.version && !info.packageSpec) {
1538
+ mergedExternalDeps.set(dep, await resolveDependencyInfo(dep, info, externalMetadataParentPaths));
1476
1539
  }
1477
1540
  }
1478
1541
  for (const transport of detectedPinoTransports) {
1479
1542
  if (!mergedExternalDeps.has(transport)) {
1480
- mergedExternalDeps.set(transport, {});
1543
+ mergedExternalDeps.set(transport, await resolveDependencyInfo(transport, void 0, externalMetadataParentPaths));
1481
1544
  }
1482
1545
  }
1483
1546
  for (const pkg2 of userDynamicPackages) {
1484
1547
  if (!mergedExternalDeps.has(pkg2)) {
1485
- mergedExternalDeps.set(pkg2, {});
1548
+ mergedExternalDeps.set(pkg2, await resolveDependencyInfo(pkg2, void 0, externalMetadataParentPaths));
1486
1549
  }
1487
1550
  }
1488
1551
  return {
@@ -1494,5 +1557,5 @@ async function analyzeBundle(entries, mastraEntry, {
1494
1557
  exports.aliasHono = aliasHono;
1495
1558
  exports.analyzeBundle = analyzeBundle;
1496
1559
  exports.getWorkspaceInformation = getWorkspaceInformation;
1497
- //# sourceMappingURL=chunk-47KJ3RKB.cjs.map
1498
- //# sourceMappingURL=chunk-47KJ3RKB.cjs.map
1560
+ //# sourceMappingURL=chunk-IMPHNLMW.cjs.map
1561
+ //# sourceMappingURL=chunk-IMPHNLMW.cjs.map