@mastra/deployer-cloudflare 1.1.15-alpha.3 → 1.1.15
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 +23 -0
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @mastra/deployer-cloudflare
|
|
2
2
|
|
|
3
|
+
## 1.1.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- dependencies updates: ([#10188](https://github.com/mastra-ai/mastra/pull/10188))
|
|
8
|
+
- Updated dependency [`cloudflare@^5.2.0` ↗︎](https://www.npmjs.com/package/cloudflare/v/5.2.0) (from `^4.5.0`, in `dependencies`)
|
|
9
|
+
|
|
10
|
+
- Fixed Cloudflare Workers deploys that failed with `Could not resolve "readable-stream"`. Workers builds now resolve stream imports correctly without requiring extra stream polyfill packages. ([#14488](https://github.com/mastra-ai/mastra/pull/14488))
|
|
11
|
+
|
|
12
|
+
- Updated dependencies [[`dc514a8`](https://github.com/mastra-ai/mastra/commit/dc514a83dba5f719172dddfd2c7b858e4943d067), [`e333b77`](https://github.com/mastra-ai/mastra/commit/e333b77e2d76ba57ccec1818e08cebc1993469ff), [`dc9fc19`](https://github.com/mastra-ai/mastra/commit/dc9fc19da4437f6b508cc355f346a8856746a76b), [`60a224d`](https://github.com/mastra-ai/mastra/commit/60a224dd497240e83698cfa5bfd02e3d1d854844), [`fbf22a7`](https://github.com/mastra-ai/mastra/commit/fbf22a7ad86bcb50dcf30459f0d075e51ddeb468), [`4e7f4e6`](https://github.com/mastra-ai/mastra/commit/4e7f4e6fe6239e0aa5f15416fb1e8ad8e9c52bcf), [`f16d92c`](https://github.com/mastra-ai/mastra/commit/f16d92c677a119a135cebcf7e2b9f51ada7a9df4), [`949b7bf`](https://github.com/mastra-ai/mastra/commit/949b7bfd4e40f2b2cba7fef5eb3f108a02cfe938), [`404fea1`](https://github.com/mastra-ai/mastra/commit/404fea13042181f0b0c73a101392ac87c79ceae2), [`ebf5047`](https://github.com/mastra-ai/mastra/commit/ebf5047e825c38a1a356f10b214c1d4260dfcd8d), [`12c647c`](https://github.com/mastra-ai/mastra/commit/12c647cf3a26826eb72d40b42e3c8356ceae16ed), [`d084b66`](https://github.com/mastra-ai/mastra/commit/d084b6692396057e83c086b954c1857d20b58a14), [`79c699a`](https://github.com/mastra-ai/mastra/commit/79c699acf3cd8a77e11c55530431f48eb48456e9), [`62757b6`](https://github.com/mastra-ai/mastra/commit/62757b6db6e8bb86569d23ad0b514178f57053f8), [`675f15b`](https://github.com/mastra-ai/mastra/commit/675f15b7eaeea649158d228ea635be40480c584d), [`b174c63`](https://github.com/mastra-ai/mastra/commit/b174c63a093108d4e53b9bc89a078d9f66202b3f), [`819f03c`](https://github.com/mastra-ai/mastra/commit/819f03c25823373b32476413bd76be28a5d8705a), [`04160ee`](https://github.com/mastra-ai/mastra/commit/04160eedf3130003cf842ad08428c8ff69af4cc1), [`a917d2b`](https://github.com/mastra-ai/mastra/commit/a917d2bdd3493434a0fe6c06b8c073388e9b1281), [`2c27503`](https://github.com/mastra-ai/mastra/commit/2c275032510d131d2cde47f99953abf0fe02c081), [`424a1df`](https://github.com/mastra-ai/mastra/commit/424a1df7bee59abb5c83717a54807fdd674a6224), [`3d70b0b`](https://github.com/mastra-ai/mastra/commit/3d70b0b3524d817173ad870768f259c06d61bd23), [`eef7cb2`](https://github.com/mastra-ai/mastra/commit/eef7cb2abe7ef15951e2fdf792a5095c6c643333), [`260fe12`](https://github.com/mastra-ai/mastra/commit/260fe1295fe7354e39d6def2775e0797a7a277f0), [`b879d6d`](https://github.com/mastra-ai/mastra/commit/b879d6db5bcf5a69cdf0ed6c4ccb42e4d0149215), [`12c88a6`](https://github.com/mastra-ai/mastra/commit/12c88a6e32bf982c2fe0c6af62e65a3414519a75), [`43595bf`](https://github.com/mastra-ai/mastra/commit/43595bf7b8df1a6edce7a23b445b5124d2a0b473), [`78670e9`](https://github.com/mastra-ai/mastra/commit/78670e97e76d7422cf7025faf371b2aeafed860d), [`e8a5b0b`](https://github.com/mastra-ai/mastra/commit/e8a5b0b9bc94d12dee4150095512ca27a288d778), [`3b45a13`](https://github.com/mastra-ai/mastra/commit/3b45a138d09d040779c0aba1edbbfc1b57442d23), [`d400e7c`](https://github.com/mastra-ai/mastra/commit/d400e7c8b8d7afa6ba2c71769eace4048e3cef8e), [`f58d1a7`](https://github.com/mastra-ai/mastra/commit/f58d1a7a457588a996c3ecb53201a68f3d28c432), [`a49a929`](https://github.com/mastra-ai/mastra/commit/a49a92904968b4fc67e01effee8c7c8d0464ba85), [`8127d96`](https://github.com/mastra-ai/mastra/commit/8127d96280492e335d49b244501088dfdd59a8f1)]:
|
|
13
|
+
- @mastra/core@1.18.0
|
|
14
|
+
- @mastra/deployer@1.18.0
|
|
15
|
+
|
|
16
|
+
## 1.1.15-alpha.4
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Fixed Cloudflare Workers deploys that failed with `Could not resolve "readable-stream"`. Workers builds now resolve stream imports correctly without requiring extra stream polyfill packages. ([#14488](https://github.com/mastra-ai/mastra/pull/14488))
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`fbf22a7`](https://github.com/mastra-ai/mastra/commit/fbf22a7ad86bcb50dcf30459f0d075e51ddeb468), [`04160ee`](https://github.com/mastra-ai/mastra/commit/04160eedf3130003cf842ad08428c8ff69af4cc1), [`2c27503`](https://github.com/mastra-ai/mastra/commit/2c275032510d131d2cde47f99953abf0fe02c081), [`424a1df`](https://github.com/mastra-ai/mastra/commit/424a1df7bee59abb5c83717a54807fdd674a6224), [`b879d6d`](https://github.com/mastra-ai/mastra/commit/b879d6db5bcf5a69cdf0ed6c4ccb42e4d0149215), [`12c88a6`](https://github.com/mastra-ai/mastra/commit/12c88a6e32bf982c2fe0c6af62e65a3414519a75), [`43595bf`](https://github.com/mastra-ai/mastra/commit/43595bf7b8df1a6edce7a23b445b5124d2a0b473), [`78670e9`](https://github.com/mastra-ai/mastra/commit/78670e97e76d7422cf7025faf371b2aeafed860d), [`d400e7c`](https://github.com/mastra-ai/mastra/commit/d400e7c8b8d7afa6ba2c71769eace4048e3cef8e), [`f58d1a7`](https://github.com/mastra-ai/mastra/commit/f58d1a7a457588a996c3ecb53201a68f3d28c432), [`a49a929`](https://github.com/mastra-ai/mastra/commit/a49a92904968b4fc67e01effee8c7c8d0464ba85)]:
|
|
23
|
+
- @mastra/core@1.18.0-alpha.4
|
|
24
|
+
- @mastra/deployer@1.18.0-alpha.4
|
|
25
|
+
|
|
3
26
|
## 1.1.15-alpha.3
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -202,6 +202,13 @@ export const execaCommandSync = execa;
|
|
|
202
202
|
export const $ = execa;
|
|
203
203
|
`;
|
|
204
204
|
await promises.writeFile(path.join(outputDirectory, this.outputDir, execaStubPath), execaStub);
|
|
205
|
+
const readableStreamStubPath = "readable-stream-stub.mjs";
|
|
206
|
+
const readableStreamStub = `// Redirect readable-stream to native node:stream (available via nodejs_compat)
|
|
207
|
+
import stream from 'node:stream';
|
|
208
|
+
export const { Readable, Writable, Duplex, Transform, PassThrough, Stream, pipeline, finished } = stream;
|
|
209
|
+
export default stream;
|
|
210
|
+
`;
|
|
211
|
+
await promises.writeFile(path.join(outputDirectory, this.outputDir, readableStreamStubPath), readableStreamStub);
|
|
205
212
|
const wranglerConfig = {
|
|
206
213
|
name: "mastra",
|
|
207
214
|
compatibility_date: "2025-04-01",
|
|
@@ -218,6 +225,7 @@ export const $ = execa;
|
|
|
218
225
|
alias: {
|
|
219
226
|
typescript: `./${typescriptStubPath}`,
|
|
220
227
|
execa: `./${execaStubPath}`,
|
|
228
|
+
"readable-stream": `./${readableStreamStubPath}`,
|
|
221
229
|
...userAlias
|
|
222
230
|
}
|
|
223
231
|
};
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/babel/mastra-instance-wrapper.ts","../src/plugins/mastra-instance-wrapper.ts","../src/babel/postgres-store-instance-checker.ts","../src/plugins/postgres-store-instance-checker.ts","../src/index.ts"],"names":["babel","mastraInstanceWrapper","transformSync","babel2","postgresStoreInstanceChecker","Deployer","writeFile","join","relative","virtual"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,SAAS,qBAAA,GAAmC;AACjD,EAAA,MAAM,UAAA,GAAa,QAAA;AACnB,EAAA,MAAM,SAAA,GAAY,QAAA;AAClB,EAAA,MAAM,CAAA,GAAUA,gBAAA,CAAA,KAAA;AAEhB,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,aAAA;AAAA,IACN,OAAA,EAAS;AAAA,MACP,uBAAuB,IAAA,EAAM;AAC3B,QAAA,IAAI,CAAA,CAAE,qBAAA,CAAsB,IAAA,CAAK,IAAA,EAAM,WAAW,CAAA,EAAG;AACnD,UAAA,KAAA,MAAW,WAAA,IAAe,IAAA,CAAK,IAAA,CAAK,WAAA,CAAY,YAAA,EAAc;AAC5D,YAAA,IACE,CAAA,CAAE,aAAa,WAAA,EAAa,EAAA,EAAI,EAAE,IAAA,EAAM,UAAA,EAAY,CAAA,IACpD,CAAA,CAAE,eAAA,CAAgB,aAAa,IAAI,CAAA,IACnC,CAAA,CAAE,YAAA,CAAa,WAAA,CAAY,IAAA,CAAK,QAAQ,EAAE,IAAA,EAAM,SAAA,EAAW,CAAA,EAC3D;AACA,cAAA,WAAA,CAAY,OAAO,CAAA,CAAE,uBAAA,CAAwB,EAAC,EAAG,YAAY,IAAI,CAAA;AAEjE,cAAA;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA;AACF,GACF;AACF;;;AC7CO,SAASC,uBAAsB,eA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;AACf,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,QAAA,EAAS,EAAG,SAAA,EAAW,EAAE,eAAA,EAAiB,WAAA,EAAa,aAAA,EAAe,KAAA,EAAM,EAAG,UAAU,CAAA;AAAA,EACpH;AAAA,EAEA,MAAM,MAAA,GAAwB;AAC5B,IAAA,IAAA,CAAK,MAAA,EAAQ,KAAK,gFAAgF,CAAA;AAAA,EACpG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAA,GAA2B;AAC/B,IAAA,MAAM,IAAI,MAAM,wFAAwF,CAAA;AAAA,EAC1G;AAAA,EAEA,MAAM,IAAA,CAAK,SAAA,EAAmB,eAAA,EAAyB,UAAA,EAAkD;AACvG,IAAA,MAAM,KAAA,CAAM,IAAA,CAAK,SAAA,EAAW,eAAA,EAAiB,UAAU,CAAA;AAEvD,IAAA,MAAM,SAAA,GAAa,MAAM,IAAA,CAAK,IAAA,CAAK,kBAAkB,CAAC,gBAAgB,CAAC,CAAA,KAAO,CAAA,EAAA,CAAA;AAE9E,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,IAAA,CAAK,MAAA,CAAO,KAAA;AAAA,QACV;AAAA,OACF;AACA,MAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import type { PluginObj } from '@babel/core';\nimport * as babel from '@babel/core';\n\n/**\n * Babel plugin that transforms Mastra exports for Cloudflare Workers compatibility.\n *\n * This plugin:\n * 1. Identifies named exports of the 'mastra' variable\n * 2. Checks if the export is a new instance of the 'Mastra' class\n * 3. Wraps the Mastra instantiation in an arrow function to ensure proper initialization\n * in the Cloudflare Workers environment\n *\n * The transformation ensures the Mastra instance is properly scoped and initialized\n * for each request in the Cloudflare Workers environment.\n *\n * @returns {PluginObj} A Babel plugin object with a visitor that performs the transformation\n *\n * @example\n * // Before transformation:\n * export const mastra = new Mastra();\n *\n * // After transformation:\n * export const mastra = () => new Mastra();\n */\nexport function mastraInstanceWrapper(): PluginObj {\n const exportName = 'mastra';\n const className = 'Mastra';\n const t = babel.types;\n\n return {\n name: 'wrap-mastra',\n visitor: {\n ExportNamedDeclaration(path) {\n if (t.isVariableDeclaration(path.node?.declaration)) {\n for (const declaration of path.node.declaration.declarations) {\n if (\n t.isIdentifier(declaration?.id, { name: exportName }) &&\n t.isNewExpression(declaration?.init) &&\n t.isIdentifier(declaration.init.callee, { name: className })\n ) {\n declaration.init = t.arrowFunctionExpression([], declaration.init);\n // there should be only one \"mastra\" export, so we can exit the loop\n break;\n }\n }\n }\n },\n },\n } as PluginObj;\n}\n","import { transformSync } from '@babel/core';\nimport type { Plugin } from 'rollup';\nimport { mastraInstanceWrapper as mastraInstanceWrapperBabel } from '../babel/mastra-instance-wrapper';\n\nexport function mastraInstanceWrapper(mastraEntryFile: string): Plugin {\n return {\n name: 'mastra-wrapper',\n transform(code, id) {\n if (id !== mastraEntryFile) {\n return null;\n }\n\n const result = transformSync(code, {\n filename: id,\n babelrc: false,\n configFile: false,\n plugins: [mastraInstanceWrapperBabel],\n });\n\n if (!result?.code) {\n throw new Error('mastra-wrapper plugin did not return code, there is likely a bug in the plugin.');\n }\n\n return {\n code: result.code,\n map: result?.map,\n };\n },\n };\n}\n","import type { NodePath, PluginObj } from '@babel/core';\nimport * as babel from '@babel/core';\nimport type { NewExpression } from '@babel/types';\n\n/**\n * Babel plugin that enforces singleton PostgresStore instances in Cloudflare Workers.\n *\n * This plugin:\n * 1. Scans for all `new PostgresStore()` instantiations\n * 2. Records their file locations\n * 3. Throws an error if multiple instances are found\n *\n * Cloudflare Workers should only create one PostgresStore instance to avoid connection\n * pool exhaustion and ensure proper resource management.\n *\n * @returns {PluginObj} A Babel plugin object that validates PostgresStore usage\n *\n * @example\n * // Throws error if multiple instances found:\n * const store1 = new PostgresStore();\n * const store2 = new PostgresStore(); // Error thrown here\n */\nexport function postgresStoreInstanceChecker(): PluginObj {\n const t = babel.types;\n const instances: { path: NodePath<NewExpression>; location: string }[] = [];\n\n return {\n name: 'postgresstore-instance-checker',\n visitor: {\n NewExpression(path, state) {\n if (t.isIdentifier(path.node.callee) && path.node.callee.name === 'PostgresStore') {\n const filename = state.file?.opts?.filename || 'unknown file';\n const location = path.node.loc\n ? `${filename}: line ${path.node.loc.start.line}, column ${path.node.loc.start.column}`\n : 'unknown location';\n\n instances.push({\n path,\n location,\n });\n }\n },\n },\n post() {\n if (instances.length > 1) {\n const errorMessage = [\n `Found ${instances.length} PostgresStore instantiations:`,\n ...instances.map((instance, i) => ` ${i + 1}. At ${instance.location}`),\n 'Only one PostgresStore instance should be created per Cloudflare Worker.',\n ].join('\\n');\n\n const lastInstance = instances[instances.length - 1];\n throw lastInstance?.path.buildCodeFrameError(errorMessage);\n }\n },\n } as PluginObj;\n}\n","import { transformSync } from '@babel/core';\nimport type { Plugin } from 'rollup';\nimport { postgresStoreInstanceChecker as postgresStoreInstanceCheckerBabel } from '../babel/postgres-store-instance-checker';\n\nexport function postgresStoreInstanceChecker(): Plugin {\n return {\n name: 'postgres-store-instance-checker',\n transform(code, id) {\n const result = transformSync(code, {\n filename: id,\n babelrc: false,\n configFile: false,\n plugins: [postgresStoreInstanceCheckerBabel],\n });\n\n // If Babel didn't transform anything or returned no code, pass through original source.\n if (!result || typeof result.code !== 'string') {\n return null;\n }\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n },\n };\n}\n","import { writeFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\nimport { Deployer } from '@mastra/deployer';\nimport type { analyzeBundle } from '@mastra/deployer/analyze';\nimport type { BundlerOptions } from '@mastra/deployer/bundler';\nimport virtual from '@rollup/plugin-virtual';\nimport type { Unstable_RawConfig } from 'wrangler'; // Unstable_RawConfig is unstable, and no stable alternative exists. However, `wrangler` is a peerDep, allowing users to use latest properties.\nimport { mastraInstanceWrapper } from './plugins/mastra-instance-wrapper';\nimport { postgresStoreInstanceChecker } from './plugins/postgres-store-instance-checker';\n\n/** @deprecated */\ninterface D1DatabaseBinding {\n binding: string;\n database_name: string;\n database_id: string;\n preview_database_id?: string;\n}\n\n/** @deprecated */\ninterface KVNamespaceBinding {\n binding: string;\n id: string;\n}\n\nexport class CloudflareDeployer extends Deployer {\n readonly userConfig: Omit<Unstable_RawConfig, 'main' | '$schema'>;\n\n constructor(\n userConfig: Omit<Unstable_RawConfig, 'main' | '$schema'> &\n // TODO: Remove deprecated fields in next major version, and update type to just Omit<Unstable_RawConfig, 'main' | '$schema'>.\n {\n /** @deprecated Use `name` instead. */\n projectName?: string;\n /** @deprecated This parameter is not used internally. */\n workerNamespace?: string;\n /** @deprecated Use `d1_databases` instead. */\n d1Databases?: D1DatabaseBinding[];\n /** @deprecated Use `kv_namespaces` instead. */\n kvNamespaces?: KVNamespaceBinding[];\n },\n ) {\n super({ name: 'CLOUDFLARE' });\n\n // Use 'browser' platform for Workers-compatible module resolution.\n // This ensures packages with conditional exports (like the Cloudflare SDK)\n // resolve to browser/worker implementations instead of Node.js-specific code\n // that depends on unavailable modules like 'https'.\n this.platform = 'browser';\n\n this.userConfig = { ...userConfig };\n\n if (userConfig.workerNamespace) {\n console.warn('[CloudflareDeployer]: `workerNamespace` is no longer used');\n }\n if (!userConfig.name && userConfig.projectName) {\n this.userConfig.name = userConfig.projectName;\n console.warn('[CloudflareDeployer]: `projectName` is deprecated, use `name` instead');\n }\n if (!userConfig.d1_databases && userConfig.d1Databases) {\n this.userConfig.d1_databases = userConfig.d1Databases;\n console.warn('[CloudflareDeployer]: `d1Databases` is deprecated, use `d1_databases` instead');\n }\n if (!userConfig.kv_namespaces && userConfig.kvNamespaces) {\n this.userConfig.kv_namespaces = userConfig.kvNamespaces;\n console.warn('[CloudflareDeployer]: `kvNamespaces` is deprecated, use `kv_namespaces` instead');\n }\n }\n\n async writeFiles(outputDirectory: string): Promise<void> {\n const {\n vars: userVars,\n alias: userAlias,\n // Remove deprecated fields so they don't leak into wrangler.json\n projectName: _projectName,\n workerNamespace: _workerNamespace,\n d1Databases: _d1Databases,\n kvNamespaces: _kvNamespaces,\n ...userConfig\n } = this.userConfig as typeof this.userConfig & {\n projectName?: string;\n workerNamespace?: string;\n d1Databases?: unknown;\n kvNamespaces?: unknown;\n };\n const loadedEnvVars = await this.loadEnvVars();\n const envsAsObject = Object.assign({}, userVars);\n\n if (loadedEnvVars.size > 0) {\n const envKeys = [...loadedEnvVars.keys()].join(', ');\n this.logger.warn(\n `Environment variables from .env (${envKeys}) were not written to wrangler.jsonc.\nUpload them as Cloudflare Secrets instead:\nnpx wrangler secret bulk .env`,\n );\n }\n\n // Write TypeScript stub to prevent bundling the full TypeScript library (~10MB)\n // The agent-builder package dynamically imports TypeScript for code validation,\n // but gracefully falls back to basic validation when TypeScript is unavailable.\n // This stub ensures the import doesn't fail while keeping the bundle small.\n const typescriptStubPath = 'typescript-stub.mjs';\n const typescriptStub = `// Stub for TypeScript - not available at runtime in Cloudflare Workers\n// The @mastra/agent-builder package will fall back to basic validation\nexport default {};\nexport const createSourceFile = () => null;\nexport const createProgram = () => null;\nexport const findConfigFile = () => null;\nexport const readConfigFile = () => ({ error: new Error('TypeScript not available') });\nexport const parseJsonConfigFileContent = () => ({ errors: [new Error('TypeScript not available')], fileNames: [], options: {} });\nexport const flattenDiagnosticMessageText = (message) => typeof message === 'string' ? message : message?.messageText || '';\nexport const ScriptTarget = { Latest: 99 };\nexport const ModuleKind = { ESNext: 99 };\nexport const JsxEmit = { ReactJSX: 4 };\nexport const DiagnosticCategory = { Warning: 0, Error: 1, Suggestion: 2, Message: 3 };\nexport const sys = {\n fileExists: () => false,\n readFile: () => undefined,\n};\n`;\n\n await writeFile(join(outputDirectory, this.outputDir, typescriptStubPath), typescriptStub);\n\n // Write execa stub — execa is used by @mastra/core's local sandbox process manager\n // but is not available/needed in Cloudflare Workers\n const execaStubPath = 'execa-stub.mjs';\n const execaStub = `// Stub for execa - not available at runtime in Cloudflare Workers\nexport const execa = () => { throw new Error('execa is not available in Cloudflare Workers'); };\nexport const execaNode = execa;\nexport const execaSync = execa;\nexport const execaCommand = execa;\nexport const execaCommandSync = execa;\nexport const $ = execa;\n`;\n await writeFile(join(outputDirectory, this.outputDir, execaStubPath), execaStub);\n\n const wranglerConfig: Unstable_RawConfig = {\n name: 'mastra',\n compatibility_date: '2025-04-01',\n compatibility_flags: ['nodejs_compat', 'nodejs_compat_populate_process_env'],\n observability: {\n logs: {\n enabled: true,\n },\n },\n ...userConfig,\n main: './index.mjs',\n vars: envsAsObject,\n // Alias stubs to prevent wrangler from bundling unavailable libraries\n alias: {\n typescript: `./${typescriptStubPath}`,\n execa: `./${execaStubPath}`,\n ...userAlias,\n },\n };\n\n // TODO: Remove writing this file in the next major version, it should only be written to the root of the project\n await writeFile(join(outputDirectory, this.outputDir, 'wrangler.json'), JSON.stringify(wranglerConfig, null, 2));\n\n const projectRoot = join(outputDirectory, '../');\n const jsoncFilePath = join(projectRoot, 'wrangler.jsonc');\n const mainFilePath = join(outputDirectory, this.outputDir, 'index.mjs');\n const tsStubFilePath = join(outputDirectory, this.outputDir, typescriptStubPath);\n\n const wranglerJsoncConfig: Unstable_RawConfig & { placeholder: string } = {\n placeholder: 'PLACEHOLDER',\n $schema: './node_modules/wrangler/config-schema.json',\n ...wranglerConfig,\n main: `./${relative(projectRoot, mainFilePath)}`,\n alias: {\n ...wranglerConfig.alias,\n typescript: `./${relative(projectRoot, tsStubFilePath)}`,\n },\n };\n\n const jsonc = JSON.stringify(wranglerJsoncConfig, null, 2).replace(\n /\"placeholder\": \"PLACEHOLDER\",/,\n '/* This file was auto-generated through Mastra. Edit the CloudflareDeployer() instance directly. */',\n );\n await writeFile(jsoncFilePath, jsonc);\n }\n\n private getEntry(): string {\n return `\n import '#polyfills';\n import { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';\n\n export default {\n fetch: async (request, env, context) => {\n const { mastra } = await import('#mastra');\n const { tools } = await import('#tools');\n const {createHonoServer, getToolExports} = await import('#server');\n const _mastra = mastra();\n\n if (_mastra.getStorage()) {\n _mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n }\n\n const app = await createHonoServer(_mastra, { tools: getToolExports(tools) });\n return app.fetch(request, env, context);\n }\n }\n`;\n }\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n await this.writeFiles(outputDirectory);\n }\n\n protected async getBundlerOptions(\n serverFile: string,\n mastraEntryFile: string,\n analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>,\n toolsPaths: (string | string[])[],\n bundlerOptions: BundlerOptions,\n ) {\n const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {\n ...bundlerOptions,\n enableEsmShim: false,\n });\n\n const hasPostgresStore = (await this.deps.checkDependencies(['@mastra/pg'])) === `ok`;\n\n if (Array.isArray(inputOptions.plugins)) {\n inputOptions.plugins = [\n virtual({\n '#polyfills': `\nprocess.versions = process.versions || {};\nprocess.versions.node = '${process.versions.node}';\n `,\n }),\n ...inputOptions.plugins,\n mastraInstanceWrapper(mastraEntryFile),\n ];\n\n if (hasPostgresStore) {\n inputOptions.plugins.push(postgresStoreInstanceChecker());\n }\n }\n\n return inputOptions;\n }\n\n async bundle(\n entryFile: string,\n outputDirectory: string,\n { toolsPaths, projectRoot }: { toolsPaths: (string | string[])[]; projectRoot: string },\n ): Promise<void> {\n return this._bundle(this.getEntry(), entryFile, { outputDirectory, projectRoot, enableEsmShim: false }, toolsPaths);\n }\n\n async deploy(): Promise<void> {\n this.logger?.info('Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.');\n }\n\n /**\n * TODO: Remove this method in the next major version\n *\n * @deprecated\n */\n async tagWorker(): Promise<void> {\n throw new Error('tagWorker method is no longer supported. Use the Cloudflare dashboard or API directly.');\n }\n\n async lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n await super.lint(entryFile, outputDirectory, toolsPaths);\n\n const hasLibsql = (await this.deps.checkDependencies(['@mastra/libsql'])) === `ok`;\n\n if (hasLibsql) {\n this.logger.error(\n '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.',\n );\n process.exit(1);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/babel/mastra-instance-wrapper.ts","../src/plugins/mastra-instance-wrapper.ts","../src/babel/postgres-store-instance-checker.ts","../src/plugins/postgres-store-instance-checker.ts","../src/index.ts"],"names":["babel","mastraInstanceWrapper","transformSync","babel2","postgresStoreInstanceChecker","Deployer","writeFile","join","relative","virtual"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,SAAS,qBAAA,GAAmC;AACjD,EAAA,MAAM,UAAA,GAAa,QAAA;AACnB,EAAA,MAAM,SAAA,GAAY,QAAA;AAClB,EAAA,MAAM,CAAA,GAAUA,gBAAA,CAAA,KAAA;AAEhB,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,aAAA;AAAA,IACN,OAAA,EAAS;AAAA,MACP,uBAAuB,IAAA,EAAM;AAC3B,QAAA,IAAI,CAAA,CAAE,qBAAA,CAAsB,IAAA,CAAK,IAAA,EAAM,WAAW,CAAA,EAAG;AACnD,UAAA,KAAA,MAAW,WAAA,IAAe,IAAA,CAAK,IAAA,CAAK,WAAA,CAAY,YAAA,EAAc;AAC5D,YAAA,IACE,CAAA,CAAE,aAAa,WAAA,EAAa,EAAA,EAAI,EAAE,IAAA,EAAM,UAAA,EAAY,CAAA,IACpD,CAAA,CAAE,eAAA,CAAgB,aAAa,IAAI,CAAA,IACnC,CAAA,CAAE,YAAA,CAAa,WAAA,CAAY,IAAA,CAAK,QAAQ,EAAE,IAAA,EAAM,SAAA,EAAW,CAAA,EAC3D;AACA,cAAA,WAAA,CAAY,OAAO,CAAA,CAAE,uBAAA,CAAwB,EAAC,EAAG,YAAY,IAAI,CAAA;AAEjE,cAAA;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF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;AAAA,QACD,GAAG,YAAA,CAAa,OAAA;AAAA,QAChBR,uBAAsB,eAAe;AAAA,OACvC;AAEA,MAAA,IAAI,gBAAA,EAAkB;AACpB,QAAA,YAAA,CAAa,OAAA,CAAQ,IAAA,CAAKG,6BAAAA,EAA8B,CAAA;AAAA,MAC1D;AAAA,IACF;AAEA,IAAA,OAAO,YAAA;AAAA,EACT;AAAA,EAEA,MAAM,MAAA,CACJ,SAAA,EACA,iBACA,EAAE,UAAA,EAAY,aAAY,EACX;AACf,IAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,QAAA,EAAS,EAAG,SAAA,EAAW,EAAE,eAAA,EAAiB,WAAA,EAAa,aAAA,EAAe,KAAA,EAAM,EAAG,UAAU,CAAA;AAAA,EACpH;AAAA,EAEA,MAAM,MAAA,GAAwB;AAC5B,IAAA,IAAA,CAAK,MAAA,EAAQ,KAAK,gFAAgF,CAAA;AAAA,EACpG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAA,GAA2B;AAC/B,IAAA,MAAM,IAAI,MAAM,wFAAwF,CAAA;AAAA,EAC1G;AAAA,EAEA,MAAM,IAAA,CAAK,SAAA,EAAmB,eAAA,EAAyB,UAAA,EAAkD;AACvG,IAAA,MAAM,KAAA,CAAM,IAAA,CAAK,SAAA,EAAW,eAAA,EAAiB,UAAU,CAAA;AAEvD,IAAA,MAAM,SAAA,GAAa,MAAM,IAAA,CAAK,IAAA,CAAK,kBAAkB,CAAC,gBAAgB,CAAC,CAAA,KAAO,CAAA,EAAA,CAAA;AAE9E,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,IAAA,CAAK,MAAA,CAAO,KAAA;AAAA,QACV;AAAA,OACF;AACA,MAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import type { PluginObj } from '@babel/core';\nimport * as babel from '@babel/core';\n\n/**\n * Babel plugin that transforms Mastra exports for Cloudflare Workers compatibility.\n *\n * This plugin:\n * 1. Identifies named exports of the 'mastra' variable\n * 2. Checks if the export is a new instance of the 'Mastra' class\n * 3. Wraps the Mastra instantiation in an arrow function to ensure proper initialization\n * in the Cloudflare Workers environment\n *\n * The transformation ensures the Mastra instance is properly scoped and initialized\n * for each request in the Cloudflare Workers environment.\n *\n * @returns {PluginObj} A Babel plugin object with a visitor that performs the transformation\n *\n * @example\n * // Before transformation:\n * export const mastra = new Mastra();\n *\n * // After transformation:\n * export const mastra = () => new Mastra();\n */\nexport function mastraInstanceWrapper(): PluginObj {\n const exportName = 'mastra';\n const className = 'Mastra';\n const t = babel.types;\n\n return {\n name: 'wrap-mastra',\n visitor: {\n ExportNamedDeclaration(path) {\n if (t.isVariableDeclaration(path.node?.declaration)) {\n for (const declaration of path.node.declaration.declarations) {\n if (\n t.isIdentifier(declaration?.id, { name: exportName }) &&\n t.isNewExpression(declaration?.init) &&\n t.isIdentifier(declaration.init.callee, { name: className })\n ) {\n declaration.init = t.arrowFunctionExpression([], declaration.init);\n // there should be only one \"mastra\" export, so we can exit the loop\n break;\n }\n }\n }\n },\n },\n } as PluginObj;\n}\n","import { transformSync } from '@babel/core';\nimport type { Plugin } from 'rollup';\nimport { mastraInstanceWrapper as mastraInstanceWrapperBabel } from '../babel/mastra-instance-wrapper';\n\nexport function mastraInstanceWrapper(mastraEntryFile: string): Plugin {\n return {\n name: 'mastra-wrapper',\n transform(code, id) {\n if (id !== mastraEntryFile) {\n return null;\n }\n\n const result = transformSync(code, {\n filename: id,\n babelrc: false,\n configFile: false,\n plugins: [mastraInstanceWrapperBabel],\n });\n\n if (!result?.code) {\n throw new Error('mastra-wrapper plugin did not return code, there is likely a bug in the plugin.');\n }\n\n return {\n code: result.code,\n map: result?.map,\n };\n },\n };\n}\n","import type { NodePath, PluginObj } from '@babel/core';\nimport * as babel from '@babel/core';\nimport type { NewExpression } from '@babel/types';\n\n/**\n * Babel plugin that enforces singleton PostgresStore instances in Cloudflare Workers.\n *\n * This plugin:\n * 1. Scans for all `new PostgresStore()` instantiations\n * 2. Records their file locations\n * 3. Throws an error if multiple instances are found\n *\n * Cloudflare Workers should only create one PostgresStore instance to avoid connection\n * pool exhaustion and ensure proper resource management.\n *\n * @returns {PluginObj} A Babel plugin object that validates PostgresStore usage\n *\n * @example\n * // Throws error if multiple instances found:\n * const store1 = new PostgresStore();\n * const store2 = new PostgresStore(); // Error thrown here\n */\nexport function postgresStoreInstanceChecker(): PluginObj {\n const t = babel.types;\n const instances: { path: NodePath<NewExpression>; location: string }[] = [];\n\n return {\n name: 'postgresstore-instance-checker',\n visitor: {\n NewExpression(path, state) {\n if (t.isIdentifier(path.node.callee) && path.node.callee.name === 'PostgresStore') {\n const filename = state.file?.opts?.filename || 'unknown file';\n const location = path.node.loc\n ? `${filename}: line ${path.node.loc.start.line}, column ${path.node.loc.start.column}`\n : 'unknown location';\n\n instances.push({\n path,\n location,\n });\n }\n },\n },\n post() {\n if (instances.length > 1) {\n const errorMessage = [\n `Found ${instances.length} PostgresStore instantiations:`,\n ...instances.map((instance, i) => ` ${i + 1}. At ${instance.location}`),\n 'Only one PostgresStore instance should be created per Cloudflare Worker.',\n ].join('\\n');\n\n const lastInstance = instances[instances.length - 1];\n throw lastInstance?.path.buildCodeFrameError(errorMessage);\n }\n },\n } as PluginObj;\n}\n","import { transformSync } from '@babel/core';\nimport type { Plugin } from 'rollup';\nimport { postgresStoreInstanceChecker as postgresStoreInstanceCheckerBabel } from '../babel/postgres-store-instance-checker';\n\nexport function postgresStoreInstanceChecker(): Plugin {\n return {\n name: 'postgres-store-instance-checker',\n transform(code, id) {\n const result = transformSync(code, {\n filename: id,\n babelrc: false,\n configFile: false,\n plugins: [postgresStoreInstanceCheckerBabel],\n });\n\n // If Babel didn't transform anything or returned no code, pass through original source.\n if (!result || typeof result.code !== 'string') {\n return null;\n }\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n },\n };\n}\n","import { writeFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\nimport { Deployer } from '@mastra/deployer';\nimport type { analyzeBundle } from '@mastra/deployer/analyze';\nimport type { BundlerOptions } from '@mastra/deployer/bundler';\nimport virtual from '@rollup/plugin-virtual';\nimport type { Unstable_RawConfig } from 'wrangler'; // Unstable_RawConfig is unstable, and no stable alternative exists. However, `wrangler` is a peerDep, allowing users to use latest properties.\nimport { mastraInstanceWrapper } from './plugins/mastra-instance-wrapper';\nimport { postgresStoreInstanceChecker } from './plugins/postgres-store-instance-checker';\n\n/** @deprecated */\ninterface D1DatabaseBinding {\n binding: string;\n database_name: string;\n database_id: string;\n preview_database_id?: string;\n}\n\n/** @deprecated */\ninterface KVNamespaceBinding {\n binding: string;\n id: string;\n}\n\nexport class CloudflareDeployer extends Deployer {\n readonly userConfig: Omit<Unstable_RawConfig, 'main' | '$schema'>;\n\n constructor(\n userConfig: Omit<Unstable_RawConfig, 'main' | '$schema'> &\n // TODO: Remove deprecated fields in next major version, and update type to just Omit<Unstable_RawConfig, 'main' | '$schema'>.\n {\n /** @deprecated Use `name` instead. */\n projectName?: string;\n /** @deprecated This parameter is not used internally. */\n workerNamespace?: string;\n /** @deprecated Use `d1_databases` instead. */\n d1Databases?: D1DatabaseBinding[];\n /** @deprecated Use `kv_namespaces` instead. */\n kvNamespaces?: KVNamespaceBinding[];\n },\n ) {\n super({ name: 'CLOUDFLARE' });\n\n // Use 'browser' platform for Workers-compatible module resolution.\n // This ensures packages with conditional exports (like the Cloudflare SDK)\n // resolve to browser/worker implementations instead of Node.js-specific code\n // that depends on unavailable modules like 'https'.\n this.platform = 'browser';\n\n this.userConfig = { ...userConfig };\n\n if (userConfig.workerNamespace) {\n console.warn('[CloudflareDeployer]: `workerNamespace` is no longer used');\n }\n if (!userConfig.name && userConfig.projectName) {\n this.userConfig.name = userConfig.projectName;\n console.warn('[CloudflareDeployer]: `projectName` is deprecated, use `name` instead');\n }\n if (!userConfig.d1_databases && userConfig.d1Databases) {\n this.userConfig.d1_databases = userConfig.d1Databases;\n console.warn('[CloudflareDeployer]: `d1Databases` is deprecated, use `d1_databases` instead');\n }\n if (!userConfig.kv_namespaces && userConfig.kvNamespaces) {\n this.userConfig.kv_namespaces = userConfig.kvNamespaces;\n console.warn('[CloudflareDeployer]: `kvNamespaces` is deprecated, use `kv_namespaces` instead');\n }\n }\n\n async writeFiles(outputDirectory: string): Promise<void> {\n const {\n vars: userVars,\n alias: userAlias,\n // Remove deprecated fields so they don't leak into wrangler.json\n projectName: _projectName,\n workerNamespace: _workerNamespace,\n d1Databases: _d1Databases,\n kvNamespaces: _kvNamespaces,\n ...userConfig\n } = this.userConfig as typeof this.userConfig & {\n projectName?: string;\n workerNamespace?: string;\n d1Databases?: unknown;\n kvNamespaces?: unknown;\n };\n const loadedEnvVars = await this.loadEnvVars();\n const envsAsObject = Object.assign({}, userVars);\n\n if (loadedEnvVars.size > 0) {\n const envKeys = [...loadedEnvVars.keys()].join(', ');\n this.logger.warn(\n `Environment variables from .env (${envKeys}) were not written to wrangler.jsonc.\nUpload them as Cloudflare Secrets instead:\nnpx wrangler secret bulk .env`,\n );\n }\n\n // Write TypeScript stub to prevent bundling the full TypeScript library (~10MB)\n // The agent-builder package dynamically imports TypeScript for code validation,\n // but gracefully falls back to basic validation when TypeScript is unavailable.\n // This stub ensures the import doesn't fail while keeping the bundle small.\n const typescriptStubPath = 'typescript-stub.mjs';\n const typescriptStub = `// Stub for TypeScript - not available at runtime in Cloudflare Workers\n// The @mastra/agent-builder package will fall back to basic validation\nexport default {};\nexport const createSourceFile = () => null;\nexport const createProgram = () => null;\nexport const findConfigFile = () => null;\nexport const readConfigFile = () => ({ error: new Error('TypeScript not available') });\nexport const parseJsonConfigFileContent = () => ({ errors: [new Error('TypeScript not available')], fileNames: [], options: {} });\nexport const flattenDiagnosticMessageText = (message) => typeof message === 'string' ? message : message?.messageText || '';\nexport const ScriptTarget = { Latest: 99 };\nexport const ModuleKind = { ESNext: 99 };\nexport const JsxEmit = { ReactJSX: 4 };\nexport const DiagnosticCategory = { Warning: 0, Error: 1, Suggestion: 2, Message: 3 };\nexport const sys = {\n fileExists: () => false,\n readFile: () => undefined,\n};\n`;\n\n await writeFile(join(outputDirectory, this.outputDir, typescriptStubPath), typescriptStub);\n\n // Write execa stub — execa is used by @mastra/core's local sandbox process manager\n // but is not available/needed in Cloudflare Workers\n const execaStubPath = 'execa-stub.mjs';\n const execaStub = `// Stub for execa - not available at runtime in Cloudflare Workers\nexport const execa = () => { throw new Error('execa is not available in Cloudflare Workers'); };\nexport const execaNode = execa;\nexport const execaSync = execa;\nexport const execaCommand = execa;\nexport const execaCommandSync = execa;\nexport const $ = execa;\n`;\n await writeFile(join(outputDirectory, this.outputDir, execaStubPath), execaStub);\n\n // Write readable-stream stub — redirects to native node:stream available via nodejs_compat.\n // readable-stream is a userland copy of Node.js streams used by packages like elevenlabs.\n // Bundling it for Workers pulls in Node.js polyfills (abort-controller, process/, string_decoder/)\n // that are unnecessary and fail to resolve. The native node:stream is API-compatible.\n const readableStreamStubPath = 'readable-stream-stub.mjs';\n const readableStreamStub = `// Redirect readable-stream to native node:stream (available via nodejs_compat)\nimport stream from 'node:stream';\nexport const { Readable, Writable, Duplex, Transform, PassThrough, Stream, pipeline, finished } = stream;\nexport default stream;\n`;\n await writeFile(join(outputDirectory, this.outputDir, readableStreamStubPath), readableStreamStub);\n\n const wranglerConfig: Unstable_RawConfig = {\n name: 'mastra',\n compatibility_date: '2025-04-01',\n compatibility_flags: ['nodejs_compat', 'nodejs_compat_populate_process_env'],\n observability: {\n logs: {\n enabled: true,\n },\n },\n ...userConfig,\n main: './index.mjs',\n vars: envsAsObject,\n // Alias stubs to prevent wrangler from bundling unavailable libraries\n alias: {\n typescript: `./${typescriptStubPath}`,\n execa: `./${execaStubPath}`,\n 'readable-stream': `./${readableStreamStubPath}`,\n ...userAlias,\n },\n };\n\n // TODO: Remove writing this file in the next major version, it should only be written to the root of the project\n await writeFile(join(outputDirectory, this.outputDir, 'wrangler.json'), JSON.stringify(wranglerConfig, null, 2));\n\n const projectRoot = join(outputDirectory, '../');\n const jsoncFilePath = join(projectRoot, 'wrangler.jsonc');\n const mainFilePath = join(outputDirectory, this.outputDir, 'index.mjs');\n const tsStubFilePath = join(outputDirectory, this.outputDir, typescriptStubPath);\n\n const wranglerJsoncConfig: Unstable_RawConfig & { placeholder: string } = {\n placeholder: 'PLACEHOLDER',\n $schema: './node_modules/wrangler/config-schema.json',\n ...wranglerConfig,\n main: `./${relative(projectRoot, mainFilePath)}`,\n alias: {\n ...wranglerConfig.alias,\n typescript: `./${relative(projectRoot, tsStubFilePath)}`,\n },\n };\n\n const jsonc = JSON.stringify(wranglerJsoncConfig, null, 2).replace(\n /\"placeholder\": \"PLACEHOLDER\",/,\n '/* This file was auto-generated through Mastra. Edit the CloudflareDeployer() instance directly. */',\n );\n await writeFile(jsoncFilePath, jsonc);\n }\n\n private getEntry(): string {\n return `\n import '#polyfills';\n import { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';\n\n export default {\n fetch: async (request, env, context) => {\n const { mastra } = await import('#mastra');\n const { tools } = await import('#tools');\n const {createHonoServer, getToolExports} = await import('#server');\n const _mastra = mastra();\n\n if (_mastra.getStorage()) {\n _mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n }\n\n const app = await createHonoServer(_mastra, { tools: getToolExports(tools) });\n return app.fetch(request, env, context);\n }\n }\n`;\n }\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n await this.writeFiles(outputDirectory);\n }\n\n protected async getBundlerOptions(\n serverFile: string,\n mastraEntryFile: string,\n analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>,\n toolsPaths: (string | string[])[],\n bundlerOptions: BundlerOptions,\n ) {\n const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {\n ...bundlerOptions,\n enableEsmShim: false,\n });\n\n const hasPostgresStore = (await this.deps.checkDependencies(['@mastra/pg'])) === `ok`;\n\n if (Array.isArray(inputOptions.plugins)) {\n inputOptions.plugins = [\n virtual({\n '#polyfills': `\nprocess.versions = process.versions || {};\nprocess.versions.node = '${process.versions.node}';\n `,\n }),\n ...inputOptions.plugins,\n mastraInstanceWrapper(mastraEntryFile),\n ];\n\n if (hasPostgresStore) {\n inputOptions.plugins.push(postgresStoreInstanceChecker());\n }\n }\n\n return inputOptions;\n }\n\n async bundle(\n entryFile: string,\n outputDirectory: string,\n { toolsPaths, projectRoot }: { toolsPaths: (string | string[])[]; projectRoot: string },\n ): Promise<void> {\n return this._bundle(this.getEntry(), entryFile, { outputDirectory, projectRoot, enableEsmShim: false }, toolsPaths);\n }\n\n async deploy(): Promise<void> {\n this.logger?.info('Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.');\n }\n\n /**\n * TODO: Remove this method in the next major version\n *\n * @deprecated\n */\n async tagWorker(): Promise<void> {\n throw new Error('tagWorker method is no longer supported. Use the Cloudflare dashboard or API directly.');\n }\n\n async lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n await super.lint(entryFile, outputDirectory, toolsPaths);\n\n const hasLibsql = (await this.deps.checkDependencies(['@mastra/libsql'])) === `ok`;\n\n if (hasLibsql) {\n this.logger.error(\n '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.',\n );\n process.exit(1);\n }\n }\n}\n"]}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAIn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AC,IAAI,CAAC;IAI1B,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAYzG"}
|
package/dist/index.js
CHANGED
|
@@ -178,6 +178,13 @@ export const execaCommandSync = execa;
|
|
|
178
178
|
export const $ = execa;
|
|
179
179
|
`;
|
|
180
180
|
await writeFile(join(outputDirectory, this.outputDir, execaStubPath), execaStub);
|
|
181
|
+
const readableStreamStubPath = "readable-stream-stub.mjs";
|
|
182
|
+
const readableStreamStub = `// Redirect readable-stream to native node:stream (available via nodejs_compat)
|
|
183
|
+
import stream from 'node:stream';
|
|
184
|
+
export const { Readable, Writable, Duplex, Transform, PassThrough, Stream, pipeline, finished } = stream;
|
|
185
|
+
export default stream;
|
|
186
|
+
`;
|
|
187
|
+
await writeFile(join(outputDirectory, this.outputDir, readableStreamStubPath), readableStreamStub);
|
|
181
188
|
const wranglerConfig = {
|
|
182
189
|
name: "mastra",
|
|
183
190
|
compatibility_date: "2025-04-01",
|
|
@@ -194,6 +201,7 @@ export const $ = execa;
|
|
|
194
201
|
alias: {
|
|
195
202
|
typescript: `./${typescriptStubPath}`,
|
|
196
203
|
execa: `./${execaStubPath}`,
|
|
204
|
+
"readable-stream": `./${readableStreamStubPath}`,
|
|
197
205
|
...userAlias
|
|
198
206
|
}
|
|
199
207
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/babel/mastra-instance-wrapper.ts","../src/plugins/mastra-instance-wrapper.ts","../src/babel/postgres-store-instance-checker.ts","../src/plugins/postgres-store-instance-checker.ts","../src/index.ts"],"names":["mastraInstanceWrapper","babel2","postgresStoreInstanceChecker","transformSync"],"mappings":";;;;;;;;AAwBO,SAAS,qBAAA,GAAmC;AACjD,EAAA,MAAM,UAAA,GAAa,QAAA;AACnB,EAAA,MAAM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,KAAA,CAAM,IAAA,CAAK,SAAA,EAAW,eAAA,EAAiB,UAAU,CAAA;AAEvD,IAAA,MAAM,SAAA,GAAa,MAAM,IAAA,CAAK,IAAA,CAAK,kBAAkB,CAAC,gBAAgB,CAAC,CAAA,KAAO,CAAA,EAAA,CAAA;AAE9E,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,IAAA,CAAK,MAAA,CAAO,KAAA;AAAA,QACV;AAAA,OACF;AACA,MAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import type { PluginObj } from '@babel/core';\nimport * as babel from '@babel/core';\n\n/**\n * Babel plugin that transforms Mastra exports for Cloudflare Workers compatibility.\n *\n * This plugin:\n * 1. Identifies named exports of the 'mastra' variable\n * 2. Checks if the export is a new instance of the 'Mastra' class\n * 3. Wraps the Mastra instantiation in an arrow function to ensure proper initialization\n * in the Cloudflare Workers environment\n *\n * The transformation ensures the Mastra instance is properly scoped and initialized\n * for each request in the Cloudflare Workers environment.\n *\n * @returns {PluginObj} A Babel plugin object with a visitor that performs the transformation\n *\n * @example\n * // Before transformation:\n * export const mastra = new Mastra();\n *\n * // After transformation:\n * export const mastra = () => new Mastra();\n */\nexport function mastraInstanceWrapper(): PluginObj {\n const exportName = 'mastra';\n const className = 'Mastra';\n const t = babel.types;\n\n return {\n name: 'wrap-mastra',\n visitor: {\n ExportNamedDeclaration(path) {\n if (t.isVariableDeclaration(path.node?.declaration)) {\n for (const declaration of path.node.declaration.declarations) {\n if (\n t.isIdentifier(declaration?.id, { name: exportName }) &&\n t.isNewExpression(declaration?.init) &&\n t.isIdentifier(declaration.init.callee, { name: className })\n ) {\n declaration.init = t.arrowFunctionExpression([], declaration.init);\n // there should be only one \"mastra\" export, so we can exit the loop\n break;\n }\n }\n }\n },\n },\n } as PluginObj;\n}\n","import { transformSync } from '@babel/core';\nimport type { Plugin } from 'rollup';\nimport { mastraInstanceWrapper as mastraInstanceWrapperBabel } from '../babel/mastra-instance-wrapper';\n\nexport function mastraInstanceWrapper(mastraEntryFile: string): Plugin {\n return {\n name: 'mastra-wrapper',\n transform(code, id) {\n if (id !== mastraEntryFile) {\n return null;\n }\n\n const result = transformSync(code, {\n filename: id,\n babelrc: false,\n configFile: false,\n plugins: [mastraInstanceWrapperBabel],\n });\n\n if (!result?.code) {\n throw new Error('mastra-wrapper plugin did not return code, there is likely a bug in the plugin.');\n }\n\n return {\n code: result.code,\n map: result?.map,\n };\n },\n };\n}\n","import type { NodePath, PluginObj } from '@babel/core';\nimport * as babel from '@babel/core';\nimport type { NewExpression } from '@babel/types';\n\n/**\n * Babel plugin that enforces singleton PostgresStore instances in Cloudflare Workers.\n *\n * This plugin:\n * 1. Scans for all `new PostgresStore()` instantiations\n * 2. Records their file locations\n * 3. Throws an error if multiple instances are found\n *\n * Cloudflare Workers should only create one PostgresStore instance to avoid connection\n * pool exhaustion and ensure proper resource management.\n *\n * @returns {PluginObj} A Babel plugin object that validates PostgresStore usage\n *\n * @example\n * // Throws error if multiple instances found:\n * const store1 = new PostgresStore();\n * const store2 = new PostgresStore(); // Error thrown here\n */\nexport function postgresStoreInstanceChecker(): PluginObj {\n const t = babel.types;\n const instances: { path: NodePath<NewExpression>; location: string }[] = [];\n\n return {\n name: 'postgresstore-instance-checker',\n visitor: {\n NewExpression(path, state) {\n if (t.isIdentifier(path.node.callee) && path.node.callee.name === 'PostgresStore') {\n const filename = state.file?.opts?.filename || 'unknown file';\n const location = path.node.loc\n ? `${filename}: line ${path.node.loc.start.line}, column ${path.node.loc.start.column}`\n : 'unknown location';\n\n instances.push({\n path,\n location,\n });\n }\n },\n },\n post() {\n if (instances.length > 1) {\n const errorMessage = [\n `Found ${instances.length} PostgresStore instantiations:`,\n ...instances.map((instance, i) => ` ${i + 1}. At ${instance.location}`),\n 'Only one PostgresStore instance should be created per Cloudflare Worker.',\n ].join('\\n');\n\n const lastInstance = instances[instances.length - 1];\n throw lastInstance?.path.buildCodeFrameError(errorMessage);\n }\n },\n } as PluginObj;\n}\n","import { transformSync } from '@babel/core';\nimport type { Plugin } from 'rollup';\nimport { postgresStoreInstanceChecker as postgresStoreInstanceCheckerBabel } from '../babel/postgres-store-instance-checker';\n\nexport function postgresStoreInstanceChecker(): Plugin {\n return {\n name: 'postgres-store-instance-checker',\n transform(code, id) {\n const result = transformSync(code, {\n filename: id,\n babelrc: false,\n configFile: false,\n plugins: [postgresStoreInstanceCheckerBabel],\n });\n\n // If Babel didn't transform anything or returned no code, pass through original source.\n if (!result || typeof result.code !== 'string') {\n return null;\n }\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n },\n };\n}\n","import { writeFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\nimport { Deployer } from '@mastra/deployer';\nimport type { analyzeBundle } from '@mastra/deployer/analyze';\nimport type { BundlerOptions } from '@mastra/deployer/bundler';\nimport virtual from '@rollup/plugin-virtual';\nimport type { Unstable_RawConfig } from 'wrangler'; // Unstable_RawConfig is unstable, and no stable alternative exists. However, `wrangler` is a peerDep, allowing users to use latest properties.\nimport { mastraInstanceWrapper } from './plugins/mastra-instance-wrapper';\nimport { postgresStoreInstanceChecker } from './plugins/postgres-store-instance-checker';\n\n/** @deprecated */\ninterface D1DatabaseBinding {\n binding: string;\n database_name: string;\n database_id: string;\n preview_database_id?: string;\n}\n\n/** @deprecated */\ninterface KVNamespaceBinding {\n binding: string;\n id: string;\n}\n\nexport class CloudflareDeployer extends Deployer {\n readonly userConfig: Omit<Unstable_RawConfig, 'main' | '$schema'>;\n\n constructor(\n userConfig: Omit<Unstable_RawConfig, 'main' | '$schema'> &\n // TODO: Remove deprecated fields in next major version, and update type to just Omit<Unstable_RawConfig, 'main' | '$schema'>.\n {\n /** @deprecated Use `name` instead. */\n projectName?: string;\n /** @deprecated This parameter is not used internally. */\n workerNamespace?: string;\n /** @deprecated Use `d1_databases` instead. */\n d1Databases?: D1DatabaseBinding[];\n /** @deprecated Use `kv_namespaces` instead. */\n kvNamespaces?: KVNamespaceBinding[];\n },\n ) {\n super({ name: 'CLOUDFLARE' });\n\n // Use 'browser' platform for Workers-compatible module resolution.\n // This ensures packages with conditional exports (like the Cloudflare SDK)\n // resolve to browser/worker implementations instead of Node.js-specific code\n // that depends on unavailable modules like 'https'.\n this.platform = 'browser';\n\n this.userConfig = { ...userConfig };\n\n if (userConfig.workerNamespace) {\n console.warn('[CloudflareDeployer]: `workerNamespace` is no longer used');\n }\n if (!userConfig.name && userConfig.projectName) {\n this.userConfig.name = userConfig.projectName;\n console.warn('[CloudflareDeployer]: `projectName` is deprecated, use `name` instead');\n }\n if (!userConfig.d1_databases && userConfig.d1Databases) {\n this.userConfig.d1_databases = userConfig.d1Databases;\n console.warn('[CloudflareDeployer]: `d1Databases` is deprecated, use `d1_databases` instead');\n }\n if (!userConfig.kv_namespaces && userConfig.kvNamespaces) {\n this.userConfig.kv_namespaces = userConfig.kvNamespaces;\n console.warn('[CloudflareDeployer]: `kvNamespaces` is deprecated, use `kv_namespaces` instead');\n }\n }\n\n async writeFiles(outputDirectory: string): Promise<void> {\n const {\n vars: userVars,\n alias: userAlias,\n // Remove deprecated fields so they don't leak into wrangler.json\n projectName: _projectName,\n workerNamespace: _workerNamespace,\n d1Databases: _d1Databases,\n kvNamespaces: _kvNamespaces,\n ...userConfig\n } = this.userConfig as typeof this.userConfig & {\n projectName?: string;\n workerNamespace?: string;\n d1Databases?: unknown;\n kvNamespaces?: unknown;\n };\n const loadedEnvVars = await this.loadEnvVars();\n const envsAsObject = Object.assign({}, userVars);\n\n if (loadedEnvVars.size > 0) {\n const envKeys = [...loadedEnvVars.keys()].join(', ');\n this.logger.warn(\n `Environment variables from .env (${envKeys}) were not written to wrangler.jsonc.\nUpload them as Cloudflare Secrets instead:\nnpx wrangler secret bulk .env`,\n );\n }\n\n // Write TypeScript stub to prevent bundling the full TypeScript library (~10MB)\n // The agent-builder package dynamically imports TypeScript for code validation,\n // but gracefully falls back to basic validation when TypeScript is unavailable.\n // This stub ensures the import doesn't fail while keeping the bundle small.\n const typescriptStubPath = 'typescript-stub.mjs';\n const typescriptStub = `// Stub for TypeScript - not available at runtime in Cloudflare Workers\n// The @mastra/agent-builder package will fall back to basic validation\nexport default {};\nexport const createSourceFile = () => null;\nexport const createProgram = () => null;\nexport const findConfigFile = () => null;\nexport const readConfigFile = () => ({ error: new Error('TypeScript not available') });\nexport const parseJsonConfigFileContent = () => ({ errors: [new Error('TypeScript not available')], fileNames: [], options: {} });\nexport const flattenDiagnosticMessageText = (message) => typeof message === 'string' ? message : message?.messageText || '';\nexport const ScriptTarget = { Latest: 99 };\nexport const ModuleKind = { ESNext: 99 };\nexport const JsxEmit = { ReactJSX: 4 };\nexport const DiagnosticCategory = { Warning: 0, Error: 1, Suggestion: 2, Message: 3 };\nexport const sys = {\n fileExists: () => false,\n readFile: () => undefined,\n};\n`;\n\n await writeFile(join(outputDirectory, this.outputDir, typescriptStubPath), typescriptStub);\n\n // Write execa stub — execa is used by @mastra/core's local sandbox process manager\n // but is not available/needed in Cloudflare Workers\n const execaStubPath = 'execa-stub.mjs';\n const execaStub = `// Stub for execa - not available at runtime in Cloudflare Workers\nexport const execa = () => { throw new Error('execa is not available in Cloudflare Workers'); };\nexport const execaNode = execa;\nexport const execaSync = execa;\nexport const execaCommand = execa;\nexport const execaCommandSync = execa;\nexport const $ = execa;\n`;\n await writeFile(join(outputDirectory, this.outputDir, execaStubPath), execaStub);\n\n const wranglerConfig: Unstable_RawConfig = {\n name: 'mastra',\n compatibility_date: '2025-04-01',\n compatibility_flags: ['nodejs_compat', 'nodejs_compat_populate_process_env'],\n observability: {\n logs: {\n enabled: true,\n },\n },\n ...userConfig,\n main: './index.mjs',\n vars: envsAsObject,\n // Alias stubs to prevent wrangler from bundling unavailable libraries\n alias: {\n typescript: `./${typescriptStubPath}`,\n execa: `./${execaStubPath}`,\n ...userAlias,\n },\n };\n\n // TODO: Remove writing this file in the next major version, it should only be written to the root of the project\n await writeFile(join(outputDirectory, this.outputDir, 'wrangler.json'), JSON.stringify(wranglerConfig, null, 2));\n\n const projectRoot = join(outputDirectory, '../');\n const jsoncFilePath = join(projectRoot, 'wrangler.jsonc');\n const mainFilePath = join(outputDirectory, this.outputDir, 'index.mjs');\n const tsStubFilePath = join(outputDirectory, this.outputDir, typescriptStubPath);\n\n const wranglerJsoncConfig: Unstable_RawConfig & { placeholder: string } = {\n placeholder: 'PLACEHOLDER',\n $schema: './node_modules/wrangler/config-schema.json',\n ...wranglerConfig,\n main: `./${relative(projectRoot, mainFilePath)}`,\n alias: {\n ...wranglerConfig.alias,\n typescript: `./${relative(projectRoot, tsStubFilePath)}`,\n },\n };\n\n const jsonc = JSON.stringify(wranglerJsoncConfig, null, 2).replace(\n /\"placeholder\": \"PLACEHOLDER\",/,\n '/* This file was auto-generated through Mastra. Edit the CloudflareDeployer() instance directly. */',\n );\n await writeFile(jsoncFilePath, jsonc);\n }\n\n private getEntry(): string {\n return `\n import '#polyfills';\n import { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';\n\n export default {\n fetch: async (request, env, context) => {\n const { mastra } = await import('#mastra');\n const { tools } = await import('#tools');\n const {createHonoServer, getToolExports} = await import('#server');\n const _mastra = mastra();\n\n if (_mastra.getStorage()) {\n _mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n }\n\n const app = await createHonoServer(_mastra, { tools: getToolExports(tools) });\n return app.fetch(request, env, context);\n }\n }\n`;\n }\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n await this.writeFiles(outputDirectory);\n }\n\n protected async getBundlerOptions(\n serverFile: string,\n mastraEntryFile: string,\n analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>,\n toolsPaths: (string | string[])[],\n bundlerOptions: BundlerOptions,\n ) {\n const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {\n ...bundlerOptions,\n enableEsmShim: false,\n });\n\n const hasPostgresStore = (await this.deps.checkDependencies(['@mastra/pg'])) === `ok`;\n\n if (Array.isArray(inputOptions.plugins)) {\n inputOptions.plugins = [\n virtual({\n '#polyfills': `\nprocess.versions = process.versions || {};\nprocess.versions.node = '${process.versions.node}';\n `,\n }),\n ...inputOptions.plugins,\n mastraInstanceWrapper(mastraEntryFile),\n ];\n\n if (hasPostgresStore) {\n inputOptions.plugins.push(postgresStoreInstanceChecker());\n }\n }\n\n return inputOptions;\n }\n\n async bundle(\n entryFile: string,\n outputDirectory: string,\n { toolsPaths, projectRoot }: { toolsPaths: (string | string[])[]; projectRoot: string },\n ): Promise<void> {\n return this._bundle(this.getEntry(), entryFile, { outputDirectory, projectRoot, enableEsmShim: false }, toolsPaths);\n }\n\n async deploy(): Promise<void> {\n this.logger?.info('Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.');\n }\n\n /**\n * TODO: Remove this method in the next major version\n *\n * @deprecated\n */\n async tagWorker(): Promise<void> {\n throw new Error('tagWorker method is no longer supported. Use the Cloudflare dashboard or API directly.');\n }\n\n async lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n await super.lint(entryFile, outputDirectory, toolsPaths);\n\n const hasLibsql = (await this.deps.checkDependencies(['@mastra/libsql'])) === `ok`;\n\n if (hasLibsql) {\n this.logger.error(\n '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.',\n );\n process.exit(1);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/babel/mastra-instance-wrapper.ts","../src/plugins/mastra-instance-wrapper.ts","../src/babel/postgres-store-instance-checker.ts","../src/plugins/postgres-store-instance-checker.ts","../src/index.ts"],"names":["mastraInstanceWrapper","babel2","postgresStoreInstanceChecker","transformSync"],"mappings":";;;;;;;;AAwBO,SAAS,qBAAA,GAAmC;AACjD,EAAA,MAAM,UAAA,GAAa,QAAA;AACnB,EAAA,MAAM,SAAA,GAAY,QAAA;AAClB,EAAA,MAAM,CAA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A;AAAA,EACpG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAA,GAA2B;AAC/B,IAAA,MAAM,IAAI,MAAM,wFAAwF,CAAA;AAAA,EAC1G;AAAA,EAEA,MAAM,IAAA,CAAK,SAAA,EAAmB,eAAA,EAAyB,UAAA,EAAkD;AACvG,IAAA,MAAM,KAAA,CAAM,IAAA,CAAK,SAAA,EAAW,eAAA,EAAiB,UAAU,CAAA;AAEvD,IAAA,MAAM,SAAA,GAAa,MAAM,IAAA,CAAK,IAAA,CAAK,kBAAkB,CAAC,gBAAgB,CAAC,CAAA,KAAO,CAAA,EAAA,CAAA;AAE9E,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,IAAA,CAAK,MAAA,CAAO,KAAA;AAAA,QACV;AAAA,OACF;AACA,MAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB;AAAA,EACF;AACF","file":"index.js","sourcesContent":["import type { PluginObj } from '@babel/core';\nimport * as babel from '@babel/core';\n\n/**\n * Babel plugin that transforms Mastra exports for Cloudflare Workers compatibility.\n *\n * This plugin:\n * 1. Identifies named exports of the 'mastra' variable\n * 2. Checks if the export is a new instance of the 'Mastra' class\n * 3. Wraps the Mastra instantiation in an arrow function to ensure proper initialization\n * in the Cloudflare Workers environment\n *\n * The transformation ensures the Mastra instance is properly scoped and initialized\n * for each request in the Cloudflare Workers environment.\n *\n * @returns {PluginObj} A Babel plugin object with a visitor that performs the transformation\n *\n * @example\n * // Before transformation:\n * export const mastra = new Mastra();\n *\n * // After transformation:\n * export const mastra = () => new Mastra();\n */\nexport function mastraInstanceWrapper(): PluginObj {\n const exportName = 'mastra';\n const className = 'Mastra';\n const t = babel.types;\n\n return {\n name: 'wrap-mastra',\n visitor: {\n ExportNamedDeclaration(path) {\n if (t.isVariableDeclaration(path.node?.declaration)) {\n for (const declaration of path.node.declaration.declarations) {\n if (\n t.isIdentifier(declaration?.id, { name: exportName }) &&\n t.isNewExpression(declaration?.init) &&\n t.isIdentifier(declaration.init.callee, { name: className })\n ) {\n declaration.init = t.arrowFunctionExpression([], declaration.init);\n // there should be only one \"mastra\" export, so we can exit the loop\n break;\n }\n }\n }\n },\n },\n } as PluginObj;\n}\n","import { transformSync } from '@babel/core';\nimport type { Plugin } from 'rollup';\nimport { mastraInstanceWrapper as mastraInstanceWrapperBabel } from '../babel/mastra-instance-wrapper';\n\nexport function mastraInstanceWrapper(mastraEntryFile: string): Plugin {\n return {\n name: 'mastra-wrapper',\n transform(code, id) {\n if (id !== mastraEntryFile) {\n return null;\n }\n\n const result = transformSync(code, {\n filename: id,\n babelrc: false,\n configFile: false,\n plugins: [mastraInstanceWrapperBabel],\n });\n\n if (!result?.code) {\n throw new Error('mastra-wrapper plugin did not return code, there is likely a bug in the plugin.');\n }\n\n return {\n code: result.code,\n map: result?.map,\n };\n },\n };\n}\n","import type { NodePath, PluginObj } from '@babel/core';\nimport * as babel from '@babel/core';\nimport type { NewExpression } from '@babel/types';\n\n/**\n * Babel plugin that enforces singleton PostgresStore instances in Cloudflare Workers.\n *\n * This plugin:\n * 1. Scans for all `new PostgresStore()` instantiations\n * 2. Records their file locations\n * 3. Throws an error if multiple instances are found\n *\n * Cloudflare Workers should only create one PostgresStore instance to avoid connection\n * pool exhaustion and ensure proper resource management.\n *\n * @returns {PluginObj} A Babel plugin object that validates PostgresStore usage\n *\n * @example\n * // Throws error if multiple instances found:\n * const store1 = new PostgresStore();\n * const store2 = new PostgresStore(); // Error thrown here\n */\nexport function postgresStoreInstanceChecker(): PluginObj {\n const t = babel.types;\n const instances: { path: NodePath<NewExpression>; location: string }[] = [];\n\n return {\n name: 'postgresstore-instance-checker',\n visitor: {\n NewExpression(path, state) {\n if (t.isIdentifier(path.node.callee) && path.node.callee.name === 'PostgresStore') {\n const filename = state.file?.opts?.filename || 'unknown file';\n const location = path.node.loc\n ? `${filename}: line ${path.node.loc.start.line}, column ${path.node.loc.start.column}`\n : 'unknown location';\n\n instances.push({\n path,\n location,\n });\n }\n },\n },\n post() {\n if (instances.length > 1) {\n const errorMessage = [\n `Found ${instances.length} PostgresStore instantiations:`,\n ...instances.map((instance, i) => ` ${i + 1}. At ${instance.location}`),\n 'Only one PostgresStore instance should be created per Cloudflare Worker.',\n ].join('\\n');\n\n const lastInstance = instances[instances.length - 1];\n throw lastInstance?.path.buildCodeFrameError(errorMessage);\n }\n },\n } as PluginObj;\n}\n","import { transformSync } from '@babel/core';\nimport type { Plugin } from 'rollup';\nimport { postgresStoreInstanceChecker as postgresStoreInstanceCheckerBabel } from '../babel/postgres-store-instance-checker';\n\nexport function postgresStoreInstanceChecker(): Plugin {\n return {\n name: 'postgres-store-instance-checker',\n transform(code, id) {\n const result = transformSync(code, {\n filename: id,\n babelrc: false,\n configFile: false,\n plugins: [postgresStoreInstanceCheckerBabel],\n });\n\n // If Babel didn't transform anything or returned no code, pass through original source.\n if (!result || typeof result.code !== 'string') {\n return null;\n }\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n },\n };\n}\n","import { writeFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path';\nimport { Deployer } from '@mastra/deployer';\nimport type { analyzeBundle } from '@mastra/deployer/analyze';\nimport type { BundlerOptions } from '@mastra/deployer/bundler';\nimport virtual from '@rollup/plugin-virtual';\nimport type { Unstable_RawConfig } from 'wrangler'; // Unstable_RawConfig is unstable, and no stable alternative exists. However, `wrangler` is a peerDep, allowing users to use latest properties.\nimport { mastraInstanceWrapper } from './plugins/mastra-instance-wrapper';\nimport { postgresStoreInstanceChecker } from './plugins/postgres-store-instance-checker';\n\n/** @deprecated */\ninterface D1DatabaseBinding {\n binding: string;\n database_name: string;\n database_id: string;\n preview_database_id?: string;\n}\n\n/** @deprecated */\ninterface KVNamespaceBinding {\n binding: string;\n id: string;\n}\n\nexport class CloudflareDeployer extends Deployer {\n readonly userConfig: Omit<Unstable_RawConfig, 'main' | '$schema'>;\n\n constructor(\n userConfig: Omit<Unstable_RawConfig, 'main' | '$schema'> &\n // TODO: Remove deprecated fields in next major version, and update type to just Omit<Unstable_RawConfig, 'main' | '$schema'>.\n {\n /** @deprecated Use `name` instead. */\n projectName?: string;\n /** @deprecated This parameter is not used internally. */\n workerNamespace?: string;\n /** @deprecated Use `d1_databases` instead. */\n d1Databases?: D1DatabaseBinding[];\n /** @deprecated Use `kv_namespaces` instead. */\n kvNamespaces?: KVNamespaceBinding[];\n },\n ) {\n super({ name: 'CLOUDFLARE' });\n\n // Use 'browser' platform for Workers-compatible module resolution.\n // This ensures packages with conditional exports (like the Cloudflare SDK)\n // resolve to browser/worker implementations instead of Node.js-specific code\n // that depends on unavailable modules like 'https'.\n this.platform = 'browser';\n\n this.userConfig = { ...userConfig };\n\n if (userConfig.workerNamespace) {\n console.warn('[CloudflareDeployer]: `workerNamespace` is no longer used');\n }\n if (!userConfig.name && userConfig.projectName) {\n this.userConfig.name = userConfig.projectName;\n console.warn('[CloudflareDeployer]: `projectName` is deprecated, use `name` instead');\n }\n if (!userConfig.d1_databases && userConfig.d1Databases) {\n this.userConfig.d1_databases = userConfig.d1Databases;\n console.warn('[CloudflareDeployer]: `d1Databases` is deprecated, use `d1_databases` instead');\n }\n if (!userConfig.kv_namespaces && userConfig.kvNamespaces) {\n this.userConfig.kv_namespaces = userConfig.kvNamespaces;\n console.warn('[CloudflareDeployer]: `kvNamespaces` is deprecated, use `kv_namespaces` instead');\n }\n }\n\n async writeFiles(outputDirectory: string): Promise<void> {\n const {\n vars: userVars,\n alias: userAlias,\n // Remove deprecated fields so they don't leak into wrangler.json\n projectName: _projectName,\n workerNamespace: _workerNamespace,\n d1Databases: _d1Databases,\n kvNamespaces: _kvNamespaces,\n ...userConfig\n } = this.userConfig as typeof this.userConfig & {\n projectName?: string;\n workerNamespace?: string;\n d1Databases?: unknown;\n kvNamespaces?: unknown;\n };\n const loadedEnvVars = await this.loadEnvVars();\n const envsAsObject = Object.assign({}, userVars);\n\n if (loadedEnvVars.size > 0) {\n const envKeys = [...loadedEnvVars.keys()].join(', ');\n this.logger.warn(\n `Environment variables from .env (${envKeys}) were not written to wrangler.jsonc.\nUpload them as Cloudflare Secrets instead:\nnpx wrangler secret bulk .env`,\n );\n }\n\n // Write TypeScript stub to prevent bundling the full TypeScript library (~10MB)\n // The agent-builder package dynamically imports TypeScript for code validation,\n // but gracefully falls back to basic validation when TypeScript is unavailable.\n // This stub ensures the import doesn't fail while keeping the bundle small.\n const typescriptStubPath = 'typescript-stub.mjs';\n const typescriptStub = `// Stub for TypeScript - not available at runtime in Cloudflare Workers\n// The @mastra/agent-builder package will fall back to basic validation\nexport default {};\nexport const createSourceFile = () => null;\nexport const createProgram = () => null;\nexport const findConfigFile = () => null;\nexport const readConfigFile = () => ({ error: new Error('TypeScript not available') });\nexport const parseJsonConfigFileContent = () => ({ errors: [new Error('TypeScript not available')], fileNames: [], options: {} });\nexport const flattenDiagnosticMessageText = (message) => typeof message === 'string' ? message : message?.messageText || '';\nexport const ScriptTarget = { Latest: 99 };\nexport const ModuleKind = { ESNext: 99 };\nexport const JsxEmit = { ReactJSX: 4 };\nexport const DiagnosticCategory = { Warning: 0, Error: 1, Suggestion: 2, Message: 3 };\nexport const sys = {\n fileExists: () => false,\n readFile: () => undefined,\n};\n`;\n\n await writeFile(join(outputDirectory, this.outputDir, typescriptStubPath), typescriptStub);\n\n // Write execa stub — execa is used by @mastra/core's local sandbox process manager\n // but is not available/needed in Cloudflare Workers\n const execaStubPath = 'execa-stub.mjs';\n const execaStub = `// Stub for execa - not available at runtime in Cloudflare Workers\nexport const execa = () => { throw new Error('execa is not available in Cloudflare Workers'); };\nexport const execaNode = execa;\nexport const execaSync = execa;\nexport const execaCommand = execa;\nexport const execaCommandSync = execa;\nexport const $ = execa;\n`;\n await writeFile(join(outputDirectory, this.outputDir, execaStubPath), execaStub);\n\n // Write readable-stream stub — redirects to native node:stream available via nodejs_compat.\n // readable-stream is a userland copy of Node.js streams used by packages like elevenlabs.\n // Bundling it for Workers pulls in Node.js polyfills (abort-controller, process/, string_decoder/)\n // that are unnecessary and fail to resolve. The native node:stream is API-compatible.\n const readableStreamStubPath = 'readable-stream-stub.mjs';\n const readableStreamStub = `// Redirect readable-stream to native node:stream (available via nodejs_compat)\nimport stream from 'node:stream';\nexport const { Readable, Writable, Duplex, Transform, PassThrough, Stream, pipeline, finished } = stream;\nexport default stream;\n`;\n await writeFile(join(outputDirectory, this.outputDir, readableStreamStubPath), readableStreamStub);\n\n const wranglerConfig: Unstable_RawConfig = {\n name: 'mastra',\n compatibility_date: '2025-04-01',\n compatibility_flags: ['nodejs_compat', 'nodejs_compat_populate_process_env'],\n observability: {\n logs: {\n enabled: true,\n },\n },\n ...userConfig,\n main: './index.mjs',\n vars: envsAsObject,\n // Alias stubs to prevent wrangler from bundling unavailable libraries\n alias: {\n typescript: `./${typescriptStubPath}`,\n execa: `./${execaStubPath}`,\n 'readable-stream': `./${readableStreamStubPath}`,\n ...userAlias,\n },\n };\n\n // TODO: Remove writing this file in the next major version, it should only be written to the root of the project\n await writeFile(join(outputDirectory, this.outputDir, 'wrangler.json'), JSON.stringify(wranglerConfig, null, 2));\n\n const projectRoot = join(outputDirectory, '../');\n const jsoncFilePath = join(projectRoot, 'wrangler.jsonc');\n const mainFilePath = join(outputDirectory, this.outputDir, 'index.mjs');\n const tsStubFilePath = join(outputDirectory, this.outputDir, typescriptStubPath);\n\n const wranglerJsoncConfig: Unstable_RawConfig & { placeholder: string } = {\n placeholder: 'PLACEHOLDER',\n $schema: './node_modules/wrangler/config-schema.json',\n ...wranglerConfig,\n main: `./${relative(projectRoot, mainFilePath)}`,\n alias: {\n ...wranglerConfig.alias,\n typescript: `./${relative(projectRoot, tsStubFilePath)}`,\n },\n };\n\n const jsonc = JSON.stringify(wranglerJsoncConfig, null, 2).replace(\n /\"placeholder\": \"PLACEHOLDER\",/,\n '/* This file was auto-generated through Mastra. Edit the CloudflareDeployer() instance directly. */',\n );\n await writeFile(jsoncFilePath, jsonc);\n }\n\n private getEntry(): string {\n return `\n import '#polyfills';\n import { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';\n\n export default {\n fetch: async (request, env, context) => {\n const { mastra } = await import('#mastra');\n const { tools } = await import('#tools');\n const {createHonoServer, getToolExports} = await import('#server');\n const _mastra = mastra();\n\n if (_mastra.getStorage()) {\n _mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n }\n\n const app = await createHonoServer(_mastra, { tools: getToolExports(tools) });\n return app.fetch(request, env, context);\n }\n }\n`;\n }\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n await this.writeFiles(outputDirectory);\n }\n\n protected async getBundlerOptions(\n serverFile: string,\n mastraEntryFile: string,\n analyzedBundleInfo: Awaited<ReturnType<typeof analyzeBundle>>,\n toolsPaths: (string | string[])[],\n bundlerOptions: BundlerOptions,\n ) {\n const inputOptions = await super.getBundlerOptions(serverFile, mastraEntryFile, analyzedBundleInfo, toolsPaths, {\n ...bundlerOptions,\n enableEsmShim: false,\n });\n\n const hasPostgresStore = (await this.deps.checkDependencies(['@mastra/pg'])) === `ok`;\n\n if (Array.isArray(inputOptions.plugins)) {\n inputOptions.plugins = [\n virtual({\n '#polyfills': `\nprocess.versions = process.versions || {};\nprocess.versions.node = '${process.versions.node}';\n `,\n }),\n ...inputOptions.plugins,\n mastraInstanceWrapper(mastraEntryFile),\n ];\n\n if (hasPostgresStore) {\n inputOptions.plugins.push(postgresStoreInstanceChecker());\n }\n }\n\n return inputOptions;\n }\n\n async bundle(\n entryFile: string,\n outputDirectory: string,\n { toolsPaths, projectRoot }: { toolsPaths: (string | string[])[]; projectRoot: string },\n ): Promise<void> {\n return this._bundle(this.getEntry(), entryFile, { outputDirectory, projectRoot, enableEsmShim: false }, toolsPaths);\n }\n\n async deploy(): Promise<void> {\n this.logger?.info('Deploying to Cloudflare failed. Please use the Cloudflare dashboard to deploy.');\n }\n\n /**\n * TODO: Remove this method in the next major version\n *\n * @deprecated\n */\n async tagWorker(): Promise<void> {\n throw new Error('tagWorker method is no longer supported. Use the Cloudflare dashboard or API directly.');\n }\n\n async lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n await super.lint(entryFile, outputDirectory, toolsPaths);\n\n const hasLibsql = (await this.deps.checkDependencies(['@mastra/libsql'])) === `ok`;\n\n if (hasLibsql) {\n this.logger.error(\n '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.',\n );\n process.exit(1);\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/deployer-cloudflare",
|
|
3
|
-
"version": "1.1.15
|
|
3
|
+
"version": "1.1.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"cloudflare": "^5.2.0",
|
|
42
42
|
"rollup": "^4.59.0",
|
|
43
43
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
44
|
-
"@mastra/deployer": "^1.18.0
|
|
44
|
+
"@mastra/deployer": "^1.18.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@babel/types": "^7.29.0",
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"vitest": "4.0.18",
|
|
56
56
|
"wrangler": "^4.73.0",
|
|
57
57
|
"zod": "^3.25.76",
|
|
58
|
-
"@internal/lint": "0.0.
|
|
59
|
-
"@internal/types-builder": "0.0.
|
|
60
|
-
"@mastra/core": "1.18.0
|
|
58
|
+
"@internal/lint": "0.0.75",
|
|
59
|
+
"@internal/types-builder": "0.0.50",
|
|
60
|
+
"@mastra/core": "1.18.0"
|
|
61
61
|
},
|
|
62
62
|
"homepage": "https://mastra.ai",
|
|
63
63
|
"repository": {
|