From bb4961839604840e3b988ab8585a5e0b3f517956 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Wed, 21 Aug 2024 14:06:12 +0100 Subject: [PATCH 1/5] fix: remove `experimental:` prefix requirement for nodejs_compat_v2 See https://jira.cfdata.org/browse/DEVDASH-218 --- .changeset/green-lies-crash.md | 7 ++++ fixtures/nodejs-hybrid-app/wrangler.toml | 2 +- fixtures/pages-nodejs-v2-compat/wrangler.toml | 2 +- .../create-worker-upload-form.ts | 3 +- .../src/deployment-bundle/node-compat.ts | 37 ++----------------- packages/wrangler/src/dev/miniflare.ts | 5 +-- packages/wrangler/src/dev/remote.tsx | 3 +- 7 files changed, 15 insertions(+), 44 deletions(-) create mode 100644 .changeset/green-lies-crash.md diff --git a/.changeset/green-lies-crash.md b/.changeset/green-lies-crash.md new file mode 100644 index 000000000000..f3bdf5a0090f --- /dev/null +++ b/.changeset/green-lies-crash.md @@ -0,0 +1,7 @@ +--- +"wrangler": patch +--- + +fix: remove `experimental:` prefix requirement for nodejs_compat_v2 + +See https://jira.cfdata.org/bro diff --git a/fixtures/nodejs-hybrid-app/wrangler.toml b/fixtures/nodejs-hybrid-app/wrangler.toml index 5f07afe5f5ac..c71823b5dba6 100644 --- a/fixtures/nodejs-hybrid-app/wrangler.toml +++ b/fixtures/nodejs-hybrid-app/wrangler.toml @@ -1,7 +1,7 @@ name = "nodejs-hybrid-app" main = "src/index.ts" compatibility_date = "2024-06-03" -compatibility_flags = ["experimental:nodejs_compat_v2"] +compatibility_flags = ["nodejs_compat_v2"] [vars] # These DB connection values are to a public database containing information about diff --git a/fixtures/pages-nodejs-v2-compat/wrangler.toml b/fixtures/pages-nodejs-v2-compat/wrangler.toml index b966f189586d..66730cf21ccc 100644 --- a/fixtures/pages-nodejs-v2-compat/wrangler.toml +++ b/fixtures/pages-nodejs-v2-compat/wrangler.toml @@ -1,3 +1,3 @@ name = "pages-nodejs-compat" compatibility_date = "2024-08-20" -compatibility_flags = ["experimental:nodejs_compat_v2"] +compatibility_flags = ["nodejs_compat_v2"] diff --git a/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts b/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts index f5b96993b495..f6568323a2bb 100644 --- a/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts +++ b/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts @@ -3,7 +3,6 @@ import { readFileSync } from "node:fs"; import path from "node:path"; import { File, FormData } from "undici"; import { handleUnsafeCapnp } from "./capnp"; -import { stripExperimentalPrefixes } from "./node-compat"; import type { CfDurableObjectMigrations, CfModuleType, @@ -547,7 +546,7 @@ export function createWorkerUploadForm(worker: CfWorkerInit): FormData { bindings: metadataBindings, ...(compatibility_date && { compatibility_date }), ...(compatibility_flags && { - compatibility_flags: stripExperimentalPrefixes(compatibility_flags), + compatibility_flags, }), ...(migrations && { migrations }), capnp_schema: capnpSchemaOutputFile, diff --git a/packages/wrangler/src/deployment-bundle/node-compat.ts b/packages/wrangler/src/deployment-bundle/node-compat.ts index 83eb05d1f30b..1c17f9085413 100644 --- a/packages/wrangler/src/deployment-bundle/node-compat.ts +++ b/packages/wrangler/src/deployment-bundle/node-compat.ts @@ -20,9 +20,8 @@ export type NodeJSCompatMode = "legacy" | "v1" | "v2" | null; * - "v2": experimental nodejs_compat_v2 flag * - null: no Node.js compatibility * - * Currently we require that the v2 mode is configured via `experimental:nodejs_compat_v2` compat flag, - * where the `experimental:` prefix is stripped before being passed to the runtime since that does not - * understand this prefix. + * Currently we require that the v2 mode is configured via `nodejs_compat_v2` compat flag. + * At a future compatibility date, the use of `nodejs_compat` flag will imply `nodejs_compat_v2`. * * We assert that only one of these modes can be specified at a time. * We assert that you must prefix v2 mode with `experimental`. @@ -48,9 +47,6 @@ export function validateNodeCompat({ node_compat: legacyNodeCompat, }); - const nodejsCompatV2NotExperimental = - compatibilityFlags.includes("nodejs_compat_v2"); - if (nodejsCompat && nodejsCompatV2) { throw new UserError( "The `nodejs_compat` and `nodejs_compat_v2` compatibility flags cannot be used in together. Please select just one." @@ -63,18 +59,6 @@ export function validateNodeCompat({ ); } - if (nodejsCompatV2NotExperimental) { - throw new UserError( - `The \`nodejs_compat_v2\` compatibility flag is experimental and must be prefixed with \`experimental:\`. Use \`experimental:nodejs_compat_v2\` flag instead.` - ); - } - - if (nodejsCompatV2) { - logger.warn( - "Enabling experimental Node.js compatibility mode v2. This feature is still in development and not ready for production use." - ); - } - if (noBundle && legacyNodeCompat) { logger.warn( "`--node-compat` and `--no-bundle` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process." @@ -95,9 +79,7 @@ export function getNodeCompatMode({ node_compat, }: Pick) { const nodejsCompat = compatibility_flags.includes("nodejs_compat"); - const nodejsCompatV2 = compatibility_flags.includes( - "experimental:nodejs_compat_v2" - ); + const nodejsCompatV2 = compatibility_flags.includes("nodejs_compat_v2"); let mode: NodeJSCompatMode; if (nodejsCompatV2) { @@ -117,16 +99,3 @@ export function getNodeCompatMode({ nodejsCompatV2, }; } - -/** - * The nodejs_compat_v2 flag currently requires an `experimental:` prefix within Wrangler, - * but this needs to be stripped before sending to workerd, since that doesn't know about that. - * - * TODO: Remove this function when we graduate nodejs_v2 to non-experimental. - * See https://jira.cfdata.org/browse/DEVDASH-218 - */ -export function stripExperimentalPrefixes( - compatFlags: string[] | undefined -): string[] | undefined { - return compatFlags?.map((flag) => flag.replace(/^experimental:/, "")); -} diff --git a/packages/wrangler/src/dev/miniflare.ts b/packages/wrangler/src/dev/miniflare.ts index 8a4b95c9e5c0..1b76aad62f00 100644 --- a/packages/wrangler/src/dev/miniflare.ts +++ b/packages/wrangler/src/dev/miniflare.ts @@ -18,7 +18,6 @@ import { } from "../ai/fetcher"; import { readConfig } from "../config"; import { ModuleTypeToRuleType } from "../deployment-bundle/module-collection"; -import { stripExperimentalPrefixes } from "../deployment-bundle/node-compat"; import { withSourceURLs } from "../deployment-bundle/source-url"; import { UserError } from "../errors"; import { logger } from "../logger"; @@ -892,9 +891,7 @@ export async function buildMiniflareOptions( { name: getName(config), compatibilityDate: config.compatibilityDate, - compatibilityFlags: stripExperimentalPrefixes( - config.compatibilityFlags - ), + compatibilityFlags: config.compatibilityFlags, ...sourceOptions, ...bindingOptions, diff --git a/packages/wrangler/src/dev/remote.tsx b/packages/wrangler/src/dev/remote.tsx index 8f2268ddcfc0..189913214b63 100644 --- a/packages/wrangler/src/dev/remote.tsx +++ b/packages/wrangler/src/dev/remote.tsx @@ -7,7 +7,6 @@ import { useErrorHandler } from "react-error-boundary"; import { helpIfErrorIsSizeOrScriptStartup } from "../deploy/deploy"; import { printBundleSize } from "../deployment-bundle/bundle-reporter"; import { getBundleType } from "../deployment-bundle/bundle-type"; -import { stripExperimentalPrefixes } from "../deployment-bundle/node-compat"; import { withSourceURLs } from "../deployment-bundle/source-url"; import { getInferredHost } from "../dev"; import { UserError } from "../errors"; @@ -669,7 +668,7 @@ export async function createRemoteWorkerInit(props: { }, migrations: undefined, // no migrations in dev compatibility_date: props.compatibilityDate, - compatibility_flags: stripExperimentalPrefixes(props.compatibilityFlags), + compatibility_flags: props.compatibilityFlags, keepVars: true, keepSecrets: true, logpush: false, From 16598c67bb485b1bb01b901a08b6ed1e6fe92000 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Wed, 21 Aug 2024 15:24:50 +0100 Subject: [PATCH 2/5] PR review updates 2 --- .changeset/green-lies-crash.md | 2 +- packages/wrangler/src/deployment-bundle/node-compat.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.changeset/green-lies-crash.md b/.changeset/green-lies-crash.md index f3bdf5a0090f..2015220c0301 100644 --- a/.changeset/green-lies-crash.md +++ b/.changeset/green-lies-crash.md @@ -4,4 +4,4 @@ fix: remove `experimental:` prefix requirement for nodejs_compat_v2 -See https://jira.cfdata.org/bro +See https://jira.cfdata.org/browse/DEVDASH-218 diff --git a/packages/wrangler/src/deployment-bundle/node-compat.ts b/packages/wrangler/src/deployment-bundle/node-compat.ts index 1c17f9085413..34a088f69685 100644 --- a/packages/wrangler/src/deployment-bundle/node-compat.ts +++ b/packages/wrangler/src/deployment-bundle/node-compat.ts @@ -17,10 +17,10 @@ export type NodeJSCompatMode = "legacy" | "v1" | "v2" | null; * Returns one of: * - "legacy": build-time polyfills, from `node_compat` flag * - "v1": nodejs_compat compatibility flag - * - "v2": experimental nodejs_compat_v2 flag + * - "v2": nodejs_compat_v2 compatibility flag * - null: no Node.js compatibility * - * Currently we require that the v2 mode is configured via `nodejs_compat_v2` compat flag. + * Currently v2 mode is configured via `nodejs_compat_v2` compat flag. * At a future compatibility date, the use of `nodejs_compat` flag will imply `nodejs_compat_v2`. * * We assert that only one of these modes can be specified at a time. From 1cbc70e8c5fa0b9d533129c97eb75efec875a6f6 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Wed, 21 Aug 2024 15:34:32 +0100 Subject: [PATCH 3/5] PR review udpdates --- packages/wrangler/src/deployment-bundle/node-compat.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/wrangler/src/deployment-bundle/node-compat.ts b/packages/wrangler/src/deployment-bundle/node-compat.ts index 34a088f69685..987e9da59518 100644 --- a/packages/wrangler/src/deployment-bundle/node-compat.ts +++ b/packages/wrangler/src/deployment-bundle/node-compat.ts @@ -78,6 +78,7 @@ export function getNodeCompatMode({ compatibility_flags, node_compat, }: Pick) { + const legacy = node_compat === true; const nodejsCompat = compatibility_flags.includes("nodejs_compat"); const nodejsCompatV2 = compatibility_flags.includes("nodejs_compat_v2"); @@ -86,14 +87,14 @@ export function getNodeCompatMode({ mode = "v2"; } else if (nodejsCompat) { mode = "v1"; - } else if (node_compat) { + } else if (legacy) { mode = "legacy"; } else { mode = null; } return { - legacy: node_compat === true, + legacy, mode, nodejsCompat, nodejsCompatV2, From 64a8048c039bfecd9245693986080a89b43cb4a6 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 22 Aug 2024 11:18:08 +0100 Subject: [PATCH 4/5] add error message for invalid use of `experimental` prefix --- .../src/deployment-bundle/node-compat.ts | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/packages/wrangler/src/deployment-bundle/node-compat.ts b/packages/wrangler/src/deployment-bundle/node-compat.ts index 987e9da59518..db654e2cc93d 100644 --- a/packages/wrangler/src/deployment-bundle/node-compat.ts +++ b/packages/wrangler/src/deployment-bundle/node-compat.ts @@ -27,50 +27,53 @@ export type NodeJSCompatMode = "legacy" | "v1" | "v2" | null; * We assert that you must prefix v2 mode with `experimental`. * We warn if using legacy or v2 mode. */ -export function validateNodeCompat({ - legacyNodeCompat, - compatibilityFlags, - noBundle, -}: { - legacyNodeCompat: boolean; - /* mutate */ compatibilityFlags: string[]; - noBundle: boolean; -}): NodeJSCompatMode { - if (legacyNodeCompat) { - logger.warn( - "Enabling Wrangler compile-time Node.js compatibility polyfill mode for builtins and globals. This is experimental and has serious tradeoffs." +export function validateNodeCompat( + config: Pick +): NodeJSCompatMode { + const { + mode, + nodejsCompat, + nodejsCompatV2, + experimentalNodejsCompatV2, + legacy, + } = getNodeCompatMode(config); + + if (experimentalNodejsCompatV2) { + throw new UserError( + "The `experimental:` prefix on `nodejs_compat_v2` is no longer valid. Please remove it and try again." ); } - const { mode, nodejsCompat, nodejsCompatV2 } = getNodeCompatMode({ - compatibility_flags: compatibilityFlags, - node_compat: legacyNodeCompat, - }); - if (nodejsCompat && nodejsCompatV2) { throw new UserError( "The `nodejs_compat` and `nodejs_compat_v2` compatibility flags cannot be used in together. Please select just one." ); } - if (legacyNodeCompat && (nodejsCompat || nodejsCompatV2)) { + if (legacy && (nodejsCompat || nodejsCompatV2)) { throw new UserError( `The ${nodejsCompat ? "`nodejs_compat`" : "`nodejs_compat_v2`"} compatibility flag cannot be used in conjunction with the legacy \`--node-compat\` flag. If you want to use the Workers ${nodejsCompat ? "`nodejs_compat`" : "`nodejs_compat_v2`"} compatibility flag, please remove the \`--node-compat\` argument from your CLI command or \`node_compat = true\` from your config file.` ); } - if (noBundle && legacyNodeCompat) { + if (config.no_bundle && legacy) { logger.warn( "`--node-compat` and `--no-bundle` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process." ); } - if (noBundle && nodejsCompatV2) { + if (config.no_bundle && nodejsCompatV2) { logger.warn( "`nodejs_compat_v2` compatibility flag and `--no-bundle` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process." ); } + if (mode === "legacy") { + logger.warn( + "Enabling Wrangler compile-time Node.js compatibility polyfill mode for builtins and globals. This is experimental and has serious tradeoffs." + ); + } + return mode; } @@ -81,6 +84,9 @@ export function getNodeCompatMode({ const legacy = node_compat === true; const nodejsCompat = compatibility_flags.includes("nodejs_compat"); const nodejsCompatV2 = compatibility_flags.includes("nodejs_compat_v2"); + const experimentalNodejsCompatV2 = compatibility_flags.includes( + "experimental:nodejs_compat_v2" + ); let mode: NodeJSCompatMode; if (nodejsCompatV2) { @@ -98,5 +104,6 @@ export function getNodeCompatMode({ mode, nodejsCompat, nodejsCompatV2, + experimentalNodejsCompatV2, }; } From 8cb9690b41dd0a8455d29f24aaf93e46fe3ba4f3 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 22 Aug 2024 13:32:12 +0100 Subject: [PATCH 5/5] reworking parameters after feedback --- .../wrangler/src/__tests__/deploy.test.ts | 8 ++--- packages/wrangler/src/api/pages/deploy.tsx | 11 +++--- packages/wrangler/src/deploy/deploy.ts | 8 ++--- .../src/deployment-bundle/node-compat.ts | 27 +++++++------- packages/wrangler/src/dev.tsx | 35 ++++++++----------- packages/wrangler/src/pages/build.ts | 12 +++---- packages/wrangler/src/pages/dev.ts | 11 +++--- .../wrangler/src/type-generation/index.ts | 5 ++- packages/wrangler/src/versions/upload.ts | 10 +++--- pnpm-lock.yaml | 2 +- 10 files changed, 63 insertions(+), 66 deletions(-) diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index f9e4bb9b4bb5..f0a95a195981 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -9845,10 +9845,10 @@ export default{ "deploy index.js --no-bundle --node-compat --dry-run --outdir dist" ); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Enabling Wrangler compile-time Node.js compatibility polyfill mode for builtins and globals. This is experimental and has serious tradeoffs. + "▲ [WARNING] \`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process. - ▲ [WARNING] \`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process. + ▲ [WARNING] Enabling Wrangler compile-time Node.js compatibility polyfill mode for builtins and globals. This is experimental and has serious tradeoffs. " `); @@ -9865,10 +9865,10 @@ export default{ fs.writeFileSync("index.js", scriptContent); await runWrangler("deploy index.js --dry-run --outdir dist"); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Enabling Wrangler compile-time Node.js compatibility polyfill mode for builtins and globals. This is experimental and has serious tradeoffs. + "▲ [WARNING] \`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process. - ▲ [WARNING] \`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process. + ▲ [WARNING] Enabling Wrangler compile-time Node.js compatibility polyfill mode for builtins and globals. This is experimental and has serious tradeoffs. " `); diff --git a/packages/wrangler/src/api/pages/deploy.tsx b/packages/wrangler/src/api/pages/deploy.tsx index be0e8dc71785..b73faff9105e 100644 --- a/packages/wrangler/src/api/pages/deploy.tsx +++ b/packages/wrangler/src/api/pages/deploy.tsx @@ -174,12 +174,11 @@ export async function deploy({ } } - const nodejsCompatMode = validateNodeCompat({ - legacyNodeCompat: false, - compatibilityFlags: - config?.compatibility_flags ?? deploymentConfig.compatibility_flags ?? [], - noBundle: config?.no_bundle ?? false, - }); + const nodejsCompatMode = validateNodeCompat( + config?.compatibility_flags ?? deploymentConfig.compatibility_flags ?? [], + /* node_compat */ false, + config?.no_bundle + ); const defineNavigatorUserAgent = isNavigatorDefined( config?.compatibility_date ?? deploymentConfig.compatibility_date, config?.compatibility_flags ?? deploymentConfig.compatibility_flags diff --git a/packages/wrangler/src/deploy/deploy.ts b/packages/wrangler/src/deploy/deploy.ts index 84bfaf9d067e..8b1de92abfec 100644 --- a/packages/wrangler/src/deploy/deploy.ts +++ b/packages/wrangler/src/deploy/deploy.ts @@ -397,11 +397,11 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m const compatibilityFlags = props.compatibilityFlags ?? config.compatibility_flags; - const nodejsCompatMode = validateNodeCompat({ - legacyNodeCompat: props.nodeCompat ?? config.node_compat ?? false, + const nodejsCompatMode = validateNodeCompat( compatibilityFlags, - noBundle: props.noBundle ?? config.no_bundle ?? false, - }); + props.nodeCompat ?? config.node_compat, + props.noBundle ?? config.no_bundle + ); // Warn if user tries minify with no-bundle if (props.noBundle && minify) { diff --git a/packages/wrangler/src/deployment-bundle/node-compat.ts b/packages/wrangler/src/deployment-bundle/node-compat.ts index db654e2cc93d..d2b4c03147bd 100644 --- a/packages/wrangler/src/deployment-bundle/node-compat.ts +++ b/packages/wrangler/src/deployment-bundle/node-compat.ts @@ -1,6 +1,5 @@ import { UserError } from "../errors"; import { logger } from "../logger"; -import type { Config } from "../config"; /** * Wrangler can provide Node.js compatibility in a number of different modes: @@ -28,7 +27,9 @@ export type NodeJSCompatMode = "legacy" | "v1" | "v2" | null; * We warn if using legacy or v2 mode. */ export function validateNodeCompat( - config: Pick + compatibilityFlags: string[], + nodeCompat: boolean | undefined, + noBundle: boolean | undefined ): NodeJSCompatMode { const { mode, @@ -36,7 +37,7 @@ export function validateNodeCompat( nodejsCompatV2, experimentalNodejsCompatV2, legacy, - } = getNodeCompatMode(config); + } = getNodeCompatMode(compatibilityFlags, nodeCompat); if (experimentalNodejsCompatV2) { throw new UserError( @@ -56,13 +57,13 @@ export function validateNodeCompat( ); } - if (config.no_bundle && legacy) { + if (noBundle && legacy) { logger.warn( "`--node-compat` and `--no-bundle` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process." ); } - if (config.no_bundle && nodejsCompatV2) { + if (noBundle && nodejsCompatV2) { logger.warn( "`nodejs_compat_v2` compatibility flag and `--no-bundle` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process." ); @@ -77,14 +78,14 @@ export function validateNodeCompat( return mode; } -export function getNodeCompatMode({ - compatibility_flags, - node_compat, -}: Pick) { - const legacy = node_compat === true; - const nodejsCompat = compatibility_flags.includes("nodejs_compat"); - const nodejsCompatV2 = compatibility_flags.includes("nodejs_compat_v2"); - const experimentalNodejsCompatV2 = compatibility_flags.includes( +export function getNodeCompatMode( + compatibilityFlags: string[], + nodeCompat: boolean | undefined +) { + const legacy = nodeCompat === true; + const nodejsCompat = compatibilityFlags.includes("nodejs_compat"); + const nodejsCompatV2 = compatibilityFlags.includes("nodejs_compat_v2"); + const experimentalNodejsCompatV2 = compatibilityFlags.includes( "experimental:nodejs_compat_v2" ); diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index 4da5e0908a64..af6fdfe3a753 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -686,15 +686,11 @@ export async function startDev(args: StartDevOptions) { moduleRoot: args.moduleRoot, moduleRules: args.rules, nodejsCompatMode: (parsedConfig: Config) => - validateNodeCompat({ - legacyNodeCompat: - args.nodeCompat ?? parsedConfig.node_compat ?? false, - compatibilityFlags: - args.compatibilityFlags ?? - parsedConfig.compatibility_flags ?? - [], - noBundle: args.noBundle ?? parsedConfig.no_bundle ?? false, - }), + validateNodeCompat( + args.compatibilityFlags ?? parsedConfig.compatibility_flags ?? [], + args.nodeCompat ?? parsedConfig.node_compat, + args.noBundle ?? parsedConfig.no_bundle + ), }, bindings: { ...(await getPagesAssetsFetcher( @@ -839,12 +835,11 @@ export async function startDev(args: StartDevOptions) { additionalModules, } = await validateDevServerSettings(args, config); - const nodejsCompatMode = validateNodeCompat({ - legacyNodeCompat: args.nodeCompat ?? config.node_compat ?? false, - compatibilityFlags: - args.compatibilityFlags ?? config.compatibility_flags ?? [], - noBundle: args.noBundle ?? config.no_bundle ?? false, - }); + const nodejsCompatMode = validateNodeCompat( + args.compatibilityFlags ?? config.compatibility_flags ?? [], + args.nodeCompat ?? config.node_compat, + args.noBundle ?? config.no_bundle + ); void metrics.sendMetricsEvent( "run dev", @@ -979,11 +974,11 @@ export async function startApiDev(args: StartDevOptions) { additionalModules, } = await validateDevServerSettings(args, config); - const nodejsCompatMode = validateNodeCompat({ - legacyNodeCompat: args.nodeCompat ?? config.node_compat ?? false, - compatibilityFlags: args.compatibilityFlags ?? config.compatibility_flags, - noBundle: args.noBundle ?? config.no_bundle ?? false, - }); + const nodejsCompatMode = validateNodeCompat( + args.compatibilityFlags ?? config.compatibility_flags, + args.nodeCompat ?? config.node_compat, + args.noBundle ?? config.no_bundle + ); await metrics.sendMetricsEvent( "run dev (api)", diff --git a/packages/wrangler/src/pages/build.ts b/packages/wrangler/src/pages/build.ts index dcd7112730be..1e4f4ebf76ad 100644 --- a/packages/wrangler/src/pages/build.ts +++ b/packages/wrangler/src/pages/build.ts @@ -437,12 +437,12 @@ const validateArgs = async (args: PagesBuildArgs): Promise => { args.outfile = resolvePath(args.outfile); } - const { nodeCompat: legacyNodeCompat, ...argsExceptNodeCompat } = args; - const nodejsCompatMode = validateNodeCompat({ - legacyNodeCompat: legacyNodeCompat, - compatibilityFlags: args.compatibilityFlags ?? [], - noBundle: config?.no_bundle ?? false, - }); + const { nodeCompat: node_compat, ...argsExceptNodeCompat } = args; + const nodejsCompatMode = validateNodeCompat( + args.compatibilityFlags ?? [], + node_compat, + config?.no_bundle + ); const defineNavigatorUserAgent = isNavigatorDefined( args.compatibilityDate, diff --git a/packages/wrangler/src/pages/dev.ts b/packages/wrangler/src/pages/dev.ts index b5a2e9c106a8..077804758d32 100644 --- a/packages/wrangler/src/pages/dev.ts +++ b/packages/wrangler/src/pages/dev.ts @@ -360,12 +360,11 @@ export const Handler = async (args: PagesDevArguments) => { let scriptPath = ""; - const nodejsCompatMode = validateNodeCompat({ - legacyNodeCompat: args.nodeCompat, - compatibilityFlags: - args.compatibilityFlags ?? config.compatibility_flags ?? [], - noBundle: args.noBundle ?? config.no_bundle ?? false, - }); + const nodejsCompatMode = validateNodeCompat( + args.compatibilityFlags ?? config.compatibility_flags ?? [], + args.nodeCompat, + args.noBundle ?? config.no_bundle + ); const defineNavigatorUserAgent = isNavigatorDefined( compatibilityDate, diff --git a/packages/wrangler/src/type-generation/index.ts b/packages/wrangler/src/type-generation/index.ts index 36167de5d837..d865abef7be0 100644 --- a/packages/wrangler/src/type-generation/index.ts +++ b/packages/wrangler/src/type-generation/index.ts @@ -92,7 +92,10 @@ export async function typesHandler( const tsconfigPath = config.tsconfig ?? join(dirname(configPath), "tsconfig.json"); const tsconfigTypes = readTsconfigTypes(tsconfigPath); - const { mode } = getNodeCompatMode(config); + const { mode } = getNodeCompatMode( + config.compatibility_flags, + config.node_compat + ); logRuntimeTypesMessage(outFile, tsconfigTypes, mode !== null); } diff --git a/packages/wrangler/src/versions/upload.ts b/packages/wrangler/src/versions/upload.ts index cf9025d19db6..a09d3ea1d070 100644 --- a/packages/wrangler/src/versions/upload.ts +++ b/packages/wrangler/src/versions/upload.ts @@ -184,11 +184,11 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m const minify = props.minify ?? config.minify; - const nodejsCompatMode = validateNodeCompat({ - legacyNodeCompat: props.nodeCompat ?? config.node_compat ?? false, - compatibilityFlags: props.compatibilityFlags ?? config.compatibility_flags, - noBundle: props.noBundle ?? config.no_bundle ?? false, - }); + const nodejsCompatMode = validateNodeCompat( + props.compatibilityFlags ?? config.compatibility_flags, + props.nodeCompat ?? config.node_compat, + props.noBundle ?? config.no_bundle + ); const compatibilityFlags = props.compatibilityFlags ?? config.compatibility_flags; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0644ea05bb26..03b1c1958f85 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11195,7 +11195,7 @@ snapshots: dependencies: '@typescript-eslint/typescript-estree': 6.10.0(typescript@5.5.4) '@typescript-eslint/utils': 6.10.0(eslint@8.49.0)(typescript@5.5.4) - debug: 4.3.6(supports-color@9.2.2) + debug: 4.3.5 eslint: 8.49.0 ts-api-utils: 1.0.3(typescript@5.5.4) optionalDependencies: