cli: Log warning if unable to parse yarn.lock

Signed-off-by: Mustansar Anwar ul Samad <mustansar.samad@gmail.com>
This commit is contained in:
Mustansar Anwar ul Samad
2022-01-27 12:03:26 +13:00
parent 5148c4f29d
commit 80f510caee
2 changed files with 48 additions and 18 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Log warning if unable to parse yarn.lock
+43 -18
View File
@@ -25,31 +25,56 @@ import { Lockfile } from '../../lib/versioning';
import { forbiddenDuplicatesFilter, includedFilter } from '../versions/lint';
export default async (cmd: Command) => {
const lockfile = await Lockfile.load(paths.resolveTargetRoot('yarn.lock'));
const result = lockfile.analyze({
filter: includedFilter,
});
const problemPackages = [...result.newVersions, ...result.newRanges]
.map(({ name }) => name)
.filter(name => forbiddenDuplicatesFilter(name));
const lockFilePath = paths.resolveTargetRoot('yarn.lock');
if (fs.existsSync(lockFilePath)) {
try {
const lockfile = await Lockfile.load(lockFilePath);
const result = lockfile.analyze({
filter: includedFilter,
});
const problemPackages = [...result.newVersions, ...result.newRanges]
.map(({ name }) => name)
.filter(name => forbiddenDuplicatesFilter(name));
if (problemPackages.length > 0) {
if (problemPackages.length > 0) {
console.log(
chalk.yellow(
`⚠️ Some of the following packages may be outdated or have duplicate installations:
${uniq(problemPackages).join(', ')}
`,
),
);
console.log(
chalk.yellow(
`⚠️ The following command may fix the issue, but it could also be an issue within one of your dependencies:
yarn backstage-cli versions:check --fix
`,
),
);
}
} catch (error) {
console.log(
chalk.yellow(
`⚠️ Unable to parse yarn.lock file properly:
${error}
skipping analyzer for outdated or duplicate installations
`,
),
);
}
} else {
console.log(
chalk.yellow(
`⚠️ Some of the following packages may be outdated or have duplicate installations:
`⚠️ Unable to find yarn.lock file:
${uniq(problemPackages).join(', ')}
skipping analyzer for outdated or duplicate installations
`,
),
);
console.log(
chalk.yellow(
`⚠️ The following command may fix the issue, but it could also be an issue within one of your dependencies:
yarn backstage-cli versions:check --fix
`,
),
);
}
const { name } = await fs.readJson(paths.resolveTarget('package.json'));