Skip to content

Commit 16ce71d

Browse files
authored
Set maxNodeModuleJsDepth in JS-containing projects (#1213)
1 parent 2aa0eb5 commit 16ce71d

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

internal/project/project.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ type Project struct {
150150
// rootFileNames was a map from Path to { NormalizedPath, ScriptInfo? } in the original code.
151151
// But the ProjectService owns script infos, so it's not clear why there was an extra pointer.
152152
rootFileNames *collections.OrderedMap[tspath.Path, string]
153+
rootJSFileCount int
153154
compilerOptions *core.CompilerOptions
154155
typeAcquisition *core.TypeAcquisition
155156
parsedCommandLine *tsoptions.ParsedCommandLine
@@ -571,6 +572,12 @@ func (p *Project) updateProgram() bool {
571572
} else {
572573
rootFileNames := p.GetRootFileNames()
573574
compilerOptions := p.compilerOptions
575+
576+
if compilerOptions.MaxNodeModuleJsDepth == nil && p.rootJSFileCount > 0 {
577+
compilerOptions = compilerOptions.Clone()
578+
compilerOptions.MaxNodeModuleJsDepth = ptrTo(2)
579+
}
580+
574581
p.programConfig = &tsoptions.ParsedCommandLine{
575582
ParsedConfig: &core.ParsedOptions{
576583
CompilerOptions: compilerOptions,
@@ -875,7 +882,7 @@ func (p *Project) RemoveFile(info *ScriptInfo, fileExists bool) {
875882
p.mu.Lock()
876883
defer p.mu.Unlock()
877884
if p.isRoot(info) && p.kind == KindInferred {
878-
p.rootFileNames.Delete(info.path)
885+
p.deleteRootFileNameOfInferred(info.path)
879886
p.setTypeAcquisition(nil)
880887
p.programConfig = nil
881888
}
@@ -898,13 +905,12 @@ func (p *Project) AddInferredProjectRoot(info *ScriptInfo) {
898905
if p.isRoot(info) {
899906
panic("script info is already a root")
900907
}
901-
p.rootFileNames.Set(info.path, info.fileName)
908+
p.setRootFileNameOfInferred(info.path, info.fileName)
902909
p.programConfig = nil
903910
p.setTypeAcquisition(nil)
904911
// !!!
905912
// if p.kind == KindInferred {
906913
// p.host.startWatchingConfigFilesForInferredProjectRoot(info.path);
907-
// // handle JS toggling
908914
// }
909915
info.attachToProject(p)
910916
p.markAsDirtyLocked()
@@ -964,6 +970,33 @@ func (p *Project) setRootFiles(rootFileNames []string) {
964970
}
965971
}
966972

973+
func (p *Project) setRootFileNameOfInferred(path tspath.Path, fileName string) {
974+
if p.kind != KindInferred {
975+
panic("setRootFileNameOfInferred called on non-inferred project")
976+
}
977+
978+
has := p.rootFileNames.Has(path)
979+
p.rootFileNames.Set(path, fileName)
980+
if !has && tspath.HasJSFileExtension(fileName) {
981+
p.rootJSFileCount++
982+
}
983+
}
984+
985+
func (p *Project) deleteRootFileNameOfInferred(path tspath.Path) {
986+
if p.kind != KindInferred {
987+
panic("deleteRootFileNameOfInferred called on non-inferred project")
988+
}
989+
990+
fileName, ok := p.rootFileNames.Get(path)
991+
if !ok {
992+
return
993+
}
994+
p.rootFileNames.Delete(path)
995+
if tspath.HasJSFileExtension(fileName) {
996+
p.rootJSFileCount--
997+
}
998+
}
999+
9671000
func (p *Project) clearSourceMapperCache() {
9681001
// !!!
9691002
}
@@ -1080,6 +1113,7 @@ func (p *Project) Close() {
10801113
}
10811114
}
10821115
p.rootFileNames = nil
1116+
p.rootJSFileCount = 0
10831117
p.parsedCommandLine = nil
10841118
p.programConfig = nil
10851119
p.checkerPool = nil

0 commit comments

Comments
 (0)