Skip to content

[autoconfig] Stop in non-interactive runs when the root holds static files and a Pages functions directory - #16369

Open
MattieTK wants to merge 1 commit into
mainfrom
fix/autoconfig-pages-functions-root
Open

MattieTK wants to merge 1 commit into
mainfrom
fix/autoconfig-pages-functions-root

Conversation

@MattieTK

@MattieTK MattieTK commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

When a project without a detected framework has a functions directory, autoconfig asks whether it is a Cloudflare Pages project (isPagesProject in framework-detection.ts). In non-interactive runs (CI, Workers Builds, coding agents) the prompt falls back to "no", and the project is configured as a static site. When the static files are in the project root, findAssetsDir returns ".", so the project root is deployed as static assets and the Pages Functions (the project's API routes) are not deployed. The deploy succeeds and the routes return the static fallback instead. Interactively, answering "yes" fails with "Automatically migrating from a Pages project to Workers is not yet supported", so only non-interactive runs reach this outcome.

Change

In getDetailsForAutoConfig, stop with an AutoConfigDetectionError when all of these hold:

  • the framework is the static one (no framework detected and not detected as Pages);
  • context.isNonInteractiveOrCI() is true, the same signal that makes the Pages prompt fall back to "no";
  • the output directory resolves to the project root;
  • <projectRoot>/functions is a directory.

The error tells the user how to continue, depending on what functions is:

This project has a `functions` directory and static files in its root, which looks like a Cloudflare Pages project using Pages Functions. Automatic configuration cannot migrate Pages Functions to Workers yet, and deploying the project root as static assets would leave the Functions undeployed.
If `functions` contains Pages Functions, move the static files into a subdirectory (for example `public/`) and deploy with `wrangler pages deploy public --project-name <name>`, or migrate the Functions to a Worker: https://developers.cloudflare.com/workers/static-assets/migration-guides/migrate-from-pages/
If `functions` is not Pages Functions, move the static files into a subdirectory or add a Wrangler configuration file for the Worker.

(The last line names cloudflare.config.ts for the cf target.) The Pages remedy deploys a subdirectory rather than ., because a direct Pages upload of the project root would also upload files such as .env.

Scope

The condition is deliberately narrow. These cases are unaffected:

  • static files in a subdirectory, for example a functions directory for another platform (Firebase) next to public/: autoconfig continues to deploy public/ as before;
  • projects detected as Pages through pages_build_output_dir or the Pages cache, and projects with a detected framework;
  • interactive runs, where the user answers the prompt themselves;
  • projects that already have a Wrangler configuration (autoconfig does not run).

The only callers that reach this are wrangler deploy (including --dry-run) and wrangler setup. wrangler dev, the Vite plugin and C3 do not, and Pages-to-Workers delegation already declines projects with functions/. A static site with a root index.html and a non-Pages functions/ folder of its own (for example HTML pages) will now stop in CI and needs one of the listed remedies.


  • 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 adds an error for a configuration autoconfig cannot handle correctly; no configuration or flags change, and the error message explains how to proceed.

Tests cover the error (and its wording for both targets), and the cases that must not throw: static files in a subdirectory, an interactive "no", a detected framework, functions as a file, and projects detected as Pages through pages_build_output_dir or the Pages cache. Removing either the static-framework or the directory condition makes a test fail. Checked manually with the built Wrangler, run non-interactively as an agent: wrangler deploy --dry-run and wrangler setup --yes on a project with a root index.html and functions/api/hello.js stop with the error and write no files, and the same with the HTML under public/ continues with Output Directory: public. Full wrangler and @cloudflare/autoconfig suites, check:type, type:tests, check:lint and check:format pass locally.


Devin Review

…files and a Pages functions directory

When no framework is detected and a functions directory exists,
autoconfig asks whether the project is a Cloudflare Pages project.
Non-interactive runs (CI and coding agents) assume it is not and carry
on as a static site. With the static files in the project root, the
root is deployed as static assets and the Pages Functions, the
project's API routes, are silently left undeployed.

Stop with an error in that case, explaining that Pages Functions cannot
be migrated automatically yet and how to continue for each situation.
Projects with their static files in a subdirectory (such as a
functions directory for another platform next to public/), projects
detected as Pages or with a framework, and interactive runs are
unaffected.
@changeset-bot

changeset-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 189150f

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 Patch
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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Oct 19, 2026
@workers-devprod
workers-devprod requested review from a team and jamesopstad and removed request for a team October 19, 2026 23:09
@workers-devprod

workers-devprod commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

// is not and continue as a static site, which would deploy the project root
// as assets and silently drop the Functions (the API routes). Stop instead.
if (
framework.id === staticFramework.id &&

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.

getFrameworkClassInstance() maps unrecognized detected framework IDs to staticFramework, so this check also fires for projects whose framework was detected but is not in allFrameworksInfos. A root-output project using such a framework and its own functions/ directory now aborts in CI, contrary to the intended "no framework detected" scope. Base this on the detector result instead.

Suggested change
framework.id === staticFramework.id &&
detectedFramework.framework.id === staticFramework.id &&

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

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

Devin Review

@ask-bonk

ask-bonk Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

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

Autoconfig now stops non-interactive root static deployments containing a functions/ directory.

  1. High packages/autoconfig/src/details/index.ts:215: Unrecognized detected frameworks are treated as static and now incorrectly abort in CI. Posted a suggestion comment.

github run

@clanky-the-clanker

Copy link
Copy Markdown

✅ Approved — A narrowly scoped, well-tested guard that stops non-interactive autoconfig from deploying the project root while leaving Pages Functions undeployed. No issues found.

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


✅ All checks passed

🔒 Security: ✅ LGTM

No security concerns. The suggested Pages remedy deploys a subdirectory rather than the project root, so files such as .env are not uploaded.


📖 AGENTS.md: ✅ LGTM

The change follows the repository conventions. A changeset is included.


📋 Code Quality: ✅ LGTM

The new guard in packages/autoconfig/src/details/index.ts is correct and narrowly scoped. Its imports are already in the file, and it runs after the configured early return and the outputDir check. The tests cover the error for both targets and each case that should not throw. I did not run the tests.


⚡ Performance: ✅ LGTM

The guard adds at most one stat call, and only after the cheaper checks pass.


📝 Documentation: ✅ LGTM

The changeset and the error message describe the behavior accurately.


Reviewed commit: 189150fe

@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

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

@cloudflare/build-output-utils

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

@cloudflare/codemods

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

@cloudflare/config

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

@cloudflare/containers-shared

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

create-cloudflare

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

@cloudflare/deploy-helpers

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-functions

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

@cloudflare/pages-shared

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

@cloudflare/runtime-types

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-plugin

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

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 189150f

@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.

The Bonk suggestion seems valid. Otherwise looks good.

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants