fix: resolve workspace MetaMask packages from the monorepo root - #167
Closed
ulissesferreira wants to merge 7 commits into
Closed
fix: resolve workspace MetaMask packages from the monorepo root#167ulissesferreira wants to merge 7 commits into
ulissesferreira wants to merge 7 commits into
Conversation
Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
…ypescript-package-resolution-5832 Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
Map @metamask/* imports to packages/*/src (including subpaths) from the repository root, disable composite for Snap configs so they can consume sibling source, and fall back to node_modules when no local package exists. Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
TypeScript path patterns allow only one star, so keep the root wildcard for package-root imports and add an explicit mapping for @metamask/snap-networks-utils subpaths. Assign optional Logger fields without writing undefined so Snap consumers with exactOptionalPropertyTypes can typecheck against local source. Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
Remove the TypeScript resolution plan and design notes from the branch, document the consumer-facing package changes, and update snap manifest shasums to match the CI build. Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
This was referenced Aug 19, 2026
ulissesferreira
added a commit
that referenced
this pull request
Aug 19, 2026
…demonstrative) Structurally replicates core's incremental repository-wide type-checking setup: tsconfig.packages.lint.json (shared), a tsconfig.lint.json per package (outDir/tsBuildInfoFile -> .tsc-lint-cache, references to workspace deps), a root tsconfig.lint.json referencing all six packages, and a `lint:tsc` script wired into `yarn lint`, exactly matching MetaMask/core/tsconfig.lint.json and MetaMask/core/packages/base-controller/tsconfig.lint.json. This intentionally does NOT touch the existing @metamask/* paths/baseUrl mapping (per #170's original scope). Running `yarn lint:tsc` from a clean state (no packages/*/dist, no .tsbuildinfo/.tsc-lint-cache) currently fails: - ~70 "Cannot find module '@metamask/snap-networks-utils/...'" errors in bitcoin-wallet-snap, solana-wallet-snap, tron-wallet-snap. This is the expected, confirmed result: the reference graph rebuilds each project's OWN .tsc-lint-cache output, but the importing package still resolves the bare specifier via node_modules -> package.json -> the real dist/, which this graph never touches. `references` + `tsc --build` do not remove the need for a paths -> src mapping (#167/#169) -- core's own tsconfig.lint.json files extend each package's regular tsconfig.json specifically to inherit that mapping. - 13 TS6307 "Projects must list all files or use an 'include' pattern" errors, specific to composite/--build mode's stricter accounting of every file entering the program (nested JSON test fixtures, snap.manifest.json) vs plain `tsc --noEmit`. A real migration would need broader `include` patterns per package. - 18 pre-existing, unrelated "Cannot find module '@metamask/superstruct'" errors via a ../snaps-registry path, confirmed byte-for-byte identical on unmodified main with or without any of this branch's changes. Committed as-is, findings documented, to answer "what would full Core parity require" -- not intended to be merged in this state.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Status: working ✅ — verified via
tsc --noEmit,tsc --traceResolution, full builds, and a realsnaps-jestrun.pathsentry intsconfig.packages.jsonto resolve@metamask/*relative to the monorepo root (./packages/*/src) instead of relying on an unset/inheritedbaseUrl, which is what made the previous../*/srcmapping fragile (only correct if the consumer happened to be a sibling directory).srccandidate is used only when it exists on disk; otherwise resolution falls through to the installednode_modulespackage — so importing a published@metamask/*package not in this repo is unaffected.@metamask/snap-networks-utils/*as an explicit subpath mapping (TypeScriptpathspatterns only allow one*), covering extra entry points like/logger.tsconfig.snaps.jsonas a shared config for snap packages, withcomposite: falseand nobaseUrl, so they can typecheck sibling workspace source without project-reference build artifacts.baseUrlunless they also re-declare the paths mapping relative to it (solana-wallet-snapdoes this to keepbaseUrl-relativesrc/...imports).jest.config.packages.js'smoduleNameMapperto the same local-source-then-installed-package rule.Loggernow assigns optionalprefix/decoratorsonly when provided, sosolana-wallet-snap(exactOptionalPropertyTypes) can typecheck against workspace source.module/moduleResolutionforbitcoin-wallet-snap/sample-snap) that turned out to be silent behavior changes rather than pure dedup.Pros and Cons
Pros:
@metamask/*mapping lives once in the sharedtsconfig.packages.json, so adding a new workspace package requires no per-package config change.Cons:
baseUrl-relative import ergonomics (e.g.from 'src/entities') unless they opt back in and re-declare paths anyway — which is exactly what fix: restate workspace @metamask/* paths per package with local baseUrl #169 does, partially undermining the "shared config" simplicity.module/moduleResolutionoverrides forbitcoin-wallet-snap/sample-snap) — a reminder that shared-config consolidation has hidden blast radius.tsconfig.snaps.jsonlayer, which is one more file in the inheritance chain to reason about.Clean-install verification
Re-verified from a genuinely fresh worktree — no
node_modules, nopackages/*/distanywhere — with onlyyarn installrun (noyarn build):yarn lint: passes (exit 0).lint:eslintitself runsbuild:only-cleanfirst, so it never depended on a prebuiltdist/.tsc --noEmitper package (bypassing the roottypecheckscript's own pre-build step, to test resolution with zero builds anywhere): bitcoin-wallet-snap, sample-snap, snap-networks-utils, solana-wallet-snap, tron-wallet-snap all pass with 0 errors, correctly resolving@metamask/*(including thesnap-networks-utils/*subpath) straight fromsrc/via thenode_modulessymlink.stellar-wallet-snapcouldn't run viayarn workspaces foreach ... exec tsc(command not found: tsc) — pre-existing gap: that package'spackage.jsonhas notypescriptdevDependency, unrelated to this PR. Runningtscdirectly against it passes with 0 errors.Confirms the fix holds in the worst case (fresh clone, install-only, zero builds), not just when a stale
dist/happens to already exist.References
baseUrlergonomics) and fix: add TypeScript project references, mirroring MetaMask/core #170 (references-only, does not fix resolution)Checklist