diff --git a/packages/cli-common/src/paths.ts b/packages/cli-common/src/paths.ts index f4fded7cd4..63173fb70e 100644 --- a/packages/cli-common/src/paths.ts +++ b/packages/cli-common/src/paths.ts @@ -110,11 +110,6 @@ export function findRootPath( ); } -// Finds the root of a given package -export function findOwnDir(searchDir: string) { - return OwnPathsImpl.findDir(searchDir); -} - // Finds the root of the monorepo that the package exists in. export function findOwnRootDir(ownDir: string) { const isLocal = fs.existsSync(resolvePath(ownDir, 'src')); @@ -204,6 +199,11 @@ class OwnPathsImpl implements OwnPaths { }; } +// Finds the root of a given package +export function findOwnDir(searchDir: string) { + return OwnPathsImpl.findDir(searchDir); +} + class TargetPathsImpl implements TargetPaths { #cwd: string | undefined; #dir: string | undefined; diff --git a/packages/cli-node/src/paths.ts b/packages/cli-node/src/paths.ts index 47b17c1825..334ef9eaf3 100644 --- a/packages/cli-node/src/paths.ts +++ b/packages/cli-node/src/paths.ts @@ -16,6 +16,7 @@ import { targetPaths, findOwnPaths } from '@backstage/cli-common'; +/* eslint-disable-next-line no-restricted-syntax */ const ownPaths = findOwnPaths(__dirname); /* eslint-disable-next-line no-restricted-syntax */ diff --git a/packages/cli/src/lib/version.ts b/packages/cli/src/lib/version.ts index a28feba015..aa8556534f 100644 --- a/packages/cli/src/lib/version.ts +++ b/packages/cli/src/lib/version.ts @@ -19,6 +19,7 @@ import semver from 'semver'; import { findOwnPaths } from '@backstage/cli-common'; import { Lockfile } from './versioning'; +/* eslint-disable-next-line no-restricted-syntax */ const ownPaths = findOwnPaths(__dirname); /* eslint-disable @backstage/no-relative-monorepo-imports */ diff --git a/packages/cli/src/modules/build/lib/bundler/moduleFederation.ts b/packages/cli/src/modules/build/lib/bundler/moduleFederation.ts index 5e19c28555..307cb5cebc 100644 --- a/packages/cli/src/modules/build/lib/bundler/moduleFederation.ts +++ b/packages/cli/src/modules/build/lib/bundler/moduleFederation.ts @@ -28,7 +28,7 @@ import { HostSharedDependencies, RuntimeSharedDependenciesGlobal, } from '@backstage/module-federation-common'; -import { dirname, join as joinPath, resolve as resolvePath } from 'path'; +import { dirname, join as joinPath, resolve as resolvePath } from 'node:path'; import fs from 'fs-extra'; import chokidar from 'chokidar'; import PQueue from 'p-queue'; diff --git a/packages/cli/src/modules/build/lib/bundler/paths.ts b/packages/cli/src/modules/build/lib/bundler/paths.ts index 2b65052550..5a7d3b14dc 100644 --- a/packages/cli/src/modules/build/lib/bundler/paths.ts +++ b/packages/cli/src/modules/build/lib/bundler/paths.ts @@ -49,6 +49,7 @@ export function resolveBundlingPaths(options: BundlingPathsOptions) { } else { targetHtml = resolvePath(targetDir, `${entry}.html`); if (!fs.pathExistsSync(targetHtml)) { + /* eslint-disable-next-line no-restricted-syntax */ targetHtml = findOwnPaths(__dirname).resolve( 'templates/serve_index.html', ); diff --git a/packages/cli/src/modules/info/commands/info.ts b/packages/cli/src/modules/info/commands/info.ts index 6fcf78cc84..c50a9da373 100644 --- a/packages/cli/src/modules/info/commands/info.ts +++ b/packages/cli/src/modules/info/commands/info.ts @@ -55,6 +55,7 @@ function hasBackstageField(packageName: string, targetPath: string): boolean { export default async (options: InfoOptions) => { await new Promise(async () => { const yarnVersion = await runOutput(['yarn', '--version']); + /* eslint-disable-next-line no-restricted-syntax */ const isLocal = fs.existsSync(findOwnPaths(__dirname).resolve('./src')); const backstageFile = targetPaths.resolveRoot('backstage.json'); diff --git a/packages/cli/src/modules/test/commands/package/test.ts b/packages/cli/src/modules/test/commands/package/test.ts index 6553ad93c9..c4acfb287b 100644 --- a/packages/cli/src/modules/test/commands/package/test.ts +++ b/packages/cli/src/modules/test/commands/package/test.ts @@ -38,6 +38,7 @@ export default async (_opts: OptionValues, cmd: Command) => { // Only include our config if caller isn't passing their own config if (!includesAnyOf(args, '-c', '--config')) { + /* eslint-disable-next-line no-restricted-syntax */ args.push('--config', findOwnPaths(__dirname).resolve('config/jest.js')); } diff --git a/packages/cli/src/modules/test/commands/repo/test.ts b/packages/cli/src/modules/test/commands/repo/test.ts index 46af4e6e4d..1f57279935 100644 --- a/packages/cli/src/modules/test/commands/repo/test.ts +++ b/packages/cli/src/modules/test/commands/repo/test.ts @@ -167,6 +167,7 @@ export async function command(opts: OptionValues, cmd: Command): Promise { // Only include our config if caller isn't passing their own config if (!hasFlags('-c', '--config')) { + /* eslint-disable-next-line no-restricted-syntax */ args.push('--config', findOwnPaths(__dirname).resolve('config/jest.js')); } diff --git a/packages/create-app/src/createApp.ts b/packages/create-app/src/createApp.ts index 9b09f59904..64db2e52ab 100644 --- a/packages/create-app/src/createApp.ts +++ b/packages/create-app/src/createApp.ts @@ -64,9 +64,11 @@ export default async (opts: OptionValues): Promise => { ]); // Pick the built-in template based on the --next flag + /* eslint-disable-next-line no-restricted-syntax */ + const ownPaths = findOwnPaths(__dirname); const builtInTemplate = opts.next - ? findOwnPaths(__dirname).resolve('templates/next-app') - : findOwnPaths(__dirname).resolve('templates/default-app'); + ? ownPaths.resolve('templates/next-app') + : ownPaths.resolve('templates/default-app'); // Use `--template-path` argument as template when specified. Otherwise, use the default template. const templateDir = opts.templatePath diff --git a/packages/e2e-test/src/commands/runCommand.ts b/packages/e2e-test/src/commands/runCommand.ts index ca95a2fa3e..dd9dd9b397 100644 --- a/packages/e2e-test/src/commands/runCommand.ts +++ b/packages/e2e-test/src/commands/runCommand.ts @@ -28,6 +28,9 @@ import mysql from 'mysql2/promise'; import pgtools from 'pgtools'; import { findOwnPaths, runOutput, run } from '@backstage/cli-common'; + +/* eslint-disable-next-line no-restricted-syntax */ +const ownPaths = findOwnPaths(__dirname); import { OptionValues } from 'commander'; const templatePackagePaths = [ @@ -135,7 +138,7 @@ async function buildDistWorkspace(workspaceName: string, rootDir: string) { } for (const pkgJsonPath of templatePackagePaths) { - const jsonPath = findOwnPaths(__dirname).resolveRoot(pkgJsonPath); + const jsonPath = ownPaths.resolveRoot(pkgJsonPath); const pkgTemplate = await fs.readFile(jsonPath, 'utf8'); const pkg = JSON.parse( handlebars.compile(pkgTemplate)( @@ -193,7 +196,7 @@ async function buildDistWorkspace(workspaceName: string, rootDir: string) { print('Pinning yarn version in workspace'); await pinYarnVersion(workspaceDir); - const yarnPatchesPath = findOwnPaths(__dirname).resolveRoot('.yarn/patches'); + const yarnPatchesPath = ownPaths.resolveRoot('.yarn/patches'); if (await fs.pathExists(yarnPatchesPath)) { print('Copying yarn patches'); await fs.copy(yarnPatchesPath, resolvePath(workspaceDir, '.yarn/patches')); @@ -211,10 +214,7 @@ async function buildDistWorkspace(workspaceName: string, rootDir: string) { * Pin the yarn version in a directory to the one we're using in the Backstage repo */ async function pinYarnVersion(dir: string) { - const yarnRc = await fs.readFile( - findOwnPaths(__dirname).resolveRoot('.yarnrc.yml'), - 'utf8', - ); + const yarnRc = await fs.readFile(ownPaths.resolveRoot('.yarnrc.yml'), 'utf8'); const yarnRcLines = yarnRc.split(/\r?\n/); const yarnPathLine = yarnRcLines.find(line => line.startsWith('yarnPath:')); if (!yarnPathLine) { @@ -225,7 +225,6 @@ async function pinYarnVersion(dir: string) { throw new Error(`Invalid 'yarnPath' in ${yarnRc}`); } const [, localYarnPath] = match; - const ownPaths = findOwnPaths(__dirname); const yarnPath = ownPaths.resolveRoot(localYarnPath); const yarnPluginPath = ownPaths.resolveRoot( localYarnPath, @@ -329,7 +328,7 @@ async function createApp( */ async function overrideYarnLockSeed(appDir: string) { const content = await fs.readFile( - findOwnPaths(__dirname).resolveRoot('packages/create-app/seed-yarn.lock'), + ownPaths.resolveRoot('packages/create-app/seed-yarn.lock'), 'utf8', ); const trimmedContent = content diff --git a/packages/repo-tools/src/commands/package-docs/utils.ts b/packages/repo-tools/src/commands/package-docs/utils.ts index 97a98a28d0..21294daa79 100644 --- a/packages/repo-tools/src/commands/package-docs/utils.ts +++ b/packages/repo-tools/src/commands/package-docs/utils.ts @@ -18,6 +18,7 @@ import { findOwnPaths } from '@backstage/cli-common'; import fs from 'fs-extra'; export async function createTemporaryTsConfig(dir: string) { + /* eslint-disable-next-line no-restricted-syntax */ const path = findOwnPaths(__dirname).resolveRoot( dir, 'tsconfig.typedoc.tmp.json', diff --git a/packages/repo-tools/src/commands/repo/schema/openapi/test.ts b/packages/repo-tools/src/commands/repo/schema/openapi/test.ts index 123a1182ea..d583854059 100644 --- a/packages/repo-tools/src/commands/repo/schema/openapi/test.ts +++ b/packages/repo-tools/src/commands/repo/schema/openapi/test.ts @@ -43,6 +43,7 @@ async function test( try { opticLocation = ( await exec(`yarn bin optic`, [], { + /* eslint-disable-next-line no-restricted-syntax */ cwd: findOwnPaths(__dirname).rootDir, }) ).stdout as string; diff --git a/packages/techdocs-cli/src/commands/serve/serve.ts b/packages/techdocs-cli/src/commands/serve/serve.ts index 511cad0472..10b7e1498f 100644 --- a/packages/techdocs-cli/src/commands/serve/serve.ts +++ b/packages/techdocs-cli/src/commands/serve/serve.ts @@ -39,6 +39,7 @@ function findPreviewBundlePath(): string { // This can be tested by running `yarn pack` and extracting the resulting tarball into a directory. // Within the extracted directory, run `npm install --only=prod`. // Once that's done you can test the CLI in any directory using `node /package `. + /* eslint-disable-next-line no-restricted-syntax */ return findOwnPaths(__dirname).resolve('dist/embedded-app'); } }