Skip to content

Commit da6812e

Browse files
chore!: drop support for old nodejs versions
1 parent 053a4ca commit da6812e

29 files changed

+5319
-1305
lines changed

package-lock.json

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

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
}
2020
},
2121
"dependencies": {
22-
"@types/express": "^5.0.0",
23-
"body-parser": "^1.18.3",
22+
"@types/express": "^5.0.1",
23+
"body-parser": "1.20.3",
2424
"cloudevents": "^8.0.2",
2525
"express": "^4.21.2",
2626
"minimist": "^1.2.8",
2727
"on-finished": "^2.3.0",
28-
"read-pkg-up": "^7.0.1",
29-
"semver": "^7.6.3"
28+
"read-package-up": "^11.0.0",
29+
"semver": "^7.7.1"
3030
},
3131
"scripts": {
3232
"test": "mocha build/test --recursive",
@@ -52,21 +52,21 @@
5252
"author": "Google Inc.",
5353
"license": "Apache-2.0",
5454
"devDependencies": {
55-
"@microsoft/api-extractor": "^7.48.0",
55+
"@microsoft/api-extractor": "^7.52.2",
5656
"@types/body-parser": "1.19.5",
5757
"@types/minimist": "1.2.5",
5858
"@types/mocha": "^10.0.0",
59-
"@types/node": "^22.10.1",
59+
"@types/node": "^22.13.14",
6060
"@types/on-finished": "2.3.4",
61-
"@types/semver": "^7.5.8",
62-
"@types/sinon": "^17.0.3",
63-
"@types/supertest": "6.0.2",
64-
"gts": "5.3.1",
65-
"mocha": "^9.2.2",
66-
"nise": "5.1.4",
67-
"pack-n-play": "2.0.0",
68-
"sinon": "15.0.1",
69-
"supertest": "^6.3.4",
70-
"typescript": "5.0.3"
61+
"@types/semver": "^7.7.0",
62+
"@types/sinon": "^17.0.4",
63+
"@types/supertest": "6.0.3",
64+
"gts": "6.0.2",
65+
"mocha": "^11.1 .0",
66+
"nise": "6.1.1",
67+
"pack-n-play": "3.0.0",
68+
"sinon": "20.0.0",
69+
"supertest": "^7.1.0",
70+
"typescript": "5.8.2"
7171
}
7272
}

src/async_local_storage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let asyncLocalStorage: AsyncLocalStorage<ExecutionContext> | undefined;
1414
export async function asyncLocalStorageMiddleware(
1515
req: Request,
1616
res: Response,
17-
next: NextFunction
17+
next: NextFunction,
1818
) {
1919
if (
2020
semver.lt(process.versions.node, requiredNodeJsVersionForLogExecutionID)
@@ -35,7 +35,7 @@ export async function asyncLocalStorageMiddleware(
3535
},
3636
() => {
3737
next();
38-
}
38+
},
3939
);
4040
}
4141

src/cloud_events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ export function isBinaryCloudEvent(req: express.Request): boolean {
5757
* @return CloudEvents context
5858
*/
5959
export function getBinaryCloudEventContext(
60-
req: express.Request
60+
req: express.Request,
6161
): CloudEvent<unknown> {
6262
const context = {} as CloudEvent<unknown>;
6363
for (const name in req.headers) {
6464
if (name.startsWith('ce-')) {
6565
const attributeName = name.substr(
66-
'ce-'.length
66+
'ce-'.length,
6767
) as keyof CloudEvent<unknown>;
6868
context[attributeName] = req.header(name);
6969
}

src/execution_context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function generateExecutionId() {
1616
export const executionContextMiddleware = (
1717
req: Request,
1818
res: Response,
19-
next: NextFunction
19+
next: NextFunction,
2020
) => {
2121
let executionId = req.header(FUNCTION_EXECUTION_ID_HEADER_KEY);
2222
if (!executionId) {

src/function_registry.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const registrationContainer = new Map<string, RegisteredFunction<any, any>>();
3939
const register = <T = unknown, U = unknown>(
4040
functionName: string,
4141
signatureType: SignatureType,
42-
userFunction: HandlerFunction<T, U>
42+
userFunction: HandlerFunction<T, U>,
4343
): void => {
4444
if (!isValidFunctionName(functionName)) {
4545
throw new Error(`Invalid function name: ${functionName}`);
@@ -73,7 +73,7 @@ export const isValidFunctionName = (functionName: string): boolean => {
7373
* the provided name has been registered
7474
*/
7575
export const getRegisteredFunction = (
76-
functionName: string
76+
functionName: string,
7777
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7878
): RegisteredFunction<any, any> | undefined => {
7979
return registrationContainer.get(functionName);
@@ -97,7 +97,7 @@ export const http = (functionName: string, handler: HttpFunction): void => {
9797
*/
9898
export const cloudEvent = <T = unknown>(
9999
functionName: string,
100-
handler: CloudEventFunction<T> | CloudEventFunctionWithCallback<T>
100+
handler: CloudEventFunction<T> | CloudEventFunctionWithCallback<T>,
101101
): void => {
102102
register(functionName, 'cloudevent', handler);
103103
};
@@ -110,7 +110,7 @@ export const cloudEvent = <T = unknown>(
110110
*/
111111
export const typed = <T, U>(
112112
functionName: string,
113-
handler: TypedFunction<T, U>['handler'] | TypedFunction<T, U>
113+
handler: TypedFunction<T, U>['handler'] | TypedFunction<T, U>,
114114
): void => {
115115
if (handler instanceof Function) {
116116
handler = {

src/function_wrappers.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const wrapHttpFunction = (execute: HttpFunction): RequestHandler => {
136136
* @return An Express hander function that invokes the user function
137137
*/
138138
const wrapCloudEventFunction = (
139-
userFunction: CloudEventFunction
139+
userFunction: CloudEventFunction,
140140
): RequestHandler => {
141141
const httpHandler = (req: Request, res: Response) => {
142142
const callback = getOnDoneCallback(res);
@@ -145,7 +145,7 @@ const wrapCloudEventFunction = (
145145
.then(() => userFunction(cloudEvent))
146146
.then(
147147
result => callback(null, result),
148-
err => callback(err, undefined)
148+
err => callback(err, undefined),
149149
);
150150
};
151151
return wrapHttpFunction(httpHandler);
@@ -157,7 +157,7 @@ const wrapCloudEventFunction = (
157157
* @return An Express hander function that invokes the user function
158158
*/
159159
const wrapCloudEventFunctionWithCallback = (
160-
userFunction: CloudEventFunctionWithCallback
160+
userFunction: CloudEventFunctionWithCallback,
161161
): RequestHandler => {
162162
const httpHandler = (req: Request, res: Response) => {
163163
const callback = getOnDoneCallback(res);
@@ -180,7 +180,7 @@ const wrapEventFunction = (userFunction: EventFunction): RequestHandler => {
180180
.then(() => userFunction(data, context))
181181
.then(
182182
result => callback(null, result),
183-
err => callback(err, undefined)
183+
err => callback(err, undefined),
184184
);
185185
};
186186
return wrapHttpFunction(httpHandler);
@@ -192,7 +192,7 @@ const wrapEventFunction = (userFunction: EventFunction): RequestHandler => {
192192
* @return An Express hander function that invokes the user function
193193
*/
194194
const wrapEventFunctionWithCallback = (
195-
userFunction: EventFunctionWithCallback
195+
userFunction: EventFunctionWithCallback,
196196
): RequestHandler => {
197197
const httpHandler = (req: Request, res: Response) => {
198198
const callback = getOnDoneCallback(res);
@@ -210,12 +210,12 @@ const wrapEventFunctionWithCallback = (
210210
const wrapTypedFunction = (typedFunction: TypedFunction): RequestHandler => {
211211
const typedHandlerWrapper: HttpFunction = async (
212212
req: Request,
213-
res: Response
213+
res: Response,
214214
) => {
215215
let reqTyped: unknown;
216216
try {
217217
reqTyped = typedFunction.format.deserializeRequest(
218-
new InvocationRequestImpl(req)
218+
new InvocationRequestImpl(req),
219219
);
220220
} catch (err) {
221221
sendCrashResponse({
@@ -234,7 +234,7 @@ const wrapTypedFunction = (typedFunction: TypedFunction): RequestHandler => {
234234
// eslint-disable-next-line @typescript-eslint/no-floating-promises
235235
typedFunction.format.serializeResponse(
236236
new InvocationResponseImpl(res),
237-
resTyped
237+
resTyped,
238238
);
239239
};
240240

@@ -249,7 +249,7 @@ const wrapTypedFunction = (typedFunction: TypedFunction): RequestHandler => {
249249
*/
250250
export const wrapUserFunction = <T = unknown>(
251251
userFunction: HandlerFunction<T>,
252-
signatureType: SignatureType
252+
signatureType: SignatureType,
253253
): RequestHandler => {
254254
switch (signatureType) {
255255
case 'http':
@@ -258,15 +258,15 @@ export const wrapUserFunction = <T = unknown>(
258258
// Callback style if user function has more than 2 arguments.
259259
if (userFunction instanceof Function && userFunction!.length > 2) {
260260
return wrapEventFunctionWithCallback(
261-
userFunction as EventFunctionWithCallback
261+
userFunction as EventFunctionWithCallback,
262262
);
263263
}
264264
return wrapEventFunction(userFunction as EventFunction);
265265
case 'cloudevent':
266266
if (userFunction instanceof Function && userFunction!.length > 1) {
267267
// Callback style if user function has more than 1 argument.
268268
return wrapCloudEventFunctionWithCallback(
269-
userFunction as CloudEventFunctionWithCallback
269+
userFunction as CloudEventFunctionWithCallback,
270270
);
271271
}
272272
return wrapCloudEventFunction(userFunction as CloudEventFunction);

src/functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export interface InvocationFormat<T, U> {
206206
*/
207207
serializeResponse(
208208
responseWriter: InvocationResponse,
209-
response: U
209+
response: U,
210210
): void | Promise<void>;
211211
}
212212

@@ -225,7 +225,7 @@ export class JsonInvocationFormat<T, U> implements InvocationFormat<T, U> {
225225
} catch (e) {
226226
throw new Error(
227227
'Failed to parse malformatted JSON in request: ' +
228-
(e as SyntaxError).message
228+
(e as SyntaxError).message,
229229
);
230230
}
231231
}

src/invoker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function sendResponse(
4444
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4545
result: any,
4646
err: Error | null,
47-
res: express.Response
47+
res: express.Response,
4848
) {
4949
if (err) {
5050
sendCrashResponse({err, res, statusHeader: 'error'});
@@ -67,7 +67,7 @@ export function sendResponse(
6767
// (this was the customer's clear intent) but send a 204 (NO CONTENT) and
6868
// log an error message explaining why their content wasn't sent.
6969
console.error(
70-
'Error serializing return value: ' + (sendErr as Error).toString()
70+
'Error serializing return value: ' + (sendErr as Error).toString(),
7171
);
7272
res.sendStatus(204); // No Content
7373
}

src/loader.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import * as path from 'path';
2222
import * as semver from 'semver';
23-
import * as readPkgUp from 'read-pkg-up';
2423
import {pathToFileURL} from 'url';
2524
import {HandlerFunction} from './functions';
2625
import {SignatureType} from './types';
@@ -56,7 +55,8 @@ async function isEsModule(modulePath: string): Promise<boolean> {
5655
return false;
5756
}
5857

59-
const pkg = await readPkgUp({
58+
const {readPackageUp} = await dynamicImport('read-package-up');
59+
const pkg = await readPackageUp({
6060
cwd: path.dirname(modulePath),
6161
normalize: false,
6262
});
@@ -73,7 +73,7 @@ async function isEsModule(modulePath: string): Promise<boolean> {
7373
*/
7474
const dynamicImport = new Function(
7575
'modulePath',
76-
'return import(modulePath)'
76+
'return import(modulePath)',
7777
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7878
) as (modulePath: string) => Promise<any>;
7979

@@ -85,7 +85,7 @@ const dynamicImport = new Function(
8585
export async function getUserFunction(
8686
codeLocation: string,
8787
functionTarget: string,
88-
signatureType: SignatureType
88+
signatureType: SignatureType,
8989
): Promise<{
9090
userFunction: HandlerFunction;
9191
signatureType: SignatureType;
@@ -96,7 +96,7 @@ export async function getUserFunction(
9696
console.error(
9797
`Provided code location '${codeLocation}' is not a loadable module.` +
9898
'\nDid you specify the correct location for the module defining ' +
99-
'your function?'
99+
'your function?',
100100
);
101101
return null;
102102
}
@@ -107,7 +107,7 @@ export async function getUserFunction(
107107
if (semver.lt(process.version, MIN_NODE_VERSION_ESMODULES)) {
108108
console.error(
109109
`Cannot load ES Module on Node.js ${process.version}. ` +
110-
`Please upgrade to Node.js v${MIN_NODE_VERSION_ESMODULES} and up.`
110+
`Please upgrade to Node.js v${MIN_NODE_VERSION_ESMODULES} and up.`,
111111
);
112112
return null;
113113
}
@@ -138,15 +138,15 @@ export async function getUserFunction(
138138
if (typeof userFunction === 'undefined') {
139139
console.error(
140140
`Function '${functionTarget}' is not defined in the provided ` +
141-
'module.\nDid you specify the correct target function to execute?'
141+
'module.\nDid you specify the correct target function to execute?',
142142
);
143143
return null;
144144
}
145145

146146
if (typeof userFunction !== 'function') {
147147
console.error(
148148
`'${functionTarget}' needs to be of type function. Got: ` +
149-
`${typeof userFunction}`
149+
`${typeof userFunction}`,
150150
);
151151
return null;
152152
}
@@ -165,7 +165,7 @@ export async function getUserFunction(
165165
}
166166
console.error(
167167
`Provided module can't be loaded.\n${additionalHint}` +
168-
`Detailed stack trace: ${err.stack}`
168+
`Detailed stack trace: ${err.stack}`,
169169
);
170170
return null;
171171
}

src/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function splitArgs(args: any[]) {
109109
export function getModifiedData(
110110
data: Uint8Array | string,
111111
encoding?: BufferEncoding,
112-
stderr = false
112+
stderr = false,
113113
) {
114114
const currentContext = getCurrentContext();
115115
if (!currentContext) {
@@ -137,7 +137,7 @@ export function getModifiedData(
137137

138138
function getTextWithContext(
139139
data: Uint8Array | string,
140-
context: ExecutionContext
140+
context: ExecutionContext,
141141
) {
142142
return {
143143
message: data,

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const main = async () => {
4343
const loadedFunction = await getUserFunction(
4444
options.sourceLocation,
4545
options.target,
46-
options.signatureType
46+
options.signatureType,
4747
);
4848
if (!loadedFunction) {
4949
console.error('Could not load the function, shutting down.');

0 commit comments

Comments
 (0)