|
11 | 11 | * provides ESLint-compatible linting with significantly better performance. |
12 | 12 | */ |
13 | 13 |
|
14 | | -import { existsSync } from 'node:fs'; |
| 14 | +import { existsSync, realpathSync } from 'node:fs'; |
15 | 15 | import { dirname, join } from 'node:path'; |
16 | 16 | import { relative } from 'node:path/win32'; |
17 | 17 | import { fileURLToPath } from 'node:url'; |
@@ -43,15 +43,32 @@ export async function lint(): Promise<{ |
43 | 43 | let oxlintTsgolintPath = resolve('oxlint-tsgolint/bin/tsgolint'); |
44 | 44 | if (process.platform === 'win32') { |
45 | 45 | // On Windows, try .exe first (bun creates .exe), then .cmd (npm/pnpm/yarn create .cmd) |
46 | | - const localBinDir = join(dirname(fileURLToPath(import.meta.url)), '..', 'node_modules', '.bin'); |
| 46 | + const scriptDir = dirname(fileURLToPath(import.meta.url)); |
| 47 | + const localBinDir = join(scriptDir, '..', 'node_modules', '.bin'); |
47 | 48 | const cwdBinDir = join(process.cwd(), 'node_modules', '.bin'); |
48 | 49 | oxlintTsgolintPath = |
49 | 50 | [ |
50 | 51 | join(localBinDir, 'tsgolint.exe'), |
51 | 52 | join(localBinDir, 'tsgolint.cmd'), |
52 | 53 | join(cwdBinDir, 'tsgolint.exe'), |
53 | 54 | join(cwdBinDir, 'tsgolint.cmd'), |
54 | | - ].find((p) => existsSync(p)) ?? join(cwdBinDir, 'tsgolint.cmd'); |
| 55 | + ].find((p) => existsSync(p)) ?? ''; |
| 56 | + // Bun stores packages in .bun/ cache dirs where the symlinked paths above won't match. |
| 57 | + if (!oxlintTsgolintPath) { |
| 58 | + try { |
| 59 | + const realPkgDir = realpathSync(join(scriptDir, '..')); |
| 60 | + const realBinDir = join(dirname(realPkgDir), '.bin'); |
| 61 | + oxlintTsgolintPath = |
| 62 | + [join(realBinDir, 'tsgolint.exe'), join(realBinDir, 'tsgolint.cmd')].find((p) => |
| 63 | + existsSync(p), |
| 64 | + ) ?? ''; |
| 65 | + } catch { |
| 66 | + // realpath failed, fall through to default |
| 67 | + } |
| 68 | + } |
| 69 | + if (!oxlintTsgolintPath) { |
| 70 | + oxlintTsgolintPath = join(cwdBinDir, 'tsgolint.cmd'); |
| 71 | + } |
55 | 72 | const relativePath = relative(process.cwd(), oxlintTsgolintPath); |
56 | 73 | // Only prepend .\ if it's actually a relative path (not an absolute path returned by relative()) |
57 | 74 | oxlintTsgolintPath = /^[a-zA-Z]:/.test(relativePath) ? relativePath : `.\\${relativePath}`; |
|
0 commit comments