Skip to content

Commit 831adff

Browse files
committed
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
2 parents 5fcd4cb + bcabda6 commit 831adff

File tree

3 files changed

+150
-3
lines changed

3 files changed

+150
-3
lines changed

.travis.yml

+15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ cache:
88

99
matrix:
1010
include:
11+
- name: 'Lowest versions of the dependencies'
12+
os: linux
13+
node_js: "10"
14+
env: JOB_PART=test
15+
install:
16+
- rm yarn.lock
17+
- node ./scripts/force-lowest-dependencies
18+
- yarn
19+
- name: 'Highest versions of the dependencies'
20+
os: linux
21+
node_js: "10"
22+
env: JOB_PART=test
23+
install:
24+
- rm yarn.lock
25+
- yarn
1126
- os: linux
1227
node_js: "10"
1328
env: JOB_PART=travis:lint

scripts/force-lowest-dependencies.js

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* This file is part of the Symfony Webpack Encore package.
3+
*
4+
* (c) Fabien Potencier <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
'use strict';
11+
12+
const fs = require('fs');
13+
const childProcess = require('child_process');
14+
15+
function getLowestVersion(dependency, range) {
16+
return new Promise((resolve, reject) => {
17+
childProcess.exec(
18+
`npm view "${dependency}@${range}" version`,
19+
{ encoding: 'utf-8' },
20+
(error, stdout) => {
21+
if (error) {
22+
reject(`Could not retrieve versions list for "${dependency}@${range}"`);
23+
return;
24+
}
25+
26+
const versions = stdout
27+
.split('\n')
28+
.filter(line => line);
29+
30+
if (versions.length === 0) {
31+
reject(`Could not find a lowest version for "${dependency}@${range}"`);
32+
return;
33+
}
34+
35+
const parts = versions[0].split(' ');
36+
37+
// If there is only one version available that version
38+
// is directly printed as the output of npm view.
39+
if (parts.length === 1) {
40+
resolve([dependency, parts[0]]);
41+
return;
42+
}
43+
44+
// If multiple versions are available then it outputs
45+
// multiple lines matching the following format:
46+
// <package>@<version> '<version>'
47+
if (parts.length === 2) {
48+
resolve([dependency, parts[1].replace(/'/g, '')]);
49+
return;
50+
}
51+
52+
reject(`Unexpected response for "${dependency}@${range}": ${versions[0]}`);
53+
}
54+
);
55+
});
56+
}
57+
58+
fs.readFile('package.json', (error, data) => {
59+
if (error) {
60+
throw error;
61+
}
62+
63+
const packageInfo = JSON.parse(data);
64+
65+
const dependencyPromises = [];
66+
if (packageInfo.dependencies) {
67+
for (const dependency in packageInfo.dependencies) {
68+
dependencyPromises.push(getLowestVersion(
69+
dependency,
70+
packageInfo.dependencies[dependency]
71+
));
72+
}
73+
}
74+
75+
const devDependencyPromises = [];
76+
if (packageInfo.devDependencies) {
77+
for (const devDependency in packageInfo.devDependencies) {
78+
devDependencyPromises.push(getLowestVersion(
79+
devDependency,
80+
packageInfo.devDependencies[devDependency]
81+
));
82+
}
83+
}
84+
85+
const dependenciesUpdate = Promise.all(dependencyPromises).then(versions => {
86+
versions.forEach(version => {
87+
packageInfo.dependencies[version[0]] = version[1];
88+
});
89+
});
90+
91+
const devDependenciesUpdate = Promise.all(devDependencyPromises).then(versions => {
92+
versions.forEach(version => {
93+
packageInfo.devDependencies[version[0]] = version[1];
94+
});
95+
});
96+
97+
// Once all the lowest versions have been resolved, update the
98+
// package.json file accordingly.
99+
Promise
100+
.all([dependenciesUpdate, devDependenciesUpdate])
101+
.then(() => new Promise((resolve, reject) => {
102+
fs.writeFile('package.json', JSON.stringify(packageInfo, null, 2), (error) => {
103+
if (error) {
104+
reject(error);
105+
return;
106+
}
107+
108+
resolve();
109+
});
110+
}))
111+
.then(() => {
112+
console.log('Updated package.json file with lowest dependency versions: ');
113+
114+
console.log('Dependencies:');
115+
for (const dependency in packageInfo.dependencies) {
116+
console.log(` - ${dependency}: ${packageInfo.dependencies[dependency]}`);
117+
}
118+
119+
console.log('Dev dependencies:');
120+
for (const dependency in packageInfo.devDependencies) {
121+
console.log(` - ${dependency}: ${packageInfo.devDependencies[dependency]}`);
122+
}
123+
})
124+
.catch(error => {
125+
console.error(error);
126+
process.exit(1); // eslint-disable-line
127+
});
128+
});

test/package-helper.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const expect = require('chai').expect;
1313
const packageHelper = require('../lib/package-helper');
1414
const path = require('path');
1515
const process = require('process');
16+
const fs = require('fs');
1617

1718
describe('package-helper', () => {
1819
const baseCwd = process.cwd();
@@ -135,14 +136,17 @@ describe('package-helper', () => {
135136

136137
describe('addPackagesVersionConstraint', () => {
137138
it('Lookup a version constraint', () => {
138-
// hardcoding sass-loader: test WILL break when this changes
139-
140139
const inputPackages = [
141140
{ name: 'sass-loader', enforce_version: 7 },
142141
{ name: 'node-sass' }
143142
];
143+
144+
const packageInfo = JSON.parse(
145+
fs.readFileSync(path.join(__dirname, '../package.json'))
146+
);
147+
144148
const expectedPackages = [
145-
{ name: 'sass-loader', version: '^7.0.1' },
149+
{ name: 'sass-loader', version: packageInfo.devDependencies['sass-loader'] },
146150
{ name: 'node-sass' }
147151
];
148152

0 commit comments

Comments
 (0)