diff --git a/.changeset/cli-final-lib-cleanup.md b/.changeset/cli-final-lib-cleanup.md new file mode 100644 index 0000000000..0884a7fc11 --- /dev/null +++ b/.changeset/cli-final-lib-cleanup.md @@ -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. diff --git a/packages/cli/src/modules/build/commands/package/start/startFrontend.ts b/packages/cli/src/modules/build/commands/package/start/startFrontend.ts index c81fd2fd66..689cd20f7a 100644 --- a/packages/cli/src/modules/build/commands/package/start/startFrontend.ts +++ b/packages/cli/src/modules/build/commands/package/start/startFrontend.ts @@ -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; diff --git a/packages/cli/src/modules/build/lib/bundler/config.ts b/packages/cli/src/modules/build/lib/bundler/config.ts index 1fe81cbec8..c3676ecf70 100644 --- a/packages/cli/src/modules/build/lib/bundler/config.ts +++ b/packages/cli/src/modules/build/lib/bundler/config.ts @@ -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'; diff --git a/packages/cli/src/modules/maintenance/commands/repo/fix.ts b/packages/cli/src/modules/maintenance/commands/repo/fix.ts index cb745b9b48..de09d8b490 100644 --- a/packages/cli/src/modules/maintenance/commands/repo/fix.ts +++ b/packages/cli/src/modules/maintenance/commands/repo/fix.ts @@ -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 { fixPluginId, fixPluginPackages, fixPeerModules, - // Run the publish preflight check too, to make sure we don't uncover errors during publishing - publishPreflightCheck, ); } diff --git a/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts b/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts index 42285259b3..dd6f43b9a7 100644 --- a/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts +++ b/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts @@ -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 = { diff --git a/packages/cli/src/lib/version.test.ts b/packages/cli/src/modules/new/lib/version.test.ts similarity index 100% rename from packages/cli/src/lib/version.test.ts rename to packages/cli/src/modules/new/lib/version.test.ts diff --git a/packages/cli/src/lib/version.ts b/packages/cli/src/modules/new/lib/version.ts similarity index 62% rename from packages/cli/src/lib/version.ts rename to packages/cli/src/modules/new/lib/version.ts index 94337710d6..0849e8a9e8 100644 --- a/packages/cli/src/lib/version.ts +++ b/packages/cli/src/modules/new/lib/version.ts @@ -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 = { '@backstage/backend-defaults': backendDefaults, @@ -84,14 +79,6 @@ export const packageVersions: Record = { '@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?: { diff --git a/packages/cli/src/wiring/CliInitializer.ts b/packages/cli/src/wiring/CliInitializer.ts index 8d0b844c78..a605199179 100644 --- a/packages/cli/src/wiring/CliInitializer.ts +++ b/packages/cli/src/wiring/CliInitializer.ts @@ -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'; diff --git a/packages/cli/src/wiring/version.ts b/packages/cli/src/wiring/version.ts new file mode 100644 index 0000000000..d7d0b3a2fe --- /dev/null +++ b/packages/cli/src/wiring/version.ts @@ -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'));