Skip to content

Commit f6ffc3f

Browse files
authored
[cleanup] remove unexpected awaits (#2806)
* remove unexpected awaits * wrap logic in promise
1 parent 03050ea commit f6ffc3f

File tree

12 files changed

+61
-60
lines changed

12 files changed

+61
-60
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ module.exports = {
3434
"jsdoc/require-param-type": "off",
3535
"jsdoc/require-returns-type": "off",
3636

37-
"@typescript-eslint/await-thenable": "warn", // TODO(bkendall): remove, allow to error.
3837
"@typescript-eslint/camelcase": "warn", // TODO(bkendall): remove, allow to error.
3938
"@typescript-eslint/explicit-function-return-type": ["warn", { allowExpressions: true }], // TODO(bkendall): SET to error.
4039
"@typescript-eslint/no-inferrable-types": "warn", // TODO(bkendall): remove, allow to error.

scripts/triggers-end-to-end-tests/tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ describe("import/export end to end", () => {
413413
// Delete all of the import files
414414
for (const f of fs.readdirSync(dbExportPath)) {
415415
const fullPath = path.join(dbExportPath, f);
416-
await fs.unlinkSync(fullPath);
416+
fs.unlinkSync(fullPath);
417417
}
418418

419419
// Delete all the data in one namespace

src/archiveDirectory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const utils = require("./utils");
2121
* @param {!Object<string, *>} options
2222
* @param {string} options.type Type of directory to create: "tar", or "zip".
2323
* @param {!Array<string>} options.ignore Globs to be ignored.
24-
* @return {!Object<string, *>} Information about the archive:
24+
* @return {!Promise<Object<string, *>>} Information about the archive:
2525
* - `file`: file name
2626
* - `stream`: read stream of the archive
2727
* - `manifest`: list of all files in the archive

src/commands/ext-info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default new Command("ext:info <extensionName>")
3434

3535
const [name, version] = extensionName.split("@");
3636
const registryEntry = await resolveRegistryEntry(name);
37-
const sourceUrl = await resolveSourceUrl(registryEntry, name, version);
37+
const sourceUrl = resolveSourceUrl(registryEntry, name, version);
3838
const source = await extensionsApi.getSource(sourceUrl);
3939
spec = source.spec;
4040
}

src/emulator/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export async function startAll(options: any, noUi: boolean = false): Promise<voi
352352
};
353353
if (options.import) {
354354
const importDir = path.resolve(options.import);
355-
const foundMetadata = await findExportMetadata(importDir);
355+
const foundMetadata = findExportMetadata(importDir);
356356
if (foundMetadata) {
357357
exportMetadata = foundMetadata;
358358
} else {

src/emulator/download.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = async (name: DownloadableEmulator) => {
3131
await validateChecksum(tmpfile, emulator.opts.expectedChecksum);
3232
}
3333
if (emulator.opts.skipCache) {
34-
await removeOldFiles(name, emulator, true);
34+
removeOldFiles(name, emulator, true);
3535
}
3636

3737
fs.copySync(tmpfile, emulator.downloadPath);
@@ -43,7 +43,7 @@ module.exports = async (name: DownloadableEmulator) => {
4343
const executablePath = emulator.binaryPath || emulator.downloadPath;
4444
fs.chmodSync(executablePath, 0o755);
4545

46-
await removeOldFiles(name, emulator);
46+
removeOldFiles(name, emulator);
4747
};
4848

4949
function unzip(zipPath: string, unzipDir: string): Promise<void> {

src/emulator/functionsEmulator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export class FunctionsEmulator implements EmulatorInstance {
424424
added = await this.addPubsubTrigger(this.args.projectId, definition);
425425
break;
426426
case Constants.SERVICE_AUTH:
427-
added = await this.addAuthTrigger(this.args.projectId, definition);
427+
added = this.addAuthTrigger(this.args.projectId, definition);
428428
break;
429429
default:
430430
this.logger.log("DEBUG", `Unsupported trigger: ${JSON.stringify(definition)}`);

src/emulator/functionsEmulatorRuntime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ async function initializeRuntime(
10461046
require("../extractTriggers")(triggerModule, triggerDefinitions);
10471047
}
10481048

1049-
const triggers = await getEmulatedTriggersFromDefinitions(triggerDefinitions, triggerModule);
1049+
const triggers = getEmulatedTriggersFromDefinitions(triggerDefinitions, triggerModule);
10501050

10511051
new EmulatorLog("SYSTEM", "triggers-parsed", "", { triggers, triggerDefinitions }).log();
10521052
return triggers;

src/extensions/extensionsHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ export async function getExtensionSourceFromName(extensionName: string): Promise
365365
if (officialExtensionRegex.test(extensionName)) {
366366
const [name, version] = extensionName.split("@");
367367
const registryEntry = await resolveRegistryEntry(name);
368-
const sourceUrl = await resolveSourceUrl(registryEntry, name, version);
368+
const sourceUrl = resolveSourceUrl(registryEntry, name, version);
369369
return await getSource(sourceUrl);
370370
} else if (existingSourceRegex.test(extensionName)) {
371371
logger.info(`Fetching the source "${extensionName}"...`);

src/hosting/functionsProxy.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,32 @@ export interface FunctionProxyRewrite {
2525
export default function(
2626
options: FunctionsProxyOptions
2727
): (r: FunctionProxyRewrite) => Promise<RequestHandler> {
28-
return async (rewrite: FunctionProxyRewrite) => {
29-
// TODO(samstern): This proxy assumes all functions are in the default region, but this is
30-
// not a safe assumption.
31-
const projectId = getProjectId(options, false);
32-
let url = `https://us-central1-${projectId}.cloudfunctions.net/${rewrite.function}`;
33-
let destLabel = "live";
28+
return (rewrite: FunctionProxyRewrite) => {
29+
return new Promise((resolve) => {
30+
// TODO(samstern): This proxy assumes all functions are in the default region, but this is
31+
// not a safe assumption.
32+
const projectId = getProjectId(options, false);
33+
let url = `https://us-central1-${projectId}.cloudfunctions.net/${rewrite.function}`;
34+
let destLabel = "live";
3435

35-
if (includes(options.targets, "functions")) {
36-
destLabel = "local";
36+
if (includes(options.targets, "functions")) {
37+
destLabel = "local";
3738

38-
// If the functions emulator is running we know the port, otherwise
39-
// things still point to production.
40-
const functionsEmu = EmulatorRegistry.get(Emulators.FUNCTIONS);
41-
if (functionsEmu) {
42-
url = FunctionsEmulator.getHttpFunctionUrl(
43-
functionsEmu.getInfo().host,
44-
functionsEmu.getInfo().port,
45-
projectId,
46-
rewrite.function,
47-
"us-central1"
48-
);
39+
// If the functions emulator is running we know the port, otherwise
40+
// things still point to production.
41+
const functionsEmu = EmulatorRegistry.get(Emulators.FUNCTIONS);
42+
if (functionsEmu) {
43+
url = FunctionsEmulator.getHttpFunctionUrl(
44+
functionsEmu.getInfo().host,
45+
functionsEmu.getInfo().port,
46+
projectId,
47+
rewrite.function,
48+
"us-central1"
49+
);
50+
}
4951
}
50-
}
5152

52-
return await proxyRequestHandler(url, `${destLabel} Function ${rewrite.function}`);
53+
resolve(proxyRequestHandler(url, `${destLabel} Function ${rewrite.function}`));
54+
});
5355
};
5456
}

src/test/hosting/cloudRunProxy.spec.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe("cloudRunProxy", () => {
2222
});
2323

2424
it("should error when not provided a valid Cloud Run service ID", async () => {
25-
const mwGenerator = await cloudRunProxy(fakeOptions);
25+
const mwGenerator = cloudRunProxy(fakeOptions);
2626
const mw = await mwGenerator({ run: { serviceId: "" } });
2727
const spyMw = sinon.spy(mw);
2828

@@ -39,7 +39,7 @@ describe("cloudRunProxy", () => {
3939
.get("/v1/projects/project-foo/locations/us-central1/services/empty")
4040
.reply(404, { error: "service doesn't exist" });
4141

42-
const mwGenerator = await cloudRunProxy(fakeOptions);
42+
const mwGenerator = cloudRunProxy(fakeOptions);
4343
const mw = await mwGenerator({ run: { serviceId: "empty" } });
4444
const spyMw = sinon.spy(mw);
4545

@@ -56,7 +56,7 @@ describe("cloudRunProxy", () => {
5656
.get("/v1/projects/project-foo/locations/us-central1/services/badService")
5757
.reply(200, { status: {} });
5858

59-
const mwGenerator = await cloudRunProxy(fakeOptions);
59+
const mwGenerator = cloudRunProxy(fakeOptions);
6060
const mw = await mwGenerator({ run: { serviceId: "badService" } });
6161
const spyMw = sinon.spy(mw);
6262

@@ -76,7 +76,7 @@ describe("cloudRunProxy", () => {
7676
.get("/")
7777
.reply(200, "live version");
7878

79-
const mwGenerator = await cloudRunProxy(fakeOptions);
79+
const mwGenerator = cloudRunProxy(fakeOptions);
8080
const mw = await mwGenerator(fakeRewrite);
8181
const spyMw = sinon.spy(mw);
8282

@@ -97,7 +97,7 @@ describe("cloudRunProxy", () => {
9797
.get("/")
9898
.reply(200, "live version");
9999

100-
const mwGenerator = await cloudRunProxy(fakeOptions);
100+
const mwGenerator = cloudRunProxy(fakeOptions);
101101
const mw = await mwGenerator({ run: { serviceId: "helloworld", region: "asia-southeast1" } });
102102
const spyMw = sinon.spy(mw);
103103

@@ -119,37 +119,37 @@ describe("cloudRunProxy", () => {
119119
.get("/")
120120
.reply(200, "live version");
121121

122-
const mwGenerator = await cloudRunProxy(fakeOptions);
122+
const mwGenerator = cloudRunProxy(fakeOptions);
123123
const mw = await mwGenerator({ run: { serviceId: "multiLookup" } });
124124
const spyMw = sinon.spy(mw);
125125

126126
await supertest(spyMw)
127127
.get("/")
128128
.expect(200, "live version");
129-
await expect(spyMw.calledOnce).to.be.true;
130-
await expect(multiNock.isDone()).to.be.true;
129+
expect(spyMw.calledOnce).to.be.true;
130+
expect(multiNock.isDone()).to.be.true;
131131

132132
// New rewrite for the same Cloud Run service
133133
const failMultiNock = nock(cloudRunApiOrigin)
134134
.get("/v1/projects/project-foo/locations/us-central1/services/multiLookup")
135135
.reply(500, "should not happen");
136136

137-
const mw2Generator = await cloudRunProxy(fakeOptions);
137+
const mw2Generator = cloudRunProxy(fakeOptions);
138138
const mw2 = await mw2Generator({ run: { serviceId: "multiLookup" } });
139139
const spyMw2 = sinon.spy(mw2);
140140

141141
await supertest(spyMw2)
142142
.get("/")
143143
.expect(200, "live version");
144-
await expect(spyMw2.calledOnce).to.be.true;
145-
await expect(failMultiNock.isDone()).to.be.false;
144+
expect(spyMw2.calledOnce).to.be.true;
145+
expect(failMultiNock.isDone()).to.be.false;
146146

147147
// Second hit to the same path
148148
await supertest(spyMw2)
149149
.get("/")
150150
.expect(200, "live version");
151-
await expect(spyMw2.calledTwice).to.be.true;
152-
await expect(failMultiNock.isDone()).to.be.false;
151+
expect(spyMw2.calledTwice).to.be.true;
152+
expect(failMultiNock.isDone()).to.be.false;
153153
});
154154

155155
it("should pass through normal 404 errors", async () => {
@@ -160,7 +160,7 @@ describe("cloudRunProxy", () => {
160160
.get("/404.html")
161161
.reply(404, "normal 404");
162162

163-
const mwGenerator = await cloudRunProxy(fakeOptions);
163+
const mwGenerator = cloudRunProxy(fakeOptions);
164164
const mw = await mwGenerator(fakeRewrite);
165165
const spyMw = sinon.spy(mw);
166166

@@ -180,7 +180,7 @@ describe("cloudRunProxy", () => {
180180
.get("/404-cascade.html")
181181
.reply(404, "normal 404 with cascade", { "x-cascade": "pass" });
182182

183-
const mwGenerator = await cloudRunProxy(fakeOptions);
183+
const mwGenerator = cloudRunProxy(fakeOptions);
184184
const mw = await mwGenerator(fakeRewrite);
185185
const spyMw = sinon.spy(mw);
186186
const finalMw = sinon.stub().callsFake((_, res) => {
@@ -207,7 +207,7 @@ describe("cloudRunProxy", () => {
207207
.get("/cached")
208208
.reply(200, "cached page", { "cache-control": "custom", "set-cookie": "nom" });
209209

210-
const mwGenerator = await cloudRunProxy(fakeOptions);
210+
const mwGenerator = cloudRunProxy(fakeOptions);
211211
const mw = await mwGenerator(fakeRewrite);
212212
const spyMw = sinon.spy(mw);
213213

@@ -228,7 +228,7 @@ describe("cloudRunProxy", () => {
228228
.get("/vary")
229229
.reply(200, "live vary version", { vary: "Other, Authorization" });
230230

231-
const mwGenerator = await cloudRunProxy(fakeOptions);
231+
const mwGenerator = cloudRunProxy(fakeOptions);
232232
const mw = await mwGenerator(fakeRewrite);
233233
const spyMw = sinon.spy(mw);
234234

@@ -249,7 +249,7 @@ describe("cloudRunProxy", () => {
249249
.get("/500")
250250
.replyWithError({ message: "normal error" });
251251

252-
const mwGenerator = await cloudRunProxy(fakeOptions);
252+
const mwGenerator = cloudRunProxy(fakeOptions);
253253
const mw = await mwGenerator(fakeRewrite);
254254
const spyMw = sinon.spy(mw);
255255

@@ -269,7 +269,7 @@ describe("cloudRunProxy", () => {
269269
.get("/timeout")
270270
.replyWithError({ message: "ahh", code: "ETIMEDOUT" });
271271

272-
const mwGenerator = await cloudRunProxy(fakeOptions);
272+
const mwGenerator = cloudRunProxy(fakeOptions);
273273
const mw = await mwGenerator(fakeRewrite);
274274
const spyMw = sinon.spy(mw);
275275

@@ -289,7 +289,7 @@ describe("cloudRunProxy", () => {
289289
.get("/sockettimeout")
290290
.replyWithError({ message: "ahh", code: "ESOCKETTIMEDOUT" });
291291

292-
const mwGenerator = await cloudRunProxy(fakeOptions);
292+
const mwGenerator = cloudRunProxy(fakeOptions);
293293
const mw = await mwGenerator(fakeRewrite);
294294
const spyMw = sinon.spy(mw);
295295

src/test/hosting/functionsProxy.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe("functionsProxy", () => {
3737
.get("/bar/")
3838
.reply(200, "live version");
3939

40-
const mwGenerator = await functionsProxy(fakeOptions);
40+
const mwGenerator = functionsProxy(fakeOptions);
4141
const mw = await mwGenerator(fakeRewrite);
4242
const spyMw = sinon.spy(mw);
4343

@@ -57,7 +57,7 @@ describe("functionsProxy", () => {
5757
const options = cloneDeep(fakeOptions);
5858
options.targets = ["functions"];
5959

60-
const mwGenerator = await functionsProxy(options);
60+
const mwGenerator = functionsProxy(options);
6161
const mw = await mwGenerator(fakeRewrite);
6262
const spyMw = sinon.spy(mw);
6363

@@ -74,7 +74,7 @@ describe("functionsProxy", () => {
7474
.get("/bar/404.html")
7575
.reply(404, "normal 404");
7676

77-
const mwGenerator = await functionsProxy(fakeOptions);
77+
const mwGenerator = functionsProxy(fakeOptions);
7878
const mw = await mwGenerator(fakeRewrite);
7979
const spyMw = sinon.spy(mw);
8080

@@ -91,7 +91,7 @@ describe("functionsProxy", () => {
9191
.get("/bar/404-cascade.html")
9292
.reply(404, "normal 404 with cascade", { "x-cascade": "pass" });
9393

94-
const mwGenerator = await functionsProxy(fakeOptions);
94+
const mwGenerator = functionsProxy(fakeOptions);
9595
const mw = await mwGenerator(fakeRewrite);
9696
const spyMw = sinon.spy(mw);
9797
const finalMw = sinon.stub().callsFake((_, res) => {
@@ -115,7 +115,7 @@ describe("functionsProxy", () => {
115115
.get("/bar/cached")
116116
.reply(200, "cached page", { "cache-control": "custom", "set-cookie": "nom" });
117117

118-
const mwGenerator = await functionsProxy(fakeOptions);
118+
const mwGenerator = functionsProxy(fakeOptions);
119119
const mw = await mwGenerator(fakeRewrite);
120120
const spyMw = sinon.spy(mw);
121121

@@ -133,7 +133,7 @@ describe("functionsProxy", () => {
133133
.get("/bar/vary")
134134
.reply(200, "live vary version", { vary: "Other, Authorization" });
135135

136-
const mwGenerator = await functionsProxy(fakeOptions);
136+
const mwGenerator = functionsProxy(fakeOptions);
137137
const mw = await mwGenerator(fakeRewrite);
138138
const spyMw = sinon.spy(mw);
139139

@@ -151,7 +151,7 @@ describe("functionsProxy", () => {
151151
.get("/bar/500")
152152
.replyWithError({ message: "normal error" });
153153

154-
const mwGenerator = await functionsProxy(fakeOptions);
154+
const mwGenerator = functionsProxy(fakeOptions);
155155
const mw = await mwGenerator(fakeRewrite);
156156
const spyMw = sinon.spy(mw);
157157

@@ -168,7 +168,7 @@ describe("functionsProxy", () => {
168168
.get("/bar/timeout")
169169
.replyWithError({ message: "ahh", code: "ETIMEDOUT" });
170170

171-
const mwGenerator = await functionsProxy(fakeOptions);
171+
const mwGenerator = functionsProxy(fakeOptions);
172172
const mw = await mwGenerator(fakeRewrite);
173173
const spyMw = sinon.spy(mw);
174174

@@ -185,7 +185,7 @@ describe("functionsProxy", () => {
185185
.get("/bar/sockettimeout")
186186
.replyWithError({ message: "ahh", code: "ESOCKETTIMEDOUT" });
187187

188-
const mwGenerator = await functionsProxy(fakeOptions);
188+
const mwGenerator = functionsProxy(fakeOptions);
189189
const mw = await mwGenerator(fakeRewrite);
190190
const spyMw = sinon.spy(mw);
191191

0 commit comments

Comments
 (0)