@mastra/deployer 1.0.0-beta.2 → 1.0.0-beta.20
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 +357 -0
- package/dist/arktype-aI7TBD0R-CCZH3EYK.js +8 -0
- package/dist/arktype-aI7TBD0R-CCZH3EYK.js.map +1 -0
- package/dist/arktype-aI7TBD0R-XHBHUL3T.cjs +10 -0
- package/dist/arktype-aI7TBD0R-XHBHUL3T.cjs.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 +4 -5
- package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
- package/dist/build/analyze.cjs +2 -2
- package/dist/build/analyze.d.ts +6 -6
- package/dist/build/analyze.d.ts.map +1 -1
- package/dist/build/analyze.js +1 -1
- package/dist/build/babel/remove-deployer.d.ts.map +1 -1
- package/dist/build/bundler.cjs +3 -3
- package/dist/build/bundler.d.ts +3 -1
- package/dist/build/bundler.d.ts.map +1 -1
- package/dist/build/bundler.js +1 -1
- package/dist/build/bundlerOptions.d.ts.map +1 -1
- package/dist/build/deployer.d.ts.map +1 -1
- package/dist/build/index.cjs +22 -13
- package/dist/build/index.d.ts +2 -0
- package/dist/build/index.d.ts.map +1 -1
- package/dist/build/index.js +5 -4
- package/dist/build/package-info.d.ts +9 -0
- package/dist/build/package-info.d.ts.map +1 -0
- package/dist/build/plugins/esm-shim.d.ts +14 -0
- package/dist/build/plugins/esm-shim.d.ts.map +1 -0
- 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/node-modules-extension-resolver.d.ts +7 -0
- package/dist/build/plugins/node-modules-extension-resolver.d.ts.map +1 -1
- package/dist/build/plugins/remove-all-except.d.ts +10 -0
- package/dist/build/plugins/remove-all-except.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/serverOptions.d.ts.map +1 -1
- package/dist/build/shared/extract-mastra-option.d.ts +4 -8
- package/dist/build/shared/extract-mastra-option.d.ts.map +1 -1
- package/dist/build/types.d.ts +5 -0
- package/dist/build/types.d.ts.map +1 -1
- package/dist/build/utils.d.ts +36 -4
- package/dist/build/utils.d.ts.map +1 -1
- package/dist/build/watcher.d.ts +2 -1
- package/dist/build/watcher.d.ts.map +1 -1
- package/dist/bundler/index.cjs +6 -2
- package/dist/bundler/index.d.ts +11 -8
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/index.js +1 -1
- package/dist/chunk-2VG357HT.cjs +4 -0
- package/dist/chunk-2VG357HT.cjs.map +1 -0
- package/dist/{chunk-OFUWEVGF.js → chunk-2ZPRZMBN.js} +70 -24
- package/dist/chunk-2ZPRZMBN.js.map +1 -0
- package/dist/{chunk-H3LLQ2MW.js → chunk-4NPMVODD.js} +813 -349
- package/dist/chunk-4NPMVODD.js.map +1 -0
- package/dist/chunk-5TYVF4KJ.cjs +76 -0
- package/dist/chunk-5TYVF4KJ.cjs.map +1 -0
- package/dist/chunk-DBXWQ2CA.js +159 -0
- package/dist/chunk-DBXWQ2CA.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-G6GFAPPU.js +6 -0
- package/dist/chunk-G6GFAPPU.js.map +1 -0
- package/dist/chunk-HPGDVJAZ.js +3 -0
- package/dist/chunk-HPGDVJAZ.js.map +1 -0
- package/dist/{chunk-IL2VLNIJ.cjs → chunk-HVKR4FT2.cjs} +77 -31
- package/dist/chunk-HVKR4FT2.cjs.map +1 -0
- package/dist/chunk-JBE6KM7R.cjs +95 -0
- package/dist/chunk-JBE6KM7R.cjs.map +1 -0
- package/dist/chunk-JRUJ546M.cjs +162 -0
- package/dist/chunk-JRUJ546M.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-KE4NVPI4.cjs +8 -0
- package/dist/chunk-KE4NVPI4.cjs.map +1 -0
- package/dist/chunk-MCWU6IKS.js +14 -0
- package/dist/chunk-MCWU6IKS.js.map +1 -0
- package/dist/{chunk-WBAWUM7Z.js → chunk-NGWTN4SJ.js} +48 -28
- package/dist/chunk-NGWTN4SJ.js.map +1 -0
- package/dist/{chunk-C74EXQSL.cjs → chunk-NWQP6PZQ.cjs} +826 -362
- package/dist/chunk-NWQP6PZQ.cjs.map +1 -0
- package/dist/chunk-QAOUDKHK.js +67 -0
- package/dist/chunk-QAOUDKHK.js.map +1 -0
- package/dist/{chunk-AQAOWLJJ.cjs → chunk-SBGBJ7NB.cjs} +57 -36
- package/dist/chunk-SBGBJ7NB.cjs.map +1 -0
- package/dist/chunk-UKP4KHBS.js +88 -0
- package/dist/chunk-UKP4KHBS.js.map +1 -0
- package/dist/chunk-V4HCIN6G.js +93 -0
- package/dist/chunk-V4HCIN6G.js.map +1 -0
- package/dist/chunk-Z53UZLS3.cjs +112 -0
- package/dist/chunk-Z53UZLS3.cjs.map +1 -0
- package/dist/chunk-ZXQ7DOYU.cjs +16 -0
- package/dist/chunk-ZXQ7DOYU.cjs.map +1 -0
- package/dist/default-u_dwuiYb-JPNIZQKK.cjs +9 -0
- package/dist/default-u_dwuiYb-JPNIZQKK.cjs.map +1 -0
- package/dist/default-u_dwuiYb-RK5OD4MY.js +3 -0
- package/dist/default-u_dwuiYb-RK5OD4MY.js.map +1 -0
- package/dist/deploy/log.d.ts +1 -1
- package/dist/deploy/log.d.ts.map +1 -1
- package/dist/docs/README.md +32 -0
- package/dist/docs/SKILL.md +36 -0
- package/dist/docs/SOURCE_MAP.json +27 -0
- package/dist/docs/deployer/01-reference.md +93 -0
- package/dist/docs/deployment/01-overview.md +60 -0
- package/dist/docs/deployment/02-mastra-server.md +70 -0
- package/dist/docs/deployment/03-monorepo.md +70 -0
- package/dist/docs/deployment/04-cloud-providers.md +17 -0
- package/dist/docs/deployment/05-web-framework.md +55 -0
- package/dist/docs/deployment/06-workflow-runners.md +11 -0
- package/dist/effect-QlVUlMFu-HN3LWZSQ.cjs +17 -0
- package/dist/effect-QlVUlMFu-HN3LWZSQ.cjs.map +1 -0
- package/dist/effect-QlVUlMFu-XOJ2F4UA.js +15 -0
- package/dist/effect-QlVUlMFu-XOJ2F4UA.js.map +1 -0
- package/dist/esm-6TGK2CUM.js +1289 -0
- package/dist/esm-6TGK2CUM.js.map +1 -0
- package/dist/esm-SQKX5ABS.cjs +1336 -0
- package/dist/esm-SQKX5ABS.cjs.map +1 -0
- package/dist/index.cjs +11 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -16
- package/dist/index.js.map +1 -1
- package/dist/server/handlers/restart-active-runs.d.ts +3 -0
- package/dist/server/handlers/restart-active-runs.d.ts.map +1 -0
- package/dist/server/index.cjs +2659 -10538
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +3 -12
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2662 -10542
- 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-KEHKUXG7.cjs +17 -0
- package/dist/sury-CWZTCd75-KEHKUXG7.cjs.map +1 -0
- package/dist/sury-CWZTCd75-L2D76L25.js +15 -0
- package/dist/sury-CWZTCd75-L2D76L25.js.map +1 -0
- package/dist/typebox-Dei93FPO-LBLFC3RD.js +8 -0
- package/dist/typebox-Dei93FPO-LBLFC3RD.js.map +1 -0
- package/dist/typebox-Dei93FPO-RDSW6DFA.cjs +10 -0
- package/dist/typebox-Dei93FPO-RDSW6DFA.cjs.map +1 -0
- package/dist/valibot--1zFm7rT-NVADAEQI.cjs +17 -0
- package/dist/valibot--1zFm7rT-NVADAEQI.cjs.map +1 -0
- package/dist/valibot--1zFm7rT-R2UKWLZC.js +15 -0
- package/dist/valibot--1zFm7rT-R2UKWLZC.js.map +1 -0
- package/dist/valibot-D_HTw1Gn-DSFFOUBW.cjs +45 -0
- package/dist/valibot-D_HTw1Gn-DSFFOUBW.cjs.map +1 -0
- package/dist/valibot-D_HTw1Gn-KWXWP2TJ.js +43 -0
- package/dist/valibot-D_HTw1Gn-KWXWP2TJ.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-GCUGPBJX.js +29 -0
- package/dist/zod-Bwrt9trS-GCUGPBJX.js.map +1 -0
- package/dist/zod-Bwrt9trS-ZZHFZ7YQ.cjs +31 -0
- package/dist/zod-Bwrt9trS-ZZHFZ7YQ.cjs.map +1 -0
- package/dist/zod-DSgpEGAE-3CMS4FSB.cjs +39 -0
- package/dist/zod-DSgpEGAE-3CMS4FSB.cjs.map +1 -0
- package/dist/zod-DSgpEGAE-IPE3O2NQ.js +37 -0
- package/dist/zod-DSgpEGAE-IPE3O2NQ.js.map +1 -0
- package/package.json +21 -24
- package/dist/build/babel/get-deployer.d.ts +0 -3
- package/dist/build/babel/get-deployer.d.ts.map +0 -1
- package/dist/build/babel/remove-all-options-bundler.d.ts +0 -5
- package/dist/build/babel/remove-all-options-bundler.d.ts.map +0 -1
- package/dist/build/babel/remove-all-options-deployer.d.ts +0 -5
- package/dist/build/babel/remove-all-options-deployer.d.ts.map +0 -1
- package/dist/build/babel/remove-all-options-server.d.ts +0 -5
- package/dist/build/babel/remove-all-options-server.d.ts.map +0 -1
- package/dist/chunk-3JYRSECU.cjs.map +0 -1
- package/dist/chunk-5QFG6SCM.js.map +0 -1
- package/dist/chunk-AQAOWLJJ.cjs.map +0 -1
- package/dist/chunk-C74EXQSL.cjs.map +0 -1
- package/dist/chunk-H3LLQ2MW.js.map +0 -1
- package/dist/chunk-HQJR52M7.js +0 -168
- package/dist/chunk-HQJR52M7.js.map +0 -1
- package/dist/chunk-IL2VLNIJ.cjs.map +0 -1
- package/dist/chunk-OFUWEVGF.js.map +0 -1
- package/dist/chunk-TDWIGFVF.cjs +0 -195
- package/dist/chunk-TDWIGFVF.cjs.map +0 -1
- package/dist/chunk-WBAWUM7Z.js.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/prompt.d.ts +0 -3
- package/dist/server/handlers/prompt.d.ts.map +0 -1
- package/dist/server/handlers/routes/agent-builder/handlers.d.ts +0 -20
- package/dist/server/handlers/routes/agent-builder/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/agent-builder/router.d.ts +0 -4
- package/dist/server/handlers/routes/agent-builder/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/agents/handlers.d.ts +0 -232
- package/dist/server/handlers/routes/agents/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/agents/router.d.ts +0 -5
- package/dist/server/handlers/routes/agents/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/agents/voice.d.ts +0 -18
- package/dist/server/handlers/routes/agents/voice.d.ts.map +0 -1
- package/dist/server/handlers/routes/logs/handlers.d.ts +0 -5
- package/dist/server/handlers/routes/logs/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/logs/router.d.ts +0 -3
- package/dist/server/handlers/routes/logs/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/mcp/handlers.d.ts +0 -139
- package/dist/server/handlers/routes/mcp/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/mcp/router.d.ts +0 -4
- package/dist/server/handlers/routes/mcp/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/memory/handlers.d.ts +0 -15
- package/dist/server/handlers/routes/memory/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/memory/router.d.ts +0 -4
- package/dist/server/handlers/routes/memory/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/observability/handlers.d.ts +0 -6
- package/dist/server/handlers/routes/observability/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/observability/router.d.ts +0 -3
- package/dist/server/handlers/routes/observability/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/scores/handlers.d.ts +0 -302
- package/dist/server/handlers/routes/scores/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/scores/router.d.ts +0 -4
- package/dist/server/handlers/routes/scores/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/tools/handlers.d.ts +0 -7
- package/dist/server/handlers/routes/tools/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/tools/router.d.ts +0 -4
- package/dist/server/handlers/routes/tools/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/vector/handlers.d.ts +0 -10
- package/dist/server/handlers/routes/vector/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/vector/router.d.ts +0 -4
- package/dist/server/handlers/routes/vector/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/workflows/handlers.d.ts +0 -20
- package/dist/server/handlers/routes/workflows/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/workflows/router.d.ts +0 -4
- package/dist/server/handlers/routes/workflows/router.d.ts.map +0 -1
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunk5TYVF4KJ_cjs = require('./chunk-5TYVF4KJ.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
9
|
var url = require('url');
|
|
10
10
|
var rollup = require('rollup');
|
|
11
11
|
var originalEsbuild = require('rollup-plugin-esbuild');
|
|
12
12
|
var commonjs = require('@rollup/plugin-commonjs');
|
|
13
13
|
var resolveFrom2 = require('resolve-from');
|
|
14
|
+
var stripJsonComments = require('strip-json-comments');
|
|
14
15
|
var typescriptPaths = require('typescript-paths');
|
|
15
16
|
var rollupPlugin = require('@optimize-lodash/rollup-plugin');
|
|
16
17
|
var json = require('@rollup/plugin-json');
|
|
@@ -19,8 +20,9 @@ var findWorkspaces = require('find-workspaces');
|
|
|
19
20
|
var logger = require('@mastra/core/logger');
|
|
20
21
|
var virtual = require('@rollup/plugin-virtual');
|
|
21
22
|
var module$1 = require('module');
|
|
23
|
+
var localPkg = require('local-pkg');
|
|
22
24
|
var nodeResolve = require('@rollup/plugin-node-resolve');
|
|
23
|
-
var
|
|
25
|
+
var originalEsmShim = require('@rollup/plugin-esm-shim');
|
|
24
26
|
var posix = require('path/posix');
|
|
25
27
|
var resolve = require('resolve.exports');
|
|
26
28
|
var error = require('@mastra/core/error');
|
|
@@ -51,90 +53,26 @@ 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);
|
|
57
60
|
var nodeResolve__default = /*#__PURE__*/_interopDefault(nodeResolve);
|
|
58
|
-
var
|
|
61
|
+
var originalEsmShim__default = /*#__PURE__*/_interopDefault(originalEsmShim);
|
|
59
62
|
var resolve__namespace = /*#__PURE__*/_interopNamespace(resolve);
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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;
|
|
66
71
|
}
|
|
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;
|
|
85
|
-
}
|
|
86
|
-
return rootPath;
|
|
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,113 +82,67 @@ 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('${url.pathToFileURL(file).href}').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
|
);
|
|
172
145
|
}
|
|
173
|
-
function removeAllOptionsFromMastraExcept(result, option, logger) {
|
|
174
|
-
const t = babel__namespace.default.types;
|
|
175
|
-
return {
|
|
176
|
-
name: "remove-all-except-" + option + "-config",
|
|
177
|
-
visitor: {
|
|
178
|
-
ExportNamedDeclaration: {
|
|
179
|
-
// remove all exports
|
|
180
|
-
exit(path3) {
|
|
181
|
-
path3.remove();
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
NewExpression(path3, state) {
|
|
185
|
-
const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
|
|
186
|
-
if (!varDeclaratorPath) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
const parentNode = path3.parentPath.node;
|
|
190
|
-
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
let mastraArgs = t.objectExpression([]);
|
|
194
|
-
if (t.isObjectExpression(path3.node.arguments[0])) {
|
|
195
|
-
mastraArgs = path3.node.arguments[0];
|
|
196
|
-
}
|
|
197
|
-
let configProperty = mastraArgs.properties.find(
|
|
198
|
-
// @ts-ignore
|
|
199
|
-
(prop) => prop.key.name === option
|
|
200
|
-
);
|
|
201
|
-
let configValue = t.objectExpression([]);
|
|
202
|
-
const programPath = path3.scope.getProgramParent().path;
|
|
203
|
-
if (!programPath) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {
|
|
207
|
-
result.hasCustomConfig = true;
|
|
208
|
-
configValue = configProperty.value;
|
|
209
|
-
if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {
|
|
210
|
-
const configBinding = state.file.scope.getBinding(option);
|
|
211
|
-
if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {
|
|
212
|
-
const id = path3.scope.generateUidIdentifier(option);
|
|
213
|
-
configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init));
|
|
214
|
-
configValue = id;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
const exportDeclaration = t.exportNamedDeclaration(
|
|
219
|
-
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), configValue)]),
|
|
220
|
-
[]
|
|
221
|
-
);
|
|
222
|
-
programPath.node.body.push(exportDeclaration);
|
|
223
|
-
},
|
|
224
|
-
Program: {
|
|
225
|
-
exit(path3) {
|
|
226
|
-
const hasExport = path3.node.body.some(
|
|
227
|
-
(node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
|
|
228
|
-
);
|
|
229
|
-
if (!hasExport) {
|
|
230
|
-
if (logger) {
|
|
231
|
-
logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
|
|
232
|
-
export const mastra = new Mastra({
|
|
233
|
-
${option}: <value>
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
`);
|
|
237
|
-
}
|
|
238
|
-
const fallbackExportDeclaration = t.exportNamedDeclaration(
|
|
239
|
-
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
|
|
240
|
-
[]
|
|
241
|
-
);
|
|
242
|
-
path3.node.body.push(fallbackExportDeclaration);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// src/build/babel/remove-all-options-bundler.ts
|
|
251
|
-
function removeAllOptionsExceptBundler(result, logger) {
|
|
252
|
-
return removeAllOptionsFromMastraExcept(result, "bundler", logger);
|
|
253
|
-
}
|
|
254
146
|
function esbuild(options = {}) {
|
|
255
147
|
return originalEsbuild__default.default({
|
|
256
148
|
target: "node20",
|
|
@@ -260,29 +152,90 @@ function esbuild(options = {}) {
|
|
|
260
152
|
});
|
|
261
153
|
}
|
|
262
154
|
var PLUGIN_NAME = "tsconfig-paths";
|
|
155
|
+
function hasPaths(tsConfigPath) {
|
|
156
|
+
try {
|
|
157
|
+
const content = fs__default.default.readFileSync(tsConfigPath, "utf8");
|
|
158
|
+
const config = JSON.parse(stripJsonComments__default.default(content));
|
|
159
|
+
return !!(config.compilerOptions?.paths && Object.keys(config.compilerOptions.paths).length > 0);
|
|
160
|
+
} catch {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
263
164
|
function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve } = {}) {
|
|
264
|
-
|
|
165
|
+
const handlerCache = /* @__PURE__ */ new Map();
|
|
166
|
+
function findTsConfigForFile(filePath) {
|
|
167
|
+
let currentDir = path2__namespace.default.dirname(filePath);
|
|
168
|
+
const root = path2__namespace.default.parse(currentDir).root;
|
|
169
|
+
while (currentDir !== root) {
|
|
170
|
+
const tsConfigPath2 = path2__namespace.default.join(currentDir, "tsconfig.json");
|
|
171
|
+
if (fs__default.default.existsSync(tsConfigPath2)) {
|
|
172
|
+
if (hasPaths(tsConfigPath2)) {
|
|
173
|
+
return tsConfigPath2;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const tsConfigBasePath = path2__namespace.default.join(currentDir, "tsconfig.base.json");
|
|
177
|
+
if (fs__default.default.existsSync(tsConfigBasePath)) {
|
|
178
|
+
if (hasPaths(tsConfigBasePath)) {
|
|
179
|
+
return tsConfigBasePath;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
currentDir = path2__namespace.default.dirname(currentDir);
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
function getHandlerForFile(filePath) {
|
|
187
|
+
if (tsConfigPath && typeof tsConfigPath === "string") {
|
|
188
|
+
if (!handlerCache.has(tsConfigPath)) {
|
|
189
|
+
handlerCache.set(
|
|
190
|
+
tsConfigPath,
|
|
191
|
+
typescriptPaths.createHandler({
|
|
192
|
+
log: () => {
|
|
193
|
+
},
|
|
194
|
+
tsConfigPath,
|
|
195
|
+
respectCoreModule,
|
|
196
|
+
falllback: (moduleName) => fs__default.default.existsSync(moduleName)
|
|
197
|
+
})
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
return handlerCache.get(tsConfigPath);
|
|
201
|
+
}
|
|
202
|
+
const configPath = findTsConfigForFile(filePath);
|
|
203
|
+
if (!configPath) {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
if (!handlerCache.has(configPath)) {
|
|
207
|
+
handlerCache.set(
|
|
208
|
+
configPath,
|
|
209
|
+
typescriptPaths.createHandler({
|
|
210
|
+
log: () => {
|
|
211
|
+
},
|
|
212
|
+
tsConfigPath: configPath,
|
|
213
|
+
respectCoreModule,
|
|
214
|
+
falllback: (moduleName) => fs__default.default.existsSync(moduleName)
|
|
215
|
+
})
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
return handlerCache.get(configPath);
|
|
219
|
+
}
|
|
220
|
+
function resolveAlias(request, importer) {
|
|
221
|
+
const dynamicHandler = getHandlerForFile(importer);
|
|
222
|
+
if (!dynamicHandler) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
const resolved = dynamicHandler(request, path2.normalize(importer));
|
|
226
|
+
return resolved;
|
|
227
|
+
}
|
|
265
228
|
return {
|
|
266
229
|
name: PLUGIN_NAME,
|
|
267
|
-
buildStart() {
|
|
268
|
-
handler = typescriptPaths.createHandler({
|
|
269
|
-
log: () => {
|
|
270
|
-
},
|
|
271
|
-
tsConfigPath,
|
|
272
|
-
respectCoreModule,
|
|
273
|
-
falllback: (moduleName) => fs__default.default.existsSync(moduleName)
|
|
274
|
-
});
|
|
275
|
-
return;
|
|
276
|
-
},
|
|
277
230
|
async resolveId(request, importer, options) {
|
|
278
|
-
if (!importer || request.startsWith("\0")) {
|
|
231
|
+
if (!importer || request.startsWith("\0") || importer.charCodeAt(0) === 0) {
|
|
279
232
|
return null;
|
|
280
233
|
}
|
|
281
|
-
const moduleName =
|
|
234
|
+
const moduleName = resolveAlias(request, importer);
|
|
282
235
|
if (!moduleName) {
|
|
283
236
|
let importerMeta = {};
|
|
284
|
-
const
|
|
285
|
-
if (!
|
|
237
|
+
const resolved2 = await this.resolve(request, importer, { skipSelf: true, ...options });
|
|
238
|
+
if (!resolved2) {
|
|
286
239
|
return null;
|
|
287
240
|
}
|
|
288
241
|
if (localResolve) {
|
|
@@ -290,37 +243,42 @@ function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve } = {}) {
|
|
|
290
243
|
importerMeta = importerInfo?.meta || {};
|
|
291
244
|
if (!request.startsWith("./") && !request.startsWith("../") && importerMeta?.[PLUGIN_NAME]?.resolved) {
|
|
292
245
|
return {
|
|
293
|
-
...
|
|
246
|
+
...resolved2,
|
|
294
247
|
external: !request.startsWith("hono/") && request !== "hono"
|
|
295
248
|
};
|
|
296
249
|
}
|
|
297
250
|
}
|
|
298
251
|
return {
|
|
299
|
-
...
|
|
252
|
+
...resolved2,
|
|
300
253
|
meta: {
|
|
301
|
-
...
|
|
254
|
+
...resolved2.meta || {},
|
|
302
255
|
...importerMeta
|
|
303
256
|
}
|
|
304
257
|
};
|
|
305
258
|
}
|
|
306
259
|
if (!path2__namespace.default.extname(moduleName)) {
|
|
307
|
-
const
|
|
308
|
-
if (!
|
|
260
|
+
const resolved2 = await this.resolve(moduleName, importer, { skipSelf: true, ...options });
|
|
261
|
+
if (!resolved2) {
|
|
309
262
|
return null;
|
|
310
263
|
}
|
|
311
264
|
return {
|
|
312
|
-
...
|
|
265
|
+
...resolved2,
|
|
313
266
|
meta: {
|
|
314
|
-
...
|
|
267
|
+
...resolved2.meta,
|
|
315
268
|
[PLUGIN_NAME]: {
|
|
316
269
|
resolved: true
|
|
317
270
|
}
|
|
318
271
|
}
|
|
319
272
|
};
|
|
320
273
|
}
|
|
274
|
+
const resolved = await this.resolve(moduleName, importer, { skipSelf: true, ...options });
|
|
275
|
+
if (!resolved) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
321
278
|
return {
|
|
322
|
-
|
|
279
|
+
...resolved,
|
|
323
280
|
meta: {
|
|
281
|
+
...resolved.meta,
|
|
324
282
|
[PLUGIN_NAME]: {
|
|
325
283
|
resolved: true
|
|
326
284
|
}
|
|
@@ -402,7 +360,117 @@ function recursiveRemoveNonReferencedNodes(code) {
|
|
|
402
360
|
);
|
|
403
361
|
});
|
|
404
362
|
}
|
|
405
|
-
function
|
|
363
|
+
function removeAllOptionsFromMastraExcept(result, option, logger) {
|
|
364
|
+
const t = babel__namespace.default.types;
|
|
365
|
+
return {
|
|
366
|
+
name: "remove-all-except-" + option + "-config",
|
|
367
|
+
visitor: {
|
|
368
|
+
ExportNamedDeclaration: {
|
|
369
|
+
// remove all exports
|
|
370
|
+
exit(path3) {
|
|
371
|
+
path3.remove();
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
NewExpression(path3, state) {
|
|
375
|
+
const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
|
|
376
|
+
if (!varDeclaratorPath) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const parentNode = path3.parentPath.node;
|
|
380
|
+
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
let mastraArgs = t.objectExpression([]);
|
|
384
|
+
if (t.isObjectExpression(path3.node.arguments[0])) {
|
|
385
|
+
mastraArgs = path3.node.arguments[0];
|
|
386
|
+
}
|
|
387
|
+
let configProperty = mastraArgs.properties.find(
|
|
388
|
+
(prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === option
|
|
389
|
+
);
|
|
390
|
+
let configValue = t.objectExpression([]);
|
|
391
|
+
const programPath = path3.scope.getProgramParent().path;
|
|
392
|
+
if (!programPath) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {
|
|
396
|
+
result.hasCustomConfig = true;
|
|
397
|
+
configValue = configProperty.value;
|
|
398
|
+
if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {
|
|
399
|
+
const configBinding = state.file.scope.getBinding(option);
|
|
400
|
+
if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {
|
|
401
|
+
const id = path3.scope.generateUidIdentifier(option);
|
|
402
|
+
configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init));
|
|
403
|
+
configValue = id;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
const exportDeclaration = t.exportNamedDeclaration(
|
|
408
|
+
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), configValue)]),
|
|
409
|
+
[]
|
|
410
|
+
);
|
|
411
|
+
programPath.node.body.push(exportDeclaration);
|
|
412
|
+
},
|
|
413
|
+
Program: {
|
|
414
|
+
exit(path3) {
|
|
415
|
+
const hasExport = path3.node.body.some(
|
|
416
|
+
(node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
|
|
417
|
+
);
|
|
418
|
+
if (!hasExport) {
|
|
419
|
+
if (logger) {
|
|
420
|
+
logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
|
|
421
|
+
export const mastra = new Mastra({
|
|
422
|
+
${option}: <value>
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
`);
|
|
426
|
+
}
|
|
427
|
+
const fallbackExportDeclaration = t.exportNamedDeclaration(
|
|
428
|
+
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
|
|
429
|
+
[]
|
|
430
|
+
);
|
|
431
|
+
path3.node.body.push(fallbackExportDeclaration);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// src/build/plugins/remove-all-except.ts
|
|
440
|
+
function removeAllOptionsFromMastraExceptPlugin(mastraEntry, name, result, options) {
|
|
441
|
+
return {
|
|
442
|
+
name: `remove-${name}`,
|
|
443
|
+
transform(code, id) {
|
|
444
|
+
if (id !== mastraEntry) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
return new Promise((resolve2, reject) => {
|
|
448
|
+
babel__namespace.transform(
|
|
449
|
+
code,
|
|
450
|
+
{
|
|
451
|
+
babelrc: false,
|
|
452
|
+
configFile: false,
|
|
453
|
+
filename: id,
|
|
454
|
+
plugins: [removeAllOptionsFromMastraExcept(result, name, options?.logger)],
|
|
455
|
+
sourceMaps: options?.sourcemap
|
|
456
|
+
},
|
|
457
|
+
(err, result2) => {
|
|
458
|
+
if (err) {
|
|
459
|
+
return reject(err);
|
|
460
|
+
}
|
|
461
|
+
resolve2({
|
|
462
|
+
code: result2.code,
|
|
463
|
+
map: result2.map
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
);
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// src/build/shared/extract-mastra-option.ts
|
|
473
|
+
function extractMastraOptionBundler(name, entryFile, result, logger) {
|
|
406
474
|
return rollup.rollup({
|
|
407
475
|
logLevel: "silent",
|
|
408
476
|
input: {
|
|
@@ -423,34 +491,7 @@ function extractMastraOptionBundler(name, entryFile, transformer, result, logger
|
|
|
423
491
|
ignoreTryCatch: false
|
|
424
492
|
}),
|
|
425
493
|
json__default.default(),
|
|
426
|
-
{
|
|
427
|
-
name: `extract-${name}-config`,
|
|
428
|
-
transform(code, id) {
|
|
429
|
-
if (id !== entryFile) {
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
return new Promise((resolve2, reject) => {
|
|
433
|
-
babel__namespace.transform(
|
|
434
|
-
code,
|
|
435
|
-
{
|
|
436
|
-
babelrc: false,
|
|
437
|
-
configFile: false,
|
|
438
|
-
filename: id,
|
|
439
|
-
plugins: [transformer(result, logger)]
|
|
440
|
-
},
|
|
441
|
-
(err, result2) => {
|
|
442
|
-
if (err) {
|
|
443
|
-
return reject(err);
|
|
444
|
-
}
|
|
445
|
-
resolve2({
|
|
446
|
-
code: result2.code,
|
|
447
|
-
map: result2.map
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
);
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
},
|
|
494
|
+
removeAllOptionsFromMastraExceptPlugin(entryFile, name, result, { logger }),
|
|
454
495
|
// let esbuild remove all unused imports
|
|
455
496
|
esbuild(),
|
|
456
497
|
{
|
|
@@ -467,11 +508,11 @@ function extractMastraOptionBundler(name, entryFile, transformer, result, logger
|
|
|
467
508
|
]
|
|
468
509
|
});
|
|
469
510
|
}
|
|
470
|
-
async function extractMastraOption(name, entryFile,
|
|
511
|
+
async function extractMastraOption(name, entryFile, outputDir, logger) {
|
|
471
512
|
const result = {
|
|
472
513
|
hasCustomConfig: false
|
|
473
514
|
};
|
|
474
|
-
const bundler = await extractMastraOptionBundler(name, entryFile,
|
|
515
|
+
const bundler = await extractMastraOptionBundler(name, entryFile, result, logger);
|
|
475
516
|
const output = await bundler.write({
|
|
476
517
|
dir: outputDir,
|
|
477
518
|
format: "es",
|
|
@@ -481,7 +522,7 @@ async function extractMastraOption(name, entryFile, transformer, outputDir, logg
|
|
|
481
522
|
const configPath = `${outputDir}/${name}-config.mjs`;
|
|
482
523
|
return {
|
|
483
524
|
bundleOutput: output,
|
|
484
|
-
getConfig: () => import(
|
|
525
|
+
getConfig: () => import(url.pathToFileURL(configPath).href).then((m) => m[name])
|
|
485
526
|
};
|
|
486
527
|
}
|
|
487
528
|
return null;
|
|
@@ -489,13 +530,7 @@ async function extractMastraOption(name, entryFile, transformer, outputDir, logg
|
|
|
489
530
|
|
|
490
531
|
// src/build/bundlerOptions.ts
|
|
491
532
|
async function getBundlerOptions(entryFile, outputDir, logger) {
|
|
492
|
-
const result = await extractMastraOption(
|
|
493
|
-
"bundler",
|
|
494
|
-
entryFile,
|
|
495
|
-
removeAllOptionsExceptBundler,
|
|
496
|
-
outputDir,
|
|
497
|
-
logger
|
|
498
|
-
);
|
|
533
|
+
const result = await extractMastraOption("bundler", entryFile, outputDir, logger);
|
|
499
534
|
if (!result) {
|
|
500
535
|
return null;
|
|
501
536
|
}
|
|
@@ -539,7 +574,7 @@ async function getWorkspaceInformation({
|
|
|
539
574
|
mastraEntryFile
|
|
540
575
|
}) {
|
|
541
576
|
const closestPkgJson = pkg__namespace.up({ cwd: path2.dirname(mastraEntryFile) });
|
|
542
|
-
const location = closestPkgJson ? path2.dirname(slash(closestPkgJson)) : slash(process.cwd());
|
|
577
|
+
const location = closestPkgJson ? path2.dirname(chunk5TYVF4KJ_cjs.slash(closestPkgJson)) : chunk5TYVF4KJ_cjs.slash(process.cwd());
|
|
543
578
|
const workspaces = await findWorkspaces.findWorkspaces(dir, { cache: workspacesCache });
|
|
544
579
|
const _workspaceMap = new Map(
|
|
545
580
|
workspaces?.map((workspace) => [
|
|
@@ -564,8 +599,57 @@ function isNodeBuiltin(dep) {
|
|
|
564
599
|
const [pkg2] = dep.split("/");
|
|
565
600
|
return dep.startsWith("node:") || module$1.builtinModules.includes(dep) || module$1.builtinModules.includes(pkg2);
|
|
566
601
|
}
|
|
602
|
+
async function getPackageRootPath(packageName, parentPath) {
|
|
603
|
+
let rootPath;
|
|
604
|
+
try {
|
|
605
|
+
let options = void 0;
|
|
606
|
+
if (parentPath) {
|
|
607
|
+
if (!parentPath.startsWith("file://")) {
|
|
608
|
+
parentPath = url.pathToFileURL(parentPath).href;
|
|
609
|
+
}
|
|
610
|
+
options = {
|
|
611
|
+
paths: [parentPath]
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
const pkg2 = await localPkg.getPackageInfo(packageName, options);
|
|
615
|
+
rootPath = pkg2?.rootPath ?? null;
|
|
616
|
+
} catch (e) {
|
|
617
|
+
rootPath = null;
|
|
618
|
+
}
|
|
619
|
+
return rootPath;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// src/build/analyze/constants.ts
|
|
623
|
+
var DEPS_TO_IGNORE = ["#tools"];
|
|
624
|
+
var GLOBAL_EXTERNALS = [
|
|
625
|
+
"pino",
|
|
626
|
+
"pino-pretty",
|
|
627
|
+
"@libsql/client",
|
|
628
|
+
"pg",
|
|
629
|
+
"libsql",
|
|
630
|
+
"#tools",
|
|
631
|
+
"typescript",
|
|
632
|
+
"undici",
|
|
633
|
+
"readable-stream"
|
|
634
|
+
];
|
|
635
|
+
var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
|
|
567
636
|
function removeDeployer() {
|
|
568
637
|
const t = babel__namespace.default.types;
|
|
638
|
+
function removeDeployerFromObject(objectExpr, scope) {
|
|
639
|
+
const deployerProp = objectExpr.properties.find(
|
|
640
|
+
(prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
|
|
641
|
+
);
|
|
642
|
+
if (deployerProp) {
|
|
643
|
+
objectExpr.properties = objectExpr.properties.filter((prop) => prop !== deployerProp);
|
|
644
|
+
if (t.isIdentifier(deployerProp.value)) {
|
|
645
|
+
const deployerBinding = scope.getBinding(deployerProp.value.name);
|
|
646
|
+
if (deployerBinding) {
|
|
647
|
+
deployerBinding.path?.parentPath?.remove();
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
return deployerProp;
|
|
652
|
+
}
|
|
569
653
|
return {
|
|
570
654
|
name: "remove-deployer",
|
|
571
655
|
visitor: {
|
|
@@ -581,23 +665,30 @@ function removeDeployer() {
|
|
|
581
665
|
if (!state.hasReplaced) {
|
|
582
666
|
state.hasReplaced = true;
|
|
583
667
|
const newMastraObj = t.cloneNode(path3.node);
|
|
584
|
-
if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.
|
|
585
|
-
const
|
|
586
|
-
|
|
587
|
-
);
|
|
588
|
-
if (
|
|
589
|
-
|
|
668
|
+
if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.length) {
|
|
669
|
+
const objectArg = newMastraObj.arguments[0];
|
|
670
|
+
let foundDeployer = false;
|
|
671
|
+
const directDeployer = removeDeployerFromObject(objectArg, state.file.scope);
|
|
672
|
+
if (directDeployer) {
|
|
673
|
+
foundDeployer = true;
|
|
590
674
|
}
|
|
591
|
-
|
|
592
|
-
(prop)
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
675
|
+
for (const prop of objectArg.properties) {
|
|
676
|
+
if (t.isSpreadElement(prop) && t.isIdentifier(prop.argument)) {
|
|
677
|
+
const spreadBinding = state.file.scope.getBinding(prop.argument.name);
|
|
678
|
+
if (spreadBinding?.path && t.isVariableDeclarator(spreadBinding.path.node)) {
|
|
679
|
+
const init = spreadBinding.path.node.init;
|
|
680
|
+
if (t.isObjectExpression(init)) {
|
|
681
|
+
const spreadDeployer = removeDeployerFromObject(init, state.file.scope);
|
|
682
|
+
if (spreadDeployer) {
|
|
683
|
+
foundDeployer = true;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
598
687
|
}
|
|
599
688
|
}
|
|
600
|
-
|
|
689
|
+
if (foundDeployer) {
|
|
690
|
+
path3.replaceWith(newMastraObj);
|
|
691
|
+
}
|
|
601
692
|
}
|
|
602
693
|
}
|
|
603
694
|
}
|
|
@@ -638,24 +729,9 @@ function removeDeployer2(mastraEntry, options) {
|
|
|
638
729
|
};
|
|
639
730
|
}
|
|
640
731
|
|
|
641
|
-
// src/build/analyze/constants.ts
|
|
642
|
-
var DEPS_TO_IGNORE = ["#tools"];
|
|
643
|
-
var GLOBAL_EXTERNALS = [
|
|
644
|
-
"pino",
|
|
645
|
-
"pino-pretty",
|
|
646
|
-
"@libsql/client",
|
|
647
|
-
"pg",
|
|
648
|
-
"libsql",
|
|
649
|
-
"#tools",
|
|
650
|
-
"typescript",
|
|
651
|
-
"undici",
|
|
652
|
-
"readable-stream"
|
|
653
|
-
];
|
|
654
|
-
var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
|
|
655
|
-
|
|
656
732
|
// src/build/analyze/analyzeEntry.ts
|
|
657
733
|
function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
|
|
658
|
-
const normalizedMastraEntry = slash(mastraEntry);
|
|
734
|
+
const normalizedMastraEntry = chunk5TYVF4KJ_cjs.slash(mastraEntry);
|
|
659
735
|
let virtualPlugin = null;
|
|
660
736
|
if (isVirtualFile) {
|
|
661
737
|
virtualPlugin = virtual__default.default({
|
|
@@ -674,7 +750,7 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
|
|
|
674
750
|
name: "custom-alias-resolver",
|
|
675
751
|
resolveId(id) {
|
|
676
752
|
if (id === "#server") {
|
|
677
|
-
return slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
|
|
753
|
+
return chunk5TYVF4KJ_cjs.slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
|
|
678
754
|
}
|
|
679
755
|
if (id === "#mastra") {
|
|
680
756
|
return normalizedMastraEntry;
|
|
@@ -692,14 +768,17 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
|
|
|
692
768
|
transformMixedEsModules: true,
|
|
693
769
|
extensions: [".js", ".ts"]
|
|
694
770
|
}),
|
|
695
|
-
removeDeployer2(mastraEntry, {
|
|
771
|
+
removeDeployer2(mastraEntry, {
|
|
772
|
+
sourcemap: sourcemapEnabled
|
|
773
|
+
}),
|
|
696
774
|
esbuild()
|
|
697
775
|
]
|
|
698
776
|
);
|
|
699
777
|
return plugins;
|
|
700
778
|
}
|
|
701
779
|
async function captureDependenciesToOptimize(output, workspaceMap, projectRoot, initialDepsToOptimize, {
|
|
702
|
-
logger: logger$1
|
|
780
|
+
logger: logger$1,
|
|
781
|
+
shouldCheckTransitiveDependencies
|
|
703
782
|
}) {
|
|
704
783
|
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
705
784
|
if (!output.facadeModuleId) {
|
|
@@ -712,18 +791,22 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
|
|
|
712
791
|
entryRootPath = await getPackageRootPath(output.facadeModuleId) || projectRoot;
|
|
713
792
|
}
|
|
714
793
|
for (const [dependency, bindings] of Object.entries(output.importedBindings)) {
|
|
715
|
-
if (isNodeBuiltin(dependency) ||
|
|
794
|
+
if (isNodeBuiltin(dependency) || dependency.startsWith("#")) {
|
|
716
795
|
continue;
|
|
717
796
|
}
|
|
718
|
-
const pkgName = getPackageName(dependency);
|
|
797
|
+
const pkgName = chunk5TYVF4KJ_cjs.getPackageName(dependency);
|
|
719
798
|
let rootPath = null;
|
|
720
799
|
let isWorkspace = false;
|
|
721
800
|
if (pkgName) {
|
|
722
801
|
rootPath = await getPackageRootPath(dependency, entryRootPath);
|
|
723
802
|
isWorkspace = workspaceMap.has(pkgName);
|
|
724
803
|
}
|
|
725
|
-
const normalizedRootPath = rootPath ? slash(rootPath) : null;
|
|
726
|
-
depsToOptimize.set(dependency, {
|
|
804
|
+
const normalizedRootPath = rootPath ? chunk5TYVF4KJ_cjs.slash(rootPath) : null;
|
|
805
|
+
depsToOptimize.set(dependency, {
|
|
806
|
+
exports: bindings,
|
|
807
|
+
rootPath: normalizedRootPath,
|
|
808
|
+
isWorkspace
|
|
809
|
+
});
|
|
727
810
|
}
|
|
728
811
|
async function checkTransitiveDependencies(internalMap, maxDepth = 10, currentDepth = 0) {
|
|
729
812
|
if (currentDepth >= maxDepth) {
|
|
@@ -767,12 +850,18 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
|
|
|
767
850
|
await checkTransitiveDependencies(internalMap, maxDepth, currentDepth + 1);
|
|
768
851
|
}
|
|
769
852
|
}
|
|
770
|
-
|
|
853
|
+
if (shouldCheckTransitiveDependencies) {
|
|
854
|
+
await checkTransitiveDependencies(initialDepsToOptimize);
|
|
855
|
+
}
|
|
771
856
|
const dynamicImports = output.dynamicImports.filter((d) => !DEPS_TO_IGNORE.includes(d));
|
|
772
857
|
if (dynamicImports.length) {
|
|
773
858
|
for (const dynamicImport of dynamicImports) {
|
|
774
859
|
if (!depsToOptimize.has(dynamicImport) && !isNodeBuiltin(dynamicImport)) {
|
|
775
|
-
depsToOptimize.set(dynamicImport, {
|
|
860
|
+
depsToOptimize.set(dynamicImport, {
|
|
861
|
+
exports: ["*"],
|
|
862
|
+
rootPath: null,
|
|
863
|
+
isWorkspace: false
|
|
864
|
+
});
|
|
776
865
|
}
|
|
777
866
|
}
|
|
778
867
|
}
|
|
@@ -786,13 +875,14 @@ async function analyzeEntry({
|
|
|
786
875
|
sourcemapEnabled,
|
|
787
876
|
workspaceMap,
|
|
788
877
|
projectRoot,
|
|
789
|
-
initialDepsToOptimize = /* @__PURE__ */ new Map()
|
|
878
|
+
initialDepsToOptimize = /* @__PURE__ */ new Map(),
|
|
790
879
|
// used to avoid infinite recursion
|
|
880
|
+
shouldCheckTransitiveDependencies = false
|
|
791
881
|
}) {
|
|
792
882
|
const optimizerBundler = await rollup.rollup({
|
|
793
883
|
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
794
884
|
input: isVirtualFile ? "#entry" : entry,
|
|
795
|
-
treeshake:
|
|
885
|
+
treeshake: false,
|
|
796
886
|
preserveSymlinks: true,
|
|
797
887
|
plugins: getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }),
|
|
798
888
|
external: DEPS_TO_IGNORE
|
|
@@ -808,7 +898,8 @@ async function analyzeEntry({
|
|
|
808
898
|
projectRoot,
|
|
809
899
|
initialDepsToOptimize,
|
|
810
900
|
{
|
|
811
|
-
logger
|
|
901
|
+
logger,
|
|
902
|
+
shouldCheckTransitiveDependencies
|
|
812
903
|
}
|
|
813
904
|
);
|
|
814
905
|
return {
|
|
@@ -819,6 +910,27 @@ async function analyzeEntry({
|
|
|
819
910
|
}
|
|
820
911
|
};
|
|
821
912
|
}
|
|
913
|
+
var FilenameDeclarationRegex = /(?:const|let|var)\s+__filename/;
|
|
914
|
+
var DirnameDeclarationRegex = /(?:const|let|var)\s+__dirname/;
|
|
915
|
+
function esmShim() {
|
|
916
|
+
const original = originalEsmShim__default.default();
|
|
917
|
+
return {
|
|
918
|
+
name: "esm-shim",
|
|
919
|
+
renderChunk(code, chunk, opts, meta) {
|
|
920
|
+
const hasFilename = code.includes("__filename");
|
|
921
|
+
const hasDirname = code.includes("__dirname");
|
|
922
|
+
const userDeclaredFilename = hasFilename && FilenameDeclarationRegex.test(code);
|
|
923
|
+
const userDeclaredDirname = hasDirname && DirnameDeclarationRegex.test(code);
|
|
924
|
+
if (userDeclaredFilename || userDeclaredDirname) {
|
|
925
|
+
return null;
|
|
926
|
+
}
|
|
927
|
+
if (typeof original.renderChunk === "function") {
|
|
928
|
+
return original.renderChunk.call(this, code, chunk, opts, meta);
|
|
929
|
+
}
|
|
930
|
+
return null;
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
}
|
|
822
934
|
function aliasHono() {
|
|
823
935
|
return {
|
|
824
936
|
name: "hono-alias",
|
|
@@ -831,8 +943,116 @@ function aliasHono() {
|
|
|
831
943
|
}
|
|
832
944
|
};
|
|
833
945
|
}
|
|
946
|
+
function nodeGypDetector() {
|
|
947
|
+
const modulesToTrack = /* @__PURE__ */ new Set();
|
|
948
|
+
const modulesToTrackPackageInfo = /* @__PURE__ */ new Map();
|
|
949
|
+
return {
|
|
950
|
+
name: "node-gyp-build-detector",
|
|
951
|
+
moduleParsed(info) {
|
|
952
|
+
if (!info.meta?.commonjs?.requires?.length) {
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
const hasNodeGypBuild = info.meta.commonjs.requires.some(
|
|
956
|
+
(m) => m?.resolved?.id.endsWith("node-gyp-build/index.js")
|
|
957
|
+
);
|
|
958
|
+
if (!hasNodeGypBuild) {
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
modulesToTrack.add(info.id);
|
|
962
|
+
modulesToTrackPackageInfo.set(info.id, localPkg.getPackageInfo(info.id));
|
|
963
|
+
},
|
|
964
|
+
async generateBundle(options, bundle) {
|
|
965
|
+
const binaryMapByChunk = /* @__PURE__ */ new Map();
|
|
966
|
+
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
967
|
+
if (chunk.type === "chunk") {
|
|
968
|
+
for (const moduleId of chunk.moduleIds) {
|
|
969
|
+
if (modulesToTrackPackageInfo.has(moduleId)) {
|
|
970
|
+
const pkgInfo = await modulesToTrackPackageInfo.get(moduleId);
|
|
971
|
+
if (!binaryMapByChunk.has(fileName)) {
|
|
972
|
+
binaryMapByChunk.set(fileName, /* @__PURE__ */ new Set());
|
|
973
|
+
}
|
|
974
|
+
if (pkgInfo?.packageJson?.name) {
|
|
975
|
+
binaryMapByChunk.get(fileName).add(pkgInfo.packageJson.name);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
const binaryMapJson = Object.fromEntries(
|
|
982
|
+
Array.from(binaryMapByChunk.entries()).map(([key, value]) => [key, Array.from(value)])
|
|
983
|
+
);
|
|
984
|
+
this.emitFile({
|
|
985
|
+
type: "asset",
|
|
986
|
+
name: "binary-map.json",
|
|
987
|
+
source: `${JSON.stringify(binaryMapJson, null, 2)}`
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
// src/build/plugins/subpath-externals-resolver.ts
|
|
994
|
+
function subpathExternalsResolver(externals) {
|
|
995
|
+
return {
|
|
996
|
+
name: "subpath-externals-resolver",
|
|
997
|
+
resolveId(id) {
|
|
998
|
+
if (id.startsWith(".") || id.startsWith("/")) {
|
|
999
|
+
return null;
|
|
1000
|
+
}
|
|
1001
|
+
const isPartOfExternals = externals.some((external) => chunk5TYVF4KJ_cjs.isDependencyPartOfPackage(id, external));
|
|
1002
|
+
if (isPartOfExternals) {
|
|
1003
|
+
return {
|
|
1004
|
+
id,
|
|
1005
|
+
external: true
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
function moduleResolveMap(externals, projectRoot) {
|
|
1012
|
+
const importMap = /* @__PURE__ */ new Map();
|
|
1013
|
+
return {
|
|
1014
|
+
name: "module-resolve-map",
|
|
1015
|
+
moduleParsed(info) {
|
|
1016
|
+
if (info.importedIds.length === 0 || !info.id) {
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
for (const importedId of info.importedIds) {
|
|
1020
|
+
for (const external of externals) {
|
|
1021
|
+
if (chunk5TYVF4KJ_cjs.isDependencyPartOfPackage(importedId, external)) {
|
|
1022
|
+
importMap.set(external, info.id);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
},
|
|
1027
|
+
async generateBundle(options, bundle) {
|
|
1028
|
+
const resolveMap = /* @__PURE__ */ new Map();
|
|
1029
|
+
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
1030
|
+
if (chunk.type === "chunk") {
|
|
1031
|
+
for (const [external, resolvedFrom] of importMap) {
|
|
1032
|
+
if (chunk.moduleIds.includes(resolvedFrom)) {
|
|
1033
|
+
const fullPath = url.pathToFileURL(chunk5TYVF4KJ_cjs.slash(path2.join(projectRoot, fileName))).toString();
|
|
1034
|
+
const innerMap = resolveMap.get(fullPath) || /* @__PURE__ */ new Map();
|
|
1035
|
+
innerMap.set(external, url.pathToFileURL(chunk5TYVF4KJ_cjs.slash(resolvedFrom)).toString());
|
|
1036
|
+
resolveMap.set(fullPath, innerMap);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
const resolveMapJson = Object.fromEntries(
|
|
1042
|
+
Array.from(resolveMap.entries()).map(([key, value]) => [key, Object.fromEntries(value.entries())])
|
|
1043
|
+
);
|
|
1044
|
+
this.emitFile({
|
|
1045
|
+
type: "asset",
|
|
1046
|
+
name: "module-resolve-map.json",
|
|
1047
|
+
source: `${JSON.stringify(resolveMapJson, null, 2)}`
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// src/build/analyze/bundleExternals.ts
|
|
834
1054
|
function prepareEntryFileName(name, rootDir) {
|
|
835
|
-
return rollupSafeName(name, rootDir);
|
|
1055
|
+
return chunk5TYVF4KJ_cjs.rollupSafeName(name, rootDir);
|
|
836
1056
|
}
|
|
837
1057
|
function createVirtualDependencies(depsToOptimize, {
|
|
838
1058
|
projectRoot,
|
|
@@ -840,7 +1060,7 @@ function createVirtualDependencies(depsToOptimize, {
|
|
|
840
1060
|
outputDir,
|
|
841
1061
|
bundlerOptions
|
|
842
1062
|
}) {
|
|
843
|
-
const { isDev = false } = bundlerOptions || {};
|
|
1063
|
+
const { isDev = false, externalsPreset = false } = bundlerOptions || {};
|
|
844
1064
|
const fileNameToDependencyMap = /* @__PURE__ */ new Map();
|
|
845
1065
|
const optimizedDependencyEntries = /* @__PURE__ */ new Map();
|
|
846
1066
|
const rootDir = workspaceRoot || projectRoot;
|
|
@@ -872,7 +1092,7 @@ function createVirtualDependencies(depsToOptimize, {
|
|
|
872
1092
|
virtual: virtualFile.join("\n")
|
|
873
1093
|
});
|
|
874
1094
|
}
|
|
875
|
-
if (isDev) {
|
|
1095
|
+
if (isDev || externalsPreset) {
|
|
876
1096
|
for (const [dep, { isWorkspace, rootPath }] of depsToOptimize.entries()) {
|
|
877
1097
|
if (!isWorkspace || !rootPath || !workspaceRoot) {
|
|
878
1098
|
continue;
|
|
@@ -882,7 +1102,7 @@ function createVirtualDependencies(depsToOptimize, {
|
|
|
882
1102
|
continue;
|
|
883
1103
|
}
|
|
884
1104
|
const fileName = posix.basename(currentDepPath.name);
|
|
885
|
-
const entryName = prepareEntryFileName(getCompiledDepCachePath(rootPath, fileName), rootDir);
|
|
1105
|
+
const entryName = prepareEntryFileName(chunk5TYVF4KJ_cjs.getCompiledDepCachePath(rootPath, fileName), rootDir);
|
|
886
1106
|
fileNameToDependencyMap.set(entryName, dep);
|
|
887
1107
|
optimizedDependencyEntries.set(dep, {
|
|
888
1108
|
...currentDepPath,
|
|
@@ -896,13 +1116,14 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
896
1116
|
transpilePackages,
|
|
897
1117
|
workspaceMap,
|
|
898
1118
|
bundlerOptions,
|
|
899
|
-
rootDir
|
|
1119
|
+
rootDir,
|
|
1120
|
+
externals
|
|
900
1121
|
}) {
|
|
901
1122
|
const transpilePackagesMap = /* @__PURE__ */ new Map();
|
|
902
1123
|
for (const pkg2 of transpilePackages) {
|
|
903
1124
|
const dir = await getPackageRootPath(pkg2);
|
|
904
1125
|
if (dir) {
|
|
905
|
-
transpilePackagesMap.set(pkg2, slash(dir));
|
|
1126
|
+
transpilePackagesMap.set(pkg2, chunk5TYVF4KJ_cjs.slash(dir));
|
|
906
1127
|
} else {
|
|
907
1128
|
transpilePackagesMap.set(pkg2, workspaceMap.get(pkg2)?.location ?? pkg2);
|
|
908
1129
|
}
|
|
@@ -917,6 +1138,7 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
917
1138
|
{}
|
|
918
1139
|
)
|
|
919
1140
|
),
|
|
1141
|
+
subpathExternalsResolver(externals),
|
|
920
1142
|
transpilePackagesMap.size ? esbuild({
|
|
921
1143
|
format: "esm",
|
|
922
1144
|
include: [...transpilePackagesMap.values()].map((p) => {
|
|
@@ -927,7 +1149,7 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
927
1149
|
}
|
|
928
1150
|
})
|
|
929
1151
|
}) : null,
|
|
930
|
-
bundlerOptions.
|
|
1152
|
+
bundlerOptions.noBundling ? {
|
|
931
1153
|
name: "alias-optimized-deps",
|
|
932
1154
|
async resolveId(id, importer, options) {
|
|
933
1155
|
if (!virtualDependencies.has(id)) {
|
|
@@ -945,7 +1167,8 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
945
1167
|
if (!resolvedPath) {
|
|
946
1168
|
resolvedPath = pkgJson.main ?? "index.js";
|
|
947
1169
|
}
|
|
948
|
-
|
|
1170
|
+
const resolved = await this.resolve(path2__namespace.posix.join(packageRootPath, resolvedPath), importer, options);
|
|
1171
|
+
return resolved;
|
|
949
1172
|
}
|
|
950
1173
|
} : null,
|
|
951
1174
|
rollupPlugin.optimizeLodashImports({
|
|
@@ -956,14 +1179,16 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
956
1179
|
transformMixedEsModules: true,
|
|
957
1180
|
ignoreTryCatch: false
|
|
958
1181
|
}),
|
|
959
|
-
bundlerOptions.
|
|
1182
|
+
bundlerOptions.noBundling ? null : nodeResolve__default.default({
|
|
960
1183
|
preferBuiltins: true,
|
|
961
1184
|
exportConditions: ["node"]
|
|
962
1185
|
}),
|
|
963
|
-
bundlerOptions.
|
|
1186
|
+
bundlerOptions.noBundling ? esmShim() : null,
|
|
964
1187
|
// hono is imported from deployer, so we need to resolve from here instead of the project root
|
|
965
1188
|
aliasHono(),
|
|
966
1189
|
json__default.default(),
|
|
1190
|
+
nodeGypDetector(),
|
|
1191
|
+
moduleResolveMap(externals, rootDir),
|
|
967
1192
|
{
|
|
968
1193
|
name: "not-found-resolver",
|
|
969
1194
|
resolveId: {
|
|
@@ -1011,6 +1236,16 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1011
1236
|
if (virtualDependencies.size === 0) {
|
|
1012
1237
|
return [];
|
|
1013
1238
|
}
|
|
1239
|
+
const noBundling = bundlerOptions.isDev || bundlerOptions.externalsPreset;
|
|
1240
|
+
const plugins = await getInputPlugins2(virtualDependencies, {
|
|
1241
|
+
transpilePackages: packagesToTranspile,
|
|
1242
|
+
workspaceMap,
|
|
1243
|
+
bundlerOptions: {
|
|
1244
|
+
noBundling
|
|
1245
|
+
},
|
|
1246
|
+
rootDir,
|
|
1247
|
+
externals
|
|
1248
|
+
});
|
|
1014
1249
|
const bundler = await rollup.rollup({
|
|
1015
1250
|
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
1016
1251
|
input: Array.from(virtualDependencies.entries()).reduce(
|
|
@@ -1021,30 +1256,27 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1021
1256
|
{}
|
|
1022
1257
|
),
|
|
1023
1258
|
external: externals,
|
|
1024
|
-
treeshake: "safest",
|
|
1025
|
-
plugins
|
|
1026
|
-
transpilePackages: packagesToTranspile,
|
|
1027
|
-
workspaceMap,
|
|
1028
|
-
bundlerOptions,
|
|
1029
|
-
rootDir
|
|
1030
|
-
})
|
|
1259
|
+
treeshake: noBundling ? false : "safest",
|
|
1260
|
+
plugins
|
|
1031
1261
|
});
|
|
1032
1262
|
const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
|
|
1033
1263
|
const { output } = await bundler.write({
|
|
1034
1264
|
format: "esm",
|
|
1035
1265
|
dir: rootDir,
|
|
1036
1266
|
entryFileNames: "[name].mjs",
|
|
1267
|
+
// used to get the filename of the actual error
|
|
1268
|
+
sourcemap: true,
|
|
1037
1269
|
/**
|
|
1038
1270
|
* Rollup creates chunks for common dependencies, but these chunks are by default written to the root directory instead of respecting the entryFileNames structure.
|
|
1039
1271
|
* So we want to write them to the `.mastra/output` folder as well.
|
|
1040
1272
|
*/
|
|
1041
1273
|
chunkFileNames: (chunkInfo) => {
|
|
1042
|
-
if (
|
|
1274
|
+
if (noBundling) {
|
|
1043
1275
|
const importedFromPackages = /* @__PURE__ */ new Set();
|
|
1044
1276
|
for (const moduleId of chunkInfo.moduleIds) {
|
|
1045
|
-
const normalized = slash(moduleId);
|
|
1277
|
+
const normalized = chunk5TYVF4KJ_cjs.slash(moduleId);
|
|
1046
1278
|
for (const [pkgName, pkgInfo] of workspaceMap.entries()) {
|
|
1047
|
-
const location = slash(pkgInfo.location);
|
|
1279
|
+
const location = chunk5TYVF4KJ_cjs.slash(pkgInfo.location);
|
|
1048
1280
|
if (normalized.startsWith(location)) {
|
|
1049
1281
|
importedFromPackages.add(pkgName);
|
|
1050
1282
|
break;
|
|
@@ -1066,11 +1298,12 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1066
1298
|
if (importedFromPackages.size === 1) {
|
|
1067
1299
|
const [pkgName] = importedFromPackages;
|
|
1068
1300
|
const workspaceLocation = workspaceMap.get(pkgName).location;
|
|
1069
|
-
return prepareEntryFileName(getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
|
|
1301
|
+
return prepareEntryFileName(chunk5TYVF4KJ_cjs.getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
|
|
1070
1302
|
}
|
|
1071
1303
|
}
|
|
1072
1304
|
return `${outputDirRelative}/[name].mjs`;
|
|
1073
1305
|
},
|
|
1306
|
+
assetFileNames: `${outputDirRelative}/[name][extname]`,
|
|
1074
1307
|
hoistTransitiveImports: false
|
|
1075
1308
|
});
|
|
1076
1309
|
await bundler.close();
|
|
@@ -1079,7 +1312,7 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1079
1312
|
function findExternalImporter(module, external, allOutputs) {
|
|
1080
1313
|
const capturedFiles = /* @__PURE__ */ new Set();
|
|
1081
1314
|
for (const id of module.imports) {
|
|
1082
|
-
if (id
|
|
1315
|
+
if (chunk5TYVF4KJ_cjs.isDependencyPartOfPackage(id, external)) {
|
|
1083
1316
|
return module;
|
|
1084
1317
|
} else {
|
|
1085
1318
|
if (id.endsWith(".mjs")) {
|
|
@@ -1100,19 +1333,31 @@ function findExternalImporter(module, external, allOutputs) {
|
|
|
1100
1333
|
}
|
|
1101
1334
|
async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
1102
1335
|
const { workspaceRoot = null, workspaceMap = /* @__PURE__ */ new Map(), projectRoot = outputDir, bundlerOptions = {} } = options;
|
|
1103
|
-
const {
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1336
|
+
const { externals: customExternals = [], transpilePackages = [], isDev = false } = bundlerOptions || {};
|
|
1337
|
+
let externalsPreset = false;
|
|
1338
|
+
if (customExternals === true) {
|
|
1339
|
+
externalsPreset = true;
|
|
1340
|
+
}
|
|
1341
|
+
const externalsList = Array.isArray(customExternals) ? customExternals : [];
|
|
1342
|
+
const allExternals = [...GLOBAL_EXTERNALS, ...DEPRECATED_EXTERNALS, ...externalsList];
|
|
1108
1343
|
const workspacePackagesNames = Array.from(workspaceMap.keys());
|
|
1109
1344
|
const packagesToTranspile = /* @__PURE__ */ new Set([...transpilePackages, ...workspacePackagesNames]);
|
|
1345
|
+
const extractedExternals = /* @__PURE__ */ new Map();
|
|
1346
|
+
if (externalsPreset) {
|
|
1347
|
+
for (const [dep, metadata] of depsToOptimize.entries()) {
|
|
1348
|
+
if (!metadata.isWorkspace) {
|
|
1349
|
+
extractedExternals.set(dep, metadata.rootPath ?? dep);
|
|
1350
|
+
depsToOptimize.delete(dep);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1110
1354
|
const { optimizedDependencyEntries, fileNameToDependencyMap } = createVirtualDependencies(depsToOptimize, {
|
|
1111
1355
|
workspaceRoot,
|
|
1112
1356
|
outputDir,
|
|
1113
1357
|
projectRoot,
|
|
1114
1358
|
bundlerOptions: {
|
|
1115
|
-
isDev
|
|
1359
|
+
isDev,
|
|
1360
|
+
externalsPreset
|
|
1116
1361
|
}
|
|
1117
1362
|
});
|
|
1118
1363
|
const output = await buildExternalDependencies(optimizedDependencyEntries, {
|
|
@@ -1122,10 +1367,11 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1122
1367
|
rootDir: workspaceRoot || projectRoot,
|
|
1123
1368
|
outputDir,
|
|
1124
1369
|
bundlerOptions: {
|
|
1125
|
-
isDev
|
|
1370
|
+
isDev,
|
|
1371
|
+
externalsPreset
|
|
1126
1372
|
}
|
|
1127
1373
|
});
|
|
1128
|
-
const
|
|
1374
|
+
const moduleResolveMap2 = /* @__PURE__ */ new Map();
|
|
1129
1375
|
const filteredChunks = output.filter((o) => o.type === "chunk");
|
|
1130
1376
|
for (const o of filteredChunks.filter((o2) => o2.isEntry || o2.isDynamicEntry)) {
|
|
1131
1377
|
for (const external of allExternals) {
|
|
@@ -1135,10 +1381,10 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1135
1381
|
const importer = findExternalImporter(o, external, filteredChunks);
|
|
1136
1382
|
if (importer) {
|
|
1137
1383
|
const fullPath = path2__namespace.join(workspaceRoot || projectRoot, importer.fileName);
|
|
1138
|
-
let innerMap =
|
|
1384
|
+
let innerMap = moduleResolveMap2.get(fullPath);
|
|
1139
1385
|
if (!innerMap) {
|
|
1140
1386
|
innerMap = /* @__PURE__ */ new Map();
|
|
1141
|
-
|
|
1387
|
+
moduleResolveMap2.set(fullPath, innerMap);
|
|
1142
1388
|
}
|
|
1143
1389
|
if (importer.moduleIds.length) {
|
|
1144
1390
|
innerMap.set(
|
|
@@ -1150,15 +1396,125 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1150
1396
|
}
|
|
1151
1397
|
}
|
|
1152
1398
|
const usedExternals = /* @__PURE__ */ Object.create(null);
|
|
1153
|
-
for (const [fullPath, innerMap] of
|
|
1399
|
+
for (const [fullPath, innerMap] of moduleResolveMap2) {
|
|
1154
1400
|
const innerObj = /* @__PURE__ */ Object.create(null);
|
|
1155
1401
|
for (const [external, value] of innerMap) {
|
|
1156
1402
|
innerObj[external] = value;
|
|
1157
1403
|
}
|
|
1158
1404
|
usedExternals[fullPath] = innerObj;
|
|
1159
1405
|
}
|
|
1406
|
+
if (extractedExternals.size > 0) {
|
|
1407
|
+
const syntheticPath = path2__namespace.join(workspaceRoot || projectRoot, "__externals__");
|
|
1408
|
+
const externalsObj = /* @__PURE__ */ Object.create(null);
|
|
1409
|
+
for (const [dep, rootPath] of extractedExternals) {
|
|
1410
|
+
externalsObj[dep] = rootPath;
|
|
1411
|
+
}
|
|
1412
|
+
usedExternals[syntheticPath] = externalsObj;
|
|
1413
|
+
}
|
|
1160
1414
|
return { output, fileNameToDependencyMap, usedExternals };
|
|
1161
1415
|
}
|
|
1416
|
+
|
|
1417
|
+
// ../../node_modules/.pnpm/stacktrace-parser@0.1.11/node_modules/stacktrace-parser/dist/stack-trace-parser.esm.js
|
|
1418
|
+
var UNKNOWN_FUNCTION = "<unknown>";
|
|
1419
|
+
function parse(stackString) {
|
|
1420
|
+
var lines = stackString.split("\n");
|
|
1421
|
+
return lines.reduce(function(stack, line) {
|
|
1422
|
+
var parseResult = parseChrome(line) || parseWinjs(line) || parseGecko(line) || parseNode(line) || parseJSC(line);
|
|
1423
|
+
if (parseResult) {
|
|
1424
|
+
stack.push(parseResult);
|
|
1425
|
+
}
|
|
1426
|
+
return stack;
|
|
1427
|
+
}, []);
|
|
1428
|
+
}
|
|
1429
|
+
var chromeRe = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|rsc|<anonymous>|\/|[a-z]:\\|\\\\).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
|
|
1430
|
+
var chromeEvalRe = /\((\S*)(?::(\d+))(?::(\d+))\)/;
|
|
1431
|
+
function parseChrome(line) {
|
|
1432
|
+
var parts = chromeRe.exec(line);
|
|
1433
|
+
if (!parts) {
|
|
1434
|
+
return null;
|
|
1435
|
+
}
|
|
1436
|
+
var isNative = parts[2] && parts[2].indexOf("native") === 0;
|
|
1437
|
+
var isEval = parts[2] && parts[2].indexOf("eval") === 0;
|
|
1438
|
+
var submatch = chromeEvalRe.exec(parts[2]);
|
|
1439
|
+
if (isEval && submatch != null) {
|
|
1440
|
+
parts[2] = submatch[1];
|
|
1441
|
+
parts[3] = submatch[2];
|
|
1442
|
+
parts[4] = submatch[3];
|
|
1443
|
+
}
|
|
1444
|
+
return {
|
|
1445
|
+
file: !isNative ? parts[2] : null,
|
|
1446
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1447
|
+
arguments: isNative ? [parts[2]] : [],
|
|
1448
|
+
lineNumber: parts[3] ? +parts[3] : null,
|
|
1449
|
+
column: parts[4] ? +parts[4] : null
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
var winjsRe = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|rsc|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
1453
|
+
function parseWinjs(line) {
|
|
1454
|
+
var parts = winjsRe.exec(line);
|
|
1455
|
+
if (!parts) {
|
|
1456
|
+
return null;
|
|
1457
|
+
}
|
|
1458
|
+
return {
|
|
1459
|
+
file: parts[2],
|
|
1460
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1461
|
+
arguments: [],
|
|
1462
|
+
lineNumber: +parts[3],
|
|
1463
|
+
column: parts[4] ? +parts[4] : null
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
var geckoRe = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|rsc|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i;
|
|
1467
|
+
var geckoEvalRe = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
|
|
1468
|
+
function parseGecko(line) {
|
|
1469
|
+
var parts = geckoRe.exec(line);
|
|
1470
|
+
if (!parts) {
|
|
1471
|
+
return null;
|
|
1472
|
+
}
|
|
1473
|
+
var isEval = parts[3] && parts[3].indexOf(" > eval") > -1;
|
|
1474
|
+
var submatch = geckoEvalRe.exec(parts[3]);
|
|
1475
|
+
if (isEval && submatch != null) {
|
|
1476
|
+
parts[3] = submatch[1];
|
|
1477
|
+
parts[4] = submatch[2];
|
|
1478
|
+
parts[5] = null;
|
|
1479
|
+
}
|
|
1480
|
+
return {
|
|
1481
|
+
file: parts[3],
|
|
1482
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1483
|
+
arguments: parts[2] ? parts[2].split(",") : [],
|
|
1484
|
+
lineNumber: parts[4] ? +parts[4] : null,
|
|
1485
|
+
column: parts[5] ? +parts[5] : null
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
var javaScriptCoreRe = /^\s*(?:([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$/i;
|
|
1489
|
+
function parseJSC(line) {
|
|
1490
|
+
var parts = javaScriptCoreRe.exec(line);
|
|
1491
|
+
if (!parts) {
|
|
1492
|
+
return null;
|
|
1493
|
+
}
|
|
1494
|
+
return {
|
|
1495
|
+
file: parts[3],
|
|
1496
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1497
|
+
arguments: [],
|
|
1498
|
+
lineNumber: +parts[4],
|
|
1499
|
+
column: parts[5] ? +parts[5] : null
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
var nodeRe = /^\s*at (?:((?:\[object object\])?[^\\/]+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
1503
|
+
function parseNode(line) {
|
|
1504
|
+
var parts = nodeRe.exec(line);
|
|
1505
|
+
if (!parts) {
|
|
1506
|
+
return null;
|
|
1507
|
+
}
|
|
1508
|
+
return {
|
|
1509
|
+
file: parts[2],
|
|
1510
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1511
|
+
arguments: [],
|
|
1512
|
+
lineNumber: +parts[3],
|
|
1513
|
+
column: parts[4] ? +parts[4] : null
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
// src/build/analyze.ts
|
|
1162
1518
|
function throwExternalDependencyError({
|
|
1163
1519
|
errorId,
|
|
1164
1520
|
moduleName,
|
|
@@ -1182,6 +1538,110 @@ export const mastra = new Mastra({
|
|
|
1182
1538
|
})`
|
|
1183
1539
|
});
|
|
1184
1540
|
}
|
|
1541
|
+
function getPackageNameFromBundledModuleName(moduleName) {
|
|
1542
|
+
const chunks = moduleName.split("-");
|
|
1543
|
+
if (!chunks.length) {
|
|
1544
|
+
return moduleName;
|
|
1545
|
+
}
|
|
1546
|
+
if (chunks[0]?.startsWith("@")) {
|
|
1547
|
+
return chunks.slice(0, 2).join("/");
|
|
1548
|
+
}
|
|
1549
|
+
return chunks[0];
|
|
1550
|
+
}
|
|
1551
|
+
function validateError(err, file, {
|
|
1552
|
+
binaryMapData,
|
|
1553
|
+
workspaceMap
|
|
1554
|
+
}) {
|
|
1555
|
+
let moduleName = null;
|
|
1556
|
+
let errorConfig = null;
|
|
1557
|
+
if (err instanceof ValidationError) {
|
|
1558
|
+
const parsedStack = parse(err.stack);
|
|
1559
|
+
if (err.type === "TypeError") {
|
|
1560
|
+
const pkgNameRegex = /.*node_modules\/([^\/]+)\//;
|
|
1561
|
+
const stacktraceFrame = parsedStack.find((frame) => frame.file && pkgNameRegex.test(frame.file));
|
|
1562
|
+
if (stacktraceFrame) {
|
|
1563
|
+
const match = stacktraceFrame.file.match(pkgNameRegex);
|
|
1564
|
+
moduleName = match?.[1] ?? getPackageNameFromBundledModuleName(path2.basename(file.name));
|
|
1565
|
+
} else {
|
|
1566
|
+
moduleName = getPackageNameFromBundledModuleName(path2.basename(file.name));
|
|
1567
|
+
}
|
|
1568
|
+
errorConfig = {
|
|
1569
|
+
id: "DEPLOYER_ANALYZE_TYPE_ERROR",
|
|
1570
|
+
messagePrefix: `Mastra wasn't able to bundle "${moduleName}", might be an older commonJS module. Please add`
|
|
1571
|
+
};
|
|
1572
|
+
} else if (err.stack?.includes?.("[ERR_MODULE_NOT_FOUND]")) {
|
|
1573
|
+
moduleName = err.message.match(/Cannot find package '([^']+)'/)?.[1];
|
|
1574
|
+
const parentModuleName = getPackageNameFromBundledModuleName(path2.basename(file.name));
|
|
1575
|
+
errorConfig = {
|
|
1576
|
+
id: "DEPLOYER_ANALYZE_MODULE_NOT_FOUND",
|
|
1577
|
+
messagePrefix: `Mastra wasn't able to build your project, We couldn't load "${moduleName}" from "${parentModuleName}". Make sure "${moduleName}" is installed or add`
|
|
1578
|
+
};
|
|
1579
|
+
if (moduleName === parentModuleName) {
|
|
1580
|
+
return;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
if (err.message.includes("No native build was found")) {
|
|
1585
|
+
const pkgName = getPackageNameFromBundledModuleName(path2.basename(file.name));
|
|
1586
|
+
moduleName = binaryMapData[file.fileName]?.[0] ?? pkgName;
|
|
1587
|
+
errorConfig = {
|
|
1588
|
+
id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
|
|
1589
|
+
messagePrefix: "We found a binary dependency in your bundle but we cannot bundle it yet. Please add"
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
if (moduleName && workspaceMap.has(moduleName)) {
|
|
1593
|
+
throw new error.MastraError({
|
|
1594
|
+
id: "DEPLOYER_ANALYZE_ERROR_IN_WORKSPACE",
|
|
1595
|
+
domain: error.ErrorDomain.DEPLOYER,
|
|
1596
|
+
category: error.ErrorCategory.USER,
|
|
1597
|
+
details: {
|
|
1598
|
+
// importFile: moduleName,
|
|
1599
|
+
packageName: moduleName
|
|
1600
|
+
},
|
|
1601
|
+
text: `We found an error in the ${moduleName} workspace package. Please find the offending package and fix the error.
|
|
1602
|
+
Error: ${err.stack}`
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
if (errorConfig && moduleName) {
|
|
1606
|
+
throwExternalDependencyError({
|
|
1607
|
+
errorId: errorConfig.id,
|
|
1608
|
+
moduleName,
|
|
1609
|
+
packageName: moduleName,
|
|
1610
|
+
messagePrefix: errorConfig.messagePrefix
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
async function validateFile(root, file, {
|
|
1615
|
+
binaryMapData,
|
|
1616
|
+
moduleResolveMapLocation,
|
|
1617
|
+
logger,
|
|
1618
|
+
workspaceMap
|
|
1619
|
+
}) {
|
|
1620
|
+
try {
|
|
1621
|
+
if (!file.isDynamicEntry && file.isEntry) {
|
|
1622
|
+
await validate(path2.join(root, file.fileName), {
|
|
1623
|
+
moduleResolveMapLocation,
|
|
1624
|
+
injectESMShim: false
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
} catch (err) {
|
|
1628
|
+
let errorToHandle = err;
|
|
1629
|
+
if (err instanceof ValidationError && err.type === "ReferenceError" && (err.message.startsWith("__dirname") || err.message.startsWith("__filename"))) {
|
|
1630
|
+
try {
|
|
1631
|
+
await validate(path2.join(root, file.fileName), {
|
|
1632
|
+
moduleResolveMapLocation,
|
|
1633
|
+
injectESMShim: true
|
|
1634
|
+
});
|
|
1635
|
+
errorToHandle = null;
|
|
1636
|
+
} catch (err2) {
|
|
1637
|
+
errorToHandle = err2;
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
if (errorToHandle instanceof Error) {
|
|
1641
|
+
validateError(errorToHandle, file, { binaryMapData, workspaceMap });
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1185
1645
|
async function validateOutput({
|
|
1186
1646
|
output,
|
|
1187
1647
|
reverseVirtualReferenceMap,
|
|
@@ -1195,60 +1655,30 @@ async function validateOutput({
|
|
|
1195
1655
|
externalDependencies: /* @__PURE__ */ new Set(),
|
|
1196
1656
|
workspaceMap
|
|
1197
1657
|
};
|
|
1198
|
-
await promises.writeFile(path2.join(outputDir, "module-resolve-map.json"), JSON.stringify(usedExternals, null, 2));
|
|
1199
1658
|
for (const deps of Object.values(usedExternals)) {
|
|
1200
1659
|
for (const dep of Object.keys(deps)) {
|
|
1201
1660
|
result.externalDependencies.add(dep);
|
|
1202
1661
|
}
|
|
1203
1662
|
}
|
|
1663
|
+
let binaryMapData = {};
|
|
1664
|
+
if (fs.existsSync(path2.join(outputDir, "binary-map.json"))) {
|
|
1665
|
+
const binaryMap = await promises.readFile(path2.join(outputDir, "binary-map.json"), "utf-8");
|
|
1666
|
+
binaryMapData = JSON.parse(binaryMap);
|
|
1667
|
+
}
|
|
1204
1668
|
for (const file of output) {
|
|
1205
1669
|
if (file.type === "asset") {
|
|
1206
1670
|
continue;
|
|
1207
1671
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
|
|
1212
|
-
}
|
|
1213
|
-
if (!file.isDynamicEntry && file.isEntry) {
|
|
1214
|
-
await validate(path2.join(projectRoot, file.fileName));
|
|
1215
|
-
}
|
|
1216
|
-
} catch (err) {
|
|
1217
|
-
if (err instanceof Error) {
|
|
1218
|
-
let moduleName = null;
|
|
1219
|
-
let errorConfig = null;
|
|
1220
|
-
if (err.message.includes("[ERR_MODULE_NOT_FOUND]")) {
|
|
1221
|
-
const moduleIdName = file.moduleIds.length >= 2 ? file.moduleIds[file.moduleIds.length - 2] : void 0;
|
|
1222
|
-
const fallbackName = file.name.split("/").pop();
|
|
1223
|
-
moduleName = moduleIdName ?? fallbackName;
|
|
1224
|
-
errorConfig = {
|
|
1225
|
-
id: "DEPLOYER_ANALYZE_MODULE_NOT_FOUND",
|
|
1226
|
-
messagePrefix: "Mastra wasn't able to build your project. Please add"
|
|
1227
|
-
};
|
|
1228
|
-
} else if (err.message.includes("Error: No native build was found for ")) {
|
|
1229
|
-
moduleName = findNativePackageModule(file.moduleIds);
|
|
1230
|
-
errorConfig = {
|
|
1231
|
-
id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
|
|
1232
|
-
messagePrefix: "We found a binary dependency in your bundle. Please add"
|
|
1233
|
-
};
|
|
1234
|
-
}
|
|
1235
|
-
if (moduleName && errorConfig) {
|
|
1236
|
-
const pkgInfo = await localPkg.getPackageInfo(moduleName);
|
|
1237
|
-
const packageName = pkgInfo?.packageJson?.name;
|
|
1238
|
-
if (packageName) {
|
|
1239
|
-
throwExternalDependencyError({
|
|
1240
|
-
errorId: errorConfig.id,
|
|
1241
|
-
moduleName,
|
|
1242
|
-
packageName,
|
|
1243
|
-
messagePrefix: errorConfig.messagePrefix
|
|
1244
|
-
});
|
|
1245
|
-
} else {
|
|
1246
|
-
logger.debug(`Could not determine the module name for file ${file.fileName}`);
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
logger.debug(`Error while validating module ${file.fileName}: ${err.message}`);
|
|
1250
|
-
}
|
|
1672
|
+
logger.debug(`Validating if ${file.fileName} is a valid module.`);
|
|
1673
|
+
if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
|
|
1674
|
+
result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
|
|
1251
1675
|
}
|
|
1676
|
+
await validateFile(projectRoot, file, {
|
|
1677
|
+
binaryMapData,
|
|
1678
|
+
moduleResolveMapLocation: path2.join(outputDir, "module-resolve-map.json"),
|
|
1679
|
+
logger,
|
|
1680
|
+
workspaceMap
|
|
1681
|
+
});
|
|
1252
1682
|
}
|
|
1253
1683
|
return result;
|
|
1254
1684
|
}
|
|
@@ -1256,7 +1686,7 @@ async function analyzeBundle(entries, mastraEntry, {
|
|
|
1256
1686
|
outputDir,
|
|
1257
1687
|
projectRoot,
|
|
1258
1688
|
isDev = false,
|
|
1259
|
-
bundlerOptions
|
|
1689
|
+
bundlerOptions
|
|
1260
1690
|
}, logger) {
|
|
1261
1691
|
const mastraConfig = await promises.readFile(mastraEntry, "utf-8");
|
|
1262
1692
|
const mastraConfigResult = {
|
|
@@ -1275,22 +1705,33 @@ export const mastra = new Mastra({
|
|
|
1275
1705
|
|
|
1276
1706
|
If you think your configuration is valid, please open an issue.`);
|
|
1277
1707
|
}
|
|
1278
|
-
const { enableEsmShim = true } = _bundlerOptions || {};
|
|
1279
|
-
const bundlerOptions = await getBundlerOptions(mastraEntry, outputDir);
|
|
1280
1708
|
const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
|
|
1709
|
+
let externalsPreset = false;
|
|
1710
|
+
const userExternals = Array.isArray(bundlerOptions?.externals) ? bundlerOptions?.externals : [];
|
|
1711
|
+
if (bundlerOptions?.externals === true) {
|
|
1712
|
+
externalsPreset = true;
|
|
1713
|
+
}
|
|
1281
1714
|
let index = 0;
|
|
1282
1715
|
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
1716
|
+
const allExternals = [...GLOBAL_EXTERNALS, ...userExternals].filter(Boolean);
|
|
1283
1717
|
logger.info("Analyzing dependencies...");
|
|
1718
|
+
const allUsedExternals = /* @__PURE__ */ new Set();
|
|
1284
1719
|
for (const entry of entries) {
|
|
1285
1720
|
const isVirtualFile = entry.includes("\n") || !fs.existsSync(entry);
|
|
1286
1721
|
const analyzeResult = await analyzeEntry({ entry, isVirtualFile }, mastraEntry, {
|
|
1287
1722
|
logger,
|
|
1288
|
-
sourcemapEnabled: bundlerOptions?.
|
|
1723
|
+
sourcemapEnabled: bundlerOptions?.enableSourcemap ?? false,
|
|
1289
1724
|
workspaceMap,
|
|
1290
|
-
projectRoot
|
|
1725
|
+
projectRoot,
|
|
1726
|
+
shouldCheckTransitiveDependencies: isDev || externalsPreset
|
|
1291
1727
|
});
|
|
1292
1728
|
await promises.writeFile(path2.join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
|
|
1293
1729
|
for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
|
|
1730
|
+
const isPartOfExternals = allExternals.some((external) => chunk5TYVF4KJ_cjs.isDependencyPartOfPackage(dep, external));
|
|
1731
|
+
if (isPartOfExternals || externalsPreset && !metadata.isWorkspace) {
|
|
1732
|
+
allUsedExternals.add(dep);
|
|
1733
|
+
continue;
|
|
1734
|
+
}
|
|
1294
1735
|
if (depsToOptimize.has(dep)) {
|
|
1295
1736
|
const existingEntry = depsToOptimize.get(dep);
|
|
1296
1737
|
depsToOptimize.set(dep, {
|
|
@@ -1302,28 +1743,49 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1302
1743
|
}
|
|
1303
1744
|
}
|
|
1304
1745
|
}
|
|
1305
|
-
if (isDev) {
|
|
1746
|
+
if (isDev || externalsPreset) {
|
|
1306
1747
|
for (const [dep, metadata] of depsToOptimize.entries()) {
|
|
1307
1748
|
if (!metadata.isWorkspace) {
|
|
1308
1749
|
depsToOptimize.delete(dep);
|
|
1309
1750
|
}
|
|
1310
1751
|
}
|
|
1311
1752
|
}
|
|
1312
|
-
|
|
1753
|
+
const sortedDeps = Array.from(depsToOptimize.keys()).sort();
|
|
1313
1754
|
logger.info("Optimizing dependencies...");
|
|
1314
|
-
logger.debug(
|
|
1315
|
-
`${Array.from(depsToOptimize.keys()).map((key) => `- ${key}`).join("\n")}`
|
|
1316
|
-
);
|
|
1755
|
+
logger.debug(`${sortedDeps.map((key) => `- ${key}`).join("\n")}`);
|
|
1317
1756
|
const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
|
|
1318
1757
|
bundlerOptions: {
|
|
1319
1758
|
...bundlerOptions,
|
|
1320
|
-
|
|
1759
|
+
externals: bundlerOptions?.externals ?? allExternals,
|
|
1321
1760
|
isDev
|
|
1322
1761
|
},
|
|
1323
1762
|
projectRoot,
|
|
1324
1763
|
workspaceRoot,
|
|
1325
1764
|
workspaceMap
|
|
1326
1765
|
});
|
|
1766
|
+
const relativeWorkspaceFolderPaths = Array.from(workspaceMap.values()).map(
|
|
1767
|
+
(pkgInfo) => path2.relative(workspaceRoot || projectRoot, pkgInfo.location)
|
|
1768
|
+
);
|
|
1769
|
+
for (const o of output) {
|
|
1770
|
+
if (o.type === "asset") {
|
|
1771
|
+
continue;
|
|
1772
|
+
}
|
|
1773
|
+
for (const i of o.imports) {
|
|
1774
|
+
if (chunk5TYVF4KJ_cjs.isBuiltinModule(i)) {
|
|
1775
|
+
continue;
|
|
1776
|
+
}
|
|
1777
|
+
if (i.startsWith(".") || i.startsWith("/")) {
|
|
1778
|
+
continue;
|
|
1779
|
+
}
|
|
1780
|
+
if (relativeWorkspaceFolderPaths.some((workspacePath) => i.startsWith(workspacePath))) {
|
|
1781
|
+
continue;
|
|
1782
|
+
}
|
|
1783
|
+
const pkgName = chunk5TYVF4KJ_cjs.getPackageName(i);
|
|
1784
|
+
if (pkgName) {
|
|
1785
|
+
allUsedExternals.add(pkgName);
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1327
1789
|
const result = await validateOutput(
|
|
1328
1790
|
{
|
|
1329
1791
|
output,
|
|
@@ -1335,20 +1797,22 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1335
1797
|
},
|
|
1336
1798
|
logger
|
|
1337
1799
|
);
|
|
1338
|
-
return
|
|
1800
|
+
return {
|
|
1801
|
+
...result,
|
|
1802
|
+
externalDependencies: /* @__PURE__ */ new Set([...result.externalDependencies, ...Array.from(allUsedExternals)])
|
|
1803
|
+
};
|
|
1339
1804
|
}
|
|
1340
1805
|
|
|
1341
1806
|
exports.aliasHono = aliasHono;
|
|
1342
1807
|
exports.analyzeBundle = analyzeBundle;
|
|
1343
1808
|
exports.esbuild = esbuild;
|
|
1809
|
+
exports.esmShim = esmShim;
|
|
1344
1810
|
exports.extractMastraOption = extractMastraOption;
|
|
1345
1811
|
exports.getBundlerOptions = getBundlerOptions;
|
|
1346
|
-
exports.getPackageName = getPackageName;
|
|
1347
1812
|
exports.getPackageRootPath = getPackageRootPath;
|
|
1348
1813
|
exports.getWorkspaceInformation = getWorkspaceInformation;
|
|
1349
|
-
exports.removeAllOptionsFromMastraExcept = removeAllOptionsFromMastraExcept;
|
|
1350
1814
|
exports.removeDeployer = removeDeployer2;
|
|
1351
|
-
exports.
|
|
1815
|
+
exports.subpathExternalsResolver = subpathExternalsResolver;
|
|
1352
1816
|
exports.tsConfigPaths = tsConfigPaths;
|
|
1353
|
-
//# sourceMappingURL=chunk-
|
|
1354
|
-
//# sourceMappingURL=chunk-
|
|
1817
|
+
//# sourceMappingURL=chunk-NWQP6PZQ.cjs.map
|
|
1818
|
+
//# sourceMappingURL=chunk-NWQP6PZQ.cjs.map
|