Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit f3bffa0

Browse files
authored
gather to accept allFiles (#21)
* gather to accept all files * bump version
1 parent de5bb4e commit f3bffa0

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@canva/dependency-tree",
3-
"version": "3.1.7",
3+
"version": "3.1.8",
44
"description": "Calculates a dependency tree for set of files",
55
"main": "dist/index.js",
66
"author": "Canva Pty Ltd",

src/index.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,15 @@ export class DependencyTree {
160160
// The files to gather dependencies for
161161
// by default globbing is used to find files from rootDirs
162162
filesToProcess,
163+
// All files collected
164+
// by default globbing is used to find files from rootDirs
165+
allFilesToProcess,
163166
batchSize = 10,
164-
}: { batchSize?: number; filesToProcess?: readonly string[] } = {}): Promise<{
167+
}: {
168+
batchSize?: number;
169+
filesToProcess?: readonly string[];
170+
allFilesToProcess?: readonly string[];
171+
} = {}): Promise<{
165172
missing: FileToDeps;
166173
resolved: FileToDeps;
167174
}> {
@@ -173,12 +180,17 @@ export class DependencyTree {
173180

174181
const fileToDeps: FileToDeps = new Map();
175182
const missing: FileToDeps = new Map();
176-
const files = filesToProcess ?? this.getFiles();
183+
const allFiles = allFilesToProcess ?? this.getFiles();
184+
const files = filesToProcess ?? allFiles;
177185
info(`Found a total of ${files.length} source files`);
178186

179187
const getDepsForFilesTasks = files.map((file: string) => async () => {
180188
info('Scanning %s', file);
181-
const importedFiles = await this.getImportedFiles(file, missing, files);
189+
const importedFiles = await this.getImportedFiles(
190+
file,
191+
missing,
192+
allFiles,
193+
);
182194
fileToDeps.set(file, importedFiles);
183195
});
184196

@@ -289,7 +301,7 @@ export class DependencyTree {
289301
*
290302
* @returns {string[]} An array of found files (absolute paths)
291303
*/
292-
private getFiles(): readonly Path[] {
304+
getFiles(): readonly Path[] {
293305
const supportedFileTypes = new Set(
294306
this.fileProcessors.reduce(
295307
(acc, processor) => [...acc, ...processor.supportedFileTypes()],

0 commit comments

Comments
 (0)