diff --git a/AGENTS.md b/AGENTS.md index ce98b4a70..2162b971c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -48,7 +48,10 @@ 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.libs.build.json` defines shared declaration build settings for library 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`. 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..18f6e935a 100644 --- a/packages/snap-networks-utils/tsconfig.build.json +++ b/packages/snap-networks-utils/tsconfig.build.json @@ -1,18 +1,12 @@ { - "extends": "./tsconfig.json", + "extends": "../../tsconfig.packages.libs.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 `tsconfig.json`, for builds, we only include the source code. + */ + "include": ["./src"] } diff --git a/packages/snap-networks-utils/tsconfig.json b/packages/snap-networks-utils/tsconfig.json index b0dc5d7d5..6f6b4541a 100644 --- a/packages/snap-networks-utils/tsconfig.json +++ b/packages/snap-networks-utils/tsconfig.json @@ -1,9 +1,6 @@ { "extends": "../../tsconfig.packages.json", "compilerOptions": { - "baseUrl": "./", - "skipLibCheck": true, - "types": ["jest"] - }, - "include": ["../../types", "./src"] + "baseUrl": "./" + } } 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..a4f086630 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.libs.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..6f6b4541a 100644 --- a/scripts/create-package/package-template/tsconfig.json +++ b/scripts/create-package/package-template/tsconfig.json @@ -2,7 +2,5 @@ "extends": "../../tsconfig.packages.json", "compilerOptions": { "baseUrl": "./" - }, - "references": [], - "include": ["../../types", "./src"] + } } diff --git a/tsconfig.base.json b/tsconfig.base.json index d38882705..af0dfe8c2 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.libs.json` - INEXISTANT, it would be the same as `tsconfig.packages.json`. + * `tsconfig.packages.libs.build.json` - Configurations for `ts-bridge`'s emission of declarations. + * + * `tsconfig.packages.snaps.json` - Snap specific configurations. + * `tsconfig.packages.snaps.build.json` - INEXISTANT, `mm-snap` already handles everything. */ "compilerOptions": { "esModuleInterop": true, diff --git a/tsconfig.json b/tsconfig.json index d375ac26d..724f194ed 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": { @@ -15,6 +15,5 @@ "skipLibCheck": true }, "files": [], - "include": ["./docs", "./tests", "./scripts"], - "exclude": ["**/node_modules"] + "include": ["./docs", "./tests", "./scripts"] } diff --git a/tsconfig.packages.json b/tsconfig.packages.json index 9600309db..df1e99669 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,15 @@ "paths": { "@metamask/*": ["../*/src"] }, - "skipLibCheck": true - } + "skipLibCheck": true, + "types": ["jest"] + }, + /** + * Keep build and test-coverage artifacts out of every package's check program. + * + * NOTE: `include`/`exclude` paths are resolved relative to the config file that declares + * them, so these must be root-relative globs rather than `./dist`-style paths. Also note + * that a child configuration defining its own `exclude` replaces this one entirely. + */ + "exclude": ["**/dist", "**/coverage"] } diff --git a/tsconfig.packages.libs.build.json b/tsconfig.packages.libs.build.json new file mode 100644 index 000000000..47be60037 --- /dev/null +++ b/tsconfig.packages.libs.build.json @@ -0,0 +1,19 @@ +{ + /** + * Shared settings for library packages, used by `tsc` to emit declarations. + * + * Library 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"] +} 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" + } +}