Skip to content

Commit 0c9f932

Browse files
authored
fix bug where location not set when .firebaserc exists (#1390)
1 parent eddfe43 commit 0c9f932

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/init/features/project.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as clc from "cli-color";
22
import * as _ from "lodash";
33

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

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

src/test/init/features/project.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,16 @@ describe("project", () => {
141141

142142
expect(setup).to.deep.equal({ config: {}, rcfile: {}, project: {} });
143143
});
144+
145+
it("should set project location even if .firebaserc is already set up", async () => {
146+
const options = {};
147+
const setup = { config: {}, rcfile: { projects: { default: "my-project" } } };
148+
getProjectStub.returns(TEST_FIREBASE_PROJECT);
149+
150+
await doSetup(setup, {}, options);
151+
152+
expect(_.get(setup, "projectId")).to.equal("my-project");
153+
expect(_.get(setup, "projectLocation")).to.equal("us-central");
154+
});
144155
});
145156
});

0 commit comments

Comments
 (0)