Skip to content

Commit ec4b2e2

Browse files
authored
RD-1230 Add TypeScript (#46)
* RD-1230 Add generating TS declarations Add base and composite tsconfigs Install typescript and some @types packages Add scripts for checking types and generating type declarations Configure type declarations to be visible from outside * RD-1230 Add ESLint support for TypeScript Also adjust the rules a bit where it makes sense with TS * RD-1230 Handle TypeScript in rollup * RD-1230 Fix paths used for collecting coverage Only collect coverage from JS and TS files * RD-1230 Adjust ESLint rules for TypeScript * RD-1230 Fix react eslint config Some TS rules were overrode by airbnb's config Extracting TS overrides into a separate file and reusing it solves the issue. * RD-1230 Disable checking JS when running tsc * RD-1230 Expose src direstory in the package Allows navigating straight to the source file when using TypeScript * RD-1230 Describe TS-contributed tsconfigs and eslint configs
1 parent 18b8617 commit ec4b2e2

24 files changed

+860
-161
lines changed

.eslintrc.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"extends": [
3-
"plugin:jsdoc/recommended",
4-
"./configs/eslint-common.json"
5-
],
2+
"extends": ["plugin:jsdoc/recommended", "./configs/eslint-common.json"],
63
"rules": {
7-
"jsdoc/require-jsdoc": ["error", {
8-
"publicOnly": true
9-
}]
4+
"jsdoc/require-jsdoc": [
5+
"error",
6+
{
7+
"publicOnly": true
8+
}
9+
]
1010
},
1111
"settings": {
1212
"jsdoc": {

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
dist
44
node_modules
55
coverage
6+
typings

babel.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
node: 'current'
88
}
99
}
10-
]
10+
],
11+
['@babel/preset-typescript']
1112
]
1213
};

backend/.eslintrc.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
2-
"extends": [
3-
"../configs/eslint-common-node.json"
4-
]
2+
"extends": ["../configs/eslint-common-node.json"],
3+
"rules": {
4+
// NOTE: packageDir is relative to the current working directory when executing linter
5+
"import/no-extraneous-dependencies": ["error", { "packageDir": "./" }],
6+
// NOTE: handled by import/no-extraneous-dependencies
7+
"node/no-extraneous-require": "off"
8+
}
59
}

backend/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"types": "./typings/index.d.ts",
3+
"engines": {
4+
"node": ">=12"
5+
}
6+
}

backend/test/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../configs/tsconfig.base.json",
3+
"compilerOptions": {
4+
"module": "CommonJS",
5+
"types": ["jest", "node"]
6+
},
7+
"include": ["../**/*"],
8+
"exclude": ["../typings/**/*"]
9+
}

backend/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../configs/tsconfig.composite.json",
3+
"compilerOptions": {
4+
"module": "CommonJS",
5+
"declarationDir": "./typings"
6+
},
7+
"exclude": ["./test", "./typings"]
8+
}

configs/README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,40 @@ Once `cloudify-ui-common` is installed as a dependency it is required to modify
1616
}
1717
```
1818
It is also required to install peer dependencies as specified in `package.json`.
19-
There are three configuration files that can be extended.
19+
There are three configuration files that can be extended.
2020
The table below describes their purpose and dependencies necessary to be installed prior using each configuration file.
2121

2222
| Configuration file | Used for | Dependencies |
2323
|--- |--- |---|
24-
| `eslint-common.json` | non-react common projects | `eslint`, `eslint-config-prettier`, `eslint-plugin-import`, `eslint-plugin-prettier`, `eslint-plugin-scanjs-rules`, `eslint-plugin-security` |
25-
| `eslint-common-react.json` | react-based projects | all from `eslint-common.json` and `eslint-plugin-react`, `eslint-plugin-react-hooks`, `eslint-plugin-jsx-a11y` |
24+
| `eslint-ts-overrides.json` | TypeScript-based projects | `@typescript-eslint/eslint-plugin`, `@typescript-eslint/parser` |
25+
| `eslint-common.json` | non-react common projects | `eslint`, `eslint-config-prettier`, `eslint-plugin-import`, `eslint-plugin-prettier`, `eslint-plugin-scanjs-rules`, `eslint-plugin-security`, all from `eslint-ts-overrides.json` |
26+
| `eslint-common-react.json` | react-based projects | all from `eslint-common.json` and `eslint-ts-overrides.json`, and `eslint-plugin-react`, `eslint-plugin-react-hooks`, `eslint-plugin-jsx-a11y` |
2627
| `eslint-common-node.json` | node-based projects | all from `eslint-common.json`, `eslint-plugin-node` |
2728

2829

30+
### TypeScript
31+
32+
There are 2 possible base `tsconfig.json` files:
33+
34+
1. `tsconfig.base.json` - contains compiler options that help maintain code quality. They allow
35+
using JavaScript and TypeScript in the same project.
36+
37+
This configuration should be used for user-facing projects that do not need to be used as
38+
dependencies in other projects (not libraries).
39+
40+
2. `tsconfig.composite.json` - extends `tsconfig.base.json` with settings necessary to allow
41+
generating [declaration maps](https://www.typescriptlang.org/tsconfig#declarationMap).
42+
43+
This is useful for libraries, which are consumed by other user-facing projects.
44+
45+
To use an existing tsconfig as a base, specify the [extends](https://www.typescriptlang.org/tsconfig#extends) property in your `tsconfig.json`:
46+
47+
```json
48+
{
49+
"extends": "./node_modules/cloudify-ui-common/configs/tsconfig.base.json"
50+
}
51+
```
52+
2953
### Prettier
3054

3155
Prettier config should be extended by every cloudify-ui project/module.

configs/eslint-common-node.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
2-
"extends": [
3-
"./eslint-common.json",
4-
"plugin:node/recommended"
5-
],
2+
"extends": ["plugin:node/recommended", "./eslint-common.json"],
63
"env": {
74
"node": true
85
}

configs/eslint-common-react.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
"./eslint-common.json",
44
"airbnb",
55
"prettier/react",
6-
"plugin:prettier/recommended"
6+
"plugin:prettier/recommended",
7+
"./eslint-ts-overrides.json"
78
],
89
"rules": {
910
"no-param-reassign": [
1011
"error",
1112
{
1213
"props": false
1314
}
14-
]
15+
],
16+
"react/jsx-filename-extension": ["error", { "extensions": [".jsx", ".tsx"] }]
1517
},
1618
"env": {
1719
"browser": true

0 commit comments

Comments
 (0)