Skip to content

Commit b17797c

Browse files
dario-piotrowiczpenalosaascorbic
authored
Autoconfig Vite improvements (#11508)
* Install Vite plugin to vite projects in autoconfig * In autoconfig consider vite projects using the vite plugin as already configured * add e2e tests * update tests * remove unnecessary assets wrangler config * fix formatting * fix tests type issues * remove e2e fixtures from linting * add `single-page-application` `not_found_handling` configuration * Update packages/wrangler/src/autoconfig/frameworks/utils/vite-config.ts Co-authored-by: Somhairle MacLeòid <smacleod@cloudflare.com> * Apply suggestions from code review Co-authored-by: Somhairle MacLeòid <smacleod@cloudflare.com> * Update packages/wrangler/src/autoconfig/frameworks/utils/vite-config.ts Co-authored-by: Somhairle MacLeòid <smacleod@cloudflare.com> * remove wrangler e2e and test React with C3, also add React in the c3 menu * remove barrel file * make `isConfigured` sync * remove setup.test.ts file * remove involutary change * remove duplicated entry * fix incorrect verify check * update changeset * add incompatibleVitePlugins option to transformViteConfig and also use the function for react-router projects * Update .changeset/petite-swans-train.md Co-authored-by: Matt Kane <m@mk.gg> --------- Co-authored-by: Somhairle MacLeòid <smacleod@cloudflare.com> Co-authored-by: Matt Kane <m@mk.gg>
1 parent 8672321 commit b17797c

File tree

17 files changed

+312
-243
lines changed

17 files changed

+312
-243
lines changed

.changeset/old-boxes-find.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Wrangler will no longer try to add additional configuration to projects using `@cloudflare/vite-plugin` when deploying or running `wrangler setup`

.changeset/petite-swans-train.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
When a Vite project is detected, install `@cloudflare/vite-plugin`

packages/create-cloudflare/e2e/helpers/framework-helpers.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,43 @@ export async function verifyTypes(
355355
}
356356
}
357357

358+
export async function verifyCloudflareVitePluginConfigured(
359+
{ verifyCloudflareVitePluginConfigured: verify }: FrameworkTestConfig,
360+
projectPath: string,
361+
) {
362+
if (!verify) {
363+
return;
364+
}
365+
366+
const viteConfigTsPAth = join(projectPath, `vite.config.ts`);
367+
const viteConfigJsPath = join(projectPath, `vite.config.js`);
368+
369+
let viteConfigPath: string;
370+
371+
if (existsSync(viteConfigTsPAth)) {
372+
viteConfigPath = viteConfigTsPAth;
373+
} else if (existsSync(viteConfigJsPath)) {
374+
viteConfigPath = viteConfigJsPath;
375+
} else {
376+
throw new Error("Could not find Vite config file to modify");
377+
}
378+
379+
const prePackageJson = JSON.parse(
380+
readFile(join(projectPath, "package.json")),
381+
) as { devDependencies: Record<string, string> };
382+
383+
expect(
384+
prePackageJson.devDependencies?.["@cloudflare/vite-plugin"],
385+
).not.toBeUndefined();
386+
387+
const viteConfig = readFile(viteConfigPath);
388+
389+
expect(viteConfig).toContain(
390+
'import { cloudflare } from "@cloudflare/vite-plugin"',
391+
);
392+
expect(viteConfig).toMatch(/plugins:\s*?\[.*?cloudflare.*?]/);
393+
}
394+
358395
export function shouldRunTest(testConfig: FrameworkTestConfig) {
359396
return (
360397
// Skip if the test is quarantined

packages/create-cloudflare/e2e/helpers/run-c3.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ export type RunnerConfig = {
6060
};
6161
};
6262
/**
63-
* Specifies whether to verify generated types for the project
63+
* Specifies whether to verify generated types for the project.
6464
*/
6565
verifyTypes?: boolean;
66+
/**
67+
* Verifies whether the Cloudflare Vite plugin has been installed and configured.
68+
*/
69+
verifyCloudflareVitePluginConfigured?: boolean;
6670
};
6771

6872
export const runC3 = async (

packages/create-cloudflare/e2e/tests/frameworks/frameworks.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
runC3ForFrameworkTest,
1717
shouldRunTest,
1818
testGitCommitMessage,
19+
verifyCloudflareVitePluginConfigured,
1920
verifyDeployment,
2021
verifyDevScript,
2122
verifyPreviewScript,
@@ -150,6 +151,11 @@ describe
150151
);
151152

152153
await verifyTypes(testConfig, frameworkConfig, project.path);
154+
155+
await verifyCloudflareVitePluginConfigured(
156+
testConfig,
157+
project.path,
158+
);
153159
} catch (e) {
154160
expect.fail(
155161
"Failed due to an exception while running C3. See logs for more details. Error: " +

packages/create-cloudflare/e2e/tests/frameworks/test-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ function getExperimentalFrameworkTestConfig(
910910
},
911911
nodeCompat: false,
912912
verifyTypes: false,
913+
verifyCloudflareVitePluginConfigured: true,
913914
},
914915
{
915916
name: "react-router",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe("autoconfig details - confirmAutoConfigDetails()", () => {
102102
workerName: "my-astro-site",
103103
buildCommand: "astro build",
104104
framework: {
105-
configured: false,
105+
isConfigured: () => false,
106106
configure: () => ({ wranglerConfig: {} }),
107107
name: "astro",
108108
},
@@ -116,7 +116,7 @@ describe("autoconfig details - confirmAutoConfigDetails()", () => {
116116
"configured": false,
117117
"framework": Object {
118118
"configure": [Function],
119-
"configured": false,
119+
"isConfigured": [Function],
120120
"name": "astro",
121121
},
122122
"outputDir": "",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe("autoconfig details - displayAutoConfigDetails()", () => {
3737
workerName: "my-astro-app",
3838
framework: {
3939
name: "Astro",
40-
configured: false,
40+
isConfigured: () => false,
4141
configure: () => ({ wranglerConfig: {} }),
4242
},
4343
buildCommand: "astro build",

packages/wrangler/src/__tests__/autoconfig/run.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ describe("autoconfig (deploy)", () => {
162162
framework: {
163163
name: "Fake",
164164
configure: configureSpy,
165+
isConfigured: () => false,
165166
} as unknown as Framework,
166167
outputDir: "dist",
167168
packageJson: {

packages/wrangler/src/autoconfig/details.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export async function getDetailsForAutoConfig({
162162

163163
return {
164164
projectPath: projectPath,
165-
configured: framework?.configured ?? false,
165+
configured: framework?.isConfigured(projectPath) ?? false,
166166
framework,
167167
packageJson,
168168
buildCommand: detectedFramework?.buildCommand ?? packageJsonBuild,

0 commit comments

Comments
 (0)