@mastra/deployer 0.10.12 → 0.10.13

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/package.json +4 -4
  2. package/dist/_tsup-dts-rollup.d.cts +0 -836
  3. package/dist/_tsup-dts-rollup.d.ts +0 -836
  4. package/dist/build/analyze.cjs +0 -10
  5. package/dist/build/analyze.d.cts +0 -1
  6. package/dist/build/analyze.d.ts +0 -1
  7. package/dist/build/analyze.js +0 -1
  8. package/dist/build/bundler.cjs +0 -14
  9. package/dist/build/bundler.d.cts +0 -2
  10. package/dist/build/bundler.d.ts +0 -2
  11. package/dist/build/bundler.js +0 -1
  12. package/dist/build/index.cjs +0 -50
  13. package/dist/build/index.d.cts +0 -10
  14. package/dist/build/index.d.ts +0 -10
  15. package/dist/build/index.js +0 -5
  16. package/dist/bundler/index.cjs +0 -10
  17. package/dist/bundler/index.d.cts +0 -1
  18. package/dist/bundler/index.d.ts +0 -1
  19. package/dist/bundler/index.js +0 -1
  20. package/dist/chunk-2C7ENC5E.js +0 -474
  21. package/dist/chunk-54KOF3NB.cjs +0 -137
  22. package/dist/chunk-6QMONK4A.cjs +0 -2
  23. package/dist/chunk-C4JT7CIH.js +0 -1
  24. package/dist/chunk-D2DCFCLH.cjs +0 -157
  25. package/dist/chunk-D6736SJL.js +0 -209
  26. package/dist/chunk-ENT5RDOI.js +0 -99
  27. package/dist/chunk-FK2WUSEN.cjs +0 -238
  28. package/dist/chunk-GPD54HBC.js +0 -380
  29. package/dist/chunk-KCP5ITLV.cjs +0 -412
  30. package/dist/chunk-M2VZQFTW.cjs +0 -125
  31. package/dist/chunk-MKB7NDY3.cjs +0 -486
  32. package/dist/chunk-TIC2KT3M.js +0 -146
  33. package/dist/chunk-UYQZMNZL.js +0 -572
  34. package/dist/chunk-XKH6F4NE.cjs +0 -604
  35. package/dist/chunk-Z544XXXK.js +0 -111
  36. package/dist/index.cjs +0 -194
  37. package/dist/index.d.cts +0 -8
  38. package/dist/index.d.ts +0 -8
  39. package/dist/index.js +0 -153
  40. package/dist/server/index.cjs +0 -8326
  41. package/dist/server/index.d.cts +0 -2
  42. package/dist/server/index.d.ts +0 -2
  43. package/dist/server/index.js +0 -8318
  44. package/dist/services/index.cjs +0 -18
  45. package/dist/services/index.d.cts +0 -3
  46. package/dist/services/index.d.ts +0 -3
  47. package/dist/services/index.js +0 -1
  48. package/dist/templates/instrumentation-template.js +0 -137
  49. package/dist/validator/custom-resolver.cjs +0 -52
  50. package/dist/validator/custom-resolver.d.cts +0 -1
  51. package/dist/validator/custom-resolver.d.ts +0 -1
  52. package/dist/validator/custom-resolver.js +0 -50
  53. package/dist/validator/loader.cjs +0 -7
  54. package/dist/validator/loader.d.cts +0 -1
  55. package/dist/validator/loader.d.ts +0 -1
  56. package/dist/validator/loader.js +0 -4
