@mastra/deployer 0.10.13 → 0.10.15-alpha.0

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.
Files changed (56) hide show
  1. package/dist/_tsup-dts-rollup.d.cts +844 -0
  2. package/dist/_tsup-dts-rollup.d.ts +844 -0
  3. package/dist/build/analyze.cjs +10 -0
  4. package/dist/build/analyze.d.cts +1 -0
  5. package/dist/build/analyze.d.ts +1 -0
  6. package/dist/build/analyze.js +1 -0
  7. package/dist/build/bundler.cjs +14 -0
  8. package/dist/build/bundler.d.cts +2 -0
  9. package/dist/build/bundler.d.ts +2 -0
  10. package/dist/build/bundler.js +1 -0
  11. package/dist/build/index.cjs +50 -0
  12. package/dist/build/index.d.cts +10 -0
  13. package/dist/build/index.d.ts +10 -0
  14. package/dist/build/index.js +5 -0
  15. package/dist/bundler/index.cjs +10 -0
  16. package/dist/bundler/index.d.cts +1 -0
  17. package/dist/bundler/index.d.ts +1 -0
  18. package/dist/bundler/index.js +1 -0
  19. package/dist/chunk-54KOF3NB.cjs +137 -0
  20. package/dist/chunk-6QMONK4A.cjs +2 -0
  21. package/dist/chunk-C4JT7CIH.js +1 -0
  22. package/dist/chunk-D2DCFCLH.cjs +157 -0
  23. package/dist/chunk-D6736SJL.js +209 -0
  24. package/dist/chunk-ENT5RDOI.js +99 -0
  25. package/dist/chunk-FK2WUSEN.cjs +238 -0
  26. package/dist/chunk-GPD54HBC.js +380 -0
  27. package/dist/chunk-HJGC75ZR.js +490 -0
  28. package/dist/chunk-KCP5ITLV.cjs +412 -0
  29. package/dist/chunk-M2VZQFTW.cjs +125 -0
  30. package/dist/chunk-TIC2KT3M.js +146 -0
  31. package/dist/chunk-UYQZMNZL.js +572 -0
  32. package/dist/chunk-XKH6F4NE.cjs +604 -0
  33. package/dist/chunk-YFMAWUII.cjs +502 -0
  34. package/dist/chunk-Z544XXXK.js +111 -0
  35. package/dist/index.cjs +194 -0
  36. package/dist/index.d.cts +8 -0
  37. package/dist/index.d.ts +8 -0
  38. package/dist/index.js +153 -0
  39. package/dist/server/index.cjs +8446 -0
  40. package/dist/server/index.d.cts +2 -0
  41. package/dist/server/index.d.ts +2 -0
  42. package/dist/server/index.js +8438 -0
  43. package/dist/services/index.cjs +18 -0
  44. package/dist/services/index.d.cts +3 -0
  45. package/dist/services/index.d.ts +3 -0
  46. package/dist/services/index.js +1 -0
  47. package/dist/templates/instrumentation-template.js +137 -0
  48. package/dist/validator/custom-resolver.cjs +52 -0
  49. package/dist/validator/custom-resolver.d.cts +1 -0
  50. package/dist/validator/custom-resolver.d.ts +1 -0
  51. package/dist/validator/custom-resolver.js +50 -0
  52. package/dist/validator/loader.cjs +7 -0
  53. package/dist/validator/loader.d.cts +1 -0
  54. package/dist/validator/loader.d.ts +1 -0
  55. package/dist/validator/loader.js +4 -0
  56. package/package.json +5 -5
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var chunkXKH6F4NE_cjs = require('../chunk-XKH6F4NE.cjs');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "analyzeBundle", {
8
+ enumerable: true,
9
+ get: function () { return chunkXKH6F4NE_cjs.analyzeBundle; }
10
+ });
@@ -0,0 +1 @@
1
+ export { analyzeBundle } from '../_tsup-dts-rollup.cjs';
@@ -0,0 +1 @@
1
+ export { analyzeBundle } from '../_tsup-dts-rollup.js';
@@ -0,0 +1 @@
1
+ export { analyzeBundle } from '../chunk-UYQZMNZL.js';
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var chunkD2DCFCLH_cjs = require('../chunk-D2DCFCLH.cjs');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "createBundler", {
8
+ enumerable: true,
9
+ get: function () { return chunkD2DCFCLH_cjs.createBundler; }
10
+ });
11
+ Object.defineProperty(exports, "getInputOptions", {
12
+ enumerable: true,
13
+ get: function () { return chunkD2DCFCLH_cjs.getInputOptions; }
14
+ });
@@ -0,0 +1,2 @@
1
+ export { getInputOptions } from '../_tsup-dts-rollup.cjs';
2
+ export { createBundler } from '../_tsup-dts-rollup.cjs';
@@ -0,0 +1,2 @@
1
+ export { getInputOptions } from '../_tsup-dts-rollup.js';
2
+ export { createBundler } from '../_tsup-dts-rollup.js';
@@ -0,0 +1 @@
1
+ export { createBundler, getInputOptions } from '../chunk-TIC2KT3M.js';
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ var chunkFK2WUSEN_cjs = require('../chunk-FK2WUSEN.cjs');
4
+ var chunkM2VZQFTW_cjs = require('../chunk-M2VZQFTW.cjs');
5
+ var chunkXKH6F4NE_cjs = require('../chunk-XKH6F4NE.cjs');
6
+ var chunkD2DCFCLH_cjs = require('../chunk-D2DCFCLH.cjs');
7
+ var chunkKCP5ITLV_cjs = require('../chunk-KCP5ITLV.cjs');
8
+
9
+
10
+
11
+ Object.defineProperty(exports, "createWatcher", {
12
+ enumerable: true,
13
+ get: function () { return chunkFK2WUSEN_cjs.createWatcher; }
14
+ });
15
+ Object.defineProperty(exports, "getServerOptions", {
16
+ enumerable: true,
17
+ get: function () { return chunkFK2WUSEN_cjs.getServerOptions; }
18
+ });
19
+ Object.defineProperty(exports, "getWatcherInputOptions", {
20
+ enumerable: true,
21
+ get: function () { return chunkFK2WUSEN_cjs.getInputOptions; }
22
+ });
23
+ Object.defineProperty(exports, "writeTelemetryConfig", {
24
+ enumerable: true,
25
+ get: function () { return chunkM2VZQFTW_cjs.writeTelemetryConfig; }
26
+ });
27
+ Object.defineProperty(exports, "analyzeBundle", {
28
+ enumerable: true,
29
+ get: function () { return chunkXKH6F4NE_cjs.analyzeBundle; }
30
+ });
31
+ Object.defineProperty(exports, "getBundlerOptions", {
32
+ enumerable: true,
33
+ get: function () { return chunkXKH6F4NE_cjs.getBundlerOptions; }
34
+ });
35
+ Object.defineProperty(exports, "createBundler", {
36
+ enumerable: true,
37
+ get: function () { return chunkD2DCFCLH_cjs.createBundler; }
38
+ });
39
+ Object.defineProperty(exports, "getBundlerInputOptions", {
40
+ enumerable: true,
41
+ get: function () { return chunkD2DCFCLH_cjs.getInputOptions; }
42
+ });
43
+ Object.defineProperty(exports, "Deps", {
44
+ enumerable: true,
45
+ get: function () { return chunkKCP5ITLV_cjs.Deps; }
46
+ });
47
+ Object.defineProperty(exports, "FileService", {
48
+ enumerable: true,
49
+ get: function () { return chunkKCP5ITLV_cjs.FileService; }
50
+ });
@@ -0,0 +1,10 @@
1
+ export { createBundler_alias_1 as createBundler } from '../_tsup-dts-rollup.cjs';
2
+ export { getBundlerInputOptions } from '../_tsup-dts-rollup.cjs';
3
+ export { createWatcher } from '../_tsup-dts-rollup.cjs';
4
+ export { getWatcherInputOptions } from '../_tsup-dts-rollup.cjs';
5
+ export { analyzeBundle_alias_1 as analyzeBundle } from '../_tsup-dts-rollup.cjs';
6
+ export { FileService_alias_1 as FileService } from '../_tsup-dts-rollup.cjs';
7
+ export { Deps_alias_1 as Deps } from '../_tsup-dts-rollup.cjs';
8
+ export { writeTelemetryConfig } from '../_tsup-dts-rollup.cjs';
9
+ export { getServerOptions } from '../_tsup-dts-rollup.cjs';
10
+ export { getBundlerOptions_alias_1 as getBundlerOptions } from '../_tsup-dts-rollup.cjs';
@@ -0,0 +1,10 @@
1
+ export { createBundler_alias_1 as createBundler } from '../_tsup-dts-rollup.js';
2
+ export { getBundlerInputOptions } from '../_tsup-dts-rollup.js';
3
+ export { createWatcher } from '../_tsup-dts-rollup.js';
4
+ export { getWatcherInputOptions } from '../_tsup-dts-rollup.js';
5
+ export { analyzeBundle_alias_1 as analyzeBundle } from '../_tsup-dts-rollup.js';
6
+ export { FileService_alias_1 as FileService } from '../_tsup-dts-rollup.js';
7
+ export { Deps_alias_1 as Deps } from '../_tsup-dts-rollup.js';
8
+ export { writeTelemetryConfig } from '../_tsup-dts-rollup.js';
9
+ export { getServerOptions } from '../_tsup-dts-rollup.js';
10
+ export { getBundlerOptions_alias_1 as getBundlerOptions } from '../_tsup-dts-rollup.js';
@@ -0,0 +1,5 @@
1
+ export { createWatcher, getServerOptions, getInputOptions as getWatcherInputOptions } from '../chunk-D6736SJL.js';
2
+ export { writeTelemetryConfig } from '../chunk-ENT5RDOI.js';
3
+ export { analyzeBundle, getBundlerOptions } from '../chunk-UYQZMNZL.js';
4
+ export { createBundler, getInputOptions as getBundlerInputOptions } from '../chunk-TIC2KT3M.js';
5
+ export { Deps, FileService } from '../chunk-GPD54HBC.js';
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ var chunkYFMAWUII_cjs = require('../chunk-YFMAWUII.cjs');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, "Bundler", {
8
+ enumerable: true,
9
+ get: function () { return chunkYFMAWUII_cjs.Bundler; }
10
+ });
@@ -0,0 +1 @@
1
+ export { Bundler } from '../_tsup-dts-rollup.cjs';
@@ -0,0 +1 @@
1
+ export { Bundler } from '../_tsup-dts-rollup.js';
@@ -0,0 +1 @@
1
+ export { Bundler } from '../chunk-HJGC75ZR.js';
@@ -0,0 +1,137 @@
1
+ 'use strict';
2
+
3
+ var babel = require('@babel/core');
4
+ var fs = require('fs');
5
+ var path = require('path');
6
+ var typescriptPaths = require('typescript-paths');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ function _interopNamespace(e) {
11
+ if (e && e.__esModule) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
29
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
30
+ var path__default = /*#__PURE__*/_interopDefault(path);
31
+
32
+ // src/build/plugins/remove-deployer.ts
33
+ function removeDeployer() {
34
+ const t = babel__namespace.default.types;
35
+ return {
36
+ name: "remove-deployer",
37
+ visitor: {
38
+ NewExpression(path2, state) {
39
+ const varDeclaratorPath = path2.findParent((path3) => t.isVariableDeclarator(path3.node));
40
+ if (!varDeclaratorPath) {
41
+ return;
42
+ }
43
+ const parentNode = path2.parentPath.node;
44
+ if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
45
+ return;
46
+ }
47
+ if (!state.hasReplaced) {
48
+ state.hasReplaced = true;
49
+ const newMastraObj = t.cloneNode(path2.node);
50
+ if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.[0]) {
51
+ const deployer = newMastraObj.arguments[0].properties.find(
52
+ (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "deployer"
53
+ );
54
+ if (!deployer) {
55
+ return;
56
+ }
57
+ newMastraObj.arguments[0].properties = newMastraObj.arguments[0].properties.filter(
58
+ (prop) => prop !== deployer
59
+ );
60
+ if (t.isObjectProperty(deployer) && t.isIdentifier(deployer.value)) {
61
+ const deployerBinding = state.file.scope.getBinding(deployer.value.name);
62
+ if (deployerBinding) {
63
+ deployerBinding?.path?.parentPath?.remove();
64
+ }
65
+ }
66
+ path2.replaceWith(newMastraObj);
67
+ }
68
+ }
69
+ }
70
+ }
71
+ };
72
+ }
73
+
74
+ // src/build/plugins/remove-deployer.ts
75
+ function removeDeployer2(mastraEntry) {
76
+ return {
77
+ name: "remove-deployer",
78
+ transform(code, id) {
79
+ if (id !== mastraEntry) {
80
+ return;
81
+ }
82
+ return new Promise((resolve, reject) => {
83
+ babel__namespace.transform(
84
+ code,
85
+ {
86
+ babelrc: false,
87
+ configFile: false,
88
+ filename: id,
89
+ plugins: [removeDeployer]
90
+ },
91
+ (err, result) => {
92
+ if (err) {
93
+ return reject(err);
94
+ }
95
+ resolve({
96
+ code: result.code,
97
+ map: result.map
98
+ });
99
+ }
100
+ );
101
+ });
102
+ }
103
+ };
104
+ }
105
+ var PLUGIN_NAME = "tsconfig-paths";
106
+ function tsConfigPaths({ tsConfigPath, respectCoreModule } = {}) {
107
+ let handler;
108
+ return {
109
+ name: PLUGIN_NAME,
110
+ buildStart() {
111
+ handler = typescriptPaths.createHandler({
112
+ log: () => {
113
+ },
114
+ tsConfigPath,
115
+ respectCoreModule,
116
+ falllback: (moduleName) => fs__default.default.existsSync(moduleName)
117
+ });
118
+ return;
119
+ },
120
+ async resolveId(request, importer, options) {
121
+ if (!importer || request.startsWith("\0")) {
122
+ return null;
123
+ }
124
+ const moduleName = handler?.(request, path.normalize(importer));
125
+ if (!moduleName) {
126
+ return this.resolve(request, importer, { skipSelf: true, ...options });
127
+ }
128
+ if (!path__default.default.extname(moduleName)) {
129
+ return this.resolve(moduleName, importer, { skipSelf: true, ...options });
130
+ }
131
+ return moduleName;
132
+ }
133
+ };
134
+ }
135
+
136
+ exports.removeDeployer = removeDeployer2;
137
+ exports.tsConfigPaths = tsConfigPaths;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,157 @@
1
+ 'use strict';
2
+
3
+ var chunk54KOF3NB_cjs = require('./chunk-54KOF3NB.cjs');
4
+ var alias = require('@rollup/plugin-alias');
5
+ var commonjs = require('@rollup/plugin-commonjs');
6
+ var json = require('@rollup/plugin-json');
7
+ var nodeResolve = require('@rollup/plugin-node-resolve');
8
+ var url = require('url');
9
+ var rollup = require('rollup');
10
+ var esbuild = require('rollup-plugin-esbuild');
11
+
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
+
14
+ var alias__default = /*#__PURE__*/_interopDefault(alias);
15
+ var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
16
+ var json__default = /*#__PURE__*/_interopDefault(json);
17
+ var nodeResolve__default = /*#__PURE__*/_interopDefault(nodeResolve);
18
+ var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
19
+
20
+ async function getInputOptions(entryFile, analyzedBundleInfo, platform, env = { "process.env.NODE_ENV": JSON.stringify("production") }) {
21
+ let nodeResolvePlugin = platform === "node" ? nodeResolve__default.default({
22
+ preferBuiltins: true,
23
+ exportConditions: ["node"]
24
+ }) : nodeResolve__default.default({
25
+ preferBuiltins: false,
26
+ browser: true
27
+ });
28
+ const externalsCopy = /* @__PURE__ */ new Set();
29
+ for (const external of analyzedBundleInfo.externalDependencies) {
30
+ if (external.startsWith("@")) {
31
+ const [scope, name] = external.split("/", 3);
32
+ externalsCopy.add(`${scope}/${name}`);
33
+ externalsCopy.add(`${scope}/${name}/*`);
34
+ } else {
35
+ externalsCopy.add(external);
36
+ externalsCopy.add(`${external}/*`);
37
+ }
38
+ }
39
+ const externals = Array.from(externalsCopy);
40
+ const normalizedEntryFile = entryFile.replaceAll("\\", "/");
41
+ return {
42
+ logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
43
+ treeshake: "smallest",
44
+ preserveSymlinks: true,
45
+ external: externals,
46
+ plugins: [
47
+ chunk54KOF3NB_cjs.tsConfigPaths(),
48
+ {
49
+ name: "alias-optimized-deps",
50
+ // @ts-ignore
51
+ resolveId(id) {
52
+ if (!analyzedBundleInfo.dependencies.has(id)) {
53
+ return null;
54
+ }
55
+ const isInvalidChunk = analyzedBundleInfo.invalidChunks.has(analyzedBundleInfo.dependencies.get(id));
56
+ if (isInvalidChunk) {
57
+ return {
58
+ id,
59
+ external: true
60
+ };
61
+ }
62
+ return {
63
+ id: ".mastra/.build/" + analyzedBundleInfo.dependencies.get(id),
64
+ external: false
65
+ };
66
+ }
67
+ },
68
+ alias__default.default({
69
+ entries: [
70
+ {
71
+ find: /^\#server$/,
72
+ replacement: url.fileURLToPath(undefined("@mastra/deployer/server")).replaceAll("\\", "/")
73
+ },
74
+ {
75
+ find: /^\@mastra\/server\/(.*)/,
76
+ replacement: `@mastra/server/$1`,
77
+ customResolver: (id) => {
78
+ if (id.startsWith("@mastra/server")) {
79
+ return {
80
+ id: url.fileURLToPath(undefined(id))
81
+ };
82
+ }
83
+ }
84
+ },
85
+ { find: /^\#mastra$/, replacement: normalizedEntryFile }
86
+ ]
87
+ }),
88
+ {
89
+ name: "tools-rewriter",
90
+ resolveId(id) {
91
+ if (id === "#tools") {
92
+ return {
93
+ id: "./tools.mjs",
94
+ external: true
95
+ };
96
+ }
97
+ }
98
+ },
99
+ esbuild__default.default({
100
+ target: "node20",
101
+ platform,
102
+ minify: false,
103
+ define: env
104
+ }),
105
+ commonjs__default.default({
106
+ extensions: [".js", ".ts"],
107
+ transformMixedEsModules: true,
108
+ esmExternals(id) {
109
+ return externals.includes(id);
110
+ }
111
+ }),
112
+ nodeResolvePlugin,
113
+ // for debugging
114
+ // {
115
+ // name: 'logger',
116
+ // //@ts-ignore
117
+ // resolveId(id, ...args) {
118
+ // console.log({ id, args });
119
+ // },
120
+ // // @ts-ignore
121
+ // transform(code, id) {
122
+ // if (code.includes('class Duplexify ')) {
123
+ // console.log({ duplex: id });
124
+ // }
125
+ // },
126
+ // },
127
+ json__default.default(),
128
+ chunk54KOF3NB_cjs.removeDeployer(entryFile),
129
+ // treeshake unused imports
130
+ esbuild__default.default({
131
+ include: entryFile,
132
+ target: "node20",
133
+ platform,
134
+ minify: false
135
+ })
136
+ ].filter(Boolean)
137
+ };
138
+ }
139
+ async function createBundler(inputOptions, outputOptions) {
140
+ const bundler = await rollup.rollup(inputOptions);
141
+ return {
142
+ write: () => {
143
+ return bundler.write({
144
+ ...outputOptions,
145
+ format: "esm",
146
+ entryFileNames: "[name].mjs",
147
+ chunkFileNames: "[name].mjs"
148
+ });
149
+ },
150
+ close: () => {
151
+ return bundler.close();
152
+ }
153
+ };
154
+ }
155
+
156
+ exports.createBundler = createBundler;
157
+ exports.getInputOptions = getInputOptions;
@@ -0,0 +1,209 @@
1
+ import { aliasHono, recursiveRemoveNonReferencedNodes, removeAllOptionsFromMastraExcept } from './chunk-UYQZMNZL.js';
2
+ import { getInputOptions } from './chunk-TIC2KT3M.js';
3
+ import { tsConfigPaths } from './chunk-Z544XXXK.js';
4
+ import { watch, rollup } from 'rollup';
5
+ import { extname, dirname } from 'path';
6
+ import resolveFrom from 'resolve-from';
7
+ import { builtinModules } from 'module';
8
+ import * as babel from '@babel/core';
9
+ import esbuild from 'rollup-plugin-esbuild';
10
+ import commonjs from '@rollup/plugin-commonjs';
11
+
12
+ function isBuiltinModule(specifier) {
13
+ return builtinModules.includes(specifier) || specifier.startsWith("node:") || builtinModules.includes(specifier.replace(/^node:/, ""));
14
+ }
15
+ function safeResolve(id, importer) {
16
+ try {
17
+ return resolveFrom(importer, id);
18
+ } catch {
19
+ return null;
20
+ }
21
+ }
22
+ function getPackageName(id) {
23
+ const parts = id.split("/");
24
+ if (id.startsWith("@")) {
25
+ return parts.slice(0, 2).join("/");
26
+ }
27
+ return parts[0];
28
+ }
29
+ function nodeModulesExtensionResolver() {
30
+ return {
31
+ name: "node-modules-extension-resolver",
32
+ resolveId(id, importer) {
33
+ if (id.startsWith(".") || id.startsWith("/") || !importer) {
34
+ return null;
35
+ }
36
+ if (isBuiltinModule(id)) {
37
+ return null;
38
+ }
39
+ if (id.startsWith("@") && id.split("/").length === 2) {
40
+ return null;
41
+ }
42
+ if (!id.startsWith("@") && id.split("/").length === 1) {
43
+ return null;
44
+ }
45
+ const foundExt = extname(id);
46
+ if (foundExt) {
47
+ return null;
48
+ }
49
+ try {
50
+ const resolved = import.meta.resolve(id);
51
+ if (!extname(resolved)) {
52
+ throw new Error(`Cannot resolve ${id} from ${importer}`);
53
+ }
54
+ return null;
55
+ } catch (e) {
56
+ for (const ext of [".mjs", ".js", ".cjs"]) {
57
+ const resolved = safeResolve(id + ext, importer);
58
+ if (resolved) {
59
+ const pkgName = getPackageName(id);
60
+ if (!pkgName) {
61
+ return null;
62
+ }
63
+ const pkgJsonPath = safeResolve(`${pkgName}/package.json`, importer);
64
+ if (!pkgJsonPath) {
65
+ return null;
66
+ }
67
+ const newImportWithExtension = resolved.replace(dirname(pkgJsonPath), pkgName);
68
+ return {
69
+ id: newImportWithExtension,
70
+ external: true
71
+ };
72
+ }
73
+ }
74
+ }
75
+ return null;
76
+ }
77
+ };
78
+ }
79
+
80
+ // src/build/watcher.ts
81
+ async function getInputOptions2(entryFile, platform, env) {
82
+ const inputOptions = await getInputOptions(
83
+ entryFile,
84
+ {
85
+ dependencies: /* @__PURE__ */ new Map(),
86
+ externalDependencies: /* @__PURE__ */ new Set(),
87
+ invalidChunks: /* @__PURE__ */ new Set()
88
+ },
89
+ platform,
90
+ env
91
+ );
92
+ if (Array.isArray(inputOptions.plugins)) {
93
+ inputOptions.plugins = inputOptions.plugins.filter(
94
+ // @ts-ignore
95
+ (plugin) => !plugin || !plugin?.name || plugin.name !== "node-resolve"
96
+ );
97
+ inputOptions.plugins.push(aliasHono());
98
+ inputOptions.plugins.push(nodeModulesExtensionResolver());
99
+ }
100
+ return inputOptions;
101
+ }
102
+ async function createWatcher(inputOptions, outputOptions) {
103
+ const watcher = await watch({
104
+ ...inputOptions,
105
+ output: {
106
+ ...outputOptions,
107
+ format: "esm",
108
+ entryFileNames: "[name].mjs",
109
+ chunkFileNames: "[name].mjs"
110
+ }
111
+ });
112
+ return watcher;
113
+ }
114
+
115
+ // src/build/babel/remove-all-options-server.ts
116
+ function removeAllOptionsExceptServer(result) {
117
+ return removeAllOptionsFromMastraExcept(result, "server");
118
+ }
119
+ function getServerOptionsBundler(entryFile, result) {
120
+ return rollup({
121
+ logLevel: "silent",
122
+ input: {
123
+ "server-config": entryFile
124
+ },
125
+ treeshake: "smallest",
126
+ plugins: [
127
+ tsConfigPaths(),
128
+ // transpile typescript to something we understand
129
+ esbuild({
130
+ target: "node20",
131
+ platform: "node",
132
+ minify: false
133
+ }),
134
+ commonjs({
135
+ extensions: [".js", ".ts"],
136
+ strictRequires: "strict",
137
+ transformMixedEsModules: true,
138
+ ignoreTryCatch: false
139
+ }),
140
+ {
141
+ name: "get-server-config",
142
+ transform(code, id) {
143
+ if (id !== entryFile) {
144
+ return;
145
+ }
146
+ return new Promise((resolve, reject) => {
147
+ babel.transform(
148
+ code,
149
+ {
150
+ babelrc: false,
151
+ configFile: false,
152
+ filename: id,
153
+ plugins: [removeAllOptionsExceptServer(result)]
154
+ },
155
+ (err, result2) => {
156
+ if (err) {
157
+ return reject(err);
158
+ }
159
+ resolve({
160
+ code: result2.code,
161
+ map: result2.map
162
+ });
163
+ }
164
+ );
165
+ });
166
+ }
167
+ },
168
+ // let esbuild remove all unused imports
169
+ esbuild({
170
+ target: "node20",
171
+ platform: "node",
172
+ minify: false
173
+ }),
174
+ {
175
+ name: "cleanup",
176
+ transform(code, id) {
177
+ if (id !== entryFile) {
178
+ return;
179
+ }
180
+ return recursiveRemoveNonReferencedNodes(code);
181
+ }
182
+ },
183
+ // let esbuild remove all unused imports
184
+ esbuild({
185
+ target: "node20",
186
+ platform: "node",
187
+ minify: false
188
+ })
189
+ ]
190
+ });
191
+ }
192
+ async function getServerOptions(entryFile, outputDir) {
193
+ const result = {
194
+ hasCustomConfig: false
195
+ };
196
+ const bundle = await getServerOptionsBundler(entryFile, result);
197
+ await bundle.write({
198
+ dir: outputDir,
199
+ format: "es",
200
+ entryFileNames: "[name].mjs",
201
+ sourcemap: true
202
+ });
203
+ if (result.hasCustomConfig) {
204
+ return (await import(`file:${outputDir}/server-config.mjs`)).server;
205
+ }
206
+ return null;
207
+ }
208
+
209
+ export { createWatcher, getInputOptions2 as getInputOptions, getServerOptions };