Skip to content

Commit

Permalink
Use TEXT bindings for plain text values in Miniflare (#7738)
Browse files Browse the repository at this point in the history
* Use TEXT bindings for plain text values in Miniflare

* Create dry-numbers-doubt.md

* Update dry-numbers-doubt.md
  • Loading branch information
penalosa authored Jan 13, 2025
1 parent d13e288 commit 8e9aa40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-numbers-doubt.md
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 16 additions & 7 deletions packages/miniflare/src/plugins/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,20 @@ function validateCompatibilityDate(log: Log, compatibilityDate: string) {
return compatibilityDate;
}

function buildJsonBindings(bindings: Record<string, Json>): Worker_Binding[] {
return Object.entries(bindings).map(([name, value]) => ({
name,
json: JSON.stringify(value),
}));
function buildBindings(bindings: Record<string, Json>): 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:";
Expand All @@ -368,7 +377,7 @@ export const CORE_PLUGIN: Plugin<
const bindings: Awaitable<Worker_Binding>[] = [];

if (options.bindings !== undefined) {
bindings.push(...buildJsonBindings(options.bindings));
bindings.push(...buildBindings(options.bindings));
}
if (options.wasmBindings !== undefined) {
bindings.push(
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8e9aa40

Please sign in to comment.