feat: init

This commit is contained in:
2026-02-13 22:02:30 +01:00
commit 8f9ff830fb
16711 changed files with 3307340 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
export type { FirebaseOptions as PresetOptions } from "./types";
declare const _default: readonly [any, any];
export default _default;

100
node_modules/nitropack/dist/presets/firebase/preset.mjs generated vendored Normal file
View File

@@ -0,0 +1,100 @@
import { defineNitroPreset, writeFile } from "nitropack/kit";
import { version as nitroVersion } from "nitropack/meta";
import { basename, join, relative } from "pathe";
import { genSafeVariableName } from "knitwork";
import { stringifyYAML } from "confbox";
import { updatePackageJSON, writeFirebaseConfig } from "./utils.mjs";
const firebase = defineNitroPreset(
{
entry: `./runtime/firebase-gen-{{ firebase.gen }}`,
commands: {
deploy: "npx firebase-tools deploy"
},
firebase: {
// we need this defined here so it's picked up by the template in firebase's entry
gen: Number.parseInt(process.env.NITRO_FIREBASE_GEN || "") || "default"
},
hooks: {
async compiled(nitro) {
await writeFirebaseConfig(nitro);
await updatePackageJSON(nitro);
},
"rollup:before": (nitro, rollupConfig) => {
const _gen = nitro.options.firebase?.gen;
if (!_gen || _gen === "default") {
nitro.logger.warn(
"Neither `firebase.gen` or `NITRO_FIREBASE_GEN` is set. Nitro will default to Cloud Functions 1st generation. It is recommended to set this to the latest generation (currently `2`). Set the version to remove this warning. See https://nitro.build/deploy/providers/firebase for more information."
);
nitro.options.firebase = { gen: 1 };
}
nitro.options.appConfig.nitro = nitro.options.appConfig.nitro || {};
nitro.options.appConfig.nitro.firebase = nitro.options.firebase;
const { serverFunctionName } = nitro.options.firebase;
if (serverFunctionName && serverFunctionName !== genSafeVariableName(serverFunctionName)) {
throw new Error(
`\`firebase.serverFunctionName\` must be a valid JS variable name: \`${serverFunctionName}\``
);
}
rollupConfig.plugins.unshift({
name: "nitro:firebase",
transform: (code, id) => {
if (basename(id).startsWith("firebase-gen-")) {
return {
code: code.replace(
/__firebaseServerFunctionName__/g,
serverFunctionName || "server"
),
map: null
};
}
}
});
}
}
},
{
name: "firebase",
url: import.meta.url
}
);
const firebaseAppHosting = defineNitroPreset(
{
extends: "node-server",
serveStatic: true,
hooks: {
async compiled(nitro) {
const serverEntry = join(nitro.options.output.serverDir, "index.mjs");
await writeFile(
join(nitro.options.rootDir, ".apphosting/bundle.yaml"),
stringifyYAML({
version: "v1",
runConfig: {
runCommand: `node ${relative(nitro.options.rootDir, serverEntry)}`,
...nitro.options.firebase?.appHosting
},
metadata: {
framework: nitro.options.framework.name || "nitropack",
frameworkVersion: nitro.options.framework.version || "2.x",
adapterPackageName: "nitropack",
adapterVersion: nitroVersion
},
outputFiles: {
serverApp: {
include: [
relative(nitro.options.rootDir, nitro.options.output.dir)
]
}
}
}),
true
);
}
}
},
{
name: "firebase-app-hosting",
stdName: "firebase_app_hosting",
url: import.meta.url
}
);
export default [firebase, firebaseAppHosting];

View File

@@ -0,0 +1,2 @@
import "#nitro-internal-pollyfills";
export declare const __firebaseServerFunctionName__: any;

View File

@@ -0,0 +1,8 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitropack/runtime";
import { useAppConfig } from "nitropack/runtime";
import functions from "firebase-functions/v1";
import { toNodeListener } from "h3";
const nitroApp = useNitroApp();
const firebaseConfig = useAppConfig().nitro.firebase;
export const __firebaseServerFunctionName__ = functions.region(firebaseConfig.region ?? functions.RESET_VALUE).runWith(firebaseConfig.runtimeOptions ?? functions.RESET_VALUE).https.onRequest(toNodeListener(nitroApp.h3App));

View File

@@ -0,0 +1,2 @@
import "#nitro-internal-pollyfills";
export declare const __firebaseServerFunctionName__: import("firebase-functions/https").HttpsFunction;

View File

@@ -0,0 +1,15 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitropack/runtime";
import { useAppConfig } from "nitropack/runtime";
import { onRequest } from "firebase-functions/v2/https";
import { toNodeListener } from "h3";
const nitroApp = useNitroApp();
const firebaseConfig = useAppConfig().nitro.firebase;
export const __firebaseServerFunctionName__ = onRequest(
{
// Must be set to public to allow all public requests by default
invoker: "public",
...firebaseConfig.httpsOptions
},
toNodeListener(nitroApp.h3App)
);

View File

@@ -0,0 +1 @@
export { __firebaseServerFunctionName__ } from "./firebase-gen-1";

View File

@@ -0,0 +1 @@
export { __firebaseServerFunctionName__ } from "./firebase-gen-1.mjs";

View File

@@ -0,0 +1,80 @@
import type { RuntimeOptions, region } from "firebase-functions/v1";
import type { HttpsOptions } from "firebase-functions/v2/https";
export type FirebaseOptions = FirebaseFunctionsOptions | AppHostingOptions;
export type FirebaseFunctionsOptions = FirebaseOptionsGen1 | FirebaseOptionsGen2;
export interface FirebaseOptionsBase {
gen: 1 | 2;
/**
* Firebase functions node runtime version.
* @see https://cloud.google.com/functions/docs/runtime-support
* @see https://cloud.google.com/functions/docs/concepts/nodejs-runtime
*/
nodeVersion?: "22" | "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;
}
export interface AppHostingOptions {
appHosting: Partial<AppHostingOutputBundleConfig["runConfig"]>;
}
export interface AppHostingOutputBundleConfig {
version: "v1";
runConfig: {
/** Command to start the server (e.g. "node dist/index.js"). Assume this command is run from the root dir of the workspace. */
runCommand: string;
/** Environment variables set when the app is run. */
environmentVariables?: Array<{
/** Name of the variable. */
variable: string;
/** Value associated with the variable. */
value: string;
/** Where the variable will be available, for now only RUNTIME is supported. */
availability: "RUNTIME"[];
}>;
/** The maximum number of concurrent requests that each server instance can receive. */
concurrency?: number;
/** The number of CPUs used in a single server instance. */
cpu?: number;
/** The amount of memory available for a server instance. */
memoryMiB?: number;
/** The limit on the minimum number of function instances that may coexist at a given time. */
minInstances?: number;
/** The limit on the maximum number of function instances that may coexist at a given time. */
maxInstances?: number;
};
metadata: {
adapterPackageName: string;
adapterVersion: string;
framework: string;
frameworkVersion?: string;
};
outputFiles?: {
/** serverApp holds a list of directories + files relative to the app root dir that frameworks need to deploy to the App Hosting server. */
serverApp: {
include: string[];
};
};
}

View File

View File

@@ -0,0 +1,3 @@
import type { Nitro } from "nitropack/types";
export declare function writeFirebaseConfig(nitro: Nitro): Promise<void>;
export declare function updatePackageJSON(nitro: Nitro): Promise<void>;

49
node_modules/nitropack/dist/presets/firebase/utils.mjs generated vendored Normal file
View File

@@ -0,0 +1,49 @@
import { existsSync } from "node:fs";
import { writeFile } from "nitropack/kit";
import { join, relative } from "pathe";
import { readPackageJSON, writePackageJSON } from "pkg-types";
export async function writeFirebaseConfig(nitro) {
const firebaseConfigPath = join(nitro.options.rootDir, "firebase.json");
if (existsSync(firebaseConfigPath)) {
return;
}
const firebaseConfig = {
functions: {
source: relative(nitro.options.rootDir, nitro.options.output.serverDir)
},
hosting: [
{
site: "<your_project_id>",
public: relative(nitro.options.rootDir, nitro.options.output.publicDir),
cleanUrls: true,
rewrites: [
{
source: "**",
function: "server"
}
]
}
]
};
await writeFile(firebaseConfigPath, JSON.stringify(firebaseConfig, null, 2));
}
export async function updatePackageJSON(nitro) {
const packageJSONPath = join(nitro.options.output.serverDir, "package.json");
const packageJSON = await readPackageJSON(packageJSONPath);
await writePackageJSON(packageJSONPath, {
...packageJSON,
main: "index.mjs",
dependencies: Object.fromEntries(
Object.entries({
// Default to "latest" normally they should be overridden with user versions
"firebase-admin": "latest",
"firebase-functions": "latest",
...packageJSON.dependencies
}).filter((e) => e[0] !== "fsevents").sort(([a], [b]) => a.localeCompare(b))
),
engines: {
// https://cloud.google.com/functions/docs/concepts/nodejs-runtime
node: nitro.options.firebase?.nodeVersion || "20"
}
});
}