From 158bfe8a69aabd5c2ba3182a9db8bd75d158ef14 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 20 Feb 2026 23:36:59 +0100 Subject: [PATCH] Give each CLI module its own paths instead of importing from lib/ Each module now has a local paths.ts that calls findPaths(__dirname) directly. This makes modules fully independent of lib/paths.ts, and the pattern will continue to work when modules are extracted into separate packages since each package's __dirname will resolve to its own root. Signed-off-by: Patrik Oldsberg Co-authored-by: Cursor --- packages/cli/src/lib/cache/SuccessCache.ts | 5 ++++- packages/cli/src/lib/typeDistProject.ts | 5 ++++- packages/cli/src/lib/version.ts | 5 ++++- packages/cli/src/lib/yarnPlugin.test.ts | 7 ++++--- packages/cli/src/lib/yarnPlugin.ts | 5 ++++- .../build/commands/package/build/command.ts | 2 +- .../build/commands/package/start/command.ts | 2 +- .../commands/package/start/startBackend.ts | 2 +- .../commands/package/start/startFrontend.ts | 2 +- .../src/modules/build/commands/repo/build.ts | 2 +- .../modules/build/commands/repo/start.test.ts | 2 +- .../src/modules/build/commands/repo/start.ts | 2 +- .../src/modules/build/lib/builder/config.ts | 2 +- .../src/modules/build/lib/builder/packager.ts | 2 +- .../src/modules/build/lib/bundler/config.ts | 2 +- .../build/lib/bundler/hasReactDomClient.ts | 2 +- .../build/lib/bundler/linkWorkspaces.ts | 2 +- .../build/lib/bundler/packageDetection.ts | 2 +- .../src/modules/build/lib/bundler/paths.ts | 2 +- .../src/modules/build/lib/bundler/server.ts | 2 +- .../build/lib/packager/createDistWorkspace.ts | 2 +- .../cli/src/modules/build/lib/role.test.ts | 2 +- packages/cli/src/modules/build/lib/role.ts | 2 +- .../modules/build/lib/runner/runBackend.ts | 2 +- .../cli/src/{lib => modules/build}/paths.ts | 0 packages/cli/src/modules/config/lib/config.ts | 2 +- packages/cli/src/modules/config/paths.ts | 20 +++++++++++++++++++ .../commands/create-github-app/index.ts | 2 +- .../src/modules/create-github-app/paths.ts | 20 +++++++++++++++++++ .../cli/src/modules/info/commands/info.ts | 2 +- packages/cli/src/modules/info/paths.ts | 20 +++++++++++++++++++ .../src/modules/lint/commands/package/lint.ts | 2 +- .../src/modules/lint/commands/repo/lint.ts | 2 +- packages/cli/src/modules/lint/paths.ts | 20 +++++++++++++++++++ .../maintenance/commands/package/clean.ts | 2 +- .../maintenance/commands/package/pack.ts | 2 +- .../maintenance/commands/repo/clean.ts | 2 +- .../modules/maintenance/commands/repo/fix.ts | 2 +- .../commands/repo/list-deprecations.ts | 2 +- packages/cli/src/modules/maintenance/paths.ts | 20 +++++++++++++++++++ .../modules/migrate/commands/packageRole.ts | 2 +- .../modules/migrate/commands/versions/bump.ts | 2 +- packages/cli/src/modules/migrate/paths.ts | 20 +++++++++++++++++++ .../modules/new/lib/codeowners/codeowners.ts | 2 +- .../new/lib/execution/PortableTemplater.ts | 2 +- .../new/lib/execution/installNewPackage.ts | 2 +- .../execution/writeTemplateContents.test.ts | 2 +- .../lib/execution/writeTemplateContents.ts | 2 +- .../collectPortableTemplateInput.ts | 2 +- .../lib/preparation/loadPortableTemplate.ts | 2 +- .../preparation/loadPortableTemplateConfig.ts | 2 +- packages/cli/src/modules/new/paths.ts | 20 +++++++++++++++++++ .../src/modules/test/commands/package/test.ts | 2 +- .../src/modules/test/commands/repo/test.ts | 2 +- packages/cli/src/modules/test/paths.ts | 20 +++++++++++++++++++ 55 files changed, 221 insertions(+), 48 deletions(-) rename packages/cli/src/{lib => modules/build}/paths.ts (100%) create mode 100644 packages/cli/src/modules/config/paths.ts create mode 100644 packages/cli/src/modules/create-github-app/paths.ts create mode 100644 packages/cli/src/modules/info/paths.ts create mode 100644 packages/cli/src/modules/lint/paths.ts create mode 100644 packages/cli/src/modules/maintenance/paths.ts create mode 100644 packages/cli/src/modules/migrate/paths.ts create mode 100644 packages/cli/src/modules/new/paths.ts create mode 100644 packages/cli/src/modules/test/paths.ts diff --git a/packages/cli/src/lib/cache/SuccessCache.ts b/packages/cli/src/lib/cache/SuccessCache.ts index a799970b4d..0d2f022251 100644 --- a/packages/cli/src/lib/cache/SuccessCache.ts +++ b/packages/cli/src/lib/cache/SuccessCache.ts @@ -16,7 +16,10 @@ import fs from 'fs-extra'; import { resolve as resolvePath } from 'node:path'; -import { paths } from '../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); const DEFAULT_CACHE_BASE_PATH = 'node_modules/.cache/backstage-cli'; diff --git a/packages/cli/src/lib/typeDistProject.ts b/packages/cli/src/lib/typeDistProject.ts index d8469aee37..e8b331d00d 100644 --- a/packages/cli/src/lib/typeDistProject.ts +++ b/packages/cli/src/lib/typeDistProject.ts @@ -20,7 +20,10 @@ import { } from '@backstage/cli-node'; import { resolve as resolvePath } from 'node:path'; import { Project, SourceFile, SyntaxKind, ts, Type } from 'ts-morph'; -import { paths } from './paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); export const createTypeDistProject = async () => { return new Project({ diff --git a/packages/cli/src/lib/version.ts b/packages/cli/src/lib/version.ts index a7a7ca1bdb..de961e213e 100644 --- a/packages/cli/src/lib/version.ts +++ b/packages/cli/src/lib/version.ts @@ -16,7 +16,10 @@ import fs from 'fs-extra'; import semver from 'semver'; -import { paths } from './paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); import { Lockfile } from './versioning'; /* eslint-disable @backstage/no-relative-monorepo-imports */ diff --git a/packages/cli/src/lib/yarnPlugin.test.ts b/packages/cli/src/lib/yarnPlugin.test.ts index d5c865e1c4..bfc264b74a 100644 --- a/packages/cli/src/lib/yarnPlugin.test.ts +++ b/packages/cli/src/lib/yarnPlugin.test.ts @@ -19,12 +19,13 @@ import { getHasYarnPlugin } from './yarnPlugin'; const mockDir = createMockDirectory(); -jest.mock('./paths', () => ({ - paths: { +jest.mock('@backstage/cli-common', () => ({ + ...jest.requireActual('@backstage/cli-common'), + findPaths: () => ({ resolveTargetRoot(filename: string) { return mockDir.resolve(filename); }, - }, + }), })); describe('getHasYarnPlugin', () => { diff --git a/packages/cli/src/lib/yarnPlugin.ts b/packages/cli/src/lib/yarnPlugin.ts index 5ad49b2524..e73108c463 100644 --- a/packages/cli/src/lib/yarnPlugin.ts +++ b/packages/cli/src/lib/yarnPlugin.ts @@ -17,7 +17,10 @@ import fs from 'fs-extra'; import yaml from 'yaml'; import z from 'zod'; -import { paths } from './paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); const yarnRcSchema = z.object({ plugins: z diff --git a/packages/cli/src/modules/build/commands/package/build/command.ts b/packages/cli/src/modules/build/commands/package/build/command.ts index 0882cfcf4f..bf4c5a46f8 100644 --- a/packages/cli/src/modules/build/commands/package/build/command.ts +++ b/packages/cli/src/modules/build/commands/package/build/command.ts @@ -23,7 +23,7 @@ import { PackageGraph, PackageRoles, } from '@backstage/cli-node'; -import { paths } from '../../../../../lib/paths'; +import { paths } from '../../../paths'; import { buildFrontend } from '../../../lib/buildFrontend'; import { buildBackend } from '../../../lib/buildBackend'; import { isValidUrl } from '../../../lib/urls'; diff --git a/packages/cli/src/modules/build/commands/package/start/command.ts b/packages/cli/src/modules/build/commands/package/start/command.ts index 3e3dbb378a..5fefb8c03f 100644 --- a/packages/cli/src/modules/build/commands/package/start/command.ts +++ b/packages/cli/src/modules/build/commands/package/start/command.ts @@ -18,7 +18,7 @@ import { OptionValues } from 'commander'; import { startPackage } from './startPackage'; import { resolveLinkedWorkspace } from './resolveLinkedWorkspace'; import { findRoleFromCommand } from '../../../lib/role'; -import { paths } from '../../../../../lib/paths'; +import { paths } from '../../../paths'; export async function command(opts: OptionValues): Promise { await startPackage({ diff --git a/packages/cli/src/modules/build/commands/package/start/startBackend.ts b/packages/cli/src/modules/build/commands/package/start/startBackend.ts index 525a4b0ba6..4b87f0e02a 100644 --- a/packages/cli/src/modules/build/commands/package/start/startBackend.ts +++ b/packages/cli/src/modules/build/commands/package/start/startBackend.ts @@ -16,7 +16,7 @@ import fs from 'fs-extra'; import { resolve as resolvePath } from 'node:path'; -import { paths } from '../../../../../lib/paths'; +import { paths } from '../../../paths'; import { runBackend } from '../../../lib/runner'; interface StartBackendOptions { 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 027dbf68e3..d55681ea07 100644 --- a/packages/cli/src/modules/build/commands/package/start/startFrontend.ts +++ b/packages/cli/src/modules/build/commands/package/start/startFrontend.ts @@ -20,7 +20,7 @@ import { getModuleFederationRemoteOptions, serveBundle, } from '../../../../build/lib/bundler'; -import { paths } from '../../../../../lib/paths'; +import { paths } from '../../../paths'; import { BackstagePackageJson } from '@backstage/cli-node'; import { hasReactDomClient } from '../../../../build/lib/bundler/hasReactDomClient'; diff --git a/packages/cli/src/modules/build/commands/repo/build.ts b/packages/cli/src/modules/build/commands/repo/build.ts index 6c99ebb0af..c8568be06a 100644 --- a/packages/cli/src/modules/build/commands/repo/build.ts +++ b/packages/cli/src/modules/build/commands/repo/build.ts @@ -18,7 +18,7 @@ import chalk from 'chalk'; import { Command, OptionValues } from 'commander'; import { relative as relativePath } from 'node:path'; import { buildPackages, getOutputsForRole } from '../../lib/builder'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { BackstagePackage, PackageGraph, diff --git a/packages/cli/src/modules/build/commands/repo/start.test.ts b/packages/cli/src/modules/build/commands/repo/start.test.ts index 0efe01df43..b1cc9faefd 100644 --- a/packages/cli/src/modules/build/commands/repo/start.test.ts +++ b/packages/cli/src/modules/build/commands/repo/start.test.ts @@ -17,7 +17,7 @@ import { PackageGraph } from '@backstage/cli-node'; import { findTargetPackages } from './start'; import { posix } from 'node:path'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; const mocks = { app: { diff --git a/packages/cli/src/modules/build/commands/repo/start.ts b/packages/cli/src/modules/build/commands/repo/start.ts index bc1ab543c1..e02dfdc6a3 100644 --- a/packages/cli/src/modules/build/commands/repo/start.ts +++ b/packages/cli/src/modules/build/commands/repo/start.ts @@ -20,7 +20,7 @@ import { PackageRole, } from '@backstage/cli-node'; import { relative as relativePath } from 'node:path'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { resolveLinkedWorkspace } from '../package/start/resolveLinkedWorkspace'; import { startPackage } from '../package/start/startPackage'; import { parseArgs } from 'node:util'; diff --git a/packages/cli/src/modules/build/lib/builder/config.ts b/packages/cli/src/modules/build/lib/builder/config.ts index 55ae09bf9c..54d33719e0 100644 --- a/packages/cli/src/modules/build/lib/builder/config.ts +++ b/packages/cli/src/modules/build/lib/builder/config.ts @@ -39,7 +39,7 @@ import { import { forwardFileImports, cssEntryPoints } from './plugins'; import { BuildOptions, Output } from './types'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { BackstagePackageJson } from '@backstage/cli-node'; import { readEntryPoints } from '../entryPoints'; diff --git a/packages/cli/src/modules/build/lib/builder/packager.ts b/packages/cli/src/modules/build/lib/builder/packager.ts index 77b1e2b134..16a6ecb828 100644 --- a/packages/cli/src/modules/build/lib/builder/packager.ts +++ b/packages/cli/src/modules/build/lib/builder/packager.ts @@ -18,7 +18,7 @@ import fs from 'fs-extra'; import { rollup, RollupOptions } from 'rollup'; import chalk from 'chalk'; import { relative as relativePath, resolve as resolvePath } from 'node:path'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { makeRollupConfigs } from './config'; import { BuildOptions, Output } from './types'; import { PackageRoles, runConcurrentTasks } from '@backstage/cli-node'; diff --git a/packages/cli/src/modules/build/lib/bundler/config.ts b/packages/cli/src/modules/build/lib/bundler/config.ts index a4e2b16ab9..d65fd815c8 100644 --- a/packages/cli/src/modules/build/lib/bundler/config.ts +++ b/packages/cli/src/modules/build/lib/bundler/config.ts @@ -25,7 +25,7 @@ import { TsCheckerRspackPlugin } from 'ts-checker-rspack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin'; import ModuleScopePlugin from 'react-dev-utils/ModuleScopePlugin'; import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack'; -import { paths as cliPaths } from '../../../../lib/paths'; +import { paths as cliPaths } from '../../paths'; import fs from 'fs-extra'; import { optimization as optimizationConfig } from './optimization'; import pickBy from 'lodash/pickBy'; diff --git a/packages/cli/src/modules/build/lib/bundler/hasReactDomClient.ts b/packages/cli/src/modules/build/lib/bundler/hasReactDomClient.ts index ad331bdf8b..5e3f4aac49 100644 --- a/packages/cli/src/modules/build/lib/bundler/hasReactDomClient.ts +++ b/packages/cli/src/modules/build/lib/bundler/hasReactDomClient.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; export function hasReactDomClient() { try { diff --git a/packages/cli/src/modules/build/lib/bundler/linkWorkspaces.ts b/packages/cli/src/modules/build/lib/bundler/linkWorkspaces.ts index 39f52067ab..cb3edca684 100644 --- a/packages/cli/src/modules/build/lib/bundler/linkWorkspaces.ts +++ b/packages/cli/src/modules/build/lib/bundler/linkWorkspaces.ts @@ -17,7 +17,7 @@ import { relative as relativePath } from 'node:path'; import { getPackages } from '@manypkg/get-packages'; import { rspack } from '@rspack/core'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; /** * This returns of collection of plugins that links a separate workspace into diff --git a/packages/cli/src/modules/build/lib/bundler/packageDetection.ts b/packages/cli/src/modules/build/lib/bundler/packageDetection.ts index 47346f803b..48702fcbd9 100644 --- a/packages/cli/src/modules/build/lib/bundler/packageDetection.ts +++ b/packages/cli/src/modules/build/lib/bundler/packageDetection.ts @@ -20,7 +20,7 @@ import chokidar from 'chokidar'; import fs from 'fs-extra'; import PQueue from 'p-queue'; import { dirname, join as joinPath, resolve as resolvePath } from 'node:path'; -import { paths as cliPaths } from '../../../../lib/paths'; +import { paths as cliPaths } from '../../paths'; const DETECTED_MODULES_MODULE_NAME = '__backstage-autodetected-plugins__'; diff --git a/packages/cli/src/modules/build/lib/bundler/paths.ts b/packages/cli/src/modules/build/lib/bundler/paths.ts index 3106da5f7d..f7fb6ecdc2 100644 --- a/packages/cli/src/modules/build/lib/bundler/paths.ts +++ b/packages/cli/src/modules/build/lib/bundler/paths.ts @@ -16,7 +16,7 @@ import fs from 'fs-extra'; import { resolve as resolvePath } from 'node:path'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; export type BundlingPathsOptions = { // bundle entrypoint, e.g. 'src/index' diff --git a/packages/cli/src/modules/build/lib/bundler/server.ts b/packages/cli/src/modules/build/lib/bundler/server.ts index b2d480f061..eadbd1b208 100644 --- a/packages/cli/src/modules/build/lib/bundler/server.ts +++ b/packages/cli/src/modules/build/lib/bundler/server.ts @@ -22,7 +22,7 @@ import openBrowser from 'react-dev-utils/openBrowser'; import { rspack } from '@rspack/core'; import { RspackDevServer } from '@rspack/dev-server'; -import { paths as libPaths } from '../../../../lib/paths'; +import { paths as libPaths } from '../../paths'; import { loadCliConfig } from '../../../config/lib/config'; import { createConfig, resolveBaseUrl, resolveEndpoint } from './config'; import { createDetectedModulesEntryPoint } from './packageDetection'; diff --git a/packages/cli/src/modules/build/lib/packager/createDistWorkspace.ts b/packages/cli/src/modules/build/lib/packager/createDistWorkspace.ts index 296355e2dd..ca71e0f332 100644 --- a/packages/cli/src/modules/build/lib/packager/createDistWorkspace.ts +++ b/packages/cli/src/modules/build/lib/packager/createDistWorkspace.ts @@ -24,7 +24,7 @@ import { import { tmpdir } from 'node:os'; import * as tar from 'tar'; import partition from 'lodash/partition'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { run } from '@backstage/cli-common'; import { dependencies as cliDependencies, diff --git a/packages/cli/src/modules/build/lib/role.test.ts b/packages/cli/src/modules/build/lib/role.test.ts index 89fa533457..ba59dcd8c0 100644 --- a/packages/cli/src/modules/build/lib/role.test.ts +++ b/packages/cli/src/modules/build/lib/role.test.ts @@ -20,7 +20,7 @@ import { findRoleFromCommand } from './role'; const mockDir = createMockDirectory(); -jest.mock('../../../lib/paths', () => ({ +jest.mock('../paths', () => ({ paths: { resolveTarget(filename: string) { return mockDir.resolve(filename); diff --git a/packages/cli/src/modules/build/lib/role.ts b/packages/cli/src/modules/build/lib/role.ts index 7af4ccb955..9dc3b55762 100644 --- a/packages/cli/src/modules/build/lib/role.ts +++ b/packages/cli/src/modules/build/lib/role.ts @@ -16,7 +16,7 @@ import fs from 'fs-extra'; import { OptionValues } from 'commander'; -import { paths } from '../../../lib/paths'; +import { paths } from '../paths'; import { PackageRoles, PackageRole } from '@backstage/cli-node'; export async function findRoleFromCommand( diff --git a/packages/cli/src/modules/build/lib/runner/runBackend.ts b/packages/cli/src/modules/build/lib/runner/runBackend.ts index d8fd447326..511fdd84bb 100644 --- a/packages/cli/src/modules/build/lib/runner/runBackend.ts +++ b/packages/cli/src/modules/build/lib/runner/runBackend.ts @@ -21,7 +21,7 @@ import { IpcServer, ServerDataStore } from '../ipc'; import debounce from 'lodash/debounce'; import { fileURLToPath } from 'node:url'; import { isAbsolute as isAbsolutePath } from 'node:path'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import spawn from 'cross-spawn'; const loaderArgs = [ diff --git a/packages/cli/src/lib/paths.ts b/packages/cli/src/modules/build/paths.ts similarity index 100% rename from packages/cli/src/lib/paths.ts rename to packages/cli/src/modules/build/paths.ts diff --git a/packages/cli/src/modules/config/lib/config.ts b/packages/cli/src/modules/config/lib/config.ts index 2b313f60bd..a8d749f4d1 100644 --- a/packages/cli/src/modules/config/lib/config.ts +++ b/packages/cli/src/modules/config/lib/config.ts @@ -16,7 +16,7 @@ import { ConfigSources, loadConfigSchema } from '@backstage/config-loader'; import { AppConfig, ConfigReader } from '@backstage/config'; -import { paths } from '../../../lib/paths'; +import { paths } from '../paths'; import { getPackages } from '@manypkg/get-packages'; import { PackageGraph } from '@backstage/cli-node'; import { resolve as resolvePath } from 'node:path'; diff --git a/packages/cli/src/modules/config/paths.ts b/packages/cli/src/modules/config/paths.ts new file mode 100644 index 0000000000..2c658c27b3 --- /dev/null +++ b/packages/cli/src/modules/config/paths.ts @@ -0,0 +1,20 @@ +/* + * 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 { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +export const paths = findPaths(__dirname); diff --git a/packages/cli/src/modules/create-github-app/commands/create-github-app/index.ts b/packages/cli/src/modules/create-github-app/commands/create-github-app/index.ts index 6c0e422080..e22d14bd6d 100644 --- a/packages/cli/src/modules/create-github-app/commands/create-github-app/index.ts +++ b/packages/cli/src/modules/create-github-app/commands/create-github-app/index.ts @@ -18,7 +18,7 @@ import fs from 'fs-extra'; import chalk from 'chalk'; import { stringify as stringifyYaml } from 'yaml'; import inquirer, { Question, Answers } from 'inquirer'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { GithubCreateAppServer } from './GithubCreateAppServer'; import openBrowser from 'react-dev-utils/openBrowser'; diff --git a/packages/cli/src/modules/create-github-app/paths.ts b/packages/cli/src/modules/create-github-app/paths.ts new file mode 100644 index 0000000000..2c658c27b3 --- /dev/null +++ b/packages/cli/src/modules/create-github-app/paths.ts @@ -0,0 +1,20 @@ +/* + * 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 { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +export const paths = findPaths(__dirname); diff --git a/packages/cli/src/modules/info/commands/info.ts b/packages/cli/src/modules/info/commands/info.ts index 923a02ef4c..d76c8cfc4b 100644 --- a/packages/cli/src/modules/info/commands/info.ts +++ b/packages/cli/src/modules/info/commands/info.ts @@ -17,7 +17,7 @@ import { version as cliVersion } from '../../../../package.json'; import os from 'node:os'; import { runOutput } from '@backstage/cli-common'; -import { paths } from '../../../lib/paths'; +import { paths } from '../paths'; import { Lockfile } from '../../../lib/versioning'; import { BackstagePackageJson, PackageGraph } from '@backstage/cli-node'; import { minimatch } from 'minimatch'; diff --git a/packages/cli/src/modules/info/paths.ts b/packages/cli/src/modules/info/paths.ts new file mode 100644 index 0000000000..2c658c27b3 --- /dev/null +++ b/packages/cli/src/modules/info/paths.ts @@ -0,0 +1,20 @@ +/* + * 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 { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +export const paths = findPaths(__dirname); diff --git a/packages/cli/src/modules/lint/commands/package/lint.ts b/packages/cli/src/modules/lint/commands/package/lint.ts index a1e45c0113..58fa646e48 100644 --- a/packages/cli/src/modules/lint/commands/package/lint.ts +++ b/packages/cli/src/modules/lint/commands/package/lint.ts @@ -16,7 +16,7 @@ import fs from 'fs-extra'; import { OptionValues } from 'commander'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { ESLint } from 'eslint'; export default async (directories: string[], opts: OptionValues) => { diff --git a/packages/cli/src/modules/lint/commands/repo/lint.ts b/packages/cli/src/modules/lint/commands/repo/lint.ts index 98a100fe3e..c3537ab254 100644 --- a/packages/cli/src/modules/lint/commands/repo/lint.ts +++ b/packages/cli/src/modules/lint/commands/repo/lint.ts @@ -25,7 +25,7 @@ import { Lockfile, runWorkerQueueThreads, } from '@backstage/cli-node'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { createScriptOptionsParser } from '../../../../lib/optionsParser'; import { SuccessCache } from '../../../../lib/cache/SuccessCache'; diff --git a/packages/cli/src/modules/lint/paths.ts b/packages/cli/src/modules/lint/paths.ts new file mode 100644 index 0000000000..2c658c27b3 --- /dev/null +++ b/packages/cli/src/modules/lint/paths.ts @@ -0,0 +1,20 @@ +/* + * 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 { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +export const paths = findPaths(__dirname); diff --git a/packages/cli/src/modules/maintenance/commands/package/clean.ts b/packages/cli/src/modules/maintenance/commands/package/clean.ts index 5e2d0d65b3..0a2d11bc14 100644 --- a/packages/cli/src/modules/maintenance/commands/package/clean.ts +++ b/packages/cli/src/modules/maintenance/commands/package/clean.ts @@ -15,7 +15,7 @@ */ import fs from 'fs-extra'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; export default async function clean() { await fs.remove(paths.resolveTarget('dist')); diff --git a/packages/cli/src/modules/maintenance/commands/package/pack.ts b/packages/cli/src/modules/maintenance/commands/package/pack.ts index cdd50517ae..4c1d475703 100644 --- a/packages/cli/src/modules/maintenance/commands/package/pack.ts +++ b/packages/cli/src/modules/maintenance/commands/package/pack.ts @@ -18,7 +18,7 @@ import { productionPack, revertProductionPack, } from '../../../../modules/build/lib/packager/productionPack'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import fs from 'fs-extra'; import { publishPreflightCheck } from '../../lib/publishing'; import { createTypeDistProject } from '../../../../lib/typeDistProject'; diff --git a/packages/cli/src/modules/maintenance/commands/repo/clean.ts b/packages/cli/src/modules/maintenance/commands/repo/clean.ts index 59e5367837..fc1aabd1b7 100644 --- a/packages/cli/src/modules/maintenance/commands/repo/clean.ts +++ b/packages/cli/src/modules/maintenance/commands/repo/clean.ts @@ -17,7 +17,7 @@ import fs from 'fs-extra'; import { resolve as resolvePath } from 'node:path'; import { PackageGraph } from '@backstage/cli-node'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { run } from '@backstage/cli-common'; export async function command(): Promise { diff --git a/packages/cli/src/modules/maintenance/commands/repo/fix.ts b/packages/cli/src/modules/maintenance/commands/repo/fix.ts index a5c6b519ed..4e718a8c9c 100644 --- a/packages/cli/src/modules/maintenance/commands/repo/fix.ts +++ b/packages/cli/src/modules/maintenance/commands/repo/fix.ts @@ -29,7 +29,7 @@ import { relative as relativePath, extname, } from 'node:path'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { publishPreflightCheck } from '../../lib/publishing'; const SCRIPT_EXTS = ['.js', '.jsx', '.ts', '.tsx', '.json']; diff --git a/packages/cli/src/modules/maintenance/commands/repo/list-deprecations.ts b/packages/cli/src/modules/maintenance/commands/repo/list-deprecations.ts index b89058e9fb..37bef58db6 100644 --- a/packages/cli/src/modules/maintenance/commands/repo/list-deprecations.ts +++ b/packages/cli/src/modules/maintenance/commands/repo/list-deprecations.ts @@ -19,7 +19,7 @@ import { ESLint } from 'eslint'; import { OptionValues } from 'commander'; import { relative as relativePath } from 'node:path'; import { PackageGraph } from '@backstage/cli-node'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; export async function command(opts: OptionValues) { const packages = await PackageGraph.listTargetPackages(); diff --git a/packages/cli/src/modules/maintenance/paths.ts b/packages/cli/src/modules/maintenance/paths.ts new file mode 100644 index 0000000000..2c658c27b3 --- /dev/null +++ b/packages/cli/src/modules/maintenance/paths.ts @@ -0,0 +1,20 @@ +/* + * 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 { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +export const paths = findPaths(__dirname); diff --git a/packages/cli/src/modules/migrate/commands/packageRole.ts b/packages/cli/src/modules/migrate/commands/packageRole.ts index 58c1487149..34c20dd6bb 100644 --- a/packages/cli/src/modules/migrate/commands/packageRole.ts +++ b/packages/cli/src/modules/migrate/commands/packageRole.ts @@ -18,7 +18,7 @@ import fs from 'fs-extra'; import { resolve as resolvePath } from 'node:path'; import { getPackages } from '@manypkg/get-packages'; import { PackageRoles } from '@backstage/cli-node'; -import { paths } from '../../../lib/paths'; +import { paths } from '../paths'; export default async () => { const { packages } = await getPackages(paths.targetDir); diff --git a/packages/cli/src/modules/migrate/commands/versions/bump.ts b/packages/cli/src/modules/migrate/commands/versions/bump.ts index a0a73dd78e..5ca151f162 100644 --- a/packages/cli/src/modules/migrate/commands/versions/bump.ts +++ b/packages/cli/src/modules/migrate/commands/versions/bump.ts @@ -25,7 +25,7 @@ import semver from 'semver'; import { OptionValues } from 'commander'; import { isError, NotFoundError } from '@backstage/errors'; import { resolve as resolvePath } from 'node:path'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { getHasYarnPlugin } from '../../../../lib/yarnPlugin'; import { fetchPackageInfo, diff --git a/packages/cli/src/modules/migrate/paths.ts b/packages/cli/src/modules/migrate/paths.ts new file mode 100644 index 0000000000..2c658c27b3 --- /dev/null +++ b/packages/cli/src/modules/migrate/paths.ts @@ -0,0 +1,20 @@ +/* + * 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 { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +export const paths = findPaths(__dirname); diff --git a/packages/cli/src/modules/new/lib/codeowners/codeowners.ts b/packages/cli/src/modules/new/lib/codeowners/codeowners.ts index 1cfddabffb..dd03320498 100644 --- a/packages/cli/src/modules/new/lib/codeowners/codeowners.ts +++ b/packages/cli/src/modules/new/lib/codeowners/codeowners.ts @@ -16,7 +16,7 @@ import fs from 'fs-extra'; import path from 'node:path'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; const TEAM_ID_RE = /^@[-\w]+\/[-\w]+$/; const USER_ID_RE = /^@[-\w]+$/; diff --git a/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts b/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts index 9dfd60baba..3662bb13fc 100644 --- a/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts +++ b/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts @@ -25,7 +25,7 @@ import upperCase from 'lodash/upperCase'; import upperFirst from 'lodash/upperFirst'; import lowerFirst from 'lodash/lowerFirst'; import { Lockfile } from '../../../../lib/versioning'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { createPackageVersionProvider } from '../../../../lib/version'; import { getHasYarnPlugin } from '../../../../lib/yarnPlugin'; diff --git a/packages/cli/src/modules/new/lib/execution/installNewPackage.ts b/packages/cli/src/modules/new/lib/execution/installNewPackage.ts index 0fe0284386..fb4a7318c2 100644 --- a/packages/cli/src/modules/new/lib/execution/installNewPackage.ts +++ b/packages/cli/src/modules/new/lib/execution/installNewPackage.ts @@ -16,7 +16,7 @@ import fs from 'fs-extra'; import upperFirst from 'lodash/upperFirst'; import camelCase from 'lodash/camelCase'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { Task } from '../tasks'; import { PortableTemplateInput } from '../types'; diff --git a/packages/cli/src/modules/new/lib/execution/writeTemplateContents.test.ts b/packages/cli/src/modules/new/lib/execution/writeTemplateContents.test.ts index a9f1ad61f7..7e0e81f137 100644 --- a/packages/cli/src/modules/new/lib/execution/writeTemplateContents.test.ts +++ b/packages/cli/src/modules/new/lib/execution/writeTemplateContents.test.ts @@ -17,7 +17,7 @@ import { relative as relativePath } from 'node:path'; import { writeTemplateContents } from './writeTemplateContents'; import { createMockDirectory } from '@backstage/backend-test-utils'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; const baseConfig = { version: '0.1.0', diff --git a/packages/cli/src/modules/new/lib/execution/writeTemplateContents.ts b/packages/cli/src/modules/new/lib/execution/writeTemplateContents.ts index 8b2f9ebf1e..c473632560 100644 --- a/packages/cli/src/modules/new/lib/execution/writeTemplateContents.ts +++ b/packages/cli/src/modules/new/lib/execution/writeTemplateContents.ts @@ -17,7 +17,7 @@ import fs from 'fs-extra'; import { dirname, resolve as resolvePath } from 'node:path'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { PortableTemplate, PortableTemplateInput } from '../types'; import { ForwardedError, InputError } from '@backstage/errors'; import { isMonoRepo as getIsMonoRepo } from '@backstage/cli-node'; diff --git a/packages/cli/src/modules/new/lib/preparation/collectPortableTemplateInput.ts b/packages/cli/src/modules/new/lib/preparation/collectPortableTemplateInput.ts index 38e8eaddba..913e37b88c 100644 --- a/packages/cli/src/modules/new/lib/preparation/collectPortableTemplateInput.ts +++ b/packages/cli/src/modules/new/lib/preparation/collectPortableTemplateInput.ts @@ -16,7 +16,7 @@ import inquirer, { DistinctQuestion } from 'inquirer'; import { getCodeownersFilePath, parseOwnerIds } from '../codeowners'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { PortableTemplateConfig, PortableTemplateInput, diff --git a/packages/cli/src/modules/new/lib/preparation/loadPortableTemplate.ts b/packages/cli/src/modules/new/lib/preparation/loadPortableTemplate.ts index f7053df552..d3231cd617 100644 --- a/packages/cli/src/modules/new/lib/preparation/loadPortableTemplate.ts +++ b/packages/cli/src/modules/new/lib/preparation/loadPortableTemplate.ts @@ -20,7 +20,7 @@ import recursiveReaddir from 'recursive-readdir'; import { resolve as resolvePath, relative as relativePath } from 'node:path'; import { dirname } from 'node:path'; import { parse as parseYaml } from 'yaml'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { PortableTemplateFile, PortableTemplatePointer, diff --git a/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.ts b/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.ts index dd937482a2..83b9e387d9 100644 --- a/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.ts +++ b/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.ts @@ -16,7 +16,7 @@ import fs from 'fs-extra'; import { resolve as resolvePath, dirname, isAbsolute } from 'node:path'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { defaultTemplates } from '../defaultTemplates'; import { PortableTemplateConfig, diff --git a/packages/cli/src/modules/new/paths.ts b/packages/cli/src/modules/new/paths.ts new file mode 100644 index 0000000000..2c658c27b3 --- /dev/null +++ b/packages/cli/src/modules/new/paths.ts @@ -0,0 +1,20 @@ +/* + * 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 { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +export const paths = findPaths(__dirname); diff --git a/packages/cli/src/modules/test/commands/package/test.ts b/packages/cli/src/modules/test/commands/package/test.ts index 992697d19c..fa804db20e 100644 --- a/packages/cli/src/modules/test/commands/package/test.ts +++ b/packages/cli/src/modules/test/commands/package/test.ts @@ -15,7 +15,7 @@ */ import { Command, OptionValues } from 'commander'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { runCheck } from '@backstage/cli-common'; function includesAnyOf(hayStack: string[], ...needles: string[]) { diff --git a/packages/cli/src/modules/test/commands/repo/test.ts b/packages/cli/src/modules/test/commands/repo/test.ts index f4d488ee0e..6b2ee2b04d 100644 --- a/packages/cli/src/modules/test/commands/repo/test.ts +++ b/packages/cli/src/modules/test/commands/repo/test.ts @@ -23,7 +23,7 @@ import { run as runJest, yargsOptions as jestYargsOptions } from 'jest-cli'; import { relative as relativePath } from 'node:path'; import { Command, OptionValues } from 'commander'; import { Lockfile, PackageGraph } from '@backstage/cli-node'; -import { paths } from '../../../../lib/paths'; +import { paths } from '../../paths'; import { runCheck, runOutput } from '@backstage/cli-common'; import { isChildPath } from '@backstage/cli-common'; import { SuccessCache } from '../../../../lib/cache/SuccessCache'; diff --git a/packages/cli/src/modules/test/paths.ts b/packages/cli/src/modules/test/paths.ts new file mode 100644 index 0000000000..2c658c27b3 --- /dev/null +++ b/packages/cli/src/modules/test/paths.ts @@ -0,0 +1,20 @@ +/* + * 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 { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +export const paths = findPaths(__dirname);