@mastra/deployer 0.0.0-afterToolExecute-20250414225911

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 +479 -0
  4. package/dist/_tsup-dts-rollup.d.ts +479 -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 +47 -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 +6 -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-54KOF3NB.cjs +137 -0
  24. package/dist/chunk-AE4CVAPK.cjs +151 -0
  25. package/dist/chunk-BDTZS3JM.js +299 -0
  26. package/dist/chunk-DYQ225MJ.js +115 -0
  27. package/dist/chunk-I3UVE6EH.cjs +161 -0
  28. package/dist/chunk-IKPL4RGG.js +140 -0
  29. package/dist/chunk-JDY6E7BT.cjs +152 -0
  30. package/dist/chunk-MYE33AKL.cjs +195 -0
  31. package/dist/chunk-NCROGJGB.cjs +142 -0
  32. package/dist/chunk-P5SATU7G.cjs +310 -0
  33. package/dist/chunk-SQQUYWPS.js +144 -0
  34. package/dist/chunk-WB3T6NKI.js +133 -0
  35. package/dist/chunk-WVBUOQT6.js +111 -0
  36. package/dist/chunk-YQB677IB.js +183 -0
  37. package/dist/index.cjs +191 -0
  38. package/dist/index.d.cts +6 -0
  39. package/dist/index.d.ts +6 -0
  40. package/dist/index.js +151 -0
  41. package/dist/server/index.cjs +3860 -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 +3853 -0
  45. package/dist/services/index.cjs +19 -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 +2 -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 +138 -0
package/dist/index.js ADDED
@@ -0,0 +1,151 @@
1
+ import { Bundler } from './chunk-SQQUYWPS.js';
2
+ import { recursiveRemoveNonReferencedNodes } from './chunk-4AYFLP6G.js';
3
+ import { FileService } from './chunk-DYQ225MJ.js';
4
+ export { FileService } from './chunk-DYQ225MJ.js';
5
+ import { DepsService } from './chunk-YQB677IB.js';
6
+ export { Deps, createChildProcessLogger, createPinoStream } from './chunk-YQB677IB.js';
7
+ import * as babel from '@babel/core';
8
+ import babel__default from '@babel/core';
9
+ import { rollup } from 'rollup';
10
+ import esbuild from 'rollup-plugin-esbuild';
11
+ import commonjs from '@rollup/plugin-commonjs';
12
+
13
+ // src/deploy/base.ts
14
+ var Deployer = class extends Bundler {
15
+ deps = new DepsService();
16
+ constructor(args) {
17
+ super(args.name, "DEPLOYER");
18
+ this.deps.__setLogger(this.logger);
19
+ }
20
+ getEnvFiles() {
21
+ const possibleFiles = [".env.production", ".env.local", ".env"];
22
+ try {
23
+ const fileService = new FileService();
24
+ const envFile = fileService.getFirstExistingFile(possibleFiles);
25
+ return Promise.resolve([envFile]);
26
+ } catch {
27
+ }
28
+ return Promise.resolve([]);
29
+ }
30
+ };
31
+ function removeAllExceptDeployer() {
32
+ const t = babel__default.types;
33
+ return {
34
+ name: "remove-all-except-deployer",
35
+ visitor: {
36
+ ExportNamedDeclaration: {
37
+ // remove all exports
38
+ exit(path) {
39
+ path.remove();
40
+ }
41
+ },
42
+ NewExpression(path) {
43
+ const varDeclaratorPath = path.findParent((path2) => t.isVariableDeclarator(path2.node));
44
+ if (!varDeclaratorPath) {
45
+ return;
46
+ }
47
+ const parentNode = path.parentPath.node;
48
+ if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
49
+ return;
50
+ }
51
+ const deployer = path.node.arguments[0]?.properties?.find(
52
+ // @ts-ignore
53
+ (prop) => prop.key.name === "deployer"
54
+ );
55
+ const programPath = path.scope.getProgramParent().path;
56
+ if (!deployer || !programPath) {
57
+ return;
58
+ }
59
+ const exportDeclaration = t.exportNamedDeclaration(
60
+ t.variableDeclaration("const", [t.variableDeclarator(t.identifier("deployer"), deployer.value)]),
61
+ []
62
+ );
63
+ programPath.node.body.push(exportDeclaration);
64
+ }
65
+ }
66
+ };
67
+ }
68
+ function getDeployerBundler(entryFile) {
69
+ return rollup({
70
+ logLevel: "silent",
71
+ input: {
72
+ deployer: entryFile
73
+ },
74
+ treeshake: "smallest",
75
+ plugins: [
76
+ // transpile typescript to something we understand
77
+ esbuild({
78
+ target: "node20",
79
+ platform: "node",
80
+ minify: false
81
+ }),
82
+ commonjs({
83
+ extensions: [".js", ".ts"],
84
+ strictRequires: "strict",
85
+ transformMixedEsModules: true,
86
+ ignoreTryCatch: false
87
+ }),
88
+ {
89
+ name: "get-deployer",
90
+ transform(code, id) {
91
+ if (id !== entryFile) {
92
+ return;
93
+ }
94
+ return new Promise((resolve, reject) => {
95
+ babel.transform(
96
+ code,
97
+ {
98
+ babelrc: false,
99
+ configFile: false,
100
+ filename: id,
101
+ plugins: [removeAllExceptDeployer]
102
+ },
103
+ (err, result) => {
104
+ if (err) {
105
+ return reject(err);
106
+ }
107
+ resolve({
108
+ code: result.code,
109
+ map: result.map
110
+ });
111
+ }
112
+ );
113
+ });
114
+ }
115
+ },
116
+ // let esbuild remove all unused imports
117
+ esbuild({
118
+ target: "node20",
119
+ platform: "node",
120
+ minify: false
121
+ }),
122
+ {
123
+ name: "cleanup-nodes",
124
+ transform(code, id) {
125
+ if (id !== entryFile) {
126
+ return;
127
+ }
128
+ return recursiveRemoveNonReferencedNodes(code);
129
+ }
130
+ },
131
+ // let esbuild remove all unused imports
132
+ esbuild({
133
+ target: "node20",
134
+ platform: "node",
135
+ minify: false
136
+ })
137
+ ]
138
+ });
139
+ }
140
+ async function getDeployer(entryFile, outputDir) {
141
+ console.log("entryFile", entryFile);
142
+ const bundle = await getDeployerBundler(entryFile);
143
+ await bundle.write({
144
+ dir: outputDir,
145
+ format: "es",
146
+ entryFileNames: "[name].mjs"
147
+ });
148
+ return (await import(`file:${outputDir}/deployer.mjs`)).deployer;
149
+ }
150
+
151
+ export { Deployer, getDeployer };