@mastra/deployer 0.10.0 → 0.10.1-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.
@@ -1,255 +0,0 @@
1
- 'use strict';
2
-
3
- var babel = require('@babel/core');
4
- var rollup = require('rollup');
5
- var esbuild = require('rollup-plugin-esbuild');
6
- var commonjs = require('@rollup/plugin-commonjs');
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 esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
30
- var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
31
-
32
- // src/build/telemetry.ts
33
- function removeAllOptionsFromMastraExcept(result, option) {
34
- const t = babel__namespace.default.types;
35
- return {
36
- name: "remove-all-except-" + option + "-config",
37
- visitor: {
38
- ExportNamedDeclaration: {
39
- // remove all exports
40
- exit(path) {
41
- path.remove();
42
- }
43
- },
44
- NewExpression(path, state) {
45
- const varDeclaratorPath = path.findParent((path2) => t.isVariableDeclarator(path2.node));
46
- if (!varDeclaratorPath) {
47
- return;
48
- }
49
- const parentNode = path.parentPath.node;
50
- if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
51
- return;
52
- }
53
- let mastraArgs = t.objectExpression([]);
54
- if (t.isObjectExpression(path.node.arguments[0])) {
55
- mastraArgs = path.node.arguments[0];
56
- }
57
- let telemetry = mastraArgs.properties.find(
58
- // @ts-ignore
59
- (prop) => prop.key.name === option
60
- );
61
- let telemetryValue = t.objectExpression([]);
62
- const programPath = path.scope.getProgramParent().path;
63
- if (!programPath) {
64
- return;
65
- }
66
- if (telemetry && t.isObjectProperty(telemetry) && t.isExpression(telemetry.value)) {
67
- result.hasCustomConfig = true;
68
- telemetryValue = telemetry.value;
69
- if (t.isIdentifier(telemetry.value) && telemetry.value.name === option) {
70
- const telemetryBinding = state.file.scope.getBinding(option);
71
- if (telemetryBinding && t.isVariableDeclarator(telemetryBinding.path.node)) {
72
- const id = path.scope.generateUidIdentifier(option);
73
- telemetryBinding.path.replaceWith(t.variableDeclarator(id, telemetryBinding.path.node.init));
74
- telemetryValue = id;
75
- }
76
- }
77
- }
78
- const exportDeclaration = t.exportNamedDeclaration(
79
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), telemetryValue)]),
80
- []
81
- );
82
- programPath.node.body.push(exportDeclaration);
83
- }
84
- }
85
- };
86
- }
87
-
88
- // src/build/babel/remove-all-options-telemetry.ts
89
- function removeAllOptionsExceptTelemetry(result) {
90
- return removeAllOptionsFromMastraExcept(result, "telemetry");
91
- }
92
- function removeNonReferencedNodes() {
93
- const t = babel__namespace.default.types;
94
- return {
95
- name: "remove-non-referenced-nodes",
96
- visitor: {
97
- Program(path) {
98
- const scope = path.scope;
99
- const currentBody = path.get("body");
100
- const filteredBody = currentBody.filter((childPath) => {
101
- if (childPath.isExportDeclaration()) {
102
- return true;
103
- }
104
- if (childPath.isVariableDeclaration()) {
105
- return childPath.node.declarations.some((decl) => {
106
- if (!t.isIdentifier(decl.id)) {
107
- return false;
108
- }
109
- const name = decl.id.name;
110
- const binding = scope.getBinding(name);
111
- return binding && (binding.referenced || binding.referencePaths.length > 0);
112
- });
113
- }
114
- if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {
115
- if (!t.isIdentifier(childPath.node.id)) {
116
- return false;
117
- }
118
- const name = childPath.node.id.name;
119
- const binding = scope.getBinding(name);
120
- return binding && (binding.referenced || binding.referencePaths.length > 0);
121
- }
122
- if (childPath.isImportDeclaration()) {
123
- return childPath.node.specifiers.some((specifier) => {
124
- const importedName = specifier.local.name;
125
- const binding = scope.getBinding(importedName);
126
- return binding && (binding.referenced || binding.referencePaths.length > 0);
127
- });
128
- }
129
- return false;
130
- });
131
- path.set(
132
- "body",
133
- filteredBody.map((p) => p.node)
134
- );
135
- }
136
- }
137
- };
138
- }
139
-
140
- // src/build/plugins/remove-unused-references.ts
141
- function recursiveRemoveNonReferencedNodes(code) {
142
- return new Promise(async (resolve, reject) => {
143
- babel__namespace.transform(
144
- code,
145
- {
146
- babelrc: false,
147
- configFile: false,
148
- plugins: [removeNonReferencedNodes()]
149
- },
150
- (err, result) => {
151
- if (err) {
152
- return reject(err);
153
- }
154
- if (result && result.code !== code) {
155
- return recursiveRemoveNonReferencedNodes(result.code).then(resolve, reject);
156
- }
157
- resolve({
158
- code: result.code,
159
- map: result.map
160
- });
161
- }
162
- );
163
- });
164
- }
165
-
166
- // src/build/telemetry.ts
167
- function getTelemetryBundler(entryFile, result) {
168
- return rollup.rollup({
169
- logLevel: "silent",
170
- input: {
171
- "telemetry-config": entryFile
172
- },
173
- treeshake: "smallest",
174
- plugins: [
175
- // transpile typescript to something we understand
176
- esbuild__default.default({
177
- target: "node20",
178
- platform: "node",
179
- minify: false
180
- }),
181
- commonjs__default.default({
182
- extensions: [".js", ".ts"],
183
- strictRequires: "strict",
184
- transformMixedEsModules: true,
185
- ignoreTryCatch: false
186
- }),
187
- {
188
- name: "get-telemetry-config",
189
- transform(code, id) {
190
- if (id !== entryFile) {
191
- return;
192
- }
193
- return new Promise((resolve, reject) => {
194
- babel__namespace.transform(
195
- code,
196
- {
197
- babelrc: false,
198
- configFile: false,
199
- filename: id,
200
- plugins: [removeAllOptionsExceptTelemetry(result)]
201
- },
202
- (err, result2) => {
203
- if (err) {
204
- return reject(err);
205
- }
206
- resolve({
207
- code: result2.code,
208
- map: result2.map
209
- });
210
- }
211
- );
212
- });
213
- }
214
- },
215
- // let esbuild remove all unused imports
216
- esbuild__default.default({
217
- target: "node20",
218
- platform: "node",
219
- minify: false
220
- }),
221
- {
222
- name: "cleanup",
223
- transform(code, id) {
224
- if (id !== entryFile) {
225
- return;
226
- }
227
- return recursiveRemoveNonReferencedNodes(code);
228
- }
229
- },
230
- // let esbuild remove all unused imports
231
- esbuild__default.default({
232
- target: "node20",
233
- platform: "node",
234
- minify: false
235
- })
236
- ]
237
- });
238
- }
239
- async function writeTelemetryConfig(entryFile, outputDir) {
240
- const result = {
241
- hasCustomConfig: false
242
- };
243
- const bundle = await getTelemetryBundler(entryFile, result);
244
- const { output } = await bundle.write({
245
- dir: outputDir,
246
- format: "es",
247
- entryFileNames: "[name].mjs"
248
- });
249
- const externals = output[0].imports.filter((x) => !x.startsWith("./"));
250
- return { ...result, externalDependencies: externals };
251
- }
252
-
253
- exports.recursiveRemoveNonReferencedNodes = recursiveRemoveNonReferencedNodes;
254
- exports.removeAllOptionsFromMastraExcept = removeAllOptionsFromMastraExcept;
255
- exports.writeTelemetryConfig = writeTelemetryConfig;
@@ -1,228 +0,0 @@
1
- import * as babel from '@babel/core';
2
- import babel__default from '@babel/core';
3
- import { rollup } from 'rollup';
4
- import esbuild from 'rollup-plugin-esbuild';
5
- import commonjs from '@rollup/plugin-commonjs';
6
-
7
- // src/build/telemetry.ts
8
- function removeAllOptionsFromMastraExcept(result, option) {
9
- const t = babel__default.types;
10
- return {
11
- name: "remove-all-except-" + option + "-config",
12
- visitor: {
13
- ExportNamedDeclaration: {
14
- // remove all exports
15
- exit(path) {
16
- path.remove();
17
- }
18
- },
19
- NewExpression(path, state) {
20
- const varDeclaratorPath = path.findParent((path2) => t.isVariableDeclarator(path2.node));
21
- if (!varDeclaratorPath) {
22
- return;
23
- }
24
- const parentNode = path.parentPath.node;
25
- if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
26
- return;
27
- }
28
- let mastraArgs = t.objectExpression([]);
29
- if (t.isObjectExpression(path.node.arguments[0])) {
30
- mastraArgs = path.node.arguments[0];
31
- }
32
- let telemetry = mastraArgs.properties.find(
33
- // @ts-ignore
34
- (prop) => prop.key.name === option
35
- );
36
- let telemetryValue = t.objectExpression([]);
37
- const programPath = path.scope.getProgramParent().path;
38
- if (!programPath) {
39
- return;
40
- }
41
- if (telemetry && t.isObjectProperty(telemetry) && t.isExpression(telemetry.value)) {
42
- result.hasCustomConfig = true;
43
- telemetryValue = telemetry.value;
44
- if (t.isIdentifier(telemetry.value) && telemetry.value.name === option) {
45
- const telemetryBinding = state.file.scope.getBinding(option);
46
- if (telemetryBinding && t.isVariableDeclarator(telemetryBinding.path.node)) {
47
- const id = path.scope.generateUidIdentifier(option);
48
- telemetryBinding.path.replaceWith(t.variableDeclarator(id, telemetryBinding.path.node.init));
49
- telemetryValue = id;
50
- }
51
- }
52
- }
53
- const exportDeclaration = t.exportNamedDeclaration(
54
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), telemetryValue)]),
55
- []
56
- );
57
- programPath.node.body.push(exportDeclaration);
58
- }
59
- }
60
- };
61
- }
62
-
63
- // src/build/babel/remove-all-options-telemetry.ts
64
- function removeAllOptionsExceptTelemetry(result) {
65
- return removeAllOptionsFromMastraExcept(result, "telemetry");
66
- }
67
- function removeNonReferencedNodes() {
68
- const t = babel__default.types;
69
- return {
70
- name: "remove-non-referenced-nodes",
71
- visitor: {
72
- Program(path) {
73
- const scope = path.scope;
74
- const currentBody = path.get("body");
75
- const filteredBody = currentBody.filter((childPath) => {
76
- if (childPath.isExportDeclaration()) {
77
- return true;
78
- }
79
- if (childPath.isVariableDeclaration()) {
80
- return childPath.node.declarations.some((decl) => {
81
- if (!t.isIdentifier(decl.id)) {
82
- return false;
83
- }
84
- const name = decl.id.name;
85
- const binding = scope.getBinding(name);
86
- return binding && (binding.referenced || binding.referencePaths.length > 0);
87
- });
88
- }
89
- if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {
90
- if (!t.isIdentifier(childPath.node.id)) {
91
- return false;
92
- }
93
- const name = childPath.node.id.name;
94
- const binding = scope.getBinding(name);
95
- return binding && (binding.referenced || binding.referencePaths.length > 0);
96
- }
97
- if (childPath.isImportDeclaration()) {
98
- return childPath.node.specifiers.some((specifier) => {
99
- const importedName = specifier.local.name;
100
- const binding = scope.getBinding(importedName);
101
- return binding && (binding.referenced || binding.referencePaths.length > 0);
102
- });
103
- }
104
- return false;
105
- });
106
- path.set(
107
- "body",
108
- filteredBody.map((p) => p.node)
109
- );
110
- }
111
- }
112
- };
113
- }
114
-
115
- // src/build/plugins/remove-unused-references.ts
116
- function recursiveRemoveNonReferencedNodes(code) {
117
- return new Promise(async (resolve, reject) => {
118
- babel.transform(
119
- code,
120
- {
121
- babelrc: false,
122
- configFile: false,
123
- plugins: [removeNonReferencedNodes()]
124
- },
125
- (err, result) => {
126
- if (err) {
127
- return reject(err);
128
- }
129
- if (result && result.code !== code) {
130
- return recursiveRemoveNonReferencedNodes(result.code).then(resolve, reject);
131
- }
132
- resolve({
133
- code: result.code,
134
- map: result.map
135
- });
136
- }
137
- );
138
- });
139
- }
140
-
141
- // src/build/telemetry.ts
142
- function getTelemetryBundler(entryFile, result) {
143
- return rollup({
144
- logLevel: "silent",
145
- input: {
146
- "telemetry-config": entryFile
147
- },
148
- treeshake: "smallest",
149
- plugins: [
150
- // transpile typescript to something we understand
151
- esbuild({
152
- target: "node20",
153
- platform: "node",
154
- minify: false
155
- }),
156
- commonjs({
157
- extensions: [".js", ".ts"],
158
- strictRequires: "strict",
159
- transformMixedEsModules: true,
160
- ignoreTryCatch: false
161
- }),
162
- {
163
- name: "get-telemetry-config",
164
- transform(code, id) {
165
- if (id !== entryFile) {
166
- return;
167
- }
168
- return new Promise((resolve, reject) => {
169
- babel.transform(
170
- code,
171
- {
172
- babelrc: false,
173
- configFile: false,
174
- filename: id,
175
- plugins: [removeAllOptionsExceptTelemetry(result)]
176
- },
177
- (err, result2) => {
178
- if (err) {
179
- return reject(err);
180
- }
181
- resolve({
182
- code: result2.code,
183
- map: result2.map
184
- });
185
- }
186
- );
187
- });
188
- }
189
- },
190
- // let esbuild remove all unused imports
191
- esbuild({
192
- target: "node20",
193
- platform: "node",
194
- minify: false
195
- }),
196
- {
197
- name: "cleanup",
198
- transform(code, id) {
199
- if (id !== entryFile) {
200
- return;
201
- }
202
- return recursiveRemoveNonReferencedNodes(code);
203
- }
204
- },
205
- // let esbuild remove all unused imports
206
- esbuild({
207
- target: "node20",
208
- platform: "node",
209
- minify: false
210
- })
211
- ]
212
- });
213
- }
214
- async function writeTelemetryConfig(entryFile, outputDir) {
215
- const result = {
216
- hasCustomConfig: false
217
- };
218
- const bundle = await getTelemetryBundler(entryFile, result);
219
- const { output } = await bundle.write({
220
- dir: outputDir,
221
- format: "es",
222
- entryFileNames: "[name].mjs"
223
- });
224
- const externals = output[0].imports.filter((x) => !x.startsWith("./"));
225
- return { ...result, externalDependencies: externals };
226
- }
227
-
228
- export { recursiveRemoveNonReferencedNodes, removeAllOptionsFromMastraExcept, writeTelemetryConfig };