From 2102566df8d3d97348c43320a6e5a38c99256efa Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 15 Sep 2022 16:22:37 -0400 Subject: [PATCH] Resolve symlinks for paths --- src/util/parseDependency.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/util/parseDependency.js b/src/util/parseDependency.js index 1ae811659..4b862be4c 100644 --- a/src/util/parseDependency.js +++ b/src/util/parseDependency.js @@ -27,6 +27,19 @@ function parseGlob(pattern) { return { base, glob } } +function resolvePathSymlinks(pathDesc) { + try { + let newPath = fs.realpathSync(pathDesc.base, { encoding: 'utf8' }) + if (newPath !== pathDesc.base) { + return [pathDesc, { ...pathDesc, base: newPath }] + } + } catch { + // TODO: log this? + } + + return [pathDesc] +} + function toDependency(pathDesc) { if (!pathDesc.glob) { return { @@ -77,5 +90,11 @@ export default function parseDependency(context, normalizedFileOrGlob) { }) ) + // Resolve the symlink for the base directory / file in each path + // These are added as additional dependencies to watch for changes because + // some tools (like webpack) will only watch the actual file or directory + // but not the symlink itself even in projects that use monorepos. + paths = paths.flatMap(resolvePathSymlinks) + return paths.map(toDependency) }