diff --git a/.changeset/cli-common-cached-paths.md b/.changeset/cli-common-cached-paths.md new file mode 100644 index 0000000000..27a683e35a --- /dev/null +++ b/.changeset/cli-common-cached-paths.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli-common': patch +--- + +Added hierarchical caching to `findOwnDir`, avoiding redundant filesystem walks when `findPaths` is called from multiple locations within the same package. diff --git a/packages/cli-common/src/paths.ts b/packages/cli-common/src/paths.ts index 5da2d596a4..51f7863b99 100644 --- a/packages/cli-common/src/paths.ts +++ b/packages/cli-common/src/paths.ts @@ -84,15 +84,45 @@ export function findRootPath( ); } +// Hierarchical cache for ownDir lookups. When we resolve a searchDir to its +// package root, we also cache every intermediate directory along the way. This +// means sibling directories only need to walk up until they hit a cached ancestor. +const ownDirCache = new Map(); + // Finds the root of a given package export function findOwnDir(searchDir: string) { - const path = findRootPath(searchDir, () => true); - if (!path) { - throw new Error( - `No package.json found while searching for package root of ${searchDir}`, - ); + const visited: string[] = []; + let dir = searchDir; + + for (let i = 0; i < 1000; i++) { + const cached = ownDirCache.get(dir); + if (cached !== undefined) { + for (const d of visited) { + ownDirCache.set(d, cached); + } + return cached; + } + + visited.push(dir); + + const packagePath = resolvePath(dir, 'package.json'); + if (fs.existsSync(packagePath)) { + for (const d of visited) { + ownDirCache.set(d, dir); + } + return dir; + } + + const newDir = dirname(dir); + if (newDir === dir) { + break; + } + dir = newDir; } - return path; + + throw new Error( + `No package.json found while searching for package root of ${searchDir}`, + ); } // Finds the root of the monorepo that the package exists in. Only accessible when running inside Backstage repo. @@ -110,6 +140,12 @@ export function findOwnRootDir(ownDir: string) { /** * Find paths related to a package and its execution context. * + * This function is cheap to call repeatedly. The package root lookup is cached + * hierarchically, so calls from different subdirectories within the same package + * only walk the filesystem once. Prefer calling this eagerly at module scope + * rather than sharing a single instance across modules — this keeps modules + * independent and works correctly when they are split into separate packages. + * * @public * @example * 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 bf4c5a46f8..8d2a295dbb 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,10 @@ import { PackageGraph, PackageRoles, } from '@backstage/cli-node'; -import { paths } from '../../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 5fefb8c03f..3e34ff3bc8 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,10 @@ import { OptionValues } from 'commander'; import { startPackage } from './startPackage'; import { resolveLinkedWorkspace } from './resolveLinkedWorkspace'; import { findRoleFromCommand } from '../../../lib/role'; -import { paths } from '../../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 4b87f0e02a..9ae2880160 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,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); 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 d55681ea07..b865cea5f4 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,10 @@ import { getModuleFederationRemoteOptions, serveBundle, } from '../../../../build/lib/bundler'; -import { paths } from '../../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 c8568be06a..a9a0d51fb9 100644 --- a/packages/cli/src/modules/build/commands/repo/build.ts +++ b/packages/cli/src/modules/build/commands/repo/build.ts @@ -18,7 +18,10 @@ 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 '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 b1cc9faefd..f4a9d2e7eb 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,10 @@ import { PackageGraph } from '@backstage/cli-node'; import { findTargetPackages } from './start'; import { posix } 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 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 e02dfdc6a3..46dd95dd3f 100644 --- a/packages/cli/src/modules/build/commands/repo/start.ts +++ b/packages/cli/src/modules/build/commands/repo/start.ts @@ -20,7 +20,10 @@ import { PackageRole, } from '@backstage/cli-node'; import { relative as relativePath } from 'node:path'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 54d33719e0..6efb306939 100644 --- a/packages/cli/src/modules/build/lib/builder/config.ts +++ b/packages/cli/src/modules/build/lib/builder/config.ts @@ -39,7 +39,10 @@ import { import { forwardFileImports, cssEntryPoints } from './plugins'; import { BuildOptions, Output } from './types'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 16a6ecb828..00b3f93b76 100644 --- a/packages/cli/src/modules/build/lib/builder/packager.ts +++ b/packages/cli/src/modules/build/lib/builder/packager.ts @@ -18,7 +18,10 @@ 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 '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 d65fd815c8..ae180ff2bf 100644 --- a/packages/cli/src/modules/build/lib/bundler/config.ts +++ b/packages/cli/src/modules/build/lib/bundler/config.ts @@ -25,11 +25,14 @@ 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 '../../paths'; + import fs from 'fs-extra'; import { optimization as optimizationConfig } from './optimization'; import pickBy from 'lodash/pickBy'; -import { runOutput } from '@backstage/cli-common'; +import { runOutput, findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const cliPaths = findPaths(__dirname); import { transforms } from './transforms'; import { version } from '../../../../lib/version'; import yn from 'yn'; diff --git a/packages/cli/src/modules/build/lib/bundler/hasReactDomClient.ts b/packages/cli/src/modules/build/lib/bundler/hasReactDomClient.ts index 5e3f4aac49..961d161ced 100644 --- a/packages/cli/src/modules/build/lib/bundler/hasReactDomClient.ts +++ b/packages/cli/src/modules/build/lib/bundler/hasReactDomClient.ts @@ -14,7 +14,10 @@ * limitations under the License. */ -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 cb3edca684..c9b3e9c0f0 100644 --- a/packages/cli/src/modules/build/lib/bundler/linkWorkspaces.ts +++ b/packages/cli/src/modules/build/lib/bundler/linkWorkspaces.ts @@ -17,7 +17,10 @@ import { relative as relativePath } from 'node:path'; import { getPackages } from '@manypkg/get-packages'; import { rspack } from '@rspack/core'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); /** * 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 48702fcbd9..1c1eef33e4 100644 --- a/packages/cli/src/modules/build/lib/bundler/packageDetection.ts +++ b/packages/cli/src/modules/build/lib/bundler/packageDetection.ts @@ -20,7 +20,10 @@ 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 '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const cliPaths = findPaths(__dirname); 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 f7fb6ecdc2..9b0c7eaa3a 100644 --- a/packages/cli/src/modules/build/lib/bundler/paths.ts +++ b/packages/cli/src/modules/build/lib/bundler/paths.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); 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 eadbd1b208..3ec20b3e54 100644 --- a/packages/cli/src/modules/build/lib/bundler/server.ts +++ b/packages/cli/src/modules/build/lib/bundler/server.ts @@ -22,7 +22,10 @@ import openBrowser from 'react-dev-utils/openBrowser'; import { rspack } from '@rspack/core'; import { RspackDevServer } from '@rspack/dev-server'; -import { paths as libPaths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const libPaths = findPaths(__dirname); 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 ca71e0f332..61beba8b0b 100644 --- a/packages/cli/src/modules/build/lib/packager/createDistWorkspace.ts +++ b/packages/cli/src/modules/build/lib/packager/createDistWorkspace.ts @@ -24,8 +24,11 @@ import { import { tmpdir } from 'node:os'; import * as tar from 'tar'; import partition from 'lodash/partition'; -import { paths } from '../../paths'; -import { run } from '@backstage/cli-common'; + +import { run, findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); import { dependencies as cliDependencies, devDependencies as cliDevDependencies, diff --git a/packages/cli/src/modules/build/lib/role.test.ts b/packages/cli/src/modules/build/lib/role.test.ts index ba59dcd8c0..a418b42232 100644 --- a/packages/cli/src/modules/build/lib/role.test.ts +++ b/packages/cli/src/modules/build/lib/role.test.ts @@ -20,12 +20,13 @@ import { findRoleFromCommand } from './role'; const mockDir = createMockDirectory(); -jest.mock('../paths', () => ({ - paths: { +jest.mock('@backstage/cli-common', () => ({ + ...jest.requireActual('@backstage/cli-common'), + findPaths: () => ({ resolveTarget(filename: string) { return mockDir.resolve(filename); }, - }, + }), })); describe('findRoleFromCommand', () => { diff --git a/packages/cli/src/modules/build/lib/role.ts b/packages/cli/src/modules/build/lib/role.ts index 9dc3b55762..b8de6e5079 100644 --- a/packages/cli/src/modules/build/lib/role.ts +++ b/packages/cli/src/modules/build/lib/role.ts @@ -16,7 +16,10 @@ import fs from 'fs-extra'; import { OptionValues } from 'commander'; -import { paths } from '../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 511fdd84bb..dea59999be 100644 --- a/packages/cli/src/modules/build/lib/runner/runBackend.ts +++ b/packages/cli/src/modules/build/lib/runner/runBackend.ts @@ -21,7 +21,10 @@ 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 '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); import spawn from 'cross-spawn'; const loaderArgs = [ diff --git a/packages/cli/src/modules/build/paths.ts b/packages/cli/src/modules/build/paths.ts deleted file mode 100644 index 2c658c27b3..0000000000 --- a/packages/cli/src/modules/build/paths.ts +++ /dev/null @@ -1,20 +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. - */ - -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/config/lib/config.ts b/packages/cli/src/modules/config/lib/config.ts index a8d749f4d1..0a20cf4705 100644 --- a/packages/cli/src/modules/config/lib/config.ts +++ b/packages/cli/src/modules/config/lib/config.ts @@ -16,7 +16,10 @@ import { ConfigSources, loadConfigSchema } from '@backstage/config-loader'; import { AppConfig, ConfigReader } from '@backstage/config'; -import { paths } from '../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 deleted file mode 100644 index 2c658c27b3..0000000000 --- a/packages/cli/src/modules/config/paths.ts +++ /dev/null @@ -1,20 +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. - */ - -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 e22d14bd6d..d5deab03f5 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,10 @@ import fs from 'fs-extra'; import chalk from 'chalk'; import { stringify as stringifyYaml } from 'yaml'; import inquirer, { Question, Answers } from 'inquirer'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 deleted file mode 100644 index 2c658c27b3..0000000000 --- a/packages/cli/src/modules/create-github-app/paths.ts +++ /dev/null @@ -1,20 +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. - */ - -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 d76c8cfc4b..3229f5f3ae 100644 --- a/packages/cli/src/modules/info/commands/info.ts +++ b/packages/cli/src/modules/info/commands/info.ts @@ -16,8 +16,11 @@ import { version as cliVersion } from '../../../../package.json'; import os from 'node:os'; -import { runOutput } from '@backstage/cli-common'; -import { paths } from '../paths'; +import { runOutput, findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); + 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 deleted file mode 100644 index 2c658c27b3..0000000000 --- a/packages/cli/src/modules/info/paths.ts +++ /dev/null @@ -1,20 +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. - */ - -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 58fa646e48..66e29e8c1f 100644 --- a/packages/cli/src/modules/lint/commands/package/lint.ts +++ b/packages/cli/src/modules/lint/commands/package/lint.ts @@ -16,7 +16,10 @@ import fs from 'fs-extra'; import { OptionValues } from 'commander'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 c3537ab254..978119ba73 100644 --- a/packages/cli/src/modules/lint/commands/repo/lint.ts +++ b/packages/cli/src/modules/lint/commands/repo/lint.ts @@ -25,7 +25,10 @@ import { Lockfile, runWorkerQueueThreads, } from '@backstage/cli-node'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 deleted file mode 100644 index 2c658c27b3..0000000000 --- a/packages/cli/src/modules/lint/paths.ts +++ /dev/null @@ -1,20 +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. - */ - -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 0a2d11bc14..333ab588c2 100644 --- a/packages/cli/src/modules/maintenance/commands/package/clean.ts +++ b/packages/cli/src/modules/maintenance/commands/package/clean.ts @@ -15,7 +15,10 @@ */ import fs from 'fs-extra'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 4c1d475703..a4769df785 100644 --- a/packages/cli/src/modules/maintenance/commands/package/pack.ts +++ b/packages/cli/src/modules/maintenance/commands/package/pack.ts @@ -18,7 +18,10 @@ import { productionPack, revertProductionPack, } from '../../../../modules/build/lib/packager/productionPack'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 fc1aabd1b7..5bebbfd4d8 100644 --- a/packages/cli/src/modules/maintenance/commands/repo/clean.ts +++ b/packages/cli/src/modules/maintenance/commands/repo/clean.ts @@ -17,8 +17,11 @@ import fs from 'fs-extra'; import { resolve as resolvePath } from 'node:path'; import { PackageGraph } from '@backstage/cli-node'; -import { paths } from '../../paths'; -import { run } from '@backstage/cli-common'; + +import { run, findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); export async function command(): Promise { const packages = await PackageGraph.listTargetPackages(); diff --git a/packages/cli/src/modules/maintenance/commands/repo/fix.ts b/packages/cli/src/modules/maintenance/commands/repo/fix.ts index 4e718a8c9c..f2d52e2f99 100644 --- a/packages/cli/src/modules/maintenance/commands/repo/fix.ts +++ b/packages/cli/src/modules/maintenance/commands/repo/fix.ts @@ -29,7 +29,10 @@ import { relative as relativePath, extname, } from 'node:path'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 37bef58db6..0e646c948b 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,10 @@ import { ESLint } from 'eslint'; import { OptionValues } from 'commander'; import { relative as relativePath } from 'node:path'; import { PackageGraph } from '@backstage/cli-node'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 deleted file mode 100644 index 2c658c27b3..0000000000 --- a/packages/cli/src/modules/maintenance/paths.ts +++ /dev/null @@ -1,20 +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. - */ - -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 34c20dd6bb..cc3e1bce69 100644 --- a/packages/cli/src/modules/migrate/commands/packageRole.ts +++ b/packages/cli/src/modules/migrate/commands/packageRole.ts @@ -18,7 +18,10 @@ 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 '../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 5ca151f162..8a12683abc 100644 --- a/packages/cli/src/modules/migrate/commands/versions/bump.ts +++ b/packages/cli/src/modules/migrate/commands/versions/bump.ts @@ -13,7 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { BACKSTAGE_JSON, bootstrapEnvProxyAgents } from '@backstage/cli-common'; +import { BACKSTAGE_JSON, bootstrapEnvProxyAgents, findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); bootstrapEnvProxyAgents(); @@ -25,7 +28,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 '../../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 deleted file mode 100644 index 2c658c27b3..0000000000 --- a/packages/cli/src/modules/migrate/paths.ts +++ /dev/null @@ -1,20 +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. - */ - -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 dd03320498..685363bdd3 100644 --- a/packages/cli/src/modules/new/lib/codeowners/codeowners.ts +++ b/packages/cli/src/modules/new/lib/codeowners/codeowners.ts @@ -16,7 +16,10 @@ import fs from 'fs-extra'; import path 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 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 3662bb13fc..084c9d2d33 100644 --- a/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts +++ b/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts @@ -25,7 +25,10 @@ import upperCase from 'lodash/upperCase'; import upperFirst from 'lodash/upperFirst'; import lowerFirst from 'lodash/lowerFirst'; import { Lockfile } from '../../../../lib/versioning'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 fb4a7318c2..7281689ff5 100644 --- a/packages/cli/src/modules/new/lib/execution/installNewPackage.ts +++ b/packages/cli/src/modules/new/lib/execution/installNewPackage.ts @@ -16,7 +16,10 @@ import fs from 'fs-extra'; import upperFirst from 'lodash/upperFirst'; import camelCase from 'lodash/camelCase'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 7e0e81f137..2a4cb8a8c5 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,10 @@ import { relative as relativePath } from 'node:path'; import { writeTemplateContents } from './writeTemplateContents'; import { createMockDirectory } from '@backstage/backend-test-utils'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 c473632560..99e6a1931f 100644 --- a/packages/cli/src/modules/new/lib/execution/writeTemplateContents.ts +++ b/packages/cli/src/modules/new/lib/execution/writeTemplateContents.ts @@ -17,12 +17,15 @@ import fs from 'fs-extra'; import { dirname, resolve as resolvePath } from 'node:path'; -import { paths } from '../../paths'; + import { PortableTemplate, PortableTemplateInput } from '../types'; import { ForwardedError, InputError } from '@backstage/errors'; import { isMonoRepo as getIsMonoRepo } from '@backstage/cli-node'; import { PortableTemplater } from './PortableTemplater'; -import { isChildPath } from '@backstage/cli-common'; +import { isChildPath, findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); export async function writeTemplateContents( template: PortableTemplate, diff --git a/packages/cli/src/modules/new/lib/preparation/collectPortableTemplateInput.ts b/packages/cli/src/modules/new/lib/preparation/collectPortableTemplateInput.ts index 913e37b88c..7a6046f927 100644 --- a/packages/cli/src/modules/new/lib/preparation/collectPortableTemplateInput.ts +++ b/packages/cli/src/modules/new/lib/preparation/collectPortableTemplateInput.ts @@ -16,7 +16,10 @@ import inquirer, { DistinctQuestion } from 'inquirer'; import { getCodeownersFilePath, parseOwnerIds } from '../codeowners'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 d3231cd617..8b77296249 100644 --- a/packages/cli/src/modules/new/lib/preparation/loadPortableTemplate.ts +++ b/packages/cli/src/modules/new/lib/preparation/loadPortableTemplate.ts @@ -20,7 +20,10 @@ 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 '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 83b9e387d9..61e04a20a5 100644 --- a/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.ts +++ b/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.ts @@ -16,7 +16,10 @@ import fs from 'fs-extra'; import { resolve as resolvePath, dirname, isAbsolute } from 'node:path'; -import { paths } from '../../paths'; +import { findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); import { defaultTemplates } from '../defaultTemplates'; import { PortableTemplateConfig, diff --git a/packages/cli/src/modules/new/paths.ts b/packages/cli/src/modules/new/paths.ts deleted file mode 100644 index 2c658c27b3..0000000000 --- a/packages/cli/src/modules/new/paths.ts +++ /dev/null @@ -1,20 +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. - */ - -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 fa804db20e..e425af4962 100644 --- a/packages/cli/src/modules/test/commands/package/test.ts +++ b/packages/cli/src/modules/test/commands/package/test.ts @@ -15,8 +15,11 @@ */ import { Command, OptionValues } from 'commander'; -import { paths } from '../../paths'; -import { runCheck } from '@backstage/cli-common'; + +import { runCheck, findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); function includesAnyOf(hayStack: string[], ...needles: string[]) { for (const needle of needles) { diff --git a/packages/cli/src/modules/test/commands/repo/test.ts b/packages/cli/src/modules/test/commands/repo/test.ts index 6b2ee2b04d..717f15e788 100644 --- a/packages/cli/src/modules/test/commands/repo/test.ts +++ b/packages/cli/src/modules/test/commands/repo/test.ts @@ -23,8 +23,11 @@ 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 '../../paths'; -import { runCheck, runOutput } from '@backstage/cli-common'; + +import { runCheck, runOutput, findPaths } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const paths = findPaths(__dirname); 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 deleted file mode 100644 index 2c658c27b3..0000000000 --- a/packages/cli/src/modules/test/paths.ts +++ /dev/null @@ -1,20 +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. - */ - -import { findPaths } from '@backstage/cli-common'; - -/* eslint-disable-next-line no-restricted-syntax */ -export const paths = findPaths(__dirname);