Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ build
node_modules

lib
dist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dist should be ignored. The dist folder will be created on the release script for publishing but should not be part of the repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in this case, do we leave the package.json pointing to dist/src/index.d.ts even though it's no longer included in my PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will be created in the release and what is shipped to npm will include the dist folder

test/test-data/go-ipfs-repo/LOCK
test/test-data/go-ipfs-repo/LOG
test/test-data/go-ipfs-repo/LOG.old
Expand Down
39 changes: 39 additions & 0 deletions dist/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export = Bootstrap;
/**
* Emits 'peer' events on a regular interval for each peer in the provided list.
*/
declare class Bootstrap extends EventEmitter {
/**
* Constructs a new Bootstrap.
*
* @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 milliseconds (default: 10000)
*
*/
constructor(options?: {
list: Array<string>;
interval: number | undefined;
});
_list: string[];
_interval: number;
_timer: NodeJS.Timeout | null;
/**
* Start emitting events.
*/
start(): void;
/**
* Emit each address in the list as a PeerInfo.
*/
_discoverBootstrapPeers(): void;
/**
* Stop emitting events.
*/
stop(): void;
}
declare namespace Bootstrap {
export { tag };
}
import { EventEmitter } from "node/events";
declare var tag: string;
//# sourceMappingURL=index.d.ts.map
1 change: 1 addition & 0 deletions dist/src/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
11 changes: 5 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const mafmt = require('mafmt')
const { EventEmitter } = require('events')
const debug = require('debug')

const log = debug('libp2p:bootstrap')
log.error = debug('libp2p:bootstrap:error')
const error = debug('libp2p:bootstrap:error')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For keeping consistent with other libp2p repos, I suggest changing this to:

const debug = require('debug')
const log = Object.assign(debug('libp2p:bootstrap'), {
  error: debug('libp2p:bootstrap:error')
})

What do you think? We currently do not use the the normal log, but perhaps we should log when the bootstrap starts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense. I added a log message to the start method in my latest commit.


/**
* Emits 'peer' events on a regular interval for each peer in the provided list.
Expand All @@ -21,7 +20,7 @@ class Bootstrap extends EventEmitter {
* @param {number} [options.interval] - the interval between emitting addresses in milliseconds (default: 10000)
*
*/
constructor (options = {}) {
constructor (options = { list: [] }) {
if (!options.list || !options.list.length) {
throw new Error('Bootstrap requires a list of peer addresses')
}
Expand Down Expand Up @@ -55,7 +54,7 @@ class Bootstrap extends EventEmitter {

this._list.forEach((candidate) => {
if (!mafmt.P2P.matches(candidate)) {
return log.error('Invalid multiaddr')
return error('Invalid multiaddr')
}

const ma = multiaddr(candidate)
Expand All @@ -68,7 +67,7 @@ class Bootstrap extends EventEmitter {
multiaddrs: [ma]
})
} catch (err) {
log.error('Invalid bootstrap peer id', err)
error('Invalid bootstrap peer id', err)
}
})
}
Expand All @@ -77,7 +76,7 @@ class Bootstrap extends EventEmitter {
* Stop emitting events.
*/
stop () {
clearInterval(this._timer)
if (this._timer) clearInterval(this._timer)
this._timer = null
}
}
Expand Down
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}