77
88"use strict" ;
99
10- var fs = require ( 'fs' ) ,
11- os = require ( 'os' ) ,
12- net = require ( 'net' ) ,
13- path = require ( 'path' ) ,
14- _async = require ( 'async' ) ,
15- debug = require ( 'debug' ) ,
16- mkdirp = require ( 'mkdirp' ) . mkdirp ;
10+ const fs = require ( 'fs' ) ,
11+ os = require ( 'os' ) ,
12+ net = require ( 'net' ) ,
13+ path = require ( 'path' ) ,
14+ _async = require ( 'async' ) ,
15+ debug = require ( 'debug' ) ,
16+ mkdirp = require ( 'mkdirp' ) . mkdirp ;
1717
18- var debugTestPort = debug ( 'portfinder:testPort' ) ,
19- debugGetPort = debug ( 'portfinder:getPort' ) ,
20- debugDefaultHosts = debug ( 'portfinder:defaultHosts' ) ;
18+ const debugTestPort = debug ( 'portfinder:testPort' ) ,
19+ debugGetPort = debug ( 'portfinder:getPort' ) ,
20+ debugDefaultHosts = debug ( 'portfinder:defaultHosts' ) ;
2121
22- var internals = { } ;
22+ const internals = { } ;
2323
2424internals . testPort = function ( options , callback ) {
2525 if ( ! callback ) {
@@ -54,7 +54,7 @@ internals.testPort = function(options, callback) {
5454 return callback ( err ) ;
5555 }
5656
57- var nextPort = exports . nextPort ( options . port ) ;
57+ const nextPort = exports . nextPort ( options . port ) ;
5858
5959 if ( nextPort > exports . highestPort ) {
6060 return callback ( new Error ( 'No open ports available' ) ) ;
@@ -154,7 +154,8 @@ exports.getPort = function (options, callback) {
154154 exports . _defaultHosts . push ( options . host )
155155 }
156156
157- var openPorts = [ ] , currentHost ;
157+ const openPorts = [ ] ;
158+ let currentHost ;
158159 return _async . eachSeries ( exports . _defaultHosts , function ( host , next ) {
159160 debugGetPort ( "in eachSeries() iteration callback: host is" , host ) ;
160161
@@ -183,10 +184,10 @@ exports.getPort = function (options, callback) {
183184 // NOTE: We may need to one day handle `my-non-existent-host.local` if users
184185 // report frustration with passing in hostnames that DONT map to bindable
185186 // hosts, without showing them a good error.
186- var msg = 'Provided host ' + options . host + ' could NOT be bound. Please provide a different host address or hostname' ;
187+ const msg = 'Provided host ' + options . host + ' could NOT be bound. Please provide a different host address or hostname' ;
187188 return callback ( Error ( msg ) ) ;
188189 } else {
189- var idx = exports . _defaultHosts . indexOf ( currentHost ) ;
190+ const idx = exports . _defaultHosts . indexOf ( currentHost ) ;
190191 exports . _defaultHosts . splice ( idx , 1 ) ;
191192 return exports . getPort ( options , callback ) ;
192193 }
@@ -209,7 +210,7 @@ exports.getPort = function (options, callback) {
209210 return callback ( null , openPorts [ 0 ] ) ;
210211 }
211212 else {
212- var msg = 'No open ports found in between ' + options . startPort + ' and ' + options . stopPort ;
213+ const msg = 'No open ports found in between ' + options . startPort + ' and ' + options . stopPort ;
213214 return callback ( Error ( msg ) ) ;
214215 }
215216 } else {
@@ -256,7 +257,7 @@ exports.getPorts = function (count, options, callback) {
256257 options = { } ;
257258 }
258259
259- var lastPort = null ;
260+ let lastPort = null ;
260261 _async . timesSeries ( count , function ( index , asyncCallback ) {
261262 if ( lastPort ) {
262263 options . port = exports . nextPort ( lastPort ) ;
@@ -363,7 +364,7 @@ exports.getSocket = function (options, callback) {
363364 // then test connection.
364365 //
365366 function checkAndTestSocket ( ) {
366- var dir = path . dirname ( options . path ) ;
367+ const dir = path . dirname ( options . path ) ;
367368
368369 fs . stat ( dir , function ( err , stats ) {
369370 if ( err || ! stats . isDirectory ( ) ) {
@@ -402,11 +403,11 @@ exports.nextPort = function (port) {
402403// specified `socketPath`.
403404//
404405exports . nextSocket = function ( socketPath ) {
405- var dir = path . dirname ( socketPath ) ,
406- name = path . basename ( socketPath , '.sock' ) ,
407- match = name . match ( / ^ ( [ a - z A - z ] + ) ( \d * ) $ / i) ,
408- index = parseInt ( match [ 2 ] ) ,
409- base = match [ 1 ] ;
406+ const dir = path . dirname ( socketPath ) ,
407+ name = path . basename ( socketPath , '.sock' ) ,
408+ match = name . match ( / ^ ( [ a - z A - z ] + ) ( \d * ) $ / i) ,
409+ base = match [ 1 ] ;
410+ let index = parseInt ( match [ 2 ] ) ;
410411 if ( isNaN ( index ) ) {
411412 index = 0 ;
412413 }
@@ -492,7 +493,7 @@ exports.nextSocket = function (socketPath) {
492493 * Note we export this so we can use it in our tests, otherwise this API is private
493494 */
494495exports . _defaultHosts = ( function ( ) {
495- var interfaces = { } ;
496+ let interfaces = { } ;
496497 try {
497498 interfaces = os . networkInterfaces ( ) ;
498499 }
@@ -514,13 +515,13 @@ exports._defaultHosts = (function() {
514515 }
515516 }
516517
517- var interfaceNames = Object . keys ( interfaces ) ,
518- hiddenButImportantHost = '0.0.0.0' , // !important - dont remove, hence the naming :)
519- results = [ hiddenButImportantHost ] ;
520- for ( var i = 0 ; i < interfaceNames . length ; i ++ ) {
521- var _interface = interfaces [ interfaceNames [ i ] ] ;
522- for ( var j = 0 ; j < _interface . length ; j ++ ) {
523- var curr = _interface [ j ] ;
518+ const interfaceNames = Object . keys ( interfaces ) ,
519+ hiddenButImportantHost = '0.0.0.0' , // !important - dont remove, hence the naming :)
520+ results = [ hiddenButImportantHost ] ;
521+ for ( let i = 0 ; i < interfaceNames . length ; i ++ ) {
522+ const _interface = interfaces [ interfaceNames [ i ] ] ;
523+ for ( let j = 0 ; j < _interface . length ; j ++ ) {
524+ const curr = _interface [ j ] ;
524525 results . push ( curr . address ) ;
525526 }
526527 }
0 commit comments