cli: eliminate src/lib/ directory and last cross-module import

Split version.ts into two locations:
- Template version provider moved to modules/new/lib/version.ts
- CLI version info moved to wiring/version.ts

Remove publishPreflightCheck from repo fix command (still runs during
package prepack). Fix build module self-references to use shorter
within-module paths.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2026-02-25 23:06:11 +01:00
parent 81308aee47
commit beab3cc456
9 changed files with 61 additions and 44 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Internal refactor to remove the `src/lib/` directory and eliminate the last cross-module import in the CLI package.
@@ -19,11 +19,11 @@ import { resolve as resolvePath } from 'node:path';
import {
getModuleFederationRemoteOptions,
serveBundle,
} from '../../../../build/lib/bundler';
} from '../../../lib/bundler';
import { targetPaths } from '@backstage/cli-common';
import { BackstagePackageJson } from '@backstage/cli-node';
import { hasReactDomClient } from '../../../../build/lib/bundler/hasReactDomClient';
import { hasReactDomClient } from '../../../lib/bundler/hasReactDomClient';
interface StartAppOptions {
verifyVersions?: boolean;
@@ -32,7 +32,7 @@ import pickBy from 'lodash/pickBy';
import { runOutput, targetPaths } from '@backstage/cli-common';
import { transforms } from './transforms';
import { version } from '../../../../lib/version';
import { version } from '../../../../wiring/version';
import yn from 'yn';
import { hasReactDomClient } from './hasReactDomClient';
import { createWorkspaceLinkingPlugins } from './linkWorkspaces';
@@ -31,8 +31,6 @@ import {
} from 'node:path';
import { targetPaths } from '@backstage/cli-common';
import { publishPreflightCheck } from '../../../build/lib/publishing';
const SCRIPT_EXTS = ['.js', '.jsx', '.ts', '.tsx', '.json'];
/**
@@ -507,8 +505,6 @@ export async function command(opts: OptionValues): Promise<void> {
fixPluginId,
fixPluginPackages,
fixPeerModules,
// Run the publish preflight check too, to make sure we don't uncover errors during publishing
publishPreflightCheck,
);
}
@@ -27,7 +27,7 @@ import lowerFirst from 'lodash/lowerFirst';
import { Lockfile } from '@backstage/cli-node';
import { targetPaths } from '@backstage/cli-common';
import { createPackageVersionProvider } from '../../../../lib/version';
import { createPackageVersionProvider } from '../version';
import { hasBackstageYarnPlugin } from '@backstage/cli-node';
const builtInHelpers = {
@@ -14,14 +14,9 @@
* limitations under the License.
*/
import fs from 'fs-extra';
import semver from 'semver';
import { findOwnPaths } from '@backstage/cli-common';
import { Lockfile } from '@backstage/cli-node';
/* eslint-disable-next-line no-restricted-syntax */
const ownPaths = findOwnPaths(__dirname);
/* eslint-disable @backstage/no-relative-monorepo-imports */
/*
This is a list of all packages used by the templates. If dependencies are added or removed,
@@ -35,28 +30,28 @@ This does not create an actual dependency on these packages and does not bring i
Rollup will extract the value of the version field in each package at build time without
leaving any imports in place.
*/
import { version as backendPluginApi } from '../../../../packages/backend-plugin-api/package.json';
import { version as backendTestUtils } from '../../../../packages/backend-test-utils/package.json';
import { version as catalogClient } from '../../../../packages/catalog-client/package.json';
import { version as cli } from '../../../../packages/cli/package.json';
import { version as config } from '../../../../packages/config/package.json';
import { version as coreAppApi } from '../../../../packages/core-app-api/package.json';
import { version as coreComponents } from '../../../../packages/core-components/package.json';
import { version as corePluginApi } from '../../../../packages/core-plugin-api/package.json';
import { version as devUtils } from '../../../../packages/dev-utils/package.json';
import { version as errors } from '../../../../packages/errors/package.json';
import { version as frontendDefaults } from '../../../../packages/frontend-defaults/package.json';
import { version as frontendPluginApi } from '../../../../packages/frontend-plugin-api/package.json';
import { version as frontendTestUtils } from '../../../../packages/frontend-test-utils/package.json';
import { version as testUtils } from '../../../../packages/test-utils/package.json';
import { version as scaffolderNode } from '../../../../plugins/scaffolder-node/package.json';
import { version as scaffolderNodeTestUtils } from '../../../../plugins/scaffolder-node-test-utils/package.json';
import { version as authBackend } from '../../../../plugins/auth-backend/package.json';
import { version as authBackendModuleGuestProvider } from '../../../../plugins/auth-backend-module-guest-provider/package.json';
import { version as catalogNode } from '../../../../plugins/catalog-node/package.json';
import { version as theme } from '../../../../packages/theme/package.json';
import { version as types } from '../../../../packages/types/package.json';
import { version as backendDefaults } from '../../../../packages/backend-defaults/package.json';
import { version as backendPluginApi } from '../../../../../../packages/backend-plugin-api/package.json';
import { version as backendTestUtils } from '../../../../../../packages/backend-test-utils/package.json';
import { version as catalogClient } from '../../../../../../packages/catalog-client/package.json';
import { version as cli } from '../../../../../../packages/cli/package.json';
import { version as config } from '../../../../../../packages/config/package.json';
import { version as coreAppApi } from '../../../../../../packages/core-app-api/package.json';
import { version as coreComponents } from '../../../../../../packages/core-components/package.json';
import { version as corePluginApi } from '../../../../../../packages/core-plugin-api/package.json';
import { version as devUtils } from '../../../../../../packages/dev-utils/package.json';
import { version as errors } from '../../../../../../packages/errors/package.json';
import { version as frontendDefaults } from '../../../../../../packages/frontend-defaults/package.json';
import { version as frontendPluginApi } from '../../../../../../packages/frontend-plugin-api/package.json';
import { version as frontendTestUtils } from '../../../../../../packages/frontend-test-utils/package.json';
import { version as testUtils } from '../../../../../../packages/test-utils/package.json';
import { version as scaffolderNode } from '../../../../../../plugins/scaffolder-node/package.json';
import { version as scaffolderNodeTestUtils } from '../../../../../../plugins/scaffolder-node-test-utils/package.json';
import { version as authBackend } from '../../../../../../plugins/auth-backend/package.json';
import { version as authBackendModuleGuestProvider } from '../../../../../../plugins/auth-backend-module-guest-provider/package.json';
import { version as catalogNode } from '../../../../../../plugins/catalog-node/package.json';
import { version as theme } from '../../../../../../packages/theme/package.json';
import { version as types } from '../../../../../../packages/types/package.json';
import { version as backendDefaults } from '../../../../../../packages/backend-defaults/package.json';
export const packageVersions: Record<string, string> = {
'@backstage/backend-defaults': backendDefaults,
@@ -84,14 +79,6 @@ export const packageVersions: Record<string, string> = {
'@backstage/plugin-catalog-node': catalogNode,
};
export function findVersion() {
const pkgContent = fs.readFileSync(ownPaths.resolve('package.json'), 'utf8');
return JSON.parse(pkgContent).version;
}
export const version = findVersion();
export const isDev = fs.pathExistsSync(ownPaths.resolve('src'));
export function createPackageVersionProvider(
lockfile?: Lockfile,
options?: {
+1 -1
View File
@@ -18,7 +18,7 @@ import { CommandGraph } from './CommandGraph';
import { CliFeature, OpaqueCliPlugin } from './types';
import { CommandRegistry } from './CommandRegistry';
import { Command } from 'commander';
import { version } from '../lib/version';
import { version } from './version';
import chalk from 'chalk';
import { exitWithError } from './errors';
import { ForwardedError } from '@backstage/errors';
+29
View File
@@ -0,0 +1,29 @@
/*
* 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 fs from 'fs-extra';
import { findOwnPaths } from '@backstage/cli-common';
/* eslint-disable-next-line no-restricted-syntax */
const ownPaths = findOwnPaths(__dirname);
export function findVersion() {
const pkgContent = fs.readFileSync(ownPaths.resolve('package.json'), 'utf8');
return JSON.parse(pkgContent).version;
}
export const version = findVersion();
export const isDev = fs.pathExistsSync(ownPaths.resolve('src'));