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