@mastra/deployer 0.2.3 → 0.2.4-alpha.1
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/dist/_tsup-dts-rollup.d.cts +7 -0
- package/dist/_tsup-dts-rollup.d.ts +7 -0
- package/dist/build/analyze.cjs +2 -2
- package/dist/build/analyze.js +1 -1
- package/dist/build/index.cjs +11 -11
- package/dist/build/index.js +3 -3
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.js +1 -1
- package/dist/{chunk-FVHOV5SC.cjs → chunk-7GYBZLVN.cjs} +3 -3
- package/dist/{chunk-IGPSPQAD.js → chunk-CS5NGTWK.js} +2 -2
- package/dist/{chunk-PRZC7CEM.cjs → chunk-KFOGAPGX.cjs} +94 -4
- package/dist/{chunk-KNO7RCEZ.cjs → chunk-NWERLYTR.cjs} +76 -19
- package/dist/{chunk-UKRVXD63.js → chunk-PUX2FDGX.js} +1 -1
- package/dist/{chunk-T23IXDLE.js → chunk-UTZ3434D.js} +77 -20
- package/dist/{chunk-XZSN3YN6.cjs → chunk-WUF7W23E.cjs} +7 -7
- package/dist/{chunk-7XQJJPRM.js → chunk-ZAXXMFXX.js} +93 -4
- package/dist/index.cjs +32 -16
- package/dist/index.js +27 -11
- package/dist/server/index.cjs +2 -2
- package/dist/server/index.js +2 -2
- package/dist/validator/custom-resolver.cjs +24 -5
- package/dist/validator/custom-resolver.js +24 -5
- package/package.json +2 -2
|
@@ -335,6 +335,11 @@ export declare type PluginOptions = Omit<RegisterOptions, 'loggerID'>;
|
|
|
335
335
|
|
|
336
336
|
export declare function queryVectors(c: Context): Promise<Response>;
|
|
337
337
|
|
|
338
|
+
export declare function recursiveRemoveNonReferencedNodes(code: string): Promise<{
|
|
339
|
+
code: string;
|
|
340
|
+
map: any;
|
|
341
|
+
}>;
|
|
342
|
+
|
|
338
343
|
export declare function removeAllExceptDeployer(): babel_2.PluginObj;
|
|
339
344
|
|
|
340
345
|
export declare function removeAllExceptTelemetryConfig(result: {
|
|
@@ -345,6 +350,8 @@ export declare function removeDeployer(): babel_2.PluginObj;
|
|
|
345
350
|
|
|
346
351
|
export declare function removeDeployer_alias_1(mastraEntry: string): Plugin;
|
|
347
352
|
|
|
353
|
+
export declare function removeNonReferencedNodes(): babel_2.PluginObj;
|
|
354
|
+
|
|
348
355
|
export declare function resolve(specifier: string, context: ResolveHookContext, nextResolve: (specifier: string, context: ResolveHookContext) => Promise<{
|
|
349
356
|
url: string;
|
|
350
357
|
}>): Promise<{
|
|
@@ -335,6 +335,11 @@ export declare type PluginOptions = Omit<RegisterOptions, 'loggerID'>;
|
|
|
335
335
|
|
|
336
336
|
export declare function queryVectors(c: Context): Promise<Response>;
|
|
337
337
|
|
|
338
|
+
export declare function recursiveRemoveNonReferencedNodes(code: string): Promise<{
|
|
339
|
+
code: string;
|
|
340
|
+
map: any;
|
|
341
|
+
}>;
|
|
342
|
+
|
|
338
343
|
export declare function removeAllExceptDeployer(): babel_2.PluginObj;
|
|
339
344
|
|
|
340
345
|
export declare function removeAllExceptTelemetryConfig(result: {
|
|
@@ -345,6 +350,8 @@ export declare function removeDeployer(): babel_2.PluginObj;
|
|
|
345
350
|
|
|
346
351
|
export declare function removeDeployer_alias_1(mastraEntry: string): Plugin;
|
|
347
352
|
|
|
353
|
+
export declare function removeNonReferencedNodes(): babel_2.PluginObj;
|
|
354
|
+
|
|
348
355
|
export declare function resolve(specifier: string, context: ResolveHookContext, nextResolve: (specifier: string, context: ResolveHookContext) => Promise<{
|
|
349
356
|
url: string;
|
|
350
357
|
}>): Promise<{
|
package/dist/build/analyze.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkNWERLYTR_cjs = require('../chunk-NWERLYTR.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "analyzeBundle", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkNWERLYTR_cjs.analyzeBundle; }
|
|
10
10
|
});
|
package/dist/build/analyze.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { analyzeBundle } from '../chunk-
|
|
1
|
+
export { analyzeBundle } from '../chunk-UTZ3434D.js';
|
package/dist/build/index.cjs
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunk7GYBZLVN_cjs = require('../chunk-7GYBZLVN.cjs');
|
|
4
|
+
var chunkKFOGAPGX_cjs = require('../chunk-KFOGAPGX.cjs');
|
|
5
|
+
var chunkNWERLYTR_cjs = require('../chunk-NWERLYTR.cjs');
|
|
6
6
|
var chunkOT6UKL2S_cjs = require('../chunk-OT6UKL2S.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
Object.defineProperty(exports, "FileService", {
|
|
11
11
|
enumerable: true,
|
|
12
|
-
get: function () { return
|
|
12
|
+
get: function () { return chunk7GYBZLVN_cjs.FileService; }
|
|
13
13
|
});
|
|
14
14
|
Object.defineProperty(exports, "createWatcher", {
|
|
15
15
|
enumerable: true,
|
|
16
|
-
get: function () { return
|
|
16
|
+
get: function () { return chunk7GYBZLVN_cjs.createWatcher; }
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "getBundler", {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: function () { return
|
|
20
|
+
get: function () { return chunk7GYBZLVN_cjs.getBundler; }
|
|
21
21
|
});
|
|
22
22
|
Object.defineProperty(exports, "getWatcher", {
|
|
23
23
|
enumerable: true,
|
|
24
|
-
get: function () { return
|
|
24
|
+
get: function () { return chunk7GYBZLVN_cjs.getWatcher; }
|
|
25
25
|
});
|
|
26
26
|
Object.defineProperty(exports, "getWatcherInputOptions", {
|
|
27
27
|
enumerable: true,
|
|
28
|
-
get: function () { return
|
|
28
|
+
get: function () { return chunk7GYBZLVN_cjs.getInputOptions; }
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "Deps", {
|
|
31
31
|
enumerable: true,
|
|
32
|
-
get: function () { return
|
|
32
|
+
get: function () { return chunkKFOGAPGX_cjs.Deps; }
|
|
33
33
|
});
|
|
34
34
|
Object.defineProperty(exports, "writeTelemetryConfig", {
|
|
35
35
|
enumerable: true,
|
|
36
|
-
get: function () { return
|
|
36
|
+
get: function () { return chunkKFOGAPGX_cjs.writeTelemetryConfig; }
|
|
37
37
|
});
|
|
38
38
|
Object.defineProperty(exports, "analyzeBundle", {
|
|
39
39
|
enumerable: true,
|
|
40
|
-
get: function () { return
|
|
40
|
+
get: function () { return chunkNWERLYTR_cjs.analyzeBundle; }
|
|
41
41
|
});
|
|
42
42
|
Object.defineProperty(exports, "createBundler", {
|
|
43
43
|
enumerable: true,
|
package/dist/build/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { FileService, createWatcher, getBundler, getWatcher, getInputOptions as getWatcherInputOptions } from '../chunk-
|
|
2
|
-
export { Deps, writeTelemetryConfig } from '../chunk-
|
|
3
|
-
export { analyzeBundle } from '../chunk-
|
|
1
|
+
export { FileService, createWatcher, getBundler, getWatcher, getInputOptions as getWatcherInputOptions } from '../chunk-PUX2FDGX.js';
|
|
2
|
+
export { Deps, writeTelemetryConfig } from '../chunk-ZAXXMFXX.js';
|
|
3
|
+
export { analyzeBundle } from '../chunk-UTZ3434D.js';
|
|
4
4
|
export { createBundler, getInputOptions as getBundlerInputOptions } from '../chunk-XEFBJH3T.js';
|
package/dist/bundler/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkWUF7W23E_cjs = require('../chunk-WUF7W23E.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "Bundler", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkWUF7W23E_cjs.Bundler; }
|
|
10
10
|
});
|
package/dist/bundler/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Bundler } from '../chunk-
|
|
1
|
+
export { Bundler } from '../chunk-CS5NGTWK.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkNWERLYTR_cjs = require('./chunk-NWERLYTR.cjs');
|
|
4
4
|
var chunkOT6UKL2S_cjs = require('./chunk-OT6UKL2S.cjs');
|
|
5
5
|
var chunk54KOF3NB_cjs = require('./chunk-54KOF3NB.cjs');
|
|
6
6
|
var alias = require('@rollup/plugin-alias');
|
|
@@ -116,7 +116,7 @@ var FileService = class {
|
|
|
116
116
|
* @returns
|
|
117
117
|
*/
|
|
118
118
|
async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
|
|
119
|
-
const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
119
|
+
const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-7GYBZLVN.cjs', document.baseURI).href)));
|
|
120
120
|
const __dirname = path__default.default.dirname(__filename);
|
|
121
121
|
const filePath = path__default.default.resolve(__dirname, "..", "starter-files", inputFile);
|
|
122
122
|
const fileString = fs2__namespace.default.readFileSync(filePath, "utf8");
|
|
@@ -262,7 +262,7 @@ async function getInputOptions2(entryFile, platform) {
|
|
|
262
262
|
// @ts-ignore
|
|
263
263
|
(plugin) => !plugin || !plugin?.name || plugin.name !== "node-resolve"
|
|
264
264
|
);
|
|
265
|
-
inputOptions.plugins.push(
|
|
265
|
+
inputOptions.plugins.push(chunkNWERLYTR_cjs.aliasHono());
|
|
266
266
|
}
|
|
267
267
|
return inputOptions;
|
|
268
268
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Deps, writeTelemetryConfig } from './chunk-
|
|
2
|
-
import { analyzeBundle } from './chunk-
|
|
1
|
+
import { Deps, writeTelemetryConfig } from './chunk-ZAXXMFXX.js';
|
|
2
|
+
import { analyzeBundle } from './chunk-UTZ3434D.js';
|
|
3
3
|
import { createBundler, getInputOptions } from './chunk-XEFBJH3T.js';
|
|
4
4
|
import { existsSync } from 'node:fs';
|
|
5
5
|
import { writeFile, stat } from 'node:fs/promises';
|
|
@@ -199,7 +199,7 @@ var Deps = class extends base.MastraBase {
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
async getPackageVersion() {
|
|
202
|
-
const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
202
|
+
const __filename = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-KFOGAPGX.cjs', document.baseURI).href)));
|
|
203
203
|
const __dirname = path.dirname(__filename);
|
|
204
204
|
const pkgJsonPath = path__default.default.join(__dirname, "..", "..", "package.json");
|
|
205
205
|
const content = await fsExtra__default.default.readJSON(pkgJsonPath);
|
|
@@ -234,10 +234,11 @@ function removeAllExceptTelemetryConfig(result) {
|
|
|
234
234
|
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
235
235
|
return;
|
|
236
236
|
}
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
let mastraArgs = t.objectExpression([]);
|
|
238
|
+
if (t.isObjectExpression(path2.node.arguments[0])) {
|
|
239
|
+
mastraArgs = path2.node.arguments[0];
|
|
239
240
|
}
|
|
240
|
-
let telemetry =
|
|
241
|
+
let telemetry = mastraArgs.properties.find(
|
|
241
242
|
// @ts-ignore
|
|
242
243
|
(prop) => prop.key.name === "telemetry"
|
|
243
244
|
);
|
|
@@ -267,6 +268,79 @@ function removeAllExceptTelemetryConfig(result) {
|
|
|
267
268
|
}
|
|
268
269
|
};
|
|
269
270
|
}
|
|
271
|
+
function removeNonReferencedNodes() {
|
|
272
|
+
const t = babel__namespace.default.types;
|
|
273
|
+
return {
|
|
274
|
+
name: "remove-non-referenced-nodes",
|
|
275
|
+
visitor: {
|
|
276
|
+
Program(path2) {
|
|
277
|
+
const scope = path2.scope;
|
|
278
|
+
const currentBody = path2.get("body");
|
|
279
|
+
const filteredBody = currentBody.filter((childPath) => {
|
|
280
|
+
if (childPath.isExportDeclaration()) {
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
if (childPath.isVariableDeclaration()) {
|
|
284
|
+
return childPath.node.declarations.some((decl) => {
|
|
285
|
+
if (!t.isIdentifier(decl.id)) {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
const name = decl.id.name;
|
|
289
|
+
const binding = scope.getBinding(name);
|
|
290
|
+
return binding && (binding.referenced || binding.referencePaths.length > 0);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {
|
|
294
|
+
if (!t.isIdentifier(childPath.node.id)) {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
const name = childPath.node.id.name;
|
|
298
|
+
const binding = scope.getBinding(name);
|
|
299
|
+
return binding && (binding.referenced || binding.referencePaths.length > 0);
|
|
300
|
+
}
|
|
301
|
+
if (childPath.isImportDeclaration()) {
|
|
302
|
+
return childPath.node.specifiers.some((specifier) => {
|
|
303
|
+
const importedName = specifier.local.name;
|
|
304
|
+
const binding = scope.getBinding(importedName);
|
|
305
|
+
return binding && (binding.referenced || binding.referencePaths.length > 0);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
return false;
|
|
309
|
+
});
|
|
310
|
+
path2.set(
|
|
311
|
+
"body",
|
|
312
|
+
filteredBody.map((p) => p.node)
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function recursiveRemoveNonReferencedNodes(code) {
|
|
319
|
+
return new Promise(async (resolve, reject) => {
|
|
320
|
+
babel__namespace.transform(
|
|
321
|
+
code,
|
|
322
|
+
{
|
|
323
|
+
babelrc: false,
|
|
324
|
+
configFile: false,
|
|
325
|
+
plugins: [removeNonReferencedNodes()]
|
|
326
|
+
},
|
|
327
|
+
(err, result) => {
|
|
328
|
+
if (err) {
|
|
329
|
+
return reject(err);
|
|
330
|
+
}
|
|
331
|
+
if (result && result.code !== code) {
|
|
332
|
+
return recursiveRemoveNonReferencedNodes(result.code).then(resolve, reject);
|
|
333
|
+
}
|
|
334
|
+
resolve({
|
|
335
|
+
code: result.code,
|
|
336
|
+
map: result.map
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
);
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// src/build/telemetry.ts
|
|
270
344
|
function getTelemetryBundler(entryFile, result) {
|
|
271
345
|
return rollup.rollup({
|
|
272
346
|
logLevel: "silent",
|
|
@@ -316,6 +390,21 @@ function getTelemetryBundler(entryFile, result) {
|
|
|
316
390
|
}
|
|
317
391
|
},
|
|
318
392
|
// let esbuild remove all unused imports
|
|
393
|
+
esbuild__default.default({
|
|
394
|
+
target: "node20",
|
|
395
|
+
platform: "node",
|
|
396
|
+
minify: false
|
|
397
|
+
}),
|
|
398
|
+
{
|
|
399
|
+
name: "cleanup",
|
|
400
|
+
transform(code, id) {
|
|
401
|
+
if (id !== entryFile) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
return recursiveRemoveNonReferencedNodes(code);
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
// let esbuild remove all unused imports
|
|
319
408
|
esbuild__default.default({
|
|
320
409
|
target: "node20",
|
|
321
410
|
platform: "node",
|
|
@@ -340,4 +429,5 @@ async function writeTelemetryConfig(entryFile, outputDir) {
|
|
|
340
429
|
exports.Deps = Deps;
|
|
341
430
|
exports.createChildProcessLogger = createChildProcessLogger;
|
|
342
431
|
exports.createPinoStream = createPinoStream;
|
|
432
|
+
exports.recursiveRemoveNonReferencedNodes = recursiveRemoveNonReferencedNodes;
|
|
343
433
|
exports.writeTelemetryConfig = writeTelemetryConfig;
|
|
@@ -12,6 +12,7 @@ var esbuild = require('rollup-plugin-esbuild');
|
|
|
12
12
|
var module$1 = require('module');
|
|
13
13
|
var path = require('path');
|
|
14
14
|
var child_process = require('child_process');
|
|
15
|
+
var promises = require('fs/promises');
|
|
15
16
|
|
|
16
17
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
18
|
|
|
@@ -60,17 +61,43 @@ function spawn(command, args = [], options = {}) {
|
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
function validate(file) {
|
|
63
|
-
return spawn(
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
return spawn(
|
|
65
|
+
"node",
|
|
66
|
+
[
|
|
67
|
+
"--import",
|
|
68
|
+
undefined("@mastra/deployer/loader"),
|
|
69
|
+
"--input-type=module",
|
|
70
|
+
"-e",
|
|
71
|
+
`import('file://${file.replaceAll("\\", "/")}')`
|
|
72
|
+
],
|
|
73
|
+
{
|
|
74
|
+
cwd: path.dirname(file)
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
var globalExternals = ["pino", "pino-pretty", "@libsql/client", "pg", "libsql", "jsdom", "sqlite3"];
|
|
79
|
+
function findExternalImporter(module, external, allOutputs) {
|
|
80
|
+
const capturedFiles = /* @__PURE__ */ new Set();
|
|
81
|
+
for (const id of module.imports) {
|
|
82
|
+
if (id === external) {
|
|
83
|
+
return module;
|
|
84
|
+
} else {
|
|
85
|
+
if (id.endsWith(".mjs")) {
|
|
86
|
+
capturedFiles.add(id);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (const file of capturedFiles) {
|
|
91
|
+
const nextModule = allOutputs.find((o) => o.fileName === file);
|
|
92
|
+
if (nextModule) {
|
|
93
|
+
const importer = findExternalImporter(nextModule, external, allOutputs);
|
|
94
|
+
if (importer) {
|
|
95
|
+
return importer;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
70
100
|
}
|
|
71
|
-
|
|
72
|
-
// src/build/analyze.ts
|
|
73
|
-
var globalExternals = ["pino", "pino-pretty", "@libsql/client"];
|
|
74
101
|
async function analyze(entry, mastraEntry, isVirtualFile, platform, logger) {
|
|
75
102
|
logger.info("Analyzing dependencies...");
|
|
76
103
|
let virtualPlugin = null;
|
|
@@ -149,7 +176,7 @@ async function bundleExternals(depsToOptimize, outputDir, logger) {
|
|
|
149
176
|
if (local === "*") {
|
|
150
177
|
virtualFile.push(`export * from '${dep}';`);
|
|
151
178
|
} else if (local === "default") {
|
|
152
|
-
virtualFile.push(`export
|
|
179
|
+
virtualFile.push(`export { default } from '${dep}';`);
|
|
153
180
|
} else {
|
|
154
181
|
exportStringBuilder.push(local);
|
|
155
182
|
}
|
|
@@ -173,9 +200,8 @@ async function bundleExternals(depsToOptimize, outputDir, logger) {
|
|
|
173
200
|
),
|
|
174
201
|
// this dependency breaks the build, so we need to exclude it
|
|
175
202
|
// TODO actually fix this so we don't need to exclude it
|
|
176
|
-
external:
|
|
203
|
+
external: globalExternals,
|
|
177
204
|
treeshake: "smallest",
|
|
178
|
-
preserveSymlinks: true,
|
|
179
205
|
plugins: [
|
|
180
206
|
virtual__default.default(
|
|
181
207
|
Array.from(virtualDependencies.entries()).reduce(
|
|
@@ -205,18 +231,45 @@ async function bundleExternals(depsToOptimize, outputDir, logger) {
|
|
|
205
231
|
format: "esm",
|
|
206
232
|
dir: outputDir,
|
|
207
233
|
entryFileNames: "[name].mjs",
|
|
208
|
-
chunkFileNames: "[name].mjs"
|
|
234
|
+
chunkFileNames: "[name].mjs",
|
|
235
|
+
hoistTransitiveImports: false
|
|
209
236
|
});
|
|
237
|
+
const moduleResolveMap = {};
|
|
238
|
+
const filteredChunks = output.filter((o) => o.type === "chunk");
|
|
239
|
+
for (const o of filteredChunks.filter((o2) => o2.isEntry || o2.isDynamicEntry)) {
|
|
240
|
+
for (const external of globalExternals) {
|
|
241
|
+
const importer = findExternalImporter(o, external, filteredChunks);
|
|
242
|
+
if (importer) {
|
|
243
|
+
const fullPath = path.join(outputDir, importer.fileName);
|
|
244
|
+
moduleResolveMap[fullPath] = moduleResolveMap[fullPath] || {};
|
|
245
|
+
if (importer.moduleIds.length) {
|
|
246
|
+
moduleResolveMap[fullPath][external] = importer.moduleIds[importer.moduleIds.length - 1]?.startsWith(
|
|
247
|
+
"\0virtual:#virtual"
|
|
248
|
+
) ? importer.moduleIds[importer.moduleIds.length - 2] : importer.moduleIds[importer.moduleIds.length - 1];
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
await promises.writeFile(path.join(outputDir, "module-resolve-map.json"), JSON.stringify(moduleResolveMap, null, 2));
|
|
210
254
|
await bundler.close();
|
|
211
|
-
return { output, reverseVirtualReferenceMap };
|
|
255
|
+
return { output, reverseVirtualReferenceMap, usedExternals: moduleResolveMap };
|
|
212
256
|
}
|
|
213
|
-
async function validateOutput(
|
|
257
|
+
async function validateOutput({
|
|
258
|
+
output,
|
|
259
|
+
reverseVirtualReferenceMap,
|
|
260
|
+
usedExternals,
|
|
261
|
+
outputDir
|
|
262
|
+
}, logger) {
|
|
214
263
|
const result = {
|
|
215
264
|
invalidChunks: /* @__PURE__ */ new Set(),
|
|
216
265
|
dependencies: /* @__PURE__ */ new Map(),
|
|
217
266
|
externalDependencies: /* @__PURE__ */ new Set()
|
|
218
267
|
};
|
|
219
|
-
|
|
268
|
+
for (const deps of Object.values(usedExternals)) {
|
|
269
|
+
for (const dep of Object.keys(deps)) {
|
|
270
|
+
result.externalDependencies.add(dep);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
220
273
|
for (const file of output) {
|
|
221
274
|
if (file.type === "asset") {
|
|
222
275
|
continue;
|
|
@@ -241,8 +294,12 @@ async function validateOutput(output, reverseVirtualReferenceMap, outputDir, log
|
|
|
241
294
|
async function analyzeBundle(entry, mastraEntry, outputDir, platform, logger) {
|
|
242
295
|
const isVirtualFile = entry.includes("\n") || !fs.existsSync(entry);
|
|
243
296
|
const depsToOptimize = await analyze(entry, mastraEntry, isVirtualFile, platform, logger);
|
|
244
|
-
const { output, reverseVirtualReferenceMap } = await bundleExternals(
|
|
245
|
-
|
|
297
|
+
const { output, reverseVirtualReferenceMap, usedExternals } = await bundleExternals(
|
|
298
|
+
depsToOptimize,
|
|
299
|
+
outputDir,
|
|
300
|
+
logger
|
|
301
|
+
);
|
|
302
|
+
const result = await validateOutput({ output, reverseVirtualReferenceMap, usedExternals, outputDir }, logger);
|
|
246
303
|
return result;
|
|
247
304
|
}
|
|
248
305
|
|
|
@@ -8,8 +8,9 @@ import { fileURLToPath } from 'node:url';
|
|
|
8
8
|
import { rollup } from 'rollup';
|
|
9
9
|
import esbuild from 'rollup-plugin-esbuild';
|
|
10
10
|
import { builtinModules } from 'node:module';
|
|
11
|
-
import { join } from 'node:path';
|
|
11
|
+
import { join, dirname } from 'node:path';
|
|
12
12
|
import { spawn as spawn$1 } from 'node:child_process';
|
|
13
|
+
import { writeFile } from 'node:fs/promises';
|
|
13
14
|
|
|
14
15
|
function isNodeBuiltin(dep) {
|
|
15
16
|
const [pkg] = dep.split("/");
|
|
@@ -50,17 +51,43 @@ function spawn(command, args = [], options = {}) {
|
|
|
50
51
|
});
|
|
51
52
|
}
|
|
52
53
|
function validate(file) {
|
|
53
|
-
return spawn(
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
return spawn(
|
|
55
|
+
"node",
|
|
56
|
+
[
|
|
57
|
+
"--import",
|
|
58
|
+
import.meta.resolve("@mastra/deployer/loader"),
|
|
59
|
+
"--input-type=module",
|
|
60
|
+
"-e",
|
|
61
|
+
`import('file://${file.replaceAll("\\", "/")}')`
|
|
62
|
+
],
|
|
63
|
+
{
|
|
64
|
+
cwd: dirname(file)
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
var globalExternals = ["pino", "pino-pretty", "@libsql/client", "pg", "libsql", "jsdom", "sqlite3"];
|
|
69
|
+
function findExternalImporter(module, external, allOutputs) {
|
|
70
|
+
const capturedFiles = /* @__PURE__ */ new Set();
|
|
71
|
+
for (const id of module.imports) {
|
|
72
|
+
if (id === external) {
|
|
73
|
+
return module;
|
|
74
|
+
} else {
|
|
75
|
+
if (id.endsWith(".mjs")) {
|
|
76
|
+
capturedFiles.add(id);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const file of capturedFiles) {
|
|
81
|
+
const nextModule = allOutputs.find((o) => o.fileName === file);
|
|
82
|
+
if (nextModule) {
|
|
83
|
+
const importer = findExternalImporter(nextModule, external, allOutputs);
|
|
84
|
+
if (importer) {
|
|
85
|
+
return importer;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
60
90
|
}
|
|
61
|
-
|
|
62
|
-
// src/build/analyze.ts
|
|
63
|
-
var globalExternals = ["pino", "pino-pretty", "@libsql/client"];
|
|
64
91
|
async function analyze(entry, mastraEntry, isVirtualFile, platform, logger) {
|
|
65
92
|
logger.info("Analyzing dependencies...");
|
|
66
93
|
let virtualPlugin = null;
|
|
@@ -139,7 +166,7 @@ async function bundleExternals(depsToOptimize, outputDir, logger) {
|
|
|
139
166
|
if (local === "*") {
|
|
140
167
|
virtualFile.push(`export * from '${dep}';`);
|
|
141
168
|
} else if (local === "default") {
|
|
142
|
-
virtualFile.push(`export
|
|
169
|
+
virtualFile.push(`export { default } from '${dep}';`);
|
|
143
170
|
} else {
|
|
144
171
|
exportStringBuilder.push(local);
|
|
145
172
|
}
|
|
@@ -163,9 +190,8 @@ async function bundleExternals(depsToOptimize, outputDir, logger) {
|
|
|
163
190
|
),
|
|
164
191
|
// this dependency breaks the build, so we need to exclude it
|
|
165
192
|
// TODO actually fix this so we don't need to exclude it
|
|
166
|
-
external:
|
|
193
|
+
external: globalExternals,
|
|
167
194
|
treeshake: "smallest",
|
|
168
|
-
preserveSymlinks: true,
|
|
169
195
|
plugins: [
|
|
170
196
|
virtual(
|
|
171
197
|
Array.from(virtualDependencies.entries()).reduce(
|
|
@@ -195,18 +221,45 @@ async function bundleExternals(depsToOptimize, outputDir, logger) {
|
|
|
195
221
|
format: "esm",
|
|
196
222
|
dir: outputDir,
|
|
197
223
|
entryFileNames: "[name].mjs",
|
|
198
|
-
chunkFileNames: "[name].mjs"
|
|
224
|
+
chunkFileNames: "[name].mjs",
|
|
225
|
+
hoistTransitiveImports: false
|
|
199
226
|
});
|
|
227
|
+
const moduleResolveMap = {};
|
|
228
|
+
const filteredChunks = output.filter((o) => o.type === "chunk");
|
|
229
|
+
for (const o of filteredChunks.filter((o2) => o2.isEntry || o2.isDynamicEntry)) {
|
|
230
|
+
for (const external of globalExternals) {
|
|
231
|
+
const importer = findExternalImporter(o, external, filteredChunks);
|
|
232
|
+
if (importer) {
|
|
233
|
+
const fullPath = join(outputDir, importer.fileName);
|
|
234
|
+
moduleResolveMap[fullPath] = moduleResolveMap[fullPath] || {};
|
|
235
|
+
if (importer.moduleIds.length) {
|
|
236
|
+
moduleResolveMap[fullPath][external] = importer.moduleIds[importer.moduleIds.length - 1]?.startsWith(
|
|
237
|
+
"\0virtual:#virtual"
|
|
238
|
+
) ? importer.moduleIds[importer.moduleIds.length - 2] : importer.moduleIds[importer.moduleIds.length - 1];
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
await writeFile(join(outputDir, "module-resolve-map.json"), JSON.stringify(moduleResolveMap, null, 2));
|
|
200
244
|
await bundler.close();
|
|
201
|
-
return { output, reverseVirtualReferenceMap };
|
|
245
|
+
return { output, reverseVirtualReferenceMap, usedExternals: moduleResolveMap };
|
|
202
246
|
}
|
|
203
|
-
async function validateOutput(
|
|
247
|
+
async function validateOutput({
|
|
248
|
+
output,
|
|
249
|
+
reverseVirtualReferenceMap,
|
|
250
|
+
usedExternals,
|
|
251
|
+
outputDir
|
|
252
|
+
}, logger) {
|
|
204
253
|
const result = {
|
|
205
254
|
invalidChunks: /* @__PURE__ */ new Set(),
|
|
206
255
|
dependencies: /* @__PURE__ */ new Map(),
|
|
207
256
|
externalDependencies: /* @__PURE__ */ new Set()
|
|
208
257
|
};
|
|
209
|
-
|
|
258
|
+
for (const deps of Object.values(usedExternals)) {
|
|
259
|
+
for (const dep of Object.keys(deps)) {
|
|
260
|
+
result.externalDependencies.add(dep);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
210
263
|
for (const file of output) {
|
|
211
264
|
if (file.type === "asset") {
|
|
212
265
|
continue;
|
|
@@ -231,8 +284,12 @@ async function validateOutput(output, reverseVirtualReferenceMap, outputDir, log
|
|
|
231
284
|
async function analyzeBundle(entry, mastraEntry, outputDir, platform, logger) {
|
|
232
285
|
const isVirtualFile = entry.includes("\n") || !existsSync(entry);
|
|
233
286
|
const depsToOptimize = await analyze(entry, mastraEntry, isVirtualFile, platform, logger);
|
|
234
|
-
const { output, reverseVirtualReferenceMap } = await bundleExternals(
|
|
235
|
-
|
|
287
|
+
const { output, reverseVirtualReferenceMap, usedExternals } = await bundleExternals(
|
|
288
|
+
depsToOptimize,
|
|
289
|
+
outputDir,
|
|
290
|
+
logger
|
|
291
|
+
);
|
|
292
|
+
const result = await validateOutput({ output, reverseVirtualReferenceMap, usedExternals, outputDir }, logger);
|
|
236
293
|
return result;
|
|
237
294
|
}
|
|
238
295
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkKFOGAPGX_cjs = require('./chunk-KFOGAPGX.cjs');
|
|
4
|
+
var chunkNWERLYTR_cjs = require('./chunk-NWERLYTR.cjs');
|
|
5
5
|
var chunkOT6UKL2S_cjs = require('./chunk-OT6UKL2S.cjs');
|
|
6
6
|
var fs = require('fs');
|
|
7
7
|
var promises = require('fs/promises');
|
|
@@ -31,7 +31,7 @@ var Bundler = class extends bundler.MastraBundler {
|
|
|
31
31
|
}
|
|
32
32
|
async writeInstrumentationFile(outputDirectory) {
|
|
33
33
|
const instrumentationFile = path.join(outputDirectory, "instrumentation.mjs");
|
|
34
|
-
const __dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
34
|
+
const __dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-WUF7W23E.cjs', document.baseURI).href))));
|
|
35
35
|
await esm.copy(path.join(__dirname, "templates", "instrumentation-template.js"), instrumentationFile);
|
|
36
36
|
}
|
|
37
37
|
async writePackageJson(outputDirectory, dependencies) {
|
|
@@ -73,10 +73,10 @@ var Bundler = class extends bundler.MastraBundler {
|
|
|
73
73
|
return chunkOT6UKL2S_cjs.createBundler(inputOptions, outputOptions);
|
|
74
74
|
}
|
|
75
75
|
async analyze(entry, mastraFile, outputDirectory) {
|
|
76
|
-
return await
|
|
76
|
+
return await chunkNWERLYTR_cjs.analyzeBundle(entry, mastraFile, path.join(outputDirectory, this.analyzeOutputDir), "node", this.logger);
|
|
77
77
|
}
|
|
78
78
|
async installDependencies(outputDirectory, rootDir = process.cwd()) {
|
|
79
|
-
const deps = new
|
|
79
|
+
const deps = new chunkKFOGAPGX_cjs.Deps(rootDir);
|
|
80
80
|
deps.__setLogger(this.logger);
|
|
81
81
|
await deps.install({ dir: path.join(outputDirectory, this.outputDir) });
|
|
82
82
|
}
|
|
@@ -92,14 +92,14 @@ var Bundler = class extends bundler.MastraBundler {
|
|
|
92
92
|
async _bundle(serverFile, mastraEntryFile, outputDirectory, bundleLocation = path.join(outputDirectory, this.outputDir)) {
|
|
93
93
|
this.logger.info("Start bundling Mastra");
|
|
94
94
|
const isVirtual = serverFile.includes("\n") || fs.existsSync(serverFile);
|
|
95
|
-
const analyzedBundleInfo = await
|
|
95
|
+
const analyzedBundleInfo = await chunkNWERLYTR_cjs.analyzeBundle(
|
|
96
96
|
serverFile,
|
|
97
97
|
mastraEntryFile,
|
|
98
98
|
path.join(outputDirectory, this.analyzeOutputDir),
|
|
99
99
|
"node",
|
|
100
100
|
this.logger
|
|
101
101
|
);
|
|
102
|
-
await
|
|
102
|
+
await chunkKFOGAPGX_cjs.writeTelemetryConfig(mastraEntryFile, path.join(outputDirectory, this.outputDir));
|
|
103
103
|
const dependenciesToInstall = /* @__PURE__ */ new Map();
|
|
104
104
|
for (const dep of analyzedBundleInfo.externalDependencies) {
|
|
105
105
|
try {
|
|
@@ -204,10 +204,11 @@ function removeAllExceptTelemetryConfig(result) {
|
|
|
204
204
|
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
205
205
|
return;
|
|
206
206
|
}
|
|
207
|
-
|
|
208
|
-
|
|
207
|
+
let mastraArgs = t.objectExpression([]);
|
|
208
|
+
if (t.isObjectExpression(path2.node.arguments[0])) {
|
|
209
|
+
mastraArgs = path2.node.arguments[0];
|
|
209
210
|
}
|
|
210
|
-
let telemetry =
|
|
211
|
+
let telemetry = mastraArgs.properties.find(
|
|
211
212
|
// @ts-ignore
|
|
212
213
|
(prop) => prop.key.name === "telemetry"
|
|
213
214
|
);
|
|
@@ -237,6 +238,79 @@ function removeAllExceptTelemetryConfig(result) {
|
|
|
237
238
|
}
|
|
238
239
|
};
|
|
239
240
|
}
|
|
241
|
+
function removeNonReferencedNodes() {
|
|
242
|
+
const t = babel__default.types;
|
|
243
|
+
return {
|
|
244
|
+
name: "remove-non-referenced-nodes",
|
|
245
|
+
visitor: {
|
|
246
|
+
Program(path2) {
|
|
247
|
+
const scope = path2.scope;
|
|
248
|
+
const currentBody = path2.get("body");
|
|
249
|
+
const filteredBody = currentBody.filter((childPath) => {
|
|
250
|
+
if (childPath.isExportDeclaration()) {
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
if (childPath.isVariableDeclaration()) {
|
|
254
|
+
return childPath.node.declarations.some((decl) => {
|
|
255
|
+
if (!t.isIdentifier(decl.id)) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
const name = decl.id.name;
|
|
259
|
+
const binding = scope.getBinding(name);
|
|
260
|
+
return binding && (binding.referenced || binding.referencePaths.length > 0);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {
|
|
264
|
+
if (!t.isIdentifier(childPath.node.id)) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
const name = childPath.node.id.name;
|
|
268
|
+
const binding = scope.getBinding(name);
|
|
269
|
+
return binding && (binding.referenced || binding.referencePaths.length > 0);
|
|
270
|
+
}
|
|
271
|
+
if (childPath.isImportDeclaration()) {
|
|
272
|
+
return childPath.node.specifiers.some((specifier) => {
|
|
273
|
+
const importedName = specifier.local.name;
|
|
274
|
+
const binding = scope.getBinding(importedName);
|
|
275
|
+
return binding && (binding.referenced || binding.referencePaths.length > 0);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
279
|
+
});
|
|
280
|
+
path2.set(
|
|
281
|
+
"body",
|
|
282
|
+
filteredBody.map((p) => p.node)
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function recursiveRemoveNonReferencedNodes(code) {
|
|
289
|
+
return new Promise(async (resolve, reject) => {
|
|
290
|
+
babel.transform(
|
|
291
|
+
code,
|
|
292
|
+
{
|
|
293
|
+
babelrc: false,
|
|
294
|
+
configFile: false,
|
|
295
|
+
plugins: [removeNonReferencedNodes()]
|
|
296
|
+
},
|
|
297
|
+
(err, result) => {
|
|
298
|
+
if (err) {
|
|
299
|
+
return reject(err);
|
|
300
|
+
}
|
|
301
|
+
if (result && result.code !== code) {
|
|
302
|
+
return recursiveRemoveNonReferencedNodes(result.code).then(resolve, reject);
|
|
303
|
+
}
|
|
304
|
+
resolve({
|
|
305
|
+
code: result.code,
|
|
306
|
+
map: result.map
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
);
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/build/telemetry.ts
|
|
240
314
|
function getTelemetryBundler(entryFile, result) {
|
|
241
315
|
return rollup({
|
|
242
316
|
logLevel: "silent",
|
|
@@ -286,6 +360,21 @@ function getTelemetryBundler(entryFile, result) {
|
|
|
286
360
|
}
|
|
287
361
|
},
|
|
288
362
|
// let esbuild remove all unused imports
|
|
363
|
+
esbuild({
|
|
364
|
+
target: "node20",
|
|
365
|
+
platform: "node",
|
|
366
|
+
minify: false
|
|
367
|
+
}),
|
|
368
|
+
{
|
|
369
|
+
name: "cleanup",
|
|
370
|
+
transform(code, id) {
|
|
371
|
+
if (id !== entryFile) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
return recursiveRemoveNonReferencedNodes(code);
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
// let esbuild remove all unused imports
|
|
289
378
|
esbuild({
|
|
290
379
|
target: "node20",
|
|
291
380
|
platform: "node",
|
|
@@ -307,4 +396,4 @@ async function writeTelemetryConfig(entryFile, outputDir) {
|
|
|
307
396
|
return result;
|
|
308
397
|
}
|
|
309
398
|
|
|
310
|
-
export { Deps, createChildProcessLogger, createPinoStream, writeTelemetryConfig };
|
|
399
|
+
export { Deps, createChildProcessLogger, createPinoStream, recursiveRemoveNonReferencedNodes, writeTelemetryConfig };
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunk7GYBZLVN_cjs = require('./chunk-7GYBZLVN.cjs');
|
|
4
|
+
var chunkWUF7W23E_cjs = require('./chunk-WUF7W23E.cjs');
|
|
5
|
+
var chunkKFOGAPGX_cjs = require('./chunk-KFOGAPGX.cjs');
|
|
6
6
|
var babel = require('@babel/core');
|
|
7
7
|
var rollup = require('rollup');
|
|
8
8
|
var esbuild = require('rollup-plugin-esbuild');
|
|
@@ -33,8 +33,8 @@ var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
|
|
|
33
33
|
var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
|
|
34
34
|
|
|
35
35
|
// src/deploy/base.ts
|
|
36
|
-
var Deployer = class extends
|
|
37
|
-
deps = new
|
|
36
|
+
var Deployer = class extends chunkWUF7W23E_cjs.Bundler {
|
|
37
|
+
deps = new chunkKFOGAPGX_cjs.Deps();
|
|
38
38
|
constructor(args) {
|
|
39
39
|
super(args.name, "DEPLOYER");
|
|
40
40
|
this.deps.__setLogger(this.logger);
|
|
@@ -42,7 +42,7 @@ var Deployer = class extends chunkXZSN3YN6_cjs.Bundler {
|
|
|
42
42
|
getEnvFiles() {
|
|
43
43
|
const possibleFiles = [".env.production", ".env.local", ".env"];
|
|
44
44
|
try {
|
|
45
|
-
const fileService = new
|
|
45
|
+
const fileService = new chunk7GYBZLVN_cjs.FileService();
|
|
46
46
|
const envFile = fileService.getFirstExistingFile(possibleFiles);
|
|
47
47
|
return Promise.resolve([envFile]);
|
|
48
48
|
} catch {
|
|
@@ -95,18 +95,18 @@ function getDeployerBundler(entryFile) {
|
|
|
95
95
|
},
|
|
96
96
|
treeshake: "smallest",
|
|
97
97
|
plugins: [
|
|
98
|
-
commonjs__default.default({
|
|
99
|
-
extensions: [".js", ".ts"],
|
|
100
|
-
strictRequires: "strict",
|
|
101
|
-
transformMixedEsModules: true,
|
|
102
|
-
ignoreTryCatch: false
|
|
103
|
-
}),
|
|
104
98
|
// transpile typescript to something we understand
|
|
105
99
|
esbuild__default.default({
|
|
106
100
|
target: "node20",
|
|
107
101
|
platform: "node",
|
|
108
102
|
minify: false
|
|
109
103
|
}),
|
|
104
|
+
commonjs__default.default({
|
|
105
|
+
extensions: [".js", ".ts"],
|
|
106
|
+
strictRequires: "strict",
|
|
107
|
+
transformMixedEsModules: true,
|
|
108
|
+
ignoreTryCatch: false
|
|
109
|
+
}),
|
|
110
110
|
{
|
|
111
111
|
name: "get-deployer",
|
|
112
112
|
transform(code, id) {
|
|
@@ -136,6 +136,21 @@ function getDeployerBundler(entryFile) {
|
|
|
136
136
|
}
|
|
137
137
|
},
|
|
138
138
|
// let esbuild remove all unused imports
|
|
139
|
+
esbuild__default.default({
|
|
140
|
+
target: "node20",
|
|
141
|
+
platform: "node",
|
|
142
|
+
minify: false
|
|
143
|
+
}),
|
|
144
|
+
{
|
|
145
|
+
name: "cleanup-nodes",
|
|
146
|
+
transform(code, id) {
|
|
147
|
+
if (id !== entryFile) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
return chunkKFOGAPGX_cjs.recursiveRemoveNonReferencedNodes(code);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
// let esbuild remove all unused imports
|
|
139
154
|
esbuild__default.default({
|
|
140
155
|
target: "node20",
|
|
141
156
|
platform: "node",
|
|
@@ -145,6 +160,7 @@ function getDeployerBundler(entryFile) {
|
|
|
145
160
|
});
|
|
146
161
|
}
|
|
147
162
|
async function getDeployer(entryFile, outputDir) {
|
|
163
|
+
console.log("entryFile", entryFile);
|
|
148
164
|
const bundle = await getDeployerBundler(entryFile);
|
|
149
165
|
await bundle.write({
|
|
150
166
|
dir: outputDir,
|
|
@@ -156,19 +172,19 @@ async function getDeployer(entryFile, outputDir) {
|
|
|
156
172
|
|
|
157
173
|
Object.defineProperty(exports, "FileService", {
|
|
158
174
|
enumerable: true,
|
|
159
|
-
get: function () { return
|
|
175
|
+
get: function () { return chunk7GYBZLVN_cjs.FileService; }
|
|
160
176
|
});
|
|
161
177
|
Object.defineProperty(exports, "Deps", {
|
|
162
178
|
enumerable: true,
|
|
163
|
-
get: function () { return
|
|
179
|
+
get: function () { return chunkKFOGAPGX_cjs.Deps; }
|
|
164
180
|
});
|
|
165
181
|
Object.defineProperty(exports, "createChildProcessLogger", {
|
|
166
182
|
enumerable: true,
|
|
167
|
-
get: function () { return
|
|
183
|
+
get: function () { return chunkKFOGAPGX_cjs.createChildProcessLogger; }
|
|
168
184
|
});
|
|
169
185
|
Object.defineProperty(exports, "createPinoStream", {
|
|
170
186
|
enumerable: true,
|
|
171
|
-
get: function () { return
|
|
187
|
+
get: function () { return chunkKFOGAPGX_cjs.createPinoStream; }
|
|
172
188
|
});
|
|
173
189
|
exports.Deployer = Deployer;
|
|
174
190
|
exports.getDeployer = getDeployer;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { FileService } from './chunk-
|
|
2
|
-
export { FileService } from './chunk-
|
|
3
|
-
import { Bundler } from './chunk-
|
|
4
|
-
import { Deps } from './chunk-
|
|
5
|
-
export { Deps, createChildProcessLogger, createPinoStream } from './chunk-
|
|
1
|
+
import { FileService } from './chunk-PUX2FDGX.js';
|
|
2
|
+
export { FileService } from './chunk-PUX2FDGX.js';
|
|
3
|
+
import { Bundler } from './chunk-CS5NGTWK.js';
|
|
4
|
+
import { Deps, recursiveRemoveNonReferencedNodes } from './chunk-ZAXXMFXX.js';
|
|
5
|
+
export { Deps, createChildProcessLogger, createPinoStream } from './chunk-ZAXXMFXX.js';
|
|
6
6
|
import * as babel from '@babel/core';
|
|
7
7
|
import babel__default from '@babel/core';
|
|
8
8
|
import { rollup } from 'rollup';
|
|
@@ -72,18 +72,18 @@ function getDeployerBundler(entryFile) {
|
|
|
72
72
|
},
|
|
73
73
|
treeshake: "smallest",
|
|
74
74
|
plugins: [
|
|
75
|
-
commonjs({
|
|
76
|
-
extensions: [".js", ".ts"],
|
|
77
|
-
strictRequires: "strict",
|
|
78
|
-
transformMixedEsModules: true,
|
|
79
|
-
ignoreTryCatch: false
|
|
80
|
-
}),
|
|
81
75
|
// transpile typescript to something we understand
|
|
82
76
|
esbuild({
|
|
83
77
|
target: "node20",
|
|
84
78
|
platform: "node",
|
|
85
79
|
minify: false
|
|
86
80
|
}),
|
|
81
|
+
commonjs({
|
|
82
|
+
extensions: [".js", ".ts"],
|
|
83
|
+
strictRequires: "strict",
|
|
84
|
+
transformMixedEsModules: true,
|
|
85
|
+
ignoreTryCatch: false
|
|
86
|
+
}),
|
|
87
87
|
{
|
|
88
88
|
name: "get-deployer",
|
|
89
89
|
transform(code, id) {
|
|
@@ -113,6 +113,21 @@ function getDeployerBundler(entryFile) {
|
|
|
113
113
|
}
|
|
114
114
|
},
|
|
115
115
|
// let esbuild remove all unused imports
|
|
116
|
+
esbuild({
|
|
117
|
+
target: "node20",
|
|
118
|
+
platform: "node",
|
|
119
|
+
minify: false
|
|
120
|
+
}),
|
|
121
|
+
{
|
|
122
|
+
name: "cleanup-nodes",
|
|
123
|
+
transform(code, id) {
|
|
124
|
+
if (id !== entryFile) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
return recursiveRemoveNonReferencedNodes(code);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
// let esbuild remove all unused imports
|
|
116
131
|
esbuild({
|
|
117
132
|
target: "node20",
|
|
118
133
|
platform: "node",
|
|
@@ -122,6 +137,7 @@ function getDeployerBundler(entryFile) {
|
|
|
122
137
|
});
|
|
123
138
|
}
|
|
124
139
|
async function getDeployer(entryFile, outputDir) {
|
|
140
|
+
console.log("entryFile", entryFile);
|
|
125
141
|
const bundle = await getDeployerBundler(entryFile);
|
|
126
142
|
await bundle.write({
|
|
127
143
|
dir: outputDir,
|
package/dist/server/index.cjs
CHANGED
|
@@ -3723,7 +3723,7 @@ async function speakHandler(c2) {
|
|
|
3723
3723
|
const { input, options } = await c2.req.json();
|
|
3724
3724
|
await validateBody({ input });
|
|
3725
3725
|
const audioStream = await agent.voice.speak(input, options);
|
|
3726
|
-
c2.header("Content-Type", `audio/${options
|
|
3726
|
+
c2.header("Content-Type", `audio/${options?.filetype ?? "mp3"}`);
|
|
3727
3727
|
c2.header("Transfer-Encoding", "chunked");
|
|
3728
3728
|
return c2.body(audioStream);
|
|
3729
3729
|
} catch (error) {
|
|
@@ -4750,7 +4750,7 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4750
4750
|
schema: {
|
|
4751
4751
|
type: "object",
|
|
4752
4752
|
properties: {
|
|
4753
|
-
|
|
4753
|
+
input: {
|
|
4754
4754
|
type: "string",
|
|
4755
4755
|
description: "Text to convert to speech"
|
|
4756
4756
|
},
|
package/dist/server/index.js
CHANGED
|
@@ -3717,7 +3717,7 @@ async function speakHandler(c2) {
|
|
|
3717
3717
|
const { input, options } = await c2.req.json();
|
|
3718
3718
|
await validateBody({ input });
|
|
3719
3719
|
const audioStream = await agent.voice.speak(input, options);
|
|
3720
|
-
c2.header("Content-Type", `audio/${options
|
|
3720
|
+
c2.header("Content-Type", `audio/${options?.filetype ?? "mp3"}`);
|
|
3721
3721
|
c2.header("Transfer-Encoding", "chunked");
|
|
3722
3722
|
return c2.body(audioStream);
|
|
3723
3723
|
} catch (error) {
|
|
@@ -4744,7 +4744,7 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4744
4744
|
schema: {
|
|
4745
4745
|
type: "object",
|
|
4746
4746
|
properties: {
|
|
4747
|
-
|
|
4747
|
+
input: {
|
|
4748
4748
|
type: "string",
|
|
4749
4749
|
description: "Text to convert to speech"
|
|
4750
4750
|
},
|
|
@@ -1,16 +1,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var promises = require('fs/promises');
|
|
3
4
|
var module$1 = require('module');
|
|
5
|
+
var path = require('path');
|
|
4
6
|
var url = require('url');
|
|
5
|
-
var resolveFrom = require('resolve-from');
|
|
6
7
|
|
|
7
8
|
// src/validator/custom-resolver.ts
|
|
9
|
+
var cache = /* @__PURE__ */ new Map();
|
|
8
10
|
function isBuiltinModule(specifier) {
|
|
9
11
|
return module$1.builtinModules.includes(specifier) || specifier.startsWith("node:") || module$1.builtinModules.includes(specifier.replace(/^node:/, ""));
|
|
10
12
|
}
|
|
11
13
|
function isRelativePath(specifier) {
|
|
12
14
|
return specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/") || /^[a-zA-Z]:\\/.test(specifier);
|
|
13
15
|
}
|
|
16
|
+
async function getParentPath(specifier, url$1) {
|
|
17
|
+
if (!cache.size) {
|
|
18
|
+
const moduleResolveMap = JSON.parse(
|
|
19
|
+
// cwd refers to the output/build directory
|
|
20
|
+
await promises.readFile(path.join(process.cwd(), "module-resolve-map.json"), "utf-8")
|
|
21
|
+
);
|
|
22
|
+
for (const [id, rest] of Object.entries(moduleResolveMap)) {
|
|
23
|
+
cache.set(url.pathToFileURL(id).toString(), rest);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const importers = cache.get(url$1);
|
|
27
|
+
if (!importers || !importers[specifier]) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const specifierParent = importers[specifier];
|
|
31
|
+
return url.pathToFileURL(specifierParent).toString();
|
|
32
|
+
}
|
|
14
33
|
async function resolve(specifier, context, nextResolve) {
|
|
15
34
|
if (isBuiltinModule(specifier)) {
|
|
16
35
|
return nextResolve(specifier, context);
|
|
@@ -18,12 +37,12 @@ async function resolve(specifier, context, nextResolve) {
|
|
|
18
37
|
if (isRelativePath(specifier)) {
|
|
19
38
|
return nextResolve(specifier, context);
|
|
20
39
|
}
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
40
|
+
if (context.parentURL) {
|
|
41
|
+
const parentPath = await getParentPath(specifier, context.parentURL);
|
|
42
|
+
if (parentPath) {
|
|
24
43
|
return nextResolve(specifier, {
|
|
25
44
|
...context,
|
|
26
|
-
parentURL:
|
|
45
|
+
parentURL: parentPath
|
|
27
46
|
});
|
|
28
47
|
}
|
|
29
48
|
}
|
|
@@ -1,14 +1,33 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
1
2
|
import { builtinModules } from 'node:module';
|
|
3
|
+
import { join } from 'node:path';
|
|
2
4
|
import { pathToFileURL } from 'node:url';
|
|
3
|
-
import { silent } from 'resolve-from';
|
|
4
5
|
|
|
5
6
|
// src/validator/custom-resolver.ts
|
|
7
|
+
var cache = /* @__PURE__ */ new Map();
|
|
6
8
|
function isBuiltinModule(specifier) {
|
|
7
9
|
return builtinModules.includes(specifier) || specifier.startsWith("node:") || builtinModules.includes(specifier.replace(/^node:/, ""));
|
|
8
10
|
}
|
|
9
11
|
function isRelativePath(specifier) {
|
|
10
12
|
return specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/") || /^[a-zA-Z]:\\/.test(specifier);
|
|
11
13
|
}
|
|
14
|
+
async function getParentPath(specifier, url) {
|
|
15
|
+
if (!cache.size) {
|
|
16
|
+
const moduleResolveMap = JSON.parse(
|
|
17
|
+
// cwd refers to the output/build directory
|
|
18
|
+
await readFile(join(process.cwd(), "module-resolve-map.json"), "utf-8")
|
|
19
|
+
);
|
|
20
|
+
for (const [id, rest] of Object.entries(moduleResolveMap)) {
|
|
21
|
+
cache.set(pathToFileURL(id).toString(), rest);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const importers = cache.get(url);
|
|
25
|
+
if (!importers || !importers[specifier]) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const specifierParent = importers[specifier];
|
|
29
|
+
return pathToFileURL(specifierParent).toString();
|
|
30
|
+
}
|
|
12
31
|
async function resolve(specifier, context, nextResolve) {
|
|
13
32
|
if (isBuiltinModule(specifier)) {
|
|
14
33
|
return nextResolve(specifier, context);
|
|
@@ -16,12 +35,12 @@ async function resolve(specifier, context, nextResolve) {
|
|
|
16
35
|
if (isRelativePath(specifier)) {
|
|
17
36
|
return nextResolve(specifier, context);
|
|
18
37
|
}
|
|
19
|
-
if (
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
38
|
+
if (context.parentURL) {
|
|
39
|
+
const parentPath = await getParentPath(specifier, context.parentURL);
|
|
40
|
+
if (parentPath) {
|
|
22
41
|
return nextResolve(specifier, {
|
|
23
42
|
...context,
|
|
24
|
-
parentURL:
|
|
43
|
+
parentURL: parentPath
|
|
25
44
|
});
|
|
26
45
|
}
|
|
27
46
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/deployer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"rollup-plugin-node-externals": "^8.0.0",
|
|
96
96
|
"typescript-paths": "^1.5.1",
|
|
97
97
|
"zod": "^3.24.2",
|
|
98
|
-
"@mastra/core": "^0.6.
|
|
98
|
+
"@mastra/core": "^0.6.4-alpha.1"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@hono/node-server": "^1.13.8",
|