diff --git a/packages/cli/src/resolve-lint.ts b/packages/cli/src/resolve-lint.ts index 399559b5ef..671b88c650 100644 --- a/packages/cli/src/resolve-lint.ts +++ b/packages/cli/src/resolve-lint.ts @@ -45,14 +45,15 @@ export async function lint(): Promise<{ // On Windows, try .exe first (bun creates .exe), then .cmd (npm/pnpm/yarn create .cmd) const scriptDir = dirname(fileURLToPath(import.meta.url)); const localBinDir = join(scriptDir, '..', 'node_modules', '.bin'); - const cwdBinDir = join(process.cwd(), 'node_modules', '.bin'); - oxlintTsgolintPath = - [ - join(localBinDir, 'tsgolint.exe'), - join(localBinDir, 'tsgolint.cmd'), - join(cwdBinDir, 'tsgolint.exe'), - join(cwdBinDir, 'tsgolint.cmd'), - ].find((p) => existsSync(p)) ?? ''; + const oxlintTsgolintPackagePath = dirname(dirname(oxlintTsgolintPath)); + const projectBinDir = join(oxlintTsgolintPackagePath, '..', '.bin'); + const pathCandidates = [ + join(localBinDir, 'tsgolint.exe'), + join(localBinDir, 'tsgolint.cmd'), + join(projectBinDir, 'tsgolint.exe'), + join(projectBinDir, 'tsgolint.cmd'), + ]; + oxlintTsgolintPath = pathCandidates.find((p) => existsSync(p)) ?? ''; // Bun stores packages in .bun/ cache dirs where the symlinked paths above won't match. if (!oxlintTsgolintPath) { try { @@ -67,7 +68,10 @@ export async function lint(): Promise<{ } } if (!oxlintTsgolintPath) { - oxlintTsgolintPath = join(cwdBinDir, 'tsgolint.cmd'); + throw new Error( + 'Unable to resolve oxlint-tsgolint executable, tried:\n' + + pathCandidates.map((path) => `- ${path}`).join('\n'), + ); } const relativePath = relative(process.cwd(), oxlintTsgolintPath); // Only prepend .\ if it's actually a relative path (not an absolute path returned by relative())