@@ -1,238 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkXKH6F4NE_cjs = require('./chunk-XKH6F4NE.cjs');
4
- var chunkD2DCFCLH_cjs = require('./chunk-D2DCFCLH.cjs');
5
- var chunk54KOF3NB_cjs = require('./chunk-54KOF3NB.cjs');
6
- var rollup = require('rollup');
7
- var path = require('path');
8
- var resolveFrom = require('resolve-from');
9
- var module$1 = require('module');
10
- var babel = require('@babel/core');
11
- var esbuild = require('rollup-plugin-esbuild');
12
- var commonjs = require('@rollup/plugin-commonjs');
13
-
14
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
-
16
- function _interopNamespace(e) {
17
- if (e && e.__esModule) return e;
18
- var n = Object.create(null);
19
- if (e) {
20
- Object.keys(e).forEach(function (k) {
21
- if (k !== 'default') {
22
- var d = Object.getOwnPropertyDescriptor(e, k);
23
- Object.defineProperty(n, k, d.get ? d : {
24
- enumerable: true,
25
- get: function () { return e[k]; }
26
- });
27
- }
28
- });
29
- }
30
- n.default = e;
31
- return Object.freeze(n);
32
- }
33
-
34
- var resolveFrom__default = /*#__PURE__*/_interopDefault(resolveFrom);
35
- var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
36
- var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
37
- var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
38
-
39
- function isBuiltinModule(specifier) {
40
- return module$1.builtinModules.includes(specifier) || specifier.startsWith("node:") || module$1.builtinModules.includes(specifier.replace(/^node:/, ""));
41
- }
42
- function safeResolve(id, importer) {
43
- try {
44
- return resolveFrom__default.default(importer, id);
45
- } catch {
46
- return null;
47
- }
48
- }
49
- function getPackageName(id) {
50
- const parts = id.split("/");
51
- if (id.startsWith("@")) {
52
- return parts.slice(0, 2).join("/");
53
- }
54
- return parts[0];
55
- }
56
- function nodeModulesExtensionResolver() {
57
- return {
58
- name: "node-modules-extension-resolver",
59
- resolveId(id, importer) {
60
- if (id.startsWith(".") || id.startsWith("/") || !importer) {
61
- return null;
62
- }
63
- if (isBuiltinModule(id)) {
64
- return null;
65
- }
66
- if (id.startsWith("@") && id.split("/").length === 2) {
67
- return null;
68
- }
69
- if (!id.startsWith("@") && id.split("/").length === 1) {
70
- return null;
71
- }
72
- const foundExt = path.extname(id);
73
- if (foundExt) {
74
- return null;
75
- }
76
- try {
77
- const resolved = undefined(id);
78
- if (!path.extname(resolved)) {
79
- throw new Error(`Cannot resolve ${id} from ${importer}`);
80
- }
81
- return null;
82
- } catch (e) {
83
- for (const ext of [".mjs", ".js", ".cjs"]) {
84
- const resolved = safeResolve(id + ext, importer);
85
- if (resolved) {
86
- const pkgName = getPackageName(id);
87
- if (!pkgName) {
88
- return null;
89
- }
90
- const pkgJsonPath = safeResolve(`${pkgName}/package.json`, importer);
91
- if (!pkgJsonPath) {
92
- return null;
93
- }
94
- const newImportWithExtension = resolved.replace(path.dirname(pkgJsonPath), pkgName);
95
- return {
96
- id: newImportWithExtension,
97
- external: true
98
- };
99
- }
100
- }
101
- }
102
- return null;
103
- }
104
- };
105
- }
106
-
107
- // src/build/watcher.ts
108
- async function getInputOptions2(entryFile, platform, env) {
109
- const inputOptions = await chunkD2DCFCLH_cjs.getInputOptions(
110
- entryFile,
111
- {
112
- dependencies: /* @__PURE__ */ new Map(),
113
- externalDependencies: /* @__PURE__ */ new Set(),
114
- invalidChunks: /* @__PURE__ */ new Set()
115
- },
116
- platform,
117
- env
118
- );
119
- if (Array.isArray(inputOptions.plugins)) {
120
- inputOptions.plugins = inputOptions.plugins.filter(
121
- // @ts-ignore
122
- (plugin) => !plugin || !plugin?.name || plugin.name !== "node-resolve"
123
- );
124
- inputOptions.plugins.push(chunkXKH6F4NE_cjs.aliasHono());
125
- inputOptions.plugins.push(nodeModulesExtensionResolver());
126
- }
127
- return inputOptions;
128
- }
129
- async function createWatcher(inputOptions, outputOptions) {
130
- const watcher = await rollup.watch({
131
- ...inputOptions,
132
- output: {
133
- ...outputOptions,
134
- format: "esm",
135
- entryFileNames: "[name].mjs",
136
- chunkFileNames: "[name].mjs"
137
- }
138
- });
139
- return watcher;
140
- }
141
-
142
- // src/build/babel/remove-all-options-server.ts
143
- function removeAllOptionsExceptServer(result) {
144
- return chunkXKH6F4NE_cjs.removeAllOptionsFromMastraExcept(result, "server");
145
- }
146
- function getServerOptionsBundler(entryFile, result) {
147
- return rollup.rollup({
148
- logLevel: "silent",
149
- input: {
150
- "server-config": entryFile
151
- },
152
- treeshake: "smallest",
153
- plugins: [
154
- chunk54KOF3NB_cjs.tsConfigPaths(),
155
- // transpile typescript to something we understand
156
- esbuild__default.default({
157
- target: "node20",
158
- platform: "node",
159
- minify: false
160
- }),
161
- commonjs__default.default({
162
- extensions: [".js", ".ts"],
163
- strictRequires: "strict",
164
- transformMixedEsModules: true,
165
- ignoreTryCatch: false
166
- }),
167
- {
168
- name: "get-server-config",
169
- transform(code, id) {
170
- if (id !== entryFile) {
171
- return;
172
- }
173
- return new Promise((resolve, reject) => {
174
- babel__namespace.transform(
175
- code,
176
- {
177
- babelrc: false,
178
- configFile: false,
179
- filename: id,
180
- plugins: [removeAllOptionsExceptServer(result)]
181
- },
182
- (err, result2) => {
183
- if (err) {
184
- return reject(err);
185
- }
186
- resolve({
187
- code: result2.code,
188
- map: result2.map
189
- });
190
- }
191
- );
192
- });
193
- }
194
- },
195
- // let esbuild remove all unused imports
196
- esbuild__default.default({
197
- target: "node20",
198
- platform: "node",
199
- minify: false
200
- }),
201
- {
202
- name: "cleanup",
203
- transform(code, id) {
204
- if (id !== entryFile) {
205
- return;
206
- }
207
- return chunkXKH6F4NE_cjs.recursiveRemoveNonReferencedNodes(code);
208
- }
209
- },
210
- // let esbuild remove all unused imports
211
- esbuild__default.default({
212
- target: "node20",
213
- platform: "node",
214
- minify: false
215
- })
216
- ]
217
- });
218
- }
219
- async function getServerOptions(entryFile, outputDir) {
220
- const result = {
221
- hasCustomConfig: false
222
- };
223
- const bundle = await getServerOptionsBundler(entryFile, result);
224
- await bundle.write({
225
- dir: outputDir,
226
- format: "es",
227
- entryFileNames: "[name].mjs",
228
- sourcemap: true
229
- });
230
- if (result.hasCustomConfig) {
231
- return (await import(`file:${outputDir}/server-config.mjs`)).server;
232
- }
233
- return null;
234
- }
235
-
236
- exports.createWatcher = createWatcher;
237
- exports.getInputOptions = getInputOptions2;
238
- exports.getServerOptions = getServerOptions;
@@ -1,380 +0,0 @@
1
- import { spawn } from 'child_process';
2
- import { Transform } from 'stream';
3
- import * as fs3 from 'fs';
4
- import fs3__default from 'fs';
5
- import fsPromises from 'fs/promises';
6
- import path, { dirname } from 'path';
7
- import { fileURLToPath } from 'url';
8
- import { MastraBase } from '@mastra/core/base';
9
- import fsExtra, { readJSON, writeJSON, ensureFile } from 'fs-extra/esm';
10
-
11
- // src/deploy/log.ts
12
- var createPinoStream = (logger) => {
13
- return new Transform({
14
- transform(chunk, _encoding, callback) {
15
- const line = chunk.toString().trim();
16
- if (line) {
17
- console.log(line);
18
- logger.info(line);
19
- }
20
- callback(null, chunk);
21
- }
22
- });
23
- };
24
- function createChildProcessLogger({ logger, root }) {
25
- const pinoStream = createPinoStream(logger);
26
- return async ({ cmd, args, env }) => {
27
- try {
28
- const subprocess = spawn(cmd, args, {
29
- cwd: root,
30
- shell: true,
31
- env
32
- });
33
- subprocess.stdout?.pipe(pinoStream);
34
- subprocess.stderr?.pipe(pinoStream);
35
- return new Promise((resolve, reject) => {
36
- subprocess.on("close", (code) => {
37
- pinoStream.end();
38
- if (code === 0) {
39
- resolve({ success: true });
40
- } else {
41
- reject(new Error(`Process exited with code ${code}`));
42
- }
43
- });
44
- subprocess.on("error", (error) => {
45
- pinoStream.end();
46
- logger.error("Process failed", { error });
47
- reject(error);
48
- });
49
- });
50
- } catch (error) {
51
- console.log(error);
52
- logger.error("Process failed", { error });
53
- pinoStream.end();
54
- return { success: false, error };
55
- }
56
- };
57
- }
58
- var Deps = class extends MastraBase {
59
- packageManager;
60
- rootDir;
61
- constructor(rootDir = process.cwd()) {
62
- super({ component: "DEPLOYER", name: "DEPS" });
63
- this.rootDir = rootDir;
64
- this.packageManager = this.getPackageManager();
65
- }
66
- findLockFile(dir) {
67
- const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
68
- for (const file of lockFiles) {
69
- if (fs3__default.existsSync(path.join(dir, file))) {
70
- return file;
71
- }
72
- }
73
- const parentDir = path.resolve(dir, "..");
74
- if (parentDir !== dir) {
75
- return this.findLockFile(parentDir);
76
- }
77
- return null;
78
- }
79
- getPackageManager() {
80
- const lockFile = this.findLockFile(this.rootDir);
81
- switch (lockFile) {
82
- case "pnpm-lock.yaml":
83
- return "pnpm";
84
- case "package-lock.json":
85
- return "npm";
86
- case "yarn.lock":
87
- return "yarn";
88
- case "bun.lock":
89
- return "bun";
90
- default:
91
- return "npm";
92
- }
93
- }
94
- getWorkspaceDependencyPath({ pkgName, version }) {
95
- return `file:./workspace-module/${pkgName}-${version}.tgz`;
96
- }
97
- async pack({ dir, destination }) {
98
- const cpLogger = createChildProcessLogger({
99
- logger: this.logger,
100
- root: dir
101
- });
102
- return cpLogger({
103
- cmd: `${this.packageManager} pack --pack-destination ${destination}`,
104
- args: [],
105
- env: {
106
- PATH: process.env.PATH
107
- }
108
- });
109
- }
110
- async writePnpmConfig(dir, options) {
111
- const packageJsonPath = path.join(dir, "package.json");
112
- const packageJson = await readJSON(packageJsonPath);
113
- packageJson.pnpm = {
114
- ...packageJson.pnpm,
115
- supportedArchitectures: {
116
- os: options.os || [],
117
- cpu: options.cpu || [],
118
- libc: options.libc || []
119
- }
120
- };
121
- await writeJSON(packageJsonPath, packageJson, { spaces: 2 });
122
- }
123
- async writeYarnConfig(dir, options) {
124
- const yarnrcPath = path.join(dir, ".yarnrc.yml");
125
- const config = {
126
- supportedArchitectures: {
127
- cpu: options.cpu || [],
128
- os: options.os || [],
129
- libc: options.libc || []
130
- }
131
- };
132
- await fsPromises.writeFile(
133
- yarnrcPath,
134
- `supportedArchitectures:
135
- ${Object.entries(config.supportedArchitectures).map(([key, value]) => ` ${key}: ${JSON.stringify(value)}`).join("\n")}`
136
- );
137
- }
138
- getNpmArgs(options) {
139
- const args = [];
140
- if (options.cpu) args.push(`--cpu=${options.cpu.join(",")}`);
141
- if (options.os) args.push(`--os=${options.os.join(",")}`);
142
- if (options.libc) args.push(`--libc=${options.libc.join(",")}`);
143
- return args;
144
- }
145
- async install({
146
- dir = this.rootDir,
147
- architecture
148
- } = {}) {
149
- let runCommand = this.packageManager;
150
- let args = [];
151
- switch (this.packageManager) {
152
- case "pnpm":
153
- runCommand = `${this.packageManager} --ignore-workspace install`;
154
- if (architecture) {
155
- await this.writePnpmConfig(dir, architecture);
156
- }
157
- break;
158
- case "yarn":
159
- await ensureFile(path.join(dir, "yarn.lock"));
160
- if (architecture) {
161
- await this.writeYarnConfig(dir, architecture);
162
- }
163
- runCommand = `${this.packageManager} install`;
164
- break;
165
- case "npm":
166
- runCommand = `${this.packageManager} install`;
167
- if (architecture) {
168
- args = this.getNpmArgs(architecture);
169
- }
170
- break;
171
- default:
172
- runCommand = `${this.packageManager} install`;
173
- }
174
- const cpLogger = createChildProcessLogger({
175
- logger: this.logger,
176
- root: dir
177
- });
178
- const env = {
179
- PATH: process.env.PATH
180
- };
181
- if (process.env.npm_config_registry) {
182
- env.npm_config_registry = process.env.npm_config_registry;
183
- }
184
- return cpLogger({
185
- cmd: runCommand,
186
- args,
187
- env
188
- });
189
- }
190
- async installPackages(packages) {
191
- let runCommand = this.packageManager;
192
- if (this.packageManager === "npm") {
193
- runCommand = `${this.packageManager} i`;
194
- } else {
195
- runCommand = `${this.packageManager} add`;
196
- }
197
- const env = {
198
- PATH: process.env.PATH
199
- };
200
- if (process.env.npm_config_registry) {
201
- env.npm_config_registry = process.env.npm_config_registry;
202
- }
203
- const cpLogger = createChildProcessLogger({
204
- logger: this.logger,
205
- root: ""
206
- });
207
- return cpLogger({
208
- cmd: `${runCommand}`,
209
- args: packages,
210
- env
211
- });
212
- }
213
- async checkDependencies(dependencies) {
214
- try {
215
- const packageJsonPath = path.join(this.rootDir, "package.json");
216
- try {
217
- await fsPromises.access(packageJsonPath);
218
- } catch {
219
- return "No package.json file found in the current directory";
220
- }
221
- const packageJson = await readJSON(packageJsonPath);
222
- for (const dependency of dependencies) {
223
- if (!packageJson.dependencies || !packageJson.dependencies[dependency]) {
224
- return `Please install ${dependency} before running this command (${this.packageManager} install ${dependency})`;
225
- }
226
- }
227
- return "ok";
228
- } catch (err) {
229
- console.error(err);
230
- return "Could not check dependencies";
231
- }
232
- }
233
- async getProjectName() {
234
- try {
235
- const packageJsonPath = path.join(this.rootDir, "package.json");
236
- const pkg = await readJSON(packageJsonPath);
237
- return pkg.name;
238
- } catch (err) {
239
- throw err;
240
- }
241
- }
242
- async getPackageVersion() {
243
- const __filename = fileURLToPath(import.meta.url);
244
- const __dirname = dirname(__filename);
245
- const pkgJsonPath = path.join(__dirname, "..", "..", "package.json");
246
- const content = await readJSON(pkgJsonPath);
247
- return content.version;
248
- }
249
- async addScriptsToPackageJson(scripts) {
250
- const packageJson = await readJSON("package.json");
251
- packageJson.scripts = {
252
- ...packageJson.scripts,
253
- ...scripts
254
- };
255
- await writeJSON("package.json", packageJson, { spaces: 2 });
256
- }
257
- };
258
- var DepsService = class extends Deps {
259
- };
260
- var EnvService = class {
261
- };
262
- var FileEnvService = class extends EnvService {
263
- filePath;
264
- constructor(filePath) {
265
- super();
266
- this.filePath = filePath;
267
- }
268
- readFile(filePath) {
269
- return new Promise((resolve, reject) => {
270
- fs3.readFile(filePath, "utf8", (err, data) => {
271
- if (err) reject(err);
272
- else resolve(data);
273
- });
274
- });
275
- }
276
- writeFile({ filePath, data }) {
277
- return new Promise((resolve, reject) => {
278
- fs3.writeFile(filePath, data, "utf8", (err) => {
279
- if (err) reject(err);
280
- else resolve();
281
- });
282
- });
283
- }
284
- async updateEnvData({
285
- key,
286
- value,
287
- filePath = this.filePath,
288
- data
289
- }) {
290
- const regex = new RegExp(`^${key}=.*$`, "m");
291
- if (data.match(regex)) {
292
- data = data.replace(regex, `${key}=${value}`);
293
- } else {
294
- data += `
295
- ${key}=${value}`;
296
- }
297
- await this.writeFile({ filePath, data });
298
- console.log(`${key} set to ${value} in ENV file.`);
299
- return data;
300
- }
301
- async getEnvValue(key) {
302
- try {
303
- const data = await this.readFile(this.filePath);
304
- const regex = new RegExp(`^${key}=(.*)$`, "m");
305
- const match = data.match(regex);
306
- return match?.[1] || null;
307
- } catch (err) {
308
- console.error(`Error reading ENV value: ${err}`);
309
- return null;
310
- }
311
- }
312
- async setEnvValue(key, value) {
313
- try {
314
- const data = await this.readFile(this.filePath);
315
- await this.updateEnvData({ key, value, data });
316
- } catch (err) {
317
- console.error(`Error writing ENV value: ${err}`);
318
- }
319
- }
320
- };
321
- var FileService = class {
322
- /**
323
- *
324
- * @param inputFile the file in the starter files directory to copy
325
- * @param outputFilePath the destination path
326
- * @param replaceIfExists flag to replace if it exists
327
- * @returns
328
- */
329
- async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
330
- const __filename = fileURLToPath(import.meta.url);
331
- const __dirname = path.dirname(__filename);
332
- const filePath = path.resolve(__dirname, "..", "starter-files", inputFile);
333
- const fileString = fs3__default.readFileSync(filePath, "utf8");
334
- if (fs3__default.existsSync(outputFilePath) && !replaceIfExists) {
335
- console.log(`${outputFilePath} already exists`);
336
- return false;
337
- }
338
- await fsExtra.outputFile(outputFilePath, fileString);
339
- return true;
340
- }
341
- async setupEnvFile({ dbUrl }) {
342
- const envPath = path.join(process.cwd(), ".env.development");
343
- await fsExtra.ensureFile(envPath);
344
- const fileEnvService = new FileEnvService(envPath);
345
- await fileEnvService.setEnvValue("DB_URL", dbUrl);
346
- }
347
- getFirstExistingFile(files) {
348
- for (const f of files) {
349
- if (fs3__default.existsSync(f)) {
350
- return f;
351
- }
352
- }
353
- throw new Error("Missing required file, checked the following paths: " + files.join(", "));
354
- }
355
- /**
356
- * Returns the first existing file from the provided array, or undefined if none exist
357
- * @param files array of file paths to check
358
- * @returns the first existing file path or undefined
359
- */
360
- getFirstExistingFileOrUndefined(files) {
361
- for (const f of files) {
362
- if (fs3__default.existsSync(f)) {
363
- return f;
364
- }
365
- }
366
- return void 0;
367
- }
368
- replaceValuesInFile({
369
- filePath,
370
- replacements
371
- }) {
372
- let fileContent = fs3__default.readFileSync(filePath, "utf8");
373
- replacements.forEach(({ search, replace }) => {
374
- fileContent = fileContent.replaceAll(search, replace);
375
- });
376
- fs3__default.writeFileSync(filePath, fileContent);
377
- }
378
- };
379
-
380
- export { Deps, DepsService, EnvService, FileService, createChildProcessLogger, createPinoStream };