From b535b539015028253f7fbeef3857215c4369d5b3 Mon Sep 17 00:00:00 2001 From: Anton Gunnarsson Date: Fri, 28 Mar 2025 07:07:24 +0000 Subject: [PATCH] Merged in feat/shared-ts-config (pull request #1610) Add typescript-config package with shared configs * Move web config to shared * Move design-system ts config to typescript-config package * Move redis-api tsconfig to typescript-config package * Sort tsconfig keys * Update react-library tsconfig Move declaration and declarationMap from base Add sourceMap This fixes Go-to-Definition, debugging and similar in packages/apps where it is consumed * Update base config module and moduleResolution Approved-by: Michael Zetterberg Approved-by: Christian Andolf --- apps/redis-api/tsconfig.json | 32 +++---------------- apps/scandic-web/package.json | 1 + apps/scandic-web/tsconfig.json | 16 +--------- packages/design-system/tsconfig.json | 21 ++---------- packages/typescript-config/base.json | 16 ++++++++++ packages/typescript-config/bun.json | 11 +++++++ packages/typescript-config/nextjs.json | 12 +++++++ packages/typescript-config/package.json | 5 +++ packages/typescript-config/react-library.json | 13 ++++++++ yarn.lock | 7 ++++ 10 files changed, 73 insertions(+), 61 deletions(-) create mode 100644 packages/typescript-config/base.json create mode 100644 packages/typescript-config/bun.json create mode 100644 packages/typescript-config/nextjs.json create mode 100644 packages/typescript-config/package.json create mode 100644 packages/typescript-config/react-library.json diff --git a/apps/redis-api/tsconfig.json b/apps/redis-api/tsconfig.json index f99ca7bc8..db662480b 100644 --- a/apps/redis-api/tsconfig.json +++ b/apps/redis-api/tsconfig.json @@ -1,30 +1,8 @@ { - "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "allowJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false, - "paths": { - "@/*": ["./src/*"] - } + "extends": "@scandic-hotels/typescript-config/bun.json", + "compilerOptions": { + "paths": { + "@/*": ["./src/*"] } + } } diff --git a/apps/scandic-web/package.json b/apps/scandic-web/package.json index e6b8222fe..0d0ad756a 100644 --- a/apps/scandic-web/package.json +++ b/apps/scandic-web/package.json @@ -104,6 +104,7 @@ "zustand": "^4.5.2" }, "devDependencies": { + "@scandic-hotels/typescript-config": "workspace:*", "@svgr/webpack": "^8.1.0", "@testing-library/jest-dom": "^6.4.6", "@testing-library/react": "^16.0.0", diff --git a/apps/scandic-web/tsconfig.json b/apps/scandic-web/tsconfig.json index 14bd213af..86e8136db 100644 --- a/apps/scandic-web/tsconfig.json +++ b/apps/scandic-web/tsconfig.json @@ -1,20 +1,6 @@ { + "extends": "@scandic-hotels/typescript-config/nextjs.json", "compilerOptions": { - "target": "es2022", - "lib": ["dom", "dom.iterable", "ES2022"], - "allowJs": true, - "checkJs": true, - "skipLibCheck": true, - "strict": true, - "noEmit": true, - "esModuleInterop": true, - "module": "esnext", - "moduleDetection": "force", - "moduleResolution": "bundler", - "resolveJsonModule": true, - "isolatedModules": true, - "jsx": "preserve", - "incremental": true, "plugins": [ { "name": "next" diff --git a/packages/design-system/tsconfig.json b/packages/design-system/tsconfig.json index 860a801a4..19cd1da41 100644 --- a/packages/design-system/tsconfig.json +++ b/packages/design-system/tsconfig.json @@ -1,25 +1,8 @@ { + "extends": "@scandic-hotels/typescript-config/react-library.json", "compilerOptions": { - "declaration": true, - "target": "ES2022", - "useDefineForClassFields": true, - "lib": ["ES2022", "DOM", "DOM.Iterable"], - "module": "ESNext", - "skipLibCheck": true, - - /* Bundler mode */ - "moduleResolution": "bundler", "allowImportingTsExtensions": true, - "resolveJsonModule": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "react-jsx", - - /* Linting */ - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true + "noEmit": true }, "include": ["example", "lib"], "exclude": ["node_modules", "**/*.test.ts"] diff --git a/packages/typescript-config/base.json b/packages/typescript-config/base.json new file mode 100644 index 000000000..570f23d72 --- /dev/null +++ b/packages/typescript-config/base.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "compilerOptions": { + "esModuleInterop": true, + "incremental": false, + "isolatedModules": true, + "lib": ["es2022", "DOM", "DOM.Iterable"], + "module": "ESNext", + "moduleDetection": "force", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "target": "ES2022" + } +} diff --git a/packages/typescript-config/bun.json b/packages/typescript-config/bun.json new file mode 100644 index 000000000..035b1545a --- /dev/null +++ b/packages/typescript-config/bun.json @@ -0,0 +1,11 @@ +{ + "extends": "@scandic-hotels/typescript-config/base.json", + "compilerOptions": { + "allowImportingTsExtensions": true, + "allowJs": true, + "noEmit": true, + "noFallthroughCasesInSwitch": true, + "target": "ESNext", + "verbatimModuleSyntax": true + } +} diff --git a/packages/typescript-config/nextjs.json b/packages/typescript-config/nextjs.json new file mode 100644 index 000000000..32b5fc74a --- /dev/null +++ b/packages/typescript-config/nextjs.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "./base.json", + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "incremental": true, + "jsx": "preserve", + "noEmit": true, + "plugins": [{ "name": "next" }] + } +} diff --git a/packages/typescript-config/package.json b/packages/typescript-config/package.json new file mode 100644 index 000000000..801df5677 --- /dev/null +++ b/packages/typescript-config/package.json @@ -0,0 +1,5 @@ +{ + "name": "@scandic-hotels/typescript-config", + "private": true, + "version": "0.0.0" +} diff --git a/packages/typescript-config/react-library.json b/packages/typescript-config/react-library.json new file mode 100644 index 000000000..13499eb15 --- /dev/null +++ b/packages/typescript-config/react-library.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "./base.json", + "compilerOptions": { + "declaration": true, + "declarationMap": true, + "jsx": "react-jsx", + "noFallthroughCasesInSwitch": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "sourceMap": true + } +} diff --git a/yarn.lock b/yarn.lock index c212ae1f3..7a94033a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6251,6 +6251,7 @@ __metadata: "@radix-ui/react-visually-hidden": "npm:^1.1.0" "@react-aria/ssr": "npm:^3.9.5" "@scandic-hotels/design-system": "workspace:*" + "@scandic-hotels/typescript-config": "workspace:*" "@sentry/nextjs": "npm:^8.41.0" "@svgr/webpack": "npm:^8.1.0" "@t3-oss/env-nextjs": "npm:^0.9.2" @@ -6344,6 +6345,12 @@ __metadata: languageName: unknown linkType: soft +"@scandic-hotels/typescript-config@workspace:*, @scandic-hotels/typescript-config@workspace:packages/typescript-config": + version: 0.0.0-use.local + resolution: "@scandic-hotels/typescript-config@workspace:packages/typescript-config" + languageName: unknown + linkType: soft + "@sentry-internal/browser-utils@npm:8.55.0": version: 8.55.0 resolution: "@sentry-internal/browser-utils@npm:8.55.0"