Skip to content

Commit efbf69c

Browse files
committed
ignore "\" vs "/" when validating path metadata
1 parent 8534ad3 commit efbf69c

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

internal/bundler/bundler.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -969,14 +969,6 @@ func loaderFromFileExtension(extensionToLoader map[string]config.Loader, base st
969969
return config.LoaderNone
970970
}
971971

972-
// Identify the path by its lowercase absolute path name with Windows-specific
973-
// slashes substituted for standard slashes. This should hopefully avoid path
974-
// issues on Windows where multiple different paths can refer to the same
975-
// underlying file.
976-
func canonicalFileSystemPathForWindows(absPath string) string {
977-
return strings.ReplaceAll(strings.ToLower(absPath), "\\", "/")
978-
}
979-
980972
func hashForFileName(hashBytes []byte) string {
981973
return base32.StdEncoding.EncodeToString(hashBytes)[:8]
982974
}
@@ -1160,7 +1152,7 @@ func (s *scanner) maybeParseFile(
11601152
path := resolveResult.PathPair.Primary
11611153
visitedKey := path
11621154
if visitedKey.Namespace == "file" {
1163-
visitedKey.Text = canonicalFileSystemPathForWindows(visitedKey.Text)
1155+
visitedKey.Text = logger.CanonicalFileSystemPathForWindows(visitedKey.Text)
11641156
}
11651157

11661158
// Only parse a given file path once
@@ -1382,7 +1374,7 @@ func (s *scanner) preprocessInjectedFiles() {
13821374
j := 0
13831375
for _, absPath := range s.options.InjectAbsPaths {
13841376
prettyPath := s.res.PrettyPath(logger.Path{Text: absPath, Namespace: "file"})
1385-
absPathKey := canonicalFileSystemPathForWindows(absPath)
1377+
absPathKey := logger.CanonicalFileSystemPathForWindows(absPath)
13861378

13871379
if duplicateInjectedFiles[absPathKey] {
13881380
s.log.Add(logger.Error, nil, logger.Range{}, fmt.Sprintf("Duplicate injected file %q", prettyPath))
@@ -1782,7 +1774,7 @@ func (s *scanner) processScannedFiles() []scannerFile {
17821774
if resolveResult.PathPair.HasSecondary() {
17831775
secondaryKey := resolveResult.PathPair.Secondary
17841776
if secondaryKey.Namespace == "file" {
1785-
secondaryKey.Text = canonicalFileSystemPathForWindows(secondaryKey.Text)
1777+
secondaryKey.Text = logger.CanonicalFileSystemPathForWindows(secondaryKey.Text)
17861778
}
17871779
if secondaryVisited, ok := s.visited[secondaryKey]; ok {
17881780
record.SourceIndex = ast.MakeIndex32(secondaryVisited.sourceIndex)
@@ -1842,7 +1834,7 @@ func (s *scanner) processScannedFiles() []scannerFile {
18421834
} else if !css.JSSourceIndex.IsValid() {
18431835
stubKey := otherFile.inputFile.Source.KeyPath
18441836
if stubKey.Namespace == "file" {
1845-
stubKey.Text = canonicalFileSystemPathForWindows(stubKey.Text)
1837+
stubKey.Text = logger.CanonicalFileSystemPathForWindows(stubKey.Text)
18461838
}
18471839
sourceIndex := s.allocateSourceIndex(stubKey, cache.SourceIndexJSStubForCSS)
18481840
source := logger.Source{
@@ -2222,12 +2214,12 @@ func (b *Bundle) Compile(log logger.Log, options config.Options, timer *helpers.
22222214
for _, sourceIndex := range allReachableFiles {
22232215
keyPath := b.files[sourceIndex].inputFile.Source.KeyPath
22242216
if keyPath.Namespace == "file" {
2225-
absPathKey := canonicalFileSystemPathForWindows(keyPath.Text)
2217+
absPathKey := logger.CanonicalFileSystemPathForWindows(keyPath.Text)
22262218
sourceAbsPaths[absPathKey] = sourceIndex
22272219
}
22282220
}
22292221
for _, outputFile := range outputFiles {
2230-
absPathKey := canonicalFileSystemPathForWindows(outputFile.AbsPath)
2222+
absPathKey := logger.CanonicalFileSystemPathForWindows(outputFile.AbsPath)
22312223
if sourceIndex, ok := sourceAbsPaths[absPathKey]; ok {
22322224
hint := ""
22332225
switch logger.API {
@@ -2254,7 +2246,7 @@ func (b *Bundle) Compile(log logger.Log, options config.Options, timer *helpers.
22542246
outputFileMap := make(map[string][]byte)
22552247
end := 0
22562248
for _, outputFile := range outputFiles {
2257-
absPathKey := canonicalFileSystemPathForWindows(outputFile.AbsPath)
2249+
absPathKey := logger.CanonicalFileSystemPathForWindows(outputFile.AbsPath)
22582250
contents, ok := outputFileMap[absPathKey]
22592251

22602252
// If this isn't a duplicate, keep the output file

internal/logger/logger.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,24 @@ func (a Path) ComesBeforeInSortedOrder(b Path) bool {
254254
(a.Flags == b.Flags && a.IgnoredSuffix < b.IgnoredSuffix)))))
255255
}
256256

257+
func (a Path) IsEquivalentTo(b Path) bool {
258+
if a.Namespace == "file" {
259+
a.Text = CanonicalFileSystemPathForWindows(a.Text)
260+
}
261+
if b.Namespace == "file" {
262+
b.Text = CanonicalFileSystemPathForWindows(b.Text)
263+
}
264+
return a == b
265+
}
266+
267+
// Identify the path by its lowercase absolute path name with Windows-specific
268+
// slashes substituted for standard slashes. This should hopefully avoid path
269+
// issues on Windows where multiple different paths can refer to the same
270+
// underlying file.
271+
func CanonicalFileSystemPathForWindows(absPath string) string {
272+
return strings.ReplaceAll(strings.ToLower(absPath), "\\", "/")
273+
}
274+
257275
var noColorResult bool
258276
var noColorOnce sync.Once
259277

internal/resolver/resolver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ func (old *ResolveResult) Compare(new *ResolveResult) (diff []string) {
196196
newDiff = append(newDiff, prettyPrintPluginName("+", "pluginName", new.PluginName))
197197
}
198198

199-
if old.PathPair.Primary != new.PathPair.Primary {
199+
if !old.PathPair.Primary.IsEquivalentTo(new.PathPair.Primary) {
200200
oldDiff = append(oldDiff, prettyPrintPath("-", "path", old.PathPair.Primary))
201201
newDiff = append(newDiff, prettyPrintPath("+", "path", new.PathPair.Primary))
202202
}
203203

204-
if old.PathPair.Secondary != new.PathPair.Secondary {
204+
if !old.PathPair.Secondary.IsEquivalentTo(new.PathPair.Secondary) {
205205
oldDiff = append(oldDiff, prettyPrintPath("-", "secondaryPath", old.PathPair.Secondary))
206206
newDiff = append(newDiff, prettyPrintPath("+", "secondaryPath", new.PathPair.Secondary))
207207
}

0 commit comments

Comments
 (0)