@@ -10,6 +10,7 @@ import (
1010 "github.com/microsoft/typescript-go/internal/ast"
1111 "github.com/microsoft/typescript-go/internal/collections"
1212 "github.com/microsoft/typescript-go/internal/core"
13+ "github.com/microsoft/typescript-go/internal/deno"
1314 "github.com/microsoft/typescript-go/internal/module"
1415 "github.com/microsoft/typescript-go/internal/tsoptions"
1516 "github.com/microsoft/typescript-go/internal/tspath"
@@ -107,6 +108,11 @@ func processAllProgramFiles(
107108 for index , rootFile := range rootFiles {
108109 loader .addRootTask (rootFile , nil , & FileIncludeReason {kind : fileIncludeKindRootFile , data : index })
109110 }
111+
112+ // deno: cause the sub tasks to be loaded which will tell us if there's a @types/node package
113+ loader .filesParser .parse (& loader , loader .rootTasks )
114+ rootTasksBeforeLibs := len (loader .rootTasks )
115+
110116 if len (rootFiles ) > 0 && compilerOptions .NoLib .IsFalseOrUnknown () {
111117 if compilerOptions .Lib == nil {
112118 name := tsoptions .GetDefaultLibFileName (compilerOptions )
@@ -117,6 +123,10 @@ func processAllProgramFiles(
117123 for index , lib := range compilerOptions .Lib {
118124 if name , ok := tsoptions .GetLibFileName (lib ); ok {
119125 libFile := loader .pathForLibFile (name )
126+ // deno: we skip loading the lib.node.d.ts file if the @types/node package has been loaded
127+ if libFile .Name == "lib.node.d.ts" && loader .hasTypesNodePackage () {
128+ continue
129+ }
120130 loader .addRootTask (libFile .path , libFile , & FileIncludeReason {kind : fileIncludeKindLibFile , data : index })
121131 }
122132 // !!! error on unknown name
@@ -128,7 +138,10 @@ func processAllProgramFiles(
128138 loader .addAutomaticTypeDirectiveTasks ()
129139 }
130140
131- loader .filesParser .parse (& loader , loader .rootTasks )
141+ // deno: now load the lib and type directive tasks
142+ loader .filesParser .wg = core .NewWorkGroup (singleThreaded )
143+ loader .filesParser .parse (& loader , loader .rootTasks [rootTasksBeforeLibs :])
144+
132145 // Clear out loader and host to ensure its not used post program creation
133146 loader .projectReferenceFileMapper .loader = nil
134147 loader .projectReferenceFileMapper .host = nil
@@ -257,6 +270,19 @@ func (p *fileLoader) toPath(file string) tspath.Path {
257270 return tspath .ToPath (file , p .opts .Host .GetCurrentDirectory (), p .opts .Host .FS ().UseCaseSensitiveFileNames ())
258271}
259272
273+ // deno: function for getting if the loader has a @types/node package
274+ func (p * fileLoader ) hasTypesNodePackage () bool {
275+ hasTypesNode := false
276+ p .filesParser .tasksByFileName .Range (func (key string , value * queuedParseTask ) bool {
277+ if value .task .loaded && deno .IsTypesNodePkgPath (value .task .path ) {
278+ hasTypesNode = true
279+ return false // stop iteration
280+ }
281+ return true // continue iteration
282+ })
283+ return hasTypesNode
284+ }
285+
260286func (p * fileLoader ) addRootTask (fileName string , libFile * LibFile , includeReason * FileIncludeReason ) {
261287 absPath := tspath .GetNormalizedAbsolutePath (fileName , p .opts .Host .GetCurrentDirectory ())
262288 if core .Tristate .IsTrue (p .opts .Config .CompilerOptions ().AllowNonTsExtensions ) || slices .Contains (p .supportedExtensions , tspath .TryGetExtensionFromPath (absPath )) {
@@ -609,7 +635,7 @@ func (p *fileLoader) createSyntheticImport(text string, file *ast.SourceFile) *a
609635}
610636
611637func isDenoLibFile (name string ) bool {
612- return strings .HasPrefix (name , "lib.deno" )
638+ return strings .HasPrefix (name , "lib.deno" ) || name == "lib.node.d.ts"
613639}
614640
615641func (p * fileLoader ) pathForLibFile (name string ) * LibFile {
0 commit comments