Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit d79ed42

Browse files
feat: migrate to TypeScript (#150)
* feat: setup typescript * chore: make typescript files out of declaration files * chore: please linter by ordering right * chore: remove unused type * chore: migrate builder to typescript * chore: migrate consts to typescript * chore: migrate main to typescript * chore: extend eslint to typescript * chore: extend prettier to typescript files * chore: fix tests * Update package.json Co-authored-by: Eduardo Bouças <[email protected]> * chore: add missing npm-run-all dependency Co-authored-by: Netlify Team Account 1 <[email protected]> Co-authored-by: Eduardo Bouças <[email protected]>
1 parent 3686a7e commit d79ed42

17 files changed

+188
-91
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ node_modules
1010
/coverage
1111
/build
1212
.vscode
13+
dist

package-lock.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"name": "@netlify/functions",
3-
"main": "./src/main.js",
4-
"types": "./src/main.d.ts",
3+
"main": "./dist/main.js",
4+
"types": "./dist/main.d.ts",
55
"version": "0.7.2",
66
"description": "JavaScript utilities for Netlify Functions",
77
"files": [
8-
"src/**/*.js",
9-
"src/**/*.ts",
10-
"!src/**/*.test.js"
8+
"dist/**/*.js",
9+
"dist/**/*.d.ts"
1110
],
1211
"scripts": {
12+
"build": "tsc",
13+
"prepack": "npm run build",
1314
"prepublishOnly": "npm ci && npm test",
1415
"test": "run-s format test:dev",
1516
"format": "run-s format:check-fix:*",
@@ -20,14 +21,14 @@
2021
"format:check-fix:prettier": "run-e format:check:prettier format:fix:prettier",
2122
"format:check:prettier": "cross-env-shell prettier --check $npm_package_config_prettier",
2223
"format:fix:prettier": "cross-env-shell prettier --write $npm_package_config_prettier",
23-
"test:dev": "run-s test:dev:*",
24-
"test:ci": "run-s test:ci:*",
24+
"test:dev": "run-s build test:dev:*",
25+
"test:ci": "run-s build test:ci:*",
2526
"test:dev:ava": "ava",
2627
"test:ci:ava": "nyc -r lcovonly -r text -r json ava"
2728
},
2829
"config": {
29-
"eslint": "--ignore-pattern README.md --ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,scripts,.github}/**/*.{js,md,html}\" \"*.{js,md,html}\" \".*.{js,md,html}\"",
30-
"prettier": "--ignore-path .gitignore --loglevel=warn \"{src,scripts,.github}/**/*.{js,md,yml,json,html}\" \"*.{js,yml,json,html}\" \".*.{js,yml,json,html}\" \"!**/package-lock.json\" \"!package-lock.json\""
30+
"eslint": "--ignore-pattern README.md --ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,scripts,.github}/**/*.{ts,js,md,html}\" \"*.{ts,js,md,html}\" \".*.{ts,js,md,html}\"",
31+
"prettier": "--ignore-path .gitignore --loglevel=warn \"{src,scripts,.github}/**/*.{ts,js,md,yml,json,html}\" \"*.{ts,js,yml,json,html}\" \".*.{ts,js,yml,json,html}\" \"!**/package-lock.json\" \"!package-lock.json\""
3132
},
3233
"ava": {
3334
"files": [
@@ -60,7 +61,9 @@
6061
"@netlify/eslint-config-node": "^3.3.4",
6162
"ava": "^2.4.0",
6263
"husky": "^4.3.8",
63-
"nyc": "^15.0.0"
64+
"npm-run-all": "^4.1.5",
65+
"nyc": "^15.0.0",
66+
"typescript": "^4.4.4"
6467
},
6568
"engines": {
6669
"node": ">=8.3.0"

src/function/context.d.ts renamed to src/function/context.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// eslint-disable-next-line eslint-comments/disable-enable-pair
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
3+
14
// From https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html.
25
export interface Context {
36
callbackWaitsForEmptyEventLoop: boolean
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
export interface Event {
2-
rawUrl: string
3-
rawQuery: string
4-
path: string
5-
httpMethod: string
6-
headers: EventHeaders
7-
multiValueHeaders: EventMultiValueHeaders
8-
queryStringParameters: EventQueryStringParameters | null
9-
multiValueQueryStringParameters: EventMultiValueQueryStringParameters | null
10-
body: string | null
11-
isBase64Encoded: boolean
12-
}
13-
141
interface EventHeaders {
152
[name: string]: string | undefined
163
}
@@ -19,14 +6,23 @@ interface EventMultiValueHeaders {
196
[name: string]: string[] | undefined
207
}
218

22-
interface EventPathParameters {
23-
[name: string]: string | undefined
24-
}
25-
269
interface EventQueryStringParameters {
2710
[name: string]: string | undefined
2811
}
2912

3013
interface EventMultiValueQueryStringParameters {
3114
[name: string]: string[] | undefined
3215
}
16+
17+
export interface Event {
18+
rawUrl: string
19+
rawQuery: string
20+
path: string
21+
httpMethod: string
22+
headers: EventHeaders
23+
multiValueHeaders: EventMultiValueHeaders
24+
queryStringParameters: EventQueryStringParameters | null
25+
multiValueQueryStringParameters: EventMultiValueQueryStringParameters | null
26+
body: string | null
27+
isBase64Encoded: boolean
28+
}

src/function/handler.d.ts renamed to src/function/handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Event } from './event'
33
import type { Response } from './response'
44

55
export interface HandlerCallback {
6+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
67
(error: any, response: Response): void
78
}
89

File renamed without changes.
File renamed without changes.

src/lib/builder.d.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/lib/builder.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)