Fix compatibility with current nostr-tools#1
Open
bitcoin3us wants to merge 1 commit into
Open
Conversation
The production build fails against current nostr-tools versions, and a
couple of relay APIs the pool relied on have changed.
- nip27: nostr-tools removed the `matchAll` / `replaceAll` helpers from
its `nip27` module (current versions export only `parse`), which broke
the build with a fatal Rollup error ("replaceAll is not exported").
Vendor a small `src/util/nip27.ts` that restores exactly the behaviour
ZapThreads used — matching NIP-21 `nostr:` references and decoding them
via nip19 — so the build no longer depends on the removed exports.
- network.ts: AbstractRelay no longer exposes the `connectionTimeout`
property or the private `_onauth` hook. Pass the timeout via
`relay.connect({ timeout })` instead, and drop the `_onauth` hook —
relays that require NIP-42 AUTH to read are already detected from the
subscription close reason in `handleClose`. Type the pool constructor
with `AbstractRelayConstructorOptions` (it only ever reads relay
options), and guard the now-optional `window.nostr.getRelays()`.
Builds cleanly against nostr-tools 2.23.x; the widget was verified in a
browser (relay connection, comment loading and the composer all work).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
47de571 to
9a75898
Compare
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
vite buildfails against recentnostr-toolsreleases:nostr-tools removed the
matchAll/replaceAllhelpers from itsnip27module — current versions export onlyparse. A fewAbstractRelayAPIs thatnetwork.tsrelied on have also changed. Sincepackage.jsondeclaresnostr-tools: ^2.7.1(which resolves to the latest 2.x), a cleannpm install+vite buildcurrently aborts.Changes
nip27 — vendor a minimal
src/util/nip27.tsthat restores exactly thematchAll/replaceAllbehaviour ZapThreads used: it matches NIP-21nostr:references and decodes them vianip19.ui.tsimports from the local module instead ofnostr-tools/nip27; behaviour is unchanged (decode failures are skipped / passed through rather than thrown).network.ts — port to the current
AbstractRelayAPI:connectionTimeoutis no longer a settable property — the timeout is passed per call viarelay.connect({ timeout })._onauthhook was removed. It is dropped here; relays that require NIP-42 AUTH to read are already detected from the subscription close reason inhandleClose, so behaviour is preserved.PrioritizedPool's constructor is typed withAbstractRelayConstructorOptions(it only readsverifyEvent/websocketImplementation);AbstractPoolConstructorOptionsnow requires fields the class does not use.window.nostr.getRelays()is now optional in theNostrtype — guarded.Testing
nostr-tools2.23.x —vite buildproducesdist/with no errors related to these changes.index.tsxSectiontyping,remarkable/linkifymissing types) — left out of scope.Note
package.jsonstill declaresnostr-tools: ^2.7.1, but the code now targets the current relay API — you may want to bump that range. Left unchanged to keep this PR focused.