Skip to content

[autoconfig] Resolve native Vite fallback commands for cf - #16803

Merged
petebacondarwin merged 16 commits into
mainfrom
codex/autoconfig-project-commands
Nov 14, 2026
Merged

petebacondarwin merged 16 commits into
mainfrom
codex/autoconfig-project-commands

Conversation

@petebacondarwin

@petebacondarwin petebacondarwin commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

In cf, vite-plugin projects can have no detected framework dev/build command. Autoconfig currently leaves those command fields empty, forcing cf to select a plugin-owned delegate or hardcode a Vite executable. That also bypasses Vite+ command selection.

Solution

Have autoconfig return the project's native Vite or Vite+ executable through the existing devCommand and buildCommand fields in those cases. Read the selected package’s bin metadata and generate a platform-compatible invocation. Resolve dependencies from the application through its validated workspace root, excluding unrelated parent installs. For configured workspace applications with a local plugin declaration, default-named Vite config, or concrete runner dependency, also honor plugin and runner declarations in the validated workspace root manifest. Application runner dependencies take priority over workspace defaults and optional peers. Non-Vite siblings remain unaffected. Return readiness problems in commandError so read-only callers can inspect projects before installing dependencies; cf validates readiness at execution.

  • Detected framework commands keep their priority, including partial command pairs; only use the native fallback when both commands are absent. Validate plugin compatibility (>=2.0.0-beta.v.13 <3, including cf auth-profile support) for all eligible cf Vite-plugin projects, including those with canonical framework commands.
  • Let Vite evaluate its configuration when the command runs, including dynamic plugin arrays, imported configs, and --config overrides. Preserve Wrangler's existing plugin detection; keep Vite's config-file precedence and the CommonJS setup preflight before dependency installation, including dry runs. Reject .cts and .cjs transformations regardless of import/export syntax because Vite loads them as CommonJS and the plugin is ESM-only. Guide users to convert imports/exports and use an ESM config extension.
  • Native fallback projects get Vite's mode support and Build Output environment; explicit assets-directory workflows and Wrangler command selection retain their existing behavior.
  • Preserve Pages detection and its migration guards before selecting a fallback. Unconfigured unsupported frameworks keep their existing setup checks; configured custom Vite projects remain eligible for native commands. Keep Pages root-assets validation and fallback eligibility in named helpers so the detection flow stays easy to follow.

A workspace app using only a custom-named Vite config must declare the Cloudflare plugin locally, or Vite/Vite+ as a dependency or dev dependency. The binary and plugin installation may remain hoisted at the root. Detection does not receive cf dev -- --config other.ts arguments, and an arbitrary config filename alone cannot distinguish a Vite app from a non-Vite sibling. This opt-in boundary is documented and tested; config contents remain entirely Vite’s responsibility.

This changes command discovery, with no runtime changes to Miniflare, the Vite plugin, or the Vitest plugin.

Release ordering

Keeping this change separate allows autoconfig to release before the executable removal.

Validation (Node.js 22.22.1, pnpm 10.33.0):

  • Full autoconfig suite passed: 440 tests in 31 files.
  • Root pnpm check passed: 206 tasks.
  • New coverage includes hoisted workspace tools and lookup boundaries, plugin version compatibility on canonical frameworks, detection before dependency installation, dynamic Vite configs, partial framework command pairs, and tool readiness revalidation after setup. Vite+ coverage preserves the canonical commands now returned by the updated framework detector while explicitly exercising the native fallback when framework commands are absent. Compatibility coverage includes older beta versions, the minimum supported beta, later betas, stable v2, and future major versions. The native Vite/Vite+ commands execute through the platform shell, including cmd.exe in Windows CI; local validation ran on macOS.
  • New review regressions cover root-only dependency declarations, application runner priority, all five detected package managers in repair guidance (including Yarn, pnpm, and nub workspace-root flags), non-Vite workspace siblings, optional Vite+ peers, custom-named configs with root-installed Vite/Vite+ and app-level opt-in, and pre-install rejection of ESM-looking .cts files. A manual check with Vite’s actual config loader confirmed the import-only plugin fails from .cts and loads from an identical .mts config.
  • Additional regression coverage preserves Pages detection from config, cache, and confirmed Functions, the non-interactive root-assets/Functions guard, unsupported Hono/Hydrogen setup, unknown framework classification, and Wrangler-only framework checks.

  • 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: this extends the existing command-discovery contract for experimental cf integration; the changeset and companion cf guidance describe the behavior.

Note

This is a contribution from an AI agent: Codex.

@changeset-bot

changeset-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6e62236

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

This PR includes changesets to release 3 packages
Name Type
@cloudflare/autoconfig Minor
wrangler Patch
@cloudflare/vitest-plugin Patch

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

ask-bonk[bot]

This comment was marked as resolved.

