Skip to content

Commit

Permalink
refactor: add type safety to auto-detected providers (#1072)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Mar 22, 2023
1 parent a022135 commit 246ba03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export async function loadOptions(
configOverrides: NitroConfig = {}
): Promise<NitroOptions> {
// 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";
Expand Down Expand Up @@ -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 || ".");
Expand Down
10 changes: 7 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<ProviderName, KebabCase<keyof typeof _PRESETS>>
> = {
azure_static: "azure",
cloudflare_pages: "cloudflare_pages",
cloudflare_pages: "cloudflare-pages",
netlify: "netlify",
stormkit: "stormkit",
vercel: "vercel",
Expand Down

0 comments on commit 246ba03

Please sign in to comment.