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

Replace webpack with vite.js #364

Merged
merged 5 commits into from
Jul 5, 2022
Merged

Replace webpack with vite.js #364

merged 5 commits into from
Jul 5, 2022

Conversation

elbywan
Copy link
Contributor

@elbywan elbywan commented Jun 15, 2022

📝 Description

This PR aims to replace webpack with vite.js to improve the developer experience while working on ledger live desktop.

Benefits: fast cold boot time, instant hot reload ✨ .

Unfortunately, vite.js is quite rigid, and the following impactful changes have been made to make it work properly:

  • Renaming of .js to .jsx files when needed (jsx inside).
  • Transpilation of @ledgerhq/live-common to esm in addition to commonjs and added subpath exports.
  • Transpilation of @ledgerhq/hw-app-btc to esm in addition to commonjs and added subpath exports.
  • Added subpath exports for @ledgerhq/devices.
  • Renamed all /lib prefixed paths to @ledgerhq/live-common and @ledgerhq/hw-app-btc.
  • Major jest update.

🔥 There are breaking changes for @ledgerhq/live-common, @ledgerhq/devices and @ledgerhq/hw-app-btc consumers

Reason

To fully embrace the "bundleless" vite.js approach, it is necessary to transpile our packages contained in the monorepository to the ESM format.

At the same time we cannot afford to break commonjs support for node.js code requiring the same packages, so we must also transpile to commonjs.

The hard part is that we have shared code (renderer/main processes) in LLD and depending on which entry point we must be able to dispatch to the right format.

Until now we added the /lib prefix to directly point to transpiled files when importing the library (ex: import whatever from "@ledgerhq/live-common/lib/whatever"). This is not possible anymore since we have both /lib and /lib-es directories.

The changes

The "official" workaround is to add subpath exports to silently map subpaths to /lib/* and /lib-es.

The configuration in the package.json file is something like:

"exports": {
    "./*/": {
      "require": "./lib/*/index.js",
      "default": "./lib-es/*/index.js"
    },
    "./*": {
      "require": "./lib/*.js",
      "default": "./lib-es/*.js"
    },
    ".": {
      "require": "./lib/index.js",
      "default": "./lib-es/index.js"
    },
  },

Which makes the following import…

import { createDataModel } from "@ledgerhq/live-common/DataModel";

…mapped to…

import { createDataModel } from "@ledgerhq/live-common/lib-es/DataModel";

…and the following require…

const { createDataModel } = require("@ledgerhq/live-common/DataModel");

…is mapped to:

const { createDataModel } = require("@ledgerhq/live-common/lib/DataModel");

The limitations

As highlighted here (nodejs/node#39994), it is not possible to target folders directly when using subpath exports.

The workaround is to suffix the call with /index (or /).

For instance, import * as currencies from "@ledgerhq/live-common/currencies"; must be rewritten to import * as currencies from "@ledgerhq/live-common/currencies/index";

This PR takes care of renaming every imports properly but will break for external projects importing subpaths with /lib and targeting a folder.

❓ Context

  • Impacted projects: A lot
  • Linked resource(s):

✅ Checklist

📸 Demo

Full boot + hot reload ⚡

screen-recording-2022-06-17-at-124531_8i2MaEI4.mp4

Just hot reload

Screen.Recording.2022-06-14.at.15.10.36.mov

🚀 Expectations to reach

Please make sure you follow these Important Steps.

Pull Requests must pass the CI and be internally validated in order to be merged.

@vercel
Copy link

vercel bot commented Jun 15, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
live-common-tools ✅ Ready (Inspect) Visit Preview Jul 5, 2022 at 2:38PM (UTC)
react-ui-storybook ✅ Ready (Inspect) Visit Preview Jul 5, 2022 at 2:38PM (UTC)
2 Ignored Deployments
Name Status Preview Updated
ledger-live-github-bot ⬜️ Ignored (Inspect) Jul 5, 2022 at 2:38PM (UTC)
native-ui-storybook ⬜️ Ignored (Inspect) Jul 5, 2022 at 2:38PM (UTC)

@changeset-bot
Copy link

changeset-bot bot commented Jun 15, 2022

🦋 Changeset detected

Latest commit: 5afac23

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 40 packages
Name Type
@ledgerhq/live-common Major
@ledgerhq/devices Major
@ledgerhq/hw-app-btc Major
@ledgerhq/live-cli Patch
ledger-live-desktop Patch
live-mobile Patch
@ledgerhq/hw-app-eth Patch
@ledgerhq/hw-transport-node-ble Patch
@ledgerhq/hw-transport-node-hid-noevents Patch
@ledgerhq/hw-transport-web-ble Patch
@ledgerhq/hw-transport-webhid Patch
@ledgerhq/hw-transport-webusb Patch
@ledgerhq/react-native-hw-transport-ble Patch
@ledgerhq/icons-ui Patch
@ledgerhq/react-ui Patch
has-hash-commit-deps Patch
@actions/submit-bot-report Patch
@actions/upload-images Patch
esbuild-utils Patch
live-github-bot Patch
native-modules-tools Patch
live-common-tools Patch
@ledgerhq/hw-transport-node-hid-singleton Patch
@ledgerhq/hw-transport-node-hid Patch
@ledgerhq/hw-transport Patch
@ledgerhq/react-native-hid Patch
@ledgerhq/native-ui Patch
@ledgerhq/hw-app-algorand Patch
@ledgerhq/hw-app-cosmos Patch
@ledgerhq/hw-app-helium Patch
@ledgerhq/hw-app-polkadot Patch
@ledgerhq/hw-app-solana Patch
@ledgerhq/hw-app-str Patch
@ledgerhq/hw-app-tezos Patch
@ledgerhq/hw-app-trx Patch
@ledgerhq/hw-app-xrp Patch
@ledgerhq/hw-transport-http Patch
@ledgerhq/hw-transport-mocker Patch
@ledgerhq/hw-transport-node-speculos-http Patch
@ledgerhq/hw-transport-node-speculos Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added common Has changes in live-common desktop Has changes in LLD ledgerjs Has changes in the ledgerjs open source libs tools Has changes in tools ui Has changes in the design system library labels Jun 15, 2022
@elbywan elbywan changed the base branch from develop to support/esbuild June 16, 2022 12:43
@github-actions github-actions bot added cli mobile Has changes in LLM labels Jun 16, 2022
@github-actions
Copy link

github-actions bot commented Jun 16, 2022

@elbywan

Screenshots: ✅

There are no changes in the screenshots for this PR. If this is expected, you are good to go.

@codecov
Copy link

codecov bot commented Jun 16, 2022

Codecov Report

Merging #364 (0ba0c20) into develop (88d1f1b) will decrease coverage by 0.33%.
The diff coverage is n/a.

❗ Current head 0ba0c20 differs from pull request most recent head 5afac23. Consider uploading reports for the commit 5afac23 to get more accurate results

@@             Coverage Diff             @@
##           develop     #364      +/-   ##
===========================================
- Coverage    47.94%   47.60%   -0.34%     
===========================================
  Files          602      598       -4     
  Lines        26550    26419     -131     
  Branches      6792     6760      -32     
===========================================
- Hits         12730    12578     -152     
- Misses       13768    13790      +22     
+ Partials        52       51       -1     
Flag Coverage Δ
test 47.60% <ø> (-0.34%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...-common/src/families/bitcoin/js-synchronisation.ts 13.14% <0.00%> (-8.86%) ⬇️
libs/ledger-live-common/src/range.ts 89.74% <0.00%> (-7.70%) ⬇️
...s/ledger-live-common/src/families/bitcoin/logic.ts 33.92% <0.00%> (-4.42%) ⬇️
...dgerjs/packages/hw-app-btc/src/splitTransaction.ts 73.68% <0.00%> (-0.55%) ⬇️
libs/ledger-live-common/src/types/manager.ts
...edger-live-common/src/hw/extractOnboardingState.ts
...er-live-common/src/hw/getOnboardingStatePolling.ts
.../src/onboarding/hooks/useOnboardingStatePolling.ts
libs/ledgerjs/packages/hw-app-eth/src/Eth.ts 78.63% <0.00%> (+0.04%) ⬆️
...dger-live-common/src/families/cosmos/api/Cosmos.ts 18.75% <0.00%> (+0.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 37a9f85...5afac23. Read the comment docs.

Copy link
Contributor

@juan-cortes juan-cortes left a comment

Choose a reason for hiding this comment

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

lgtm crazy pr

Copy link
Contributor

@Justkant Justkant left a comment

Choose a reason for hiding this comment

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

LGTM, works well on LLM and LLD starts so fast, I like it ✌️ thx for the work on that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli common Has changes in live-common desktop Has changes in LLD HODL Do not merge ledgerjs Has changes in the ledgerjs open source libs mobile Has changes in LLM tools Has changes in tools ui Has changes in the design system library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants