From 45e0386b126eece43ee63c4477a218170c7ccd62 Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Thu, 12 Jan 2023 23:57:30 +0000 Subject: [PATCH 1/2] Add --node-compat to Pages publish --- .changeset/happy-trees-check.md | 5 +++++ packages/wrangler/src/pages/build.ts | 1 - packages/wrangler/src/pages/dev.ts | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .changeset/happy-trees-check.md diff --git a/.changeset/happy-trees-check.md b/.changeset/happy-trees-check.md new file mode 100644 index 000000000000..ebfa34e4f915 --- /dev/null +++ b/.changeset/happy-trees-check.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Add support for `--node-compat` when running `wrangler pages publish`. Support for CI will be coming in the future. diff --git a/packages/wrangler/src/pages/build.ts b/packages/wrangler/src/pages/build.ts index e50f288c5053..8dbde102d142 100644 --- a/packages/wrangler/src/pages/build.ts +++ b/packages/wrangler/src/pages/build.ts @@ -83,7 +83,6 @@ export function Options(yargs: CommonYargsArgv) { describe: "Enable Node.js compatibility", default: false, type: "boolean", - hidden: true, }, "compatibility-date": { describe: "Date to use for compatibility checks", diff --git a/packages/wrangler/src/pages/dev.ts b/packages/wrangler/src/pages/dev.ts index 95c144a0f0f4..c83dcada1d1a 100644 --- a/packages/wrangler/src/pages/dev.ts +++ b/packages/wrangler/src/pages/dev.ts @@ -179,7 +179,6 @@ export function Options(yargs: CommonYargsArgv) { describe: "Enable Node.js compatibility", default: false, type: "boolean", - hidden: true, }, "experimental-local": { describe: "Run on my machine using the Cloudflare Workers runtime", From 2bc6376c17ed7859df28718cbbdd648c0f2ccd12 Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Tue, 31 Oct 2023 19:22:46 +0000 Subject: [PATCH 2/2] Rebase --- packages/wrangler/src/api/pages/deploy.tsx | 18 ++++++++++++++++++ packages/wrangler/src/pages/deploy.tsx | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/packages/wrangler/src/api/pages/deploy.tsx b/packages/wrangler/src/api/pages/deploy.tsx index 7327b0268b38..326789a8b11b 100644 --- a/packages/wrangler/src/api/pages/deploy.tsx +++ b/packages/wrangler/src/api/pages/deploy.tsx @@ -76,6 +76,11 @@ interface PagesDeployOptions { // TODO: Allow passing in the API key and plumb it through // to the API calls so that the deploy function does not // rely on the `CLOUDFLARE_API_KEY` environment variable + + /** + * Whether or not to polyfill Node.js APIs + */ + nodeCompat?: boolean; } /** @@ -94,6 +99,7 @@ export async function deploy({ commitDirty, functionsDirectory: customFunctionsDirectory, bundle, + nodeCompat, }: PagesDeployOptions) { let _headers: string | undefined, _redirects: string | undefined, @@ -166,6 +172,17 @@ export async function deploy({ `functions-filepath-routing-config-${Math.random()}.json` ); + if (nodeCompat) { + if (nodejsCompat) { + console.error('You cannot use both the legacy node-compat and the compatibility flag nodejs_compat.'); + process.exit(1); + } + + console.warn( + "Enabling node.js compatibility mode for builtins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details." + ); + } + try { workerBundle = await buildFunctions({ outputConfigPath, @@ -174,6 +191,7 @@ export async function deploy({ buildOutputDirectory: directory, routesOutputPath, local: false, + legacyNodeCompat: nodeCompat, nodejsCompat, }); diff --git a/packages/wrangler/src/pages/deploy.tsx b/packages/wrangler/src/pages/deploy.tsx index 2da6a071f338..7ed7aa7161df 100644 --- a/packages/wrangler/src/pages/deploy.tsx +++ b/packages/wrangler/src/pages/deploy.tsx @@ -71,6 +71,11 @@ export function Options(yargs: CommonYargsArgv) { type: "string", hidden: true, }, + "node-compat": { + describe: "Enable node.js compatibility", + default: false, + type: "boolean", + }, }); } @@ -86,6 +91,7 @@ export const Handler = async ({ bundle, noBundle, config: wranglerConfig, + nodeCompat, }: PublishArgs) => { // Check for deprecated `wrangler pages publish` command if (_[1] === "publish") { @@ -260,6 +266,7 @@ export const Handler = async ({ // TODO: Here lies a known bug. If you specify both `--bundle` and `--no-bundle`, this behavior is undefined and you will get unexpected results. // There is no sane way to get the true value out of yargs, so here we are. bundle: bundle ?? !noBundle, + nodeCompat, }); saveToConfigCache(PAGES_CONFIG_CACHE_FILENAME, {