Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
07afabe
[autoconfig] Scaffold project files for cf setup
petebacondarwin Nov 25, 2026
88a94a0
[autoconfig] Address project scaffolding review
petebacondarwin Nov 25, 2026
01dfe4d
[autoconfig] Preserve workspace Vite and skip ignored dangling assets
petebacondarwin Nov 25, 2026
0954062
[autoconfig] Verify workspace runners and allowed asset links
petebacondarwin Nov 25, 2026
e2ab99b
[autoconfig] Normalize Windows line endings in Vite config test
petebacondarwin Nov 25, 2026
330a43b
[autoconfig] Cover already-installed Vite+ workspace runner
petebacondarwin Nov 26, 2026
536b32e
[build-output-utils] Simplify broken asset symlink handling
petebacondarwin Nov 26, 2026
28c2ad9
[wrangler] Respect .assetsignore when watching assets
petebacondarwin Nov 26, 2026
a6a498e
[wrangler] Reload assets when metadata casing differs
petebacondarwin Nov 26, 2026
e41f9d8
[wrangler] Match asset metadata watcher to filesystem casing
petebacondarwin Nov 26, 2026
d896324
[wrangler] Cover uppercase-only assets metadata
petebacondarwin Nov 26, 2026
d4f65a3
[autoconfig] Address project scaffolding review feedback
petebacondarwin Nov 27, 2026
717ceb1
[autoconfig] Check for TypeScript after framework setup
petebacondarwin Nov 27, 2026
6a4f2d7
Apply suggestion from @jamesopstad
petebacondarwin Nov 27, 2026
4b93e19
[autoconfig] Mark newly scaffolded packages as ESM
petebacondarwin Nov 27, 2026
69ecbfe
[miniflare] Preserve directory symlinks in asset scanning
petebacondarwin Nov 27, 2026
40bd9ab
[autoconfig] Default project file confirmation to yes
petebacondarwin Nov 27, 2026
ff06edf
Let callers filter build output assets
petebacondarwin Nov 27, 2026
ba27f1d
Test asset copy filters in workers-shared
petebacondarwin Nov 27, 2026
f78c65c
Guard all asset directory descents against ancestor cycles
petebacondarwin Nov 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/cf-autoconfig-project-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@cloudflare/autoconfig": minor
"@cloudflare/build-output-utils": minor
"@cloudflare/cli-shared-helpers": patch
"@cloudflare/workers-utils": minor
"miniflare": patch
"wrangler": patch
---

Create missing project files and install their tooling when autoconfig generates `cloudflare.config.ts`.

Projects get a local manifest and TypeScript config where needed, along with default `cf dev` and `cf build` scripts when those scripts are missing. Interactive setup asks before creating these files; non-interactive runs, such as CI, accept the additions without prompting. Existing scripts, compiler settings, and the project's choice of build tool are preserved, including Vite runners declared at the workspace root. New manifests set `"type": "module"` so Node loads `cloudflare.config.ts` without a module-type warning. Existing manifests keep their module type. Autoconfig reports when an explicit CommonJS package setting prevents it from writing a usable `cloudflare.config.ts`.

For static sites that serve the project root, autoconfig adds `node_modules`, `.cloudflare`, and the new configuration and package-manager files to `.assetsignore`. Wrangler's asset watcher, local asset serving, and build output skip directories according to those rules, which you can edit to include paths you want to serve. Local dev still follows directory symlinks, but does not revisit ancestor directories.

Builds do not support broken asset symlinks. A missing target fails the build unless `.assetsignore` excludes the link regardless of whether it points to a file or a directory.

`writeAssets` accepts an optional filter. It does not apply `.assetsignore` when no filter is provided. Wrangler uses the shared `createAssetsCopyFilter` helper to honor `.assetsignore` and preserve asset metadata in build output.
1 change: 1 addition & 0 deletions packages/autoconfig/src/details/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export async function getDetailsForAutoConfig({
packageJson,
packageManager,
nodeModulesPaths,
workspaceRoot,
commandError: viteCommands?.error,
devCommand: useStaticAssets
? undefined
Expand Down
51 changes: 36 additions & 15 deletions packages/autoconfig/src/details/vite-commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from "node:fs";
import { existsSync, statSync } from "node:fs";
import { join, resolve } from "node:path";
import { parsePackageJSON, readFileSync } from "@cloudflare/workers-utils";
import semiver from "semiver";
Expand All @@ -12,6 +12,8 @@ type ProjectPackageJSON = PackageJSON & {
optionalDependencies?: Record<string, unknown>;
};

export type ViteRunner = "vite" | "vite-plus";

/** Whether the project uses Vite+ as its Vite command runner. */
export function usesVitePlus(packageJson?: PackageJSON): boolean {
return Boolean(
Expand Down Expand Up @@ -63,7 +65,7 @@ export function getViteProjectCommands({
("@cloudflare/vite-plugin" in projectDependencies ||
projectRunner ||
hasViteConfig(projectPath))
? readPackage(join(workspaceRoot, "package.json"))
? readWorkspacePackage(workspaceRoot)
: undefined;
const dependencies = {
...getDeclaredDependencies(workspacePackageJson),
Expand Down Expand Up @@ -112,14 +114,8 @@ export function getViteProjectCommands({
}

const commandName = packageName === "vite-plus" ? "vp" : "vite";
const tool = readProjectPackage(nodeModulesPaths, packageName);
const bin = tool?.packageJson.bin;
const relativeBinary = typeof bin === "string" ? bin : bin?.[commandName];
const binary =
tool && relativeBinary
? resolve(tool.directory, relativeBinary)
: undefined;
if (!binary || !existsSync(binary)) {
const binary = resolveViteRunnerExecutable(nodeModulesPaths, packageName);
if (!binary) {
return {
error: {
code: "vite-tool-not-installed",
Expand All @@ -140,10 +136,31 @@ export function getViteProjectCommands({
};
}

/** Peer and optional declarations alone do not select a project's command runner. */
function getViteRunner(
/** Finds the installed executable for the selected runner, not just its Vite core dependency. */
export function resolveViteRunnerExecutable(
nodeModulesPaths: readonly string[],
runner: ViteRunner
): string | undefined {
const tool = readProjectPackage(nodeModulesPaths, runner);
const commandName = runner === "vite-plus" ? "vp" : "vite";
const bin = tool?.packageJson.bin;
const relativeBinary = typeof bin === "string" ? bin : bin?.[commandName];
if (tool && relativeBinary) {
const binary = resolve(tool.directory, relativeBinary);
try {
if (statSync(binary).isFile()) {
return binary;
}
} catch {
return;
}
}
}

/** Selects the Vite runner declared in a manifest, ignoring peer and optional dependencies. */
export function getViteRunner(
packageJson?: PackageJSON
): "vite" | "vite-plus" | undefined {
): ViteRunner | undefined {
if (usesVitePlus(packageJson)) {
return "vite-plus";
}
Expand All @@ -161,9 +178,13 @@ function getDeclaredDependencies(packageJson?: ProjectPackageJSON) {
};
}

function readPackage(path: string): ProjectPackageJSON | undefined {
/** Reads the manifest of a validated workspace root, if one exists. */
export function readWorkspacePackage(
workspaceRoot: string
): ProjectPackageJSON | undefined {
const packageJsonPath = join(workspaceRoot, "package.json");
try {
return parsePackageJSON(readFileSync(path), path);
return parsePackageJSON(readFileSync(packageJsonPath), packageJsonPath);
} catch {
return;
}
Expand Down
1 change: 1 addition & 0 deletions packages/autoconfig/src/frameworks/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class Astro extends Framework {
return {
// `astro add` owns the Cloudflare configuration.
workerConfig: null,
createsCloudflareConfig: true,
};
}

Expand Down
2 changes: 2 additions & 0 deletions packages/autoconfig/src/frameworks/framework-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export type ConfigurationResults = {
buildTool?: "vite" | "wrangler";
/** Worker configuration generated by the framework. `null` if an external tool generates it. */
workerConfig: Partial<WorkerConfig> | null;
/** Whether the framework's setup generates `cloudflare.config.ts` itself. */
createsCloudflareConfig?: boolean;
/** Build configuration that complements the Worker configuration. */
buildConfig?: BuildConfig;
// Scripts to override in the package.json. Most frameworks should not need to do this, as their default detected build command will be sufficient
Expand Down
1 change: 1 addition & 0 deletions packages/autoconfig/src/frameworks/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ async function configureWithVinext({
buildTool: "vite",
// `vinext init` creates the cloudflare.config.ts file
workerConfig: null,
createsCloudflareConfig: true,
buildCommandOverride: `${npx} vite build`,
};
}
Expand Down
1 change: 1 addition & 0 deletions packages/autoconfig/src/frameworks/react-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ export class ReactRouter extends Framework {
writeEntryServerTsx(useMiddlewarePattern, context);

transformViteConfig(projectPath, {
target,
viteEnvironmentName: "ssr",
incompatibleVitePlugins: ["netlifyReactRouter"],
});
Expand Down
2 changes: 1 addition & 1 deletion packages/autoconfig/src/frameworks/solid-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class SolidStart extends Framework {
projectPath,
version: CF_VITE_PLUGIN_VERSION_RANGE,
});
transformViteConfig(projectPath);
transformViteConfig(projectPath, { target });
// SolidStart 2.2.3 and later add this exclude themselves
if (semiver(this.frameworkVersion, "2.2.3") < 0) {
excludeSolidStartFromServerPrebundling(projectPath, context);
Expand Down
2 changes: 1 addition & 1 deletion packages/autoconfig/src/frameworks/tanstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class TanstackStart extends Framework {
version: target === "cf" ? CF_VITE_PLUGIN_VERSION_RANGE : undefined,
});

transformViteConfig(projectPath, { viteEnvironmentName: "ssr" });
transformViteConfig(projectPath, { target, viteEnvironmentName: "ssr" });
}

return {
Expand Down
Loading
Loading