Skip to content

Commit 3da07e2

Browse files
committed
fix(oxlint-plugin): Resolve the oxlint bin without assuming a pnpm layout
The rule-harness tests spawned node_modules/.pnpm/node_modules/.bin/oxlint, a pnpm virtual-store hoist path. oxlint is only a transitive dependency of vite-plus, so no package manager guarantees a stable .bin shim for it: under Bun-style hoisted installs that path does not exist, and the root node_modules/.bin/oxlint is vite-plus's LSP-only wrapper, so all 35 rule tests fail with spawn ENOENT. Resolve oxlint/package.json through vite-plus instead, at module scope so a broken install fails once with a clear resolution error, and run the package's own bin/oxlint through process.execPath so the spawn does not depend on shebang support or whichever node is first on PATH.
1 parent df78cda commit 3da07e2

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

‎oxlint-plugin-t3code/test/utils.ts‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ import * as Predicate from "effect/Predicate";
99
import * as Schema from "effect/Schema";
1010
import * as Stream from "effect/Stream";
1111
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
12+
import * as NodeModule from "node:module";
13+
14+
// oxlint is only a transitive dependency (via vite-plus), so its bin placement
15+
// varies by package manager: pnpm hoists it into the virtual store, while
16+
// other layouts expose vite-plus's LSP-only wrapper instead. Resolve the real
17+
// package through vite-plus rather than hardcoding either layout, and do it at
18+
// module scope so a broken install fails once with a resolution error instead
19+
// of as an opaque defect in every test.
20+
const oxlintPackageJsonPath = NodeModule.createRequire(
21+
NodeModule.createRequire(import.meta.url).resolve("vite-plus/package.json"),
22+
).resolve("oxlint/package.json");
1223

1324
class OxlintFixtureFailure extends Data.TaggedError("OxlintFixtureFailure")<{
1425
readonly exitCode: number;
@@ -93,14 +104,7 @@ export const createOxlintRuleHarness = (
93104
const configPath = path.join(fixtureDir, ".oxlintrc.json");
94105
const sourcePath = path.join(fixtureDir, options.filename ?? "fixture.ts");
95106
const repoRoot = path.join(import.meta.dirname, "..", "..");
96-
const oxlintBin = path.join(
97-
repoRoot,
98-
"node_modules",
99-
".pnpm",
100-
"node_modules",
101-
".bin",
102-
"oxlint",
103-
);
107+
const oxlintBin = path.join(path.dirname(oxlintPackageJsonPath), "bin", "oxlint");
104108
const pluginPath = path.join(repoRoot, "oxlint-plugin-t3code", "index.ts");
105109

106110
yield* fs.writeFileString(
@@ -112,8 +116,13 @@ export const createOxlintRuleHarness = (
112116
);
113117
yield* fs.writeFileString(sourcePath, source);
114118

119+
// Run through the current Node binary: oxlint's bin is an extensionless
120+
// shebang script, which Windows cannot spawn directly and which would
121+
// otherwise pick up whatever node is first on PATH.
115122
const output = yield* spawnAndCollectOutput(
116-
ChildProcess.make(oxlintBin, ["--config", configPath, sourcePath], { cwd: repoRoot }),
123+
ChildProcess.make(process.execPath, [oxlintBin, "--config", configPath, sourcePath], {
124+
cwd: repoRoot,
125+
}),
117126
);
118127

119128
if (output.exitCode !== 0) {

0 commit comments

Comments
 (0)