From 246ba0306367f73e9e08a4980ff0b528906c39fb Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 22 Mar 2023 13:12:46 +0000 Subject: [PATCH] refactor: add type safety to auto-detected providers (#1072) --- src/options.ts | 5 +++-- src/utils/index.ts | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/options.ts b/src/options.ts index 6a6bf6b2fe..40f8bc3fc4 100644 --- a/src/options.ts +++ b/src/options.ts @@ -106,7 +106,8 @@ export async function loadOptions( configOverrides: NitroConfig = {} ): Promise { // Preset - let presetOverride = configOverrides.preset || process.env.NITRO_PRESET; + let presetOverride = + (configOverrides.preset as string) || process.env.NITRO_PRESET; const defaultPreset = detectTarget() || "node-server"; if (configOverrides.dev) { presetOverride = "nitro-dev"; @@ -146,7 +147,7 @@ export async function loadOptions( options.preset = presetOverride || - layers.find((l) => l.config.preset)?.config.preset || + (layers.find((l) => l.config.preset)?.config.preset as string) || defaultPreset; options.rootDir = resolve(options.rootDir || "."); diff --git a/src/utils/index.ts b/src/utils/index.ts index 4ea3e1c659..5e04f1ef36 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -7,7 +7,9 @@ import consola from "consola"; import chalk from "chalk"; import { getProperty } from "dot-prop"; import { provider } from "std-env"; -import { Nitro } from "../types"; +import type { ProviderName } from "std-env"; +import { KebabCase, Nitro } from "../types"; +import type * as _PRESETS from "../presets"; export function hl(str: string) { return chalk.cyan(str); @@ -98,9 +100,11 @@ export function replaceAll(input: string, from: string, to: string) { return input.replace(new RegExp(from, "g"), to); } -const autodetectableProviders = { +const autodetectableProviders: Partial< + Record> +> = { azure_static: "azure", - cloudflare_pages: "cloudflare_pages", + cloudflare_pages: "cloudflare-pages", netlify: "netlify", stormkit: "stormkit", vercel: "vercel",