Remove the stellar-sdk npm aliases and deduplicate stellar-sdk copies
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- typescript, webpack
- Domain
- build-system, tooling
Research direction
Start by comparing the dependency entries in extension/package.json, @shared/constants/package.json, @shared/api/package.json, and @shared/helpers/package.json, then inspect getSdk() in @shared/helpers/stellar.ts and the lavamoat path at extension/package.json:125-126. Use webpack-bundle-analyzer to measure the bundle and run yarn install, yarn tsc, yarn lint, yarn test, yarn build, and the e2e suite. Done means fewer SDK copies with key-manager, swap, signing, and account workflows still passing.
Written by the indexing model from the issue text.
Description
Summary
The dependency tree contains four copies of @stellar/stellar-sdk. Two of them exist
because we install the same package twice under npm aliases. The other two come from
third-party packages that pin old SDK versions. All four are reachable from the built
extension.
This costs bundle size, install size, and supply-chain surface. This issue proposes
removing the aliases and reducing the number of copies.
Current state
Package name in node_modules |
Version | Comes from | Size on disk |
|---|---|---|---|
stellar-sdk (alias) |
16.0.0-rc.1 | our code, ~100 files | 33M |
stellar-sdk-next (alias) |
16.0.0-rc.1 | our code, 5 files | 33M |
@stellar/stellar-sdk |
15.0.1 | @stellar/[email protected] (background / key manager) |
17M |
@stellar/stellar-sdk (nested) |
11.3.0 | [email protected] (popup swap) |
3.8M |
The aliases are declared in four workspaces:
extension/package.json:87, @shared/constants/package.json:6,
@shared/api/package.json:12, @shared/helpers/package.json:7.
Note that Yarn already treats the two aliases as one package at resolution time:
yarn.lock:22301
"stellar-sdk-next@npm:@stellar/[email protected], stellar-sdk@npm:@stellar/[email protected]":
One locator, two descriptors. The duplication happens only at link time, because the
two package names are different, so they are installed into two directories. Webpack
then builds two separate module graphs from them. Yarn cannot merge this; only removing
the alias can.
Why the alias exists today
stellar-sdk-next was added to stage a protocol upgrade. The idea was to point -next
at a release candidate while stellar-sdk stayed on the stable release, then select one
per network at runtime with getSdk(networkPassphrase) (@shared/helpers/stellar.ts:22).
That is not what happens now:
- Both aliases are pinned to the same version. We always bump them together.
isNextSdkis[""].includes(networkPassphrase), which is always false. The-next
branch is dead code.
So the second copy currently gives us nothing.
Proposed change
- Replace
"stellar-sdk": "npm:@stellar/stellar-sdk@<version>"with
"@stellar/stellar-sdk": "<version>"in the four workspacepackage.jsonfiles. - Update the imports. About 100 files import
stellar-sdk. This is a mechanical
find-and-replace. - Remove
stellar-sdk-nextand the 5 imports that use it. KeepgetSdk()as a
one-line function that always returns the single SDK, so the call sites do not
change in this PR. - Reduce the third-party copies:
@stellar/[email protected]pins SDK15.0.1. Check for a newer
release built against SDK 16. If there is none, open an upstream request to make
@stellar/stellar-sdka peer dependency with a range, not an exact pin.[email protected]pins^11.3.0. Check whether a newer release exists.- A Yarn
resolutionsentry can force a single version, but this touches the key
manager, which is on the signing path. Do not do this without testing account
import, account recovery, and hardware wallet signing.
- Measure the bundle before and after with
webpack-bundle-analyzer, and record the
numbers in the PR.
Trade-off to decide
Removing stellar-sdk-next also removes the mechanism we would use for the next
protocol upgrade. Two options:
- (a) Remove it now, add it back only during a transition. Add the alias when we
need to run an RC beside the stable SDK, then delete it after activation. - (b) Keep it. Accept a permanent duplicate copy for a mechanism that is used for a
few weeks per protocol release.
Recommendation: (a). The current setup pays the cost all the time.
Verification
yarn installand confirmnode_moduleshas fewer@stellar/stellar-sdkcopies.yarn tsc,yarn lint,yarn testall pass.yarn build(webpack) succeeds, and lavamoat /allowScriptsstill resolves the
stellar-sdk>stellar-base>sodium-nativepath, which is keyed by package name
(extension/package.json:125-126). This path changes when the alias is removed.- Manual check of the key manager: create account, import account, recover account.
- Manual check of a swap, which uses
soroswap-router-sdk. - e2e suite passes.
Out of scope
Runtime behaviour changes. This is a packaging change only.
- Dominant language
- TypeScript
- Stars
- 122
- Forks
- 62
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 41
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stellar/freighter
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
Write the banner publishing guidePossibly taken @aristidesstaffieri claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
stellar/freighter#3152 · 1 assignee ·
Maintainers usually reply within 2 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 2 days
-
Dont call blockaid on empty token listMay be free again A pull request for this issue was closed without being merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 2 days
-
follow-up
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
All issues in stellar/freighter
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zabuton-app/meguri#875 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
iruzen-dono/workless#117 ·
Maintainers usually reply within 1 day
-
area:api area:web wave wave:trivial
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
vetro-protocol/vetro-monorepo#1321 ·
Maintainers usually reply within 1 day