Repository navigation
[autoconfig] Resolve native Vite fallback commands for cf - #16803
Conversation
🦋 Changeset detectedLatest commit: 6e62236 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
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. |
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/codemods
@cloudflare/config
@cloudflare/containers-shared
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/runtime-types
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-plugin
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
58e2aa9 to
160ef6b
Compare
|
Codeowners approval required for this PR:
Show detailed file reviewers |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
binfield of the project's own installedviteorvite-pluspackage. 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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
48ab6ac to
a6997c3
Compare
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
There was a problem hiding this comment.
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_FILESlist, in Vite's precedence order. - CommonJS check:
assertViteConfigCanBeTransformedruns before dependency installation, including on dry runs. It also runs insidetransformViteConfig, so it cannot be skipped. - Export resolution:
resolveConfigObjectfollows identifiers,as/satisfieswrappers, parentheses anddefineConfigcalls, and stops on cycles. - Tests: they cover config-file precedence,
.cjs/.ctsfiles 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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
✅ 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
Problem
In
cf, vite-plugin projects can have no detected frameworkdev/buildcommand. Autoconfig currently leaves those command fields empty, forcingcfto select a plugin-owned delegate or hardcode a Vite executable. That also bypasses Vite+ command selection.Solution
Have
autoconfigreturn the project's native Vite or Vite+ executable through the existingdevCommandandbuildCommandfields in those cases. Read the selected package’sbinmetadata 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 incommandErrorso read-only callers can inspect projects before installing dependencies; cf validates readiness at execution.>=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.--configoverrides. Preserve Wrangler's existing plugin detection; keep Vite's config-file precedence and the CommonJS setup preflight before dependency installation, including dry runs. Reject.ctsand.cjstransformations 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.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.tsarguments, 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
cf-vite.Keeping this change separate allows autoconfig to release before the executable removal.
Validation (Node.js 22.22.1, pnpm 10.33.0):
pnpm checkpassed: 206 tasks..ctsfiles. A manual check with Vite’s actual config loader confirmed the import-only plugin fails from.ctsand loads from an identical.mtsconfig.Note
This is a contribution from an AI agent: Codex.