Skip to content

Commit

Permalink
Rename createPkgGraph → createWorkspaceGraph, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jul 14, 2024
1 parent 7274e8d commit 9deb9c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions packages/knip/src/ConfigurationChief.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
import type { PackageJson } from './types/package-json.js';
import { arrayify, compact } from './util/array.js';
import parsedArgValues from './util/cli-arguments.js';
import { type WorkspaceGraph, createWorkspaceGraph } from './util/create-workspace-graph.js';
import { ConfigurationError } from './util/errors.js';
import { findFile, isDirectory, isFile, loadJSON } from './util/fs.js';
import { getIncludedIssueTypes } from './util/get-included-issue-types.js';
Expand All @@ -24,7 +25,6 @@ import { _load } from './util/loader.js';
import mapWorkspaces from './util/map-workspaces.js';
import { getKeysByValue } from './util/object.js';
import { join, relative, resolve, toPosix } from './util/path.js';
import { type Graph, createPkgGraph } from './util/pkgs-graph.js';
import { normalizePluginConfig, toCamelCase } from './util/plugin.js';
import { toRegexOrString } from './util/regex.js';
import { unwrapFunction } from './util/unwrap-function.js';
Expand Down Expand Up @@ -114,7 +114,7 @@ export class ConfigurationChief {
availableWorkspaceNames: string[] = [];
availableWorkspacePkgNames = new Set<string>();
availableWorkspaceDirs: string[] = [];
packageGraph: Graph | undefined;
workspaceGraph: WorkspaceGraph | undefined;
includedWorkspaces: Workspace[] = [];

resolvedConfigFilePath?: string;
Expand Down Expand Up @@ -182,7 +182,7 @@ export class ConfigurationChief {
}

public getFilters() {
if (this.packageGraph && workspaceArg) return { dir: join(this.cwd, workspaceArg) };
if (this.workspaceGraph && workspaceArg) return { dir: join(this.cwd, workspaceArg) };
return {};
}

Expand Down Expand Up @@ -244,7 +244,7 @@ export class ConfigurationChief {
.reverse()
.map(dir => join(this.cwd, dir));

this.packageGraph = createPkgGraph(
this.workspaceGraph = createWorkspaceGraph(
this.cwd,
this.availableWorkspaceNames,
this.availableWorkspacePkgNames,
Expand Down Expand Up @@ -345,7 +345,7 @@ export class ConfigurationChief {
if (workspaceArg && this.isStrict) {
ws.add(workspaceArg);
} else if (workspaceArg) {
const graph = this.packageGraph;
const graph = this.workspaceGraph;
if (graph) {
const seen = new Set<string>();
const initialWorkspaces = workspaceNames.map(name => join(this.cwd, name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ interface Package {
dir: string;
}

export type Graph = Record<string, Set<string>>;
export type WorkspaceGraph = Record<string, Set<string>>;

const types = ['peerDependencies', 'devDependencies', 'optionalDependencies', 'dependencies'] as const;

export function createPkgGraph(
export function createWorkspaceGraph(
cwd: string,
wsNames: string[],
wsPkgNames: Set<string>,
byPkgName: Map<string, Package>,
byName: Map<string, Package>
) {
const graph: Graph = {};
const graph: WorkspaceGraph = {};

const getPkgDirs = (pkg: Package) => {
const getWorkspaceDirs = (pkg: Package) => {
const dirs = new Set<string>();
for (const type of types) {
if (pkg.manifest[type]) {
Expand All @@ -36,7 +36,7 @@ export function createPkgGraph(

for (const name of wsNames) {
const pkg = byName.get(name);
if (pkg) graph[join(cwd, name)] = getPkgDirs(pkg);
if (pkg) graph[join(cwd, name)] = getWorkspaceDirs(pkg);
}

return graph;
Expand Down

0 comments on commit 9deb9c5

Please sign in to comment.