@@ -14,17 +14,6 @@ import (
14
14
"github.com/microsoft/typescript-go/internal/tspath"
15
15
)
16
16
17
- type TypesMapFile struct {
18
- TypesMap map [string ]SafeListEntry `json:"typesMap"`
19
- SimpleMap map [string ]string `json:"simpleMap,omitzero"`
20
- }
21
-
22
- type SafeListEntry struct {
23
- Match string `json:"match"`
24
- Exclude [][]any `json:"exclude"`
25
- Types []string `json:"types"`
26
- }
27
-
28
17
type PendingRequest struct {
29
18
requestId int32
30
19
packageNames []string
@@ -65,8 +54,6 @@ type TypingsInstaller struct {
65
54
missingTypingsSet collections.SyncMap [string , bool ]
66
55
67
56
typesRegistry map [string ]map [string ]string
68
- typesMap * TypesMapFile
69
- safeList map [string ]string
70
57
71
58
installRunCount atomic.Int32
72
59
inFlightRequestCount int
@@ -142,7 +129,7 @@ func (ti *TypingsInstaller) InstallPackage(p *Project, fileName string, packageN
142
129
143
130
func (ti * TypingsInstaller ) EnqueueInstallTypingsRequest (p * Project , typingsInfo * TypingsInfo ) {
144
131
// because we arent using buffers, no need to throttle for requests here
145
- p .Log ("TI :: Got install request for: " + p .Name ())
132
+ p .Log ("ATA :: Got install request for: " + p .Name ())
146
133
go ti .discoverAndInstallTypings (
147
134
p ,
148
135
typingsInfo ,
@@ -154,15 +141,12 @@ func (ti *TypingsInstaller) EnqueueInstallTypingsRequest(p *Project, typingsInfo
154
141
func (ti * TypingsInstaller ) discoverAndInstallTypings (p * Project , typingsInfo * TypingsInfo , fileNames []string , projectRootPath string ) {
155
142
ti .init ((p ))
156
143
157
- ti .initializeSafeList (p )
158
-
159
144
cachedTypingPaths , newTypingNames , filesToWatch := DiscoverTypings (
160
145
p .FS (),
161
146
p .Log ,
162
147
typingsInfo ,
163
148
fileNames ,
164
149
projectRootPath ,
165
- ti .safeList ,
166
150
& ti .packageNameToTypingLocation ,
167
151
ti .typesRegistry ,
168
152
)
@@ -178,9 +162,9 @@ func (ti *TypingsInstaller) discoverAndInstallTypings(p *Project, typingsInfo *T
178
162
ti .installTypings (p , typingsInfo , requestId , cachedTypingPaths , filteredTypings )
179
163
return
180
164
}
181
- p .Log ("TI :: All typings are known to be missing or invalid - no need to install more typings" )
165
+ p .Log ("ATA :: All typings are known to be missing or invalid - no need to install more typings" )
182
166
} else {
183
- p .Log ("TI :: No new typings were requested as a result of typings discovery" )
167
+ p .Log ("ATA :: No new typings were requested as a result of typings discovery" )
184
168
}
185
169
p .UpdateTypingFiles (typingsInfo , cachedTypingPaths )
186
170
// !!! sheetal events to send
@@ -275,7 +259,7 @@ func (ti *TypingsInstaller) invokeRoutineToInstallTypings(
275
259
}
276
260
277
261
if success {
278
- p .Logf ("TI :: Installed typings %v" , packageNames )
262
+ p .Logf ("ATA :: Installed typings %v" , packageNames )
279
263
var installedTypingFiles []string
280
264
resolver := module .NewResolver (p , & core.CompilerOptions {ModuleResolution : core .ModuleResolutionKindNodeNext }, "" , "" )
281
265
for _ , packageName := range request .filteredTypings {
@@ -296,12 +280,12 @@ func (ti *TypingsInstaller) invokeRoutineToInstallTypings(
296
280
ti .packageNameToTypingLocation .Store (packageName , newTyping )
297
281
installedTypingFiles = append (installedTypingFiles , typingFile )
298
282
}
299
- p .Logf ("TI :: Installed typing files %v" , installedTypingFiles )
283
+ p .Logf ("ATA :: Installed typing files %v" , installedTypingFiles )
300
284
p .UpdateTypingFiles (request .typingsInfo , append (request .currentlyCachedTypings , installedTypingFiles ... ))
301
285
// DO we really need these events
302
286
// this.event(response, "setTypings");
303
287
} else {
304
- p .Logf ("TI :: install request failed, marking packages as missing to prevent repeated requests: %v" , request .filteredTypings )
288
+ p .Logf ("ATA :: install request failed, marking packages as missing to prevent repeated requests: %v" , request .filteredTypings )
305
289
for _ , typing := range request .filteredTypings {
306
290
ti .missingTypingsSet .Store (typing , true )
307
291
}
@@ -362,15 +346,15 @@ func (ti *TypingsInstaller) installWorker(
362
346
success bool ,
363
347
),
364
348
) {
365
- p .Logf ("TI :: #%d with cwd: %s arguments: %v" , requestId , cwd , packageNames )
349
+ p .Logf ("ATA :: #%d with cwd: %s arguments: %v" , requestId , cwd , packageNames )
366
350
hasError := InstallNpmPackages (packageNames , func (packageNames []string , hasError * atomic.Bool ) {
367
351
var npmArgs []string
368
352
npmArgs = append (npmArgs , "install" , "--ignore-scripts" )
369
353
npmArgs = append (npmArgs , packageNames ... )
370
354
npmArgs = append (npmArgs , "--save-dev" , "--user-agent=\" typesInstaller/" + core .Version ()+ "\" " )
371
355
output , err := ti .options .NpmInstall (cwd , npmArgs )
372
356
if err != nil {
373
- p .Logf ("TI :: Output is: %s" , output )
357
+ p .Logf ("ATA :: Output is: %s" , output )
374
358
hasError .Store (true )
375
359
}
376
360
})
@@ -418,23 +402,23 @@ func (ti *TypingsInstaller) filterTypings(
418
402
for _ , typing := range typingsToInstall {
419
403
typingKey := module .MangleScopedPackageName (typing )
420
404
if _ , ok := ti .missingTypingsSet .Load (typingKey ); ok {
421
- p .Logf ("TI :: '%s':: '%s' is in missingTypingsSet - skipping..." , typing , typingKey )
405
+ p .Logf ("ATA :: '%s':: '%s' is in missingTypingsSet - skipping..." , typing , typingKey )
422
406
continue
423
407
}
424
408
validationResult , name , isScopeName := ValidatePackageName (typing )
425
409
if validationResult != NameOk {
426
410
// add typing name to missing set so we won't process it again
427
411
ti .missingTypingsSet .Store (typingKey , true )
428
- p .Log ("TI :: " + RenderPackageNameValidationFailure (typing , validationResult , name , isScopeName ))
412
+ p .Log ("ATA :: " + RenderPackageNameValidationFailure (typing , validationResult , name , isScopeName ))
429
413
continue
430
414
}
431
415
typesRegistryEntry , ok := ti .typesRegistry [typingKey ]
432
416
if ! ok {
433
- p .Logf ("TI :: '%s':: Entry for package '%s' does not exist in local types registry - skipping..." , typing , typingKey )
417
+ p .Logf ("ATA :: '%s':: Entry for package '%s' does not exist in local types registry - skipping..." , typing , typingKey )
434
418
continue
435
419
}
436
420
if typingLocation , ok := ti .packageNameToTypingLocation .Load (typingKey ); ok && IsTypingUpToDate (typingLocation , typesRegistryEntry ) {
437
- p .Logf ("TI :: '%s':: '%s' already has an up-to-date typing - skipping..." , typing , typingKey )
421
+ p .Logf ("ATA :: '%s':: '%s' already has an up-to-date typing - skipping..." , typing , typingKey )
438
422
continue
439
423
}
440
424
result = append (result , typingKey )
@@ -444,7 +428,7 @@ func (ti *TypingsInstaller) filterTypings(
444
428
445
429
func (ti * TypingsInstaller ) init (p * Project ) {
446
430
ti .initOnce .Do (func () {
447
- p .Log ("TI :: Global cache location '" + ti .TypingsLocation + "'" ) //, safe file path '" + safeListPath + "', types map path '" + typesMapLocation + "`")
431
+ p .Log ("ATA :: Global cache location '" + ti .TypingsLocation + "'" ) //, safe file path '" + safeListPath + "', types map path '" + typesMapLocation + "`")
448
432
ti .processCacheLocation (p )
449
433
450
434
// !!! sheetal handle npm path here if we would support it
@@ -459,11 +443,11 @@ func (ti *TypingsInstaller) init(p *Project) {
459
443
// }
460
444
461
445
ti .ensureTypingsLocationExists (p )
462
- p .Log ("TI :: Updating types-registry@latest npm package..." )
446
+ p .Log ("ATA :: Updating types-registry@latest npm package..." )
463
447
if _ , err := ti .options .NpmInstall (ti .TypingsLocation , []string {"install" , "--ignore-scripts" , "types-registry@latest" }); err == nil {
464
- p .Log ("TI :: Updated types-registry npm package" )
448
+ p .Log ("ATA :: Updated types-registry npm package" )
465
449
} else {
466
- p .Logf ("TI :: Error updating types-registry package: %v" , err )
450
+ p .Logf ("ATA :: Error updating types-registry package: %v" , err )
467
451
// !!! sheetal events to send
468
452
// // store error info to report it later when it is known that server is already listening to events from typings installer
469
453
// this.delayedInitializationError = {
@@ -496,18 +480,18 @@ type NpmLock struct {
496
480
}
497
481
498
482
func (ti * TypingsInstaller ) processCacheLocation (p * Project ) {
499
- p .Log ("TI :: Processing cache location " + ti .TypingsLocation )
483
+ p .Log ("ATA :: Processing cache location " + ti .TypingsLocation )
500
484
packageJson := tspath .CombinePaths (ti .TypingsLocation , "package.json" )
501
485
packageLockJson := tspath .CombinePaths (ti .TypingsLocation , "package-lock.json" )
502
- p .Log ("TI :: Trying to find '" + packageJson + "'..." )
486
+ p .Log ("ATA :: Trying to find '" + packageJson + "'..." )
503
487
if p .FS ().FileExists (packageJson ) && p .FS ().FileExists ((packageLockJson )) {
504
488
var npmConfig NpmConfig
505
489
npmConfigContents := parseNpmConfigOrLock (p , packageJson , & npmConfig )
506
490
var npmLock NpmLock
507
491
npmLockContents := parseNpmConfigOrLock (p , packageLockJson , & npmLock )
508
492
509
- p .Log ("TI :: Loaded content of " + packageJson + ": " + npmConfigContents )
510
- p .Log ("TI :: Loaded content of " + packageLockJson + ": " + npmLockContents )
493
+ p .Log ("ATA :: Loaded content of " + packageJson + ": " + npmConfigContents )
494
+ p .Log ("ATA :: Loaded content of " + packageLockJson + ": " + npmLockContents )
511
495
512
496
// !!! sheetal strada uses Node10
513
497
resolver := module .NewResolver (p , & core.CompilerOptions {ModuleResolution : core .ModuleResolutionKindNodeNext }, "" , "" )
@@ -535,9 +519,9 @@ func (ti *TypingsInstaller) processCacheLocation(p *Project) {
535
519
if existingTypingFile .TypingsLocation == typingFile {
536
520
continue
537
521
}
538
- p .Log ("TI :: New typing for package " + packageName + " from " + typingFile + " conflicts with existing typing file " + existingTypingFile .TypingsLocation )
522
+ p .Log ("ATA :: New typing for package " + packageName + " from " + typingFile + " conflicts with existing typing file " + existingTypingFile .TypingsLocation )
539
523
}
540
- p .Log ("TI :: Adding entry into typings cache: " + packageName + " => " + typingFile )
524
+ p .Log ("ATA :: Adding entry into typings cache: " + packageName + " => " + typingFile )
541
525
version := npmLockValue .Version
542
526
if version == "" {
543
527
continue
@@ -551,7 +535,7 @@ func (ti *TypingsInstaller) processCacheLocation(p *Project) {
551
535
}
552
536
}
553
537
}
554
- p .Log ("TI :: Finished processing cache location " + ti .TypingsLocation )
538
+ p .Log ("ATA :: Finished processing cache location " + ti .TypingsLocation )
555
539
}
556
540
557
541
func parseNpmConfigOrLock [T NpmConfig | NpmLock ](p * Project , location string , config * T ) string {
@@ -562,13 +546,13 @@ func parseNpmConfigOrLock[T NpmConfig | NpmLock](p *Project, location string, co
562
546
563
547
func (ti * TypingsInstaller ) ensureTypingsLocationExists (p * Project ) {
564
548
npmConfigPath := tspath .CombinePaths (ti .TypingsLocation , "package.json" )
565
- p .Log ("TI :: Npm config file: " + npmConfigPath )
549
+ p .Log ("ATA :: Npm config file: " + npmConfigPath )
566
550
567
551
if ! p .FS ().FileExists (npmConfigPath ) {
568
- p .Logf ("TI :: Npm config file: '%s' is missing, creating new one..." , npmConfigPath )
552
+ p .Logf ("ATA :: Npm config file: '%s' is missing, creating new one..." , npmConfigPath )
569
553
err := p .FS ().WriteFile (npmConfigPath , "{ \" private\" : true }" , false )
570
554
if err != nil {
571
- p .Logf ("TI :: Npm config file write failed: %v" , err )
555
+ p .Logf ("ATA :: Npm config file write failed: %v" , err )
572
556
}
573
557
}
574
558
}
@@ -589,61 +573,13 @@ func (ti *TypingsInstaller) loadTypesRegistryFile(p *Project) map[string]map[str
589
573
return typesRegistry
590
574
}
591
575
}
592
- p .Logf ("TI :: Error when loading types registry file '%s': %v" , typesRegistryFile , err )
576
+ p .Logf ("ATA :: Error when loading types registry file '%s': %v" , typesRegistryFile , err )
593
577
} else {
594
- p .Logf ("TI :: Error reading types registry file '%s'" , typesRegistryFile )
578
+ p .Logf ("ATA :: Error reading types registry file '%s'" , typesRegistryFile )
595
579
}
596
580
return map [string ]map [string ]string {}
597
581
}
598
582
599
- func (ti * TypingsInstaller ) initializeSafeList (p * Project ) {
600
- if ti .safeList != nil {
601
- return
602
- }
603
- ti .loadTypesMap (p )
604
- if ti .typesMap .SimpleMap != nil {
605
- p .Logf ("TI:: Loaded safelist from types map file '%s'" , tspath .CombinePaths (p .DefaultLibraryPath (), "typesMap.json" ))
606
- ti .safeList = ti .typesMap .SimpleMap
607
- return
608
- }
609
-
610
- p .Logf ("TI:: Failed to load safelist from types map file '$%s'" , tspath .CombinePaths (p .DefaultLibraryPath (), "typesMap.json" ))
611
- ti .loadSafeList (p )
612
- }
613
-
614
- func (ti * TypingsInstaller ) loadTypesMap (p * Project ) {
615
- if ti .typesMap != nil {
616
- return
617
- }
618
- typesMapLocation := tspath .CombinePaths (p .DefaultLibraryPath (), "typesMap.json" )
619
- typesMapContents , ok := p .FS ().ReadFile (typesMapLocation )
620
- if ok {
621
- err := json .Unmarshal ([]byte (typesMapContents ), & ti .typesMap )
622
- if err != nil {
623
- return
624
- }
625
- p .Logf ("TI:: Error when parsing typesMapLocation '%s': %v" , typesMapLocation , err )
626
- } else {
627
- p .Logf ("TI:: Error reading typesMapLocation '%s'" , typesMapLocation )
628
- }
629
- ti .typesMap = & TypesMapFile {}
630
- }
631
-
632
- func (ti * TypingsInstaller ) loadSafeList (p * Project ) {
633
- safeListLocation := tspath .CombinePaths (p .DefaultLibraryPath (), "typingSafeList.json" )
634
- safeListContents , ok := p .FS ().ReadFile (safeListLocation )
635
- if ok {
636
- err := json .Unmarshal ([]byte (safeListContents ), & ti .safeList )
637
- if err != nil {
638
- return
639
- }
640
- p .Logf ("TI:: Error when parsing safeListLocation '%s': %v" , safeListLocation , err )
641
- } else {
642
- p .Logf ("TI:: Error reading safeListLocation '%s'" , safeListLocation )
643
- }
644
- ti .safeList = map [string ]string {}
645
- }
646
-
647
583
func NpmInstall (cwd string , npmInstallArgs []string ) ([]byte , error ) {
648
584
cmd := exec .Command ("npm" , npmInstallArgs ... )
649
585
cmd .Dir = cwd
0 commit comments