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

fix issues where project ID was missing in Hosting setup #6528

Merged
merged 2 commits into from
Nov 15, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixes issue where initializing Hosting fails when selecting a project. (#6527)
2 changes: 1 addition & 1 deletion src/getDefaultHostingSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

/**
* Tries to determine the default hosting site for a project, else falls back to projectId.
* @param options The command-line options object

Check warning on line 14 in src/getDefaultHostingSite.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Missing @param "options.projectId"
* @return The hosting site ID
*/
export async function getDefaultHostingSite(options: any): Promise<string> {
export async function getDefaultHostingSite(options: { projectId?: string }): Promise<string> {
const projectId = needProjectId(options);
const project = await getFirebaseProject(projectId);
let site = project.resources?.hostingSite;
Expand Down
3 changes: 1 addition & 2 deletions src/hosting/interactive.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FirebaseError } from "../error";
import { logWarning } from "../utils";
import { needProjectId, needProjectNumber } from "../projectUtils";
import { Options } from "../options";
import { promptOnce } from "../prompt";
import { Site, createSite } from "./api";

Expand All @@ -17,7 +16,7 @@ const prompt =
export async function interactiveCreateHostingSite(
siteId: string,
appId: string,
options: Options
options: { projectId?: string; nonInteractive?: boolean }
): Promise<Site> {
const projectId = needProjectId(options);
const projectNumber = await needProjectNumber(options);
Expand Down
47 changes: 28 additions & 19 deletions src/init/features/hosting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,45 @@

/**
* Does the setup steps for Firebase Hosting.
* WARNING: #6527 - `options` may not have all the things you think it does.
*/
export async function doSetup(setup: any, config: any, options: Options): Promise<void> {

Check warning on line 32 in src/init/features/hosting/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type

Check warning on line 32 in src/init/features/hosting/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
setup.hosting = {};

Check warning on line 33 in src/init/features/hosting/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .hosting on an `any` value

let hasHostingSite = true;
try {
await getDefaultHostingSite(options);
} catch (err: unknown) {
if (err !== errNoDefaultSite) {
throw err;
// There's a path where we can set up Hosting without a project, so if
// if setup.projectId is empty, we don't do any checking for a Hosting site.
if (setup.projectId) {

Check warning on line 37 in src/init/features/hosting/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .projectId on an `any` value
let hasHostingSite = true;
try {
await getDefaultHostingSite({ projectId: setup.projectId });

Check warning on line 40 in src/init/features/hosting/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 40 in src/init/features/hosting/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .projectId on an `any` value
} catch (err: unknown) {
if (err !== errNoDefaultSite) {
throw err;
}
hasHostingSite = false;
}
hasHostingSite = false;
}

if (!hasHostingSite) {
const confirmCreate = await promptOnce({
type: "confirm",
message: "A Firebase Hosting site is required to deploy. Would you like to create one now?",
default: true,
});
if (confirmCreate) {
const newSite = await interactiveCreateHostingSite("", "", options);
logger.info();
logSuccess(`Firebase Hosting site ${last(newSite.name.split("/"))} created!`);
logger.info();
if (!hasHostingSite) {
const confirmCreate = await promptOnce({
type: "confirm",
message: "A Firebase Hosting site is required to deploy. Would you like to create one now?",
default: true,
});
if (confirmCreate) {
const createOptions = {
projectId: setup.projectId,

Check warning on line 56 in src/init/features/hosting/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 56 in src/init/features/hosting/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .projectId on an `any` value
nonInteractive: options.nonInteractive,
};
const newSite = await interactiveCreateHostingSite("", "", createOptions);
logger.info();
logSuccess(`Firebase Hosting site ${last(newSite.name.split("/"))} created!`);
logger.info();
}
}
}

let discoveredFramework = experiments.isEnabled("webframeworks")
? await discover(config.projectDir, false)

Check warning on line 68 in src/init/features/hosting/index.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe argument of type `any` assigned to a parameter of type `string`
: undefined;

if (experiments.isEnabled("webframeworks")) {
Expand Down
Loading