Prevent web-deploy when no web frontend is selected

This commit is contained in:
Aman Varshney
2025-07-07 18:07:36 +05:30
parent dd31abd190
commit d344b85922
6 changed files with 64 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
import type { ProjectConfig } from "./types";
import type { ProjectConfig, Frontend } from "./types";
import { getUserPkgManager } from "./utils/get-package-manager";
const __filename = fileURLToPath(import.meta.url);
@@ -126,3 +126,14 @@ export const ADDON_COMPATIBILITY = {
starlight: [],
none: [],
} as const;
// TODO: need to refactor this
export const WEB_FRAMEWORKS: readonly Frontend[] = [
"tanstack-router",
"react-router",
"tanstack-start",
"next",
"nuxt",
"svelte",
"solid",
];

View File

@@ -1,8 +1,12 @@
import { cancel, isCancel, select } from "@clack/prompts";
import pc from "picocolors";
import { DEFAULT_CONFIG } from "../constants";
import { DEFAULT_CONFIG, WEB_FRAMEWORKS } from "../constants";
import type { Backend, Frontend, Runtime, WebDeploy } from "../types";
function hasWebFrontend(frontends: Frontend[]): boolean {
return frontends.some((f) => WEB_FRAMEWORKS.includes(f));
}
type DeploymentOption = {
value: WebDeploy;
label: string;
@@ -29,15 +33,18 @@ export async function getDeploymentChoice(
deployment?: WebDeploy,
_runtime?: Runtime,
_backend?: Backend,
_frontend: Frontend[] = [],
frontend: Frontend[] = [],
): Promise<WebDeploy> {
if (deployment !== undefined) return deployment;
if (!hasWebFrontend(frontend)) {
return "none";
}
const options: DeploymentOption[] = [
{
value: "workers",
label: "Cloudflare Workers",
hint: "Deploy to Cloudflare Workers using Wrangler",
hint: "Deploy to Cloudflare Workers using Wrangler",
},
{ value: "none", label: "None", hint: "Manual setup" },
];
@@ -57,9 +64,13 @@ export async function getDeploymentChoice(
}
export async function getDeploymentToAdd(
_frontend: Frontend[],
frontend: Frontend[],
existingDeployment?: WebDeploy,
): Promise<WebDeploy> {
if (!hasWebFrontend(frontend)) {
return "none";
}
const options: DeploymentOption[] = [];
if (existingDeployment !== "workers") {

View File

@@ -16,6 +16,7 @@ import {
type Runtime,
type WebDeploy,
} from "./types";
import { WEB_FRAMEWORKS } from "./constants";
export function processAndValidateFlags(
options: CLIInput,
@@ -125,15 +126,8 @@ export function processAndValidateFlags(
const validOptions = options.frontend.filter(
(f): f is Frontend => f !== "none",
);
const webFrontends = validOptions.filter(
(f) =>
f === "tanstack-router" ||
f === "react-router" ||
f === "tanstack-start" ||
f === "next" ||
f === "nuxt" ||
f === "svelte" ||
f === "solid",
const webFrontends = validOptions.filter((f) =>
WEB_FRAMEWORKS.includes(f),
);
const nativeFrontends = validOptions.filter(
(f) => f === "native-nativewind" || f === "native-unistyles",
@@ -451,6 +445,16 @@ export function processAndValidateFlags(
process.exit(1);
}
const hasWebFrontendFlag = (config.frontend ?? []).some((f) =>
WEB_FRAMEWORKS.includes(f),
);
if (config.webDeploy && config.webDeploy !== "none" && !hasWebFrontendFlag) {
consola.fatal(
"'--web-deploy' requires a web frontend. Please select a web frontend or set '--web-deploy none'.",
);
process.exit(1);
}
return config;
}