Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit f46c06f

Browse files
committed
fix: Bootstrap module resolution error
1 parent b2af6ef commit f46c06f

File tree

8 files changed

+51
-16
lines changed

8 files changed

+51
-16
lines changed

.jsdoc.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
{
2+
"tags": {
3+
"allowUnknownTags": true
4+
},
25
"source": {
36
"include": ["src/"],
47
"exclude": ["node_modules"]
58
},
69
"opts": {
710
"destination": "src/",
811
"template": "./node_modules/tsd-jsdoc/dist"
9-
}
12+
},
13+
"plugins": ["./node_modules/jsdoc-export-default-interop/dist/index"]
14+
1015
}

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
script:
2424
- npx aegir dep-check
2525
- npm run lint
26-
- npm run generate-typings
2726

2827
- stage: test
2928
name: chrome

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"aegir": "^20.0.0",
3434
"chai": "^4.2.0",
3535
"jsdoc": "^3.6.3",
36+
"jsdoc-export-default-interop": "^0.3.1",
3637
"tsd-jsdoc": "^2.3.1",
3738
"typescript-definition-tester": "0.0.6"
3839
},

src/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @module js-libp2p-bootstrap
2+
* @module libp2p-bootstrap
33
*/
44
'use strict'
55

@@ -14,14 +14,14 @@ const log = debug('libp2p:bootstrap')
1414
log.error = debug('libp2p:bootstrap:error')
1515

1616
/**
17-
* Emits 'peer' events on a regular interval for each peer in the provided list.
1817
* @class
19-
* @memberof module:js-libp2p-bootstrap
18+
* @memberof module:libp2p-bootstrap
2019
*/
2120
class Bootstrap extends EventEmitter {
2221
/**
23-
* Constructs a new Bootstrap.
22+
* Emits 'peer' events on a regular interval for each peer in the provided list
2423
*
24+
* @constructs
2525
* @param {Object} options
2626
* @param {Array<string>} options.list - the list of peer addresses in multi-address format
2727
* @param {number} [options.interval] - the interval between emitting addresses (in milli-seconds)
@@ -49,6 +49,7 @@ class Bootstrap extends EventEmitter {
4949

5050
/**
5151
* Emit each address in the list as a PeerInfo.
52+
* @ignore
5253
*/
5354
_discoverBootstrapPeers () {
5455
this._list.forEach(async (candidate) => {

src/types.d.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/**
2-
* @module js-libp2p-bootstrap
2+
* @module libp2p-bootstrap
33
*/
4-
declare module "js-libp2p-bootstrap" {
4+
declare module "libp2p-bootstrap" {
55
/**
6-
* Constructs a new Bootstrap.
6+
* Emits 'peer' events on a regular interval for each peer in the provided list.
77
*
8+
* @constructs
89
* @param {Object} options
910
* @param {Array<string>} options.list - the list of peer addresses in multi-address format
1011
* @param {number} [options.interval] - the interval between emitting addresses (in milli-seconds)
@@ -19,10 +20,6 @@ declare module "js-libp2p-bootstrap" {
1920
* Start emitting events.
2021
*/
2122
start(): void;
22-
/**
23-
* Emit each address in the list as a PeerInfo.
24-
*/
25-
_discoverBootstrapPeers(): void;
2623
/**
2724
* Stop emitting events.
2825
*/
@@ -32,5 +29,18 @@ declare module "js-libp2p-bootstrap" {
3229
* @type string
3330
*/
3431
var tag: string;
32+
33+
/**
34+
* NB: Always include the snippet below because its not
35+
* generated by tsd-jsdoc else the test would keep failing
36+
*
37+
* Due to some wierd behaviour in Node.JS module resolution
38+
* it's not possible to access 'Bootstrap' via dot notation
39+
* even though its exported as
40+
* ```
41+
* exports = module.exports = Bootstrap
42+
* ```
43+
*/
44+
export default Bootstrap;
3545
}
3646

test/node.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-env mocha */
22
'use strict'
3+
/// <reference path="../../src/types.d.ts" />
34

45
const tt = require('typescript-definition-tester')
56
// typings test should run only in the node
@@ -8,8 +9,21 @@ describe('typings declaration tests', () => {
89
it('should compile typings examples successfully against types.d.ts', (done) => {
910
tt.compileDirectory(
1011
`${__dirname}/typings`,
11-
(fileName) => fileName.indexOf('.ts') > -1,
12+
(fileName) => fileName.indexOf('.pass.ts') > -1,
1213
(error) => done(error)
1314
)
1415
})
16+
17+
it('should fail to compile typings examples successfully against types.d.ts', (done) => {
18+
tt.compileDirectory(
19+
`${__dirname}/typings`,
20+
(fileName) => fileName.indexOf('.fail.ts') > -1,
21+
(error) => {
22+
if (error) {
23+
return done(null)
24+
}
25+
done(new Error('Should throw compilation error as Bootstrap is default export'))
26+
}
27+
)
28+
})
1529
})
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/// <reference path="../../src/types.d.ts" />
2-
3-
import { Bootstrap } from "js-libp2p-bootstrap";
2+
import { Bootstrap } from "libp2p-bootstrap";
43
const bootstrap1 = new Bootstrap({list: ["item"], interval: 1})
54
bootstrap1.start()

test/typings/test2.pass.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference path="../../src/types.d.ts" />
2+
3+
import Bootstrap from "libp2p-bootstrap";
4+
const bootstrap1 = new Bootstrap({list: ["item"], interval: 1})
5+
bootstrap1.start()
6+
bootstrap1.stop()

0 commit comments

Comments
 (0)