Skip to content

Commit a6d80fc

Browse files
committed
fix #2177: Revert "check for consistent path metadata from plugins"
This reverts commit 8534ad3. This reverts commit efbf69c. This reverts commit ddd53f9.
1 parent 757d7d9 commit a6d80fc

File tree

7 files changed

+23
-285
lines changed

7 files changed

+23
-285
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* Revert path metadata validation for now ([#2177](https://github.com/evanw/esbuild/issues/2177))
6+
7+
This release reverts the path metadata validation that was introduced in the previous release. This validation has uncovered a potential issue with how esbuild handles `onResolve` callbacks in plugins that will need to be fixed before path metadata validation is re-enabled.
8+
39
## 0.14.35
410

511
* Add support for parsing `typeof` on #private fields from TypeScript 4.7 ([#2174](https://github.com/evanw/esbuild/pull/2174))

internal/bundler/bundler.go

+17-58
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ func RunOnResolvePlugins(
788788
return &resolver.ResolveResult{
789789
PathPair: resolver.PathPair{Primary: result.Path},
790790
IsExternal: result.External,
791-
PluginName: pluginName,
792791
PluginData: result.PluginData,
793792
PrimarySideEffectsData: sideEffectsData,
794793
}, false, resolver.DebugMeta{}
@@ -969,6 +968,14 @@ func loaderFromFileExtension(extensionToLoader map[string]config.Loader, base st
969968
return config.LoaderNone
970969
}
971970

971+
// Identify the path by its lowercase absolute path name with Windows-specific
972+
// slashes substituted for standard slashes. This should hopefully avoid path
973+
// issues on Windows where multiple different paths can refer to the same
974+
// underlying file.
975+
func canonicalFileSystemPathForWindows(absPath string) string {
976+
return strings.ReplaceAll(strings.ToLower(absPath), "\\", "/")
977+
}
978+
972979
func hashForFileName(hashBytes []byte) string {
973980
return base32.StdEncoding.EncodeToString(hashBytes)[:8]
974981
}
@@ -995,10 +1002,7 @@ type scanner struct {
9951002
}
9961003

9971004
type visitedFile struct {
998-
importSource *logger.Source
999-
resolveResult resolver.ResolveResult
1000-
importPathRange logger.Range
1001-
sourceIndex uint32
1005+
sourceIndex uint32
10021006
}
10031007

10041008
type EntryPoint struct {
@@ -1152,62 +1156,17 @@ func (s *scanner) maybeParseFile(
11521156
path := resolveResult.PathPair.Primary
11531157
visitedKey := path
11541158
if visitedKey.Namespace == "file" {
1155-
visitedKey.Text = logger.CanonicalFileSystemPathForWindows(visitedKey.Text)
1159+
visitedKey.Text = canonicalFileSystemPathForWindows(visitedKey.Text)
11561160
}
11571161

11581162
// Only parse a given file path once
11591163
visited, ok := s.visited[visitedKey]
11601164
if ok {
1161-
// Validate that the resolved metadata for this file is the same as before
1162-
if diff := visited.resolveResult.Compare(&resolveResult); diff != nil {
1163-
prettyPath := s.res.PrettyPath(resolveResult.PathPair.Primary)
1164-
tracker := logger.MakeLineColumnTracker(importSource)
1165-
notes := make([]logger.MsgData, 0, 5+len(diff))
1166-
1167-
if visited.importSource != nil {
1168-
visitedTracker := logger.MakeLineColumnTracker(visited.importSource)
1169-
notes = append(notes, visitedTracker.MsgData(visited.importPathRange,
1170-
"The original metadata for that path comes from when it was imported here:"))
1171-
}
1172-
1173-
notes = append(notes,
1174-
logger.MsgData{Text: "The difference in metadata is displayed below:"},
1175-
logger.MsgData{},
1176-
)
1177-
for _, line := range diff {
1178-
notes = append(notes, logger.MsgData{Text: line})
1179-
}
1180-
explain := ""
1181-
if a, b := resolveResult.PluginName, visited.resolveResult.PluginName; a != "" && (a == b || b == "") {
1182-
explain += fmt.Sprintf("This is a bug in the %q plugin. ", a)
1183-
} else if a == "" && b != "" {
1184-
explain += fmt.Sprintf("This is a bug in the %q plugin. ", b)
1185-
}
1186-
explain += "Plugins provide metadata for a given path in an \"onResolve\" callback. " +
1187-
"All metadata provided for the same path must be consistent to ensure deterministic builds. " +
1188-
"Due to parallelism, one set of provided metadata will be randomly chosen for a given path, " +
1189-
"so providing inconsistent metadata for the same path can cause non-determinism."
1190-
notes = append(notes,
1191-
logger.MsgData{},
1192-
logger.MsgData{Text: explain},
1193-
)
1194-
1195-
s.log.AddMsg(logger.Msg{
1196-
Kind: logger.Error,
1197-
Data: tracker.MsgData(importPathRange,
1198-
fmt.Sprintf("Detected inconsistent metadata for the path %q when it was imported here:", prettyPath)),
1199-
Notes: notes,
1200-
PluginName: resolveResult.PluginName,
1201-
})
1202-
}
12031165
return visited.sourceIndex
12041166
}
12051167

12061168
visited = visitedFile{
1207-
sourceIndex: s.allocateSourceIndex(visitedKey, cache.SourceIndexNormal),
1208-
resolveResult: resolveResult,
1209-
importSource: importSource,
1210-
importPathRange: importPathRange,
1169+
sourceIndex: s.allocateSourceIndex(visitedKey, cache.SourceIndexNormal),
12111170
}
12121171
s.visited[visitedKey] = visited
12131172
s.remaining++
@@ -1374,7 +1333,7 @@ func (s *scanner) preprocessInjectedFiles() {
13741333
j := 0
13751334
for _, absPath := range s.options.InjectAbsPaths {
13761335
prettyPath := s.res.PrettyPath(logger.Path{Text: absPath, Namespace: "file"})
1377-
absPathKey := logger.CanonicalFileSystemPathForWindows(absPath)
1336+
absPathKey := canonicalFileSystemPathForWindows(absPath)
13781337

13791338
if duplicateInjectedFiles[absPathKey] {
13801339
s.log.Add(logger.Error, nil, logger.Range{}, fmt.Sprintf("Duplicate injected file %q", prettyPath))
@@ -1774,7 +1733,7 @@ func (s *scanner) processScannedFiles() []scannerFile {
17741733
if resolveResult.PathPair.HasSecondary() {
17751734
secondaryKey := resolveResult.PathPair.Secondary
17761735
if secondaryKey.Namespace == "file" {
1777-
secondaryKey.Text = logger.CanonicalFileSystemPathForWindows(secondaryKey.Text)
1736+
secondaryKey.Text = canonicalFileSystemPathForWindows(secondaryKey.Text)
17781737
}
17791738
if secondaryVisited, ok := s.visited[secondaryKey]; ok {
17801739
record.SourceIndex = ast.MakeIndex32(secondaryVisited.sourceIndex)
@@ -1834,7 +1793,7 @@ func (s *scanner) processScannedFiles() []scannerFile {
18341793
} else if !css.JSSourceIndex.IsValid() {
18351794
stubKey := otherFile.inputFile.Source.KeyPath
18361795
if stubKey.Namespace == "file" {
1837-
stubKey.Text = logger.CanonicalFileSystemPathForWindows(stubKey.Text)
1796+
stubKey.Text = canonicalFileSystemPathForWindows(stubKey.Text)
18381797
}
18391798
sourceIndex := s.allocateSourceIndex(stubKey, cache.SourceIndexJSStubForCSS)
18401799
source := logger.Source{
@@ -2214,12 +2173,12 @@ func (b *Bundle) Compile(log logger.Log, options config.Options, timer *helpers.
22142173
for _, sourceIndex := range allReachableFiles {
22152174
keyPath := b.files[sourceIndex].inputFile.Source.KeyPath
22162175
if keyPath.Namespace == "file" {
2217-
absPathKey := logger.CanonicalFileSystemPathForWindows(keyPath.Text)
2176+
absPathKey := canonicalFileSystemPathForWindows(keyPath.Text)
22182177
sourceAbsPaths[absPathKey] = sourceIndex
22192178
}
22202179
}
22212180
for _, outputFile := range outputFiles {
2222-
absPathKey := logger.CanonicalFileSystemPathForWindows(outputFile.AbsPath)
2181+
absPathKey := canonicalFileSystemPathForWindows(outputFile.AbsPath)
22232182
if sourceIndex, ok := sourceAbsPaths[absPathKey]; ok {
22242183
hint := ""
22252184
switch logger.API {
@@ -2246,7 +2205,7 @@ func (b *Bundle) Compile(log logger.Log, options config.Options, timer *helpers.
22462205
outputFileMap := make(map[string][]byte)
22472206
end := 0
22482207
for _, outputFile := range outputFiles {
2249-
absPathKey := logger.CanonicalFileSystemPathForWindows(outputFile.AbsPath)
2208+
absPathKey := canonicalFileSystemPathForWindows(outputFile.AbsPath)
22502209
contents, ok := outputFileMap[absPathKey]
22512210

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

internal/config/config.go

-6
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,6 @@ type TSTarget struct {
337337
TargetIsAtLeastES2022 bool
338338
}
339339

340-
func (a *TSTarget) IsEquivalentTo(b *TSTarget) bool {
341-
return (a == nil && b == nil) || (a != nil && b != nil &&
342-
a.UnsupportedJSFeatures == b.UnsupportedJSFeatures &&
343-
a.TargetIsAtLeastES2022 == b.TargetIsAtLeastES2022)
344-
}
345-
346340
type PathPlaceholder uint8
347341

348342
const (

internal/js_ast/js_ast.go

-6
Original file line numberDiff line numberDiff line change
@@ -1732,12 +1732,6 @@ func (mt ModuleType) IsESM() bool {
17321732
return mt >= ModuleESM_MJS && mt <= ModuleESM_PackageJSON
17331733
}
17341734

1735-
func (a ModuleType) IsEquivalentTo(b ModuleType) bool {
1736-
return (a == ModuleUnknown && b == ModuleUnknown) ||
1737-
(a.IsCommonJS() && b.IsCommonJS()) ||
1738-
(a.IsESM() && b.IsESM())
1739-
}
1740-
17411735
type ModuleTypeData struct {
17421736
Source *logger.Source
17431737
Range logger.Range

internal/logger/logger.go

-29
Original file line numberDiff line numberDiff line change
@@ -254,24 +254,6 @@ 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-
275257
var noColorResult bool
276258
var noColorOnce sync.Once
277259

@@ -1109,16 +1091,6 @@ func msgString(includeSource bool, terminalInfo TerminalInfo, kind MsgKind, data
11091091

11101092
case Note:
11111093
sb := strings.Builder{}
1112-
reset := ""
1113-
1114-
// Add special color support for rendering textual diffs
1115-
if strings.HasPrefix(data.Text, "-") {
1116-
sb.WriteString(colors.Red)
1117-
reset = colors.Reset
1118-
} else if strings.HasPrefix(data.Text, "+") {
1119-
sb.WriteString(colors.Green)
1120-
reset = colors.Reset
1121-
}
11221094

11231095
for _, line := range strings.Split(data.Text, "\n") {
11241096
// Special-case word wrapping
@@ -1141,7 +1113,6 @@ func msgString(includeSource bool, terminalInfo TerminalInfo, kind MsgKind, data
11411113
}
11421114

11431115
sb.WriteString(location)
1144-
sb.WriteString(reset)
11451116
return sb.String()
11461117
}
11471118

internal/resolver/resolver.go

-127
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ type SideEffectsData struct {
9898
type ResolveResult struct {
9999
PathPair PathPair
100100

101-
// If non-empty, this was the result of an "onResolve" plugin
102-
PluginName string
103-
104101
// If this was resolved by a plugin, the plugin gets to store its data here
105102
PluginData interface{}
106103

@@ -128,130 +125,6 @@ type ResolveResult struct {
128125
UnusedImportsTS config.UnusedImportsTS
129126
}
130127

131-
func prettyPrintPluginName(prefix string, key string, value string) string {
132-
if value == "" {
133-
return fmt.Sprintf("%s %q: null,", prefix, key)
134-
}
135-
return fmt.Sprintf("%s %q: %q,", prefix, key, value)
136-
}
137-
138-
func prettyPrintPath(prefix string, key string, value logger.Path) string {
139-
lines := []string{
140-
fmt.Sprintf("%s %q: {", prefix, key),
141-
fmt.Sprintf("%s \"text\": %q,", prefix, value.Text),
142-
fmt.Sprintf("%s \"namespace\": %q,", prefix, value.Namespace),
143-
}
144-
if value.IgnoredSuffix != "" {
145-
lines = append(lines, fmt.Sprintf("%s \"suffix\": %q,", prefix, value.IgnoredSuffix))
146-
}
147-
if value.IsDisabled() {
148-
lines = append(lines, fmt.Sprintf("%s \"disabled\": true,", prefix))
149-
}
150-
lines = append(lines, fmt.Sprintf("%s },", prefix))
151-
return strings.Join(lines, "\n")
152-
}
153-
154-
func prettyPrintStringArray(prefix string, key string, value []string) string {
155-
return fmt.Sprintf("%s %q: [%s],", prefix, key, helpers.StringArrayToQuotedCommaSeparatedString(value))
156-
}
157-
158-
func prettyPrintTSTarget(prefix string, key string, value *config.TSTarget) string {
159-
if value == nil {
160-
return fmt.Sprintf("%s %q: null,", prefix, key)
161-
}
162-
return fmt.Sprintf("%s %q: %q,", prefix, key, value.Target)
163-
}
164-
165-
func prettyPrintModuleType(prefix string, key string, value js_ast.ModuleType) string {
166-
kind := "null"
167-
if value.IsCommonJS() {
168-
kind = "\"commonjs\""
169-
} else if value.IsESM() {
170-
kind = "\"module\""
171-
}
172-
return fmt.Sprintf("%s %q: %s,", prefix, key, kind)
173-
}
174-
175-
func prettyPrintUnusedImports(prefix string, key string, value config.UnusedImportsTS) string {
176-
source := "null"
177-
switch value {
178-
case config.UnusedImportsKeepStmtRemoveValues:
179-
source = "{ \"importsNotUsedAsValues\": \"preserve\" }"
180-
case config.UnusedImportsKeepValues:
181-
source = "{ \"preserveValueImports\": true }"
182-
}
183-
return fmt.Sprintf("%s %q: %s,", prefix, key, source)
184-
}
185-
186-
func (old *ResolveResult) Compare(new *ResolveResult) (diff []string) {
187-
var oldDiff []string
188-
var newDiff []string
189-
190-
if old.PluginName != new.PluginName {
191-
oldDiff = append(oldDiff, prettyPrintPluginName("-", "pluginName", old.PluginName))
192-
newDiff = append(newDiff, prettyPrintPluginName("+", "pluginName", new.PluginName))
193-
}
194-
195-
if !old.PathPair.Primary.IsEquivalentTo(new.PathPair.Primary) {
196-
oldDiff = append(oldDiff, prettyPrintPath("-", "path", old.PathPair.Primary))
197-
newDiff = append(newDiff, prettyPrintPath("+", "path", new.PathPair.Primary))
198-
}
199-
200-
if !old.PathPair.Secondary.IsEquivalentTo(new.PathPair.Secondary) {
201-
oldDiff = append(oldDiff, prettyPrintPath("-", "secondaryPath", old.PathPair.Secondary))
202-
newDiff = append(newDiff, prettyPrintPath("+", "secondaryPath", new.PathPair.Secondary))
203-
}
204-
205-
if !helpers.StringArraysEqual(old.JSXFactory, new.JSXFactory) {
206-
oldDiff = append(oldDiff, prettyPrintStringArray("-", "jsxFactory", old.JSXFactory))
207-
newDiff = append(newDiff, prettyPrintStringArray("+", "jsxFactory", new.JSXFactory))
208-
}
209-
210-
if !helpers.StringArraysEqual(old.JSXFragment, new.JSXFragment) {
211-
oldDiff = append(oldDiff, prettyPrintStringArray("-", "jsxFragment", old.JSXFragment))
212-
newDiff = append(newDiff, prettyPrintStringArray("+", "jsxFragment", new.JSXFragment))
213-
}
214-
215-
if (old.PrimarySideEffectsData != nil) != (new.PrimarySideEffectsData != nil) {
216-
oldDiff = append(oldDiff, fmt.Sprintf("- \"sideEffects\": %v,", old.PrimarySideEffectsData != nil))
217-
newDiff = append(newDiff, fmt.Sprintf("+ \"sideEffects\": %v,", new.PrimarySideEffectsData != nil))
218-
}
219-
220-
if !old.TSTarget.IsEquivalentTo(new.TSTarget) {
221-
oldDiff = append(oldDiff, prettyPrintTSTarget("-", "tsTarget", old.TSTarget))
222-
newDiff = append(newDiff, prettyPrintTSTarget("+", "tsTarget", new.TSTarget))
223-
}
224-
225-
if !old.ModuleTypeData.Type.IsEquivalentTo(new.ModuleTypeData.Type) {
226-
oldDiff = append(oldDiff, prettyPrintModuleType("-", "type", old.ModuleTypeData.Type))
227-
newDiff = append(newDiff, prettyPrintModuleType("+", "type", new.ModuleTypeData.Type))
228-
}
229-
230-
if old.IsExternal != new.IsExternal {
231-
oldDiff = append(oldDiff, fmt.Sprintf("- \"external\": %v,", old.IsExternal))
232-
newDiff = append(newDiff, fmt.Sprintf("+ \"external\": %v,", new.IsExternal))
233-
}
234-
235-
if old.UseDefineForClassFieldsTS != new.UseDefineForClassFieldsTS {
236-
oldDiff = append(oldDiff, fmt.Sprintf("- \"useDefineForClassFields\": %v,", old.UseDefineForClassFieldsTS))
237-
newDiff = append(newDiff, fmt.Sprintf("+ \"useDefineForClassFields\": %v,", new.UseDefineForClassFieldsTS))
238-
}
239-
240-
if old.UnusedImportsTS != new.UnusedImportsTS {
241-
oldDiff = append(oldDiff, prettyPrintUnusedImports("-", "unusedImports", old.UnusedImportsTS))
242-
newDiff = append(newDiff, prettyPrintUnusedImports("+", "unusedImports", new.UnusedImportsTS))
243-
}
244-
245-
if oldDiff != nil {
246-
diff = make([]string, 0, 2+len(oldDiff)+len(newDiff))
247-
diff = append(diff, " {")
248-
diff = append(diff, oldDiff...)
249-
diff = append(diff, newDiff...)
250-
diff = append(diff, " }")
251-
}
252-
return
253-
}
254-
255128
type DebugMeta struct {
256129
suggestionText string
257130
suggestionMessage string

0 commit comments

Comments
 (0)