From 1a1e86195e696449acee3fc4079eabed756dc8c5 Mon Sep 17 00:00:00 2001 From: Pavel <14926950+prichodko@users.noreply.github.com> Date: Wed, 23 Feb 2022 16:16:42 +0100 Subject: [PATCH] Improve TypeScript monorepo configuration (#226) * Unify TypeScript configuration * Fix package.json target fields --- package.json | 2 ++ packages/status-core/package.json | 13 +++---- packages/status-core/src/index.ts | 1 + packages/status-core/tsconfig.json | 53 +++-------------------------- packages/status-react/package.json | 13 +++---- packages/status-react/tsconfig.json | 51 ++++----------------------- tsconfig.base.json | 27 +++++++++++++++ yarn.lock | 2 +- 8 files changed, 56 insertions(+), 106 deletions(-) create mode 100644 tsconfig.base.json diff --git a/package.json b/package.json index eec5caa4..f82b2cc0 100644 --- a/package.json +++ b/package.json @@ -9,11 +9,13 @@ "fix": "run-s 'fix:*' && wsrun -e -c -s fix", "build": "wsrun -e -c -s build", "format": "prettier --write .", + "typecheck": "wsrun -e -c -s typecheck", "test": "wsrun -e -c -s test" }, "devDependencies": { "npm-run-all": "^4.1.5", "prettier": "^2.5.1", + "typescript": "^4.5.5", "wsrun": "^5.2.4" }, "packageManager": "yarn@1.22.17" diff --git a/packages/status-core/package.json b/packages/status-core/package.json index f31e4939..536a331d 100644 --- a/packages/status-core/package.json +++ b/packages/status-core/package.json @@ -10,13 +10,14 @@ "bugs": { "url": "https://github.com/status-im/status-web/issues" }, - "main": "dist/cjs/src/index.js", - "module": "dist/esm/src/index.js", - "types": "dist/esm/src/index.d.ts", + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "types": "dist/types/index.d.ts", "scripts": { "build": "run-s 'build:*'", "build:esm": "tsc --module es2020 --target es2017 --outDir dist/esm", "build:cjs": "tsc --outDir dist/cjs", + "build:types": "tsc --emitDeclarationOnly", "fix": "run-s 'fix:*'", "fix:lint": "eslint src --ext .ts --fix", "test": "run-s 'test:*'", @@ -24,7 +25,8 @@ "test:unit": "mocha", "proto": "run-s 'proto:*'", "proto:lint": "buf lint", - "proto:build": "buf generate" + "proto:build": "buf generate", + "typecheck": "tsc --noEmit" }, "devDependencies": { "@types/bn.js": "^5.1.0", @@ -46,8 +48,7 @@ "mocha": "^9.1.1", "npm-run-all": "^4.1.5", "ts-node": "^10.2.1", - "ts-proto": "^1.83.0", - "typescript": "^4.4.3" + "ts-proto": "^1.83.0" }, "dependencies": { "bn.js": "^5.2.0", diff --git a/packages/status-core/src/index.ts b/packages/status-core/src/index.ts index 8fb7553e..b20b847d 100644 --- a/packages/status-core/src/index.ts +++ b/packages/status-core/src/index.ts @@ -5,6 +5,7 @@ export { Contacts } from './contacts' export { Chat } from './chat' export * from './groupChats' export * as utils from './utils' +export * from './utils' export { ApplicationMetadataMessage } from './wire/application_metadata_message' export { ChatMessage, diff --git a/packages/status-core/tsconfig.json b/packages/status-core/tsconfig.json index 482825d4..ed816987 100644 --- a/packages/status-core/tsconfig.json +++ b/packages/status-core/tsconfig.json @@ -1,51 +1,8 @@ { - "compilerOptions": { - "incremental": true, - "target": "es6", - "outDir": "dist", - "rootDir": "src", - "moduleResolution": "node", - "module": "commonjs", - "declaration": true, - "sourceMap": true, - "esModuleInterop": true, - "resolveJsonModule": true, - "composite": true, - "strict": true /* Enable all strict type-checking options. */, - - /* Strict Type-Checking Options */ - "noImplicitAny": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "strictPropertyInitialization": true, - "noImplicitThis": true, - "alwaysStrict": true, - - /* Additional Checks */ - "noUnusedLocals": true, - "noUnusedParameters": true, - "noImplicitReturns": false /* to set at a later stage */, - "noFallthroughCasesInSwitch": true, - "forceConsistentCasingInFileNames": true, - - /* Debugging Options */ - "traceResolution": false, - "listEmittedFiles": false, - "listFiles": false, - "pretty": true, - - // Due to broken types in indirect dependencies - "skipLibCheck": true, - - "lib": ["es6", "dom"], - "typeRoots": [ - "./node_modules/@types", - "./src/types", - "../../node_modules/@types" - ] - }, + "extends": "../../tsconfig.base.json", "include": ["src"], - "exclude": ["node_modules/**"], - "types": ["mocha"], - "compileOnSave": false + "compilerOptions": { + "outDir": "dist", + "declarationDir": "dist/types" + } } diff --git a/packages/status-react/package.json b/packages/status-react/package.json index b3ceca3f..147355ff 100644 --- a/packages/status-react/package.json +++ b/packages/status-react/package.json @@ -11,20 +11,22 @@ "bugs": { "url": "https://github.com/status-im/status-web/issues" }, - "main": "dist/cjs/src/index.js", - "module": "dist/esm/src/index.js", - "types": "dist/esm/src/index.d.ts", + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "types": "dist/types/index.d.ts", "scripts": { "build": "run-s 'build:*'", "build:esm": "tsc --module es2020 --target es2017 --outDir dist/esm", "build:cjs": "tsc --outDir dist/cjs", + "build:types": "tsc --emitDeclarationOnly", "fix": "run-s 'fix:*'", "fix:lint": "eslint './{src,test}/**/*.{ts,tsx}' --fix", "test": "run-s 'test:*'", "test:lint": "eslint './{src,test}/**/*.{ts,tsx}'", "proto": "run-s 'proto:*'", "proto:lint": "buf lint", - "proto:build": "buf generate" + "proto:build": "buf generate", + "typecheck": "tsc --noEmit" }, "devDependencies": { "@hcaptcha/react-hcaptcha": "^1.0.0", @@ -49,8 +51,7 @@ "npm-watch": "^0.11.0", "qrcode.react": "^1.0.1", "rimraf": "^3.0.2", - "ts-node": "^10.1.0", - "typescript": "^4.3.5" + "ts-node": "^10.1.0" }, "dependencies": { "@status-im/core": "^0.0.0", diff --git a/packages/status-react/tsconfig.json b/packages/status-react/tsconfig.json index 416708b4..bbbb84f2 100644 --- a/packages/status-react/tsconfig.json +++ b/packages/status-react/tsconfig.json @@ -1,48 +1,9 @@ { - "compilerOptions": { - "target": "es6", - "jsx": "react", - "outDir": "dist", - "moduleResolution": "node", - "module": "commonjs", - "declaration": true, - "sourceMap": true, - "esModuleInterop": true, - "resolveJsonModule": true, - "composite": true, - "strict": true /* Enable all strict type-checking options. */, - - /* Strict Type-Checking Options */ - "noImplicitAny": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "strictPropertyInitialization": true, - "noImplicitThis": true, - "alwaysStrict": true, - - /* Additional Checks */ - "noUnusedLocals": true, - "noUnusedParameters": true, - "noImplicitReturns": false /* to set at a later stage */, - "noFallthroughCasesInSwitch": true, - "forceConsistentCasingInFileNames": true, - - /* Debugging Options */ - "traceResolution": false, - "listEmittedFiles": false, - "listFiles": false, - "pretty": true, - - // Due to broken types in indirect dependencies - "skipLibCheck": true, - "typeRoots": [ - "./node_modules/@types", - "./src/types", - "../../node_modules/@types" - ] - }, + "extends": "../../tsconfig.base.json", "include": ["src"], - "exclude": ["node_modules/**"], - "types": ["mocha"], - "compileOnSave": false + "compilerOptions": { + "outDir": "./dist", + "declarationDir": "dist/types", + "resolveJsonModule": true + } } diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 00000000..58c75bb0 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "incremental": true, + "target": "ES2020", + "module": "ES2020", + "moduleResolution": "node", + "jsx": "preserve", + "declaration": true, + "declarationMap": true, + // "emitDeclarationOnly": true, + "sourceMap": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + // "noEmit": true, + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + // "exactOptionalPropertyTypes": true, + "noFallthroughCasesInSwitch": true, + // "noImplicitReturns": true, + // "noUncheckedIndexedAccess": true, + // "noPropertyAccessFromIndexSignature": true /* Enforces using indexed accessors for keys declared using an indexed type */, + "skipLibCheck": true, + "pretty": true + } +} diff --git a/yarn.lock b/yarn.lock index 2da1a865..c42e5129 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6572,7 +6572,7 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@^4.0.0, typescript@^4.3.5, typescript@^4.4.3: +typescript@^4.0.0, typescript@^4.5.5: version "4.5.5" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3" integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==