|
9 | 9 | import { Vertexes } from './DependencyGraph.js';
|
10 | 10 | import { createDependencyGraph } from './createDependencyGraph.js';
|
11 | 11 | import { MemoryFileService } from './MemoryFileService.js';
|
12 |
| -import { TaskManager } from './TaskManager.js'; |
13 | 12 | import { findFileUsage } from './findFileUsage.js';
|
14 | 13 | import { parseFile } from './parseFile.js';
|
15 | 14 | import { Output } from './Output.js';
|
@@ -627,74 +626,97 @@ export const edit = async ({
|
627 | 626 |
|
628 | 627 | initialFiles.sort((a, b) => a.depth - b.depth);
|
629 | 628 |
|
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]; |
637 | 630 |
|
638 |
| - await Promise.resolve(); |
| 631 | + while (queue.length > 0) { |
| 632 | + const first = queue.shift(); |
639 | 633 |
|
640 |
| - if (c.signal.aborted) { |
641 |
| - return; |
| 634 | + if (!first) { |
| 635 | + break; |
642 | 636 | }
|
643 | 637 |
|
644 |
| - const result = processFile({ |
645 |
| - targetFile: c.file, |
646 |
| - vertexes: dependencyGraph.eject(), |
| 638 | + const current = { |
| 639 | + vertexes: dependencyGraph.vertexes, |
647 | 640 | files: fileService.eject(),
|
648 | 641 | fileNames: fileService.getFileNames(),
|
649 |
| - deleteUnusedFile, |
650 |
| - enableCodeFix, |
651 |
| - options, |
652 |
| - projectRoot, |
653 |
| - }); |
654 |
| - |
655 |
| - if (c.signal.aborted) { |
656 |
| - return; |
657 |
| - } |
| 642 | + }; |
658 | 643 |
|
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; |
663 | 649 | }
|
664 |
| - output.deleteFile(c.file); |
665 |
| - fileService.delete(c.file); |
666 | 650 |
|
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); |
669 | 667 |
|
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 []; |
674 | 686 | }
|
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); |
688 | 697 |
|
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 | + } |
693 | 705 | }
|
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 | + ); |
696 | 717 | }
|
697 |
| - }); |
| 718 | + } |
698 | 719 |
|
699 |
| - await taskManager.execute(initialFiles.map((v) => v.file)); |
| 720 | + // this is kept for compatibility with the old implementation |
| 721 | + return Promise.resolve(); |
700 | 722 | };
|
0 commit comments