Skip to content

Commit 2aa0eb5

Browse files
authored
Skip looking up external files for typings (#1249)
1 parent fe5949c commit 2aa0eb5

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

internal/project/ata_test.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,13 @@ func TestAta(t *testing.T) {
285285
})
286286

287287
t.Run("discover from node_modules", func(t *testing.T) {
288-
t.Skip("Skip for now - to add back when we skip external library files to lookup typings for")
289288
t.Parallel()
290289
files := map[string]any{
291290
"/user/username/projects/project/app.js": "",
292291
"/user/username/projects/project/package.json": `{
293292
"dependencies": {
294-
"jquery": "1.0.0",
295-
},
293+
"jquery": "1.0.0"
294+
}
296295
}`,
297296
"/user/username/projects/project/jsconfig.json": `{}`,
298297
"/user/username/projects/project/node_modules/commander/index.js": "",
@@ -312,7 +311,6 @@ func TestAta(t *testing.T) {
312311

313312
service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "")
314313
_, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js")
315-
// Order is determinate since second install will run only after completing first one
316314
status := <-host.ServiceOptions.InstallStatus
317315
assert.Equal(t, status, project.TypingsInstallerStatus{
318316
RequestId: 1,
@@ -323,14 +321,13 @@ func TestAta(t *testing.T) {
323321

324322
// Explicit types prevent automatic inclusion from package.json listing
325323
t.Run("discover from node_modules empty types", func(t *testing.T) {
326-
t.Skip("Skip for now - to add back when we skip external library files to lookup typings for")
327324
t.Parallel()
328325
files := map[string]any{
329326
"/user/username/projects/project/app.js": "",
330327
"/user/username/projects/project/package.json": `{
331328
"dependencies": {
332-
"jquery": "1.0.0",
333-
},
329+
"jquery": "1.0.0"
330+
}
334331
}`,
335332
"/user/username/projects/project/jsconfig.json": `{
336333
"compilerOptions": {
@@ -354,25 +351,23 @@ func TestAta(t *testing.T) {
354351

355352
service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "")
356353
_, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js")
357-
// Order is determinate since second install will run only after completing first one
358354
status := <-host.ServiceOptions.InstallStatus
359355
assert.Equal(t, status, project.TypingsInstallerStatus{
360356
RequestId: 1,
361357
Project: p,
362-
Status: "Success",
358+
Status: "Skipped 0 typings",
363359
})
364360
})
365361

366362
// A type reference directive will not resolve to the global typings cache
367363
t.Run("discover from node_modules explicit types", func(t *testing.T) {
368-
t.Skip("Skip for now - to add back when we skip external library files to lookup typings for")
369364
t.Parallel()
370365
files := map[string]any{
371366
"/user/username/projects/project/app.js": "",
372367
"/user/username/projects/project/package.json": `{
373368
"dependencies": {
374-
"jquery": "1.0.0",
375-
},
369+
"jquery": "1.0.0"
370+
}
376371
}`,
377372
"/user/username/projects/project/jsconfig.json": `{
378373
"compilerOptions": {
@@ -396,25 +391,23 @@ func TestAta(t *testing.T) {
396391

397392
service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "")
398393
_, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js")
399-
// Order is determinate since second install will run only after completing first one
400394
status := <-host.ServiceOptions.InstallStatus
401395
assert.Equal(t, status, project.TypingsInstallerStatus{
402396
RequestId: 1,
403397
Project: p,
404-
Status: "Success",
398+
Status: "Skipped 0 typings",
405399
})
406400
})
407401

408402
// However, explicit types will not prevent unresolved imports from pulling in typings
409403
t.Run("discover from node_modules empty types has import", func(t *testing.T) {
410-
t.Skip("Skip for now - to add back when we skip external library files to lookup typings for")
411404
t.Parallel()
412405
files := map[string]any{
413406
"/user/username/projects/project/app.js": `import "jquery";`,
414407
"/user/username/projects/project/package.json": `{
415408
"dependencies": {
416-
"jquery": "1.0.0",
417-
},
409+
"jquery": "1.0.0"
410+
}
418411
}`,
419412
"/user/username/projects/project/jsconfig.json": `{
420413
"compilerOptions": {
@@ -438,7 +431,6 @@ func TestAta(t *testing.T) {
438431

439432
service.OpenFile("/user/username/projects/project/app.js", files["/user/username/projects/project/app.js"].(string), core.ScriptKindJS, "")
440433
_, p := service.EnsureDefaultProjectForFile("/user/username/projects/project/app.js")
441-
// Order is determinate since second install will run only after completing first one
442434
status := <-host.ServiceOptions.InstallStatus
443435
assert.Equal(t, status, project.TypingsInstallerStatus{
444436
RequestId: 1,

internal/project/project.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,15 @@ func (p *Project) getTypeAcquisition() *core.TypeAcquisition {
635635
return p.typeAcquisition
636636
}
637637

638+
func (p *Project) setTypeAcquisition(typeAcquisition *core.TypeAcquisition) {
639+
if typeAcquisition == nil || !typeAcquisition.Enable.IsTrue() {
640+
p.unresolvedImports = nil
641+
p.unresolvedImportsPerFile = nil
642+
p.typingFiles = nil
643+
}
644+
p.typeAcquisition = typeAcquisition
645+
}
646+
638647
func (p *Project) enqueueInstallTypingsForProject(oldProgram *compiler.Program, forceRefresh bool) {
639648
typingsInstaller := p.host.TypingsInstaller()
640649
if typingsInstaller == nil {
@@ -643,10 +652,6 @@ func (p *Project) enqueueInstallTypingsForProject(oldProgram *compiler.Program,
643652

644653
typeAcquisition := p.getTypeAcquisition()
645654
if typeAcquisition == nil || !typeAcquisition.Enable.IsTrue() {
646-
// !!! sheetal Should be probably done where we set typeAcquisition
647-
p.unresolvedImports = nil
648-
p.unresolvedImportsPerFile = nil
649-
p.typingFiles = nil
650655
return
651656
}
652657

@@ -871,7 +876,7 @@ func (p *Project) RemoveFile(info *ScriptInfo, fileExists bool) {
871876
defer p.mu.Unlock()
872877
if p.isRoot(info) && p.kind == KindInferred {
873878
p.rootFileNames.Delete(info.path)
874-
p.typeAcquisition = nil
879+
p.setTypeAcquisition(nil)
875880
p.programConfig = nil
876881
}
877882
p.onFileAddedOrRemoved()
@@ -895,7 +900,7 @@ func (p *Project) AddInferredProjectRoot(info *ScriptInfo) {
895900
}
896901
p.rootFileNames.Set(info.path, info.fileName)
897902
p.programConfig = nil
898-
p.typeAcquisition = nil
903+
p.setTypeAcquisition(nil)
899904
// !!!
900905
// if p.kind == KindInferred {
901906
// p.host.startWatchingConfigFilesForInferredProjectRoot(info.path);
@@ -924,11 +929,11 @@ func (p *Project) LoadConfig() error {
924929
)
925930

926931
p.compilerOptions = p.parsedCommandLine.CompilerOptions()
927-
p.typeAcquisition = p.parsedCommandLine.TypeAcquisition()
932+
p.setTypeAcquisition(p.parsedCommandLine.TypeAcquisition())
928933
p.setRootFiles(p.parsedCommandLine.FileNames())
929934
} else {
930935
p.compilerOptions = &core.CompilerOptions{}
931-
p.typeAcquisition = nil
936+
p.setTypeAcquisition(nil)
932937
return fmt.Errorf("could not read file %q", p.configFileName)
933938
}
934939
return nil
@@ -983,10 +988,9 @@ func (p *Project) GetFileNames(excludeFilesFromExternalLibraries bool, excludeCo
983988
result := []string{}
984989
sourceFiles := p.program.GetSourceFiles()
985990
for _, sourceFile := range sourceFiles {
986-
// !! This is probably ready to be implemented now?
987-
// if excludeFilesFromExternalLibraries && p.program.IsSourceFileFromExternalLibrary(sourceFile) {
988-
// continue;
989-
// }
991+
if excludeFilesFromExternalLibraries && p.program.IsSourceFileFromExternalLibrary(sourceFile) {
992+
continue
993+
}
990994
result = append(result, sourceFile.FileName())
991995
}
992996
// if (!excludeConfigFiles) {

0 commit comments

Comments
 (0)