-
Notifications
You must be signed in to change notification settings - Fork 846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[experimental] Create a sham of legacy @solana/web3.js
that can be used as a drop-in replacement for most use cases
#1825
Labels
enhancement
New feature or request
Comments
This was referenced Nov 17, 2023
steveluscher
added a commit
that referenced
this issue
Nov 20, 2023
# Preamble Imagine that you depend on a module that itself depends on the legacy `@solana/web3.js`. This makes it difficult for you to remove the legacy library from your project. The chances are, though, that module only needs a _fraction_ of what web3.js provides. The goal of the sham – of which this PR is the first – is to provide drop-in replacements for just the things that a set list of known dependencies require. You should be able to hot-swap the sham in via npm `overrides` or yarn `resolutions` and thereby drop the legacy web3.js from your bundle. # Summary This PR introduces an interface compatible(-ish) `PublicKey` that you can use as a drop-in replacement for the one in `@solana/web3.js@1` # Test Plan ``` cd packages/library-legacy-sham/ pnpm test:unit:browser pnpm test:unit:node ``` See later diffs for a functional test plan where we actually drop the sham in to an actual application and see the results. Addresses #1825.
steveluscher
added a commit
that referenced
this issue
Nov 20, 2023
steveluscher
added a commit
that referenced
this issue
Nov 20, 2023
# Preamble Imagine that you depend on a module that itself depends on the legacy `@solana/web3.js`. This makes it difficult for you to remove the legacy library from your project. The chances are, though, that module only needs a _fraction_ of what web3.js provides. The goal of the sham – of which this PR is the first – is to provide drop-in replacements for just the things that a set list of known dependencies require. You should be able to hot-swap the sham in via npm `overrides` or yarn `resolutions` and thereby drop the legacy web3.js from your bundle. # Summary This PR introduces an interface compatible(-ish) `Keypair` that you can use as a drop-in replacement for the one in `@solana/web3.js@1` # Test Plan ``` cd packages/library-legacy-sham/ pnpm test:unit:browser pnpm test:unit:node ``` See later diffs for a functional test plan where we actually drop the sham in to an actual application and see the results. Addresses #1825.
steveluscher
added a commit
that referenced
this issue
Nov 20, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Motivation
You're an application that depends on a bunch of packages (
mpl-token-metadata
,@solana/wallet-adapter-react
, etc.) and those packages themselves depend on@solana/web3.js
(the legacy version).Each of those packages use a tiny slice of web3.js.
@solana/wallet-adapter-react
for instance only does things likenew PublicKey()
,new Connection()
, andpublicKey.toBytes()
.We could create a drop-in replacement for
@solana/web3.js
that only did the things that typical applications exercise; a sham, if you will.This package would offer API compatible-ish versions of
PublicKey
,Connection
et al, that used the new web3.js under the hood, or nothing at all.Not a single line of your application should have to change and the legacy @solana/web3.js would just disappear from your bundle.
Example use case
#yolo replace all your legacy imports with that.
pnpm (package.json)
Using
overrides
.npm (package.json)
Using
overrides
.Yarn (package.json)
Using
resolutions
.Details
Here's an example of how you might implement a sham
PublicKey
.Playground link.
The text was updated successfully, but these errors were encountered: