Skip to content

Commit 5b9ea00

Browse files
committed
build: resolve latest MDC version through yarn
Uses Yarn to resolve the latest canary version of MDC in an attempt to avoid flakes due to mismatches.
1 parent 3ae6124 commit 5b9ea00

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

scripts/circleci/setup-mdc-canary.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
const {join} = require('path');
2-
const {spawn} = require('child_process');
2+
const {spawn, spawnSync} = require('child_process');
33
const packageJson = require(join(__dirname, '../../package.json'));
4+
5+
// Note that yarn also has a `versions` field, but it appears to be sorting canary versions
6+
// alphabetically so we can't depend on it. Instead we use `time` which is a version to time map.
7+
const versionsProcess = spawnSync('yarn', ['info', 'material-components-web', 'time', '--json'], {
8+
shell: true
9+
});
10+
let versions = null;
11+
12+
try {
13+
versions = JSON.parse(versionsProcess.stdout).data;
14+
} catch (e) {
15+
console.error('Failed to retrieve latest MDC version');
16+
throw e;
17+
}
18+
19+
const latestCanaryVersion = Object.keys(versions)
20+
.filter(key => key.includes('-canary'))
21+
.sort((a, b) => new Date(versions[a]) - new Date(versions[b]))
22+
.pop();
23+
424
const pattern = /^material-components-web$|^@material\//;
525
const params = Object.keys(packageJson.devDependencies)
626
.filter(dependency => pattern.test(dependency))
7-
.reduce((mdcDependencies, dependency) => [...mdcDependencies, `${dependency}@canary`], []);
27+
.reduce((mdcDependencies, dependency) =>
28+
[...mdcDependencies, `${dependency}@${latestCanaryVersion}`], []);
829

930
if (!params.length) {
1031
throw Error(`Could not find MDC dependencies in package.json`);
1132
}
1233

13-
console.log('Updating all MDC dependencies to latest canary version');
34+
console.log(`Updating all MDC dependencies to version ${latestCanaryVersion}`);
1435
const childProcess = spawn('yarn', ['add', ...params, '-D'], {shell: true});
1536
childProcess.stdout.on('data', data => console.log(data + ''));
1637
childProcess.stderr.on('data', data => console.error(data + ''));

0 commit comments

Comments
 (0)