Skip to content

Commit

Permalink
pull out common tsconfig search logic
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Apr 16, 2023
1 parent ecb3a89 commit 23cee51
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,27 @@ func (r resolverQuery) parseTSConfig(file string, visited map[string]bool) (*TSC
// and because it would deadlock since we're currently in the middle of
// populating the directory info cache.

maybeFinishOurSearch := func(base *TSConfigJSON, err error, extendsFile string) (*TSConfigJSON, bool) {
if err == nil {
return base, true
}

if err == syscall.ENOENT {
// Return false to indicate that we should continue searching
return nil, false
}

if err == errParseErrorImportCycle {
r.log.AddID(logger.MsgID_TsconfigJSON_Cycle, logger.Warning, &tracker, extendsRange,
fmt.Sprintf("Base config file %q forms cycle", extends))
} else if err != errParseErrorAlreadyLogged {
r.log.AddError(&tracker, extendsRange,
fmt.Sprintf("Cannot read file %q: %s",
PrettyPath(r.fs, logger.Path{Text: extendsFile, Namespace: "file"}), err.Error()))
}
return nil, true
}

// Check for a Yarn PnP manifest and use that to rewrite the path
if IsPackagePath(extends) {
pnpData := r.pnpManifest
Expand Down Expand Up @@ -1087,19 +1108,9 @@ func (r resolverQuery) parseTSConfig(file string, visited map[string]bool) (*TSC
}
}

if err == nil {
return base
} else if err == syscall.ENOENT {
continue
} else if err == errParseErrorImportCycle {
r.log.AddID(logger.MsgID_TsconfigJSON_Cycle, logger.Warning, &tracker, extendsRange,
fmt.Sprintf("Base config file %q forms cycle", extends))
} else if err != errParseErrorAlreadyLogged {
r.log.AddError(&tracker, extendsRange,
fmt.Sprintf("Cannot read file %q: %s",
PrettyPath(r.fs, logger.Path{Text: fileToCheck, Namespace: "file"}), err.Error()))
if result, shouldReturn := maybeFinishOurSearch(base, err, fileToCheck); shouldReturn {
return result
}
return nil
}
}

Expand Down Expand Up @@ -1152,18 +1163,8 @@ func (r resolverQuery) parseTSConfig(file string, visited map[string]bool) (*TSC
}
}

if err == nil {
return base
} else if err != syscall.ENOENT {
if err == errParseErrorImportCycle {
r.log.AddID(logger.MsgID_TsconfigJSON_Cycle, logger.Warning, &tracker, extendsRange,
fmt.Sprintf("Base config file %q forms cycle", extends))
} else if err != errParseErrorAlreadyLogged {
r.log.AddError(&tracker, extendsRange,
fmt.Sprintf("Cannot read file %q: %s",
PrettyPath(r.fs, logger.Path{Text: extendsFile, Namespace: "file"}), err.Error()))
}
return nil
if result, shouldReturn := maybeFinishOurSearch(base, err, extendsFile); shouldReturn {
return result
}
}

Expand Down

0 comments on commit 23cee51

Please sign in to comment.