@mastra/deployer 0.2.1-alpha.1 → 0.2.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 +60 -18
- package/dist/_tsup-dts-rollup.d.ts +60 -18
- package/dist/build/analyze.cjs +2 -2
- package/dist/build/analyze.js +1 -1
- package/dist/build/bundler.cjs +3 -3
- package/dist/build/bundler.js +1 -1
- package/dist/build/index.cjs +14 -14
- package/dist/build/index.js +4 -4
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.js +1 -1
- package/dist/chunk-3H66SAKS.cjs +139 -0
- package/dist/{chunk-SL5KZNFT.js → chunk-7XQJJPRM.js} +26 -13
- package/dist/{chunk-72GFPLLU.js → chunk-DZ4D3KXZ.js} +4 -6
- package/dist/{chunk-YLIG5BNH.cjs → chunk-GLTC4BEQ.cjs} +42 -78
- package/dist/{chunk-J2F3DJTF.cjs → chunk-HLGZCQQW.cjs} +40 -22
- package/dist/{chunk-VPY2RQUP.js → chunk-HRR4D2GM.js} +29 -11
- package/dist/{chunk-TQSSPVHI.js → chunk-JNF4CXZJ.js} +42 -78
- package/dist/{chunk-PT5XTSU2.js → chunk-JNNKML56.js} +13 -1
- package/dist/{chunk-4LYFNYJ4.cjs → chunk-JSFQUYK4.cjs} +13 -1
- package/dist/{chunk-YJMYF7RI.cjs → chunk-PMHXFDK2.cjs} +8 -10
- package/dist/{chunk-VPP5727D.cjs → chunk-PRZC7CEM.cjs} +27 -14
- package/dist/chunk-XO6KJHXC.js +128 -0
- package/dist/index.cjs +16 -12
- package/dist/index.js +11 -7
- package/dist/server/index.cjs +183 -40
- package/dist/server/index.js +183 -40
- package/dist/validator/custom-resolver.cjs +33 -0
- package/dist/validator/custom-resolver.d.cts +1 -0
- package/dist/validator/custom-resolver.d.ts +1 -0
- package/dist/validator/custom-resolver.js +31 -0
- package/dist/validator/loader.cjs +7 -0
- package/dist/validator/loader.d.cts +1 -0
- package/dist/validator/loader.d.ts +1 -0
- package/dist/validator/loader.js +4 -0
- package/package.json +14 -3
- package/dist/chunk-AC67BJSW.js +0 -260
- package/dist/chunk-QFYK5AS3.cjs +0 -292
|
@@ -195,7 +195,7 @@ function removeAllExceptTelemetryConfig(result) {
|
|
|
195
195
|
path2.remove();
|
|
196
196
|
}
|
|
197
197
|
},
|
|
198
|
-
NewExpression(path2) {
|
|
198
|
+
NewExpression(path2, state) {
|
|
199
199
|
const varDeclaratorPath = path2.findParent((path3) => t.isVariableDeclarator(path3.node));
|
|
200
200
|
if (!varDeclaratorPath) {
|
|
201
201
|
return;
|
|
@@ -204,23 +204,32 @@ function removeAllExceptTelemetryConfig(result) {
|
|
|
204
204
|
if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
|
|
205
205
|
return;
|
|
206
206
|
}
|
|
207
|
-
|
|
207
|
+
if (!t.isObjectExpression(path2.node.arguments[0]) || !path2.node.arguments[0].properties?.[0]) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
let telemetry = path2.node.arguments[0].properties.find(
|
|
208
211
|
// @ts-ignore
|
|
209
212
|
(prop) => prop.key.name === "telemetry"
|
|
210
213
|
);
|
|
214
|
+
let telemetryValue = t.objectExpression([]);
|
|
211
215
|
const programPath = path2.scope.getProgramParent().path;
|
|
212
216
|
if (!programPath) {
|
|
213
217
|
return;
|
|
214
218
|
}
|
|
215
|
-
if (telemetry) {
|
|
219
|
+
if (telemetry && t.isObjectProperty(telemetry) && t.isExpression(telemetry.value)) {
|
|
216
220
|
result.hasCustomConfig = true;
|
|
217
|
-
|
|
218
|
-
telemetry
|
|
219
|
-
|
|
220
|
-
|
|
221
|
+
telemetryValue = telemetry.value;
|
|
222
|
+
if (t.isIdentifier(telemetry.value) && telemetry.value.name === "telemetry") {
|
|
223
|
+
const telemetryBinding = state.file.scope.getBinding("telemetry");
|
|
224
|
+
if (telemetryBinding && t.isVariableDeclarator(telemetryBinding.path.node)) {
|
|
225
|
+
const id = path2.scope.generateUidIdentifier("telemetry");
|
|
226
|
+
telemetryBinding.path.replaceWith(t.variableDeclarator(id, telemetryBinding.path.node.init));
|
|
227
|
+
telemetryValue = id;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
221
230
|
}
|
|
222
231
|
const exportDeclaration = t.exportNamedDeclaration(
|
|
223
|
-
t.variableDeclaration("const", [t.variableDeclarator(t.identifier("telemetry"),
|
|
232
|
+
t.variableDeclaration("const", [t.variableDeclarator(t.identifier("telemetry"), telemetryValue)]),
|
|
224
233
|
[]
|
|
225
234
|
);
|
|
226
235
|
programPath.node.body.push(exportDeclaration);
|
|
@@ -228,11 +237,9 @@ function removeAllExceptTelemetryConfig(result) {
|
|
|
228
237
|
}
|
|
229
238
|
};
|
|
230
239
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
};
|
|
235
|
-
const bundle = await rollup({
|
|
240
|
+
function getTelemetryBundler(entryFile, result) {
|
|
241
|
+
return rollup({
|
|
242
|
+
logLevel: "silent",
|
|
236
243
|
input: {
|
|
237
244
|
"telemetry-config": entryFile
|
|
238
245
|
},
|
|
@@ -286,6 +293,12 @@ async function writeTelemetryConfig(entryFile, outputDir) {
|
|
|
286
293
|
})
|
|
287
294
|
]
|
|
288
295
|
});
|
|
296
|
+
}
|
|
297
|
+
async function writeTelemetryConfig(entryFile, outputDir) {
|
|
298
|
+
const result = {
|
|
299
|
+
hasCustomConfig: false
|
|
300
|
+
};
|
|
301
|
+
const bundle = await getTelemetryBundler(entryFile, result);
|
|
289
302
|
await bundle.write({
|
|
290
303
|
dir: outputDir,
|
|
291
304
|
format: "es",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { aliasHono } from './chunk-
|
|
2
|
-
import { getInputOptions
|
|
3
|
-
import { removeDeployer } from './chunk-
|
|
1
|
+
import { aliasHono } from './chunk-JNF4CXZJ.js';
|
|
2
|
+
import { getInputOptions } from './chunk-XO6KJHXC.js';
|
|
3
|
+
import { removeDeployer } from './chunk-JNNKML56.js';
|
|
4
4
|
import alias from '@rollup/plugin-alias';
|
|
5
5
|
import commonjs from '@rollup/plugin-commonjs';
|
|
6
6
|
import json from '@rollup/plugin-json';
|
|
@@ -144,7 +144,7 @@ function getOptions(inputOptions, platform, root) {
|
|
|
144
144
|
return {
|
|
145
145
|
logLevel: "silent",
|
|
146
146
|
...inputOptions,
|
|
147
|
-
treeshake:
|
|
147
|
+
treeshake: "smallest",
|
|
148
148
|
preserveSymlinks: true,
|
|
149
149
|
external: [
|
|
150
150
|
...nodeBuiltins,
|
|
@@ -153,7 +153,6 @@ function getOptions(inputOptions, platform, root) {
|
|
|
153
153
|
],
|
|
154
154
|
plugins: [
|
|
155
155
|
...inputOptions.plugins ?? [],
|
|
156
|
-
telemetryFix(),
|
|
157
156
|
alias({
|
|
158
157
|
entries: [
|
|
159
158
|
{
|
|
@@ -179,7 +178,6 @@ function getOptions(inputOptions, platform, root) {
|
|
|
179
178
|
transformMixedEsModules: true
|
|
180
179
|
// dynamicRequireTargets: ['node_modules/**/@libsql+win32-*/*'],
|
|
181
180
|
}),
|
|
182
|
-
libSqlFix(),
|
|
183
181
|
// for debugging
|
|
184
182
|
// {
|
|
185
183
|
// name: 'logger',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkJSFQUYK4_cjs = require('./chunk-JSFQUYK4.cjs');
|
|
4
4
|
var commonjs = require('@rollup/plugin-commonjs');
|
|
5
5
|
var json = require('@rollup/plugin-json');
|
|
6
6
|
var nodeResolve = require('@rollup/plugin-node-resolve');
|
|
@@ -10,6 +10,8 @@ var url = require('url');
|
|
|
10
10
|
var rollup = require('rollup');
|
|
11
11
|
var esbuild = require('rollup-plugin-esbuild');
|
|
12
12
|
var module$1 = require('module');
|
|
13
|
+
var path = require('path');
|
|
14
|
+
var child_process = require('child_process');
|
|
13
15
|
|
|
14
16
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
17
|
|
|
@@ -35,81 +37,40 @@ function aliasHono() {
|
|
|
35
37
|
}
|
|
36
38
|
};
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
file: "pino-pretty"
|
|
57
|
-
}
|
|
58
|
-
];
|
|
59
|
-
const fileReferences = /* @__PURE__ */ new Map();
|
|
60
|
-
return {
|
|
61
|
-
name: "rollup-plugin-pino",
|
|
62
|
-
async resolveId(id, importee) {
|
|
63
|
-
if (id === "pino") {
|
|
64
|
-
const resolvedPino = await this.resolve(id, importee);
|
|
65
|
-
if (resolvedPino) {
|
|
66
|
-
await Promise.all(
|
|
67
|
-
workerFiles.map(async (file) => {
|
|
68
|
-
const resolvedEntry = await this.resolve(file.id, resolvedPino.id);
|
|
69
|
-
if (!resolvedEntry) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
const reference = this.emitFile({
|
|
73
|
-
type: "chunk",
|
|
74
|
-
id: resolvedEntry.id,
|
|
75
|
-
name: `${file.file}`
|
|
76
|
-
});
|
|
77
|
-
fileReferences.set(file.id, reference);
|
|
78
|
-
})
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
renderChunk(code, chunk) {
|
|
84
|
-
if (chunk.type === "chunk" && chunk.isEntry && fileReferences.size && chunk.name === "index") {
|
|
85
|
-
const importRegex = /^(?:import(?:["'\s]*[\w*${}\n\r\t, ]+from\s*)?["'\s].+[;"'\s]*)$/gm;
|
|
86
|
-
const codeToInject = `globalThis.__bundlerPathsOverrides = {
|
|
87
|
-
${Array.from(fileReferences.entries()).map(([key, file]) => {
|
|
88
|
-
return '"' + key + '": import.meta.ROLLUP_FILE_URL_' + file;
|
|
89
|
-
}).join(",\n")}
|
|
90
|
-
};`;
|
|
91
|
-
const matches = Array.from(code.matchAll(importRegex));
|
|
92
|
-
if (matches.length > 0) {
|
|
93
|
-
const lastImport = matches[matches.length - 1];
|
|
94
|
-
const lastImportEnd = lastImport.index + lastImport[0].length;
|
|
95
|
-
const newCode = code.slice(0, lastImportEnd) + "\n\n" + codeToInject + "\n\n" + code.slice(lastImportEnd);
|
|
96
|
-
return {
|
|
97
|
-
code: newCode,
|
|
98
|
-
map: null
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
code: `${codeToInject}
|
|
103
|
-
|
|
104
|
-
${code}`,
|
|
105
|
-
map: null
|
|
106
|
-
};
|
|
40
|
+
function spawn(command, args = [], options = {}) {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const childProcess = child_process.spawn(command, args, {
|
|
43
|
+
// stdio: 'inherit',
|
|
44
|
+
...options
|
|
45
|
+
});
|
|
46
|
+
childProcess.on("error", (error) => {
|
|
47
|
+
reject(error);
|
|
48
|
+
});
|
|
49
|
+
let stderr = "";
|
|
50
|
+
childProcess.stderr?.on("data", (message) => {
|
|
51
|
+
stderr += message;
|
|
52
|
+
});
|
|
53
|
+
childProcess.on("close", (code) => {
|
|
54
|
+
if (code === 0) {
|
|
55
|
+
resolve();
|
|
56
|
+
} else {
|
|
57
|
+
reject(new Error(stderr));
|
|
107
58
|
}
|
|
108
|
-
}
|
|
109
|
-
};
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function validate(file) {
|
|
63
|
+
return spawn("node", [
|
|
64
|
+
"--import",
|
|
65
|
+
undefined("@mastra/deployer/loader"),
|
|
66
|
+
"--input-type=module",
|
|
67
|
+
"-e",
|
|
68
|
+
`import('file://${file.replaceAll("\\", "/")}')`
|
|
69
|
+
]);
|
|
110
70
|
}
|
|
111
71
|
|
|
112
72
|
// src/build/analyze.ts
|
|
73
|
+
var globalExternals = ["pino", "pino-pretty", "@libsql/client"];
|
|
113
74
|
async function analyze(entry, mastraEntry, isVirtualFile, platform, logger) {
|
|
114
75
|
logger.info("Analyzing dependencies...");
|
|
115
76
|
let virtualPlugin = null;
|
|
@@ -119,10 +80,11 @@ async function analyze(entry, mastraEntry, isVirtualFile, platform, logger) {
|
|
|
119
80
|
});
|
|
120
81
|
entry = "#entry";
|
|
121
82
|
}
|
|
83
|
+
const normalizedMastraEntry = mastraEntry.replaceAll("\\", "/");
|
|
122
84
|
const optimizerBundler = await rollup.rollup({
|
|
123
85
|
logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
|
|
124
86
|
input: isVirtualFile ? "#entry" : entry,
|
|
125
|
-
treeshake:
|
|
87
|
+
treeshake: "smallest",
|
|
126
88
|
preserveSymlinks: true,
|
|
127
89
|
plugins: [
|
|
128
90
|
virtualPlugin,
|
|
@@ -133,7 +95,7 @@ async function analyze(entry, mastraEntry, isVirtualFile, platform, logger) {
|
|
|
133
95
|
return url.fileURLToPath(undefined("@mastra/deployer/server")).replaceAll("\\", "/");
|
|
134
96
|
}
|
|
135
97
|
if (id === "#mastra") {
|
|
136
|
-
return
|
|
98
|
+
return normalizedMastraEntry;
|
|
137
99
|
}
|
|
138
100
|
}
|
|
139
101
|
},
|
|
@@ -149,7 +111,7 @@ async function analyze(entry, mastraEntry, isVirtualFile, platform, logger) {
|
|
|
149
111
|
transformMixedEsModules: true,
|
|
150
112
|
extensions: [".js", ".ts"]
|
|
151
113
|
}),
|
|
152
|
-
|
|
114
|
+
chunkJSFQUYK4_cjs.removeDeployer(normalizedMastraEntry),
|
|
153
115
|
esbuild__default.default({
|
|
154
116
|
target: "node20",
|
|
155
117
|
platform,
|
|
@@ -210,7 +172,7 @@ async function bundleExternals(depsToOptimize, outputDir, logger) {
|
|
|
210
172
|
),
|
|
211
173
|
// this dependency breaks the build, so we need to exclude it
|
|
212
174
|
// TODO actually fix this so we don't need to exclude it
|
|
213
|
-
external: ["jsdom"],
|
|
175
|
+
external: ["jsdom", ...globalExternals],
|
|
214
176
|
treeshake: "smallest",
|
|
215
177
|
preserveSymlinks: true,
|
|
216
178
|
plugins: [
|
|
@@ -223,7 +185,6 @@ async function bundleExternals(depsToOptimize, outputDir, logger) {
|
|
|
223
185
|
{}
|
|
224
186
|
)
|
|
225
187
|
),
|
|
226
|
-
pino(),
|
|
227
188
|
commonjs__default.default({
|
|
228
189
|
strictRequires: "strict",
|
|
229
190
|
transformMixedEsModules: true,
|
|
@@ -254,6 +215,7 @@ async function validateOutput(output, reverseVirtualReferenceMap, outputDir, log
|
|
|
254
215
|
dependencies: /* @__PURE__ */ new Map(),
|
|
255
216
|
externalDependencies: /* @__PURE__ */ new Set()
|
|
256
217
|
};
|
|
218
|
+
globalExternals.forEach((dep) => result.externalDependencies.add(dep));
|
|
257
219
|
for (const file of output) {
|
|
258
220
|
if (file.type === "asset") {
|
|
259
221
|
continue;
|
|
@@ -263,7 +225,9 @@ async function validateOutput(output, reverseVirtualReferenceMap, outputDir, log
|
|
|
263
225
|
if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
|
|
264
226
|
result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
|
|
265
227
|
}
|
|
266
|
-
|
|
228
|
+
if (!file.isDynamicEntry && file.isEntry) {
|
|
229
|
+
await validate(path.join(outputDir, file.fileName));
|
|
230
|
+
}
|
|
267
231
|
} catch (err) {
|
|
268
232
|
result.invalidChunks.add(file.fileName);
|
|
269
233
|
if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkPRZC7CEM_cjs = require('./chunk-PRZC7CEM.cjs');
|
|
4
|
+
var chunkGLTC4BEQ_cjs = require('./chunk-GLTC4BEQ.cjs');
|
|
5
|
+
var chunk3H66SAKS_cjs = require('./chunk-3H66SAKS.cjs');
|
|
6
6
|
var fs = require('fs');
|
|
7
7
|
var promises = require('fs/promises');
|
|
8
8
|
var path = require('path');
|
|
9
9
|
var url = require('url');
|
|
10
10
|
var bundler = require('@mastra/core/bundler');
|
|
11
11
|
var virtual = require('@rollup/plugin-virtual');
|
|
12
|
-
var
|
|
13
|
-
var
|
|
12
|
+
var esm = require('fs-extra/esm');
|
|
13
|
+
var resolveFrom = require('resolve-from');
|
|
14
14
|
|
|
15
15
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
16
16
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
17
|
|
|
18
18
|
var virtual__default = /*#__PURE__*/_interopDefault(virtual);
|
|
19
|
-
var
|
|
19
|
+
var resolveFrom__default = /*#__PURE__*/_interopDefault(resolveFrom);
|
|
20
20
|
|
|
21
21
|
var Bundler = class extends bundler.MastraBundler {
|
|
22
22
|
analyzeOutputDir = ".build";
|
|
@@ -25,18 +25,18 @@ var Bundler = class extends bundler.MastraBundler {
|
|
|
25
25
|
super({ name, component });
|
|
26
26
|
}
|
|
27
27
|
async prepare(outputDirectory) {
|
|
28
|
-
await
|
|
29
|
-
await
|
|
30
|
-
await
|
|
28
|
+
await esm.emptyDir(outputDirectory);
|
|
29
|
+
await esm.ensureDir(path.join(outputDirectory, this.analyzeOutputDir));
|
|
30
|
+
await esm.ensureDir(path.join(outputDirectory, this.outputDir));
|
|
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-
|
|
35
|
-
await
|
|
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-HLGZCQQW.cjs', document.baseURI).href))));
|
|
35
|
+
await esm.copy(path.join(__dirname, "templates", "instrumentation-template.js"), instrumentationFile);
|
|
36
36
|
}
|
|
37
37
|
async writePackageJson(outputDirectory, dependencies) {
|
|
38
38
|
this.logger.debug(`Writing project's package.json`);
|
|
39
|
-
await
|
|
39
|
+
await esm.ensureDir(outputDirectory);
|
|
40
40
|
const pkgPath = path.join(outputDirectory, "package.json");
|
|
41
41
|
const dependenciesMap = /* @__PURE__ */ new Map();
|
|
42
42
|
for (const [key, value] of dependencies.entries()) {
|
|
@@ -70,35 +70,50 @@ var Bundler = class extends bundler.MastraBundler {
|
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
72
|
createBundler(inputOptions, outputOptions) {
|
|
73
|
-
return
|
|
73
|
+
return chunk3H66SAKS_cjs.createBundler(inputOptions, outputOptions);
|
|
74
74
|
}
|
|
75
75
|
async analyze(entry, mastraFile, outputDirectory) {
|
|
76
|
-
return await
|
|
76
|
+
return await chunkGLTC4BEQ_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 chunkPRZC7CEM_cjs.Deps(rootDir);
|
|
80
80
|
deps.__setLogger(this.logger);
|
|
81
81
|
await deps.install({ dir: path.join(outputDirectory, this.outputDir) });
|
|
82
82
|
}
|
|
83
|
+
async copyPublic(mastraDir, outputDirectory) {
|
|
84
|
+
const publicDir = path.join(mastraDir, "public");
|
|
85
|
+
try {
|
|
86
|
+
await promises.stat(publicDir);
|
|
87
|
+
} catch {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await esm.copy(publicDir, path.join(outputDirectory, this.outputDir));
|
|
91
|
+
}
|
|
83
92
|
async _bundle(serverFile, mastraEntryFile, outputDirectory, bundleLocation = path.join(outputDirectory, this.outputDir)) {
|
|
84
93
|
this.logger.info("Start bundling Mastra");
|
|
85
94
|
const isVirtual = serverFile.includes("\n") || fs.existsSync(serverFile);
|
|
86
|
-
const analyzedBundleInfo = await
|
|
95
|
+
const analyzedBundleInfo = await chunkGLTC4BEQ_cjs.analyzeBundle(
|
|
87
96
|
serverFile,
|
|
88
97
|
mastraEntryFile,
|
|
89
98
|
path.join(outputDirectory, this.analyzeOutputDir),
|
|
90
99
|
"node",
|
|
91
100
|
this.logger
|
|
92
101
|
);
|
|
93
|
-
await
|
|
94
|
-
const dependenciesToInstall =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
await chunkPRZC7CEM_cjs.writeTelemetryConfig(mastraEntryFile, path.join(outputDirectory, this.outputDir));
|
|
103
|
+
const dependenciesToInstall = /* @__PURE__ */ new Map();
|
|
104
|
+
for (const dep of analyzedBundleInfo.externalDependencies) {
|
|
105
|
+
try {
|
|
106
|
+
const pkgPath = resolveFrom__default.default(mastraEntryFile, `${dep}/package.json`);
|
|
107
|
+
const pkg = await esm.readJSON(pkgPath);
|
|
108
|
+
dependenciesToInstall.set(dep, pkg.version);
|
|
109
|
+
} catch {
|
|
110
|
+
dependenciesToInstall.set(dep, "latest");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
98
113
|
await this.writePackageJson(path.join(outputDirectory, this.outputDir), dependenciesToInstall);
|
|
99
114
|
await this.writeInstrumentationFile(path.join(outputDirectory, this.outputDir));
|
|
100
115
|
this.logger.info("Bundling Mastra application");
|
|
101
|
-
const inputOptions = await
|
|
116
|
+
const inputOptions = await chunk3H66SAKS_cjs.getInputOptions(mastraEntryFile, analyzedBundleInfo, "node");
|
|
102
117
|
if (isVirtual) {
|
|
103
118
|
inputOptions.input = { index: "#entry" };
|
|
104
119
|
if (Array.isArray(inputOptions.plugins)) {
|
|
@@ -112,6 +127,9 @@ var Bundler = class extends bundler.MastraBundler {
|
|
|
112
127
|
const bundler = await this.createBundler(inputOptions, { dir: bundleLocation });
|
|
113
128
|
await bundler.write();
|
|
114
129
|
this.logger.info("Bundling Mastra done");
|
|
130
|
+
this.logger.info("Copying public files");
|
|
131
|
+
await this.copyPublic(path.dirname(mastraEntryFile), outputDirectory);
|
|
132
|
+
this.logger.info("Done copying public files");
|
|
115
133
|
this.logger.info("Installing dependencies");
|
|
116
134
|
await this.installDependencies(outputDirectory);
|
|
117
135
|
this.logger.info("Done installing dependencies");
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Deps, writeTelemetryConfig } from './chunk-
|
|
2
|
-
import { analyzeBundle } from './chunk-
|
|
3
|
-
import { createBundler, getInputOptions } from './chunk-
|
|
1
|
+
import { Deps, writeTelemetryConfig } from './chunk-7XQJJPRM.js';
|
|
2
|
+
import { analyzeBundle } from './chunk-JNF4CXZJ.js';
|
|
3
|
+
import { createBundler, getInputOptions } from './chunk-XO6KJHXC.js';
|
|
4
4
|
import { existsSync } from 'node:fs';
|
|
5
|
-
import { writeFile } from 'node:fs/promises';
|
|
5
|
+
import { writeFile, stat } from 'node:fs/promises';
|
|
6
6
|
import { join, dirname } from 'node:path';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
import { MastraBundler } from '@mastra/core/bundler';
|
|
9
9
|
import virtual from '@rollup/plugin-virtual';
|
|
10
|
-
import { ensureDir, copy } from 'fs-extra';
|
|
11
|
-
import
|
|
10
|
+
import { emptyDir, ensureDir, copy, readJSON } from 'fs-extra/esm';
|
|
11
|
+
import resolveFrom from 'resolve-from';
|
|
12
12
|
|
|
13
13
|
var Bundler = class extends MastraBundler {
|
|
14
14
|
analyzeOutputDir = ".build";
|
|
@@ -17,7 +17,7 @@ var Bundler = class extends MastraBundler {
|
|
|
17
17
|
super({ name, component });
|
|
18
18
|
}
|
|
19
19
|
async prepare(outputDirectory) {
|
|
20
|
-
await
|
|
20
|
+
await emptyDir(outputDirectory);
|
|
21
21
|
await ensureDir(join(outputDirectory, this.analyzeOutputDir));
|
|
22
22
|
await ensureDir(join(outputDirectory, this.outputDir));
|
|
23
23
|
}
|
|
@@ -72,6 +72,15 @@ var Bundler = class extends MastraBundler {
|
|
|
72
72
|
deps.__setLogger(this.logger);
|
|
73
73
|
await deps.install({ dir: join(outputDirectory, this.outputDir) });
|
|
74
74
|
}
|
|
75
|
+
async copyPublic(mastraDir, outputDirectory) {
|
|
76
|
+
const publicDir = join(mastraDir, "public");
|
|
77
|
+
try {
|
|
78
|
+
await stat(publicDir);
|
|
79
|
+
} catch {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
await copy(publicDir, join(outputDirectory, this.outputDir));
|
|
83
|
+
}
|
|
75
84
|
async _bundle(serverFile, mastraEntryFile, outputDirectory, bundleLocation = join(outputDirectory, this.outputDir)) {
|
|
76
85
|
this.logger.info("Start bundling Mastra");
|
|
77
86
|
const isVirtual = serverFile.includes("\n") || existsSync(serverFile);
|
|
@@ -83,10 +92,16 @@ var Bundler = class extends MastraBundler {
|
|
|
83
92
|
this.logger
|
|
84
93
|
);
|
|
85
94
|
await writeTelemetryConfig(mastraEntryFile, join(outputDirectory, this.outputDir));
|
|
86
|
-
const dependenciesToInstall =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
95
|
+
const dependenciesToInstall = /* @__PURE__ */ new Map();
|
|
96
|
+
for (const dep of analyzedBundleInfo.externalDependencies) {
|
|
97
|
+
try {
|
|
98
|
+
const pkgPath = resolveFrom(mastraEntryFile, `${dep}/package.json`);
|
|
99
|
+
const pkg = await readJSON(pkgPath);
|
|
100
|
+
dependenciesToInstall.set(dep, pkg.version);
|
|
101
|
+
} catch {
|
|
102
|
+
dependenciesToInstall.set(dep, "latest");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
90
105
|
await this.writePackageJson(join(outputDirectory, this.outputDir), dependenciesToInstall);
|
|
91
106
|
await this.writeInstrumentationFile(join(outputDirectory, this.outputDir));
|
|
92
107
|
this.logger.info("Bundling Mastra application");
|
|
@@ -104,6 +119,9 @@ var Bundler = class extends MastraBundler {
|
|
|
104
119
|
const bundler = await this.createBundler(inputOptions, { dir: bundleLocation });
|
|
105
120
|
await bundler.write();
|
|
106
121
|
this.logger.info("Bundling Mastra done");
|
|
122
|
+
this.logger.info("Copying public files");
|
|
123
|
+
await this.copyPublic(dirname(mastraEntryFile), outputDirectory);
|
|
124
|
+
this.logger.info("Done copying public files");
|
|
107
125
|
this.logger.info("Installing dependencies");
|
|
108
126
|
await this.installDependencies(outputDirectory);
|
|
109
127
|
this.logger.info("Done installing dependencies");
|