Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 Convert to Typescript #120

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = {
env: {
jest: true,
node: true,
},
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint", "jest", "prettier"],
rules: {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "after-used",
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"no-var": "error",
"prettier/prettier": "error",
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"prettier",
],
overrides: [
{
files: ["*.test.ts"],
rules: {
"@typescript-eslint/no-non-null-assertion": ["off"],
"@typescript-eslint/no-explicit-any": ["off"],
},
},
],
};
25 changes: 0 additions & 25 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ RUN npx [email protected] install --production
COPY . .
ENV NODE_ENV=production
EXPOSE 5000
CMD ["node", "app/server.js"]
CMD npm run server
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: node app/server.js
web: npm run server
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions app/server.js → app/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ const logger = require("@app/logger");
const port = config.express.port;

app.listen(port, () => logger.info(`Listening on port ${port}`));

export {};
14 changes: 14 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
collectCoverageFrom: ["app/**/*.{js,ts}"],
globals: {
"ts-jest": {
isolatedModules: true,
},
},
moduleNameMapper: {
"^@app(.*)$": "<rootDir>/app$1",
},
preset: "ts-jest",
roots: ["app"],
testEnvironment: "node",
};
36 changes: 19 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
"scripts": {
"prepare": "husky install",
"prestart": "node bin/pre-start",
"start": "nodemon --watch . --watch .env.development --watch .env.development.local app/server.js",
"lint": "eslint 'app/**/*.js'",
"server": "node app/server.js",
"start": "ts-node-dev --transpile-only --watch .,.env.development,.env.development.local app/server.ts",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodemon is a popular option.. is ts-node-dev well supported?

"lint": "npm-run-all -c lint:*",
"lint:eslint": "eslint 'app/**/*.{js,ts}'",
"lint:tsc": "tsc --noEmit",
"server": "ts-node --transpile-only app/server.ts",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider an explicit build step instead of using ts-node in production.

"test": "jest --watch",
"test:coverage": "jest --coverage"
},
Expand All @@ -17,6 +19,7 @@
"dependencies": {
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.4",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-basic-auth": "^1.2.0",
"helmet": "^4.6.0",
Expand All @@ -26,10 +29,18 @@
"morgan": "^1.9.0",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"ts-node": "^10.0.0",
"typescript": "^4.3.4",
"winston": "^3.2.1"
},
"devDependencies": {
"dotenv": "^10.0.0",
"@types/express": "^4.17.12",
"@types/jest": "^26.0.23",
"@types/lodash": "^4.14.170",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really still need lodash? Especially since this project is now Node 16+ and typescript.

"@types/node": "^15.12.4",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^4.28.0",
"@typescript-eslint/parser": "^4.28.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^24.4.0",
Expand All @@ -38,27 +49,18 @@
"jest": "^27.1.0",
"jest-junit": "^12.0.0",
"lint-staged": "^11.1.2",
"nodemon": "^2.0.7",
"npm-run-all": "^4.1.5",
"prettier": "^2.3.2",
"shelljs": "^0.8.2",
"supertest": "^6.1.6"
"supertest": "^6.1.6",
"ts-jest": "^27.0.3",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to have an example in the project of mocking a module in jest, and using the ts-jest utils.

"ts-node-dev": "^1.1.6"
},
"engines": {
"node": "^14.17.6",
"yarn": ">=1.12.1"
},
"_moduleAliases": {
"@app": "app"
},
"jest": {
"roots": [
"app"
],
"moduleNameMapper": {
"^@app(.*)$": "<rootDir>/app$1"
},
"collectCoverageFrom": [
"app/**/*.js"
]
}
}
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure node and jest are included in types.

"baseUrl": "app",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es2020"],
"module": "commonjs",
"outDir": "build",
"skipLibCheck": true,
"strict": true,
"target": "es2020"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly list excludes here (node_modules by default).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit includes as well.

}
Loading