knip 0.0.0-angular.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +907 -0
- package/dist/ConfigurationChief.d.ts +53 -0
- package/dist/ConfigurationChief.js +297 -0
- package/dist/ConfigurationValidator.d.ts +2325 -0
- package/dist/ConfigurationValidator.js +119 -0
- package/dist/ConsoleStreamer.d.ts +12 -0
- package/dist/ConsoleStreamer.js +34 -0
- package/dist/DependencyDeputy.d.ts +64 -0
- package/dist/DependencyDeputy.js +254 -0
- package/dist/IssueCollector.d.ts +27 -0
- package/dist/IssueCollector.js +52 -0
- package/dist/PrincipalFactory.d.ts +25 -0
- package/dist/PrincipalFactory.js +56 -0
- package/dist/ProjectPrincipal.d.ts +64 -0
- package/dist/ProjectPrincipal.js +197 -0
- package/dist/WorkspaceWorker.d.ts +56 -0
- package/dist/WorkspaceWorker.js +244 -0
- package/dist/binaries/bash-parser.d.ts +6 -0
- package/dist/binaries/bash-parser.js +58 -0
- package/dist/binaries/index.d.ts +2 -0
- package/dist/binaries/index.js +18 -0
- package/dist/binaries/resolvers/c8.d.ts +2 -0
- package/dist/binaries/resolvers/c8.js +10 -0
- package/dist/binaries/resolvers/dotenv.d.ts +2 -0
- package/dist/binaries/resolvers/dotenv.js +6 -0
- package/dist/binaries/resolvers/fallback.d.ts +2 -0
- package/dist/binaries/resolvers/fallback.js +22 -0
- package/dist/binaries/resolvers/index.d.ts +8 -0
- package/dist/binaries/resolvers/index.js +8 -0
- package/dist/binaries/resolvers/node.d.ts +2 -0
- package/dist/binaries/resolvers/node.js +10 -0
- package/dist/binaries/resolvers/nodemon.d.ts +2 -0
- package/dist/binaries/resolvers/nodemon.js +15 -0
- package/dist/binaries/resolvers/npx.d.ts +2 -0
- package/dist/binaries/resolvers/npx.js +20 -0
- package/dist/binaries/resolvers/pnpm.d.ts +2 -0
- package/dist/binaries/resolvers/pnpm.js +63 -0
- package/dist/binaries/resolvers/rollup.d.ts +2 -0
- package/dist/binaries/resolvers/rollup.js +11 -0
- package/dist/binaries/resolvers/yarn.d.ts +2 -0
- package/dist/binaries/resolvers/yarn.js +48 -0
- package/dist/binaries/types.d.ts +15 -0
- package/dist/binaries/types.js +1 -0
- package/dist/binaries/util.d.ts +8 -0
- package/dist/binaries/util.js +33 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +72 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.js +90 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +334 -0
- package/dist/issues/initializers.d.ts +4 -0
- package/dist/issues/initializers.js +11 -0
- package/dist/manifest/helpers.d.ts +7 -0
- package/dist/manifest/helpers.js +16 -0
- package/dist/manifest/index.d.ts +16 -0
- package/dist/manifest/index.js +56 -0
- package/dist/plugins/_template/index.d.ts +9 -0
- package/dist/plugins/_template/index.js +14 -0
- package/dist/plugins/_template/types.d.ts +3 -0
- package/dist/plugins/_template/types.js +1 -0
- package/dist/plugins/angular/index.d.ts +6 -0
- package/dist/plugins/angular/index.js +36 -0
- package/dist/plugins/angular/types.d.ts +745 -0
- package/dist/plugins/angular/types.js +1 -0
- package/dist/plugins/ava/index.d.ts +7 -0
- package/dist/plugins/ava/index.js +20 -0
- package/dist/plugins/ava/types.d.ts +4 -0
- package/dist/plugins/ava/types.js +1 -0
- package/dist/plugins/babel/helpers.d.ts +15 -0
- package/dist/plugins/babel/helpers.js +34 -0
- package/dist/plugins/babel/index.d.ts +8 -0
- package/dist/plugins/babel/index.js +30 -0
- package/dist/plugins/babel/types.d.ts +9 -0
- package/dist/plugins/babel/types.js +1 -0
- package/dist/plugins/capacitor/index.d.ts +6 -0
- package/dist/plugins/capacitor/index.js +11 -0
- package/dist/plugins/capacitor/types.d.ts +3 -0
- package/dist/plugins/capacitor/types.js +1 -0
- package/dist/plugins/changesets/index.d.ts +6 -0
- package/dist/plugins/changesets/index.js +15 -0
- package/dist/plugins/commitizen/index.d.ts +6 -0
- package/dist/plugins/commitizen/index.js +14 -0
- package/dist/plugins/commitizen/types.d.ts +3 -0
- package/dist/plugins/commitizen/types.js +1 -0
- package/dist/plugins/commitlint/index.d.ts +6 -0
- package/dist/plugins/commitlint/index.js +18 -0
- package/dist/plugins/cspell/index.d.ts +6 -0
- package/dist/plugins/cspell/index.js +17 -0
- package/dist/plugins/cspell/types.d.ts +3 -0
- package/dist/plugins/cspell/types.js +1 -0
- package/dist/plugins/cypress/index.d.ts +5 -0
- package/dist/plugins/cypress/index.js +10 -0
- package/dist/plugins/eslint/fallback.d.ts +1 -0
- package/dist/plugins/eslint/fallback.js +13 -0
- package/dist/plugins/eslint/helpers.d.ts +14 -0
- package/dist/plugins/eslint/helpers.js +83 -0
- package/dist/plugins/eslint/index.d.ts +7 -0
- package/dist/plugins/eslint/index.js +15 -0
- package/dist/plugins/eslint/types.d.ts +27 -0
- package/dist/plugins/eslint/types.js +1 -0
- package/dist/plugins/gatsby/index.d.ts +7 -0
- package/dist/plugins/gatsby/index.js +30 -0
- package/dist/plugins/gatsby/types.d.ts +15 -0
- package/dist/plugins/gatsby/types.js +1 -0
- package/dist/plugins/github-actions/index.d.ts +6 -0
- package/dist/plugins/github-actions/index.js +21 -0
- package/dist/plugins/husky/index.d.ts +6 -0
- package/dist/plugins/husky/index.js +19 -0
- package/dist/plugins/index.d.ts +41 -0
- package/dist/plugins/index.js +41 -0
- package/dist/plugins/jest/index.d.ts +7 -0
- package/dist/plugins/jest/index.js +68 -0
- package/dist/plugins/lefthook/index.d.ts +6 -0
- package/dist/plugins/lefthook/index.js +28 -0
- package/dist/plugins/lint-staged/index.d.ts +6 -0
- package/dist/plugins/lint-staged/index.js +32 -0
- package/dist/plugins/lint-staged/types.d.ts +5 -0
- package/dist/plugins/lint-staged/types.js +1 -0
- package/dist/plugins/markdownlint/helpers.d.ts +1 -0
- package/dist/plugins/markdownlint/helpers.js +6 -0
- package/dist/plugins/markdownlint/index.d.ts +6 -0
- package/dist/plugins/markdownlint/index.js +19 -0
- package/dist/plugins/markdownlint/types.d.ts +3 -0
- package/dist/plugins/markdownlint/types.js +1 -0
- package/dist/plugins/mocha/index.d.ts +6 -0
- package/dist/plugins/mocha/index.js +15 -0
- package/dist/plugins/next/index.d.ts +6 -0
- package/dist/plugins/next/index.js +11 -0
- package/dist/plugins/npm-package-json-lint/index.d.ts +6 -0
- package/dist/plugins/npm-package-json-lint/index.js +13 -0
- package/dist/plugins/npm-package-json-lint/types.d.ts +3 -0
- package/dist/plugins/npm-package-json-lint/types.js +1 -0
- package/dist/plugins/nx/index.d.ts +6 -0
- package/dist/plugins/nx/index.js +24 -0
- package/dist/plugins/nx/types.d.ts +11 -0
- package/dist/plugins/nx/types.js +1 -0
- package/dist/plugins/nyc/index.d.ts +6 -0
- package/dist/plugins/nyc/index.js +11 -0
- package/dist/plugins/playwright/index.d.ts +5 -0
- package/dist/plugins/playwright/index.js +5 -0
- package/dist/plugins/postcss/index.d.ts +6 -0
- package/dist/plugins/postcss/index.js +23 -0
- package/dist/plugins/postcss/types.d.ts +3 -0
- package/dist/plugins/postcss/types.js +1 -0
- package/dist/plugins/prettier/index.d.ts +6 -0
- package/dist/plugins/prettier/index.js +20 -0
- package/dist/plugins/release-it/index.d.ts +6 -0
- package/dist/plugins/release-it/index.js +30 -0
- package/dist/plugins/release-it/types.d.ts +10 -0
- package/dist/plugins/release-it/types.js +1 -0
- package/dist/plugins/remark/index.d.ts +6 -0
- package/dist/plugins/remark/index.js +18 -0
- package/dist/plugins/remix/index.d.ts +6 -0
- package/dist/plugins/remix/index.js +11 -0
- package/dist/plugins/rollup/index.d.ts +5 -0
- package/dist/plugins/rollup/index.js +5 -0
- package/dist/plugins/semantic-release/index.d.ts +6 -0
- package/dist/plugins/semantic-release/index.js +17 -0
- package/dist/plugins/semantic-release/types.d.ts +3 -0
- package/dist/plugins/semantic-release/types.js +1 -0
- package/dist/plugins/sentry/index.d.ts +5 -0
- package/dist/plugins/sentry/index.js +5 -0
- package/dist/plugins/storybook/index.d.ts +8 -0
- package/dist/plugins/storybook/index.js +19 -0
- package/dist/plugins/storybook/types.d.ts +11 -0
- package/dist/plugins/storybook/types.js +1 -0
- package/dist/plugins/stryker/index.d.ts +6 -0
- package/dist/plugins/stryker/index.js +17 -0
- package/dist/plugins/stryker/types.d.ts +5 -0
- package/dist/plugins/stryker/types.js +1 -0
- package/dist/plugins/stylelint/index.d.ts +6 -0
- package/dist/plugins/stylelint/index.js +22 -0
- package/dist/plugins/stylelint/types.d.ts +4 -0
- package/dist/plugins/stylelint/types.js +1 -0
- package/dist/plugins/svelte/index.d.ts +7 -0
- package/dist/plugins/svelte/index.js +9 -0
- package/dist/plugins/tailwind/index.d.ts +5 -0
- package/dist/plugins/tailwind/index.js +5 -0
- package/dist/plugins/typedoc/index.d.ts +6 -0
- package/dist/plugins/typedoc/index.js +22 -0
- package/dist/plugins/typedoc/types.d.ts +3 -0
- package/dist/plugins/typedoc/types.js +1 -0
- package/dist/plugins/typescript/index.d.ts +7 -0
- package/dist/plugins/typescript/index.js +42 -0
- package/dist/plugins/vite/index.d.ts +6 -0
- package/dist/plugins/vite/index.js +12 -0
- package/dist/plugins/vite/types.d.ts +4 -0
- package/dist/plugins/vite/types.js +1 -0
- package/dist/plugins/vitest/helpers.d.ts +6 -0
- package/dist/plugins/vitest/helpers.js +22 -0
- package/dist/plugins/vitest/index.d.ts +9 -0
- package/dist/plugins/vitest/index.js +25 -0
- package/dist/plugins/vitest/types.d.ts +11 -0
- package/dist/plugins/vitest/types.js +1 -0
- package/dist/plugins/webpack/index.d.ts +6 -0
- package/dist/plugins/webpack/index.js +82 -0
- package/dist/plugins/webpack/types.d.ts +10 -0
- package/dist/plugins/webpack/types.js +1 -0
- package/dist/reporters/codeowners.d.ts +3 -0
- package/dist/reporters/codeowners.js +62 -0
- package/dist/reporters/compact.d.ts +3 -0
- package/dist/reporters/compact.js +36 -0
- package/dist/reporters/index.d.ts +7 -0
- package/dist/reporters/index.js +10 -0
- package/dist/reporters/json.d.ts +3 -0
- package/dist/reporters/json.js +67 -0
- package/dist/reporters/symbols.d.ts +3 -0
- package/dist/reporters/symbols.js +54 -0
- package/dist/reporters/util.d.ts +15 -0
- package/dist/reporters/util.js +17 -0
- package/dist/types/cli.d.ts +10 -0
- package/dist/types/cli.js +1 -0
- package/dist/types/compilers.d.ts +6 -0
- package/dist/types/compilers.js +1 -0
- package/dist/types/config.d.ts +39 -0
- package/dist/types/config.js +3 -0
- package/dist/types/exports.d.ts +20 -0
- package/dist/types/exports.js +1 -0
- package/dist/types/imports.d.ts +13 -0
- package/dist/types/imports.js +1 -0
- package/dist/types/issues.d.ts +62 -0
- package/dist/types/issues.js +10 -0
- package/dist/types/plugins.d.ts +19 -0
- package/dist/types/plugins.js +1 -0
- package/dist/types/workspace.d.ts +17 -0
- package/dist/types/workspace.js +1 -0
- package/dist/typescript/SourceFile.d.ts +18 -0
- package/dist/typescript/SourceFile.js +1 -0
- package/dist/typescript/SourceFileManager.d.ts +13 -0
- package/dist/typescript/SourceFileManager.js +57 -0
- package/dist/typescript/ast-helpers.d.ts +27 -0
- package/dist/typescript/ast-helpers.js +101 -0
- package/dist/typescript/createHosts.d.ts +15 -0
- package/dist/typescript/createHosts.js +39 -0
- package/dist/typescript/getImportsAndExports.d.ts +29 -0
- package/dist/typescript/getImportsAndExports.js +159 -0
- package/dist/typescript/resolveModuleNames.d.ts +2 -0
- package/dist/typescript/resolveModuleNames.js +27 -0
- package/dist/typescript/sys.d.ts +35 -0
- package/dist/typescript/sys.js +16 -0
- package/dist/typescript/utils.d.ts +2 -0
- package/dist/typescript/utils.js +9 -0
- package/dist/typescript/visitors/exports/exportAssignment.d.ts +3 -0
- package/dist/typescript/visitors/exports/exportAssignment.js +9 -0
- package/dist/typescript/visitors/exports/exportDeclaration.d.ts +3 -0
- package/dist/typescript/visitors/exports/exportDeclaration.js +13 -0
- package/dist/typescript/visitors/exports/exportKeyword.d.ts +3 -0
- package/dist/typescript/visitors/exports/exportKeyword.js +77 -0
- package/dist/typescript/visitors/exports/index.d.ts +3 -0
- package/dist/typescript/visitors/exports/index.js +7 -0
- package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +3 -0
- package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +31 -0
- package/dist/typescript/visitors/helpers.d.ts +4 -0
- package/dist/typescript/visitors/helpers.js +10 -0
- package/dist/typescript/visitors/imports/importCall.d.ts +3 -0
- package/dist/typescript/visitors/imports/importCall.js +11 -0
- package/dist/typescript/visitors/imports/importDeclaration.d.ts +3 -0
- package/dist/typescript/visitors/imports/importDeclaration.js +32 -0
- package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +3 -0
- package/dist/typescript/visitors/imports/importEqualsDeclaration.js +11 -0
- package/dist/typescript/visitors/imports/index.d.ts +3 -0
- package/dist/typescript/visitors/imports/index.js +18 -0
- package/dist/typescript/visitors/imports/jsDocType.d.ts +3 -0
- package/dist/typescript/visitors/imports/jsDocType.js +11 -0
- package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +3 -0
- package/dist/typescript/visitors/imports/reExportDeclaration.js +21 -0
- package/dist/typescript/visitors/imports/requireCall.d.ts +3 -0
- package/dist/typescript/visitors/imports/requireCall.js +45 -0
- package/dist/typescript/visitors/imports/requireResolveCall.d.ts +3 -0
- package/dist/typescript/visitors/imports/requireResolveCall.js +12 -0
- package/dist/typescript/visitors/index.d.ts +10 -0
- package/dist/typescript/visitors/index.js +16 -0
- package/dist/typescript/visitors/scripts/execa.d.ts +3 -0
- package/dist/typescript/visitors/scripts/execa.js +18 -0
- package/dist/typescript/visitors/scripts/index.d.ts +3 -0
- package/dist/typescript/visitors/scripts/index.js +5 -0
- package/dist/typescript/visitors/scripts/zx.d.ts +3 -0
- package/dist/typescript/visitors/scripts/zx.js +8 -0
- package/dist/util/Performance.d.ts +23 -0
- package/dist/util/Performance.js +80 -0
- package/dist/util/array.d.ts +2 -0
- package/dist/util/array.js +2 -0
- package/dist/util/cli-arguments.d.ts +28 -0
- package/dist/util/cli-arguments.js +83 -0
- package/dist/util/compilers.d.ts +426 -0
- package/dist/util/compilers.js +20 -0
- package/dist/util/debug.d.ts +3 -0
- package/dist/util/debug.js +34 -0
- package/dist/util/errors.d.ts +12 -0
- package/dist/util/errors.js +14 -0
- package/dist/util/fs.d.ts +7 -0
- package/dist/util/fs.js +42 -0
- package/dist/util/get-included-issue-types.d.ts +16 -0
- package/dist/util/get-included-issue-types.js +37 -0
- package/dist/util/git.d.ts +1 -0
- package/dist/util/git.js +20 -0
- package/dist/util/glob.d.ts +19 -0
- package/dist/util/glob.js +59 -0
- package/dist/util/loader.d.ts +1 -0
- package/dist/util/loader.js +31 -0
- package/dist/util/map.d.ts +1 -0
- package/dist/util/map.js +6 -0
- package/dist/util/modules.d.ts +8 -0
- package/dist/util/modules.js +52 -0
- package/dist/util/object.d.ts +3 -0
- package/dist/util/object.js +37 -0
- package/dist/util/path.d.ts +11 -0
- package/dist/util/path.js +13 -0
- package/dist/util/plugin.d.ts +3 -0
- package/dist/util/plugin.js +14 -0
- package/dist/util/register.d.ts +1 -0
- package/dist/util/register.js +14 -0
- package/dist/util/reporter.d.ts +3 -0
- package/dist/util/reporter.js +16 -0
- package/dist/util/require.d.ts +5 -0
- package/dist/util/require.js +34 -0
- package/dist/util/tsconfig-loader.d.ts +2 -0
- package/dist/util/tsconfig-loader.js +11 -0
- package/dist/util/workspace.d.ts +1 -0
- package/dist/util/workspace.js +11 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/license +12 -0
- package/package.json +150 -0
- package/schema.json +403 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="npmcli__package-json" />
|
|
2
|
+
import type { SyncCompilers, AsyncCompilers } from './types/compilers.js';
|
|
3
|
+
import type { Configuration, WorkspaceConfiguration } from './types/config.js';
|
|
4
|
+
import type { PackageJson } from '@npmcli/package-json';
|
|
5
|
+
type ConfigurationManagerOptions = {
|
|
6
|
+
cwd: string;
|
|
7
|
+
isProduction: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type Workspace = {
|
|
10
|
+
name: string;
|
|
11
|
+
pkgName?: string;
|
|
12
|
+
dir: string;
|
|
13
|
+
ancestors: string[];
|
|
14
|
+
config: WorkspaceConfiguration;
|
|
15
|
+
};
|
|
16
|
+
export declare class ConfigurationChief {
|
|
17
|
+
cwd: string;
|
|
18
|
+
isProduction: boolean;
|
|
19
|
+
config: Configuration;
|
|
20
|
+
manifestPath?: string;
|
|
21
|
+
manifest?: PackageJson;
|
|
22
|
+
ignoredWorkspacePatterns: string[];
|
|
23
|
+
manifestWorkspaces: Map<string, string>;
|
|
24
|
+
additionalWorkspaceNames: Set<string>;
|
|
25
|
+
availableWorkspaceNames: string[];
|
|
26
|
+
availableWorkspaceDirs: string[];
|
|
27
|
+
enabledWorkspaces: Workspace[];
|
|
28
|
+
localWorkspaces: Set<string>;
|
|
29
|
+
resolvedConfigFilePath?: string;
|
|
30
|
+
constructor({ cwd, isProduction }: ConfigurationManagerOptions);
|
|
31
|
+
init(): Promise<void>;
|
|
32
|
+
getCompilers(): [SyncCompilers, AsyncCompilers];
|
|
33
|
+
getRules(): import("./types/issues.js").Rules;
|
|
34
|
+
private normalize;
|
|
35
|
+
private setWorkspaces;
|
|
36
|
+
private getListedWorkspaces;
|
|
37
|
+
private getIgnoredWorkspacePatterns;
|
|
38
|
+
private getManifestWorkspaces;
|
|
39
|
+
private getAdditionalWorkspaceNames;
|
|
40
|
+
private getAvailableWorkspaceNames;
|
|
41
|
+
private getEnabledWorkspaces;
|
|
42
|
+
getWorkspaces(): Workspace[];
|
|
43
|
+
private getDescendentWorkspaces;
|
|
44
|
+
private getIgnoredWorkspacesFor;
|
|
45
|
+
getNegatedWorkspacePatterns(name: string): string[];
|
|
46
|
+
private getConfigKeyForWorkspace;
|
|
47
|
+
private getConfigForWorkspace;
|
|
48
|
+
getIssueTypesToReport(): import("./types/issues.js").Report;
|
|
49
|
+
findWorkspaceByFilePath(filePath: string): Workspace | undefined;
|
|
50
|
+
findWorkspaceByPackageName(packageName: string): Workspace | undefined;
|
|
51
|
+
getUnusedIgnoredWorkspaces(): string[];
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import mapWorkspaces from '@npmcli/map-workspaces';
|
|
3
|
+
import micromatch from 'micromatch';
|
|
4
|
+
import { ConfigurationValidator } from './ConfigurationValidator.js';
|
|
5
|
+
import { ROOT_WORKSPACE_NAME, DEFAULT_EXTENSIONS, KNIP_CONFIG_LOCATIONS } from './constants.js';
|
|
6
|
+
import { defaultRules } from './issues/initializers.js';
|
|
7
|
+
import * as plugins from './plugins/index.js';
|
|
8
|
+
import { arrayify, compact } from './util/array.js';
|
|
9
|
+
import parsedArgValues from './util/cli-arguments.js';
|
|
10
|
+
import { partitionCompilers } from './util/compilers.js';
|
|
11
|
+
import { ConfigurationError } from './util/errors.js';
|
|
12
|
+
import { findFile, loadJSON } from './util/fs.js';
|
|
13
|
+
import { getIncludedIssueTypes } from './util/get-included-issue-types.js';
|
|
14
|
+
import { _dirGlob } from './util/glob.js';
|
|
15
|
+
import { _load } from './util/loader.js';
|
|
16
|
+
import { getKeysByValue } from './util/object.js';
|
|
17
|
+
import { join, relative, toPosix } from './util/path.js';
|
|
18
|
+
import { toCamelCase } from './util/plugin.js';
|
|
19
|
+
import { byPathDepth } from './util/workspace.js';
|
|
20
|
+
const { config: rawConfigArg, workspace: rawWorkspaceArg, include = [], exclude = [], dependencies = false, exports = false, } = parsedArgValues;
|
|
21
|
+
const workspaceArg = rawWorkspaceArg ? toPosix(rawWorkspaceArg).replace(/^\.\//, '').replace(/\/$/, '') : undefined;
|
|
22
|
+
const getDefaultWorkspaceConfig = (extensions) => {
|
|
23
|
+
const exts = [...DEFAULT_EXTENSIONS, ...(extensions ?? [])].map(ext => ext.slice(1)).join(',');
|
|
24
|
+
return {
|
|
25
|
+
entry: [`{index,cli,main}.{${exts}}!`, `src/{index,cli,main}.{${exts}}!`],
|
|
26
|
+
project: [`**/*.{${exts}}!`],
|
|
27
|
+
paths: {},
|
|
28
|
+
ignore: [],
|
|
29
|
+
ignoreBinaries: [],
|
|
30
|
+
ignoreDependencies: [],
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const defaultConfig = {
|
|
34
|
+
rules: defaultRules,
|
|
35
|
+
include: [],
|
|
36
|
+
exclude: [],
|
|
37
|
+
ignore: [],
|
|
38
|
+
ignoreBinaries: [],
|
|
39
|
+
ignoreDependencies: [],
|
|
40
|
+
ignoreExportsUsedInFile: false,
|
|
41
|
+
ignoreWorkspaces: [],
|
|
42
|
+
syncCompilers: new Map(),
|
|
43
|
+
asyncCompilers: new Map(),
|
|
44
|
+
workspaces: {
|
|
45
|
+
[ROOT_WORKSPACE_NAME]: getDefaultWorkspaceConfig(),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
const PLUGIN_NAMES = Object.keys(plugins);
|
|
49
|
+
export class ConfigurationChief {
|
|
50
|
+
cwd;
|
|
51
|
+
isProduction = false;
|
|
52
|
+
config;
|
|
53
|
+
manifestPath;
|
|
54
|
+
manifest;
|
|
55
|
+
ignoredWorkspacePatterns = [];
|
|
56
|
+
manifestWorkspaces = new Map();
|
|
57
|
+
additionalWorkspaceNames = new Set();
|
|
58
|
+
availableWorkspaceNames = [];
|
|
59
|
+
availableWorkspaceDirs = [];
|
|
60
|
+
enabledWorkspaces = [];
|
|
61
|
+
localWorkspaces = new Set();
|
|
62
|
+
resolvedConfigFilePath;
|
|
63
|
+
constructor({ cwd, isProduction }) {
|
|
64
|
+
this.cwd = cwd;
|
|
65
|
+
this.isProduction = isProduction;
|
|
66
|
+
this.config = defaultConfig;
|
|
67
|
+
}
|
|
68
|
+
async init() {
|
|
69
|
+
const manifestPath = findFile(this.cwd, 'package.json');
|
|
70
|
+
const manifest = manifestPath && (await loadJSON(manifestPath));
|
|
71
|
+
if (!manifestPath || !manifest) {
|
|
72
|
+
throw new ConfigurationError('Unable to find package.json');
|
|
73
|
+
}
|
|
74
|
+
this.manifestPath = manifestPath;
|
|
75
|
+
this.manifest = manifest;
|
|
76
|
+
const pnpmWorkspacesPath = findFile(this.cwd, 'pnpm-workspace.yaml');
|
|
77
|
+
const pnpmWorkspaces = pnpmWorkspacesPath && (await _load(pnpmWorkspacesPath));
|
|
78
|
+
if (this.manifest && !this.manifest.workspaces && pnpmWorkspaces) {
|
|
79
|
+
this.manifest.workspaces = pnpmWorkspaces;
|
|
80
|
+
}
|
|
81
|
+
for (const configPath of rawConfigArg ? [rawConfigArg] : KNIP_CONFIG_LOCATIONS) {
|
|
82
|
+
this.resolvedConfigFilePath = findFile(this.cwd, configPath);
|
|
83
|
+
if (this.resolvedConfigFilePath)
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
if (rawConfigArg && !this.resolvedConfigFilePath && !manifest.knip) {
|
|
87
|
+
throw new ConfigurationError(`Unable to find ${rawConfigArg} or package.json#knip`);
|
|
88
|
+
}
|
|
89
|
+
const rawLocalConfig = this.resolvedConfigFilePath ? await _load(this.resolvedConfigFilePath) : manifest.knip;
|
|
90
|
+
if (rawLocalConfig) {
|
|
91
|
+
const parsedConfig = ConfigurationValidator.parse(partitionCompilers(rawLocalConfig));
|
|
92
|
+
this.config = this.normalize(parsedConfig);
|
|
93
|
+
}
|
|
94
|
+
await this.setWorkspaces();
|
|
95
|
+
}
|
|
96
|
+
getCompilers() {
|
|
97
|
+
return [this.config.syncCompilers, this.config.asyncCompilers];
|
|
98
|
+
}
|
|
99
|
+
getRules() {
|
|
100
|
+
return this.config.rules;
|
|
101
|
+
}
|
|
102
|
+
normalize(rawLocalConfig) {
|
|
103
|
+
const initialWorkspaces = rawLocalConfig.workspaces ?? {
|
|
104
|
+
[ROOT_WORKSPACE_NAME]: {
|
|
105
|
+
...rawLocalConfig,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
const rules = { ...defaultRules, ...rawLocalConfig.rules };
|
|
109
|
+
const include = rawLocalConfig.include ?? defaultConfig.include;
|
|
110
|
+
const exclude = rawLocalConfig.exclude ?? defaultConfig.exclude;
|
|
111
|
+
const ignore = arrayify(rawLocalConfig.ignore ?? defaultConfig.ignore);
|
|
112
|
+
const ignoreBinaries = rawLocalConfig.ignoreBinaries ?? [];
|
|
113
|
+
const ignoreExportsUsedInFile = rawLocalConfig.ignoreExportsUsedInFile ?? false;
|
|
114
|
+
const ignoreDependencies = rawLocalConfig.ignoreDependencies ?? [];
|
|
115
|
+
const ignoreWorkspaces = rawLocalConfig.ignoreWorkspaces ?? defaultConfig.ignoreWorkspaces;
|
|
116
|
+
const { syncCompilers, asyncCompilers } = rawLocalConfig;
|
|
117
|
+
const extensions = [...Object.keys(syncCompilers ?? {}), ...Object.keys(asyncCompilers ?? {})];
|
|
118
|
+
const defaultWorkspaceConfig = getDefaultWorkspaceConfig(extensions);
|
|
119
|
+
const workspaces = Object.entries(initialWorkspaces)
|
|
120
|
+
.filter(([workspaceName]) => !ignoreWorkspaces.includes(workspaceName))
|
|
121
|
+
.reduce((workspaces, workspace) => {
|
|
122
|
+
const [workspaceName, workspaceConfig] = workspace;
|
|
123
|
+
const entry = workspaceConfig.entry ? arrayify(workspaceConfig.entry) : defaultWorkspaceConfig.entry;
|
|
124
|
+
const project = workspaceConfig.project ? arrayify(workspaceConfig.project) : defaultWorkspaceConfig.project;
|
|
125
|
+
const paths = workspaceConfig.paths ?? defaultWorkspaceConfig.paths;
|
|
126
|
+
workspaces[workspaceName] = {
|
|
127
|
+
entry,
|
|
128
|
+
project,
|
|
129
|
+
paths,
|
|
130
|
+
ignore: arrayify(workspaceConfig.ignore),
|
|
131
|
+
ignoreBinaries: arrayify(workspaceConfig.ignoreBinaries),
|
|
132
|
+
ignoreDependencies: arrayify(workspaceConfig.ignoreDependencies),
|
|
133
|
+
};
|
|
134
|
+
for (const [name, pluginConfig] of Object.entries(workspaceConfig)) {
|
|
135
|
+
const pluginName = toCamelCase(name);
|
|
136
|
+
if (PLUGIN_NAMES.includes(pluginName)) {
|
|
137
|
+
if (pluginConfig === false) {
|
|
138
|
+
workspaces[workspaceName][pluginName] = false;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const isObject = typeof pluginConfig !== 'string' && !Array.isArray(pluginConfig);
|
|
142
|
+
const config = isObject ? arrayify(pluginConfig.config) : pluginConfig ? arrayify(pluginConfig) : null;
|
|
143
|
+
const entry = isObject && 'entry' in pluginConfig ? arrayify(pluginConfig.entry) : null;
|
|
144
|
+
const project = isObject && 'project' in pluginConfig ? arrayify(pluginConfig.project) : entry;
|
|
145
|
+
workspaces[workspaceName][pluginName] = {
|
|
146
|
+
config,
|
|
147
|
+
entry,
|
|
148
|
+
project,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return workspaces;
|
|
154
|
+
}, {});
|
|
155
|
+
return {
|
|
156
|
+
rules,
|
|
157
|
+
include,
|
|
158
|
+
exclude,
|
|
159
|
+
ignore,
|
|
160
|
+
ignoreBinaries,
|
|
161
|
+
ignoreDependencies,
|
|
162
|
+
ignoreExportsUsedInFile,
|
|
163
|
+
ignoreWorkspaces,
|
|
164
|
+
syncCompilers: new Map(Object.entries(syncCompilers ?? {})),
|
|
165
|
+
asyncCompilers: new Map(Object.entries(asyncCompilers ?? {})),
|
|
166
|
+
workspaces,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async setWorkspaces() {
|
|
170
|
+
this.ignoredWorkspacePatterns = this.getIgnoredWorkspacePatterns();
|
|
171
|
+
this.manifestWorkspaces = await this.getManifestWorkspaces();
|
|
172
|
+
this.additionalWorkspaceNames = await this.getAdditionalWorkspaceNames();
|
|
173
|
+
this.availableWorkspaceNames = this.getAvailableWorkspaceNames();
|
|
174
|
+
this.availableWorkspaceDirs = this.availableWorkspaceNames
|
|
175
|
+
.sort(byPathDepth)
|
|
176
|
+
.reverse()
|
|
177
|
+
.map(dir => join(this.cwd, dir));
|
|
178
|
+
this.enabledWorkspaces = this.getEnabledWorkspaces();
|
|
179
|
+
this.localWorkspaces = new Set(compact(this.enabledWorkspaces.map(w => w.pkgName)));
|
|
180
|
+
}
|
|
181
|
+
getListedWorkspaces() {
|
|
182
|
+
return this.manifest?.workspaces
|
|
183
|
+
? Array.isArray(this.manifest.workspaces)
|
|
184
|
+
? this.manifest.workspaces
|
|
185
|
+
: this.manifest.workspaces.packages ?? []
|
|
186
|
+
: [];
|
|
187
|
+
}
|
|
188
|
+
getIgnoredWorkspacePatterns() {
|
|
189
|
+
const ignoredWorkspaces = this.getListedWorkspaces()
|
|
190
|
+
.filter(name => name.startsWith('!'))
|
|
191
|
+
.map(name => name.replace(/^!/, ''));
|
|
192
|
+
return [...ignoredWorkspaces, ...this.config.ignoreWorkspaces];
|
|
193
|
+
}
|
|
194
|
+
async getManifestWorkspaces() {
|
|
195
|
+
const workspaces = await mapWorkspaces({
|
|
196
|
+
pkg: this.manifest ?? {},
|
|
197
|
+
cwd: this.cwd,
|
|
198
|
+
});
|
|
199
|
+
const manifestWorkspaces = new Map();
|
|
200
|
+
for (const [pkgName, dir] of workspaces.entries()) {
|
|
201
|
+
manifestWorkspaces.set(relative(this.cwd, dir), pkgName);
|
|
202
|
+
}
|
|
203
|
+
return manifestWorkspaces;
|
|
204
|
+
}
|
|
205
|
+
async getAdditionalWorkspaceNames() {
|
|
206
|
+
const additionalWorkspaceKeys = Object.keys(this.config.workspaces);
|
|
207
|
+
const patterns = additionalWorkspaceKeys.filter(key => key.includes('*'));
|
|
208
|
+
const dirs = additionalWorkspaceKeys.filter(key => !key.includes('*'));
|
|
209
|
+
const globbedDirs = await _dirGlob({ patterns, cwd: this.cwd });
|
|
210
|
+
return new Set([...dirs, ...globbedDirs].filter(name => name !== ROOT_WORKSPACE_NAME &&
|
|
211
|
+
!this.manifestWorkspaces.has(name) &&
|
|
212
|
+
!micromatch.isMatch(name, this.ignoredWorkspacePatterns)));
|
|
213
|
+
}
|
|
214
|
+
getAvailableWorkspaceNames() {
|
|
215
|
+
return [ROOT_WORKSPACE_NAME, ...this.manifestWorkspaces.keys(), ...this.additionalWorkspaceNames].filter(name => !micromatch.isMatch(name, this.ignoredWorkspacePatterns));
|
|
216
|
+
}
|
|
217
|
+
getEnabledWorkspaces() {
|
|
218
|
+
if (workspaceArg && !existsSync(workspaceArg)) {
|
|
219
|
+
throw new ConfigurationError(`Directory does not exist: ${workspaceArg}`);
|
|
220
|
+
}
|
|
221
|
+
const getAncestors = (name) => (ancestors, ancestorName) => {
|
|
222
|
+
if (name === ancestorName)
|
|
223
|
+
return ancestors;
|
|
224
|
+
if (ancestorName === ROOT_WORKSPACE_NAME || name.startsWith(ancestorName + '/'))
|
|
225
|
+
ancestors.push(ancestorName);
|
|
226
|
+
return ancestors;
|
|
227
|
+
};
|
|
228
|
+
const workspaceNames = workspaceArg
|
|
229
|
+
? [
|
|
230
|
+
...this.availableWorkspaceNames.reduce(getAncestors(workspaceArg), []),
|
|
231
|
+
...this.availableWorkspaceNames.filter(name => name === workspaceArg),
|
|
232
|
+
]
|
|
233
|
+
: this.availableWorkspaceNames;
|
|
234
|
+
return workspaceNames.sort(byPathDepth).map((name) => ({
|
|
235
|
+
name,
|
|
236
|
+
pkgName: this.manifestWorkspaces.get(name) ?? this.manifest?.name,
|
|
237
|
+
dir: join(this.cwd, name),
|
|
238
|
+
config: this.getConfigForWorkspace(name),
|
|
239
|
+
ancestors: this.availableWorkspaceNames.reduce(getAncestors(name), []),
|
|
240
|
+
}));
|
|
241
|
+
}
|
|
242
|
+
getWorkspaces() {
|
|
243
|
+
return this.enabledWorkspaces;
|
|
244
|
+
}
|
|
245
|
+
getDescendentWorkspaces(name) {
|
|
246
|
+
return this.availableWorkspaceNames
|
|
247
|
+
.filter(workspaceName => workspaceName !== name)
|
|
248
|
+
.filter(workspaceName => name === ROOT_WORKSPACE_NAME || workspaceName.startsWith(name + '/'));
|
|
249
|
+
}
|
|
250
|
+
getIgnoredWorkspacesFor(name) {
|
|
251
|
+
return this.ignoredWorkspacePatterns
|
|
252
|
+
.filter(workspaceName => workspaceName !== name)
|
|
253
|
+
.filter(workspaceName => name === ROOT_WORKSPACE_NAME || workspaceName.startsWith(name));
|
|
254
|
+
}
|
|
255
|
+
getNegatedWorkspacePatterns(name) {
|
|
256
|
+
const descendentWorkspaces = this.getDescendentWorkspaces(name);
|
|
257
|
+
const matchName = new RegExp(`^${name}/`);
|
|
258
|
+
const ignoredWorkspaces = this.getIgnoredWorkspacesFor(name);
|
|
259
|
+
return [...ignoredWorkspaces, ...descendentWorkspaces]
|
|
260
|
+
.map(workspaceName => workspaceName.replace(matchName, ''))
|
|
261
|
+
.map(workspaceName => `!${workspaceName}`);
|
|
262
|
+
}
|
|
263
|
+
getConfigKeyForWorkspace(workspaceName) {
|
|
264
|
+
return Object.keys(this.config.workspaces)
|
|
265
|
+
.sort(byPathDepth)
|
|
266
|
+
.reverse()
|
|
267
|
+
.find(pattern => micromatch.isMatch(workspaceName, pattern));
|
|
268
|
+
}
|
|
269
|
+
getConfigForWorkspace(workspaceName) {
|
|
270
|
+
const key = this.getConfigKeyForWorkspace(workspaceName);
|
|
271
|
+
if (key && this.config?.workspaces?.[key])
|
|
272
|
+
return this.config.workspaces[key];
|
|
273
|
+
return getDefaultWorkspaceConfig();
|
|
274
|
+
}
|
|
275
|
+
getIssueTypesToReport() {
|
|
276
|
+
const cliArgs = { include, exclude, dependencies, exports };
|
|
277
|
+
const excludesFromRules = getKeysByValue(this.config.rules, 'off');
|
|
278
|
+
const config = {
|
|
279
|
+
include: this.config.include ?? [],
|
|
280
|
+
exclude: [...excludesFromRules, ...this.config.exclude],
|
|
281
|
+
isProduction: this.isProduction,
|
|
282
|
+
};
|
|
283
|
+
return getIncludedIssueTypes(cliArgs, config);
|
|
284
|
+
}
|
|
285
|
+
findWorkspaceByFilePath(filePath) {
|
|
286
|
+
const workspaceDir = this.availableWorkspaceDirs.find(workspaceDir => filePath.startsWith(workspaceDir + '/'));
|
|
287
|
+
return this.enabledWorkspaces.find(workspace => workspace.dir === workspaceDir);
|
|
288
|
+
}
|
|
289
|
+
findWorkspaceByPackageName(packageName) {
|
|
290
|
+
return this.enabledWorkspaces.find(workspace => workspace.pkgName === packageName);
|
|
291
|
+
}
|
|
292
|
+
getUnusedIgnoredWorkspaces() {
|
|
293
|
+
const ignoredWorkspaceNames = this.config.ignoreWorkspaces;
|
|
294
|
+
const workspaceNames = [...this.manifestWorkspaces.keys(), ...this.additionalWorkspaceNames];
|
|
295
|
+
return ignoredWorkspaceNames.filter(ignoredWorkspaceName => !workspaceNames.some(name => micromatch.isMatch(name, ignoredWorkspaceName)));
|
|
296
|
+
}
|
|
297
|
+
}
|