Skip to content

Commit 90241d0

Browse files
thomasballingerConvex, Inc.
authored andcommitted
Run tsc with node instead of tsc.CMD directly. (#24701)
The Node.js fix for CVE-2024-27980 makes running tsc.CMD directly no longer work on Windows. Change on all platforms for consistency. If TypeScript was indirectly installed but `tsc` still ended up in the `node_module/bin` directory then this change will cause such installations not to run a typecheck. GitOrigin-RevId: 7777aabbd94e40157a87f810985e620ec59368fa
1 parent 0cfd5a4 commit 90241d0

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

npm-packages/convex/src/cli/lib/typecheck.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ async function runTsc(
9393
handleResult: TypecheckResultHandler,
9494
): Promise<void> {
9595
// Check if tsc is even installed
96-
const tscPath = path.join(
97-
"node_modules",
98-
".bin",
99-
process.platform === "win32" ? "tsc.CMD" : "tsc",
100-
);
96+
const tscPath = path.join("node_modules", "typescript", "bin", "tsc");
10197
if (!ctx.fs.exists(tscPath)) {
10298
return handleResult("cantTypeCheck", () => {
10399
logError(
@@ -108,7 +104,10 @@ async function runTsc(
108104
}
109105

110106
// Check the TypeScript version matches the recommendation from Convex
111-
const versionResult = await spawnAsync(ctx, tscPath, ["--version"]);
107+
const versionResult = await spawnAsync(ctx, process.execPath, [
108+
tscPath,
109+
"--version",
110+
]);
112111

113112
const version = versionResult.stdout.match(/Version (.*)/)?.[1] ?? null;
114113
const hasOlderTypeScriptVersion = version && semver.lt(version, "4.8.4");
@@ -136,7 +135,11 @@ async function runTscInner(
136135
// be very useful if there's an error, but we'll run it again to get a nice
137136
// user-facing error in this exceptional case.
138137
// The `--listFiles` command prints out files touched on success or error.
139-
const result = await spawnAsync(ctx, tscPath, tscArgs.concat("--listFiles"));
138+
const result = await spawnAsync(ctx, process.execPath, [
139+
tscPath,
140+
...tscArgs,
141+
"--listFiles",
142+
]);
140143
if (result.status === null) {
141144
return handleResult("typecheckFailed", () => {
142145
logFailure(ctx, `TypeScript typecheck timed out.`);
@@ -192,9 +195,14 @@ async function runTscInner(
192195
},
193196
async () => {
194197
showSpinner(ctx, "Collecting TypeScript errors");
195-
await spawnAsync(ctx, tscPath, [...tscArgs, "--pretty", "true"], {
196-
stdio: "inherit",
197-
});
198+
await spawnAsync(
199+
ctx,
200+
process.execPath,
201+
[tscPath, ...tscArgs, "--pretty", "true"],
202+
{
203+
stdio: "inherit",
204+
},
205+
);
198206
// If this passes, we had a concurrent file change that'll overlap with
199207
// our observations in the first run. Invalidate our context's filesystem
200208
// but allow the rest of the system to observe the success.

0 commit comments

Comments
 (0)