Skip to content

Commit

Permalink
fix: update export paths (#42)
Browse files Browse the repository at this point in the history
Update paths to remove file extensions and use index for default file in directories.

Fixes the following TypeScript error:

```
Cannot find module '@libp2p/http-fetch/auth.js' or its corresponding type declarations.
  There are types at '/Users/path/to/node_modules/@libp2p/http-fetch/dist/src/auth/auth.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.
```

We can't update the module resolution yet due to compatibility issues with other dependencies, namely that not all of them have `"types"` fields in their exports maps yet.
  • Loading branch information
achingbrain authored Oct 29, 2024
1 parent 5f6e9c5 commit ca914d3
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 22 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ See the `examples/` for full examples of how to use the HTTP service.
import { createLibp2p } from 'libp2p'
import { http } from '@libp2p/http-fetch'

async function main () {
const node = await createLibp2p({
// other options ...
services: {
Expand All @@ -54,10 +53,7 @@ resp = await node.services.http.fetch('multiaddr:/dns4/example.com/tcp/443/tls/h
// And of course, you can use the fetch API as you normally would
resp = await node.services.http.fetch('https://example.com')

// This gives you the accessiblity of the fetch API with the flexibility of using a p2p network.
}

main()
// This gives you the accessibility of the fetch API with the flexibility of using a p2p network.
```

# Install
Expand Down
2 changes: 1 addition & 1 deletion examples/hono-server-over-libp2p/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { http } from '@libp2p/http-fetch'
import { sendPing } from '@libp2p/http-fetch/ping.js'
import { sendPing } from '@libp2p/http-fetch/ping'
import { tcp } from '@libp2p/tcp'
import { multiaddr } from '@multiformats/multiaddr'
import { createLibp2p } from 'libp2p'
Expand Down
2 changes: 1 addition & 1 deletion examples/hono-server-over-libp2p/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { serve } from '@hono/node-server'
import { WELL_KNOWN_PROTOCOLS, httpCustomServer } from '@libp2p/http-fetch'
import { PING_PROTOCOL_ID, servePing } from '@libp2p/http-fetch/ping.js'
import { PING_PROTOCOL_ID, servePing } from '@libp2p/http-fetch/ping'
import { tcp } from '@libp2p/tcp'
import { Hono } from 'hono'
import { createLibp2p } from 'libp2p'
Expand Down
4 changes: 2 additions & 2 deletions examples/peer-id-auth/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { serve } from '@hono/node-server'
import { generateKeyPair } from '@libp2p/crypto/keys'
import { ClientAuth, HTTPPeerIDAuthProto, ServerAuth } from '@libp2p/http-fetch/auth.js'
import { WellKnownHandler, WELL_KNOWN_PROTOCOLS } from '@libp2p/http-fetch/well-known-handler.js'
import { ClientAuth, HTTPPeerIDAuthProto, ServerAuth } from '@libp2p/http-fetch/auth'
import { WellKnownHandler, WELL_KNOWN_PROTOCOLS } from '@libp2p/http-fetch/well-known-handler'
import { peerIdFromPrivateKey } from '@libp2p/peer-id'
import { Hono } from 'hono'

Expand Down
2 changes: 1 addition & 1 deletion examples/two-js-peers/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { http } from '@libp2p/http-fetch'
import { sendPing } from '@libp2p/http-fetch/ping.js'
import { sendPing } from '@libp2p/http-fetch/ping'
import { peerIdFromString } from '@libp2p/peer-id'
import { tcp } from '@libp2p/tcp'
import { multiaddr } from '@multiformats/multiaddr'
Expand Down
2 changes: 1 addition & 1 deletion examples/two-js-peers/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { http } from '@libp2p/http-fetch'
import { PING_PROTOCOL_ID, servePing } from '@libp2p/http-fetch/ping.js'
import { PING_PROTOCOL_ID, servePing } from '@libp2p/http-fetch/ping'
import { tcp } from '@libp2p/tcp'
import { createLibp2p } from 'libp2p'

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
"types": "./dist/src/index.d.ts",
"import": "./dist/src/index.js"
},
"./auth.js": {
"types": "./dist/src/auth/auth.d.ts",
"import": "./dist/src/auth/auth.js"
"./auth": {
"types": "./dist/src/auth/index.d.ts",
"import": "./dist/src/auth/index.js"
},
"./ping.js": {
"./ping": {
"types": "./dist/src/ping.d.ts",
"import": "./dist/src/ping.js"
},
"./well-known-handler.js": {
"./well-known-handler": {
"types": "./dist/src/well-known-handler.d.ts",
"import": "./dist/src/well-known-handler.js"
}
Expand Down
File renamed without changes.
6 changes: 1 addition & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* import { createLibp2p } from 'libp2p'
* import { http } from '@libp2p/http-fetch'
*
* async function main () {
* const node = await createLibp2p({
* // other options ...
* services: {
Expand All @@ -30,10 +29,7 @@
* // And of course, you can use the fetch API as you normally would
* resp = await node.services.http.fetch('https://example.com')
*
* // This gives you the accessiblity of the fetch API with the flexibility of using a p2p network.
* }
*
* main()
* // This gives you the accessibility of the fetch API with the flexibility of using a p2p network.
* ```
*/

Expand Down
2 changes: 1 addition & 1 deletion typedoc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"entryPoints": [
"./src/index.ts",
"./src/auth/auth.ts",
"./src/auth/index.ts",
"./src/ping.ts",
"./src/well-known-handler.ts"
]
Expand Down

0 comments on commit ca914d3

Please sign in to comment.