diff --git a/.jsdoc.json b/.jsdoc.json index 1eb01cf..123a19a 100644 --- a/.jsdoc.json +++ b/.jsdoc.json @@ -1,4 +1,7 @@ { + "tags": { + "allowUnknownTags": true + }, "source": { "include": ["src/"], "exclude": ["node_modules"] @@ -6,5 +9,7 @@ "opts": { "destination": "src/", "template": "./node_modules/tsd-jsdoc/dist" - } + }, + "plugins": ["./node_modules/jsdoc-export-default-interop/dist/index"] + } \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 71c596f..44b3ebc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,6 @@ jobs: script: - npx aegir dep-check - npm run lint - - npm run generate-typings - stage: test name: chrome diff --git a/package.json b/package.json index d0a553a..16e7e0e 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/index.js b/src/index.js index 2dac59d..6d7cb4c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ /** - * @module js-libp2p-bootstrap + * @module libp2p-bootstrap */ 'use strict' @@ -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} options.list - the list of peer addresses in multi-address format * @param {number} [options.interval] - the interval between emitting addresses (in milli-seconds) @@ -49,6 +49,7 @@ class Bootstrap extends EventEmitter { /** * Emit each address in the list as a PeerInfo. + * @ignore */ _discoverBootstrapPeers () { this._list.forEach(async (candidate) => { diff --git a/src/types.d.ts b/src/types.d.ts index f1f2503..383d1d9 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -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} options.list - the list of peer addresses in multi-address format * @param {number} [options.interval] - the interval between emitting addresses (in milli-seconds) @@ -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. */ @@ -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 + * + * And 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; } diff --git a/test/node.js b/test/node.js index 11285a9..1770348 100644 --- a/test/node.js +++ b/test/node.js @@ -1,5 +1,6 @@ /* eslint-env mocha */ 'use strict' +/// const tt = require('typescript-definition-tester') // typings test should run only in the node @@ -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')) + } + ) + }) }) diff --git a/test/typings/test.ts b/test/typings/test.fail.ts similarity index 72% rename from test/typings/test.ts rename to test/typings/test.fail.ts index e0c1558..ead9e67 100644 --- a/test/typings/test.ts +++ b/test/typings/test.fail.ts @@ -1,5 +1,4 @@ /// - -import { Bootstrap } from "js-libp2p-bootstrap"; +import { Bootstrap } from "libp2p-bootstrap"; const bootstrap1 = new Bootstrap({list: ["item"], interval: 1}) bootstrap1.start() diff --git a/test/typings/test2.pass.ts b/test/typings/test2.pass.ts new file mode 100644 index 0000000..f4d73d9 --- /dev/null +++ b/test/typings/test2.pass.ts @@ -0,0 +1,6 @@ +/// + +import Bootstrap from "libp2p-bootstrap"; +const bootstrap1 = new Bootstrap({list: ["item"], interval: 1}) +bootstrap1.start() +bootstrap1.stop() \ No newline at end of file