Skip to content

feat(snap-networks-utils): enable bundling .svgs into networks utils - #423

Merged
Julink-eth merged 4 commits into
mainfrom
feat/snap-networks-utils-svg-imports
Oct 8, 2026
Merged

Julink-eth merged 4 commits into
mainfrom
feat/snap-networks-utils-svg-imports

Conversation

@Julink-eth

Copy link
Copy Markdown
Contributor

Explanation

@metamask/snap-networks-utils could not import .svg files the way the snaps do (import icon from './icon.svg'), because unlike mm-snap-built snaps, the library build did nothing with them. This forced the shared Asset fallback icon into an inline QUESTION_MARK_SVG string (#418).
This PR makes .svg imports work in the library:

  • build and build:all now chain a new build:assets script that copies src/**/*.svg into dist/ as-is. ts-bridge keeps the imports in its output, and mm-snap's webpack config already turns .svg imports into their file contents, so a snap bundling the library inlines the markup exactly like its own SVGs. (Verified end to end with a temporary .svg: the library build copies it, the library tests see the real markup, and the Stellar bundle contains the inlined SVG.)
  • Library Jest tests get the real markup too, via jest.svg-transformer.js moved to the repo root from Solana, which previously had the only copy. Solana now points at the shared file; its behavior is unchanged because its moduleNameMapper stub already takes precedence over the transform.
  • yarn.config.cjs required library build/build:all scripts to match the ts-bridge command exactly, rejecting the chained copy step. The constraint now requires the script to start with the ts-bridge command, reusing the existing expectWorkspaceScriptStartsWith helper that snaps already follow, so other commands may be chained after it.
    One caveat, documented in the README and changelog: the published package now requires a bundler that loads .svg files as source (e.g. mm-snap), since plain Node would fail to resolve the import. All current consumers are snaps, which is fine.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@Julink-eth
Julink-eth requested review from a team as code owners October 7, 2026 11:42
@sonarqubecloud

sonarqubecloud Bot commented Oct 8, 2026

Copy link
Copy Markdown

@mikesposito mikesposito left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references && yarn build:assets",
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean && yarn build:assets",
"build:assets": "rsync -a --prune-empty-dirs --include='*/' --include='*.svg' --exclude='*' src/ dist/",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we may have to come back at this at some point, as rsync does not work on Windows

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it only works on IOS/Ubuntu it's good for now agreed.

@Julink-eth
Julink-eth added this pull request to the merge queue Oct 8, 2026
Merged via the queue into main with commit 189be72 Oct 8, 2026
57 of 58 checks passed
@Julink-eth
Julink-eth deleted the feat/snap-networks-utils-svg-imports branch October 8, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants