Fix lint errors: add eslint-disable for __dirname, fix no-use-before-define

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2026-02-22 14:32:02 +01:00
parent 6fa63d411f
commit 553e727d5f
13 changed files with 26 additions and 16 deletions
+5 -5
View File
@@ -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;
+1
View File
@@ -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 */
+1
View File
@@ -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 */
@@ -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';
@@ -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',
);
@@ -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');
@@ -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'));
}
@@ -167,6 +167,7 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
// 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'));
}
+4 -2
View File
@@ -64,9 +64,11 @@ export default async (opts: OptionValues): Promise<void> => {
]);
// 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
+7 -8
View File
@@ -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
@@ -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',
@@ -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;
@@ -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 <tmp-dir>/package <command>`.
/* eslint-disable-next-line no-restricted-syntax */
return findOwnPaths(__dirname).resolve('dist/embedded-app');
}
}