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
feat(cli): remove unused symbols from codegen #200
Conversation
🌟 This is absolutely fantastic work! I'm thrilled to see this progress and truly appreciate the effort you've put into this plugin. It's important to remember that this is a "nice to have" feature, so it's perfectly okay if it doesn't cover every edge case. Developers using @polkadot-api/client have several options, including:
Now, let me share some thoughts on the specific points you raised:
I can't express enough how grateful I am for your contribution. It's community efforts like yours that drive this project forward. Thank you so much for dedicating your time and skills to help improve our project. 🙏 |
Thanks for the feedback! I have added a commit to handle nested destructuring, as it was rather simple to add. |
This is awesome! Let's get this merged, for sure! We can take it from here, since the most difficult work has already been taken care off. It would be very nice if you could take some time to look into the "Passing tracking variables through function arguments" edge-case 🙏 A tip proposal for this contribution has been submitted (using Thanks again! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
My attempt at solving #198 through method [2a].
I've built a rollup plugin (which is compatible with vite) that given the path to a codegen folder, detects calls to
createClient
using the generated descriptors, traces their usages and removes the unused descriptors from the build.With the current example of
vite/src/main.ts
, the minified code is shaved by ~50kB:Resulting built code without the plugin:
Resulting built code with the plugin:
This plugin is able to trace many common cases:
And it also covers the minimum for source map support. This can be used as an initial version where it covers many of the happy paths. There are still a few tweaks to improve and some challenges to solve:
client.tx.Balances[method]
, or any thing that has to get solved in runtime. Currently it ignores it, but I would suggest bailing out from removing any symbol when detecting such cases.const { tx: { Balances }} = client
. There are other assignment patterns defined in the AST types that need to be handled as well.I've added this as a new package
rollup-plugin-descriptor-treeshake
. I'm happy to change anything you might need, or if you think you want to use a different approach altoghether it's also fine; I just found this feature request interesting :).