Skip to content

Commit 0be8434

Browse files
author
Jeremy Dorne
committed
symlink fixes
realPathToSymlinks don't add paths more than once realPathToSymlinks ternary + path over realPath flip in the ternary fix boolean
1 parent 9b66258 commit 0be8434

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/compiler/moduleSpecifiers.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ namespace ts.moduleSpecifiers {
213213
}
214214

215215
export function forEachFileNameOfModule<T>(
216-
importingFileName: string,
216+
_importingFileName: string,
217217
importedFileName: string,
218218
host: ModuleSpecifierResolutionHost,
219219
preferSymlinks: boolean,
@@ -233,27 +233,23 @@ namespace ts.moduleSpecifiers {
233233
? host.getSymlinkCache()
234234
: discoverProbableSymlinks(host.getSourceFiles(), getCanonicalFileName, cwd);
235235

236-
const symlinkedDirectories = links.getSymlinkedDirectories();
237236
const useCaseSensitiveFileNames = !host.useCaseSensitiveFileNames || host.useCaseSensitiveFileNames();
238-
const result = symlinkedDirectories && forEachEntry(symlinkedDirectories, (resolved, path) => {
239-
if (resolved === false) return undefined;
240-
if (startsWithDirectory(importingFileName, resolved.realPath, getCanonicalFileName)) {
241-
return undefined; // Don't want to a package to globally import from itself
242-
}
243-
237+
const realPathToSymlinks = links.getRealPathToSymlinks();
238+
const result = realPathToSymlinks && forEachEntry(realPathToSymlinks, (paths, resolved) => {
244239
return forEach(targets, target => {
245-
if (!containsPath(resolved.real, target, !useCaseSensitiveFileNames)) {
240+
if (!containsPath(resolved, target, !useCaseSensitiveFileNames)) {
246241
return;
247242
}
248243

249-
const relative = getRelativePathFromDirectory(resolved.real, target, getCanonicalFileName);
250-
const option = resolvePath(path, relative);
251-
if (!host.fileExists || host.fileExists(option)) {
244+
const relative = getRelativePathFromDirectory(resolved, target, getCanonicalFileName);
245+
for (const path of paths) {
246+
const option = resolvePath(path, relative);
252247
const result = cb(option, target === referenceRedirect);
253248
if (result) return result;
254249
}
255250
});
256251
});
252+
257253
return result ||
258254
(preferSymlinks ? forEach(targets, p => cb(p, p === referenceRedirect)) : undefined);
259255
}

src/compiler/utilities.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -6050,18 +6050,31 @@ namespace ts {
60506050
export interface SymlinkCache {
60516051
getSymlinkedDirectories(): ReadonlyESMap<Path, SymlinkedDirectory | false> | undefined;
60526052
getSymlinkedFiles(): ReadonlyESMap<Path, string> | undefined;
6053+
getRealPathToSymlinks(): ReadonlyESMap<string, Path[]> | undefined;
60536054
setSymlinkedDirectory(path: Path, directory: SymlinkedDirectory | false): void;
60546055
setSymlinkedFile(path: Path, real: string): void;
60556056
}
60566057

60576058
export function createSymlinkCache(): SymlinkCache {
60586059
let symlinkedDirectories: ESMap<Path, SymlinkedDirectory | false> | undefined;
60596060
let symlinkedFiles: ESMap<Path, string> | undefined;
6061+
let realPathToSymlinks: ESMap<string, Path[]>;
60606062
return {
60616063
getSymlinkedFiles: () => symlinkedFiles,
60626064
getSymlinkedDirectories: () => symlinkedDirectories,
6065+
getRealPathToSymlinks: () => realPathToSymlinks,
60636066
setSymlinkedFile: (path, real) => (symlinkedFiles || (symlinkedFiles = new Map())).set(path, real),
6064-
setSymlinkedDirectory: (path, directory) => (symlinkedDirectories || (symlinkedDirectories = new Map())).set(path, directory),
6067+
setSymlinkedDirectory: (path, directory) => {
6068+
// Don't add false directories or directories that have already been added
6069+
if (directory !== false && symlinkedDirectories?.has(path) !== true) {
6070+
if (realPathToSymlinks === undefined) {
6071+
realPathToSymlinks = new Map();
6072+
}
6073+
realPathToSymlinks.has(directory.real) ? realPathToSymlinks.get(directory.real)?.push(path) : realPathToSymlinks.set(directory.real, [path]);
6074+
}
6075+
6076+
(symlinkedDirectories || (symlinkedDirectories = new Map())).set(path, directory);
6077+
},
60656078
};
60666079
}
60676080

0 commit comments

Comments
 (0)