Skip to content

Commit

Permalink
fix: resolve symlinks in system watchers (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-oles committed Feb 12, 2022
1 parent a6b66eb commit b5a38c1
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/typescript/worker/lib/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ export const system: ControlledTypeScriptSystem = {
isInitialRun = false;
},
invokeFileCreated(path: string) {
const normalizedPath = realFileSystem.normalizePath(path);
const normalizedPath = normalizeAndResolvePath(path);

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

deletedFiles.set(normalizedPath, false);
},
invokeFileChanged(path: string) {
const normalizedPath = realFileSystem.normalizePath(path);
const normalizedPath = normalizeAndResolvePath(path);

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

if (!deletedFiles.get(normalizedPath)) {
invokeFileWatchers(path, typescript.FileWatcherEventKind.Deleted);
Expand All @@ -205,8 +205,7 @@ function createWatcher<TCallback>(
path: string,
callback: TCallback
) {
const normalizedPath = realFileSystem.normalizePath(path);

const normalizedPath = normalizeAndResolvePath(path);
const watchers = watchersMap.get(normalizedPath) || [];
const nextWatchers = [...watchers, callback];
watchersMap.set(normalizedPath, nextWatchers);
Expand All @@ -226,7 +225,7 @@ function createWatcher<TCallback>(
}

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

function invokeDirectoryWatchers(path: string) {
const normalizedPath = realFileSystem.normalizePath(path);
const normalizedPath = normalizeAndResolvePath(path);
const directory = dirname(normalizedPath);

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

function normalizeAndResolvePath(path: string) {
let normalizedPath = realFileSystem.normalizePath(path);
try {
normalizedPath = realFileSystem.realPath(normalizedPath);
} catch (error) {
// ignore error - maybe file doesn't exist
}
return normalizedPath;
}

function isArtifact(path: string) {
return (
(artifacts.dirs.some((dir) => path.includes(dir)) ||
Expand Down

0 comments on commit b5a38c1

Please sign in to comment.