@mastra/deployer 0.0.0-a2a-20250421213654

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 (58) hide show
  1. package/LICENSE.md +46 -0
  2. package/README.md +159 -0
  3. package/dist/_tsup-dts-rollup.d.cts +548 -0
  4. package/dist/_tsup-dts-rollup.d.ts +548 -0
  5. package/dist/build/analyze.cjs +10 -0
  6. package/dist/build/analyze.d.cts +1 -0
  7. package/dist/build/analyze.d.ts +1 -0
  8. package/dist/build/analyze.js +1 -0
  9. package/dist/build/bundler.cjs +14 -0
  10. package/dist/build/bundler.d.cts +2 -0
  11. package/dist/build/bundler.d.ts +2 -0
  12. package/dist/build/bundler.js +1 -0
  13. package/dist/build/index.cjs +46 -0
  14. package/dist/build/index.d.cts +9 -0
  15. package/dist/build/index.d.ts +9 -0
  16. package/dist/build/index.js +5 -0
  17. package/dist/bundler/index.cjs +10 -0
  18. package/dist/bundler/index.d.cts +1 -0
  19. package/dist/bundler/index.d.ts +1 -0
  20. package/dist/bundler/index.js +1 -0
  21. package/dist/chunk-2ZPQX6BX.cjs +254 -0
  22. package/dist/chunk-4AYFLP6G.js +227 -0
  23. package/dist/chunk-4VC5Z4YR.cjs +391 -0
  24. package/dist/chunk-54KOF3NB.cjs +137 -0
  25. package/dist/chunk-5QD7CDGY.js +306 -0
  26. package/dist/chunk-6QMONK4A.cjs +2 -0
  27. package/dist/chunk-AOSWYZKN.js +138 -0
  28. package/dist/chunk-C4JT7CIH.js +1 -0
  29. package/dist/chunk-IMGVLBV7.cjs +149 -0
  30. package/dist/chunk-KTYDROLB.js +136 -0
  31. package/dist/chunk-LA6Y6GAB.cjs +312 -0
  32. package/dist/chunk-Q6OKTZNC.cjs +316 -0
  33. package/dist/chunk-USZDOFES.js +301 -0
  34. package/dist/chunk-UV4RQQ3R.js +359 -0
  35. package/dist/chunk-WVBUOQT6.js +111 -0
  36. package/dist/chunk-Z7KAM3CZ.cjs +164 -0
  37. package/dist/index.cjs +190 -0
  38. package/dist/index.d.cts +6 -0
  39. package/dist/index.d.ts +6 -0
  40. package/dist/index.js +149 -0
  41. package/dist/server/index.cjs +3952 -0
  42. package/dist/server/index.d.cts +2 -0
  43. package/dist/server/index.d.ts +2 -0
  44. package/dist/server/index.js +3944 -0
  45. package/dist/services/index.cjs +18 -0
  46. package/dist/services/index.d.cts +3 -0
  47. package/dist/services/index.d.ts +3 -0
  48. package/dist/services/index.js +1 -0
  49. package/dist/templates/instrumentation-template.js +89 -0
  50. package/dist/validator/custom-resolver.cjs +52 -0
  51. package/dist/validator/custom-resolver.d.cts +1 -0
  52. package/dist/validator/custom-resolver.d.ts +1 -0
  53. package/dist/validator/custom-resolver.js +50 -0
  54. package/dist/validator/loader.cjs +7 -0
  55. package/dist/validator/loader.d.cts +1 -0
  56. package/dist/validator/loader.d.ts +1 -0
  57. package/dist/validator/loader.js +4 -0
  58. package/package.json +140 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,190 @@
