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 {
@@ -252,7 +253,7 @@ exports.getPorts = function (count, options, callback) {
252253 options = { } ;
253254 }
254255
255- var lastPort = null ;
256+ let lastPort = null ;
256257 _async . timesSeries ( count , function ( index , asyncCallback ) {
257258 if ( lastPort ) {
258259 options . port = exports . nextPort ( lastPort ) ;
@@ -355,7 +356,7 @@ exports.getSocket = function (options, callback) {
355356 // then test connection.
356357 //
357358 function checkAndTestSocket ( ) {
358- var dir = path . dirname ( options . path ) ;
359+ const dir = path . dirname ( options . path ) ;
359360
360361 fs . stat ( dir , function ( err , stats ) {
361362 if ( err || ! stats . isDirectory ( ) ) {
@@ -394,11 +395,11 @@ exports.nextPort = function (port) {
394395// specified `socketPath`.
395396//
396397exports . nextSocket = function ( socketPath ) {
397- var dir = path . dirname ( socketPath ) ,
398- name = path . basename ( socketPath , '.sock' ) ,
399- match = name . match ( / ^ ( [ a - z A - z ] + ) ( \d * ) $ / i) ,
400- index = parseInt ( match [ 2 ] ) ,
401- base = match [ 1 ] ;
398+ const dir = path . dirname ( socketPath ) ,
399+ name = path . basename ( socketPath , '.sock' ) ,
400+ match = name . match ( / ^ ( [ a - z A - z ] + ) ( \d * ) $ / i) ,
401+ base = match [ 1 ] ;
402+ let index = parseInt ( match [ 2 ] ) ;
402403 if ( isNaN ( index ) ) {
403404 index = 0 ;
404405 }
@@ -484,7 +485,7 @@ exports.nextSocket = function (socketPath) {
484485 * Note we export this so we can use it in our tests, otherwise this API is private
485486 */
486487exports . _defaultHosts = ( function ( ) {
487- var interfaces = { } ;
488+ let interfaces = { } ;
488489 try {
489490 interfaces = os . networkInterfaces ( ) ;
490491 }
@@ -506,13 +507,13 @@ exports._defaultHosts = (function() {
506507 }
507508 }
508509
509- var interfaceNames = Object . keys ( interfaces ) ,
510- hiddenButImportantHost = '0.0.0.0' , // !important - dont remove, hence the naming :)
511- results = [ hiddenButImportantHost ] ;
512- for ( var i = 0 ; i < interfaceNames . length ; i ++ ) {
513- var _interface = interfaces [ interfaceNames [ i ] ] ;
514- for ( var j = 0 ; j < _interface . length ; j ++ ) {
515- var curr = _interface [ j ] ;
510+ const interfaceNames = Object . keys ( interfaces ) ,
511+ hiddenButImportantHost = '0.0.0.0' , // !important - dont remove, hence the naming :)
512+ results = [ hiddenButImportantHost ] ;
513+ for ( let i = 0 ; i < interfaceNames . length ; i ++ ) {
514+ const _interface = interfaces [ interfaceNames [ i ] ] ;
515+ for ( let j = 0 ; j < _interface . length ; j ++ ) {
516+ const curr = _interface [ j ] ;
516517 results . push ( curr . address ) ;
517518 }
518519 }
0 commit comments