Skip to content

Commit

Permalink
fix(generate:typetests): Resolve symlinks to previous versions (micro…
Browse files Browse the repository at this point in the history
…soft#22494)

The previous version types path is a symlink or junction, and without
resolving them to a real path, the module resolution in ts-morph was
wrong, and was picking up local packages.

This change ensures we resolve the symlink/junction before we add the
SourceFile to ts-morph.
  • Loading branch information
tylerbutler authored Sep 13, 2024
1 parent 697bb0c commit 90991c9
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License.
*/

import { realpathSync } from "node:fs";
import { mkdir, rm, writeFile } from "node:fs/promises";
import path from "node:path";
import {
Expand Down Expand Up @@ -515,7 +516,11 @@ export function loadTypesSourceFile(typesPath: string): SourceFile {
module: ModuleKind.Node16,
},
});
const sourceFile = project.addSourceFileAtPath(typesPath);

// The typesPath may be a symlink or junction, so resolve the real path
// before adding it to the project to ensure correct module resolutions.
const realTypesPath = realpathSync(typesPath);
const sourceFile = project.addSourceFileAtPath(realTypesPath);
return sourceFile;
}

Expand Down

0 comments on commit 90991c9

Please sign in to comment.