@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
@@ -0,0 +1,391 @@
1
+ 'use strict';
2
+
3
+ var child_process = require('child_process');
4
+ var stream = require('stream');
5
+ var fs3 = require('fs');
6
+ var fsPromises = require('fs/promises');
7
+ var path = require('path');
8
+ var url = require('url');
9
+ var base = require('@mastra/core/base');
10
+ var fsExtra = require('fs-extra/esm');
11
+
12
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
+
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ Object.keys(e).forEach(function (k) {
20
+ if (k !== 'default') {
21
+ var d = Object.getOwnPropertyDescriptor(e, k);
22
+ Object.defineProperty(n, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: function () { return e[k]; }
25
+ });
26
+ }
27
+ });
28
+ }
29
+ n.default = e;
30
+ return Object.freeze(n);
31
+ }
32
+
33
+ var fs3__namespace = /*#__PURE__*/_interopNamespace(fs3);
34
+ var fsPromises__default = /*#__PURE__*/_interopDefault(fsPromises);
35
+ var path__default = /*#__PURE__*/_interopDefault(path);
36
+ var fsExtra__default = /*#__PURE__*/_interopDefault(fsExtra);
37
+
38
+ // src/deploy/log.ts
39
+ var createPinoStream = (logger) => {
40
+ return new stream.Transform({
41
+ transform(chunk, _encoding, callback) {
42
+ const line = chunk.toString().trim();
43
+ if (line) {
44
+ console.log(line);
45
+ logger.info(line);
46
+ }
47
+ callback(null, chunk);
48
+ }
49
+ });
50
+ };
51
+ function createChildProcessLogger({ logger, root }) {
52
+ const pinoStream = createPinoStream(logger);
53
+ return async ({ cmd, args, env }) => {
54
+ try {
55
+ const subprocess = child_process.spawn(cmd, args, {
56
+ cwd: root,
57
+ shell: true,
58
+ env
59
+ });
60
+ subprocess.stdout?.pipe(pinoStream);
61
+ subprocess.stderr?.pipe(pinoStream);
62
+ return new Promise((resolve, reject) => {
63
+ subprocess.on("close", (code) => {
64
+ pinoStream.end();
65
+ if (code === 0) {
66
+ resolve({ success: true });
67
+ } else {
68
+ reject(new Error(`Process exited with code ${code}`));
69
+ }
70
+ });
71
+ subprocess.on("error", (error) => {
72
+ pinoStream.end();
73
+ logger.error("Process failed", { error });
74
+ reject(error);
75
+ });
76
+ });
77
+ } catch (error) {
78
+ console.log(error);
79
+ logger.error("Process failed", { error });
80
+ pinoStream.end();
81
+ return { success: false, error };
82
+ }
83
+ };
84
+ }
85
+ var Deps = class extends base.MastraBase {
86
+ packageManager;
87
+ rootDir;
88
+ constructor(rootDir = process.cwd()) {
89
+ super({ component: "DEPLOYER", name: "DEPS" });
90
+ this.rootDir = rootDir;
91
+ this.packageManager = this.getPackageManager();
92
+ }
93
+ findLockFile(dir) {
94
+ const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
95
+ for (const file of lockFiles) {
96
+ if (fs3__namespace.default.existsSync(path__default.default.join(dir, file))) {
97
+ return file;
98
+ }
99
+ }
100
+ const parentDir = path__default.default.resolve(dir, "..");
101
+ if (parentDir !== dir) {
102
+ return this.findLockFile(parentDir);
103
+ }
104
+ return null;
105
+ }
106
+ getPackageManager() {
107
+ const lockFile = this.findLockFile(this.rootDir);
108
+ switch (lockFile) {
109
+ case "pnpm-lock.yaml":
110
+ return "pnpm";
111
+ case "package-lock.json":
112
+ return "npm";
113
+ case "yarn.lock":
114
+ return "yarn";
115
+ case "bun.lock":
116
+ return "bun";
117
+ default:
118
+ return "npm";
119
+ }
120
+ }
121
+ getWorkspaceDependencyPath({ pkgName, version }) {
122
+ return `file:./workspace-module/${pkgName}-${version}.tgz`;
123
+ }
124
+ async pack({ dir, destination }) {
125
+ const cpLogger = createChildProcessLogger({
126
+ logger: this.logger,
127
+ root: dir
128
+ });
129
+ return cpLogger({
130
+ cmd: `${this.packageManager} pack --pack-destination ${destination}`,
131
+ args: [],
132
+ env: {
133
+ PATH: process.env.PATH
134
+ }
135
+ });
136
+ }
137
+ async writePnpmConfig(dir, options) {
138
+ const packageJsonPath = path__default.default.join(dir, "package.json");
139
+ const packageJson = await fsExtra.readJSON(packageJsonPath);
140
+ packageJson.pnpm = {
141
+ ...packageJson.pnpm,
142
+ supportedArchitectures: {
143
+ os: options.os || [],
144
+ cpu: options.cpu || [],
145
+ libc: options.libc || []
146
+ }
147
+ };
148
+ await fsExtra.writeJSON(packageJsonPath, packageJson, { spaces: 2 });
149
+ }
150
+ async writeYarnConfig(dir, options) {
151
+ const yarnrcPath = path__default.default.join(dir, ".yarnrc.yml");
152
+ const config = {
153
+ supportedArchitectures: {
154
+ cpu: options.cpu || [],
155
+ os: options.os || [],
156
+ libc: options.libc || []
157
+ }
158
+ };
159
+ await fsPromises__default.default.writeFile(
160
+ yarnrcPath,
161
+ `supportedArchitectures:
162
+ ${Object.entries(config.supportedArchitectures).map(([key, value]) => ` ${key}: ${JSON.stringify(value)}`).join("\n")}`
163
+ );
164
+ }
165
+ getNpmArgs(options) {
166
+ const args = [];
167
+ if (options.cpu) args.push(`--cpu=${options.cpu.join(",")}`);
168
+ if (options.os) args.push(`--os=${options.os.join(",")}`);
169
+ if (options.libc) args.push(`--libc=${options.libc.join(",")}`);
170
+ return args;
171
+ }
172
+ async install({
173
+ dir = this.rootDir,
174
+ architecture
175
+ } = {}) {
176
+ let runCommand = this.packageManager;
177
+ let args = [];
178
+ switch (this.packageManager) {
179
+ case "pnpm":
180
+ runCommand = `${this.packageManager} --ignore-workspace install`;
181
+ if (architecture) {
182
+ await this.writePnpmConfig(dir, architecture);
183
+ }
184
+ break;
185
+ case "yarn":
186
+ await fsExtra.ensureFile(path__default.default.join(dir, "yarn.lock"));
187
+ if (architecture) {
188
+ await this.writeYarnConfig(dir, architecture);
189
+ }
190
+ runCommand = `${this.packageManager} install`;
191
+ break;
192
+ case "npm":
193
+ runCommand = `${this.packageManager} install`;
194
+ if (architecture) {
195
+ args = this.getNpmArgs(architecture);
196
+ }
197
+ break;
198
+ default:
199
+ runCommand = `${this.packageManager} install`;
200
+ }
201
+ const cpLogger = createChildProcessLogger({
202
+ logger: this.logger,
203
+ root: dir
204
+ });
205
+ return cpLogger({
206
+ cmd: runCommand,
207
+ args,
208
+ env: {
209
+ PATH: process.env.PATH
210
+ }
211
+ });
212
+ }
213
+ async installPackages(packages) {
214
+ let runCommand = this.packageManager;
215
+ if (this.packageManager === "npm") {
216
+ runCommand = `${this.packageManager} i`;
217
+ } else {
218
+ runCommand = `${this.packageManager} add`;
219
+ }
220
+ const cpLogger = createChildProcessLogger({
221
+ logger: this.logger,
222
+ root: ""
223
+ });
224
+ return cpLogger({
225
+ cmd: `${runCommand}`,
226
+ args: packages,
227
+ env: {
228
+ PATH: process.env.PATH
229
+ }
230
+ });
231
+ }
232
+ async checkDependencies(dependencies) {
233
+ try {
234
+ const packageJsonPath = path__default.default.join(this.rootDir, "package.json");
235
+ try {
236
+ await fsPromises__default.default.access(packageJsonPath);
237
+ } catch {
238
+ return "No package.json file found in the current directory";
239
+ }
240
+ const packageJson = await fsExtra.readJSON(packageJsonPath);
241
+ for (const dependency of dependencies) {
242
+ if (!packageJson.dependencies || !packageJson.dependencies[dependency]) {
243
+ return `Please install ${dependency} before running this command (${this.packageManager} install ${dependency})`;
244
+ }
245
+ }
246
+ return "ok";
247
+ } catch (err) {
248
+ console.error(err);
249
+ return "Could not check dependencies";
250
+ }
251
+ }
252
+ async getProjectName() {
253
+ try {
254
+ const packageJsonPath = path__default.default.join(this.rootDir, "package.json");
255
+ const pkg = await fsExtra.readJSON(packageJsonPath);
256
+ return pkg.name;
257
+ } catch (err) {
258
+ throw err;
259
+ }
260
+ }
261
+ async getPackageVersion() {
262
+ const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-4VC5Z4YR.cjs', document.baseURI).href)));
263
+ const __dirname = path.dirname(__filename);
264
+ const pkgJsonPath = path__default.default.join(__dirname, "..", "..", "package.json");
265
+ const content = await fsExtra.readJSON(pkgJsonPath);
266
+ return content.version;
267
+ }
268
+ async addScriptsToPackageJson(scripts) {
269
+ const packageJson = await fsExtra.readJSON("package.json");
270
+ packageJson.scripts = {
271
+ ...packageJson.scripts,
272
+ ...scripts
273
+ };
274
+ await fsExtra.writeJSON("package.json", packageJson, { spaces: 2 });
275
+ }
276
+ };
277
+ var DepsService = class extends Deps {
278
+ };
279
+ var EnvService = class {
280
+ };
281
+ var FileEnvService = class extends EnvService {
282
+ filePath;
283
+ constructor(filePath) {
284
+ super();
285
+ this.filePath = filePath;
286
+ }
287
+ readFile(filePath) {
288
+ return new Promise((resolve, reject) => {
289
+ fs3__namespace.readFile(filePath, "utf8", (err, data) => {
290
+ if (err) reject(err);
291
+ else resolve(data);
292
+ });
293
+ });
294
+ }
295
+ writeFile({ filePath, data }) {
296
+ return new Promise((resolve, reject) => {
297
+ fs3__namespace.writeFile(filePath, data, "utf8", (err) => {
298
+ if (err) reject(err);
299
+ else resolve();
300
+ });
301
+ });
302
+ }
303
+ async updateEnvData({
304
+ key,
305
+ value,
306
+ filePath = this.filePath,
307
+ data
308
+ }) {
309
+ const regex = new RegExp(`^${key}=.*$`, "m");
310
+ if (data.match(regex)) {
311
+ data = data.replace(regex, `${key}=${value}`);
312
+ } else {
313
+ data += `
314
+ ${key}=${value}`;
315
+ }
316
+ await this.writeFile({ filePath, data });
317
+ console.log(`${key} set to ${value} in ENV file.`);
318
+ return data;
319
+ }
320
+ async getEnvValue(key) {
321
+ try {
322
+ const data = await this.readFile(this.filePath);
323
+ const regex = new RegExp(`^${key}=(.*)$`, "m");
324
+ const match = data.match(regex);
325
+ return match?.[1] || null;
326
+ } catch (err) {
327
+ console.error(`Error reading ENV value: ${err}`);
328
+ return null;
329
+ }
330
+ }
331
+ async setEnvValue(key, value) {
332
+ try {
333
+ const data = await this.readFile(this.filePath);
334
+ await this.updateEnvData({ key, value, data });
335
+ } catch (err) {
336
+ console.error(`Error writing ENV value: ${err}`);
337
+ }
338
+ }
339
+ };
340
+ var FileService = class {
341
+ /**
342
+ *
343
+ * @param inputFile the file in the starter files directory to copy
344
+ * @param outputFilePath the destination path
345
+ * @param replaceIfExists flag to replace if it exists
346
+ * @returns
347
+ */
348
+ async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
349
+ const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-4VC5Z4YR.cjs', document.baseURI).href)));
350
+ const __dirname = path__default.default.dirname(__filename);
351
+ const filePath = path__default.default.resolve(__dirname, "..", "starter-files", inputFile);
352
+ const fileString = fs3__namespace.default.readFileSync(filePath, "utf8");
353
+ if (fs3__namespace.default.existsSync(outputFilePath) && !replaceIfExists) {
354
+ console.log(`${outputFilePath} already exists`);
355
+ return false;
356
+ }
357
+ await fsExtra__default.default.outputFile(outputFilePath, fileString);
358
+ return true;
359
+ }
360
+ async setupEnvFile({ dbUrl }) {
361
+ const envPath = path__default.default.join(process.cwd(), ".env.development");
362
+ await fsExtra__default.default.ensureFile(envPath);
363
+ const fileEnvService = new FileEnvService(envPath);
364
+ await fileEnvService.setEnvValue("DB_URL", dbUrl);
365
+ }
366
+ getFirstExistingFile(files) {
367
+ for (const f of files) {
368
+ if (fs3__namespace.default.existsSync(f)) {
369
+ return f;
370
+ }
371
+ }
372
+ throw new Error("Missing required file, checked the following paths: " + files.join(", "));
373
+ }
374
+ replaceValuesInFile({
375
+ filePath,
376
+ replacements
377
+ }) {
378
+ let fileContent = fs3__namespace.default.readFileSync(filePath, "utf8");
379
+ replacements.forEach(({ search, replace }) => {
380
+ fileContent = fileContent.replaceAll(search, replace);
381
+ });
382
+ fs3__namespace.default.writeFileSync(filePath, fileContent);
383
+ }
384
+ };
385
+
386
+ exports.Deps = Deps;
387
+ exports.DepsService = DepsService;
388
+ exports.EnvService = EnvService;
389
+ exports.FileService = FileService;
390
+ exports.createChildProcessLogger = createChildProcessLogger;
391
+ exports.createPinoStream = createPinoStream;
@@ -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;