diff --git a/jest.config.packages.js b/jest.config.packages.js index a7c6bc1e1..bb3ef91aa 100644 --- a/jest.config.packages.js +++ b/jest.config.packages.js @@ -77,19 +77,23 @@ module.exports = { // ], // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module - // Here we ensure that Jest resolves `@metamask/*` imports to the uncompiled source code for packages that live in this repo. - // NOTE: This must be synchronized with the `paths` option in `tsconfig.base.json`. + // Resolve workspace `@metamask/*` imports to uncompiled source. Paths are + // relative to the monorepo root, not to the consuming package. When a local + // `packages//src` directory does not exist, use the installed package. + // NOTE: This must be synchronized with the `paths` option in `tsconfig.packages.json`. moduleNameMapper: { '^@metamask/json-rpc-engine/v2$': [ '/../json-rpc-engine/src/v2/index.ts', ], '^@metamask/utils/node$': require.resolve('@metamask/utils/node'), - '^@metamask/(.+)$': [ - '/../$1/src', - // Some @metamask/* packages we are referencing aren't in this monorepo, - // so in that case use their published versions + '^@metamask/([^/]+)$': [ + '/../../packages/$1/src', '/../../node_modules/@metamask/$1', ], + '^@metamask/([^/]+)/(.+)$': [ + '/../../packages/$1/src/$2', + '/../../node_modules/@metamask/$1/$2', + ], }, // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader diff --git a/packages/bitcoin-wallet-snap/CHANGELOG.md b/packages/bitcoin-wallet-snap/CHANGELOG.md index 570452d8e..e30fcfa79 100644 --- a/packages/bitcoin-wallet-snap/CHANGELOG.md +++ b/packages/bitcoin-wallet-snap/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Resolve workspace `@metamask/*` TypeScript types from the monorepo root instead of assuming sibling directories ([#167](https://github.com/MetaMask/internal-snaps/pull/167)) + ## [2.0.1] ### Fixed diff --git a/packages/bitcoin-wallet-snap/snap.manifest.json b/packages/bitcoin-wallet-snap/snap.manifest.json index f594f203d..9e59617f5 100644 --- a/packages/bitcoin-wallet-snap/snap.manifest.json +++ b/packages/bitcoin-wallet-snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/internal-snaps.git" }, "source": { - "shasum": "jV649WZbbfbj3FpOMD5U/xDPuRD0t4F+pxCoy08a/O0=", + "shasum": "PpNYFDDadcYp9uuFWMdaURUB5G8vsXrwOETgpFEzUW4=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/bitcoin-wallet-snap/tsconfig.json b/packages/bitcoin-wallet-snap/tsconfig.json index a8a6abb0f..8dfec9077 100644 --- a/packages/bitcoin-wallet-snap/tsconfig.json +++ b/packages/bitcoin-wallet-snap/tsconfig.json @@ -1,19 +1,11 @@ { - "extends": "../../tsconfig.packages.json", + "extends": "../../tsconfig.snaps.json", "compilerOptions": { - "baseUrl": "./", "lib": ["ES2021", "DOM"], - "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, - "module": "ESNext", - "moduleResolution": "bundler", - "types": ["jest"] + "noUncheckedIndexedAccess": true }, "include": ["**/*.ts", "**/*.tsx", "locales/*.json"] } diff --git a/packages/sample-snap/tsconfig.json b/packages/sample-snap/tsconfig.json index 6db6f2381..036b93ac5 100644 --- a/packages/sample-snap/tsconfig.json +++ b/packages/sample-snap/tsconfig.json @@ -1,11 +1,4 @@ { - "extends": "../../tsconfig.packages.json", - "compilerOptions": { - "baseUrl": "./", - "jsx": "react-jsx", - "skipLibCheck": true, - "jsxImportSource": "@metamask/snaps-sdk", - "types": ["jest"] - }, + "extends": "../../tsconfig.snaps.json", "include": ["**/*.ts", "**/*.tsx", "locales/*.json"] } diff --git a/packages/snap-networks-utils/CHANGELOG.md b/packages/snap-networks-utils/CHANGELOG.md index dac68b80a..cfe98ffe3 100644 --- a/packages/snap-networks-utils/CHANGELOG.md +++ b/packages/snap-networks-utils/CHANGELOG.md @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump `@metamask/utils` from `^11.9.0` to `^11.11.9` ([#161](https://github.com/MetaMask/internal-snaps/pull/161)) +### Fixed + +- Assign optional `Logger` `prefix` and `decorators` only when they are provided so `exactOptionalPropertyTypes` consumers can typecheck against workspace source ([#167](https://github.com/MetaMask/internal-snaps/pull/167)) + ## [1.0.0] ### Added diff --git a/packages/snap-networks-utils/src/logger/Logger.ts b/packages/snap-networks-utils/src/logger/Logger.ts index 57230867b..87dce9c41 100644 --- a/packages/snap-networks-utils/src/logger/Logger.ts +++ b/packages/snap-networks-utils/src/logger/Logger.ts @@ -128,8 +128,12 @@ export class Logger { assert(level, LogLevelStruct); this.#level = level; - this.#prefix = prefix; - this.#decorators = decorators; + if (prefix !== undefined) { + this.#prefix = prefix; + } + if (decorators !== undefined) { + this.#decorators = decorators; + } } /** @@ -146,7 +150,9 @@ export class Logger { return new Logger({ level: this.#level, prefix: this.#prefix ? `${this.#prefix} ${prefix}` : prefix, - decorators: this.#decorators, + ...(this.#decorators === undefined + ? {} + : { decorators: this.#decorators }), }); } diff --git a/packages/snap-networks-utils/tsconfig.json b/packages/snap-networks-utils/tsconfig.json index 464677940..081aced0e 100644 --- a/packages/snap-networks-utils/tsconfig.json +++ b/packages/snap-networks-utils/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "../../tsconfig.packages.json", "compilerOptions": { - "baseUrl": "./", "skipLibCheck": true, "types": ["jest"] }, diff --git a/packages/solana-wallet-snap/CHANGELOG.md b/packages/solana-wallet-snap/CHANGELOG.md index ab6dd1dbf..45931b301 100644 --- a/packages/solana-wallet-snap/CHANGELOG.md +++ b/packages/solana-wallet-snap/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Resolve workspace `@metamask/*` TypeScript types from the monorepo root instead of assuming sibling directories ([#167](https://github.com/MetaMask/internal-snaps/pull/167)) - Extract Snap-owned assets domain logic into `SnapAssetsAdapter`; `AssetsService` is a thin facade that delegates metadata, market data, fetch, persist, and account asset reads through the adapter (no Core routing yet). ([#121](https://github.com/MetaMask/internal-snaps/pull/121)) - Align `AssetsService` read API with `snap-networks-utils` / AssetsController shapes by adding `getAccountAssetByID`, `getAccountAssetsByIDs`, `getAccountAssetsByScope`, and `getAccountAssets`, and routing Keyring and Send through them (still Snap-owned storage). ([#120](https://github.com/MetaMask/internal-snaps/pull/120)) diff --git a/packages/solana-wallet-snap/snap.manifest.json b/packages/solana-wallet-snap/snap.manifest.json index 57d2ca99d..9ec50e91d 100644 --- a/packages/solana-wallet-snap/snap.manifest.json +++ b/packages/solana-wallet-snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/internal-snaps.git" }, "source": { - "shasum": "2c2WNzBfLdP/UYJdepbBVpyYrpjzuSob/iobC9JJRLo=", + "shasum": "ogadUr7kiFH3ZTJLvNrBtK3z9EpDy1UGFLA+DSe0XVU=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/solana-wallet-snap/tsconfig.json b/packages/solana-wallet-snap/tsconfig.json index 3eb63f359..7031f2018 100644 --- a/packages/solana-wallet-snap/tsconfig.json +++ b/packages/solana-wallet-snap/tsconfig.json @@ -1,20 +1,19 @@ { - "extends": "../../tsconfig.packages.json", + "extends": "../../tsconfig.snaps.json", "compilerOptions": { "baseUrl": "./", - "jsx": "react-jsx", - "jsxImportSource": "@metamask/snaps-sdk", - "resolveJsonModule": true, + "paths": { + "@metamask/*": ["../../packages/*/src"], + "@metamask/snap-networks-utils/*": [ + "../../packages/snap-networks-utils/src/*" + ] + }, + "lib": ["ES2023", "DOM"], + "target": "es2023", "exactOptionalPropertyTypes": true, "forceConsistentCasingInFileNames": true, "noErrorTruncation": true, - "noUncheckedIndexedAccess": true, - "skipLibCheck": true, - "lib": ["ES2023", "DOM"], - "target": "es2023", - "module": "preserve", - "moduleResolution": "bundler", - "types": ["jest"] + "noUncheckedIndexedAccess": true }, "include": ["**/*.ts", "**/*.tsx", "locales/*.json"] } diff --git a/packages/stellar-wallet-snap/CHANGELOG.md b/packages/stellar-wallet-snap/CHANGELOG.md index e6268ac1d..eb9eb201f 100644 --- a/packages/stellar-wallet-snap/CHANGELOG.md +++ b/packages/stellar-wallet-snap/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Resolve workspace `@metamask/*` TypeScript types from the monorepo root instead of assuming sibling directories ([#167](https://github.com/MetaMask/internal-snaps/pull/167)) - This package was migrated from [snap-stellar-wallet](https://github.com/MetaMask/snap-stellar-wallet). See the source repository for the original [changelog](https://github.com/MetaMask/snap-stellar-wallet/blob/main/packages/snap/CHANGELOG.md) ([#161](https://github.com/MetaMask/internal-snaps/pull/161)) ### Fixed diff --git a/packages/stellar-wallet-snap/tsconfig.json b/packages/stellar-wallet-snap/tsconfig.json index df5a8f6b6..797db4496 100644 --- a/packages/stellar-wallet-snap/tsconfig.json +++ b/packages/stellar-wallet-snap/tsconfig.json @@ -1,19 +1,12 @@ { - "extends": "../../tsconfig.packages.json", + "extends": "../../tsconfig.snaps.json", "compilerOptions": { - "resolveJsonModule": true /* lets us import JSON modules from within TypeScript modules. */, - "jsx": "react-jsx", - "jsxImportSource": "@metamask/snaps-sdk", + "lib": ["ES2023", "DOM"], + "target": "es2023", "exactOptionalPropertyTypes": false, "forceConsistentCasingInFileNames": true, "noErrorTruncation": true, - "noUncheckedIndexedAccess": true, - "skipLibCheck": true, - "lib": ["ES2023", "DOM"], - "target": "es2023", - "module": "preserve", - "moduleResolution": "bundler", - "types": ["jest"] + "noUncheckedIndexedAccess": true }, "include": ["**/*.ts", "**/*.tsx", "locales/*.json"] } diff --git a/packages/tron-wallet-snap/CHANGELOG.md b/packages/tron-wallet-snap/CHANGELOG.md index 733239f5e..678db5766 100644 --- a/packages/tron-wallet-snap/CHANGELOG.md +++ b/packages/tron-wallet-snap/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Resolve workspace `@metamask/*` TypeScript types from the monorepo root instead of assuming sibling directories ([#167](https://github.com/MetaMask/internal-snaps/pull/167)) - Extract shared asset util functions and inject `SnapAssetsAdapter` from `context` into `AssetsService` ([#143](https://github.com/MetaMask/internal-snaps/pull/143)) - Rename `getByKeyringAccountId` to `getAccountAssets` (with essential-asset synthesis) and update keyring callers ([#143](https://github.com/MetaMask/internal-snaps/pull/143)) diff --git a/packages/tron-wallet-snap/snap.manifest.json b/packages/tron-wallet-snap/snap.manifest.json index fe36b7959..317ca5920 100644 --- a/packages/tron-wallet-snap/snap.manifest.json +++ b/packages/tron-wallet-snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/internal-snaps.git" }, "source": { - "shasum": "MbqwOXbHFI83/qWOj9zDSXJizgEt5oQ+QnpHq0g/sls=", + "shasum": "Dgq9UwYX7J/Mo+Ubvm4cwZGPlea3fC/CPtq7jJhReec=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/tron-wallet-snap/tsconfig.json b/packages/tron-wallet-snap/tsconfig.json index df5a8f6b6..797db4496 100644 --- a/packages/tron-wallet-snap/tsconfig.json +++ b/packages/tron-wallet-snap/tsconfig.json @@ -1,19 +1,12 @@ { - "extends": "../../tsconfig.packages.json", + "extends": "../../tsconfig.snaps.json", "compilerOptions": { - "resolveJsonModule": true /* lets us import JSON modules from within TypeScript modules. */, - "jsx": "react-jsx", - "jsxImportSource": "@metamask/snaps-sdk", + "lib": ["ES2023", "DOM"], + "target": "es2023", "exactOptionalPropertyTypes": false, "forceConsistentCasingInFileNames": true, "noErrorTruncation": true, - "noUncheckedIndexedAccess": true, - "skipLibCheck": true, - "lib": ["ES2023", "DOM"], - "target": "es2023", - "module": "preserve", - "moduleResolution": "bundler", - "types": ["jest"] + "noUncheckedIndexedAccess": true }, "include": ["**/*.ts", "**/*.tsx", "locales/*.json"] } diff --git a/scripts/create-package/package-template/tsconfig.json b/scripts/create-package/package-template/tsconfig.json index 025ba2ef7..fabfb3eca 100644 --- a/scripts/create-package/package-template/tsconfig.json +++ b/scripts/create-package/package-template/tsconfig.json @@ -1,8 +1,5 @@ { "extends": "../../tsconfig.packages.json", - "compilerOptions": { - "baseUrl": "./" - }, "references": [], "include": ["../../types", "./src"] } diff --git a/tsconfig.packages.json b/tsconfig.packages.json index a655abc1f..5710af502 100644 --- a/tsconfig.packages.json +++ b/tsconfig.packages.json @@ -5,14 +5,23 @@ "extends": "./tsconfig.base.json", "compilerOptions": { /** - * Here we ensure that TypeScript resolves `@metamask/*` imports to the - * uncompiled source code for packages that live in this repo. + * Resolve `@metamask/*` imports to uncompiled source for packages in this + * repo. Paths are relative to this file (the monorepo root). + * + * A local candidate is used only when `packages//src` exists. + * Published `@metamask/*` dependencies fall through to `node_modules`. + * TypeScript path patterns allow only one `*`, so workspace packages + * with extra entry points need an explicit subpath mapping. * * NOTE: This must be synchronized with the `moduleNameMapper` option in - * `jest.config.packages.js`. + * `jest.config.packages.js`. Consuming configs should not set `baseUrl` + * unless they also re-declare these paths relative to that `baseUrl`. */ "paths": { - "@metamask/*": ["../*/src"] + "@metamask/*": ["./packages/*/src"], + "@metamask/snap-networks-utils/*": [ + "./packages/snap-networks-utils/src/*" + ] } } } diff --git a/tsconfig.snaps.json b/tsconfig.snaps.json new file mode 100644 index 000000000..5019f992c --- /dev/null +++ b/tsconfig.snaps.json @@ -0,0 +1,25 @@ +{ + /** + * Shared TypeScript settings for Snap packages. + * + * Snaps are bundled with `mm-snap` and are not part of the root + * `tsc --build` graph, so `composite` is disabled here. That lets + * workspace `@metamask/*` path mappings resolve to sibling `src/` + * directories without requiring project-reference build artifacts. + * + * Do not set `baseUrl` here. Inherited path mappings are resolved + * against `baseUrl` when it is present, which would break the + * monorepo-root mappings in `tsconfig.packages.json`. + */ + "extends": "./tsconfig.packages.json", + "compilerOptions": { + "composite": false, + "jsx": "react-jsx", + "jsxImportSource": "@metamask/snaps-sdk", + "module": "preserve", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "skipLibCheck": true, + "types": ["jest"] + } +}