1
+ 'use strict';
2
+
3
+ var chunkQ6OKTZNC_cjs = require('./chunk-Q6OKTZNC.cjs');
4
+ var chunk2ZPQX6BX_cjs = require('./chunk-2ZPQX6BX.cjs');
5
+ var chunk4VC5Z4YR_cjs = require('./chunk-4VC5Z4YR.cjs');
6
+ var babel = require('@babel/core');
7
+ var rollup = require('rollup');
8
+ var esbuild = require('rollup-plugin-esbuild');
9
+ var commonjs = require('@rollup/plugin-commonjs');
10
+
11
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
+
13
+ function _interopNamespace(e) {
14
+ if (e && e.__esModule) return e;
15
+ var n = Object.create(null);
16
+ if (e) {
17
+ Object.keys(e).forEach(function (k) {
18
+ if (k !== 'default') {
19
+ var d = Object.getOwnPropertyDescriptor(e, k);
20
+ Object.defineProperty(n, k, d.get ? d : {
21
+ enumerable: true,
22
+ get: function () { return e[k]; }
23
+ });
24
+ }
25
+ });
26
+ }
27
+ n.default = e;
28
+ return Object.freeze(n);
29
+ }
30
+
31
+ var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
32
+ var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
33
+ var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
34
+
35
+ // src/deploy/base.ts
36
+ var Deployer = class extends chunkQ6OKTZNC_cjs.Bundler {
37
+ deps = new chunk4VC5Z4YR_cjs.DepsService();
38
+ constructor(args) {
39
+ super(args.name, "DEPLOYER");
40
+ this.deps.__setLogger(this.logger);
41
+ }
42
+ getEnvFiles() {
43
+ const possibleFiles = [".env.production", ".env.local", ".env"];
44
+ try {
45
+ const fileService = new chunk4VC5Z4YR_cjs.FileService();
46
+ const envFile = fileService.getFirstExistingFile(possibleFiles);
47
+ return Promise.resolve([envFile]);
48
+ } catch {
49
+ }
50
+ return Promise.resolve([]);
51
+ }
52
+ };
53
+ function removeAllExceptDeployer() {
54
+ const t = babel__namespace.default.types;
55
+ return {
56
+ name: "remove-all-except-deployer",
57
+ visitor: {
58
+ ExportNamedDeclaration: {
59
+ // remove all exports
60
+ exit(path) {
61
+ path.remove();
62
+ }
63
+ },
64
+ NewExpression(path) {
65
+ const varDeclaratorPath = path.findParent((path2) => t.isVariableDeclarator(path2.node));
66
+ if (!varDeclaratorPath) {
67
+ return;
68
+ }
69
+ const parentNode = path.parentPath.node;
70
+ if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
71
+ return;
72
+ }
73
+ const deployer = path.node.arguments[0]?.properties?.find(
74
+ // @ts-ignore
75
+ (prop) => prop.key.name === "deployer"
76
+ );
77
+ const programPath = path.scope.getProgramParent().path;
78
+ if (!deployer || !programPath) {
79
+ return;
80
+ }
81
+ const exportDeclaration = t.exportNamedDeclaration(
82
+ t.variableDeclaration("const", [t.variableDeclarator(t.identifier("deployer"), deployer.value)]),
83
+ []
84
+ );
85
+ programPath.node.body.push(exportDeclaration);
86
+ }
87
+ }
88
+ };
89
+ }
90
+ function getDeployerBundler(entryFile) {
91
+ return rollup.rollup({
92
+ logLevel: "silent",
93
+ input: {
94
+ deployer: entryFile
95
+ },
96
+ treeshake: "smallest",
97
+ plugins: [
98
+ // transpile typescript to something we understand
99
+ esbuild__default.default({
100
+ target: "node20",
101
+ platform: "node",
102
+ minify: false
103
+ }),
104
+ commonjs__default.default({
105
+ extensions: [".js", ".ts"],
106
+ strictRequires: "strict",
107
+ transformMixedEsModules: true,
108
+ ignoreTryCatch: false
109
+ }),
110
+ {
111
+ name: "get-deployer",
112
+ transform(code, id) {
113
+ if (id !== entryFile) {
114
+ return;
115
+ }
116
+ return new Promise((resolve, reject) => {
117
+ babel__namespace.transform(
118
+ code,
119
+ {
120
+ babelrc: false,
121
+ configFile: false,
122
+ filename: id,
123
+ plugins: [removeAllExceptDeployer]
124
+ },
125
+ (err, result) => {
126
+ if (err) {
127
+ return reject(err);
128
+ }
129
+ resolve({
130
+ code: result.code,
131
+ map: result.map
132
+ });
133
+ }
134
+ );
135
+ });
136
+ }
137
+ },
138
+ // let esbuild remove all unused imports
139
+ esbuild__default.default({
140
+ target: "node20",
141
+ platform: "node",
142
+ minify: false
143
+ }),
144
+ {
145
+ name: "cleanup-nodes",
146
+ transform(code, id) {
147
+ if (id !== entryFile) {
148
+ return;
149
+ }
150
+ return chunk2ZPQX6BX_cjs.recursiveRemoveNonReferencedNodes(code);
151
+ }
152
+ },
153
+ // let esbuild remove all unused imports
154
+ esbuild__default.default({
155
+ target: "node20",
156
+ platform: "node",
157
+ minify: false
158
+ })
159
+ ]
160
+ });
161
+ }
162
+ async function getDeployer(entryFile, outputDir) {
163
+ console.log("entryFile", entryFile);
164
+ const bundle = await getDeployerBundler(entryFile);
165
+ await bundle.write({
166
+ dir: outputDir,
167
+ format: "es",
168
+ entryFileNames: "[name].mjs"
169
+ });
170
+ return (await import(`file:${outputDir}/deployer.mjs`)).deployer;
171
+ }
172
+
173
+ Object.defineProperty(exports, "Deps", {
174
+ enumerable: true,
175
+ get: function () { return chunk4VC5Z4YR_cjs.Deps; }
176
+ });
177
+ Object.defineProperty(exports, "FileService", {
178
+ enumerable: true,
179
+ get: function () { return chunk4VC5Z4YR_cjs.FileService; }
180
+ });
181
+ Object.defineProperty(exports, "createChildProcessLogger", {
182
+ enumerable: true,
183
+ get: function () { return chunk4VC5Z4YR_cjs.createChildProcessLogger; }
184
+ });
185
+ Object.defineProperty(exports, "createPinoStream", {
186
+ enumerable: true,
187
+ get: function () { return chunk4VC5Z4YR_cjs.createPinoStream; }
188
+ });
189
+ exports.Deployer = Deployer;
190
+ exports.getDeployer = getDeployer;
@@ -0,0 +1,6 @@
1
+ export { Deps } from './_tsup-dts-rollup.cjs';
2
+ export { FileService } from './_tsup-dts-rollup.cjs';
3
+ export { getDeployer } from './_tsup-dts-rollup.cjs';
4
+ export { Deployer } from './_tsup-dts-rollup.cjs';
5
+ export { createChildProcessLogger } from './_tsup-dts-rollup.cjs';
6
+ export { createPinoStream } from './_tsup-dts-rollup.cjs';
@@ -0,0 +1,6 @@
1
+ export { Deps } from './_tsup-dts-rollup.js';
2
+ export { FileService } from './_tsup-dts-rollup.js';
3
+ export { getDeployer } from './_tsup-dts-rollup.js';
4
+ export { Deployer } from './_tsup-dts-rollup.js';
5
+ export { createChildProcessLogger } from './_tsup-dts-rollup.js';
6
+ export { createPinoStream } from './_tsup-dts-rollup.js';
package/dist/index.js ADDED
@@ -0,0 +1,149 @@
1
+ import { Bundler } from './chunk-5QD7CDGY.js';
2
+ import { recursiveRemoveNonReferencedNodes } from './chunk-4AYFLP6G.js';
3
+ import { DepsService, FileService } from './chunk-UV4RQQ3R.js';
4
+ export { Deps, FileService, createChildProcessLogger, createPinoStream } from './chunk-UV4RQQ3R.js';
5
+ import * as babel from '@babel/core';
6
+ import babel__default from '@babel/core';
7
+ import { rollup } from 'rollup';
8
+ import esbuild from 'rollup-plugin-esbuild';
9
+ import commonjs from '@rollup/plugin-commonjs';
10
+
11
+ // src/deploy/base.ts
12
+ var Deployer = class extends Bundler {
13
+ deps = new DepsService();
14
+ constructor(args) {
15
+ super(args.name, "DEPLOYER");
16
+ this.deps.__setLogger(this.logger);
17
+ }
18
+ getEnvFiles() {
19
+ const possibleFiles = [".env.production", ".env.local", ".env"];
20
+ try {
21
+ const fileService = new FileService();
22
+ const envFile = fileService.getFirstExistingFile(possibleFiles);
23
+ return Promise.resolve([envFile]);
24
+ } catch {
25
+ }
26
+ return Promise.resolve([]);
27
+ }
28
+ };
29
+ function removeAllExceptDeployer() {
30
+ const t = babel__default.types;
31
+ return {
32
+ name: "remove-all-except-deployer",
33
+ visitor: {
34
+ ExportNamedDeclaration: {
35
+ // remove all exports
36
+ exit(path) {
37
+ path.remove();
38
+ }
39
+ },
40
+ NewExpression(path) {
41
+ const varDeclaratorPath = path.findParent((path2) => t.isVariableDeclarator(path2.node));
42
+ if (!varDeclaratorPath) {
43
+ return;
44
+ }
45
+ const parentNode = path.parentPath.node;
46
+ if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
47
+ return;
48
+ }
49
+ const deployer = path.node.arguments[0]?.properties?.find(
50
+ // @ts-ignore
51
+ (prop) => prop.key.name === "deployer"
52
+ );
53
+ const programPath = path.scope.getProgramParent().path;
54
+ if (!deployer || !programPath) {
55
+ return;
56
+ }
57
+ const exportDeclaration = t.exportNamedDeclaration(
58
+ t.variableDeclaration("const", [t.variableDeclarator(t.identifier("deployer"), deployer.value)]),
59
+ []
60
+ );
61
+ programPath.node.body.push(exportDeclaration);
62
+ }
63
+ }
64
+ };
65
+ }
66
+ function getDeployerBundler(entryFile) {
67
+ return rollup({
68
+ logLevel: "silent",
69
+ input: {
70
+ deployer: entryFile
71
+ },
72
+ treeshake: "smallest",
73
+ plugins: [
74
+ // transpile typescript to something we understand
75
+ esbuild({
76
+ target: "node20",
77
+ platform: "node",
78
+ minify: false
79
+ }),
80
+ commonjs({
81
+ extensions: [".js", ".ts"],
82
+ strictRequires: "strict",
83
+ transformMixedEsModules: true,
84
+ ignoreTryCatch: false
85
+ }),
86
+ {
87
+ name: "get-deployer",
88
+ transform(code, id) {
89
+ if (id !== entryFile) {
90
+ return;
91
+ }
92
+ return new Promise((resolve, reject) => {
93
+ babel.transform(
94
+ code,
95
+ {
96
+ babelrc: false,
97
+ configFile: false,
98
+ filename: id,
99
+ plugins: [removeAllExceptDeployer]
100
+ },
101
+ (err, result) => {
102
+ if (err) {
103
+ return reject(err);
104
+ }
105
+ resolve({
106
+ code: result.code,
107
+ map: result.map
108
+ });
109
+ }
110
+ );
111
+ });
112
+ }
113
+ },
114
+ // let esbuild remove all unused imports
115
+ esbuild({
116
+ target: "node20",
117
+ platform: "node",
118
+ minify: false
119
+ }),
120
+ {
121
+ name: "cleanup-nodes",
122
+ transform(code, id) {
123
+ if (id !== entryFile) {
124
+ return;
125
+ }
126
+ return recursiveRemoveNonReferencedNodes(code);
127
+ }
128
+ },
129
+ // let esbuild remove all unused imports
130
+ esbuild({
131
+ target: "node20",
132
+ platform: "node",
133
+ minify: false
134
+ })
135
+ ]
136
+ });
137
+ }
138
+ async function getDeployer(entryFile, outputDir) {
139
+ console.log("entryFile", entryFile);
140
+ const bundle = await getDeployerBundler(entryFile);
141
+ await bundle.write({
142
+ dir: outputDir,
143
+ format: "es",
144
+ entryFileNames: "[name].mjs"
145
+ });
146
+ return (await import(`file:${outputDir}/deployer.mjs`)).deployer;
147
+ }
148
+
149
+ export { Deployer, getDeployer };