Skip to content

Commit 2f30c85

Browse files
committed
chore(deps): use gts v2
fixes issues #167 #148
1 parent 0a13b2f commit 2f30c85

File tree

11 files changed

+1817
-745
lines changed

11 files changed

+1817
-745
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/node_modules
2+
build/
3+
test/

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./node_modules/gts"
3+
}

.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require('gts/.prettierrc.json')
3+
}

package-lock.json

Lines changed: 1774 additions & 718 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@types/node": "11.15.20",
4444
"@types/on-finished": "2.3.1",
4545
"@types/supertest": "2.0.10",
46-
"gts": "1.0.0",
46+
"gts": "2.0.2",
4747
"mocha": "8.1.0",
4848
"power-assert": "1.6.1",
4949
"supertest": "4.0.2",

src/cloudevents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import * as express from 'express';
16-
import { CloudEventsContext } from './functions';
16+
import {CloudEventsContext} from './functions';
1717

1818
/**
1919
* Checks whether the incoming request is a CloudEvents event in binary content

src/functions.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,22 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
/* eslint-disable @typescript-eslint/no-explicit-any */
1516
import * as express from 'express';
1617

1718
export interface HttpFunction {
18-
// tslint:disable-next-line:no-any express interface.
1919
(req: express.Request, res: express.Response): any;
2020
}
2121
export interface EventFunction {
22-
// tslint:disable-next-line:no-any
2322
(data: {}, context: Context): any;
2423
}
2524
export interface EventFunctionWithCallback {
26-
// tslint:disable-next-line:no-any
2725
(data: {}, context: Context, callback: Function): any;
2826
}
2927
export interface CloudEventFunction {
30-
// tslint:disable-next-line:no-any
3128
(cloudevent: CloudEventsContext): any;
3229
}
3330
export interface CloudEventFunctionWithCallback {
34-
// tslint:disable-next-line:no-any
3531
(cloudevent: CloudEventsContext, callback: Function): any;
3632
}
3733
export type HandlerFunction =
@@ -101,7 +97,7 @@ export interface CloudEventsContext {
10197
*/
10298
contenttype?: string;
10399

104-
// tslint:disable-next-line:no-any CloudEvents extension attributes.
100+
// CloudEvents extension attributes.
105101
[key: string]: any;
106102
}
107103

src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
// unmarshalled as CloudEvents from an incoming request.
3333

3434
import * as minimist from 'minimist';
35-
import { resolve } from 'path';
35+
import {resolve} from 'path';
3636

37-
import { getUserFunction } from './loader';
37+
import {getUserFunction} from './loader';
3838

39-
import { ErrorHandler, SignatureType, getServer } from './invoker';
39+
import {ErrorHandler, SignatureType, getServer} from './invoker';
4040

4141
// Supported command-line flags
4242
const FLAG = {
@@ -80,6 +80,7 @@ if (SIGNATURE_TYPE === undefined) {
8080
SignatureType
8181
).join(', ')}.`
8282
);
83+
// eslint-disable-next-line no-process-exit
8384
process.exit(1);
8485
}
8586

@@ -91,12 +92,14 @@ if (process.argv[2] === '-h' || process.argv[2] === '--help') {
9192
Documentation:
9293
https://github.com/GoogleCloudPlatform/functions-framework-nodejs`
9394
);
95+
// eslint-disable-next-line no-process-exit
9496
process.exit(0);
9597
}
9698

9799
const USER_FUNCTION = getUserFunction(CODE_LOCATION, TARGET);
98100
if (!USER_FUNCTION) {
99101
console.error('Could not load the function, shutting down.');
102+
// eslint-disable-next-line no-process-exit
100103
process.exit(1);
101104
}
102105

src/invoker.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
// functions with HTTP trigger).
2222

2323
import * as bodyParser from 'body-parser';
24+
// eslint-disable-next-line node/no-deprecated-api
2425
import * as domain from 'domain';
2526
import * as express from 'express';
2627
import * as http from 'http';
2728
import * as onFinished from 'on-finished';
2829

29-
import { FUNCTION_STATUS_HEADER_FIELD } from './types';
30-
import { logAndSendError } from './logger';
31-
import { isBinaryCloudEvent, getBinaryCloudEventContext } from './cloudevents';
30+
import {FUNCTION_STATUS_HEADER_FIELD} from './types';
31+
import {logAndSendError} from './logger';
32+
import {isBinaryCloudEvent, getBinaryCloudEventContext} from './cloudevents';
3233
import {
3334
HttpFunction,
3435
EventFunction,
@@ -41,6 +42,7 @@ import {
4142
// We optionally annotate the express Request with a rawBody field.
4243
// Express leaves the Express namespace open to allow merging of new fields.
4344
declare global {
45+
// eslint-disable-next-line @typescript-eslint/no-namespace
4446
namespace Express {
4547
export interface Request {
4648
rawBody?: Buffer;
@@ -63,7 +65,7 @@ let latestRes: express.Response | null = null;
6365
* @param err Error from function execution.
6466
* @param res Express response object.
6567
*/
66-
// tslint:disable-next-line:no-any
68+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6769
function sendResponse(result: any, err: Error | null, res: express.Response) {
6870
if (err) {
6971
res.set(FUNCTION_STATUS_HEADER_FIELD, 'error');
@@ -131,7 +133,7 @@ function wrapCloudEventFunction(
131133
): HttpFunction {
132134
return (req: express.Request, res: express.Response) => {
133135
const callback = process.domain.bind(
134-
// tslint:disable-next-line:no-any
136+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
135137
(err: Error | null, result: any) => {
136138
if (res.locals.functionExecutionFinished) {
137139
console.log('Ignoring extra callback call');
@@ -184,7 +186,7 @@ function wrapEventFunction(
184186
return (req: express.Request, res: express.Response) => {
185187
const event = req.body;
186188
const callback = process.domain.bind(
187-
// tslint:disable-next-line:no-any
189+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
188190
(err: Error | null, result: any) => {
189191
if (res.locals.functionExecutionFinished) {
190192
console.log('Ignoring extra callback call');
@@ -251,6 +253,7 @@ function registerFunctionRoutes(
251253
if (functionSignatureType === SignatureType.HTTP) {
252254
app.use('/favicon.ico|/robots.txt', (req, res, next) => {
253255
res.sendStatus(404);
256+
next();
254257
});
255258

256259
app.use('/*', (req, res, next) => {
@@ -266,17 +269,17 @@ function registerFunctionRoutes(
266269
});
267270
} else if (functionSignatureType === SignatureType.EVENT) {
268271
app.post('/*', (req, res, next) => {
269-
const wrappedUserFunction = wrapEventFunction(userFunction as
270-
| EventFunction
271-
| EventFunctionWithCallback);
272+
const wrappedUserFunction = wrapEventFunction(
273+
userFunction as EventFunction | EventFunctionWithCallback
274+
);
272275
const handler = makeHttpHandler(wrappedUserFunction);
273276
handler(req, res, next);
274277
});
275278
} else {
276279
app.post('/*', (req, res, next) => {
277-
const wrappedUserFunction = wrapCloudEventFunction(userFunction as
278-
| CloudEventFunction
279-
| CloudEventFunctionWithCallback);
280+
const wrappedUserFunction = wrapCloudEventFunction(
281+
userFunction as CloudEventFunction | CloudEventFunctionWithCallback
282+
);
280283
const handler = makeHttpHandler(wrappedUserFunction);
281284
handler(req, res, next);
282285
});
@@ -318,6 +321,7 @@ export class ErrorHandler {
318321
process.on(signal as NodeJS.Signals, () => {
319322
console.log(`Received ${signal}`);
320323
this.server.close(() => {
324+
// eslint-disable-next-line no-process-exit
321325
process.exit();
322326
});
323327
});

src/loader.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/**
2222
* Import function signature type's definition.
2323
*/
24-
import { HandlerFunction } from './functions';
24+
import {HandlerFunction} from './functions';
2525

2626
/**
2727
* Returns user's function from function file.
@@ -39,6 +39,7 @@ export function getUserFunction(
3939
return null;
4040
}
4141

42+
// eslint-disable-next-line @typescript-eslint/no-var-requires
4243
const functionModule = require(functionModulePath);
4344
let userFunction = functionTarget
4445
.split('.')
@@ -52,6 +53,7 @@ export function getUserFunction(
5253

5354
// TODO: do we want 'function' fallback?
5455
if (typeof userFunction === 'undefined') {
56+
// eslint-disable-next-line no-prototype-builtins
5557
if (functionModule.hasOwnProperty('function')) {
5658
userFunction = functionModule['function'];
5759
} else {
@@ -104,7 +106,9 @@ function getFunctionModulePath(codeLocation: string): string | null {
104106
try {
105107
// TODO: Decide if we want to keep this fallback.
106108
path = require.resolve(codeLocation + '/function.js');
107-
} catch (ex) {}
109+
} catch (ex) {
110+
return path;
111+
}
108112
}
109113
return path;
110114
}

src/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import * as express from 'express';
16-
import { FUNCTION_STATUS_HEADER_FIELD } from './types';
16+
import {FUNCTION_STATUS_HEADER_FIELD} from './types';
1717

1818
/**
1919
* Logs an error message and sends back an error response to the incoming
@@ -23,7 +23,7 @@ import { FUNCTION_STATUS_HEADER_FIELD } from './types';
2323
* @param callback A function to be called synchronously.
2424
*/
2525
export function logAndSendError(
26-
// tslint:disable-next-line:no-any
26+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2727
err: Error | any,
2828
res: express.Response | null,
2929
callback?: Function

0 commit comments

Comments
 (0)