@mastra/deployer-cloudflare 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807182016

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,194 +1,296 @@
1
- 'use strict';
2
-
3
- var promises = require('fs/promises');
4
- var path = require('path');
5
- var deployer = require('@mastra/deployer');
6
- var virtual = require('@rollup/plugin-virtual');
7
- var babel = require('@babel/core');
8
-
9
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
-
11
- function _interopNamespace(e) {
12
- if (e && e.__esModule) return e;
13
- var n = Object.create(null);
14
- if (e) {
15
- Object.keys(e).forEach(function (k) {
16
- if (k !== 'default') {
17
- var d = Object.getOwnPropertyDescriptor(e, k);
18
- Object.defineProperty(n, k, d.get ? d : {
19
- enumerable: true,
20
- get: function () { return e[k]; }
21
- });
22
- }
23
- });
24
- }
25
- n.default = e;
26
- 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
+ };
27
69
  }
28
-
29
- var virtual__default = /*#__PURE__*/_interopDefault(virtual);
30
- var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
31
-
32
- // src/index.ts
33
- function mastraInstanceWrapper() {
34
- const exportName = "mastra";
35
- const className = "Mastra";
36
- const t = babel__namespace.types;
37
- return {
38
- name: "wrap-mastra",
39
- visitor: {
40
- ExportNamedDeclaration(path) {
41
- if (t.isVariableDeclaration(path.node?.declaration)) {
42
- for (const declaration of path.node.declaration.declarations) {
43
- if (t.isIdentifier(declaration?.id, { name: exportName }) && t.isNewExpression(declaration?.init) && t.isIdentifier(declaration.init.callee, { name: className })) {
44
- declaration.init = t.arrowFunctionExpression([], declaration.init);
45
- break;
46
- }
47
- }
48
- }
49
- }
50
- }
51
- };
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
+ };
52
90
  }
53
-
54
- // src/plugins/mastra-instance-wrapper.ts
55
- function mastraInstanceWrapper2(mastraEntryFile) {
56
- return {
57
- name: "mastra-wrapper",
58
- transform(code, id) {
59
- if (id !== mastraEntryFile) {
60
- return null;
61
- }
62
- const result = babel.transformSync(code, {
63
- filename: id,
64
- babelrc: false,
65
- configFile: false,
66
- plugins: [mastraInstanceWrapper]
67
- });
68
- if (!result?.code) {
69
- throw new Error("mastra-wrapper plugin did not return code, there is likely a bug in the plugin.");
70
- }
71
- return {
72
- code: result.code,
73
- map: result?.map
74
- };
75
- }
76
- };
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
+ };
77
137
  }
138
+ //#endregion
139
+ //#region src/plugins/postgres-store-instance-checker.ts
78
140
  function postgresStoreInstanceChecker() {
79
- const t = babel__namespace.types;
80
- const instances = [];
81
- return {
82
- name: "postgresstore-instance-checker",
83
- visitor: {
84
- NewExpression(path, state) {
85
- if (t.isIdentifier(path.node.callee) && path.node.callee.name === "PostgresStore") {
86
- const filename = state.file?.opts?.filename || "unknown file";
87
- const location = path.node.loc ? `${filename}: line ${path.node.loc.start.line}, column ${path.node.loc.start.column}` : "unknown location";
88
- instances.push({
89
- path,
90
- location
91
- });
92
- }
93
- }
94
- },
95
- post() {
96
- if (instances.length > 1) {
97
- const errorMessage = [
98
- `Found ${instances.length} PostgresStore instantiations:`,
99
- ...instances.map((instance, i) => ` ${i + 1}. At ${instance.location}`),
100
- "Only one PostgresStore instance should be created per Cloudflare Worker."
101
- ].join("\n");
102
- const lastInstance = instances[instances.length - 1];
103
- throw lastInstance?.path.buildCodeFrameError(errorMessage);
104
- }
105
- }
106
- };
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
+ };
107
157
  }
