Skip to content
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

fix: support tree-shakable models/utils #285

Merged
merged 3 commits into from
Apr 14, 2021

Conversation

magicmatatjahu
Copy link
Member

@magicmatatjahu magicmatatjahu commented Apr 12, 2021

Description

Working on asyncapi/shape-up-process#88 I have to remove unnecessary dependencies as much as possible while bundling. I wanna create two bundles for browser:

  • with parser onboard
  • and without (for hydration)

In the second case I have to remove all parser unnecessary stuff, but unfornatelly bundler cannot properly tree-shakable unnecessary utils from models - in component we use directly two models AsyncAPIDocument and Schemas to support parser-js API. Problem is with this file - bundler treats cjs module as JS object, not like esm module so includes everything from "module". This PR moves every util related to models to separate file.

Examples with weight:

  • component with parser - about 800kb
  • component without parser but without this PR - about 445kb
  • component without parser and with this PR (tested locally) - about 170kb

Component without parser after my changes has also included Buffer due to this line https://github.com/asyncapi/parser-js/blob/master/lib/models/message.js#L16 Buffer works only on NodeJS and bundler tried to resolve it by adding about 64kb additional code related only to Buffer polyfill... I will try to handle the Buffer later in this cycle, but I prefer to leave it and go with completing more important tasks. Removing almost 650kb is a big deal anyway.

Related issue(s)
Part of asyncapi/shape-up-process#88
Part of asyncapi/html-template#166

@derberg
Copy link
Member

derberg commented Apr 14, 2021

shouldn't model utils go to models dir then?

were there any change in the logic of utils once you moved them, hard to spot when there is a change in code location. Hilfe!

@magicmatatjahu
Copy link
Member Author

@derberg I thought about that, but models-utils are used also in mixins, but this is not a problem to move logic to models/utils.js file.

were there any change in the logic of utils once you moved them, hard to spot when there is a change in code location. Hilfe!

Nope, only moved utils to models-utils and fixing imports in files to appropriate.

Thanks for review!

@derberg
Copy link
Member

derberg commented Apr 14, 2021

then do models/utils.js and mixins/utils.js ?

@magicmatatjahu
Copy link
Member Author

@derberg Ok, I moved to models/utils.js file.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

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

lgtm

@magicmatatjahu
Copy link
Member Author

Thanks!

@magicmatatjahu magicmatatjahu merged commit 059eaa2 into asyncapi:master Apr 14, 2021
@magicmatatjahu magicmatatjahu deleted the tree-shakable-models branch April 14, 2021 08:40
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 1.4.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants