@mastra/deployer 1.0.0-beta.9 → 1.0.4
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 +811 -0
- package/dist/arktype-aI7TBD0R-CCZH3EYK.js +8 -0
- package/dist/{arktype-aI7TBD0R-OEPFT4G6.js.map → arktype-aI7TBD0R-CCZH3EYK.js.map} +1 -1
- package/dist/{arktype-aI7TBD0R-4YXBEQBG.cjs → arktype-aI7TBD0R-XHBHUL3T.cjs} +3 -3
- package/dist/{arktype-aI7TBD0R-4YXBEQBG.cjs.map → arktype-aI7TBD0R-XHBHUL3T.cjs.map} +1 -1
- package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
- package/dist/build/analyze/bundleExternals.d.ts +4 -5
- package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
- package/dist/build/analyze.cjs +2 -2
- package/dist/build/analyze.d.ts +5 -5
- package/dist/build/analyze.d.ts.map +1 -1
- package/dist/build/analyze.js +1 -1
- package/dist/build/babel/remove-deployer.d.ts.map +1 -1
- package/dist/build/bundler.cjs +3 -3
- package/dist/build/bundler.d.ts +3 -1
- package/dist/build/bundler.d.ts.map +1 -1
- package/dist/build/bundler.js +1 -1
- package/dist/build/bundlerOptions.d.ts.map +1 -1
- package/dist/build/deployer.d.ts.map +1 -1
- package/dist/build/index.cjs +19 -10
- package/dist/build/index.d.ts +2 -0
- package/dist/build/index.d.ts.map +1 -1
- package/dist/build/index.js +4 -3
- package/dist/build/package-info.d.ts +9 -0
- package/dist/build/package-info.d.ts.map +1 -0
- package/dist/build/plugins/node-modules-extension-resolver.d.ts +7 -0
- package/dist/build/plugins/node-modules-extension-resolver.d.ts.map +1 -1
- package/dist/build/plugins/remove-all-except.d.ts +10 -0
- package/dist/build/plugins/remove-all-except.d.ts.map +1 -0
- package/dist/build/plugins/tsconfig-paths.d.ts +1 -1
- package/dist/build/plugins/tsconfig-paths.d.ts.map +1 -1
- package/dist/build/serverOptions.d.ts.map +1 -1
- package/dist/build/shared/extract-mastra-option.d.ts +4 -8
- package/dist/build/shared/extract-mastra-option.d.ts.map +1 -1
- package/dist/build/types.d.ts +5 -0
- package/dist/build/types.d.ts.map +1 -1
- package/dist/build/utils.d.ts +35 -4
- package/dist/build/utils.d.ts.map +1 -1
- package/dist/build/watcher.d.ts +2 -1
- package/dist/build/watcher.d.ts.map +1 -1
- package/dist/bundler/index.cjs +6 -2
- package/dist/bundler/index.d.ts +10 -7
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/index.js +1 -1
- package/dist/chunk-2VG357HT.cjs +4 -0
- package/dist/{chunk-BTNPI4Z7.cjs.map → chunk-2VG357HT.cjs.map} +1 -1
- package/dist/chunk-5FPJTHRK.js +88 -0
- package/dist/chunk-5FPJTHRK.js.map +1 -0
- package/dist/{chunk-2OTEFUER.cjs → chunk-5TYVF4KJ.cjs} +31 -24
- package/dist/chunk-5TYVF4KJ.cjs.map +1 -0
- package/dist/{chunk-BFQ2S5UD.cjs → chunk-7EPD2XJR.cjs} +76 -20
- package/dist/chunk-7EPD2XJR.cjs.map +1 -0
- package/dist/{chunk-MMUE22EL.js → chunk-DBXWQ2CA.js} +10 -10
- package/dist/chunk-DBXWQ2CA.js.map +1 -0
- package/dist/chunk-G6GFAPPU.js +6 -0
- package/dist/{chunk-Q2YGWEXY.js.map → chunk-G6GFAPPU.js.map} +1 -1
- package/dist/chunk-GU4OME5Q.cjs +112 -0
- package/dist/chunk-GU4OME5Q.cjs.map +1 -0
- package/dist/chunk-HPGDVJAZ.js +3 -0
- package/dist/{chunk-FBT6QP7J.js.map → chunk-HPGDVJAZ.js.map} +1 -1
- package/dist/{chunk-TK2CCU7I.js → chunk-HWSYWSD7.js} +278 -190
- package/dist/chunk-HWSYWSD7.js.map +1 -0
- package/dist/{chunk-GD2TGMBP.cjs → chunk-JBE6KM7R.cjs} +3 -3
- package/dist/{chunk-GD2TGMBP.cjs.map → chunk-JBE6KM7R.cjs.map} +1 -1
- package/dist/{chunk-TXKETRIN.cjs → chunk-JRUJ546M.cjs} +10 -10
- package/dist/chunk-JRUJ546M.cjs.map +1 -0
- package/dist/{chunk-7PLNIFGZ.cjs → chunk-KE4NVPI4.cjs} +3 -3
- package/dist/{chunk-7PLNIFGZ.cjs.map → chunk-KE4NVPI4.cjs.map} +1 -1
- package/dist/chunk-MCWU6IKS.js +14 -0
- package/dist/{chunk-N5TMJUIR.js.map → chunk-MCWU6IKS.js.map} +1 -1
- package/dist/{chunk-UQZGTSBF.js → chunk-NGQZZ54Y.js} +68 -13
- package/dist/chunk-NGQZZ54Y.js.map +1 -0
- package/dist/chunk-QAOUDKHK.js +67 -0
- package/dist/chunk-QAOUDKHK.js.map +1 -0
- package/dist/{chunk-RBPCXFN7.js → chunk-SD6NHZ2H.js} +47 -28
- package/dist/chunk-SD6NHZ2H.js.map +1 -0
- package/dist/{chunk-MUWNMVNL.cjs → chunk-T7NCLSYN.cjs} +297 -209
- package/dist/chunk-T7NCLSYN.cjs.map +1 -0
- package/dist/{chunk-P4L6VIHY.js → chunk-V4HCIN6G.js} +3 -3
- package/dist/{chunk-P4L6VIHY.js.map → chunk-V4HCIN6G.js.map} +1 -1
- package/dist/{chunk-SS22TD6R.cjs → chunk-VOI3B5MX.cjs} +54 -34
- package/dist/chunk-VOI3B5MX.cjs.map +1 -0
- package/dist/chunk-ZXQ7DOYU.cjs +16 -0
- package/dist/{chunk-ID3HN3BH.cjs.map → chunk-ZXQ7DOYU.cjs.map} +1 -1
- package/dist/default-u_dwuiYb-JPNIZQKK.cjs +9 -0
- package/dist/{default-u_dwuiYb-PWN6FHC6.cjs.map → default-u_dwuiYb-JPNIZQKK.cjs.map} +1 -1
- package/dist/default-u_dwuiYb-RK5OD4MY.js +3 -0
- package/dist/{default-u_dwuiYb-65M4BHAA.js.map → default-u_dwuiYb-RK5OD4MY.js.map} +1 -1
- package/dist/docs/README.md +32 -0
- package/dist/docs/SKILL.md +36 -0
- package/dist/docs/SOURCE_MAP.json +27 -0
- package/dist/docs/deployer/01-reference.md +93 -0
- package/dist/docs/deployment/01-overview.md +64 -0
- package/dist/docs/deployment/02-mastra-server.md +129 -0
- package/dist/docs/deployment/03-monorepo.md +142 -0
- package/dist/docs/deployment/04-cloud-providers.md +17 -0
- package/dist/docs/deployment/05-web-framework.md +55 -0
- package/dist/docs/deployment/06-workflow-runners.md +11 -0
- package/dist/effect-QlVUlMFu-HN3LWZSQ.cjs +17 -0
- package/dist/{effect-QlVUlMFu-2ADPKIDF.cjs.map → effect-QlVUlMFu-HN3LWZSQ.cjs.map} +1 -1
- package/dist/{effect-QlVUlMFu-FD73M3OO.js → effect-QlVUlMFu-XOJ2F4UA.js} +4 -4
- package/dist/{effect-QlVUlMFu-FD73M3OO.js.map → effect-QlVUlMFu-XOJ2F4UA.js.map} +1 -1
- package/dist/{esm-BLVTLTJW.js → esm-6TGK2CUM.js} +3 -3
- package/dist/esm-6TGK2CUM.js.map +1 -0
- package/dist/{esm-E3NUCNVN.cjs → esm-SQKX5ABS.cjs} +3 -3
- package/dist/esm-SQKX5ABS.cjs.map +1 -0
- package/dist/index.cjs +4 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -14
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +523 -87
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +521 -86
- package/dist/server/index.js.map +1 -1
- package/dist/server/types.d.ts +1 -1
- package/dist/server/types.d.ts.map +1 -1
- package/dist/sury-CWZTCd75-KEHKUXG7.cjs +17 -0
- package/dist/{sury-CWZTCd75-K3FHMZF5.cjs.map → sury-CWZTCd75-KEHKUXG7.cjs.map} +1 -1
- package/dist/{sury-CWZTCd75-Y2GURJ6K.js → sury-CWZTCd75-L2D76L25.js} +4 -4
- package/dist/{sury-CWZTCd75-Y2GURJ6K.js.map → sury-CWZTCd75-L2D76L25.js.map} +1 -1
- package/dist/typebox-Dei93FPO-LBLFC3RD.js +8 -0
- package/dist/{typebox-Dei93FPO-2WP4NOYD.js.map → typebox-Dei93FPO-LBLFC3RD.js.map} +1 -1
- package/dist/{typebox-Dei93FPO-WTXAW2LA.cjs → typebox-Dei93FPO-RDSW6DFA.cjs} +3 -3
- package/dist/{typebox-Dei93FPO-WTXAW2LA.cjs.map → typebox-Dei93FPO-RDSW6DFA.cjs.map} +1 -1
- package/dist/valibot--1zFm7rT-NVADAEQI.cjs +17 -0
- package/dist/{valibot--1zFm7rT-HMTCRBB3.cjs.map → valibot--1zFm7rT-NVADAEQI.cjs.map} +1 -1
- package/dist/{valibot--1zFm7rT-VGFBTDTW.js → valibot--1zFm7rT-R2UKWLZC.js} +4 -4
- package/dist/{valibot--1zFm7rT-VGFBTDTW.js.map → valibot--1zFm7rT-R2UKWLZC.js.map} +1 -1
- package/dist/{valibot-D_HTw1Gn-ILCWWLE4.cjs → valibot-D_HTw1Gn-DSFFOUBW.cjs} +7 -7
- package/dist/{valibot-D_HTw1Gn-ILCWWLE4.cjs.map → valibot-D_HTw1Gn-DSFFOUBW.cjs.map} +1 -1
- package/dist/{valibot-D_HTw1Gn-LLCGNU3W.js → valibot-D_HTw1Gn-KWXWP2TJ.js} +5 -5
- package/dist/{valibot-D_HTw1Gn-LLCGNU3W.js.map → valibot-D_HTw1Gn-KWXWP2TJ.js.map} +1 -1
- package/dist/validator/custom-resolver.cjs +2 -2
- package/dist/validator/custom-resolver.js +1 -1
- package/dist/{zod-Bwrt9trS-XCRGYQVE.js → zod-Bwrt9trS-GCUGPBJX.js} +5 -5
- package/dist/{zod-Bwrt9trS-XCRGYQVE.js.map → zod-Bwrt9trS-GCUGPBJX.js.map} +1 -1
- package/dist/{zod-Bwrt9trS-XDMWF3NW.cjs → zod-Bwrt9trS-ZZHFZ7YQ.cjs} +7 -7
- package/dist/{zod-Bwrt9trS-XDMWF3NW.cjs.map → zod-Bwrt9trS-ZZHFZ7YQ.cjs.map} +1 -1
- package/dist/{zod-DSgpEGAE-ZWQMF6SS.cjs → zod-DSgpEGAE-3CMS4FSB.cjs} +7 -7
- package/dist/{zod-DSgpEGAE-ZWQMF6SS.cjs.map → zod-DSgpEGAE-3CMS4FSB.cjs.map} +1 -1
- package/dist/{zod-DSgpEGAE-TKBHSSLS.js → zod-DSgpEGAE-IPE3O2NQ.js} +5 -5
- package/dist/{zod-DSgpEGAE-TKBHSSLS.js.map → zod-DSgpEGAE-IPE3O2NQ.js.map} +1 -1
- package/package.json +15 -15
- package/dist/arktype-aI7TBD0R-OEPFT4G6.js +0 -8
- package/dist/build/babel/get-deployer.d.ts +0 -3
- package/dist/build/babel/get-deployer.d.ts.map +0 -1
- package/dist/build/babel/remove-all-options-bundler.d.ts +0 -5
- package/dist/build/babel/remove-all-options-bundler.d.ts.map +0 -1
- package/dist/build/babel/remove-all-options-deployer.d.ts +0 -5
- package/dist/build/babel/remove-all-options-deployer.d.ts.map +0 -1
- package/dist/build/babel/remove-all-options-server.d.ts +0 -5
- package/dist/build/babel/remove-all-options-server.d.ts.map +0 -1
- package/dist/chunk-2OTEFUER.cjs.map +0 -1
- package/dist/chunk-5CWPEG6R.js +0 -62
- package/dist/chunk-5CWPEG6R.js.map +0 -1
- package/dist/chunk-BFQ2S5UD.cjs.map +0 -1
- package/dist/chunk-BTNPI4Z7.cjs +0 -4
- package/dist/chunk-FBT6QP7J.js +0 -3
- package/dist/chunk-ID3HN3BH.cjs +0 -16
- package/dist/chunk-MMUE22EL.js.map +0 -1
- package/dist/chunk-MUWNMVNL.cjs.map +0 -1
- package/dist/chunk-N5TMJUIR.js +0 -14
- package/dist/chunk-Q2YGWEXY.js +0 -6
- package/dist/chunk-RBPCXFN7.js.map +0 -1
- package/dist/chunk-SS22TD6R.cjs.map +0 -1
- package/dist/chunk-TK2CCU7I.js.map +0 -1
- package/dist/chunk-TXKETRIN.cjs.map +0 -1
- package/dist/chunk-UQZGTSBF.js.map +0 -1
- package/dist/chunk-X4TNUYQL.cjs +0 -196
- package/dist/chunk-X4TNUYQL.cjs.map +0 -1
- package/dist/chunk-X5QU7B2W.js +0 -169
- package/dist/chunk-X5QU7B2W.js.map +0 -1
- package/dist/default-u_dwuiYb-65M4BHAA.js +0 -3
- package/dist/default-u_dwuiYb-PWN6FHC6.cjs +0 -9
- package/dist/effect-QlVUlMFu-2ADPKIDF.cjs +0 -17
- package/dist/esm-BLVTLTJW.js.map +0 -1
- package/dist/esm-E3NUCNVN.cjs.map +0 -1
- package/dist/server/handlers/prompt.d.ts +0 -3
- package/dist/server/handlers/prompt.d.ts.map +0 -1
- package/dist/sury-CWZTCd75-K3FHMZF5.cjs +0 -17
- package/dist/typebox-Dei93FPO-2WP4NOYD.js +0 -8
- package/dist/valibot--1zFm7rT-HMTCRBB3.cjs +0 -17
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { slash, isDependencyPartOfPackage,
|
|
1
|
+
import { slash, isDependencyPartOfPackage, isBuiltinModule, getPackageName, getCompiledDepCachePath, rollupSafeName } from './chunk-QAOUDKHK.js';
|
|
2
2
|
import * as babel from '@babel/core';
|
|
3
3
|
import babel__default from '@babel/core';
|
|
4
4
|
import fs, { existsSync } from 'fs';
|
|
5
5
|
import { readFile, writeFile } from 'fs/promises';
|
|
6
6
|
import * as path2 from 'path';
|
|
7
|
-
import path2__default, { dirname, join, normalize, basename as basename$1 } from 'path';
|
|
7
|
+
import path2__default, { dirname, join, relative, normalize, basename as basename$1 } from 'path';
|
|
8
8
|
import { spawn as spawn$1 } from 'child_process';
|
|
9
|
+
import { pathToFileURL, fileURLToPath } from 'url';
|
|
9
10
|
import { rollup } from 'rollup';
|
|
10
11
|
import originalEsbuild from 'rollup-plugin-esbuild';
|
|
11
12
|
import commonjs from '@rollup/plugin-commonjs';
|
|
@@ -14,17 +15,16 @@ import stripJsonComments from 'strip-json-comments';
|
|
|
14
15
|
import { createHandler } from 'typescript-paths';
|
|
15
16
|
import { optimizeLodashImports } from '@optimize-lodash/rollup-plugin';
|
|
16
17
|
import json from '@rollup/plugin-json';
|
|
17
|
-
import { fileURLToPath, pathToFileURL } from 'url';
|
|
18
18
|
import * as pkg from 'empathic/package';
|
|
19
19
|
import { createWorkspacesCache, findWorkspaces, findWorkspacesRoot } from 'find-workspaces';
|
|
20
20
|
import { noopLogger } from '@mastra/core/logger';
|
|
21
21
|
import virtual from '@rollup/plugin-virtual';
|
|
22
22
|
import { builtinModules } from 'module';
|
|
23
|
+
import { getPackageInfo } from 'local-pkg';
|
|
23
24
|
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
24
25
|
import originalEsmShim from '@rollup/plugin-esm-shim';
|
|
25
26
|
import { basename } from 'path/posix';
|
|
26
27
|
import * as resolve from 'resolve.exports';
|
|
27
|
-
import { getPackageInfo } from 'local-pkg';
|
|
28
28
|
import { MastraBaseError, ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
29
29
|
|
|
30
30
|
var ValidationError = class extends Error {
|
|
@@ -95,7 +95,7 @@ globalThis.__dirname = dirname(__filename);
|
|
|
95
95
|
"--input-type=module",
|
|
96
96
|
"--enable-source-maps",
|
|
97
97
|
"-e",
|
|
98
|
-
`${prefixCode};import('
|
|
98
|
+
`${prefixCode};import('${pathToFileURL(file).href}').catch(err => {
|
|
99
99
|
${errorHandler.toString()}
|
|
100
100
|
errorHandler(err);
|
|
101
101
|
})`.replaceAll(/\n/g, "")
|
|
@@ -109,87 +109,6 @@ globalThis.__dirname = dirname(__filename);
|
|
|
109
109
|
}
|
|
110
110
|
);
|
|
111
111
|
}
|
|
112
|
-
function removeAllOptionsFromMastraExcept(result, option, logger) {
|
|
113
|
-
const t = babel__default.types;
|
|
114
|
-
return {
|
|
115
|
-
name: "remove-all-except-" + option + "-config",
|
|
116
|
-
visitor: {
|
|
117
|
-
ExportNamedDeclaration: {
|
|
118
|
-
// remove all exports
|
|
119
|
-
exit(path3) {
|
|
120
|
-
path3.remove();
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
NewExpression(path3, state) {
|
|
124
|
-
const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
|
|
125
|
-
if (!varDeclaratorPath) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const parentNode = path3.parentPath.node;
|
|
129
|
-
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
let mastraArgs = t.objectExpression([]);
|
|
133
|
-
if (t.isObjectExpression(path3.node.arguments[0])) {
|
|
134
|
-
mastraArgs = path3.node.arguments[0];
|
|
135
|
-
}
|
|
136
|
-
let configProperty = mastraArgs.properties.find(
|
|
137
|
-
// @ts-ignore
|
|
138
|
-
(prop) => prop.key.name === option
|
|
139
|
-
);
|
|
140
|
-
let configValue = t.objectExpression([]);
|
|
141
|
-
const programPath = path3.scope.getProgramParent().path;
|
|
142
|
-
if (!programPath) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {
|
|
146
|
-
result.hasCustomConfig = true;
|
|
147
|
-
configValue = configProperty.value;
|
|
148
|
-
if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {
|
|
149
|
-
const configBinding = state.file.scope.getBinding(option);
|
|
150
|
-
if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {
|
|
151
|
-
const id = path3.scope.generateUidIdentifier(option);
|
|
152
|
-
configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init));
|
|
153
|
-
configValue = id;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
const exportDeclaration = t.exportNamedDeclaration(
|
|
158
|
-
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), configValue)]),
|
|
159
|
-
[]
|
|
160
|
-
);
|
|
161
|
-
programPath.node.body.push(exportDeclaration);
|
|
162
|
-
},
|
|
163
|
-
Program: {
|
|
164
|
-
exit(path3) {
|
|
165
|
-
const hasExport = path3.node.body.some(
|
|
166
|
-
(node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
|
|
167
|
-
);
|
|
168
|
-
if (!hasExport) {
|
|
169
|
-
if (logger) {
|
|
170
|
-
logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
|
|
171
|
-
export const mastra = new Mastra({
|
|
172
|
-
${option}: <value>
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
`);
|
|
176
|
-
}
|
|
177
|
-
const fallbackExportDeclaration = t.exportNamedDeclaration(
|
|
178
|
-
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
|
|
179
|
-
[]
|
|
180
|
-
);
|
|
181
|
-
path3.node.body.push(fallbackExportDeclaration);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// src/build/babel/remove-all-options-bundler.ts
|
|
190
|
-
function removeAllOptionsExceptBundler(result, logger) {
|
|
191
|
-
return removeAllOptionsFromMastraExcept(result, "bundler", logger);
|
|
192
|
-
}
|
|
193
112
|
function esbuild(options = {}) {
|
|
194
113
|
return originalEsbuild({
|
|
195
114
|
target: "node20",
|
|
@@ -203,7 +122,7 @@ function hasPaths(tsConfigPath) {
|
|
|
203
122
|
try {
|
|
204
123
|
const content = fs.readFileSync(tsConfigPath, "utf8");
|
|
205
124
|
const config = JSON.parse(stripJsonComments(content));
|
|
206
|
-
return !!(config.compilerOptions?.paths && Object.keys(config.compilerOptions.paths).length > 0);
|
|
125
|
+
return !!(config.compilerOptions?.paths && Object.keys(config.compilerOptions.paths).length > 0 || typeof config.extends === "string" && config.extends.length > 0 || Array.isArray(config.extends) && config.extends.length > 0);
|
|
207
126
|
} catch {
|
|
208
127
|
return false;
|
|
209
128
|
}
|
|
@@ -407,7 +326,117 @@ function recursiveRemoveNonReferencedNodes(code) {
|
|
|
407
326
|
);
|
|
408
327
|
});
|
|
409
328
|
}
|
|
410
|
-
function
|
|
329
|
+
function removeAllOptionsFromMastraExcept(result, option, logger) {
|
|
330
|
+
const t = babel__default.types;
|
|
331
|
+
return {
|
|
332
|
+
name: "remove-all-except-" + option + "-config",
|
|
333
|
+
visitor: {
|
|
334
|
+
ExportNamedDeclaration: {
|
|
335
|
+
// remove all exports
|
|
336
|
+
exit(path3) {
|
|
337
|
+
path3.remove();
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
NewExpression(path3, state) {
|
|
341
|
+
const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
|
|
342
|
+
if (!varDeclaratorPath) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
const parentNode = path3.parentPath.node;
|
|
346
|
+
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
let mastraArgs = t.objectExpression([]);
|
|
350
|
+
if (t.isObjectExpression(path3.node.arguments[0])) {
|
|
351
|
+
mastraArgs = path3.node.arguments[0];
|
|
352
|
+
}
|
|
353
|
+
let configProperty = mastraArgs.properties.find(
|
|
354
|
+
(prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === option
|
|
355
|
+
);
|
|
356
|
+
let configValue = t.objectExpression([]);
|
|
357
|
+
const programPath = path3.scope.getProgramParent().path;
|
|
358
|
+
if (!programPath) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (configProperty && t.isObjectProperty(configProperty) && t.isExpression(configProperty.value)) {
|
|
362
|
+
result.hasCustomConfig = true;
|
|
363
|
+
configValue = configProperty.value;
|
|
364
|
+
if (t.isIdentifier(configProperty.value) && configProperty.value.name === option) {
|
|
365
|
+
const configBinding = state.file.scope.getBinding(option);
|
|
366
|
+
if (configBinding && t.isVariableDeclarator(configBinding.path.node)) {
|
|
367
|
+
const id = path3.scope.generateUidIdentifier(option);
|
|
368
|
+
configBinding.path.replaceWith(t.variableDeclarator(id, configBinding.path.node.init));
|
|
369
|
+
configValue = id;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const exportDeclaration = t.exportNamedDeclaration(
|
|
374
|
+
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), configValue)]),
|
|
375
|
+
[]
|
|
376
|
+
);
|
|
377
|
+
programPath.node.body.push(exportDeclaration);
|
|
378
|
+
},
|
|
379
|
+
Program: {
|
|
380
|
+
exit(path3) {
|
|
381
|
+
const hasExport = path3.node.body.some(
|
|
382
|
+
(node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
|
|
383
|
+
);
|
|
384
|
+
if (!hasExport) {
|
|
385
|
+
if (logger) {
|
|
386
|
+
logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
|
|
387
|
+
export const mastra = new Mastra({
|
|
388
|
+
${option}: <value>
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
`);
|
|
392
|
+
}
|
|
393
|
+
const fallbackExportDeclaration = t.exportNamedDeclaration(
|
|
394
|
+
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
|
|
395
|
+
[]
|
|
396
|
+
);
|
|
397
|
+
path3.node.body.push(fallbackExportDeclaration);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// src/build/plugins/remove-all-except.ts
|
|
406
|
+
function removeAllOptionsFromMastraExceptPlugin(mastraEntry, name, result, options) {
|
|
407
|
+
return {
|
|
408
|
+
name: `remove-${name}`,
|
|
409
|
+
transform(code, id) {
|
|
410
|
+
if (id !== mastraEntry) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
return new Promise((resolve2, reject) => {
|
|
414
|
+
babel.transform(
|
|
415
|
+
code,
|
|
416
|
+
{
|
|
417
|
+
babelrc: false,
|
|
418
|
+
configFile: false,
|
|
419
|
+
filename: id,
|
|
420
|
+
plugins: [removeAllOptionsFromMastraExcept(result, name, options?.logger)],
|
|
421
|
+
sourceMaps: options?.sourcemap
|
|
422
|
+
},
|
|
423
|
+
(err, result2) => {
|
|
424
|
+
if (err) {
|
|
425
|
+
return reject(err);
|
|
426
|
+
}
|
|
427
|
+
resolve2({
|
|
428
|
+
code: result2.code,
|
|
429
|
+
map: result2.map
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// src/build/shared/extract-mastra-option.ts
|
|
439
|
+
function extractMastraOptionBundler(name, entryFile, result, logger) {
|
|
411
440
|
return rollup({
|
|
412
441
|
logLevel: "silent",
|
|
413
442
|
input: {
|
|
@@ -428,34 +457,7 @@ function extractMastraOptionBundler(name, entryFile, transformer, result, logger
|
|
|
428
457
|
ignoreTryCatch: false
|
|
429
458
|
}),
|
|
430
459
|
json(),
|
|
431
|
-
{
|
|
432
|
-
name: `extract-${name}-config`,
|
|
433
|
-
transform(code, id) {
|
|
434
|
-
if (id !== entryFile) {
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
return new Promise((resolve2, reject) => {
|
|
438
|
-
babel.transform(
|
|
439
|
-
code,
|
|
440
|
-
{
|
|
441
|
-
babelrc: false,
|
|
442
|
-
configFile: false,
|
|
443
|
-
filename: id,
|
|
444
|
-
plugins: [transformer(result, logger)]
|
|
445
|
-
},
|
|
446
|
-
(err, result2) => {
|
|
447
|
-
if (err) {
|
|
448
|
-
return reject(err);
|
|
449
|
-
}
|
|
450
|
-
resolve2({
|
|
451
|
-
code: result2.code,
|
|
452
|
-
map: result2.map
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
);
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
},
|
|
460
|
+
removeAllOptionsFromMastraExceptPlugin(entryFile, name, result, { logger }),
|
|
459
461
|
// let esbuild remove all unused imports
|
|
460
462
|
esbuild(),
|
|
461
463
|
{
|
|
@@ -472,11 +474,11 @@ function extractMastraOptionBundler(name, entryFile, transformer, result, logger
|
|
|
472
474
|
]
|
|
473
475
|
});
|
|
474
476
|
}
|
|
475
|
-
async function extractMastraOption(name, entryFile,
|
|
477
|
+
async function extractMastraOption(name, entryFile, outputDir, logger) {
|
|
476
478
|
const result = {
|
|
477
479
|
hasCustomConfig: false
|
|
478
480
|
};
|
|
479
|
-
const bundler = await extractMastraOptionBundler(name, entryFile,
|
|
481
|
+
const bundler = await extractMastraOptionBundler(name, entryFile, result, logger);
|
|
480
482
|
const output = await bundler.write({
|
|
481
483
|
dir: outputDir,
|
|
482
484
|
format: "es",
|
|
@@ -494,13 +496,7 @@ async function extractMastraOption(name, entryFile, transformer, outputDir, logg
|
|
|
494
496
|
|
|
495
497
|
// src/build/bundlerOptions.ts
|
|
496
498
|
async function getBundlerOptions(entryFile, outputDir, logger) {
|
|
497
|
-
const result = await extractMastraOption(
|
|
498
|
-
"bundler",
|
|
499
|
-
entryFile,
|
|
500
|
-
removeAllOptionsExceptBundler,
|
|
501
|
-
outputDir,
|
|
502
|
-
logger
|
|
503
|
-
);
|
|
499
|
+
const result = await extractMastraOption("bundler", entryFile, outputDir, logger);
|
|
504
500
|
if (!result) {
|
|
505
501
|
return null;
|
|
506
502
|
}
|
|
@@ -569,8 +565,57 @@ function isNodeBuiltin(dep) {
|
|
|
569
565
|
const [pkg2] = dep.split("/");
|
|
570
566
|
return dep.startsWith("node:") || builtinModules.includes(dep) || builtinModules.includes(pkg2);
|
|
571
567
|
}
|
|
568
|
+
async function getPackageRootPath(packageName, parentPath) {
|
|
569
|
+
let rootPath;
|
|
570
|
+
try {
|
|
571
|
+
let options = void 0;
|
|
572
|
+
if (parentPath) {
|
|
573
|
+
if (!parentPath.startsWith("file://")) {
|
|
574
|
+
parentPath = pathToFileURL(parentPath).href;
|
|
575
|
+
}
|
|
576
|
+
options = {
|
|
577
|
+
paths: [parentPath]
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
const pkg2 = await getPackageInfo(packageName, options);
|
|
581
|
+
rootPath = pkg2?.rootPath ?? null;
|
|
582
|
+
} catch (e) {
|
|
583
|
+
rootPath = null;
|
|
584
|
+
}
|
|
585
|
+
return rootPath;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// src/build/analyze/constants.ts
|
|
589
|
+
var DEPS_TO_IGNORE = ["#tools"];
|
|
590
|
+
var GLOBAL_EXTERNALS = [
|
|
591
|
+
"pino",
|
|
592
|
+
"pino-pretty",
|
|
593
|
+
"@libsql/client",
|
|
594
|
+
"pg",
|
|
595
|
+
"libsql",
|
|
596
|
+
"#tools",
|
|
597
|
+
"typescript",
|
|
598
|
+
"undici",
|
|
599
|
+
"readable-stream"
|
|
600
|
+
];
|
|
601
|
+
var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
|
|
572
602
|
function removeDeployer() {
|
|
573
603
|
const t = babel__default.types;
|
|
604
|
+
function removeDeployerFromObject(objectExpr, scope) {
|
|
605
|
+
const deployerProp = objectExpr.properties.find(
|
|
606
|
+
(prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
|
|
607
|
+
);
|
|
608
|
+
if (deployerProp) {
|
|
609
|
+
objectExpr.properties = objectExpr.properties.filter((prop) => prop !== deployerProp);
|
|
610
|
+
if (t.isIdentifier(deployerProp.value)) {
|
|
611
|
+
const deployerBinding = scope.getBinding(deployerProp.value.name);
|
|
612
|
+
if (deployerBinding) {
|
|
613
|
+
deployerBinding.path?.parentPath?.remove();
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return deployerProp;
|
|
618
|
+
}
|
|
574
619
|
return {
|
|
575
620
|
name: "remove-deployer",
|
|
576
621
|
visitor: {
|
|
@@ -586,23 +631,30 @@ function removeDeployer() {
|
|
|
586
631
|
if (!state.hasReplaced) {
|
|
587
632
|
state.hasReplaced = true;
|
|
588
633
|
const newMastraObj = t.cloneNode(path3.node);
|
|
589
|
-
if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.
|
|
590
|
-
const
|
|
591
|
-
|
|
592
|
-
);
|
|
593
|
-
if (
|
|
594
|
-
|
|
634
|
+
if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.length) {
|
|
635
|
+
const objectArg = newMastraObj.arguments[0];
|
|
636
|
+
let foundDeployer = false;
|
|
637
|
+
const directDeployer = removeDeployerFromObject(objectArg, state.file.scope);
|
|
638
|
+
if (directDeployer) {
|
|
639
|
+
foundDeployer = true;
|
|
595
640
|
}
|
|
596
|
-
|
|
597
|
-
(prop)
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
641
|
+
for (const prop of objectArg.properties) {
|
|
642
|
+
if (t.isSpreadElement(prop) && t.isIdentifier(prop.argument)) {
|
|
643
|
+
const spreadBinding = state.file.scope.getBinding(prop.argument.name);
|
|
644
|
+
if (spreadBinding?.path && t.isVariableDeclarator(spreadBinding.path.node)) {
|
|
645
|
+
const init = spreadBinding.path.node.init;
|
|
646
|
+
if (t.isObjectExpression(init)) {
|
|
647
|
+
const spreadDeployer = removeDeployerFromObject(init, state.file.scope);
|
|
648
|
+
if (spreadDeployer) {
|
|
649
|
+
foundDeployer = true;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
603
653
|
}
|
|
604
654
|
}
|
|
605
|
-
|
|
655
|
+
if (foundDeployer) {
|
|
656
|
+
path3.replaceWith(newMastraObj);
|
|
657
|
+
}
|
|
606
658
|
}
|
|
607
659
|
}
|
|
608
660
|
}
|
|
@@ -643,21 +695,6 @@ function removeDeployer2(mastraEntry, options) {
|
|
|
643
695
|
};
|
|
644
696
|
}
|
|
645
697
|
|
|
646
|
-
// src/build/analyze/constants.ts
|
|
647
|
-
var DEPS_TO_IGNORE = ["#tools"];
|
|
648
|
-
var GLOBAL_EXTERNALS = [
|
|
649
|
-
"pino",
|
|
650
|
-
"pino-pretty",
|
|
651
|
-
"@libsql/client",
|
|
652
|
-
"pg",
|
|
653
|
-
"libsql",
|
|
654
|
-
"#tools",
|
|
655
|
-
"typescript",
|
|
656
|
-
"undici",
|
|
657
|
-
"readable-stream"
|
|
658
|
-
];
|
|
659
|
-
var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
|
|
660
|
-
|
|
661
698
|
// src/build/analyze/analyzeEntry.ts
|
|
662
699
|
function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
|
|
663
700
|
const normalizedMastraEntry = slash(mastraEntry);
|
|
@@ -697,7 +734,9 @@ function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabl
|
|
|
697
734
|
transformMixedEsModules: true,
|
|
698
735
|
extensions: [".js", ".ts"]
|
|
699
736
|
}),
|
|
700
|
-
removeDeployer2(mastraEntry, {
|
|
737
|
+
removeDeployer2(mastraEntry, {
|
|
738
|
+
sourcemap: sourcemapEnabled
|
|
739
|
+
}),
|
|
701
740
|
esbuild()
|
|
702
741
|
]
|
|
703
742
|
);
|
|
@@ -987,7 +1026,7 @@ function createVirtualDependencies(depsToOptimize, {
|
|
|
987
1026
|
outputDir,
|
|
988
1027
|
bundlerOptions
|
|
989
1028
|
}) {
|
|
990
|
-
const { isDev = false } = bundlerOptions || {};
|
|
1029
|
+
const { isDev = false, externalsPreset = false } = bundlerOptions || {};
|
|
991
1030
|
const fileNameToDependencyMap = /* @__PURE__ */ new Map();
|
|
992
1031
|
const optimizedDependencyEntries = /* @__PURE__ */ new Map();
|
|
993
1032
|
const rootDir = workspaceRoot || projectRoot;
|
|
@@ -1019,7 +1058,7 @@ function createVirtualDependencies(depsToOptimize, {
|
|
|
1019
1058
|
virtual: virtualFile.join("\n")
|
|
1020
1059
|
});
|
|
1021
1060
|
}
|
|
1022
|
-
if (isDev) {
|
|
1061
|
+
if (isDev || externalsPreset) {
|
|
1023
1062
|
for (const [dep, { isWorkspace, rootPath }] of depsToOptimize.entries()) {
|
|
1024
1063
|
if (!isWorkspace || !rootPath || !workspaceRoot) {
|
|
1025
1064
|
continue;
|
|
@@ -1076,7 +1115,7 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
1076
1115
|
}
|
|
1077
1116
|
})
|
|
1078
1117
|
}) : null,
|
|
1079
|
-
bundlerOptions.
|
|
1118
|
+
bundlerOptions.noBundling ? {
|
|
1080
1119
|
name: "alias-optimized-deps",
|
|
1081
1120
|
async resolveId(id, importer, options) {
|
|
1082
1121
|
if (!virtualDependencies.has(id)) {
|
|
@@ -1106,11 +1145,11 @@ async function getInputPlugins2(virtualDependencies, {
|
|
|
1106
1145
|
transformMixedEsModules: true,
|
|
1107
1146
|
ignoreTryCatch: false
|
|
1108
1147
|
}),
|
|
1109
|
-
bundlerOptions.
|
|
1148
|
+
bundlerOptions.noBundling ? null : nodeResolve({
|
|
1110
1149
|
preferBuiltins: true,
|
|
1111
1150
|
exportConditions: ["node"]
|
|
1112
1151
|
}),
|
|
1113
|
-
bundlerOptions.
|
|
1152
|
+
bundlerOptions.noBundling ? esmShim() : null,
|
|
1114
1153
|
// hono is imported from deployer, so we need to resolve from here instead of the project root
|
|
1115
1154
|
aliasHono(),
|
|
1116
1155
|
json(),
|
|
@@ -1163,6 +1202,16 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1163
1202
|
if (virtualDependencies.size === 0) {
|
|
1164
1203
|
return [];
|
|
1165
1204
|
}
|
|
1205
|
+
const noBundling = bundlerOptions.isDev || bundlerOptions.externalsPreset;
|
|
1206
|
+
const plugins = await getInputPlugins2(virtualDependencies, {
|
|
1207
|
+
transpilePackages: packagesToTranspile,
|
|
1208
|
+
workspaceMap,
|
|
1209
|
+
bundlerOptions: {
|
|
1210
|
+
noBundling
|
|
1211
|
+
},
|
|
1212
|
+
rootDir,
|
|
1213
|
+
externals
|
|
1214
|
+
});
|
|
1166
1215
|
const bundler = await rollup({
|
|
1167
1216
|
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
1168
1217
|
input: Array.from(virtualDependencies.entries()).reduce(
|
|
@@ -1173,14 +1222,8 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1173
1222
|
{}
|
|
1174
1223
|
),
|
|
1175
1224
|
external: externals,
|
|
1176
|
-
treeshake:
|
|
1177
|
-
plugins
|
|
1178
|
-
transpilePackages: packagesToTranspile,
|
|
1179
|
-
workspaceMap,
|
|
1180
|
-
bundlerOptions,
|
|
1181
|
-
rootDir,
|
|
1182
|
-
externals
|
|
1183
|
-
})
|
|
1225
|
+
treeshake: noBundling ? false : "safest",
|
|
1226
|
+
plugins
|
|
1184
1227
|
});
|
|
1185
1228
|
const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
|
|
1186
1229
|
const { output } = await bundler.write({
|
|
@@ -1194,7 +1237,7 @@ async function buildExternalDependencies(virtualDependencies, {
|
|
|
1194
1237
|
* So we want to write them to the `.mastra/output` folder as well.
|
|
1195
1238
|
*/
|
|
1196
1239
|
chunkFileNames: (chunkInfo) => {
|
|
1197
|
-
if (
|
|
1240
|
+
if (noBundling) {
|
|
1198
1241
|
const importedFromPackages = /* @__PURE__ */ new Set();
|
|
1199
1242
|
for (const moduleId of chunkInfo.moduleIds) {
|
|
1200
1243
|
const normalized = slash(moduleId);
|
|
@@ -1256,19 +1299,31 @@ function findExternalImporter(module, external, allOutputs) {
|
|
|
1256
1299
|
}
|
|
1257
1300
|
async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
1258
1301
|
const { workspaceRoot = null, workspaceMap = /* @__PURE__ */ new Map(), projectRoot = outputDir, bundlerOptions = {} } = options;
|
|
1259
|
-
const {
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1302
|
+
const { externals: customExternals = [], transpilePackages = [], isDev = false } = bundlerOptions || {};
|
|
1303
|
+
let externalsPreset = false;
|
|
1304
|
+
if (customExternals === true) {
|
|
1305
|
+
externalsPreset = true;
|
|
1306
|
+
}
|
|
1307
|
+
const externalsList = Array.isArray(customExternals) ? customExternals : [];
|
|
1308
|
+
const allExternals = [...GLOBAL_EXTERNALS, ...DEPRECATED_EXTERNALS, ...externalsList];
|
|
1264
1309
|
const workspacePackagesNames = Array.from(workspaceMap.keys());
|
|
1265
1310
|
const packagesToTranspile = /* @__PURE__ */ new Set([...transpilePackages, ...workspacePackagesNames]);
|
|
1311
|
+
const extractedExternals = /* @__PURE__ */ new Map();
|
|
1312
|
+
if (externalsPreset) {
|
|
1313
|
+
for (const [dep, metadata] of depsToOptimize.entries()) {
|
|
1314
|
+
if (!metadata.isWorkspace) {
|
|
1315
|
+
extractedExternals.set(dep, metadata.rootPath ?? dep);
|
|
1316
|
+
depsToOptimize.delete(dep);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1266
1320
|
const { optimizedDependencyEntries, fileNameToDependencyMap } = createVirtualDependencies(depsToOptimize, {
|
|
1267
1321
|
workspaceRoot,
|
|
1268
1322
|
outputDir,
|
|
1269
1323
|
projectRoot,
|
|
1270
1324
|
bundlerOptions: {
|
|
1271
|
-
isDev
|
|
1325
|
+
isDev,
|
|
1326
|
+
externalsPreset
|
|
1272
1327
|
}
|
|
1273
1328
|
});
|
|
1274
1329
|
const output = await buildExternalDependencies(optimizedDependencyEntries, {
|
|
@@ -1278,7 +1333,8 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1278
1333
|
rootDir: workspaceRoot || projectRoot,
|
|
1279
1334
|
outputDir,
|
|
1280
1335
|
bundlerOptions: {
|
|
1281
|
-
isDev
|
|
1336
|
+
isDev,
|
|
1337
|
+
externalsPreset
|
|
1282
1338
|
}
|
|
1283
1339
|
});
|
|
1284
1340
|
const moduleResolveMap2 = /* @__PURE__ */ new Map();
|
|
@@ -1313,6 +1369,14 @@ async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
|
1313
1369
|
}
|
|
1314
1370
|
usedExternals[fullPath] = innerObj;
|
|
1315
1371
|
}
|
|
1372
|
+
if (extractedExternals.size > 0) {
|
|
1373
|
+
const syntheticPath = path2.join(workspaceRoot || projectRoot, "__externals__");
|
|
1374
|
+
const externalsObj = /* @__PURE__ */ Object.create(null);
|
|
1375
|
+
for (const [dep, rootPath] of extractedExternals) {
|
|
1376
|
+
externalsObj[dep] = rootPath;
|
|
1377
|
+
}
|
|
1378
|
+
usedExternals[syntheticPath] = externalsObj;
|
|
1379
|
+
}
|
|
1316
1380
|
return { output, fileNameToDependencyMap, usedExternals };
|
|
1317
1381
|
}
|
|
1318
1382
|
|
|
@@ -1588,7 +1652,7 @@ async function analyzeBundle(entries, mastraEntry, {
|
|
|
1588
1652
|
outputDir,
|
|
1589
1653
|
projectRoot,
|
|
1590
1654
|
isDev = false,
|
|
1591
|
-
bundlerOptions
|
|
1655
|
+
bundlerOptions
|
|
1592
1656
|
}, logger) {
|
|
1593
1657
|
const mastraConfig = await readFile(mastraEntry, "utf-8");
|
|
1594
1658
|
const mastraConfigResult = {
|
|
@@ -1607,28 +1671,30 @@ export const mastra = new Mastra({
|
|
|
1607
1671
|
|
|
1608
1672
|
If you think your configuration is valid, please open an issue.`);
|
|
1609
1673
|
}
|
|
1610
|
-
const { enableEsmShim = true } = _bundlerOptions || {};
|
|
1611
|
-
const bundlerOptions = await getBundlerOptions(mastraEntry, outputDir);
|
|
1612
1674
|
const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
|
|
1675
|
+
let externalsPreset = false;
|
|
1676
|
+
const userExternals = Array.isArray(bundlerOptions?.externals) ? bundlerOptions?.externals : [];
|
|
1677
|
+
if (bundlerOptions?.externals === true) {
|
|
1678
|
+
externalsPreset = true;
|
|
1679
|
+
}
|
|
1613
1680
|
let index = 0;
|
|
1614
1681
|
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
1615
|
-
const
|
|
1616
|
-
const allExternals = [...GLOBAL_EXTERNALS, ...customExternals];
|
|
1682
|
+
const allExternals = [...GLOBAL_EXTERNALS, ...userExternals].filter(Boolean);
|
|
1617
1683
|
logger.info("Analyzing dependencies...");
|
|
1618
1684
|
const allUsedExternals = /* @__PURE__ */ new Set();
|
|
1619
1685
|
for (const entry of entries) {
|
|
1620
1686
|
const isVirtualFile = entry.includes("\n") || !existsSync(entry);
|
|
1621
1687
|
const analyzeResult = await analyzeEntry({ entry, isVirtualFile }, mastraEntry, {
|
|
1622
1688
|
logger,
|
|
1623
|
-
sourcemapEnabled: bundlerOptions?.
|
|
1689
|
+
sourcemapEnabled: bundlerOptions?.enableSourcemap ?? false,
|
|
1624
1690
|
workspaceMap,
|
|
1625
1691
|
projectRoot,
|
|
1626
|
-
shouldCheckTransitiveDependencies: isDev
|
|
1692
|
+
shouldCheckTransitiveDependencies: isDev || externalsPreset
|
|
1627
1693
|
});
|
|
1628
1694
|
await writeFile(join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
|
|
1629
1695
|
for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
|
|
1630
1696
|
const isPartOfExternals = allExternals.some((external) => isDependencyPartOfPackage(dep, external));
|
|
1631
|
-
if (isPartOfExternals) {
|
|
1697
|
+
if (isPartOfExternals || externalsPreset && !metadata.isWorkspace) {
|
|
1632
1698
|
allUsedExternals.add(dep);
|
|
1633
1699
|
continue;
|
|
1634
1700
|
}
|
|
@@ -1643,7 +1709,7 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1643
1709
|
}
|
|
1644
1710
|
}
|
|
1645
1711
|
}
|
|
1646
|
-
if (isDev) {
|
|
1712
|
+
if (isDev || externalsPreset) {
|
|
1647
1713
|
for (const [dep, metadata] of depsToOptimize.entries()) {
|
|
1648
1714
|
if (!metadata.isWorkspace) {
|
|
1649
1715
|
depsToOptimize.delete(dep);
|
|
@@ -1656,14 +1722,36 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1656
1722
|
const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
|
|
1657
1723
|
bundlerOptions: {
|
|
1658
1724
|
...bundlerOptions,
|
|
1659
|
-
externals: allExternals,
|
|
1660
|
-
enableEsmShim,
|
|
1725
|
+
externals: bundlerOptions?.externals ?? allExternals,
|
|
1661
1726
|
isDev
|
|
1662
1727
|
},
|
|
1663
1728
|
projectRoot,
|
|
1664
1729
|
workspaceRoot,
|
|
1665
1730
|
workspaceMap
|
|
1666
1731
|
});
|
|
1732
|
+
const relativeWorkspaceFolderPaths = Array.from(workspaceMap.values()).map(
|
|
1733
|
+
(pkgInfo) => relative(workspaceRoot || projectRoot, pkgInfo.location)
|
|
1734
|
+
);
|
|
1735
|
+
for (const o of output) {
|
|
1736
|
+
if (o.type === "asset") {
|
|
1737
|
+
continue;
|
|
1738
|
+
}
|
|
1739
|
+
for (const i of o.imports) {
|
|
1740
|
+
if (isBuiltinModule(i)) {
|
|
1741
|
+
continue;
|
|
1742
|
+
}
|
|
1743
|
+
if (i.startsWith(".") || i.startsWith("/")) {
|
|
1744
|
+
continue;
|
|
1745
|
+
}
|
|
1746
|
+
if (relativeWorkspaceFolderPaths.some((workspacePath) => i.startsWith(workspacePath))) {
|
|
1747
|
+
continue;
|
|
1748
|
+
}
|
|
1749
|
+
const pkgName = getPackageName(i);
|
|
1750
|
+
if (pkgName) {
|
|
1751
|
+
allUsedExternals.add(pkgName);
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1667
1755
|
const result = await validateOutput(
|
|
1668
1756
|
{
|
|
1669
1757
|
output,
|
|
@@ -1681,6 +1769,6 @@ If you think your configuration is valid, please open an issue.`);
|
|
|
1681
1769
|
};
|
|
1682
1770
|
}
|
|
1683
1771
|
|
|
1684
|
-
export { aliasHono, analyzeBundle, esbuild, esmShim, extractMastraOption, getBundlerOptions,
|
|
1685
|
-
//# sourceMappingURL=chunk-
|
|
1686
|
-
//# sourceMappingURL=chunk-
|
|
1772
|
+
export { aliasHono, analyzeBundle, esbuild, esmShim, extractMastraOption, getBundlerOptions, getPackageRootPath, getWorkspaceInformation, removeDeployer2 as removeDeployer, subpathExternalsResolver, tsConfigPaths };
|
|
1773
|
+
//# sourceMappingURL=chunk-HWSYWSD7.js.map
|
|
1774
|
+
//# sourceMappingURL=chunk-HWSYWSD7.js.map
|