Skip to content

Commit

Permalink
refactor: modify check-yarn-lock.js to use a blacklist instead of a w…
Browse files Browse the repository at this point in the history
…hitelist

Refactor `scripts/check-yarn-lock.js` to use a dynamically calculated
blacklist (`npx lerna ls --all --json`) instead of a hard-coded whitelist to
improve accuracy and reduce future maintenance.
  • Loading branch information
michaelsbradleyjr committed Mar 23, 2020
1 parent bc92b7a commit 469504f
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions scripts/check-yarn-lock.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
const {readFileSync} = require('fs');
const {join} = require('path');
const { execSync } = require('child_process');
const { readFileSync } = require('fs');
const { join } = require('path');

const allPackages = JSON.parse(execSync(
'npx lerna ls --all --json',
{cwd: join(__dirname, '..'), stdio: ['pipe', 'pipe', 'ignore']}
).toString().trim());

const allPackagesNames = new Set(allPackages.map(pkg => pkg.name));

try {
const yarnLock = readFileSync(join(__dirname, '..', 'yarn.lock')).toString();
const embarkPkgs = yarnLock.match(/embark(js)?(-\S+)?@|@embarklabs\/\S+@/g);
const badSpecTest = spec => (
!(spec.startsWith('embark-test-contract-') ||
spec.startsWith('@embarklabs/ethereumjs-wallet'))
);
if (embarkPkgs &&
embarkPkgs.some(badSpecTest)) {
let badSpecs = [...(new Set(embarkPkgs))]
.filter(badSpecTest)
.map(spec => spec.slice(0, -1));
const plur = badSpecs.length > 1;
const embarkPkgs = yarnLock
.match(/embark(js)?(-\S+)?@|@embarklabs\/\S+@/g)
.map(match => match.slice(0, -1));
const badPkgTest = pkgName => allPackagesNames.has(pkgName);
if (embarkPkgs && embarkPkgs.some(badPkgTest)) {
let badPkgNames = [...(new Set(embarkPkgs))].filter(badPkgTest);
const plur = badPkgNames.length > 1;
console.error();
console.error(
[
`Found specifier${plur ? 's' : ''} for ${badSpecs.join(', ')} in the`,
`root yarn.lock file.\n\nThis probably happened because some package's`,
`version and/or dev/Deps specifiers need to be adjusted relative to`,
`the current versions in the master branch.`
`Found specifier${plur ? 's' : ''} for ${badPkgNames.join(', ')} in`,
`the root yarn.lock file.\n\nThis probably happened because some`,
`package's version and/or dev/Deps specifiers need to be adjusted`,
`relative to the current versions in the master branch.`
].join(' ')
);
console.error();
Expand Down

0 comments on commit 469504f

Please sign in to comment.