Skip to content

Commit d25f7e2

Browse files
Wrangler: fix autoconfig using absolute paths for static projects (#11455)
1 parent b154de2 commit d25f7e2

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

.changeset/slick-beers-cover.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Fix autoconfig using absolute paths for static projects
6+
7+
Running the experimental autoconfig logic through `wrangler setup` and `wrangler deploy --x-autoconfig` on a static project results in absolute paths being used, this is incorrect, especially when such paths are being included in the generated wrangler.jsonc, the changes here fix the autoconfig logic to instead use paths relative to the project's root instead.
8+
9+
For example given a project located in `/Users/usr/projects/sites/my-static-site`, before:
10+
11+
```ts
12+
// wrangler.jsonc at /Users/usr/projects/sites/my-static-site
13+
{
14+
"$schema": "node_modules/wrangler/config-schema.json",
15+
"name": "static",
16+
"compatibility_date": "2025-11-27",
17+
"observability": {
18+
"enabled": true
19+
},
20+
"assets": {
21+
"directory": "/Users/usr/projects/sites/my-static-site/public"
22+
}
23+
}
24+
```
25+
26+
and after:
27+
28+
```ts
29+
// wrangler.jsonc at /Users/usr/projects/sites/my-static-site
30+
{
31+
"$schema": "node_modules/wrangler/config-schema.json",
32+
"name": "static",
33+
"compatibility_date": "2025-11-27",
34+
"observability": {
35+
"enabled": true
36+
},
37+
"assets": {
38+
"directory": "public"
39+
}
40+
}
41+
```

packages/wrangler/src/__tests__/autoconfig/details/get-details-for-auto-config.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { randomUUID } from "node:crypto";
22
import { writeFile } from "node:fs/promises";
3-
import { join } from "node:path";
43
import { seed } from "@cloudflare/workers-utils/test-helpers";
54
import { describe, expect, it } from "vitest";
65
import * as details from "../../../autoconfig/details";
@@ -111,7 +110,7 @@ describe("autoconfig details - getDetailsForAutoConfig()", () => {
111110
await writeFile("index.html", `<h1>Hello World</h1>`);
112111

113112
await expect(details.getDetailsForAutoConfig()).resolves.toMatchObject({
114-
outputDir: process.cwd(),
113+
outputDir: ".",
115114
});
116115
});
117116

@@ -122,7 +121,7 @@ describe("autoconfig details - getDetailsForAutoConfig()", () => {
122121
});
123122

124123
await expect(details.getDetailsForAutoConfig()).resolves.toMatchObject({
125-
outputDir: join(process.cwd(), "public"),
124+
outputDir: "public",
126125
});
127126
});
128127

@@ -133,7 +132,7 @@ describe("autoconfig details - getDetailsForAutoConfig()", () => {
133132
});
134133

135134
await expect(details.getDetailsForAutoConfig()).resolves.toMatchObject({
136-
outputDir: process.cwd(),
135+
outputDir: ".",
137136
});
138137
});
139138

packages/wrangler/src/__tests__/setup.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describe("wrangler setup", () => {
120120
Detected Project Settings:
121121
- Worker Name: <WORKER_NAME>
122122
- Framework: Static
123-
- Output Directory: <cwd>/public
123+
- Output Directory: public
124124
125125
126126
📄 Create wrangler.jsonc:

packages/wrangler/src/autoconfig/details.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { statSync } from "node:fs";
22
import { readdir, stat } from "node:fs/promises";
3-
import { basename, join, resolve } from "node:path";
3+
import { basename, join, relative, resolve } from "node:path";
44
import { brandColor } from "@cloudflare/cli/colors";
55
import {
66
FatalError,
@@ -47,14 +47,14 @@ async function hasIndexHtml(dir: string): Promise<boolean> {
4747
*/
4848
async function findAssetsDir(from: string): Promise<string | undefined> {
4949
if (await hasIndexHtml(from)) {
50-
return from;
50+
return ".";
5151
}
5252
const children = await readdir(from);
5353
for (const child of children) {
5454
const path = join(from, child);
5555
const stats = await stat(path);
5656
if (stats.isDirectory() && (await hasIndexHtml(path))) {
57-
return path;
57+
return relative(from, path);
5858
}
5959
}
6060
return undefined;

0 commit comments

Comments
 (0)