Skip to content

Full autoconfig flow for some projects - #11164

Merged
penalosa merged 11 commits into
mainfrom
penalosa/framework-detection
Nov 5, 2025
Merged

Full autoconfig flow for some projects#11164
penalosa merged 11 commits into
mainfrom
penalosa/framework-detection

Conversation

@penalosa

@penalosa penalosa commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

Fixes https://jira.cfdata.org/browse/DEVX-2264 & https://jira.cfdata.org/browse/DEVX-2266

This fills out details of runAutoConfig() and getDetailsForAutoConfig(). There are several differences from the designed behaviour:

  • Instead of options.framework being just an object containing framework details, it's now a class containing a .configure() function that can be used by getDetailsForAutoConfig(). This defaults to a "static" implementation that should work for full stack sites, but I think this gives us a clean way to add proper support for full stack frameworks as we migrate them over from C3. I've included support for Astro as an example.
  • TODO: I haven't implemented any behaviour to try and detect the output directory for a non-framework static site. As designed, this should be the first child directory that contains an index.html file: followup: https://jira.cfdata.org/browse/DEVX-2277 via Detect non-framework static sites #11180
  • Currently projectPath is identical to cwd in all cases. @dario-piotrowicz did you have thoughts here?
  • After internal discussion, I've vendored the required elements of C3 in c3-vendor rather than pulling out to a common location. These are minimal, and in the medium term autoconfig will likely replace the guts of C3 anyway.

  • Tests
    • Tests included
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: tracked elsewhere
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: new feature

@penalosa
penalosa requested a review from a team November 3, 2025 20:25
@penalosa
penalosa requested a review from a team as a code owner November 3, 2025 20:25
@changeset-bot

changeset-bot Bot commented Nov 3, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 238be87

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

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


export class Astro extends Framework {
name = "astro";
async configure(outputDir: string): Promise<RawConfig> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This does less than C3. In particular, it doesn't set up getPlatformProxy() or the Cloudflare image service. I think we should do those things in the Astro Cloudflare adapter (astro add cloudflare) instead of here.

Comment on lines +53 to +61
$schema: "node_modules/wrangler/config-schema.json",
name:
getCIOverrideName() ??
autoConfigDetails.packageJson?.name ??
dirname(autoConfigDetails.projectPath ?? process.cwd()),
compatibility_date: getDevCompatibilityDate(undefined),
observability: {
enabled: true,
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These config properties are common across ~all apps

/** Whether the framework is used for static generation or fullstack deployment */
mode: "static" | "fullstack";
};
framework?: Framework;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dario-piotrowicz what do you think about this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

makes sense to me 👍

Comment thread packages/wrangler/src/deploy/index.ts Outdated
Comment on lines +279 to +285
let maybeOutputDir: string | undefined;
if (args.script) {
const stats = statSync(args.script);
if (stats.isDirectory()) {
maybeOutputDir = args.script;
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure about this... This allows wrangler deploy ./public to work, which I think might be an expectation some people have? Do we want to support this? If we do, we likely have to support it in dev and the rest of deploy, too, because the option could be present even if autoconfig doesn't run. How do we resolve conflicts between this and the assets output dir in the config file?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

mh... I am not sure... we never say what you can provide a directory to wrangler deploy and I also find that to be a bit of an ambiguous API (for example someone could thing that you can put the worker code in the directory you provided to wrangler deploy?)...

but I can see where you're coming from...

if we want to have a truly smooth UX we might need to support this 😕

this is probably also something product would chip in as well 🤔
cc. @yomna-shousha @MattieTK

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I am curious how that would conflict with the behavior in this PR: #10016
Are you thinking that autoconfig takes the priority here?

If I am understanding correctly:
I run: wrangler deploy ./public --experimental-autoconfig
Framework detection runs, it finds Astro
It uses ./public as output dir (overriding Astro's default ./dist)
Shows user: "Framework: astro, Build: npm run build, Output: ./public"
Asks: "Deploy with these settings?"
and so on and so forth

Essentially just allowing the user to specify what we would have otherwise detected (potentially correctly or incorrectly for their setup).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm going to remove this logic from this PR—let's discuss and maybe re-apply in a followup


export interface PackageManager {
type: "npm" | "yarn" | "pnpm";
npx: string;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From C3

Comment thread packages/wrangler/src/package-manager.ts Outdated
@dario-piotrowicz

Copy link
Copy Markdown
Member

Currently projectPath is identical to cwd in all cases. dario-piotrowicz did you have thoughts here?

Yeah I'm not surprised, I thought of projectPath as something that'd make sense in the programmatic API, in wrangler deploy it's going to alway be the cwd, if you find it totally unnecessary at this stage I'm ok if you want to remove it 🙂

However I am also thinking that it could be useful for testing? (especially if/when we're going to have fixtures for autoconfig).

It's totally up to you, for me we can omit it for now and add it later if/when needed 🙂

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry I must have misunderstood things in our conversation 😓, if we are reusing c3 to this degree than actually I think it'd make sense to create a private package in the monorepo instead of coping things over. As long as we don't publish that package getting rid of it later if/when needed should be pretty trivial 🤔

But if you already went down this route and want to proceed with it I am also happy with this 🙂

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(if we were to externalize the c3 logic in its own (private) package, we might as well call that package @cloudflare/autoconfig and also contain all the autoconfig logic 🤔 (and we could in the future publish it if that's the direction that product wants))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is actually a fairly small subset of C3, and e.g. uses Wrangler's package manager detection rather than C3's, so I think it's okay to keep as-is. We can always split out later if we need to include more.

/** Whether the framework is used for static generation or fullstack deployment */
mode: "static" | "fullstack";
};
framework?: Framework;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

makes sense to me 👍

Comment thread packages/wrangler/src/deploy/index.ts Outdated
Comment on lines +279 to +285
let maybeOutputDir: string | undefined;
if (args.script) {
const stats = statSync(args.script);
if (stats.isDirectory()) {
maybeOutputDir = args.script;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

mh... I am not sure... we never say what you can provide a directory to wrangler deploy and I also find that to be a bit of an ambiguous API (for example someone could thing that you can put the worker code in the directory you provided to wrangler deploy?)...

but I can see where you're coming from...

if we want to have a truly smooth UX we might need to support this 😕

this is probably also something product would chip in as well 🤔
cc. @yomna-shousha @MattieTK

@penalosa
penalosa requested review from a team as code owners November 4, 2025 15:13
@pkg-pr-new

pkg-pr-new Bot commented Nov 4, 2025

Copy link
Copy Markdown
create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@11164

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@11164

miniflare

npm i https://pkg.pr.new/miniflare@11164

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@11164

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@11164

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@11164

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@11164

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@11164

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@11164

wrangler

npm i https://pkg.pr.new/wrangler@11164

commit: 238be87

Comment thread fixtures/browser-rendering/tsconfig.json
Comment thread packages/wrangler/src/xxhash-wasm.d.ts
});
await writeFileSync("public/.assetsignore", "_worker.js\n_routes.json");
return {
main: `${outputDir}/dist/_worker.js/index.js`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Screenshot 2025-11-04 at 2 58 14 PM It looks like we are creating a double path here

Comment thread packages/wrangler/src/autoconfig/run.ts Outdated
Comment thread packages/wrangler/src/deployment-bundle/run-custom-build.ts Outdated
penalosa and others added 3 commits November 5, 2025 10:49
Co-authored-by: Dario Piotrowicz <dario@cloudflare.com>
Co-authored-by: Dario Piotrowicz <dario@cloudflare.com>
@github-actions

github-actions Bot commented Nov 5, 2025

Copy link
Copy Markdown
Contributor

Failed to automatically backport this PR's changes to Wrangler v3. Please manually create a PR targeting the v3-maintenance branch with your changes. Thank you for helping us keep Wrangler v3 supported!

Depending on your changes, running git rebase --onto v3-maintenance main penalosa/framework-detection might be a good starting point.

Notes:

  • your PR branch should be named v3-backport-11164
  • add the skip-v3-pr label to the current PR to stop this workflow from failing

@dario-piotrowicz dario-piotrowicz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great to me 😄 🚀

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Nov 5, 2025
@penalosa
penalosa merged commit 305d7bf into main Nov 5, 2025
35 of 37 checks passed
@penalosa
penalosa deleted the penalosa/framework-detection branch November 5, 2025 12:24
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Nov 5, 2025
@lrapoport-cf lrapoport-cf mentioned this pull request Nov 6, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants