diff --git a/.changeset/dry-numbers-doubt.md b/.changeset/dry-numbers-doubt.md new file mode 100644 index 000000000000..69984d6d577b --- /dev/null +++ b/.changeset/dry-numbers-doubt.md @@ -0,0 +1,5 @@ +--- +"miniflare": patch +--- + +Use TEXT bindings for plain text values in Miniflare. This is an internal detail that should have no user facing impact. diff --git a/packages/miniflare/src/plugins/core/index.ts b/packages/miniflare/src/plugins/core/index.ts index 721508b6290f..18341d16c729 100644 --- a/packages/miniflare/src/plugins/core/index.ts +++ b/packages/miniflare/src/plugins/core/index.ts @@ -339,11 +339,20 @@ function validateCompatibilityDate(log: Log, compatibilityDate: string) { return compatibilityDate; } -function buildJsonBindings(bindings: Record): Worker_Binding[] { - return Object.entries(bindings).map(([name, value]) => ({ - name, - json: JSON.stringify(value), - })); +function buildBindings(bindings: Record): Worker_Binding[] { + return Object.entries(bindings).map(([name, value]) => { + if (typeof value === "string") { + return { + name, + text: value, + }; + } else { + return { + name, + json: JSON.stringify(value), + }; + } + }); } const WRAPPED_MODULE_PREFIX = "miniflare-internal:wrapped:"; @@ -368,7 +377,7 @@ export const CORE_PLUGIN: Plugin< const bindings: Awaitable[] = []; if (options.bindings !== undefined) { - bindings.push(...buildJsonBindings(options.bindings)); + bindings.push(...buildBindings(options.bindings)); } if (options.wasmBindings !== undefined) { bindings.push( @@ -424,7 +433,7 @@ export const CORE_PLUGIN: Plugin< // Build binding const moduleName = workerNameToWrappedModule(scriptName); const innerBindings = - bindings === undefined ? [] : buildJsonBindings(bindings); + bindings === undefined ? [] : buildBindings(bindings); // `scriptName`'s bindings will be added to `innerBindings` when // assembling the config return {