Skip to content

Fix issue where projectId and displayName are not getting parsed #8635

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

Merged
merged 9 commits into from
Jun 3, 2025
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
@@ -1,2 +1,3 @@
- Fixed issue where `projects:create` didn't correctly parse the `projectId` and `displayName` input. (#8634)
- Improved GetDatabase API call caching for Firestore function deployments. (#8681)
- Increased timeout for linking CloudSQL instances to Data Connect.
2 changes: 1 addition & 1 deletion src/commands/projects-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
.action(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async (projectId: string | undefined, options: any): Promise<FirebaseProjectMetadata> => {
options.projectId = projectId; // add projectId into options to pass into prompt function

Check warning on line 28 in src/commands/projects-create.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .projectId on an `any` value

if (options.organization && options.folder) {

Check warning on line 30 in src/commands/projects-create.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .folder on an `any` value

Check warning on line 30 in src/commands/projects-create.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .organization on an `any` value
throw new FirebaseError(
"Invalid argument, please provide only one type of project parent (organization or folder)",
);
}
if (!options.nonInteractive) {

Check warning on line 35 in src/commands/projects-create.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .nonInteractive on an `any` value
// Inserts projectId and displayName
options = { ...options, ...(await promptProjectCreation()) };
options = { ...options, ...(await promptProjectCreation(options)) };

Check warning on line 37 in src/commands/projects-create.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `Options`

Check warning on line 37 in src/commands/projects-create.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
}
if (!options.projectId) {

Check warning on line 39 in src/commands/projects-create.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .projectId on an `any` value
throw new FirebaseError("Project ID cannot be empty");
}

let parentResource;
if (options.organization) {

Check warning on line 44 in src/commands/projects-create.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .organization on an `any` value
parentResource = { type: ProjectParentResourceType.ORGANIZATION, id: options.organization };

Check warning on line 45 in src/commands/projects-create.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .organization on an `any` value

Check warning on line 45 in src/commands/projects-create.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
} else if (options.folder) {
parentResource = { type: ProjectParentResourceType.FOLDER, id: options.folder };
}
Expand Down
7 changes: 4 additions & 3 deletions src/init/features/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FirebaseProjectMetadata } from "../../types/project";
import { logger } from "../../logger";
import * as utils from "../../utils";
import * as prompt from "../../prompt";
import { Options } from "../../options";

const OPTION_NO_PROJECT = "Don't set up a default project";
const OPTION_USE_PROJECT = "Use an existing project";
Expand Down Expand Up @@ -41,12 +42,12 @@ function toInitProjectInfo(projectMetaData: FirebaseProjectMetadata): InitProjec
};
}

async function promptAndCreateNewProject(): Promise<FirebaseProjectMetadata> {
async function promptAndCreateNewProject(options: Options): Promise<FirebaseProjectMetadata> {
utils.logBullet(
"If you want to create a project in a Google Cloud organization or folder, please use " +
`"firebase projects:create" instead, and return to this command when you've created the project.`,
);
const { projectId, displayName } = await promptProjectCreation();
const { projectId, displayName } = await promptProjectCreation(options);
// N.B. This shouldn't be possible because of the validator on the input field, but it
// is being left around in case there's something I don't know.
if (!projectId) {
Expand Down Expand Up @@ -82,7 +83,7 @@ async function projectChoicePrompt(options: any): Promise<FirebaseProjectMetadat
case OPTION_USE_PROJECT:
return getOrPromptProject(options);
case OPTION_NEW_PROJECT:
return promptAndCreateNewProject();
return promptAndCreateNewProject(options);
case OPTION_ADD_FIREBASE:
return promptAndAddFirebaseToCloudProject();
default:
Expand Down
69 changes: 39 additions & 30 deletions src/management/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { logger } from "../logger";
import * as utils from "../utils";
import { FirebaseProjectMetadata, CloudProjectInfo, ProjectPage } from "../types/project";
import { bestEffortEnsure } from "../ensureApiEnabled";
import { Options } from "../options";

const TIMEOUT_MILLIS = 30000;
const MAXIMUM_PROMPT_LIST = 100;
Expand All @@ -29,35 +30,41 @@ export interface ProjectParentResource {
/**
* Prompt user to create a new project
*/
export async function promptProjectCreation(): Promise<{ projectId: string; displayName: string }> {
const projectId = await prompt.input({
message:
"Please specify a unique project id " +
`(${clc.yellow("warning")}: cannot be modified afterward) [6-30 characters]:\n`,
validate: (projectId: string) => {
if (projectId.length < 6) {
return "Project ID must be at least 6 characters long";
} else if (projectId.length > 30) {
return "Project ID cannot be longer than 30 characters";
} else {
return true;
}
},
});

const displayName = await prompt.input({
default: projectId,
message: "What would you like to call your project? (defaults to your project ID)",
validate: (displayName: string) => {
if (displayName.length < 4) {
return "Project name must be at least 4 characters long";
} else if (displayName.length > 30) {
return "Project name cannot be longer than 30 characters";
} else {
return true;
}
},
});
export async function promptProjectCreation(
options: Options,
): Promise<{ projectId: string; displayName: string }> {
const projectId =
options.projectId ??
(await prompt.input({
message:
"Please specify a unique project id " +
`(${clc.yellow("warning")}: cannot be modified afterward) [6-30 characters]:\n`,
validate: (projectId: string) => {
if (projectId.length < 6) {
return "Project ID must be at least 6 characters long";
} else if (projectId.length > 30) {
return "Project ID cannot be longer than 30 characters";
} else {
return true;
}
},
}));

const displayName =
(options.displayName as string) ??
(await prompt.input({
default: projectId,
message: "What would you like to call your project? (defaults to your project ID)",
validate: (displayName: string) => {
if (displayName.length < 4) {
return "Project name must be at least 4 characters long";
} else if (displayName.length > 30) {
return "Project name cannot be longer than 30 characters";
} else {
return true;
}
},
}));

return { projectId, displayName };
}
Expand Down Expand Up @@ -137,7 +144,9 @@ function logNewFirebaseProjectInfo(projectInfo: FirebaseProjectMetadata): void {
/**
* Get the user's desired project, prompting if necessary.
*/
export async function getOrPromptProject(options: any): Promise<FirebaseProjectMetadata> {
export async function getOrPromptProject(
options: Partial<Options>,
): Promise<FirebaseProjectMetadata> {
if (options.project) {
return await getFirebaseProject(options.project);
}
Expand Down
Loading