@mastra/deployer 0.0.0-error-handler-fix-20251020202607 → 0.0.0-execa-dynamic-import-20260304221256
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 +1850 -5
- package/LICENSE.md +15 -0
- package/dist/arktype-aI7TBD0R-MD6ESOAI.js +8 -0
- package/dist/arktype-aI7TBD0R-MD6ESOAI.js.map +1 -0
- package/dist/arktype-aI7TBD0R-MS2OLT4Z.cjs +10 -0
- package/dist/arktype-aI7TBD0R-MS2OLT4Z.cjs.map +1 -0
- package/dist/build/analyze/analyzeEntry.d.ts +8 -4
- package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
- package/dist/build/analyze/bundleExternals.d.ts +8 -7
- package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
- package/dist/build/analyze/constants.d.ts.map +1 -1
- package/dist/build/analyze.cjs +2 -2
- package/dist/build/analyze.d.ts +7 -7
- package/dist/build/analyze.d.ts.map +1 -1
- package/dist/build/analyze.js +1 -1
- package/dist/build/babel/remove-all-options-except.d.ts +1 -1
- package/dist/build/babel/remove-all-options-except.d.ts.map +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 +5 -3
- package/dist/build/bundler.d.ts.map +1 -1
- package/dist/build/bundler.js +1 -1
- package/dist/build/bundlerOptions.d.ts +1 -1
- package/dist/build/bundlerOptions.d.ts.map +1 -1
- package/dist/build/deployer.d.ts +1 -1
- package/dist/build/deployer.d.ts.map +1 -1
- package/dist/build/index.cjs +31 -22
- package/dist/build/index.d.ts +2 -1
- package/dist/build/index.d.ts.map +1 -1
- package/dist/build/index.js +6 -5
- package/dist/build/package-info.d.ts +9 -0
- package/dist/build/package-info.d.ts.map +1 -0
- package/dist/build/plugins/esm-shim.d.ts +14 -0
- package/dist/build/plugins/esm-shim.d.ts.map +1 -0
- package/dist/build/plugins/module-resolve-map.d.ts +3 -0
- package/dist/build/plugins/module-resolve-map.d.ts.map +1 -0
- package/dist/build/plugins/node-gyp-detector.d.ts +3 -0
- package/dist/build/plugins/node-gyp-detector.d.ts.map +1 -0
- package/dist/build/plugins/node-modules-extension-resolver.d.ts +7 -0
- package/dist/build/plugins/node-modules-extension-resolver.d.ts.map +1 -1
- package/dist/build/plugins/pino.d.ts.map +1 -1
- package/dist/build/plugins/remove-all-except.d.ts +10 -0
- package/dist/build/plugins/remove-all-except.d.ts.map +1 -0
- package/dist/build/plugins/subpath-externals-resolver.d.ts +3 -0
- package/dist/build/plugins/subpath-externals-resolver.d.ts.map +1 -0
- package/dist/build/plugins/tsconfig-paths.d.ts +8 -0
- package/dist/build/plugins/tsconfig-paths.d.ts.map +1 -1
- package/dist/build/serverOptions.d.ts +1 -1
- package/dist/build/serverOptions.d.ts.map +1 -1
- package/dist/build/shared/extract-mastra-option.d.ts +5 -9
- package/dist/build/shared/extract-mastra-option.d.ts.map +1 -1
- package/dist/build/types.d.ts +18 -0
- package/dist/build/types.d.ts.map +1 -1
- package/dist/build/utils.d.ts +79 -4
- package/dist/build/utils.d.ts.map +1 -1
- package/dist/build/watcher.d.ts +4 -1
- package/dist/build/watcher.d.ts.map +1 -1
- package/dist/bundler/index.cjs +6 -2
- package/dist/bundler/index.d.ts +13 -10
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/index.js +1 -1
- package/dist/chunk-32UHMKRP.cjs +95 -0
- package/dist/chunk-32UHMKRP.cjs.map +1 -0
- package/dist/chunk-6UIXBIO6.js +1322 -0
- package/dist/chunk-6UIXBIO6.js.map +1 -0
- package/dist/chunk-73SEUI3W.cjs +1353 -0
- package/dist/chunk-73SEUI3W.cjs.map +1 -0
- package/dist/chunk-ANF3UFZ3.js +318 -0
- package/dist/chunk-ANF3UFZ3.js.map +1 -0
- package/dist/{chunk-5QFG6SCM.js → chunk-DPDWM7HQ.js} +2 -2
- package/dist/chunk-DPDWM7HQ.js.map +1 -0
- package/dist/chunk-EBHDMP6N.cjs +122 -0
- package/dist/chunk-EBHDMP6N.cjs.map +1 -0
- package/dist/{chunk-WAWEQ3DP.js → chunk-EZBW45SX.js} +72 -32
- package/dist/chunk-EZBW45SX.js.map +1 -0
- package/dist/chunk-G7R456H2.cjs +108 -0
- package/dist/chunk-G7R456H2.cjs.map +1 -0
- package/dist/chunk-IMLDKOVJ.js +98 -0
- package/dist/chunk-IMLDKOVJ.js.map +1 -0
- package/dist/chunk-JNSGICDP.js +159 -0
- package/dist/chunk-JNSGICDP.js.map +1 -0
- package/dist/{chunk-3JYRSECU.cjs → chunk-JVBCN3RH.cjs} +4 -4
- package/dist/chunk-JVBCN3RH.cjs.map +1 -0
- package/dist/{chunk-LGC3GUMR.cjs → chunk-MEHKYO3L.cjs} +89 -153
- package/dist/chunk-MEHKYO3L.cjs.map +1 -0
- package/dist/chunk-NQTC7BHX.cjs +4 -0
- package/dist/chunk-NQTC7BHX.cjs.map +1 -0
- package/dist/chunk-O73YCD6A.js +262 -0
- package/dist/chunk-O73YCD6A.js.map +1 -0
- package/dist/chunk-PF6MO6L3.cjs +162 -0
- package/dist/chunk-PF6MO6L3.cjs.map +1 -0
- package/dist/{chunk-HMMDNIEQ.cjs → chunk-R2SYO6PH.cjs} +79 -39
- package/dist/chunk-R2SYO6PH.cjs.map +1 -0
- package/dist/chunk-TFSGAJE4.cjs +16 -0
- package/dist/chunk-TFSGAJE4.cjs.map +1 -0
- package/dist/chunk-UCL7MHBL.js +93 -0
- package/dist/chunk-UCL7MHBL.js.map +1 -0
- package/dist/chunk-UPVHAZ5Q.cjs +288 -0
- package/dist/chunk-UPVHAZ5Q.cjs.map +1 -0
- package/dist/chunk-UQZFTY5Q.cjs +8 -0
- package/dist/chunk-UQZFTY5Q.cjs.map +1 -0
- package/dist/{chunk-465ZVXAK.js → chunk-USX4L64H.js} +83 -146
- package/dist/chunk-USX4L64H.js.map +1 -0
- package/dist/chunk-V3HWDUN7.js +6 -0
- package/dist/chunk-V3HWDUN7.js.map +1 -0
- package/dist/chunk-WGU72NH4.js +14 -0
- package/dist/chunk-WGU72NH4.js.map +1 -0
- package/dist/chunk-XN3FKMO6.js +97 -0
- package/dist/chunk-XN3FKMO6.js.map +1 -0
- package/dist/chunk-YEOQZ6LM.js +3 -0
- package/dist/chunk-YEOQZ6LM.js.map +1 -0
- package/dist/chunk-YIUDHDPS.cjs +351 -0
- package/dist/chunk-YIUDHDPS.cjs.map +1 -0
- package/dist/default-u_dwuiYb-BOJNVDPF.js +3 -0
- package/dist/default-u_dwuiYb-BOJNVDPF.js.map +1 -0
- package/dist/default-u_dwuiYb-HYOFMURU.cjs +9 -0
- package/dist/default-u_dwuiYb-HYOFMURU.cjs.map +1 -0
- package/dist/deploy/log.d.ts +1 -1
- package/dist/deploy/log.d.ts.map +1 -1
- package/dist/docs/SKILL.md +31 -0
- package/dist/docs/assets/SOURCE_MAP.json +27 -0
- package/dist/docs/references/docs-deployment-cloud-providers.md +15 -0
- package/dist/docs/references/docs-deployment-mastra-server.md +122 -0
- package/dist/docs/references/docs-deployment-monorepo.md +142 -0
- package/dist/docs/references/docs-deployment-overview.md +62 -0
- package/dist/docs/references/docs-deployment-web-framework.md +52 -0
- package/dist/docs/references/docs-deployment-workflow-runners.md +9 -0
- package/dist/docs/references/reference-deployer.md +100 -0
- package/dist/effect-QlVUlMFu-FWNF43NY.cjs +17 -0
- package/dist/effect-QlVUlMFu-FWNF43NY.cjs.map +1 -0
- package/dist/effect-QlVUlMFu-UDX7FFQO.js +15 -0
- package/dist/effect-QlVUlMFu-UDX7FFQO.js.map +1 -0
- package/dist/esm-6PM2YB3Y.cjs +1336 -0
- package/dist/esm-6PM2YB3Y.cjs.map +1 -0
- package/dist/esm-CAB7GAHT.js +1289 -0
- package/dist/esm-CAB7GAHT.js.map +1 -0
- package/dist/index.cjs +11 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -16
- package/dist/index.js.map +1 -1
- package/dist/server/handlers/a2a.d.ts +1 -1
- package/dist/server/handlers/health.d.ts +5 -0
- package/dist/server/handlers/health.d.ts.map +1 -0
- package/dist/server/handlers/restart-active-runs.d.ts +3 -0
- package/dist/server/handlers/restart-active-runs.d.ts.map +1 -0
- package/dist/server/handlers/utils/query-parsers.d.ts +15 -0
- package/dist/server/handlers/utils/query-parsers.d.ts.map +1 -1
- package/dist/server/handlers/utils.d.ts +0 -7
- package/dist/server/handlers/utils.d.ts.map +1 -1
- package/dist/server/index.cjs +2983 -10849
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +3 -12
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2983 -10850
- package/dist/server/index.js.map +1 -1
- package/dist/server/types.d.ts +1 -1
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/welcome.d.ts +1 -1
- package/dist/server/welcome.d.ts.map +1 -1
- package/dist/services/index.cjs +4 -4
- package/dist/services/index.js +1 -1
- package/dist/sury-CWZTCd75-2U3FQUNZ.cjs +17 -0
- package/dist/sury-CWZTCd75-2U3FQUNZ.cjs.map +1 -0
- package/dist/sury-CWZTCd75-52HHC6OD.js +15 -0
- package/dist/sury-CWZTCd75-52HHC6OD.js.map +1 -0
- package/dist/typebox-Dei93FPO-EBJ4ULZC.cjs +10 -0
- package/dist/typebox-Dei93FPO-EBJ4ULZC.cjs.map +1 -0
- package/dist/typebox-Dei93FPO-TURR2FV5.js +8 -0
- package/dist/typebox-Dei93FPO-TURR2FV5.js.map +1 -0
- package/dist/valibot--1zFm7rT-KH26NMFX.cjs +17 -0
- package/dist/valibot--1zFm7rT-KH26NMFX.cjs.map +1 -0
- package/dist/valibot--1zFm7rT-O4VBDBTD.js +15 -0
- package/dist/valibot--1zFm7rT-O4VBDBTD.js.map +1 -0
- package/dist/valibot-D_HTw1Gn-EVIH6VOI.js +43 -0
- package/dist/valibot-D_HTw1Gn-EVIH6VOI.js.map +1 -0
- package/dist/valibot-D_HTw1Gn-YHTB53Q2.cjs +45 -0
- package/dist/valibot-D_HTw1Gn-YHTB53Q2.cjs.map +1 -0
- package/dist/validator/custom-resolver.cjs +46 -12
- package/dist/validator/custom-resolver.cjs.map +1 -1
- package/dist/validator/custom-resolver.d.ts +15 -1
- package/dist/validator/custom-resolver.d.ts.map +1 -1
- package/dist/validator/custom-resolver.js +44 -11
- package/dist/validator/custom-resolver.js.map +1 -1
- package/dist/validator/validate.d.ts +16 -1
- package/dist/validator/validate.d.ts.map +1 -1
- package/dist/zod-Bwrt9trS-SFESLKHY.cjs +31 -0
- package/dist/zod-Bwrt9trS-SFESLKHY.cjs.map +1 -0
- package/dist/zod-Bwrt9trS-UDJPKIQS.js +29 -0
- package/dist/zod-Bwrt9trS-UDJPKIQS.js.map +1 -0
- package/dist/zod-DSgpEGAE-3CP5FXLX.cjs +39 -0
- package/dist/zod-DSgpEGAE-3CP5FXLX.cjs.map +1 -0
- package/dist/zod-DSgpEGAE-EQI5QBJK.js +37 -0
- package/dist/zod-DSgpEGAE-EQI5QBJK.js.map +1 -0
- package/package.json +34 -35
- 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/build/babel/remove-all-options-telemetry.d.ts +0 -5
- package/dist/build/babel/remove-all-options-telemetry.d.ts.map +0 -1
- package/dist/build/customInstrumentation.d.ts +0 -10
- package/dist/build/customInstrumentation.d.ts.map +0 -1
- package/dist/build/telemetry.d.ts +0 -8
- package/dist/build/telemetry.d.ts.map +0 -1
- package/dist/chunk-3JYRSECU.cjs.map +0 -1
- package/dist/chunk-465ZVXAK.js.map +0 -1
- package/dist/chunk-5QFG6SCM.js.map +0 -1
- package/dist/chunk-CEXVMFUD.js +0 -1265
- package/dist/chunk-CEXVMFUD.js.map +0 -1
- package/dist/chunk-CKUCDCGI.js +0 -168
- package/dist/chunk-CKUCDCGI.js.map +0 -1
- package/dist/chunk-HMMDNIEQ.cjs.map +0 -1
- package/dist/chunk-LGC3GUMR.cjs.map +0 -1
- package/dist/chunk-MCDDO4WY.cjs +0 -1309
- package/dist/chunk-MCDDO4WY.cjs.map +0 -1
- package/dist/chunk-OYO2MJED.cjs +0 -195
- package/dist/chunk-OYO2MJED.cjs.map +0 -1
- package/dist/chunk-SBTEIZ3B.js +0 -26
- package/dist/chunk-SBTEIZ3B.js.map +0 -1
- package/dist/chunk-WAWEQ3DP.js.map +0 -1
- package/dist/chunk-WIQEFIRX.cjs +0 -28
- package/dist/chunk-WIQEFIRX.cjs.map +0 -1
- package/dist/server/handlers/auth/defaults.d.ts +0 -3
- package/dist/server/handlers/auth/defaults.d.ts.map +0 -1
- package/dist/server/handlers/auth/helpers.d.ts +0 -11
- package/dist/server/handlers/auth/helpers.d.ts.map +0 -1
- package/dist/server/handlers/auth/index.d.ts +0 -11
- package/dist/server/handlers/auth/index.d.ts.map +0 -1
- package/dist/server/handlers/prompt.d.ts +0 -3
- package/dist/server/handlers/prompt.d.ts.map +0 -1
- package/dist/server/handlers/routes/agent-builder/handlers.d.ts +0 -17
- package/dist/server/handlers/routes/agent-builder/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/agent-builder/router.d.ts +0 -4
- package/dist/server/handlers/routes/agent-builder/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/agents/handlers.d.ts +0 -363
- package/dist/server/handlers/routes/agents/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/agents/router.d.ts +0 -5
- package/dist/server/handlers/routes/agents/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/agents/voice.d.ts +0 -18
- package/dist/server/handlers/routes/agents/voice.d.ts.map +0 -1
- package/dist/server/handlers/routes/logs/handlers.d.ts +0 -5
- package/dist/server/handlers/routes/logs/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/logs/router.d.ts +0 -3
- package/dist/server/handlers/routes/logs/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/mcp/handlers.d.ts +0 -139
- package/dist/server/handlers/routes/mcp/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/mcp/router.d.ts +0 -4
- package/dist/server/handlers/routes/mcp/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/memory/handlers.d.ts +0 -17
- package/dist/server/handlers/routes/memory/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/memory/router.d.ts +0 -4
- package/dist/server/handlers/routes/memory/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/observability/handlers.d.ts +0 -6
- package/dist/server/handlers/routes/observability/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/observability/router.d.ts +0 -3
- package/dist/server/handlers/routes/observability/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/scores/handlers.d.ts +0 -300
- package/dist/server/handlers/routes/scores/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/scores/router.d.ts +0 -4
- package/dist/server/handlers/routes/scores/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/telemetry/handlers.d.ts +0 -4
- package/dist/server/handlers/routes/telemetry/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/telemetry/router.d.ts +0 -3
- package/dist/server/handlers/routes/telemetry/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/tools/handlers.d.ts +0 -7
- package/dist/server/handlers/routes/tools/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/tools/router.d.ts +0 -4
- package/dist/server/handlers/routes/tools/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/vector/handlers.d.ts +0 -10
- package/dist/server/handlers/routes/vector/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/vector/router.d.ts +0 -4
- package/dist/server/handlers/routes/vector/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/workflows/handlers.d.ts +0 -20
- package/dist/server/handlers/routes/workflows/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/workflows/legacyWorkflows.d.ts +0 -11
- package/dist/server/handlers/routes/workflows/legacyWorkflows.d.ts.map +0 -1
- package/dist/server/handlers/routes/workflows/router.d.ts +0 -4
- package/dist/server/handlers/routes/workflows/router.d.ts.map +0 -1
- package/dist/templates/instrumentation-template.js +0 -172
package/dist/chunk-MCDDO4WY.cjs
DELETED
|
@@ -1,1309 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var babel = require('@babel/core');
|
|
4
|
-
var fs = require('fs');
|
|
5
|
-
var promises = require('fs/promises');
|
|
6
|
-
var path2 = require('path');
|
|
7
|
-
var child_process = require('child_process');
|
|
8
|
-
var localPkg = require('local-pkg');
|
|
9
|
-
var url = require('url');
|
|
10
|
-
var rollup = require('rollup');
|
|
11
|
-
var originalEsbuild = require('rollup-plugin-esbuild');
|
|
12
|
-
var commonjs = require('@rollup/plugin-commonjs');
|
|
13
|
-
var resolveFrom2 = require('resolve-from');
|
|
14
|
-
var typescriptPaths = require('typescript-paths');
|
|
15
|
-
var rollupPlugin = require('@optimize-lodash/rollup-plugin');
|
|
16
|
-
var json = require('@rollup/plugin-json');
|
|
17
|
-
var pkg = require('empathic/package');
|
|
18
|
-
var findWorkspaces = require('find-workspaces');
|
|
19
|
-
var logger = require('@mastra/core/logger');
|
|
20
|
-
var virtual = require('@rollup/plugin-virtual');
|
|
21
|
-
var module$1 = require('module');
|
|
22
|
-
var nodeResolve = require('@rollup/plugin-node-resolve');
|
|
23
|
-
var esmShim = require('@rollup/plugin-esm-shim');
|
|
24
|
-
var posix = require('path/posix');
|
|
25
|
-
var resolve = require('resolve.exports');
|
|
26
|
-
var error = require('@mastra/core/error');
|
|
27
|
-
|
|
28
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
29
|
-
|
|
30
|
-
function _interopNamespace(e) {
|
|
31
|
-
if (e && e.__esModule) return e;
|
|
32
|
-
var n = Object.create(null);
|
|
33
|
-
if (e) {
|
|
34
|
-
Object.keys(e).forEach(function (k) {
|
|
35
|
-
if (k !== 'default') {
|
|
36
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
37
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function () { return e[k]; }
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
n.default = e;
|
|
45
|
-
return Object.freeze(n);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
|
|
49
|
-
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
50
|
-
var path2__namespace = /*#__PURE__*/_interopNamespace(path2);
|
|
51
|
-
var originalEsbuild__default = /*#__PURE__*/_interopDefault(originalEsbuild);
|
|
52
|
-
var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
|
|
53
|
-
var resolveFrom2__default = /*#__PURE__*/_interopDefault(resolveFrom2);
|
|
54
|
-
var json__default = /*#__PURE__*/_interopDefault(json);
|
|
55
|
-
var pkg__namespace = /*#__PURE__*/_interopNamespace(pkg);
|
|
56
|
-
var virtual__default = /*#__PURE__*/_interopDefault(virtual);
|
|
57
|
-
var nodeResolve__default = /*#__PURE__*/_interopDefault(nodeResolve);
|
|
58
|
-
var esmShim__default = /*#__PURE__*/_interopDefault(esmShim);
|
|
59
|
-
var resolve__namespace = /*#__PURE__*/_interopNamespace(resolve);
|
|
60
|
-
|
|
61
|
-
// src/build/analyze.ts
|
|
62
|
-
function getPackageName(id) {
|
|
63
|
-
const parts = id.split("/");
|
|
64
|
-
if (id.startsWith("@")) {
|
|
65
|
-
return parts.slice(0, 2).join("/");
|
|
66
|
-
}
|
|
67
|
-
return parts[0];
|
|
68
|
-
}
|
|
69
|
-
async function getPackageRootPath(packageName, parentPath) {
|
|
70
|
-
let rootPath;
|
|
71
|
-
try {
|
|
72
|
-
let options = void 0;
|
|
73
|
-
if (parentPath) {
|
|
74
|
-
if (!parentPath.startsWith("file://")) {
|
|
75
|
-
parentPath = url.pathToFileURL(parentPath).href;
|
|
76
|
-
}
|
|
77
|
-
options = {
|
|
78
|
-
paths: [parentPath]
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
const pkg2 = await localPkg.getPackageInfo(packageName, options);
|
|
82
|
-
rootPath = pkg2?.rootPath ?? null;
|
|
83
|
-
} catch (e) {
|
|
84
|
-
rootPath = null;
|
|
85
|
-
}
|
|
86
|
-
return rootPath;
|
|
87
|
-
}
|
|
88
|
-
function getCompiledDepCachePath(rootPath, packageName) {
|
|
89
|
-
return slash(path2.join(rootPath, "node_modules", ".cache", packageName));
|
|
90
|
-
}
|
|
91
|
-
function slash(path3) {
|
|
92
|
-
const isExtendedLengthPath = path3.startsWith("\\\\?\\");
|
|
93
|
-
if (isExtendedLengthPath) {
|
|
94
|
-
return path3;
|
|
95
|
-
}
|
|
96
|
-
return path3.replaceAll("\\", "/");
|
|
97
|
-
}
|
|
98
|
-
function rollupSafeName(name, rootDir) {
|
|
99
|
-
const rel = path2.relative(rootDir, name);
|
|
100
|
-
let entry = slash(rel);
|
|
101
|
-
entry = entry.replace(/^(\.\.\/)+/, "");
|
|
102
|
-
entry = entry.replace(/^\/+/, "");
|
|
103
|
-
entry = entry.replace(/^[A-Za-z]:\//, "");
|
|
104
|
-
if (!entry) {
|
|
105
|
-
entry = slash(path2.basename(name));
|
|
106
|
-
}
|
|
107
|
-
return entry;
|
|
108
|
-
}
|
|
109
|
-
var NATIVE_BINDING_LOADERS = [
|
|
110
|
-
"node-gyp-build",
|
|
111
|
-
"prebuild-install",
|
|
112
|
-
"bindings",
|
|
113
|
-
"node-addon-api",
|
|
114
|
-
"node-pre-gyp",
|
|
115
|
-
"nan"
|
|
116
|
-
// Native Abstractions for Node.js
|
|
117
|
-
];
|
|
118
|
-
function findNativePackageModule(moduleIds) {
|
|
119
|
-
return moduleIds.find((id) => {
|
|
120
|
-
if (id.startsWith("\0")) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
if (!id.includes("/node_modules/")) {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
for (const loader of NATIVE_BINDING_LOADERS) {
|
|
127
|
-
if (id.includes(`/${loader}/`) || id.includes(`/${loader}@`)) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return true;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// src/validator/validate.ts
|
|
136
|
-
function spawn(command, args = [], options = {}) {
|
|
137
|
-
return new Promise((resolve2, reject) => {
|
|
138
|
-
const childProcess = child_process.spawn(command, args, {
|
|
139
|
-
// stdio: 'inherit',
|
|
140
|
-
...options
|
|
141
|
-
});
|
|
142
|
-
childProcess.on("error", (error) => {
|
|
143
|
-
reject(error);
|
|
144
|
-
});
|
|
145
|
-
let stderr = "";
|
|
146
|
-
childProcess.stderr?.on("data", (message) => {
|
|
147
|
-
stderr += message;
|
|
148
|
-
});
|
|
149
|
-
childProcess.on("close", (code) => {
|
|
150
|
-
if (code === 0) {
|
|
151
|
-
resolve2();
|
|
152
|
-
} else {
|
|
153
|
-
reject(new Error(stderr));
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
function validate(file) {
|
|
159
|
-
return spawn(
|
|
160
|
-
"node",
|
|
161
|
-
[
|
|
162
|
-
"--import",
|
|
163
|
-
undefined("@mastra/deployer/loader"),
|
|
164
|
-
"--input-type=module",
|
|
165
|
-
"-e",
|
|
166
|
-
`import('file://${slash(file)}')`
|
|
167
|
-
],
|
|
168
|
-
{
|
|
169
|
-
cwd: path2.dirname(file)
|
|
170
|
-
}
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
function removeAllOptionsFromMastraExcept(result, option, logger) {
|
|
174
|
-
const t = babel__namespace.default.types;
|
|
175
|
-
return {
|
|
176
|
-
name: "remove-all-except-" + option + "-config",
|
|
177
|
-
visitor: {
|
|
178
|
-
ExportNamedDeclaration: {
|
|
179
|
-
// remove all exports
|
|
180
|
-
exit(path3) {
|
|
181
|
-
path3.remove();
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
NewExpression(path3, state) {
|
|
185
|
-
const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
|
|
186
|
-
if (!varDeclaratorPath) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
const parentNode = path3.parentPath.node;
|
|
190
|
-
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
let mastraArgs = t.objectExpression([]);
|
|
194
|
-
if (t.isObjectExpression(path3.node.arguments[0])) {
|
|
195
|
-
mastraArgs = path3.node.arguments[0];
|
|
196
|
-
}
|
|
197
|
-
let telemetry = mastraArgs.properties.find(
|
|
198
|
-
// @ts-ignore
|
|
199
|
-
(prop) => prop.key.name === option
|
|
200
|
-
);
|
|
201
|
-
let telemetryValue = t.objectExpression([]);
|
|
202
|
-
const programPath = path3.scope.getProgramParent().path;
|
|
203
|
-
if (!programPath) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
if (telemetry && t.isObjectProperty(telemetry) && t.isExpression(telemetry.value)) {
|
|
207
|
-
result.hasCustomConfig = true;
|
|
208
|
-
telemetryValue = telemetry.value;
|
|
209
|
-
if (t.isIdentifier(telemetry.value) && telemetry.value.name === option) {
|
|
210
|
-
const telemetryBinding = state.file.scope.getBinding(option);
|
|
211
|
-
if (telemetryBinding && t.isVariableDeclarator(telemetryBinding.path.node)) {
|
|
212
|
-
const id = path3.scope.generateUidIdentifier(option);
|
|
213
|
-
telemetryBinding.path.replaceWith(t.variableDeclarator(id, telemetryBinding.path.node.init));
|
|
214
|
-
telemetryValue = id;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
const exportDeclaration = t.exportNamedDeclaration(
|
|
219
|
-
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), telemetryValue)]),
|
|
220
|
-
[]
|
|
221
|
-
);
|
|
222
|
-
programPath.node.body.push(exportDeclaration);
|
|
223
|
-
},
|
|
224
|
-
Program: {
|
|
225
|
-
exit(path3) {
|
|
226
|
-
const hasExport = path3.node.body.some(
|
|
227
|
-
(node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
|
|
228
|
-
);
|
|
229
|
-
if (!hasExport) {
|
|
230
|
-
if (logger) {
|
|
231
|
-
logger.warn(`Mastra ${option} config could not be extracted. Please make sure your entry file looks like this:
|
|
232
|
-
export const mastra = new Mastra({
|
|
233
|
-
${option}: <value>
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
`);
|
|
237
|
-
}
|
|
238
|
-
const fallbackExportDeclaration = t.exportNamedDeclaration(
|
|
239
|
-
t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), t.objectExpression([]))]),
|
|
240
|
-
[]
|
|
241
|
-
);
|
|
242
|
-
path3.node.body.push(fallbackExportDeclaration);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// src/build/babel/remove-all-options-bundler.ts
|
|
251
|
-
function removeAllOptionsExceptBundler(result, logger) {
|
|
252
|
-
return removeAllOptionsFromMastraExcept(result, "bundler", logger);
|
|
253
|
-
}
|
|
254
|
-
function esbuild(options = {}) {
|
|
255
|
-
return originalEsbuild__default.default({
|
|
256
|
-
target: "node20",
|
|
257
|
-
platform: "node",
|
|
258
|
-
minify: false,
|
|
259
|
-
...options
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
var PLUGIN_NAME = "tsconfig-paths";
|
|
263
|
-
function tsConfigPaths({ tsConfigPath, respectCoreModule, localResolve } = {}) {
|
|
264
|
-
let handler;
|
|
265
|
-
return {
|
|
266
|
-
name: PLUGIN_NAME,
|
|
267
|
-
buildStart() {
|
|
268
|
-
handler = typescriptPaths.createHandler({
|
|
269
|
-
log: () => {
|
|
270
|
-
},
|
|
271
|
-
tsConfigPath,
|
|
272
|
-
respectCoreModule,
|
|
273
|
-
falllback: (moduleName) => fs__default.default.existsSync(moduleName)
|
|
274
|
-
});
|
|
275
|
-
return;
|
|
276
|
-
},
|
|
277
|
-
async resolveId(request, importer, options) {
|
|
278
|
-
if (!importer || request.startsWith("\0")) {
|
|
279
|
-
return null;
|
|
280
|
-
}
|
|
281
|
-
const moduleName = handler?.(request, path2.normalize(importer));
|
|
282
|
-
if (!moduleName) {
|
|
283
|
-
let importerMeta = {};
|
|
284
|
-
const resolved = await this.resolve(request, importer, { skipSelf: true, ...options });
|
|
285
|
-
if (!resolved) {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
if (localResolve) {
|
|
289
|
-
const importerInfo = this.getModuleInfo(importer);
|
|
290
|
-
importerMeta = importerInfo?.meta || {};
|
|
291
|
-
if (!request.startsWith("./") && !request.startsWith("../") && importerMeta?.[PLUGIN_NAME]?.resolved) {
|
|
292
|
-
return {
|
|
293
|
-
...resolved,
|
|
294
|
-
external: !request.startsWith("hono/") && request !== "hono"
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
return {
|
|
299
|
-
...resolved,
|
|
300
|
-
meta: {
|
|
301
|
-
...resolved.meta || {},
|
|
302
|
-
...importerMeta
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
if (!path2__namespace.default.extname(moduleName)) {
|
|
307
|
-
const resolved = await this.resolve(moduleName, importer, { skipSelf: true, ...options });
|
|
308
|
-
if (!resolved) {
|
|
309
|
-
return null;
|
|
310
|
-
}
|
|
311
|
-
return {
|
|
312
|
-
...resolved,
|
|
313
|
-
meta: {
|
|
314
|
-
...resolved.meta,
|
|
315
|
-
[PLUGIN_NAME]: {
|
|
316
|
-
resolved: true
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
return {
|
|
322
|
-
id: moduleName,
|
|
323
|
-
meta: {
|
|
324
|
-
[PLUGIN_NAME]: {
|
|
325
|
-
resolved: true
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
function removeNonReferencedNodes() {
|
|
333
|
-
const t = babel__namespace.default.types;
|
|
334
|
-
return {
|
|
335
|
-
name: "remove-non-referenced-nodes",
|
|
336
|
-
visitor: {
|
|
337
|
-
Program(path3) {
|
|
338
|
-
const scope = path3.scope;
|
|
339
|
-
const currentBody = path3.get("body");
|
|
340
|
-
const filteredBody = currentBody.filter((childPath) => {
|
|
341
|
-
if (childPath.isExportDeclaration()) {
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
|
-
if (childPath.isVariableDeclaration()) {
|
|
345
|
-
return childPath.node.declarations.some((decl) => {
|
|
346
|
-
if (!t.isIdentifier(decl.id)) {
|
|
347
|
-
return false;
|
|
348
|
-
}
|
|
349
|
-
const name = decl.id.name;
|
|
350
|
-
const binding = scope.getBinding(name);
|
|
351
|
-
return binding && (binding.referenced || binding.referencePaths.length > 0);
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {
|
|
355
|
-
if (!t.isIdentifier(childPath.node.id)) {
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
358
|
-
const name = childPath.node.id.name;
|
|
359
|
-
const binding = scope.getBinding(name);
|
|
360
|
-
return binding && (binding.referenced || binding.referencePaths.length > 0);
|
|
361
|
-
}
|
|
362
|
-
if (childPath.isImportDeclaration()) {
|
|
363
|
-
return childPath.node.specifiers.some((specifier) => {
|
|
364
|
-
const importedName = specifier.local.name;
|
|
365
|
-
const binding = scope.getBinding(importedName);
|
|
366
|
-
return binding && (binding.referenced || binding.referencePaths.length > 0);
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
return false;
|
|
370
|
-
});
|
|
371
|
-
path3.set(
|
|
372
|
-
"body",
|
|
373
|
-
filteredBody.map((p) => p.node)
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// src/build/plugins/remove-unused-references.ts
|
|
381
|
-
function recursiveRemoveNonReferencedNodes(code) {
|
|
382
|
-
return new Promise(async (resolve2, reject) => {
|
|
383
|
-
babel__namespace.transform(
|
|
384
|
-
code,
|
|
385
|
-
{
|
|
386
|
-
babelrc: false,
|
|
387
|
-
configFile: false,
|
|
388
|
-
plugins: [removeNonReferencedNodes()]
|
|
389
|
-
},
|
|
390
|
-
(err, result) => {
|
|
391
|
-
if (err) {
|
|
392
|
-
return reject(err);
|
|
393
|
-
}
|
|
394
|
-
if (result && result.code !== code) {
|
|
395
|
-
return recursiveRemoveNonReferencedNodes(result.code).then(resolve2, reject);
|
|
396
|
-
}
|
|
397
|
-
resolve2({
|
|
398
|
-
code: result.code,
|
|
399
|
-
map: result.map
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
);
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
function extractMastraOptionBundler(name, entryFile, transformer, result, logger) {
|
|
406
|
-
return rollup.rollup({
|
|
407
|
-
logLevel: "silent",
|
|
408
|
-
input: {
|
|
409
|
-
[`${name}-config`]: entryFile
|
|
410
|
-
},
|
|
411
|
-
treeshake: "smallest",
|
|
412
|
-
plugins: [
|
|
413
|
-
tsConfigPaths(),
|
|
414
|
-
// transpile typescript to something we understand
|
|
415
|
-
esbuild(),
|
|
416
|
-
rollupPlugin.optimizeLodashImports({
|
|
417
|
-
include: "**/*.{js,ts,mjs,cjs}"
|
|
418
|
-
}),
|
|
419
|
-
commonjs__default.default({
|
|
420
|
-
extensions: [".js", ".ts"],
|
|
421
|
-
strictRequires: "strict",
|
|
422
|
-
transformMixedEsModules: true,
|
|
423
|
-
ignoreTryCatch: false
|
|
424
|
-
}),
|
|
425
|
-
json__default.default(),
|
|
426
|
-
{
|
|
427
|
-
name: `extract-${name}-config`,
|
|
428
|
-
transform(code, id) {
|
|
429
|
-
if (id !== entryFile) {
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
return new Promise((resolve2, reject) => {
|
|
433
|
-
babel__namespace.transform(
|
|
434
|
-
code,
|
|
435
|
-
{
|
|
436
|
-
babelrc: false,
|
|
437
|
-
configFile: false,
|
|
438
|
-
filename: id,
|
|
439
|
-
plugins: [transformer(result, logger)]
|
|
440
|
-
},
|
|
441
|
-
(err, result2) => {
|
|
442
|
-
if (err) {
|
|
443
|
-
return reject(err);
|
|
444
|
-
}
|
|
445
|
-
resolve2({
|
|
446
|
-
code: result2.code,
|
|
447
|
-
map: result2.map
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
);
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
},
|
|
454
|
-
// let esbuild remove all unused imports
|
|
455
|
-
esbuild(),
|
|
456
|
-
{
|
|
457
|
-
name: "cleanup",
|
|
458
|
-
transform(code, id) {
|
|
459
|
-
if (id !== entryFile) {
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
return recursiveRemoveNonReferencedNodes(code);
|
|
463
|
-
}
|
|
464
|
-
},
|
|
465
|
-
// let esbuild remove it once more
|
|
466
|
-
esbuild()
|
|
467
|
-
]
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
async function extractMastraOption(name, entryFile, transformer, outputDir, logger) {
|
|
471
|
-
const result = {
|
|
472
|
-
hasCustomConfig: false
|
|
473
|
-
};
|
|
474
|
-
const bundler = await extractMastraOptionBundler(name, entryFile, transformer, result, logger);
|
|
475
|
-
const output = await bundler.write({
|
|
476
|
-
dir: outputDir,
|
|
477
|
-
format: "es",
|
|
478
|
-
entryFileNames: "[name].mjs"
|
|
479
|
-
});
|
|
480
|
-
if (result.hasCustomConfig) {
|
|
481
|
-
const configPath = `${outputDir}/${name}-config.mjs`;
|
|
482
|
-
return {
|
|
483
|
-
bundleOutput: output,
|
|
484
|
-
getConfig: () => import(`file:${configPath}`).then((m) => m[name])
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
return null;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// src/build/bundlerOptions.ts
|
|
491
|
-
async function getBundlerOptions(entryFile, outputDir, logger) {
|
|
492
|
-
const result = await extractMastraOption(
|
|
493
|
-
"bundler",
|
|
494
|
-
entryFile,
|
|
495
|
-
removeAllOptionsExceptBundler,
|
|
496
|
-
outputDir,
|
|
497
|
-
logger
|
|
498
|
-
);
|
|
499
|
-
if (!result) {
|
|
500
|
-
return null;
|
|
501
|
-
}
|
|
502
|
-
return result.getConfig();
|
|
503
|
-
}
|
|
504
|
-
function checkConfigExport(result) {
|
|
505
|
-
const t = babel__namespace.default.types;
|
|
506
|
-
const mastraVars = /* @__PURE__ */ new Set();
|
|
507
|
-
return {
|
|
508
|
-
visitor: {
|
|
509
|
-
ExportNamedDeclaration(path3) {
|
|
510
|
-
const decl = path3.node.declaration;
|
|
511
|
-
if (t.isVariableDeclaration(decl)) {
|
|
512
|
-
const varDecl = decl.declarations[0];
|
|
513
|
-
if (t.isIdentifier(varDecl?.id, { name: "mastra" }) && t.isNewExpression(varDecl.init) && t.isIdentifier(varDecl.init.callee, { name: "Mastra" })) {
|
|
514
|
-
result.hasValidConfig = true;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
if (Array.isArray(path3.node.specifiers)) {
|
|
518
|
-
for (const spec of path3.node.specifiers) {
|
|
519
|
-
if (t.isExportSpecifier(spec) && t.isIdentifier(spec.exported, { name: "mastra" }) && t.isIdentifier(spec.local) && mastraVars.has(spec.local.name)) {
|
|
520
|
-
result.hasValidConfig = true;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
},
|
|
525
|
-
// For cases 2-4 we need to track whether those variables are assigned to `new Mastra()`
|
|
526
|
-
VariableDeclaration(path3) {
|
|
527
|
-
for (const decl of path3.node.declarations) {
|
|
528
|
-
if (t.isIdentifier(decl.id) && t.isNewExpression(decl.init) && t.isIdentifier(decl.init.callee, { name: "Mastra" })) {
|
|
529
|
-
mastraVars.add(decl.id.name);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
var workspacesCache = findWorkspaces.createWorkspacesCache();
|
|
537
|
-
async function getWorkspaceInformation({
|
|
538
|
-
dir = process.cwd(),
|
|
539
|
-
mastraEntryFile
|
|
540
|
-
}) {
|
|
541
|
-
const closestPkgJson = pkg__namespace.up({ cwd: path2.dirname(mastraEntryFile) });
|
|
542
|
-
const location = closestPkgJson ? path2.dirname(slash(closestPkgJson)) : slash(process.cwd());
|
|
543
|
-
const workspaces = await findWorkspaces.findWorkspaces(dir, { cache: workspacesCache });
|
|
544
|
-
const _workspaceMap = new Map(
|
|
545
|
-
workspaces?.map((workspace) => [
|
|
546
|
-
workspace.package.name,
|
|
547
|
-
{
|
|
548
|
-
location: workspace.location,
|
|
549
|
-
dependencies: workspace.package.dependencies,
|
|
550
|
-
version: workspace.package.version
|
|
551
|
-
}
|
|
552
|
-
]) ?? []
|
|
553
|
-
);
|
|
554
|
-
const isWorkspacePackage = (workspaces ?? []).some((ws) => ws.location === location);
|
|
555
|
-
const workspaceRoot = isWorkspacePackage ? findWorkspaces.findWorkspacesRoot(dir, { cache: workspacesCache })?.location : void 0;
|
|
556
|
-
return {
|
|
557
|
-
// If the current package is not part of the workspace, the bundling down the line shouldn't look at any workspace packages
|
|
558
|
-
workspaceMap: isWorkspacePackage ? _workspaceMap : /* @__PURE__ */ new Map(),
|
|
559
|
-
workspaceRoot,
|
|
560
|
-
isWorkspacePackage
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
function isNodeBuiltin(dep) {
|
|
564
|
-
const [pkg2] = dep.split("/");
|
|
565
|
-
return dep.startsWith("node:") || module$1.builtinModules.includes(dep) || module$1.builtinModules.includes(pkg2);
|
|
566
|
-
}
|
|
567
|
-
function removeDeployer() {
|
|
568
|
-
const t = babel__namespace.default.types;
|
|
569
|
-
return {
|
|
570
|
-
name: "remove-deployer",
|
|
571
|
-
visitor: {
|
|
572
|
-
NewExpression(path3, state) {
|
|
573
|
-
const varDeclaratorPath = path3.findParent((path4) => t.isVariableDeclarator(path4.node));
|
|
574
|
-
if (!varDeclaratorPath) {
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
const parentNode = path3.parentPath.node;
|
|
578
|
-
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
if (!state.hasReplaced) {
|
|
582
|
-
state.hasReplaced = true;
|
|
583
|
-
const newMastraObj = t.cloneNode(path3.node);
|
|
584
|
-
if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.[0]) {
|
|
585
|
-
const deployer = newMastraObj.arguments[0].properties.find(
|
|
586
|
-
(prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
|
|
587
|
-
);
|
|
588
|
-
if (!deployer) {
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
newMastraObj.arguments[0].properties = newMastraObj.arguments[0].properties.filter(
|
|
592
|
-
(prop) => prop !== deployer
|
|
593
|
-
);
|
|
594
|
-
if (t.isObjectProperty(deployer) && t.isIdentifier(deployer.value)) {
|
|
595
|
-
const deployerBinding = state.file.scope.getBinding(deployer.value.name);
|
|
596
|
-
if (deployerBinding) {
|
|
597
|
-
deployerBinding?.path?.parentPath?.remove();
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
path3.replaceWith(newMastraObj);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
// src/build/plugins/remove-deployer.ts
|
|
609
|
-
function removeDeployer2(mastraEntry, options) {
|
|
610
|
-
return {
|
|
611
|
-
name: "remove-deployer",
|
|
612
|
-
transform(code, id) {
|
|
613
|
-
if (id !== mastraEntry) {
|
|
614
|
-
return;
|
|
615
|
-
}
|
|
616
|
-
return new Promise((resolve2, reject) => {
|
|
617
|
-
babel__namespace.transform(
|
|
618
|
-
code,
|
|
619
|
-
{
|
|
620
|
-
babelrc: false,
|
|
621
|
-
configFile: false,
|
|
622
|
-
filename: id,
|
|
623
|
-
plugins: [removeDeployer],
|
|
624
|
-
sourceMaps: options?.sourcemap
|
|
625
|
-
},
|
|
626
|
-
(err, result) => {
|
|
627
|
-
if (err) {
|
|
628
|
-
return reject(err);
|
|
629
|
-
}
|
|
630
|
-
resolve2({
|
|
631
|
-
code: result.code,
|
|
632
|
-
map: result.map
|
|
633
|
-
});
|
|
634
|
-
}
|
|
635
|
-
);
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
};
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
// src/build/analyze/constants.ts
|
|
642
|
-
var DEPS_TO_IGNORE = ["#tools"];
|
|
643
|
-
var GLOBAL_EXTERNALS = [
|
|
644
|
-
"pino",
|
|
645
|
-
"pino-pretty",
|
|
646
|
-
"@libsql/client",
|
|
647
|
-
"pg",
|
|
648
|
-
"libsql",
|
|
649
|
-
"#tools",
|
|
650
|
-
"typescript",
|
|
651
|
-
"undici"
|
|
652
|
-
];
|
|
653
|
-
var DEPRECATED_EXTERNALS = ["fastembed", "nodemailer", "jsdom", "sqlite3"];
|
|
654
|
-
|
|
655
|
-
// src/build/analyze/analyzeEntry.ts
|
|
656
|
-
function getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }) {
|
|
657
|
-
const normalizedMastraEntry = slash(mastraEntry);
|
|
658
|
-
let virtualPlugin = null;
|
|
659
|
-
if (isVirtualFile) {
|
|
660
|
-
virtualPlugin = virtual__default.default({
|
|
661
|
-
"#entry": entry
|
|
662
|
-
});
|
|
663
|
-
entry = "#entry";
|
|
664
|
-
}
|
|
665
|
-
const plugins = [];
|
|
666
|
-
if (virtualPlugin) {
|
|
667
|
-
plugins.push(virtualPlugin);
|
|
668
|
-
}
|
|
669
|
-
plugins.push(
|
|
670
|
-
...[
|
|
671
|
-
tsConfigPaths(),
|
|
672
|
-
{
|
|
673
|
-
name: "custom-alias-resolver",
|
|
674
|
-
resolveId(id) {
|
|
675
|
-
if (id === "#server") {
|
|
676
|
-
return slash(url.fileURLToPath(undefined("@mastra/deployer/server")));
|
|
677
|
-
}
|
|
678
|
-
if (id === "#mastra") {
|
|
679
|
-
return normalizedMastraEntry;
|
|
680
|
-
}
|
|
681
|
-
if (id.startsWith("@mastra/server")) {
|
|
682
|
-
return url.fileURLToPath(undefined(id));
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
},
|
|
686
|
-
json__default.default(),
|
|
687
|
-
esbuild(),
|
|
688
|
-
commonjs__default.default({
|
|
689
|
-
strictRequires: "debug",
|
|
690
|
-
ignoreTryCatch: false,
|
|
691
|
-
transformMixedEsModules: true,
|
|
692
|
-
extensions: [".js", ".ts"]
|
|
693
|
-
}),
|
|
694
|
-
removeDeployer2(mastraEntry, { sourcemap: sourcemapEnabled }),
|
|
695
|
-
esbuild()
|
|
696
|
-
]
|
|
697
|
-
);
|
|
698
|
-
return plugins;
|
|
699
|
-
}
|
|
700
|
-
async function captureDependenciesToOptimize(output, workspaceMap, projectRoot, {
|
|
701
|
-
logger: logger$1
|
|
702
|
-
}) {
|
|
703
|
-
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
704
|
-
if (!output.facadeModuleId) {
|
|
705
|
-
throw new Error(
|
|
706
|
-
"Something went wrong, we could not find the package name of the entry file. Please open an issue."
|
|
707
|
-
);
|
|
708
|
-
}
|
|
709
|
-
let entryRootPath = projectRoot;
|
|
710
|
-
if (!output.facadeModuleId.startsWith("\0virtual:")) {
|
|
711
|
-
entryRootPath = await getPackageRootPath(output.facadeModuleId) || projectRoot;
|
|
712
|
-
}
|
|
713
|
-
for (const [dependency, bindings] of Object.entries(output.importedBindings)) {
|
|
714
|
-
if (isNodeBuiltin(dependency) || DEPS_TO_IGNORE.includes(dependency)) {
|
|
715
|
-
continue;
|
|
716
|
-
}
|
|
717
|
-
const pkgName = getPackageName(dependency);
|
|
718
|
-
let rootPath = null;
|
|
719
|
-
let isWorkspace = false;
|
|
720
|
-
if (pkgName) {
|
|
721
|
-
rootPath = await getPackageRootPath(dependency, entryRootPath);
|
|
722
|
-
isWorkspace = workspaceMap.has(pkgName);
|
|
723
|
-
}
|
|
724
|
-
const normalizedRootPath = rootPath ? slash(rootPath) : null;
|
|
725
|
-
depsToOptimize.set(dependency, { exports: bindings, rootPath: normalizedRootPath, isWorkspace });
|
|
726
|
-
}
|
|
727
|
-
async function checkTransitiveDependencies(internalMap, maxDepth = 10, currentDepth = 0) {
|
|
728
|
-
if (currentDepth >= maxDepth) {
|
|
729
|
-
logger$1.warn("Maximum dependency depth reached while checking transitive dependencies.");
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
const depsSnapshot = new Map(depsToOptimize);
|
|
733
|
-
let hasAddedDeps = false;
|
|
734
|
-
for (const [dep, meta] of depsSnapshot) {
|
|
735
|
-
if (!meta.isWorkspace || internalMap.has(dep)) {
|
|
736
|
-
continue;
|
|
737
|
-
}
|
|
738
|
-
try {
|
|
739
|
-
const resolvedPath = resolveFrom2__default.default(projectRoot, dep);
|
|
740
|
-
if (!resolvedPath) {
|
|
741
|
-
logger$1.warn(`Could not resolve path for workspace dependency ${dep}`);
|
|
742
|
-
continue;
|
|
743
|
-
}
|
|
744
|
-
const analysis = await analyzeEntry({ entry: resolvedPath, isVirtualFile: false }, "", {
|
|
745
|
-
workspaceMap,
|
|
746
|
-
projectRoot,
|
|
747
|
-
logger: logger.noopLogger,
|
|
748
|
-
sourcemapEnabled: false
|
|
749
|
-
});
|
|
750
|
-
if (!analysis?.dependencies) {
|
|
751
|
-
continue;
|
|
752
|
-
}
|
|
753
|
-
for (const [innerDep, innerMeta] of analysis.dependencies) {
|
|
754
|
-
if (innerMeta.isWorkspace && !internalMap.has(innerDep) && !depsToOptimize.has(innerDep)) {
|
|
755
|
-
depsToOptimize.set(innerDep, innerMeta);
|
|
756
|
-
internalMap.set(innerDep, innerMeta);
|
|
757
|
-
hasAddedDeps = true;
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
} catch (err) {
|
|
761
|
-
logger$1.error(`Failed to resolve or analyze dependency ${dep}: ${err.message}`);
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
if (hasAddedDeps) {
|
|
765
|
-
await checkTransitiveDependencies(internalMap, maxDepth, currentDepth + 1);
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
await checkTransitiveDependencies(/* @__PURE__ */ new Map());
|
|
769
|
-
const dynamicImports = output.dynamicImports.filter((d) => !DEPS_TO_IGNORE.includes(d));
|
|
770
|
-
if (dynamicImports.length) {
|
|
771
|
-
for (const dynamicImport of dynamicImports) {
|
|
772
|
-
if (!depsToOptimize.has(dynamicImport) && !isNodeBuiltin(dynamicImport)) {
|
|
773
|
-
depsToOptimize.set(dynamicImport, { exports: ["*"], rootPath: null, isWorkspace: false });
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
return depsToOptimize;
|
|
778
|
-
}
|
|
779
|
-
async function analyzeEntry({
|
|
780
|
-
entry,
|
|
781
|
-
isVirtualFile
|
|
782
|
-
}, mastraEntry, {
|
|
783
|
-
logger,
|
|
784
|
-
sourcemapEnabled,
|
|
785
|
-
workspaceMap,
|
|
786
|
-
projectRoot
|
|
787
|
-
}) {
|
|
788
|
-
const optimizerBundler = await rollup.rollup({
|
|
789
|
-
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
790
|
-
input: isVirtualFile ? "#entry" : entry,
|
|
791
|
-
treeshake: "smallest",
|
|
792
|
-
preserveSymlinks: true,
|
|
793
|
-
plugins: getInputPlugins({ entry, isVirtualFile }, mastraEntry, { sourcemapEnabled }),
|
|
794
|
-
external: DEPS_TO_IGNORE
|
|
795
|
-
});
|
|
796
|
-
const { output } = await optimizerBundler.generate({
|
|
797
|
-
format: "esm",
|
|
798
|
-
inlineDynamicImports: true
|
|
799
|
-
});
|
|
800
|
-
await optimizerBundler.close();
|
|
801
|
-
const depsToOptimize = await captureDependenciesToOptimize(output[0], workspaceMap, projectRoot, {
|
|
802
|
-
logger
|
|
803
|
-
});
|
|
804
|
-
return {
|
|
805
|
-
dependencies: depsToOptimize,
|
|
806
|
-
output: {
|
|
807
|
-
code: output[0].code,
|
|
808
|
-
map: output[0].map
|
|
809
|
-
}
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
function aliasHono() {
|
|
813
|
-
return {
|
|
814
|
-
name: "hono-alias",
|
|
815
|
-
resolveId(id) {
|
|
816
|
-
if (!id.startsWith("@hono/") && !id.startsWith("hono/") && id !== "hono" && id !== "hono-openapi") {
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
const path3 = undefined(id);
|
|
820
|
-
return url.fileURLToPath(path3);
|
|
821
|
-
}
|
|
822
|
-
};
|
|
823
|
-
}
|
|
824
|
-
function prepareEntryFileName(name, rootDir) {
|
|
825
|
-
return rollupSafeName(name, rootDir);
|
|
826
|
-
}
|
|
827
|
-
function createVirtualDependencies(depsToOptimize, {
|
|
828
|
-
projectRoot,
|
|
829
|
-
workspaceRoot,
|
|
830
|
-
outputDir,
|
|
831
|
-
bundlerOptions
|
|
832
|
-
}) {
|
|
833
|
-
const { isDev = false } = bundlerOptions || {};
|
|
834
|
-
const fileNameToDependencyMap = /* @__PURE__ */ new Map();
|
|
835
|
-
const optimizedDependencyEntries = /* @__PURE__ */ new Map();
|
|
836
|
-
const rootDir = workspaceRoot || projectRoot;
|
|
837
|
-
for (const [dep, { exports: exports2 }] of depsToOptimize.entries()) {
|
|
838
|
-
const fileName = dep.replaceAll("/", "-");
|
|
839
|
-
const virtualFile = [];
|
|
840
|
-
const exportStringBuilder = [];
|
|
841
|
-
for (const local of exports2) {
|
|
842
|
-
if (local === "*") {
|
|
843
|
-
virtualFile.push(`export * from '${dep}';`);
|
|
844
|
-
continue;
|
|
845
|
-
} else if (local === "default") {
|
|
846
|
-
exportStringBuilder.push("default");
|
|
847
|
-
} else {
|
|
848
|
-
exportStringBuilder.push(local);
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
const chunks = [];
|
|
852
|
-
if (exportStringBuilder.length) {
|
|
853
|
-
chunks.push(`{ ${exportStringBuilder.join(", ")} }`);
|
|
854
|
-
}
|
|
855
|
-
if (chunks.length) {
|
|
856
|
-
virtualFile.push(`export ${chunks.join(", ")} from '${dep}';`);
|
|
857
|
-
}
|
|
858
|
-
let entryName = prepareEntryFileName(path2__namespace.join(outputDir, fileName), rootDir);
|
|
859
|
-
fileNameToDependencyMap.set(entryName, dep);
|
|
860
|
-
optimizedDependencyEntries.set(dep, {
|
|
861
|
-
name: entryName,
|
|
862
|
-
virtual: virtualFile.join("\n")
|
|
863
|
-
});
|
|
864
|
-
}
|
|
865
|
-
if (isDev) {
|
|
866
|
-
for (const [dep, { isWorkspace, rootPath }] of depsToOptimize.entries()) {
|
|
867
|
-
if (!isWorkspace || !rootPath || !workspaceRoot) {
|
|
868
|
-
continue;
|
|
869
|
-
}
|
|
870
|
-
const currentDepPath = optimizedDependencyEntries.get(dep);
|
|
871
|
-
if (!currentDepPath) {
|
|
872
|
-
continue;
|
|
873
|
-
}
|
|
874
|
-
const fileName = posix.basename(currentDepPath.name);
|
|
875
|
-
const entryName = prepareEntryFileName(getCompiledDepCachePath(rootPath, fileName), rootDir);
|
|
876
|
-
fileNameToDependencyMap.set(entryName, dep);
|
|
877
|
-
optimizedDependencyEntries.set(dep, {
|
|
878
|
-
...currentDepPath,
|
|
879
|
-
name: entryName
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
return { optimizedDependencyEntries, fileNameToDependencyMap };
|
|
884
|
-
}
|
|
885
|
-
async function getInputPlugins2(virtualDependencies, {
|
|
886
|
-
transpilePackages,
|
|
887
|
-
workspaceMap,
|
|
888
|
-
bundlerOptions,
|
|
889
|
-
rootDir
|
|
890
|
-
}) {
|
|
891
|
-
const transpilePackagesMap = /* @__PURE__ */ new Map();
|
|
892
|
-
for (const pkg2 of transpilePackages) {
|
|
893
|
-
const dir = await getPackageRootPath(pkg2);
|
|
894
|
-
if (dir) {
|
|
895
|
-
transpilePackagesMap.set(pkg2, slash(dir));
|
|
896
|
-
} else {
|
|
897
|
-
transpilePackagesMap.set(pkg2, workspaceMap.get(pkg2)?.location ?? pkg2);
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
return [
|
|
901
|
-
virtual__default.default(
|
|
902
|
-
Array.from(virtualDependencies.entries()).reduce(
|
|
903
|
-
(acc, [dep, virtualDep]) => {
|
|
904
|
-
acc[`#virtual-${dep}`] = virtualDep.virtual;
|
|
905
|
-
return acc;
|
|
906
|
-
},
|
|
907
|
-
{}
|
|
908
|
-
)
|
|
909
|
-
),
|
|
910
|
-
transpilePackagesMap.size ? esbuild({
|
|
911
|
-
format: "esm",
|
|
912
|
-
include: [...transpilePackagesMap.values()].map((p) => {
|
|
913
|
-
if (path2__namespace.isAbsolute(p)) {
|
|
914
|
-
return new RegExp(`^${p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/(?!.*node_modules).*$`);
|
|
915
|
-
} else {
|
|
916
|
-
return new RegExp(`/${p.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/(?!.*node_modules).*$`);
|
|
917
|
-
}
|
|
918
|
-
})
|
|
919
|
-
}) : null,
|
|
920
|
-
bundlerOptions.isDev ? {
|
|
921
|
-
name: "alias-optimized-deps",
|
|
922
|
-
async resolveId(id, importer, options) {
|
|
923
|
-
if (!virtualDependencies.has(id)) {
|
|
924
|
-
return null;
|
|
925
|
-
}
|
|
926
|
-
const info = virtualDependencies.get(id);
|
|
927
|
-
const packageRootPath = path2__namespace.join(rootDir, path2__namespace.dirname(path2__namespace.dirname(path2__namespace.dirname(info.name))));
|
|
928
|
-
const pkgJsonBuffer = await promises.readFile(path2__namespace.join(packageRootPath, "package.json"), "utf-8");
|
|
929
|
-
const pkgJson = JSON.parse(pkgJsonBuffer);
|
|
930
|
-
if (!pkgJson) {
|
|
931
|
-
return null;
|
|
932
|
-
}
|
|
933
|
-
const pkgName = pkgJson.name || "";
|
|
934
|
-
let resolvedPath = resolve__namespace.exports(pkgJson, id.replace(pkgName, "."))?.[0];
|
|
935
|
-
if (!resolvedPath) {
|
|
936
|
-
resolvedPath = pkgJson.main ?? "index.js";
|
|
937
|
-
}
|
|
938
|
-
return await this.resolve(path2__namespace.posix.join(packageRootPath, resolvedPath), importer, options);
|
|
939
|
-
}
|
|
940
|
-
} : null,
|
|
941
|
-
rollupPlugin.optimizeLodashImports({
|
|
942
|
-
include: "**/*.{js,ts,mjs,cjs}"
|
|
943
|
-
}),
|
|
944
|
-
commonjs__default.default({
|
|
945
|
-
strictRequires: "strict",
|
|
946
|
-
transformMixedEsModules: true,
|
|
947
|
-
ignoreTryCatch: false
|
|
948
|
-
}),
|
|
949
|
-
bundlerOptions.isDev ? null : nodeResolve__default.default(),
|
|
950
|
-
bundlerOptions.isDev ? esmShim__default.default() : null,
|
|
951
|
-
// hono is imported from deployer, so we need to resolve from here instead of the project root
|
|
952
|
-
aliasHono(),
|
|
953
|
-
json__default.default(),
|
|
954
|
-
{
|
|
955
|
-
name: "not-found-resolver",
|
|
956
|
-
resolveId: {
|
|
957
|
-
order: "post",
|
|
958
|
-
async handler(id, importer) {
|
|
959
|
-
if (!importer) {
|
|
960
|
-
return null;
|
|
961
|
-
}
|
|
962
|
-
if (!id.endsWith(".node")) {
|
|
963
|
-
return null;
|
|
964
|
-
}
|
|
965
|
-
const pkgInfo = await localPkg.getPackageInfo(importer);
|
|
966
|
-
const packageName = pkgInfo?.packageJson?.name || id;
|
|
967
|
-
throw new error.MastraBaseError({
|
|
968
|
-
id: "DEPLOYER_BUNDLE_EXTERNALS_MISSING_NATIVE_BUILD",
|
|
969
|
-
domain: error.ErrorDomain.DEPLOYER,
|
|
970
|
-
category: error.ErrorCategory.USER,
|
|
971
|
-
details: {
|
|
972
|
-
importFile: importer,
|
|
973
|
-
packageName
|
|
974
|
-
},
|
|
975
|
-
text: `We found a binary dependency in your bundle. Please add \`${packageName}\` to your externals.
|
|
976
|
-
|
|
977
|
-
export const mastra = new Mastra({
|
|
978
|
-
bundler: {
|
|
979
|
-
externals: ["${packageName}"],
|
|
980
|
-
}
|
|
981
|
-
})`
|
|
982
|
-
});
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
].filter(Boolean);
|
|
987
|
-
}
|
|
988
|
-
async function buildExternalDependencies(virtualDependencies, {
|
|
989
|
-
externals,
|
|
990
|
-
packagesToTranspile,
|
|
991
|
-
workspaceMap,
|
|
992
|
-
rootDir,
|
|
993
|
-
outputDir,
|
|
994
|
-
bundlerOptions
|
|
995
|
-
}) {
|
|
996
|
-
if (virtualDependencies.size === 0) {
|
|
997
|
-
return [];
|
|
998
|
-
}
|
|
999
|
-
const bundler = await rollup.rollup({
|
|
1000
|
-
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
1001
|
-
input: Array.from(virtualDependencies.entries()).reduce(
|
|
1002
|
-
(acc, [dep, virtualDep]) => {
|
|
1003
|
-
acc[virtualDep.name] = `#virtual-${dep}`;
|
|
1004
|
-
return acc;
|
|
1005
|
-
},
|
|
1006
|
-
{}
|
|
1007
|
-
),
|
|
1008
|
-
external: externals,
|
|
1009
|
-
treeshake: "smallest",
|
|
1010
|
-
plugins: getInputPlugins2(virtualDependencies, {
|
|
1011
|
-
transpilePackages: packagesToTranspile,
|
|
1012
|
-
workspaceMap,
|
|
1013
|
-
bundlerOptions,
|
|
1014
|
-
rootDir
|
|
1015
|
-
})
|
|
1016
|
-
});
|
|
1017
|
-
const outputDirRelative = prepareEntryFileName(outputDir, rootDir);
|
|
1018
|
-
const { output } = await bundler.write({
|
|
1019
|
-
format: "esm",
|
|
1020
|
-
dir: rootDir,
|
|
1021
|
-
entryFileNames: "[name].mjs",
|
|
1022
|
-
/**
|
|
1023
|
-
* Rollup creates chunks for common dependencies, but these chunks are by default written to the root directory instead of respecting the entryFileNames structure.
|
|
1024
|
-
* So we want to write them to the `.mastra/output` folder as well.
|
|
1025
|
-
*/
|
|
1026
|
-
chunkFileNames: (chunkInfo) => {
|
|
1027
|
-
if (bundlerOptions.isDev) {
|
|
1028
|
-
const importedFromPackages = /* @__PURE__ */ new Set();
|
|
1029
|
-
for (const moduleId of chunkInfo.moduleIds) {
|
|
1030
|
-
const normalized = slash(moduleId);
|
|
1031
|
-
for (const [pkgName, pkgInfo] of workspaceMap.entries()) {
|
|
1032
|
-
const location = slash(pkgInfo.location);
|
|
1033
|
-
if (normalized.startsWith(location)) {
|
|
1034
|
-
importedFromPackages.add(pkgName);
|
|
1035
|
-
break;
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
if (importedFromPackages.size > 1) {
|
|
1040
|
-
throw new error.MastraBaseError({
|
|
1041
|
-
id: "DEPLOYER_BUNDLE_EXTERNALS_SHARED_CHUNK",
|
|
1042
|
-
domain: error.ErrorDomain.DEPLOYER,
|
|
1043
|
-
category: error.ErrorCategory.USER,
|
|
1044
|
-
details: {
|
|
1045
|
-
chunkName: chunkInfo.name,
|
|
1046
|
-
packages: JSON.stringify(Array.from(importedFromPackages))
|
|
1047
|
-
},
|
|
1048
|
-
text: `Please open an issue. We found a shared chunk "${chunkInfo.name}" used by multiple workspace packages: ${Array.from(importedFromPackages).join(", ")}.`
|
|
1049
|
-
});
|
|
1050
|
-
}
|
|
1051
|
-
if (importedFromPackages.size === 1) {
|
|
1052
|
-
const [pkgName] = importedFromPackages;
|
|
1053
|
-
const workspaceLocation = workspaceMap.get(pkgName).location;
|
|
1054
|
-
return prepareEntryFileName(getCompiledDepCachePath(workspaceLocation, "[name].mjs"), rootDir);
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
return `${outputDirRelative}/[name].mjs`;
|
|
1058
|
-
},
|
|
1059
|
-
hoistTransitiveImports: false
|
|
1060
|
-
});
|
|
1061
|
-
await bundler.close();
|
|
1062
|
-
return output;
|
|
1063
|
-
}
|
|
1064
|
-
function findExternalImporter(module, external, allOutputs) {
|
|
1065
|
-
const capturedFiles = /* @__PURE__ */ new Set();
|
|
1066
|
-
for (const id of module.imports) {
|
|
1067
|
-
if (id === external) {
|
|
1068
|
-
return module;
|
|
1069
|
-
} else {
|
|
1070
|
-
if (id.endsWith(".mjs")) {
|
|
1071
|
-
capturedFiles.add(id);
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
for (const file of capturedFiles) {
|
|
1076
|
-
const nextModule = allOutputs.find((o) => o.fileName === file);
|
|
1077
|
-
if (nextModule) {
|
|
1078
|
-
const importer = findExternalImporter(nextModule, external, allOutputs);
|
|
1079
|
-
if (importer) {
|
|
1080
|
-
return importer;
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
return null;
|
|
1085
|
-
}
|
|
1086
|
-
async function bundleExternals(depsToOptimize, outputDir, options) {
|
|
1087
|
-
const { workspaceRoot = null, workspaceMap = /* @__PURE__ */ new Map(), projectRoot = outputDir, bundlerOptions = {} } = options;
|
|
1088
|
-
const {
|
|
1089
|
-
externals: customExternals = [],
|
|
1090
|
-
transpilePackages = [],
|
|
1091
|
-
isDev = false} = bundlerOptions || {};
|
|
1092
|
-
const allExternals = [...GLOBAL_EXTERNALS, ...DEPRECATED_EXTERNALS, ...customExternals];
|
|
1093
|
-
const workspacePackagesNames = Array.from(workspaceMap.keys());
|
|
1094
|
-
const packagesToTranspile = /* @__PURE__ */ new Set([...transpilePackages, ...workspacePackagesNames]);
|
|
1095
|
-
const { optimizedDependencyEntries, fileNameToDependencyMap } = createVirtualDependencies(depsToOptimize, {
|
|
1096
|
-
workspaceRoot,
|
|
1097
|
-
outputDir,
|
|
1098
|
-
projectRoot,
|
|
1099
|
-
bundlerOptions: {
|
|
1100
|
-
isDev
|
|
1101
|
-
}
|
|
1102
|
-
});
|
|
1103
|
-
const output = await buildExternalDependencies(optimizedDependencyEntries, {
|
|
1104
|
-
externals: allExternals,
|
|
1105
|
-
packagesToTranspile,
|
|
1106
|
-
workspaceMap,
|
|
1107
|
-
rootDir: workspaceRoot || projectRoot,
|
|
1108
|
-
outputDir,
|
|
1109
|
-
bundlerOptions: {
|
|
1110
|
-
isDev
|
|
1111
|
-
}
|
|
1112
|
-
});
|
|
1113
|
-
const moduleResolveMap = /* @__PURE__ */ new Map();
|
|
1114
|
-
const filteredChunks = output.filter((o) => o.type === "chunk");
|
|
1115
|
-
for (const o of filteredChunks.filter((o2) => o2.isEntry || o2.isDynamicEntry)) {
|
|
1116
|
-
for (const external of allExternals) {
|
|
1117
|
-
if (DEPS_TO_IGNORE.includes(external)) {
|
|
1118
|
-
continue;
|
|
1119
|
-
}
|
|
1120
|
-
const importer = findExternalImporter(o, external, filteredChunks);
|
|
1121
|
-
if (importer) {
|
|
1122
|
-
const fullPath = path2__namespace.join(workspaceRoot || projectRoot, importer.fileName);
|
|
1123
|
-
let innerMap = moduleResolveMap.get(fullPath);
|
|
1124
|
-
if (!innerMap) {
|
|
1125
|
-
innerMap = /* @__PURE__ */ new Map();
|
|
1126
|
-
moduleResolveMap.set(fullPath, innerMap);
|
|
1127
|
-
}
|
|
1128
|
-
if (importer.moduleIds.length) {
|
|
1129
|
-
innerMap.set(
|
|
1130
|
-
external,
|
|
1131
|
-
importer.moduleIds[importer.moduleIds.length - 1]?.startsWith("\0virtual:#virtual") ? importer.moduleIds[importer.moduleIds.length - 2] : importer.moduleIds[importer.moduleIds.length - 1]
|
|
1132
|
-
);
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
const usedExternals = /* @__PURE__ */ Object.create(null);
|
|
1138
|
-
for (const [fullPath, innerMap] of moduleResolveMap) {
|
|
1139
|
-
const innerObj = /* @__PURE__ */ Object.create(null);
|
|
1140
|
-
for (const [external, value] of innerMap) {
|
|
1141
|
-
innerObj[external] = value;
|
|
1142
|
-
}
|
|
1143
|
-
usedExternals[fullPath] = innerObj;
|
|
1144
|
-
}
|
|
1145
|
-
return { output, fileNameToDependencyMap, usedExternals };
|
|
1146
|
-
}
|
|
1147
|
-
async function validateOutput({
|
|
1148
|
-
output,
|
|
1149
|
-
reverseVirtualReferenceMap,
|
|
1150
|
-
usedExternals,
|
|
1151
|
-
outputDir,
|
|
1152
|
-
projectRoot,
|
|
1153
|
-
workspaceMap
|
|
1154
|
-
}, logger) {
|
|
1155
|
-
const result = {
|
|
1156
|
-
dependencies: /* @__PURE__ */ new Map(),
|
|
1157
|
-
externalDependencies: /* @__PURE__ */ new Set(),
|
|
1158
|
-
workspaceMap
|
|
1159
|
-
};
|
|
1160
|
-
await promises.writeFile(path2.join(outputDir, "module-resolve-map.json"), JSON.stringify(usedExternals, null, 2));
|
|
1161
|
-
for (const deps of Object.values(usedExternals)) {
|
|
1162
|
-
for (const dep of Object.keys(deps)) {
|
|
1163
|
-
result.externalDependencies.add(dep);
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
for (const file of output) {
|
|
1167
|
-
if (file.type === "asset") {
|
|
1168
|
-
continue;
|
|
1169
|
-
}
|
|
1170
|
-
try {
|
|
1171
|
-
logger.debug(`Validating if ${file.fileName} is a valid module.`);
|
|
1172
|
-
if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
|
|
1173
|
-
result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
|
|
1174
|
-
}
|
|
1175
|
-
if (!file.isDynamicEntry && file.isEntry) {
|
|
1176
|
-
await validate(path2.join(projectRoot, file.fileName));
|
|
1177
|
-
}
|
|
1178
|
-
} catch (err) {
|
|
1179
|
-
if (err instanceof Error && err.message.includes("Error: No native build was found for ")) {
|
|
1180
|
-
const moduleName = findNativePackageModule(file.moduleIds);
|
|
1181
|
-
if (!moduleName) {
|
|
1182
|
-
logger.debug(`Could not determine the module name for file ${file.fileName}`);
|
|
1183
|
-
continue;
|
|
1184
|
-
}
|
|
1185
|
-
const pkgInfo = await localPkg.getPackageInfo(moduleName);
|
|
1186
|
-
const packageName = pkgInfo?.packageJson?.name;
|
|
1187
|
-
if (packageName) {
|
|
1188
|
-
throw new error.MastraError({
|
|
1189
|
-
id: "DEPLOYER_ANALYZE_MISSING_NATIVE_BUILD",
|
|
1190
|
-
domain: error.ErrorDomain.DEPLOYER,
|
|
1191
|
-
category: error.ErrorCategory.USER,
|
|
1192
|
-
details: {
|
|
1193
|
-
importFile: moduleName,
|
|
1194
|
-
packageName
|
|
1195
|
-
},
|
|
1196
|
-
text: `We found a binary dependency in your bundle. Please add \`${packageName}\` to your externals.
|
|
1197
|
-
|
|
1198
|
-
export const mastra = new Mastra({
|
|
1199
|
-
bundler: {
|
|
1200
|
-
externals: ["${packageName}"],
|
|
1201
|
-
}
|
|
1202
|
-
})`
|
|
1203
|
-
});
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
return result;
|
|
1209
|
-
}
|
|
1210
|
-
async function analyzeBundle(entries, mastraEntry, {
|
|
1211
|
-
outputDir,
|
|
1212
|
-
projectRoot,
|
|
1213
|
-
isDev = false,
|
|
1214
|
-
bundlerOptions: _bundlerOptions
|
|
1215
|
-
}, logger) {
|
|
1216
|
-
const mastraConfig = await promises.readFile(mastraEntry, "utf-8");
|
|
1217
|
-
const mastraConfigResult = {
|
|
1218
|
-
hasValidConfig: false
|
|
1219
|
-
};
|
|
1220
|
-
await babel__namespace.transformAsync(mastraConfig, {
|
|
1221
|
-
filename: mastraEntry,
|
|
1222
|
-
presets: [undefined("@babel/preset-typescript")],
|
|
1223
|
-
plugins: [checkConfigExport(mastraConfigResult)]
|
|
1224
|
-
});
|
|
1225
|
-
if (!mastraConfigResult.hasValidConfig) {
|
|
1226
|
-
logger.warn(`Invalid Mastra config. Please make sure that your entry file looks like this:
|
|
1227
|
-
export const mastra = new Mastra({
|
|
1228
|
-
// your options
|
|
1229
|
-
})
|
|
1230
|
-
|
|
1231
|
-
If you think your configuration is valid, please open an issue.`);
|
|
1232
|
-
}
|
|
1233
|
-
const { enableEsmShim = true } = _bundlerOptions || {};
|
|
1234
|
-
const bundlerOptions = await getBundlerOptions(mastraEntry, outputDir);
|
|
1235
|
-
const { workspaceMap, workspaceRoot } = await getWorkspaceInformation({ mastraEntryFile: mastraEntry });
|
|
1236
|
-
let index = 0;
|
|
1237
|
-
const depsToOptimize = /* @__PURE__ */ new Map();
|
|
1238
|
-
logger.info("Analyzing dependencies...");
|
|
1239
|
-
for (const entry of entries) {
|
|
1240
|
-
const isVirtualFile = entry.includes("\n") || !fs.existsSync(entry);
|
|
1241
|
-
const analyzeResult = await analyzeEntry({ entry, isVirtualFile }, mastraEntry, {
|
|
1242
|
-
logger,
|
|
1243
|
-
sourcemapEnabled: bundlerOptions?.sourcemap ?? false,
|
|
1244
|
-
workspaceMap,
|
|
1245
|
-
projectRoot
|
|
1246
|
-
});
|
|
1247
|
-
await promises.writeFile(path2.join(outputDir, `entry-${index++}.mjs`), analyzeResult.output.code);
|
|
1248
|
-
for (const [dep, metadata] of analyzeResult.dependencies.entries()) {
|
|
1249
|
-
if (depsToOptimize.has(dep)) {
|
|
1250
|
-
const existingEntry = depsToOptimize.get(dep);
|
|
1251
|
-
depsToOptimize.set(dep, {
|
|
1252
|
-
...existingEntry,
|
|
1253
|
-
exports: [.../* @__PURE__ */ new Set([...existingEntry.exports, ...metadata.exports])]
|
|
1254
|
-
});
|
|
1255
|
-
} else {
|
|
1256
|
-
depsToOptimize.set(dep, metadata);
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
if (isDev) {
|
|
1261
|
-
for (const [dep, metadata] of depsToOptimize.entries()) {
|
|
1262
|
-
if (!metadata.isWorkspace) {
|
|
1263
|
-
depsToOptimize.delete(dep);
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
logger.debug(`Analyzed dependencies: ${Array.from(depsToOptimize.keys()).join(", ")}`);
|
|
1268
|
-
logger.info("Optimizing dependencies...");
|
|
1269
|
-
logger.debug(
|
|
1270
|
-
`${Array.from(depsToOptimize.keys()).map((key) => `- ${key}`).join("\n")}`
|
|
1271
|
-
);
|
|
1272
|
-
const { output, fileNameToDependencyMap, usedExternals } = await bundleExternals(depsToOptimize, outputDir, {
|
|
1273
|
-
bundlerOptions: {
|
|
1274
|
-
...bundlerOptions,
|
|
1275
|
-
enableEsmShim,
|
|
1276
|
-
isDev
|
|
1277
|
-
},
|
|
1278
|
-
projectRoot,
|
|
1279
|
-
workspaceRoot,
|
|
1280
|
-
workspaceMap
|
|
1281
|
-
});
|
|
1282
|
-
const result = await validateOutput(
|
|
1283
|
-
{
|
|
1284
|
-
output,
|
|
1285
|
-
reverseVirtualReferenceMap: fileNameToDependencyMap,
|
|
1286
|
-
usedExternals,
|
|
1287
|
-
outputDir,
|
|
1288
|
-
projectRoot: workspaceRoot || projectRoot,
|
|
1289
|
-
workspaceMap
|
|
1290
|
-
},
|
|
1291
|
-
logger
|
|
1292
|
-
);
|
|
1293
|
-
return result;
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
exports.aliasHono = aliasHono;
|
|
1297
|
-
exports.analyzeBundle = analyzeBundle;
|
|
1298
|
-
exports.esbuild = esbuild;
|
|
1299
|
-
exports.extractMastraOption = extractMastraOption;
|
|
1300
|
-
exports.getBundlerOptions = getBundlerOptions;
|
|
1301
|
-
exports.getPackageName = getPackageName;
|
|
1302
|
-
exports.getPackageRootPath = getPackageRootPath;
|
|
1303
|
-
exports.getWorkspaceInformation = getWorkspaceInformation;
|
|
1304
|
-
exports.removeAllOptionsFromMastraExcept = removeAllOptionsFromMastraExcept;
|
|
1305
|
-
exports.removeDeployer = removeDeployer2;
|
|
1306
|
-
exports.slash = slash;
|
|
1307
|
-
exports.tsConfigPaths = tsConfigPaths;
|
|
1308
|
-
//# sourceMappingURL=chunk-MCDDO4WY.cjs.map
|
|
1309
|
-
//# sourceMappingURL=chunk-MCDDO4WY.cjs.map
|