From a08c4b0b057bdd452ae1dac9fb6df55835d3f697 Mon Sep 17 00:00:00 2001 From: Kevin Lee Date: Thu, 28 Jan 2021 14:35:08 -0800 Subject: [PATCH 1/2] Add check for outdated/duplicate packages to yarn start --- .changeset/orange-pets-whisper.md | 5 +++++ packages/cli/src/commands/app/serve.ts | 28 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .changeset/orange-pets-whisper.md diff --git a/.changeset/orange-pets-whisper.md b/.changeset/orange-pets-whisper.md new file mode 100644 index 0000000000..e96c210e43 --- /dev/null +++ b/.changeset/orange-pets-whisper.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Add check for outdated/duplicate packages to yarn start diff --git a/packages/cli/src/commands/app/serve.ts b/packages/cli/src/commands/app/serve.ts index dc165ecb90..e0f2881332 100644 --- a/packages/cli/src/commands/app/serve.ts +++ b/packages/cli/src/commands/app/serve.ts @@ -15,12 +15,40 @@ */ import fs from 'fs-extra'; +import chalk from 'chalk'; import { Command } from 'commander'; import { serveBundle } from '../../lib/bundler'; import { loadCliConfig } from '../../lib/config'; import { paths } from '../../lib/paths'; +import { Lockfile } from '../../lib/versioning'; +import { 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.map(({ name }) => name); + + if (problemPackages.length > 1) { + console.log( + chalk.yellow( + `The following packages may be outdated or have duplicate installations: + + ${problemPackages.join(', ')} + `, + ), + ); + console.log( + chalk.yellow( + `This can be resolved using the following command: + + yarn backstage-cli versions:check --fix + `, + ), + ); + } + const { name } = await fs.readJson(paths.resolveTarget('package.json')); const waitForExit = await serveBundle({ entry: 'src/index', From 8de07b3e658bfd1900db0d6362f2d2020a1f4253 Mon Sep 17 00:00:00 2001 From: Kevin Lee Date: Thu, 28 Jan 2021 19:55:17 -0800 Subject: [PATCH 2/2] Prepend caution icon to yarn start warning and check for package newRanges --- packages/cli/src/commands/app/serve.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/commands/app/serve.ts b/packages/cli/src/commands/app/serve.ts index e0f2881332..b542030109 100644 --- a/packages/cli/src/commands/app/serve.ts +++ b/packages/cli/src/commands/app/serve.ts @@ -16,6 +16,7 @@ import fs from 'fs-extra'; import chalk from 'chalk'; +import uniq from 'lodash/uniq'; import { Command } from 'commander'; import { serveBundle } from '../../lib/bundler'; import { loadCliConfig } from '../../lib/config'; @@ -28,20 +29,22 @@ export default async (cmd: Command) => { const result = lockfile.analyze({ filter: includedFilter, }); - const problemPackages = result.newVersions.map(({ name }) => name); + const problemPackages = [...result.newVersions, ...result.newRanges].map( + ({ name }) => name, + ); if (problemPackages.length > 1) { console.log( chalk.yellow( - `The following packages may be outdated or have duplicate installations: + `⚠️ Some of the following packages may be outdated or have duplicate installations: - ${problemPackages.join(', ')} + ${uniq(problemPackages).join(', ')} `, ), ); console.log( chalk.yellow( - `This can be resolved using the following command: + `⚠️ This can be resolved using the following command: yarn backstage-cli versions:check --fix `,