@mastra/deployer 0.24.7-alpha.1 → 0.24.7-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.
- package/CHANGELOG.md +27 -0
- package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
- package/dist/build/analyze.cjs +2 -2
- package/dist/build/analyze.d.ts +1 -1
- 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.map +1 -1
- package/dist/build/bundler.js +1 -1
- package/dist/build/index.cjs +12 -12
- package/dist/build/index.js +4 -4
- package/dist/build/plugins/module-resolve-map.d.ts +3 -0
- package/dist/build/plugins/module-resolve-map.d.ts.map +1 -0
- package/dist/build/plugins/node-gyp-detector.d.ts +3 -0
- package/dist/build/plugins/node-gyp-detector.d.ts.map +1 -0
- package/dist/build/plugins/subpath-externals-resolver.d.ts +3 -0
- package/dist/build/plugins/subpath-externals-resolver.d.ts.map +1 -0
- package/dist/build/utils.d.ts +1 -0
- package/dist/build/utils.d.ts.map +1 -1
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.d.ts +1 -1
- package/dist/bundler/index.js +1 -1
- package/dist/{chunk-K7JCMIZW.cjs → chunk-35IO74UA.cjs} +17 -16
- package/dist/chunk-35IO74UA.cjs.map +1 -0
- package/dist/chunk-3GJSIS6L.cjs +69 -0
- package/dist/chunk-3GJSIS6L.cjs.map +1 -0
- package/dist/{chunk-MYLM6HSI.js → chunk-4UJPXE65.js} +5 -4
- package/dist/chunk-4UJPXE65.js.map +1 -0
- package/dist/{chunk-UWCXK7X6.cjs → chunk-AG6GOBBO.cjs} +15 -14
- package/dist/chunk-AG6GOBBO.cjs.map +1 -0
- package/dist/{chunk-KEU3VV3H.js → chunk-DFJK4OKW.js} +3 -3
- package/dist/{chunk-KEU3VV3H.js.map → chunk-DFJK4OKW.js.map} +1 -1
- package/dist/{chunk-KLIBX4WB.js → chunk-G4OG2LG5.js} +6 -5
- package/dist/chunk-G4OG2LG5.js.map +1 -0
- package/dist/{chunk-7VIDVYTY.js → chunk-GWACJ2WL.js} +6 -14
- package/dist/chunk-GWACJ2WL.js.map +1 -0
- package/dist/{chunk-FHZKTDSF.cjs → chunk-M2JPS7OF.cjs} +5 -5
- package/dist/{chunk-FHZKTDSF.cjs.map → chunk-M2JPS7OF.cjs.map} +1 -1
- package/dist/chunk-NEGQTTJS.js +62 -0
- package/dist/chunk-NEGQTTJS.js.map +1 -0
- package/dist/{chunk-53B6GOCH.cjs → chunk-SKDU2LXD.cjs} +13 -21
- package/dist/chunk-SKDU2LXD.cjs.map +1 -0
- package/dist/{chunk-PHZK4P6J.js → chunk-TDUDRKXR.js} +417 -143
- package/dist/chunk-TDUDRKXR.js.map +1 -0
- package/dist/{chunk-6R73ZVZX.cjs → chunk-UB6E4QPC.cjs} +430 -158
- package/dist/chunk-UB6E4QPC.cjs.map +1 -0
- package/dist/index.cjs +5 -5
- package/dist/index.js +2 -2
- package/dist/server/handlers/routes/scores/handlers.d.ts +4 -0
- package/dist/server/handlers/routes/scores/handlers.d.ts.map +1 -1
- package/dist/validator/custom-resolver.cjs +20 -12
- package/dist/validator/custom-resolver.cjs.map +1 -1
- package/dist/validator/custom-resolver.d.ts.map +1 -1
- package/dist/validator/custom-resolver.js +18 -10
- package/dist/validator/custom-resolver.js.map +1 -1
- package/dist/validator/validate.d.ts +15 -1
- package/dist/validator/validate.d.ts.map +1 -1
- package/package.json +6 -7
- package/dist/chunk-53B6GOCH.cjs.map +0 -1
- package/dist/chunk-6R73ZVZX.cjs.map +0 -1
- package/dist/chunk-7VIDVYTY.js.map +0 -1
- package/dist/chunk-K7JCMIZW.cjs.map +0 -1
- package/dist/chunk-KLIBX4WB.js.map +0 -1
- package/dist/chunk-MYLM6HSI.js.map +0 -1
- package/dist/chunk-PHZK4P6J.js.map +0 -1
- package/dist/chunk-UWCXK7X6.cjs.map +0 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunk3GJSIS6L_cjs = require('./chunk-3GJSIS6L.cjs');
|
|
3
4
|
var babel = require('@babel/core');
|
|
4
5
|
var fs = require('fs');
|
|
5
6
|
var promises = require('fs/promises');
|
|
6
7
|
var path2 = require('path');
|
|
7
8
|
var child_process = require('child_process');
|
|
8
|
-
var localPkg = require('local-pkg');
|
|
9
|
-
var url = require('url');
|
|
10
9
|
var rollup = require('rollup');
|
|
11
10
|
var originalEsbuild = require('rollup-plugin-esbuild');
|
|
12
11
|
var commonjs = require('@rollup/plugin-commonjs');
|
|
@@ -18,11 +17,13 @@ var pkg = require('empathic/package');
|
|
|
18
17
|
var findWorkspaces = require('find-workspaces');
|
|
19
18
|
var logger = require('@mastra/core/logger');
|
|
20
19
|
var virtual = require('@rollup/plugin-virtual');
|
|
20
|
+
var url = require('url');
|
|
21
21
|
var module$1 = require('module');
|
|
22
22
|
var nodeResolve = require('@rollup/plugin-node-resolve');
|
|
23
23
|
var originalEsmShim = require('@rollup/plugin-esm-shim');
|
|
24
24
|
var posix = require('path/posix');
|
|
25
25
|
var resolve = require('resolve.exports');
|
|
26
|
+
var localPkg = require('local-pkg');
|
|
26
27
|
var error = require('@mastra/core/error');
|
|
27
28
|
|
|
28
29
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -58,83 +59,18 @@ var nodeResolve__default = /*#__PURE__*/_interopDefault(nodeResolve);
|
|
|
58
59
|
var originalEsmShim__default = /*#__PURE__*/_interopDefault(originalEsmShim);
|
|
59
60
|
var resolve__namespace = /*#__PURE__*/_interopNamespace(resolve);
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
async function getPackageRootPath(packageName, parentPath) {
|
|
70
|
-
let rootPath;
|
|
71
|
-
try {
|
|
72
|
-
let options = void 0;
|
|
73
|
-
if (parentPath) {
|
|
74
|
-
if (!parentPath.startsWith("file://")) {
|
|
75
|
-
parentPath = url.pathToFileURL(parentPath).href;
|
|
76
|
-
}
|
|
77
|
-
options = {
|
|
78
|
-
paths: [parentPath]
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
const pkg2 = await localPkg.getPackageInfo(packageName, options);
|
|
82
|
-
rootPath = pkg2?.rootPath ?? null;
|
|
83
|
-
} catch (e) {
|
|
84
|
-
rootPath = null;
|
|
62
|
+
var ValidationError = class extends Error {
|
|
63
|
+
type;
|
|
64
|
+
stack;
|
|
65
|
+
constructor(args) {
|
|
66
|
+
super(args.message);
|
|
67
|
+
this.type = args.type;
|
|
68
|
+
this.stack = args.stack;
|
|
85
69
|
}
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
function getCompiledDepCachePath(rootPath, packageName) {
|
|
89
|
-
return slash(path2.join(rootPath, "node_modules", ".cache", packageName));
|
|
90
|
-
}
|
|
91
|
-
function slash(path3) {
|
|
92
|
-
const isExtendedLengthPath = path3.startsWith("\\\\?\\");
|
|
93
|
-
if (isExtendedLengthPath) {
|
|
94
|
-
return path3;
|
|
95
|
-
}
|
|
96
|
-
return path3.replaceAll("\\", "/");
|
|
97
|
-
}
|
|
98
|
-
function rollupSafeName(name, rootDir) {
|
|
99
|
-
const rel = path2.relative(rootDir, name);
|
|
100
|
-
let entry = slash(rel);
|
|
101
|
-
entry = entry.replace(/^(\.\.\/)+/, "");
|
|
102
|
-
entry = entry.replace(/^\/+/, "");
|
|
103
|
-
entry = entry.replace(/^[A-Za-z]:\//, "");
|
|
104
|
-
if (!entry) {
|
|
105
|
-
entry = slash(path2.basename(name));
|
|
106
|
-
}
|
|
107
|
-
return entry;
|
|
108
|
-
}
|
|
109
|
-
var NATIVE_BINDING_LOADERS = [
|
|
110
|
-
"node-gyp-build",
|
|
111
|
-
"prebuild-install",
|
|
112
|
-
"bindings",
|
|
113
|
-
"node-addon-api",
|
|
114
|
-
"node-pre-gyp",
|
|
115
|
-
"nan"
|
|
116
|
-
// Native Abstractions for Node.js
|
|
117
|
-
];
|
|
118
|
-
function findNativePackageModule(moduleIds) {
|
|
119
|
-
return moduleIds.find((id) => {
|
|
120
|
-
if (id.startsWith("\0")) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
if (!id.includes("/node_modules/")) {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
for (const loader of NATIVE_BINDING_LOADERS) {
|
|
127
|
-
if (id.includes(`/${loader}/`) || id.includes(`/${loader}@`)) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return true;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// src/validator/validate.ts
|
|
70
|
+
};
|
|
136
71
|
function spawn(command, args = [], options = {}) {
|
|
137
72
|
return new Promise((resolve2, reject) => {
|
|
73
|
+
let validationError = null;
|
|
138
74
|
const childProcess = child_process.spawn(command, args, {
|
|
139
75
|
// stdio: 'inherit',
|
|
140
76
|
...options
|
|
@@ -144,28 +80,63 @@ function spawn(command, args = [], options = {}) {
|
|
|
144
80
|
});
|
|
145
81
|
let stderr = "";
|
|
146
82
|
childProcess.stderr?.on("data", (message) => {
|
|
147
|
-
|
|
83
|
+
try {
|
|
84
|
+
validationError = JSON.parse(message.toString());
|
|
85
|
+
} catch {
|
|
86
|
+
stderr += message;
|
|
87
|
+
}
|
|
148
88
|
});
|
|
149
89
|
childProcess.on("close", (code) => {
|
|
150
90
|
if (code === 0) {
|
|
151
91
|
resolve2();
|
|
152
92
|
} else {
|
|
153
|
-
|
|
93
|
+
if (validationError) {
|
|
94
|
+
reject(new ValidationError(validationError));
|
|
95
|
+
} else {
|
|
96
|
+
reject(new Error(stderr));
|
|
97
|
+
}
|
|
154
98
|
}
|
|
155
99
|
});
|
|
156
100
|
});
|
|
157
101
|
}
|
|
158
|
-
function validate(file) {
|
|
102
|
+
function validate(file, { injectESMShim = false, moduleResolveMapLocation }) {
|
|
103
|
+
let prefixCode = "";
|
|
104
|
+
if (injectESMShim) {
|
|
105
|
+
prefixCode = `import { fileURLToPath } from 'url';
|
|
106
|
+
import { dirname } from 'path';
|
|
107
|
+
|
|
108
|
+
globalThis.__filename = fileURLToPath(import.meta.url);
|
|
109
|
+
globalThis.__dirname = dirname(__filename);
|
|
110
|
+
`;
|
|
111
|
+
}
|
|
112
|
+
function errorHandler(err) {
|
|
113
|
+
console.error(
|
|
114
|
+
JSON.stringify({
|
|
115
|
+
type: err.name,
|
|
116
|
+
message: err.message,
|
|
117
|
+
stack: err.stack
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
159
122
|
return spawn(
|
|
160
|
-
|
|
123
|
+
process.execPath,
|
|
161
124
|
[
|
|
162
125
|
"--import",
|
|
163
126
|
undefined("@mastra/deployer/loader"),
|
|
164
127
|
"--input-type=module",
|
|
128
|
+
"--enable-source-maps",
|
|
165
129
|
"-e",
|
|
166
|
-
|
|
130
|
+
`${prefixCode};import('file://${chunk3GJSIS6L_cjs.slash(file)}').catch(err => {
|
|
131
|
+
${errorHandler.toString()}
|
|
132
|
+
errorHandler(err);
|
|
133
|
+
})`.replaceAll(/\n/g, "")
|
|
167
134
|
],
|
|
168
135
|
{
|
|
136
|
+
env: {
|
|
137
|
+
...process.env,
|
|
138
|
+
MODULE_MAP: `${moduleResolveMapLocation}`
|
|
139
|
+
},
|
|
169
140
|
cwd: path2.dirname(file)
|
|
170
141
|
}
|
|
171
142
|
);
|
|
@@ -604,7 +575,7 @@ async function getWorkspaceInformation({
|
|
|
604
575
|
mastraEntryFile
|
|
605
576
|
}) {
|
|
606
577
|
const closestPkgJson = pkg__namespace.up({ cwd: path2.dirname(mastraEntryFile) });
|
|
607
|
-
const location = closestPkgJson ? path2.dirname(slash(closestPkgJson)) : slash(process.cwd());
|
|
578
|
+
const location = closestPkgJson ? path2.dirname(chunk3GJSIS6L_cjs.slash(closestPkgJson)) : chunk3GJSIS6L_cjs.slash(process.cwd());
|
|
608
579
|
const workspaces = await findWorkspaces.findWorkspaces(dir, { cache: workspacesCache });
|
|
609
580
|
const _workspaceMap = new Map(
|
|
610
581
|
workspaces?.map((workspace) => [
|
|
@@ -720,7 +691,7 @@ var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
|
|
|
720
691
|
|
|
721
692
|
// src/build/analyze/analyzeEntry.ts
|
|
722
693
|
function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
|
|
723
|
-
const normalizedMastraEntry = slash(mastraEntry);
|
|
694
|
+
const normalizedMastraEntry = chunk3GJSIS6L_cjs.slash(mastraEntry);
|
|
724
695
|
let virtualPlugin = null;
|
|
725
696
|
if (isVirtualFile) {
|
|
726
697
|
virtualPlugin = virtual__default.default({
|
|
@@ -739,7 +710,7 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
|
|
|
739
710
|
name: "custom-alias-resolver",
|
|
740
711
|
resolveId(id) {
|
|
741
712
|
if (id === "#server") {
|
|
742
|
-
return slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
|
|
713
|
+
return chunk3GJSIS6L_cjs.slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
|
|
743
714
|
}
|
|
744
715
|
if (id === "#mastra") {
|
|
745
716
|
return normalizedMastraEntry;
|
|
@@ -775,20 +746,20 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
|
|
|
775
746
|
}
|
|
776
747
|
let entryRootPath = projectRoot;
|
|
777
748
|
if (!output.facadeModuleId.startsWith("\0virtual:")) {
|
|
778
|
-
entryRootPath = await getPackageRootPath(output.facadeModuleId) || projectRoot;
|
|
749
|
+
entryRootPath = await chunk3GJSIS6L_cjs.getPackageRootPath(output.facadeModuleId) || projectRoot;
|
|
779
750
|
}
|
|
780
751
|
for (const [dependency, bindings] of Object.entries(output.importedBindings)) {
|
|
781
752
|
if (isNodeBuiltin(dependency) || DEPS_TO_IGNORE.includes(dependency)) {
|
|
782
753
|
continue;
|
|
783
754
|
}
|
|
784
|
-
const pkgName = getPackageName(dependency);
|
|
755
|
+
const pkgName = chunk3GJSIS6L_cjs.getPackageName(dependency);
|
|
785
756
|
let rootPath = null;
|
|
786
757
|
let isWorkspace = false;
|
|
787
758
|
if (pkgName) {
|
|
788
|
-
rootPath = await getPackageRootPath(dependency, entryRootPath);
|
|
759
|
+
rootPath = await chunk3GJSIS6L_cjs.getPackageRootPath(dependency, entryRootPath);
|
|
789
760
|
isWorkspace = workspaceMap.has(pkgName);
|
|
790
761
|
}
|
|
791
|
-
const normalizedRootPath = rootPath ? slash(rootPath) : null;
|
|
762
|
+
const normalizedRootPath = rootPath ? chunk3GJSIS6L_cjs.slash(rootPath) : null;
|
|
792
763
|
depsToOptimize.set(dependency, {
|
|
793
764
|
exports: bindings,
|
|
794
765
|
rootPath: normalizedRootPath,
|
|
@@ -930,8 +901,116 @@ function aliasHono() {
|
|
|
930
901
|
}
|
|
931
902
|
};
|
|
932
903
|
}
|
|
904
|
+
|
|
905
|
+
// src/build/plugins/subpath-externals-resolver.ts
|
|
906
|
+
function subpathExternalsResolver(externals) {
|
|
907
|
+
return {
|
|
908
|
+
name: "subpath-externals-resolver",
|
|
909
|
+
resolveId(id) {
|
|
910
|
+
if (id.startsWith(".") || id.startsWith("/")) {
|
|
911
|
+
return null;
|
|
912
|
+
}
|
|
913
|
+
const isPartOfExternals = externals.some((external) => chunk3GJSIS6L_cjs.isDependencyPartOfPackage(id, external));
|
|
914
|
+
if (isPartOfExternals) {
|
|
915
|
+
return {
|
|
916
|
+
id,
|
|
917
|
+
external: true
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
function nodeGypDetector() {
|
|
924
|
+
const modulesToTrack = /* @__PURE__ */ new Set();
|
|
925
|
+
const modulesToTrackPackageInfo = /* @__PURE__ */ new Map();
|
|
926
|
+
return {
|
|
927
|
+
name: "node-gyp-build-detector",
|
|
928
|
+
moduleParsed(info) {
|
|
929
|
+
if (!info.meta?.commonjs?.requires?.length) {
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
const hasNodeGypBuild = info.meta.commonjs.requires.some(
|
|
933
|
+
(m) => m?.resolved?.id.endsWith("node-gyp-build/index.js")
|
|
934
|
+
);
|
|
935
|
+
if (!hasNodeGypBuild) {
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
modulesToTrack.add(info.id);
|
|
939
|
+
modulesToTrackPackageInfo.set(info.id, localPkg.getPackageInfo(info.id));
|
|
940
|
+
},
|
|
941
|
+
async generateBundle(options, bundle) {
|
|
942
|
+
const binaryMapByChunk = /* @__PURE__ */ new Map();
|
|
943
|
+
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
944
|
+
if (chunk.type === "chunk") {
|
|
945
|
+
for (const moduleId of chunk.moduleIds) {
|
|
946
|
+
if (modulesToTrackPackageInfo.has(moduleId)) {
|
|
947
|
+
const pkgInfo = await modulesToTrackPackageInfo.get(moduleId);
|
|
948
|
+
if (!binaryMapByChunk.has(fileName)) {
|
|
949
|
+
binaryMapByChunk.set(fileName, /* @__PURE__ */ new Set());
|
|
950
|
+
}
|
|
951
|
+
if (pkgInfo?.packageJson?.name) {
|
|
952
|
+
binaryMapByChunk.get(fileName).add(pkgInfo.packageJson.name);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
const binaryMapJson = Object.fromEntries(
|
|
959
|
+
Array.from(binaryMapByChunk.entries()).map(([key, value]) => [key, Array.from(value)])
|
|
960
|
+
);
|
|
961
|
+
this.emitFile({
|
|
962
|
+
type: "asset",
|
|
963
|
+
name: "binary-map.json",
|
|
964
|
+
source: `${JSON.stringify(binaryMapJson, null, 2)}`
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
function moduleResolveMap(externals, projectRoot) {
|
|
970
|
+
const importMap = /* @__PURE__ */ new Map();
|
|
971
|
+
return {
|
|
972
|
+
name: "module-resolve-map",
|
|
973
|
+
moduleParsed(info) {
|
|
974
|
+
if (info.importedIds.length === 0 || !info.id) {
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
for (const importedId of info.importedIds) {
|
|
978
|
+
for (const external of externals) {
|
|
979
|
+
if (chunk3GJSIS6L_cjs.isDependencyPartOfPackage(importedId, external)) {
|
|
980
|
+
importMap.set(external, info.id);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
},
|
|
985
|
+
async generateBundle(options, bundle) {
|
|
986
|
+
const resolveMap = /* @__PURE__ */ new Map();
|
|
987
|
+
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
988
|
+
if (chunk.type === "chunk") {
|
|
989
|
+
for (const [external, resolvedFrom] of importMap) {
|
|
990
|
+
if (chunk.moduleIds.includes(resolvedFrom)) {
|
|
991
|
+
const fullPath = url.pathToFileURL(chunk3GJSIS6L_cjs.slash(path2.join(projectRoot, fileName))).toString();
|
|
992
|
+
const innerMap = resolveMap.get(fullPath) || /* @__PURE__ */ new Map();
|
|
993
|
+
innerMap.set(external, url.pathToFileURL(chunk3GJSIS6L_cjs.slash(resolvedFrom)).toString());
|
|
994
|
+
resolveMap.set(fullPath, innerMap);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
const resolveMapJson = Object.fromEntries(
|
|
1000
|
+
Array.from(resolveMap.entries()).map(([key, value]) => [key, Object.fromEntries(value.entries())])
|
|
1001
|
+
);
|
|
1002
|
+
this.emitFile({
|
|
1003
|
+
type: "asset",
|
|
1004
|
+
name: "module-resolve-map.json",
|
|
1005
|
+
source: `${JSON.stringify(resolveMapJson, null, 2)}`
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// src/build/analyze/bundleExternals.ts
|
|
933
1012
|
function prepareEntryFileName(name, rootDir) {
|
|
934
|
-
return rollupSafeName(name, rootDir);
|
|
1013
|
+
return chunk3GJSIS6L_cjs.rollupSafeName(name, rootDir);
|
|
935
1014
|
}
|
|
936
1015
|
function createVirtualDependencies(depsToOptimize, {
|
|
937
1016
|
projectRoot,
|
|
@@ -981,7 +1060,7 @@ function createVirtualDependencies(depsToOptimize, {
|
|
|
981
1060
|
continue;
|
|
982
1061
|
}
|
|
983
1062
|
const fileName = posix.basename(currentDepPath.name);
|
|
984
|
-
const entryName = prepareEntryFileName(getCompiledDepCachePath(rootPath, fileName), rootDir);
|
|
1063
|
+
const entryName = prepareEntryFileName(chunk3GJSIS6L_cjs.getCompiledDepCachePath(rootPath, fileName), rootDir);
|
|
985
1064
|
fileNameToDependencyMap.set(entryName, dep);
|
|
986
1065
|
optimizedDependencyEntries.set(dep, {
|
|
987
1066
|
...currentDepPath,
|
|
@@ -995,13 +1074,14 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
995
1074
|
transpilePackages,
|
|
996
1075
|
workspaceMap,
|
|
997
1076
|
bundlerOptions,
|
|
998
|
-
rootDir
|
|
1077
|
+
rootDir,
|
|
1078
|
+
externals
|
|
999
1079
|
}) {
|
|
1000
1080
|
const transpilePackagesMap = /* @__PURE__ */ new Map();
|
|
1001
1081
|
for (const pkg2 of transpilePackages) {
|
|
1002
|
-
const dir = await getPackageRootPath(pkg2);
|
|
1082
|
+
const dir = await chunk3GJSIS6L_cjs.getPackageRootPath(pkg2);
|
|
1003
1083
|
if (dir) {
|
|
1004
|
-
transpilePackagesMap.set(pkg2, slash(dir));
|
|
1084
|
+
transpilePackagesMap.set(pkg2, chunk3GJSIS6L_cjs.slash(dir));
|
|
1005
1085
|
} else {
|
|
1006
1086
|
transpilePackagesMap.set(pkg2, workspaceMap.get(pkg2)?.location ?? pkg2);
|
|
1007
1087
|
}
|
|
@@ -1016,6 +1096,7 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
1016
1096
|
{}
|
|
1017
1097
|
)
|
|
1018
1098
|
),
|
|
1099
|
+
subpathExternalsResolver(externals),
|
|
1019
1100
|
transpilePackagesMap.size ? esbuild({
|
|
1020
1101
|
format: "esm",
|
|
1021
1102
|
include: [...transpilePackagesMap.values()].map((p) => {
|
|
@@ -1044,7 +1125,8 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
1044
1125
|
if (!resolvedPath) {
|
|
1045
1126
|
resolvedPath = pkgJson.main ?? "index.js";
|
|
1046
1127
|
}
|
|
1047
|
-
|
|
1128
|
+
const resolved = await this.resolve(path2__namespace.posix.join(packageRootPath, resolvedPath), importer, options);
|
|
1129
|
+
return resolved;
|
|
1048
1130
|
}
|
|
1049
1131
|
} : null,
|
|
1050
1132
|
rollupPlugin.optimizeLodashImports({
|
|
@@ -1063,6 +1145,8 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
1063
1145
|
// hono is imported from deployer, so we need to resolve from here instead of the project root
|
|
1064
1146
|
aliasHono(),
|
|
1065
1147
|
json__default.default(),
|
|
1148
|
+
nodeGypDetector(),
|
|
1149
|
+
moduleResolveMap(externals, rootDir),
|
|
1066
1150
|
{
|
|
1067
1151
|
name: "not-found-resolver",
|
|
1068
1152
|
resolveId: {
|
|
@@ -1120,12 +1204,13 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1120
1204
|
{}
|
|
1121
1205
|
),
|
|
1122
1206
|
external: externals,
|
|
1123
|
-
treeshake: "safest",
|
|
1207
|
+
treeshake: bundlerOptions.isDev ? false : "safest",
|
|
1124
1208
|
plugins: getInputPlugins2(virtualDependencies, {
|
|
1125
1209
|
transpilePackages: packagesToTranspile,
|
|
1126
1210
|
workspaceMap,
|
|
1127
1211
|
bundlerOptions,
|
|
1128
|
-
rootDir
|
|
1212
|
+
rootDir,
|
|
1213
|
+
externals
|
|
1129
1214
|
})
|
|
1130
1215
|
});
|
|
1131
1216
|
const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
|
|
@@ -1133,6 +1218,8 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1133
1218
|
format: "esm",
|
|
1134
1219
|
dir: rootDir,
|
|
1135
1220
|
entryFileNames: "[name].mjs",
|
|
1221
|
+
// used to get the filename of the actual error
|
|
1222
|
+
sourcemap: true,
|
|
1136
1223
|
/**
|
|
1137
1224
|
* Rollup creates chunks for common dependencies, but these chunks are by default written to the root directory instead of respecting the entryFileNames structure.
|
|
1138
1225
|
* So we want to write them to the `.mastra/output` folder as well.
|
|
@@ -1141,9 +1228,9 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1141
1228
|
if (bundlerOptions.isDev) {
|
|
1142
1229
|
const importedFromPackages = /* @__PURE__ */ new Set();
|
|
1143
1230
|
for (const moduleId of chunkInfo.moduleIds) {
|
|
1144
|
-
const normalized = slash(moduleId);
|
|
1231
|
+
const normalized = chunk3GJSIS6L_cjs.slash(moduleId);
|
|
1145
1232
|
for (const [pkgName, pkgInfo] of workspaceMap.entries()) {
|
|
1146
|
-
const location = slash(pkgInfo.location);
|
|
1233
|
+
const location = chunk3GJSIS6L_cjs.slash(pkgInfo.location);
|
|
1147
1234
|
if (normalized.startsWith(location)) {
|
|
1148
1235
|
importedFromPackages.add(pkgName);
|
|
1149
1236
|
break;
|
|
@@ -1165,11 +1252,12 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1165
1252
|
if (importedFromPackages.size === 1) {
|
|
1166
1253
|
const [pkgName] = importedFromPackages;
|
|
1167
1254
|
const workspaceLocation = workspaceMap.get(pkgName).location;
|
|
1168
|
-
return prepareEntryFileName(getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
|
|
1255
|
+
return prepareEntryFileName(chunk3GJSIS6L_cjs.getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
|
|
1169
1256
|
}
|
|
1170
1257
|
}
|
|
1171
1258
|
return `${outputDirRelative}/[name].mjs`;
|
|
1172
1259
|
},
|
|
1260
|
+
assetFileNames: `${outputDirRelative}/[name][extname]`,
|
|
1173
1261
|
hoistTransitiveImports: false
|
|
1174
1262
|
});
|
|
1175
1263
|
await bundler.close();
|
|
@@ -1178,7 +1266,7 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1178
1266
|
function findExternalImporter(module, external, allOutputs) {
|
|
1179
1267
|
const capturedFiles = /* @__PURE__ */ new Set();
|
|
1180
1268
|
for (const id of module.imports) {
|
|
1181
|
-
if (id
|
|
1269
|
+
if (chunk3GJSIS6L_cjs.isDependencyPartOfPackage(id, external)) {
|
|
1182
1270
|
return module;
|
|
1183
1271
|
} else {
|
|
1184
1272
|
if (id.endsWith(".mjs")) {
|
|
@@ -1224,7 +1312,7 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1224
1312
|
isDev
|
|
1225
1313
|
}
|
|
1226
1314
|
});
|
|
1227
|
-
const
|
|
1315
|
+
const moduleResolveMap2 = /* @__PURE__ */ new Map();
|
|
1228
1316
|
const filteredChunks = output.filter((o) => o.type === "chunk");
|
|
1229
1317
|
for (const o of filteredChunks.filter((o2) => o2.isEntry || o2.isDynamicEntry)) {
|
|
1230
1318
|
for (const external of allExternals) {
|
|
@@ -1234,10 +1322,10 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1234
1322
|
const importer = findExternalImporter(o, external, filteredChunks);
|
|
1235
1323
|
if (importer) {
|
|
1236
1324
|
const fullPath = path2__namespace.join(workspaceRoot || projectRoot, importer.fileName);
|
|
1237
|
-
let innerMap =
|
|
1325
|
+
let innerMap = moduleResolveMap2.get(fullPath);
|
|
1238
1326
|
if (!innerMap) {
|
|
1239
1327
|
innerMap = /* @__PURE__ */ new Map();
|
|
1240
|
-
|
|
1328
|
+
moduleResolveMap2.set(fullPath, innerMap);
|
|
1241
1329
|
}
|
|
1242
1330
|
if (importer.moduleIds.length) {
|
|
1243
1331
|
innerMap.set(
|
|
@@ -1249,7 +1337,7 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1249
1337
|
}
|
|
1250
1338
|
}
|
|
1251
1339
|
const usedExternals = /* @__PURE__ */ Object.create(null);
|
|
1252
|
-
for (const [fullPath, innerMap] of
|
|
1340
|
+
for (const [fullPath, innerMap] of moduleResolveMap2) {
|
|
1253
1341
|
const innerObj = /* @__PURE__ */ Object.create(null);
|
|
1254
1342
|
for (const [external, value] of innerMap) {
|
|
1255
1343
|
innerObj[external] = value;
|
|
@@ -1258,6 +1346,108 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1258
1346
|
}
|
|
1259
1347
|
return { output, fileNameToDependencyMap, usedExternals };
|
|
1260
1348
|
}
|
|
1349
|
+
|
|
1350
|
+
// ../../node_modules/.pnpm/stacktrace-parser@0.1.11/node_modules/stacktrace-parser/dist/stack-trace-parser.esm.js
|
|
1351
|
+
var UNKNOWN_FUNCTION = "<unknown>";
|
|
1352
|
+
function parse(stackString) {
|
|
1353
|
+
var lines = stackString.split("\n");
|
|
1354
|
+
return lines.reduce(function(stack, line) {
|
|
1355
|
+
var parseResult = parseChrome(line) || parseWinjs(line) || parseGecko(line) || parseNode(line) || parseJSC(line);
|
|
1356
|
+
if (parseResult) {
|
|
1357
|
+
stack.push(parseResult);
|
|
1358
|
+
}
|
|
1359
|
+
return stack;
|
|
1360
|
+
}, []);
|
|
1361
|
+
}
|
|
1362
|
+
var chromeRe = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|rsc|<anonymous>|\/|[a-z]:\\|\\\\).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
|
|
1363
|
+
var chromeEvalRe = /\((\S*)(?::(\d+))(?::(\d+))\)/;
|
|
1364
|
+
function parseChrome(line) {
|
|
1365
|
+
var parts = chromeRe.exec(line);
|
|
1366
|
+
if (!parts) {
|
|
1367
|
+
return null;
|
|
1368
|
+
}
|
|
1369
|
+
var isNative = parts[2] && parts[2].indexOf("native") === 0;
|
|
1370
|
+
var isEval = parts[2] && parts[2].indexOf("eval") === 0;
|
|
1371
|
+
var submatch = chromeEvalRe.exec(parts[2]);
|
|
1372
|
+
if (isEval && submatch != null) {
|
|
1373
|
+
parts[2] = submatch[1];
|
|
1374
|
+
parts[3] = submatch[2];
|
|
1375
|
+
parts[4] = submatch[3];
|
|
1376
|
+
}
|
|
1377
|
+
return {
|
|
1378
|
+
file: !isNative ? parts[2] : null,
|
|
1379
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1380
|
+
arguments: isNative ? [parts[2]] : [],
|
|
1381
|
+
lineNumber: parts[3] ? +parts[3] : null,
|
|
1382
|
+
column: parts[4] ? +parts[4] : null
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
var winjsRe = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|rsc|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
1386
|
+
function parseWinjs(line) {
|
|
1387
|
+
var parts = winjsRe.exec(line);
|
|
1388
|
+
if (!parts) {
|
|
1389
|
+
return null;
|
|
1390
|
+
}
|
|
1391
|
+
return {
|
|
1392
|
+
file: parts[2],
|
|
1393
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1394
|
+
arguments: [],
|
|
1395
|
+
lineNumber: +parts[3],
|
|
1396
|
+
column: parts[4] ? +parts[4] : null
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
var geckoRe = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|rsc|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i;
|
|
1400
|
+
var geckoEvalRe = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
|
|
1401
|
+
function parseGecko(line) {
|
|
1402
|
+
var parts = geckoRe.exec(line);
|
|
1403
|
+
if (!parts) {
|
|
1404
|
+
return null;
|
|
1405
|
+
}
|
|
1406
|
+
var isEval = parts[3] && parts[3].indexOf(" > eval") > -1;
|
|
1407
|
+
var submatch = geckoEvalRe.exec(parts[3]);
|
|
1408
|
+
if (isEval && submatch != null) {
|
|
1409
|
+
parts[3] = submatch[1];
|
|
1410
|
+
parts[4] = submatch[2];
|
|
1411
|
+
parts[5] = null;
|
|
1412
|
+
}
|
|
1413
|
+
return {
|
|
1414
|
+
file: parts[3],
|
|
1415
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1416
|
+
arguments: parts[2] ? parts[2].split(",") : [],
|
|
1417
|
+
lineNumber: parts[4] ? +parts[4] : null,
|
|
1418
|
+
column: parts[5] ? +parts[5] : null
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1421
|
+
var javaScriptCoreRe = /^\s*(?:([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$/i;
|
|
1422
|
+
function parseJSC(line) {
|
|
1423
|
+
var parts = javaScriptCoreRe.exec(line);
|
|
1424
|
+
if (!parts) {
|
|
1425
|
+
return null;
|
|
1426
|
+
}
|
|
1427
|
+
return {
|
|
1428
|
+
file: parts[3],
|
|
1429
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1430
|
+
arguments: [],
|
|
1431
|
+
lineNumber: +parts[4],
|
|
1432
|
+
column: parts[5] ? +parts[5] : null
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
var nodeRe = /^\s*at (?:((?:\[object object\])?[^\\/]+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
1436
|
+
function parseNode(line) {
|
|
1437
|
+
var parts = nodeRe.exec(line);
|
|
1438
|
+
if (!parts) {
|
|
1439
|
+
return null;
|
|
1440
|
+
}
|
|
1441
|
+
return {
|
|
1442
|
+
file: parts[2],
|
|
1443
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1444
|
+
arguments: [],
|
|
1445
|
+
lineNumber: +parts[3],
|
|
1446
|
+
column: parts[4] ? +parts[4] : null
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
// src/build/analyze.ts
|
|
1261
1451
|
function throwExternalDependencyError({
|
|
1262
1452
|
errorId,
|
|
1263
1453
|
moduleName,
|
|
@@ -1281,6 +1471,110 @@ export const mastra = new Mastra({
|
|
|
1281
1471
|
})`
|
|
1282
1472
|
});
|
|
1283
1473
|
}
|
|
1474
|
+
function getPackageNameFromBundledModuleName(moduleName) {
|
|
1475
|
+
const chunks = moduleName.split("-");
|
|
1476
|
+
if (!chunks.length) {
|
|
1477
|
+
return moduleName;
|
|
1478
|
+
}
|
|
1479
|
+
if (chunks[0]?.startsWith("@")) {
|
|
1480
|
+
return chunks.slice(0, 2).join("/");
|
|
1481
|
+
}
|
|
1482
|
+
return chunks[0];
|
|
1483
|
+
}
|
|
1484
|
+
function validateError(err, file, {
|
|
1485
|
+
binaryMapData,
|
|
1486
|
+
workspaceMap
|
|
1487
|
+
}) {
|
|
1488
|
+
let moduleName = null;
|
|
1489
|
+
let errorConfig = null;
|
|
1490
|
+
if (err instanceof ValidationError) {
|
|
1491
|
+
const parsedStack = parse(err.stack);
|
|
1492
|
+
if (err.type === "TypeError") {
|
|
1493
|
+
const pkgNameRegex = /.*node_modules\/([^\/]+)\//;
|
|
1494
|
+
const stacktraceFrame = parsedStack.find((frame) => frame.file && pkgNameRegex.test(frame.file));
|
|
1495
|
+
if (stacktraceFrame) {
|
|
1496
|
+
const match = stacktraceFrame.file.match(pkgNameRegex);
|
|
1497
|
+
moduleName = match?.[1] ?? getPackageNameFromBundledModuleName(path2.basename(file.name));
|
|
1498
|
+
} else {
|
|
1499
|
+
moduleName = getPackageNameFromBundledModuleName(path2.basename(file.name));
|
|
1500
|
+
}
|
|
1501
|
+
errorConfig = {
|
|
1502
|
+
id: "DEPLOYER_ANALYZE_TYPE_ERROR",
|
|
1503
|
+
messagePrefix: `Mastra wasn't able to bundle "${moduleName}", might be an older commonJS module. Please add`
|
|
1504
|
+
};
|
|
1505
|
+
} else if (err.stack?.includes?.("[ERR_MODULE_NOT_FOUND]")) {
|
|
1506
|
+
moduleName = err.message.match(/Cannot find package '([^']+)'/)?.[1];
|
|
1507
|
+
const parentModuleName = getPackageNameFromBundledModuleName(path2.basename(file.name));
|
|
1508
|
+
errorConfig = {
|
|
1509
|
+
id: "DEPLOYER_ANALYZE_MODULE_NOT_FOUND",
|
|
1510
|
+
messagePrefix: `Mastra wasn't able to build your project, We couldn't load "${moduleName}" from "${parentModuleName}". Make sure "${moduleName}" is installed or add`
|
|
1511
|
+
};
|
|
1512
|
+
if (moduleName === parentModuleName) {
|
|
1513
|
+
return;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
if (err.message.includes("No native build was found")) {
|
|
1518
|
+
const pkgName = getPackageNameFromBundledModuleName(path2.basename(file.name));
|
|
1519
|
+
moduleName = binaryMapData[file.fileName]?.[0] ?? pkgName;
|
|
1520
|
+
errorConfig = {
|
|
1521
|
+
id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
|
|
1522
|
+
messagePrefix: "We found a binary dependency in your bundle but we cannot bundle it yet. Please add"
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
1525
|
+
if (moduleName && workspaceMap.has(moduleName)) {
|
|
1526
|
+
throw new error.MastraError({
|
|
1527
|
+
id: "DEPLOYER_ANALYZE_ERROR_IN_WORKSPACE",
|
|
1528
|
+
domain: error.ErrorDomain.DEPLOYER,
|
|
1529
|
+
category: error.ErrorCategory.USER,
|
|
1530
|
+
details: {
|
|
1531
|
+
// importFile: moduleName,
|
|
1532
|
+
packageName: moduleName
|
|
1533
|
+
},
|
|
1534
|
+
text: `We found an error in the ${moduleName} workspace package. Please find the offending package and fix the error.
|
|
1535
|
+
Error: ${err.stack}`
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
if (errorConfig && moduleName) {
|
|
1539
|
+
throwExternalDependencyError({
|
|
1540
|
+
errorId: errorConfig.id,
|
|
1541
|
+
moduleName,
|
|
1542
|
+
packageName: moduleName,
|
|
1543
|
+
messagePrefix: errorConfig.messagePrefix
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
async function validateFile(root, file, {
|
|
1548
|
+
binaryMapData,
|
|
1549
|
+
moduleResolveMapLocation,
|
|
1550
|
+
logger,
|
|
1551
|
+
workspaceMap
|
|
1552
|
+
}) {
|
|
1553
|
+
try {
|
|
1554
|
+
if (!file.isDynamicEntry && file.isEntry) {
|
|
1555
|
+
await validate(path2.join(root, file.fileName), {
|
|
1556
|
+
moduleResolveMapLocation,
|
|
1557
|
+
injectESMShim: false
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
} catch (err) {
|
|
1561
|
+
let errorToHandle = err;
|
|
1562
|
+
if (err instanceof ValidationError && err.type === "ReferenceError" && (err.message.startsWith("__dirname") || err.message.startsWith("__filename"))) {
|
|
1563
|
+
try {
|
|
1564
|
+
await validate(path2.join(root, file.fileName), {
|
|
1565
|
+
moduleResolveMapLocation,
|
|
1566
|
+
injectESMShim: true
|
|
1567
|
+
});
|
|
1568
|
+
errorToHandle = null;
|
|
1569
|
+
} catch (err2) {
|
|
1570
|
+
errorToHandle = err2;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
if (errorToHandle instanceof Error) {
|
|
1574
|
+
validateError(errorToHandle, file, { binaryMapData, workspaceMap });
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1284
1578
|
async function validateOutput({
|
|
1285
1579
|
output,
|
|
1286
1580
|
reverseVirtualReferenceMap,
|
|
@@ -1294,60 +1588,30 @@ async function validateOutput({
|
|
|
1294
1588
|
externalDependencies: /* @__PURE__ */ new Set(),
|
|
1295
1589
|
workspaceMap
|
|
1296
1590
|
};
|
|
1297
|
-
await promises.writeFile(path2.join(outputDir, "module-resolve-map.json"), JSON.stringify(usedExternals, null, 2));
|
|
1298
1591
|
for (const deps of Object.values(usedExternals)) {
|
|
1299
1592
|
for (const dep of Object.keys(deps)) {
|
|
1300
1593
|
result.externalDependencies.add(dep);
|
|
1301
1594
|
}
|
|
1302
1595
|
}
|
|
1596
|
+
let binaryMapData = {};
|
|
1597
|
+
if (fs.existsSync(path2.join(outputDir, "binary-map.json"))) {
|
|
1598
|
+
const binaryMap = await promises.readFile(path2.join(outputDir, "binary-map.json"), "utf-8");
|
|
1599
|
+
binaryMapData = JSON.parse(binaryMap);
|
|
1600
|
+
}
|
|
1303
1601
|
for (const file of output) {
|
|
1304
1602
|
if (file.type === "asset") {
|
|
1305
1603
|
continue;
|
|
1306
1604
|
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
|
|
1311
|
-
}
|
|
1312
|
-
if (!file.isDynamicEntry && file.isEntry) {
|
|
1313
|
-
await validate(path2.join(projectRoot, file.fileName));
|
|
1314
|
-
}
|
|
1315
|
-
} catch (err) {
|
|
1316
|
-
if (err instanceof Error) {
|
|
1317
|
-
let moduleName = null;
|
|
1318
|
-
let errorConfig = null;
|
|
1319
|
-
if (err.message.includes("[ERR_MODULE_NOT_FOUND]")) {
|
|
1320
|
-
const moduleIdName = file.moduleIds.length >= 2 ? file.moduleIds[file.moduleIds.length - 2] : void 0;
|
|
1321
|
-
const fallbackName = file.name.split("/").pop();
|
|
1322
|
-
moduleName = moduleIdName ?? fallbackName;
|
|
1323
|
-
errorConfig = {
|
|
1324
|
-
id: "DEPLOYER_ANALYZE_MODULE_NOT_FOUND",
|
|
1325
|
-
messagePrefix: "Mastra wasn't able to build your project. Please add"
|
|
1326
|
-
};
|
|
1327
|
-
} else if (err.message.includes("Error: No native build was found for ")) {
|
|
1328
|
-
moduleName = findNativePackageModule(file.moduleIds);
|
|
1329
|
-
errorConfig = {
|
|
1330
|
-
id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
|
|
1331
|
-
messagePrefix: "We found a binary dependency in your bundle. Please add"
|
|
1332
|
-
};
|
|
1333
|
-
}
|
|
1334
|
-
if (moduleName && errorConfig) {
|
|
1335
|
-
const pkgInfo = await localPkg.getPackageInfo(moduleName);
|
|
1336
|
-
const packageName = pkgInfo?.packageJson?.name;
|
|
1337
|
-
if (packageName) {
|
|
1338
|
-
throwExternalDependencyError({
|
|
1339
|
-
errorId: errorConfig.id,
|
|
1340
|
-
moduleName,
|
|
1341
|
-
packageName,
|
|
1342
|
-
messagePrefix: errorConfig.messagePrefix
|
|
1343
|
-
});
|
|
1344
|
-
} else {
|
|
1345
|
-
logger.debug(`Could not determine the module name for file ${file.fileName}`);
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
logger.debug(`Error while validating module ${file.fileName}: ${err.message}`);
|
|
1349
|
-
}
|
|
1605
|
+
logger.debug(`Validating if ${file.fileName} is a valid module.`);
|
|
1606
|
+
if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
|
|
1607
|
+
result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
|
|
1350
1608
|
}
|
|
1609
|
+
await validateFile(projectRoot, file, {
|
|
1610
|
+
binaryMapData,
|
|
1611
|
+
moduleResolveMapLocation: path2.join(outputDir, "module-resolve-map.json"),
|
|
1612
|
+
logger,
|
|
1613
|
+
workspaceMap
|
|
1614
|
+
});
|
|
1351
1615
|
}
|
|
1352
1616
|
return result;
|
|
1353
1617
|
}
|
|
@@ -1379,7 +1643,10 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1379
1643
|
const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
|
|
1380
1644
|
let index = 0;
|
|
1381
1645
|
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
1646
|
+
const { externals: customExternals = [] } = bundlerOptions || {};
|
|
1647
|
+
const allExternals = [...GLOBAL_EXTERNALS, ...customExternals];
|
|
1382
1648
|
logger.info("Analyzing dependencies...");
|
|
1649
|
+
const allUsedExternals = /* @__PURE__ */ new Set();
|
|
1383
1650
|
for (const entry of entries) {
|
|
1384
1651
|
const isVirtualFile = entry.includes("\n") || !fs.existsSync(entry);
|
|
1385
1652
|
const analyzeResult = await analyzeEntry({ entry, isVirtualFile }, mastraEntry, {
|
|
@@ -1391,6 +1658,11 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1391
1658
|
});
|
|
1392
1659
|
await promises.writeFile(path2.join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
|
|
1393
1660
|
for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
|
|
1661
|
+
const isPartOfExternals = allExternals.some((external) => chunk3GJSIS6L_cjs.isDependencyPartOfPackage(dep, external));
|
|
1662
|
+
if (isPartOfExternals) {
|
|
1663
|
+
allUsedExternals.add(dep);
|
|
1664
|
+
continue;
|
|
1665
|
+
}
|
|
1394
1666
|
if (depsToOptimize.has(dep)) {
|
|
1395
1667
|
const existingEntry = depsToOptimize.get(dep);
|
|
1396
1668
|
depsToOptimize.set(dep, {
|
|
@@ -1409,14 +1681,13 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1409
1681
|
}
|
|
1410
1682
|
}
|
|
1411
1683
|
}
|
|
1412
|
-
|
|
1684
|
+
const sortedDeps = Array.from(depsToOptimize.keys()).sort();
|
|
1413
1685
|
logger.info("Optimizing dependencies...");
|
|
1414
|
-
logger.debug(
|
|
1415
|
-
`${Array.from(depsToOptimize.keys()).map((key) => `- ${key}`).join("\n")}`
|
|
1416
|
-
);
|
|
1686
|
+
logger.debug(`${sortedDeps.map((key) => `- ${key}`).join("\n")}`);
|
|
1417
1687
|
const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
|
|
1418
1688
|
bundlerOptions: {
|
|
1419
1689
|
...bundlerOptions,
|
|
1690
|
+
externals: allExternals,
|
|
1420
1691
|
enableEsmShim,
|
|
1421
1692
|
isDev
|
|
1422
1693
|
},
|
|
@@ -1435,7 +1706,10 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1435
1706
|
},
|
|
1436
1707
|
logger
|
|
1437
1708
|
);
|
|
1438
|
-
return
|
|
1709
|
+
return {
|
|
1710
|
+
...result,
|
|
1711
|
+
externalDependencies: /* @__PURE__ */ new Set([...result.externalDependencies, ...Array.from(allUsedExternals)])
|
|
1712
|
+
};
|
|
1439
1713
|
}
|
|
1440
1714
|
|
|
1441
1715
|
exports.aliasHono = aliasHono;
|
|
@@ -1444,12 +1718,10 @@ exports.esbuild = esbuild;
|
|
|
1444
1718
|
exports.esmShim = esmShim;
|
|
1445
1719
|
exports.extractMastraOption = extractMastraOption;
|
|
1446
1720
|
exports.getBundlerOptions = getBundlerOptions;
|
|
1447
|
-
exports.getPackageName = getPackageName;
|
|
1448
|
-
exports.getPackageRootPath = getPackageRootPath;
|
|
1449
1721
|
exports.getWorkspaceInformation = getWorkspaceInformation;
|
|
1450
1722
|
exports.removeAllOptionsFromMastraExcept = removeAllOptionsFromMastraExcept;
|
|
1451
1723
|
exports.removeDeployer = removeDeployer2;
|
|
1452
|
-
exports.
|
|
1724
|
+
exports.subpathExternalsResolver = subpathExternalsResolver;
|
|
1453
1725
|
exports.tsConfigPaths = tsConfigPaths;
|
|
1454
|
-
//# sourceMappingURL=chunk-
|
|
1455
|
-
//# sourceMappingURL=chunk-
|
|
1726
|
+
//# sourceMappingURL=chunk-UB6E4QPC.cjs.map
|
|
1727
|
+
//# sourceMappingURL=chunk-UB6E4QPC.cjs.map
|