Skip to content

Commit

Permalink
Ensure vendor exclusions are applied
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Mar 19, 2024
1 parent 51a7be2 commit dbd443e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/helpers/walk-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface WalkInput {
folders: string[],
/** An instantiated Ignore object listing ignored files */
ignored: Ignore,
/** A list of regexes to ignore */
regexIgnores: RegExp[],
};

interface WalkOutput {
Expand All @@ -26,7 +28,7 @@ interface WalkOutput {

/** Generate list of files in a directory. */
export default function walk(data: WalkInput): WalkOutput {
const { init, commonRoot, folderRoots, folders, ignored } = data;
const { init, commonRoot, folderRoots, folders, ignored, regexIgnores } = data;

// Initialise files and folders lists
if (init) {
Expand Down Expand Up @@ -67,15 +69,16 @@ export default function walk(data: WalkInput): WalkOutput {
if (nonExistant) continue;
// Skip if marked as ignored
const isIgnored = ignored.test(localPath).ignored;
if (isIgnored) continue;
const isRegexIgnored = regexIgnores.some(pattern => pattern.test(localPath));
if (isIgnored || isRegexIgnored) continue;

// Add absolute folder path to list
allFolders.add(paths.resolve(folder).replace(/\\/g, '/'));
// Check if this is a folder or file
if (file.endsWith('/')) {
// Recurse into subfolders
allFolders.add(path);
walk({ init: false, commonRoot, folderRoots, folders: [path], ignored });
walk({ init: false, commonRoot, folderRoots, folders: [path], ignored, regexIgnores });
}
else {
// Add file path to list
Expand All @@ -86,7 +89,7 @@ export default function walk(data: WalkInput): WalkOutput {
// Recurse into all folders
else {
for (const i in folders) {
walk({ init: false, commonRoot, folderRoots: [folderRoots[i]], folders: [folders[i]], ignored });
walk({ init: false, commonRoot, folderRoots: [folderRoots[i]], folders: [folders[i]], ignored, regexIgnores });
}
}
// Return absolute files and folders lists
Expand Down
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ async function analyse(rawPaths?: string | string[], opts: T.Options = {}): Prom
const ignored = ignore();
ignored.add('.git/');
ignored.add(opts.ignoredFiles ?? []);
const regexIgnores: RegExp[] = [];
if (!opts.keepVendored) regexIgnores.push(...vendorPaths.map(path => RegExp(path, 'i')));
const regexIgnores: RegExp[] = opts.keepVendored ? [] : vendorPaths.map(path => RegExp(path, 'i'));

// Load file paths and folders
let files: T.AbsFile[];
Expand All @@ -78,7 +77,7 @@ async function analyse(rawPaths?: string | string[], opts: T.Options = {}): Prom
}
else {
// Uses directory on disc
const data = walk({ init: true, commonRoot, folderRoots: resolvedInput, folders: resolvedInput, ignored });
const data = walk({ init: true, commonRoot, folderRoots: resolvedInput, folders: resolvedInput, ignored, regexIgnores });
files = data.files;
}

Expand Down

0 comments on commit dbd443e

Please sign in to comment.