Skip to content
Merged
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
15 changes: 15 additions & 0 deletions .changeset/cyan-bugs-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"wrangler": patch
---

Add `versionCommand` to the `autoconfig_summary` field in the autoconfig output entry

Add the version upload command to the output being printed by `wrangler deploy` to `WRANGLER_OUTPUT_FILE_DIRECTORY`/`WRANGLER_OUTPUT_FILE_PATH`. This complements the existing `buildCommand` and `deployCommand` fields and allows CI systems to know how to upload new versions of Workers.

For example, for a standard npm project this would be:

- Version command: `npx wrangler versions upload`

While for a Next.js project it would be:

- Version command: `npx @opennextjs/cloudflare upload`
7 changes: 7 additions & 0 deletions .changeset/forty-yaks-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"create-cloudflare": patch
---

Simplify creating a new Astro app

The Astro CLI should not ask users whether they want to use git as create-cloudflare handles that already
8 changes: 8 additions & 0 deletions .changeset/grumpy-nails-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@cloudflare/vite-plugin": patch
---

Always emit a `.assetsignore` file in the client output directory.

Previously, we would emit a `.assetsignore` file in the client output directory only if the client output included a `wrangler.json` file.
We now always emit it, which prevents a `wrangler.json` file being deployed as an asset if it is copied into this directory by mistake.
11 changes: 10 additions & 1 deletion packages/containers-shared/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ import sharedConfig from "@cloudflare/eslint-config-shared";
import { defineConfig, globalIgnores } from "eslint/config";

// src/client/** is a generated client that we shouldn't lint
export default defineConfig(globalIgnores(["src/client/**"]), sharedConfig);
export default defineConfig([
globalIgnores(["src/client/**"]),
sharedConfig,
{
files: ["tests/**/*.test.ts"],
rules: {
"workers-sdk/no-vitest-import-expect": "error",
},
},
]);
16 changes: 11 additions & 5 deletions packages/containers-shared/tests/docker-context.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execFileSync } from "node:child_process";
import { UserError } from "@cloudflare/workers-utils";
import { afterEach, describe, expect, it, vi } from "vitest";
import { afterEach, describe, it, vi } from "vitest";
import { resolveDockerHost } from "../src/utils";

vi.mock("node:child_process");
Expand All @@ -13,7 +13,7 @@ describe.skipIf(process.platform !== "linux" && process.env.CI === "true")(
vi.unstubAllEnvs();
});

