From 65617085c17680e40f1612dccf5490d4182ed93d Mon Sep 17 00:00:00 2001 From: Peter Etelej Date: Fri, 27 Aug 2021 17:12:06 +0300 Subject: [PATCH] Fix pathname parsing for tracked files (#5008) The trackedModified call in the tracking logic has a bug that incorrectly removes `null` from pathnames Currently: ``` let pathname = parsed.href.replace(parsed.hash, '').replace(parsed.search, '') ``` Where if `parsed.hash` or `parsed.search` are missing (which is mostly the case for FS files), the value is null eg `{ hash: null, search: null}` - In which case, we essentially trim `null` converting `/mypath/nulldir/file.js` -> `/mypath/dir/filejs` and breaking builds (see #4920 ). Fix checks if `hash` or `search` are set before replacing them Fixes #4920 --- src/jit/lib/setupContextUtils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/jit/lib/setupContextUtils.js b/src/jit/lib/setupContextUtils.js index b4730e4c1..95eb08c9d 100644 --- a/src/jit/lib/setupContextUtils.js +++ b/src/jit/lib/setupContextUtils.js @@ -379,7 +379,8 @@ function trackModified(files, fileModifiedMap) { if (!file) continue let parsed = url.parse(file) - let pathname = parsed.href.replace(parsed.hash, '').replace(parsed.search, '') + let pathname = parsed.hash ? parsed.href.replace(parsed.hash, '') : parsed.href + pathname = parsed.search ? pathname.replace(parsed.search, '') : pathname let newModified = fs.statSync(decodeURIComponent(pathname)).mtimeMs if (!fileModifiedMap.has(file) || newModified > fileModifiedMap.get(file)) {