From be0278e9a6ba9620958e562c08bd7a029f953658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jerna=C5=9B?= Date: Fri, 15 Nov 2024 13:55:03 +0100 Subject: [PATCH] fix(cli): Remove circular import by extracting function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Łukasz Jernaś --- .changeset/khaki-nails-know.md | 5 ++ packages/cli/src/commands/versions/bump.ts | 35 +------------ packages/cli/src/commands/versions/migrate.ts | 2 +- packages/cli/src/commands/versions/utils.ts | 51 +++++++++++++++++++ 4 files changed, 58 insertions(+), 35 deletions(-) create mode 100644 .changeset/khaki-nails-know.md create mode 100644 packages/cli/src/commands/versions/utils.ts diff --git a/.changeset/khaki-nails-know.md b/.changeset/khaki-nails-know.md new file mode 100644 index 0000000000..387946971e --- /dev/null +++ b/.changeset/khaki-nails-know.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Removed circular import diff --git a/packages/cli/src/commands/versions/bump.ts b/packages/cli/src/commands/versions/bump.ts index 8d43f38967..eec7f6b20a 100644 --- a/packages/cli/src/commands/versions/bump.ts +++ b/packages/cli/src/commands/versions/bump.ts @@ -22,14 +22,12 @@ if (shouldUseGlobalAgent()) { import fs from 'fs-extra'; import chalk from 'chalk'; -import ora from 'ora'; import semver from 'semver'; import { OptionValues } from 'commander'; import yaml from 'yaml'; import z from 'zod'; import { isError, NotFoundError } from '@backstage/errors'; import { resolve as resolvePath } from 'path'; -import { run } from '../../lib/run'; import { paths } from '../../lib/paths'; import { mapDependencies, @@ -45,6 +43,7 @@ import { ReleaseManifest, } from '@backstage/release-manifests'; import { migrateMovedPackages } from './migrate'; +import { runYarnInstall } from './utils'; function shouldUseGlobalAgent(): boolean { // see https://www.npmjs.com/package/global-agent @@ -508,35 +507,3 @@ async function getHasYarnPlugin() { plugin => plugin.path === '.yarn/plugins/@yarnpkg/plugin-backstage.cjs', ); } - -export async function runYarnInstall() { - const spinner = ora({ - prefixText: `Running ${chalk.blue('yarn install')} to install new versions`, - spinner: 'arc', - color: 'green', - }).start(); - - const installOutput = new Array(); - try { - await run('yarn', ['install'], { - env: { - FORCE_COLOR: 'true', - // We filter out all of the npm_* environment variables that are added when - // executing through yarn. This works around an issue where these variables - // incorrectly override local yarn or npm config in the project directory. - ...Object.fromEntries( - Object.entries(process.env).map(([name, value]) => - name.startsWith('npm_') ? [name, undefined] : [name, value], - ), - ), - }, - stdoutLogFunc: data => installOutput.push(data), - stderrLogFunc: data => installOutput.push(data), - }); - spinner.succeed(); - } catch (error) { - spinner.fail(); - process.stdout.write(Buffer.concat(installOutput)); - throw error; - } -} diff --git a/packages/cli/src/commands/versions/migrate.ts b/packages/cli/src/commands/versions/migrate.ts index 321a78ef9f..8415de0f57 100644 --- a/packages/cli/src/commands/versions/migrate.ts +++ b/packages/cli/src/commands/versions/migrate.ts @@ -19,7 +19,7 @@ import { resolve as resolvePath, join as joinPath } from 'path'; import { OptionValues } from 'commander'; import { readJson, writeJson } from 'fs-extra'; import { minimatch } from 'minimatch'; -import { runYarnInstall } from './bump'; +import { runYarnInstall } from './utils'; import replace from 'replace-in-file'; declare module 'replace-in-file' { diff --git a/packages/cli/src/commands/versions/utils.ts b/packages/cli/src/commands/versions/utils.ts new file mode 100644 index 0000000000..22c5f0c028 --- /dev/null +++ b/packages/cli/src/commands/versions/utils.ts @@ -0,0 +1,51 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ora from 'ora'; +import chalk from 'chalk'; +import { run } from '../../lib/run'; + +export async function runYarnInstall() { + const spinner = ora({ + prefixText: `Running ${chalk.blue('yarn install')} to install new versions`, + spinner: 'arc', + color: 'green', + }).start(); + + const installOutput = new Array(); + try { + await run('yarn', ['install'], { + env: { + FORCE_COLOR: 'true', + // We filter out all of the npm_* environment variables that are added when + // executing through yarn. This works around an issue where these variables + // incorrectly override local yarn or npm config in the project directory. + ...Object.fromEntries( + Object.entries(process.env).map(([name, value]) => + name.startsWith('npm_') ? [name, undefined] : [name, value], + ), + ), + }, + stdoutLogFunc: data => installOutput.push(data), + stderrLogFunc: data => installOutput.push(data), + }); + spinner.succeed(); + } catch (error) { + spinner.fail(); + process.stdout.write(Buffer.concat(installOutput)); + throw error; + } +}