Skip to content

Commit

Permalink
Fix: Compiler couldn't resolve files at a long path(256+) on window (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin committed Jan 17, 2024
1 parent 8f4ee2d commit fa57980
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/compiler",
"comment": "Fix: Compiler couldn't resolve files at a long path(256+) on windows",
"type": "none"
}
],
"packageName": "@typespec/compiler"
}
15 changes: 13 additions & 2 deletions packages/compiler/src/core/node-host.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mkdir, readdir, readFile, realpath, rm, stat, writeFile } from "fs/promises";
import { realpath } from "fs";
import { mkdir, readdir, readFile, rm, stat, writeFile } from "fs/promises";
import { fileURLToPath, pathToFileURL } from "url";
import { createSourceFile } from "./diagnostics.js";
import { fetch } from "./fetch.js";
Expand Down Expand Up @@ -33,7 +34,17 @@ export const NodeHost: CompilerHost = {
return stat(path);
},
realpath(path) {
return realpath(path);
// BUG in the promise version of realpath https://github.com/microsoft/typespec/issues/2783
// Fix was only made to node 21.6 at this time. https://github.com/nodejs/node/issues/51031
return new Promise((resolve, reject) => {
realpath(path, (err, resolvedPath) => {
if (err) {
reject(err);
} else {
resolve(resolvedPath);
}
});
});
},
getSourceFileKind: getSourceFileKindFromExt,
mkdirp: (path: string) => mkdir(path, { recursive: true }),
Expand Down

0 comments on commit fa57980

Please sign in to comment.