@mastra/deployer 1.54.0-alpha.0 → 1.54.0-alpha.2
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 +16 -0
- package/dist/analyze-C2q7jxbN.js +1308 -0
- package/dist/analyze-C2q7jxbN.js.map +1 -0
- package/dist/analyze-DhDZW9TS.cjs +1318 -0
- package/dist/analyze-DhDZW9TS.cjs.map +1 -0
- package/dist/arktype-aI7TBD0R-BsgjPZ4a.cjs +8 -0
- package/dist/arktype-aI7TBD0R-BsgjPZ4a.cjs.map +1 -0
- package/dist/arktype-aI7TBD0R-_UZl-wsH.js +8 -0
- package/dist/arktype-aI7TBD0R-_UZl-wsH.js.map +1 -0
- package/dist/build/analyze/constants.d.ts.map +1 -1
- package/dist/build/analyze.cjs +3 -12
- package/dist/build/analyze.js +2 -3
- package/dist/build/bundler.cjs +6 -24
- package/dist/build/bundler.js +2 -3
- package/dist/build/index.cjs +29 -101
- package/dist/build/index.js +7 -8
- package/dist/build-De4AZhfJ.cjs +908 -0
- package/dist/build-De4AZhfJ.cjs.map +1 -0
- package/dist/build-KCOeHd4N.js +834 -0
- package/dist/build-KCOeHd4N.js.map +1 -0
- package/dist/bundler/index.cjs +318 -13
- package/dist/bundler/index.cjs.map +1 -1
- package/dist/bundler/index.js +314 -2
- package/dist/bundler/index.js.map +1 -1
- package/dist/bundler-BqrDXofn.cjs +792 -0
- package/dist/bundler-BqrDXofn.cjs.map +1 -0
- package/dist/bundler-D86rFu2J.js +705 -0
- package/dist/bundler-D86rFu2J.js.map +1 -0
- package/dist/bundlerOptions-aFsEi86t.js +180 -0
- package/dist/bundlerOptions-aFsEi86t.js.map +1 -0
- package/dist/bundlerOptions-rBmtSyGe.cjs +194 -0
- package/dist/bundlerOptions-rBmtSyGe.cjs.map +1 -0
- package/dist/core-D0wEgdn3.cjs +790 -0
- package/dist/core-D0wEgdn3.cjs.map +1 -0
- package/dist/core-DF65PJXc.js +790 -0
- package/dist/core-DF65PJXc.js.map +1 -0
- package/dist/dist-BauTimif.js +532 -0
- package/dist/dist-BauTimif.js.map +1 -0
- package/dist/dist-Cv-mAEtr.cjs +532 -0
- package/dist/dist-Cv-mAEtr.cjs.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +2 -23
- package/dist/docs/references/docs-deployment-cloud-providers.md +1 -0
- package/dist/docs/references/docs-deployment-overview.md +1 -0
- package/dist/effect-QlVUlMFu-CwFnyS-g.cjs +14 -0
- package/dist/effect-QlVUlMFu-CwFnyS-g.cjs.map +1 -0
- package/dist/effect-QlVUlMFu-gyLQRCtQ.js +14 -0
- package/dist/effect-QlVUlMFu-gyLQRCtQ.js.map +1 -0
- package/dist/esm-BX-weMyC.js +4634 -0
- package/dist/esm-BX-weMyC.js.map +1 -0
- package/dist/esm-D81PZ_wJ.cjs +4634 -0
- package/dist/esm-D81PZ_wJ.cjs.map +1 -0
- package/dist/index-CLddUTqr-B5mOP6DC.cjs +145 -0
- package/dist/index-CLddUTqr-B5mOP6DC.cjs.map +1 -0
- package/dist/index-CLddUTqr-CkS6Y_hA.js +140 -0
- package/dist/index-CLddUTqr-CkS6Y_hA.js.map +1 -0
- package/dist/index.cjs +35 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -30
- package/dist/index.js.map +1 -1
- package/dist/rolldown-runtime-emK7D4bc.cjs +35 -0
- package/dist/server/index.cjs +3141 -3874
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +3131 -3842
- package/dist/server/index.js.map +1 -1
- package/dist/server/types.d.ts +1 -0
- package/dist/server/types.d.ts.map +1 -1
- package/dist/services/index.cjs +5 -20
- package/dist/services/index.js +2 -3
- package/dist/services-BxYMLS9-.cjs +430 -0
- package/dist/services-BxYMLS9-.cjs.map +1 -0
- package/dist/services-CLi56qqe.js +391 -0
- package/dist/services-CLi56qqe.js.map +1 -0
- package/dist/sury-CWZTCd75-B85M6878.js +14 -0
- package/dist/sury-CWZTCd75-B85M6878.js.map +1 -0
- package/dist/sury-CWZTCd75-DTj5HlK_.cjs +14 -0
- package/dist/sury-CWZTCd75-DTj5HlK_.cjs.map +1 -0
- package/dist/typebox-Dei93FPO-BeuT13_G.cjs +8 -0
- package/dist/typebox-Dei93FPO-BeuT13_G.cjs.map +1 -0
- package/dist/typebox-Dei93FPO-DovwMlVl.js +8 -0
- package/dist/typebox-Dei93FPO-DovwMlVl.js.map +1 -0
- package/dist/utils-FVOUvj-I.js +190 -0
- package/dist/utils-FVOUvj-I.js.map +1 -0
- package/dist/utils-O98BGdnP.cjs +267 -0
- package/dist/utils-O98BGdnP.cjs.map +1 -0
- package/dist/valibot--1zFm7rT-BqJHja5B.cjs +14 -0
- package/dist/valibot--1zFm7rT-BqJHja5B.cjs.map +1 -0
- package/dist/valibot--1zFm7rT-Y4Fhea0w.js +14 -0
- package/dist/valibot--1zFm7rT-Y4Fhea0w.js.map +1 -0
- package/dist/validator/custom-resolver.cjs +71 -73
- package/dist/validator/custom-resolver.cjs.map +1 -1
- package/dist/validator/custom-resolver.js +70 -71
- package/dist/validator/custom-resolver.js.map +1 -1
- package/dist/validator/loader.cjs +6 -7
- package/dist/validator/loader.cjs.map +1 -1
- package/dist/validator/loader.js +8 -4
- package/dist/validator/loader.js.map +1 -1
- package/dist/zod-Bwrt9trS-2JL6_UI_.cjs +23 -0
- package/dist/zod-Bwrt9trS-2JL6_UI_.cjs.map +1 -0
- package/dist/zod-Bwrt9trS-rVHICsmp.js +23 -0
- package/dist/zod-Bwrt9trS-rVHICsmp.js.map +1 -0
- package/package.json +7 -7
- package/dist/arktype-aI7TBD0R-K3QZAVE2.js +0 -8
- package/dist/arktype-aI7TBD0R-K3QZAVE2.js.map +0 -1
- package/dist/arktype-aI7TBD0R-WK5AZZMC.cjs +0 -10
- package/dist/arktype-aI7TBD0R-WK5AZZMC.cjs.map +0 -1
- package/dist/build/analyze.cjs.map +0 -1
- package/dist/build/analyze.js.map +0 -1
- package/dist/build/bundler.cjs.map +0 -1
- package/dist/build/bundler.js.map +0 -1
- package/dist/build/index.cjs.map +0 -1
- package/dist/build/index.js.map +0 -1
- package/dist/chunk-36AWZH7Z.cjs +0 -252
- package/dist/chunk-36AWZH7Z.cjs.map +0 -1
- package/dist/chunk-3XIMK24X.cjs +0 -765
- package/dist/chunk-3XIMK24X.cjs.map +0 -1
- package/dist/chunk-46M65MQG.cjs +0 -95
- package/dist/chunk-46M65MQG.cjs.map +0 -1
- package/dist/chunk-4ZNTNJ6T.js +0 -6
- package/dist/chunk-4ZNTNJ6T.js.map +0 -1
- package/dist/chunk-5PORNUPF.js +0 -739
- package/dist/chunk-5PORNUPF.js.map +0 -1
- package/dist/chunk-743HRNWT.cjs +0 -1546
- package/dist/chunk-743HRNWT.cjs.map +0 -1
- package/dist/chunk-AEQ7JHDB.cjs +0 -412
- package/dist/chunk-AEQ7JHDB.cjs.map +0 -1
- package/dist/chunk-E5SBYHQK.js +0 -244
- package/dist/chunk-E5SBYHQK.js.map +0 -1
- package/dist/chunk-FKKJQUGR.cjs +0 -497
- package/dist/chunk-FKKJQUGR.cjs.map +0 -1
- package/dist/chunk-FQHUOYYL.js +0 -1514
- package/dist/chunk-FQHUOYYL.js.map +0 -1
- package/dist/chunk-G7MIMGMX.js +0 -14
- package/dist/chunk-G7MIMGMX.js.map +0 -1
- package/dist/chunk-HZC3PTK2.cjs +0 -16
- package/dist/chunk-HZC3PTK2.cjs.map +0 -1
- package/dist/chunk-JZRFRUGM.cjs +0 -158
- package/dist/chunk-JZRFRUGM.cjs.map +0 -1
- package/dist/chunk-L45X3DJX.js +0 -385
- package/dist/chunk-L45X3DJX.js.map +0 -1
- package/dist/chunk-PC25XSK7.cjs +0 -8
- package/dist/chunk-PC25XSK7.cjs.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -9
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-Q7SFCCGT.cjs +0 -11
- package/dist/chunk-Q7SFCCGT.cjs.map +0 -1
- package/dist/chunk-T4UT2QX7.js +0 -3
- package/dist/chunk-T4UT2QX7.js.map +0 -1
- package/dist/chunk-UBIDJOJA.js +0 -93
- package/dist/chunk-UBIDJOJA.js.map +0 -1
- package/dist/chunk-V3EKV6QB.cjs +0 -162
- package/dist/chunk-V3EKV6QB.cjs.map +0 -1
- package/dist/chunk-WHD2QQ3N.js +0 -783
- package/dist/chunk-WHD2QQ3N.js.map +0 -1
- package/dist/chunk-WP65JQAT.js +0 -144
- package/dist/chunk-WP65JQAT.js.map +0 -1
- package/dist/chunk-YO5OFXPN.cjs +0 -819
- package/dist/chunk-YO5OFXPN.cjs.map +0 -1
- package/dist/chunk-YUBKHO52.js +0 -465
- package/dist/chunk-YUBKHO52.js.map +0 -1
- package/dist/chunk-YWMYXUHX.cjs +0 -4
- package/dist/chunk-YWMYXUHX.cjs.map +0 -1
- package/dist/chunk-ZKZOVNT4.js +0 -159
- package/dist/chunk-ZKZOVNT4.js.map +0 -1
- package/dist/core-XIDAXLRB.js +0 -11866
- package/dist/core-XIDAXLRB.js.map +0 -1
- package/dist/core-XJNQ4AY6.cjs +0 -12141
- package/dist/core-XJNQ4AY6.cjs.map +0 -1
- package/dist/default-u_dwuiYb-HGUAHA6N.cjs +0 -9
- package/dist/default-u_dwuiYb-HGUAHA6N.cjs.map +0 -1
- package/dist/default-u_dwuiYb-MVPTVDCE.js +0 -3
- package/dist/default-u_dwuiYb-MVPTVDCE.js.map +0 -1
- package/dist/dist-UEE5OLII.cjs +0 -521
- package/dist/dist-UEE5OLII.cjs.map +0 -1
- package/dist/dist-X75F2Q36.js +0 -515
- package/dist/dist-X75F2Q36.js.map +0 -1
- package/dist/effect-QlVUlMFu-QNLZLGWO.js +0 -15
- package/dist/effect-QlVUlMFu-QNLZLGWO.js.map +0 -1
- package/dist/effect-QlVUlMFu-XUD6EH23.cjs +0 -17
- package/dist/effect-QlVUlMFu-XUD6EH23.cjs.map +0 -1
- package/dist/esm-DFCHSIJZ.cjs +0 -1589
- package/dist/esm-DFCHSIJZ.cjs.map +0 -1
- package/dist/esm-PXGQ5WB4.js +0 -1542
- package/dist/esm-PXGQ5WB4.js.map +0 -1
- package/dist/services/index.cjs.map +0 -1
- package/dist/services/index.js.map +0 -1
- package/dist/sury-CWZTCd75-3KQQJ22C.cjs +0 -17
- package/dist/sury-CWZTCd75-3KQQJ22C.cjs.map +0 -1
- package/dist/sury-CWZTCd75-DZQHKAZF.js +0 -15
- package/dist/sury-CWZTCd75-DZQHKAZF.js.map +0 -1
- package/dist/typebox-Dei93FPO-GOYJ5OUT.js +0 -8
- package/dist/typebox-Dei93FPO-GOYJ5OUT.js.map +0 -1
- package/dist/typebox-Dei93FPO-M7J7E57W.cjs +0 -10
- package/dist/typebox-Dei93FPO-M7J7E57W.cjs.map +0 -1
- package/dist/valibot--1zFm7rT-NVM3G3TI.cjs +0 -17
- package/dist/valibot--1zFm7rT-NVM3G3TI.cjs.map +0 -1
- package/dist/valibot--1zFm7rT-ZVGQI7WV.js +0 -15
- package/dist/valibot--1zFm7rT-ZVGQI7WV.js.map +0 -1
- package/dist/valibot-D_HTw1Gn-UCPEGDL7.cjs +0 -45
- package/dist/valibot-D_HTw1Gn-UCPEGDL7.cjs.map +0 -1
- package/dist/valibot-D_HTw1Gn-XPR4F6VS.js +0 -43
- package/dist/valibot-D_HTw1Gn-XPR4F6VS.js.map +0 -1
- package/dist/zod-Bwrt9trS-GN7ZXBMN.js +0 -29
- package/dist/zod-Bwrt9trS-GN7ZXBMN.js.map +0 -1
- package/dist/zod-Bwrt9trS-OVKARV6W.cjs +0 -31
- package/dist/zod-Bwrt9trS-OVKARV6W.cjs.map +0 -1
- package/dist/zod-DSgpEGAE-E7YZZ7VC.js +0 -37
- package/dist/zod-DSgpEGAE-E7YZZ7VC.js.map +0 -1
- package/dist/zod-DSgpEGAE-UNQNGL2W.cjs +0 -39
- package/dist/zod-DSgpEGAE-UNQNGL2W.cjs.map +0 -1
|
@@ -0,0 +1,1308 @@
|
|
|
1
|
+
import { a as getPackageName, c as isBuiltinModule, f as rollupSafeName, i as getNodeResolveOptions, l as isDependencyPartOfPackage, p as slash, r as getCompiledDepCachePath, s as isBareModuleSpecifier, u as isExternalProtocolImport } from "./utils-FVOUvj-I.js";
|
|
2
|
+
import "./services-CLi56qqe.js";
|
|
3
|
+
import { a as tsConfigPaths, c as protocolExternalResolver, d as getPackageRootPath, f as esmShim, i as mastraToolsAliasPlugin, o as subpathExternalsResolver, p as esbuild, r as mastraInternalAliasPlugin, s as removeDeployer, u as getPackageMetadata } from "./bundler-D86rFu2J.js";
|
|
4
|
+
import { spawn } from "child_process";
|
|
5
|
+
import { existsSync } from "fs";
|
|
6
|
+
import { readFile, writeFile } from "fs/promises";
|
|
7
|
+
import * as path$1 from "path";
|
|
8
|
+
import { basename, dirname, isAbsolute, join, relative } from "path";
|
|
9
|
+
import { ErrorCategory, ErrorDomain, MastraBaseError, MastraError } from "@mastra/core/error";
|
|
10
|
+
import virtual from "@rollup/plugin-virtual";
|
|
11
|
+
import * as pkg from "empathic/package";
|
|
12
|
+
import { transformAsync, transformSync, types } from "@babel/core";
|
|
13
|
+
import "@sindresorhus/slugify";
|
|
14
|
+
import { createWorkspacesCache, findWorkspaces, findWorkspacesRoot } from "find-workspaces";
|
|
15
|
+
import "fs-extra";
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
17
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
18
|
+
import json from "@rollup/plugin-json";
|
|
19
|
+
import { rollup } from "rollup";
|
|
20
|
+
import { optimizeLodashImports } from "@optimize-lodash/rollup-plugin";
|
|
21
|
+
import nodeResolve from "@rollup/plugin-node-resolve";
|
|
22
|
+
import { getPackageInfo } from "local-pkg";
|
|
23
|
+
import { basename as basename$1 } from "path/posix";
|
|
24
|
+
import * as resolve from "resolve.exports";
|
|
25
|
+
//#region \0rolldown/runtime.js
|
|
26
|
+
var __create = Object.create;
|
|
27
|
+
var __defProp = Object.defineProperty;
|
|
28
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
29
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
30
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
31
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
32
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
33
|
+
var __copyProps = (to, from, except, desc) => {
|
|
34
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
35
|
+
key = keys[i];
|
|
36
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
37
|
+
get: ((k) => from[k]).bind(null, key),
|
|
38
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return to;
|
|
42
|
+
};
|
|
43
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
44
|
+
value: mod,
|
|
45
|
+
enumerable: true
|
|
46
|
+
}) : target, mod));
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/bundler/workspaceDependencies.ts
|
|
49
|
+
var import_stack_trace_parser_cjs = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
var UNKNOWN_FUNCTION = "<unknown>";
|
|
52
|
+
/**
|
|
53
|
+
* This parses the different stack traces and puts them into one format
|
|
54
|
+
* This borrows heavily from TraceKit (https://github.com/csnover/TraceKit)
|
|
55
|
+
*/
|
|
56
|
+
function parse(stackString) {
|
|
57
|
+
return stackString.split("\n").reduce(function(stack, line) {
|
|
58
|
+
var parseResult = parseChrome(line) || parseWinjs(line) || parseGecko(line) || parseNode(line) || parseJSC(line);
|
|
59
|
+
if (parseResult) stack.push(parseResult);
|
|
60
|
+
return stack;
|
|
61
|
+
}, []);
|
|
62
|
+
}
|
|
63
|
+
var chromeRe = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|rsc|<anonymous>|\/|[a-z]:\\|\\\\).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
|
|
64
|
+
var chromeEvalRe = /\((\S*)(?::(\d+))(?::(\d+))\)/;
|
|
65
|
+
function parseChrome(line) {
|
|
66
|
+
var parts = chromeRe.exec(line);
|
|
67
|
+
if (!parts) return null;
|
|
68
|
+
var isNative = parts[2] && parts[2].indexOf("native") === 0;
|
|
69
|
+
var isEval = parts[2] && parts[2].indexOf("eval") === 0;
|
|
70
|
+
var submatch = chromeEvalRe.exec(parts[2]);
|
|
71
|
+
if (isEval && submatch != null) {
|
|
72
|
+
parts[2] = submatch[1];
|
|
73
|
+
parts[3] = submatch[2];
|
|
74
|
+
parts[4] = submatch[3];
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
file: !isNative ? parts[2] : null,
|
|
78
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
79
|
+
arguments: isNative ? [parts[2]] : [],
|
|
80
|
+
lineNumber: parts[3] ? +parts[3] : null,
|
|
81
|
+
column: parts[4] ? +parts[4] : null
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
var winjsRe = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|rsc|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
85
|
+
function parseWinjs(line) {
|
|
86
|
+
var parts = winjsRe.exec(line);
|
|
87
|
+
if (!parts) return null;
|
|
88
|
+
return {
|
|
89
|
+
file: parts[2],
|
|
90
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
91
|
+
arguments: [],
|
|
92
|
+
lineNumber: +parts[3],
|
|
93
|
+
column: parts[4] ? +parts[4] : null
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
var geckoRe = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|rsc|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i;
|
|
97
|
+
var geckoEvalRe = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
|
|
98
|
+
function parseGecko(line) {
|
|
99
|
+
var parts = geckoRe.exec(line);
|
|
100
|
+
if (!parts) return null;
|
|
101
|
+
var isEval = parts[3] && parts[3].indexOf(" > eval") > -1;
|
|
102
|
+
var submatch = geckoEvalRe.exec(parts[3]);
|
|
103
|
+
if (isEval && submatch != null) {
|
|
104
|
+
parts[3] = submatch[1];
|
|
105
|
+
parts[4] = submatch[2];
|
|
106
|
+
parts[5] = null;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
file: parts[3],
|
|
110
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
111
|
+
arguments: parts[2] ? parts[2].split(",") : [],
|
|
112
|
+
lineNumber: parts[4] ? +parts[4] : null,
|
|
113
|
+
column: parts[5] ? +parts[5] : null
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
var javaScriptCoreRe = /^\s*(?:([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$/i;
|
|
117
|
+
function parseJSC(line) {
|
|
118
|
+
var parts = javaScriptCoreRe.exec(line);
|
|
119
|
+
if (!parts) return null;
|
|
120
|
+
return {
|
|
121
|
+
file: parts[3],
|
|
122
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
123
|
+
arguments: [],
|
|
124
|
+
lineNumber: +parts[4],
|
|
125
|
+
column: parts[5] ? +parts[5] : null
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
var nodeRe = /^\s*at (?:((?:\[object object\])?[^\\/]+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
129
|
+
function parseNode(line) {
|
|
130
|
+
var parts = nodeRe.exec(line);
|
|
131
|
+
if (!parts) return null;
|
|
132
|
+
return {
|
|
133
|
+
file: parts[2],
|
|
134
|
+
methodName: parts[1] || UNKNOWN_FUNCTION,
|
|
135
|
+
arguments: [],
|
|
136
|
+
lineNumber: +parts[3],
|
|
137
|
+
column: parts[4] ? +parts[4] : null
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
exports.parse = parse;
|
|
141
|
+
})))(), 1);
|
|
142
|
+
/**
|
|
143
|
+
* Create a shared cache for find-workspaces
|
|
144
|
+
*/
|
|
145
|
+
const workspacesCache = createWorkspacesCache();
|
|
146
|
+
/**
|
|
147
|
+
* A utility function around find-workspaces to get information about:
|
|
148
|
+
* - Which workspace packages are available in the project
|
|
149
|
+
* - What is the workspace root location
|
|
150
|
+
* - Is the current package a workspace package
|
|
151
|
+
*
|
|
152
|
+
* Because `findWorkspacesRoot` only traverses up until it finds workspace information, but doesn't check if the current package is even part of the workspace. We rather want to return `null` for these cases because in other code paths we use `workspaceRoot || projectRoot` to determine the root of the project.
|
|
153
|
+
*
|
|
154
|
+
* @params dir - The directory to start searching from (default: `process.cwd()`)
|
|
155
|
+
* @params location - The location of the current package (usually the directory containing the package.json)
|
|
156
|
+
*/
|
|
157
|
+
async function getWorkspaceInformation({ dir = process.cwd(), mastraEntryFile }) {
|
|
158
|
+
const closestPkgJson = pkg.up({ cwd: dirname(mastraEntryFile) });
|
|
159
|
+
const location = closestPkgJson ? dirname(slash(closestPkgJson)) : slash(process.cwd());
|
|
160
|
+
const workspaces = await findWorkspaces(dir, { cache: workspacesCache });
|
|
161
|
+
const _workspaceMap = new Map(workspaces?.map((workspace) => [workspace.package.name, {
|
|
162
|
+
location: workspace.location,
|
|
163
|
+
dependencies: workspace.package.dependencies,
|
|
164
|
+
version: workspace.package.version
|
|
165
|
+
}]) ?? []);
|
|
166
|
+
const isWorkspacePackage = (workspaces ?? []).some((ws) => ws.location === location);
|
|
167
|
+
const workspaceRoot = isWorkspacePackage ? findWorkspacesRoot(dir, { cache: workspacesCache })?.location : void 0;
|
|
168
|
+
return {
|
|
169
|
+
workspaceMap: isWorkspacePackage ? _workspaceMap : /* @__PURE__ */ new Map(),
|
|
170
|
+
workspaceRoot,
|
|
171
|
+
isWorkspacePackage
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/validator/validate.ts
|
|
176
|
+
var ValidationError = class extends Error {
|
|
177
|
+
type;
|
|
178
|
+
stack;
|
|
179
|
+
constructor(args) {
|
|
180
|
+
super(args.message);
|
|
181
|
+
this.type = args.type;
|
|
182
|
+
this.stack = args.stack;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Promisified version of Node.js spawn function
|
|
187
|
+
*
|
|
188
|
+
* @param command - The command to run
|
|
189
|
+
* @param args - List of string arguments
|
|
190
|
+
* @param options - Spawn options
|
|
191
|
+
* @returns Promise that resolves with the exit code when the process completes
|
|
192
|
+
*/
|
|
193
|
+
function spawn$1(command, args = [], options = {}) {
|
|
194
|
+
return new Promise((resolve, reject) => {
|
|
195
|
+
let validationError = null;
|
|
196
|
+
const childProcess = spawn(command, args, {
|
|
197
|
+
stdio: [
|
|
198
|
+
"ignore",
|
|
199
|
+
"ignore",
|
|
200
|
+
"pipe"
|
|
201
|
+
],
|
|
202
|
+
...options
|
|
203
|
+
});
|
|
204
|
+
childProcess.on("error", (error) => {
|
|
205
|
+
reject(error);
|
|
206
|
+
});
|
|
207
|
+
let stderr = "";
|
|
208
|
+
childProcess.stderr?.on("data", (message) => {
|
|
209
|
+
try {
|
|
210
|
+
validationError = JSON.parse(message.toString());
|
|
211
|
+
} catch {
|
|
212
|
+
stderr += message;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
childProcess.on("close", (code) => {
|
|
216
|
+
if (code === 0) resolve();
|
|
217
|
+
else if (validationError) reject(new ValidationError(validationError));
|
|
218
|
+
else reject(new Error(stderr));
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
function validate(file, { injectESMShim = false, moduleResolveMapLocation, stubbedExternals = [] }) {
|
|
223
|
+
let prefixCode = "";
|
|
224
|
+
if (injectESMShim) prefixCode = `import { fileURLToPath } from 'url';
|
|
225
|
+
import { dirname } from 'path';
|
|
226
|
+
|
|
227
|
+
globalThis.__filename = fileURLToPath(import.meta.url);
|
|
228
|
+
globalThis.__dirname = dirname(__filename);
|
|
229
|
+
`;
|
|
230
|
+
function errorHandler(err) {
|
|
231
|
+
console.error(JSON.stringify({
|
|
232
|
+
type: err.name,
|
|
233
|
+
message: err.message,
|
|
234
|
+
stack: err.stack
|
|
235
|
+
}));
|
|
236
|
+
process.exit(1);
|
|
237
|
+
}
|
|
238
|
+
return spawn$1(process.execPath, [
|
|
239
|
+
"--import",
|
|
240
|
+
import.meta.resolve("@mastra/deployer/loader"),
|
|
241
|
+
"--input-type=module",
|
|
242
|
+
"--enable-source-maps",
|
|
243
|
+
"-e",
|
|
244
|
+
`${prefixCode};import('${pathToFileURL(file).href}').catch(err => {
|
|
245
|
+
${errorHandler.toString()}
|
|
246
|
+
errorHandler(err);
|
|
247
|
+
})`.replaceAll(/\n/g, "")
|
|
248
|
+
], {
|
|
249
|
+
env: {
|
|
250
|
+
...process.env,
|
|
251
|
+
MODULE_MAP: `${moduleResolveMapLocation}`,
|
|
252
|
+
STUBBED_EXTERNALS: JSON.stringify(stubbedExternals)
|
|
253
|
+
},
|
|
254
|
+
cwd: dirname(file)
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
//#region src/build/analyze/constants.ts
|
|
259
|
+
const DEPS_TO_IGNORE = [
|
|
260
|
+
"#tools",
|
|
261
|
+
"execa",
|
|
262
|
+
"effect",
|
|
263
|
+
"sury",
|
|
264
|
+
"@ast-grep/napi",
|
|
265
|
+
"@hono/node-ws"
|
|
266
|
+
];
|
|
267
|
+
const GLOBAL_EXTERNALS = [
|
|
268
|
+
"pino",
|
|
269
|
+
"pino-pretty",
|
|
270
|
+
"@libsql/client",
|
|
271
|
+
"pg",
|
|
272
|
+
"libsql",
|
|
273
|
+
"#tools",
|
|
274
|
+
"typescript",
|
|
275
|
+
"undici",
|
|
276
|
+
"readable-stream",
|
|
277
|
+
"bufferutil",
|
|
278
|
+
"utf-8-validate",
|
|
279
|
+
"execa",
|
|
280
|
+
"@ast-grep/napi",
|
|
281
|
+
"@hono/node-ws"
|
|
282
|
+
];
|
|
283
|
+
const DEPRECATED_EXTERNALS = [
|
|
284
|
+
"fastembed",
|
|
285
|
+
"nodemailer",
|
|
286
|
+
"jsdom",
|
|
287
|
+
"sqlite3"
|
|
288
|
+
];
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/build/analyze/analyzeEntry.ts
|
|
291
|
+
/**
|
|
292
|
+
* Configures and returns the Rollup plugins needed for analyzing entry files.
|
|
293
|
+
* Sets up module resolution, transpilation, and custom alias handling for Mastra-specific imports.
|
|
294
|
+
*/
|
|
295
|
+
function getInputPlugins$1({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
|
|
296
|
+
let virtualPlugin = null;
|
|
297
|
+
if (isVirtualFile) {
|
|
298
|
+
virtualPlugin = virtual({ "#entry": entry });
|
|
299
|
+
entry = "#entry";
|
|
300
|
+
}
|
|
301
|
+
const plugins = [];
|
|
302
|
+
if (virtualPlugin) plugins.push(virtualPlugin);
|
|
303
|
+
plugins.push(...[
|
|
304
|
+
protocolExternalResolver(),
|
|
305
|
+
mastraInternalAliasPlugin(mastraEntry),
|
|
306
|
+
mastraToolsAliasPlugin(),
|
|
307
|
+
tsConfigPaths(),
|
|
308
|
+
json(),
|
|
309
|
+
esbuild(),
|
|
310
|
+
commonjs({
|
|
311
|
+
strictRequires: "debug",
|
|
312
|
+
ignoreTryCatch: false,
|
|
313
|
+
transformMixedEsModules: true,
|
|
314
|
+
extensions: [".js", ".ts"]
|
|
315
|
+
}),
|
|
316
|
+
removeDeployer(mastraEntry, { sourcemap: sourcemapEnabled }),
|
|
317
|
+
esbuild()
|
|
318
|
+
]);
|
|
319
|
+
return plugins;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Extracts and categorizes dependencies from Rollup output to determine which ones need optimization.
|
|
323
|
+
* Analyzes both static imports and dynamic imports while filtering out Node.js built-ins and ignored dependencies.
|
|
324
|
+
* Identifies workspace packages and resolves package root paths for proper bundling optimization.
|
|
325
|
+
*/
|
|
326
|
+
async function captureDependenciesToOptimize(output, workspaceMap, projectRoot, { logger, shouldCheckTransitiveDependencies }) {
|
|
327
|
+
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
328
|
+
if (!output.facadeModuleId) throw new Error("Something went wrong, we could not find the package name of the entry file. Please open an issue.");
|
|
329
|
+
let entryRootPath = projectRoot;
|
|
330
|
+
if (!output.facadeModuleId.startsWith("\0virtual:")) entryRootPath = await getPackageRootPath(output.facadeModuleId) || projectRoot;
|
|
331
|
+
for (const [dependency, bindings] of Object.entries(output.importedBindings)) {
|
|
332
|
+
if (!isBareModuleSpecifier(dependency)) continue;
|
|
333
|
+
const pkgName = getPackageName(dependency);
|
|
334
|
+
let rootPath = null;
|
|
335
|
+
let isWorkspace = false;
|
|
336
|
+
let version;
|
|
337
|
+
let packageSpec;
|
|
338
|
+
if (pkgName) {
|
|
339
|
+
const metadata = await getPackageMetadata(dependency, entryRootPath);
|
|
340
|
+
rootPath = metadata.rootPath;
|
|
341
|
+
version = metadata.version;
|
|
342
|
+
packageSpec = metadata.packageSpec;
|
|
343
|
+
isWorkspace = workspaceMap.has(pkgName);
|
|
344
|
+
}
|
|
345
|
+
const normalizedRootPath = rootPath ? slash(rootPath) : null;
|
|
346
|
+
depsToOptimize.set(dependency, {
|
|
347
|
+
exports: bindings,
|
|
348
|
+
rootPath: normalizedRootPath,
|
|
349
|
+
isWorkspace,
|
|
350
|
+
version,
|
|
351
|
+
packageSpec
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
const processedWorkspaceDeps = /* @__PURE__ */ new Set();
|
|
355
|
+
/**
|
|
356
|
+
* Recursively discovers transitive workspace dependencies from package manifests.
|
|
357
|
+
*/
|
|
358
|
+
function checkTransitiveDependencies(maxDepth = 10, currentDepth = 0) {
|
|
359
|
+
if (currentDepth >= maxDepth) {
|
|
360
|
+
logger.warn("Maximum dependency depth reached while checking transitive dependencies.");
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const depsSnapshot = new Map(depsToOptimize);
|
|
364
|
+
let hasAddedDeps = false;
|
|
365
|
+
for (const [dep, meta] of depsSnapshot) {
|
|
366
|
+
const pkgName = getPackageName(dep);
|
|
367
|
+
if (!pkgName || !meta.isWorkspace || processedWorkspaceDeps.has(pkgName)) continue;
|
|
368
|
+
processedWorkspaceDeps.add(pkgName);
|
|
369
|
+
const workspaceInfo = workspaceMap.get(pkgName);
|
|
370
|
+
if (!workspaceInfo?.dependencies) continue;
|
|
371
|
+
for (const [innerDep, _innerDepVersion] of Object.entries(workspaceInfo.dependencies)) {
|
|
372
|
+
const innerWorkspaceInfo = workspaceMap.get(innerDep);
|
|
373
|
+
if (!innerWorkspaceInfo) continue;
|
|
374
|
+
const existingMeta = depsToOptimize.get(innerDep);
|
|
375
|
+
if (existingMeta) {
|
|
376
|
+
depsToOptimize.set(innerDep, {
|
|
377
|
+
...existingMeta,
|
|
378
|
+
exports: existingMeta.exports.includes("*") ? existingMeta.exports : [...existingMeta.exports, "*"]
|
|
379
|
+
});
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
depsToOptimize.set(innerDep, {
|
|
383
|
+
exports: ["*"],
|
|
384
|
+
rootPath: slash(innerWorkspaceInfo.location),
|
|
385
|
+
isWorkspace: true,
|
|
386
|
+
version: innerWorkspaceInfo.version
|
|
387
|
+
});
|
|
388
|
+
hasAddedDeps = true;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (hasAddedDeps) checkTransitiveDependencies(maxDepth, currentDepth + 1);
|
|
392
|
+
}
|
|
393
|
+
if (shouldCheckTransitiveDependencies) checkTransitiveDependencies();
|
|
394
|
+
const dynamicImports = output.dynamicImports.filter((d) => !DEPS_TO_IGNORE.includes(d));
|
|
395
|
+
if (dynamicImports.length) {
|
|
396
|
+
for (const dynamicImport of dynamicImports) if (!depsToOptimize.has(dynamicImport) && isBareModuleSpecifier(dynamicImport)) {
|
|
397
|
+
const pkgName = getPackageName(dynamicImport);
|
|
398
|
+
let version;
|
|
399
|
+
let packageSpec;
|
|
400
|
+
let rootPath = null;
|
|
401
|
+
if (pkgName) {
|
|
402
|
+
const metadata = await getPackageMetadata(dynamicImport, entryRootPath);
|
|
403
|
+
rootPath = metadata.rootPath;
|
|
404
|
+
version = metadata.version;
|
|
405
|
+
packageSpec = metadata.packageSpec;
|
|
406
|
+
}
|
|
407
|
+
depsToOptimize.set(dynamicImport, {
|
|
408
|
+
exports: ["*"],
|
|
409
|
+
rootPath: rootPath ? slash(rootPath) : null,
|
|
410
|
+
isWorkspace: false,
|
|
411
|
+
version,
|
|
412
|
+
packageSpec
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return depsToOptimize;
|
|
417
|
+
}
|
|
418
|
+
async function analyzeEntry({ entry, isVirtualFile }, mastraEntry, { logger, sourcemapEnabled, workspaceMap, projectRoot, shouldCheckTransitiveDependencies = false, analyzeCache }) {
|
|
419
|
+
const cacheKey = isVirtualFile ? void 0 : slash(entry);
|
|
420
|
+
if (cacheKey && analyzeCache?.has(cacheKey)) return analyzeCache.get(cacheKey);
|
|
421
|
+
const optimizerBundler = await rollup({
|
|
422
|
+
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
423
|
+
input: isVirtualFile ? "#entry" : entry,
|
|
424
|
+
treeshake: false,
|
|
425
|
+
preserveSymlinks: true,
|
|
426
|
+
plugins: getInputPlugins$1({
|
|
427
|
+
entry,
|
|
428
|
+
isVirtualFile
|
|
429
|
+
}, mastraEntry, { sourcemapEnabled }),
|
|
430
|
+
external: DEPS_TO_IGNORE
|
|
431
|
+
});
|
|
432
|
+
const { output } = await optimizerBundler.generate({
|
|
433
|
+
format: "esm",
|
|
434
|
+
inlineDynamicImports: true
|
|
435
|
+
});
|
|
436
|
+
await optimizerBundler.close();
|
|
437
|
+
const result = {
|
|
438
|
+
dependencies: await captureDependenciesToOptimize(output[0], workspaceMap, projectRoot, {
|
|
439
|
+
logger,
|
|
440
|
+
shouldCheckTransitiveDependencies
|
|
441
|
+
}),
|
|
442
|
+
output: {
|
|
443
|
+
code: output[0].code,
|
|
444
|
+
map: output[0].map
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
if (cacheKey && analyzeCache) analyzeCache.set(cacheKey, result);
|
|
448
|
+
return result;
|
|
449
|
+
}
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region src/build/plugins/hono-alias.ts
|
|
452
|
+
function aliasHono() {
|
|
453
|
+
return {
|
|
454
|
+
name: "hono-alias",
|
|
455
|
+
resolveId(id) {
|
|
456
|
+
if (!id.startsWith("@hono/") && !id.startsWith("hono/") && id !== "hono" && id !== "hono-openapi") return;
|
|
457
|
+
return fileURLToPath(import.meta.resolve(id));
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region src/build/plugins/module-resolve-map.ts
|
|
463
|
+
function moduleResolveMap(externals, projectRoot) {
|
|
464
|
+
const importMap = /* @__PURE__ */ new Map();
|
|
465
|
+
return {
|
|
466
|
+
name: "module-resolve-map",
|
|
467
|
+
moduleParsed(info) {
|
|
468
|
+
if (info.importedIds.length === 0 || !info.id) return;
|
|
469
|
+
for (const importedId of info.importedIds) for (const external of externals) if (isDependencyPartOfPackage(importedId, external)) importMap.set(external, info.id);
|
|
470
|
+
},
|
|
471
|
+
async generateBundle(options, bundle) {
|
|
472
|
+
const resolveMap = /* @__PURE__ */ new Map();
|
|
473
|
+
for (const [fileName, chunk] of Object.entries(bundle)) if (chunk.type === "chunk") {
|
|
474
|
+
for (const [external, resolvedFrom] of importMap) if (chunk.moduleIds.includes(resolvedFrom)) {
|
|
475
|
+
const fullPath = pathToFileURL(slash(join(projectRoot, fileName))).toString();
|
|
476
|
+
const innerMap = resolveMap.get(fullPath) || /* @__PURE__ */ new Map();
|
|
477
|
+
innerMap.set(external, pathToFileURL(slash(resolvedFrom)).toString());
|
|
478
|
+
resolveMap.set(fullPath, innerMap);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
const resolveMapJson = Object.fromEntries(Array.from(resolveMap.entries()).map(([key, value]) => [key, Object.fromEntries(value.entries())]));
|
|
482
|
+
this.emitFile({
|
|
483
|
+
type: "asset",
|
|
484
|
+
name: "module-resolve-map.json",
|
|
485
|
+
source: `${JSON.stringify(resolveMapJson, null, 2)}`
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
//#endregion
|
|
491
|
+
//#region src/build/plugins/node-gyp-detector.ts
|
|
492
|
+
function nodeGypDetector() {
|
|
493
|
+
const modulesToTrack = /* @__PURE__ */ new Set();
|
|
494
|
+
const modulesToTrackPackageInfo = /* @__PURE__ */ new Map();
|
|
495
|
+
return {
|
|
496
|
+
name: "node-gyp-build-detector",
|
|
497
|
+
moduleParsed(info) {
|
|
498
|
+
if (!info.meta?.commonjs?.requires?.length) return;
|
|
499
|
+
if (!info.meta.commonjs.requires.some((m) => m?.resolved?.id.endsWith("node-gyp-build/index.js"))) return;
|
|
500
|
+
modulesToTrack.add(info.id);
|
|
501
|
+
modulesToTrackPackageInfo.set(info.id, getPackageInfo(info.id));
|
|
502
|
+
},
|
|
503
|
+
async generateBundle(options, bundle) {
|
|
504
|
+
const binaryMapByChunk = /* @__PURE__ */ new Map();
|
|
505
|
+
for (const [fileName, chunk] of Object.entries(bundle)) if (chunk.type === "chunk") {
|
|
506
|
+
for (const moduleId of chunk.moduleIds) if (modulesToTrackPackageInfo.has(moduleId)) {
|
|
507
|
+
const pkgInfo = await modulesToTrackPackageInfo.get(moduleId);
|
|
508
|
+
if (!binaryMapByChunk.has(fileName)) binaryMapByChunk.set(fileName, /* @__PURE__ */ new Set());
|
|
509
|
+
if (pkgInfo?.packageJson?.name) binaryMapByChunk.get(fileName).add(pkgInfo.packageJson.name);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
const binaryMapJson = Object.fromEntries(Array.from(binaryMapByChunk.entries()).map(([key, value]) => [key, Array.from(value)]));
|
|
513
|
+
this.emitFile({
|
|
514
|
+
type: "asset",
|
|
515
|
+
name: "binary-map.json",
|
|
516
|
+
source: `${JSON.stringify(binaryMapJson, null, 2)}`
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/build/analyze/bundleExternals.ts
|
|
523
|
+
function prepareEntryFileName(name, rootDir) {
|
|
524
|
+
return rollupSafeName(name, rootDir);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Creates virtual dependency modules for optimized bundling by generating virtual entry points for each dependency with their specific exports and handling workspace package path resolution.
|
|
528
|
+
*/
|
|
529
|
+
function createVirtualDependencies(depsToOptimize, { projectRoot, workspaceRoot, outputDir, bundlerOptions }) {
|
|
530
|
+
const { isDev = false, externalsPreset = false } = bundlerOptions || {};
|
|
531
|
+
const fileNameToDependencyMap = /* @__PURE__ */ new Map();
|
|
532
|
+
const optimizedDependencyEntries = /* @__PURE__ */ new Map();
|
|
533
|
+
const rootDir = workspaceRoot || projectRoot;
|
|
534
|
+
for (const [dep, { exports }] of depsToOptimize.entries()) {
|
|
535
|
+
const fileName = dep.replaceAll("/", "__");
|
|
536
|
+
const virtualFile = [];
|
|
537
|
+
const exportStringBuilder = [];
|
|
538
|
+
for (const local of exports) if (local === "*") {
|
|
539
|
+
virtualFile.push(`export * from '${dep}';`);
|
|
540
|
+
continue;
|
|
541
|
+
} else if (local === "default") exportStringBuilder.push("default");
|
|
542
|
+
else exportStringBuilder.push(local);
|
|
543
|
+
const chunks = [];
|
|
544
|
+
if (exportStringBuilder.length) chunks.push(`{ ${exportStringBuilder.join(", ")} }`);
|
|
545
|
+
if (chunks.length) virtualFile.push(`export ${chunks.join(", ")} from '${dep}';`);
|
|
546
|
+
let entryName = prepareEntryFileName(path$1.join(outputDir, fileName), rootDir);
|
|
547
|
+
fileNameToDependencyMap.set(entryName, dep);
|
|
548
|
+
optimizedDependencyEntries.set(dep, {
|
|
549
|
+
name: entryName,
|
|
550
|
+
virtual: virtualFile.join("\n")
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
if (isDev || externalsPreset) for (const [dep, { isWorkspace, rootPath }] of depsToOptimize.entries()) {
|
|
554
|
+
if (!isWorkspace || !rootPath || !workspaceRoot) continue;
|
|
555
|
+
const currentDepPath = optimizedDependencyEntries.get(dep);
|
|
556
|
+
if (!currentDepPath) continue;
|
|
557
|
+
const entryName = prepareEntryFileName(getCompiledDepCachePath(rootPath, basename$1(currentDepPath.name)), rootDir);
|
|
558
|
+
fileNameToDependencyMap.set(entryName, dep);
|
|
559
|
+
optimizedDependencyEntries.set(dep, {
|
|
560
|
+
...currentDepPath,
|
|
561
|
+
name: entryName
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
optimizedDependencyEntries,
|
|
566
|
+
fileNameToDependencyMap
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Configures and returns Rollup plugins for bundling external dependencies.
|
|
571
|
+
* Sets up virtual modules, TypeScript compilation, CommonJS transformation, and workspace resolution.
|
|
572
|
+
*/
|
|
573
|
+
async function getInputPlugins(virtualDependencies, { transpilePackages, workspaceMap, bundlerOptions, rootDir, externals, platform }) {
|
|
574
|
+
const transpilePackagesMap = /* @__PURE__ */ new Map();
|
|
575
|
+
for (const pkg of transpilePackages) {
|
|
576
|
+
const dir = await getPackageRootPath(pkg);
|
|
577
|
+
if (dir) transpilePackagesMap.set(pkg, slash(dir));
|
|
578
|
+
else transpilePackagesMap.set(pkg, workspaceMap.get(pkg)?.location ?? pkg);
|
|
579
|
+
}
|
|
580
|
+
return [
|
|
581
|
+
virtual(Array.from(virtualDependencies.entries()).reduce((acc, [dep, virtualDep]) => {
|
|
582
|
+
acc[`#virtual-${dep}`] = virtualDep.virtual;
|
|
583
|
+
return acc;
|
|
584
|
+
}, {})),
|
|
585
|
+
tsConfigPaths(),
|
|
586
|
+
protocolExternalResolver(),
|
|
587
|
+
subpathExternalsResolver(externals),
|
|
588
|
+
transpilePackagesMap.size ? esbuild({
|
|
589
|
+
format: "esm",
|
|
590
|
+
include: [...[...transpilePackagesMap.values()].map((p) => {
|
|
591
|
+
if (path$1.isAbsolute(p)) return new RegExp(`^${p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/(?!.*node_modules).*$`);
|
|
592
|
+
else return new RegExp(`\/${p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/(?!.*node_modules).*$`);
|
|
593
|
+
}), ...[...transpilePackagesMap.keys()].map((pkgName) => {
|
|
594
|
+
const escapedPkgName = pkgName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
595
|
+
return new RegExp(`/node_modules/${escapedPkgName}/(?!.*node_modules).*$`);
|
|
596
|
+
})],
|
|
597
|
+
exclude: []
|
|
598
|
+
}) : null,
|
|
599
|
+
bundlerOptions.noBundling ? {
|
|
600
|
+
name: "alias-optimized-deps",
|
|
601
|
+
async resolveId(id, importer, options) {
|
|
602
|
+
if (!virtualDependencies.has(id)) return null;
|
|
603
|
+
const info = virtualDependencies.get(id);
|
|
604
|
+
const packageRootPath = path$1.join(rootDir, path$1.dirname(path$1.dirname(path$1.dirname(info.name))));
|
|
605
|
+
const pkgJsonBuffer = await readFile(path$1.join(packageRootPath, "package.json"), "utf-8");
|
|
606
|
+
const pkgJson = JSON.parse(pkgJsonBuffer);
|
|
607
|
+
if (!pkgJson) return null;
|
|
608
|
+
const pkgName = pkgJson.name || "";
|
|
609
|
+
let resolvedPath = resolve.exports(pkgJson, id.replace(pkgName, "."))?.[0];
|
|
610
|
+
if (!resolvedPath) resolvedPath = pkgJson.main ?? "index.js";
|
|
611
|
+
return await this.resolve(path$1.posix.join(packageRootPath, resolvedPath), importer, options);
|
|
612
|
+
}
|
|
613
|
+
} : null,
|
|
614
|
+
optimizeLodashImports({ include: "**/*.{js,ts,mjs,cjs}" }),
|
|
615
|
+
commonjs({
|
|
616
|
+
strictRequires: "strict",
|
|
617
|
+
transformMixedEsModules: true,
|
|
618
|
+
ignoreTryCatch: false
|
|
619
|
+
}),
|
|
620
|
+
bundlerOptions.noBundling ? null : nodeResolve(getNodeResolveOptions(platform)),
|
|
621
|
+
bundlerOptions.noBundling ? esmShim() : null,
|
|
622
|
+
aliasHono(),
|
|
623
|
+
json(),
|
|
624
|
+
nodeGypDetector(),
|
|
625
|
+
moduleResolveMap(externals, rootDir),
|
|
626
|
+
{
|
|
627
|
+
name: "not-found-resolver",
|
|
628
|
+
resolveId: {
|
|
629
|
+
order: "post",
|
|
630
|
+
async handler(id, importer) {
|
|
631
|
+
if (!importer) return null;
|
|
632
|
+
if (!id.endsWith(".node")) return null;
|
|
633
|
+
const packageName = (await getPackageInfo(importer))?.packageJson?.name || id;
|
|
634
|
+
throw new MastraBaseError({
|
|
635
|
+
id: "DEPLOYER_BUNDLE_EXTERNALS_MISSING_NATIVE_BUILD",
|
|
636
|
+
domain: ErrorDomain.DEPLOYER,
|
|
637
|
+
category: ErrorCategory.USER,
|
|
638
|
+
details: {
|
|
639
|
+
importFile: importer,
|
|
640
|
+
packageName
|
|
641
|
+
},
|
|
642
|
+
text: `We found a possible binary dependency in your bundle. ${id} was not found when imported at ${importer}.
|
|
643
|
+
|
|
644
|
+
Please consider adding \`${packageName}\` to your externals, or updating this import to not end with ".node".
|
|
645
|
+
|
|
646
|
+
export const mastra = new Mastra({
|
|
647
|
+
bundler: {
|
|
648
|
+
externals: ["${packageName}"],
|
|
649
|
+
}
|
|
650
|
+
})`
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
].filter(Boolean);
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Executes the Rollup build process for virtual dependencies using configured plugins.
|
|
659
|
+
* Bundles all virtual dependency modules into optimized ESM files with proper external handling.
|
|
660
|
+
*/
|
|
661
|
+
async function buildExternalDependencies(virtualDependencies, { externals, packagesToTranspile, workspaceMap, rootDir, outputDir, bundlerOptions, platform }) {
|
|
662
|
+
/**
|
|
663
|
+
* If there are no virtual dependencies to bundle, return an empty array to avoid Rollup errors.
|
|
664
|
+
*/
|
|
665
|
+
if (virtualDependencies.size === 0) return [];
|
|
666
|
+
const noBundling = bundlerOptions.isDev || bundlerOptions.externalsPreset;
|
|
667
|
+
const plugins = await getInputPlugins(virtualDependencies, {
|
|
668
|
+
transpilePackages: packagesToTranspile,
|
|
669
|
+
workspaceMap,
|
|
670
|
+
bundlerOptions: { noBundling },
|
|
671
|
+
rootDir,
|
|
672
|
+
externals,
|
|
673
|
+
platform
|
|
674
|
+
});
|
|
675
|
+
const bundler = await rollup({
|
|
676
|
+
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
677
|
+
input: Array.from(virtualDependencies.entries()).reduce((acc, [dep, virtualDep]) => {
|
|
678
|
+
acc[virtualDep.name] = `#virtual-${dep}`;
|
|
679
|
+
return acc;
|
|
680
|
+
}, {}),
|
|
681
|
+
external: externals,
|
|
682
|
+
treeshake: noBundling ? false : "safest",
|
|
683
|
+
plugins
|
|
684
|
+
});
|
|
685
|
+
const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
|
|
686
|
+
const { output } = await bundler.write({
|
|
687
|
+
format: "esm",
|
|
688
|
+
dir: rootDir,
|
|
689
|
+
entryFileNames: "[name].mjs",
|
|
690
|
+
sourcemap: true,
|
|
691
|
+
/**
|
|
692
|
+
* Rollup creates chunks for common dependencies, but these chunks are by default written to the root directory instead of respecting the entryFileNames structure.
|
|
693
|
+
* So we want to write them to the `.mastra/output` folder as well.
|
|
694
|
+
*/
|
|
695
|
+
chunkFileNames: (chunkInfo) => {
|
|
696
|
+
/**
|
|
697
|
+
* This whole bunch of logic directly below is for the edge case shown in the e2e-tests/monorepo with "tinyrainbow" package. It's used in multiple places in the package and as such Rollup creates a shared chunk for it. During 'mastra dev' / with externals: true, we don't want that chunk to show up in the '.mastra/output' folder (outputDirRelative) but inside <pkg>/node_modules/.cache instead.
|
|
698
|
+
* We only care about this for the "noBundling" case!
|
|
699
|
+
*/
|
|
700
|
+
if (noBundling) {
|
|
701
|
+
const importedFromPackages = /* @__PURE__ */ new Set();
|
|
702
|
+
for (const moduleId of chunkInfo.moduleIds) {
|
|
703
|
+
const normalized = slash(moduleId);
|
|
704
|
+
for (const [pkgName, pkgInfo] of workspaceMap.entries()) {
|
|
705
|
+
const location = slash(pkgInfo.location);
|
|
706
|
+
if (normalized.startsWith(location)) {
|
|
707
|
+
importedFromPackages.add(pkgName);
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
if (importedFromPackages.size > 1) throw new MastraBaseError({
|
|
713
|
+
id: "DEPLOYER_BUNDLE_EXTERNALS_SHARED_CHUNK",
|
|
714
|
+
domain: ErrorDomain.DEPLOYER,
|
|
715
|
+
category: ErrorCategory.USER,
|
|
716
|
+
details: {
|
|
717
|
+
chunkName: chunkInfo.name,
|
|
718
|
+
packages: JSON.stringify(Array.from(importedFromPackages))
|
|
719
|
+
},
|
|
720
|
+
text: `Please open an issue. We found a shared chunk "${chunkInfo.name}" used by multiple workspace packages: ${Array.from(importedFromPackages).join(", ")}.`
|
|
721
|
+
});
|
|
722
|
+
if (importedFromPackages.size === 1) {
|
|
723
|
+
const [pkgName] = importedFromPackages;
|
|
724
|
+
const workspaceLocation = workspaceMap.get(pkgName).location;
|
|
725
|
+
return prepareEntryFileName(getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return `${outputDirRelative}/[name].mjs`;
|
|
729
|
+
},
|
|
730
|
+
assetFileNames: `${outputDirRelative}/[name][extname]`,
|
|
731
|
+
hoistTransitiveImports: false
|
|
732
|
+
});
|
|
733
|
+
await bundler.close();
|
|
734
|
+
return output;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Recursively searches through Rollup output chunks to find which module imports a specific external dependency.
|
|
738
|
+
* Used to build the module resolution map for proper external dependency tracking.
|
|
739
|
+
*/
|
|
740
|
+
function findExternalImporter(module, external, allOutputs, visited = /* @__PURE__ */ new Set()) {
|
|
741
|
+
if (visited.has(module.fileName)) return null;
|
|
742
|
+
visited.add(module.fileName);
|
|
743
|
+
const capturedFiles = /* @__PURE__ */ new Set();
|
|
744
|
+
for (const id of [...module.imports, ...module.dynamicImports]) if (isDependencyPartOfPackage(id, external)) return module;
|
|
745
|
+
else if (id.endsWith(".mjs")) capturedFiles.add(id);
|
|
746
|
+
for (const file of capturedFiles) {
|
|
747
|
+
const nextModule = allOutputs.find((o) => o.fileName === file);
|
|
748
|
+
if (nextModule) {
|
|
749
|
+
const importer = findExternalImporter(nextModule, external, allOutputs, visited);
|
|
750
|
+
if (importer) return importer;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return null;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Bundles vendor dependencies identified in the analysis step.
|
|
757
|
+
* Creates virtual modules for each dependency and bundles them using rollup.
|
|
758
|
+
*
|
|
759
|
+
* @param depsToOptimize - Map of dependencies to optimize with their metadata (exported bindings, rootPath, isWorkspace)
|
|
760
|
+
* @param outputDir - Directory where bundled files will be written
|
|
761
|
+
* @param logger - Logger instance for debugging
|
|
762
|
+
* @returns Object containing bundle output and reference map for validation
|
|
763
|
+
*/
|
|
764
|
+
async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
765
|
+
const { workspaceRoot = null, workspaceMap = /* @__PURE__ */ new Map(), projectRoot = outputDir, bundlerOptions = {}, platform = "node" } = options;
|
|
766
|
+
const { externals: customExternals = [], transpilePackages = [], isDev = false } = bundlerOptions || {};
|
|
767
|
+
/**
|
|
768
|
+
* A user can set `externals: true` to indicate they want to externalize all dependencies. In this case, we set `externalsPreset` to true to skip bundling any externals.
|
|
769
|
+
*/
|
|
770
|
+
let externalsPreset = false;
|
|
771
|
+
if (customExternals === true) externalsPreset = true;
|
|
772
|
+
const externalsList = Array.isArray(customExternals) ? customExternals : [];
|
|
773
|
+
const allExternals = [
|
|
774
|
+
...GLOBAL_EXTERNALS,
|
|
775
|
+
...DEPRECATED_EXTERNALS,
|
|
776
|
+
...externalsList
|
|
777
|
+
];
|
|
778
|
+
const workspacePackagesNames = Array.from(workspaceMap.keys());
|
|
779
|
+
const packagesToTranspile = /* @__PURE__ */ new Set([...transpilePackages, ...workspacePackagesNames]);
|
|
780
|
+
/**
|
|
781
|
+
* When externals: true, we need to extract non-workspace deps from depsToOptimize
|
|
782
|
+
* and add them directly to usedExternals instead of bundling them.
|
|
783
|
+
*/
|
|
784
|
+
const extractedExternals = /* @__PURE__ */ new Map();
|
|
785
|
+
if (externalsPreset) {
|
|
786
|
+
for (const [dep, metadata] of depsToOptimize.entries()) if (!metadata.isWorkspace) {
|
|
787
|
+
extractedExternals.set(dep, metadata.rootPath ?? dep);
|
|
788
|
+
depsToOptimize.delete(dep);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
const { optimizedDependencyEntries, fileNameToDependencyMap } = createVirtualDependencies(depsToOptimize, {
|
|
792
|
+
workspaceRoot,
|
|
793
|
+
outputDir,
|
|
794
|
+
projectRoot,
|
|
795
|
+
bundlerOptions: {
|
|
796
|
+
isDev,
|
|
797
|
+
externalsPreset
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
const output = await buildExternalDependencies(optimizedDependencyEntries, {
|
|
801
|
+
externals: allExternals,
|
|
802
|
+
packagesToTranspile,
|
|
803
|
+
workspaceMap,
|
|
804
|
+
rootDir: workspaceRoot || projectRoot,
|
|
805
|
+
outputDir,
|
|
806
|
+
bundlerOptions: {
|
|
807
|
+
isDev,
|
|
808
|
+
externalsPreset
|
|
809
|
+
},
|
|
810
|
+
platform
|
|
811
|
+
});
|
|
812
|
+
const moduleResolveMap = /* @__PURE__ */ new Map();
|
|
813
|
+
const filteredChunks = output.filter((o) => o.type === "chunk");
|
|
814
|
+
for (const o of filteredChunks.filter((o) => o.isEntry || o.isDynamicEntry)) for (const external of allExternals) {
|
|
815
|
+
if (DEPS_TO_IGNORE.includes(external)) continue;
|
|
816
|
+
const importer = findExternalImporter(o, external, filteredChunks);
|
|
817
|
+
if (importer) {
|
|
818
|
+
const fullPath = path$1.join(workspaceRoot || projectRoot, importer.fileName);
|
|
819
|
+
let innerMap = moduleResolveMap.get(fullPath);
|
|
820
|
+
if (!innerMap) {
|
|
821
|
+
innerMap = /* @__PURE__ */ new Map();
|
|
822
|
+
moduleResolveMap.set(fullPath, innerMap);
|
|
823
|
+
}
|
|
824
|
+
if (importer.moduleIds.length) innerMap.set(external, importer.moduleIds[importer.moduleIds.length - 1]?.startsWith("\0virtual:#virtual") ? importer.moduleIds[importer.moduleIds.length - 2] : importer.moduleIds[importer.moduleIds.length - 1]);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Convert moduleResolveMap to a plain object with prototype-less objects
|
|
829
|
+
*/
|
|
830
|
+
const usedExternals = Object.create(null);
|
|
831
|
+
for (const [fullPath, innerMap] of moduleResolveMap) {
|
|
832
|
+
const innerObj = Object.create(null);
|
|
833
|
+
for (const [external, value] of innerMap) innerObj[external] = value;
|
|
834
|
+
usedExternals[fullPath] = innerObj;
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* When externals: true, add the extracted non-workspace deps to usedExternals
|
|
838
|
+
* using a synthetic entry path to track them.
|
|
839
|
+
*/
|
|
840
|
+
if (extractedExternals.size > 0) {
|
|
841
|
+
const syntheticPath = path$1.join(workspaceRoot || projectRoot, "__externals__");
|
|
842
|
+
const externalsObj = Object.create(null);
|
|
843
|
+
for (const [dep, rootPath] of extractedExternals) externalsObj[dep] = rootPath;
|
|
844
|
+
usedExternals[syntheticPath] = externalsObj;
|
|
845
|
+
}
|
|
846
|
+
return {
|
|
847
|
+
output,
|
|
848
|
+
fileNameToDependencyMap,
|
|
849
|
+
usedExternals
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
//#endregion
|
|
853
|
+
//#region src/build/babel/check-config-export.ts
|
|
854
|
+
function checkConfigExport(result) {
|
|
855
|
+
const mastraVars = /* @__PURE__ */ new Set();
|
|
856
|
+
return { visitor: {
|
|
857
|
+
NewExpression(path) {
|
|
858
|
+
if (!types.isIdentifier(path.node.callee)) return;
|
|
859
|
+
const binding = path.scope.getBinding(path.node.callee.name);
|
|
860
|
+
if (binding?.path.isImportSpecifier() && types.isIdentifier(binding.path.node.imported, { name: "MastraFactory" })) result.projectType = "factory";
|
|
861
|
+
},
|
|
862
|
+
ExportNamedDeclaration(path) {
|
|
863
|
+
const decl = path.node.declaration;
|
|
864
|
+
if (types.isVariableDeclaration(decl)) {
|
|
865
|
+
const varDecl = decl.declarations[0];
|
|
866
|
+
if (types.isIdentifier(varDecl?.id, { name: "mastra" }) && types.isNewExpression(varDecl.init) && types.isIdentifier(varDecl.init.callee, { name: "Mastra" })) result.hasValidConfig = true;
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* 2) export { foo as mastra }
|
|
870
|
+
* 3) export { mastra }
|
|
871
|
+
* 4) export { mastra, foo }
|
|
872
|
+
*/
|
|
873
|
+
if (Array.isArray(path.node.specifiers)) {
|
|
874
|
+
for (const spec of path.node.specifiers) if (types.isExportSpecifier(spec) && types.isIdentifier(spec.exported, { name: "mastra" }) && types.isIdentifier(spec.local) && mastraVars.has(spec.local.name)) result.hasValidConfig = true;
|
|
875
|
+
}
|
|
876
|
+
},
|
|
877
|
+
VariableDeclaration(path) {
|
|
878
|
+
for (const decl of path.node.declarations) if (types.isIdentifier(decl.id) && types.isNewExpression(decl.init) && types.isIdentifier(decl.init.callee, { name: "Mastra" })) mastraVars.add(decl.id.name);
|
|
879
|
+
}
|
|
880
|
+
} };
|
|
881
|
+
}
|
|
882
|
+
//#endregion
|
|
883
|
+
//#region src/build/babel/detect-pino-transports.ts
|
|
884
|
+
/**
|
|
885
|
+
* Extract string value from a node (supports StringLiteral and TemplateLiteral without expressions)
|
|
886
|
+
*/
|
|
887
|
+
function getStringValue(node) {
|
|
888
|
+
if (!node) return null;
|
|
889
|
+
if (types.isStringLiteral(node)) return node.value;
|
|
890
|
+
if (types.isTemplateLiteral(node) && node.expressions.length === 0 && node.quasis.length === 1) return node.quasis[0]?.value.cooked ?? null;
|
|
891
|
+
return null;
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Extract target value from an object property
|
|
895
|
+
*/
|
|
896
|
+
function extractTargetFromProperty(prop) {
|
|
897
|
+
if (!types.isObjectProperty(prop)) return null;
|
|
898
|
+
const key = prop.key;
|
|
899
|
+
if (types.isIdentifier(key, { name: "target" }) || types.isStringLiteral(key) && key.value === "target") return getStringValue(prop.value);
|
|
900
|
+
return null;
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Check if a binding came from a pino import/require
|
|
904
|
+
*/
|
|
905
|
+
function isBindingFromPino(path, identifierName) {
|
|
906
|
+
const binding = path.scope.getBinding(identifierName);
|
|
907
|
+
if (!binding) return identifierName === "pino";
|
|
908
|
+
const bindingPath = binding.path;
|
|
909
|
+
if (bindingPath.isImportDefaultSpecifier()) {
|
|
910
|
+
const importDecl = bindingPath.parentPath;
|
|
911
|
+
if (importDecl?.isImportDeclaration()) return importDecl.node.source.value === "pino";
|
|
912
|
+
}
|
|
913
|
+
if (bindingPath.isImportNamespaceSpecifier()) {
|
|
914
|
+
const importDecl = bindingPath.parentPath;
|
|
915
|
+
if (importDecl?.isImportDeclaration()) return importDecl.node.source.value === "pino";
|
|
916
|
+
}
|
|
917
|
+
if (bindingPath.isImportSpecifier()) {
|
|
918
|
+
const importDecl = bindingPath.parentPath;
|
|
919
|
+
if (importDecl?.isImportDeclaration() && importDecl.node.source.value === "pino") {
|
|
920
|
+
const imported = bindingPath.node.imported;
|
|
921
|
+
if (types.isIdentifier(imported) && imported.name === "default") return true;
|
|
922
|
+
if (types.isStringLiteral(imported) && imported.value === "default") return true;
|
|
923
|
+
}
|
|
924
|
+
return false;
|
|
925
|
+
}
|
|
926
|
+
if (bindingPath.isVariableDeclarator()) {
|
|
927
|
+
const init = bindingPath.node.init;
|
|
928
|
+
if (types.isCallExpression(init) && types.isIdentifier(init.callee, { name: "require" }) && init.arguments.length === 1 && types.isStringLiteral(init.arguments[0]) && init.arguments[0].value === "pino") return true;
|
|
929
|
+
}
|
|
930
|
+
return false;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Check if a call expression is a pino.transport() call using scope analysis
|
|
934
|
+
*/
|
|
935
|
+
function isPinoTransportCall(path) {
|
|
936
|
+
const callee = path.node.callee;
|
|
937
|
+
if (!types.isMemberExpression(callee)) return false;
|
|
938
|
+
if (!types.isIdentifier(callee.property, { name: "transport" })) return false;
|
|
939
|
+
if (types.isIdentifier(callee.object)) return isBindingFromPino(path, callee.object.name);
|
|
940
|
+
if (types.isMemberExpression(callee.object) && types.isIdentifier(callee.object.object) && types.isIdentifier(callee.object.property, { name: "default" })) return isBindingFromPino(path, callee.object.object.name);
|
|
941
|
+
return false;
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Extract transport targets from a pino.transport() argument
|
|
945
|
+
*/
|
|
946
|
+
function extractTransportsFromArg(arg) {
|
|
947
|
+
const targets = [];
|
|
948
|
+
if (!types.isObjectExpression(arg)) return targets;
|
|
949
|
+
for (const prop of arg.properties) {
|
|
950
|
+
if (!types.isObjectProperty(prop)) continue;
|
|
951
|
+
const key = prop.key;
|
|
952
|
+
const keyName = types.isIdentifier(key) ? key.name : types.isStringLiteral(key) ? key.value : null;
|
|
953
|
+
if (keyName === "target") {
|
|
954
|
+
const value = getStringValue(prop.value);
|
|
955
|
+
if (value) targets.push(value);
|
|
956
|
+
} else if (keyName === "targets") {
|
|
957
|
+
if (types.isArrayExpression(prop.value)) {
|
|
958
|
+
for (const element of prop.value.elements) if (types.isObjectExpression(element)) for (const innerProp of element.properties) {
|
|
959
|
+
const targetValue = extractTargetFromProperty(innerProp);
|
|
960
|
+
if (targetValue) targets.push(targetValue);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return targets;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Babel plugin to detect pino transport targets in code.
|
|
969
|
+
* Matches patterns like:
|
|
970
|
+
* - pino.transport({ target: "package-name" })
|
|
971
|
+
* - pino.transport({ targets: [{ target: "package-name" }] })
|
|
972
|
+
* - variable.transport({ target: "..." }) where variable is assigned from pino import
|
|
973
|
+
*
|
|
974
|
+
* @param transports - Set to collect detected transport package names
|
|
975
|
+
* @returns Babel plugin object
|
|
976
|
+
*/
|
|
977
|
+
function detectPinoTransports(transports) {
|
|
978
|
+
return {
|
|
979
|
+
name: "detect-pino-transports",
|
|
980
|
+
visitor: { CallExpression(path) {
|
|
981
|
+
if (!isPinoTransportCall(path)) return;
|
|
982
|
+
const firstArg = path.node.arguments[0];
|
|
983
|
+
if (firstArg && !types.isSpreadElement(firstArg)) for (const target of extractTransportsFromArg(firstArg)) transports.add(target);
|
|
984
|
+
} }
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
//#endregion
|
|
988
|
+
//#region src/build/analyze.ts
|
|
989
|
+
function preferDependencyInfo(existing, incoming) {
|
|
990
|
+
return {
|
|
991
|
+
version: incoming.version ?? existing?.version,
|
|
992
|
+
packageSpec: incoming.packageSpec ?? existing?.packageSpec
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
async function resolveDependencyInfo(dep, existing, parentPaths) {
|
|
996
|
+
if (existing?.version || existing?.packageSpec) return existing;
|
|
997
|
+
const packageName = getPackageName(dep);
|
|
998
|
+
const packageNames = [...new Set([dep, packageName].filter(Boolean))];
|
|
999
|
+
for (const parentPath of parentPaths) for (const name of packageNames) {
|
|
1000
|
+
const metadata = await getPackageMetadata(name, parentPath);
|
|
1001
|
+
if (metadata.version || metadata.packageSpec) return preferDependencyInfo(existing, metadata);
|
|
1002
|
+
}
|
|
1003
|
+
for (const name of packageNames) {
|
|
1004
|
+
const metadata = await getPackageMetadata(name);
|
|
1005
|
+
if (metadata.version || metadata.packageSpec) return preferDependencyInfo(existing, metadata);
|
|
1006
|
+
}
|
|
1007
|
+
return existing ?? {};
|
|
1008
|
+
}
|
|
1009
|
+
function importerParentPaths(importerId, base) {
|
|
1010
|
+
if (!importerId || importerId.startsWith("\0") || !isAbsolute(importerId)) return base;
|
|
1011
|
+
return [.../* @__PURE__ */ new Set([importerId, ...base])];
|
|
1012
|
+
}
|
|
1013
|
+
function getLastConcreteModuleId(moduleIds) {
|
|
1014
|
+
return moduleIds.findLast((id) => !id.startsWith("\0") && isAbsolute(id));
|
|
1015
|
+
}
|
|
1016
|
+
function throwExternalDependencyError({ errorId, moduleName, packageName, messagePrefix }) {
|
|
1017
|
+
throw new MastraError({
|
|
1018
|
+
id: errorId,
|
|
1019
|
+
domain: ErrorDomain.DEPLOYER,
|
|
1020
|
+
category: ErrorCategory.USER,
|
|
1021
|
+
details: {
|
|
1022
|
+
importFile: moduleName,
|
|
1023
|
+
packageName
|
|
1024
|
+
},
|
|
1025
|
+
text: `${messagePrefix} \`${packageName}\` to your externals.
|
|
1026
|
+
|
|
1027
|
+
export const mastra = new Mastra({
|
|
1028
|
+
bundler: {
|
|
1029
|
+
externals: ["${packageName}"],
|
|
1030
|
+
}
|
|
1031
|
+
})`
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
function getPackageNameFromBundledModuleName(moduleName) {
|
|
1035
|
+
if (moduleName.includes("__")) return moduleName.replaceAll("__", "/");
|
|
1036
|
+
const chunks = moduleName.split("-");
|
|
1037
|
+
if (!chunks.length) return moduleName;
|
|
1038
|
+
if (chunks[0]?.startsWith("@")) return chunks.slice(0, 2).join("/");
|
|
1039
|
+
return chunks[0];
|
|
1040
|
+
}
|
|
1041
|
+
function validateError(err, file, { binaryMapData, workspaceMap }) {
|
|
1042
|
+
let moduleName = null;
|
|
1043
|
+
let errorConfig = null;
|
|
1044
|
+
if (err instanceof ValidationError) {
|
|
1045
|
+
const parsedStack = import_stack_trace_parser_cjs.parse(err.stack);
|
|
1046
|
+
if (err.type === "TypeError") {
|
|
1047
|
+
const pkgNameRegex = /.*node_modules\/([^\/]+)\//;
|
|
1048
|
+
const stacktraceFrame = parsedStack.find((frame) => frame.file && pkgNameRegex.test(frame.file));
|
|
1049
|
+
if (stacktraceFrame) moduleName = stacktraceFrame.file.match(pkgNameRegex)?.[1] ?? getPackageNameFromBundledModuleName(basename(file.name));
|
|
1050
|
+
else moduleName = getPackageNameFromBundledModuleName(basename(file.name));
|
|
1051
|
+
errorConfig = {
|
|
1052
|
+
id: "DEPLOYER_ANALYZE_TYPE_ERROR",
|
|
1053
|
+
messagePrefix: `Mastra wasn't able to bundle "${moduleName}", might be an older commonJS module. Please add`
|
|
1054
|
+
};
|
|
1055
|
+
} else if (err.stack?.includes?.("[ERR_MODULE_NOT_FOUND]")) {
|
|
1056
|
+
moduleName = err.message.match(/Cannot find package '([^']+)'/)?.[1];
|
|
1057
|
+
const parentModuleName = getPackageNameFromBundledModuleName(basename(file.name));
|
|
1058
|
+
errorConfig = {
|
|
1059
|
+
id: "DEPLOYER_ANALYZE_MODULE_NOT_FOUND",
|
|
1060
|
+
messagePrefix: `Mastra wasn't able to build your project, We couldn't load "${moduleName}" from "${parentModuleName}". Make sure "${moduleName}" is installed or add`
|
|
1061
|
+
};
|
|
1062
|
+
if (moduleName === parentModuleName) return;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
if (err.message.includes("No native build was found")) {
|
|
1066
|
+
const pkgName = getPackageNameFromBundledModuleName(basename(file.name));
|
|
1067
|
+
moduleName = binaryMapData[file.fileName]?.[0] ?? pkgName;
|
|
1068
|
+
errorConfig = {
|
|
1069
|
+
id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
|
|
1070
|
+
messagePrefix: "We found a binary dependency in your bundle but we cannot bundle it yet. Please add"
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
if (moduleName && workspaceMap.has(moduleName)) throw new MastraError({
|
|
1074
|
+
id: "DEPLOYER_ANALYZE_ERROR_IN_WORKSPACE",
|
|
1075
|
+
domain: ErrorDomain.DEPLOYER,
|
|
1076
|
+
category: ErrorCategory.USER,
|
|
1077
|
+
details: { packageName: moduleName },
|
|
1078
|
+
text: `We found an error in the ${moduleName} workspace package. Please find the offending package and fix the error.
|
|
1079
|
+
Error: ${err.stack}`
|
|
1080
|
+
});
|
|
1081
|
+
if (errorConfig && moduleName) throwExternalDependencyError({
|
|
1082
|
+
errorId: errorConfig.id,
|
|
1083
|
+
moduleName,
|
|
1084
|
+
packageName: moduleName,
|
|
1085
|
+
messagePrefix: errorConfig.messagePrefix
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
async function validateFile(root, file, { binaryMapData, moduleResolveMapLocation, logger, workspaceMap, stubbedExternals }) {
|
|
1089
|
+
try {
|
|
1090
|
+
if (!file.isDynamicEntry && file.isEntry) await validate(join(root, file.fileName), {
|
|
1091
|
+
moduleResolveMapLocation,
|
|
1092
|
+
injectESMShim: false,
|
|
1093
|
+
stubbedExternals
|
|
1094
|
+
});
|
|
1095
|
+
} catch (err) {
|
|
1096
|
+
let errorToHandle = err;
|
|
1097
|
+
if (err instanceof ValidationError && err.type === "ReferenceError" && (err.message.startsWith("__dirname") || err.message.startsWith("__filename"))) try {
|
|
1098
|
+
await validate(join(root, file.fileName), {
|
|
1099
|
+
moduleResolveMapLocation,
|
|
1100
|
+
injectESMShim: true,
|
|
1101
|
+
stubbedExternals
|
|
1102
|
+
});
|
|
1103
|
+
errorToHandle = null;
|
|
1104
|
+
} catch (err) {
|
|
1105
|
+
errorToHandle = err;
|
|
1106
|
+
}
|
|
1107
|
+
if (errorToHandle instanceof Error) validateError(errorToHandle, file, {
|
|
1108
|
+
binaryMapData,
|
|
1109
|
+
logger,
|
|
1110
|
+
workspaceMap
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Validates the bundled output by attempting to import each generated module.
|
|
1116
|
+
* Tracks external dependencies that couldn't be bundled.
|
|
1117
|
+
*
|
|
1118
|
+
* @param output - Bundle output from rollup
|
|
1119
|
+
* @param reverseVirtualReferenceMap - Map to resolve virtual module names back to original deps
|
|
1120
|
+
* @param outputDir - Directory containing the bundled files
|
|
1121
|
+
* @param logger - Logger instance for debugging
|
|
1122
|
+
* @param workspaceMap - Map of workspace packages that gets directly passed through for later consumption
|
|
1123
|
+
* @returns Analysis result containing dependency mappings
|
|
1124
|
+
*/
|
|
1125
|
+
async function validateOutput({ output, reverseVirtualReferenceMap, usedExternals, outputDir, projectRoot, workspaceMap, depsVersionInfo }, logger) {
|
|
1126
|
+
const result = {
|
|
1127
|
+
dependencies: /* @__PURE__ */ new Map(),
|
|
1128
|
+
externalDependencies: /* @__PURE__ */ new Map(),
|
|
1129
|
+
workspaceMap
|
|
1130
|
+
};
|
|
1131
|
+
const externalMetadataParentPaths = [projectRoot, ...Array.from(workspaceMap.values()).map((pkgInfo) => pkgInfo.location)];
|
|
1132
|
+
for (const deps of Object.values(usedExternals)) for (const [dep, importerId] of Object.entries(deps)) {
|
|
1133
|
+
if (isExternalProtocolImport(dep)) continue;
|
|
1134
|
+
const pkgName = getPackageName(dep);
|
|
1135
|
+
if (pkgName) {
|
|
1136
|
+
const dependencyInfo = await resolveDependencyInfo(dep, depsVersionInfo.get(dep) || depsVersionInfo.get(pkgName), importerParentPaths(importerId, externalMetadataParentPaths));
|
|
1137
|
+
result.externalDependencies.set(pkgName, preferDependencyInfo(result.externalDependencies.get(pkgName), dependencyInfo));
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
let binaryMapData = {};
|
|
1141
|
+
if (existsSync(join(outputDir, "binary-map.json"))) {
|
|
1142
|
+
const binaryMap = await readFile(join(outputDir, "binary-map.json"), "utf-8");
|
|
1143
|
+
binaryMapData = JSON.parse(binaryMap);
|
|
1144
|
+
}
|
|
1145
|
+
for (const file of output) {
|
|
1146
|
+
if (file.type === "asset") continue;
|
|
1147
|
+
logger.debug("Validating module", { fileName: file.fileName });
|
|
1148
|
+
if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
|
|
1149
|
+
await validateFile(projectRoot, file, {
|
|
1150
|
+
binaryMapData,
|
|
1151
|
+
moduleResolveMapLocation: join(outputDir, "module-resolve-map.json"),
|
|
1152
|
+
logger,
|
|
1153
|
+
workspaceMap,
|
|
1154
|
+
stubbedExternals: [...GLOBAL_EXTERNALS, ...DEPS_TO_IGNORE]
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
return result;
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* Main bundle analysis function that orchestrates the three-step process:
|
|
1161
|
+
* 1. Analyze dependencies
|
|
1162
|
+
* 2. Bundle dependencies modules
|
|
1163
|
+
* 3. Validate generated bundles
|
|
1164
|
+
*
|
|
1165
|
+
* This helps identify which dependencies need to be externalized vs bundled.
|
|
1166
|
+
*/
|
|
1167
|
+
async function analyzeBundle(entries, mastraEntry, { outputDir, projectRoot, platform, isDev = false, bundlerOptions }, logger) {
|
|
1168
|
+
const mastraConfig = await readFile(mastraEntry, "utf-8");
|
|
1169
|
+
const mastraConfigResult = { hasValidConfig: false };
|
|
1170
|
+
await transformAsync(mastraConfig, {
|
|
1171
|
+
filename: mastraEntry,
|
|
1172
|
+
presets: [import.meta.resolve("@babel/preset-typescript")],
|
|
1173
|
+
plugins: [() => checkConfigExport(mastraConfigResult)]
|
|
1174
|
+
});
|
|
1175
|
+
if (!mastraConfigResult.hasValidConfig) logger.warn("Invalid Mastra config", { details: "Please make sure that your entry file looks like this:\nexport const mastra = new Mastra({\n // your options\n})\n\nIf you think your configuration is valid, please open an issue." });
|
|
1176
|
+
const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
|
|
1177
|
+
let externalsPreset = false;
|
|
1178
|
+
const userExternals = Array.isArray(bundlerOptions?.externals) ? bundlerOptions?.externals : [];
|
|
1179
|
+
const userDynamicPackages = bundlerOptions?.dynamicPackages ?? [];
|
|
1180
|
+
if (bundlerOptions?.externals === true) externalsPreset = true;
|
|
1181
|
+
let index = 0;
|
|
1182
|
+
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
1183
|
+
const allExternals = [...GLOBAL_EXTERNALS, ...userExternals].filter(Boolean);
|
|
1184
|
+
const detectedPinoTransports = /* @__PURE__ */ new Set();
|
|
1185
|
+
logger.info("Analyzing dependencies...");
|
|
1186
|
+
const allUsedExternals = /* @__PURE__ */ new Map();
|
|
1187
|
+
const analyzeCache = /* @__PURE__ */ new Map();
|
|
1188
|
+
for (const entry of entries) {
|
|
1189
|
+
const analyzeResult = await analyzeEntry({
|
|
1190
|
+
entry,
|
|
1191
|
+
isVirtualFile: entry.includes("\n") || !existsSync(entry)
|
|
1192
|
+
}, mastraEntry, {
|
|
1193
|
+
logger,
|
|
1194
|
+
sourcemapEnabled: bundlerOptions?.enableSourcemap ?? false,
|
|
1195
|
+
workspaceMap,
|
|
1196
|
+
projectRoot,
|
|
1197
|
+
shouldCheckTransitiveDependencies: true,
|
|
1198
|
+
analyzeCache
|
|
1199
|
+
});
|
|
1200
|
+
transformSync(analyzeResult.output.code, {
|
|
1201
|
+
filename: "pino-detection.js",
|
|
1202
|
+
plugins: [() => detectPinoTransports(detectedPinoTransports)],
|
|
1203
|
+
configFile: false,
|
|
1204
|
+
babelrc: false,
|
|
1205
|
+
code: false
|
|
1206
|
+
});
|
|
1207
|
+
await writeFile(join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
|
|
1208
|
+
for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
|
|
1209
|
+
if (allExternals.some((external) => isDependencyPartOfPackage(dep, external)) || externalsPreset && !metadata.isWorkspace) {
|
|
1210
|
+
const pkgName = getPackageName(dep);
|
|
1211
|
+
if (pkgName) allUsedExternals.set(pkgName, preferDependencyInfo(allUsedExternals.get(pkgName), metadata));
|
|
1212
|
+
continue;
|
|
1213
|
+
}
|
|
1214
|
+
if (depsToOptimize.has(dep)) {
|
|
1215
|
+
const existingEntry = depsToOptimize.get(dep);
|
|
1216
|
+
depsToOptimize.set(dep, {
|
|
1217
|
+
...existingEntry,
|
|
1218
|
+
version: metadata.version ?? existingEntry.version,
|
|
1219
|
+
packageSpec: metadata.packageSpec ?? existingEntry.packageSpec,
|
|
1220
|
+
exports: [.../* @__PURE__ */ new Set([...existingEntry.exports, ...metadata.exports])]
|
|
1221
|
+
});
|
|
1222
|
+
} else depsToOptimize.set(dep, metadata);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
const depsVersionInfo = /* @__PURE__ */ new Map();
|
|
1226
|
+
for (const [dep, metadata] of depsToOptimize.entries()) {
|
|
1227
|
+
const pkgName = getPackageName(dep);
|
|
1228
|
+
if (pkgName && (metadata.version || metadata.packageSpec)) depsVersionInfo.set(pkgName, preferDependencyInfo(depsVersionInfo.get(pkgName), metadata));
|
|
1229
|
+
if (metadata.version || metadata.packageSpec) depsVersionInfo.set(dep, preferDependencyInfo(depsVersionInfo.get(dep), metadata));
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Only during `mastra dev` we want to optimize workspace packages. In previous steps we might have added dependencies that are not workspace packages, so we gotta remove them again.
|
|
1233
|
+
*/
|
|
1234
|
+
if (isDev || externalsPreset) {
|
|
1235
|
+
for (const [dep, metadata] of depsToOptimize.entries()) if (!metadata.isWorkspace) depsToOptimize.delete(dep);
|
|
1236
|
+
}
|
|
1237
|
+
const sortedDeps = Array.from(depsToOptimize.keys()).sort();
|
|
1238
|
+
logger.info("Optimizing dependencies...");
|
|
1239
|
+
logger.debug("Sorted dependencies", { deps: sortedDeps });
|
|
1240
|
+
const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
|
|
1241
|
+
bundlerOptions: {
|
|
1242
|
+
...bundlerOptions,
|
|
1243
|
+
externals: bundlerOptions?.externals ?? allExternals,
|
|
1244
|
+
isDev
|
|
1245
|
+
},
|
|
1246
|
+
projectRoot,
|
|
1247
|
+
workspaceRoot,
|
|
1248
|
+
workspaceMap,
|
|
1249
|
+
platform
|
|
1250
|
+
});
|
|
1251
|
+
const relativeWorkspaceFolderPaths = Array.from(workspaceMap.values()).map((pkgInfo) => slash(relative(workspaceRoot || projectRoot, pkgInfo.location)));
|
|
1252
|
+
for (const o of output) {
|
|
1253
|
+
if (o.type === "asset") continue;
|
|
1254
|
+
const importerId = getLastConcreteModuleId(o.moduleIds);
|
|
1255
|
+
for (const i of o.imports) {
|
|
1256
|
+
if (isBuiltinModule(i)) continue;
|
|
1257
|
+
if (i.startsWith(".") || i.startsWith("/")) continue;
|
|
1258
|
+
if (!isBareModuleSpecifier(i) || isExternalProtocolImport(i)) continue;
|
|
1259
|
+
if (relativeWorkspaceFolderPaths.some((workspacePath) => i.startsWith(workspacePath))) continue;
|
|
1260
|
+
const pkgName = getPackageName(i);
|
|
1261
|
+
if (pkgName && workspaceMap.has(pkgName)) continue;
|
|
1262
|
+
if (pkgName) {
|
|
1263
|
+
const dependencyInfo = await resolveDependencyInfo(i, depsVersionInfo.get(i) || depsVersionInfo.get(pkgName), importerParentPaths(importerId, [projectRoot, ...Array.from(workspaceMap.values()).map((pkgInfo) => pkgInfo.location)]));
|
|
1264
|
+
allUsedExternals.set(pkgName, preferDependencyInfo(allUsedExternals.get(pkgName), dependencyInfo));
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
const result = await validateOutput({
|
|
1269
|
+
output,
|
|
1270
|
+
reverseVirtualReferenceMap: fileNameToDependencyMap,
|
|
1271
|
+
usedExternals,
|
|
1272
|
+
outputDir,
|
|
1273
|
+
projectRoot: workspaceRoot || projectRoot,
|
|
1274
|
+
workspaceMap,
|
|
1275
|
+
depsVersionInfo
|
|
1276
|
+
}, logger);
|
|
1277
|
+
/**
|
|
1278
|
+
* Build the final set of external dependencies from four sources:
|
|
1279
|
+
* 1. result.externalDependencies - externals discovered during bundle validation
|
|
1280
|
+
* 2. allUsedExternals - packages detected via static analysis that matched the externals config
|
|
1281
|
+
* 3. detectedPinoTransports - pino transports detected by the plugin during bundling
|
|
1282
|
+
* 4. userDynamicPackages - user-specified packages loaded dynamically at runtime
|
|
1283
|
+
*
|
|
1284
|
+
* Prefer entries with version info over entries without
|
|
1285
|
+
*/
|
|
1286
|
+
const mergedExternalDeps = new Map(result.externalDependencies);
|
|
1287
|
+
for (const [dep, info] of allUsedExternals) {
|
|
1288
|
+
if (isExternalProtocolImport(dep)) continue;
|
|
1289
|
+
mergedExternalDeps.set(dep, preferDependencyInfo(mergedExternalDeps.get(dep), info));
|
|
1290
|
+
}
|
|
1291
|
+
const externalMetadataParentPaths = [
|
|
1292
|
+
projectRoot,
|
|
1293
|
+
...Array.from(workspaceMap.values()).map((pkgInfo) => pkgInfo.location),
|
|
1294
|
+
import.meta.dirname
|
|
1295
|
+
];
|
|
1296
|
+
for (const [dep, info] of mergedExternalDeps) if (!info.version && !info.packageSpec) mergedExternalDeps.set(dep, await resolveDependencyInfo(dep, info, externalMetadataParentPaths));
|
|
1297
|
+
for (const transport of detectedPinoTransports) if (!mergedExternalDeps.has(transport)) mergedExternalDeps.set(transport, await resolveDependencyInfo(transport, void 0, externalMetadataParentPaths));
|
|
1298
|
+
for (const pkg of userDynamicPackages) if (!mergedExternalDeps.has(pkg)) mergedExternalDeps.set(pkg, await resolveDependencyInfo(pkg, void 0, externalMetadataParentPaths));
|
|
1299
|
+
return {
|
|
1300
|
+
...result,
|
|
1301
|
+
externalDependencies: mergedExternalDeps,
|
|
1302
|
+
...mastraConfigResult.projectType ? { projectType: mastraConfigResult.projectType } : {}
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
//#endregion
|
|
1306
|
+
export { getWorkspaceInformation as i, checkConfigExport as n, aliasHono as r, analyzeBundle as t };
|
|
1307
|
+
|
|
1308
|
+
//# sourceMappingURL=analyze-C2q7jxbN.js.map
|