From d6afe60ccdd7f1607975f2f2ad5db1ad5a716aee Mon Sep 17 00:00:00 2001 From: Thomas Burke <40719837+thomasmburke@users.noreply.github.com> Date: Thu, 15 Oct 2020 05:36:59 -0700 Subject: [PATCH] Require hosting deploy targets to be in the project's firebase.json (#2704) --- CHANGELOG.md | 1 + src/hosting/normalizedHostingConfigs.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d0116e537d..758d6004a50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,3 +3,4 @@ - Updates Cloud Functions for Firebase templates to better support function development. - Release Firestore emulator v1.11.9: Fixes != and not-in operators. - Add endpoints to enable/disable background triggers in the Cloud Functions emulator. +- Fixes `TypeError` that arises when trying to deploy with Firebase Hosting targets that don't exist in the project's firebase.json (#1232). diff --git a/src/hosting/normalizedHostingConfigs.ts b/src/hosting/normalizedHostingConfigs.ts index b282822ec81..f75d25e47aa 100644 --- a/src/hosting/normalizedHostingConfigs.ts +++ b/src/hosting/normalizedHostingConfigs.ts @@ -19,10 +19,18 @@ function filterOnly(configs: HostingConfig[], onlyString: string): HostingConfig return configs; } + // Strip out Hosting deploy targets from onlyTarget onlyTargets = onlyTargets .filter((target) => target.startsWith("hosting:")) .map((target) => target.replace("hosting:", "")); + // Check to see that all the hosting deploy targets exist in the hosting config + onlyTargets.forEach((onlyTarget) => { + if (!configs.some((config) => config.target === onlyTarget)) { + throw new FirebaseError(`Hosting target ${bold(onlyTarget)} not detected in firebase.json`); + } + }); + return configs.filter((config: HostingConfig) => onlyTargets.includes(config.target || config.site) );