Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve symlinks in system watchers #712

Merged
merged 1 commit into from
Feb 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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