From 80f510caee943fdb96a8683fe9948bf47a20d143 Mon Sep 17 00:00:00 2001 From: Mustansar Anwar ul Samad Date: Thu, 27 Jan 2022 12:03:26 +1300 Subject: [PATCH] cli: Log warning if unable to parse yarn.lock Signed-off-by: Mustansar Anwar ul Samad --- .changeset/witty-lizards-nail.md | 5 +++ packages/cli/src/commands/app/serve.ts | 61 ++++++++++++++++++-------- 2 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 .changeset/witty-lizards-nail.md diff --git a/.changeset/witty-lizards-nail.md b/.changeset/witty-lizards-nail.md new file mode 100644 index 0000000000..2ce3faa3f7 --- /dev/null +++ b/.changeset/witty-lizards-nail.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Log warning if unable to parse yarn.lock diff --git a/packages/cli/src/commands/app/serve.ts b/packages/cli/src/commands/app/serve.ts index 197ecab18b..716d47bd4c 100644 --- a/packages/cli/src/commands/app/serve.ts +++ b/packages/cli/src/commands/app/serve.ts @@ -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'));