diff --git a/.changeset/tidy-baboons-rest.md b/.changeset/tidy-baboons-rest.md new file mode 100644 index 000000000000..ffc19964f3a6 --- /dev/null +++ b/.changeset/tidy-baboons-rest.md @@ -0,0 +1,5 @@ +--- +"wrangler": minor +--- + +Rename Hyperdrive local connection string environment variable from `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_` to `CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_`. The old variable name is still supported but will now show a deprecation warning. diff --git a/packages/wrangler/e2e/dev.test.ts b/packages/wrangler/e2e/dev.test.ts index ccb96c795a91..40f192e74ad5 100644 --- a/packages/wrangler/e2e/dev.test.ts +++ b/packages/wrangler/e2e/dev.test.ts @@ -684,7 +684,7 @@ describe("hyperdrive dev tests", () => { const worker = helper.runLongLived("wrangler dev", { env: { ...process.env, - WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE: `postgresql://user:pass@127.0.0.1:${port}/some_db`, + CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE: `postgresql://user:pass@127.0.0.1:${port}/some_db`, }, }); diff --git a/packages/wrangler/src/dev.ts b/packages/wrangler/src/dev.ts index 3268f08744f4..5e58d9544fde 100644 --- a/packages/wrangler/src/dev.ts +++ b/packages/wrangler/src/dev.ts @@ -911,10 +911,17 @@ export function getBindings( // Hyperdrive bindings const hyperdriveBindings = configParam.hyperdrive.map((hyperdrive) => { - const connectionStringFromEnv = - process.env[ - `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_${hyperdrive.binding}` - ]; + const prefix = `CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_`; + const deprecatedPrefix = `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_`; + + let varName = `${prefix}${hyperdrive.binding}`; + let connectionStringFromEnv = process.env[varName]; + + if (!connectionStringFromEnv) { + varName = `${deprecatedPrefix}${hyperdrive.binding}`; + connectionStringFromEnv = process.env[varName]; + } + // only require a local connection string in the wrangler file or the env if not using dev --remote if ( local && @@ -922,7 +929,7 @@ export function getBindings( hyperdrive.localConnectionString === undefined ) { throw new UserError( - `When developing locally, you should use a local Postgres connection string to emulate Hyperdrive functionality. Please setup Postgres locally and set the value of the 'WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_${hyperdrive.binding}' variable or "${hyperdrive.binding}"'s "localConnectionString" to the Postgres connection string.`, + `When developing locally, you should use a local Postgres connection string to emulate Hyperdrive functionality. Please setup Postgres locally and set the value of the '${prefix}${hyperdrive.binding}' variable or "${hyperdrive.binding}"'s "localConnectionString" to the Postgres connection string.`, { telemetryMessage: "no local hyperdrive connection string" } ); } @@ -930,8 +937,13 @@ export function getBindings( // If there is a non-empty connection string specified in the environment, // use that as our local connection string configuration. if (connectionStringFromEnv) { + if (varName.startsWith(deprecatedPrefix)) { + logger.once.warn( + `Using "${deprecatedPrefix}" environment variable. This is deprecated. Please use "${prefix}" instead.` + ); + } logger.log( - `Found a non-empty WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING variable for binding. Hyperdrive will connect to this database during local development.` + `Found a non-empty ${varName} variable for binding. Hyperdrive will connect to this database during local development.` ); hyperdrive.localConnectionString = connectionStringFromEnv; } diff --git a/packages/wrangler/src/environment-variables/factory.ts b/packages/wrangler/src/environment-variables/factory.ts index 45bdba0079b2..b298b88fb580 100644 --- a/packages/wrangler/src/environment-variables/factory.ts +++ b/packages/wrangler/src/environment-variables/factory.ts @@ -25,7 +25,7 @@ type VariableNames = // ## Development & Local Testing /** Local database connection strings for Hyperdrive development. The * should be replaced with the Hyperdrive binding name in the Worker. */ - | `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_${string}` + | `CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_${string}` /** Suppress Hyperdrive-related warnings during development. */ | "NO_HYPERDRIVE_WARNING" /** Path to HTTPS private key file for running the local development server in HTTPS mode. Without this Wrangler will generate keys automatically. */