Skip to content

Commit

Permalink
Fix pathname parsing for tracked files (#5008)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
peteretelej committed Aug 27, 2021
1 parent 8218aa6 commit 6561708
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/jit/lib/setupContextUtils.js
Expand Up @@ -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)) {
Expand Down

0 comments on commit 6561708

Please sign in to comment.