@mastra/deployer-cloudflare 1.2.10 → 1.2.11
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 +16 -0
- package/dist/index.cjs +315 -288
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +291 -264
- package/dist/index.js.map +1 -1
- package/dist/secrets-manager/index.cjs +67 -87
- package/dist/secrets-manager/index.cjs.map +1 -1
- package/dist/secrets-manager/index.js +66 -85
- package/dist/secrets-manager/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,168 +1,188 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { join, relative } from
|
|
4
|
-
import { Deployer } from
|
|
5
|
-
import virtual from
|
|
6
|
-
import * as babel from
|
|
7
|
-
import { transformSync } from
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import { builtinModules } from "module";
|
|
2
|
+
import { writeFile } from "fs/promises";
|
|
3
|
+
import { join, relative } from "path";
|
|
4
|
+
import { Deployer } from "@mastra/deployer";
|
|
5
|
+
import virtual from "@rollup/plugin-virtual";
|
|
6
|
+
import * as babel from "@babel/core";
|
|
7
|
+
import { transformSync } from "@babel/core";
|
|
8
|
+
//#region src/babel/mastra-instance-wrapper.ts
|
|
9
|
+
/**
|
|
10
|
+
* Babel plugin that transforms Mastra exports for Cloudflare Workers compatibility.
|
|
11
|
+
*
|
|
12
|
+
* This plugin:
|
|
13
|
+
* 1. Identifies named exports of the 'mastra' variable
|
|
14
|
+
* 2. Checks if the export is a new instance of the 'Mastra' class
|
|
15
|
+
* 3. Wraps the Mastra instantiation in an arrow function to ensure proper initialization
|
|
16
|
+
* in the Cloudflare Workers environment
|
|
17
|
+
*
|
|
18
|
+
* The transformation ensures the Mastra instance is properly scoped and initialized
|
|
19
|
+
* for each request in the Cloudflare Workers environment.
|
|
20
|
+
*
|
|
21
|
+
* @returns {PluginObject} A Babel plugin object with a visitor that performs the transformation
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Before transformation:
|
|
25
|
+
* export const mastra = new Mastra();
|
|
26
|
+
*
|
|
27
|
+
* // After transformation:
|
|
28
|
+
* export const mastra = () => new Mastra();
|
|
29
|
+
*/
|
|
30
|
+
function mastraInstanceWrapper$1() {
|
|
31
|
+
const exportName = "mastra";
|
|
32
|
+
const className = "Mastra";
|
|
33
|
+
const t = babel.types;
|
|
34
|
+
return {
|
|
35
|
+
name: "wrap-mastra",
|
|
36
|
+
visitor: { ExportNamedDeclaration(path) {
|
|
37
|
+
if (t.isVariableDeclaration(path.node?.declaration)) {
|
|
38
|
+
for (const declaration of path.node.declaration.declarations) if (t.isIdentifier(declaration?.id, { name: exportName }) && t.isNewExpression(declaration?.init) && t.isIdentifier(declaration.init.callee, { name: className })) {
|
|
39
|
+
declaration.init = t.arrowFunctionExpression([], declaration.init);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} }
|
|
44
|
+
};
|
|
29
45
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
map: result?.map
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
};
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/plugins/mastra-instance-wrapper.ts
|
|
48
|
+
function mastraInstanceWrapper(mastraEntryFile) {
|
|
49
|
+
return {
|
|
50
|
+
name: "mastra-wrapper",
|
|
51
|
+
transform(code, id) {
|
|
52
|
+
if (id !== mastraEntryFile) return null;
|
|
53
|
+
const result = transformSync(code, {
|
|
54
|
+
filename: id,
|
|
55
|
+
babelrc: false,
|
|
56
|
+
configFile: false,
|
|
57
|
+
plugins: [mastraInstanceWrapper$1]
|
|
58
|
+
});
|
|
59
|
+
if (!result?.code) throw new Error("mastra-wrapper plugin did not return code, there is likely a bug in the plugin.");
|
|
60
|
+
return {
|
|
61
|
+
code: result.code,
|
|
62
|
+
map: result?.map
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
54
66
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/babel/postgres-store-instance-checker.ts
|
|
69
|
+
/**
|
|
70
|
+
* Babel plugin that enforces singleton PostgresStore instances in Cloudflare Workers.
|
|
71
|
+
*
|
|
72
|
+
* This plugin:
|
|
73
|
+
* 1. Scans for all `new PostgresStore()` instantiations
|
|
74
|
+
* 2. Records their file locations
|
|
75
|
+
* 3. Throws an error if multiple instances are found
|
|
76
|
+
*
|
|
77
|
+
* Cloudflare Workers should only create one PostgresStore instance to avoid connection
|
|
78
|
+
* pool exhaustion and ensure proper resource management.
|
|
79
|
+
*
|
|
80
|
+
* @returns {PluginObject} A Babel plugin object that validates PostgresStore usage
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* // Throws error if multiple instances found:
|
|
84
|
+
* const store1 = new PostgresStore();
|
|
85
|
+
* const store2 = new PostgresStore(); // Error thrown here
|
|
86
|
+
*/
|
|
87
|
+
function postgresStoreInstanceChecker$1() {
|
|
88
|
+
const t = babel.types;
|
|
89
|
+
const instances = [];
|
|
90
|
+
return {
|
|
91
|
+
name: "postgresstore-instance-checker",
|
|
92
|
+
visitor: { NewExpression(path, state) {
|
|
93
|
+
if (t.isIdentifier(path.node.callee) && path.node.callee.name === "PostgresStore") {
|
|
94
|
+
const filename = state.file?.opts?.filename || "unknown file";
|
|
95
|
+
const location = path.node.loc ? `${filename}: line ${path.node.loc.start.line}, column ${path.node.loc.start.column}` : "unknown location";
|
|
96
|
+
instances.push({
|
|
97
|
+
path,
|
|
98
|
+
location
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
} },
|
|
102
|
+
post() {
|
|
103
|
+
if (instances.length > 1) {
|
|
104
|
+
const errorMessage = [
|
|
105
|
+
`Found ${instances.length} PostgresStore instantiations:`,
|
|
106
|
+
...instances.map((instance, i) => ` ${i + 1}. At ${instance.location}`),
|
|
107
|
+
"Only one PostgresStore instance should be created per Cloudflare Worker."
|
|
108
|
+
].join("\n");
|
|
109
|
+
throw instances[instances.length - 1]?.path.buildCodeFrameError(errorMessage);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
84
113
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
};
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/plugins/postgres-store-instance-checker.ts
|
|
116
|
+
function postgresStoreInstanceChecker() {
|
|
117
|
+
return {
|
|
118
|
+
name: "postgres-store-instance-checker",
|
|
119
|
+
transform(code, id) {
|
|
120
|
+
const result = transformSync(code, {
|
|
121
|
+
filename: id,
|
|
122
|
+
babelrc: false,
|
|
123
|
+
configFile: false,
|
|
124
|
+
plugins: [postgresStoreInstanceChecker$1]
|
|
125
|
+
});
|
|
126
|
+
if (!result || typeof result.code !== "string") return null;
|
|
127
|
+
return {
|
|
128
|
+
code: result.code,
|
|
129
|
+
map: result.map ? result.map : null
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
};
|
|
106
133
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/index.ts
|
|
136
|
+
const nodeBuiltins = new Set(builtinModules);
|
|
137
|
+
/**
|
|
138
|
+
* Rollup plugin that marks bare Node.js builtin imports (e.g. `process`, `path`)
|
|
139
|
+
* as external. Cloudflare Workers with `nodejs_compat` provides these at runtime,
|
|
140
|
+
* so they must not be resolved to npm polyfill packages during bundling.
|
|
141
|
+
*/
|
|
110
142
|
function nodeBuiltinsExternal() {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
143
|
+
return {
|
|
144
|
+
name: "node-builtins-external",
|
|
145
|
+
resolveId(id) {
|
|
146
|
+
if (nodeBuiltins.has(id)) return {
|
|
147
|
+
id,
|
|
148
|
+
external: true
|
|
149
|
+
};
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
120
153
|
}
|
|
121
154
|
var CloudflareDeployer = class extends Deployer {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
projectName: _projectName,
|
|
149
|
-
workerNamespace: _workerNamespace,
|
|
150
|
-
d1Databases: _d1Databases,
|
|
151
|
-
kvNamespaces: _kvNamespaces,
|
|
152
|
-
...userConfig
|
|
153
|
-
} = this.userConfig;
|
|
154
|
-
const loadedEnvVars = await this.loadEnvVars();
|
|
155
|
-
const envsAsObject = Object.assign({}, userVars);
|
|
156
|
-
if (loadedEnvVars.size > 0) {
|
|
157
|
-
const envKeys = [...loadedEnvVars.keys()].join(", ");
|
|
158
|
-
this.logger.warn(
|
|
159
|
-
`Environment variables from .env (${envKeys}) were not written to wrangler.jsonc.
|
|
155
|
+
userConfig;
|
|
156
|
+
constructor(userConfig) {
|
|
157
|
+
super({ name: "CLOUDFLARE" });
|
|
158
|
+
this.platform = "browser";
|
|
159
|
+
this.userConfig = { ...userConfig };
|
|
160
|
+
if (userConfig.workerNamespace) console.warn("[CloudflareDeployer]: `workerNamespace` is no longer used");
|
|
161
|
+
if (!userConfig.name && userConfig.projectName) {
|
|
162
|
+
this.userConfig.name = userConfig.projectName;
|
|
163
|
+
console.warn("[CloudflareDeployer]: `projectName` is deprecated, use `name` instead");
|
|
164
|
+
}
|
|
165
|
+
if (!userConfig.d1_databases && userConfig.d1Databases) {
|
|
166
|
+
this.userConfig.d1_databases = userConfig.d1Databases;
|
|
167
|
+
console.warn("[CloudflareDeployer]: `d1Databases` is deprecated, use `d1_databases` instead");
|
|
168
|
+
}
|
|
169
|
+
if (!userConfig.kv_namespaces && userConfig.kvNamespaces) {
|
|
170
|
+
this.userConfig.kv_namespaces = userConfig.kvNamespaces;
|
|
171
|
+
console.warn("[CloudflareDeployer]: `kvNamespaces` is deprecated, use `kv_namespaces` instead");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async writeFiles(outputDirectory) {
|
|
175
|
+
const { vars: userVars, alias: userAlias, projectName: _projectName, workerNamespace: _workerNamespace, d1Databases: _d1Databases, kvNamespaces: _kvNamespaces, ...userConfig } = this.userConfig;
|
|
176
|
+
const loadedEnvVars = await this.loadEnvVars();
|
|
177
|
+
const envsAsObject = Object.assign({}, userVars);
|
|
178
|
+
if (loadedEnvVars.size > 0) {
|
|
179
|
+
const envKeys = [...loadedEnvVars.keys()].join(", ");
|
|
180
|
+
this.logger.warn(`Environment variables from .env (${envKeys}) were not written to wrangler.jsonc.
|
|
160
181
|
Upload them as Cloudflare Secrets instead:
|
|
161
|
-
npx wrangler secret bulk .env`
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const typescriptStub = `// Stub for TypeScript - not available at runtime in Cloudflare Workers
|
|
182
|
+
npx wrangler secret bulk .env`);
|
|
183
|
+
}
|
|
184
|
+
const typescriptStubPath = "typescript-stub.mjs";
|
|
185
|
+
await writeFile(join(outputDirectory, this.outputDir, typescriptStubPath), `// Stub for TypeScript - not available at runtime in Cloudflare Workers
|
|
166
186
|
// The @mastra/agent-builder package will fall back to basic validation
|
|
167
187
|
export default {};
|
|
168
188
|
export const createSourceFile = () => null;
|
|
@@ -179,68 +199,72 @@ export const sys = {
|
|
|
179
199
|
fileExists: () => false,
|
|
180
200
|
readFile: () => undefined,
|
|
181
201
|
};
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const execaStub = `// Stub for execa - not available at runtime in Cloudflare Workers
|
|
202
|
+
`);
|
|
203
|
+
const execaStubPath = "execa-stub.mjs";
|
|
204
|
+
await writeFile(join(outputDirectory, this.outputDir, execaStubPath), `// Stub for execa - not available at runtime in Cloudflare Workers
|
|
186
205
|
export const execa = () => { throw new Error('execa is not available in Cloudflare Workers'); };
|
|
187
206
|
export const execaNode = execa;
|
|
188
207
|
export const execaSync = execa;
|
|
189
208
|
export const execaCommand = execa;
|
|
190
209
|
export const execaCommandSync = execa;
|
|
191
210
|
export const $ = execa;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const readableStreamStub = `// Redirect readable-stream to native node:stream (available via nodejs_compat)
|
|
211
|
+
`);
|
|
212
|
+
const readableStreamStubPath = "readable-stream-stub.mjs";
|
|
213
|
+
await writeFile(join(outputDirectory, this.outputDir, readableStreamStubPath), `// Redirect readable-stream to native node:stream (available via nodejs_compat)
|
|
196
214
|
import stream from 'node:stream';
|
|
197
215
|
export const { Readable, Writable, Duplex, Transform, PassThrough, Stream, pipeline, finished } = stream;
|
|
198
216
|
export default stream;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
217
|
+
`);
|
|
218
|
+
const moduleStubPath = "module-stub.mjs";
|
|
219
|
+
await writeFile(join(outputDirectory, this.outputDir, moduleStubPath), `// Stub for module.createRequire in Cloudflare Workers
|
|
220
|
+
export function createRequire() {
|
|
221
|
+
const req = specifier => {
|
|
222
|
+
throw new Error(\`require(\${specifier}) is not available in Cloudflare Workers\`);
|
|
223
|
+
};
|
|
224
|
+
req.resolve = specifier => specifier;
|
|
225
|
+
return req;
|
|
226
|
+
}
|
|
227
|
+
export default { createRequire };
|
|
228
|
+
`);
|
|
229
|
+
const wranglerConfig = {
|
|
230
|
+
name: "mastra",
|
|
231
|
+
compatibility_date: "2025-04-01",
|
|
232
|
+
compatibility_flags: ["nodejs_compat", "nodejs_compat_populate_process_env"],
|
|
233
|
+
observability: { logs: { enabled: true } },
|
|
234
|
+
...userConfig,
|
|
235
|
+
main: "./index.mjs",
|
|
236
|
+
vars: envsAsObject,
|
|
237
|
+
alias: {
|
|
238
|
+
typescript: `./${typescriptStubPath}`,
|
|
239
|
+
execa: `./${execaStubPath}`,
|
|
240
|
+
"readable-stream": `./${readableStreamStubPath}`,
|
|
241
|
+
module: `./${moduleStubPath}`,
|
|
242
|
+
"node:module": `./${moduleStubPath}`,
|
|
243
|
+
...userAlias
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
await writeFile(join(outputDirectory, this.outputDir, "wrangler.json"), JSON.stringify(wranglerConfig, null, 2));
|
|
247
|
+
const projectRoot = join(outputDirectory, "../");
|
|
248
|
+
const jsoncFilePath = join(projectRoot, "wrangler.jsonc");
|
|
249
|
+
const mainFilePath = join(outputDirectory, this.outputDir, "index.mjs");
|
|
250
|
+
const tsStubFilePath = join(outputDirectory, this.outputDir, typescriptStubPath);
|
|
251
|
+
const moduleStubFilePath = join(outputDirectory, this.outputDir, moduleStubPath);
|
|
252
|
+
const wranglerJsoncConfig = {
|
|
253
|
+
placeholder: "PLACEHOLDER",
|
|
254
|
+
$schema: "./node_modules/wrangler/config-schema.json",
|
|
255
|
+
...wranglerConfig,
|
|
256
|
+
main: `./${relative(projectRoot, mainFilePath)}`,
|
|
257
|
+
alias: {
|
|
258
|
+
...wranglerConfig.alias,
|
|
259
|
+
typescript: `./${relative(projectRoot, tsStubFilePath)}`,
|
|
260
|
+
module: `./${relative(projectRoot, moduleStubFilePath)}`,
|
|
261
|
+
"node:module": `./${relative(projectRoot, moduleStubFilePath)}`
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
await writeFile(jsoncFilePath, JSON.stringify(wranglerJsoncConfig, null, 2).replace(/"placeholder": "PLACEHOLDER",/, "/* This file was auto-generated through Mastra. Edit the CloudflareDeployer() instance directly. */"));
|
|
265
|
+
}
|
|
266
|
+
getEntry() {
|
|
267
|
+
return `
|
|
244
268
|
import '#polyfills';
|
|
245
269
|
import { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';
|
|
246
270
|
|
|
@@ -255,66 +279,69 @@ export default stream;
|
|
|
255
279
|
_mastra.__registerInternalWorkflow(scoreTracesWorkflow);
|
|
256
280
|
}
|
|
257
281
|
|
|
258
|
-
const app = await createHonoServer(_mastra, { tools: getToolExports(tools) });
|
|
282
|
+
const app = await createHonoServer(_mastra, { tools: getToolExports(tools), browserStream: false });
|
|
259
283
|
return app.fetch(request, env, context);
|
|
260
284
|
}
|
|
261
285
|
}
|
|
262
286
|
`;
|
|
287
|
+
}
|
|
288
|
+
async prepare(outputDirectory) {
|
|
289
|
+
await super.prepare(outputDirectory);
|
|
290
|
+
await this.writeFiles(outputDirectory);
|
|
291
|
+
}
|
|
292
|
+
async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, bundlerOptions) {
|
|
293
|
+
const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {
|
|
294
|
+
...bundlerOptions,
|
|
295
|
+
enableEsmShim: false
|
|
296
|
+
});
|
|
297
|
+
const hasPostgresStore = await this.deps.checkDependencies(["@mastra/pg"]) === `ok`;
|
|
298
|
+
if (Array.isArray(inputOptions.plugins)) {
|
|
299
|
+
inputOptions.plugins = [
|
|
300
|
+
nodeBuiltinsExternal(),
|
|
301
|
+
virtual({ "#polyfills": `
|
|
302
|
+
try {
|
|
303
|
+
if (!process.versions) {
|
|
304
|
+
Object.defineProperty(process, 'versions', { value: {}, configurable: true });
|
|
263
305
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
await this.writeFiles(outputDirectory);
|
|
267
|
-
}
|
|
268
|
-
async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, bundlerOptions) {
|
|
269
|
-
const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {
|
|
270
|
-
...bundlerOptions,
|
|
271
|
-
enableEsmShim: false
|
|
272
|
-
});
|
|
273
|
-
const hasPostgresStore = await this.deps.checkDependencies(["@mastra/pg"]) === `ok`;
|
|
274
|
-
if (Array.isArray(inputOptions.plugins)) {
|
|
275
|
-
inputOptions.plugins = [
|
|
276
|
-
nodeBuiltinsExternal(),
|
|
277
|
-
virtual({
|
|
278
|
-
"#polyfills": `
|
|
279
|
-
process.versions = process.versions || {};
|
|
280
|
-
process.versions.node = '${process.versions.node}';
|
|
281
|
-
`
|
|
282
|
-
}),
|
|
283
|
-
...inputOptions.plugins,
|
|
284
|
-
mastraInstanceWrapper2(mastraEntryFile)
|
|
285
|
-
];
|
|
286
|
-
if (hasPostgresStore) {
|
|
287
|
-
inputOptions.plugins.push(postgresStoreInstanceChecker2());
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return inputOptions;
|
|
291
|
-
}
|
|
292
|
-
async bundle(entryFile, outputDirectory, { toolsPaths, projectRoot }) {
|
|
293
|
-
return this._bundle(this.getEntry(), entryFile, { outputDirectory, projectRoot, enableEsmShim: false }, toolsPaths);
|
|
294
|
-
}
|
|
295
|
-
async deploy() {
|
|
296
|
-
this.logger?.info("Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.");
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* TODO: Remove this method in the next major version
|
|
300
|
-
*
|
|
301
|
-
* @deprecated
|
|
302
|
-
*/
|
|
303
|
-
async tagWorker() {
|
|
304
|
-
throw new Error("tagWorker method is no longer supported. Use the Cloudflare dashboard or API directly.");
|
|
305
|
-
}
|
|
306
|
-
async lint(entryFile, outputDirectory, toolsPaths) {
|
|
307
|
-
await super.lint(entryFile, outputDirectory, toolsPaths);
|
|
308
|
-
const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
|
|
309
|
-
if (hasLibsql) {
|
|
310
|
-
this.logger.error(
|
|
311
|
-
"Cloudflare Deployer does not support @libsql/client (which may have been installed by @mastra/libsql) as a dependency. Please use Cloudflare D1 instead: @mastra/cloudflare-d1."
|
|
312
|
-
);
|
|
313
|
-
process.exit(1);
|
|
314
|
-
}
|
|
306
|
+
if (!process.versions.node) {
|
|
307
|
+
Object.defineProperty(process.versions, 'node', { value: '${process.versions.node}', configurable: true });
|
|
315
308
|
}
|
|
309
|
+
} catch {}
|
|
310
|
+
` }),
|
|
311
|
+
...inputOptions.plugins,
|
|
312
|
+
mastraInstanceWrapper(mastraEntryFile)
|
|
313
|
+
];
|
|
314
|
+
if (hasPostgresStore) inputOptions.plugins.push(postgresStoreInstanceChecker());
|
|
315
|
+
}
|
|
316
|
+
return inputOptions;
|
|
317
|
+
}
|
|
318
|
+
async bundle(entryFile, outputDirectory, { toolsPaths, projectRoot }) {
|
|
319
|
+
return this._bundle(this.getEntry(), entryFile, {
|
|
320
|
+
outputDirectory,
|
|
321
|
+
projectRoot,
|
|
322
|
+
enableEsmShim: false
|
|
323
|
+
}, toolsPaths);
|
|
324
|
+
}
|
|
325
|
+
async deploy() {
|
|
326
|
+
this.logger?.info("Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.");
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* TODO: Remove this method in the next major version
|
|
330
|
+
*
|
|
331
|
+
* @deprecated
|
|
332
|
+
*/
|
|
333
|
+
async tagWorker() {
|
|
334
|
+
throw new Error("tagWorker method is no longer supported. Use the Cloudflare dashboard or API directly.");
|
|
335
|
+
}
|
|
336
|
+
async lint(entryFile, outputDirectory, toolsPaths) {
|
|
337
|
+
await super.lint(entryFile, outputDirectory, toolsPaths);
|
|
338
|
+
if (await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`) {
|
|
339
|
+
this.logger.error("Cloudflare Deployer does not support @libsql/client (which may have been installed by @mastra/libsql) as a dependency. Please use Cloudflare D1 instead: @mastra/cloudflare-d1.");
|
|
340
|
+
process.exit(1);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
316
343
|
};
|
|
317
|
-
|
|
344
|
+
//#endregion
|
|
318
345
|
export { CloudflareDeployer };
|
|
319
|
-
|
|
346
|
+
|
|
320
347
|
//# sourceMappingURL=index.js.map
|