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

Add --node-compat to Pages publish #2541

Closed
wants to merge 2 commits into from
Closed
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/happy-trees-check.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 18 additions & 0 deletions packages/wrangler/src/api/pages/deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -94,6 +99,7 @@ export async function deploy({
commitDirty,
functionsDirectory: customFunctionsDirectory,
bundle,
nodeCompat,
}: PagesDeployOptions) {
let _headers: string | undefined,
_redirects: string | undefined,
Expand Down Expand Up @@ -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,
Expand All @@ -174,6 +191,7 @@ export async function deploy({
buildOutputDirectory: directory,
routesOutputPath,
local: false,
legacyNodeCompat: nodeCompat,
nodejsCompat,
});

Expand Down
1 change: 0 additions & 1 deletion packages/wrangler/src/pages/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions packages/wrangler/src/pages/deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export function Options(yargs: CommonYargsArgv) {
type: "string",
hidden: true,
},
"node-compat": {
describe: "Enable node.js compatibility",
default: false,
type: "boolean",
},
});
}

Expand All @@ -86,6 +91,7 @@ export const Handler = async ({
bundle,
noBundle,
config: wranglerConfig,
nodeCompat,
}: PublishArgs) => {
// Check for deprecated `wrangler pages publish` command
if (_[1] === "publish") {
Expand Down Expand Up @@ -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<PagesConfigCache>(PAGES_CONFIG_CACHE_FILENAME, {
Expand Down
1 change: 0 additions & 1 deletion packages/wrangler/src/pages/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down