Skip to content

Commit 6e52869

Browse files
authored
fix issues where project ID was missing in Hosting setup (#6528)
* fix issues where project ID was missing in Hosting setup fixes #6527 * formatting is SO HARD
1 parent 3b345d5 commit 6e52869

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixes issue where initializing Hosting fails when selecting a project. (#6527)

src/getDefaultHostingSite.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const errNoDefaultSite = new FirebaseError(
1414
* @param options The command-line options object
1515
* @return The hosting site ID
1616
*/
17-
export async function getDefaultHostingSite(options: any): Promise<string> {
17+
export async function getDefaultHostingSite(options: { projectId?: string }): Promise<string> {
1818
const projectId = needProjectId(options);
1919
const project = await getFirebaseProject(projectId);
2020
let site = project.resources?.hostingSite;

src/hosting/interactive.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { FirebaseError } from "../error";
22
import { logWarning } from "../utils";
33
import { needProjectId, needProjectNumber } from "../projectUtils";
4-
import { Options } from "../options";
54
import { promptOnce } from "../prompt";
65
import { Site, createSite } from "./api";
76

@@ -17,7 +16,7 @@ const prompt =
1716
export async function interactiveCreateHostingSite(
1817
siteId: string,
1918
appId: string,
20-
options: Options
19+
options: { projectId?: string; nonInteractive?: boolean }
2120
): Promise<Site> {
2221
const projectId = needProjectId(options);
2322
const projectNumber = await needProjectNumber(options);

src/init/features/hosting/index.ts

+28-19
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,40 @@ const DEFAULT_IGNORES = ["firebase.json", "**/.*", "**/node_modules/**"];
2727

2828
/**
2929
* Does the setup steps for Firebase Hosting.
30+
* WARNING: #6527 - `options` may not have all the things you think it does.
3031
*/
3132
export async function doSetup(setup: any, config: any, options: Options): Promise<void> {
3233
setup.hosting = {};
3334

34-
let hasHostingSite = true;
35-
try {
36-
await getDefaultHostingSite(options);
37-
} catch (err: unknown) {
38-
if (err !== errNoDefaultSite) {
39-
throw err;
35+
// There's a path where we can set up Hosting without a project, so if
36+
// if setup.projectId is empty, we don't do any checking for a Hosting site.
37+
if (setup.projectId) {
38+
let hasHostingSite = true;
39+
try {
40+
await getDefaultHostingSite({ projectId: setup.projectId });
41+
} catch (err: unknown) {
42+
if (err !== errNoDefaultSite) {
43+
throw err;
44+
}
45+
hasHostingSite = false;
4046
}
41-
hasHostingSite = false;
42-
}
4347

44-
if (!hasHostingSite) {
45-
const confirmCreate = await promptOnce({
46-
type: "confirm",
47-
message: "A Firebase Hosting site is required to deploy. Would you like to create one now?",
48-
default: true,
49-
});
50-
if (confirmCreate) {
51-
const newSite = await interactiveCreateHostingSite("", "", options);
52-
logger.info();
53-
logSuccess(`Firebase Hosting site ${last(newSite.name.split("/"))} created!`);
54-
logger.info();
48+
if (!hasHostingSite) {
49+
const confirmCreate = await promptOnce({
50+
type: "confirm",
51+
message: "A Firebase Hosting site is required to deploy. Would you like to create one now?",
52+
default: true,
53+
});
54+
if (confirmCreate) {
55+
const createOptions = {
56+
projectId: setup.projectId,
57+
nonInteractive: options.nonInteractive,
58+
};
59+
const newSite = await interactiveCreateHostingSite("", "", createOptions);
60+
logger.info();
61+
logSuccess(`Firebase Hosting site ${last(newSite.name.split("/"))} created!`);
62+
logger.info();
63+
}
5564
}
5665
}
5766

0 commit comments

Comments
 (0)