@mastra/deployer 0.24.9-alpha.1 → 0.24.10-alpha.0

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 (72) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/build/analyze/bundleExternals.d.ts +4 -5
  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 +2 -2
  6. package/dist/build/analyze.d.ts.map +1 -1
  7. package/dist/build/analyze.js +1 -1
  8. package/dist/build/bundler.cjs +3 -3
  9. package/dist/build/bundler.d.ts +2 -1
  10. package/dist/build/bundler.d.ts.map +1 -1
  11. package/dist/build/bundler.js +1 -1
  12. package/dist/build/index.cjs +12 -12
  13. package/dist/build/index.js +4 -4
  14. package/dist/build/plugins/node-modules-extension-resolver.d.ts +7 -0
  15. package/dist/build/plugins/node-modules-extension-resolver.d.ts.map +1 -1
  16. package/dist/build/utils.d.ts +6 -0
  17. package/dist/build/utils.d.ts.map +1 -1
  18. package/dist/build/watcher.d.ts.map +1 -1
  19. package/dist/bundler/index.cjs +2 -2
  20. package/dist/bundler/index.d.ts +5 -5
  21. package/dist/bundler/index.d.ts.map +1 -1
  22. package/dist/bundler/index.js +1 -1
  23. package/dist/{chunk-3GJSIS6L.cjs → chunk-24QKSIF4.cjs} +8 -3
  24. package/dist/chunk-24QKSIF4.cjs.map +1 -0
  25. package/dist/{chunk-BYJ5P75V.cjs → chunk-37AZSKLD.cjs} +31 -27
  26. package/dist/chunk-37AZSKLD.cjs.map +1 -0
  27. package/dist/{chunk-NEGQTTJS.js → chunk-AI2IXYON.js} +8 -4
  28. package/dist/chunk-AI2IXYON.js.map +1 -0
  29. package/dist/{chunk-IN6YCLG2.js → chunk-EL7U6UCA.js} +3 -3
  30. package/dist/{chunk-IN6YCLG2.js.map → chunk-EL7U6UCA.js.map} +1 -1
  31. package/dist/{chunk-4BZNZFZN.cjs → chunk-I343PEBO.cjs} +5 -5
  32. package/dist/{chunk-4BZNZFZN.cjs.map → chunk-I343PEBO.cjs.map} +1 -1
  33. package/dist/chunk-JESLK2Y3.js +249 -0
  34. package/dist/chunk-JESLK2Y3.js.map +1 -0
  35. package/dist/{chunk-IMZH6M7G.cjs → chunk-JZYQOKB4.cjs} +109 -57
  36. package/dist/chunk-JZYQOKB4.cjs.map +1 -0
  37. package/dist/chunk-MTB7RTAH.cjs +123 -0
  38. package/dist/chunk-MTB7RTAH.cjs.map +1 -0
  39. package/dist/{chunk-FIVDPLGU.js → chunk-NWWMYMSL.js} +20 -16
  40. package/dist/chunk-NWWMYMSL.js.map +1 -0
  41. package/dist/{chunk-E5MVIUAD.js → chunk-PEMRXQDH.js} +6 -76
  42. package/dist/chunk-PEMRXQDH.js.map +1 -0
  43. package/dist/{chunk-C3343ELD.js → chunk-Z7PGONL4.js} +89 -37
  44. package/dist/chunk-Z7PGONL4.js.map +1 -0
  45. package/dist/chunk-ZYA3ZCCR.cjs +261 -0
  46. package/dist/chunk-ZYA3ZCCR.cjs.map +1 -0
  47. package/dist/index.cjs +5 -5
  48. package/dist/index.js +2 -2
  49. package/dist/server/handlers/prompt.d.ts.map +1 -1
  50. package/dist/server/handlers/routes/agents/handlers.d.ts +6 -0
  51. package/dist/server/handlers/routes/agents/handlers.d.ts.map +1 -1
  52. package/dist/server/handlers/routes/scores/handlers.d.ts +30 -30
  53. package/dist/server/index.cjs +3 -2
  54. package/dist/server/index.cjs.map +1 -1
  55. package/dist/server/index.js +3 -2
  56. package/dist/server/index.js.map +1 -1
  57. package/dist/validator/custom-resolver.cjs +2 -2
  58. package/dist/validator/custom-resolver.js +1 -1
  59. package/package.json +5 -5
  60. package/dist/chunk-3GJSIS6L.cjs.map +0 -1
  61. package/dist/chunk-62BMSTRF.cjs +0 -196
  62. package/dist/chunk-62BMSTRF.cjs.map +0 -1
  63. package/dist/chunk-BYJ5P75V.cjs.map +0 -1
  64. package/dist/chunk-C3343ELD.js.map +0 -1
  65. package/dist/chunk-E5MVIUAD.js.map +0 -1
  66. package/dist/chunk-FIVDPLGU.js.map +0 -1
  67. package/dist/chunk-IMZH6M7G.cjs.map +0 -1
  68. package/dist/chunk-NEGQTTJS.js.map +0 -1
  69. package/dist/chunk-QPQ6DGHM.js +0 -147
  70. package/dist/chunk-QPQ6DGHM.js.map +0 -1
  71. package/dist/chunk-UHRSJYRY.cjs +0 -157
  72. package/dist/chunk-UHRSJYRY.cjs.map +0 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk3GJSIS6L_cjs = require('./chunk-3GJSIS6L.cjs');
3
+ var chunk24QKSIF4_cjs = require('./chunk-24QKSIF4.cjs');
4
4
  var babel = require('@babel/core');
5
5
  var fs = require('fs');
6
6
  var promises = require('fs/promises');
@@ -129,7 +129,7 @@ globalThis.__dirname = dirname(__filename);
129
129
  "--input-type=module",
130
130
  "--enable-source-maps",
131
131
  "-e",
132
- `${prefixCode};import('file://${chunk3GJSIS6L_cjs.slash(file)}').catch(err => {
132
+ `${prefixCode};import('file://${chunk24QKSIF4_cjs.slash(file)}').catch(err => {
133
133
  ${errorHandler.toString()}
134
134
  errorHandler(err);
135
135
  })`.replaceAll(/\n/g, "")
@@ -578,7 +578,7 @@ async function getWorkspaceInformation({
578
578
  mastraEntryFile
579
579
  }) {
580
580
  const closestPkgJson = pkg__namespace.up({ cwd: path2.dirname(mastraEntryFile) });
581
- const location = closestPkgJson ? path2.dirname(chunk3GJSIS6L_cjs.slash(closestPkgJson)) : chunk3GJSIS6L_cjs.slash(process.cwd());
581
+ const location = closestPkgJson ? path2.dirname(chunk24QKSIF4_cjs.slash(closestPkgJson)) : chunk24QKSIF4_cjs.slash(process.cwd());
582
582
  const workspaces = await findWorkspaces.findWorkspaces(dir, { cache: workspacesCache });
583
583
  const _workspaceMap = new Map(
584
584
  workspaces?.map((workspace) => [
@@ -694,7 +694,7 @@ var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
694
694
 
695
695
  // src/build/analyze/analyzeEntry.ts
696
696
  function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
697
- const normalizedMastraEntry = chunk3GJSIS6L_cjs.slash(mastraEntry);
697
+ const normalizedMastraEntry = chunk24QKSIF4_cjs.slash(mastraEntry);
698
698
  let virtualPlugin = null;
699
699
  if (isVirtualFile) {
700
700
  virtualPlugin = virtual__default.default({
@@ -713,7 +713,7 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
713
713
  name: "custom-alias-resolver",
714
714
  resolveId(id) {
715
715
  if (id === "#server") {
716
- return chunk3GJSIS6L_cjs.slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
716
+ return chunk24QKSIF4_cjs.slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
717
717
  }
718
718
  if (id === "#mastra") {
719
719
  return normalizedMastraEntry;
@@ -749,20 +749,20 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
749
749
  }
750
750
  let entryRootPath = projectRoot;
751
751
  if (!output.facadeModuleId.startsWith("\0virtual:")) {
752
- entryRootPath = await chunk3GJSIS6L_cjs.getPackageRootPath(output.facadeModuleId) || projectRoot;
752
+ entryRootPath = await chunk24QKSIF4_cjs.getPackageRootPath(output.facadeModuleId) || projectRoot;
753
753
  }
754
754
  for (const [dependency, bindings] of Object.entries(output.importedBindings)) {
755
755
  if (isNodeBuiltin(dependency) || dependency.startsWith("#")) {
756
756
  continue;
757
757
  }
758
- const pkgName = chunk3GJSIS6L_cjs.getPackageName(dependency);
758
+ const pkgName = chunk24QKSIF4_cjs.getPackageName(dependency);
759
759
  let rootPath = null;
760
760
  let isWorkspace = false;
761
761
  if (pkgName) {
762
- rootPath = await chunk3GJSIS6L_cjs.getPackageRootPath(dependency, entryRootPath);
762
+ rootPath = await chunk24QKSIF4_cjs.getPackageRootPath(dependency, entryRootPath);
763
763
  isWorkspace = workspaceMap.has(pkgName);
764
764
  }
765
- const normalizedRootPath = rootPath ? chunk3GJSIS6L_cjs.slash(rootPath) : null;
765
+ const normalizedRootPath = rootPath ? chunk24QKSIF4_cjs.slash(rootPath) : null;
766
766
  depsToOptimize.set(dependency, {
767
767
  exports: bindings,
768
768
  rootPath: normalizedRootPath,
@@ -913,7 +913,7 @@ function subpathExternalsResolver(externals) {
913
913
  if (id.startsWith(".") || id.startsWith("/")) {
914
914
  return null;
915
915
  }
916
- const isPartOfExternals = externals.some((external) => chunk3GJSIS6L_cjs.isDependencyPartOfPackage(id, external));
916
+ const isPartOfExternals = externals.some((external) => chunk24QKSIF4_cjs.isDependencyPartOfPackage(id, external));
917
917
  if (isPartOfExternals) {
918
918
  return {
919
919
  id,
@@ -979,7 +979,7 @@ function moduleResolveMap(externals, projectRoot) {
979
979
  }
980
980
  for (const importedId of info.importedIds) {
981
981
  for (const external of externals) {
982
- if (chunk3GJSIS6L_cjs.isDependencyPartOfPackage(importedId, external)) {
982
+ if (chunk24QKSIF4_cjs.isDependencyPartOfPackage(importedId, external)) {
983
983
  importMap.set(external, info.id);
984
984
  }
985
985
  }
@@ -991,9 +991,9 @@ function moduleResolveMap(externals, projectRoot) {
991
991
  if (chunk.type === "chunk") {
992
992
  for (const [external, resolvedFrom] of importMap) {
993
993
  if (chunk.moduleIds.includes(resolvedFrom)) {
994
- const fullPath = url.pathToFileURL(chunk3GJSIS6L_cjs.slash(path2.join(projectRoot, fileName))).toString();
994
+ const fullPath = url.pathToFileURL(chunk24QKSIF4_cjs.slash(path2.join(projectRoot, fileName))).toString();
995
995
  const innerMap = resolveMap.get(fullPath) || /* @__PURE__ */ new Map();
996
- innerMap.set(external, url.pathToFileURL(chunk3GJSIS6L_cjs.slash(resolvedFrom)).toString());
996
+ innerMap.set(external, url.pathToFileURL(chunk24QKSIF4_cjs.slash(resolvedFrom)).toString());
997
997
  resolveMap.set(fullPath, innerMap);
998
998
  }
999
999
  }
@@ -1013,7 +1013,7 @@ function moduleResolveMap(externals, projectRoot) {
1013
1013
 
1014
1014
  // src/build/analyze/bundleExternals.ts
1015
1015
  function prepareEntryFileName(name, rootDir) {
1016
- return chunk3GJSIS6L_cjs.rollupSafeName(name, rootDir);
1016
+ return chunk24QKSIF4_cjs.rollupSafeName(name, rootDir);
1017
1017
  }
1018
1018
  function createVirtualDependencies(depsToOptimize, {
1019
1019
  projectRoot,
@@ -1021,7 +1021,7 @@ function createVirtualDependencies(depsToOptimize, {
1021
1021
  outputDir,
1022
1022
  bundlerOptions
1023
1023
  }) {
1024
- const { isDev = false } = bundlerOptions || {};
1024
+ const { isDev = false, externalsPreset = false } = bundlerOptions || {};
1025
1025
  const fileNameToDependencyMap = /* @__PURE__ */ new Map();
1026
1026
  const optimizedDependencyEntries = /* @__PURE__ */ new Map();
1027
1027
  const rootDir = workspaceRoot || projectRoot;
@@ -1053,7 +1053,7 @@ function createVirtualDependencies(depsToOptimize, {
1053
1053
  virtual: virtualFile.join("\n")
1054
1054
  });
1055
1055
  }
1056
- if (isDev) {
1056
+ if (isDev || externalsPreset) {
1057
1057
  for (const [dep, { isWorkspace, rootPath }] of depsToOptimize.entries()) {
1058
1058
  if (!isWorkspace || !rootPath || !workspaceRoot) {
1059
1059
  continue;
@@ -1063,7 +1063,7 @@ function createVirtualDependencies(depsToOptimize, {
1063
1063
  continue;
1064
1064
  }
1065
1065
  const fileName = posix.basename(currentDepPath.name);
1066
- const entryName = prepareEntryFileName(chunk3GJSIS6L_cjs.getCompiledDepCachePath(rootPath, fileName), rootDir);
1066
+ const entryName = prepareEntryFileName(chunk24QKSIF4_cjs.getCompiledDepCachePath(rootPath, fileName), rootDir);
1067
1067
  fileNameToDependencyMap.set(entryName, dep);
1068
1068
  optimizedDependencyEntries.set(dep, {
1069
1069
  ...currentDepPath,
@@ -1082,9 +1082,9 @@ async function getInputPlugins2(virtualDependencies, {
1082
1082
  }) {
1083
1083
  const transpilePackagesMap = /* @__PURE__ */ new Map();
1084
1084
  for (const pkg2 of transpilePackages) {
1085
- const dir = await chunk3GJSIS6L_cjs.getPackageRootPath(pkg2);
1085
+ const dir = await chunk24QKSIF4_cjs.getPackageRootPath(pkg2);
1086
1086
  if (dir) {
1087
- transpilePackagesMap.set(pkg2, chunk3GJSIS6L_cjs.slash(dir));
1087
+ transpilePackagesMap.set(pkg2, chunk24QKSIF4_cjs.slash(dir));
1088
1088
  } else {
1089
1089
  transpilePackagesMap.set(pkg2, workspaceMap.get(pkg2)?.location ?? pkg2);
1090
1090
  }
@@ -1110,7 +1110,7 @@ async function getInputPlugins2(virtualDependencies, {
1110
1110
  }
1111
1111
  })
1112
1112
  }) : null,
1113
- bundlerOptions.isDev ? {
1113
+ bundlerOptions.noBundling ? {
1114
1114
  name: "alias-optimized-deps",
1115
1115
  async resolveId(id, importer, options) {
1116
1116
  if (!virtualDependencies.has(id)) {
@@ -1140,11 +1140,11 @@ async function getInputPlugins2(virtualDependencies, {
1140
1140
  transformMixedEsModules: true,
1141
1141
  ignoreTryCatch: false
1142
1142
  }),
1143
- bundlerOptions.isDev ? null : nodeResolve__default.default({
1143
+ bundlerOptions.noBundling ? null : nodeResolve__default.default({
1144
1144
  preferBuiltins: true,
1145
1145
  exportConditions: ["node"]
1146
1146
  }),
1147
- bundlerOptions.isDev ? esmShim() : null,
1147
+ bundlerOptions.noBundling ? esmShim() : null,
1148
1148
  // hono is imported from deployer, so we need to resolve from here instead of the project root
1149
1149
  aliasHono(),
1150
1150
  json__default.default(),
@@ -1197,6 +1197,16 @@ async function buildExternalDependencies(virtualDependencies, {
1197
1197
  if (virtualDependencies.size === 0) {
1198
1198
  return [];
1199
1199
  }
1200
+ const noBundling = bundlerOptions.isDev || bundlerOptions.externalsPreset;
1201
+ const plugins = await getInputPlugins2(virtualDependencies, {
1202
+ transpilePackages: packagesToTranspile,
1203
+ workspaceMap,
1204
+ bundlerOptions: {
1205
+ noBundling
1206
+ },
1207
+ rootDir,
1208
+ externals
1209
+ });
1200
1210
  const bundler = await rollup.rollup({
1201
1211
  logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
1202
1212
  input: Array.from(virtualDependencies.entries()).reduce(
@@ -1207,14 +1217,8 @@ async function buildExternalDependencies(virtualDependencies, {
1207
1217
  {}
1208
1218
  ),
1209
1219
  external: externals,
1210
- treeshake: bundlerOptions.isDev ? false : "safest",
1211
- plugins: getInputPlugins2(virtualDependencies, {
1212
- transpilePackages: packagesToTranspile,
1213
- workspaceMap,
1214
- bundlerOptions,
1215
- rootDir,
1216
- externals
1217
- })
1220
+ treeshake: noBundling ? false : "safest",
1221
+ plugins
1218
1222
  });
1219
1223
  const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
1220
1224
  const { output } = await bundler.write({
@@ -1228,12 +1232,12 @@ async function buildExternalDependencies(virtualDependencies, {
1228
1232
  * So we want to write them to the `.mastra/output` folder as well.
1229
1233
  */
1230
1234
  chunkFileNames: (chunkInfo) => {
1231
- if (bundlerOptions.isDev) {
1235
+ if (noBundling) {
1232
1236
  const importedFromPackages = /* @__PURE__ */ new Set();
1233
1237
  for (const moduleId of chunkInfo.moduleIds) {
1234
- const normalized = chunk3GJSIS6L_cjs.slash(moduleId);
1238
+ const normalized = chunk24QKSIF4_cjs.slash(moduleId);
1235
1239
  for (const [pkgName, pkgInfo] of workspaceMap.entries()) {
1236
- const location = chunk3GJSIS6L_cjs.slash(pkgInfo.location);
1240
+ const location = chunk24QKSIF4_cjs.slash(pkgInfo.location);
1237
1241
  if (normalized.startsWith(location)) {
1238
1242
  importedFromPackages.add(pkgName);
1239
1243
  break;
@@ -1255,7 +1259,7 @@ async function buildExternalDependencies(virtualDependencies, {
1255
1259
  if (importedFromPackages.size === 1) {
1256
1260
  const [pkgName] = importedFromPackages;
1257
1261
  const workspaceLocation = workspaceMap.get(pkgName).location;
1258
- return prepareEntryFileName(chunk3GJSIS6L_cjs.getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
1262
+ return prepareEntryFileName(chunk24QKSIF4_cjs.getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
1259
1263
  }
1260
1264
  }
1261
1265
  return `${outputDirRelative}/[name].mjs`;
@@ -1269,7 +1273,7 @@ async function buildExternalDependencies(virtualDependencies, {
1269
1273
  function findExternalImporter(module, external, allOutputs) {
1270
1274
  const capturedFiles = /* @__PURE__ */ new Set();
1271
1275
  for (const id of module.imports) {
1272
- if (chunk3GJSIS6L_cjs.isDependencyPartOfPackage(id, external)) {
1276
+ if (chunk24QKSIF4_cjs.isDependencyPartOfPackage(id, external)) {
1273
1277
  return module;
1274
1278
  } else {
1275
1279
  if (id.endsWith(".mjs")) {
@@ -1290,19 +1294,31 @@ function findExternalImporter(module, external, allOutputs) {
1290
1294
  }
1291
1295
  async function bundleExternals(depsToOptimize, outputDir, options) {
1292
1296
  const { workspaceRoot = null, workspaceMap = /* @__PURE__ */ new Map(), projectRoot = outputDir, bundlerOptions = {} } = options;
1293
- const {
1294
- externals: customExternals = [],
1295
- transpilePackages = [],
1296
- isDev = false} = bundlerOptions || {};
1297
- const allExternals = [...GLOBAL_EXTERNALS, ...DEPRECATED_EXTERNALS, ...customExternals];
1297
+ const { externals: customExternals = [], transpilePackages = [], isDev = false } = bundlerOptions || {};
1298
+ let externalsPreset = false;
1299
+ if (customExternals === true) {
1300
+ externalsPreset = true;
1301
+ }
1302
+ const externalsList = Array.isArray(customExternals) ? customExternals : [];
1303
+ const allExternals = [...GLOBAL_EXTERNALS, ...DEPRECATED_EXTERNALS, ...externalsList];
1298
1304
  const workspacePackagesNames = Array.from(workspaceMap.keys());
1299
1305
  const packagesToTranspile = /* @__PURE__ */ new Set([...transpilePackages, ...workspacePackagesNames]);
1306
+ const extractedExternals = /* @__PURE__ */ new Map();
1307
+ if (externalsPreset) {
1308
+ for (const [dep, metadata] of depsToOptimize.entries()) {
1309
+ if (!metadata.isWorkspace) {
1310
+ extractedExternals.set(dep, metadata.rootPath ?? dep);
1311
+ depsToOptimize.delete(dep);
1312
+ }
1313
+ }
1314
+ }
1300
1315
  const { optimizedDependencyEntries, fileNameToDependencyMap } = createVirtualDependencies(depsToOptimize, {
1301
1316
  workspaceRoot,
1302
1317
  outputDir,
1303
1318
  projectRoot,
1304
1319
  bundlerOptions: {
1305
- isDev
1320
+ isDev,
1321
+ externalsPreset
1306
1322
  }
1307
1323
  });
1308
1324
  const output = await buildExternalDependencies(optimizedDependencyEntries, {
@@ -1312,7 +1328,8 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
1312
1328
  rootDir: workspaceRoot || projectRoot,
1313
1329
  outputDir,
1314
1330
  bundlerOptions: {
1315
- isDev
1331
+ isDev,
1332
+ externalsPreset
1316
1333
  }
1317
1334
  });
1318
1335
  const moduleResolveMap2 = /* @__PURE__ */ new Map();
@@ -1347,6 +1364,14 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
1347
1364
  }
1348
1365
  usedExternals[fullPath] = innerObj;
1349
1366
  }
1367
+ if (extractedExternals.size > 0) {
1368
+ const syntheticPath = path2__namespace.join(workspaceRoot || projectRoot, "__externals__");
1369
+ const externalsObj = /* @__PURE__ */ Object.create(null);
1370
+ for (const [dep, rootPath] of extractedExternals) {
1371
+ externalsObj[dep] = rootPath;
1372
+ }
1373
+ usedExternals[syntheticPath] = externalsObj;
1374
+ }
1350
1375
  return { output, fileNameToDependencyMap, usedExternals };
1351
1376
  }
1352
1377
 
@@ -1622,7 +1647,7 @@ async function analyzeBundle(entries, mastraEntry, {
1622
1647
  outputDir,
1623
1648
  projectRoot,
1624
1649
  isDev = false,
1625
- bundlerOptions: _bundlerOptions
1650
+ bundlerOptions: internalBundlerOptions
1626
1651
  }, logger) {
1627
1652
  const mastraConfig = await promises.readFile(mastraEntry, "utf-8");
1628
1653
  const mastraConfigResult = {
@@ -1641,28 +1666,33 @@ export const mastra = new Mastra({
1641
1666
 
1642
1667
  If you think your configuration is valid, please open an issue.`);
1643
1668
  }
1644
- const { enableEsmShim = true } = _bundlerOptions || {};
1645
- const bundlerOptions = await getBundlerOptions(mastraEntry, outputDir);
1669
+ const { externals: _bundlerExternals = [] } = internalBundlerOptions || {};
1670
+ const userBundlerOptions = await getBundlerOptions(mastraEntry, outputDir);
1646
1671
  const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
1672
+ let externalsPreset = false;
1673
+ if (userBundlerOptions?.externals === true) {
1674
+ externalsPreset = true;
1675
+ }
1647
1676
  let index = 0;
1648
1677
  const depsToOptimize = /* @__PURE__ */ new Map();
1649
- const { externals: customExternals = [] } = bundlerOptions || {};
1650
- const allExternals = [...GLOBAL_EXTERNALS, ...customExternals];
1678
+ const bundlerExternals = Array.isArray(_bundlerExternals) ? _bundlerExternals : [];
1679
+ const userExternals = Array.isArray(userBundlerOptions?.externals) ? userBundlerOptions?.externals : [];
1680
+ const allExternals = [...GLOBAL_EXTERNALS, ...bundlerExternals, ...userExternals];
1651
1681
  logger.info("Analyzing dependencies...");
1652
1682
  const allUsedExternals = /* @__PURE__ */ new Set();
1653
1683
  for (const entry of entries) {
1654
1684
  const isVirtualFile = entry.includes("\n") || !fs.existsSync(entry);
1655
1685
  const analyzeResult = await analyzeEntry({ entry, isVirtualFile }, mastraEntry, {
1656
1686
  logger,
1657
- sourcemapEnabled: bundlerOptions?.sourcemap ?? false,
1687
+ sourcemapEnabled: userBundlerOptions?.sourcemap ?? false,
1658
1688
  workspaceMap,
1659
1689
  projectRoot,
1660
- shouldCheckTransitiveDependencies: isDev
1690
+ shouldCheckTransitiveDependencies: isDev || externalsPreset
1661
1691
  });
1662
1692
  await promises.writeFile(path2.join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
1663
1693
  for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
1664
- const isPartOfExternals = allExternals.some((external) => chunk3GJSIS6L_cjs.isDependencyPartOfPackage(dep, external));
1665
- if (isPartOfExternals) {
1694
+ const isPartOfExternals = allExternals.some((external) => chunk24QKSIF4_cjs.isDependencyPartOfPackage(dep, external));
1695
+ if (isPartOfExternals || externalsPreset && !metadata.isWorkspace) {
1666
1696
  allUsedExternals.add(dep);
1667
1697
  continue;
1668
1698
  }
@@ -1677,7 +1707,7 @@ If you think your configuration is valid, please open an issue.`);
1677
1707
  }
1678
1708
  }
1679
1709
  }
1680
- if (isDev) {
1710
+ if (isDev || externalsPreset) {
1681
1711
  for (const [dep, metadata] of depsToOptimize.entries()) {
1682
1712
  if (!metadata.isWorkspace) {
1683
1713
  depsToOptimize.delete(dep);
@@ -1689,15 +1719,37 @@ If you think your configuration is valid, please open an issue.`);
1689
1719
  logger.debug(`${sortedDeps.map((key) => `- ${key}`).join("\n")}`);
1690
1720
  const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
1691
1721
  bundlerOptions: {
1692
- ...bundlerOptions,
1693
- externals: allExternals,
1694
- enableEsmShim,
1722
+ ...userBundlerOptions,
1723
+ externals: userBundlerOptions?.externals ?? allExternals,
1695
1724
  isDev
1696
1725
  },
1697
1726
  projectRoot,
1698
1727
  workspaceRoot,
1699
1728
  workspaceMap
1700
1729
  });
1730
+ const relativeWorkspaceFolderPaths = Array.from(workspaceMap.values()).map(
1731
+ (pkgInfo) => path2.relative(workspaceRoot || projectRoot, pkgInfo.location)
1732
+ );
1733
+ for (const o of output) {
1734
+ if (o.type === "asset") {
1735
+ continue;
1736
+ }
1737
+ for (const i of o.imports) {
1738
+ if (chunk24QKSIF4_cjs.isBuiltinModule(i)) {
1739
+ continue;
1740
+ }
1741
+ if (i.startsWith(".") || i.startsWith("/")) {
1742
+ continue;
1743
+ }
1744
+ if (relativeWorkspaceFolderPaths.some((workspacePath) => i.startsWith(workspacePath))) {
1745
+ continue;
1746
+ }
1747
+ const pkgName = chunk24QKSIF4_cjs.getPackageName(i);
1748
+ if (pkgName) {
1749
+ allUsedExternals.add(pkgName);
1750
+ }
1751
+ }
1752
+ }
1701
1753
  const result = await validateOutput(
1702
1754
  {
1703
1755
  output,
@@ -1726,5 +1778,5 @@ exports.removeAllOptionsFromMastraExcept = removeAllOptionsFromMastraExcept;
1726
1778
  exports.removeDeployer = removeDeployer2;
1727
1779
  exports.subpathExternalsResolver = subpathExternalsResolver;
1728
1780
  exports.tsConfigPaths = tsConfigPaths;
1729
- //# sourceMappingURL=chunk-IMZH6M7G.cjs.map
1730
- //# sourceMappingURL=chunk-IMZH6M7G.cjs.map
1781
+ //# sourceMappingURL=chunk-JZYQOKB4.cjs.map
1782
+ //# sourceMappingURL=chunk-JZYQOKB4.cjs.map