Mwalker has submitted this change and it was merged. Change subject: Updating make files per changes to production branch ......................................................................
Updating make files per changes to production branch Change-Id: I635986e8be4a155bf35db1c0aa1744fc6769f49b --- M Makefile M unify-package-json.js 2 files changed, 54 insertions(+), 72 deletions(-) Approvals: Mwalker: Verified; Looks good to me, approved diff --git a/Makefile b/Makefile index 5c92ee5..1973916 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,9 @@ core: export LINK=g++ - npm install semver when + rm -f ./package.json + npm cache clear + npm install prfun semver ./unify-package-json.js npm install npm update @@ -16,6 +18,4 @@ npm prune clean: - rm -f ./package.json - npm cache clear rm -rf ./node_modules diff --git a/unify-package-json.js b/unify-package-json.js index 2234c6a..6791543 100755 --- a/unify-package-json.js +++ b/unify-package-json.js @@ -7,36 +7,35 @@ * 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' ), semver = require( 'semver' ), fs = require( 'fs' ), + path = require( 'path' ), 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 ) { - child_process.exec( - 'find . -path ./node_modules -prune -o -name package.json -print', - function( error, stdout, stderr ) { - files = stdout.trim().split( '\n' ); - resolve( files ); - } - ) + var readdir = Promise.promisify(fs.readdir, fs); + return readdir( __dirname ).then( function( files ) { + return files.map( function( f ) { + return path.join( __dirname, f, "package.json" ); + } ).filter( function ( f ) { + return fs.existsSync( f ); + } ); } ); } function readPackageJson( files ) { - return when.map( - files, + return files.map( function( file ) { return require( file ); } @@ -46,64 +45,45 @@ function buildDependencies( packageObjs ) { var glodeps, optdeps, glodevdeps; var iterate = function iterate( key, arrayObj ) { - var unifiedDeps = {}; + var unifiedDeps = new Map(); arrayObj.forEach( function( el ) { var name = el.name, - packdeps = el[key], - pkg, glover, pkgver; + packdeps = el[key] || {}; - for ( pkg in packdeps ) { - if ( !packdeps.hasOwnProperty( pkg ) ) { - continue; + Object.keys(packdeps).forEach( function( pkg ) { + var pkgver = packdeps[pkg]; + if ( !unifiedDeps.has( pkg ) ) { + unifiedDeps.set( pkg, new Map() ); } - - if ( pkg in unifiedDeps ) { - // Check to see if the versions are compatible - glover = unifiedDeps[pkg][0]; - pkgver = packdeps[pkg]; - - // Strict equality is nice; they need the same thing - if ( glover === pkgver ) { - continue; - } - - // If either is an approximate version (major / minor match) strip - // the tidle so semver can process and then see if the other requirement matches - if ( glover[0] === '~' && semver.satisfies( glover.substr( 1 ), pkgver ) ) { - continue; - } - if ( pkgver[0] === '~' && semver.satisfies( pkgver.substr( 1 ), glover ) ) { - continue; - } - - // TODO: Handle greater than / less than. - - console.error( - util.format( - 'Could not reconcile common dependency on %s. %s requires %s where %s requires %s.', - pkg, - unifiedDeps[pkg][1], glover, - name, pkgver - ) - ); - - } else { - // Not already used, just add it - unifiedDeps[pkg] = [packdeps[pkg], name]; + var vermap = unifiedDeps.get( pkg ); + if ( !vermap.has( pkgver ) ) { + vermap.set( pkgver, new Set() ); } + vermap.get( pkgver ).add( name ); + } ); + } ); + // Go through and combine versions for a given package with the + // "and" operator (which for semver is a space) and let npm figure + // out how to satisfy the conflict. But emit diagnostics on + // stderr to help us debug this if necessary. + var result = {}; + unifiedDeps.forEach( function( vermap, pkg ) { + result[ pkg ] = Array.from( vermap.keys() ).join( ' ' ); + var who = Array.from( vermap.values() ); + if ( who.length > 1 ) { + console.warn( + util.format( + '* Could not reconcile common dependency on %s. (%s)', + pkg, + who.map( function( s ) { + return Array.from( s.values() ).join(' '); + }).join(', ') + ) + ); } } ); - - // Clean the metadata we left - for ( dep in unifiedDeps ) { - if ( !unifiedDeps.hasOwnProperty( dep ) ) { - continue; - } - unifiedDeps[dep] = unifiedDeps[dep][0]; - } - - return unifiedDeps; + return result; }; console.info( 'Unifying runtime dependencies' ); @@ -134,16 +114,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/138728 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I635986e8be4a155bf35db1c0aa1744fc6769f49b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/ocg-collection Gerrit-Branch: master Gerrit-Owner: Mwalker <mwal...@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