Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split preset types #1910

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions src/presets/cloudflare-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { globby } from "globby";
import { defineNitroPreset } from "../preset";
import type { Nitro } from "../types";
import { CloudflarePagesRoutes } from "../types/presets/cloudflare";

export const cloudflarePages = defineNitroPreset({
extends: "cloudflare",
Expand Down Expand Up @@ -59,20 +60,6 @@ export const cloudflarePagesStatic = defineNitroPreset({
},
});

/**
* https://developers.cloudflare.com/pages/platform/functions/routing/#functions-invocation-routes
*/
export interface CloudflarePagesRoutes {
/** Defines the version of the schema. Currently there is only one version of the schema (version 1), however, we may add more in the future and aim to be backwards compatible. */
version?: 1;

/** Defines routes that will be invoked by Functions. Accepts wildcard behavior. */
include?: string[];

/** Defines routes that will not be invoked by Functions. Accepts wildcard behavior. `exclude` always take priority over `include`. */
exclude?: string[];
}

async function writeCFRoutes(nitro: Nitro) {
const _cfPagesConfig = nitro.options.cloudflare?.pages || {};
const routes: CloudflarePagesRoutes = {
Expand Down
2 changes: 1 addition & 1 deletion src/presets/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Nitro } from "../types";
import type {
VercelBuildConfigV3,
VercelServerlessFunctionConfig,
} from "../types/presets";
} from "../types/presets/vercel";

// https://vercel.com/docs/build-output-api/v3

Expand Down
185 changes: 0 additions & 185 deletions src/types/presets.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/types/presets/azure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface AzureOptions {
config?: {
platform?: {
apiRuntime?: string;
[key: string]: unknown;
};
navigationFallback?: {
rewrite?: string;
[key: string]: unknown;
};
[key: string]: unknown;
};
}
45 changes: 45 additions & 0 deletions src/types/presets/cloudflare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* https://developers.cloudflare.com/pages/platform/functions/routing/#functions-invocation-routes
*/
export interface CloudflarePagesRoutes {
/** Defines the version of the schema. Currently there is only one version of the schema (version 1), however, we may add more in the future and aim to be backwards compatible. */
version?: 1;

/** Defines routes that will be invoked by Functions. Accepts wildcard behavior. */
include?: string[];

/** Defines routes that will not be invoked by Functions. Accepts wildcard behavior. `exclude` always take priority over `include`. */
exclude?: string[];
}

export interface CloudflareOptions {
pages: {
/**
* Nitro will automatically generate a `_routes.json` that controls which files get served statically and
* which get served by the Worker. Using this config will override the automatic `_routes.json`. Or, if the
* `merge` options is set, it will merge the user-set routes with the auto-generated ones, giving priority
* to the user routes.
*
* @see https://developers.cloudflare.com/pages/platform/functions/routing/#functions-invocation-routes
*
* There are a maximum of 100 rules, and you must have at least one include rule. Wildcards are accepted.
*
* If any fields are unset, they default to:
*
* ```json
* {
* "version": 1,
* "include": ["/*"],
* "exclude": []
* }
* ```
*/
routes?: CloudflarePagesRoutes;
/**
* If set to `false`, nitro will disable the automatically generated `_routes.json` and instead use the user-set only ones.
*
* @default true
*/
defaultRoutes?: boolean;
};
}
41 changes: 41 additions & 0 deletions src/types/presets/firebase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { HttpsOptions } from "firebase-functions/v2/https";
import type { RuntimeOptions, region } from "firebase-functions";

export type FirebaseOptions = FirebaseOptionsGen1 | FirebaseOptionsGen2;

export interface FirebaseOptionsBase {
gen: 1 | 2;
/**
* Firebase functions node runtime version.
* @see https://cloud.google.com/functions/docs/concepts/nodejs-runtime
*/
nodeVersion?: "20" | "18" | "16";
/**
* When deploying multiple apps within the same Firebase project
* you must give your server a unique name in order to avoid overwriting your functions.
*
* @default "server"
*/
serverFunctionName?: string;
}

export interface FirebaseOptionsGen1 extends FirebaseOptionsBase {
gen: 1;
/**
* Firebase functions 1st generation region passed to `functions.region()`.
*/
region?: Parameters<typeof region>[0];
/**
* Firebase functions 1st generation runtime options passed to `functions.runWith()`.
*/
runtimeOptions?: RuntimeOptions;
}

export interface FirebaseOptionsGen2 extends FirebaseOptionsBase {
gen: 2;
/**
* Firebase functions 2nd generation https options passed to `onRequest`.
* @see https://firebase.google.com/docs/reference/functions/2nd-gen/node/firebase-functions.https.httpsoptions
*/
httpsOptions?: HttpsOptions;
}
11 changes: 11 additions & 0 deletions src/types/presets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AzureOptions } from "./azure";
import { CloudflareOptions } from "./cloudflare";
import { FirebaseOptions } from "./firebase";
import { VercelOptions } from "./vercel";

export interface PresetOptions {
azure: AzureOptions;
cloudflare: CloudflareOptions;
firebase: FirebaseOptions;
vercel: VercelOptions;
}
Loading