Skip to content

Commit

Permalink
Refactor: remove unused events and opts from Finder
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Nov 12, 2021
1 parent 88dc694 commit 48c683c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ module.exports = function detect (names, opts, done) {
const browser = opts.browsers[name]
if (!browser) throw new Error('No such browser is defined: ' + name)

const f = new Finder(name, browser, opts)

f.on('error', next).on('end', (res, methods) => {
new Finder(name, browser).run((res, methods) => {
for (const b of res.values()) result.push(b)
totalMethods += methods
next()
Expand Down
18 changes: 9 additions & 9 deletions lib/finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ const mt = require('pe-machine-type')
const util = require('util')
const path = require('path')
const existent = require('existent')
const Emitter = require('events').EventEmitter
const registry = require('./registry')

const versionInfo = require('./version-info')
const extractPath = require('./extract-path')
const HIVES = ['HKLM', 'HKCU']
const kCallback = Symbol('callback')

module.exports = Finder

function Finder (name, props, opts) {
function Finder (name, props) {
for (const k in props) this[k] = props[k]

this.name = name
this.bin = this.bin || (name + '.exe')
this[kCallback] = null
this.planned = 0
this.opts = opts

// Results by path and invalid paths
this.results = new Map()
this.ignored = new Set()

// Count the number of ways we found this browser
this.methods = 0
}

// Do browser-specific search
Finder.prototype.run = function (callback) {
this[kCallback] = callback
this.find()
}

require('util').inherits(Finder, Emitter)

Finder.prototype.env = function (envVar) {
this.file(null, env[envVar], envVar)
}
Expand Down Expand Up @@ -164,7 +164,7 @@ Finder.prototype.startMenu = function (startEntry) {
)
}

// Transform and normalize paths, then write them to stream
// Transform and normalize paths, then record result
Finder.prototype.found = function (bin, metadata, method, cb, _skipPre) {
if (this.closed) return

Expand Down Expand Up @@ -266,13 +266,13 @@ Finder.prototype.end = function () {

// Destroy (TODO: no longer neccesary?)
for (const m in this) {
if (typeof this[m] === 'function' && m !== 'emit') {
if (typeof this[m] === 'function' && m !== kCallback) {
this[m] = noop
}
}

this.closed = true
this.emit('end', this.results, this.methods)
this[kCallback](this.results, this.methods)
}

function debugKey (key, valueName) {
Expand Down
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ test('find methods', function (t) {
}
}

function find (method, fn, done) {
function find (method, fn) {
const browsers = {
methods_test: {
bin: 'dummy.exe',
Expand Down Expand Up @@ -276,7 +276,7 @@ test('firefox channel from ProductVersion', function (t) {
}
}

detect({ browsers, channel: true }, function (err, results) {
detect({ browsers }, function (err, results) {
t.ifError(err, 'no error')
t.same(results, [
{
Expand Down Expand Up @@ -313,7 +313,7 @@ test('firefox developer channel from ProductName', function (t) {
}
}

detect({ browsers, channel: true }, function (err, results) {
detect({ browsers }, function (err, results) {
t.ifError(err, 'no error')
t.same(results, [
{
Expand Down

0 comments on commit 48c683c

Please sign in to comment.