Skip to content

Commit dfbf03f

Browse files
add react-router c3 template (#8553)
* add react-router c3 template * fix duplicate $schema in wrangler.jsonc * add test * changeset * fix test * fix schema adding * actually fix :( * fix type error * pr review * hide remix * update c3 tests node version * set vite localhost in tests :( * fix double git question * Update packages/create-cloudflare/templates/react-router/c3.ts Co-authored-by: James Opstad <[email protected]> * bump node again to appease angular * hopefully bust turbo cache after node bump * trailing comma >:( * add node version in more places * set pnpm store location * Revert "set pnpm store location" This reverts commit c608b24. * nuxt no install --------- Co-authored-by: James Opstad <[email protected]>
1 parent 9c844f7 commit dfbf03f

File tree

14 files changed

+139
-11
lines changed

14 files changed

+139
-11
lines changed

.changeset/few-parts-tell.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"create-cloudflare": minor
3+
---
4+
5+
feat: add React Router + Workers assets template
6+
7+
Also hide the Remix template in the interactive menu, although it is still accessible via CLI with `--framework=remix`.

.github/actions/run-c3-e2e/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ inputs:
2222
apiToken:
2323
description: "The api token of the test account"
2424
required: true
25+
node-version:
26+
description: the version of Node.js to install
27+
required: true
2528

2629
runs:
2730
using: "composite"
@@ -44,6 +47,7 @@ runs:
4447
shell: bash
4548
run: pnpm run test:e2e --filter create-cloudflare
4649
env:
50+
NODE_VERSION: ${{ inputs.node-version }}
4751
CLOUDFLARE_API_TOKEN: ${{ inputs.apiToken }}
4852
CLOUDFLARE_ACCOUNT_ID: ${{ inputs.accountId }}
4953
E2E_QUARANTINE: ${{ inputs.quarantine }}

.github/workflows/c3-e2e.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
if: steps.changes.outputs.everything_but_markdown == 'true'
6363
uses: ./.github/actions/install-dependencies
6464
with:
65+
node-version: 20.11.1
6566
turbo-api: ${{ secrets.TURBO_API }}
6667
turbo-team: ${{ secrets.TURBO_TEAM }}
6768
turbo-token: ${{ secrets.TURBO_TOKEN }}
@@ -71,6 +72,7 @@ jobs:
7172
if: steps.changes.outputs.everything_but_markdown == 'true'
7273
uses: ./.github/actions/run-c3-e2e
7374
with:
75+
node-version: 20.11.1
7476
packageManager: ${{ matrix.pm.name }}
7577
packageManagerVersion: ${{ matrix.pm.version }}
7678
quarantine: false
@@ -82,6 +84,7 @@ jobs:
8284
if: steps.changes.outputs.everything_but_markdown == 'true'
8385
uses: ./.github/actions/run-c3-e2e
8486
with:
87+
node-version: 20.11.1
8588
packageManager: ${{ matrix.pm.name }}
8689
packageManagerVersion: ${{ matrix.pm.version }}
8790
quarantine: false

packages/create-cloudflare/e2e-tests/frameworks.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,15 @@ const verifyBuildCfTypesScript = async (
370370
expect(outputFileContentPreLines).toContain("// Generated by Wrangler");
371371

372372
// the file contains the env interface
373-
expect(outputFileContentPreLines).toContain(
374-
`interface ${envInterfaceName} {`,
373+
// the file still contains the env interface
374+
const hasEnvInterfacePre = outputFileContentPreLines.some(
375+
(line) =>
376+
// old type gen - some framework templates pin older versions of wrangler
377+
line === `interface ${envInterfaceName} {` ||
378+
// new after importable env change
379+
line === `interface ${envInterfaceName} extends Cloudflare.Env {}`,
375380
);
381+
expect(hasEnvInterfacePre).toBe(true);
376382

377383
// Run the `cf-typegen` script to generate types for bindings in fixture
378384
const buildTypesProc = spawnWithLogging(
@@ -389,14 +395,14 @@ const verifyBuildCfTypesScript = async (
389395
expect(outputFileContentPostLines).not.toContain("// Generated by Wrangler");
390396

391397
// the file still contains the env interface
392-
const hasEnvInterface = outputFileContentPostLines.some(
398+
const hasEnvInterfacePost = outputFileContentPostLines.some(
393399
(line) =>
394-
// old type gen - some frameworkte templates pin older versions of wrangler
400+
// old type gen - some framework templates pin older versions of wrangler
395401
line === `interface ${envInterfaceName} {` ||
396402
// new after importable env change
397403
line === `interface ${envInterfaceName} extends Cloudflare.Env {}`,
398404
);
399-
expect(hasEnvInterface).toBe(true);
405+
expect(hasEnvInterfacePost).toBe(true);
400406
};
401407

402408
const verifyBuildScript = async (

packages/create-cloudflare/e2e-tests/frameworks/framework-test-config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@ import { keys, LONG_TIMEOUT } from "../helpers";
33
// These are ordered based on speed and reliability for ease of debugging
44
export default function getFrameworkTestConfig(pm: string) {
55
return {
6+
"react-router": {
7+
unsupportedOSs: ["win32"],
8+
testCommitMessage: true,
9+
timeout: LONG_TIMEOUT,
10+
verifyDeploy: {
11+
route: "/",
12+
expectedText: "Hello from Cloudflare",
13+
},
14+
verifyPreview: {
15+
route: "/",
16+
expectedText: "Hello from Cloudflare",
17+
previewArgs: ["--host=127.0.0.1"],
18+
},
19+
verifyBuildCfTypes: {
20+
outputFile: "worker-configuration.d.ts",
21+
envInterfaceName: "Env",
22+
},
23+
flags: ["--no-install", "--no-git-init"],
24+
},
625
"astro:pages": {
726
argv: ["--platform", "pages"],
827
testCommitMessage: true,

packages/create-cloudflare/src/frameworks/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"create-qwik": "1.12.0",
1515
"create-vite": "6.1.1",
1616
"create-remix": "2.15.3",
17+
"create-react-router": "7.4.0",
1718
"create-solid": "0.6.1",
1819
"create-vue": "3.14.2",
1920
"gatsby": "5.14.1",

packages/create-cloudflare/src/templates.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import openapiTemplate from "templates/openapi/c3";
3838
import preExistingTemplate from "templates/pre-existing/c3";
3939
import queuesTemplate from "templates/queues/c3";
4040
import qwikTemplate from "templates/qwik/c3";
41+
import reactRouterTemplate from "templates/react-router/c3";
4142
import reactTemplate from "templates/react/c3";
4243
import remixTemplate from "templates/remix/c3";
4344
import scheduledTemplate from "templates/scheduled/c3";
@@ -56,6 +57,7 @@ export type MultiPlatformTemplateConfig = {
5657
pages: TemplateConfig;
5758
workers: TemplateConfig;
5859
};
60+
hidden?: boolean;
5961
};
6062

6163
export type TemplateConfig = {
@@ -186,6 +188,7 @@ export function getFrameworkMap({ experimental = false }): TemplateMap {
186188
nuxt: nuxtTemplate,
187189
qwik: qwikTemplate,
188190
react: reactTemplate,
191+
"react-router": reactRouterTemplate,
189192
remix: remixTemplate,
190193
solid: solidTemplate,
191194
svelte: svelteTemplate,
@@ -400,11 +403,20 @@ export const createContext = async (
400403
const frameworkMap = getFrameworkMap({
401404
experimental: args.experimental,
402405
});
403-
const frameworkOptions = Object.entries(frameworkMap).map(
404-
([key, config]) => ({
405-
label: config.displayName,
406-
value: key,
407-
}),
406+
407+
const frameworkOptions = Object.entries(frameworkMap).reduce<Option[]>(
408+
(acc, [key, config]) => {
409+
// only hide if we're going to show the options - otherwise, the
410+
// result will show up as (skipped) instead of the actual value
411+
if (!config.hidden || args.framework) {
412+
acc.push({
413+
label: config.displayName,
414+
value: key,
415+
});
416+
}
417+
return acc;
418+
},
419+
[],
408420
);
409421

410422
const framework = await processArgument(args, "framework", {

packages/create-cloudflare/src/wrangler/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export const updateWranglerConfig = async (ctx: C3Context) => {
4545
ensureNameExists(parsed, ctx.project.name),
4646
);
4747

48-
const comment = `/**\n * For more details on how to configure Wrangler, refer to:\n * https://developers.cloudflare.com/workers/wrangler/configuration/\n */\n{\n\t"$schema": "node_modules/wrangler/config-schema.json",`;
48+
let comment = `/**\n * For more details on how to configure Wrangler, refer to:\n * https://developers.cloudflare.com/workers/wrangler/configuration/\n */\n{`;
49+
if (!modified["$schema"]) {
50+
comment += `\n\t"$schema": "node_modules/wrangler/config-schema.json",`;
51+
}
4952

5053
if (!modified["observability"]) {
5154
modified["observability"] = { enabled: true };
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module 'cloudflare:test' {
2+
// extends Env in ../worker-configuration.d.ts
3+
interface ProvidedEnv extends Env {}
4+
5+
// You can also
6+
// interface ProvidedEnv {
7+
// KV_NAMESPACE: KVNamespace;
8+
// }
9+
}

packages/create-cloudflare/templates/nuxt/pages/c3.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const generate = async (ctx: C3Context) => {
2121
ctx.project.name,
2222
"--packageManager",
2323
npm,
24+
"--no-install",
2425
gitFlag,
2526
]);
2627

0 commit comments

Comments
 (0)