UNPKG

@storm-software/eslint

Version:

A package containing the base ESLint configuration used by Storm Software across many projects.

44 lines (41 loc) 1.77 kB
import { findWorkspaceRoot } from './chunk-BSVVS7SV.js'; import { relative, joinPaths } from './chunk-VIFGWE6I.js'; import { init_esm_shims } from './chunk-H2OHWXFL.js'; import { existsSync, statSync } from 'node:fs'; // src/utils/tsconfig-path.ts init_esm_shims(); function getTsConfigPath(tsconfigPath, type = "app") { const workspaceRoot = findWorkspaceRoot(); if (tsconfigPath && existsSync(tsconfigPath) && statSync(tsconfigPath).isFile()) { return relative(workspaceRoot, tsconfigPath); } let result = checkTsConfigPath(process.cwd()); if (result) { return relative(workspaceRoot, joinPaths(process.cwd(), result)); } result = checkTsConfigPath(workspaceRoot); if (result) { return result; } console.warn( `No tsconfig.json found${tsconfigPath ? ` provided: ${tsconfigPath}` : ""}. Consider adding a tsconfig.json file to your project's ESLint configuration.` ); return workspaceRoot?.replace(/\\/g, "/").replaceAll(/\/$/g, "") === process.cwd().replace(/\\/g, "/").replaceAll(/\/$/g, "") ? "tsconfig.base.json" : `tsconfig.${type}.json`; } function checkTsConfigPath(root) { if (existsSync(joinPaths(root, "tsconfig.json"))) { return "tsconfig.json"; } else if (existsSync(joinPaths(root, "tsconfig.base.json"))) { return "tsconfig.base.json"; } else if (existsSync(joinPaths(root, "tsconfig.app.json"))) { return "tsconfig.app.json"; } else if (existsSync(joinPaths(root, "tsconfig.lib.json"))) { return "tsconfig.lib.json"; } else if (existsSync(joinPaths(root, "tsconfig.eslint.json"))) { return "tsconfig.eslint.json"; } else if (existsSync(joinPaths(root, "tsconfig.lint.json"))) { return "tsconfig.lint.json"; } return void 0; } export { checkTsConfigPath, getTsConfigPath };