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

Force commonjs imports for ledgerhq-react-native-hw-transport-ble #879

Merged
merged 2 commits into from
Aug 9, 2022

Conversation

elbywan
Copy link
Contributor

@elbywan elbywan commented Aug 9, 2022

📝 Description

Why?

Following this PR #364 @ledgerhq/device is now transpiled to commonjs and esm (in the /lib and /lib-es folders respectively).

Subpath exports have thus been added to use the same path (without /lib and /lib-es) in imports and allow consuming bundlers to declare which version of the dependency they want.

An unforeseen side-effect is that for the react-native package (ledgerhq-react-native-hw-transport-ble) consumers use exclusively the metro bundler which is incompatible with subpath exports.

Done

Adding /lib to the imports should work and should never cause duplicate issues since the metro bundler will always resolve the commonjs version of the package anyway.

Side effect:

📦 Updated pnpm to 7.9.0

❓ Context

✅ Checklist

  • Test coverage
  • Atomic delivery
  • No breaking changes

📸 Demo

Steps to test:

from ledger-live

  • cd libs/ledgerjs/packages/react-native-hw-transport-ble/
  • pnpm pack (will generate ledgerhq-react-native-hw-transport-ble-6.27.2.tgz to the current folder)

from another folder

  • npx react-native init RNtransportBleTest
  • cd RNtransportBleTest/
  • npm i path/to/ledgerhq-react-native-hw-transport-ble-6.27.2.tgz
  • npm install --save react-native-ble-plx
  • cd ios && pod update && cd ..
  • Add this to the App.js file:
import TransportBLE from '@ledgerhq/react-native-hw-transport-ble';

console.log(TransportBLE);
  • npm start / npm ios

Should print:

 LOG  [Function BluetoothTransport]
 LOG  Running "RNtransportBleTest" with {"rootTag":1,"initialProps":{}}

🚀 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 Aug 9, 2022

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

Name Status Preview Updated
live-common-tools ✅ Ready (Inspect) Visit Preview Aug 9, 2022 at 9:06AM (UTC)
3 Ignored Deployments
Name Status Preview Updated
ledger-live-github-bot ⬜️ Ignored (Inspect) Aug 9, 2022 at 9:06AM (UTC)
native-ui-storybook ⬜️ Ignored (Inspect) Aug 9, 2022 at 9:06AM (UTC)
react-ui-storybook ⬜️ Ignored (Inspect) Aug 9, 2022 at 9:06AM (UTC)

@changeset-bot
Copy link

changeset-bot bot commented Aug 9, 2022

⚠️ No Changeset found

Latest commit: 400a517

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions github-actions bot added ledgerjs Has changes in the ledgerjs open source libs mobile Has changes in LLM labels Aug 9, 2022
@elbywan elbywan linked an issue Aug 9, 2022 that may be closed by this pull request
# See: https://github.com/actions/setup-node/issues/543#issuecomment-1182469390
loglevel=warn
# Disabled because it does not seem to be working and it regenerates the lockfile abusively
side-effects-cache=false
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting, i didn't even know about this file!

Copy link
Contributor Author

@elbywan elbywan Aug 9, 2022

Choose a reason for hiding this comment

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

yeah it's super useful to tweak pnpm behaviour

https://pnpm.io/npmrc

@codecov
Copy link

codecov bot commented Aug 9, 2022

Codecov Report

Merging #879 (400a517) into develop (d3d7c8d) will increase coverage by 3.68%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           develop     #879      +/-   ##
===========================================
+ Coverage    43.82%   47.51%   +3.68%     
===========================================
  Files          572      621      +49     
  Lines        24625    27873    +3248     
  Branches      6506     7174     +668     
===========================================
+ Hits         10793    13245    +2452     
- Misses       12742    13495     +753     
- Partials      1090     1133      +43     
Flag Coverage Δ
test 47.51% <ø> (+3.68%) ⬆️

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

Impacted Files Coverage Δ
...s/packages/hw-app-eth/src/services/ledger/erc20.ts 97.43% <0.00%> (ø)
...s/hw-app-btc/src/shouldUseTrustedInputForSegwit.ts 100.00% <0.00%> (ø)
...js/packages/hw-app-btc/src/newops/psbtFinalizer.ts 78.57% <0.00%> (ø)
libs/ledgerjs/packages/hw-app-btc/src/constants.ts 100.00% <0.00%> (ø)
libs/ledgerjs/packages/hw-app-solana/src/Solana.ts 100.00% <0.00%> (ø)
.../ledgerjs/packages/hw-app-btc/src/newops/merkle.ts 83.82% <0.00%> (ø)
...-app-btc/src/startUntrustedHashTransactionInput.ts 90.16% <0.00%> (ø)
.../ledgerjs/packages/hw-app-btc/src/newops/policy.ts 91.66% <0.00%> (ø)
...bs/ledgerjs/packages/hw-app-btc/src/signMessage.ts 86.84% <0.00%> (ø)
...js/packages/hw-app-btc/src/newops/psbtExtractor.ts 100.00% <0.00%> (ø)
... and 39 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

import { sendAPDU } from "@ledgerhq/devices/ble/sendAPDU";
import { receiveAPDU } from "@ledgerhq/devices/ble/receiveAPDU";
import { sendAPDU } from "@ledgerhq/devices/lib/ble/sendAPDU";
import { receiveAPDU } from "@ledgerhq/devices/lib/ble/receiveAPDU";
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we using /lib here ?

Copy link
Contributor Author

@elbywan elbywan Aug 9, 2022

Choose a reason for hiding this comment

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

This is the whole point of this PR 😉.

metro is unable to map @ledgerhq/devices/ble/… to either /lib/ble/… or /lib-es/ble/… because it does not support package exports.

Workarounds exist and are documented in the linked issue but it's not ideal at all to have to modify the metro config file.

Adding /lib here is not a big deal anyway since the react-native-hw-transport-ble package is only consumed by react-native clients and will never need to resolve the /lib-es version.

@github-actions
Copy link

github-actions bot commented Aug 9, 2022

@elbywan

Screenshots: ✅

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

@elbywan elbywan merged commit d7d9251 into develop Aug 9, 2022
@elbywan elbywan deleted the bugfix/native-transport-force-imports branch August 9, 2022 09:40
AlexandruPislariu pushed a commit to multiversx/ledger-live that referenced this pull request Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ledgerjs Has changes in the ledgerjs open source libs mobile Has changes in LLM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to resolve module in react-native-hw-transport-ble
3 participants