@mastra/deployer 1.0.0-beta.10 → 1.0.0-beta.13
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.
- package/CHANGELOG.md +36 -0
- package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
- package/dist/build/analyze/bundleExternals.d.ts +4 -5
- package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
- package/dist/build/analyze.cjs +2 -2
- package/dist/build/analyze.d.ts +2 -2
- package/dist/build/analyze.d.ts.map +1 -1
- package/dist/build/analyze.js +1 -1
- package/dist/build/bundler.cjs +3 -3
- package/dist/build/bundler.d.ts +2 -1
- package/dist/build/bundler.d.ts.map +1 -1
- package/dist/build/bundler.js +1 -1
- package/dist/build/index.cjs +15 -10
- package/dist/build/index.d.ts +1 -0
- package/dist/build/index.d.ts.map +1 -1
- package/dist/build/index.js +4 -3
- package/dist/build/package-info.d.ts +9 -0
- package/dist/build/package-info.d.ts.map +1 -0
- package/dist/build/plugins/node-modules-extension-resolver.d.ts +7 -0
- package/dist/build/plugins/node-modules-extension-resolver.d.ts.map +1 -1
- package/dist/build/utils.d.ts +18 -4
- package/dist/build/utils.d.ts.map +1 -1
- package/dist/build/watcher.d.ts.map +1 -1
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.d.ts +5 -5
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/index.js +1 -1
- package/dist/chunk-24GY667C.cjs +123 -0
- package/dist/chunk-24GY667C.cjs.map +1 -0
- package/dist/{chunk-SS22TD6R.cjs → chunk-3GOE3SL2.cjs} +27 -23
- package/dist/chunk-3GOE3SL2.cjs.map +1 -0
- package/dist/{chunk-5CWPEG6R.js → chunk-HHA2Y3AS.js} +23 -24
- package/dist/chunk-HHA2Y3AS.js.map +1 -0
- package/dist/{chunk-MUWNMVNL.cjs → chunk-KCGBR2X6.cjs} +130 -58
- package/dist/chunk-KCGBR2X6.cjs.map +1 -0
- package/dist/chunk-LENVOSFH.cjs +261 -0
- package/dist/chunk-LENVOSFH.cjs.map +1 -0
- package/dist/chunk-R6O3XWXM.js +249 -0
- package/dist/chunk-R6O3XWXM.js.map +1 -0
- package/dist/{chunk-TK2CCU7I.js → chunk-RGUNHE4Y.js} +111 -40
- package/dist/chunk-RGUNHE4Y.js.map +1 -0
- package/dist/{chunk-X5QU7B2W.js → chunk-SRPOHKWH.js} +6 -76
- package/dist/chunk-SRPOHKWH.js.map +1 -0
- package/dist/{chunk-2OTEFUER.cjs → chunk-VA2CSOKJ.cjs} +24 -24
- package/dist/chunk-VA2CSOKJ.cjs.map +1 -0
- package/dist/{chunk-RBPCXFN7.js → chunk-XTXGU6QF.js} +19 -15
- package/dist/chunk-XTXGU6QF.js.map +1 -0
- package/dist/index.cjs +5 -5
- package/dist/index.js +2 -2
- package/dist/server/index.cjs +40 -23
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +40 -23
- package/dist/server/index.js.map +1 -1
- package/dist/validator/custom-resolver.cjs +2 -2
- package/dist/validator/custom-resolver.js +1 -1
- package/package.json +5 -6
- package/dist/chunk-2OTEFUER.cjs.map +0 -1
- package/dist/chunk-5CWPEG6R.js.map +0 -1
- package/dist/chunk-BFQ2S5UD.cjs +0 -157
- package/dist/chunk-BFQ2S5UD.cjs.map +0 -1
- package/dist/chunk-MUWNMVNL.cjs.map +0 -1
- package/dist/chunk-RBPCXFN7.js.map +0 -1
- package/dist/chunk-SS22TD6R.cjs.map +0 -1
- package/dist/chunk-TK2CCU7I.js.map +0 -1
- package/dist/chunk-UQZGTSBF.js +0 -147
- package/dist/chunk-UQZGTSBF.js.map +0 -1
- package/dist/chunk-X4TNUYQL.cjs +0 -196
- package/dist/chunk-X4TNUYQL.cjs.map +0 -1
- package/dist/chunk-X5QU7B2W.js.map +0 -1
- package/dist/server/handlers/prompt.d.ts +0 -3
- package/dist/server/handlers/prompt.d.ts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkVA2CSOKJ_cjs = require('./chunk-VA2CSOKJ.cjs');
|
|
4
4
|
var babel = require('@babel/core');
|
|
5
5
|
var fs = require('fs');
|
|
6
6
|
var promises = require('fs/promises');
|
|
@@ -20,11 +20,11 @@ var findWorkspaces = require('find-workspaces');
|
|
|
20
20
|
var logger = require('@mastra/core/logger');
|
|
21
21
|
var virtual = require('@rollup/plugin-virtual');
|
|
22
22
|
var module$1 = require('module');
|
|
23
|
+
var localPkg = require('local-pkg');
|
|
23
24
|
var nodeResolve = require('@rollup/plugin-node-resolve');
|
|
24
25
|
var originalEsmShim = require('@rollup/plugin-esm-shim');
|
|
25
26
|
var posix = require('path/posix');
|
|
26
27
|
var resolve = require('resolve.exports');
|
|
27
|
-
var localPkg = require('local-pkg');
|
|
28
28
|
var error = require('@mastra/core/error');
|
|
29
29
|
|
|
30
30
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -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://${
|
|
132
|
+
`${prefixCode};import('file://${chunkVA2CSOKJ_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(
|
|
581
|
+
const location = closestPkgJson ? path2.dirname(chunkVA2CSOKJ_cjs.slash(closestPkgJson)) : chunkVA2CSOKJ_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) => [
|
|
@@ -676,6 +676,25 @@ function removeDeployer2(mastraEntry, options) {
|
|
|
676
676
|
}
|
|
677
677
|
};
|
|
678
678
|
}
|
|
679
|
+
async function getPackageRootPath(packageName, parentPath) {
|
|
680
|
+
let rootPath;
|
|
681
|
+
try {
|
|
682
|
+
let options = void 0;
|
|
683
|
+
if (parentPath) {
|
|
684
|
+
if (!parentPath.startsWith("file://")) {
|
|
685
|
+
parentPath = url.pathToFileURL(parentPath).href;
|
|
686
|
+
}
|
|
687
|
+
options = {
|
|
688
|
+
paths: [parentPath]
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
const pkg2 = await localPkg.getPackageInfo(packageName, options);
|
|
692
|
+
rootPath = pkg2?.rootPath ?? null;
|
|
693
|
+
} catch (e) {
|
|
694
|
+
rootPath = null;
|
|
695
|
+
}
|
|
696
|
+
return rootPath;
|
|
697
|
+
}
|
|
679
698
|
|
|
680
699
|
// src/build/analyze/constants.ts
|
|
681
700
|
var DEPS_TO_IGNORE = ["#tools"];
|
|
@@ -694,7 +713,7 @@ var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
|
|
|
694
713
|
|
|
695
714
|
// src/build/analyze/analyzeEntry.ts
|
|
696
715
|
function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
|
|
697
|
-
const normalizedMastraEntry =
|
|
716
|
+
const normalizedMastraEntry = chunkVA2CSOKJ_cjs.slash(mastraEntry);
|
|
698
717
|
let virtualPlugin = null;
|
|
699
718
|
if (isVirtualFile) {
|
|
700
719
|
virtualPlugin = virtual__default.default({
|
|
@@ -713,7 +732,7 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
|
|
|
713
732
|
name: "custom-alias-resolver",
|
|
714
733
|
resolveId(id) {
|
|
715
734
|
if (id === "#server") {
|
|
716
|
-
return
|
|
735
|
+
return chunkVA2CSOKJ_cjs.slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
|
|
717
736
|
}
|
|
718
737
|
if (id === "#mastra") {
|
|
719
738
|
return normalizedMastraEntry;
|
|
@@ -749,20 +768,20 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
|
|
|
749
768
|
}
|
|
750
769
|
let entryRootPath = projectRoot;
|
|
751
770
|
if (!output.facadeModuleId.startsWith("\0virtual:")) {
|
|
752
|
-
entryRootPath = await
|
|
771
|
+
entryRootPath = await getPackageRootPath(output.facadeModuleId) || projectRoot;
|
|
753
772
|
}
|
|
754
773
|
for (const [dependency, bindings] of Object.entries(output.importedBindings)) {
|
|
755
774
|
if (isNodeBuiltin(dependency) || dependency.startsWith("#")) {
|
|
756
775
|
continue;
|
|
757
776
|
}
|
|
758
|
-
const pkgName =
|
|
777
|
+
const pkgName = chunkVA2CSOKJ_cjs.getPackageName(dependency);
|
|
759
778
|
let rootPath = null;
|
|
760
779
|
let isWorkspace = false;
|
|
761
780
|
if (pkgName) {
|
|
762
|
-
rootPath = await
|
|
781
|
+
rootPath = await getPackageRootPath(dependency, entryRootPath);
|
|
763
782
|
isWorkspace = workspaceMap.has(pkgName);
|
|
764
783
|
}
|
|
765
|
-
const normalizedRootPath = rootPath ?
|
|
784
|
+
const normalizedRootPath = rootPath ? chunkVA2CSOKJ_cjs.slash(rootPath) : null;
|
|
766
785
|
depsToOptimize.set(dependency, {
|
|
767
786
|
exports: bindings,
|
|
768
787
|
rootPath: normalizedRootPath,
|
|
@@ -959,7 +978,7 @@ function subpathExternalsResolver(externals) {
|
|
|
959
978
|
if (id.startsWith(".") || id.startsWith("/")) {
|
|
960
979
|
return null;
|
|
961
980
|
}
|
|
962
|
-
const isPartOfExternals = externals.some((external) =>
|
|
981
|
+
const isPartOfExternals = externals.some((external) => chunkVA2CSOKJ_cjs.isDependencyPartOfPackage(id, external));
|
|
963
982
|
if (isPartOfExternals) {
|
|
964
983
|
return {
|
|
965
984
|
id,
|
|
@@ -979,7 +998,7 @@ function moduleResolveMap(externals, projectRoot) {
|
|
|
979
998
|
}
|
|
980
999
|
for (const importedId of info.importedIds) {
|
|
981
1000
|
for (const external of externals) {
|
|
982
|
-
if (
|
|
1001
|
+
if (chunkVA2CSOKJ_cjs.isDependencyPartOfPackage(importedId, external)) {
|
|
983
1002
|
importMap.set(external, info.id);
|
|
984
1003
|
}
|
|
985
1004
|
}
|
|
@@ -991,9 +1010,9 @@ function moduleResolveMap(externals, projectRoot) {
|
|
|
991
1010
|
if (chunk.type === "chunk") {
|
|
992
1011
|
for (const [external, resolvedFrom] of importMap) {
|
|
993
1012
|
if (chunk.moduleIds.includes(resolvedFrom)) {
|
|
994
|
-
const fullPath = url.pathToFileURL(
|
|
1013
|
+
const fullPath = url.pathToFileURL(chunkVA2CSOKJ_cjs.slash(path2.join(projectRoot, fileName))).toString();
|
|
995
1014
|
const innerMap = resolveMap.get(fullPath) || /* @__PURE__ */ new Map();
|
|
996
|
-
innerMap.set(external, url.pathToFileURL(
|
|
1015
|
+
innerMap.set(external, url.pathToFileURL(chunkVA2CSOKJ_cjs.slash(resolvedFrom)).toString());
|
|
997
1016
|
resolveMap.set(fullPath, innerMap);
|
|
998
1017
|
}
|
|
999
1018
|
}
|
|
@@ -1013,7 +1032,7 @@ function moduleResolveMap(externals, projectRoot) {
|
|
|
1013
1032
|
|
|
1014
1033
|
// src/build/analyze/bundleExternals.ts
|
|
1015
1034
|
function prepareEntryFileName(name, rootDir) {
|
|
1016
|
-
return
|
|
1035
|
+
return chunkVA2CSOKJ_cjs.rollupSafeName(name, rootDir);
|
|
1017
1036
|
}
|
|
1018
1037
|
function createVirtualDependencies(depsToOptimize, {
|
|
1019
1038
|
projectRoot,
|
|
@@ -1021,7 +1040,7 @@ function createVirtualDependencies(depsToOptimize, {
|
|
|
1021
1040
|
outputDir,
|
|
1022
1041
|
bundlerOptions
|
|
1023
1042
|
}) {
|
|
1024
|
-
const { isDev = false } = bundlerOptions || {};
|
|
1043
|
+
const { isDev = false, externalsPreset = false } = bundlerOptions || {};
|
|
1025
1044
|
const fileNameToDependencyMap = /* @__PURE__ */ new Map();
|
|
1026
1045
|
const optimizedDependencyEntries = /* @__PURE__ */ new Map();
|
|
1027
1046
|
const rootDir = workspaceRoot || projectRoot;
|
|
@@ -1053,7 +1072,7 @@ function createVirtualDependencies(depsToOptimize, {
|
|
|
1053
1072
|
virtual: virtualFile.join("\n")
|
|
1054
1073
|
});
|
|
1055
1074
|
}
|
|
1056
|
-
if (isDev) {
|
|
1075
|
+
if (isDev || externalsPreset) {
|
|
1057
1076
|
for (const [dep, { isWorkspace, rootPath }] of depsToOptimize.entries()) {
|
|
1058
1077
|
if (!isWorkspace || !rootPath || !workspaceRoot) {
|
|
1059
1078
|
continue;
|
|
@@ -1063,7 +1082,7 @@ function createVirtualDependencies(depsToOptimize, {
|
|
|
1063
1082
|
continue;
|
|
1064
1083
|
}
|
|
1065
1084
|
const fileName = posix.basename(currentDepPath.name);
|
|
1066
|
-
const entryName = prepareEntryFileName(
|
|
1085
|
+
const entryName = prepareEntryFileName(chunkVA2CSOKJ_cjs.getCompiledDepCachePath(rootPath, fileName), rootDir);
|
|
1067
1086
|
fileNameToDependencyMap.set(entryName, dep);
|
|
1068
1087
|
optimizedDependencyEntries.set(dep, {
|
|
1069
1088
|
...currentDepPath,
|
|
@@ -1082,9 +1101,9 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
1082
1101
|
}) {
|
|
1083
1102
|
const transpilePackagesMap = /* @__PURE__ */ new Map();
|
|
1084
1103
|
for (const pkg2 of transpilePackages) {
|
|
1085
|
-
const dir = await
|
|
1104
|
+
const dir = await getPackageRootPath(pkg2);
|
|
1086
1105
|
if (dir) {
|
|
1087
|
-
transpilePackagesMap.set(pkg2,
|
|
1106
|
+
transpilePackagesMap.set(pkg2, chunkVA2CSOKJ_cjs.slash(dir));
|
|
1088
1107
|
} else {
|
|
1089
1108
|
transpilePackagesMap.set(pkg2, workspaceMap.get(pkg2)?.location ?? pkg2);
|
|
1090
1109
|
}
|
|
@@ -1110,7 +1129,7 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
1110
1129
|
}
|
|
1111
1130
|
})
|
|
1112
1131
|
}) : null,
|
|
1113
|
-
bundlerOptions.
|
|
1132
|
+
bundlerOptions.noBundling ? {
|
|
1114
1133
|
name: "alias-optimized-deps",
|
|
1115
1134
|
async resolveId(id, importer, options) {
|
|
1116
1135
|
if (!virtualDependencies.has(id)) {
|
|
@@ -1140,11 +1159,11 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
1140
1159
|
transformMixedEsModules: true,
|
|
1141
1160
|
ignoreTryCatch: false
|
|
1142
1161
|
}),
|
|
1143
|
-
bundlerOptions.
|
|
1162
|
+
bundlerOptions.noBundling ? null : nodeResolve__default.default({
|
|
1144
1163
|
preferBuiltins: true,
|
|
1145
1164
|
exportConditions: ["node"]
|
|
1146
1165
|
}),
|
|
1147
|
-
bundlerOptions.
|
|
1166
|
+
bundlerOptions.noBundling ? esmShim() : null,
|
|
1148
1167
|
// hono is imported from deployer, so we need to resolve from here instead of the project root
|
|
1149
1168
|
aliasHono(),
|
|
1150
1169
|
json__default.default(),
|
|
@@ -1197,6 +1216,16 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1197
1216
|
if (virtualDependencies.size === 0) {
|
|
1198
1217
|
return [];
|
|
1199
1218
|
}
|
|
1219
|
+
const noBundling = bundlerOptions.isDev || bundlerOptions.externalsPreset;
|
|
1220
|
+
const plugins = await getInputPlugins2(virtualDependencies, {
|
|
1221
|
+
transpilePackages: packagesToTranspile,
|
|
1222
|
+
workspaceMap,
|
|
1223
|
+
bundlerOptions: {
|
|
1224
|
+
noBundling
|
|
1225
|
+
},
|
|
1226
|
+
rootDir,
|
|
1227
|
+
externals
|
|
1228
|
+
});
|
|
1200
1229
|
const bundler = await rollup.rollup({
|
|
1201
1230
|
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
1202
1231
|
input: Array.from(virtualDependencies.entries()).reduce(
|
|
@@ -1207,14 +1236,8 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1207
1236
|
{}
|
|
1208
1237
|
),
|
|
1209
1238
|
external: externals,
|
|
1210
|
-
treeshake:
|
|
1211
|
-
plugins
|
|
1212
|
-
transpilePackages: packagesToTranspile,
|
|
1213
|
-
workspaceMap,
|
|
1214
|
-
bundlerOptions,
|
|
1215
|
-
rootDir,
|
|
1216
|
-
externals
|
|
1217
|
-
})
|
|
1239
|
+
treeshake: noBundling ? false : "safest",
|
|
1240
|
+
plugins
|
|
1218
1241
|
});
|
|
1219
1242
|
const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
|
|
1220
1243
|
const { output } = await bundler.write({
|
|
@@ -1228,12 +1251,12 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1228
1251
|
* So we want to write them to the `.mastra/output` folder as well.
|
|
1229
1252
|
*/
|
|
1230
1253
|
chunkFileNames: (chunkInfo) => {
|
|
1231
|
-
if (
|
|
1254
|
+
if (noBundling) {
|
|
1232
1255
|
const importedFromPackages = /* @__PURE__ */ new Set();
|
|
1233
1256
|
for (const moduleId of chunkInfo.moduleIds) {
|
|
1234
|
-
const normalized =
|
|
1257
|
+
const normalized = chunkVA2CSOKJ_cjs.slash(moduleId);
|
|
1235
1258
|
for (const [pkgName, pkgInfo] of workspaceMap.entries()) {
|
|
1236
|
-
const location =
|
|
1259
|
+
const location = chunkVA2CSOKJ_cjs.slash(pkgInfo.location);
|
|
1237
1260
|
if (normalized.startsWith(location)) {
|
|
1238
1261
|
importedFromPackages.add(pkgName);
|
|
1239
1262
|
break;
|
|
@@ -1255,7 +1278,7 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1255
1278
|
if (importedFromPackages.size === 1) {
|
|
1256
1279
|
const [pkgName] = importedFromPackages;
|
|
1257
1280
|
const workspaceLocation = workspaceMap.get(pkgName).location;
|
|
1258
|
-
return prepareEntryFileName(
|
|
1281
|
+
return prepareEntryFileName(chunkVA2CSOKJ_cjs.getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
|
|
1259
1282
|
}
|
|
1260
1283
|
}
|
|
1261
1284
|
return `${outputDirRelative}/[name].mjs`;
|
|
@@ -1269,7 +1292,7 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1269
1292
|
function findExternalImporter(module, external, allOutputs) {
|
|
1270
1293
|
const capturedFiles = /* @__PURE__ */ new Set();
|
|
1271
1294
|
for (const id of module.imports) {
|
|
1272
|
-
if (
|
|
1295
|
+
if (chunkVA2CSOKJ_cjs.isDependencyPartOfPackage(id, external)) {
|
|
1273
1296
|
return module;
|
|
1274
1297
|
} else {
|
|
1275
1298
|
if (id.endsWith(".mjs")) {
|
|
@@ -1290,19 +1313,31 @@ function findExternalImporter(module, external, allOutputs) {
|
|
|
1290
1313
|
}
|
|
1291
1314
|
async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
1292
1315
|
const { workspaceRoot = null, workspaceMap = /* @__PURE__ */ new Map(), projectRoot = outputDir, bundlerOptions = {} } = options;
|
|
1293
|
-
const {
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1316
|
+
const { externals: customExternals = [], transpilePackages = [], isDev = false } = bundlerOptions || {};
|
|
1317
|
+
let externalsPreset = false;
|
|
1318
|
+
if (customExternals === true) {
|
|
1319
|
+
externalsPreset = true;
|
|
1320
|
+
}
|
|
1321
|
+
const externalsList = Array.isArray(customExternals) ? customExternals : [];
|
|
1322
|
+
const allExternals = [...GLOBAL_EXTERNALS, ...DEPRECATED_EXTERNALS, ...externalsList];
|
|
1298
1323
|
const workspacePackagesNames = Array.from(workspaceMap.keys());
|
|
1299
1324
|
const packagesToTranspile = /* @__PURE__ */ new Set([...transpilePackages, ...workspacePackagesNames]);
|
|
1325
|
+
const extractedExternals = /* @__PURE__ */ new Map();
|
|
1326
|
+
if (externalsPreset) {
|
|
1327
|
+
for (const [dep, metadata] of depsToOptimize.entries()) {
|
|
1328
|
+
if (!metadata.isWorkspace) {
|
|
1329
|
+
extractedExternals.set(dep, metadata.rootPath ?? dep);
|
|
1330
|
+
depsToOptimize.delete(dep);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1300
1334
|
const { optimizedDependencyEntries, fileNameToDependencyMap } = createVirtualDependencies(depsToOptimize, {
|
|
1301
1335
|
workspaceRoot,
|
|
1302
1336
|
outputDir,
|
|
1303
1337
|
projectRoot,
|
|
1304
1338
|
bundlerOptions: {
|
|
1305
|
-
isDev
|
|
1339
|
+
isDev,
|
|
1340
|
+
externalsPreset
|
|
1306
1341
|
}
|
|
1307
1342
|
});
|
|
1308
1343
|
const output = await buildExternalDependencies(optimizedDependencyEntries, {
|
|
@@ -1312,7 +1347,8 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1312
1347
|
rootDir: workspaceRoot || projectRoot,
|
|
1313
1348
|
outputDir,
|
|
1314
1349
|
bundlerOptions: {
|
|
1315
|
-
isDev
|
|
1350
|
+
isDev,
|
|
1351
|
+
externalsPreset
|
|
1316
1352
|
}
|
|
1317
1353
|
});
|
|
1318
1354
|
const moduleResolveMap2 = /* @__PURE__ */ new Map();
|
|
@@ -1347,6 +1383,14 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1347
1383
|
}
|
|
1348
1384
|
usedExternals[fullPath] = innerObj;
|
|
1349
1385
|
}
|
|
1386
|
+
if (extractedExternals.size > 0) {
|
|
1387
|
+
const syntheticPath = path2__namespace.join(workspaceRoot || projectRoot, "__externals__");
|
|
1388
|
+
const externalsObj = /* @__PURE__ */ Object.create(null);
|
|
1389
|
+
for (const [dep, rootPath] of extractedExternals) {
|
|
1390
|
+
externalsObj[dep] = rootPath;
|
|
1391
|
+
}
|
|
1392
|
+
usedExternals[syntheticPath] = externalsObj;
|
|
1393
|
+
}
|
|
1350
1394
|
return { output, fileNameToDependencyMap, usedExternals };
|
|
1351
1395
|
}
|
|
1352
1396
|
|
|
@@ -1622,7 +1666,7 @@ async function analyzeBundle(entries, mastraEntry, {
|
|
|
1622
1666
|
outputDir,
|
|
1623
1667
|
projectRoot,
|
|
1624
1668
|
isDev = false,
|
|
1625
|
-
bundlerOptions:
|
|
1669
|
+
bundlerOptions: internalBundlerOptions
|
|
1626
1670
|
}, logger) {
|
|
1627
1671
|
const mastraConfig = await promises.readFile(mastraEntry, "utf-8");
|
|
1628
1672
|
const mastraConfigResult = {
|
|
@@ -1641,28 +1685,33 @@ export const mastra = new Mastra({
|
|
|
1641
1685
|
|
|
1642
1686
|
If you think your configuration is valid, please open an issue.`);
|
|
1643
1687
|
}
|
|
1644
|
-
const {
|
|
1645
|
-
const
|
|
1688
|
+
const { externals: _bundlerExternals = [] } = internalBundlerOptions || {};
|
|
1689
|
+
const userBundlerOptions = await getBundlerOptions(mastraEntry, outputDir);
|
|
1646
1690
|
const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
|
|
1691
|
+
let externalsPreset = false;
|
|
1692
|
+
if (userBundlerOptions?.externals === true) {
|
|
1693
|
+
externalsPreset = true;
|
|
1694
|
+
}
|
|
1647
1695
|
let index = 0;
|
|
1648
1696
|
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
1649
|
-
const
|
|
1650
|
-
const
|
|
1697
|
+
const bundlerExternals = Array.isArray(_bundlerExternals) ? _bundlerExternals : [];
|
|
1698
|
+
const userExternals = Array.isArray(userBundlerOptions?.externals) ? userBundlerOptions?.externals : [];
|
|
1699
|
+
const allExternals = [...GLOBAL_EXTERNALS, ...bundlerExternals, ...userExternals];
|
|
1651
1700
|
logger.info("Analyzing dependencies...");
|
|
1652
1701
|
const allUsedExternals = /* @__PURE__ */ new Set();
|
|
1653
1702
|
for (const entry of entries) {
|
|
1654
1703
|
const isVirtualFile = entry.includes("\n") || !fs.existsSync(entry);
|
|
1655
1704
|
const analyzeResult = await analyzeEntry({ entry, isVirtualFile }, mastraEntry, {
|
|
1656
1705
|
logger,
|
|
1657
|
-
sourcemapEnabled:
|
|
1706
|
+
sourcemapEnabled: userBundlerOptions?.sourcemap ?? false,
|
|
1658
1707
|
workspaceMap,
|
|
1659
1708
|
projectRoot,
|
|
1660
|
-
shouldCheckTransitiveDependencies: isDev
|
|
1709
|
+
shouldCheckTransitiveDependencies: isDev || externalsPreset
|
|
1661
1710
|
});
|
|
1662
1711
|
await promises.writeFile(path2.join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
|
|
1663
1712
|
for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
|
|
1664
|
-
const isPartOfExternals = allExternals.some((external) =>
|
|
1665
|
-
if (isPartOfExternals) {
|
|
1713
|
+
const isPartOfExternals = allExternals.some((external) => chunkVA2CSOKJ_cjs.isDependencyPartOfPackage(dep, external));
|
|
1714
|
+
if (isPartOfExternals || externalsPreset && !metadata.isWorkspace) {
|
|
1666
1715
|
allUsedExternals.add(dep);
|
|
1667
1716
|
continue;
|
|
1668
1717
|
}
|
|
@@ -1677,7 +1726,7 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1677
1726
|
}
|
|
1678
1727
|
}
|
|
1679
1728
|
}
|
|
1680
|
-
if (isDev) {
|
|
1729
|
+
if (isDev || externalsPreset) {
|
|
1681
1730
|
for (const [dep, metadata] of depsToOptimize.entries()) {
|
|
1682
1731
|
if (!metadata.isWorkspace) {
|
|
1683
1732
|
depsToOptimize.delete(dep);
|
|
@@ -1689,15 +1738,37 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1689
1738
|
logger.debug(`${sortedDeps.map((key) => `- ${key}`).join("\n")}`);
|
|
1690
1739
|
const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
|
|
1691
1740
|
bundlerOptions: {
|
|
1692
|
-
...
|
|
1693
|
-
externals: allExternals,
|
|
1694
|
-
enableEsmShim,
|
|
1741
|
+
...userBundlerOptions,
|
|
1742
|
+
externals: userBundlerOptions?.externals ?? allExternals,
|
|
1695
1743
|
isDev
|
|
1696
1744
|
},
|
|
1697
1745
|
projectRoot,
|
|
1698
1746
|
workspaceRoot,
|
|
1699
1747
|
workspaceMap
|
|
1700
1748
|
});
|
|
1749
|
+
const relativeWorkspaceFolderPaths = Array.from(workspaceMap.values()).map(
|
|
1750
|
+
(pkgInfo) => path2.relative(workspaceRoot || projectRoot, pkgInfo.location)
|
|
1751
|
+
);
|
|
1752
|
+
for (const o of output) {
|
|
1753
|
+
if (o.type === "asset") {
|
|
1754
|
+
continue;
|
|
1755
|
+
}
|
|
1756
|
+
for (const i of o.imports) {
|
|
1757
|
+
if (chunkVA2CSOKJ_cjs.isBuiltinModule(i)) {
|
|
1758
|
+
continue;
|
|
1759
|
+
}
|
|
1760
|
+
if (i.startsWith(".") || i.startsWith("/")) {
|
|
1761
|
+
continue;
|
|
1762
|
+
}
|
|
1763
|
+
if (relativeWorkspaceFolderPaths.some((workspacePath) => i.startsWith(workspacePath))) {
|
|
1764
|
+
continue;
|
|
1765
|
+
}
|
|
1766
|
+
const pkgName = chunkVA2CSOKJ_cjs.getPackageName(i);
|
|
1767
|
+
if (pkgName) {
|
|
1768
|
+
allUsedExternals.add(pkgName);
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1701
1772
|
const result = await validateOutput(
|
|
1702
1773
|
{
|
|
1703
1774
|
output,
|
|
@@ -1721,10 +1792,11 @@ exports.esbuild = esbuild;
|
|
|
1721
1792
|
exports.esmShim = esmShim;
|
|
1722
1793
|
exports.extractMastraOption = extractMastraOption;
|
|
1723
1794
|
exports.getBundlerOptions = getBundlerOptions;
|
|
1795
|
+
exports.getPackageRootPath = getPackageRootPath;
|
|
1724
1796
|
exports.getWorkspaceInformation = getWorkspaceInformation;
|
|
1725
1797
|
exports.removeAllOptionsFromMastraExcept = removeAllOptionsFromMastraExcept;
|
|
1726
1798
|
exports.removeDeployer = removeDeployer2;
|
|
1727
1799
|
exports.subpathExternalsResolver = subpathExternalsResolver;
|
|
1728
1800
|
exports.tsConfigPaths = tsConfigPaths;
|
|
1729
|
-
//# sourceMappingURL=chunk-
|
|
1730
|
-
//# sourceMappingURL=chunk-
|
|
1801
|
+
//# sourceMappingURL=chunk-KCGBR2X6.cjs.map
|
|
1802
|
+
//# sourceMappingURL=chunk-KCGBR2X6.cjs.map
|