Skip to content

Commit f55942d

Browse files
authored
Bump various dependencies and devDependencies and drop support for node 14
* build: Bump pinned version of semver for security warning * build: Bump pinned version of tar to 6.x for security warning The breaking change is dropping Node 4–8 support; we require 14. * build: General npm audit bump to fix various upstream issues * build: Bump lowest version of coveralls devDependency * build: Bump lowest version of preq devDependency * build: Bump pinned version of mocha to 10.x The breaking change is dropping Node 12 support; we require 14. * build: Bump lowest version of yargs dependency No-op in practice, as we're already using said latest version. * build: Bump lowest version of bunyan dependency No-op in practice, as we're already using said latest version. * build: Bump eslint-config-wikimedia to 0.26.0. This requires Node 15 or higher. * CI: Drop Node 14 testing * build: Bump lowest version of semver dependency to 7.6.0
1 parent 3d6ca91 commit f55942d

File tree

16 files changed

+1609
-1323
lines changed

16 files changed

+1609
-1323
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"no-underscore-dangle": "off",
1212
"no-use-before-define": "off",
1313
"es-x/no-hashbang": "off",
14+
"n/no-process-exit": "off",
1415
"jsdoc/newline-after-description": "off"
1516
}
1617
}

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
strategy:
1111
matrix:
12-
node-version: [14.x, 16.x]
12+
node-version: [16.x]
1313

1414
steps:
1515
- uses: actions/checkout@v2

lib/base_service.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class BaseService {
7777
this._basePath = config.app_base_path;
7878
} else if ( /\/node_modules\/service-runner\/lib$/.test( __dirname ) ) {
7979
// Default to guessing the base path
80-
this._basePath = path.resolve( `${__dirname}/../../../` );
80+
this._basePath = path.resolve( `${ __dirname }/../../../` );
8181
} else {
8282
this._basePath = path.resolve( './' );
8383
}
@@ -109,7 +109,7 @@ class BaseService {
109109

110110
// display the version
111111
if ( this.options.displayVersion ) {
112-
console.log( `${config.serviceName} ${config.package.version}` );
112+
console.log( `${ config.serviceName } ${ config.package.version }` );
113113
process.exit( 0 );
114114
}
115115

@@ -337,7 +337,7 @@ class BaseService {
337337
let configFile = this.options.configFile;
338338
if ( !/^\//.test( configFile ) ) {
339339
// resolve relative paths
340-
configFile = path.resolve( `${process.cwd()}/${configFile}` );
340+
configFile = path.resolve( `${ process.cwd() }/${ configFile }` );
341341
}
342342
action = fs.readFileAsync( configFile )
343343
.then( ( yamlSource ) => yaml.load( this._replaceEnvVars( yamlSource ) ) );
@@ -349,7 +349,7 @@ class BaseService {
349349
let packageJson = {};
350350
try {
351351
// eslint-disable-next-line security/detect-non-literal-require
352-
packageJson = require( `${this._basePath}/package.json` );
352+
packageJson = require( `${ this._basePath }/package.json` );
353353
} catch ( e ) {
354354
// Ignore error.
355355
}
@@ -366,7 +366,7 @@ class BaseService {
366366
this.config = config;
367367
} )
368368
.catch( ( e ) => {
369-
console.error( `Error while reading config file: ${e}` );
369+
console.error( `Error while reading config file: ${ e }` );
370370
process.exit( 1 );
371371
} );
372372
}
@@ -412,7 +412,7 @@ class BaseService {
412412
} catch ( e ) {
413413
if ( path.isAbsolute( opts.mod ) ||
414414
( opts.baseTried && opts.modsTried ) ||
415-
!e.message.startsWith( `Cannot find module '${modName}'` ) ) {
415+
!e.message.startsWith( `Cannot find module '${ modName }'` ) ) {
416416
// we have a full path here which can't be required, we have tried
417417
// all of the possible combinations, or the error is not about not
418418
// finding modName, so bail out

lib/docker.js

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function promisedSpawn( args, options ) {
5555
let ret = '';
5656
let err = '';
5757
if ( opts.verbose ) {
58-
console.log( `# RUNNING: ${args.join( ' ' )}\n (in ${process.cwd()})` );
58+
console.log( `# RUNNING: ${ args.join( ' ' ) }\n (in ${ process.cwd() })` );
5959
}
6060
child = spawn( '/usr/bin/env', args, argOpts );
6161
if ( options.capture ) {
@@ -87,11 +87,11 @@ function promisedSpawn( args, options ) {
8787
if ( options.useErrHandler || options.errMessage ) {
8888
promise = promise.catch( ( err ) => {
8989
if ( options.errMessage ) {
90-
console.error( `ERROR: ${options.errMessage.split( '\n' ).join( '\nERROR: ' )}` );
90+
console.error( `ERROR: ${ options.errMessage.split( '\n' ).join( '\nERROR: ' ) }` );
9191
}
92-
let msg = `ERROR: ${args.slice( 0, 2 ).join( ' ' )} exited with code ${err.code}`;
92+
let msg = `ERROR: ${ args.slice( 0, 2 ).join( ' ' ) } exited with code ${ err.code }`;
9393
if ( err.message ) {
94-
msg += ` and message ${err.message}`;
94+
msg += ` and message ${ err.message }`;
9595
}
9696
console.error( msg );
9797
process.exit( err.code );
@@ -153,7 +153,7 @@ function createDockerFile() {
153153
// set the deploy target
154154
// allow the user to specify the exact target to use, like "debian:sid"
155155
const baseImg = /^.+:.+$/.test( pkg.deploy.target ) ? pkg.deploy.target : targets[ pkg.deploy.target ];
156-
let contents = `FROM ${baseImg}\n`;
156+
let contents = `FROM ${ baseImg }\n`;
157157

158158
if ( !baseImg || baseImg === '' ) {
159159
console.error( 'ERROR: You must specify a valid target!' );
@@ -172,13 +172,13 @@ function createDockerFile() {
172172
if ( pkg.uri ) {
173173
debPkgs.push( pkg.uri );
174174
} else if ( !pkg.repo_url || !pkg.pool || !pkg.packages || !pkg.release ) {
175-
console.error( `ERROR: Incorrect dependency spec: ${JSON.stringify( pkg )}` );
175+
console.error( `ERROR: Incorrect dependency spec: ${ JSON.stringify( pkg ) }` );
176176
process.exit( 1 );
177177
} else {
178178
customSourcePkgs.push( pkg );
179179
}
180180
} else {
181-
console.error( `ERROR: Incorrect dependency spec: ${pkg}` );
181+
console.error( `ERROR: Incorrect dependency spec: ${ pkg }` );
182182
process.exit( 1 );
183183
}
184184
} );
@@ -189,67 +189,67 @@ function createDockerFile() {
189189
extraPkgs.push( 'apt-transport-https' );
190190
}
191191

192-
contents += `RUN apt-get update && apt-get install -y ${extraPkgs.join( ' ' )} && rm -rf /var/lib/apt/lists/*\n`; /**/
192+
contents += `RUN apt-get update && apt-get install -y ${ extraPkgs.join( ' ' ) } && rm -rf /var/lib/apt/lists/*\n`; /**/
193193

194194
if ( customSourcePkgs.length ) {
195-
contents += `RUN echo > /etc/apt/sources.list && ${customSourcePkgs.map( ( customSourcePkgSpec ) =>
196-
`echo deb "${customSourcePkgSpec.repo_url} ${customSourcePkgSpec.release} ${customSourcePkgSpec.pool}" >> /etc/apt/sources.list` ).join( ' && ' )}\n`;
197-
contents += `RUN apt-get update && ${customSourcePkgs.map( ( customSourcePkgSpec ) => `apt-get install -y --force-yes -t ${customSourcePkgSpec.release} ${customSourcePkgSpec.packages.join( ' ' )}` ).join( ' && ' )} && rm -rf /var/lib/apt/lists/*\n`; /**/
195+
contents += `RUN echo > /etc/apt/sources.list && ${ customSourcePkgs.map( ( customSourcePkgSpec ) =>
196+
`echo deb "${ customSourcePkgSpec.repo_url } ${ customSourcePkgSpec.release } ${ customSourcePkgSpec.pool }" >> /etc/apt/sources.list` ).join( ' && ' ) }\n`;
197+
contents += `RUN apt-get update && ${ customSourcePkgs.map( ( customSourcePkgSpec ) => `apt-get install -y --force-yes -t ${ customSourcePkgSpec.release } ${ customSourcePkgSpec.packages.join( ' ' ) }` ).join( ' && ' ) } && rm -rf /var/lib/apt/lists/*\n`; /**/
198198
}
199199

200200
if ( debPkgs.length ) {
201-
contents += `RUN ${debPkgs.map( ( uri ) => `wget ${uri} -O package.deb && dpkg -i package.deb && rm package.deb` ).join( ' && ' )}\n`;
201+
contents += `RUN ${ debPkgs.map( ( uri ) => `wget ${ uri } -O package.deb && dpkg -i package.deb && rm package.deb` ).join( ' && ' ) }\n`;
202202
}
203203

204204
let npmCommand = 'npm';
205205
if ( nodeVersion !== 'system' ) {
206206
const nvmDownloadURI = 'https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh';
207207
contents += 'RUN mkdir -p /usr/local/nvm\n';
208208
contents += 'ENV NVM_DIR /usr/local/nvm\n';
209-
contents += `RUN wget -qO- ${nvmDownloadURI} | bash && . $NVM_DIR/nvm.sh && nvm install ${nodeVersion}\n`;
210-
npmCommand = `. $NVM_DIR/nvm.sh && nvm use ${nodeVersion} && npm`;
209+
contents += `RUN wget -qO- ${ nvmDownloadURI } | bash && . $NVM_DIR/nvm.sh && nvm install ${ nodeVersion }\n`;
210+
npmCommand = `. $NVM_DIR/nvm.sh && nvm use ${ nodeVersion } && npm`;
211211
}
212212

213213
if ( !opts.deploy ) {
214-
contents += `RUN mkdir /opt/service\nADD . /opt/service\nWORKDIR /opt/service\nRUN ${npmCommand} install && npm dedupe\n`;
214+
contents += `RUN mkdir /opt/service\nADD . /opt/service\nWORKDIR /opt/service\nRUN ${ npmCommand } install && npm dedupe\n`;
215215
}
216216

217217
if ( opts.uid !== 0 &&
218218
// In 'Docker for Mac' the mapping between users/groups
219219
// is done internally by docker, so we can run as root
220220
os.type() !== 'Darwin' ) {
221-
contents += `RUN groupadd -o -g ${opts.gid} -r rungroup && useradd -o -m -r -g rungroup -u ${opts.uid} runuser\nUSER runuser\nENV HOME=/home/runuser LINK=g++\n`;
221+
contents += `RUN groupadd -o -g ${ opts.gid } -r rungroup && useradd -o -m -r -g rungroup -u ${ opts.uid } runuser\nUSER runuser\nENV HOME=/home/runuser LINK=g++\n`;
222222
} else {
223223
contents += 'ENV HOME=/root/ LINK=g++\n';
224224
}
225225

226226
let envCommand = 'ENV IN_DOCKER=1';
227227
if ( pkg.deploy.env && Object.keys( pkg.deploy.env ) ) {
228228
Object.keys( pkg.deploy.env ).forEach( ( envVar ) => {
229-
envCommand += ` ${envVar}="${pkg.deploy.env[ envVar ]}"`;
229+
envCommand += ` ${ envVar }="${ pkg.deploy.env[ envVar ] }"`;
230230
} );
231231
}
232-
contents += `${envCommand}\n`;
232+
contents += `${ envCommand }\n`;
233233

234234
if ( opts.deploy ) {
235235
let beforeInstall = '';
236236
let afterInstall = '';
237237
if ( npmVersion ) {
238-
beforeInstall += `${npmCommand} install npm@${npmVersion} &&`;
238+
beforeInstall += `${ npmCommand } install npm@${ npmVersion } &&`;
239239
npmCommand = './node_modules/.bin/npm';
240240
afterInstall = '&& rm -rf ./node_modules/npm ./node_modules/.bin/npm';
241241
}
242242
let installOpts = ' --production ';
243243
if ( pkg.deploy.install_opts ) {
244-
installOpts += `${pkg.deploy.install_opts.join( ' ' )} `;
244+
installOpts += `${ pkg.deploy.install_opts.join( ' ' ) } `;
245245
}
246-
contents += `CMD ${beforeInstall} ${npmCommand} install${installOpts} ${afterInstall}`;
246+
contents += `CMD ${ beforeInstall } ${ npmCommand } install${ installOpts } ${ afterInstall }`;
247247
} else if ( opts.tests ) {
248-
contents += `CMD ${npmCommand} test`;
248+
contents += `CMD ${ npmCommand } test`;
249249
} else if ( opts.coverage ) {
250-
contents += `CMD ${npmCommand} run-script coverage`;
250+
contents += `CMD ${ npmCommand } run-script coverage`;
251251
} else {
252-
contents += `CMD ${npmCommand} start`;
252+
contents += `CMD ${ npmCommand } start`;
253253
}
254254

255255
return fs.writeFileAsync( 'Dockerfile', contents );
@@ -289,7 +289,7 @@ function startContainer( args, hidePorts ) {
289289
config.services.forEach( ( srv ) => {
290290
srv.conf = srv.conf || {};
291291
srv.conf.port = srv.conf.port || 8888;
292-
cmd.push( '-p', `${srv.conf.port}:${srv.conf.port}` );
292+
cmd.push( '-p', `${ srv.conf.port }:${ srv.conf.port }` );
293293
} );
294294
}
295295

@@ -321,7 +321,7 @@ function ensureDockerVersion() {
321321
const minimumDockerVersion = os.type() === 'Darwin' ? '1.12.0' : '1.8.0';
322322
dockerVersion = dockerVersion.replace( /\.0+(0|[1-9]+)/g, '.$1' );
323323
if ( semver.lt( dockerVersion, minimumDockerVersion ) ) {
324-
console.error( `Building the deploy repo on ${os.type()} supported only with docker ${minimumDockerVersion}+` );
324+
console.error( `Building the deploy repo on ${ os.type() } supported only with docker ${ minimumDockerVersion }+` );
325325
process.exit( 1 );
326326
}
327327
} );
@@ -368,10 +368,10 @@ function updateDeploy() {
368368
opts.name = props.name || pkg.name;
369369
opts.remote_name = props.remote || 'origin';
370370
opts.submodule_ref = props.submodule_ref ||
371-
`https://gerrit.wikimedia.org/r/mediawiki/services/${opts.name}`;
371+
`https://gerrit.wikimedia.org/r/mediawiki/services/${ opts.name }`;
372372
opts.src_branch = props.src_branch || 'master';
373373
opts.deploy_branch = props.deploy_branch || 'master';
374-
opts.remote_branch = `${opts.remote_name}/${opts.deploy_branch}`;
374+
opts.remote_branch = `${ opts.remote_name }/${ opts.deploy_branch }`;
375375
// we need to CHDIR into the deploy dir for subsequent operations
376376
process.chdir( opts.dir );
377377
return chainedPgit( [
@@ -392,25 +392,25 @@ function updateDeploy() {
392392
// update it fully
393393
return promisedGit( [ 'submodule', 'update', '--init' ] )
394394
.then( () => {
395-
process.chdir( `${opts.dir}/${opts.submodule}` );
395+
process.chdir( `${ opts.dir }/${ opts.submodule }` );
396396
return chainedPgit( [
397397
// fetch new commits
398398
[ 'fetch', 'origin' ],
399399
// inspect what has changed
400-
[ 'diff', '--name-only', `origin/${opts.src_branch}` ]
400+
[ 'diff', '--name-only', `origin/${ opts.src_branch }` ]
401401
] ).then( ( changes ) => {
402402
if ( /package\.json/.test( changes ) ) {
403403
// package.json has changed, so we need
404404
// to rebuild the node_modules directory
405405
opts.need_build = true;
406406
}
407407
// get the SHA1 of the latest commit on the src branch
408-
return promisedGit( [ 'rev-parse', '--short', `origin/${opts.src_branch}` ] );
408+
return promisedGit( [ 'rev-parse', '--short', `origin/${ opts.src_branch }` ] );
409409
} ).then( ( shortSha1 ) => {
410-
opts.commit_msg = `Update ${opts.name} to ${shortSha1}\n\n`;
410+
opts.commit_msg = `Update ${ opts.name } to ${ shortSha1 }\n\n`;
411411
// get a nice list of commits included in the change
412412
return promisedGit( [ 'log',
413-
`..origin/${opts.src_branch}`,
413+
`..origin/${ opts.src_branch }`,
414414
'--oneline',
415415
'--no-merges',
416416
'--reverse',
@@ -431,8 +431,8 @@ function updateDeploy() {
431431
} else if ( !logs ) {
432432
logs = '';
433433
}
434-
opts.commit_msg += `List of changes:\n${logs}`;
435-
return promisedGit( [ 'checkout', `origin/${opts.src_branch}` ] );
434+
opts.commit_msg += `List of changes:\n${ logs }`;
435+
return promisedGit( [ 'checkout', `origin/${ opts.src_branch }` ] );
436436
} ).then( () => {
437437
// go back to the root dir
438438
process.chdir( opts.dir );
@@ -444,14 +444,14 @@ function updateDeploy() {
444444
// no submodule, need to add it
445445
opts.submodule = 'src';
446446
opts.need_build = true;
447-
opts.commit_msg = `Initial import of ${opts.name}`;
447+
opts.commit_msg = `Initial import of ${ opts.name }`;
448448
return promisedGit( [ 'submodule',
449449
'add',
450450
opts.submodule_ref,
451451
opts.submodule ] );
452452
}
453453
} ).then( () => // make sure the package.json symlink is in place
454-
fs.symlinkAsync( `${opts.submodule}/package.json`, 'package.json' )
454+
fs.symlinkAsync( `${ opts.submodule }/package.json`, 'package.json' )
455455
.catch( () => {} ).then( () => promisedGit( [ 'add', 'package.json' ] ) ) ).then( () => {
456456
if ( !opts.need_build ) {
457457
return;
@@ -465,7 +465,7 @@ function updateDeploy() {
465465
.then( () => promisedSpawn( [ 'rm', '-rf', 'node_modules' ],
466466
{ capture: true, ignoreErr: true } ) )
467467
// start the container which builds the modules
468-
.then( () => startContainer( [ '-v', `${opts.dir}:/opt/service`, '-w', '/opt/service' ], true ) )
468+
.then( () => startContainer( [ '-v', `${ opts.dir }:/opt/service`, '-w', '/opt/service' ], true ) )
469469
.then( () => {
470470
// remove unnecessary files
471471
let findAttr;
@@ -497,7 +497,7 @@ function updateDeploy() {
497497
.then( () => {
498498
if ( !opts.review ) {
499499
console.log( '\n\nChanges are sitting in the sync-repo branch in' );
500-
console.log( `${opts.dir} with the commit:` );
500+
console.log( `${ opts.dir } with the commit:` );
501501
console.log( opts.commit_msg );
502502
return;
503503
}
@@ -532,12 +532,12 @@ function getUid() {
532532
).then( ( dir ) => {
533533
opts.dir = dir;
534534
// make sure that the dir exists and it is a git repo
535-
return fs.statAsync( `${dir}/.git` );
535+
return fs.statAsync( `${ dir }/.git` );
536536
} ).then( ( stat ) => {
537537
opts.uid = stat.uid;
538538
opts.gid = stat.gid;
539539
} ).catch( () => {
540-
console.error( `ERROR: The deploy repo dir ${opts.dir} does not exist or is not a git repo!` );
540+
console.error( `ERROR: The deploy repo dir ${ opts.dir } does not exist or is not a git repo!` );
541541
process.exit( 3 );
542542
} );
543543
}
@@ -604,7 +604,7 @@ function main( options, configuration ) {
604604
imgName += '-deploy';
605605
}
606606
// the container's name
607-
name = `${pkg.name}-${Date.now()}-${Math.floor( Math.random() * 1000 )}`;
607+
name = `${ pkg.name }-${ Date.now() }-${ Math.floor( Math.random() * 1000 ) }`;
608608

609609
// trap exit signals
610610
process.on( 'SIGINT', sigHandle );

lib/logger.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class NamedLevelStdout extends Writable {
1818
super( Object.assign( options, { objectMode: true } ) );
1919
this.downstream = downstream;
2020
}
21+
2122
_write( logEntry, encoding, callback ) {
2223
logEntry.level = bunyan.nameFromLevel[ logEntry.level ].toUpperCase();
2324
this.downstream.write(
@@ -26,6 +27,7 @@ class NamedLevelStdout extends Writable {
2627
callback
2728
);
2829
}
30+
2931
destroy() {
3032
super.destroy();
3133
this.downstream.destroy();
@@ -230,7 +232,7 @@ class Logger {
230232
const pos = LEVELS.indexOf( level );
231233
if ( pos !== -1 ) {
232234
// eslint-disable-next-line security/detect-non-literal-regexp
233-
return new RegExp( `^(${LEVELS.slice( pos ).join( '|' )})(?=/|$)` );
235+
return new RegExp( `^(${ LEVELS.slice( pos ).join( '|' ) })(?=/|$)` );
234236
} else {
235237
// Match nothing
236238
return /^$/;

lib/master.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class Master extends BaseService {
110110

111111
// Fork workers.
112112
this._logger.log( 'info/service-runner',
113-
`master(${process.pid}) initializing ${this.config.num_workers} workers` );
113+
`master(${ process.pid }) initializing ${ this.config.num_workers } workers` );
114114

115115
process.on( 'SIGINT', this._shutdownMasterHandler );
116116
process.on( 'SIGTERM', this._shutdownMasterHandler );
@@ -289,13 +289,14 @@ class Master extends BaseService {
289289
return; // Ignore prom-client internal communication.
290290
default:
291291
this._logger.log( 'error/service-runner/master',
292-
`unknown message type received from worker ${msg.type}` );
292+
`unknown message type received from worker ${ msg.type }` );
293293
}
294294
};
295295

296296
worker.on( 'message', workerMessageHandler );
297297
} );
298298
}
299+
299300
// Fork a single worker, wait for it to start executing and set everything up,
300301
// and then fork all the rest of the workers.
301302
_startWorkers( workersToStart ) {

0 commit comments

Comments
 (0)