Skip to content

Commit ce83ae7

Browse files
authored
Merge branch 'main' into docs/update-benchmark
2 parents b1091f1 + cfb1d72 commit ce83ae7

File tree

3 files changed

+78
-182
lines changed

3 files changed

+78
-182
lines changed

lib/util/TaskManager.test.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

lib/util/TaskManager.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

lib/util/edit.ts

Lines changed: 78 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import { Vertexes } from './DependencyGraph.js';
1010
import { createDependencyGraph } from './createDependencyGraph.js';
1111
import { MemoryFileService } from './MemoryFileService.js';
12-
import { TaskManager } from './TaskManager.js';
1312
import { findFileUsage } from './findFileUsage.js';
1413
import { parseFile } from './parseFile.js';
1514
import { Output } from './Output.js';
@@ -627,74 +626,97 @@ export const edit = async ({
627626

628627
initialFiles.sort((a, b) => a.depth - b.depth);
629628

630-
const taskManager = new TaskManager(async (c) => {
631-
// if the file is not in the file service, it means it has been deleted in a previous iteration
632-
if (!fileService.exists(c.file)) {
633-
return;
634-
}
635-
636-
const vertex = dependencyGraph.vertexes.get(c.file);
629+
const queue = [initialFiles];
637630

638-
await Promise.resolve();
631+
while (queue.length > 0) {
632+
const first = queue.shift();
639633

640-
if (c.signal.aborted) {
641-
return;
634+
if (!first) {
635+
break;
642636
}
643637

644-
const result = processFile({
645-
targetFile: c.file,
646-
vertexes: dependencyGraph.eject(),
638+
const current = {
639+
vertexes: dependencyGraph.vertexes,
647640
files: fileService.eject(),
648641
fileNames: fileService.getFileNames(),
649-
deleteUnusedFile,
650-
enableCodeFix,
651-
options,
652-
projectRoot,
653-
});
654-
655-
if (c.signal.aborted) {
656-
return;
657-
}
642+
};
658643

659-
switch (result.operation) {
660-
case 'delete': {
661-
if (entrypoints.includes(c.file)) {
662-
break;
644+
const next = first
645+
.map((v) => {
646+
// if the file is not in the file service, it means it has been deleted in a previous iteration
647+
if (!fileService.exists(v.file)) {
648+
return;
663649
}
664-
output.deleteFile(c.file);
665-
fileService.delete(c.file);
666650

667-
if (vertex) {
668-
dependencyGraph.deleteVertex(c.file);
651+
const result = processFile({
652+
targetFile: v.file,
653+
vertexes: current.vertexes,
654+
files: current.files,
655+
fileNames: current.fileNames,
656+
deleteUnusedFile,
657+
enableCodeFix,
658+
options,
659+
projectRoot,
660+
});
661+
662+
return { result, ...v };
663+
})
664+
.filter((r) => !!r)
665+
.map(({ result, file }) => {
666+
const vertex = dependencyGraph.vertexes.get(file);
669667

670-
if (recursive) {
671-
c.add(
672-
...Array.from(vertex.to).filter((f) => !entrypoints.includes(f)),
673-
);
668+
switch (result.operation) {
669+
case 'delete': {
670+
if (entrypoints.includes(file)) {
671+
return [];
672+
}
673+
output.deleteFile(file);
674+
fileService.delete(file);
675+
676+
if (vertex) {
677+
dependencyGraph.deleteVertex(file);
678+
679+
if (recursive) {
680+
return Array.from(vertex.to).filter(
681+
(f) => !entrypoints.includes(f),
682+
);
683+
}
684+
}
685+
return [];
674686
}
675-
}
676-
break;
677-
}
678-
case 'edit': {
679-
for (const item of result.removedExports) {
680-
output.removeExport({
681-
file: item.fileName,
682-
content: fileService.get(item.fileName),
683-
code: item.code,
684-
position: item.position,
685-
});
686-
}
687-
fileService.set(c.file, result.content);
687+
case 'edit': {
688+
for (const item of result.removedExports) {
689+
output.removeExport({
690+
file: item.fileName,
691+
content: fileService.get(item.fileName),
692+
code: item.code,
693+
position: item.position,
694+
});
695+
}
696+
fileService.set(file, result.content);
688697

689-
if (vertex && result.removedExports.length > 0 && recursive) {
690-
c.add(
691-
...Array.from(vertex.to).filter((f) => !entrypoints.includes(f)),
692-
);
698+
if (vertex && result.removedExports.length > 0 && recursive) {
699+
return Array.from(vertex.to).filter(
700+
(f) => !entrypoints.includes(f),
701+
);
702+
}
703+
return [];
704+
}
693705
}
694-
break;
695-
}
706+
});
707+
708+
const files = Array.from(new Set(next.flat()));
709+
710+
if (files.length > 0) {
711+
queue.push(
712+
files.map((file) => ({
713+
file,
714+
depth: dependencyGraph.vertexes.get(file)?.data.depth || Infinity,
715+
})),
716+
);
696717
}
697-
});
718+
}
698719

699-
await taskManager.execute(initialFiles.map((v) => v.file));
720+
// this is kept for compatibility with the old implementation
721+
return Promise.resolve();
700722
};

0 commit comments

Comments
 (0)