@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
package/dist/chunk-E5SBYHQK.js
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import { tsConfigPaths, esbuild } from './chunk-5PORNUPF.js';
|
|
2
|
-
import { pathToFileURL } from 'url';
|
|
3
|
-
import { optimizeLodashImports } from '@optimize-lodash/rollup-plugin';
|
|
4
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
5
|
-
import json from '@rollup/plugin-json';
|
|
6
|
-
import { rollup } from 'rollup';
|
|
7
|
-
import { transformAsync, types } from '@babel/core';
|
|
8
|
-
|
|
9
|
-
function removeAllOptionsFromMastraExcept(result, option, logger) {
|
|
10
|
-
return {
|
|
11
|
-
name: "remove-all-except-" + option + "-config",
|
|
12
|
-
visitor: {
|
|
13
|
-
ExportNamedDeclaration: {
|
|
14
|
-
// remove all exports, but keep the underlying declarations — the
|
|
15
|
-
// extracted option may reference them (e.g. `export const deployer = ...`
|
|
16
|
-
// used as `new Mastra({ deployer })`). Unreferenced declarations are
|
|
17
|
-
// dropped by the cleanup pass afterwards.
|
|
18
|
-
exit(path) {
|
|
19
|
-
if (path.node.declaration) {
|
|
20
|
-
const [declaration] = path.replaceWith(path.node.declaration);
|
|
21
|
-
declaration.skip();
|
|
22
|
-
} else {
|
|
23
|
-
path.remove();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
NewExpression(path, state) {
|
|
28
|
-
const varDeclaratorPath = path.findParent((path2) => types.isVariableDeclarator(path2.node));
|
|
29
|
-
if (!varDeclaratorPath) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const parentNode = path.parentPath.node;
|
|
33
|
-
if (!types.isVariableDeclarator(parentNode) || !types.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
let mastraArgs = types.objectExpression([]);
|
|
37
|
-
if (types.isObjectExpression(path.node.arguments[0])) {
|
|
38
|
-
mastraArgs = path.node.arguments[0];
|
|
39
|
-
}
|
|
40
|
-
let configProperty = mastraArgs.properties.find(
|
|
41
|
-
(prop) => types.isObjectProperty(prop) && types.isIdentifier(prop.key) && prop.key.name === option
|
|
42
|
-
);
|
|
43
|
-
let configValue = types.objectExpression([]);
|
|
44
|
-
const programPath = path.scope.getProgramParent().path;
|
|
45
|
-
if (!programPath) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (configProperty && types.isObjectProperty(configProperty) && types.isExpression(configProperty.value)) {
|
|
49
|
-
result.hasCustomConfig = true;
|
|
50
|
-
configValue = configProperty.value;
|
|
51
|
-
if (types.isIdentifier(configProperty.value) && configProperty.value.name === option) {
|
|
52
|
-
const configBinding = state.file.scope.getBinding(option);
|
|
53
|
-
if (configBinding && types.isVariableDeclarator(configBinding.path.node)) {
|
|
54
|
-
const id = path.scope.generateUidIdentifier(option);
|
|
55
|
-
configBinding.path.replaceWith(types.variableDeclarator(id, configBinding.path.node.init));
|
|
56
|
-
configValue = id;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const exportDeclaration = types.exportNamedDeclaration(
|
|
61
|
-
types.variableDeclaration("const", [types.variableDeclarator(types.identifier(option), configValue)]),
|
|
62
|
-
[]
|
|
63
|
-
);
|
|
64
|
-
programPath.node.body.push(exportDeclaration);
|
|
65
|
-
},
|
|
66
|
-
Program: {
|
|
67
|
-
exit(path) {
|
|
68
|
-
const hasExport = path.node.body.some(
|
|
69
|
-
(node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
|
|
70
|
-
);
|
|
71
|
-
if (!hasExport) {
|
|
72
|
-
if (logger) {
|
|
73
|
-
logger.warn("Mastra config could not be extracted", {
|
|
74
|
-
option,
|
|
75
|
-
details: "Please make sure your entry file looks like this:\nexport const mastra = new Mastra({\n <option>: <value>\n})"
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
const fallbackExportDeclaration = types.exportNamedDeclaration(
|
|
79
|
-
types.variableDeclaration("const", [types.variableDeclarator(types.identifier(option), types.objectExpression([]))]),
|
|
80
|
-
[]
|
|
81
|
-
);
|
|
82
|
-
path.node.body.push(fallbackExportDeclaration);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// src/build/plugins/remove-all-except.ts
|
|
91
|
-
function removeAllOptionsFromMastraExceptPlugin(mastraEntry, name, result, options) {
|
|
92
|
-
return {
|
|
93
|
-
name: `remove-${name}`,
|
|
94
|
-
transform(code, id) {
|
|
95
|
-
if (id !== mastraEntry) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
return transformAsync(code, {
|
|
99
|
-
babelrc: false,
|
|
100
|
-
configFile: false,
|
|
101
|
-
filename: id,
|
|
102
|
-
plugins: [() => removeAllOptionsFromMastraExcept(result, name, options?.logger)],
|
|
103
|
-
sourceMaps: options?.sourcemap
|
|
104
|
-
}).then((result2) => ({
|
|
105
|
-
code: result2.code,
|
|
106
|
-
map: result2.map
|
|
107
|
-
}));
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function removeNonReferencedNodes() {
|
|
112
|
-
return {
|
|
113
|
-
name: "remove-non-referenced-nodes",
|
|
114
|
-
visitor: {
|
|
115
|
-
Program(path) {
|
|
116
|
-
const scope = path.scope;
|
|
117
|
-
const currentBody = path.get("body");
|
|
118
|
-
const filteredBody = currentBody.filter((childPath) => {
|
|
119
|
-
if (childPath.isExportDeclaration()) {
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
if (childPath.isVariableDeclaration()) {
|
|
123
|
-
return childPath.node.declarations.some((decl) => {
|
|
124
|
-
if (!types.isIdentifier(decl.id)) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
const name = decl.id.name;
|
|
128
|
-
const binding = scope.getBinding(name);
|
|
129
|
-
return binding && (binding.referenced || binding.referencePaths.length > 0);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {
|
|
133
|
-
if (!types.isIdentifier(childPath.node.id)) {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
const name = childPath.node.id.name;
|
|
137
|
-
const binding = scope.getBinding(name);
|
|
138
|
-
return binding && (binding.referenced || binding.referencePaths.length > 0);
|
|
139
|
-
}
|
|
140
|
-
if (childPath.isImportDeclaration()) {
|
|
141
|
-
return childPath.node.specifiers.some((specifier) => {
|
|
142
|
-
const importedName = specifier.local.name;
|
|
143
|
-
const binding = scope.getBinding(importedName);
|
|
144
|
-
return binding && (binding.referenced || binding.referencePaths.length > 0);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
return false;
|
|
148
|
-
});
|
|
149
|
-
path.set(
|
|
150
|
-
"body",
|
|
151
|
-
filteredBody.map((p) => p.node)
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// src/build/plugins/remove-unused-references.ts
|
|
159
|
-
async function recursiveRemoveNonReferencedNodes(code) {
|
|
160
|
-
const result = await transformAsync(code, {
|
|
161
|
-
babelrc: false,
|
|
162
|
-
configFile: false,
|
|
163
|
-
plugins: [removeNonReferencedNodes]
|
|
164
|
-
});
|
|
165
|
-
if (result && result.code !== code) {
|
|
166
|
-
return recursiveRemoveNonReferencedNodes(result.code);
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
code: result.code,
|
|
170
|
-
map: result.map
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// src/build/shared/extract-mastra-option.ts
|
|
175
|
-
function extractMastraOptionBundler(name, entryFile, result, logger) {
|
|
176
|
-
return rollup({
|
|
177
|
-
logLevel: "silent",
|
|
178
|
-
input: {
|
|
179
|
-
[`${name}-config`]: entryFile
|
|
180
|
-
},
|
|
181
|
-
treeshake: "smallest",
|
|
182
|
-
plugins: [
|
|
183
|
-
tsConfigPaths(),
|
|
184
|
-
// transpile typescript to something we understand
|
|
185
|
-
esbuild(),
|
|
186
|
-
optimizeLodashImports({
|
|
187
|
-
include: "**/*.{js,ts,mjs,cjs}"
|
|
188
|
-
}),
|
|
189
|
-
commonjs({
|
|
190
|
-
extensions: [".js", ".ts"],
|
|
191
|
-
strictRequires: "strict",
|
|
192
|
-
transformMixedEsModules: true,
|
|
193
|
-
ignoreTryCatch: false
|
|
194
|
-
}),
|
|
195
|
-
json(),
|
|
196
|
-
removeAllOptionsFromMastraExceptPlugin(entryFile, name, result, { logger }),
|
|
197
|
-
// let esbuild remove all unused imports
|
|
198
|
-
esbuild(),
|
|
199
|
-
{
|
|
200
|
-
name: "cleanup",
|
|
201
|
-
transform(code, id) {
|
|
202
|
-
if (id !== entryFile) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
return recursiveRemoveNonReferencedNodes(code);
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
// let esbuild remove it once more
|
|
209
|
-
esbuild()
|
|
210
|
-
]
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
async function extractMastraOption(name, entryFile, outputDir, logger) {
|
|
214
|
-
const result = {
|
|
215
|
-
hasCustomConfig: false
|
|
216
|
-
};
|
|
217
|
-
const bundler = await extractMastraOptionBundler(name, entryFile, result, logger);
|
|
218
|
-
const output = await bundler.write({
|
|
219
|
-
dir: outputDir,
|
|
220
|
-
format: "es",
|
|
221
|
-
entryFileNames: "[name].mjs"
|
|
222
|
-
});
|
|
223
|
-
if (result.hasCustomConfig) {
|
|
224
|
-
const configPath = `${outputDir}/${name}-config.mjs`;
|
|
225
|
-
return {
|
|
226
|
-
bundleOutput: output,
|
|
227
|
-
getConfig: () => import(pathToFileURL(configPath).href).then((m) => m[name])
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
return null;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// src/build/bundlerOptions.ts
|
|
234
|
-
async function getBundlerOptions(entryFile, outputDir, logger) {
|
|
235
|
-
const result = await extractMastraOption("bundler", entryFile, outputDir, logger);
|
|
236
|
-
if (!result) {
|
|
237
|
-
return null;
|
|
238
|
-
}
|
|
239
|
-
return result.getConfig();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export { extractMastraOption, getBundlerOptions };
|
|
243
|
-
//# sourceMappingURL=chunk-E5SBYHQK.js.map
|
|
244
|
-
//# sourceMappingURL=chunk-E5SBYHQK.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/build/babel/remove-all-options-except.ts","../src/build/plugins/remove-all-except.ts","../src/build/babel/remove-non-referenced-nodes.ts","../src/build/plugins/remove-unused-references.ts","../src/build/shared/extract-mastra-option.ts","../src/build/bundlerOptions.ts"],"names":["path","t","result","transformAsync"],"mappings":";;;;;;;;AAKO,SAAS,gCAAA,CACd,MAAA,EACA,MAAA,EACA,MAAA,EACc;AACd,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,uBAAuB,MAAA,GAAS,SAAA;AAAA,IACtC,OAAA,EAAS;AAAA,MACP,sBAAA,EAAwB;AAAA;AAAA;AAAA;AAAA;AAAA,QAKtB,KAAK,IAAA,EAAM;AACT,UAAA,IAAI,IAAA,CAAK,KAAK,WAAA,EAAa;AACzB,YAAA,MAAM,CAAC,WAAW,CAAA,GAAI,KAAK,WAAA,CAAY,IAAA,CAAK,KAAK,WAAW,CAAA;AAG5D,YAAA,WAAA,CAAY,IAAA,EAAK;AAAA,UACnB,CAAA,MAAO;AACL,YAAA,IAAA,CAAK,MAAA,EAAO;AAAA,UACd;AAAA,QACF;AAAA,OACF;AAAA,MAEA,aAAA,CAAc,MAAM,KAAA,EAAO;AAEzB,QAAA,MAAM,iBAAA,GAAoB,KAAK,UAAA,CAAW,CAAAA,UAAQC,KAAA,CAAE,oBAAA,CAAqBD,KAAAA,CAAK,IAAI,CAAC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AAA;AAEvC,IAAA,OAAO;AAAA,MACL,YAAA,EAAc,MAAA;AAAA,MACd,SAAA,EAAW,MAAM,OAAO,aAAA,CAAc,UAAU,CAAA,CAAE,IAAA,CAAA,CAAM,IAAA,CAAK,CAAA,CAAA,KAAK,CAAA,CAAE,IAAI,CAAoB;AAAA,KAC9F;AAAA,EACF;AAEA,EAAA,OAAO,IAAA;AACT;;;AC9EA,eAAsB,iBAAA,CACpB,SAAA,EACA,SAAA,EACA,MAAA,EACmC;AACnC,EAAA,MAAM,SAAS,MAAM,mBAAA,CAAoB,SAAA,EAAW,SAAA,EAAW,WAAW,MAAM,CAAA;AAEhF,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,OAAO,OAAO,SAAA,EAAU;AAC1B","file":"chunk-E5SBYHQK.js","sourcesContent":["import { types as t } from '@babel/core';\nimport type { NodePath, PluginObject, types } from '@babel/core';\nimport type { IMastraLogger } from '@mastra/core/logger';\nimport type { Config as MastraConfig } from '@mastra/core/mastra';\n\nexport function removeAllOptionsFromMastraExcept(\n result: { hasCustomConfig: boolean },\n option: keyof MastraConfig,\n logger?: IMastraLogger,\n): PluginObject {\n return {\n name: 'remove-all-except-' + option + '-config',\n visitor: {\n ExportNamedDeclaration: {\n // remove all exports, but keep the underlying declarations — the\n // extracted option may reference them (e.g. `export const deployer = ...`\n // used as `new Mastra({ deployer })`). Unreferenced declarations are\n // dropped by the cleanup pass afterwards.\n exit(path) {\n if (path.node.declaration) {\n const [declaration] = path.replaceWith(path.node.declaration);\n // Already traversed — don't requeue, or the NewExpression visitor\n // would append the extracted export a second time.\n declaration.skip();\n } else {\n path.remove();\n }\n },\n },\n\n NewExpression(path, state) {\n // is a variable declaration\n const varDeclaratorPath = path.findParent(path => t.isVariableDeclarator(path.node));\n if (!varDeclaratorPath) {\n return;\n }\n\n const parentNode = path.parentPath.node;\n // check if it's a const of mastra\n if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== 'mastra') {\n return;\n }\n\n let mastraArgs = t.objectExpression([]);\n if (t.isObjectExpression(path.node.arguments[0])) {\n mastraArgs = path.node.arguments[0];\n }\n\n // Find the config property, skipping SpreadElement nodes\n let configProperty = mastraArgs.properties.find(\n prop => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === option,\n );\n let configValue: types.Expression = t.objectExpression([]);\n\n const programPath = path.scope.getProgramParent().path as NodePath<types.Program> | undefined;\n if (!programPath) {\n return;\n }\n\n if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {\n result.hasCustomConfig = true;\n configValue = configProperty.value;\n\n if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {\n const configBinding = state.file.scope.getBinding(option)!;\n\n if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {\n const id = path.scope.generateUidIdentifier(option);\n\n configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init!));\n configValue = id;\n }\n }\n }\n\n // add the deployer export\n const exportDeclaration = t.exportNamedDeclaration(\n t.variableDeclaration('const', [t.variableDeclarator(t.identifier(option), configValue)]),\n [],\n );\n\n programPath.node.body.push(exportDeclaration);\n },\n\n Program: {\n exit(path) {\n // Add a fallback export if no mastra configuration was found\n const hasExport = path.node.body.some(\n node => node.type === 'ExportNamedDeclaration' || node.type === 'ExportDefaultDeclaration',\n );\n\n if (!hasExport) {\n if (logger) {\n logger.warn('Mastra config could not be extracted', {\n option,\n details:\n 'Please make sure your entry file looks like this:\\nexport const mastra = new Mastra({\\n <option>: <value>\\n})',\n });\n }\n\n const fallbackExportDeclaration = t.exportNamedDeclaration(\n t.variableDeclaration('const', [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),\n [],\n );\n path.node.body.push(fallbackExportDeclaration);\n }\n },\n },\n },\n } satisfies PluginObject;\n}\n","import { transformAsync } from '@babel/core';\nimport type { IMastraLogger } from '@mastra/core/logger';\nimport type { Config as MastraConfig } from '@mastra/core/mastra';\nimport type { Plugin, SourceMapInput } from 'rollup';\nimport { removeAllOptionsFromMastraExcept } from '../babel/remove-all-options-except';\n\nexport function removeAllOptionsFromMastraExceptPlugin(\n mastraEntry: string,\n name: keyof MastraConfig,\n result: { hasCustomConfig: boolean },\n options?: { sourcemap?: boolean; logger?: IMastraLogger },\n): Plugin {\n return {\n name: `remove-${name}`,\n transform(code, id) {\n if (id !== mastraEntry) {\n return;\n }\n\n return transformAsync(code, {\n babelrc: false,\n configFile: false,\n filename: id,\n plugins: [() => removeAllOptionsFromMastraExcept(result, name, options?.logger)],\n sourceMaps: options?.sourcemap,\n }).then(result => ({\n code: result!.code!,\n map: result!.map! as SourceMapInput,\n }));\n },\n } satisfies Plugin;\n}\n","import { types as t } from '@babel/core';\nimport type { PluginObject } from '@babel/core';\n\nexport function removeNonReferencedNodes() {\n return {\n name: 'remove-non-referenced-nodes',\n visitor: {\n Program(path) {\n // Get the scope information\n const scope = path.scope;\n\n // Filter body to keep only referenced nodes\n const currentBody = path.get('body');\n const filteredBody = currentBody.filter(childPath => {\n if (childPath.isExportDeclaration()) {\n return true;\n }\n\n // For variable declarations, check if any declared variables are referenced\n if (childPath.isVariableDeclaration()) {\n return childPath.node.declarations.some(decl => {\n if (!t.isIdentifier(decl.id)) {\n return false;\n }\n\n const name = decl.id.name;\n const binding = scope.getBinding(name);\n // Keep if it has references or is exported\n return binding && (binding.referenced || binding.referencePaths.length > 0);\n });\n }\n\n // For function/class declarations, check if they're referenced\n if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {\n if (!t.isIdentifier(childPath.node.id)) {\n return false;\n }\n\n const name = childPath.node.id.name;\n const binding = scope.getBinding(name);\n return binding && (binding.referenced || binding.referencePaths.length > 0);\n }\n\n // For imports, check if any imported items are referenced\n if (childPath.isImportDeclaration()) {\n return childPath.node.specifiers.some(specifier => {\n const importedName = specifier.local.name;\n const binding = scope.getBinding(importedName);\n return binding && (binding.referenced || binding.referencePaths.length > 0);\n });\n }\n\n // Default to keeping other node types\n return false;\n });\n\n // Replace the program body with filtered nodes\n path.set(\n 'body',\n filteredBody.map(p => p.node),\n );\n },\n },\n } as PluginObject;\n}\n","import { transformAsync } from '@babel/core';\nimport { removeNonReferencedNodes } from '../babel/remove-non-referenced-nodes';\n\nexport async function recursiveRemoveNonReferencedNodes(code: string): Promise<{ code: string; map: any }> {\n const result = await transformAsync(code, {\n babelrc: false,\n configFile: false,\n plugins: [removeNonReferencedNodes],\n });\n\n // keep looping until the code is not changed\n if (result && result.code! !== code) {\n return recursiveRemoveNonReferencedNodes(result!.code!);\n }\n\n return {\n code: result!.code!,\n map: result!.map!,\n };\n}\n","import { pathToFileURL } from 'node:url';\nimport type { IMastraLogger } from '@mastra/core/logger';\nimport type { Config as MastraConfig } from '@mastra/core/mastra';\nimport { optimizeLodashImports } from '@optimize-lodash/rollup-plugin';\nimport commonjs from '@rollup/plugin-commonjs';\nimport json from '@rollup/plugin-json';\nimport { rollup } from 'rollup';\nimport type { RollupOutput } from 'rollup';\nimport { esbuild } from '../plugins/esbuild';\nimport { removeAllOptionsFromMastraExceptPlugin } from '../plugins/remove-all-except';\nimport { recursiveRemoveNonReferencedNodes } from '../plugins/remove-unused-references';\nimport { tsConfigPaths } from '../plugins/tsconfig-paths';\n\nexport function extractMastraOptionBundler(\n name: keyof MastraConfig,\n entryFile: string,\n result: {\n hasCustomConfig: boolean;\n },\n logger?: IMastraLogger,\n) {\n return rollup({\n logLevel: 'silent',\n input: {\n [`${name}-config`]: entryFile,\n },\n treeshake: 'smallest',\n plugins: [\n tsConfigPaths(),\n // transpile typescript to something we understand\n esbuild(),\n optimizeLodashImports({\n include: '**/*.{js,ts,mjs,cjs}',\n }),\n commonjs({\n extensions: ['.js', '.ts'],\n strictRequires: 'strict',\n transformMixedEsModules: true,\n ignoreTryCatch: false,\n }),\n json(),\n removeAllOptionsFromMastraExceptPlugin(entryFile, name, result, { logger }),\n // let esbuild remove all unused imports\n esbuild(),\n {\n name: 'cleanup',\n transform(code, id) {\n if (id !== entryFile) {\n return;\n }\n\n return recursiveRemoveNonReferencedNodes(code);\n },\n },\n // let esbuild remove it once more\n esbuild(),\n ],\n });\n}\n\nexport async function extractMastraOption<T extends keyof MastraConfig>(\n name: T,\n entryFile: string,\n outputDir: string,\n logger?: IMastraLogger,\n): Promise<{\n bundleOutput: RollupOutput;\n getConfig: () => Promise<MastraConfig[T]>;\n} | null> {\n const result = {\n hasCustomConfig: false,\n };\n\n const bundler = await extractMastraOptionBundler(name, entryFile, result, logger);\n\n const output = await bundler.write({\n dir: outputDir,\n format: 'es',\n entryFileNames: '[name].mjs',\n });\n\n if (result.hasCustomConfig) {\n const configPath = `${outputDir}/${name}-config.mjs`;\n\n return {\n bundleOutput: output,\n getConfig: () => import(pathToFileURL(configPath).href).then(m => m[name] as MastraConfig[T]),\n };\n }\n\n return null;\n}\n","import type { IMastraLogger } from '@mastra/core/logger';\nimport type { Config } from '@mastra/core/mastra';\nimport { extractMastraOption, extractMastraOptionBundler } from './shared/extract-mastra-option';\n\nexport function getBundlerOptionsBundler(\n entryFile: string,\n result: {\n hasCustomConfig: false;\n },\n) {\n return extractMastraOptionBundler('bundler', entryFile, result);\n}\n\nexport async function getBundlerOptions(\n entryFile: string,\n outputDir: string,\n logger?: IMastraLogger,\n): Promise<Config['bundler'] | null> {\n const result = await extractMastraOption('bundler', entryFile, outputDir, logger);\n\n if (!result) {\n return null;\n }\n\n return result.getConfig();\n}\n"]}
|