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

[multi] Reduce dependencies in main and preload layers #3509

Merged
merged 11 commits into from
Jun 21, 2021

Conversation

matheusd
Copy link
Member

This reduces the dependencies to third party packages in the main electron and preload script layers of the application.

This improves the codebase by relying less on third party code, slightly reduces compilation time and improves security by reducing the attack surface of a possible supply chain attack.

The main changes introduced by this PR are:

  • Add a script that can generate graphs for the dependency tree of each layer of the application
    • This was added as the first commit so that dependencies before and after the refactor can be checked by doing a node ./scripts/generateDepGraphs.js
  • Remove the now unneeded (due to updated electron version) intl-relativetimeformat polyfill
  • Reduce (but not yet eliminate) dependency on lodash by performing specific imports and functions
  • Remove the need to import the wallet by moving the single outstanding dependency directly into the main_dev package
  • Remove the dependency to the websocket' (ws) library by using the jsonrpc` api on dcrd in post mode (instead of websocket mode)
  • Switch from using the fs-extra package to the node standard fs (we don't use any of the additional features offered by fs-extra)
  • Run yarn-deduplicate

The script added to generate graphs of the app's dependencies generates a link to npmgraphs.js.org which can be used to compare transitive dependencies as specified in the npm registry:

Before this PR

After this PR:

Note that the dependency to electron (and electron-devtools-installer in the main layer) are ignored in the graphs due to them being implicitly required, and their absence making the graphs slightly easier to read.

After this PR, the main electron layer only has two top-level dependencies which themselves have a large number of transitive deps: winston and electron-store. Given those two are going to demand slightly more work to replace, I've left them to be refactored in future PRs.

This is useful to track dependencies in the project.
This isn't needed anymore due to being included natively in recent electron
versions.
This removes the dependency to react in the main process.
This reworks some functions to remove the need to import lodash in the main
process stack.
This removes the need to import the wallet pkg as a dependency in the main
process code, which removes a lot of transitive dependencies.

It also fixes the usage and version CLI args which were broken by previous
commits.
This allows dropping the dependency to the ws (websocket) library.
We're not really using any fs-extra features, so the standard fs module
is sufficient.
This makes imports of the "config.js" work when generating the dependency
graphs.
Copy link
Collaborator

@bgptr bgptr left a comment

Choose a reason for hiding this comment

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

LGTM

@alexlyp alexlyp merged commit 808c67e into decred:master Jun 21, 2021
@matheusd matheusd deleted the reduce-main-deps branch February 3, 2022 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants