Skip to content

Commit

Permalink
fix: only warn about miniflare feature support (ai, vectorize, cron) …
Browse files Browse the repository at this point in the history
…once (#6331)

We have some warnings in local mode dev when trying to use ai bindings / vectorize / cron, but they are printed every time the worker is started. This PR changes the warning to only be printed once per worker start.
  • Loading branch information
threepointone authored Jul 25, 2024
1 parent affdc56 commit e6ada07
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .changeset/lemon-items-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: only warn about miniflare feature support (ai, vectorize, cron) once

We have some warnings in local mode dev when trying to use ai bindings / vectorize / cron, but they are printed every time the worker is started. This PR changes the warning to only be printed once per worker start.
29 changes: 21 additions & 8 deletions packages/wrangler/src/dev/miniflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,10 @@ export function handleRuntimeStdio(stdout: Readable, stderr: Readable) {
});
}

let didWarnMiniflareCronSupport = false;
let didWarnMiniflareVectorizeSupport = false;
let didWarnAiAccountUsage = false;

export async function buildMiniflareOptions(
log: Log,
config: Omit<ConfigBundle, "rules">,
Expand All @@ -808,20 +812,29 @@ export async function buildMiniflareOptions(
entrypointNames: string[];
}> {
if (config.crons.length > 0) {
logger.warn("Miniflare 3 does not support CRON triggers yet, ignoring...");
if (!didWarnMiniflareCronSupport) {
didWarnMiniflareCronSupport = true;
log.warn("Miniflare 3 does not support CRON triggers yet, ignoring...");
}
}

if (config.bindings.ai) {
logger.warn(
"Using Workers AI always accesses your Cloudflare account in order to run AI models, and so will incur usage charges even in local development."
);
if (!didWarnAiAccountUsage) {
didWarnAiAccountUsage = true;
logger.warn(
"Using Workers AI always accesses your Cloudflare account in order to run AI models, and so will incur usage charges even in local development."
);
}
}

if (config.bindings.vectorize?.length) {
// TODO: add local support for Vectorize bindings (https://github.com/cloudflare/workers-sdk/issues/4360)
logger.warn(
"Vectorize bindings are not currently supported in local mode. Please use --remote if you are working with them."
);
if (!didWarnMiniflareVectorizeSupport) {
didWarnMiniflareVectorizeSupport = true;
// TODO: add local support for Vectorize bindings (https://github.com/cloudflare/workers-sdk/issues/4360)
logger.warn(
"Vectorize bindings are not currently supported in local mode. Please use --remote if you are working with them."
);
}
}

const upstream =
Expand Down

0 comments on commit e6ada07

Please sign in to comment.