Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TEXT bindings for plain text values in Miniflare #7738

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading