Skip to content

Commit

Permalink
fix(firebase): fail build on wrong serverFunctionName
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsc committed Oct 4, 2024
1 parent 3bd0910 commit be91ea5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/2.deploy/20.providers/firebase.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,5 @@ export default defineNuxtConfig({
::

::important
`serverFunctionName` should not include dashes (`-`).
`serverFunctionName` cannot include dashes (`-`).
::
10 changes: 5 additions & 5 deletions src/presets/firebase/preset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineNitroPreset } from "nitropack/kit";
import { basename } from "pathe";
import type { Plugin } from "rollup";
import { genSafeVariableName } from "knitwork"
import { updatePackageJSON, writeFirebaseConfig } from "./utils";

export type { FirebaseOptions as PresetOptions } from "./types";
Expand Down Expand Up @@ -33,10 +34,9 @@ const firebase = defineNitroPreset(
nitro.options.appConfig.nitro = nitro.options.appConfig.nitro || {};
nitro.options.appConfig.nitro.firebase = nitro.options.firebase;

if(nitro.options.firebase?.serverFunctionName.includes('-')){
nitro.logger.warn(
"Your `serverFunctionName` should not include dashes (`-`). We have normalized it to use underscores (`_`) but it is recommended that you change it."
);
const { serverFunctionName } = nitro.options.firebase
if(serverFunctionName && serverFunctionName !== genSafeVariableName(serverFunctionName)) {
throw new Error("`serverFunctionName` cannot include dashes")
}

// Replace __firebaseServerFunctionName__ to actual name in entries
Expand All @@ -47,7 +47,7 @@ const firebase = defineNitroPreset(
return {
code: code.replace(
/__firebaseServerFunctionName__/g,
nitro.options.firebase?.serverFunctionName.replace(/-/g, '_') || "server"
serverFunctionName || "server"
),
map: null,
};
Expand Down

0 comments on commit be91ea5

Please sign in to comment.