Skip to content

Commit

Permalink
Internally rename nodeCompat to legacyNodeCompat
Browse files Browse the repository at this point in the history
  • Loading branch information
GregBrimble committed Jan 12, 2023
1 parent 6a67efe commit ab63043
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 65 deletions.
2 changes: 1 addition & 1 deletion packages/wrangler/bin/wrangler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function runWrangler() {
// Note Volta and nvm are also recommended in the official docs:
// https://developers.cloudflare.com/workers/get-started/guide#2-install-the-workers-cli
console.error(
`Wrangler requires at least node.js v${MIN_NODE_VERSION}. You are using v${process.versions.node}. Please update your version of node.js.
`Wrangler requires at least Node.js v${MIN_NODE_VERSION}. You are using v${process.versions.node}. Please update your version of Node.js.
Consider using a Node.js version manager such as https://volta.sh/ or https://github.com/nvm-sh/nvm.`
);
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/__tests__/dev.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ describe("wrangler dev", () => {
--experimental-local Run on my machine using the Cloudflare Workers runtime [boolean] [default: false]
--experimental-local-remote-kv Read/write KV data from/to real namespaces on the Cloudflare network [boolean] [default: false]
--minify Minify the script [boolean]
--node-compat Enable node.js compatibility [boolean]
--node-compat Enable Node.js compatibility [boolean]
--persist Enable persistence for local mode, using default path: .wrangler/state [boolean]
--persist-to Specify directory to use for local persistence (implies --persist) [string]
--live-reload Auto reload HTML pages when change is detected in local mode [boolean]
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/__tests__/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6513,7 +6513,7 @@ addEventListener('fetch', event => {});`
"err": "",
"out": "Total Upload: xx KiB / gzip: xx KiB
--dry-run: exiting now.",
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
",
}
Expand Down Expand Up @@ -6560,7 +6560,7 @@ addEventListener('fetch', event => {});`
"err": "",
"out": "Total Upload: xx KiB / gzip: xx KiB
--dry-run: exiting now.",
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
",
}
Expand Down Expand Up @@ -6978,7 +6978,7 @@ addEventListener('fetch', event => {});`
"publish index.js --no-bundle --node-compat --dry-run --outdir dist"
);
expect(std.warn).toMatchInlineSnapshot(`
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
▲ [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.
Expand All @@ -6998,7 +6998,7 @@ addEventListener('fetch', event => {});`
fs.writeFileSync("index.js", scriptContent);
await runWrangler("publish index.js --dry-run --outdir dist");
expect(std.warn).toMatchInlineSnapshot(`
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mEnabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.[0m
▲ [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.
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/__tests__/test-old-node-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const wranglerProcess = spawn(
{ stdio: "pipe" }
);

const messageToMatch = "Wrangler requires at least node.js v16.13.0";
const messageToMatch = "Wrangler requires at least Node.js v16.13.0";

wranglerProcess.once("exit", (code) => {
try {
Expand All @@ -25,7 +25,7 @@ wranglerProcess.once("exit", (code) => {
} catch (err) {
console.error("Error:", err);
throw new Error(
"This test has to be run with a version of node.js under 16.13 to pass"
"This test has to be run with a version of Node.js under 16.13 to pass"
);
}
});
11 changes: 6 additions & 5 deletions packages/wrangler/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export async function bundleWorker(
watch?: esbuild.WatchMode | boolean;
tsconfig?: string;
minify?: boolean;
nodeCompat?: boolean;
legacyNodeCompat?: boolean;
define: Config["define"];
checkFetch: boolean;
services?: Config["services"];
Expand Down Expand Up @@ -129,7 +129,7 @@ export async function bundleWorker(
watch,
tsconfig,
minify,
nodeCompat,
legacyNodeCompat,
checkFetch,
local,
assets,
Expand Down Expand Up @@ -338,7 +338,7 @@ export async function bundleWorker(
// use process.env["NODE_ENV" + ""] so that esbuild doesn't replace it
// when we do a build of wrangler. (re: https://github.com/cloudflare/wrangler2/issues/1477)
"process.env.NODE_ENV": `"${process.env["NODE_ENV" + ""]}"`,
...(nodeCompat ? { global: "globalThis" } : {}),
...(legacyNodeCompat ? { global: "globalThis" } : {}),
...(checkFetch ? { fetch: "checkedFetch" } : {}),
...options.define,
},
Expand All @@ -351,7 +351,7 @@ export async function bundleWorker(
},
plugins: [
moduleCollector.plugin,
...(nodeCompat
...(legacyNodeCompat
? [NodeGlobalsPolyfills({ buffer: true }), NodeModulesPolyfills()]
: []),
...(plugins || []),
Expand All @@ -369,7 +369,8 @@ export async function bundleWorker(
try {
result = await esbuild.build(buildOptions);
} catch (e) {
if (!nodeCompat && isBuildFailure(e)) rewriteNodeCompatBuildFailure(e);
if (!legacyNodeCompat && isBuildFailure(e))
rewriteNodeCompatBuildFailure(e);
throw e;
}

Expand Down
18 changes: 9 additions & 9 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
type: "boolean",
})
.option("node-compat", {
describe: "Enable node.js compatibility",
describe: "Enable Node.js compatibility",
type: "boolean",
})
.option("experimental-enable-local-persistence", {
Expand Down Expand Up @@ -421,7 +421,7 @@ export async function startDev(args: StartDevOptions) {

const {
entry,
nodeCompat,
legacyNodeCompat,
upstreamProtocol,
zoneId,
host,
Expand Down Expand Up @@ -460,7 +460,7 @@ export async function startDev(args: StartDevOptions) {
rules={getRules(configParam)}
legacyEnv={isLegacyEnv(configParam)}
minify={args.minify ?? configParam.minify}
nodeCompat={nodeCompat}
legacyNodeCompat={legacyNodeCompat}
build={configParam.build || {}}
define={{ ...configParam.define, ...cliDefines }}
initialMode={
Expand Down Expand Up @@ -558,7 +558,7 @@ export async function startApiDev(args: StartDevOptions) {

const {
entry,
nodeCompat,
legacyNodeCompat,
upstreamProtocol,
zoneId,
host,
Expand Down Expand Up @@ -597,7 +597,7 @@ export async function startApiDev(args: StartDevOptions) {
rules: getRules(configParam),
legacyEnv: isLegacyEnv(configParam),
minify: args.minify ?? configParam.minify,
nodeCompat: nodeCompat,
legacyNodeCompat,
build: configParam.build || {},
define: { ...config.define, ...cliDefines },
initialMode: args.local ? "local" : "remote",
Expand Down Expand Up @@ -780,10 +780,10 @@ async function validateDevServerSettings(
"https://github.com/cloudflare/wrangler2/issues/583."
);
}
const nodeCompat = args.nodeCompat ?? config.node_compat;
if (nodeCompat) {
const legacyNodeCompat = args.nodeCompat ?? config.node_compat;
if (legacyNodeCompat) {
logger.warn(
"Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
"Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
);
}

Expand All @@ -806,7 +806,7 @@ async function validateDevServerSettings(
return {
entry,
upstreamProtocol,
nodeCompat,
legacyNodeCompat,
getLocalPort,
getInspectorPort,
zoneId,
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/dev/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export type DevProps = {
compatibilityFlags: string[] | undefined;
usageModel: "bundled" | "unbound" | undefined;
minify: boolean | undefined;
nodeCompat: boolean | undefined;
legacyNodeCompat: boolean | undefined;
build: Config["build"];
env: string | undefined;
legacyEnv: boolean;
Expand Down Expand Up @@ -292,7 +292,7 @@ function DevSession(props: DevSessionProps) {
),
tsconfig: props.tsconfig,
minify: props.minify,
nodeCompat: props.nodeCompat,
legacyNodeCompat: props.legacyNodeCompat,
betaD1Shims,
define: props.define,
noBundle: props.noBundle,
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/dev/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function startDevServer(
),
tsconfig: props.tsconfig,
minify: props.minify,
nodeCompat: props.nodeCompat,
legacyNodeCompat: props.legacyNodeCompat,
define: props.define,
noBundle: props.noBundle,
assets: props.assetsConfig,
Expand Down Expand Up @@ -209,7 +209,7 @@ async function runEsbuild({
serveAssetsFromWorker,
tsconfig,
minify,
nodeCompat,
legacyNodeCompat,
define,
noBundle,
workerDefinitions,
Expand All @@ -231,7 +231,7 @@ async function runEsbuild({
serveAssetsFromWorker: boolean;
tsconfig: string | undefined;
minify: boolean | undefined;
nodeCompat: boolean | undefined;
legacyNodeCompat: boolean | undefined;
noBundle: boolean;
workerDefinitions: WorkerRegistry;
firstPartyWorkerDevFacade: boolean | undefined;
Expand Down Expand Up @@ -263,7 +263,7 @@ async function runEsbuild({
rules,
tsconfig,
minify,
nodeCompat,
legacyNodeCompat,
define,
checkFetch: true,
assets: assets && {
Expand Down
10 changes: 5 additions & 5 deletions packages/wrangler/src/dev/use-esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function useEsbuild({
serveAssetsFromWorker,
tsconfig,
minify,
nodeCompat,
legacyNodeCompat,
betaD1Shims,
define,
noBundle,
Expand All @@ -54,7 +54,7 @@ export function useEsbuild({
serveAssetsFromWorker: boolean;
tsconfig: string | undefined;
minify: boolean | undefined;
nodeCompat: boolean | undefined;
legacyNodeCompat: boolean | undefined;
betaD1Shims?: string[];
noBundle: boolean;
workerDefinitions: WorkerRegistry;
Expand Down Expand Up @@ -85,7 +85,7 @@ export function useEsbuild({
const watchMode: WatchMode = {
async onRebuild(error) {
if (error !== null) {
if (!nodeCompat) rewriteNodeCompatBuildFailure(error);
if (!legacyNodeCompat) rewriteNodeCompatBuildFailure(error);
logBuildFailure(error);
logger.error("Watch build failed:", error.message);
} else {
Expand Down Expand Up @@ -121,7 +121,7 @@ export function useEsbuild({
watch: watchMode,
tsconfig,
minify,
nodeCompat,
legacyNodeCompat,
betaD1Shims,
define,
checkFetch: true,
Expand Down Expand Up @@ -187,7 +187,7 @@ export function useEsbuild({
exit,
noBundle,
minify,
nodeCompat,
legacyNodeCompat,
define,
assets,
services,
Expand Down
18 changes: 9 additions & 9 deletions packages/wrangler/src/pages/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function Options(yargs: Argv) {
description: "The directory to output static assets to",
},
"node-compat": {
describe: "Enable node.js compatibility",
describe: "Enable Node.js compatibility",
default: false,
type: "boolean",
hidden: true,
Expand All @@ -103,17 +103,17 @@ export const Handler = async ({
watch,
plugin,
buildOutputDirectory,
nodeCompat,
nodeCompat: legacyNodeCompat,
bindings,
}: PagesBuildArgs) => {
if (!isInPagesCI) {
// Beta message for `wrangler pages <commands>` usage
logger.log(pagesBetaWarning);
}

if (nodeCompat) {
if (legacyNodeCompat) {
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."
"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."
);
}

Expand All @@ -139,7 +139,7 @@ export const Handler = async ({
watch,
plugin,
buildOutputDirectory,
nodeCompat,
legacyNodeCompat,
routesOutputPath,
local: false,
d1Databases,
Expand Down Expand Up @@ -173,7 +173,7 @@ export async function buildFunctions({
plugin = false,
buildOutputDirectory,
routesOutputPath,
nodeCompat,
legacyNodeCompat,
local,
d1Databases,
}: Partial<
Expand All @@ -186,9 +186,9 @@ export async function buildFunctions({
| "watch"
| "plugin"
| "buildOutputDirectory"
| "nodeCompat"
>
> & {
legacyNodeCompat?: boolean;
functionsDirectory: string;
onEnd?: () => void;
outfile: Required<PagesBuildArgs>["outfile"];
Expand Down Expand Up @@ -242,7 +242,7 @@ export async function buildFunctions({
minify,
sourcemap,
watch,
nodeCompat,
legacyNodeCompat,
functionsDirectory: absoluteFunctionsDirectory,
local,
betaD1Shims: d1Databases,
Expand All @@ -263,7 +263,7 @@ export async function buildFunctions({
betaD1Shims: d1Databases,
onEnd,
buildOutputDirectory,
nodeCompat,
legacyNodeCompat,
})
);
}
Expand Down
Loading

0 comments on commit ab63043

Please sign in to comment.