@@ -49,6 +49,10 @@ type fileLoader struct {
4949
5050 pathForLibFileCache collections.SyncMap [string , * LibFile ]
5151 pathForLibFileResolutions collections.SyncMap [tspath.Path , * libResolution ]
52+
53+ // deno: flags for lib.node.d.ts handling
54+ shouldLoadNodeTypes atomic.Bool
55+ foundNodeTypes atomic.Bool
5256}
5357
5458type processedFiles struct {
@@ -108,10 +112,6 @@ func processAllProgramFiles(
108112 loader .addRootTask (rootFile , nil , & FileIncludeReason {kind : fileIncludeKindRootFile , data : index })
109113 }
110114
111- // deno: cause the sub tasks to be loaded which will tell us if there's a @types/node package
112- loader .filesParser .parse (& loader , loader .rootTasks )
113- rootTasksBeforeLibs := len (loader .rootTasks )
114-
115115 if len (rootFiles ) > 0 && compilerOptions .NoLib .IsFalseOrUnknown () {
116116 if compilerOptions .Lib == nil {
117117 name := tsoptions .GetDefaultLibFileName (compilerOptions )
@@ -122,10 +122,6 @@ func processAllProgramFiles(
122122 for index , lib := range compilerOptions .Lib {
123123 if name , ok := tsoptions .GetLibFileName (lib ); ok {
124124 libFile := loader .pathForLibFile (name )
125- // deno: we skip loading the lib.node.d.ts file if the @types/node package has been loaded
126- if libFile .Name == "lib.node.d.ts" && loader .hasTypesNodePackage () {
127- continue
128- }
129125 loader .addRootTask (libFile .path , libFile , & FileIncludeReason {kind : fileIncludeKindLibFile , data : index })
130126 }
131127 // !!! error on unknown name
@@ -137,9 +133,26 @@ func processAllProgramFiles(
137133 loader .addAutomaticTypeDirectiveTasks ()
138134 }
139135
140- // deno: now load the lib and type directive tasks
141- loader .filesParser .wg = core .NewWorkGroup (singleThreaded )
142- loader .filesParser .parse (& loader , loader .rootTasks [rootTasksBeforeLibs :])
136+ loader .filesParser .parse (& loader , loader .rootTasks )
137+
138+ // deno: now load the built-in node types if they were previously attempted
139+ // to be loaded and there's no @types/node package found in the loader
140+ if loader .foundNodeTypes .Load () && ! loader .hasTypesNodePackage () {
141+ loader .shouldLoadNodeTypes .Store (true )
142+ libFile := loader .pathForLibFile ("lib.node.d.ts" )
143+ // Remove the existing task data entirely so it will be reprocessed fresh
144+ // This includes all subtasks that might have been skipped
145+ loader .filesParser .taskDataByPath .Delete (loader .toPath (libFile .path ))
146+ libIndex := 0
147+ if compilerOptions .Lib != nil {
148+ libIndex = len (compilerOptions .Lib )
149+ }
150+ loader .addRootTask (libFile .path , libFile , & FileIncludeReason {kind : fileIncludeKindLibFile , data : libIndex })
151+
152+ // parse and load only the newly added lib.node.d.ts task
153+ loader .filesParser .wg = core .NewWorkGroup (singleThreaded )
154+ loader .filesParser .parse (& loader , loader .rootTasks [len (loader .rootTasks )- 1 :])
155+ }
143156
144157 // Clear out loader and host to ensure its not used post program creation
145158 loader .projectReferenceFileMapper .loader = nil
0 commit comments