From 503393640184a7d95e2273f6e16e2d1e279ea957 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 25 Feb 2026 14:09:25 +0100 Subject: [PATCH] Keep versioning utilities internal to CLI migrate module Signed-off-by: Patrik Oldsberg --- .changeset/cli-node-lockfile-tostring.md | 2 +- packages/cli-node/package.json | 1 - packages/cli-node/report.api.md | 29 ------------------- packages/cli-node/src/index.ts | 1 - packages/cli-node/src/versioning/index.ts | 19 ------------ .../migrate/commands/versions/bump.test.ts | 6 ++-- .../modules/migrate/commands/versions/bump.ts | 5 ++-- .../migrate/lib}/versioning/packages.test.ts | 0 .../migrate/lib}/versioning/packages.ts | 24 ++------------- .../modules/migrate/lib}/versioning/yarn.ts | 5 ---- yarn.lock | 1 - 11 files changed, 9 insertions(+), 84 deletions(-) delete mode 100644 packages/cli-node/src/versioning/index.ts rename packages/{cli-node/src => cli/src/modules/migrate/lib}/versioning/packages.test.ts (100%) rename packages/{cli-node/src => cli/src/modules/migrate/lib}/versioning/packages.ts (89%) rename packages/{cli-node/src => cli/src/modules/migrate/lib}/versioning/yarn.ts (95%) diff --git a/.changeset/cli-node-lockfile-tostring.md b/.changeset/cli-node-lockfile-tostring.md index b808002578..bf4fc31225 100644 --- a/.changeset/cli-node-lockfile-tostring.md +++ b/.changeset/cli-node-lockfile-tostring.md @@ -2,4 +2,4 @@ '@backstage/cli-node': patch --- -Added `toString()` method to `Lockfile` for serializing lockfiles back to string format. Also added new exports: `detectYarnVersion`, `fetchPackageInfo`, `mapDependencies`, and `YarnInfoInspectData`. +Added `toString()` method to `Lockfile` for serializing lockfiles back to string format. diff --git a/packages/cli-node/package.json b/packages/cli-node/package.json index 2853733ff2..014ed56992 100644 --- a/packages/cli-node/package.json +++ b/packages/cli-node/package.json @@ -38,7 +38,6 @@ "@yarnpkg/lockfile": "^1.1.0", "@yarnpkg/parsers": "^3.0.0", "fs-extra": "^11.2.0", - "minimatch": "^10.2.1", "semver": "^7.5.3", "zod": "^3.25.76" }, diff --git a/packages/cli-node/report.api.md b/packages/cli-node/report.api.md index 9de5d1ffed..cf27d92894 100644 --- a/packages/cli-node/report.api.md +++ b/packages/cli-node/report.api.md @@ -93,12 +93,6 @@ export type ConcurrentTasksOptions = { worker: (item: TItem) => Promise; }; -// @public -export function detectYarnVersion(dir?: string): Promise<'classic' | 'berry'>; - -// @public -export function fetchPackageInfo(name: string): Promise; - // @public export class GitUtils { static listChangedFiles(ref: string): Promise; @@ -140,12 +134,6 @@ export type LockfileQueryEntry = { dataKey: string; }; -// @public -export function mapDependencies( - targetDir: string, - pattern: string, -): Promise>; - // @public export const packageFeatureType: readonly [ '@backstage/BackendFeature', @@ -221,13 +209,6 @@ export class PackageRoles { static getRoleInfo(role: string): PackageRoleInfo; } -// @public -export type PkgVersionInfo = { - range: string; - name: string; - location: string; -}; - // @public export function runConcurrentTasks( options: ConcurrentTasksOptions, @@ -250,14 +231,4 @@ export type WorkerQueueThreadsOptions = { | Promise<(item: TItem) => Promise>; context?: TContext; }; - -// @public -export type YarnInfoInspectData = { - name: string; - 'dist-tags': Record; - versions: string[]; - time: { - [version: string]: string; - }; -}; ``` diff --git a/packages/cli-node/src/index.ts b/packages/cli-node/src/index.ts index 6fc26b19d5..5540666a05 100644 --- a/packages/cli-node/src/index.ts +++ b/packages/cli-node/src/index.ts @@ -24,4 +24,3 @@ export * from './git'; export * from './monorepo'; export * from './concurrency'; export * from './roles'; -export * from './versioning'; diff --git a/packages/cli-node/src/versioning/index.ts b/packages/cli-node/src/versioning/index.ts deleted file mode 100644 index 99cbc0803c..0000000000 --- a/packages/cli-node/src/versioning/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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. - */ - -export { detectYarnVersion } from './yarn'; -export { fetchPackageInfo, mapDependencies } from './packages'; -export type { PkgVersionInfo, YarnInfoInspectData } from './packages'; diff --git a/packages/cli/src/modules/migrate/commands/versions/bump.test.ts b/packages/cli/src/modules/migrate/commands/versions/bump.test.ts index 7ee65db712..0061d07eba 100644 --- a/packages/cli/src/modules/migrate/commands/versions/bump.test.ts +++ b/packages/cli/src/modules/migrate/commands/versions/bump.test.ts @@ -19,7 +19,7 @@ import * as runObj from '@backstage/cli-common'; import { overrideTargetPaths } from '@backstage/cli-common/testUtils'; import bump, { bumpBackstageJsonVersion, createVersionFinder } from './bump'; import { registerMswTestHooks, withLogCollector } from '@backstage/test-utils'; -import { YarnInfoInspectData } from '@backstage/cli-node'; +import { YarnInfoInspectData } from '../../lib/versioning/packages'; import { setupServer } from 'msw/node'; import { rest } from 'msw'; import { NotFoundError } from '@backstage/errors'; @@ -69,8 +69,8 @@ jest.mock('@backstage/cli-common', () => { }); const mockFetchPackageInfo = jest.fn(); -jest.mock('@backstage/cli-node', () => { - const actual = jest.requireActual('@backstage/cli-node'); +jest.mock('../../lib/versioning/packages', () => { + const actual = jest.requireActual('../../lib/versioning/packages'); return { ...actual, fetchPackageInfo: (name: string) => mockFetchPackageInfo(name), diff --git a/packages/cli/src/modules/migrate/commands/versions/bump.ts b/packages/cli/src/modules/migrate/commands/versions/bump.ts index 2f310561b7..7ecd908d8a 100644 --- a/packages/cli/src/modules/migrate/commands/versions/bump.ts +++ b/packages/cli/src/modules/migrate/commands/versions/bump.ts @@ -31,13 +31,12 @@ import { isError, NotFoundError } from '@backstage/errors'; import { resolve as resolvePath } from 'node:path'; import { getHasYarnPlugin } from '../../../../lib/yarnPlugin'; +import { Lockfile, runConcurrentTasks } from '@backstage/cli-node'; import { fetchPackageInfo, - Lockfile, mapDependencies, - runConcurrentTasks, YarnInfoInspectData, -} from '@backstage/cli-node'; +} from '../../lib/versioning/packages'; import { getManifestByReleaseLine, getManifestByVersion, diff --git a/packages/cli-node/src/versioning/packages.test.ts b/packages/cli/src/modules/migrate/lib/versioning/packages.test.ts similarity index 100% rename from packages/cli-node/src/versioning/packages.test.ts rename to packages/cli/src/modules/migrate/lib/versioning/packages.test.ts diff --git a/packages/cli-node/src/versioning/packages.ts b/packages/cli/src/modules/migrate/lib/versioning/packages.ts similarity index 89% rename from packages/cli-node/src/versioning/packages.ts rename to packages/cli/src/modules/migrate/lib/versioning/packages.ts index 7cfcf132ed..11f1ba3041 100644 --- a/packages/cli-node/src/versioning/packages.ts +++ b/packages/cli/src/modules/migrate/lib/versioning/packages.ts @@ -27,11 +27,7 @@ const DEP_TYPES = [ 'optionalDependencies', ] as const; -/** - * Package data as returned by `yarn info`. - * - * @public - */ +// Package data as returned by `yarn info` export type YarnInfoInspectData = { name: string; 'dist-tags': Record; @@ -45,22 +41,12 @@ type YarnInfo = { data: YarnInfoInspectData | { type: string; data: unknown }; }; -/** - * Version information for a package dependency. - * - * @public - */ -export type PkgVersionInfo = { +type PkgVersionInfo = { range: string; name: string; location: string; }; -/** - * Fetches package information from the registry using `yarn info` or `yarn npm info`. - * - * @public - */ export async function fetchPackageInfo( name: string, ): Promise { @@ -106,11 +92,7 @@ export async function fetchPackageInfo( } } -/** - * Map all dependencies in the repo as dependency to dependents. - * - * @public - */ +/** Map all dependencies in the repo as dependency => dependents */ export async function mapDependencies( targetDir: string, pattern: string, diff --git a/packages/cli-node/src/versioning/yarn.ts b/packages/cli/src/modules/migrate/lib/versioning/yarn.ts similarity index 95% rename from packages/cli-node/src/versioning/yarn.ts rename to packages/cli/src/modules/migrate/lib/versioning/yarn.ts index 200c8866ce..908ddca949 100644 --- a/packages/cli-node/src/versioning/yarn.ts +++ b/packages/cli/src/modules/migrate/lib/versioning/yarn.ts @@ -19,11 +19,6 @@ import { runOutput } from '@backstage/cli-common'; const versions = new Map>(); -/** - * Detects the version of Yarn in use. - * - * @public - */ export function detectYarnVersion(dir?: string): Promise<'classic' | 'berry'> { const cwd = dir ?? process.cwd(); if (versions.has(cwd)) { diff --git a/yarn.lock b/yarn.lock index 3cc1c9c756..74484a0056 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3276,7 +3276,6 @@ __metadata: "@yarnpkg/lockfile": "npm:^1.1.0" "@yarnpkg/parsers": "npm:^3.0.0" fs-extra: "npm:^11.2.0" - minimatch: "npm:^10.2.1" semver: "npm:^7.5.3" zod: "npm:^3.25.76" languageName: unknown