Skip to content

Commit e6fea13

Browse files
[vite-plugin] add validation for configPaths (#8572)
* [vite-plugin] add validation for `configPath`s * Apply suggestions from code review Co-authored-by: James Opstad <[email protected]> * remove extra describe block * rename `configPath` to `entryWorkerConfigPath` * add `allowedWranglerConfigExtensions` const * add missing arguments * update tests --------- Co-authored-by: James Opstad <[email protected]>
1 parent e9106df commit e6fea13

File tree

14 files changed

+287
-17
lines changed

14 files changed

+287
-17
lines changed

.changeset/sharp-dogs-love.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/vite-plugin": patch
3+
---
4+
5+
Add validation for the `configPath` option in the plugin config that clearly indicates any issues.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
fetch() {
3+
return new Response("Hello world");
4+
},
5+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "@vite-plugin-cloudflare-e2e/no-wrangler-config-for-auxiliary-worker",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite"
8+
},
9+
"devDependencies": {
10+
"@cloudflare/vite-plugin": "*",
11+
"vite": "^6.1.0"
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { cloudflare } from "@cloudflare/vite-plugin";
2+
import { defineConfig } from "vite";
3+
4+
export default defineConfig({
5+
plugins: [
6+
cloudflare({
7+
auxiliaryWorkers: [{ configPath: "./aux-worker/wrangler.toml" }],
8+
}),
9+
],
10+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "no-wrangler-config-for-auxiliary-worker"
2+
compatibility_date = "2024-12-30"
3+
main = "index.ts"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "@vite-plugin-cloudflare-e2e/no-wrangler-config",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite"
8+
},
9+
"devDependencies": {
10+
"@cloudflare/vite-plugin": "*",
11+
"vite": "^6.1.0"
12+
}
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { cloudflare } from "@cloudflare/vite-plugin";
2+
import { defineConfig } from "vite";
3+
4+
export default defineConfig({
5+
plugins: [cloudflare()],
6+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { describe } from "vitest";
2+
import { runCommand, test } from "./helpers.js";
3+
4+
// Note: the tests here just make sure that the validation does take place, for more fine grained
5+
// testing regarding the validation there are unit tests in src/__tests__/get-validated-wrangler-config-path.spec.ts
6+
7+
describe("during development wrangler config files are validated", () => {
8+
test("for the entry worker", async ({ expect, seed, viteCommand }) => {
9+
const projectPath = await seed("no-wrangler-config");
10+
runCommand(`pnpm install`, projectPath);
11+
12+
const proc = await viteCommand("pnpm", "dev", projectPath);
13+
14+
expect(await proc.exitCode).not.toBe(0);
15+
expect(proc.stderr).toMatch(
16+
/Error: No config file found in the .*? directory/
17+
);
18+
});
19+
20+
test("for auxiliary workers", async ({ expect, seed, viteCommand }) => {
21+
const projectPath = await seed("no-wrangler-config-for-auxiliary-worker");
22+
runCommand(`pnpm install`, projectPath);
23+
24+
const proc = await viteCommand("pnpm", "dev", projectPath);
25+
26+
expect(await proc.exitCode).not.toBe(0);
27+
expect(proc.stderr).toMatch(
28+
/The provided configPath .*? requested for one of your auxiliary workers doesn't point to an existing file/
29+
);
30+
});
31+
});

packages/vite-plugin-cloudflare/src/__tests__/fixtures/empty-dir.toml/.gitkeep

Whitespace-only changes.

packages/vite-plugin-cloudflare/src/__tests__/fixtures/empty-dir/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)