Skip to content

Commit

Permalink
Merge branch 'main' into cole/pipelines-auto-r2-tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
cmackenzie1 authored Dec 12, 2024
2 parents d40ac0c + eba018e commit 6f27584
Show file tree
Hide file tree
Showing 56 changed files with 1,734 additions and 290 deletions.
11 changes: 11 additions & 0 deletions .changeset/c3-frameworks-update-7513.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"create-cloudflare": patch
---

chore: update dependencies of "create-cloudflare" package

The following dependency versions have been updated:

| Dependency | From | To |
| ------------ | ------ | ------ |
| create-astro | 4.10.0 | 4.11.0 |
11 changes: 11 additions & 0 deletions .changeset/c3-frameworks-update-7530.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"create-cloudflare": patch
---

chore: update dependencies of "create-cloudflare" package

The following dependency versions have been updated:

| Dependency | From | To |
| ---------- | ------ | ------ |
| create-vue | 3.12.1 | 3.12.2 |
11 changes: 11 additions & 0 deletions .changeset/c3-frameworks-update-7531.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"create-cloudflare": patch
---

chore: update dependencies of "create-cloudflare" package

The following dependency versions have been updated:

| Dependency | From | To |
| ---------- | ----- | ----- |
| sv | 0.6.2 | 0.6.7 |
5 changes: 5 additions & 0 deletions .changeset/clean-peas-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Add file prefix option to wrangler pipelines commands
5 changes: 5 additions & 0 deletions .changeset/happy-ears-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

Added wrangler r2 domain get command
5 changes: 5 additions & 0 deletions .changeset/hot-ads-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": minor
---

feature: Add support for wrangler.json(c) in templates
10 changes: 10 additions & 0 deletions .changeset/khaki-steaks-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"wrangler": patch
---

fix: ensure that non-inherited fields are not removed when using an inferred named environment

It is an error for the the user to provide an environment name that doesn't match any of the named environments in the Wrangler configuration.
But if there are no named environments defined at all in the Wrangler configuration, we special case the top-level environment as though it was a named environment.
Previously, when this happens, we would remove all the nonInheritable fields from the configuration (essentially all the bindings) leaving an incorrect configuration.
Now we correctly generate a flattened named environment that has the nonInheritable fields, plus correctly applies any transformFn on inheritable fields.
5 changes: 5 additions & 0 deletions .changeset/late-phones-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Include response body in Cloudchamber API errors
5 changes: 5 additions & 0 deletions .changeset/nervous-jeans-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Fix to not require local connection string when using Hyperdrive and wrangler dev --remote
5 changes: 5 additions & 0 deletions .changeset/new-shoes-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": patch
---

fix: update create-remix to fix creating a Remix project failing with "Cannot find module 'fs-extra'"
5 changes: 5 additions & 0 deletions .changeset/shy-waves-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": patch
---

update Next.js template to use Next.js v.15
7 changes: 7 additions & 0 deletions .changeset/swift-bulldogs-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

The `x-provision` experimental flag now identifies draft and inherit bindings by looking up the current binding settings.

Draft bindings can then be provisioned (connected to new or existing KV, D1, or R2 resources) during `wrangler deploy`.
7 changes: 2 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ version: 2
updates:
# Automatically check for updates in framework CLIs for C3
- package-ecosystem: "npm"
open-pull-requests-limit: 10
directory: "/packages/create-cloudflare/src/frameworks"
schedule:
# Note: this interval is likely going to be too short and create
# too much noise, we are just setting it as daily for the time
#  being to test the efficacy of the solution, we shall set it
# to "weekly" after a testing period of 1/2 weeks
interval: "daily"
interval: "weekly"
versioning-strategy: increase
# the following is used to add the [C3] prefix to the PR title,
# we override the commit message but setting a prefix like this
Expand Down
24 changes: 24 additions & 0 deletions packages/create-cloudflare/e2e-tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,30 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
},
);

test({ experimental }).skipIf(process.platform === "win32")(
"Cloning remote template that uses wrangler.json",
async ({ logStream, project }) => {
const { output } = await runC3(
[
project.path,
"--template=cloudflare/templates/multiplayer-globe-template",
"--no-deploy",
"--git=false",
],
[],
logStream,
);

expect(output).toContain(
`repository cloudflare/templates/multiplayer-globe-template`,
);
expect(output).toContain(
`Cloning template from: cloudflare/templates/multiplayer-globe-template`,
);
expect(output).toContain(`template cloned and validated`);
},
);

test({ experimental }).skipIf(process.platform === "win32")(
"Inferring the category, type and language if the type is `hello-world-python`",
async ({ logStream, project }) => {
Expand Down
1 change: 1 addition & 0 deletions packages/create-cloudflare/e2e-tests/frameworks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ function getFrameworkTests(opts: {
"--tailwind",
"--src-dir",
"--app",
"--turbopack",
"--import-alias",
"@/*",
],
Expand Down
20 changes: 15 additions & 5 deletions packages/create-cloudflare/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import { quoteShellArgs, runCommand } from "helpers/command";
import { readFile } from "helpers/files";
import { detectPackageManager } from "helpers/packageManagers";
import { poll } from "helpers/poll";
import { parse as jsoncParse } from "jsonc-parser";
import { isInsideGitRepo } from "./git";
import { chooseAccount, wranglerLogin } from "./wrangler/accounts";
import { readWranglerToml } from "./wrangler/config";
import {
readWranglerJson,
readWranglerToml,
wranglerJsonExists,
} from "./wrangler/config";
import type { C3Context } from "types";

export const offerToDeploy = async (ctx: C3Context) => {
Expand Down Expand Up @@ -72,12 +77,17 @@ const isDeployable = async (ctx: C3Context) => {
if (ctx.template.platform === "pages") {
return true;
}
const wranglerConfig = readWranglerConfig(ctx);
return !hasBinding(wranglerConfig);
};

const readWranglerConfig = (ctx: C3Context) => {
if (wranglerJsonExists(ctx)) {
const wranglerJsonStr = readWranglerJson(ctx);
return jsoncParse(wranglerJsonStr);
}
const wranglerTomlStr = readWranglerToml(ctx);

const wranglerToml = TOML.parse(wranglerTomlStr.replace(/\r\n/g, "\n"));

return !hasBinding(wranglerToml);
return TOML.parse(wranglerTomlStr.replace(/\r\n/g, "\n"));
};

export const runDeploy = async (ctx: C3Context) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/create-cloudflare/src/frameworks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const getFrameworkCli = (ctx: C3Context, withVersion = true) => {

const frameworkCli = ctx.template
.frameworkCli as keyof typeof frameworksPackageJson.dependencies;
const version = frameworksPackageJson.dependencies[frameworkCli];
const version =
ctx.template.frameworkCliPinnedVersion ??
frameworksPackageJson.dependencies[frameworkCli];
return withVersion ? `${frameworkCli}@${version}` : frameworkCli;
};

Expand Down
10 changes: 5 additions & 5 deletions packages/create-cloudflare/src/frameworks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
"so that we can use dependabot to update these dependencies automatically."
],
"dependencies": {
"create-astro": "4.10.0",
"create-astro": "4.11.0",
"create-analog": "1.8.1",
"@angular/create": "19.0.4",
"create-docusaurus": "3.6.3",
"create-hono": "0.14.3",
"create-next-app": "14.2.5",
"create-next-app": "15.0.3",
"create-qwik": "1.11.0",
"create-vite": "6.0.1",
"create-remix": "2.15.0",
"create-remix": "2.15.1",
"create-solid": "0.5.14",
"create-vue": "3.12.1",
"create-vue": "3.12.2",
"gatsby": "5.14.0",
"sv": "0.6.2",
"sv": "0.6.7",
"nuxi": "3.16.0"
}
}
23 changes: 17 additions & 6 deletions packages/create-cloudflare/src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,21 @@ export type TemplateConfig = {
* to handle config version skew between different versions of c3
*/
configVersion: number;
/** The id by which template is referred to internally and keyed in lookup maps*/
/** The id by which template is referred to internally and keyed in lookup maps */
id: string;
/** A string that controls how the template is presented to the user in the selection menu*/
/** A string that controls how the template is presented to the user in the selection menu */
displayName: string;
/** A string that explains what is inside the template, including any resources and how those will be used*/
/** A string that explains what is inside the template, including any resources and how those will be used */
description?: string;
/** The deployment platform for this template */
platform: "workers" | "pages";
/** The name of the framework cli tool that is used to generate this project or undefined if none. */
/** The name of the framework cli tool that is used to generate this project or undefined if none */
frameworkCli?: string;
/**
* A specific version of the framework cli tool to use instead of the standard one taken from the src/frameworks/package.json
* (which gets managed and bumped by dependabot)
*/
frameworkCliPinnedVersion?: string;
/** When set to true, hides this template from the selection menu */
hidden?: boolean;
/** Specifies a set of files that will be copied to the project directory during creation.
Expand Down Expand Up @@ -627,9 +632,15 @@ const validateTemplate = (path: string, config: TemplateConfig) => {
const validateTemplateSrcDirectory = (path: string, config: TemplateConfig) => {
if (config.platform === "workers") {
const wranglerTomlPath = resolve(path, "wrangler.toml");
if (!existsSync(wranglerTomlPath)) {
const wranglerJsonPath = resolve(path, "wrangler.json");
const wranglerJsoncPath = resolve(path, "wrangler.jsonc");
if (
!existsSync(wranglerTomlPath) &&
!existsSync(wranglerJsonPath) &&
!existsSync(wranglerJsoncPath)
) {
throw new Error(
`create-cloudflare templates must contain a "wrangler.toml" file.`,
`create-cloudflare templates must contain a "wrangler.toml" or "wrangler.json(c)" file.`,
);
}
}
Expand Down
23 changes: 23 additions & 0 deletions packages/create-cloudflare/src/wrangler/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,39 @@ const getWranglerTomlPath = (ctx: C3Context) => {
return resolve(ctx.project.path, "wrangler.toml");
};

const getWranglerJsonPath = (ctx: C3Context) => {
return resolve(ctx.project.path, "wrangler.json");
};

const getWranglerJsoncPath = (ctx: C3Context) => {
return resolve(ctx.project.path, "wrangler.jsonc");
};

export const wranglerTomlExists = (ctx: C3Context) => {
const wranglerTomlPath = getWranglerTomlPath(ctx);
return existsSync(wranglerTomlPath);
};

export const wranglerJsonExists = (ctx: C3Context) => {
const wranglerJsonPath = getWranglerJsonPath(ctx);
const wranglerJsoncPath = getWranglerJsoncPath(ctx);
return existsSync(wranglerJsonPath) || existsSync(wranglerJsoncPath);
};

export const readWranglerToml = (ctx: C3Context) => {
const wranglerTomlPath = getWranglerTomlPath(ctx);
return readFile(wranglerTomlPath);
};

export const readWranglerJson = (ctx: C3Context) => {
const wranglerJsonPath = getWranglerJsonPath(ctx);
if (existsSync(wranglerJsonPath)) {
return readFile(wranglerJsonPath);
}
const wranglerJsoncPath = getWranglerJsoncPath(ctx);
return readFile(wranglerJsoncPath);
};

export const writeWranglerToml = (ctx: C3Context, contents: string) => {
const wranglerTomlPath = getWranglerTomlPath(ctx);
return writeFile(wranglerTomlPath, contents);
Expand Down
4 changes: 4 additions & 0 deletions packages/create-cloudflare/templates-experimental/next/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export default {
configVersion: 1,
id: "next",
frameworkCli: "create-next-app",
// TODO: here we need to specify a version of create-next-app which is different from the
// standard one used in the stable Next.js template, that's because our open-next adapter
// is not yet fully ready for Next.js 15, once it is we should remove the following
frameworkCliPinnedVersion: "14.2.5",
platform: "workers",
displayName: "Next (using Node.js compat + Workers Assets)",
path: "templates-experimental/next",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/templates/next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ In order to enable the example:
```ts
// KV Example:
```
and uncomment the commented lines below it.
and uncomment the commented lines below it (also uncomment the relevant imports).
- Do the same in the `wrangler.toml` file, where
the comment is:
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getRequestContext } from '@cloudflare/next-on-pages'
// import { getRequestContext } from '@cloudflare/next-on-pages'

export const runtime = 'edge'

export async function GET(request) {
let responseText = 'Hello World'
export async function GET() {
const responseText = 'Hello World'

// In the edge runtime you can use Bindings that are available in your application
// (for more details see:
Expand All @@ -15,7 +15,7 @@ export async function GET(request) {
// const myKv = getRequestContext().env.MY_KV_NAMESPACE
// await myKv.put('suffix', ' from a KV store!')
// const suffix = await myKv.get('suffix')
// responseText += suffix
// return new Response(responseText + suffix)

return new Response(responseText)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { NextRequest } from 'next/server'
import { getRequestContext } from '@cloudflare/next-on-pages'
// import { getRequestContext } from '@cloudflare/next-on-pages'

export const runtime = 'edge'

export async function GET(request: NextRequest) {
let responseText = 'Hello World'
export async function GET() {
const responseText = 'Hello World'

// In the edge runtime you can use Bindings that are available in your application
// (for more details see:
Expand All @@ -16,7 +15,7 @@ export async function GET(request: NextRequest) {
// const myKv = getRequestContext().env.MY_KV_NAMESPACE
// await myKv.put('suffix', ' from a KV store!')
// const suffix = await myKv.get('suffix')
// responseText += suffix
// return new Response(responseText + suffix)

return new Response(responseText)
}
6 changes: 3 additions & 3 deletions packages/create-cloudflare/templates/next/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ const generate = async (ctx: C3Context) => {
updateStatus("Created wrangler.toml file");
};

const updateNextConfig = () => {
const updateNextConfig = (usesTs: boolean) => {
const s = spinner();

const configFile = "next.config.mjs";
const configFile = `next.config.${usesTs ? "ts" : "mjs"}`;
s.start(`Updating \`${configFile}\``);

const configContent = readFile(configFile);
Expand Down Expand Up @@ -107,7 +107,7 @@ const configure = async (ctx: C3Context) => {
await writeEslintrc(ctx);
}

updateNextConfig();
updateNextConfig(usesTs);

copyFile(
join(getTemplatePath(ctx), "README.md"),
Expand Down
Loading

0 comments on commit 6f27584

Please sign in to comment.