Skip to content

Commit edf896d

Browse files
ascorbicpenalosa
andauthored
Use detected framework names in autoconfig (#11366)
* Use detected framework names in autoconfig * Fix type * Snap * Update packages/wrangler/src/autoconfig/frameworks/index.ts Co-authored-by: Somhairle MacLeòid <smacleod@cloudflare.com> * Format * Change signature for getFramework --------- Co-authored-by: Somhairle MacLeòid <smacleod@cloudflare.com>
1 parent 2ca70b1 commit edf896d

File tree

10 files changed

+23
-27
lines changed

10 files changed

+23
-27
lines changed

.changeset/swift-pants-create.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Use correctly-formatted names when displayed detected framework details

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ describe("autoconfig (deploy)", () => {
158158
configured: false,
159159
workerName: "my-worker",
160160
framework: {
161-
name: "fake",
161+
name: "Fake",
162162
configure: configureSpy,
163163
} as unknown as Framework,
164164
outputDir: "dist",
@@ -173,7 +173,7 @@ describe("autoconfig (deploy)", () => {
173173
"
174174
Detected Project Settings:
175175
- Worker Name: my-worker
176-
- Framework: fake
176+
- Framework: Fake
177177
- Build Command: echo 'built' > build.txt
178178
- Output Directory: dist
179179

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe("wrangler setup", () => {
119119
120120
Detected Project Settings:
121121
- Worker Name: <WORKER_NAME>
122-
- Framework: static
122+
- Framework: Static
123123
- Output Directory: <cwd>/public
124124
125125

packages/wrangler/src/autoconfig/details.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ export async function getDetailsForAutoConfig({
131131

132132
const detectedFramework: Settings | undefined = buildSettings?.[0];
133133

134-
const framework: AutoConfigDetails["framework"] = getFramework(
135-
detectedFramework?.framework.id
136-
);
134+
const framework = getFramework(detectedFramework?.framework);
137135
const packageJsonPath = resolve(projectPath, "package.json");
138136

139137
let packageJson: PackageJSON | undefined;

packages/wrangler/src/autoconfig/frameworks/astro.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import type { ConfigurationOptions } from ".";
77
import type { RawConfig } from "@cloudflare/workers-utils";
88

99
export class Astro extends Framework {
10-
name = "astro";
11-
1210
async configure({
1311
outputDir,
1412
dryRun,
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { Astro } from "./astro";
22
import { Static } from "./static";
33
import { SvelteKit } from "./sveltekit";
4+
import type { Framework } from ".";
45

5-
export function getFramework(id: string) {
6-
if (id === "astro") {
7-
return new Astro();
6+
export function getFramework(detectedFramework?: {
7+
id: string;
8+
name: string;
9+
}): Framework {
10+
switch (detectedFramework?.id) {
11+
case "astro":
12+
return new Astro(detectedFramework.name);
13+
case "svelte-kit":
14+
return new SvelteKit(detectedFramework.name);
15+
default:
16+
return new Static(detectedFramework?.name);
817
}
9-
if (id === "svelte-kit") {
10-
return new SvelteKit();
11-
}
12-
13-
return new Static(id);
1418
}

packages/wrangler/src/autoconfig/frameworks/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type ConfigurationOptions = {
77
dryRun: boolean;
88
};
99
export abstract class Framework {
10-
abstract name: string;
10+
constructor(public name: string = "Static") {}
1111

1212
// Override commands used to configure the project. Most frameworks should not need to do this, as their default detected build command will be sufficient
1313
preview?: string; // default is `npm run build && wrangler dev`

packages/wrangler/src/autoconfig/frameworks/static.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import type { ConfigurationOptions } from ".";
33
import type { RawConfig } from "@cloudflare/workers-utils";
44

55
export class Static extends Framework {
6-
name: string;
7-
constructor(name: string) {
8-
super();
9-
this.name = name ?? "static";
10-
}
11-
126
configure({
137
outputDir,
148
}: ConfigurationOptions): Promise<RawConfig> | RawConfig {

packages/wrangler/src/autoconfig/frameworks/sveltekit.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import type { ConfigurationOptions } from ".";
88
import type { RawConfig } from "@cloudflare/workers-utils";
99

1010
export class SvelteKit extends Framework {
11-
name = "svelte-kit";
12-
1311
async configure({ dryRun }: ConfigurationOptions): Promise<RawConfig> {
1412
const { dlx } = await getPackageManager();
1513
if (!dryRun) {

packages/wrangler/src/autoconfig/run.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { confirm } from "../dialogs";
66
import { logger } from "../logger";
77
import { sendMetricsEvent } from "../metrics";
88
import { getDevCompatibilityDate } from "../utils/compatibility-date";
9-
import { capitalize } from "../utils/strings";
109
import { addWranglerToAssetsIgnore } from "./add-wrangler-assetsignore";
1110
import { addWranglerToGitIgnore } from "./c3-vendor/add-wrangler-gitignore";
1211
import { installWrangler } from "./c3-vendor/packages";
@@ -233,7 +232,7 @@ export async function buildOperationsSummary(
233232
logger.log(
234233
`🛠️ ${
235234
autoConfigDetails.framework.configurationDescription ??
236-
`Configuring project for ${capitalize(autoConfigDetails.framework.name)}`
235+
`Configuring project for ${autoConfigDetails.framework.name}`
237236
}`
238237
);
239238
logger.log("");

0 commit comments

Comments
 (0)