Skip to content

Commit

Permalink
fix bug where location not set when .firebaserc exists (#1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
thechenky committed Jun 12, 2019
1 parent eddfe43 commit 0c9f932
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/init/features/project.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as clc from "cli-color";
import * as _ from "lodash";

import * as firebaseApi from "../../firebaseApi";
import * as Config from "../../config";
import * as FirebaseError from "../../error";
import { FirebaseProject, getProject, listProjects } from "../../firebaseApi";
Expand Down Expand Up @@ -121,9 +122,14 @@ export async function doSetup(setup: any, config: Config, options: any): Promise
logger.info(`but for now we'll just set up a default project.`);
logger.info();

if (_.has(setup.rcfile, "projects.default")) {
utils.logBullet(`.firebaserc already has a default project, skipping`);
setup.projectId = _.get(setup.rcfile, "projects.default");
const projectFromRcFile = _.get(setup.rcfile, "projects.default");
if (projectFromRcFile) {
utils.logBullet(`.firebaserc already has a default project, using ${projectFromRcFile}.`);
// we still need to get project info in case user wants to init firestore or storage, which
// require a resource location:
const rcProject: FirebaseProject = await firebaseApi.getProject(projectFromRcFile);
setup.projectId = projectFromRcFile;
setup.projectLocation = _.get(rcProject, "resources.locationId");
return;
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/init/features/project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,16 @@ describe("project", () => {

expect(setup).to.deep.equal({ config: {}, rcfile: {}, project: {} });
});

it("should set project location even if .firebaserc is already set up", async () => {
const options = {};
const setup = { config: {}, rcfile: { projects: { default: "my-project" } } };
getProjectStub.returns(TEST_FIREBASE_PROJECT);

await doSetup(setup, {}, options);

expect(_.get(setup, "projectId")).to.equal("my-project");
expect(_.get(setup, "projectLocation")).to.equal("us-central");
});
});
});

0 comments on commit 0c9f932

Please sign in to comment.