it("should return WRANGLER_DOCKER_HOST when set", async () => {
it("should return WRANGLER_DOCKER_HOST when set", async ({ expect }) => {
vi.stubEnv(
"WRANGLER_DOCKER_HOST",
"unix:///FROM/WRANGLER/DOCKER/HOST/wrangler/socket"
Expand All @@ -24,23 +24,29 @@ describe.skipIf(process.platform !== "linux" && process.env.CI === "true")(
expect(result).toBe("unix:///FROM/WRANGLER/DOCKER/HOST/wrangler/socket");
});

it("should return DOCKER_HOST when WRANGLER_DOCKER_HOST is not set", async () => {
it("should return DOCKER_HOST when WRANGLER_DOCKER_HOST is not set", async ({
expect,
}) => {
vi.stubEnv("WRANGLER_DOCKER_HOST", undefined);
vi.stubEnv("DOCKER_HOST", "unix:///FROM/DOCKER/HOST/docker/socket");

const result = resolveDockerHost("/no/op/docker");
expect(result).toBe("unix:///FROM/DOCKER/HOST/docker/socket");
});

it("should use Docker context when no env vars are set", async () => {
it("should use Docker context when no env vars are set", async ({
expect,
}) => {
vi.mocked(execFileSync)
.mockReturnValue(`{"Current":true,"Description":"Current DOCKER_HOST based configuration","DockerEndpoint":"unix:///FROM/CURRENT/CONTEXT/run/docker.sock","Error":"","Name":"default"}
{"Current":false,"Description":"Docker Desktop","DockerEndpoint":"unix:///FROM/OTHER/CONTEXT/run/docker.sock","Error":"","Name":"desktop-linux"}`);
const result = resolveDockerHost("/no/op/docker");
expect(result).toBe("unix:///FROM/CURRENT/CONTEXT/run/docker.sock");
});

it("should fall back to platform default when context fails", () => {
it("should fall back to platform default when context fails", ({
expect,
}) => {
vi.mocked(execFileSync).mockImplementation(() => {
throw new UserError("Docker command failed");
});
Expand Down
6 changes: 3 additions & 3 deletions packages/containers-shared/tests/knobs.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { describe, expect, it, vi } from "vitest";
import { describe, it, vi } from "vitest";
import { getCloudflareContainerRegistry } from "./../src/knobs";

describe("getCloudflareContainerRegistry", () => {
it("should return the managed registry", () => {
it("should return the managed registry", ({ expect }) => {
expect(getCloudflareContainerRegistry()).toBe("registry.cloudflare.com");
vi.stubEnv("WRANGLER_API_ENVIRONMENT", "production");
expect(getCloudflareContainerRegistry()).toBe("registry.cloudflare.com");
});

it("should return the staging registry", () => {
it("should return the staging registry", ({ expect }) => {
vi.stubEnv("WRANGLER_API_ENVIRONMENT", "staging");
expect(getCloudflareContainerRegistry()).toBe(
"staging.registry.cloudflare.com"
Expand Down
8 changes: 5 additions & 3 deletions packages/containers-shared/tests/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeEach, describe, it, vi } from "vitest";
import { checkExposedPorts } from "./../src/utils";
import type { ContainerDevOptions } from "../src/types";

Expand All @@ -21,14 +21,16 @@ describe("checkExposedPorts", () => {
docketImageInspectResult = "1";
});

it("should not error when some ports are exported", async () => {
it("should not error when some ports are exported", async ({ expect }) => {
docketImageInspectResult = "1";
await expect(
checkExposedPorts("docker", containerConfig)
).resolves.toBeUndefined();
});

it("should error, with an appropriate message when no ports are exported", async () => {
it("should error, with an appropriate message when no ports are exported", async ({
expect,
}) => {
docketImageInspectResult = "0";
await expect(checkExposedPorts("docker", containerConfig)).rejects
.toThrowErrorMatchingInlineSnapshot(`
Expand Down
20 changes: 2 additions & 18 deletions packages/create-cloudflare/e2e/tests/frameworks/test-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,7 @@ function getFrameworkTestConfig(pm: string): NamedFrameworkTestConfig[] {
expectedText: "C3_TEST",
},
nodeCompat: true,
flags: [
"--skip-houston",
"--no-install",
"--no-git",
"--template",
"blog",
"--typescript",
"strict",
],
flags: ["--skip-houston", "--template", "blog", "--typescript", "strict"],
},
{
name: "astro:workers",
Expand All @@ -84,15 +76,7 @@ function getFrameworkTestConfig(pm: string): NamedFrameworkTestConfig[] {
expectedText: "C3_TEST",
},
nodeCompat: true,
flags: [
"--skip-houston",
"--no-install",
"--no-git",
"--template",
"blog",
"--typescript",
"strict",
],
flags: ["--skip-houston", "--template", "blog", "--typescript", "strict"],
},
{
name: "docusaurus:pages",
Expand Down
15 changes: 10 additions & 5 deletions packages/create-cloudflare/templates/astro/pages/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ import type { C3Context, PackageJson } from "types";
const { npx } = detectPackageManager();

const generate = async (ctx: C3Context) => {
await runFrameworkGenerator(ctx, [ctx.project.name, "--no-install"]);
// `--add cloudflare` could be used here because it invokes `astro` which is not installed (`--no-install`)
// The adapter is added in the `configure` step instead
await runFrameworkGenerator(ctx, [
ctx.project.name,
// c3 will later install the dependencies
"--no-install",
// c3 will later ask users if they want to use git
"--no-git",
]);

logRaw(""); // newline
};
Expand All @@ -26,10 +34,7 @@ const configure = async () => {
)}`,
});

updateAstroConfig();
};

const updateAstroConfig = () => {
// Update Astro config to enable platformProxy and imageService
const filePath = "astro.config.mjs";

updateStatus(`Updating configuration in ${blue(filePath)}`);
Expand Down
15 changes: 10 additions & 5 deletions packages/create-cloudflare/templates/astro/workers/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ import type { C3Context, PackageJson } from "types";
const { npx } = detectPackageManager();

const generate = async (ctx: C3Context) => {
await runFrameworkGenerator(ctx, [ctx.project.name, "--no-install"]);
// `--add cloudflare` could be used here because it invokes `astro` which is not installed (`--no-install`)
// The adapter is added in the `configure` step instead
await runFrameworkGenerator(ctx, [
ctx.project.name,
// c3 will later install the dependencies
"--no-install",
// c3 will later ask users if they want to use git
"--no-git",
]);

logRaw(""); // newline
};
Expand All @@ -26,10 +34,7 @@ const configure = async () => {
)}`,
});

updateAstroConfig();
};

const updateAstroConfig = () => {
// Update Astro config to enable platformProxy and imageService
const filePath = "astro.config.mjs";

updateStatus(`Updating configuration in ${blue(filePath)}`);
Expand Down
10 changes: 9 additions & 1 deletion packages/edge-preview-authenticated-proxy/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import sharedConfig from "@cloudflare/eslint-config-shared";
import { defineConfig } from "eslint/config";

export default defineConfig(sharedConfig);
export default defineConfig([
sharedConfig,
{
files: ["tests/**/*.test.ts"],
rules: {
"workers-sdk/no-vitest-import-expect": "error",
},
},
]);
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { randomBytes } from "node:crypto";
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
// eslint-disable-next-line workers-sdk/no-vitest-import-expect -- see #12346
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import { unstable_dev } from "wrangler";
import type { Unstable_DevWorker } from "wrangler";
Expand Down
10 changes: 9 additions & 1 deletion packages/playground-preview-worker/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import sharedConfig from "@cloudflare/eslint-config-shared";
import { defineConfig } from "eslint/config";

export default defineConfig(sharedConfig);
export default defineConfig([
sharedConfig,
{
files: ["tests/**/*.test.ts"],
rules: {
"workers-sdk/no-vitest-import-expect": "error",
},
},
]);
1 change: 1 addition & 0 deletions packages/playground-preview-worker/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fetch } from "undici";
// eslint-disable-next-line workers-sdk/no-vitest-import-expect -- see #12346
import { beforeAll, describe, expect, it } from "vitest";

const REMOTE = "https://playground-testing.devprod.cloudflare.dev";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
import { page, viteTestUrl } from "./index";
import { viteTestUrl } from "./index";

export async function getTextResponse(path = "/"): Promise<string> {
const response = await getResponse(path);
return response.text();
}

export async function getJsonResponse(
path = "/"
): Promise<null | Record<string, unknown> | Array<unknown>> {
export async function getJsonResponse(path = "/"): Promise<unknown> {
const response = await getResponse(path);
const text = await response.text();
try {
return JSON.parse(text);
} catch {
throw new Error("Invalid JSON response:\n" + text);
}
return response.json();
}

export async function getResponse(path = "/") {
const url = `${viteTestUrl}${path}`;
const response = page.waitForResponse(url);
await page.goto(url);
return response;
export async function getResponse(path = "/"): Promise<Response> {
return fetch(`${viteTestUrl}${path}`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
viteTestUrl,
} from "../../__test-utils__";

export const browserMode = true;

test("supports Data modules with a '.bin' extension", async () => {
const result = await getJsonResponse("/bin");
expect(result).toEqual({ byteLength: 342936 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { expect, test } from "vitest";
import { getResponse, page, viteTestUrl } from "../../__test-utils__";
import "./base-tests";

export const browserMode = true;

test("fetches transformed HTML asset", async () => {
await page.goto(`${viteTestUrl}/transformed-html-asset`);
const content = await page.textContent("h1");
Expand All @@ -10,8 +12,8 @@ test("fetches transformed HTML asset", async () => {

test("fetches original public directory asset if requested directly", async () => {
const response = await getResponse("/public-image.svg");
const contentType = await response.headerValue("content-type");
const additionalHeader = await response.headerValue("additional-header");
const contentType = response.headers.get("content-type");
const additionalHeader = response.headers.get("additional-header");
expect(contentType).toBe("image/svg+xml");
expect(additionalHeader).toBe(null);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { getResponse, getTextResponse } from "../../__test-utils__";

test("fetches public directory asset", async () => {
const response = await getResponse("/public-directory-asset");
const contentType = await response.headerValue("content-type");
const additionalHeader = await response.headerValue("additional-header");
const contentType = response.headers.get("content-type");
const additionalHeader = response.headers.get("additional-header");
expect(contentType).toBe("image/svg+xml");
expect(additionalHeader).toBe("public-directory-asset");
});

test("fetches imported asset", async () => {
const response = await getResponse("/imported-asset");
const contentType = await response.headerValue("content-type");
const additionalHeader = await response.headerValue("additional-header");
const contentType = response.headers.get("content-type");
const additionalHeader = response.headers.get("additional-header");
expect(contentType).toBe("image/svg+xml");
expect(additionalHeader).toBe("imported-asset");
});
Expand All @@ -24,8 +24,8 @@ test("fetches imported asset with url suffix", async () => {

test("fetches inline asset", async () => {
const response = await getResponse("/inline-asset");
const contentType = await response.headerValue("content-type");
const additionalHeader = await response.headerValue("additional-header");
const contentType = response.headers.get("content-type");
const additionalHeader = response.headers.get("additional-header");
expect(contentType).toBe("image/svg+xml");
expect(additionalHeader).toBe("inline-asset");
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

test("fetches public directory asset", async () => {
const response = await getResponse("/public-image.svg");
const contentType = await response.headerValue("content-type");
const contentType = response.headers.get("content-type");
expect(contentType).toBe("image/svg+xml");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
serverLogs,
} from "../../__test-utils__";

export const browserMode = true;

test("returns the index.html page", async () => {
const content = await page.textContent("h1");
expect(content).toBe("HTML page");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { describe, expect, test } from "vitest";
import { isBuild, page, viteTestUrl } from "../../__test-utils__";

export const browserMode = true;

describe.runIf(!isBuild)(
"error thrown in the default export of the entry Worker",
async () => {
Expand Down
Loading
Loading