Skip to content

Commit

Permalink
fix duplicate emits
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Apr 9, 2020
1 parent 51ccf4a commit b5955ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bin/ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const main = async () => {
name: 'name',
message: 'Name of the module to search',
default: 'express'
}, {
},
{
type: 'input',
name: 'limit',
message: 'How many modules to display at most',
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const cheerio = require('cheerio')

module.exports = name => {
const dependants = []
const visited = new Set()
let offset = 0

const next = async () => {
Expand All @@ -14,8 +15,9 @@ module.exports = name => {
const dependant = $(el)
.attr('href')
.slice('/package/'.length)
if (dependant !== name && !dependants.includes(dependant)) {
if (dependant !== name && !visited.has(dependant)) {
dependants.push(dependant)
visited.add(dependant)
}
})
offset += 36
Expand Down

0 comments on commit b5955ff

Please sign in to comment.