@mastra/deployer 0.0.0-bundle-recursion-20251030002519 → 0.0.0-bundle-version-20260121091645
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 +1261 -5
- 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/constants.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 +18 -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 +13 -9
- 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-5IFGGF2Q.cjs +112 -0
- package/dist/chunk-5IFGGF2Q.cjs.map +1 -0
- package/dist/chunk-5TYVF4KJ.cjs +76 -0
- package/dist/chunk-5TYVF4KJ.cjs.map +1 -0
- package/dist/{chunk-QOMQKAKY.cjs → chunk-6ITQIDNC.cjs} +77 -31
- package/dist/chunk-6ITQIDNC.cjs.map +1 -0
- package/dist/{chunk-ZIBSZS2J.js → chunk-6VRWO5WR.js} +70 -24
- package/dist/chunk-6VRWO5WR.js.map +1 -0
- package/dist/{chunk-JCACPNJQ.cjs → chunk-AS55XT3Y.cjs} +886 -365
- package/dist/chunk-AS55XT3Y.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-L6Z4LACC.js → chunk-FH3CFNNS.js} +77 -39
- package/dist/chunk-FH3CFNNS.js.map +1 -0
- package/dist/chunk-G6GFAPPU.js +6 -0
- package/dist/chunk-G6GFAPPU.js.map +1 -0
- package/dist/{chunk-65RQUN2A.js → chunk-GX3DPJAT.js} +873 -352
- package/dist/chunk-GX3DPJAT.js.map +1 -0
- package/dist/chunk-HPGDVJAZ.js +3 -0
- package/dist/chunk-HPGDVJAZ.js.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-QAOUDKHK.js +67 -0
- package/dist/chunk-QAOUDKHK.js.map +1 -0
- package/dist/{chunk-HS4XRPI7.cjs → chunk-RZIZWYXY.cjs} +83 -44
- package/dist/chunk-RZIZWYXY.cjs.map +1 -0
- package/dist/chunk-V4HCIN6G.js +93 -0
- package/dist/chunk-V4HCIN6G.js.map +1 -0
- package/dist/chunk-ZJA5AK4R.js +88 -0
- package/dist/chunk-ZJA5AK4R.js.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 +64 -0
- package/dist/docs/deployment/02-mastra-server.md +129 -0
- package/dist/docs/deployment/03-monorepo.md +142 -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/health.d.ts +5 -0
- package/dist/server/handlers/health.d.ts.map +1 -0
- 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/handlers/utils/query-parsers.d.ts +15 -0
- package/dist/server/handlers/utils/query-parsers.d.ts.map +1 -1
- package/dist/server/handlers/utils.d.ts +0 -7
- package/dist/server/handlers/utils.d.ts.map +1 -1
- package/dist/server/index.cjs +2813 -11309
- 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 +2813 -11310
- package/dist/server/index.js.map +1 -1
- package/dist/server/types.d.ts +1 -1
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/welcome.d.ts +1 -1
- package/dist/server/welcome.d.ts.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 +30 -30
- 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-65RQUN2A.js.map +0 -1
- package/dist/chunk-6OU6DT6H.js +0 -168
- package/dist/chunk-6OU6DT6H.js.map +0 -1
- package/dist/chunk-HS4XRPI7.cjs.map +0 -1
- package/dist/chunk-JAY7OZFT.cjs +0 -195
- package/dist/chunk-JAY7OZFT.cjs.map +0 -1
- package/dist/chunk-JCACPNJQ.cjs.map +0 -1
- package/dist/chunk-L6Z4LACC.js.map +0 -1
- package/dist/chunk-QOMQKAKY.cjs.map +0 -1
- package/dist/chunk-ZIBSZS2J.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 -22
- 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 -363
- 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 -17
- 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 -300
- 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 -22
- package/dist/server/handlers/routes/workflows/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/workflows/legacyWorkflows.d.ts +0 -11
- package/dist/server/handlers/routes/workflows/legacyWorkflows.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
|
+
import { slash, isDependencyPartOfPackage, getPackageName, isBuiltinModule, getCompiledDepCachePath, rollupSafeName } from './chunk-QAOUDKHK.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,
|
|
7
|
+
import path2__default, { dirname, join, relative, normalize, basename as basename$1 } from 'path';
|
|
7
8
|
import { spawn as spawn$1 } from 'child_process';
|
|
8
|
-
import { getPackageInfo } from 'local-pkg';
|
|
9
9
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
10
10
|
import { rollup } from 'rollup';
|
|
11
11
|
import originalEsbuild from 'rollup-plugin-esbuild';
|
|
12
12
|
import commonjs from '@rollup/plugin-commonjs';
|
|
13
13
|
import resolveFrom2 from 'resolve-from';
|
|
14
|
+
import stripJsonComments from 'strip-json-comments';
|
|
14
15
|
import { createHandler } from 'typescript-paths';
|
|
15
16
|
import { optimizeLodashImports } from '@optimize-lodash/rollup-plugin';
|
|
16
17
|
import json from '@rollup/plugin-json';
|
|
@@ -18,90 +19,27 @@ import * as pkg from 'empathic/package';
|
|
|
18
19
|
import { createWorkspacesCache, findWorkspaces, findWorkspacesRoot } from 'find-workspaces';
|
|
19
20
|
import { noopLogger } from '@mastra/core/logger';
|
|
20
21
|
import virtual from '@rollup/plugin-virtual';
|
|
22
|
+
import { readJSON } from 'fs-extra/esm';
|
|
21
23
|
import { builtinModules } from 'module';
|
|
24
|
+
import { getPackageInfo } from 'local-pkg';
|
|
22
25
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
23
|
-
import
|
|
26
|
+
import originalEsmShim from '@rollup/plugin-esm-shim';
|
|
24
27
|
import { basename } from 'path/posix';
|
|
25
28
|
import * as resolve from 'resolve.exports';
|
|
26
29
|
import { MastraBaseError, ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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));
|
|
31
|
+
var ValidationError = class extends Error {
|
|
32
|
+
type;
|
|
33
|
+
stack;
|
|
34
|
+
constructor(args) {
|
|
35
|
+
super(args.message);
|
|
36
|
+
this.type = args.type;
|
|
37
|
+
this.stack = args.stack;
|
|
73
38
|
}
|
|
74
|
-
|
|
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
|
|
39
|
+
};
|
|
103
40
|
function spawn(command, args = [], options = {}) {
|
|
104
41
|
return new Promise((resolve2, reject) => {
|
|
42
|
+
let validationError = null;
|
|
105
43
|
const childProcess = spawn$1(command, args, {
|
|
106
44
|
// stdio: 'inherit',
|
|
107
45
|
...options
|
|
@@ -111,113 +49,67 @@ function spawn(command, args = [], options = {}) {
|
|
|
111
49
|
});
|
|
112
50
|
let stderr = "";
|
|
113
51
|
childProcess.stderr?.on("data", (message) => {
|
|
114
|
-
|
|
52
|
+
try {
|
|
53
|
+
validationError = JSON.parse(message.toString());
|
|
54
|
+
} catch {
|
|
55
|
+
stderr += message;
|
|
56
|
+
}
|
|
115
57
|
});
|
|
116
58
|
childProcess.on("close", (code) => {
|
|
117
59
|
if (code === 0) {
|
|
118
60
|
resolve2();
|
|
119
61
|
} else {
|
|
120
|
-
|
|
62
|
+
if (validationError) {
|
|
63
|
+
reject(new ValidationError(validationError));
|
|
64
|
+
} else {
|
|
65
|
+
reject(new Error(stderr));
|
|
66
|
+
}
|
|
121
67
|
}
|
|
122
68
|
});
|
|
123
69
|
});
|
|
124
70
|
}
|
|
125
|
-
function validate(file) {
|
|
71
|
+
function validate(file, { injectESMShim = false, moduleResolveMapLocation }) {
|
|
72
|
+
let prefixCode = "";
|
|
73
|
+
if (injectESMShim) {
|
|
74
|
+
prefixCode = `import { fileURLToPath } from 'url';
|
|
75
|
+
import { dirname } from 'path';
|
|
76
|
+
|
|
77
|
+
globalThis.__filename = fileURLToPath(import.meta.url);
|
|
78
|
+
globalThis.__dirname = dirname(__filename);
|
|
79
|
+
`;
|
|
80
|
+
}
|
|
81
|
+
function errorHandler(err) {
|
|
82
|
+
console.error(
|
|
83
|
+
JSON.stringify({
|
|
84
|
+
type: err.name,
|
|
85
|
+
message: err.message,
|
|
86
|
+
stack: err.stack
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
126
91
|
return spawn(
|
|
127
|
-
|
|
92
|
+
process.execPath,
|
|
128
93
|
[
|
|
129
94
|
"--import",
|
|
130
95
|
import.meta.resolve("@mastra/deployer/loader"),
|
|
131
96
|
"--input-type=module",
|
|
97
|
+
"--enable-source-maps",
|
|
132
98
|
"-e",
|
|
133
|
-
|
|
99
|
+
`${prefixCode};import('${pathToFileURL(file).href}').catch(err => {
|
|
100
|
+
${errorHandler.toString()}
|
|
101
|
+
errorHandler(err);
|
|
102
|
+
})`.replaceAll(/\n/g, "")
|
|
134
103
|
],
|
|
135
104
|
{
|
|
105
|
+
env: {
|
|
106
|
+
...process.env,
|
|
107
|
+
MODULE_MAP: `${moduleResolveMapLocation}`
|
|
108
|
+
},
|
|
136
109
|
cwd: dirname(file)
|
|
137
110
|
}
|
|
138
111
|
);
|
|
139
112
|
}
|
|
140
|
-
function removeAllOptionsFromMastraExcept(result, option, logger) {
|
|
141
|
-
const t = babel__default.types;
|
|
142
|
-
return {
|
|
143
|
-
name: "remove-all-except-" + option + "-config",
|
|
144
|
-
visitor: {
|
|
145
|
-
ExportNamedDeclaration: {
|
|
146
|
-
// remove all exports
|
|
147
|
-
exit(path3) {
|
|
148
|
-
path3.remove();
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
NewExpression(path3, state) {
|
|
152
|
-
const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
|
|
153
|
-
if (!varDeclaratorPath) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const parentNode = path3.parentPath.node;
|
|
157
|
-
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
let mastraArgs = t.objectExpression([]);
|
|
161
|
-
if (t.isObjectExpression(path3.node.arguments[0])) {
|
|
162
|
-
mastraArgs = path3.node.arguments[0];
|
|
163
|
-
}
|
|
164
|
-
let configProperty = mastraArgs.properties.find(
|
|
165
|
-
// @ts-ignore
|
|
166
|
-
(prop) => prop.key.name === option
|
|
167
|
-
);
|
|
168
|
-
let configValue = t.objectExpression([]);
|
|
169
|
-
const programPath = path3.scope.getProgramParent().path;
|
|
170
|
-
if (!programPath) {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {
|
|
174
|
-
result.hasCustomConfig = true;
|
|
175
|
-
configValue = configProperty.value;
|
|
176
|
-
if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {
|
|
177
|
-
const configBinding = state.file.scope.getBinding(option);
|
|
178
|
-
if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {
|
|
179
|
-
const id = path3.scope.generateUidIdentifier(option);
|
|
180
|
-
configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init));
|
|
181
|
-
configValue = id;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
const exportDeclaration = t.exportNamedDeclaration(
|
|
186
|
-
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), configValue)]),
|
|
187
|
-
[]
|
|
188
|
-
);
|
|
189
|
-
programPath.node.body.push(exportDeclaration);
|
|
190
|
-
},
|
|
191
|
-
Program: {
|
|
192
|
-
exit(path3) {
|
|
193
|
-
const hasExport = path3.node.body.some(
|
|
194
|
-
(node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
|
|
195
|
-
);
|
|
196
|
-
if (!hasExport) {
|
|
197
|
-
if (logger) {
|
|
198
|
-
logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
|
|
199
|
-
export const mastra = new Mastra({
|
|
200
|
-
${option}: <value>
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
`);
|
|
204
|
-
}
|
|
205
|
-
const fallbackExportDeclaration = t.exportNamedDeclaration(
|
|
206
|
-
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
|
|
207
|
-
[]
|
|
208
|
-
);
|
|
209
|
-
path3.node.body.push(fallbackExportDeclaration);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// src/build/babel/remove-all-options-bundler.ts
|
|
218
|
-
function removeAllOptionsExceptBundler(result, logger) {
|
|
219
|
-
return removeAllOptionsFromMastraExcept(result, "bundler", logger);
|
|
220
|
-
}
|
|
221
113
|
function esbuild(options = {}) {
|
|
222
114
|
return originalEsbuild({
|
|
223
115
|
target: "node20",
|
|
@@ -227,29 +119,90 @@ function esbuild(options = {}) {
|
|
|
227
119
|
});
|
|
228
120
|
}
|
|
229
121
|
var PLUGIN_NAME = "tsconfig-paths";
|
|
122
|
+
function hasPaths(tsConfigPath) {
|
|
123
|
+
try {
|
|
124
|
+
const content = fs.readFileSync(tsConfigPath, "utf8");
|
|
125
|
+
const config = JSON.parse(stripJsonComments(content));
|
|
126
|
+
return !!(config.compilerOptions?.paths && Object.keys(config.compilerOptions.paths).length > 0 || typeof config.extends === "string" && config.extends.length > 0 || Array.isArray(config.extends) && config.extends.length > 0);
|
|
127
|
+
} catch {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
230
131
|
function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve } = {}) {
|
|
231
|
-
|
|
132
|
+
const handlerCache = /* @__PURE__ */ new Map();
|
|
133
|
+
function findTsConfigForFile(filePath) {
|
|
134
|
+
let currentDir = path2__default.dirname(filePath);
|
|
135
|
+
const root = path2__default.parse(currentDir).root;
|
|
136
|
+
while (currentDir !== root) {
|
|
137
|
+
const tsConfigPath2 = path2__default.join(currentDir, "tsconfig.json");
|
|
138
|
+
if (fs.existsSync(tsConfigPath2)) {
|
|
139
|
+
if (hasPaths(tsConfigPath2)) {
|
|
140
|
+
return tsConfigPath2;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const tsConfigBasePath = path2__default.join(currentDir, "tsconfig.base.json");
|
|
144
|
+
if (fs.existsSync(tsConfigBasePath)) {
|
|
145
|
+
if (hasPaths(tsConfigBasePath)) {
|
|
146
|
+
return tsConfigBasePath;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
currentDir = path2__default.dirname(currentDir);
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
function getHandlerForFile(filePath) {
|
|
154
|
+
if (tsConfigPath && typeof tsConfigPath === "string") {
|
|
155
|
+
if (!handlerCache.has(tsConfigPath)) {
|
|
156
|
+
handlerCache.set(
|
|
157
|
+
tsConfigPath,
|
|
158
|
+
createHandler({
|
|
159
|
+
log: () => {
|
|
160
|
+
},
|
|
161
|
+
tsConfigPath,
|
|
162
|
+
respectCoreModule,
|
|
163
|
+
falllback: (moduleName) => fs.existsSync(moduleName)
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
return handlerCache.get(tsConfigPath);
|
|
168
|
+
}
|
|
169
|
+
const configPath = findTsConfigForFile(filePath);
|
|
170
|
+
if (!configPath) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
if (!handlerCache.has(configPath)) {
|
|
174
|
+
handlerCache.set(
|
|
175
|
+
configPath,
|
|
176
|
+
createHandler({
|
|
177
|
+
log: () => {
|
|
178
|
+
},
|
|
179
|
+
tsConfigPath: configPath,
|
|
180
|
+
respectCoreModule,
|
|
181
|
+
falllback: (moduleName) => fs.existsSync(moduleName)
|
|
182
|
+
})
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
return handlerCache.get(configPath);
|
|
186
|
+
}
|
|
187
|
+
function resolveAlias(request, importer) {
|
|
188
|
+
const dynamicHandler = getHandlerForFile(importer);
|
|
189
|
+
if (!dynamicHandler) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
const resolved = dynamicHandler(request, normalize(importer));
|
|
193
|
+
return resolved;
|
|
194
|
+
}
|
|
232
195
|
return {
|
|
233
196
|
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
197
|
async resolveId(request, importer, options) {
|
|
245
|
-
if (!importer || request.startsWith("\0")) {
|
|
198
|
+
if (!importer || request.startsWith("\0") || importer.charCodeAt(0) === 0) {
|
|
246
199
|
return null;
|
|
247
200
|
}
|
|
248
|
-
const moduleName =
|
|
201
|
+
const moduleName = resolveAlias(request, importer);
|
|
249
202
|
if (!moduleName) {
|
|
250
203
|
let importerMeta = {};
|
|
251
|
-
const
|
|
252
|
-
if (!
|
|
204
|
+
const resolved2 = await this.resolve(request, importer, { skipSelf: true, ...options });
|
|
205
|
+
if (!resolved2) {
|
|
253
206
|
return null;
|
|
254
207
|
}
|
|
255
208
|
if (localResolve) {
|
|
@@ -257,37 +210,42 @@ function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve } = {}) {
|
|
|
257
210
|
importerMeta = importerInfo?.meta || {};
|
|
258
211
|
if (!request.startsWith("./") && !request.startsWith("../") && importerMeta?.[PLUGIN_NAME]?.resolved) {
|
|
259
212
|
return {
|
|
260
|
-
...
|
|
213
|
+
...resolved2,
|
|
261
214
|
external: !request.startsWith("hono/") && request !== "hono"
|
|
262
215
|
};
|
|
263
216
|
}
|
|
264
217
|
}
|
|
265
218
|
return {
|
|
266
|
-
...
|
|
219
|
+
...resolved2,
|
|
267
220
|
meta: {
|
|
268
|
-
...
|
|
221
|
+
...resolved2.meta || {},
|
|
269
222
|
...importerMeta
|
|
270
223
|
}
|
|
271
224
|
};
|
|
272
225
|
}
|
|
273
226
|
if (!path2__default.extname(moduleName)) {
|
|
274
|
-
const
|
|
275
|
-
if (!
|
|
227
|
+
const resolved2 = await this.resolve(moduleName, importer, { skipSelf: true, ...options });
|
|
228
|
+
if (!resolved2) {
|
|
276
229
|
return null;
|
|
277
230
|
}
|
|
278
231
|
return {
|
|
279
|
-
...
|
|
232
|
+
...resolved2,
|
|
280
233
|
meta: {
|
|
281
|
-
...
|
|
234
|
+
...resolved2.meta,
|
|
282
235
|
[PLUGIN_NAME]: {
|
|
283
236
|
resolved: true
|
|
284
237
|
}
|
|
285
238
|
}
|
|
286
239
|
};
|
|
287
240
|
}
|
|
241
|
+
const resolved = await this.resolve(moduleName, importer, { skipSelf: true, ...options });
|
|
242
|
+
if (!resolved) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
288
245
|
return {
|
|
289
|
-
|
|
246
|
+
...resolved,
|
|
290
247
|
meta: {
|
|
248
|
+
...resolved.meta,
|
|
291
249
|
[PLUGIN_NAME]: {
|
|
292
250
|
resolved: true
|
|
293
251
|
}
|
|
@@ -369,7 +327,117 @@ function recursiveRemoveNonReferencedNodes(code) {
|
|
|
369
327
|
);
|
|
370
328
|
});
|
|
371
329
|
}
|
|
372
|
-
function
|
|
330
|
+
function removeAllOptionsFromMastraExcept(result, option, logger) {
|
|
331
|
+
const t = babel__default.types;
|
|
332
|
+
return {
|
|
333
|
+
name: "remove-all-except-" + option + "-config",
|
|
334
|
+
visitor: {
|
|
335
|
+
ExportNamedDeclaration: {
|
|
336
|
+
// remove all exports
|
|
337
|
+
exit(path3) {
|
|
338
|
+
path3.remove();
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
NewExpression(path3, state) {
|
|
342
|
+
const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
|
|
343
|
+
if (!varDeclaratorPath) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const parentNode = path3.parentPath.node;
|
|
347
|
+
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
let mastraArgs = t.objectExpression([]);
|
|
351
|
+
if (t.isObjectExpression(path3.node.arguments[0])) {
|
|
352
|
+
mastraArgs = path3.node.arguments[0];
|
|
353
|
+
}
|
|
354
|
+
let configProperty = mastraArgs.properties.find(
|
|
355
|
+
(prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === option
|
|
356
|
+
);
|
|
357
|
+
let configValue = t.objectExpression([]);
|
|
358
|
+
const programPath = path3.scope.getProgramParent().path;
|
|
359
|
+
if (!programPath) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {
|
|
363
|
+
result.hasCustomConfig = true;
|
|
364
|
+
configValue = configProperty.value;
|
|
365
|
+
if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {
|
|
366
|
+
const configBinding = state.file.scope.getBinding(option);
|
|
367
|
+
if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {
|
|
368
|
+
const id = path3.scope.generateUidIdentifier(option);
|
|
369
|
+
configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init));
|
|
370
|
+
configValue = id;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const exportDeclaration = t.exportNamedDeclaration(
|
|
375
|
+
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), configValue)]),
|
|
376
|
+
[]
|
|
377
|
+
);
|
|
378
|
+
programPath.node.body.push(exportDeclaration);
|
|
379
|
+
},
|
|
380
|
+
Program: {
|
|
381
|
+
exit(path3) {
|
|
382
|
+
const hasExport = path3.node.body.some(
|
|
383
|
+
(node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
|
|
384
|
+
);
|
|
385
|
+
if (!hasExport) {
|
|
386
|
+
if (logger) {
|
|
387
|
+
logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
|
|
388
|
+
export const mastra = new Mastra({
|
|
389
|
+
${option}: <value>
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
`);
|
|
393
|
+
}
|
|
394
|
+
const fallbackExportDeclaration = t.exportNamedDeclaration(
|
|
395
|
+
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
|
|
396
|
+
[]
|
|
397
|
+
);
|
|
398
|
+
path3.node.body.push(fallbackExportDeclaration);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// src/build/plugins/remove-all-except.ts
|
|
407
|
+
function removeAllOptionsFromMastraExceptPlugin(mastraEntry, name, result, options) {
|
|
408
|
+
return {
|
|
409
|
+
name: `remove-${name}`,
|
|
410
|
+
transform(code, id) {
|
|
411
|
+
if (id !== mastraEntry) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
return new Promise((resolve2, reject) => {
|
|
415
|
+
babel.transform(
|
|
416
|
+
code,
|
|
417
|
+
{
|
|
418
|
+
babelrc: false,
|
|
419
|
+
configFile: false,
|
|
420
|
+
filename: id,
|
|
421
|
+
plugins: [removeAllOptionsFromMastraExcept(result, name, options?.logger)],
|
|
422
|
+
sourceMaps: options?.sourcemap
|
|
423
|
+
},
|
|
424
|
+
(err, result2) => {
|
|
425
|
+
if (err) {
|
|
426
|
+
return reject(err);
|
|
427
|
+
}
|
|
428
|
+
resolve2({
|
|
429
|
+
code: result2.code,
|
|
430
|
+
map: result2.map
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
);
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// src/build/shared/extract-mastra-option.ts
|
|
440
|
+
function extractMastraOptionBundler(name, entryFile, result, logger) {
|
|
373
441
|
return rollup({
|
|
374
442
|
logLevel: "silent",
|
|
375
443
|
input: {
|
|
@@ -390,34 +458,7 @@ function extractMastraOptionBundler(name, entryFile, transformer, result, logger
|
|
|
390
458
|
ignoreTryCatch: false
|
|
391
459
|
}),
|
|
392
460
|
json(),
|
|
393
|
-
{
|
|
394
|
-
name: `extract-${name}-config`,
|
|
395
|
-
transform(code, id) {
|
|
396
|
-
if (id !== entryFile) {
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
return new Promise((resolve2, reject) => {
|
|
400
|
-
babel.transform(
|
|
401
|
-
code,
|
|
402
|
-
{
|
|
403
|
-
babelrc: false,
|
|
404
|
-
configFile: false,
|
|
405
|
-
filename: id,
|
|
406
|
-
plugins: [transformer(result, logger)]
|
|
407
|
-
},
|
|
408
|
-
(err, result2) => {
|
|
409
|
-
if (err) {
|
|
410
|
-
return reject(err);
|
|
411
|
-
}
|
|
412
|
-
resolve2({
|
|
413
|
-
code: result2.code,
|
|
414
|
-
map: result2.map
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
);
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
},
|
|
461
|
+
removeAllOptionsFromMastraExceptPlugin(entryFile, name, result, { logger }),
|
|
421
462
|
// let esbuild remove all unused imports
|
|
422
463
|
esbuild(),
|
|
423
464
|
{
|
|
@@ -434,11 +475,11 @@ function extractMastraOptionBundler(name, entryFile, transformer, result, logger
|
|
|
434
475
|
]
|
|
435
476
|
});
|
|
436
477
|
}
|
|
437
|
-
async function extractMastraOption(name, entryFile,
|
|
478
|
+
async function extractMastraOption(name, entryFile, outputDir, logger) {
|
|
438
479
|
const result = {
|
|
439
480
|
hasCustomConfig: false
|
|
440
481
|
};
|
|
441
|
-
const bundler = await extractMastraOptionBundler(name, entryFile,
|
|
482
|
+
const bundler = await extractMastraOptionBundler(name, entryFile, result, logger);
|
|
442
483
|
const output = await bundler.write({
|
|
443
484
|
dir: outputDir,
|
|
444
485
|
format: "es",
|
|
@@ -448,7 +489,7 @@ async function extractMastraOption(name, entryFile, transformer, outputDir, logg
|
|
|
448
489
|
const configPath = `${outputDir}/${name}-config.mjs`;
|
|
449
490
|
return {
|
|
450
491
|
bundleOutput: output,
|
|
451
|
-
getConfig: () => import(
|
|
492
|
+
getConfig: () => import(pathToFileURL(configPath).href).then((m) => m[name])
|
|
452
493
|
};
|
|
453
494
|
}
|
|
454
495
|
return null;
|
|
@@ -456,13 +497,7 @@ async function extractMastraOption(name, entryFile, transformer, outputDir, logg
|
|
|
456
497
|
|
|
457
498
|
// src/build/bundlerOptions.ts
|
|
458
499
|
async function getBundlerOptions(entryFile, outputDir, logger) {
|
|
459
|
-
const result = await extractMastraOption(
|
|
460
|
-
"bundler",
|
|
461
|
-
entryFile,
|
|
462
|
-
removeAllOptionsExceptBundler,
|
|
463
|
-
outputDir,
|
|
464
|
-
logger
|
|
465
|
-
);
|
|
500
|
+
const result = await extractMastraOption("bundler", entryFile, outputDir, logger);
|
|
466
501
|
if (!result) {
|
|
467
502
|
return null;
|
|
468
503
|
}
|
|
@@ -531,8 +566,57 @@ function isNodeBuiltin(dep) {
|
|
|
531
566
|
const [pkg2] = dep.split("/");
|
|
532
567
|
return dep.startsWith("node:") || builtinModules.includes(dep) || builtinModules.includes(pkg2);
|
|
533
568
|
}
|
|
569
|
+
async function getPackageRootPath(packageName, parentPath) {
|
|
570
|
+
let rootPath;
|
|
571
|
+
try {
|
|
572
|
+
let options = void 0;
|
|
573
|
+
if (parentPath) {
|
|
574
|
+
if (!parentPath.startsWith("file://")) {
|
|
575
|
+
parentPath = pathToFileURL(parentPath).href;
|
|
576
|
+
}
|
|
577
|
+
options = {
|
|
578
|
+
paths: [parentPath]
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
const pkg2 = await getPackageInfo(packageName, options);
|
|
582
|
+
rootPath = pkg2?.rootPath ?? null;
|
|
583
|
+
} catch (e) {
|
|
584
|
+
rootPath = null;
|
|
585
|
+
}
|
|
586
|
+
return rootPath;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// src/build/analyze/constants.ts
|
|
590
|
+
var DEPS_TO_IGNORE = ["#tools"];
|
|
591
|
+
var GLOBAL_EXTERNALS = [
|
|
592
|
+
"pino",
|
|
593
|
+
"pino-pretty",
|
|
594
|
+
"@libsql/client",
|
|
595
|
+
"pg",
|
|
596
|
+
"libsql",
|
|
597
|
+
"#tools",
|
|
598
|
+
"typescript",
|
|
599
|
+
"undici",
|
|
600
|
+
"readable-stream"
|
|
601
|
+
];
|
|
602
|
+
var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
|
|
534
603
|
function removeDeployer() {
|
|
535
604
|
const t = babel__default.types;
|
|
605
|
+
function removeDeployerFromObject(objectExpr, scope) {
|
|
606
|
+
const deployerProp = objectExpr.properties.find(
|
|
607
|
+
(prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
|
|
608
|
+
);
|
|
609
|
+
if (deployerProp) {
|
|
610
|
+
objectExpr.properties = objectExpr.properties.filter((prop) => prop !== deployerProp);
|
|
611
|
+
if (t.isIdentifier(deployerProp.value)) {
|
|
612
|
+
const deployerBinding = scope.getBinding(deployerProp.value.name);
|
|
613
|
+
if (deployerBinding) {
|
|
614
|
+
deployerBinding.path?.parentPath?.remove();
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return deployerProp;
|
|
619
|
+
}
|
|
536
620
|
return {
|
|
537
621
|
name: "remove-deployer",
|
|
538
622
|
visitor: {
|
|
@@ -548,23 +632,30 @@ function removeDeployer() {
|
|
|
548
632
|
if (!state.hasReplaced) {
|
|
549
633
|
state.hasReplaced = true;
|
|
550
634
|
const newMastraObj = t.cloneNode(path3.node);
|
|
551
|
-
if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
);
|
|
555
|
-
if (
|
|
556
|
-
|
|
635
|
+
if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.length) {
|
|
636
|
+
const objectArg = newMastraObj.arguments[0];
|
|
637
|
+
let foundDeployer = false;
|
|
638
|
+
const directDeployer = removeDeployerFromObject(objectArg, state.file.scope);
|
|
639
|
+
if (directDeployer) {
|
|
640
|
+
foundDeployer = true;
|
|
557
641
|
}
|
|
558
|
-
|
|
559
|
-
(prop)
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
642
|
+
for (const prop of objectArg.properties) {
|
|
643
|
+
if (t.isSpreadElement(prop) && t.isIdentifier(prop.argument)) {
|
|
644
|
+
const spreadBinding = state.file.scope.getBinding(prop.argument.name);
|
|
645
|
+
if (spreadBinding?.path && t.isVariableDeclarator(spreadBinding.path.node)) {
|
|
646
|
+
const init = spreadBinding.path.node.init;
|
|
647
|
+
if (t.isObjectExpression(init)) {
|
|
648
|
+
const spreadDeployer = removeDeployerFromObject(init, state.file.scope);
|
|
649
|
+
if (spreadDeployer) {
|
|
650
|
+
foundDeployer = true;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
565
654
|
}
|
|
566
655
|
}
|
|
567
|
-
|
|
656
|
+
if (foundDeployer) {
|
|
657
|
+
path3.replaceWith(newMastraObj);
|
|
658
|
+
}
|
|
568
659
|
}
|
|
569
660
|
}
|
|
570
661
|
}
|
|
@@ -605,20 +696,6 @@ function removeDeployer2(mastraEntry, options) {
|
|
|
605
696
|
};
|
|
606
697
|
}
|
|
607
698
|
|
|
608
|
-
// src/build/analyze/constants.ts
|
|
609
|
-
var DEPS_TO_IGNORE = ["#tools"];
|
|
610
|
-
var GLOBAL_EXTERNALS = [
|
|
611
|
-
"pino",
|
|
612
|
-
"pino-pretty",
|
|
613
|
-
"@libsql/client",
|
|
614
|
-
"pg",
|
|
615
|
-
"libsql",
|
|
616
|
-
"#tools",
|
|
617
|
-
"typescript",
|
|
618
|
-
"undici"
|
|
619
|
-
];
|
|
620
|
-
var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
|
|
621
|
-
|
|
622
699
|
// src/build/analyze/analyzeEntry.ts
|
|
623
700
|
function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
|
|
624
701
|
const normalizedMastraEntry = slash(mastraEntry);
|
|
@@ -658,14 +735,17 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
|
|
|
658
735
|
transformMixedEsModules: true,
|
|
659
736
|
extensions: [".js", ".ts"]
|
|
660
737
|
}),
|
|
661
|
-
removeDeployer2(mastraEntry, {
|
|
738
|
+
removeDeployer2(mastraEntry, {
|
|
739
|
+
sourcemap: sourcemapEnabled
|
|
740
|
+
}),
|
|
662
741
|
esbuild()
|
|
663
742
|
]
|
|
664
743
|
);
|
|
665
744
|
return plugins;
|
|
666
745
|
}
|
|
667
746
|
async function captureDependenciesToOptimize(output, workspaceMap, projectRoot, initialDepsToOptimize, {
|
|
668
|
-
logger
|
|
747
|
+
logger,
|
|
748
|
+
shouldCheckTransitiveDependencies
|
|
669
749
|
}) {
|
|
670
750
|
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
671
751
|
if (!output.facadeModuleId) {
|
|
@@ -678,18 +758,31 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
|
|
|
678
758
|
entryRootPath = await getPackageRootPath(output.facadeModuleId) || projectRoot;
|
|
679
759
|
}
|
|
680
760
|
for (const [dependency, bindings] of Object.entries(output.importedBindings)) {
|
|
681
|
-
if (isNodeBuiltin(dependency) ||
|
|
761
|
+
if (isNodeBuiltin(dependency) || dependency.startsWith("#")) {
|
|
682
762
|
continue;
|
|
683
763
|
}
|
|
684
764
|
const pkgName = getPackageName(dependency);
|
|
685
765
|
let rootPath = null;
|
|
686
766
|
let isWorkspace = false;
|
|
767
|
+
let version;
|
|
687
768
|
if (pkgName) {
|
|
688
769
|
rootPath = await getPackageRootPath(dependency, entryRootPath);
|
|
689
770
|
isWorkspace = workspaceMap.has(pkgName);
|
|
771
|
+
if (rootPath) {
|
|
772
|
+
try {
|
|
773
|
+
const pkgJson = await readJSON(`${rootPath}/package.json`);
|
|
774
|
+
version = pkgJson.version;
|
|
775
|
+
} catch {
|
|
776
|
+
}
|
|
777
|
+
}
|
|
690
778
|
}
|
|
691
779
|
const normalizedRootPath = rootPath ? slash(rootPath) : null;
|
|
692
|
-
depsToOptimize.set(dependency, {
|
|
780
|
+
depsToOptimize.set(dependency, {
|
|
781
|
+
exports: bindings,
|
|
782
|
+
rootPath: normalizedRootPath,
|
|
783
|
+
isWorkspace,
|
|
784
|
+
version
|
|
785
|
+
});
|
|
693
786
|
}
|
|
694
787
|
async function checkTransitiveDependencies(internalMap, maxDepth = 10, currentDepth = 0) {
|
|
695
788
|
if (currentDepth >= maxDepth) {
|
|
@@ -733,12 +826,32 @@ async function captureDependenciesToOptimize(output, workspaceMap, projectRoot,
|
|
|
733
826
|
await checkTransitiveDependencies(internalMap, maxDepth, currentDepth + 1);
|
|
734
827
|
}
|
|
735
828
|
}
|
|
736
|
-
|
|
829
|
+
if (shouldCheckTransitiveDependencies) {
|
|
830
|
+
await checkTransitiveDependencies(initialDepsToOptimize);
|
|
831
|
+
}
|
|
737
832
|
const dynamicImports = output.dynamicImports.filter((d) => !DEPS_TO_IGNORE.includes(d));
|
|
738
833
|
if (dynamicImports.length) {
|
|
739
834
|
for (const dynamicImport of dynamicImports) {
|
|
740
835
|
if (!depsToOptimize.has(dynamicImport) && !isNodeBuiltin(dynamicImport)) {
|
|
741
|
-
|
|
836
|
+
const pkgName = getPackageName(dynamicImport);
|
|
837
|
+
let version;
|
|
838
|
+
let rootPath = null;
|
|
839
|
+
if (pkgName) {
|
|
840
|
+
rootPath = await getPackageRootPath(dynamicImport, entryRootPath);
|
|
841
|
+
if (rootPath) {
|
|
842
|
+
try {
|
|
843
|
+
const pkgJson = await readJSON(`${rootPath}/package.json`);
|
|
844
|
+
version = pkgJson.version;
|
|
845
|
+
} catch {
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
depsToOptimize.set(dynamicImport, {
|
|
850
|
+
exports: ["*"],
|
|
851
|
+
rootPath: rootPath ? slash(rootPath) : null,
|
|
852
|
+
isWorkspace: false,
|
|
853
|
+
version
|
|
854
|
+
});
|
|
742
855
|
}
|
|
743
856
|
}
|
|
744
857
|
}
|
|
@@ -752,13 +865,14 @@ async function analyzeEntry({
|
|
|
752
865
|
sourcemapEnabled,
|
|
753
866
|
workspaceMap,
|
|
754
867
|
projectRoot,
|
|
755
|
-
initialDepsToOptimize = /* @__PURE__ */ new Map()
|
|
868
|
+
initialDepsToOptimize = /* @__PURE__ */ new Map(),
|
|
756
869
|
// used to avoid infinite recursion
|
|
870
|
+
shouldCheckTransitiveDependencies = false
|
|
757
871
|
}) {
|
|
758
872
|
const optimizerBundler = await rollup({
|
|
759
873
|
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
760
874
|
input: isVirtualFile ? "#entry" : entry,
|
|
761
|
-
treeshake:
|
|
875
|
+
treeshake: false,
|
|
762
876
|
preserveSymlinks: true,
|
|
763
877
|
plugins: getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }),
|
|
764
878
|
external: DEPS_TO_IGNORE
|
|
@@ -774,7 +888,8 @@ async function analyzeEntry({
|
|
|
774
888
|
projectRoot,
|
|
775
889
|
initialDepsToOptimize,
|
|
776
890
|
{
|
|
777
|
-
logger
|
|
891
|
+
logger,
|
|
892
|
+
shouldCheckTransitiveDependencies
|
|
778
893
|
}
|
|
779
894
|
);
|
|
780
895
|
return {
|
|
@@ -785,6 +900,27 @@ async function analyzeEntry({
|
|
|
785
900
|
}
|
|
786
901
|
};
|
|
787
902
|
}
|
|
903
|
+
var FilenameDeclarationRegex = /(?:const|let|var)\s+__filename/;
|
|
904
|
+
var DirnameDeclarationRegex = /(?:const|let|var)\s+__dirname/;
|
|
905
|
+
function esmShim() {
|
|
906
|
+
const original = originalEsmShim();
|
|
907
|
+
return {
|
|
908
|
+
name: "esm-shim",
|
|
909
|
+
renderChunk(code, chunk, opts, meta) {
|
|
910
|
+
const hasFilename = code.includes("__filename");
|
|
911
|
+
const hasDirname = code.includes("__dirname");
|
|
912
|
+
const userDeclaredFilename = hasFilename && FilenameDeclarationRegex.test(code);
|
|
913
|
+
const userDeclaredDirname = hasDirname && DirnameDeclarationRegex.test(code);
|
|
914
|
+
if (userDeclaredFilename || userDeclaredDirname) {
|
|
915
|
+
return null;
|
|
916
|
+
}
|
|
917
|
+
if (typeof original.renderChunk === "function") {
|
|
918
|
+
return original.renderChunk.call(this, code, chunk, opts, meta);
|
|
919
|
+
}
|
|
920
|
+
return null;
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
}
|
|
788
924
|
function aliasHono() {
|
|
789
925
|
return {
|
|
790
926
|
name: "hono-alias",
|
|
@@ -797,6 +933,114 @@ function aliasHono() {
|
|
|
797
933
|
}
|
|
798
934
|
};
|
|
799
935
|
}
|
|
936
|
+
function nodeGypDetector() {
|
|
937
|
+
const modulesToTrack = /* @__PURE__ */ new Set();
|
|
938
|
+
const modulesToTrackPackageInfo = /* @__PURE__ */ new Map();
|
|
939
|
+
return {
|
|
940
|
+
name: "node-gyp-build-detector",
|
|
941
|
+
moduleParsed(info) {
|
|
942
|
+
if (!info.meta?.commonjs?.requires?.length) {
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
const hasNodeGypBuild = info.meta.commonjs.requires.some(
|
|
946
|
+
(m) => m?.resolved?.id.endsWith("node-gyp-build/index.js")
|
|
947
|
+
);
|
|
948
|
+
if (!hasNodeGypBuild) {
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
modulesToTrack.add(info.id);
|
|
952
|
+
modulesToTrackPackageInfo.set(info.id, getPackageInfo(info.id));
|
|
953
|
+
},
|
|
954
|
+
async generateBundle(options, bundle) {
|
|
955
|
+
const binaryMapByChunk = /* @__PURE__ */ new Map();
|
|
956
|
+
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
957
|
+
if (chunk.type === "chunk") {
|
|
958
|
+
for (const moduleId of chunk.moduleIds) {
|
|
959
|
+
if (modulesToTrackPackageInfo.has(moduleId)) {
|
|
960
|
+
const pkgInfo = await modulesToTrackPackageInfo.get(moduleId);
|
|
961
|
+
if (!binaryMapByChunk.has(fileName)) {
|
|
962
|
+
binaryMapByChunk.set(fileName, /* @__PURE__ */ new Set());
|
|
963
|
+
}
|
|
964
|
+
if (pkgInfo?.packageJson?.name) {
|
|
965
|
+
binaryMapByChunk.get(fileName).add(pkgInfo.packageJson.name);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
const binaryMapJson = Object.fromEntries(
|
|
972
|
+
Array.from(binaryMapByChunk.entries()).map(([key, value]) => [key, Array.from(value)])
|
|
973
|
+
);
|
|
974
|
+
this.emitFile({
|
|
975
|
+
type: "asset",
|
|
976
|
+
name: "binary-map.json",
|
|
977
|
+
source: `${JSON.stringify(binaryMapJson, null, 2)}`
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
// src/build/plugins/subpath-externals-resolver.ts
|
|
984
|
+
function subpathExternalsResolver(externals) {
|
|
985
|
+
return {
|
|
986
|
+
name: "subpath-externals-resolver",
|
|
987
|
+
resolveId(id) {
|
|
988
|
+
if (id.startsWith(".") || id.startsWith("/")) {
|
|
989
|
+
return null;
|
|
990
|
+
}
|
|
991
|
+
const isPartOfExternals = externals.some((external) => isDependencyPartOfPackage(id, external));
|
|
992
|
+
if (isPartOfExternals) {
|
|
993
|
+
return {
|
|
994
|
+
id,
|
|
995
|
+
external: true
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
function moduleResolveMap(externals, projectRoot) {
|
|
1002
|
+
const importMap = /* @__PURE__ */ new Map();
|
|
1003
|
+
return {
|
|
1004
|
+
name: "module-resolve-map",
|
|
1005
|
+
moduleParsed(info) {
|
|
1006
|
+
if (info.importedIds.length === 0 || !info.id) {
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
for (const importedId of info.importedIds) {
|
|
1010
|
+
for (const external of externals) {
|
|
1011
|
+
if (isDependencyPartOfPackage(importedId, external)) {
|
|
1012
|
+
importMap.set(external, info.id);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
},
|
|
1017
|
+
async generateBundle(options, bundle) {
|
|
1018
|
+
const resolveMap = /* @__PURE__ */ new Map();
|
|
1019
|
+
for (const [fileName, chunk] of Object.entries(bundle)) {
|
|
1020
|
+
if (chunk.type === "chunk") {
|
|
1021
|
+
for (const [external, resolvedFrom] of importMap) {
|
|
1022
|
+
if (chunk.moduleIds.includes(resolvedFrom)) {
|
|
1023
|
+
const fullPath = pathToFileURL(slash(join(projectRoot, fileName))).toString();
|
|
1024
|
+
const innerMap = resolveMap.get(fullPath) || /* @__PURE__ */ new Map();
|
|
1025
|
+
innerMap.set(external, pathToFileURL(slash(resolvedFrom)).toString());
|
|
1026
|
+
resolveMap.set(fullPath, innerMap);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
const resolveMapJson = Object.fromEntries(
|
|
1032
|
+
Array.from(resolveMap.entries()).map(([key, value]) => [key, Object.fromEntries(value.entries())])
|
|
1033
|
+
);
|
|
1034
|
+
this.emitFile({
|
|
1035
|
+
type: "asset",
|
|
1036
|
+
name: "module-resolve-map.json",
|
|
1037
|
+
source: `${JSON.stringify(resolveMapJson, null, 2)}`
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
// src/build/analyze/bundleExternals.ts
|
|
800
1044
|
function prepareEntryFileName(name, rootDir) {
|
|
801
1045
|
return rollupSafeName(name, rootDir);
|
|
802
1046
|
}
|
|
@@ -806,7 +1050,7 @@ function createVirtualDependencies(depsToOptimize, {
|
|
|
806
1050
|
outputDir,
|
|
807
1051
|
bundlerOptions
|
|
808
1052
|
}) {
|
|
809
|
-
const { isDev = false } = bundlerOptions || {};
|
|
1053
|
+
const { isDev = false, externalsPreset = false } = bundlerOptions || {};
|
|
810
1054
|
const fileNameToDependencyMap = /* @__PURE__ */ new Map();
|
|
811
1055
|
const optimizedDependencyEntries = /* @__PURE__ */ new Map();
|
|
812
1056
|
const rootDir = workspaceRoot || projectRoot;
|
|
@@ -838,7 +1082,7 @@ function createVirtualDependencies(depsToOptimize, {
|
|
|
838
1082
|
virtual: virtualFile.join("\n")
|
|
839
1083
|
});
|
|
840
1084
|
}
|
|
841
|
-
if (isDev) {
|
|
1085
|
+
if (isDev || externalsPreset) {
|
|
842
1086
|
for (const [dep, { isWorkspace, rootPath }] of depsToOptimize.entries()) {
|
|
843
1087
|
if (!isWorkspace || !rootPath || !workspaceRoot) {
|
|
844
1088
|
continue;
|
|
@@ -862,7 +1106,8 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
862
1106
|
transpilePackages,
|
|
863
1107
|
workspaceMap,
|
|
864
1108
|
bundlerOptions,
|
|
865
|
-
rootDir
|
|
1109
|
+
rootDir,
|
|
1110
|
+
externals
|
|
866
1111
|
}) {
|
|
867
1112
|
const transpilePackagesMap = /* @__PURE__ */ new Map();
|
|
868
1113
|
for (const pkg2 of transpilePackages) {
|
|
@@ -883,6 +1128,7 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
883
1128
|
{}
|
|
884
1129
|
)
|
|
885
1130
|
),
|
|
1131
|
+
subpathExternalsResolver(externals),
|
|
886
1132
|
transpilePackagesMap.size ? esbuild({
|
|
887
1133
|
format: "esm",
|
|
888
1134
|
include: [...transpilePackagesMap.values()].map((p) => {
|
|
@@ -893,7 +1139,7 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
893
1139
|
}
|
|
894
1140
|
})
|
|
895
1141
|
}) : null,
|
|
896
|
-
bundlerOptions.
|
|
1142
|
+
bundlerOptions.noBundling ? {
|
|
897
1143
|
name: "alias-optimized-deps",
|
|
898
1144
|
async resolveId(id, importer, options) {
|
|
899
1145
|
if (!virtualDependencies.has(id)) {
|
|
@@ -911,7 +1157,8 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
911
1157
|
if (!resolvedPath) {
|
|
912
1158
|
resolvedPath = pkgJson.main ?? "index.js";
|
|
913
1159
|
}
|
|
914
|
-
|
|
1160
|
+
const resolved = await this.resolve(path2.posix.join(packageRootPath, resolvedPath), importer, options);
|
|
1161
|
+
return resolved;
|
|
915
1162
|
}
|
|
916
1163
|
} : null,
|
|
917
1164
|
optimizeLodashImports({
|
|
@@ -922,14 +1169,16 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
922
1169
|
transformMixedEsModules: true,
|
|
923
1170
|
ignoreTryCatch: false
|
|
924
1171
|
}),
|
|
925
|
-
bundlerOptions.
|
|
1172
|
+
bundlerOptions.noBundling ? null : nodeResolve({
|
|
926
1173
|
preferBuiltins: true,
|
|
927
1174
|
exportConditions: ["node"]
|
|
928
1175
|
}),
|
|
929
|
-
bundlerOptions.
|
|
1176
|
+
bundlerOptions.noBundling ? esmShim() : null,
|
|
930
1177
|
// hono is imported from deployer, so we need to resolve from here instead of the project root
|
|
931
1178
|
aliasHono(),
|
|
932
1179
|
json(),
|
|
1180
|
+
nodeGypDetector(),
|
|
1181
|
+
moduleResolveMap(externals, rootDir),
|
|
933
1182
|
{
|
|
934
1183
|
name: "not-found-resolver",
|
|
935
1184
|
resolveId: {
|
|
@@ -977,6 +1226,16 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
977
1226
|
if (virtualDependencies.size === 0) {
|
|
978
1227
|
return [];
|
|
979
1228
|
}
|
|
1229
|
+
const noBundling = bundlerOptions.isDev || bundlerOptions.externalsPreset;
|
|
1230
|
+
const plugins = await getInputPlugins2(virtualDependencies, {
|
|
1231
|
+
transpilePackages: packagesToTranspile,
|
|
1232
|
+
workspaceMap,
|
|
1233
|
+
bundlerOptions: {
|
|
1234
|
+
noBundling
|
|
1235
|
+
},
|
|
1236
|
+
rootDir,
|
|
1237
|
+
externals
|
|
1238
|
+
});
|
|
980
1239
|
const bundler = await rollup({
|
|
981
1240
|
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
982
1241
|
input: Array.from(virtualDependencies.entries()).reduce(
|
|
@@ -987,25 +1246,22 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
987
1246
|
{}
|
|
988
1247
|
),
|
|
989
1248
|
external: externals,
|
|
990
|
-
treeshake: "
|
|
991
|
-
plugins
|
|
992
|
-
transpilePackages: packagesToTranspile,
|
|
993
|
-
workspaceMap,
|
|
994
|
-
bundlerOptions,
|
|
995
|
-
rootDir
|
|
996
|
-
})
|
|
1249
|
+
treeshake: noBundling ? false : "safest",
|
|
1250
|
+
plugins
|
|
997
1251
|
});
|
|
998
1252
|
const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
|
|
999
1253
|
const { output } = await bundler.write({
|
|
1000
1254
|
format: "esm",
|
|
1001
1255
|
dir: rootDir,
|
|
1002
1256
|
entryFileNames: "[name].mjs",
|
|
1257
|
+
// used to get the filename of the actual error
|
|
1258
|
+
sourcemap: true,
|
|
1003
1259
|
/**
|
|
1004
1260
|
* Rollup creates chunks for common dependencies, but these chunks are by default written to the root directory instead of respecting the entryFileNames structure.
|
|
1005
1261
|
* So we want to write them to the `.mastra/output` folder as well.
|
|
1006
1262
|
*/
|
|
1007
1263
|
chunkFileNames: (chunkInfo) => {
|
|
1008
|
-
if (
|
|
1264
|
+
if (noBundling) {
|
|
1009
1265
|
const importedFromPackages = /* @__PURE__ */ new Set();
|
|
1010
1266
|
for (const moduleId of chunkInfo.moduleIds) {
|
|
1011
1267
|
const normalized = slash(moduleId);
|
|
@@ -1037,6 +1293,7 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1037
1293
|
}
|
|
1038
1294
|
return `${outputDirRelative}/[name].mjs`;
|
|
1039
1295
|
},
|
|
1296
|
+
assetFileNames: `${outputDirRelative}/[name][extname]`,
|
|
1040
1297
|
hoistTransitiveImports: false
|
|
1041
1298
|
});
|
|
1042
1299
|
await bundler.close();
|
|
@@ -1045,7 +1302,7 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1045
1302
|
function findExternalImporter(module, external, allOutputs) {
|
|
1046
1303
|
const capturedFiles = /* @__PURE__ */ new Set();
|
|
1047
1304
|
for (const id of module.imports) {
|
|
1048
|
-
if (id
|
|
1305
|
+
if (isDependencyPartOfPackage(id, external)) {
|
|
1049
1306
|
return module;
|
|
1050
1307
|
} else {
|
|
1051
1308
|
if (id.endsWith(".mjs")) {
|
|
@@ -1066,19 +1323,31 @@ function findExternalImporter(module, external, allOutputs) {
|
|
|
1066
1323
|
}
|
|
1067
1324
|
async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
1068
1325
|
const { workspaceRoot = null, workspaceMap = /* @__PURE__ */ new Map(), projectRoot = outputDir, bundlerOptions = {} } = options;
|
|
1069
|
-
const {
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1326
|
+
const { externals: customExternals = [], transpilePackages = [], isDev = false } = bundlerOptions || {};
|
|
1327
|
+
let externalsPreset = false;
|
|
1328
|
+
if (customExternals === true) {
|
|
1329
|
+
externalsPreset = true;
|
|
1330
|
+
}
|
|
1331
|
+
const externalsList = Array.isArray(customExternals) ? customExternals : [];
|
|
1332
|
+
const allExternals = [...GLOBAL_EXTERNALS, ...DEPRECATED_EXTERNALS, ...externalsList];
|
|
1074
1333
|
const workspacePackagesNames = Array.from(workspaceMap.keys());
|
|
1075
1334
|
const packagesToTranspile = /* @__PURE__ */ new Set([...transpilePackages, ...workspacePackagesNames]);
|
|
1335
|
+
const extractedExternals = /* @__PURE__ */ new Map();
|
|
1336
|
+
if (externalsPreset) {
|
|
1337
|
+
for (const [dep, metadata] of depsToOptimize.entries()) {
|
|
1338
|
+
if (!metadata.isWorkspace) {
|
|
1339
|
+
extractedExternals.set(dep, metadata.rootPath ?? dep);
|
|
1340
|
+
depsToOptimize.delete(dep);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1076
1344
|
const { optimizedDependencyEntries, fileNameToDependencyMap } = createVirtualDependencies(depsToOptimize, {
|
|
1077
1345
|
workspaceRoot,
|
|
1078
1346
|
outputDir,
|
|
1079
1347
|
projectRoot,
|
|
1080
1348
|
bundlerOptions: {
|
|
1081
|
-
isDev
|
|
1349
|
+
isDev,
|
|
1350
|
+
externalsPreset
|
|
1082
1351
|
}
|
|
1083
1352
|
});
|
|
1084
1353
|
const output = await buildExternalDependencies(optimizedDependencyEntries, {
|
|
@@ -1088,10 +1357,11 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1088
1357
|
rootDir: workspaceRoot || projectRoot,
|
|
1089
1358
|
outputDir,
|
|
1090
1359
|
bundlerOptions: {
|
|
1091
|
-
isDev
|
|
1360
|
+
isDev,
|
|
1361
|
+
externalsPreset
|
|
1092
1362
|
}
|
|
1093
1363
|
});
|
|
1094
|
-
const
|
|
1364
|
+
const moduleResolveMap2 = /* @__PURE__ */ new Map();
|
|
1095
1365
|
const filteredChunks = output.filter((o) => o.type === "chunk");
|
|
1096
1366
|
for (const o of filteredChunks.filter((o2) => o2.isEntry || o2.isDynamicEntry)) {
|
|
1097
1367
|
for (const external of allExternals) {
|
|
@@ -1101,10 +1371,10 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1101
1371
|
const importer = findExternalImporter(o, external, filteredChunks);
|
|
1102
1372
|
if (importer) {
|
|
1103
1373
|
const fullPath = path2.join(workspaceRoot || projectRoot, importer.fileName);
|
|
1104
|
-
let innerMap =
|
|
1374
|
+
let innerMap = moduleResolveMap2.get(fullPath);
|
|
1105
1375
|
if (!innerMap) {
|
|
1106
1376
|
innerMap = /* @__PURE__ */ new Map();
|
|
1107
|
-
|
|
1377
|
+
moduleResolveMap2.set(fullPath, innerMap);
|
|
1108
1378
|
}
|
|
1109
1379
|
if (importer.moduleIds.length) {
|
|
1110
1380
|
innerMap.set(
|
|
@@ -1116,15 +1386,125 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1116
1386
|
}
|
|
1117
1387
|
}
|
|
1118
1388
|
const usedExternals = /* @__PURE__ */ Object.create(null);
|
|
1119
|
-
for (const [fullPath, innerMap] of
|
|
1389
|
+
for (const [fullPath, innerMap] of moduleResolveMap2) {
|
|
1120
1390
|
const innerObj = /* @__PURE__ */ Object.create(null);
|
|
1121
1391
|
for (const [external, value] of innerMap) {
|
|
1122
1392
|
innerObj[external] = value;
|
|
1123
1393
|
}
|
|
1124
1394
|
usedExternals[fullPath] = innerObj;
|
|
1125
1395
|
}
|
|
1396
|
+
if (extractedExternals.size > 0) {
|
|
1397
|
+
const syntheticPath = path2.join(workspaceRoot || projectRoot, "__externals__");
|
|
1398
|
+
const externalsObj = /* @__PURE__ */ Object.create(null);
|
|
1399
|
+
for (const [dep, rootPath] of extractedExternals) {
|
|
1400
|
+
externalsObj[dep] = rootPath;
|
|
1401
|
+
}
|
|
1402
|
+
usedExternals[syntheticPath] = externalsObj;
|
|
1403
|
+
}
|
|
1126
1404
|
return { output, fileNameToDependencyMap, usedExternals };
|
|
1127
1405
|
}
|
|
1406
|
+
|
|
1407
|
+
// ../../node_modules/.pnpm/stacktrace-parser@0.1.11/node_modules/stacktrace-parser/dist/stack-trace-parser.esm.js
|
|
1408
|
+
var UNKNOWN_FUNCTION = "<unknown>";
|
|
1409
|
+
function parse(stackString) {
|
|
1410
|
+
var lines = stackString.split("\n");
|
|
1411
|
+
return lines.reduce(function(stack, line) {
|
|
1412
|
+
var parseResult = parseChrome(line) || parseWinjs(line) || parseGecko(line) || parseNode(line) || parseJSC(line);
|
|
1413
|
+
if (parseResult) {
|
|
1414
|
+
stack.push(parseResult);
|
|
1415
|
+
}
|
|
1416
|
+
return stack;
|
|
1417
|
+
}, []);
|
|
1418
|
+
}
|
|
1419
|
+
var chromeRe = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|rsc|<anonymous>|\/|[a-z]:\\|\\\\).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
|
|
1420
|
+
var chromeEvalRe = /\((\S*)(?::(\d+))(?::(\d+))\)/;
|
|
1421
|
+
function parseChrome(line) {
|
|
1422
|
+
var parts = chromeRe.exec(line);
|
|
1423
|
+
if (!parts) {
|
|
1424
|
+
return null;
|
|
1425
|
+
}
|
|
1426
|
+
var isNative = parts[2] && parts[2].indexOf("native") === 0;
|
|
1427
|
+
var isEval = parts[2] && parts[2].indexOf("eval") === 0;
|
|
1428
|
+
var submatch = chromeEvalRe.exec(parts[2]);
|
|
1429
|
+
if (isEval && submatch != null) {
|
|
1430
|
+
parts[2] = submatch[1];
|
|
1431
|
+
parts[3] = submatch[2];
|
|
1432
|
+
parts[4] = submatch[3];
|
|
1433
|
+
}
|
|
1434
|
+
return {
|
|
1435
|
+
file: !isNative ? parts[2] : null,
|
|
1436
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1437
|
+
arguments: isNative ? [parts[2]] : [],
|
|
1438
|
+
lineNumber: parts[3] ? +parts[3] : null,
|
|
1439
|
+
column: parts[4] ? +parts[4] : null
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
var winjsRe = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|rsc|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
1443
|
+
function parseWinjs(line) {
|
|
1444
|
+
var parts = winjsRe.exec(line);
|
|
1445
|
+
if (!parts) {
|
|
1446
|
+
return null;
|
|
1447
|
+
}
|
|
1448
|
+
return {
|
|
1449
|
+
file: parts[2],
|
|
1450
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1451
|
+
arguments: [],
|
|
1452
|
+
lineNumber: +parts[3],
|
|
1453
|
+
column: parts[4] ? +parts[4] : null
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
var geckoRe = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|rsc|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i;
|
|
1457
|
+
var geckoEvalRe = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
|
|
1458
|
+
function parseGecko(line) {
|
|
1459
|
+
var parts = geckoRe.exec(line);
|
|
1460
|
+
if (!parts) {
|
|
1461
|
+
return null;
|
|
1462
|
+
}
|
|
1463
|
+
var isEval = parts[3] && parts[3].indexOf(" > eval") > -1;
|
|
1464
|
+
var submatch = geckoEvalRe.exec(parts[3]);
|
|
1465
|
+
if (isEval && submatch != null) {
|
|
1466
|
+
parts[3] = submatch[1];
|
|
1467
|
+
parts[4] = submatch[2];
|
|
1468
|
+
parts[5] = null;
|
|
1469
|
+
}
|
|
1470
|
+
return {
|
|
1471
|
+
file: parts[3],
|
|
1472
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1473
|
+
arguments: parts[2] ? parts[2].split(",") : [],
|
|
1474
|
+
lineNumber: parts[4] ? +parts[4] : null,
|
|
1475
|
+
column: parts[5] ? +parts[5] : null
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
var javaScriptCoreRe = /^\s*(?:([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$/i;
|
|
1479
|
+
function parseJSC(line) {
|
|
1480
|
+
var parts = javaScriptCoreRe.exec(line);
|
|
1481
|
+
if (!parts) {
|
|
1482
|
+
return null;
|
|
1483
|
+
}
|
|
1484
|
+
return {
|
|
1485
|
+
file: parts[3],
|
|
1486
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1487
|
+
arguments: [],
|
|
1488
|
+
lineNumber: +parts[4],
|
|
1489
|
+
column: parts[5] ? +parts[5] : null
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1492
|
+
var nodeRe = /^\s*at (?:((?:\[object object\])?[^\\/]+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
1493
|
+
function parseNode(line) {
|
|
1494
|
+
var parts = nodeRe.exec(line);
|
|
1495
|
+
if (!parts) {
|
|
1496
|
+
return null;
|
|
1497
|
+
}
|
|
1498
|
+
return {
|
|
1499
|
+
file: parts[2],
|
|
1500
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
1501
|
+
arguments: [],
|
|
1502
|
+
lineNumber: +parts[3],
|
|
1503
|
+
column: parts[4] ? +parts[4] : null
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
// src/build/analyze.ts
|
|
1128
1508
|
function throwExternalDependencyError({
|
|
1129
1509
|
errorId,
|
|
1130
1510
|
moduleName,
|
|
@@ -1148,73 +1528,152 @@ export const mastra = new Mastra({
|
|
|
1148
1528
|
})`
|
|
1149
1529
|
});
|
|
1150
1530
|
}
|
|
1531
|
+
function getPackageNameFromBundledModuleName(moduleName) {
|
|
1532
|
+
const chunks = moduleName.split("-");
|
|
1533
|
+
if (!chunks.length) {
|
|
1534
|
+
return moduleName;
|
|
1535
|
+
}
|
|
1536
|
+
if (chunks[0]?.startsWith("@")) {
|
|
1537
|
+
return chunks.slice(0, 2).join("/");
|
|
1538
|
+
}
|
|
1539
|
+
return chunks[0];
|
|
1540
|
+
}
|
|
1541
|
+
function validateError(err, file, {
|
|
1542
|
+
binaryMapData,
|
|
1543
|
+
workspaceMap
|
|
1544
|
+
}) {
|
|
1545
|
+
let moduleName = null;
|
|
1546
|
+
let errorConfig = null;
|
|
1547
|
+
if (err instanceof ValidationError) {
|
|
1548
|
+
const parsedStack = parse(err.stack);
|
|
1549
|
+
if (err.type === "TypeError") {
|
|
1550
|
+
const pkgNameRegex = /.*node_modules\/([^\/]+)\//;
|
|
1551
|
+
const stacktraceFrame = parsedStack.find((frame) => frame.file && pkgNameRegex.test(frame.file));
|
|
1552
|
+
if (stacktraceFrame) {
|
|
1553
|
+
const match = stacktraceFrame.file.match(pkgNameRegex);
|
|
1554
|
+
moduleName = match?.[1] ?? getPackageNameFromBundledModuleName(basename$1(file.name));
|
|
1555
|
+
} else {
|
|
1556
|
+
moduleName = getPackageNameFromBundledModuleName(basename$1(file.name));
|
|
1557
|
+
}
|
|
1558
|
+
errorConfig = {
|
|
1559
|
+
id: "DEPLOYER_ANALYZE_TYPE_ERROR",
|
|
1560
|
+
messagePrefix: `Mastra wasn't able to bundle "${moduleName}", might be an older commonJS module. Please add`
|
|
1561
|
+
};
|
|
1562
|
+
} else if (err.stack?.includes?.("[ERR_MODULE_NOT_FOUND]")) {
|
|
1563
|
+
moduleName = err.message.match(/Cannot find package '([^']+)'/)?.[1];
|
|
1564
|
+
const parentModuleName = getPackageNameFromBundledModuleName(basename$1(file.name));
|
|
1565
|
+
errorConfig = {
|
|
1566
|
+
id: "DEPLOYER_ANALYZE_MODULE_NOT_FOUND",
|
|
1567
|
+
messagePrefix: `Mastra wasn't able to build your project, We couldn't load "${moduleName}" from "${parentModuleName}". Make sure "${moduleName}" is installed or add`
|
|
1568
|
+
};
|
|
1569
|
+
if (moduleName === parentModuleName) {
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
if (err.message.includes("No native build was found")) {
|
|
1575
|
+
const pkgName = getPackageNameFromBundledModuleName(basename$1(file.name));
|
|
1576
|
+
moduleName = binaryMapData[file.fileName]?.[0] ?? pkgName;
|
|
1577
|
+
errorConfig = {
|
|
1578
|
+
id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
|
|
1579
|
+
messagePrefix: "We found a binary dependency in your bundle but we cannot bundle it yet. Please add"
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
if (moduleName && workspaceMap.has(moduleName)) {
|
|
1583
|
+
throw new MastraError({
|
|
1584
|
+
id: "DEPLOYER_ANALYZE_ERROR_IN_WORKSPACE",
|
|
1585
|
+
domain: ErrorDomain.DEPLOYER,
|
|
1586
|
+
category: ErrorCategory.USER,
|
|
1587
|
+
details: {
|
|
1588
|
+
// importFile: moduleName,
|
|
1589
|
+
packageName: moduleName
|
|
1590
|
+
},
|
|
1591
|
+
text: `We found an error in the ${moduleName} workspace package. Please find the offending package and fix the error.
|
|
1592
|
+
Error: ${err.stack}`
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
if (errorConfig && moduleName) {
|
|
1596
|
+
throwExternalDependencyError({
|
|
1597
|
+
errorId: errorConfig.id,
|
|
1598
|
+
moduleName,
|
|
1599
|
+
packageName: moduleName,
|
|
1600
|
+
messagePrefix: errorConfig.messagePrefix
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
async function validateFile(root, file, {
|
|
1605
|
+
binaryMapData,
|
|
1606
|
+
moduleResolveMapLocation,
|
|
1607
|
+
logger,
|
|
1608
|
+
workspaceMap
|
|
1609
|
+
}) {
|
|
1610
|
+
try {
|
|
1611
|
+
if (!file.isDynamicEntry && file.isEntry) {
|
|
1612
|
+
await validate(join(root, file.fileName), {
|
|
1613
|
+
moduleResolveMapLocation,
|
|
1614
|
+
injectESMShim: false
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1617
|
+
} catch (err) {
|
|
1618
|
+
let errorToHandle = err;
|
|
1619
|
+
if (err instanceof ValidationError && err.type === "ReferenceError" && (err.message.startsWith("__dirname") || err.message.startsWith("__filename"))) {
|
|
1620
|
+
try {
|
|
1621
|
+
await validate(join(root, file.fileName), {
|
|
1622
|
+
moduleResolveMapLocation,
|
|
1623
|
+
injectESMShim: true
|
|
1624
|
+
});
|
|
1625
|
+
errorToHandle = null;
|
|
1626
|
+
} catch (err2) {
|
|
1627
|
+
errorToHandle = err2;
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
if (errorToHandle instanceof Error) {
|
|
1631
|
+
validateError(errorToHandle, file, { binaryMapData, workspaceMap });
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1151
1635
|
async function validateOutput({
|
|
1152
1636
|
output,
|
|
1153
1637
|
reverseVirtualReferenceMap,
|
|
1154
1638
|
usedExternals,
|
|
1155
1639
|
outputDir,
|
|
1156
1640
|
projectRoot,
|
|
1157
|
-
workspaceMap
|
|
1641
|
+
workspaceMap,
|
|
1642
|
+
depsVersionInfo
|
|
1158
1643
|
}, logger) {
|
|
1159
1644
|
const result = {
|
|
1160
1645
|
dependencies: /* @__PURE__ */ new Map(),
|
|
1161
|
-
externalDependencies: /* @__PURE__ */ new
|
|
1646
|
+
externalDependencies: /* @__PURE__ */ new Map(),
|
|
1162
1647
|
workspaceMap
|
|
1163
1648
|
};
|
|
1164
|
-
await writeFile(join(outputDir, "module-resolve-map.json"), JSON.stringify(usedExternals, null, 2));
|
|
1165
1649
|
for (const deps of Object.values(usedExternals)) {
|
|
1166
1650
|
for (const dep of Object.keys(deps)) {
|
|
1167
|
-
|
|
1651
|
+
const pkgName = getPackageName(dep);
|
|
1652
|
+
if (pkgName) {
|
|
1653
|
+
const versionInfo = depsVersionInfo.get(dep) || depsVersionInfo.get(pkgName) || {};
|
|
1654
|
+
result.externalDependencies.set(pkgName, versionInfo);
|
|
1655
|
+
}
|
|
1168
1656
|
}
|
|
1169
1657
|
}
|
|
1658
|
+
let binaryMapData = {};
|
|
1659
|
+
if (existsSync(join(outputDir, "binary-map.json"))) {
|
|
1660
|
+
const binaryMap = await readFile(join(outputDir, "binary-map.json"), "utf-8");
|
|
1661
|
+
binaryMapData = JSON.parse(binaryMap);
|
|
1662
|
+
}
|
|
1170
1663
|
for (const file of output) {
|
|
1171
1664
|
if (file.type === "asset") {
|
|
1172
1665
|
continue;
|
|
1173
1666
|
}
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
|
|
1178
|
-
}
|
|
1179
|
-
if (!file.isDynamicEntry && file.isEntry) {
|
|
1180
|
-
await validate(join(projectRoot, file.fileName));
|
|
1181
|
-
}
|
|
1182
|
-
} catch (err) {
|
|
1183
|
-
if (err instanceof Error) {
|
|
1184
|
-
let moduleName = null;
|
|
1185
|
-
let errorConfig = null;
|
|
1186
|
-
if (err.message.includes("[ERR_MODULE_NOT_FOUND]")) {
|
|
1187
|
-
const moduleIdName = file.moduleIds.length >= 2 ? file.moduleIds[file.moduleIds.length - 2] : void 0;
|
|
1188
|
-
const fallbackName = file.name.split("/").pop();
|
|
1189
|
-
moduleName = moduleIdName ?? fallbackName;
|
|
1190
|
-
errorConfig = {
|
|
1191
|
-
id: "DEPLOYER_ANALYZE_MODULE_NOT_FOUND",
|
|
1192
|
-
messagePrefix: "Mastra wasn't able to build your project. Please add"
|
|
1193
|
-
};
|
|
1194
|
-
} else if (err.message.includes("Error: No native build was found for ")) {
|
|
1195
|
-
moduleName = findNativePackageModule(file.moduleIds);
|
|
1196
|
-
errorConfig = {
|
|
1197
|
-
id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
|
|
1198
|
-
messagePrefix: "We found a binary dependency in your bundle. Please add"
|
|
1199
|
-
};
|
|
1200
|
-
}
|
|
1201
|
-
if (moduleName && errorConfig) {
|
|
1202
|
-
const pkgInfo = await getPackageInfo(moduleName);
|
|
1203
|
-
const packageName = pkgInfo?.packageJson?.name;
|
|
1204
|
-
if (packageName) {
|
|
1205
|
-
throwExternalDependencyError({
|
|
1206
|
-
errorId: errorConfig.id,
|
|
1207
|
-
moduleName,
|
|
1208
|
-
packageName,
|
|
1209
|
-
messagePrefix: errorConfig.messagePrefix
|
|
1210
|
-
});
|
|
1211
|
-
} else {
|
|
1212
|
-
logger.debug(`Could not determine the module name for file ${file.fileName}`);
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
logger.debug(`Error while validating module ${file.fileName}: ${err.message}`);
|
|
1216
|
-
}
|
|
1667
|
+
logger.debug(`Validating if ${file.fileName} is a valid module.`);
|
|
1668
|
+
if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
|
|
1669
|
+
result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
|
|
1217
1670
|
}
|
|
1671
|
+
await validateFile(projectRoot, file, {
|
|
1672
|
+
binaryMapData,
|
|
1673
|
+
moduleResolveMapLocation: join(outputDir, "module-resolve-map.json"),
|
|
1674
|
+
logger,
|
|
1675
|
+
workspaceMap
|
|
1676
|
+
});
|
|
1218
1677
|
}
|
|
1219
1678
|
return result;
|
|
1220
1679
|
}
|
|
@@ -1222,7 +1681,7 @@ async function analyzeBundle(entries, mastraEntry, {
|
|
|
1222
1681
|
outputDir,
|
|
1223
1682
|
projectRoot,
|
|
1224
1683
|
isDev = false,
|
|
1225
|
-
bundlerOptions
|
|
1684
|
+
bundlerOptions
|
|
1226
1685
|
}, logger) {
|
|
1227
1686
|
const mastraConfig = await readFile(mastraEntry, "utf-8");
|
|
1228
1687
|
const mastraConfigResult = {
|
|
@@ -1241,22 +1700,38 @@ export const mastra = new Mastra({
|
|
|
1241
1700
|
|
|
1242
1701
|
If you think your configuration is valid, please open an issue.`);
|
|
1243
1702
|
}
|
|
1244
|
-
const { enableEsmShim = true } = _bundlerOptions || {};
|
|
1245
|
-
const bundlerOptions = await getBundlerOptions(mastraEntry, outputDir);
|
|
1246
1703
|
const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
|
|
1704
|
+
let externalsPreset = false;
|
|
1705
|
+
const userExternals = Array.isArray(bundlerOptions?.externals) ? bundlerOptions?.externals : [];
|
|
1706
|
+
if (bundlerOptions?.externals === true) {
|
|
1707
|
+
externalsPreset = true;
|
|
1708
|
+
}
|
|
1247
1709
|
let index = 0;
|
|
1248
1710
|
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
1711
|
+
const allExternals = [...GLOBAL_EXTERNALS, ...userExternals].filter(Boolean);
|
|
1249
1712
|
logger.info("Analyzing dependencies...");
|
|
1713
|
+
const allUsedExternals = /* @__PURE__ */ new Map();
|
|
1250
1714
|
for (const entry of entries) {
|
|
1251
1715
|
const isVirtualFile = entry.includes("\n") || !existsSync(entry);
|
|
1252
1716
|
const analyzeResult = await analyzeEntry({ entry, isVirtualFile }, mastraEntry, {
|
|
1253
1717
|
logger,
|
|
1254
|
-
sourcemapEnabled: bundlerOptions?.
|
|
1718
|
+
sourcemapEnabled: bundlerOptions?.enableSourcemap ?? false,
|
|
1255
1719
|
workspaceMap,
|
|
1256
|
-
projectRoot
|
|
1720
|
+
projectRoot,
|
|
1721
|
+
shouldCheckTransitiveDependencies: isDev || externalsPreset
|
|
1257
1722
|
});
|
|
1258
1723
|
await writeFile(join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
|
|
1259
1724
|
for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
|
|
1725
|
+
const isPartOfExternals = allExternals.some((external) => isDependencyPartOfPackage(dep, external));
|
|
1726
|
+
if (isPartOfExternals || externalsPreset && !metadata.isWorkspace) {
|
|
1727
|
+
const pkgName = getPackageName(dep);
|
|
1728
|
+
if (pkgName && !allUsedExternals.has(pkgName)) {
|
|
1729
|
+
allUsedExternals.set(pkgName, {
|
|
1730
|
+
version: metadata.version
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
continue;
|
|
1734
|
+
}
|
|
1260
1735
|
if (depsToOptimize.has(dep)) {
|
|
1261
1736
|
const existingEntry = depsToOptimize.get(dep);
|
|
1262
1737
|
depsToOptimize.set(dep, {
|
|
@@ -1268,28 +1743,64 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1268
1743
|
}
|
|
1269
1744
|
}
|
|
1270
1745
|
}
|
|
1271
|
-
if (isDev) {
|
|
1746
|
+
if (isDev || externalsPreset) {
|
|
1272
1747
|
for (const [dep, metadata] of depsToOptimize.entries()) {
|
|
1273
1748
|
if (!metadata.isWorkspace) {
|
|
1274
1749
|
depsToOptimize.delete(dep);
|
|
1275
1750
|
}
|
|
1276
1751
|
}
|
|
1277
1752
|
}
|
|
1278
|
-
|
|
1753
|
+
const sortedDeps = Array.from(depsToOptimize.keys()).sort();
|
|
1279
1754
|
logger.info("Optimizing dependencies...");
|
|
1280
|
-
logger.debug(
|
|
1281
|
-
`${Array.from(depsToOptimize.keys()).map((key) => `- ${key}`).join("\n")}`
|
|
1282
|
-
);
|
|
1755
|
+
logger.debug(`${sortedDeps.map((key) => `- ${key}`).join("\n")}`);
|
|
1283
1756
|
const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
|
|
1284
1757
|
bundlerOptions: {
|
|
1285
1758
|
...bundlerOptions,
|
|
1286
|
-
|
|
1759
|
+
externals: bundlerOptions?.externals ?? allExternals,
|
|
1287
1760
|
isDev
|
|
1288
1761
|
},
|
|
1289
1762
|
projectRoot,
|
|
1290
1763
|
workspaceRoot,
|
|
1291
1764
|
workspaceMap
|
|
1292
1765
|
});
|
|
1766
|
+
const relativeWorkspaceFolderPaths = Array.from(workspaceMap.values()).map(
|
|
1767
|
+
(pkgInfo) => relative(workspaceRoot || projectRoot, pkgInfo.location)
|
|
1768
|
+
);
|
|
1769
|
+
const depsVersionInfo = /* @__PURE__ */ new Map();
|
|
1770
|
+
for (const [dep, metadata] of depsToOptimize.entries()) {
|
|
1771
|
+
const pkgName = getPackageName(dep);
|
|
1772
|
+
if (pkgName && metadata.version) {
|
|
1773
|
+
depsVersionInfo.set(pkgName, {
|
|
1774
|
+
version: metadata.version
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
if (metadata.version) {
|
|
1778
|
+
depsVersionInfo.set(dep, {
|
|
1779
|
+
version: metadata.version
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
for (const o of output) {
|
|
1784
|
+
if (o.type === "asset") {
|
|
1785
|
+
continue;
|
|
1786
|
+
}
|
|
1787
|
+
for (const i of o.imports) {
|
|
1788
|
+
if (isBuiltinModule(i)) {
|
|
1789
|
+
continue;
|
|
1790
|
+
}
|
|
1791
|
+
if (i.startsWith(".") || i.startsWith("/")) {
|
|
1792
|
+
continue;
|
|
1793
|
+
}
|
|
1794
|
+
if (relativeWorkspaceFolderPaths.some((workspacePath) => i.startsWith(workspacePath))) {
|
|
1795
|
+
continue;
|
|
1796
|
+
}
|
|
1797
|
+
const pkgName = getPackageName(i);
|
|
1798
|
+
if (pkgName && !allUsedExternals.has(pkgName)) {
|
|
1799
|
+
const versionInfo = depsVersionInfo.get(i) || depsVersionInfo.get(pkgName) || {};
|
|
1800
|
+
allUsedExternals.set(pkgName, versionInfo);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1293
1804
|
const result = await validateOutput(
|
|
1294
1805
|
{
|
|
1295
1806
|
output,
|
|
@@ -1297,13 +1808,23 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1297
1808
|
usedExternals,
|
|
1298
1809
|
outputDir,
|
|
1299
1810
|
projectRoot: workspaceRoot || projectRoot,
|
|
1300
|
-
workspaceMap
|
|
1811
|
+
workspaceMap,
|
|
1812
|
+
depsVersionInfo
|
|
1301
1813
|
},
|
|
1302
1814
|
logger
|
|
1303
1815
|
);
|
|
1304
|
-
|
|
1816
|
+
const mergedExternalDeps = new Map(result.externalDependencies);
|
|
1817
|
+
for (const [dep, info] of allUsedExternals) {
|
|
1818
|
+
if (!mergedExternalDeps.has(dep)) {
|
|
1819
|
+
mergedExternalDeps.set(dep, info);
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
return {
|
|
1823
|
+
...result,
|
|
1824
|
+
externalDependencies: mergedExternalDeps
|
|
1825
|
+
};
|
|
1305
1826
|
}
|
|
1306
1827
|
|
|
1307
|
-
export { aliasHono, analyzeBundle, esbuild, extractMastraOption, getBundlerOptions,
|
|
1308
|
-
//# sourceMappingURL=chunk-
|
|
1309
|
-
//# sourceMappingURL=chunk-
|
|
1828
|
+
export { aliasHono, analyzeBundle, esbuild, esmShim, extractMastraOption, getBundlerOptions, getPackageRootPath, getWorkspaceInformation, removeDeployer2 as removeDeployer, subpathExternalsResolver, tsConfigPaths };
|
|
1829
|
+
//# sourceMappingURL=chunk-GX3DPJAT.js.map
|
|
1830
|
+
//# sourceMappingURL=chunk-GX3DPJAT.js.map
|