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

fix: c3, use latest types for @cloudflare/workers-types #6897

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .changeset/few-sheep-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"create-cloudflare": patch
---

fix: c3, use latest types for `@cloudflare/workers-types`

We have some code that looks for the latest compat date generated in a workers-types dist, but that's been frozen for 202307-01 forever. We have upcoming work that'll replace this with generated types based on compat date/flags, but till then let's generate new projects with the default types.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("Compatibility Date Helpers", () => {

const date = await getWorkerdCompatibilityDate();

const fallbackDate = "2023-05-18";
const fallbackDate = "2024-10-04";
expect(date).toBe(fallbackDate);
expect(spinner.start).toHaveBeenCalled();
expect(spinner.stop).toHaveBeenCalledWith(
Expand All @@ -78,7 +78,7 @@ describe("Compatibility Date Helpers", () => {

const date = await getWorkerdCompatibilityDate();

const fallbackDate = "2023-05-18";
const fallbackDate = "2024-10-04";
expect(date).toBe(fallbackDate);
expect(spinner.start).toHaveBeenCalled();
expect(spinner.stop).toHaveBeenCalledWith(
Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/src/helpers/compatDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function getWorkerdCompatibilityDate() {
}
} catch {}

const fallbackDate = "2023-05-18";
const fallbackDate = "2024-10-04";

s.stop(
`${brandColor("compatibility date")} ${dim(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { brandColor, dim } from "@cloudflare/cli/colors";
import { spinner } from "@cloudflare/cli/interactive";
import { runFrameworkGenerator } from "frameworks/index";
import { mergeObjectProperties, transformFile } from "helpers/codemod";
import { getLatestTypesEntrypoint } from "helpers/compatDate";
import { readFile, writeFile } from "helpers/files";
import { detectPackageManager } from "helpers/packageManagers";
import { installPackages } from "helpers/packages";
Expand Down Expand Up @@ -48,19 +47,15 @@ const configure = async (ctx: C3Context) => {
updateEnvTypes(ctx);
};

const updateEnvTypes = (ctx: C3Context) => {
const updateEnvTypes = (_ctx: C3Context) => {
const filepath = "env.d.ts";

const s = spinner();
s.start(`Updating ${filepath}`);

let file = readFile(filepath);

let typesEntrypoint = `@cloudflare/workers-types`;
const latestEntrypoint = getLatestTypesEntrypoint(ctx);
if (latestEntrypoint) {
typesEntrypoint += `/${latestEntrypoint}`;
}
const typesEntrypoint = `@cloudflare/workers-types/experimental`;

// Replace placeholder with actual types entrypoint
file = file.replace("WORKERS_TYPES_ENTRYPOINT", typesEntrypoint);
Expand Down
9 changes: 2 additions & 7 deletions packages/create-cloudflare/templates/analog/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { brandColor, dim } from "@cloudflare/cli/colors";
import { spinner } from "@cloudflare/cli/interactive";
import { runFrameworkGenerator } from "frameworks/index";
import { loadTemplateSnippets, transformFile } from "helpers/codemod";
import { getLatestTypesEntrypoint } from "helpers/compatDate";
import { readFile, writeFile } from "helpers/files";
import { detectPackageManager } from "helpers/packageManagers";
import { installPackages } from "helpers/packages";
Expand Down Expand Up @@ -43,19 +42,15 @@ const configure = async (ctx: C3Context) => {
updateEnvTypes(ctx);
};

const updateEnvTypes = (ctx: C3Context) => {
const updateEnvTypes = (_ctx: C3Context) => {
const filepath = "env.d.ts";

const s = spinner();
s.start(`Updating ${filepath}`);

let file = readFile(filepath);

let typesEntrypoint = `@cloudflare/workers-types`;
const latestEntrypoint = getLatestTypesEntrypoint(ctx);
if (latestEntrypoint) {
typesEntrypoint += `/${latestEntrypoint}`;
}
const typesEntrypoint = `@cloudflare/workers-types/experimental`;

// Replace placeholder with actual types entrypoint
file = file.replace("WORKERS_TYPES_ENTRYPOINT", typesEntrypoint);
Expand Down
9 changes: 2 additions & 7 deletions packages/create-cloudflare/templates/nuxt/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { brandColor, dim } from "@cloudflare/cli/colors";
import { spinner } from "@cloudflare/cli/interactive";
import { runFrameworkGenerator } from "frameworks/index";
import { mergeObjectProperties, transformFile } from "helpers/codemod";
import { getLatestTypesEntrypoint } from "helpers/compatDate";
import { readFile, writeFile } from "helpers/files";
import { detectPackageManager } from "helpers/packageManagers";
import { installPackages } from "helpers/packages";
Expand Down Expand Up @@ -48,19 +47,15 @@ const configure = async (ctx: C3Context) => {
updateEnvTypes(ctx);
};

const updateEnvTypes = (ctx: C3Context) => {
const updateEnvTypes = (_ctx: C3Context) => {
const filepath = "env.d.ts";

const s = spinner();
s.start(`Updating ${filepath}`);

let file = readFile(filepath);

let typesEntrypoint = `@cloudflare/workers-types`;
const latestEntrypoint = getLatestTypesEntrypoint(ctx);
if (latestEntrypoint) {
typesEntrypoint += `/${latestEntrypoint}`;
}
const typesEntrypoint = `@cloudflare/workers-types/experimental`;

// Replace placeholder with actual types entrypoint
file = file.replace("WORKERS_TYPES_ENTRYPOINT", typesEntrypoint);
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading