Skip to content

Improve autoconfig types#12350

Merged
petebacondarwin merged 2 commits intomainfrom
dario/autoconfig-types
Feb 3, 2026
Merged

Improve autoconfig types#12350
petebacondarwin merged 2 commits intomainfrom
dario/autoconfig-types

Conversation

@dario-piotrowicz
Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz commented Feb 1, 2026

As I've mentioned here: #12190 (comment)

I've noticed that the autoconfig types could be improved, so that's what this PR is for, it contains some minor changes to make the autoconfig types more correct/useful. Also removing optional chaining operations that are actually not necessary.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: code refactoring

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 1, 2026

⚠️ No Changeset found

Latest commit: aaaa18e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 1, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: aaaa18e

Comment on lines +40 to +45
"framework": Static {
"autoConfigSupported": true,
"configurationDescription": undefined,
"id": "static",
"name": "Static",
},
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note: all the changes in this PR around Static being used are actually correctly representing the current behavior of autoconfig and there are no behavioral changes being introduced.

`);
});

it("should omit the framework entry when they it is not part of the details object", () => {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we might want to implement this, but currently we always get the 'Static' framework

Comment thread packages/wrangler/src/autoconfig/details.ts Outdated
Comment on lines -323 to -324
// If wranglerConfigToWrite is null we don't know whether there is server side code, we default to assume that there is
wranglerConfigToWrite === null ||
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

wranglerConfigToWrite cannot be null, this change was incorrectly introduced in #12190

@dario-piotrowicz dario-piotrowicz marked this pull request as ready for review February 1, 2026 22:50
@dario-piotrowicz dario-piotrowicz requested a review from a team as a code owner February 1, 2026 22:50
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional flags.

Open in Devin Review

Comment thread packages/wrangler/src/autoconfig/details.ts
configured: boolean;
/** Details about the detected framework (if any) */
framework?: Framework;
/** Details about the detected framework. It can be a JS framework or 'Static' if no actual JS framework is used. */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: "Static" sounds like a framework name to me, can you think of another name? StaticHtml/StaticAssets/StaticFiles ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah I agree... we have discussed this and haven't come up with anything better for now, I can open a followup PR to improve that if you want, but ideally I'd keep this PR as is (non-behavioral refactoring only)

Comment on lines +22 to +38
export type AutoConfigDetailsForConfiguredProject = Optional<
AutoConfigDetailsBase,
// If AutoConfig detects that the project is already configured it's unnecessary to check
// what framework is being used, so in this case `framework` is optional
"framework"
> & {
configured: true;
};

export type AutoConfigDetailsForNonConfiguredProject = AutoConfigDetailsBase & {
configured: false;
};

export type AutoConfigDetails =
| AutoConfigDetailsForConfiguredProject
| AutoConfigDetailsForNonConfiguredProject;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question: It is really valuable to have separate AutoConfigDetails / AutoConfigDetailsForNonConfiguredProject / AutoConfigDetailsForConfiguredProject ?

Sounds like a lot of code for something simple. Myabe it is worth but maybe it is overkill.

I have look at the details in great depth and let you decide.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's the whole reason as to why I opened the PR 😅

I do think that this makes things better since thanks to this we can have more strict/precise types in the code and avoids the need to assert things or use unnecessary optional chaining.

So for me, this makes, as you pointed out, the type a bit more complex, but then it simplifies and makes more robust the autoconfig code in various places, it is a bit of a tradeoff 🙂

Copy link
Copy Markdown
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

LGTM.

A few minor comment

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Feb 2, 2026
@petebacondarwin petebacondarwin merged commit 7a116ba into main Feb 3, 2026
53 of 56 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Feb 3, 2026
@petebacondarwin petebacondarwin deleted the dario/autoconfig-types branch February 3, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants