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