diff --git a/package.json b/package.json index 4d1aa69..960ff27 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,10 @@ "node": ">=6.0.0", "npm": ">=3.0.0" }, + "types": "dist/src/index.d.ts", "devDependencies": { - "aegir": "^25.0.0", + "@types/debug": "^4.1.5", + "aegir": "^30.3.0", "libp2p-interfaces": "^0.4.0" }, "dependencies": { diff --git a/src/index.js b/src/index.js index 1aceb84..4c1d2b3 100644 --- a/src/index.js +++ b/src/index.js @@ -6,8 +6,9 @@ const mafmt = require('mafmt') const { EventEmitter } = require('events') const debug = require('debug') -const log = debug('libp2p:bootstrap') -log.error = debug('libp2p:bootstrap:error') +const log = Object.assign(debug('libp2p:bootstrap'), { + error: debug('libp2p:bootstrap:error') +}) /** * Emits 'peer' events on a regular interval for each peer in the provided list. @@ -18,10 +19,10 @@ class Bootstrap extends EventEmitter { * * @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 milliseconds (default: 10000) + * @param {number} [options.interval = 10000] - the interval between emitting addresses in milliseconds * */ - constructor (options = {}) { + constructor (options = { list: [] }) { if (!options.list || !options.list.length) { throw new Error('Bootstrap requires a list of peer addresses') } @@ -41,7 +42,7 @@ class Bootstrap extends EventEmitter { } this._timer = setInterval(() => this._discoverBootstrapPeers(), this._interval) - + log('Starting bootstrap node discovery') this._discoverBootstrapPeers() } @@ -77,7 +78,7 @@ class Bootstrap extends EventEmitter { * Stop emitting events. */ stop () { - clearInterval(this._timer) + if (this._timer) clearInterval(this._timer) this._timer = null } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..5fe9838 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "aegir/src/config/tsconfig.aegir.json", + "compilerOptions": { + "outDir": "dist", + "baseUrl": "./", + "paths": { + "*": ["./types/*"] + } + }, + "include": [ + "types", + "test", // remove this line if you don't want to type-check tests + "src" + ] +}