@ask-bonk

ask-bonk Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

Adds native Vite/Vite+ fallback command discovery for cf projects.

Posted 1 inline suggestion.

github run

@pkg-pr-new

pkg-pr-new Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@16803

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@16803

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@16803

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@16803

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@16803

create-cloudflare

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

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@16803

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@16803

@cloudflare/pages-shared

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

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@16803

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@16803

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@16803

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 6e62236

@petebacondarwin
petebacondarwin force-pushed the codex/autoconfig-project-commands branch from 58e2aa9 to 160ef6b Compare November 9, 2026 19:09
@petebacondarwin
petebacondarwin marked this pull request as ready for review November 9, 2026 20:56
@workers-devprod
workers-devprod requested review from a team and cjol and removed request for a team November 9, 2026 20:56
@workers-devprod

workers-devprod commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

clanky-the-clanker[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

clanky-the-clanker[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

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.

Superseded by the review of 93977164.

This review, of f35c771e

✅ Approved — The one remaining warning from the last review, the narrower detection of Vite config shapes, is fixed and covered by tests, and no new issues were found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Low release risk. The @cloudflare/autoconfig minor bump fits the change to the experimental cf command-discovery contract.


🔒 Security: ✅ LGTM

The binary path comes from the project's installed package bin metadata. It is quoted for POSIX shells and for cmd.exe. The Vite config is parsed as an AST and is never executed.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

resolveConfigObject now follows identifiers, with a guard against cycles. It unwraps TypeScript as, satisfies and type assertions and looks through defineConfig(...). The config shapes the last review listed are detected again and are covered in packages/autoconfig/tests/vite-config.test.ts. The bounded nodeModulesPaths, the commandError flow, the readiness re-check in run.ts and the Pages and unsupported-framework guards also hold up.


⚡ Performance: ✅ LGTM

Detection adds a few synchronous file reads and one AST parse, which is negligible. The re-detection in run.ts only runs for cf when a build will run and a command error was reported.


📝 Documentation: ✅ LGTM

The new changeset describes the native Vite fallback behaviour accurately.


Reviewed commit: f35c771e

clanky-the-clanker[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

clanky-the-clanker[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

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.

Superseded by the review of 5151dda0.

This review, of dfd0330e

✅ Approved — The earlier WARNING about the CommonJS Vite config guard is fixed: the check now runs before any install, on dry runs too. No new issues were found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Low release risk. The changeset's minor bump of @cloudflare/autoconfig fits this change.


🔒 Security: ✅ LGTM

  • The executable path comes from the bin field of the project's own installed vite or vite-plus package. It is quoted for POSIX shells and for cmd.exe.
  • The Vite config is parsed as an AST and never executed.
  • Dependency lookup stops at the validated workspace root.

📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

Fixed: Vite.configure (frameworks/vite.ts:45-47) now calls assertViteConfigCanBeTransformed before the dryRun check and before installCloudflareVitePlugin. A .cjs/.cts config that uses module.exports or exports.* is therefore rejected before package.json or the lockfile change, and during dry runs too. transformViteConfig keeps the same check for its other callers.

The config file order in vite-config.ts follows Vite's defaults. hasViteConfig and getViteConfigPath read the same list, so detection and the transform pick the same file.


⚡ Performance: ✅ LGTM

Detection adds a few small synchronous filesystem reads and AST walks per run. The re-detection after setup in run.ts runs only when commandError is set.


📝 Documentation: ✅ LGTM

No issues found.


Reviewed commit: dfd0330e

@clanky-the-clanker clanky-the-clanker Bot left a comment •

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.

Superseded by the review of 70d19bed.

This review, of 5151dda0

✅ Approved — No issues found in the changes since the last review. The CommonJS config preflight runs before any install or dry-run exit, and the new tests cover it.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Low release risk. The changeset's minor bump of @cloudflare/autoconfig fits this change.


🔒 Security: ✅ LGTM

No issues found. The Vite config is parsed as an AST and never executed. The executable path comes from the bin field of the project's own installed package and is quoted for the target shell.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

assertViteConfigCanBeTransformed runs before the dryRun check and before the install in Vite.configure. A rejected .cjs or .cts config therefore leaves the project untouched. Detection and the transform pick the config file from the same VITE_CONFIG_FILES list, so they always agree. The new tests cover rejection on both dry and real runs, and configuring ESM source in a .cts file.


⚡ Performance: ✅ LGTM

Detection adds a few small synchronous filesystem reads per run, plus an AST walk over one Vite config file. The cost is negligible.


📝 Documentation: ✅ LGTM

No issues found.


Reviewed commit: 5151dda0

@clanky-the-clanker clanky-the-clanker Bot left a comment •

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.

Superseded by the review of e538b001.

This review, of 70d19bed

✅ Approved — No issues found in the changes since the last review. The config-format preflight runs before any install or dry-run exit, and tests cover it.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Release risk is low. A minor bump of @cloudflare/autoconfig fits this change.


🔒 Security: ✅ LGTM

The Vite config is parsed as an AST and never executed.

The executable path comes from the bin field of the project's own installed vite or vite-plus package. It is quoted for the target shell.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

Vite.configure calls assertViteConfigCanBeTransformed before it checks dryRun and before it installs the plugin.

Detection, hasViteConfig, getViteConfigPath and the transform all choose the config file from the same VITE_CONFIG_FILES list, so they always agree on which file to use.

.cjs configs are always rejected. .cts configs are accepted only when the exported object is the same one the transform rewrites.


⚡ Performance: ✅ LGTM

No issues found.


📝 Documentation: ✅ LGTM

No issues found.


Reviewed commit: 70d19bed

@jamesopstad jamesopstad left a comment

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.

Thanks for working through the earlier comments. My main suggestion now is that we drop the Vite config check as there are too many edge cases where it could fail.

@petebacondarwin
petebacondarwin force-pushed the codex/autoconfig-project-commands branch from 48ab6ac to a6997c3 Compare November 13, 2026 19:37

@workers-devprod workers-devprod left a comment

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.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Nov 13, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

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.

Superseded by the review of a5925523.

This review, of a6997c3b

✅ Approved — No findings: the changes since the last review (one config-file precedence list, a CommonJS check before installing dependencies, the changeset) are correct and covered by tests.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Low. A minor bump of @cloudflare/autoconfig fits this change.


🔒 Security: ✅ LGTM

The executable path comes from the bin field of the project's own installed vite or vite-plus package and is quoted for the target shell. The node_modules lookup stops at the validated workspace root. The Vite config is parsed as an AST and never executed.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

  • Config-file order: detection, path lookup and plugin detection now use one VITE_CONFIG_FILES list, in Vite's precedence order.
  • CommonJS check: assertViteConfigCanBeTransformed runs before dependency installation, including on dry runs. It also runs inside transformViteConfig, so it cannot be skipped.
  • Export resolution: resolveConfigObject follows identifiers, as/satisfies wrappers, parentheses and defineConfig calls, and stops on cycles.
  • Tests: they cover config-file precedence, .cjs/.cts files and mixed exports, and check that the config file is left unmodified when the CommonJS check rejects it.

⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The changeset matches the shipped behaviour.


Reviewed commit: a6997c3b

devin-ai-integration[bot]

This comment was marked as resolved.

clanky-the-clanker[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

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.

Superseded by the review of 6e622362.

This review, of 0413e4e5

✅ Approved — The earlier Yarn workspace-root warning is fixed, and the code changed since the last review has no new issues.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Low. The changeset's version bumps fit the scope of the change.


🔒 Security: ✅ LGTM

The executable path comes from the bin field of the project's own installed vite or vite-plus package. It is quoted for the target shell. The node_modules lookup does not go past the validated workspace root.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

getInstallCommand now uses a flag for each package manager: -W for Yarn, --workspace-root for pnpm and nub, and nothing for npm and bun. The flag is only added at a workspace root. The lookup boundary, the root-manifest scoping, the readiness check during setup and the CommonJS preflight all look correct.


⚡ Performance: ✅ LGTM

The lookups are bounded and the readiness check runs at most once.


📝 Documentation: ✅ LGTM

The changeset matches what the code does.


Reviewed commit: 0413e4e5

@clanky-the-clanker clanky-the-clanker Bot left a comment

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.

✅ Approved — No issues found in the changes since the previously approved commit. The workspace runner scoping, lookup boundary and install guidance are correct and tested.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Risk: Low. A minor bump for @cloudflare/autoconfig and a patch for wrangler fit the change.


🔒 Security: ✅ LGTM

The executable path comes from the bin field of the project's own installed vite or vite-plus package and is quoted for the platform shell. The install hint is built from fixed strings. The CommonJS preflight only checks file extensions and never runs the config.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

The runner priority (app first, then workspace root, then vite), the conditions for reading the workspace root manifest, the getNodeModulesPaths boundary, the ordering of the Pages guard, and the per-manager workspace-root install flags are all correct and covered by tests.


⚡ Performance: ✅ LGTM

Each detection runs a bounded number of file existence checks and manifest reads, once.


📝 Documentation: ✅ LGTM

The changeset matches the implemented behaviour, including the lookup boundary at the workspace root, which replaces the broader guidance in the earlier generated changelog entry.


Reviewed commit: 6e622362

@petebacondarwin
petebacondarwin merged commit b219078 into main Nov 14, 2026
84 of 86 checks passed
@petebacondarwin
petebacondarwin deleted the codex/autoconfig-project-commands branch November 14, 2026 08:22
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants