Skip to content

Commit dad6bb4

Browse files
rChaozfengmk2
andauthored
fix(lint): correctly resolve tsgolint in yarn monorepo packages (#1310)
Closes #1296 The `oxlint-tsgolint` executable resolution algorithm assumes that there is a `node_modules` directory in the current working directory (current package directory). However, this is only true for `pnpm`, `yarn` only creates a single `node_modules` in the workspace root, unlike `pnpm` which creates one under every package. Because of this, `vp lint`/`vp check` fail to find the `tsgolint` executable. Updates the algorithm to extract the `node_modules` directory location based on `resolve()`, rather than `process.cwd()`. Additionally improves the error message to list all tried paths, rather than just one: **Before** ``` VITE+ - The Unified Toolchain for the Web Failed to find tsgolint executable: OXLINT_TSGOLINT_PATH points to '.\node_modules\.bin\tsgolint.cmd' which does not exist ``` **Now** ``` VITE+ - The Unified Toolchain for the Web error: Failed to resolve lint command: GenericFailure, Error: Unable to resolve oxlint-tsgolint executable, tried: - C:\Users\Matei\projects\agent-lab\node_modules\vite-plus\node_modules\.bin\tsgolint.exe - C:\Users\Matei\projects\agent-lab\node_modules\vite-plus\node_modules\.bin\tsgolint.cmd - C:\Users\Matei\projects\agent-lab\node_modules\.bin\tsgolint.exe - C:\Users\Matei\projects\agent-lab\node_modules\.bin\tsgolint.cmd ``` --------- Co-authored-by: MK (fengmk2) <fengmk2@gmail.com>
1 parent d7b9b6a commit dad6bb4

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/cli/src/resolve-lint.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ export async function lint(): Promise<{
4545
// On Windows, try .exe first (bun creates .exe), then .cmd (npm/pnpm/yarn create .cmd)
4646
const scriptDir = dirname(fileURLToPath(import.meta.url));
4747
const localBinDir = join(scriptDir, '..', 'node_modules', '.bin');
48-
const cwdBinDir = join(process.cwd(), 'node_modules', '.bin');
49-
oxlintTsgolintPath =
50-
[
51-
join(localBinDir, 'tsgolint.exe'),
52-
join(localBinDir, 'tsgolint.cmd'),
53-
join(cwdBinDir, 'tsgolint.exe'),
54-
join(cwdBinDir, 'tsgolint.cmd'),
55-
].find((p) => existsSync(p)) ?? '';
48+
const oxlintTsgolintPackagePath = dirname(dirname(oxlintTsgolintPath));
49+
const projectBinDir = join(oxlintTsgolintPackagePath, '..', '.bin');
50+
const pathCandidates = [
51+
join(localBinDir, 'tsgolint.exe'),
52+
join(localBinDir, 'tsgolint.cmd'),
53+
join(projectBinDir, 'tsgolint.exe'),
54+
join(projectBinDir, 'tsgolint.cmd'),
55+
];
56+
oxlintTsgolintPath = pathCandidates.find((p) => existsSync(p)) ?? '';
5657
// Bun stores packages in .bun/ cache dirs where the symlinked paths above won't match.
5758
if (!oxlintTsgolintPath) {
5859
try {
@@ -67,7 +68,10 @@ export async function lint(): Promise<{
6768
}
6869
}
6970
if (!oxlintTsgolintPath) {
70-
oxlintTsgolintPath = join(cwdBinDir, 'tsgolint.cmd');
71+
throw new Error(
72+
'Unable to resolve oxlint-tsgolint executable, tried:\n' +
73+
pathCandidates.map((path) => `- ${path}`).join('\n'),
74+
);
7175
}
7276
const relativePath = relative(process.cwd(), oxlintTsgolintPath);
7377
// Only prepend .\ if it's actually a relative path (not an absolute path returned by relative())

0 commit comments

Comments
 (0)