@mastra/deployer 0.0.1-alpha.27 → 0.0.1-alpha.29
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.
- package/CHANGELOG.md +24 -0
- package/dist/build/index.d.ts +51 -0
- package/dist/build/index.js +593 -0
- package/dist/index.d.ts +15 -96
- package/dist/index.js +555 -470
- package/dist/server/index.js +920 -6853
- package/global.d.ts +1 -0
- package/package.json +26 -10
- package/src/build/babel/fix-libsql.ts +41 -0
- package/src/build/babel/get-deployer.ts +54 -0
- package/src/build/babel/remove-deployer.ts +39 -0
- package/src/build/bundle.ts +116 -244
- package/src/build/deployer.ts +71 -0
- package/src/build/deps.ts +1 -1
- package/src/build/index.ts +3 -5
- package/src/build/plugins/fix-libsql.ts +69 -0
- package/src/build/plugins/remove-deployer.ts +37 -0
- package/src/build/plugins/telemetry-fix.ts +54 -0
- package/src/deploy/base.ts +31 -163
- package/src/deploy/log.ts +1 -1
- package/src/index.ts +3 -2
- package/src/server/handlers/agents.ts +3 -3
- package/src/server/handlers/logs.ts +19 -4
- package/src/server/handlers/memory.ts +17 -35
- package/src/server/handlers/tools.ts +0 -26
- package/src/server/handlers/vector.ts +1 -1
- package/src/server/handlers/workflows.ts +4 -3
- package/src/server/index.ts +40 -101
- package/src/server/openapi.json +25 -52
- package/tsconfig.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @mastra/deployer
|
|
2
2
|
|
|
3
|
+
## 0.0.1-alpha.29
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0696eeb: Cleanup Mastra server
|
|
8
|
+
- 38b7f66: Update deployer logic
|
|
9
|
+
- Updated dependencies [2f17a5f]
|
|
10
|
+
- Updated dependencies [cb290ee]
|
|
11
|
+
- Updated dependencies [b4d7416]
|
|
12
|
+
- Updated dependencies [38b7f66]
|
|
13
|
+
- @mastra/core@0.2.0-alpha.84
|
|
14
|
+
|
|
15
|
+
## 0.0.1-alpha.28
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 2ab57d6: Fix: Workflows require a trigger schema otherwise it fails to run in dev
|
|
20
|
+
- 9625602: Use mastra core splitted bundles in other packages
|
|
21
|
+
- Updated dependencies [30322ce]
|
|
22
|
+
- Updated dependencies [78eec7c]
|
|
23
|
+
- Updated dependencies [9625602]
|
|
24
|
+
- Updated dependencies [8769a62]
|
|
25
|
+
- @mastra/core@0.2.0-alpha.83
|
|
26
|
+
|
|
3
27
|
## 0.0.1-alpha.27
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as rollup from 'rollup';
|
|
2
|
+
import { InputOptions, Plugin, InputOption } from 'rollup';
|
|
3
|
+
import { MastraBase } from '@mastra/core/base';
|
|
4
|
+
|
|
5
|
+
declare class Deps extends MastraBase {
|
|
6
|
+
private packageManager;
|
|
7
|
+
constructor();
|
|
8
|
+
private findLockFile;
|
|
9
|
+
private getPackageManager;
|
|
10
|
+
install({ dir, packages }: {
|
|
11
|
+
dir?: string;
|
|
12
|
+
packages?: string[];
|
|
13
|
+
}): Promise<unknown>;
|
|
14
|
+
installPackages(packages: string[]): Promise<unknown>;
|
|
15
|
+
checkDependencies(dependencies: string[]): Promise<string>;
|
|
16
|
+
getProjectName(): Promise<any>;
|
|
17
|
+
getPackageVersion(): Promise<string | undefined>;
|
|
18
|
+
addScriptsToPackageJson(scripts: Record<string, string>): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type NormalizedInputOptions = Omit<Partial<InputOptions>, 'plugins' | 'input' | 'external'> & {
|
|
22
|
+
plugins?: Plugin[];
|
|
23
|
+
input: InputOption;
|
|
24
|
+
external?: (string | RegExp)[];
|
|
25
|
+
};
|
|
26
|
+
declare function getBundler(inputOptions: NormalizedInputOptions, platform?: 'node' | 'browser'): Promise<rollup.RollupBuild>;
|
|
27
|
+
declare function getWatcher(inputOptions: NormalizedInputOptions, platform?: 'node' | 'browser'): Promise<rollup.RollupWatcher>;
|
|
28
|
+
|
|
29
|
+
declare class FileService {
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param inputFile the file in the starter files directory to copy
|
|
33
|
+
* @param outputFilePath the destination path
|
|
34
|
+
* @param replaceIfExists flag to replace if it exists
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
copyStarterFile(inputFile: string, outputFilePath: string, replaceIfExists?: boolean): Promise<boolean>;
|
|
38
|
+
setupEnvFile({ dbUrl }: {
|
|
39
|
+
dbUrl: string;
|
|
40
|
+
}): Promise<void>;
|
|
41
|
+
getFirstExistingFile(files: string[]): string;
|
|
42
|
+
replaceValuesInFile({ filePath, replacements, }: {
|
|
43
|
+
filePath: string;
|
|
44
|
+
replacements: {
|
|
45
|
+
search: string;
|
|
46
|
+
replace: string;
|
|
47
|
+
}[];
|
|
48
|
+
}): void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { Deps, FileService, getBundler, getWatcher };
|
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
import alias from '@rollup/plugin-alias';
|
|
2
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
+
import json from '@rollup/plugin-json';
|
|
4
|
+
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
5
|
+
import builtins from 'builtins';
|
|
6
|
+
import path2, { dirname, join, resolve } from 'path';
|
|
7
|
+
import { rollup, watch } from 'rollup';
|
|
8
|
+
import esbuild from 'rollup-plugin-esbuild';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
import * as fs2 from 'fs';
|
|
11
|
+
import fs2__default from 'fs';
|
|
12
|
+
import fsExtra from 'fs-extra/esm';
|
|
13
|
+
import * as babel from '@babel/core';
|
|
14
|
+
import babel__default from '@babel/core';
|
|
15
|
+
import { currentTarget } from '@neon-rs/load';
|
|
16
|
+
import { familySync, GLIBC } from 'detect-libc';
|
|
17
|
+
import { addNamed } from '@babel/helper-module-imports';
|
|
18
|
+
import { platform } from 'process';
|
|
19
|
+
import { MastraBase } from '@mastra/core/base';
|
|
20
|
+
import fsPromises from 'fs/promises';
|
|
21
|
+
import '@mastra/core/logger';
|
|
22
|
+
import { spawn } from 'child_process';
|
|
23
|
+
import { Transform } from 'stream';
|
|
24
|
+
|
|
25
|
+
// src/build/bundle.ts
|
|
26
|
+
var EnvService = class {
|
|
27
|
+
};
|
|
28
|
+
var FileEnvService = class extends EnvService {
|
|
29
|
+
filePath;
|
|
30
|
+
constructor(filePath) {
|
|
31
|
+
super();
|
|
32
|
+
this.filePath = filePath;
|
|
33
|
+
}
|
|
34
|
+
readFile(filePath) {
|
|
35
|
+
return new Promise((resolve2, reject) => {
|
|
36
|
+
fs2.readFile(filePath, "utf8", (err, data) => {
|
|
37
|
+
if (err) reject(err);
|
|
38
|
+
else resolve2(data);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
writeFile({ filePath, data }) {
|
|
43
|
+
return new Promise((resolve2, reject) => {
|
|
44
|
+
fs2.writeFile(filePath, data, "utf8", (err) => {
|
|
45
|
+
if (err) reject(err);
|
|
46
|
+
else resolve2();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async updateEnvData({
|
|
51
|
+
key,
|
|
52
|
+
value,
|
|
53
|
+
filePath = this.filePath,
|
|
54
|
+
data
|
|
55
|
+
}) {
|
|
56
|
+
const regex = new RegExp(`^${key}=.*$`, "m");
|
|
57
|
+
if (data.match(regex)) {
|
|
58
|
+
data = data.replace(regex, `${key}=${value}`);
|
|
59
|
+
} else {
|
|
60
|
+
data += `
|
|
61
|
+
${key}=${value}`;
|
|
62
|
+
}
|
|
63
|
+
await this.writeFile({ filePath, data });
|
|
64
|
+
console.log(`${key} set to ${value} in ENV file.`);
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
async getEnvValue(key) {
|
|
68
|
+
try {
|
|
69
|
+
const data = await this.readFile(this.filePath);
|
|
70
|
+
const regex = new RegExp(`^${key}=(.*)$`, "m");
|
|
71
|
+
const match = data.match(regex);
|
|
72
|
+
return match?.[1] || null;
|
|
73
|
+
} catch (err) {
|
|
74
|
+
console.error(`Error reading ENV value: ${err}`);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async setEnvValue(key, value) {
|
|
79
|
+
try {
|
|
80
|
+
const data = await this.readFile(this.filePath);
|
|
81
|
+
await this.updateEnvData({ key, value, data });
|
|
82
|
+
} catch (err) {
|
|
83
|
+
console.error(`Error writing ENV value: ${err}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// src/build/fs.ts
|
|
89
|
+
var FileService = class {
|
|
90
|
+
/**
|
|
91
|
+
*
|
|
92
|
+
* @param inputFile the file in the starter files directory to copy
|
|
93
|
+
* @param outputFilePath the destination path
|
|
94
|
+
* @param replaceIfExists flag to replace if it exists
|
|
95
|
+
* @returns
|
|
96
|
+
*/
|
|
97
|
+
async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
|
|
98
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
99
|
+
const __dirname = path2.dirname(__filename);
|
|
100
|
+
const filePath = path2.resolve(__dirname, "..", "starter-files", inputFile);
|
|
101
|
+
const fileString = fs2__default.readFileSync(filePath, "utf8");
|
|
102
|
+
if (fs2__default.existsSync(outputFilePath) && !replaceIfExists) {
|
|
103
|
+
console.log(`${outputFilePath} already exists`);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
await fsExtra.outputFile(outputFilePath, fileString);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
async setupEnvFile({ dbUrl }) {
|
|
110
|
+
const envPath = path2.join(process.cwd(), ".env.development");
|
|
111
|
+
await fsExtra.ensureFile(envPath);
|
|
112
|
+
const fileEnvService = new FileEnvService(envPath);
|
|
113
|
+
await fileEnvService.setEnvValue("DB_URL", dbUrl);
|
|
114
|
+
}
|
|
115
|
+
getFirstExistingFile(files) {
|
|
116
|
+
for (const f of files) {
|
|
117
|
+
if (fs2__default.existsSync(f)) {
|
|
118
|
+
return f;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
throw new Error("Missing required file, checked the following paths: " + files.join(", "));
|
|
122
|
+
}
|
|
123
|
+
replaceValuesInFile({
|
|
124
|
+
filePath,
|
|
125
|
+
replacements
|
|
126
|
+
}) {
|
|
127
|
+
let fileContent = fs2__default.readFileSync(filePath, "utf8");
|
|
128
|
+
replacements.forEach(({ search, replace }) => {
|
|
129
|
+
fileContent = fileContent.replaceAll(search, replace);
|
|
130
|
+
});
|
|
131
|
+
fs2__default.writeFileSync(filePath, fileContent);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
function rewriteLibsqlImport() {
|
|
135
|
+
const t = babel__default.types;
|
|
136
|
+
let hasReplaced = false;
|
|
137
|
+
return {
|
|
138
|
+
name: "rewrite-libsql-import",
|
|
139
|
+
visitor: {
|
|
140
|
+
FunctionDeclaration(path3) {
|
|
141
|
+
if (path3.node.id?.name === "requireNative" && !hasReplaced) {
|
|
142
|
+
hasReplaced = true;
|
|
143
|
+
const createRequire = addNamed(path3, "createRequire", "module");
|
|
144
|
+
const requireIdentifier = t.identifier("require");
|
|
145
|
+
path3.replaceWith(
|
|
146
|
+
t.functionDeclaration(
|
|
147
|
+
t.identifier("requireNative"),
|
|
148
|
+
[],
|
|
149
|
+
t.blockStatement([
|
|
150
|
+
t.variableDeclaration("const", [
|
|
151
|
+
t.variableDeclarator(
|
|
152
|
+
requireIdentifier,
|
|
153
|
+
t.callExpression(createRequire, [
|
|
154
|
+
t.memberExpression(
|
|
155
|
+
t.metaProperty(t.identifier("import"), t.identifier("meta")),
|
|
156
|
+
t.identifier("url")
|
|
157
|
+
)
|
|
158
|
+
])
|
|
159
|
+
)
|
|
160
|
+
]),
|
|
161
|
+
t.returnStatement(t.callExpression(requireIdentifier, [t.stringLiteral("./libsql.node")]))
|
|
162
|
+
])
|
|
163
|
+
)
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/build/plugins/fix-libsql.ts
|
|
172
|
+
function libSqlFix() {
|
|
173
|
+
return {
|
|
174
|
+
name: "libSqlFix",
|
|
175
|
+
transform(code, id) {
|
|
176
|
+
if (!id.includes("\\libsql\\index.js") && !id.includes("/libsql/index.js")) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
return new Promise((resolve2, reject) => {
|
|
180
|
+
babel.transform(
|
|
181
|
+
code,
|
|
182
|
+
{
|
|
183
|
+
babelrc: false,
|
|
184
|
+
configFile: false,
|
|
185
|
+
filename: id,
|
|
186
|
+
plugins: [rewriteLibsqlImport]
|
|
187
|
+
},
|
|
188
|
+
(err, result) => {
|
|
189
|
+
if (err) {
|
|
190
|
+
return reject(err);
|
|
191
|
+
}
|
|
192
|
+
resolve2({
|
|
193
|
+
code: result.code,
|
|
194
|
+
map: result.map
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
async generateBundle({ file, dir }) {
|
|
201
|
+
if (!file && !dir) {
|
|
202
|
+
throw new Error("No output options were given.");
|
|
203
|
+
}
|
|
204
|
+
const outputDirectory = dir || dirname(file);
|
|
205
|
+
let target = currentTarget();
|
|
206
|
+
if (familySync() == GLIBC) {
|
|
207
|
+
switch (target) {
|
|
208
|
+
case "linux-x64-musl":
|
|
209
|
+
target = "linux-x64-gnu";
|
|
210
|
+
break;
|
|
211
|
+
case "linux-arm64-musl":
|
|
212
|
+
target = "linux-arm64-gnu";
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const fileToCopy = await this.resolve(`@libsql/${target}/index.node`);
|
|
217
|
+
if (fileToCopy) {
|
|
218
|
+
await fsExtra.copy(fileToCopy.id, join(outputDirectory, "libsql.node"));
|
|
219
|
+
} else {
|
|
220
|
+
throw new Error(`libsql binding not found for @libsql/${target}/index.node`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function removeDeployer() {
|
|
226
|
+
const t = babel__default.types;
|
|
227
|
+
let mastraClass = null;
|
|
228
|
+
let hasReplaced = false;
|
|
229
|
+
return {
|
|
230
|
+
name: "remove-deployer",
|
|
231
|
+
visitor: {
|
|
232
|
+
ImportDeclaration(path3) {
|
|
233
|
+
if ((path3.node.source.value === "@mastra/core" || path3.node.source.value === "@mastra/core/mastra") && path3.node.specifiers) {
|
|
234
|
+
const mastraObj = path3.node.specifiers.find(
|
|
235
|
+
(p) => t.isImportSpecifier(p) && t.isIdentifier(p.imported) && p.imported.name === "Mastra"
|
|
236
|
+
);
|
|
237
|
+
if (mastraObj?.local?.name) {
|
|
238
|
+
mastraClass = mastraObj.local.name;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
NewExpression(path3) {
|
|
243
|
+
if (mastraClass && t.isIdentifier(path3.node.callee) && path3.node.callee.name === mastraClass && !hasReplaced) {
|
|
244
|
+
hasReplaced = true;
|
|
245
|
+
const newMastraObj = t.cloneNode(path3.node);
|
|
246
|
+
if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.[0]) {
|
|
247
|
+
newMastraObj.arguments[0].properties = newMastraObj.arguments[0].properties.filter(
|
|
248
|
+
(prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name !== "deployer"
|
|
249
|
+
);
|
|
250
|
+
path3.replaceWith(newMastraObj);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// src/build/plugins/remove-deployer.ts
|
|
259
|
+
function removeDeployer2(mastraEntry) {
|
|
260
|
+
return {
|
|
261
|
+
name: "remove-deployer",
|
|
262
|
+
transform(code, id) {
|
|
263
|
+
if (id !== mastraEntry) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
return new Promise((resolve2, reject) => {
|
|
267
|
+
babel.transform(
|
|
268
|
+
code,
|
|
269
|
+
{
|
|
270
|
+
babelrc: false,
|
|
271
|
+
configFile: false,
|
|
272
|
+
filename: id,
|
|
273
|
+
plugins: [removeDeployer]
|
|
274
|
+
},
|
|
275
|
+
(err, result) => {
|
|
276
|
+
if (err) {
|
|
277
|
+
return reject(err);
|
|
278
|
+
}
|
|
279
|
+
resolve2({
|
|
280
|
+
code: result.code,
|
|
281
|
+
map: result.map
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function getTelemetryMachineFile() {
|
|
290
|
+
switch (platform) {
|
|
291
|
+
case "darwin":
|
|
292
|
+
return "getMachineId-darwin";
|
|
293
|
+
case "linux":
|
|
294
|
+
return "getMachineId-linux";
|
|
295
|
+
case "freebsd":
|
|
296
|
+
return "getMachineId-bsd";
|
|
297
|
+
case "win32":
|
|
298
|
+
return "getMachineId-win";
|
|
299
|
+
default:
|
|
300
|
+
return "getMachineId-unsupported";
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function telemetryFix() {
|
|
304
|
+
return {
|
|
305
|
+
name: "telemetry-fix",
|
|
306
|
+
transform(code, id) {
|
|
307
|
+
if (id.includes("require-in-the-middle")) {
|
|
308
|
+
return code.replace(
|
|
309
|
+
`const path = require('path')`,
|
|
310
|
+
`const path = require('path');
|
|
311
|
+
const { createRequire } = require('module');
|
|
312
|
+
const realRequire = createRequire(import.meta.url)`
|
|
313
|
+
).replaceAll(`require.resolve`, `realRequire.resolve`);
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
resolveId(id, importer) {
|
|
317
|
+
if (id === "./machine-id/getMachineId" && importer) {
|
|
318
|
+
return { id: resolve(dirname(importer), `./machine-id/${getTelemetryMachineFile()}.js`) };
|
|
319
|
+
}
|
|
320
|
+
if (id === "formdata-node") {
|
|
321
|
+
return { id: "formdata-node", external: false };
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
load(id) {
|
|
325
|
+
if (id.startsWith("formdata-node")) {
|
|
326
|
+
return "export default {};";
|
|
327
|
+
}
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// src/build/bundle.ts
|
|
334
|
+
function getOptions(inputOptions, platform2) {
|
|
335
|
+
const fileService = new FileService();
|
|
336
|
+
const entry = fileService.getFirstExistingFile([
|
|
337
|
+
join(process.cwd(), "src/mastra/index.ts"),
|
|
338
|
+
join(process.cwd(), "src/mastra/index.js")
|
|
339
|
+
]);
|
|
340
|
+
const nodeBuiltins = platform2 === "node" ? builtins({ version: "20.0.0" }) : [];
|
|
341
|
+
let nodeResolvePlugin = platform2 === "node" ? nodeResolve({
|
|
342
|
+
preferBuiltins: true,
|
|
343
|
+
exportConditions: ["node", "import", "require"],
|
|
344
|
+
mainFields: ["module", "main"]
|
|
345
|
+
}) : nodeResolve({
|
|
346
|
+
preferBuiltins: false,
|
|
347
|
+
exportConditions: ["browser", "import", "require"],
|
|
348
|
+
mainFields: ["module", "main"],
|
|
349
|
+
browser: true
|
|
350
|
+
});
|
|
351
|
+
return {
|
|
352
|
+
logLevel: "silent",
|
|
353
|
+
...inputOptions,
|
|
354
|
+
treeshake: false,
|
|
355
|
+
preserveSymlinks: true,
|
|
356
|
+
external: [
|
|
357
|
+
...nodeBuiltins,
|
|
358
|
+
...nodeBuiltins.map((builtin) => "node:" + builtin),
|
|
359
|
+
...inputOptions.external ?? []
|
|
360
|
+
],
|
|
361
|
+
plugins: [
|
|
362
|
+
...inputOptions.plugins ?? [],
|
|
363
|
+
telemetryFix(),
|
|
364
|
+
alias({
|
|
365
|
+
entries: [
|
|
366
|
+
{
|
|
367
|
+
find: /^\#server$/,
|
|
368
|
+
replacement: fileURLToPath(import.meta.resolve("@mastra/deployer/server")).replaceAll("\\", "/")
|
|
369
|
+
},
|
|
370
|
+
{ find: /^\#mastra$/, replacement: entry.replaceAll("\\", "/") },
|
|
371
|
+
{
|
|
372
|
+
find: /^hono\//,
|
|
373
|
+
replacement: "hono/",
|
|
374
|
+
customResolver: (id, importer) => {
|
|
375
|
+
if (!importer?.startsWith("\0virtual")) {
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
const path3 = import.meta.resolve(id);
|
|
379
|
+
return fileURLToPath(path3);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
]
|
|
383
|
+
}),
|
|
384
|
+
commonjs({
|
|
385
|
+
strictRequires: "debug"
|
|
386
|
+
// dynamicRequireTargets: ['node_modules/**/@libsql+win32-*/*'],
|
|
387
|
+
}),
|
|
388
|
+
libSqlFix(),
|
|
389
|
+
// for debugging
|
|
390
|
+
// {
|
|
391
|
+
// name: 'logger',
|
|
392
|
+
// // @ts-ignore
|
|
393
|
+
// resolveId(id, ...args) {
|
|
394
|
+
// console.log({ id, args });
|
|
395
|
+
// },
|
|
396
|
+
// },
|
|
397
|
+
nodeResolvePlugin,
|
|
398
|
+
json(),
|
|
399
|
+
esbuild({
|
|
400
|
+
include: /\.tsx?$/,
|
|
401
|
+
target: "node20",
|
|
402
|
+
platform: platform2,
|
|
403
|
+
minify: false,
|
|
404
|
+
define: {
|
|
405
|
+
"process.env.NODE_ENV": JSON.stringify("production")
|
|
406
|
+
}
|
|
407
|
+
}),
|
|
408
|
+
removeDeployer2(entry),
|
|
409
|
+
esbuild({
|
|
410
|
+
include: entry,
|
|
411
|
+
target: "node20",
|
|
412
|
+
platform: platform2,
|
|
413
|
+
minify: false
|
|
414
|
+
})
|
|
415
|
+
].filter(Boolean)
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
async function getBundler(inputOptions, platform2 = "node") {
|
|
419
|
+
const bundle = await rollup(getOptions(inputOptions, platform2));
|
|
420
|
+
return bundle;
|
|
421
|
+
}
|
|
422
|
+
async function getWatcher(inputOptions, platform2 = "node") {
|
|
423
|
+
const watcher = watch(getOptions(inputOptions, platform2));
|
|
424
|
+
return watcher;
|
|
425
|
+
}
|
|
426
|
+
var createPinoStream = (logger) => {
|
|
427
|
+
return new Transform({
|
|
428
|
+
transform(chunk, _encoding, callback) {
|
|
429
|
+
const line = chunk.toString().trim();
|
|
430
|
+
if (line) {
|
|
431
|
+
console.log(line);
|
|
432
|
+
logger.info(line);
|
|
433
|
+
}
|
|
434
|
+
callback(null, chunk);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
};
|
|
438
|
+
function createChildProcessLogger({ logger, root }) {
|
|
439
|
+
const pinoStream = createPinoStream(logger);
|
|
440
|
+
return async ({ cmd, args, env }) => {
|
|
441
|
+
try {
|
|
442
|
+
const subprocess = spawn(cmd, args, {
|
|
443
|
+
cwd: root,
|
|
444
|
+
shell: true,
|
|
445
|
+
env
|
|
446
|
+
});
|
|
447
|
+
subprocess.stdout?.pipe(pinoStream);
|
|
448
|
+
subprocess.stderr?.pipe(pinoStream);
|
|
449
|
+
return new Promise((resolve2, reject) => {
|
|
450
|
+
subprocess.on("close", (code) => {
|
|
451
|
+
pinoStream.end();
|
|
452
|
+
if (code === 0) {
|
|
453
|
+
resolve2({ success: true });
|
|
454
|
+
} else {
|
|
455
|
+
reject(new Error(`Process exited with code ${code}`));
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
subprocess.on("error", (error) => {
|
|
459
|
+
pinoStream.end();
|
|
460
|
+
logger.error("Process failed", { error });
|
|
461
|
+
reject(error);
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
} catch (error) {
|
|
465
|
+
console.log(error);
|
|
466
|
+
logger.error("Process failed", { error });
|
|
467
|
+
pinoStream.end();
|
|
468
|
+
return { success: false, error };
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// src/build/deps.ts
|
|
474
|
+
var Deps = class extends MastraBase {
|
|
475
|
+
packageManager;
|
|
476
|
+
constructor() {
|
|
477
|
+
super({ component: "DEPLOYER", name: "DEPS" });
|
|
478
|
+
this.packageManager = this.getPackageManager();
|
|
479
|
+
}
|
|
480
|
+
findLockFile(dir) {
|
|
481
|
+
const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
|
|
482
|
+
for (const file of lockFiles) {
|
|
483
|
+
if (fs2__default.existsSync(path2.join(dir, file))) {
|
|
484
|
+
return file;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const parentDir = path2.resolve(dir, "..");
|
|
488
|
+
if (parentDir !== dir) {
|
|
489
|
+
return this.findLockFile(parentDir);
|
|
490
|
+
}
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
getPackageManager() {
|
|
494
|
+
const lockFile = this.findLockFile(process.cwd());
|
|
495
|
+
switch (lockFile) {
|
|
496
|
+
case "pnpm-lock.yaml":
|
|
497
|
+
return "pnpm";
|
|
498
|
+
case "package-lock.json":
|
|
499
|
+
return "npm";
|
|
500
|
+
case "yarn.lock":
|
|
501
|
+
return "yarn";
|
|
502
|
+
case "bun.lock":
|
|
503
|
+
return "bun";
|
|
504
|
+
default:
|
|
505
|
+
return "npm";
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
async install({ dir = process.cwd(), packages = [] }) {
|
|
509
|
+
let runCommand = this.packageManager;
|
|
510
|
+
if (this.packageManager === "npm") {
|
|
511
|
+
runCommand = `${this.packageManager} i`;
|
|
512
|
+
} else {
|
|
513
|
+
runCommand = `${this.packageManager} ${packages?.length > 0 ? `add` : `install`}`;
|
|
514
|
+
}
|
|
515
|
+
const cpLogger = createChildProcessLogger({
|
|
516
|
+
logger: this.logger,
|
|
517
|
+
root: dir
|
|
518
|
+
});
|
|
519
|
+
return cpLogger({
|
|
520
|
+
cmd: runCommand,
|
|
521
|
+
args: packages,
|
|
522
|
+
env: {
|
|
523
|
+
PATH: process.env.PATH
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
async installPackages(packages) {
|
|
528
|
+
let runCommand = this.packageManager;
|
|
529
|
+
if (this.packageManager === "npm") {
|
|
530
|
+
runCommand = `${this.packageManager} i`;
|
|
531
|
+
} else {
|
|
532
|
+
runCommand = `${this.packageManager} add`;
|
|
533
|
+
}
|
|
534
|
+
const cpLogger = createChildProcessLogger({
|
|
535
|
+
logger: this.logger,
|
|
536
|
+
root: ""
|
|
537
|
+
});
|
|
538
|
+
return cpLogger({
|
|
539
|
+
cmd: `${runCommand}`,
|
|
540
|
+
args: packages,
|
|
541
|
+
env: {
|
|
542
|
+
PATH: process.env.PATH
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
async checkDependencies(dependencies) {
|
|
547
|
+
try {
|
|
548
|
+
const packageJsonPath = path2.join(process.cwd(), "package.json");
|
|
549
|
+
try {
|
|
550
|
+
await fsPromises.access(packageJsonPath);
|
|
551
|
+
} catch {
|
|
552
|
+
return "No package.json file found in the current directory";
|
|
553
|
+
}
|
|
554
|
+
const packageJson = JSON.parse(await fsPromises.readFile(packageJsonPath, "utf-8"));
|
|
555
|
+
for (const dependency of dependencies) {
|
|
556
|
+
if (!packageJson.dependencies || !packageJson.dependencies[dependency]) {
|
|
557
|
+
return `Please install ${dependency} before running this command (${this.packageManager} install ${dependency})`;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return "ok";
|
|
561
|
+
} catch (err) {
|
|
562
|
+
console.error(err);
|
|
563
|
+
return "Could not check dependencies";
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
async getProjectName() {
|
|
567
|
+
try {
|
|
568
|
+
const packageJsonPath = path2.join(process.cwd(), "package.json");
|
|
569
|
+
const packageJson = await fsPromises.readFile(packageJsonPath, "utf-8");
|
|
570
|
+
const pkg = JSON.parse(packageJson);
|
|
571
|
+
return pkg.name;
|
|
572
|
+
} catch (err) {
|
|
573
|
+
throw err;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
async getPackageVersion() {
|
|
577
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
578
|
+
const __dirname = dirname(__filename);
|
|
579
|
+
const pkgJsonPath = path2.join(__dirname, "..", "..", "package.json");
|
|
580
|
+
const content = await fsExtra.readJSON(pkgJsonPath);
|
|
581
|
+
return content.version;
|
|
582
|
+
}
|
|
583
|
+
async addScriptsToPackageJson(scripts) {
|
|
584
|
+
const packageJson = JSON.parse(await fsPromises.readFile("package.json", "utf-8"));
|
|
585
|
+
packageJson.scripts = {
|
|
586
|
+
...packageJson.scripts,
|
|
587
|
+
...scripts
|
|
588
|
+
};
|
|
589
|
+
await fsPromises.writeFile("package.json", JSON.stringify(packageJson, null, 2));
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
export { Deps, FileService, getBundler, getWatcher };
|