Skip to content

Commit

Permalink
Group handlers in main sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jul 14, 2024
1 parent 0dc5eba commit 7274e8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions packages/knip/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { addNsValues, addValues, createFileNode } from './util/dependency-graph.
import { isFile } from './util/fs.js';
import { _glob, negate } from './util/glob.js';
import { getGitIgnoredHandler } from './util/globby.js';
import { getHandler } from './util/handle-dependency.js';
import { getReferencedDependencyHandler } from './util/handle-dependency.js';
import { getHasStrictlyNsReferences, getType } from './util/has-strictly-ns-references.js';
import { getIsIdentifierReferencedHandler } from './util/is-identifier-referenced.js';
import { getEntryPathFromManifest, getPackageNameFromModuleSpecifier } from './util/modules.js';
Expand Down Expand Up @@ -66,9 +66,6 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
const factory = new PrincipalFactory();
const streamer = new ConsoleStreamer({ isEnabled: isShowProgress });

const isGitIgnored = await getGitIgnoredHandler({ cwd, gitignore });
const toSourceFilePath = getToSourcePathHandler(chief);

streamer.cast('Reading workspace configuration(s)...');

await chief.init();
Expand All @@ -95,6 +92,12 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
debugLogObject('*', 'Included workspaces', () => workspaces.map(w => w.pkgName));
debugLogObject('*', 'Included workspace configs', o);

const isGitIgnored = await getGitIgnoredHandler({ cwd, gitignore });
const toSourceFilePath = getToSourcePathHandler(chief);
const handleReferencedDependency = getReferencedDependencyHandler(collector, deputy, chief);
const shouldIgnore = getShouldIgnoreHandler(isProduction);
const shouldIgnoreTags = getShouldIgnoreTagHandler(tags);

for (const workspace of workspaces) {
const { name, dir, ancestors, pkgName, manifestPath } = workspace;

Expand Down Expand Up @@ -251,8 +254,7 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
const entryPaths = new Set<string>();

const getFileNode = (filePath: string) => graph.get(filePath) ?? createFileNode();

const handleReferencedDependency = getHandler(collector, deputy, chief);
const isIdentifierReferenced = getIsIdentifierReferencedHandler(graph, entryPaths);

const updateImportDetails = (importedModule: ImportDetails, importItems: ImportDetails) => {
for (const id of importItems.refs) importedModule.refs.add(id);
Expand Down Expand Up @@ -371,11 +373,6 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {

if (isIsolateWorkspaces) for (const principal of principals) factory.deletePrincipal(principal);

const shouldIgnore = getShouldIgnoreHandler(isProduction);
const shouldIgnoreTags = getShouldIgnoreTagHandler(tags);

const isIdentifierReferenced = getIsIdentifierReferencedHandler(graph, entryPaths);

const ignoreExportsUsedInFile = chief.config.ignoreExportsUsedInFile;
const isExportedItemReferenced = (exportedItem: Export | ExportMember) =>
exportedItem.refs[1] ||
Expand Down Expand Up @@ -589,6 +586,7 @@ export const main = async (unresolvedConfiguration: CommandLineOptions) => {
for (const issue of dependencyIssues) collector.addIssue(issue);
if (!isProduction) for (const issue of devDependencyIssues) collector.addIssue(issue);
for (const issue of optionalPeerDependencyIssues) collector.addIssue(issue);

const configurationHints = deputy.getConfigurationHints(collector.getIssues());
for (const hint of configurationHints) collector.addConfigurationHint(hint);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/knip/src/util/handle-dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { fromBinary, isBinary } from './protocols.js';
import { _resolveSpecifier } from './require.js';
import { resolveSync } from './resolve.js';

export const getHandler =
export const getReferencedDependencyHandler =
(collector: IssueCollector, deputy: DependencyDeputy, chief: ConfigurationChief) =>
(specifier: string, containingFilePath: string, workspace: Workspace) => {
if (isBinary(specifier)) {
Expand Down

0 comments on commit 7274e8d

Please sign in to comment.