diff --git a/.changeset/clever-timers-teach.md b/.changeset/clever-timers-teach.md new file mode 100644 index 0000000000000..abb83582d7478 --- /dev/null +++ b/.changeset/clever-timers-teach.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +chore: Rename `--bundle` to `--no-bundle` in Pages commands to make similar to Workers diff --git a/.changeset/warm-nails-clap.md b/.changeset/warm-nails-clap.md new file mode 100644 index 0000000000000..9c87977b4d2bb --- /dev/null +++ b/.changeset/warm-nails-clap.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +allow `fetch()` calls locally to accept URL Objects diff --git a/fixtures/pages-workerjs-app/tests/index.test.ts b/fixtures/pages-workerjs-app/tests/index.test.ts index 4f9a6764698d3..ac7e44e3b5d1d 100644 --- a/fixtures/pages-workerjs-app/tests/index.test.ts +++ b/fixtures/pages-workerjs-app/tests/index.test.ts @@ -16,13 +16,13 @@ describe.concurrent("Pages _worker.js", () => { ).toThrowError(); }); - it("should not throw an error when the _worker.js file imports something if --bundle is true", async ({ + it("should not throw an error when the _worker.js file imports something if --no-bundle is false", async ({ expect, }) => { const { ip, port, stop } = await runWranglerPagesDev( resolve(__dirname, ".."), "./workerjs-test", - ["--bundle"] + ["--no-bundle=false", "--port=0"] ); await expect( fetch(`http://${ip}:${port}/`).then((resp) => resp.text()) diff --git a/fixtures/shared/src/run-wrangler-long-lived.ts b/fixtures/shared/src/run-wrangler-long-lived.ts index f092ead49bd86..fb1a635aba1fe 100644 --- a/fixtures/shared/src/run-wrangler-long-lived.ts +++ b/fixtures/shared/src/run-wrangler-long-lived.ts @@ -39,12 +39,14 @@ async function runLongLivedWrangler(command: string[], cwd: string) { "../../packages/wrangler/bin/wrangler.js", command, { - stdio: ["ignore", "ignore", "ignore", "ipc"], + stdio: ["pipe", "pipe", "pipe", "ipc"], cwd, } ).on("message", (message) => { resolveReadyPromise(JSON.parse(message.toString())); }); + wranglerProcess.stderr?.on("data", (data) => console.log(`${data}`)); + wranglerProcess.stdout?.on("data", (data) => console.log(`${data}`)); async function stop() { return new Promise((resolve, reject) => { diff --git a/packages/wrangler/src/__tests__/pages.test.ts b/packages/wrangler/src/__tests__/pages.test.ts index 6b754f11f96d2..5071112ca99b1 100644 --- a/packages/wrangler/src/__tests__/pages.test.ts +++ b/packages/wrangler/src/__tests__/pages.test.ts @@ -351,7 +351,7 @@ describe("pages", () => { --commit-message The commit message to attach to this deployment [string] --commit-dirty Whether or not the workspace should be considered dirty for this deployment [boolean] --skip-caching Skip asset caching which speeds up builds [boolean] - --bundle Whether to run bundling on \`_worker.js\` before deploying [boolean] [default: false] + --no-bundle Whether to run bundling on \`_worker.js\` before deploying [boolean] [default: true] 🚧 'wrangler pages ' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose" `); diff --git a/packages/wrangler/src/pages/dev.ts b/packages/wrangler/src/pages/dev.ts index 9ec919590150a..8aeff7b785c44 100644 --- a/packages/wrangler/src/pages/dev.ts +++ b/packages/wrangler/src/pages/dev.ts @@ -79,9 +79,9 @@ export function Options(yargs: Argv) { description: "The location of the single Worker script if not using functions", }, - bundle: { + "no-bundle": { type: "boolean", - default: false, + default: true, description: "Whether to run bundling on `_worker.js`", }, binding: { @@ -168,7 +168,7 @@ export const Handler = async ({ "inspector-port": inspectorPort, proxy: requestedProxyPort, "script-path": singleWorkerScriptPath, - bundle, + noBundle, binding: bindings = [], kv: kvs = [], do: durableObjects = [], @@ -264,7 +264,7 @@ export const Handler = async ({ await checkRawWorker(workerScriptPath, () => scriptReadyResolve()); }; - if (bundle) { + if (!noBundle) { // We want to actually run the `_worker.js` script through the bundler // So update the final path to the script that will be uploaded and // change the `runBuild()` function to bundle the `_worker.js`. diff --git a/packages/wrangler/src/pages/publish.tsx b/packages/wrangler/src/pages/publish.tsx index feb7b39c459e1..d9bb84892f3eb 100644 --- a/packages/wrangler/src/pages/publish.tsx +++ b/packages/wrangler/src/pages/publish.tsx @@ -63,9 +63,9 @@ export function Options(yargs: Argv) { type: "boolean", description: "Skip asset caching which speeds up builds", }, - bundle: { + "no-bundle": { type: "boolean", - default: false, + default: true, description: "Whether to run bundling on `_worker.js` before deploying", }, config: { @@ -85,7 +85,7 @@ export const Handler = async ({ commitMessage, commitDirty, skipCaching, - bundle, + noBundle, config: wranglerConfig, }: PublishArgs) => { if (wranglerConfig) { @@ -384,7 +384,9 @@ export const Handler = async ({ */ if (_workerJS) { let workerFileContents = _workerJS; - if (bundle) { + if (noBundle) { + await checkRawWorker(workerScriptPath, () => {}); + } else { const outfile = join(tmpdir(), `./bundledWorker-${Math.random()}.mjs`); await buildRawWorker({ workerScriptPath, @@ -396,8 +398,6 @@ export const Handler = async ({ onEnd: () => {}, }); workerFileContents = readFileSync(outfile, "utf8"); - } else { - await checkRawWorker(workerScriptPath, () => {}); } formData.append("_worker.js", new File([workerFileContents], "_worker.js")); diff --git a/packages/wrangler/templates/checked-fetch.js b/packages/wrangler/templates/checked-fetch.js index 243f59ba2a0ff..64960e446c688 100644 --- a/packages/wrangler/templates/checked-fetch.js +++ b/packages/wrangler/templates/checked-fetch.js @@ -1,9 +1,7 @@ const urls = new Set(); export function checkedFetch(request, init) { - const url = new URL( - (typeof request === "string" ? new Request(request, init) : request).url - ); + const url = new URL(new Request(request, init).url); if (url.port && url.port !== "443" && url.protocol === "https:") { if (!urls.has(url.toString())) { urls.add(url.toString());