@@ -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"
@@ -104,10 +105,14 @@ func processAllProgramFiles(
104105 }
105106 loader .addProjectReferenceTasks (singleThreaded )
106107 loader .resolver = loader .opts .Host .MakeResolver (loader .projectReferenceFileMapper .host , compilerOptions , opts .TypingsLocation , opts .ProjectName )
107- hadTypesNode := false
108108 for index , rootFile := range rootFiles {
109109 loader .addRootTask (rootFile , nil , & FileIncludeReason {kind : fileIncludeKindRootFile , data : index })
110110 }
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+
111116 if len (rootFiles ) > 0 && compilerOptions .NoLib .IsFalseOrUnknown () {
112117 if compilerOptions .Lib == nil {
113118 name := tsoptions .GetDefaultLibFileName (compilerOptions )
@@ -119,9 +124,7 @@ func processAllProgramFiles(
119124 if name , ok := tsoptions .GetLibFileName (lib ); ok {
120125 libFile := loader .pathForLibFile (name )
121126 // deno: we skip loading the lib.node.d.ts file if the @types/node package has been loaded
122- // so defer loading this until after everything else
123- if libFile .path == "asset:///lib.node.d.ts" {
124- hadTypesNode = true
127+ if libFile .Name == "lib.node.d.ts" && loader .hasTypesNodePackage () {
125128 continue
126129 }
127130 loader .addRootTask (libFile .path , libFile , & FileIncludeReason {kind : fileIncludeKindLibFile , data : index })
@@ -135,7 +138,10 @@ func processAllProgramFiles(
135138 loader .addAutomaticTypeDirectiveTasks ()
136139 }
137140
138- 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+
139145 // Clear out loader and host to ensure its not used post program creation
140146 loader .projectReferenceFileMapper .loader = nil
141147 loader .projectReferenceFileMapper .host = nil
@@ -264,6 +270,18 @@ func (p *fileLoader) toPath(file string) tspath.Path {
264270 return tspath .ToPath (file , p .opts .Host .GetCurrentDirectory (), p .opts .Host .FS ().UseCaseSensitiveFileNames ())
265271}
266272
273+ func (p * fileLoader ) hasTypesNodePackage () bool {
274+ hasTypesNode := false
275+ p .filesParser .tasksByFileName .Range (func (key string , value * queuedParseTask ) bool {
276+ if value .task .loaded && deno .IsTypesNodePkgPath (value .task .path ) {
277+ hasTypesNode = true
278+ return false // stop iteration
279+ }
280+ return true // continue iteration
281+ })
282+ return hasTypesNode
283+ }
284+
267285func (p * fileLoader ) addRootTask (fileName string , libFile * LibFile , includeReason * FileIncludeReason ) {
268286 absPath := tspath .GetNormalizedAbsolutePath (fileName , p .opts .Host .GetCurrentDirectory ())
269287 if core .Tristate .IsTrue (p .opts .Config .CompilerOptions ().AllowNonTsExtensions ) || slices .Contains (p .supportedExtensions , tspath .TryGetExtensionFromPath (absPath )) {
@@ -616,7 +634,7 @@ func (p *fileLoader) createSyntheticImport(text string, file *ast.SourceFile) *a
616634}
617635
618636func isDenoLibFile (name string ) bool {
619- return strings .HasPrefix (name , "lib.deno" )
637+ return strings .HasPrefix (name , "lib.deno" ) || name == "lib.node.d.ts"
620638}
621639
622640func (p * fileLoader ) pathForLibFile (name string ) * LibFile {
0 commit comments