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

C3-workers-assets-experimental-templates #6678

Merged
merged 17 commits into from
Sep 12, 2024

Conversation

petebacondarwin
Copy link
Contributor

@petebacondarwin petebacondarwin commented Sep 11, 2024

To try this out:

npx create-cloudflare@latest --experimental

What this PR solves / how to test

Adds experimental support to C3 for generating Workers with Assets projects.

Author has addressed the following

  • Tests
    • TODO (before merge)
    • Included
    • Not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required / Maybe required
    • Not required because:
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Included
    • Not necessary because:
  • Public documentation

Copy link

changeset-bot bot commented Sep 11, 2024

🦋 Changeset detected

Latest commit: 1ab2c79

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-cloudflare Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Sep 11, 2024

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10834033820/npm-package-wrangler-6678

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6678/npm-package-wrangler-6678

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10834033820/npm-package-wrangler-6678 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10834033820/npm-package-create-cloudflare-6678 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10834033820/npm-package-cloudflare-kv-asset-handler-6678
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10834033820/npm-package-miniflare-6678
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10834033820/npm-package-cloudflare-pages-shared-6678
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10834033820/npm-package-cloudflare-vitest-pool-workers-6678
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10834033820/npm-package-cloudflare-workers-editor-shared-6678
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/10834033820/npm-package-cloudflare-workers-shared-6678

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.76.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240821.2
workerd 1.20240909.0 1.20240909.0
workerd --version 1.20240909.0 2024-09-09

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@petebacondarwin petebacondarwin force-pushed the c3-workers-assets-experimental-templates branch 2 times, most recently from 67c4973 to 3021d43 Compare September 12, 2024 08:34
vi.mocked(readFile).mockReturnValue(`
experimental_assets = { directory = "./dist", binding = "ASSETS" }

[[durable_objects.bindings]]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably Durable Objects can be deployed if they have migrations setup.
But the previous state of affairs didn't support that, so it is out of scope for this PR to change that.

@@ -67,12 +68,11 @@ const isDeployable = async (ctx: C3Context) => {
return true;
}

const wranglerToml = readWranglerToml(ctx);
if (wranglerToml.match(/(?<!#\s*)bindings?\s*=.*/m)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach was too simplistic because it also blocked Workers that have assets bindings, which can be deployed straight up.

] as keyof typeof clisPackageJson.dependencies;
const version = clisPackageJson.dependencies[frameworkCli];
const frameworkCli = ctx.template
.frameworkCli as keyof typeof frameworksPackageJson.dependencies;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source of truth for mapping between frameworks and their CLI has moved to the c3.ts template so that is all kept in one place, allowing us to remove that map from the frameworks/package.json

@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.json"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is needed so that VS Code (eslint) knows that the TS files in this folder are configured by TypeScript. The package.json in this directory makes eslint think this is a separate TS project.

@@ -98,9 +98,9 @@ export const gitCommit = async (ctx: C3Context) => {
};

const createCommitMessage = async (ctx: C3Context) => {
const isPages = ctx.template.platform === "pages";
const framework = ctx.template.frameworkCli;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not only Pages projects that can run Frameworks!

if (args?.experimental) {
logRaw(
blue(
"You have selected experimental mode - the options below are filtered to those that support experimental mode.\n",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tanushree-sharma - you might have a view on the copy here, but I wanted to call out to people that they would see a different list of frameworks/templates when the are running --experimental mode.

@petebacondarwin petebacondarwin force-pushed the c3-workers-assets-experimental-templates branch from 3021d43 to 3df7947 Compare September 12, 2024 08:53
@petebacondarwin petebacondarwin added the e2e Run e2e tests on a PR label Sep 12, 2024
@petebacondarwin petebacondarwin marked this pull request as ready for review September 12, 2024 09:01
@petebacondarwin petebacondarwin force-pushed the c3-workers-assets-experimental-templates branch from f511ded to 06258bf Compare September 12, 2024 09:05
Copy link
Contributor

@penalosa penalosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't reviewed the templates-experimental folder, but this looks good!

@petebacondarwin petebacondarwin force-pushed the c3-workers-assets-experimental-templates branch from 06258bf to 1ab2c79 Compare September 12, 2024 15:32
@penalosa penalosa merged commit 40ecf47 into main Sep 12, 2024
29 checks passed
@penalosa penalosa deleted the c3-workers-assets-experimental-templates branch September 12, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run e2e tests on a PR
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants