-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor #403 Add new Travis jobs to test lowest/highest versions of all…
… the dependencies (Lyrkan) This PR was squashed before being merged into the master branch (closes #403). Discussion ---------- Add new Travis jobs to test lowest/highest versions of all the dependencies This PR adds two Travis jobs that allow to test the lowest and highest versions of all the dependencies (including the dev ones since the version ranges are used by the package helper). I wasn't sure about the method to use for the lowest versions since we can't really guess them without calling the npm's registry API. So, if someone has a better idea... :) Note that both jobs currently fail for the following reasons: - Lowest versions: This isn't really an issue since it seems related to Webpack 4 for which we haven't released a version yet. We could increase the minimum version to match the one from the `yarn.lock` file before releasing. - Highest versions: This is caused by the last version of the `mini-css-extract-plugin` (0.4.3) which doesn't seem to work well with the `webpack-manifest-plugin` anymore (see webpack-contrib/mini-css-extract-plugin#177 (comment)). Closes #39. Commits ------- bcabda6 Add some missing 'return' statements 0161000 Remove hardcoded sass-loader version in addPackagesVersionConstraint test 7abea75 Add new Travis jobs to test lowest/highest versions of all the dependencies
- Loading branch information
Showing
3 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* This file is part of the Symfony Webpack Encore package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const childProcess = require('child_process'); | ||
|
||
function getLowestVersion(dependency, range) { | ||
return new Promise((resolve, reject) => { | ||
childProcess.exec( | ||
`npm view "${dependency}@${range}" version`, | ||
{ encoding: 'utf-8' }, | ||
(error, stdout) => { | ||
if (error) { | ||
reject(`Could not retrieve versions list for "${dependency}@${range}"`); | ||
return; | ||
} | ||
|
||
const versions = stdout | ||
.split('\n') | ||
.filter(line => line); | ||
|
||
if (versions.length === 0) { | ||
reject(`Could not find a lowest version for "${dependency}@${range}"`); | ||
return; | ||
} | ||
|
||
const parts = versions[0].split(' '); | ||
|
||
// If there is only one version available that version | ||
// is directly printed as the output of npm view. | ||
if (parts.length === 1) { | ||
resolve([dependency, parts[0]]); | ||
return; | ||
} | ||
|
||
// If multiple versions are available then it outputs | ||
// multiple lines matching the following format: | ||
// <package>@<version> '<version>' | ||
if (parts.length === 2) { | ||
resolve([dependency, parts[1].replace(/'/g, '')]); | ||
return; | ||
} | ||
|
||
reject(`Unexpected response for "${dependency}@${range}": ${versions[0]}`); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
fs.readFile('package.json', (error, data) => { | ||
if (error) { | ||
throw error; | ||
} | ||
|
||
const packageInfo = JSON.parse(data); | ||
|
||
const dependencyPromises = []; | ||
if (packageInfo.dependencies) { | ||
for (const dependency in packageInfo.dependencies) { | ||
dependencyPromises.push(getLowestVersion( | ||
dependency, | ||
packageInfo.dependencies[dependency] | ||
)); | ||
} | ||
} | ||
|
||
const devDependencyPromises = []; | ||
if (packageInfo.devDependencies) { | ||
for (const devDependency in packageInfo.devDependencies) { | ||
devDependencyPromises.push(getLowestVersion( | ||
devDependency, | ||
packageInfo.devDependencies[devDependency] | ||
)); | ||
} | ||
} | ||
|
||
const dependenciesUpdate = Promise.all(dependencyPromises).then(versions => { | ||
versions.forEach(version => { | ||
packageInfo.dependencies[version[0]] = version[1]; | ||
}); | ||
}); | ||
|
||
const devDependenciesUpdate = Promise.all(devDependencyPromises).then(versions => { | ||
versions.forEach(version => { | ||
packageInfo.devDependencies[version[0]] = version[1]; | ||
}); | ||
}); | ||
|
||
// Once all the lowest versions have been resolved, update the | ||
// package.json file accordingly. | ||
Promise | ||
.all([dependenciesUpdate, devDependenciesUpdate]) | ||
.then(() => new Promise((resolve, reject) => { | ||
fs.writeFile('package.json', JSON.stringify(packageInfo, null, 2), (error) => { | ||
if (error) { | ||
reject(error); | ||
return; | ||
} | ||
|
||
resolve(); | ||
}); | ||
})) | ||
.then(() => { | ||
console.log('Updated package.json file with lowest dependency versions: '); | ||
|
||
console.log('Dependencies:'); | ||
for (const dependency in packageInfo.dependencies) { | ||
console.log(` - ${dependency}: ${packageInfo.dependencies[dependency]}`); | ||
} | ||
|
||
console.log('Dev dependencies:'); | ||
for (const dependency in packageInfo.devDependencies) { | ||
console.log(` - ${dependency}: ${packageInfo.devDependencies[dependency]}`); | ||
} | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
process.exit(1); // eslint-disable-line | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters