Skip to content

Commit b5a38c1

Browse files
authored
fix: resolve symlinks in system watchers (#712)
1 parent a6b66eb commit b5a38c1

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/typescript/worker/lib/system.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ export const system: ControlledTypeScriptSystem = {
161161
isInitialRun = false;
162162
},
163163
invokeFileCreated(path: string) {
164-
const normalizedPath = realFileSystem.normalizePath(path);
164+
const normalizedPath = normalizeAndResolvePath(path);
165165

166166
invokeFileWatchers(path, typescript.FileWatcherEventKind.Created);
167167
invokeDirectoryWatchers(normalizedPath);
168168

169169
deletedFiles.set(normalizedPath, false);
170170
},
171171
invokeFileChanged(path: string) {
172-
const normalizedPath = realFileSystem.normalizePath(path);
172+
const normalizedPath = normalizeAndResolvePath(path);
173173

174174
if (deletedFiles.get(normalizedPath) || !fileWatcherCallbacksMap.has(normalizedPath)) {
175175
invokeFileWatchers(path, typescript.FileWatcherEventKind.Created);
@@ -181,7 +181,7 @@ export const system: ControlledTypeScriptSystem = {
181181
}
182182
},
183183
invokeFileDeleted(path: string) {
184-
const normalizedPath = realFileSystem.normalizePath(path);
184+
const normalizedPath = normalizeAndResolvePath(path);
185185

186186
if (!deletedFiles.get(normalizedPath)) {
187187
invokeFileWatchers(path, typescript.FileWatcherEventKind.Deleted);
@@ -205,8 +205,7 @@ function createWatcher<TCallback>(
205205
path: string,
206206
callback: TCallback
207207
) {
208-
const normalizedPath = realFileSystem.normalizePath(path);
209-
208+
const normalizedPath = normalizeAndResolvePath(path);
210209
const watchers = watchersMap.get(normalizedPath) || [];
211210
const nextWatchers = [...watchers, callback];
212211
watchersMap.set(normalizedPath, nextWatchers);
@@ -226,7 +225,7 @@ function createWatcher<TCallback>(
226225
}
227226

228227
function invokeFileWatchers(path: string, event: ts.FileWatcherEventKind) {
229-
const normalizedPath = realFileSystem.normalizePath(path);
228+
const normalizedPath = normalizeAndResolvePath(path);
230229
if (normalizedPath.endsWith('.js')) {
231230
// trigger relevant .d.ts file watcher - handles the case, when we have webpack watcher
232231
// that points to a symlinked package
@@ -243,7 +242,7 @@ function invokeFileWatchers(path: string, event: ts.FileWatcherEventKind) {
243242
}
244243

245244
function invokeDirectoryWatchers(path: string) {
246-
const normalizedPath = realFileSystem.normalizePath(path);
245+
const normalizedPath = normalizeAndResolvePath(path);
247246
const directory = dirname(normalizedPath);
248247

249248
if (ignoredPaths.some((ignoredPath) => forwardSlash(normalizedPath).includes(ignoredPath))) {
@@ -272,6 +271,16 @@ function invokeDirectoryWatchers(path: string) {
272271
);
273272
}
274273

274+
function normalizeAndResolvePath(path: string) {
275+
let normalizedPath = realFileSystem.normalizePath(path);
276+
try {
277+
normalizedPath = realFileSystem.realPath(normalizedPath);
278+
} catch (error) {
279+
// ignore error - maybe file doesn't exist
280+
}
281+
return normalizedPath;
282+
}
283+
275284
function isArtifact(path: string) {
276285
return (
277286
(artifacts.dirs.some((dir) => path.includes(dir)) ||

0 commit comments

Comments
 (0)