Mwalker has submitted this change and it was merged. Change subject: Update `unify-package-json` to use ES6 Promises. ......................................................................
Update `unify-package-json` to use ES6 Promises. Change-Id: I04e07418d4a8d757f64281f68b3e1a2424cade8e --- M Makefile M unify-package-json.js 2 files changed, 14 insertions(+), 13 deletions(-) Approvals: Mwalker: Verified; Looks good to me, approved diff --git a/Makefile b/Makefile index 6eb4a80..1973916 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ export LINK=g++ rm -f ./package.json npm cache clear - npm install when semver + npm install prfun semver ./unify-package-json.js npm install npm update diff --git a/unify-package-json.js b/unify-package-json.js index 2234c6a..998cb1e 100755 --- a/unify-package-json.js +++ b/unify-package-json.js @@ -7,8 +7,8 @@ * It will throw errors if multiple files reference different versions of the * same upstream package. * - * Ironically; this script itself has dependencies in the form of the when library - * (because node.js for some stupid reason doesn't include promises anymore) + * Ironically; this script itself has dependencies in the form of the `prfun` + * library (since we want to use fancy non-standard Promise features). */ var child_process = require( 'child_process' ), @@ -17,13 +17,13 @@ util = require( 'util' ); try { - var when = require('when'); + require('prfun'); } catch ( err ) { - console.err( "The 'when' library could not be loaded. Please `npm install when`") + console.err( "The 'prfun' library could not be loaded. Please `npm install prfun`") } function findPackageJson() { - return when.promise( function( resolve, reject, notify ) { + return new Promise( function( resolve, reject ) { child_process.exec( 'find . -path ./node_modules -prune -o -name package.json -print', function( error, stdout, stderr ) { @@ -35,8 +35,7 @@ } function readPackageJson( files ) { - return when.map( - files, + return files.map( function( file ) { return require( file ); } @@ -134,16 +133,18 @@ devDependencies: deps.devDependencies }; - fs.writeFile( 'package.json', JSON.stringify( packageObj, null, 2 ), function( err ) { - console.log('wrote file'); - } ); + var writeFile = Promise.promisify(fs.writeFile, fs); + return writeFile( 'package.json', JSON.stringify( packageObj, null, 2 ) ). + then(function() { + console.log('wrote file'); + } ); } /* === Glue logic === */ findPackageJson() .then( readPackageJson ) - .then( when.lift( buildDependencies ) ) + .then( Promise.method( buildDependencies ) ) .then( writePackageJson ) - .catch( function( err ) { console.error( err ) }); + .done(); -- To view, visit https://gerrit.wikimedia.org/r/138621 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I04e07418d4a8d757f64281f68b3e1a2424cade8e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/ocg-collection Gerrit-Branch: wmf-deploy Gerrit-Owner: Cscott <canan...@wikimedia.org> Gerrit-Reviewer: Mwalker <mwal...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits