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

Commit

Permalink
fix: Bootstrap module resolution error
Browse files Browse the repository at this point in the history
  • Loading branch information
samparsky committed Aug 27, 2019
1 parent b2af6ef commit f46c06f
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 16 deletions.
7 changes: 6 additions & 1 deletion .jsdoc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"tags": {
"allowUnknownTags": true
},
"source": {
"include": ["src/"],
"exclude": ["node_modules"]
},
"opts": {
"destination": "src/",
"template": "./node_modules/tsd-jsdoc/dist"
}
},
"plugins": ["./node_modules/jsdoc-export-default-interop/dist/index"]

}
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
script:
- npx aegir dep-check
- npm run lint
- npm run generate-typings

- stage: test
name: chrome
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"aegir": "^20.0.0",
"chai": "^4.2.0",
"jsdoc": "^3.6.3",
"jsdoc-export-default-interop": "^0.3.1",
"tsd-jsdoc": "^2.3.1",
"typescript-definition-tester": "0.0.6"
},
Expand Down
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @module js-libp2p-bootstrap
* @module libp2p-bootstrap
*/
'use strict'

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

/**
* Emits 'peer' events on a regular interval for each peer in the provided list.
* @class
* @memberof module:js-libp2p-bootstrap
* @memberof module:libp2p-bootstrap
*/
class Bootstrap extends EventEmitter {
/**
* Constructs a new Bootstrap.
* Emits 'peer' events on a regular interval for each peer in the provided list
*
* @constructs
* @param {Object} options
* @param {Array<string>} options.list - the list of peer addresses in multi-address format
* @param {number} [options.interval] - the interval between emitting addresses (in milli-seconds)
Expand Down Expand Up @@ -49,6 +49,7 @@ class Bootstrap extends EventEmitter {

/**
* Emit each address in the list as a PeerInfo.
* @ignore
*/
_discoverBootstrapPeers () {
this._list.forEach(async (candidate) => {
Expand Down
24 changes: 17 additions & 7 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/**
* @module js-libp2p-bootstrap
* @module libp2p-bootstrap
*/
declare module "js-libp2p-bootstrap" {
declare module "libp2p-bootstrap" {
/**
* Constructs a new Bootstrap.
* Emits 'peer' events on a regular interval for each peer in the provided list.
*
* @constructs
* @param {Object} options
* @param {Array<string>} options.list - the list of peer addresses in multi-address format
* @param {number} [options.interval] - the interval between emitting addresses (in milli-seconds)
Expand All @@ -19,10 +20,6 @@ declare module "js-libp2p-bootstrap" {
* Start emitting events.
*/
start(): void;
/**
* Emit each address in the list as a PeerInfo.
*/
_discoverBootstrapPeers(): void;
/**
* Stop emitting events.
*/
Expand All @@ -32,5 +29,18 @@ declare module "js-libp2p-bootstrap" {
* @type string
*/
var tag: string;

/**
* NB: Always include the snippet below because its not
* generated by tsd-jsdoc else the test would keep failing
*
* Due to some wierd behaviour in Node.JS module resolution
* it's not possible to access 'Bootstrap' via dot notation
* even though its exported as
* ```
* exports = module.exports = Bootstrap
* ```
*/
export default Bootstrap;
}

16 changes: 15 additions & 1 deletion test/node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-env mocha */
'use strict'
/// <reference path="../../src/types.d.ts" />

const tt = require('typescript-definition-tester')
// typings test should run only in the node
Expand All @@ -8,8 +9,21 @@ describe('typings declaration tests', () => {
it('should compile typings examples successfully against types.d.ts', (done) => {
tt.compileDirectory(
`${__dirname}/typings`,
(fileName) => fileName.indexOf('.ts') > -1,
(fileName) => fileName.indexOf('.pass.ts') > -1,
(error) => done(error)
)
})

it('should fail to compile typings examples successfully against types.d.ts', (done) => {
tt.compileDirectory(
`${__dirname}/typings`,
(fileName) => fileName.indexOf('.fail.ts') > -1,
(error) => {
if (error) {
return done(null)
}
done(new Error('Should throw compilation error as Bootstrap is default export'))
}
)
})
})
3 changes: 1 addition & 2 deletions test/typings/test.ts → test/typings/test.fail.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <reference path="../../src/types.d.ts" />

import { Bootstrap } from "js-libp2p-bootstrap";
import { Bootstrap } from "libp2p-bootstrap";
const bootstrap1 = new Bootstrap({list: ["item"], interval: 1})
bootstrap1.start()
6 changes: 6 additions & 0 deletions test/typings/test2.pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <reference path="../../src/types.d.ts" />

import Bootstrap from "libp2p-bootstrap";
const bootstrap1 = new Bootstrap({list: ["item"], interval: 1})
bootstrap1.start()
bootstrap1.stop()

0 comments on commit f46c06f

Please sign in to comment.