From a754be96c13ce95d75e32f378a6b5824dab982ae Mon Sep 17 00:00:00 2001 From: Ulisses Ferreira Date: Wed, 2 Sep 2026 17:16:26 +0100 Subject: [PATCH] chore: reorganize `tsconfig` files for clarity --- AGENTS.md | 7 +++-- packages/bitcoin-wallet-snap/tsconfig.json | 25 +++--------------- packages/sample-snap/tsconfig.json | 10 +++---- .../snap-networks-utils/tsconfig.build.json | 17 +++++------- packages/snap-networks-utils/tsconfig.json | 10 ++++--- packages/solana-wallet-snap/tsconfig.json | 25 +++--------------- packages/stellar-wallet-snap/tsconfig.json | 25 +++--------------- packages/tron-wallet-snap/tsconfig.json | 26 +++---------------- .../package-template/tsconfig.build.json | 5 ++-- .../package-template/tsconfig.json | 5 ++-- tsconfig.base.json | 12 ++++++++- tsconfig.json | 2 +- tsconfig.packages.json | 5 ++-- tsconfig.packages.non-snaps.build.json | 20 ++++++++++++++ tsconfig.packages.snaps.json | 20 ++++++++++++++ 15 files changed, 91 insertions(+), 123 deletions(-) create mode 100644 tsconfig.packages.non-snaps.build.json create mode 100644 tsconfig.packages.snaps.json diff --git a/AGENTS.md b/AGENTS.md index ce98b4a70..d3693e6e1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -48,12 +48,15 @@ The monorepo uses a hierarchical configuration approach for different tools. For - `tsconfig.base.json` defines shared compiler defaults for all other config files. - `tsconfig.json` defines TypeScript settings for repository scripts and editor features. -- `tsconfig.packages.json` defines shared source, editor, and type-checking settings for all packages. +- `tsconfig.packages.json` defines shared TypeScript settings for all packages. +- Packages are either Snaps or non-Snaps: + - `tsconfig.packages.snaps.json` defines shared TypeScript settings for all Snap packages. + - `tsconfig.packages.non-snaps.build.json` defines shared declaration build settings for non-Snap packages, used by `ts-bridge`. - `tsconfig.scripts.json` defines shared TypeScript settings for directories in `scripts/`. - The root `lint:tsc` script checks repository scripts with `tsconfig.json`, then checks each workspace package configuration directly. It does not build Snap bundles with `tsc`. - `packages/**/tsconfig.json` (and `scripts/create-package/package-template/tsconfig.json`) defines TypeScript settings for each package that are meant to be used by code editors and type checking. -- Library packages and the package template also have `tsconfig.build.json` files for `ts-bridge` declaration builds. Snap packages do not have build configs because `mm-snap` builds their bundles. +- Non-Snap packages and the package template also have `tsconfig.build.json` files for `ts-bridge` declaration builds. Snap packages do not have build configs because `mm-snap` builds their bundles. - `scripts/create-package/tsconfig.json` customizes TypeScript settings for the `create-package` tool. #### Jest diff --git a/packages/bitcoin-wallet-snap/tsconfig.json b/packages/bitcoin-wallet-snap/tsconfig.json index e060c47ac..490c6090d 100644 --- a/packages/bitcoin-wallet-snap/tsconfig.json +++ b/packages/bitcoin-wallet-snap/tsconfig.json @@ -1,26 +1,7 @@ { - "extends": "../../tsconfig.packages.json", + "extends": "../../tsconfig.packages.snaps.json", "compilerOptions": { - "baseUrl": "./", - "jsx": "react-jsx", - "jsxImportSource": "@metamask/snaps-sdk", - "resolveJsonModule": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "noErrorTruncation": true, - "noUncheckedIndexedAccess": true, - "skipLibCheck": true, - "lib": ["ES2023", "DOM"], - "target": "es2023", - "module": "preserve", - "moduleResolution": "bundler", - "types": ["jest"] + "baseUrl": "./" }, - "include": [ - "**/*.ts", - "**/*.tsx", - "locales/*.json", - "snap.manifest.json", - "src/**/*.json" - ] + "include": ["**/*.ts", "**/*.tsx", "**/*.json"] } diff --git a/packages/sample-snap/tsconfig.json b/packages/sample-snap/tsconfig.json index 6db6f2381..490c6090d 100644 --- a/packages/sample-snap/tsconfig.json +++ b/packages/sample-snap/tsconfig.json @@ -1,11 +1,7 @@ { - "extends": "../../tsconfig.packages.json", + "extends": "../../tsconfig.packages.snaps.json", "compilerOptions": { - "baseUrl": "./", - "jsx": "react-jsx", - "skipLibCheck": true, - "jsxImportSource": "@metamask/snaps-sdk", - "types": ["jest"] + "baseUrl": "./" }, - "include": ["**/*.ts", "**/*.tsx", "locales/*.json"] + "include": ["**/*.ts", "**/*.tsx", "**/*.json"] } diff --git a/packages/snap-networks-utils/tsconfig.build.json b/packages/snap-networks-utils/tsconfig.build.json index f010fa5ac..6cc6351fa 100644 --- a/packages/snap-networks-utils/tsconfig.build.json +++ b/packages/snap-networks-utils/tsconfig.build.json @@ -1,18 +1,13 @@ { - "extends": "./tsconfig.json", + "extends": "../../tsconfig.packages.non-snaps.build.json", "compilerOptions": { "baseUrl": "./", - "composite": true, - "declaration": true, - "declarationMap": true, - "emitDeclarationOnly": true, - "inlineSources": true, - "noEmit": false, - "sourceMap": true, "outDir": "./dist", "rootDir": "./src" }, - "references": [], - "include": ["../../types", "./src"], - "exclude": ["**/*.test.ts", "**/tests", "**/jest.config.ts"] + /** + * Unlike Snap's which include all TypeScript, TSX and JSON files, here we want + * to mirror what gets built. + */ + "include": ["./src"] } diff --git a/packages/snap-networks-utils/tsconfig.json b/packages/snap-networks-utils/tsconfig.json index b0dc5d7d5..bc7c31680 100644 --- a/packages/snap-networks-utils/tsconfig.json +++ b/packages/snap-networks-utils/tsconfig.json @@ -1,9 +1,11 @@ { "extends": "../../tsconfig.packages.json", "compilerOptions": { - "baseUrl": "./", - "skipLibCheck": true, - "types": ["jest"] + "baseUrl": "./" }, - "include": ["../../types", "./src"] + /** + * Unlike Snap's which include all TypeScript, TSX and JSON files, here we want + * to mirror what gets built. + */ + "include": ["./src"] } diff --git a/packages/solana-wallet-snap/tsconfig.json b/packages/solana-wallet-snap/tsconfig.json index e060c47ac..490c6090d 100644 --- a/packages/solana-wallet-snap/tsconfig.json +++ b/packages/solana-wallet-snap/tsconfig.json @@ -1,26 +1,7 @@ { - "extends": "../../tsconfig.packages.json", + "extends": "../../tsconfig.packages.snaps.json", "compilerOptions": { - "baseUrl": "./", - "jsx": "react-jsx", - "jsxImportSource": "@metamask/snaps-sdk", - "resolveJsonModule": true, - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "noErrorTruncation": true, - "noUncheckedIndexedAccess": true, - "skipLibCheck": true, - "lib": ["ES2023", "DOM"], - "target": "es2023", - "module": "preserve", - "moduleResolution": "bundler", - "types": ["jest"] + "baseUrl": "./" }, - "include": [ - "**/*.ts", - "**/*.tsx", - "locales/*.json", - "snap.manifest.json", - "src/**/*.json" - ] + "include": ["**/*.ts", "**/*.tsx", "**/*.json"] } diff --git a/packages/stellar-wallet-snap/tsconfig.json b/packages/stellar-wallet-snap/tsconfig.json index 69148854d..490c6090d 100644 --- a/packages/stellar-wallet-snap/tsconfig.json +++ b/packages/stellar-wallet-snap/tsconfig.json @@ -1,26 +1,7 @@ { - "extends": "../../tsconfig.packages.json", + "extends": "../../tsconfig.packages.snaps.json", "compilerOptions": { - "baseUrl": "./", - "resolveJsonModule": true /* lets us import JSON modules from within TypeScript modules. */, - "jsx": "react-jsx", - "jsxImportSource": "@metamask/snaps-sdk", - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "noErrorTruncation": true, - "noUncheckedIndexedAccess": true, - "skipLibCheck": true, - "lib": ["ES2023", "DOM"], - "target": "es2023", - "module": "preserve", - "moduleResolution": "bundler", - "types": ["jest"] + "baseUrl": "./" }, - "include": [ - "**/*.ts", - "**/*.tsx", - "locales/*.json", - "snap.manifest.json", - "tokenlists/*.json" - ] + "include": ["**/*.ts", "**/*.tsx", "**/*.json"] } diff --git a/packages/tron-wallet-snap/tsconfig.json b/packages/tron-wallet-snap/tsconfig.json index 1436fad0e..490c6090d 100644 --- a/packages/tron-wallet-snap/tsconfig.json +++ b/packages/tron-wallet-snap/tsconfig.json @@ -1,27 +1,7 @@ { - "extends": "../../tsconfig.packages.json", + "extends": "../../tsconfig.packages.snaps.json", "compilerOptions": { - "baseUrl": "./", - "resolveJsonModule": true /* lets us import JSON modules from within TypeScript modules. */, - "jsx": "react-jsx", - "jsxImportSource": "@metamask/snaps-sdk", - "exactOptionalPropertyTypes": false, - "forceConsistentCasingInFileNames": true, - "noErrorTruncation": true, - "noUncheckedIndexedAccess": true, - "skipLibCheck": true, - "lib": ["ES2023", "DOM"], - "target": "es2023", - "module": "preserve", - "moduleResolution": "bundler", - "types": ["jest"] + "baseUrl": "./" }, - "include": [ - "**/*.ts", - "**/*.tsx", - "locales/*.json", - "messages.json", - "snap.manifest.json", - "src/**/*.json" - ] + "include": ["**/*.ts", "**/*.tsx", "**/*.json"] } diff --git a/scripts/create-package/package-template/tsconfig.build.json b/scripts/create-package/package-template/tsconfig.build.json index 02a0eea03..7d5f92e04 100644 --- a/scripts/create-package/package-template/tsconfig.build.json +++ b/scripts/create-package/package-template/tsconfig.build.json @@ -1,10 +1,9 @@ { - "extends": "../../tsconfig.packages.build.json", + "extends": "../../../tsconfig.packages.non-snaps.build.json", "compilerOptions": { "baseUrl": "./", "outDir": "./dist", "rootDir": "./src" }, - "references": [], - "include": ["../../types", "./src"] + "include": ["./src"] } diff --git a/scripts/create-package/package-template/tsconfig.json b/scripts/create-package/package-template/tsconfig.json index 025ba2ef7..e0810056e 100644 --- a/scripts/create-package/package-template/tsconfig.json +++ b/scripts/create-package/package-template/tsconfig.json @@ -1,8 +1,7 @@ { - "extends": "../../tsconfig.packages.json", + "extends": "../../../tsconfig.packages.json", "compilerOptions": { "baseUrl": "./" }, - "references": [], - "include": ["../../types", "./src"] + "include": ["./src"] } diff --git a/tsconfig.base.json b/tsconfig.base.json index d38882705..e65286acf 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,6 +1,16 @@ { /** - * This configuration is extended by all other TypeScript configurations. + * Configuration extended by all other TypeScript configurations, whose purpose is described here: + * + * `tsconfig.json` - Repository root configuration. + * `tsconfig.scripts.json` - Used for the `scripts/` directory. + * `tsconfig.packages.json` - Shared by all `packages/`, whether Snaps or not. + * + * `tsconfig.packages.non-snaps.json` - Inexistant because it's would be the same as `tsconfig.packages.json`. + * `tsconfig.packages.non-snaps.build.json` - Configurations for `ts-bridge`'s emission of declarations. + * + * `tsconfig.packages.snaps.json` - Snap specific configurations. + * `tsconfig.packages.snaps.build.json` - Not needed because `mm-snap` already handles everything. */ "compilerOptions": { "esModuleInterop": true, diff --git a/tsconfig.json b/tsconfig.json index d375ac26d..5412cdc26 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { /** - * Repository-level configuration used by the `lint` script and editors such as VSCode. + * Repository-level configuration used by the `lint` script and editors. */ "extends": "./tsconfig.base.json", "compilerOptions": { diff --git a/tsconfig.packages.json b/tsconfig.packages.json index 9600309db..aa884c627 100644 --- a/tsconfig.packages.json +++ b/tsconfig.packages.json @@ -1,6 +1,6 @@ { /** - * Shared settings for package source, editor, and type-checking configurations. + * Shared settings for all packages, whether a Snap or not. */ "extends": "./tsconfig.base.json", "compilerOptions": { @@ -18,6 +18,7 @@ "paths": { "@metamask/*": ["../*/src"] }, - "skipLibCheck": true + "skipLibCheck": true, + "types": ["jest"] } } diff --git a/tsconfig.packages.non-snaps.build.json b/tsconfig.packages.non-snaps.build.json new file mode 100644 index 000000000..b75b529bb --- /dev/null +++ b/tsconfig.packages.non-snaps.build.json @@ -0,0 +1,20 @@ +{ + /** + * Shared settings for non-Snap package build configurations, used by `ts-bridge` to emit + * declarations. + * + * Non-Snap packages extending this configuration must still define their own `outDir`, + * `rootDir`, and `include`, since these are resolved relative to each package. + */ + "extends": "./tsconfig.packages.json", + "compilerOptions": { + "composite": true, + "declaration": true, + "declarationMap": true, + "emitDeclarationOnly": true, + "inlineSources": true, + "noEmit": false, + "sourceMap": true + }, + "exclude": ["**/*.test.ts", "**/tests", "**/jest.config.ts"] +} diff --git a/tsconfig.packages.snaps.json b/tsconfig.packages.snaps.json new file mode 100644 index 000000000..49fbf5ea8 --- /dev/null +++ b/tsconfig.packages.snaps.json @@ -0,0 +1,20 @@ +{ + /** + * Shared settings for Snap packages, i.e. packages whose bundles are built by `mm-snap` + * rather than by `tsc` or `ts-bridge`. + * + * Snap packages must still set `baseUrl` to their own directory, so that the `paths` option + * resolves correctly. + */ + "extends": "./tsconfig.packages.json", + "compilerOptions": { + "exactOptionalPropertyTypes": false, + "jsx": "react-jsx", + "jsxImportSource": "@metamask/snaps-sdk", + "lib": ["ES2023", "DOM"], + "module": "preserve", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "target": "ES2023" + } +}