@mastra/deployer 1.0.0-beta.5 → 1.0.0-beta.6
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 +64 -0
- package/dist/arktype-aI7TBD0R-4YXBEQBG.cjs +10 -0
- package/dist/arktype-aI7TBD0R-4YXBEQBG.cjs.map +1 -0
- package/dist/arktype-aI7TBD0R-OEPFT4G6.js +8 -0
- package/dist/arktype-aI7TBD0R-OEPFT4G6.js.map +1 -0
- package/dist/build/analyze/analyzeEntry.d.ts +4 -1
- package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
- 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 +13 -13
- 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.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-EM3VETMX.js → chunk-2O34LWCA.js} +5 -4
- package/dist/chunk-2O34LWCA.js.map +1 -0
- package/dist/chunk-2OTEFUER.cjs +69 -0
- package/dist/chunk-2OTEFUER.cjs.map +1 -0
- package/dist/chunk-5CWPEG6R.js +62 -0
- package/dist/chunk-5CWPEG6R.js.map +1 -0
- package/dist/{chunk-6S5GQUS6.cjs → chunk-74E2QDFC.cjs} +16 -15
- package/dist/chunk-74E2QDFC.cjs.map +1 -0
- package/dist/chunk-7PLNIFGZ.cjs +8 -0
- package/dist/chunk-7PLNIFGZ.cjs.map +1 -0
- package/dist/{chunk-Z7TBDRZ7.cjs → chunk-BCGWTALY.cjs} +12 -20
- package/dist/chunk-BCGWTALY.cjs.map +1 -0
- package/dist/chunk-BTNPI4Z7.cjs +4 -0
- package/dist/chunk-BTNPI4Z7.cjs.map +1 -0
- package/dist/{chunk-Z7KK37HD.js → chunk-CL2TNGFZ.js} +6 -14
- package/dist/chunk-CL2TNGFZ.js.map +1 -0
- package/dist/{chunk-5QFG6SCM.js → chunk-DPDWM7HQ.js} +2 -2
- package/dist/chunk-DPDWM7HQ.js.map +1 -0
- package/dist/chunk-FBT6QP7J.js +3 -0
- package/dist/chunk-FBT6QP7J.js.map +1 -0
- package/dist/chunk-GD2TGMBP.cjs +95 -0
- package/dist/chunk-GD2TGMBP.cjs.map +1 -0
- package/dist/{chunk-QBQY35KA.js → chunk-HQXN5AOP.js} +6 -5
- package/dist/chunk-HQXN5AOP.js.map +1 -0
- package/dist/chunk-ID3HN3BH.cjs +16 -0
- package/dist/chunk-ID3HN3BH.cjs.map +1 -0
- package/dist/{chunk-3JYRSECU.cjs → chunk-JVBCN3RH.cjs} +4 -4
- package/dist/chunk-JVBCN3RH.cjs.map +1 -0
- package/dist/chunk-MMUE22EL.js +159 -0
- package/dist/chunk-MMUE22EL.js.map +1 -0
- package/dist/chunk-N5TMJUIR.js +14 -0
- package/dist/chunk-N5TMJUIR.js.map +1 -0
- package/dist/{chunk-NK3AYZ6D.js → chunk-NFK4J35T.js} +526 -173
- package/dist/chunk-NFK4J35T.js.map +1 -0
- package/dist/chunk-P4L6VIHY.js +93 -0
- package/dist/chunk-P4L6VIHY.js.map +1 -0
- package/dist/{chunk-WFL4V5AW.cjs → chunk-PRPZEAA3.cjs} +539 -188
- package/dist/chunk-PRPZEAA3.cjs.map +1 -0
- package/dist/chunk-Q2YGWEXY.js +6 -0
- package/dist/chunk-Q2YGWEXY.js.map +1 -0
- package/dist/chunk-TXKETRIN.cjs +162 -0
- package/dist/chunk-TXKETRIN.cjs.map +1 -0
- package/dist/{chunk-NVCHGD24.cjs → chunk-XJAHDG3S.cjs} +15 -14
- package/dist/chunk-XJAHDG3S.cjs.map +1 -0
- package/dist/default-u_dwuiYb-65M4BHAA.js +3 -0
- package/dist/default-u_dwuiYb-65M4BHAA.js.map +1 -0
- package/dist/default-u_dwuiYb-PWN6FHC6.cjs +9 -0
- package/dist/default-u_dwuiYb-PWN6FHC6.cjs.map +1 -0
- package/dist/deploy/log.d.ts +1 -1
- package/dist/deploy/log.d.ts.map +1 -1
- package/dist/effect-QlVUlMFu-2ADPKIDF.cjs +17 -0
- package/dist/effect-QlVUlMFu-2ADPKIDF.cjs.map +1 -0
- package/dist/effect-QlVUlMFu-FD73M3OO.js +15 -0
- package/dist/effect-QlVUlMFu-FD73M3OO.js.map +1 -0
- package/dist/esm-BLVTLTJW.js +1289 -0
- package/dist/esm-BLVTLTJW.js.map +1 -0
- package/dist/esm-E3NUCNVN.cjs +1336 -0
- package/dist/esm-E3NUCNVN.cjs.map +1 -0
- package/dist/index.cjs +12 -12
- package/dist/index.js +4 -4
- package/dist/server/index.cjs +1113 -1508
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1101 -1496
- package/dist/server/index.js.map +1 -1
- package/dist/services/index.cjs +4 -4
- package/dist/services/index.js +1 -1
- package/dist/sury-CWZTCd75-K3FHMZF5.cjs +17 -0
- package/dist/sury-CWZTCd75-K3FHMZF5.cjs.map +1 -0
- package/dist/sury-CWZTCd75-Y2GURJ6K.js +15 -0
- package/dist/sury-CWZTCd75-Y2GURJ6K.js.map +1 -0
- package/dist/typebox-Dei93FPO-2WP4NOYD.js +8 -0
- package/dist/typebox-Dei93FPO-2WP4NOYD.js.map +1 -0
- package/dist/typebox-Dei93FPO-WTXAW2LA.cjs +10 -0
- package/dist/typebox-Dei93FPO-WTXAW2LA.cjs.map +1 -0
- package/dist/valibot--1zFm7rT-HMTCRBB3.cjs +17 -0
- package/dist/valibot--1zFm7rT-HMTCRBB3.cjs.map +1 -0
- package/dist/valibot--1zFm7rT-VGFBTDTW.js +15 -0
- package/dist/valibot--1zFm7rT-VGFBTDTW.js.map +1 -0
- package/dist/valibot-D_HTw1Gn-ILCWWLE4.cjs +45 -0
- package/dist/valibot-D_HTw1Gn-ILCWWLE4.cjs.map +1 -0
- package/dist/valibot-D_HTw1Gn-LLCGNU3W.js +43 -0
- package/dist/valibot-D_HTw1Gn-LLCGNU3W.js.map +1 -0
- 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/dist/zod-Bwrt9trS-XCRGYQVE.js +29 -0
- package/dist/zod-Bwrt9trS-XCRGYQVE.js.map +1 -0
- package/dist/zod-Bwrt9trS-XDMWF3NW.cjs +31 -0
- package/dist/zod-Bwrt9trS-XDMWF3NW.cjs.map +1 -0
- package/dist/zod-DSgpEGAE-TKBHSSLS.js +37 -0
- package/dist/zod-DSgpEGAE-TKBHSSLS.js.map +1 -0
- package/dist/zod-DSgpEGAE-ZWQMF6SS.cjs +39 -0
- package/dist/zod-DSgpEGAE-ZWQMF6SS.cjs.map +1 -0
- package/package.json +8 -6
- package/dist/chunk-3JYRSECU.cjs.map +0 -1
- package/dist/chunk-5QFG6SCM.js.map +0 -1
- package/dist/chunk-6S5GQUS6.cjs.map +0 -1
- package/dist/chunk-EM3VETMX.js.map +0 -1
- package/dist/chunk-NK3AYZ6D.js.map +0 -1
- package/dist/chunk-NVCHGD24.cjs.map +0 -1
- package/dist/chunk-QBQY35KA.js.map +0 -1
- package/dist/chunk-WFL4V5AW.cjs.map +0 -1
- package/dist/chunk-Z7KK37HD.js.map +0 -1
- package/dist/chunk-Z7TBDRZ7.cjs.map +0 -1
- package/dist/server/handlers/auth/defaults.d.ts +0 -3
- package/dist/server/handlers/auth/defaults.d.ts.map +0 -1
- package/dist/server/handlers/auth/helpers.d.ts +0 -11
- package/dist/server/handlers/auth/helpers.d.ts.map +0 -1
- package/dist/server/handlers/auth/index.d.ts +0 -11
- package/dist/server/handlers/auth/index.d.ts.map +0 -1
- package/dist/server/handlers/mcp.d.ts +0 -86
- package/dist/server/handlers/mcp.d.ts.map +0 -1
- package/dist/server/schemas/mcp.d.ts +0 -230
- package/dist/server/schemas/mcp.d.ts.map +0 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import { slash, isDependencyPartOfPackage, getPackageRootPath, getPackageName, getCompiledDepCachePath, rollupSafeName } from './chunk-5CWPEG6R.js';
|
|
1
2
|
import * as babel from '@babel/core';
|
|
2
3
|
import babel__default from '@babel/core';
|
|
3
4
|
import fs, { existsSync } from 'fs';
|
|
4
5
|
import { readFile, writeFile } from 'fs/promises';
|
|
5
6
|
import * as path2 from 'path';
|
|
6
|
-
import path2__default, { dirname, join, normalize,
|
|
7
|
+
import path2__default, { dirname, join, normalize, basename as basename$1 } from 'path';
|
|
7
8
|
import { spawn as spawn$1 } from 'child_process';
|
|
8
|
-
import { getPackageInfo } from 'local-pkg';
|
|
9
|
-
import { pathToFileURL, fileURLToPath } from 'url';
|
|
10
9
|
import { rollup } from 'rollup';
|
|
11
10
|
import originalEsbuild from 'rollup-plugin-esbuild';
|
|
12
11
|
import commonjs from '@rollup/plugin-commonjs';
|
|
@@ -18,90 +17,27 @@ import * as pkg from 'empathic/package';
|
|
|
18
17
|
import { createWorkspacesCache, findWorkspaces, findWorkspacesRoot } from 'find-workspaces';
|
|
19
18
|
import { noopLogger } from '@mastra/core/logger';
|
|
20
19
|
import virtual from '@rollup/plugin-virtual';
|
|
20
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
21
21
|
import { builtinModules } from 'module';
|
|
22
22
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
23
23
|
import esmShim from '@rollup/plugin-esm-shim';
|
|
24
24
|
import { basename } from 'path/posix';
|
|
25
25
|
import * as resolve from 'resolve.exports';
|
|
26
|
+
import { getPackageInfo } from 'local-pkg';
|
|
26
27
|
import { MastraBaseError, ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
var ValidationError = class extends Error {
|
|
30
|
+
type;
|
|
31
|
+
stack;
|
|
32
|
+
constructor(args) {
|
|
33
|
+
super(args.message);
|
|
34
|
+
this.type = args.type;
|
|
35
|
+
this.stack = args.stack;
|
|
33
36
|
}
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
async function getPackageRootPath(packageName, parentPath) {
|
|
37
|
-
let rootPath;
|
|
38
|
-
try {
|
|
39
|
-
let options = void 0;
|
|
40
|
-
if (parentPath) {
|
|
41
|
-
if (!parentPath.startsWith("file://")) {
|
|
42
|
-
parentPath = pathToFileURL(parentPath).href;
|
|
43
|
-
}
|
|
44
|
-
options = {
|
|
45
|
-
paths: [parentPath]
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const pkg2 = await getPackageInfo(packageName, options);
|
|
49
|
-
rootPath = pkg2?.rootPath ?? null;
|
|
50
|
-
} catch (e) {
|
|
51
|
-
rootPath = null;
|
|
52
|
-
}
|
|
53
|
-
return rootPath;
|
|
54
|
-
}
|
|
55
|
-
function getCompiledDepCachePath(rootPath, packageName) {
|
|
56
|
-
return slash(join(rootPath, "node_modules", ".cache", packageName));
|
|
57
|
-
}
|
|
58
|
-
function slash(path3) {
|
|
59
|
-
const isExtendedLengthPath = path3.startsWith("\\\\?\\");
|
|
60
|
-
if (isExtendedLengthPath) {
|
|
61
|
-
return path3;
|
|
62
|
-
}
|
|
63
|
-
return path3.replaceAll("\\", "/");
|
|
64
|
-
}
|
|
65
|
-
function rollupSafeName(name, rootDir) {
|
|
66
|
-
const rel = relative(rootDir, name);
|
|
67
|
-
let entry = slash(rel);
|
|
68
|
-
entry = entry.replace(/^(\.\.\/)+/, "");
|
|
69
|
-
entry = entry.replace(/^\/+/, "");
|
|
70
|
-
entry = entry.replace(/^[A-Za-z]:\//, "");
|
|
71
|
-
if (!entry) {
|
|
72
|
-
entry = slash(basename$1(name));
|
|
73
|
-
}
|
|
74
|
-
return entry;
|
|
75
|
-
}
|
|
76
|
-
var NATIVE_BINDING_LOADERS = [
|
|
77
|
-
"node-gyp-build",
|
|
78
|
-
"prebuild-install",
|
|
79
|
-
"bindings",
|
|
80
|
-
"node-addon-api",
|
|
81
|
-
"node-pre-gyp",
|
|
82
|
-
"nan"
|
|
83
|
-
// Native Abstractions for Node.js
|
|
84
|
-
];
|
|
85
|
-
function findNativePackageModule(moduleIds) {
|
|
86
|
-
return moduleIds.find((id) => {
|
|
87
|
-
if (id.startsWith("\0")) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
if (!id.includes("/node_modules/")) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
for (const loader of NATIVE_BINDING_LOADERS) {
|
|
94
|
-
if (id.includes(`/${loader}/`) || id.includes(`/${loader}@`)) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return true;
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// src/validator/validate.ts
|
|
37
|
+
};
|
|
103
38
|
function spawn(command, args = [], options = {}) {
|
|
104
39
|
return new Promise((resolve2, reject) => {
|
|
40
|
+
let validationError = null;
|
|
105
41
|
const childProcess = spawn$1(command, args, {
|
|
106
42
|
// stdio: 'inherit',
|
|
107
43
|
...options
|
|
@@ -111,28 +47,63 @@ function spawn(command, args = [], options = {}) {
|
|
|
111
47
|
});
|
|
112
48
|
let stderr = "";
|
|
113
49
|
childProcess.stderr?.on("data", (message) => {
|
|
114
|
-
|
|
50
|
+
try {
|
|
51
|
+
validationError = JSON.parse(message.toString());
|
|
52
|
+
} catch {
|
|
53
|
+
stderr += message;
|
|
54
|
+
}
|
|
115
55
|
});
|
|
116
56
|
childProcess.on("close", (code) => {
|
|
117
57
|
if (code === 0) {
|
|
118
58
|
resolve2();
|
|
119
59
|
} else {
|
|
120
|
-
|
|
60
|
+
if (validationError) {
|
|
61
|
+
reject(new ValidationError(validationError));
|
|
62
|
+
} else {
|
|
63
|
+
reject(new Error(stderr));
|
|
64
|
+
}
|
|
121
65
|
}
|
|
122
66
|
});
|
|
123
67
|
});
|
|
124
68
|
}
|
|
125
|
-
function validate(file) {
|
|
69
|
+
function validate(file, { injectESMShim = false, moduleResolveMapLocation }) {
|
|
70
|
+
let prefixCode = "";
|
|
71
|
+
if (injectESMShim) {
|
|
72
|
+
prefixCode = `import { fileURLToPath } from 'url';
|
|
73
|
+
import { dirname } from 'path';
|
|
74
|
+
|
|
75
|
+
globalThis.__filename = fileURLToPath(import.meta.url);
|
|
76
|
+
globalThis.__dirname = dirname(__filename);
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
function errorHandler(err) {
|
|
80
|
+
console.error(
|
|
81
|
+
JSON.stringify({
|
|
82
|
+
type: err.name,
|
|
83
|
+
message: err.message,
|
|
84
|
+
stack: err.stack
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
126
89
|
return spawn(
|
|
127
|
-
|
|
90
|
+
process.execPath,
|
|
128
91
|
[
|
|
129
92
|
"--import",
|
|
130
93
|
import.meta.resolve("@mastra/deployer/loader"),
|
|
131
94
|
"--input-type=module",
|
|
95
|
+
"--enable-source-maps",
|
|
132
96
|
"-e",
|
|
133
|
-
|
|
97
|
+
`${prefixCode};import('file://${slash(file)}').catch(err => {
|
|
98
|
+
${errorHandler.toString()}
|
|
99
|
+
errorHandler(err);
|
|
100
|
+
})`.replaceAll(/\n/g, "")
|
|
134
101
|
],
|
|
135
102
|
{
|
|
103
|
+
env: {
|
|
104
|
+
...process.env,
|
|
105
|
+
MODULE_MAP: `${moduleResolveMapLocation}`
|
|
106
|
+
},
|
|
136
107
|
cwd: dirname(file)
|
|
137
108
|
}
|
|
138
109
|
);
|
|
@@ -228,28 +199,88 @@ function esbuild(options = {}) {
|
|
|
228
199
|
}
|
|
229
200
|
var PLUGIN_NAME = "tsconfig-paths";
|
|
230
201
|
function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve } = {}) {
|
|
231
|
-
|
|
202
|
+
const handlerCache = /* @__PURE__ */ new Map();
|
|
203
|
+
function findTsConfigForFile(filePath) {
|
|
204
|
+
let currentDir = path2__default.dirname(filePath);
|
|
205
|
+
const root = path2__default.parse(currentDir).root;
|
|
206
|
+
while (currentDir !== root) {
|
|
207
|
+
const tsConfigPath2 = path2__default.join(currentDir, "tsconfig.json");
|
|
208
|
+
if (fs.existsSync(tsConfigPath2)) {
|
|
209
|
+
if (hasPaths(tsConfigPath2)) {
|
|
210
|
+
return tsConfigPath2;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const tsConfigBasePath = path2__default.join(currentDir, "tsconfig.base.json");
|
|
214
|
+
if (fs.existsSync(tsConfigBasePath)) {
|
|
215
|
+
if (hasPaths(tsConfigBasePath)) {
|
|
216
|
+
return tsConfigBasePath;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
currentDir = path2__default.dirname(currentDir);
|
|
220
|
+
}
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
function hasPaths(tsConfigPath2) {
|
|
224
|
+
try {
|
|
225
|
+
const config = JSON.parse(fs.readFileSync(tsConfigPath2, "utf8"));
|
|
226
|
+
return !!(config.compilerOptions?.paths && Object.keys(config.compilerOptions.paths).length > 0);
|
|
227
|
+
} catch {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function getHandlerForFile(filePath) {
|
|
232
|
+
if (tsConfigPath && typeof tsConfigPath === "string") {
|
|
233
|
+
if (!handlerCache.has(tsConfigPath)) {
|
|
234
|
+
handlerCache.set(
|
|
235
|
+
tsConfigPath,
|
|
236
|
+
createHandler({
|
|
237
|
+
log: () => {
|
|
238
|
+
},
|
|
239
|
+
tsConfigPath,
|
|
240
|
+
respectCoreModule,
|
|
241
|
+
falllback: (moduleName) => fs.existsSync(moduleName)
|
|
242
|
+
})
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
return handlerCache.get(tsConfigPath);
|
|
246
|
+
}
|
|
247
|
+
const configPath = findTsConfigForFile(filePath);
|
|
248
|
+
if (!configPath) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
if (!handlerCache.has(configPath)) {
|
|
252
|
+
handlerCache.set(
|
|
253
|
+
configPath,
|
|
254
|
+
createHandler({
|
|
255
|
+
log: () => {
|
|
256
|
+
},
|
|
257
|
+
tsConfigPath: configPath,
|
|
258
|
+
respectCoreModule,
|
|
259
|
+
falllback: (moduleName) => fs.existsSync(moduleName)
|
|
260
|
+
})
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
return handlerCache.get(configPath);
|
|
264
|
+
}
|
|
265
|
+
function resolveAlias(request, importer) {
|
|
266
|
+
const dynamicHandler = getHandlerForFile(importer);
|
|
267
|
+
if (!dynamicHandler) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
const resolved = dynamicHandler(request, normalize(importer));
|
|
271
|
+
return resolved;
|
|
272
|
+
}
|
|
232
273
|
return {
|
|
233
274
|
name: PLUGIN_NAME,
|
|
234
|
-
buildStart() {
|
|
235
|
-
handler = createHandler({
|
|
236
|
-
log: () => {
|
|
237
|
-
},
|
|
238
|
-
tsConfigPath,
|
|
239
|
-
respectCoreModule,
|
|
240
|
-
falllback: (moduleName) => fs.existsSync(moduleName)
|
|
241
|
-
});
|
|
242
|
-
return;
|
|
243
|
-
},
|
|
244
275
|
async resolveId(request, importer, options) {
|
|
245
|
-
if (!importer || request.startsWith("\0")) {
|
|
276
|
+
if (!importer || request.startsWith("\0") || importer.startsWith("\0")) {
|
|
246
277
|
return null;
|
|
247
278
|
}
|
|
248
|
-
const moduleName =
|
|
279
|
+
const moduleName = resolveAlias(request, importer);
|
|
249
280
|
if (!moduleName) {
|
|
250
281
|
let importerMeta = {};
|
|
251
|
-
const
|
|
252
|
-
if (!
|
|
282
|
+
const resolved2 = await this.resolve(request, importer, { skipSelf: true, ...options });
|
|
283
|
+
if (!resolved2) {
|
|
253
284
|
return null;
|
|
254
285
|
}
|
|
255
286
|
if (localResolve) {
|
|
@@ -257,37 +288,42 @@ function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve } = {}) {
|
|
|
257
288
|
importerMeta = importerInfo?.meta || {};
|
|
258
289
|
if (!request.startsWith("./") && !request.startsWith("../") && importerMeta?.[PLUGIN_NAME]?.resolved) {
|
|
259
290
|
return {
|
|
260
|
-
...
|
|
291
|
+
...resolved2,
|
|
261
292
|
external: !request.startsWith("hono/") && request !== "hono"
|
|
262
293
|
};
|
|
263
294
|
}
|
|
264
295
|
}
|
|
265
296
|
return {
|
|
266
|
-
...
|
|
297
|
+
...resolved2,
|
|
267
298
|
meta: {
|
|
268
|
-
...
|
|
299
|
+
...resolved2.meta || {},
|
|
269
300
|
...importerMeta
|
|
270
301
|
}
|
|
271
302
|
};
|
|
272
303
|
}
|
|
273
304
|
if (!path2__default.extname(moduleName)) {
|
|
274
|
-
const
|
|
275
|
-
if (!
|
|
305
|
+
const resolved2 = await this.resolve(moduleName, importer, { skipSelf: true, ...options });
|
|
306
|
+
if (!resolved2) {
|
|
276
307
|
return null;
|
|
277
308
|
}
|
|
278
309
|
return {
|
|
279
|
-
...
|
|
310
|
+
...resolved2,
|
|
280
311
|
meta: {
|
|
281
|
-
...
|
|
312
|
+
...resolved2.meta,
|
|
282
313
|
[PLUGIN_NAME]: {
|
|
283
314
|
resolved: true
|
|
284
315
|
}
|
|
285
316
|
}
|
|
286
317
|
};
|
|
287
318
|
}
|
|
319
|
+
const resolved = await this.resolve(moduleName, importer, { skipSelf: true, ...options });
|
|
320
|
+
if (!resolved) {
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
288
323
|
return {
|
|
289
|
-
|
|
324
|
+
...resolved,
|
|
290
325
|
meta: {
|
|
326
|
+
...resolved.meta,
|
|
291
327
|
[PLUGIN_NAME]: {
|
|
292
328
|
resolved: true
|
|
293
329
|
}
|
|
@@ -666,7 +702,8 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
|
|
|
666
702
|
return plugins;
|
|
667
703
|
}
|
|
668
704
|
async function captureDependenciesToOptimize(output, workspaceMap, projectRoot, initialDepsToOptimize, {
|
|
669
|
-
logger
|
|
705
|
+
logger,
|
|
706
|
+
shouldCheckTransitiveDependencies
|
|
670
707
|
}) {
|
|
671
708
|
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
672
709
|
if (!output.facadeModuleId) {
|
|
@@ -690,7 +727,11 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
|
|
|
690
727
|
isWorkspace = workspaceMap.has(pkgName);
|
|
691
728
|
}
|
|
692
729
|
const normalizedRootPath = rootPath ? slash(rootPath) : null;
|
|
693
|
-
depsToOptimize.set(dependency, {
|
|
730
|
+
depsToOptimize.set(dependency, {
|
|
731
|
+
exports: bindings,
|
|
732
|
+
rootPath: normalizedRootPath,
|
|
733
|
+
isWorkspace
|
|
734
|
+
});
|
|
694
735
|
}
|
|
695
736
|
async function checkTransitiveDependencies(internalMap, maxDepth = 10, currentDepth = 0) {
|
|
696
737
|
if (currentDepth >= maxDepth) {
|
|
@@ -734,12 +775,18 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
|
|
|
734
775
|
await checkTransitiveDependencies(internalMap, maxDepth, currentDepth + 1);
|
|
735
776
|
}
|
|
736
777
|
}
|
|
737
|
-
|
|
778
|
+
if (shouldCheckTransitiveDependencies) {
|
|
779
|
+
await checkTransitiveDependencies(initialDepsToOptimize);
|
|
780
|
+
}
|
|
738
781
|
const dynamicImports = output.dynamicImports.filter((d) => !DEPS_TO_IGNORE.includes(d));
|
|
739
782
|
if (dynamicImports.length) {
|
|
740
783
|
for (const dynamicImport of dynamicImports) {
|
|
741
784
|
if (!depsToOptimize.has(dynamicImport) && !isNodeBuiltin(dynamicImport)) {
|
|
742
|
-
depsToOptimize.set(dynamicImport, {
|
|
785
|
+
depsToOptimize.set(dynamicImport, {
|
|
786
|
+
exports: ["*"],
|
|
787
|
+
rootPath: null,
|
|
788
|
+
isWorkspace: false
|
|
789
|
+
});
|
|
743
790
|
}
|
|
744
791
|
}
|
|
745
792
|
}
|
|
@@ -753,8 +800,9 @@ async function analyzeEntry({
|
|
|
753
800
|
sourcemapEnabled,
|
|
754
801
|
workspaceMap,
|
|
755
802
|
projectRoot,
|
|
756
|
-
initialDepsToOptimize = /* @__PURE__ */ new Map()
|
|
803
|
+
initialDepsToOptimize = /* @__PURE__ */ new Map(),
|
|
757
804
|
// used to avoid infinite recursion
|
|
805
|
+
shouldCheckTransitiveDependencies = false
|
|
758
806
|
}) {
|
|
759
807
|
const optimizerBundler = await rollup({
|
|
760
808
|
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
@@ -775,7 +823,8 @@ async function analyzeEntry({
|
|
|
775
823
|
projectRoot,
|
|
776
824
|
initialDepsToOptimize,
|
|
777
825
|
{
|
|
778
|
-
logger
|
|
826
|
+
logger,
|
|
827
|
+
shouldCheckTransitiveDependencies
|
|
779
828
|
}
|
|
780
829
|
);
|
|
781
830
|
return {
|
|
@@ -798,6 +847,114 @@ function aliasHono() {
|
|
|
798
847
|
}
|
|
799
848
|
};
|
|
800
849
|
}
|
|
850
|
+
function nodeGypDetector() {
|
|
851
|
+
const modulesToTrack = /* @__PURE__ */ new Set();
|
|
852
|
+
const modulesToTrackPackageInfo = /* @__PURE__ */ new Map();
|
|
853
|
+
return {
|
|
854
|
+
name: "node-gyp-build-detector",
|
|
855
|
+
moduleParsed(info) {
|
|
856
|
+
if (!info.meta?.commonjs?.requires?.length) {
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
const hasNodeGypBuild = info.meta.commonjs.requires.some(
|
|
860
|
+
(m) => m?.resolved?.id.endsWith("node-gyp-build/index.js")
|
|
861
|
+
);
|
|
862
|
+
if (!hasNodeGypBuild) {
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
modulesToTrack.add(info.id);
|
|
866
|
+
modulesToTrackPackageInfo.set(info.id, getPackageInfo(info.id));
|
|
867
|
+
},
|
|
868
|
+
async generateBundle(options, bundle) {
|
|
869
|
+
const binaryMapByChunk = /* @__PURE__ */ new Map();
|
|
870
|
+
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
871
|
+
if (chunk.type === "chunk") {
|
|
872
|
+
for (const moduleId of chunk.moduleIds) {
|
|
873
|
+
if (modulesToTrackPackageInfo.has(moduleId)) {
|
|
874
|
+
const pkgInfo = await modulesToTrackPackageInfo.get(moduleId);
|
|
875
|
+
if (!binaryMapByChunk.has(fileName)) {
|
|
876
|
+
binaryMapByChunk.set(fileName, /* @__PURE__ */ new Set());
|
|
877
|
+
}
|
|
878
|
+
if (pkgInfo?.packageJson?.name) {
|
|
879
|
+
binaryMapByChunk.get(fileName).add(pkgInfo.packageJson.name);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
const binaryMapJson = Object.fromEntries(
|
|
886
|
+
Array.from(binaryMapByChunk.entries()).map(([key, value]) => [key, Array.from(value)])
|
|
887
|
+
);
|
|
888
|
+
this.emitFile({
|
|
889
|
+
type: "asset",
|
|
890
|
+
name: "binary-map.json",
|
|
891
|
+
source: `${JSON.stringify(binaryMapJson, null, 2)}`
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// src/build/plugins/subpath-externals-resolver.ts
|
|
898
|
+
function subpathExternalsResolver(externals) {
|
|
899
|
+
return {
|
|
900
|
+
name: "subpath-externals-resolver",
|
|
901
|
+
resolveId(id) {
|
|
902
|
+
if (id.startsWith(".") || id.startsWith("/")) {
|
|
903
|
+
return null;
|
|
904
|
+
}
|
|
905
|
+
const isPartOfExternals = externals.some((external) => isDependencyPartOfPackage(id, external));
|
|
906
|
+
if (isPartOfExternals) {
|
|
907
|
+
return {
|
|
908
|
+
id,
|
|
909
|
+
external: true
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
function moduleResolveMap(externals, projectRoot) {
|
|
916
|
+
const importMap = /* @__PURE__ */ new Map();
|
|
917
|
+
return {
|
|
918
|
+
name: "module-resolve-map",
|
|
919
|
+
moduleParsed(info) {
|
|
920
|
+
if (info.importedIds.length === 0 || !info.id) {
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
for (const importedId of info.importedIds) {
|
|
924
|
+
for (const external of externals) {
|
|
925
|
+
if (isDependencyPartOfPackage(importedId, external)) {
|
|
926
|
+
importMap.set(external, info.id);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
},
|
|
931
|
+
async generateBundle(options, bundle) {
|
|
932
|
+
const resolveMap = /* @__PURE__ */ new Map();
|
|
933
|
+
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
934
|
+
if (chunk.type === "chunk") {
|
|
935
|
+
for (const [external, resolvedFrom] of importMap) {
|
|
936
|
+
if (chunk.moduleIds.includes(resolvedFrom)) {
|
|
937
|
+
const fullPath = pathToFileURL(slash(join(projectRoot, fileName))).toString();
|
|
938
|
+
const innerMap = resolveMap.get(fullPath) || /* @__PURE__ */ new Map();
|
|
939
|
+
innerMap.set(external, pathToFileURL(slash(resolvedFrom)).toString());
|
|
940
|
+
resolveMap.set(fullPath, innerMap);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
const resolveMapJson = Object.fromEntries(
|
|
946
|
+
Array.from(resolveMap.entries()).map(([key, value]) => [key, Object.fromEntries(value.entries())])
|
|
947
|
+
);
|
|
948
|
+
this.emitFile({
|
|
949
|
+
type: "asset",
|
|
950
|
+
name: "module-resolve-map.json",
|
|
951
|
+
source: `${JSON.stringify(resolveMapJson, null, 2)}`
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// src/build/analyze/bundleExternals.ts
|
|
801
958
|
function prepareEntryFileName(name, rootDir) {
|
|
802
959
|
return rollupSafeName(name, rootDir);
|
|
803
960
|
}
|
|
@@ -863,7 +1020,8 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
863
1020
|
transpilePackages,
|
|
864
1021
|
workspaceMap,
|
|
865
1022
|
bundlerOptions,
|
|
866
|
-
rootDir
|
|
1023
|
+
rootDir,
|
|
1024
|
+
externals
|
|
867
1025
|
}) {
|
|
868
1026
|
const transpilePackagesMap = /* @__PURE__ */ new Map();
|
|
869
1027
|
for (const pkg2 of transpilePackages) {
|
|
@@ -884,6 +1042,7 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
884
1042
|
{}
|
|
885
1043
|
)
|
|
886
1044
|
),
|
|
1045
|
+
subpathExternalsResolver(externals),
|
|
887
1046
|
transpilePackagesMap.size ? esbuild({
|
|
888
1047
|
format: "esm",
|
|
889
1048
|
include: [...transpilePackagesMap.values()].map((p) => {
|
|
@@ -912,7 +1071,8 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
912
1071
|
if (!resolvedPath) {
|
|
913
1072
|
resolvedPath = pkgJson.main ?? "index.js";
|
|
914
1073
|
}
|
|
915
|
-
|
|
1074
|
+
const resolved = await this.resolve(path2.posix.join(packageRootPath, resolvedPath), importer, options);
|
|
1075
|
+
return resolved;
|
|
916
1076
|
}
|
|
917
1077
|
} : null,
|
|
918
1078
|
optimizeLodashImports({
|
|
@@ -931,6 +1091,8 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
931
1091
|
// hono is imported from deployer, so we need to resolve from here instead of the project root
|
|
932
1092
|
aliasHono(),
|
|
933
1093
|
json(),
|
|
1094
|
+
nodeGypDetector(),
|
|
1095
|
+
moduleResolveMap(externals, rootDir),
|
|
934
1096
|
{
|
|
935
1097
|
name: "not-found-resolver",
|
|
936
1098
|
resolveId: {
|
|
@@ -988,12 +1150,13 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
988
1150
|
{}
|
|
989
1151
|
),
|
|
990
1152
|
external: externals,
|
|
991
|
-
treeshake: "safest",
|
|
1153
|
+
treeshake: bundlerOptions.isDev ? false : "safest",
|
|
992
1154
|
plugins: getInputPlugins2(virtualDependencies, {
|
|
993
1155
|
transpilePackages: packagesToTranspile,
|
|
994
1156
|
workspaceMap,
|
|
995
1157
|
bundlerOptions,
|
|
996
|
-
rootDir
|
|
1158
|
+
rootDir,
|
|
1159
|
+
externals
|
|
997
1160
|
})
|
|
998
1161
|
});
|
|
999
1162
|
const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
|
|
@@ -1001,6 +1164,8 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1001
1164
|
format: "esm",
|
|
1002
1165
|
dir: rootDir,
|
|
1003
1166
|
entryFileNames: "[name].mjs",
|
|
1167
|
+
// used to get the filename of the actual error
|
|
1168
|
+
sourcemap: true,
|
|
1004
1169
|
/**
|
|
1005
1170
|
* Rollup creates chunks for common dependencies, but these chunks are by default written to the root directory instead of respecting the entryFileNames structure.
|
|
1006
1171
|
* So we want to write them to the `.mastra/output` folder as well.
|
|
@@ -1038,6 +1203,7 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1038
1203
|
}
|
|
1039
1204
|
return `${outputDirRelative}/[name].mjs`;
|
|
1040
1205
|
},
|
|
1206
|
+
assetFileNames: `${outputDirRelative}/[name][extname]`,
|
|
1041
1207
|
hoistTransitiveImports: false
|
|
1042
1208
|
});
|
|
1043
1209
|
await bundler.close();
|
|
@@ -1046,7 +1212,7 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1046
1212
|
function findExternalImporter(module, external, allOutputs) {
|
|
1047
1213
|
const capturedFiles = /* @__PURE__ */ new Set();
|
|
1048
1214
|
for (const id of module.imports) {
|
|
1049
|
-
if (id
|
|
1215
|
+
if (isDependencyPartOfPackage(id, external)) {
|
|
1050
1216
|
return module;
|
|
1051
1217
|
} else {
|
|
1052
1218
|
if (id.endsWith(".mjs")) {
|
|
@@ -1092,7 +1258,7 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1092
1258
|
isDev
|
|
1093
1259
|
}
|
|
1094
1260
|
});
|
|
1095
|
-
const
|
|
1261
|
+
const moduleResolveMap2 = /* @__PURE__ */ new Map();
|
|
1096
1262
|
const filteredChunks = output.filter((o) => o.type === "chunk");
|
|
1097
1263
|
for (const o of filteredChunks.filter((o2) => o2.isEntry || o2.isDynamicEntry)) {
|
|
1098
1264
|
for (const external of allExternals) {
|
|
@@ -1102,10 +1268,10 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1102
1268
|
const importer = findExternalImporter(o, external, filteredChunks);
|
|
1103
1269
|
if (importer) {
|
|
1104
1270
|
const fullPath = path2.join(workspaceRoot || projectRoot, importer.fileName);
|
|
1105
|
-
let innerMap =
|
|
1271
|
+
let innerMap = moduleResolveMap2.get(fullPath);
|
|
1106
1272
|
if (!innerMap) {
|
|
1107
1273
|
innerMap = /* @__PURE__ */ new Map();
|
|
1108
|
-
|
|
1274
|
+
moduleResolveMap2.set(fullPath, innerMap);
|
|
1109
1275
|
}
|
|
1110
1276
|
if (importer.moduleIds.length) {
|
|
1111
1277
|
innerMap.set(
|
|
@@ -1117,7 +1283,7 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1117
1283
|
}
|
|
1118
1284
|
}
|
|
1119
1285
|
const usedExternals = /* @__PURE__ */ Object.create(null);
|
|
1120
|
-
for (const [fullPath, innerMap] of
|
|
1286
|
+
for (const [fullPath, innerMap] of moduleResolveMap2) {
|
|
1121
1287
|
const innerObj = /* @__PURE__ */ Object.create(null);
|
|
1122
1288
|
for (const [external, value] of innerMap) {
|
|
1123
1289
|
innerObj[external] = value;
|
|
@@ -1126,6 +1292,108 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1126
1292
|
}
|
|
1127
1293
|
return { output, fileNameToDependencyMap, usedExternals };
|
|
1128
1294
|
}
|
|
1295
|
+
|
|
1296
|
+
// ../../node_modules/.pnpm/stacktrace-parser@0.1.11/node_modules/stacktrace-parser/dist/stack-trace-parser.esm.js
|
|
1297
|
+
var UNKNOWN_FUNCTION = "<unknown>";
|
|
1298
|
+
function parse(stackString) {
|
|
1299
|
+
var lines = stackString.split("\n");
|
|
1300
|
+
return lines.reduce(function(stack, line) {
|
|
1301
|
+
var parseResult = parseChrome(line) || parseWinjs(line) || parseGecko(line) || parseNode(line) || parseJSC(line);
|
|
1302
|
+
if (parseResult) {
|
|
1303
|
+
stack.push(parseResult);
|
|
1304
|
+
}
|
|
1305
|
+
return stack;
|
|
1306
|
+
}, []);
|
|
1307
|
+
}
|
|
1308
|
+
var chromeRe = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|rsc|<anonymous>|\/|[a-z]:\\|\\\\).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
|
|
1309
|
+
var chromeEvalRe = /\((\S*)(?::(\d+))(?::(\d+))\)/;
|
|
1310
|
+
function parseChrome(line) {
|
|
1311
|
+
var parts = chromeRe.exec(line);
|
|
1312
|
+
if (!parts) {
|
|
1313
|
+
return null;
|
|
1314
|
+
}
|
|
1315
|
+
var isNative = parts[2] && parts[2].indexOf("native") === 0;
|
|
1316
|
+
var isEval = parts[2] && parts[2].indexOf("eval") === 0;
|
|
1317
|
+
var submatch = chromeEvalRe.exec(parts[2]);
|
|
1318
|
+
if (isEval && submatch != null) {
|
|
1319
|
+
parts[2] = submatch[1];
|
|
1320
|
+
parts[3] = submatch[2];
|
|
1321
|
+
parts[4] = submatch[3];
|
|
1322
|
+
}
|
|
1323
|
+
return {
|
|
1324
|
+
file: !isNative ? parts[2] : null,
|
|
1325
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1326
|
+
arguments: isNative ? [parts[2]] : [],
|
|
1327
|
+
lineNumber: parts[3] ? +parts[3] : null,
|
|
1328
|
+
column: parts[4] ? +parts[4] : null
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
var winjsRe = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|rsc|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
1332
|
+
function parseWinjs(line) {
|
|
1333
|
+
var parts = winjsRe.exec(line);
|
|
1334
|
+
if (!parts) {
|
|
1335
|
+
return null;
|
|
1336
|
+
}
|
|
1337
|
+
return {
|
|
1338
|
+
file: parts[2],
|
|
1339
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1340
|
+
arguments: [],
|
|
1341
|
+
lineNumber: +parts[3],
|
|
1342
|
+
column: parts[4] ? +parts[4] : null
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
var geckoRe = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|rsc|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i;
|
|
1346
|
+
var geckoEvalRe = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
|
|
1347
|
+
function parseGecko(line) {
|
|
1348
|
+
var parts = geckoRe.exec(line);
|
|
1349
|
+
if (!parts) {
|
|
1350
|
+
return null;
|
|
1351
|
+
}
|
|
1352
|
+
var isEval = parts[3] && parts[3].indexOf(" > eval") > -1;
|
|
1353
|
+
var submatch = geckoEvalRe.exec(parts[3]);
|
|
1354
|
+
if (isEval && submatch != null) {
|
|
1355
|
+
parts[3] = submatch[1];
|
|
1356
|
+
parts[4] = submatch[2];
|
|
1357
|
+
parts[5] = null;
|
|
1358
|
+
}
|
|
1359
|
+
return {
|
|
1360
|
+
file: parts[3],
|
|
1361
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1362
|
+
arguments: parts[2] ? parts[2].split(",") : [],
|
|
1363
|
+
lineNumber: parts[4] ? +parts[4] : null,
|
|
1364
|
+
column: parts[5] ? +parts[5] : null
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
var javaScriptCoreRe = /^\s*(?:([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$/i;
|
|
1368
|
+
function parseJSC(line) {
|
|
1369
|
+
var parts = javaScriptCoreRe.exec(line);
|
|
1370
|
+
if (!parts) {
|
|
1371
|
+
return null;
|
|
1372
|
+
}
|
|
1373
|
+
return {
|
|
1374
|
+
file: parts[3],
|
|
1375
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1376
|
+
arguments: [],
|
|
1377
|
+
lineNumber: +parts[4],
|
|
1378
|
+
column: parts[5] ? +parts[5] : null
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
var nodeRe = /^\s*at (?:((?:\[object object\])?[^\\/]+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
1382
|
+
function parseNode(line) {
|
|
1383
|
+
var parts = nodeRe.exec(line);
|
|
1384
|
+
if (!parts) {
|
|
1385
|
+
return null;
|
|
1386
|
+
}
|
|
1387
|
+
return {
|
|
1388
|
+
file: parts[2],
|
|
1389
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1390
|
+
arguments: [],
|
|
1391
|
+
lineNumber: +parts[3],
|
|
1392
|
+
column: parts[4] ? +parts[4] : null
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
// src/build/analyze.ts
|
|
1129
1397
|
function throwExternalDependencyError({
|
|
1130
1398
|
errorId,
|
|
1131
1399
|
moduleName,
|
|
@@ -1149,6 +1417,110 @@ export const mastra = new Mastra({
|
|
|
1149
1417
|
})`
|
|
1150
1418
|
});
|
|
1151
1419
|
}
|
|
1420
|
+
function getPackageNameFromBundledModuleName(moduleName) {
|
|
1421
|
+
const chunks = moduleName.split("-");
|
|
1422
|
+
if (!chunks.length) {
|
|
1423
|
+
return moduleName;
|
|
1424
|
+
}
|
|
1425
|
+
if (chunks[0]?.startsWith("@")) {
|
|
1426
|
+
return chunks.slice(0, 2).join("/");
|
|
1427
|
+
}
|
|
1428
|
+
return chunks[0];
|
|
1429
|
+
}
|
|
1430
|
+
function validateError(err, file, {
|
|
1431
|
+
binaryMapData,
|
|
1432
|
+
workspaceMap
|
|
1433
|
+
}) {
|
|
1434
|
+
let moduleName = null;
|
|
1435
|
+
let errorConfig = null;
|
|
1436
|
+
if (err instanceof ValidationError) {
|
|
1437
|
+
const parsedStack = parse(err.stack);
|
|
1438
|
+
if (err.type === "TypeError") {
|
|
1439
|
+
const pkgNameRegex = /.*node_modules\/([^\/]+)\//;
|
|
1440
|
+
const stacktraceFrame = parsedStack.find((frame) => frame.file && pkgNameRegex.test(frame.file));
|
|
1441
|
+
if (stacktraceFrame) {
|
|
1442
|
+
const match = stacktraceFrame.file.match(pkgNameRegex);
|
|
1443
|
+
moduleName = match?.[1] ?? getPackageNameFromBundledModuleName(basename$1(file.name));
|
|
1444
|
+
} else {
|
|
1445
|
+
moduleName = getPackageNameFromBundledModuleName(basename$1(file.name));
|
|
1446
|
+
}
|
|
1447
|
+
errorConfig = {
|
|
1448
|
+
id: "DEPLOYER_ANALYZE_TYPE_ERROR",
|
|
1449
|
+
messagePrefix: `Mastra wasn't able to bundle "${moduleName}", might be an older commonJS module. Please add`
|
|
1450
|
+
};
|
|
1451
|
+
} else if (err.stack?.includes?.("[ERR_MODULE_NOT_FOUND]")) {
|
|
1452
|
+
moduleName = err.message.match(/Cannot find package '([^']+)'/)?.[1];
|
|
1453
|
+
const parentModuleName = getPackageNameFromBundledModuleName(basename$1(file.name));
|
|
1454
|
+
errorConfig = {
|
|
1455
|
+
id: "DEPLOYER_ANALYZE_MODULE_NOT_FOUND",
|
|
1456
|
+
messagePrefix: `Mastra wasn't able to build your project, We couldn't load "${moduleName}" from "${parentModuleName}". Make sure "${moduleName}" is installed or add`
|
|
1457
|
+
};
|
|
1458
|
+
if (moduleName === parentModuleName) {
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
if (err.message.includes("No native build was found")) {
|
|
1464
|
+
const pkgName = getPackageNameFromBundledModuleName(basename$1(file.name));
|
|
1465
|
+
moduleName = binaryMapData[file.fileName]?.[0] ?? pkgName;
|
|
1466
|
+
errorConfig = {
|
|
1467
|
+
id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
|
|
1468
|
+
messagePrefix: "We found a binary dependency in your bundle but we cannot bundle it yet. Please add"
|
|
1469
|
+
};
|
|
1470
|
+
}
|
|
1471
|
+
if (moduleName && workspaceMap.has(moduleName)) {
|
|
1472
|
+
throw new MastraError({
|
|
1473
|
+
id: "DEPLOYER_ANALYZE_ERROR_IN_WORKSPACE",
|
|
1474
|
+
domain: ErrorDomain.DEPLOYER,
|
|
1475
|
+
category: ErrorCategory.USER,
|
|
1476
|
+
details: {
|
|
1477
|
+
// importFile: moduleName,
|
|
1478
|
+
packageName: moduleName
|
|
1479
|
+
},
|
|
1480
|
+
text: `We found an error in the ${moduleName} workspace package. Please find the offending package and fix the error.
|
|
1481
|
+
Error: ${err.stack}`
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
if (errorConfig && moduleName) {
|
|
1485
|
+
throwExternalDependencyError({
|
|
1486
|
+
errorId: errorConfig.id,
|
|
1487
|
+
moduleName,
|
|
1488
|
+
packageName: moduleName,
|
|
1489
|
+
messagePrefix: errorConfig.messagePrefix
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
async function validateFile(root, file, {
|
|
1494
|
+
binaryMapData,
|
|
1495
|
+
moduleResolveMapLocation,
|
|
1496
|
+
logger,
|
|
1497
|
+
workspaceMap
|
|
1498
|
+
}) {
|
|
1499
|
+
try {
|
|
1500
|
+
if (!file.isDynamicEntry && file.isEntry) {
|
|
1501
|
+
await validate(join(root, file.fileName), {
|
|
1502
|
+
moduleResolveMapLocation,
|
|
1503
|
+
injectESMShim: false
|
|
1504
|
+
});
|
|
1505
|
+
}
|
|
1506
|
+
} catch (err) {
|
|
1507
|
+
let errorToHandle = err;
|
|
1508
|
+
if (err instanceof ValidationError && err.type === "ReferenceError" && (err.message.startsWith("__dirname") || err.message.startsWith("__filename"))) {
|
|
1509
|
+
try {
|
|
1510
|
+
await validate(join(root, file.fileName), {
|
|
1511
|
+
moduleResolveMapLocation,
|
|
1512
|
+
injectESMShim: true
|
|
1513
|
+
});
|
|
1514
|
+
errorToHandle = null;
|
|
1515
|
+
} catch (err2) {
|
|
1516
|
+
errorToHandle = err2;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
if (errorToHandle instanceof Error) {
|
|
1520
|
+
validateError(errorToHandle, file, { binaryMapData, workspaceMap });
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1152
1524
|
async function validateOutput({
|
|
1153
1525
|
output,
|
|
1154
1526
|
reverseVirtualReferenceMap,
|
|
@@ -1162,60 +1534,30 @@ async function validateOutput({
|
|
|
1162
1534
|
externalDependencies: /* @__PURE__ */ new Set(),
|
|
1163
1535
|
workspaceMap
|
|
1164
1536
|
};
|
|
1165
|
-
await writeFile(join(outputDir, "module-resolve-map.json"), JSON.stringify(usedExternals, null, 2));
|
|
1166
1537
|
for (const deps of Object.values(usedExternals)) {
|
|
1167
1538
|
for (const dep of Object.keys(deps)) {
|
|
1168
1539
|
result.externalDependencies.add(dep);
|
|
1169
1540
|
}
|
|
1170
1541
|
}
|
|
1542
|
+
let binaryMapData = {};
|
|
1543
|
+
if (existsSync(join(outputDir, "binary-map.json"))) {
|
|
1544
|
+
const binaryMap = await readFile(join(outputDir, "binary-map.json"), "utf-8");
|
|
1545
|
+
binaryMapData = JSON.parse(binaryMap);
|
|
1546
|
+
}
|
|
1171
1547
|
for (const file of output) {
|
|
1172
1548
|
if (file.type === "asset") {
|
|
1173
1549
|
continue;
|
|
1174
1550
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
|
|
1179
|
-
}
|
|
1180
|
-
if (!file.isDynamicEntry && file.isEntry) {
|
|
1181
|
-
await validate(join(projectRoot, file.fileName));
|
|
1182
|
-
}
|
|
1183
|
-
} catch (err) {
|
|
1184
|
-
if (err instanceof Error) {
|
|
1185
|
-
let moduleName = null;
|
|
1186
|
-
let errorConfig = null;
|
|
1187
|
-
if (err.message.includes("[ERR_MODULE_NOT_FOUND]")) {
|
|
1188
|
-
const moduleIdName = file.moduleIds.length >= 2 ? file.moduleIds[file.moduleIds.length - 2] : void 0;
|
|
1189
|
-
const fallbackName = file.name.split("/").pop();
|
|
1190
|
-
moduleName = moduleIdName ?? fallbackName;
|
|
1191
|
-
errorConfig = {
|
|
1192
|
-
id: "DEPLOYER_ANALYZE_MODULE_NOT_FOUND",
|
|
1193
|
-
messagePrefix: "Mastra wasn't able to build your project. Please add"
|
|
1194
|
-
};
|
|
1195
|
-
} else if (err.message.includes("Error: No native build was found for ")) {
|
|
1196
|
-
moduleName = findNativePackageModule(file.moduleIds);
|
|
1197
|
-
errorConfig = {
|
|
1198
|
-
id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
|
|
1199
|
-
messagePrefix: "We found a binary dependency in your bundle. Please add"
|
|
1200
|
-
};
|
|
1201
|
-
}
|
|
1202
|
-
if (moduleName && errorConfig) {
|
|
1203
|
-
const pkgInfo = await getPackageInfo(moduleName);
|
|
1204
|
-
const packageName = pkgInfo?.packageJson?.name;
|
|
1205
|
-
if (packageName) {
|
|
1206
|
-
throwExternalDependencyError({
|
|
1207
|
-
errorId: errorConfig.id,
|
|
1208
|
-
moduleName,
|
|
1209
|
-
packageName,
|
|
1210
|
-
messagePrefix: errorConfig.messagePrefix
|
|
1211
|
-
});
|
|
1212
|
-
} else {
|
|
1213
|
-
logger.debug(`Could not determine the module name for file ${file.fileName}`);
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
logger.debug(`Error while validating module ${file.fileName}: ${err.message}`);
|
|
1217
|
-
}
|
|
1551
|
+
logger.debug(`Validating if ${file.fileName} is a valid module.`);
|
|
1552
|
+
if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
|
|
1553
|
+
result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
|
|
1218
1554
|
}
|
|
1555
|
+
await validateFile(projectRoot, file, {
|
|
1556
|
+
binaryMapData,
|
|
1557
|
+
moduleResolveMapLocation: join(outputDir, "module-resolve-map.json"),
|
|
1558
|
+
logger,
|
|
1559
|
+
workspaceMap
|
|
1560
|
+
});
|
|
1219
1561
|
}
|
|
1220
1562
|
return result;
|
|
1221
1563
|
}
|
|
@@ -1247,17 +1589,26 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1247
1589
|
const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
|
|
1248
1590
|
let index = 0;
|
|
1249
1591
|
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
1592
|
+
const { externals: customExternals = [] } = bundlerOptions || {};
|
|
1593
|
+
const allExternals = [...GLOBAL_EXTERNALS, ...customExternals];
|
|
1250
1594
|
logger.info("Analyzing dependencies...");
|
|
1595
|
+
const allUsedExternals = /* @__PURE__ */ new Set();
|
|
1251
1596
|
for (const entry of entries) {
|
|
1252
1597
|
const isVirtualFile = entry.includes("\n") || !existsSync(entry);
|
|
1253
1598
|
const analyzeResult = await analyzeEntry({ entry, isVirtualFile }, mastraEntry, {
|
|
1254
1599
|
logger,
|
|
1255
1600
|
sourcemapEnabled: bundlerOptions?.sourcemap ?? false,
|
|
1256
1601
|
workspaceMap,
|
|
1257
|
-
projectRoot
|
|
1602
|
+
projectRoot,
|
|
1603
|
+
shouldCheckTransitiveDependencies: isDev
|
|
1258
1604
|
});
|
|
1259
1605
|
await writeFile(join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
|
|
1260
1606
|
for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
|
|
1607
|
+
const isPartOfExternals = allExternals.some((external) => isDependencyPartOfPackage(dep, external));
|
|
1608
|
+
if (isPartOfExternals) {
|
|
1609
|
+
allUsedExternals.add(dep);
|
|
1610
|
+
continue;
|
|
1611
|
+
}
|
|
1261
1612
|
if (depsToOptimize.has(dep)) {
|
|
1262
1613
|
const existingEntry = depsToOptimize.get(dep);
|
|
1263
1614
|
depsToOptimize.set(dep, {
|
|
@@ -1276,14 +1627,13 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1276
1627
|
}
|
|
1277
1628
|
}
|
|
1278
1629
|
}
|
|
1279
|
-
|
|
1630
|
+
const sortedDeps = Array.from(depsToOptimize.keys()).sort();
|
|
1280
1631
|
logger.info("Optimizing dependencies...");
|
|
1281
|
-
logger.debug(
|
|
1282
|
-
`${Array.from(depsToOptimize.keys()).map((key) => `- ${key}`).join("\n")}`
|
|
1283
|
-
);
|
|
1632
|
+
logger.debug(`${sortedDeps.map((key) => `- ${key}`).join("\n")}`);
|
|
1284
1633
|
const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
|
|
1285
1634
|
bundlerOptions: {
|
|
1286
1635
|
...bundlerOptions,
|
|
1636
|
+
externals: allExternals,
|
|
1287
1637
|
enableEsmShim,
|
|
1288
1638
|
isDev
|
|
1289
1639
|
},
|
|
@@ -1302,9 +1652,12 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1302
1652
|
},
|
|
1303
1653
|
logger
|
|
1304
1654
|
);
|
|
1305
|
-
return
|
|
1655
|
+
return {
|
|
1656
|
+
...result,
|
|
1657
|
+
externalDependencies: /* @__PURE__ */ new Set([...result.externalDependencies, ...Array.from(allUsedExternals)])
|
|
1658
|
+
};
|
|
1306
1659
|
}
|
|
1307
1660
|
|
|
1308
|
-
export { aliasHono, analyzeBundle, esbuild, extractMastraOption, getBundlerOptions,
|
|
1309
|
-
//# sourceMappingURL=chunk-
|
|
1310
|
-
//# sourceMappingURL=chunk-
|
|
1661
|
+
export { aliasHono, analyzeBundle, esbuild, extractMastraOption, getBundlerOptions, getWorkspaceInformation, removeAllOptionsFromMastraExcept, removeDeployer2 as removeDeployer, subpathExternalsResolver, tsConfigPaths };
|
|
1662
|
+
//# sourceMappingURL=chunk-NFK4J35T.js.map
|
|
1663
|
+
//# sourceMappingURL=chunk-NFK4J35T.js.map
|