Skip to content

Commit 8e9aa40

Browse files
authoredJan 13, 2025··
Use TEXT bindings for plain text values in Miniflare (#7738)
* Use TEXT bindings for plain text values in Miniflare * Create dry-numbers-doubt.md * Update dry-numbers-doubt.md
1 parent d13e288 commit 8e9aa40

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed
 

‎.changeset/dry-numbers-doubt.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"miniflare": patch
3+
---
4+
5+
Use TEXT bindings for plain text values in Miniflare. This is an internal detail that should have no user facing impact.

‎packages/miniflare/src/plugins/core/index.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,20 @@ function validateCompatibilityDate(log: Log, compatibilityDate: string) {
339339
return compatibilityDate;
340340
}
341341

342-
function buildJsonBindings(bindings: Record<string, Json>): Worker_Binding[] {
343-
return Object.entries(bindings).map(([name, value]) => ({
344-
name,
345-
json: JSON.stringify(value),
346-
}));
342+
function buildBindings(bindings: Record<string, Json>): Worker_Binding[] {
343+
return Object.entries(bindings).map(([name, value]) => {
344+
if (typeof value === "string") {
345+
return {
346+
name,
347+
text: value,
348+
};
349+
} else {
350+
return {
351+
name,
352+
json: JSON.stringify(value),
353+
};
354+
}
355+
});
347356
}
348357

349358
const WRAPPED_MODULE_PREFIX = "miniflare-internal:wrapped:";
@@ -368,7 +377,7 @@ export const CORE_PLUGIN: Plugin<
368377
const bindings: Awaitable<Worker_Binding>[] = [];
369378

370379
if (options.bindings !== undefined) {
371-
bindings.push(...buildJsonBindings(options.bindings));
380+
bindings.push(...buildBindings(options.bindings));
372381
}
373382
if (options.wasmBindings !== undefined) {
374383
bindings.push(
@@ -424,7 +433,7 @@ export const CORE_PLUGIN: Plugin<
424433
// Build binding
425434
const moduleName = workerNameToWrappedModule(scriptName);
426435
const innerBindings =
427-
bindings === undefined ? [] : buildJsonBindings(bindings);
436+
bindings === undefined ? [] : buildBindings(bindings);
428437
// `scriptName`'s bindings will be added to `innerBindings` when
429438
// assembling the config
430439
return {

0 commit comments

Comments
 (0)
Please sign in to comment.