-
Notifications
You must be signed in to change notification settings - Fork 648
Implement maxNodeModuleJsDepth, noResolve #1189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
e94211c
72edd5d
30ff966
053af5b
f13dffc
f8305a6
4ebaa9f
2d84c60
06f94ed
05245c3
9f0f9cc
0f12bac
0d68348
fdf7e30
3145cc5
b0b5380
19e90bc
a117059
ee8c8f6
739c128
98fcddd
12af89d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,74 @@ | ||
package compiler | ||
|
||
import ( | ||
"math" | ||
"sync" | ||
|
||
"github.com/microsoft/typescript-go/internal/collections" | ||
"github.com/microsoft/typescript-go/internal/core" | ||
"github.com/microsoft/typescript-go/internal/tspath" | ||
) | ||
|
||
type fileLoaderWorkerTask interface { | ||
type fileLoaderWorkerTask[T any] interface { | ||
comparable | ||
FileName() string | ||
start(loader *fileLoader) | ||
isLoaded() bool | ||
load(loader *fileLoader) | ||
getSubTasks() []T | ||
shouldIncreaseDepth() bool | ||
} | ||
|
||
type fileLoaderWorker[K fileLoaderWorkerTask] struct { | ||
type fileLoaderWorker[K fileLoaderWorkerTask[K]] struct { | ||
wg core.WorkGroup | ||
tasksByFileName collections.SyncMap[string, K] | ||
getSubTasks func(t K) []K | ||
tasksByFileName collections.SyncMap[string, *queuedTask[K]] | ||
maxDepth int | ||
} | ||
|
||
type queuedTask[K fileLoaderWorkerTask[K]] struct { | ||
task K | ||
mu sync.Mutex | ||
lowestDepth int | ||
} | ||
|
||
func (w *fileLoaderWorker[K]) runAndWait(loader *fileLoader, tasks []K) { | ||
w.start(loader, tasks) | ||
w.start(loader, tasks, 0) | ||
w.wg.RunAndWait() | ||
} | ||
|
||
func (w *fileLoaderWorker[K]) start(loader *fileLoader, tasks []K) { | ||
if len(tasks) > 0 { | ||
for i, task := range tasks { | ||
loadedTask, loaded := w.tasksByFileName.LoadOrStore(task.FileName(), task) | ||
if loaded { | ||
// dedup tasks to ensure correct file order, regardless of which task would be started first | ||
tasks[i] = loadedTask | ||
} else { | ||
w.wg.Queue(func() { | ||
task.start(loader) | ||
subTasks := w.getSubTasks(task) | ||
w.start(loader, subTasks) | ||
}) | ||
} | ||
func (w *fileLoaderWorker[K]) start(loader *fileLoader, tasks []K, depth int) { | ||
for i, task := range tasks { | ||
newTask := &queuedTask[K]{task: task, lowestDepth: math.MaxInt} | ||
loadedTask, loaded := w.tasksByFileName.LoadOrStore(task.FileName(), newTask) | ||
task = loadedTask.task | ||
if loaded { | ||
tasks[i] = task | ||
} | ||
|
||
currentDepth := depth | ||
if task.shouldIncreaseDepth() { | ||
currentDepth++ | ||
} | ||
|
||
if currentDepth > w.maxDepth { | ||
continue | ||
} | ||
|
||
w.wg.Queue(func() { | ||
loadedTask.mu.Lock() | ||
defer loadedTask.mu.Unlock() | ||
|
||
if !task.isLoaded() { | ||
task.load(loader) | ||
} | ||
|
||
if currentDepth < loadedTask.lowestDepth { | ||
// If we're seeing this task at a lower depth than before, | ||
// reprocess its subtasks to ensure they are loaded. | ||
loadedTask.lowestDepth = currentDepth | ||
subTasks := task.getSubTasks() | ||
w.start(loader, subTasks, currentDepth) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The subtasks may or may not have been elided when they were seen at a lower depth—is there a mechanism here to skip them if they’ve already been run? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They'll be deduped by the |
||
} | ||
}) | ||
} | ||
} | ||
|
||
|
@@ -49,12 +80,12 @@ func (w *fileLoaderWorker[K]) collectWorker(loader *fileLoader, tasks []K, itera | |
var results []tspath.Path | ||
for _, task := range tasks { | ||
// ensure we only walk each task once | ||
if seen.Has(task) { | ||
if !task.isLoaded() || seen.Has(task) { | ||
continue | ||
} | ||
seen.Add(task) | ||
var subResults []tspath.Path | ||
if subTasks := w.getSubTasks(task); len(subTasks) > 0 { | ||
if subTasks := task.getSubTasks(); len(subTasks) > 0 { | ||
subResults = w.collectWorker(loader, subTasks, iterate, seen) | ||
} | ||
iterate(task, subResults) | ||
|
Uh oh!
There was an error while loading. Please reload this page.