Resolve symlinks for paths

This commit is contained in:
Jordan Pittman 2022-09-15 16:22:37 -04:00
parent 14c39f4d44
commit 2102566df8

View file

@ -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)
}