Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Upgraded `inquirer` library to address some visual bugs with prompting (#8389)
- Fixed an issue where the prompt to create apphosting.emulator.yaml did not work with backends that are not at the project.root (#8412)
4 changes: 2 additions & 2 deletions src/apphosting/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
export function discoverBackendRoot(cwd: string): string | null {
let dir = cwd;

while (true) {

Check warning on line 64 in src/apphosting/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected constant condition
const files = fs.listFiles(dir);
if (files.some((file) => APPHOSTING_YAML_FILE_REGEX.test(file))) {
return dir;
Expand Down Expand Up @@ -100,8 +100,8 @@
let raw: string;
try {
raw = fs.readFile(yamlPath);
} catch (err: any) {

Check warning on line 103 in src/apphosting/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (err.code !== "ENOENT") {

Check warning on line 104 in src/apphosting/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .code on an `any` value
throw new FirebaseError(`Unexpected error trying to load ${yamlPath}`, {
original: getError(err),
});
Expand Down Expand Up @@ -218,11 +218,11 @@
*/
export async function maybeGenerateEmulatorYaml(
projectId: string | undefined,
repoRoot: string,
backendRoot: string,
): Promise<Env[] | null> {
// Even if the app is in /project/app, the user might have their apphosting.yaml file in /project/apphosting.yaml.
// Walk up the tree to see if we find other local files so that we can put apphosting.emulator.yaml in the right place.
const basePath = dynamicDispatch.discoverBackendRoot(repoRoot) || repoRoot;
const basePath = dynamicDispatch.discoverBackendRoot(backendRoot) || backendRoot;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const basePath = dynamicDispatch.discoverBackendRoot(backendRoot) || backendRoot;
const basePath = dynamicDispatch.discoverBackendRoot(backendRoot) ?? backendRoot;

Nit: IIUC, ?? is preferred over || for undefined fallbacks

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer a style where you only use ?? when you know null and/or 0 is a valid value.

if (fs.fileExistsSync(join(basePath, APPHOSTING_EMULATORS_YAML_FILE))) {
logger.debug(
"apphosting.emulator.yaml already exists, skipping generation and secrets access prompt",
Expand Down Expand Up @@ -316,7 +316,7 @@
default: suggestedTestKeyName(name),
});

if (await csm.secretExists(projectId!, secretRef)) {

Check warning on line 319 in src/apphosting/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
action = await prompt.select<"reuse" | "pick-new">({
message:
"This secret reference already exists, would you like to reuse it or create a new one?",
Expand All @@ -330,7 +330,7 @@
}
}

newEnv[name] = { variable: name, secret: secretRef! };

Check warning on line 333 in src/apphosting/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
if (action === "reuse") {
continue;
}
Expand All @@ -339,13 +339,13 @@
`What new value would you like for secret ${name} [input is hidden]?`,
);
// TODO: Do we need to support overriding locations? Inferring them from the original?
await csm.createSecret(projectId!, secretRef!, { [csm.FIREBASE_MANAGED]: "apphosting" });

Check warning on line 342 in src/apphosting/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion

Check warning on line 342 in src/apphosting/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
await csm.addVersion(projectId!, secretRef!, secretValue);

Check warning on line 343 in src/apphosting/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion

Check warning on line 343 in src/apphosting/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
}

return newEnv;
}

export function suggestedTestKeyName(variable: string): string {

Check warning on line 349 in src/apphosting/config.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
return "test-" + variable.replace(/_/g, "-").toLowerCase();
}
4 changes: 1 addition & 3 deletions src/emulator/initEmulators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { detectStartCommand } from "./apphosting/developmentServer";
import { EmulatorLogger } from "./emulatorLogger";
import { Emulators } from "./types";
import { Env, maybeGenerateEmulatorYaml } from "../apphosting/config";
import { detectProjectRoot } from "../detectProjectRoot";
import { Config } from "../config";
import { getProjectId } from "../projectUtils";
import { grantEmailsSecretAccess } from "../apphosting/secrets";
Expand Down Expand Up @@ -42,8 +41,7 @@ export const AdditionalInitFns: AdditionalInitFnsType = {
const projectId = getProjectId(config.options);
let env: Env[] | null = [];
try {
const projectRoot = detectProjectRoot({ cwd: config.options.cwd }) ?? backendRoot;
env = await maybeGenerateEmulatorYaml(projectId, projectRoot);
env = await maybeGenerateEmulatorYaml(projectId, backendRoot);
} catch (e) {
logger.log("WARN", "failed to export app hosting configs");
}
Expand Down
Loading