mirror of https://github.com/embarklabs/embark.git
refactor: modify check-yarn-lock.js to use a blacklist instead of a whitelist
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.
This commit is contained in:
parent
bc92b7aac5
commit
469504f3b2
|
@ -1,26 +1,30 @@
|
||||||
const {readFileSync} = require('fs');
|
const { execSync } = require('child_process');
|
||||||
const {join} = require('path');
|
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 {
|
try {
|
||||||
const yarnLock = readFileSync(join(__dirname, '..', 'yarn.lock')).toString();
|
const yarnLock = readFileSync(join(__dirname, '..', 'yarn.lock')).toString();
|
||||||
const embarkPkgs = yarnLock.match(/embark(js)?(-\S+)?@|@embarklabs\/\S+@/g);
|
const embarkPkgs = yarnLock
|
||||||
const badSpecTest = spec => (
|
.match(/embark(js)?(-\S+)?@|@embarklabs\/\S+@/g)
|
||||||
!(spec.startsWith('embark-test-contract-') ||
|
.map(match => match.slice(0, -1));
|
||||||
spec.startsWith('@embarklabs/ethereumjs-wallet'))
|
const badPkgTest = pkgName => allPackagesNames.has(pkgName);
|
||||||
);
|
if (embarkPkgs && embarkPkgs.some(badPkgTest)) {
|
||||||
if (embarkPkgs &&
|
let badPkgNames = [...(new Set(embarkPkgs))].filter(badPkgTest);
|
||||||
embarkPkgs.some(badSpecTest)) {
|
const plur = badPkgNames.length > 1;
|
||||||
let badSpecs = [...(new Set(embarkPkgs))]
|
|
||||||
.filter(badSpecTest)
|
|
||||||
.map(spec => spec.slice(0, -1));
|
|
||||||
const plur = badSpecs.length > 1;
|
|
||||||
console.error();
|
console.error();
|
||||||
console.error(
|
console.error(
|
||||||
[
|
[
|
||||||
`Found specifier${plur ? 's' : ''} for ${badSpecs.join(', ')} in the`,
|
`Found specifier${plur ? 's' : ''} for ${badPkgNames.join(', ')} in`,
|
||||||
`root yarn.lock file.\n\nThis probably happened because some package's`,
|
`the root yarn.lock file.\n\nThis probably happened because some`,
|
||||||
`version and/or dev/Deps specifiers need to be adjusted relative to`,
|
`package's version and/or dev/Deps specifiers need to be adjusted`,
|
||||||
`the current versions in the master branch.`
|
`relative to the current versions in the master branch.`
|
||||||
].join(' ')
|
].join(' ')
|
||||||
);
|
);
|
||||||
console.error();
|
console.error();
|
||||||
|
|
Loading…
Reference in New Issue