Skip to content

Commit 2a8aef1

Browse files
committed
fix(cli): fallback to cwd's node_modules to find tsgolint
1 parent 895581e commit 2a8aef1

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

packages/cli/src/resolve-lint.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* provides ESLint-compatible linting with significantly better performance.
1212
*/
1313

14+
import { existsSync } from 'node:fs';
1415
import { dirname, join } from 'node:path';
1516
import { relative } from 'node:path/win32';
1617
import { fileURLToPath } from 'node:url';
@@ -33,22 +34,28 @@ export async function lint(): Promise<{
3334
}> {
3435
// Resolve the oxlint binary directly (it's a native executable)
3536
const binPath = resolve('oxlint/bin/oxlint');
36-
const oxlintTsgolintPath = join(
37-
dirname(fileURLToPath(import.meta.url)),
38-
'..',
39-
'node_modules',
40-
'.bin',
41-
`tsgolint${process.platform === 'win32' ? '.cmd' : ''}`,
42-
);
37+
let oxlintTsgolintPath = resolve('oxlint-tsgolint/bin/tsgolint');
38+
if (process.platform === 'win32') {
39+
// If on Windows, resolve the tsgolint binary from the local node_modules
40+
oxlintTsgolintPath = join(
41+
dirname(fileURLToPath(import.meta.url)),
42+
'..',
43+
'node_modules',
44+
'.bin',
45+
'tsgolint.cmd',
46+
);
47+
if (!existsSync(oxlintTsgolintPath)) {
48+
// Fallback to the cwd node_modules
49+
oxlintTsgolintPath = join(process.cwd(), 'node_modules', '.bin', 'tsgolint.cmd');
50+
}
51+
oxlintTsgolintPath = `.\\${relative(process.cwd(), oxlintTsgolintPath)}`;
52+
}
4353
const result = {
4454
binPath,
4555
// TODO: provide envs inference API
4656
envs: {
4757
...DEFAULT_ENVS,
48-
OXLINT_TSGOLINT_PATH:
49-
process.platform !== 'win32'
50-
? oxlintTsgolintPath
51-
: `.\\${relative(process.cwd(), oxlintTsgolintPath)}`,
58+
OXLINT_TSGOLINT_PATH: oxlintTsgolintPath,
5259
},
5360
};
5461
return result;

0 commit comments

Comments
 (0)