Skip to content

Commit

Permalink
Include only direct dependents and filter issues by provided --workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 5, 2023
1 parent 3261a17 commit 4dd951b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
12 changes: 9 additions & 3 deletions src/ConfigurationChief.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ export class ConfigurationChief {
return this.config.rules;
}

public getFilters() {
if (this.workspacesGraph?.graph && workspaceArg) return { dir: join(this.cwd, workspaceArg) };
return {};
}

private normalize(rawLocalConfig: RawConfiguration) {
const initialWorkspaces = rawLocalConfig.workspaces ?? {
[ROOT_WORKSPACE_NAME]: {
Expand Down Expand Up @@ -341,14 +346,15 @@ export class ConfigurationChief {

if (graph && workspaceArg) {
const seen = new Set<string>();
const workspaceDirsWithDependants = new Set(workspaceNames.map(name => join(this.cwd, name)));
const initialWorkspaces = new Set(workspaceNames.map(name => join(this.cwd, name)));
const workspaceDirsWithDependants = new Set(initialWorkspaces);
const addDependents = (dir: string) => {
seen.add(dir);
const deps = graph[dir]?.dependencies ?? [];
if (deps.length > 0 && Array.from(workspaceDirsWithDependants).some(dir => deps.includes(dir))) {
if (deps.length > 0 && Array.from(initialWorkspaces).some(dir => deps.includes(dir))) {
workspaceDirsWithDependants.add(dir);
deps.filter(dir => !seen.has(dir)).forEach(addDependents);
}
deps.filter(dir => !seen.has(dir)).forEach(addDependents);
};
this.availableWorkspaceNames.map(name => join(this.cwd, name)).forEach(addDependents);
workspaceDirsWithDependants.forEach(dir => ws.add(relative(this.cwd, dir) || ROOT_WORKSPACE_NAME));
Expand Down
20 changes: 14 additions & 6 deletions src/IssueCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { initIssues, initCounters } from './issues/initializers.js';
import { relative } from './util/path.js';
import type { ConfigurationHint, Issue, Rules } from './types/issues.js';

type Filters = Partial<{
dir: string;
}>;

type IssueCollectorOptions = {
cwd: string;
rules: Rules;
filters: Filters;
};

// TODO Fix dirty check
Expand All @@ -20,14 +25,16 @@ function objectInSet(set: Set<ConfigurationHint>, obj: ConfigurationHint) {
export class IssueCollector {
private cwd: string;
private rules: Rules;
private filters: Filters;
private issues = initIssues();
private counters = initCounters();
private referencedFiles: Set<string> = new Set();
private configurationHints: Set<ConfigurationHint> = new Set();

constructor({ cwd, rules }: IssueCollectorOptions) {
constructor({ cwd, rules, filters }: IssueCollectorOptions) {
this.cwd = cwd;
this.rules = rules;
this.filters = filters;
}

addFileCounts({ processed, unused }: { processed: number; unused: number }) {
Expand All @@ -37,15 +44,16 @@ export class IssueCollector {

addFilesIssues(filePaths: string[]) {
filePaths.forEach(filePath => {
if (!this.referencedFiles.has(filePath)) {
this.issues.files.add(filePath);
this.counters.files++;
this.counters.processed++;
}
if (this.filters.dir && !filePath.startsWith(this.filters.dir + '/')) return;
if (this.referencedFiles.has(filePath)) return;
this.issues.files.add(filePath);
this.counters.files++;
this.counters.processed++;
});
}

addIssue(issue: Issue) {
if (this.filters.dir && !issue.filePath.startsWith(this.filters.dir + '/')) return;
const key = relative(this.cwd, issue.filePath);
issue.severity = this.rules[issue.type];
this.issues[issue.type][key] = this.issues[issue.type][key] ?? {};
Expand Down
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,27 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
const workspaces = chief.getWorkspaces();
const report = chief.getIssueTypesToReport();
const rules = chief.getRules();
const filters = chief.getFilters();

const isReportDependencies = report.dependencies || report.unlisted || report.unresolved;
const isReportValues = report.exports || report.nsExports || report.classMembers;
const isReportTypes = report.types || report.nsTypes || report.enumMembers;

const collector = new IssueCollector({ cwd, rules });
const collector = new IssueCollector({ cwd, rules, filters });

const enabledPluginsStore: Map<string, string[]> = new Map();

// TODO Organize better
deputy.addIgnored(chief.config.ignoreBinaries, chief.config.ignoreDependencies);

debugLogObject('Included workspaces', workspaces);
debugLogObject(
'Included workspaces',
workspaces.map(w => w.pkgName)
);
debugLogObject(
'Included workspace configs',
workspaces.map(w => ({ name: w.name, pkgName: w.pkgName, config: w.config, ancestors: w.ancestors }))
);

const handleReferencedDependency = ({
specifier,
Expand Down

0 comments on commit 4dd951b

Please sign in to comment.