108
-
109
- // src/plugins/postgres-store-instance-checker.ts
110
- function postgresStoreInstanceChecker2() {
111
- return {
112
- name: "postgres-store-instance-checker",
113
- transform(code, id) {
114
- const result = babel.transformSync(code, {
115
- filename: id,
116
- babelrc: false,
117
- configFile: false,
118
- plugins: [postgresStoreInstanceChecker]
119
- });
120
- if (!result || typeof result.code !== "string") {
121
- return null;
122
- }
123
- return {
124
- code: result.code,
125
- map: result.map ?? null
126
- };
127
- }
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
+ */
166
+ function nodeBuiltinsExternal() {
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
+ };
177
+ }
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.
205
+ Upload them as Cloudflare Secrets instead:
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
210
+ // The @mastra/agent-builder package will fall back to basic validation
211
+ export default {};
212
+ export const createSourceFile = () => null;
213
+ export const createProgram = () => null;
214
+ export const findConfigFile = () => null;
215
+ export const readConfigFile = () => ({ error: new Error('TypeScript not available') });
216
+ export const parseJsonConfigFileContent = () => ({ errors: [new Error('TypeScript not available')], fileNames: [], options: {} });
217
+ export const flattenDiagnosticMessageText = (message) => typeof message === 'string' ? message : message?.messageText || '';
218
+ export const ScriptTarget = { Latest: 99 };
219
+ export const ModuleKind = { ESNext: 99 };
220
+ export const JsxEmit = { ReactJSX: 4 };
221
+ export const DiagnosticCategory = { Warning: 0, Error: 1, Suggestion: 2, Message: 3 };
222
+ export const sys = {
223
+ fileExists: () => false,
224
+ readFile: () => undefined,
225
+ };
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
229
+ export const execa = () => { throw new Error('execa is not available in Cloudflare Workers'); };
230
+ export const execaNode = execa;
231
+ export const execaSync = execa;
232
+ export const execaCommand = execa;
233
+ export const execaCommandSync = execa;
234
+ export const $ = execa;
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)
238
+ import stream from 'node:stream';
239
+ export const { Readable, Writable, Duplex, Transform, PassThrough, Stream, pipeline, finished } = stream;
240
+ export default stream;
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\`);
128
247
  };
248
+ req.resolve = specifier => specifier;
249
+ return req;
129
250
  }
130
-
131
- // src/index.ts
132
- var CloudflareDeployer = class extends deployer.Deployer {
133
- routes = [];
134
- workerNamespace;
135
- env;
136
- projectName;
137
- d1Databases;
138
- kvNamespaces;
139
- constructor({
140
- env,
141
- projectName = "mastra",
142
- routes,
143
- workerNamespace,
144
- d1Databases,
145
- kvNamespaces
146
- }) {
147
- super({ name: "CLOUDFLARE" });
148
- this.projectName = projectName;
149
- this.routes = routes;
150
- this.workerNamespace = workerNamespace;
151
- if (env) {
152
- this.env = env;
153
- }
154
- if (d1Databases) this.d1Databases = d1Databases;
155
- if (kvNamespaces) this.kvNamespaces = kvNamespaces;
156
- }
157
- async writeFiles(outputDirectory) {
158
- const env = await this.loadEnvVars();
159
- const envsAsObject = Object.assign({}, Object.fromEntries(env.entries()), this.env);
160
- const cfWorkerName = this.projectName;
161
- const wranglerConfig = {
162
- name: cfWorkerName,
163
- main: "./index.mjs",
164
- compatibility_date: "2025-04-01",
165
- compatibility_flags: ["nodejs_compat", "nodejs_compat_populate_process_env"],
166
- observability: {
167
- logs: {
168
- enabled: true
169
- }
170
- },
171
- vars: envsAsObject
172
- };
173
- if (!this.workerNamespace && this.routes) {
174
- wranglerConfig.routes = this.routes;
175
- }
176
- if (this.d1Databases?.length) {
177
- wranglerConfig.d1_databases = this.d1Databases;
178
- }
179
- if (this.kvNamespaces?.length) {
180
- wranglerConfig.kv_namespaces = this.kvNamespaces;
181
- }
182
- await promises.writeFile(path.join(outputDirectory, this.outputDir, "wrangler.json"), JSON.stringify(wranglerConfig));
183
- }
184
- getEntry() {
185
- return `
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 `
186
292
  import '#polyfills';
187
- import { evaluate } from '@mastra/core/eval';
188
- import { AvailableHooks, registerHook } from '@mastra/core/hooks';
189
- import { TABLE_EVALS } from '@mastra/core/storage';
190
- import { scoreTracesWorkflow } from '@mastra/core/scores/scoreTraces';
191
- import { checkEvalStorageFields } from '@mastra/core/utils';
293
+ import { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';
192
294
 
193
295
  export default {
194
296
  fetch: async (request, env, context) => {
@@ -201,98 +303,69 @@ var CloudflareDeployer = class extends deployer.Deployer {
201
303
  _mastra.__registerInternalWorkflow(scoreTracesWorkflow);
202
304
  }
203
305
 
204
- registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
205
- evaluate({
206
- agentName,
207
- input,
208
- metric,
209
- output,
210
- runId,
211
- globalRunId: runId,
212
- instructions,
213
- });
214
- });
215
-
216
- registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
217
- const storage = _mastra.getStorage();
218
- if (storage) {
219
- // Check for required fields
220
- const logger = _mastra?.getLogger();
221
- const areFieldsValid = checkEvalStorageFields(traceObject, logger);
222
- if (!areFieldsValid) return;
223
-
224
- await storage.insert({
225
- tableName: TABLE_EVALS,
226
- record: {
227
- input: traceObject.input,
228
- output: traceObject.output,
229
- result: JSON.stringify(traceObject.result || {}),
230
- agent_name: traceObject.agentName,
231
- metric_name: traceObject.metricName,
232
- instructions: traceObject.instructions,
233
- test_info: null,
234
- global_run_id: traceObject.globalRunId,
235
- run_id: traceObject.runId,
236
- created_at: new Date().toISOString(),
237
- },
238
- });
239
- }
240
- });
241
-
242
- const app = await createHonoServer(_mastra, { tools: getToolExports(tools) });
306
+ const app = await createHonoServer(_mastra, { tools: getToolExports(tools), browserStream: false });
243
307
  return app.fetch(request, env, context);
244
308
  }
245
309
  }
246
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 });
247
329
  }
248
- async prepare(outputDirectory) {
249
- await super.prepare(outputDirectory);
250
- await this.writeFiles(outputDirectory);
251
- }
252
- async getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, { enableSourcemap = false } = {}) {
253
- const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {
254
- enableSourcemap,
255
- enableEsmShim: false
256
- });
257
- const hasPostgresStore = await this.deps.checkDependencies(["@mastra/pg"]) === `ok`;
258
- if (Array.isArray(inputOptions.plugins)) {
259
- inputOptions.plugins = [
260
- virtual__default.default({
261
- "#polyfills": `
262
- process.versions = process.versions || {};
263
- process.versions.node = '${process.versions.node}';
264
- `
265
- }),
266
- ...inputOptions.plugins,
267
- mastraInstanceWrapper2(mastraEntryFile)
268
- ];
269
- if (hasPostgresStore) {
270
- inputOptions.plugins.push(postgresStoreInstanceChecker2());
271
- }
272
- }
273
- return inputOptions;
274
- }
275
- async bundle(entryFile, outputDirectory, { toolsPaths, projectRoot }) {
276
- return this._bundle(this.getEntry(), entryFile, { outputDirectory, projectRoot, enableEsmShim: false }, toolsPaths);
277
- }
278
- async deploy() {
279
- this.logger?.info("Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.");
280
- }
281
- async tagWorker() {
282
- throw new Error("tagWorker method is no longer supported. Use the Cloudflare dashboard or API directly.");
283
- }
284
- async lint(entryFile, outputDirectory, toolsPaths) {
285
- await super.lint(entryFile, outputDirectory, toolsPaths);
286
- const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
287
- if (hasLibsql) {
288
- this.logger.error(
289
- "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."
290
- );
291
- process.exit(1);
292
- }
330
+ if (!process.versions.node) {
331
+ Object.defineProperty(process.versions, 'node', { value: '${process.versions.node}', configurable: true });
293
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
+ }
294
367
  };
295
-
368
+ //#endregion
296
369
  exports.CloudflareDeployer = CloudflareDeployer;
297
- //# sourceMappingURL=index.cjs.map
370
+
298
371
  //# sourceMappingURL=index.cjs.map