From 2c365c799f9d12d3ce74869569f0a2c576269179 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Sat, 11 Jan 2025 19:24:30 +0000 Subject: [PATCH 1/3] Use TEXT bindings for plain text values in Miniflare --- packages/miniflare/src/plugins/core/index.ts | 23 ++++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) 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 { From e260ec3084d75bb7f1f90921c07d5220e547f029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Somhairle=20MacLe=C3=B2id?= Date: Mon, 13 Jan 2025 13:26:06 +0000 Subject: [PATCH 2/3] Create dry-numbers-doubt.md --- .changeset/dry-numbers-doubt.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dry-numbers-doubt.md diff --git a/.changeset/dry-numbers-doubt.md b/.changeset/dry-numbers-doubt.md new file mode 100644 index 000000000000..00477f96a4a9 --- /dev/null +++ b/.changeset/dry-numbers-doubt.md @@ -0,0 +1,5 @@ +--- +"miniflare": minor +--- + +Use TEXT bindings for plain text values in Miniflare. This is an internal detail that should have no user facing impact. From dce441c1f8c2c7eb22fdb421a00f06fd0222d767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Somhairle=20MacLe=C3=B2id?= Date: Mon, 13 Jan 2025 13:26:29 +0000 Subject: [PATCH 3/3] Update dry-numbers-doubt.md --- .changeset/dry-numbers-doubt.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/dry-numbers-doubt.md b/.changeset/dry-numbers-doubt.md index 00477f96a4a9..69984d6d577b 100644 --- a/.changeset/dry-numbers-doubt.md +++ b/.changeset/dry-numbers-doubt.md @@ -1,5 +1,5 @@ --- -"miniflare": minor +"miniflare": patch --- Use TEXT bindings for plain text values in Miniflare. This is an internal detail that should have no user facing impact.