fix(transport): make NodeHIDTransport reachable from consumers - #31
Merged
Conversation
The exports map declared only ".", so the deep path the transport factory's own error message directs Node consumers to — dist/core/transport/ nodehid-transport.js — was blocked by both Node (ERR_PACKAGE_PATH_NOT_EXPORTED) and TypeScript (TS2307). The class was not re-exported from the root either, so neither remedy that message suggests was possible: you could not import it directly, and you could not construct one to inject via transportFactory. The only route left was reimplementing HWTransport against node-hid. Add a ./node subpath export and a root re-export. The subpath is the one that works in bare Node ESM: the root barrel statically pulls hw-transport-webhid and hw-transport, which reach @ledgerhq/errors@6.32.0, whose lib-es build uses an extensionless relative import that Node's ESM resolver rejects. Bundlers resolve it, node does not. nodehid-transport has no static @LedgerHQ imports at all, so the subpath sidesteps it and the root re-export stays browser-safe — the node-hid dependency is behind a dynamic import inside connect(). Also declare @ledgerhq/hw-transport-node-hid as an optional peer dependency. It was a devDependency only, so consumers were never told to install it, while the WebHID and Web BLE transports were already declared this way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
NodeHIDTransportshipped in the package but no consumer could reach it.The
exportsmap declared only".", so the deep path thattransport-factory's ownerror message directs Node consumers to —
dist/core/transport/nodehid-transport.js—was blocked by Node (
ERR_PACKAGE_PATH_NOT_EXPORTED) and TypeScript (TS2307). Theclass was not re-exported from the root either.
That made both remedies the factory suggests impossible: you could not import it
directly, and you could not construct one in order to inject it via
transportFactory.The only route left for a Node consumer was reimplementing
HWTransportagainstnode-hid— duplicating a transport this package already ships and tests.Fix
./nodesubpath export —@railgun-community/ledger-client/nodeNodeHIDTransport, alongsideWebHIDTransport/WebBLETransport@ledgerhq/hw-transport-node-hiddeclared as an optional peer dependency. It was adevDependency only, so consumers were never told to install it, while WebHID and Web BLE
were already declared this way.
docs/api/transport.mdnow name the supported import pathWhy both a subpath and a root export
The root re-export alone does not unblock a Node consumer. Measured from a real consumer
in bare Node ESM:
The root barrel statically pulls
@ledgerhq/hw-transport-webhidand@ledgerhq/hw-transport, which reach@ledgerhq/errors@6.32.0, whoselib-es/index.jsuses an extensionless relative import that Node's ESM resolver rejects. Bundlers resolve
it; bare
nodedoes not. This is pre-existing —webhid-transport.jsandledger-transport-adapter.jseach fail identically on their own, independent of thischange.
The subpath sidesteps it:
nodehid-transporthas no static@ledgerhqimports at all(only
./types.js,../errors.js,./apdu-wire.js). That is also why the rootre-export stays browser-safe — the
node-hiddependency is behind a dynamic importinside
connect(), the same shapeWebBLETransportalready uses.Verification
yarn lint,yarn typecheck,yarn buildclean; 547 tests / 38 files passnodehid-transport.{js,d.ts}present in
package/dist/, andimport ... from '@railgun-community/ledger-client/node'resolves at runtime
--module nodenextFollow-up, not in this PR
Making
webhid-transportandledger-transport-adapterlazy would fix the root barrelunder bare Node ESM. That is a behavioral change with real risk and does not belong in a
packaging fix.