Skip to content

Commit 2e8c7a8

Browse files
antoine-cottineauClément DoursclementDours
authored
Add a package to share a common tsconfig (#13)
* feat: add a new package for sharing tsconfig.json * feat: create a shareable tsconfig in the tsconfig package * feat: use the shareable config in the example app * feat: add an example that breaks a shared tsconfig rule * deps: install missing eslint deps in the example app * feat: break another tsconfig rule * docs: add some documentation about the tsconfig package * feat: set the repo version to the same value as the packages * v0.2.0 * v0.3.0 * docs: add more information on how to publish packages * feat: use tsconfig in example-app * feat: update noImplicitReturns rule breaking example comment * refacto: rename folder from tsconfig to typescript-config * add script to run type tests in example-app --------- Co-authored-by: Clément Dours <[email protected]> Co-authored-by: Clément Dours <[email protected]>
1 parent 01fdbd5 commit 2e8c7a8

File tree

9 files changed

+4471
-2321
lines changed

9 files changed

+4471
-2321
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ Here are some useful commands:
2929
- rename the directory of a package: `mv package-my-config new-directory-name && yarn lerna bootstrap`,
3030
- run a script `do-something` that exists in at least one package: `yarn lerna run do-something` (this will try to run the script in all packages in which it is defined).
3131

32+
## Publishing a new version of a package
33+
34+
If this is the first time the package is published to npm, running `yarn lerna publish --no-private` [doesn't seem to work](https://github.com/lerna/lerna/issues/1821). Instead, you should `cd` into your package and run `yarn publish --access public`. `yarn` will then ask the new version the package should have.
35+
36+
If the package has already been published on npm, you can use `yarn lerna publish --no-private` in the root directory of the project.
37+
38+
For each of these two tasks, you will need to have an account on [npmjs.com](https://www.npmjs.com/) and to be added to the [@bam.tech](https://www.npmjs.com/settings/bam.tech/packages) organization.
39+
3240
## Running commands
3341

3442
- `yarn lerna run start`: run the 'start' script in all packages (currently only present in `example-app`),

example-app/package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,30 @@
55
"license": "MIT",
66
"scripts": {
77
"start": "node .",
8-
"lint": "eslint ."
8+
"lint": "eslint .",
9+
"types":"tsc --noEmit"
910
},
1011
"devDependencies": {
1112
"@types/jest": "^29.5.2",
1213
"@types/react": "^18.2.14",
13-
"@typescript-eslint/eslint-plugin": "^5.48.0",
14-
"eslint": "^8.31.0",
14+
"@bam.tech/typescript-config": "*",
15+
"@typescript-eslint/eslint-plugin": "^5.49.0",
16+
"eslint": "^8.32.0",
1517
"eslint-plugin-jest": "^27.2.2",
1618
"eslint-plugin-jest-formatting": "^3.1.0",
1719
"eslint-plugin-prettier": "^4.2.1",
18-
"eslint-plugin-react": "^7.31.11",
20+
"eslint-plugin-react": "^7.32.1",
1921
"eslint-plugin-react-hooks": "^4.6.0",
2022
"eslint-plugin-react-native": "^4.0.0",
2123
"eslint-plugin-testing-library": "^5.11.0",
2224
"jest": "^29.5.0",
23-
"prettier": "^2.8.8"
25+
"prettier": "^2.8.8",
26+
"typescript": "^4.9.4"
2427
},
2528
"private": "true",
2629
"dependencies": {
2730
"react": "^18.2.0",
28-
"react-native": "^0.72.0"
31+
"react-native": "^0.72.0",
32+
"expo": "^47.0.13"
2933
}
3034
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This example breaks the rule noImplicitReturns activated by the rule strict
2+
// (https://www.typescriptlang.org/tsconfig#noImplicitReturns)
3+
// specified in the imported tsconfig.
4+
export const lookupHeadphonesManufacturer = (
5+
color: "blue" | "black"
6+
): string => {
7+
if (color === "blue") {
8+
return "beats";
9+
} else {
10+
("bose");
11+
}
12+
};
13+
14+
// This example breaks the rule allowUnreachableCode: false (https://www.typescriptlang.org/tsconfig#allowUnreachableCode)
15+
// specified in the imported tsconfig.
16+
const fn = (n: number) => {
17+
if (n > 5) {
18+
return true;
19+
} else {
20+
return false;
21+
}
22+
};

example-app/tsconfig.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"compilerOptions": {
3-
"jsx": "react-native",
4-
"baseUrl": "./"
5-
}
2+
"extends": "@bam.tech/typescript-config"
63
}

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
33
"useWorkspaces": true,
4-
"version": "0.0.0"
4+
"version": "0.2.0"
55
}

packages/typescript-config/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# tsconfig for BAM
2+
3+
This project is just a simple package that exposes a tsconfig.json file that gathers the compiler options that should be used in any new BAM project.
4+
5+
## How to use?
6+
7+
In your app, run `yarn add @bam.tech/typescript-config expo`.
8+
9+
In your `.tsconfig.json` config file, extend the exported tsconfig:
10+
11+
```json
12+
// tsconfig.json
13+
{
14+
"extends": "@bam.tech/typescript-config/tsconfig"
15+
}
16+
```
17+
18+
## How to customize?
19+
20+
You can still customize your tsconfig by overriding any acceptable field.
21+
22+
## How to improve?
23+
24+
If you find a useful compiler options that you feel every project at BAM should use, feel free to open a PR.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@bam.tech/typescript-config",
3+
"version": "0.3.0",
4+
"license": "MIT",
5+
"peerDependencies": {
6+
"expo": ">=47"
7+
}
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"extends": "expo/tsconfig.base",
3+
"compilerOptions": {
4+
"allowJs": true,
5+
"allowSyntheticDefaultImports": true,
6+
"allowUnreachableCode": false,
7+
"esModuleInterop": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"isolatedModules": true,
10+
"jsx": "react-native",
11+
"lib": ["esnext"],
12+
"moduleResolution": "node",
13+
"noEmit": true,
14+
"noFallthroughCasesInSwitch": true,
15+
"noImplicitOverride": true,
16+
"noImplicitReturns": true,
17+
"noUncheckedIndexedAccess": true,
18+
"resolveJsonModule": true,
19+
"skipLibCheck": true,
20+
"strict": true,
21+
"target": "esnext",
22+
"types": ["react-native", "jest"]
23+
}
24+
}

0 commit comments

Comments
 (0)