Skip to content

Commit d84f9c1

Browse files
authored
fix(cli): fix tsgolint path resolution for yarn install (#360)
### What changed? - Added `existsSync` import from `node:fs` to check if files exist - Modified the tsgolint binary resolution logic to: - First try to resolve from `oxlint-tsgolint/bin/tsgolint` for non-Windows platforms - For Windows, attempt to find the binary in the local `node_modules/.bin` directory - Add a fallback to the current working directory's `node_modules/.bin` if not found - Simplified the environment variable assignment by moving the platform-specific logic to the path resolution ```bash yarn lint Failed to find tsgolint executable: OXLINT_TSGOLINT_PATH points to '~/rollipop/node_modules/@voidzero-dev/vite-plus/node_modules/.bin/tsgolint' which does not exist ```
1 parent 4819622 commit d84f9c1

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)