knip 5.63.0 → 5.63.1
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/dist/CacheConsultant.d.ts +3 -9
- package/dist/CacheConsultant.js +5 -5
- package/dist/ConfigurationChief.d.ts +585 -38
- package/dist/ConfigurationChief.js +33 -122
- package/dist/ConsoleStreamer.d.ts +2 -3
- package/dist/ConsoleStreamer.js +2 -2
- package/dist/DependencyDeputy.d.ts +2 -6
- package/dist/IssueCollector.d.ts +4 -12
- package/dist/IssueCollector.js +9 -9
- package/dist/IssueFixer.d.ts +3 -14
- package/dist/IssueFixer.js +11 -21
- package/dist/PrincipalFactory.d.ts +3 -2
- package/dist/PrincipalFactory.js +11 -11
- package/dist/ProjectPrincipal.d.ts +4 -3
- package/dist/ProjectPrincipal.js +8 -8
- package/dist/WorkspaceWorker.d.ts +4 -9
- package/dist/WorkspaceWorker.js +8 -12
- package/dist/binaries/bash-parser.js +1 -1
- package/dist/binaries/fallback.js +1 -1
- package/dist/binaries/package-manager/pnpm.js +6 -1
- package/dist/cli.js +43 -61
- package/dist/compilers/index.d.ts +14 -4
- package/dist/graph/analyze.d.ts +3 -8
- package/dist/graph/analyze.js +24 -27
- package/dist/graph/build.d.ts +3 -17
- package/dist/graph/build.js +42 -39
- package/dist/index.d.ts +3 -7
- package/dist/index.js +22 -62
- package/dist/plugins/index.d.ts +5 -0
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/nuxt/index.js +4 -3
- package/dist/plugins/nuxt/types.d.ts +3 -2
- package/dist/plugins/pnpm/index.d.ts +7 -0
- package/dist/plugins/pnpm/index.js +8 -0
- package/dist/plugins/rsbuild/index.js +23 -6
- package/dist/plugins/rsbuild/types.d.ts +3 -0
- package/dist/plugins.js +3 -2
- package/dist/reporters/codeclimate.d.ts +1 -1
- package/dist/reporters/codeclimate.js +10 -10
- package/dist/reporters/codeowners.d.ts +1 -1
- package/dist/reporters/codeowners.js +5 -5
- package/dist/reporters/compact.d.ts +1 -1
- package/dist/reporters/compact.js +7 -7
- package/dist/reporters/disclosure.d.ts +1 -1
- package/dist/reporters/disclosure.js +2 -2
- package/dist/reporters/index.d.ts +6 -6
- package/dist/reporters/json.d.ts +1 -1
- package/dist/reporters/json.js +3 -3
- package/dist/reporters/markdown.d.ts +1 -1
- package/dist/reporters/markdown.js +4 -4
- package/dist/reporters/symbols.js +1 -1
- package/dist/reporters/util/configuration-hints.d.ts +1 -1
- package/dist/reporters/util/configuration-hints.js +6 -7
- package/dist/reporters/util/util.d.ts +2 -2
- package/dist/reporters/util/util.js +4 -4
- package/dist/reporters/watch.d.ts +3 -4
- package/dist/reporters/watch.js +5 -5
- package/dist/schema/configuration.d.ts +64 -8
- package/dist/schema/plugins.d.ts +23 -0
- package/dist/schema/plugins.js +1 -0
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +1 -0
- package/dist/types/config.d.ts +4 -10
- package/dist/types/issues.d.ts +1 -2
- package/dist/types/{cli.d.ts → options.d.ts} +2 -2
- package/dist/types/package-json.d.ts +1 -0
- package/dist/types/project.d.ts +1 -7
- package/dist/typescript/get-imports-and-exports.d.ts +2 -2
- package/dist/typescript/get-imports-and-exports.js +9 -10
- package/dist/util/Performance.js +16 -6
- package/dist/util/cli-arguments.d.ts +1 -2
- package/dist/util/cli-arguments.js +3 -13
- package/dist/util/create-options.d.ts +1219 -0
- package/dist/util/create-options.js +112 -0
- package/dist/util/debug.js +3 -4
- package/dist/util/errors.d.ts +1 -1
- package/dist/util/file-entry-cache.js +3 -3
- package/dist/util/get-included-issue-types.d.ts +9 -13
- package/dist/util/get-included-issue-types.js +10 -16
- package/dist/util/get-referenced-inputs.js +1 -1
- package/dist/util/input.d.ts +1 -1
- package/dist/util/input.js +1 -1
- package/dist/util/is-identifier-referenced.d.ts +1 -1
- package/dist/util/is-identifier-referenced.js +2 -2
- package/dist/util/load-config.d.ts +1 -0
- package/dist/util/load-config.js +24 -0
- package/dist/util/path.d.ts +4 -4
- package/dist/util/path.js +5 -7
- package/dist/util/require.js +1 -2
- package/dist/util/tag.d.ts +1 -1
- package/dist/util/to-source-path.d.ts +1 -1
- package/dist/util/to-source-path.js +5 -5
- package/dist/util/trace.d.ts +6 -6
- package/dist/util/trace.js +18 -22
- package/dist/util/watch.d.ts +2 -5
- package/dist/util/watch.js +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/schema.json +4 -0
- package/dist/util/unwrap-function.d.ts +0 -1
- package/dist/util/unwrap-function.js +0 -13
- /package/dist/types/{cli.js → options.js} +0 -0
package/dist/ProjectPrincipal.js
CHANGED
|
@@ -43,8 +43,7 @@ export class ProjectPrincipal {
|
|
|
43
43
|
backend;
|
|
44
44
|
findReferences;
|
|
45
45
|
getImplementationAtPosition;
|
|
46
|
-
constructor({ compilerOptions,
|
|
47
|
-
this.cwd = cwd;
|
|
46
|
+
constructor(options, { compilerOptions, compilers, pkgName, toSourceFilePath }) {
|
|
48
47
|
this.compilerOptions = {
|
|
49
48
|
...compilerOptions,
|
|
50
49
|
...baseCompilerOptions,
|
|
@@ -55,12 +54,13 @@ export class ProjectPrincipal {
|
|
|
55
54
|
this.extensions = new Set([...DEFAULT_EXTENSIONS, ...getCompilerExtensions(compilers)]);
|
|
56
55
|
this.syncCompilers = syncCompilers;
|
|
57
56
|
this.asyncCompilers = asyncCompilers;
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
57
|
+
this.cwd = options.cwd;
|
|
58
|
+
this.isSkipLibs = options.isSkipLibs;
|
|
59
|
+
this.isWatch = options.isWatch;
|
|
60
|
+
this.cache = new CacheConsultant(pkgName || ANONYMOUS, options);
|
|
61
61
|
this.toSourceFilePath = toSourceFilePath;
|
|
62
62
|
this.backend = {
|
|
63
|
-
fileManager: new SourceFileManager({ compilers, isSkipLibs }),
|
|
63
|
+
fileManager: new SourceFileManager({ compilers, isSkipLibs: options.isSkipLibs }),
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
init() {
|
|
@@ -156,7 +156,7 @@ export class ProjectPrincipal {
|
|
|
156
156
|
const sourceFiles = this.getProgramSourceFiles();
|
|
157
157
|
return Array.from(this.projectPaths).filter(filePath => !sourceFiles.has(filePath));
|
|
158
158
|
}
|
|
159
|
-
analyzeSourceFile(filePath, options) {
|
|
159
|
+
analyzeSourceFile(filePath, options, ignoreExportsUsedInFile) {
|
|
160
160
|
const fd = this.cache.getFileDescriptor(filePath);
|
|
161
161
|
if (!fd.changed && fd.meta?.data)
|
|
162
162
|
return fd.meta.data;
|
|
@@ -168,7 +168,7 @@ export class ProjectPrincipal {
|
|
|
168
168
|
throw new Error(`Unable to find ${filePath}`);
|
|
169
169
|
const skipExports = this.skipExportsAnalysis.has(filePath);
|
|
170
170
|
const resolve = (specifier) => this.backend.resolveModuleNames([specifier], sourceFile.fileName)[0];
|
|
171
|
-
return _getImportsAndExports(sourceFile, resolve, typeChecker,
|
|
171
|
+
return _getImportsAndExports(sourceFile, resolve, typeChecker, options, ignoreExportsUsedInFile, skipExports);
|
|
172
172
|
}
|
|
173
173
|
invalidateFile(filePath) {
|
|
174
174
|
this.backend.fileManager.snapshotCache.delete(filePath);
|
|
@@ -5,11 +5,11 @@ import type { Configuration, GetReferencedInternalFilePath, GetSourceFile, Works
|
|
|
5
5
|
import type { ConfigurationHints } from './types/issues.js';
|
|
6
6
|
import type { PackageJson } from './types/package-json.js';
|
|
7
7
|
import type { DependencySet } from './types/workspace.js';
|
|
8
|
+
import type { MainOptions } from './util/create-options.js';
|
|
8
9
|
import { type Input } from './util/input.js';
|
|
9
10
|
type WorkspaceManagerOptions = {
|
|
10
11
|
name: string;
|
|
11
12
|
dir: string;
|
|
12
|
-
cwd: string;
|
|
13
13
|
config: WorkspaceConfiguration;
|
|
14
14
|
manifest: PackageJson;
|
|
15
15
|
dependencies: DependencySet;
|
|
@@ -20,11 +20,8 @@ type WorkspaceManagerOptions = {
|
|
|
20
20
|
negatedWorkspacePatterns: string[];
|
|
21
21
|
ignoredWorkspacePatterns: string[];
|
|
22
22
|
enabledPluginsInAncestors: string[];
|
|
23
|
-
isProduction: boolean;
|
|
24
|
-
isStrict: boolean;
|
|
25
|
-
isCache: boolean;
|
|
26
|
-
cacheLocation: string;
|
|
27
23
|
configFilesMap: Map<string, Map<PluginName, Set<string>>>;
|
|
24
|
+
options: MainOptions;
|
|
28
25
|
};
|
|
29
26
|
type CacheItem = {
|
|
30
27
|
resolveConfig?: Input[];
|
|
@@ -34,24 +31,22 @@ type CacheItem = {
|
|
|
34
31
|
export declare class WorkspaceWorker {
|
|
35
32
|
name: string;
|
|
36
33
|
dir: string;
|
|
37
|
-
cwd: string;
|
|
38
34
|
config: WorkspaceConfiguration;
|
|
39
35
|
manifest: PackageJson;
|
|
40
36
|
dependencies: DependencySet;
|
|
41
37
|
getReferencedInternalFilePath: GetReferencedInternalFilePath;
|
|
42
38
|
findWorkspaceByFilePath: (filePath: string) => Workspace | undefined;
|
|
43
39
|
getSourceFile: GetSourceFile;
|
|
44
|
-
isProduction: boolean;
|
|
45
|
-
isStrict: boolean;
|
|
46
40
|
rootIgnore: Configuration['ignore'];
|
|
47
41
|
negatedWorkspacePatterns: string[];
|
|
48
42
|
ignoredWorkspacePatterns: string[];
|
|
43
|
+
options: MainOptions;
|
|
49
44
|
enabledPluginsMap: Record<PluginName, boolean>;
|
|
50
45
|
enabledPlugins: PluginName[];
|
|
51
46
|
enabledPluginsInAncestors: string[];
|
|
52
47
|
cache: CacheConsultant<CacheItem>;
|
|
53
48
|
configFilesMap: Map<string, Map<PluginName, Set<string>>>;
|
|
54
|
-
constructor({ name, dir,
|
|
49
|
+
constructor({ name, dir, config, manifest, dependencies, rootIgnore, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, getReferencedInternalFilePath, findWorkspaceByFilePath, getSourceFile, configFilesMap, options, }: WorkspaceManagerOptions);
|
|
55
50
|
init(): Promise<void>;
|
|
56
51
|
private determineEnabledPlugins;
|
|
57
52
|
private getConfigForPlugin;
|
package/dist/WorkspaceWorker.js
CHANGED
|
@@ -19,32 +19,27 @@ const initEnabledPluginsMap = () => Object.keys(Plugins).reduce((enabled, plugin
|
|
|
19
19
|
export class WorkspaceWorker {
|
|
20
20
|
name;
|
|
21
21
|
dir;
|
|
22
|
-
cwd;
|
|
23
22
|
config;
|
|
24
23
|
manifest;
|
|
25
24
|
dependencies;
|
|
26
25
|
getReferencedInternalFilePath;
|
|
27
26
|
findWorkspaceByFilePath;
|
|
28
27
|
getSourceFile;
|
|
29
|
-
isProduction;
|
|
30
|
-
isStrict;
|
|
31
28
|
rootIgnore;
|
|
32
29
|
negatedWorkspacePatterns = [];
|
|
33
30
|
ignoredWorkspacePatterns = [];
|
|
31
|
+
options;
|
|
34
32
|
enabledPluginsMap = initEnabledPluginsMap();
|
|
35
33
|
enabledPlugins = [];
|
|
36
34
|
enabledPluginsInAncestors;
|
|
37
35
|
cache;
|
|
38
36
|
configFilesMap;
|
|
39
|
-
constructor({ name, dir,
|
|
37
|
+
constructor({ name, dir, config, manifest, dependencies, rootIgnore, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, getReferencedInternalFilePath, findWorkspaceByFilePath, getSourceFile, configFilesMap, options, }) {
|
|
40
38
|
this.name = name;
|
|
41
39
|
this.dir = dir;
|
|
42
|
-
this.cwd = cwd;
|
|
43
40
|
this.config = config;
|
|
44
41
|
this.manifest = manifest;
|
|
45
42
|
this.dependencies = dependencies;
|
|
46
|
-
this.isProduction = isProduction;
|
|
47
|
-
this.isStrict = isStrict;
|
|
48
43
|
this.rootIgnore = rootIgnore;
|
|
49
44
|
this.negatedWorkspacePatterns = negatedWorkspacePatterns;
|
|
50
45
|
this.ignoredWorkspacePatterns = ignoredWorkspacePatterns;
|
|
@@ -53,7 +48,8 @@ export class WorkspaceWorker {
|
|
|
53
48
|
this.getReferencedInternalFilePath = getReferencedInternalFilePath;
|
|
54
49
|
this.findWorkspaceByFilePath = findWorkspaceByFilePath;
|
|
55
50
|
this.getSourceFile = getSourceFile;
|
|
56
|
-
this.
|
|
51
|
+
this.options = options;
|
|
52
|
+
this.cache = new CacheConsultant(`plugins-${name}`, options);
|
|
57
53
|
this.getConfigurationHints = timerify(this.getConfigurationHints.bind(this), 'worker.getConfigurationHints');
|
|
58
54
|
}
|
|
59
55
|
async init() {
|
|
@@ -64,7 +60,7 @@ export class WorkspaceWorker {
|
|
|
64
60
|
for (const [pluginName, plugin] of PluginEntries) {
|
|
65
61
|
if (this.config[pluginName] === false)
|
|
66
62
|
continue;
|
|
67
|
-
if (this.cwd !== this.dir && plugin.isRootOnly)
|
|
63
|
+
if (this.options.cwd !== this.dir && plugin.isRootOnly)
|
|
68
64
|
continue;
|
|
69
65
|
if (this.config[pluginName]) {
|
|
70
66
|
this.enabledPluginsMap[pluginName] = true;
|
|
@@ -169,10 +165,10 @@ export class WorkspaceWorker {
|
|
|
169
165
|
async runPlugins() {
|
|
170
166
|
const wsName = this.name;
|
|
171
167
|
const cwd = this.dir;
|
|
172
|
-
const rootCwd = this.cwd;
|
|
168
|
+
const rootCwd = this.options.cwd;
|
|
173
169
|
const manifest = this.manifest;
|
|
174
170
|
const containingFilePath = join(cwd, 'package.json');
|
|
175
|
-
const isProduction = this.isProduction;
|
|
171
|
+
const isProduction = this.options.isProduction;
|
|
176
172
|
const knownBinsOnly = false;
|
|
177
173
|
const manifestScriptNames = new Set(Object.keys(manifest.scripts ?? {}));
|
|
178
174
|
const baseOptions = { manifestScriptNames, cwd, rootCwd, containingFilePath, knownBinsOnly };
|
|
@@ -344,7 +340,7 @@ export class WorkspaceWorker {
|
|
|
344
340
|
} while (remainingPlugins.size > 0 && configFiles.size > 0);
|
|
345
341
|
}
|
|
346
342
|
}
|
|
347
|
-
debugLogArray(wsName, 'Plugin dependencies', () => compact(inputs.map(toDebugString)));
|
|
343
|
+
debugLogArray(wsName, 'Plugin dependencies', () => compact(inputs.map(input => toDebugString(input, rootCwd))));
|
|
348
344
|
return inputs;
|
|
349
345
|
}
|
|
350
346
|
getConfigurationHints(type, patterns, filePaths, includedPaths) {
|
|
@@ -88,7 +88,7 @@ export const getDependenciesFromScript = (script, options) => {
|
|
|
88
88
|
return parsed?.commands ? getDependenciesFromNodes(parsed.commands) : [];
|
|
89
89
|
}
|
|
90
90
|
catch (error) {
|
|
91
|
-
const msg = `Warning: failed to parse and ignoring script in ${relative(options.containingFilePath)} (${truncate(script, 30)})`;
|
|
91
|
+
const msg = `Warning: failed to parse and ignoring script in ${relative(options.cwd, options.containingFilePath)} (${truncate(script, 30)})`;
|
|
92
92
|
debugLogObject('*', msg, error);
|
|
93
93
|
return [];
|
|
94
94
|
}
|
|
@@ -7,7 +7,7 @@ const positionals = new Set(['babel-node', 'esbuild', 'execa', 'jiti', 'oxnode',
|
|
|
7
7
|
const positionalBinaries = new Set(['concurrently']);
|
|
8
8
|
export const resolve = (binary, args, { fromArgs }) => {
|
|
9
9
|
const parsed = parseArgs(args, { boolean: ['quiet', 'verbose'], '--': endOfCommandBinaries.includes(binary) });
|
|
10
|
-
const bin = binary.startsWith('.') ? toEntry(binary) : binary
|
|
10
|
+
const bin = binary.startsWith('.') ? toEntry(binary) : /[*:]/.test(binary) ? undefined : toBinary(binary);
|
|
11
11
|
const shiftedArgs = spawningBinaries.includes(binary) ? fromArgs(args) : [];
|
|
12
12
|
const pos = positionals.has(binary) ? [toDeferResolve(parsed._[0])] : [];
|
|
13
13
|
const newCommand = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--']) : [];
|
|
@@ -3,9 +3,12 @@ import { toBinary } from '../../util/input.js';
|
|
|
3
3
|
import { resolveDlx } from './pnpx.js';
|
|
4
4
|
const commands = [
|
|
5
5
|
'add',
|
|
6
|
+
'approve-builds',
|
|
6
7
|
'audit',
|
|
7
8
|
'bin',
|
|
8
9
|
'cache',
|
|
10
|
+
'cat-file',
|
|
11
|
+
'cat-index',
|
|
9
12
|
'config',
|
|
10
13
|
'dedupe',
|
|
11
14
|
'deploy',
|
|
@@ -13,7 +16,9 @@ const commands = [
|
|
|
13
16
|
'doctor',
|
|
14
17
|
'env',
|
|
15
18
|
'fetch',
|
|
19
|
+
'find-hash',
|
|
16
20
|
'i',
|
|
21
|
+
'ignored-builds',
|
|
17
22
|
'import',
|
|
18
23
|
'init',
|
|
19
24
|
'install-test',
|
|
@@ -25,7 +30,6 @@ const commands = [
|
|
|
25
30
|
'ln',
|
|
26
31
|
'ls',
|
|
27
32
|
'outdated',
|
|
28
|
-
'outdated',
|
|
29
33
|
'pack',
|
|
30
34
|
'patch-commit',
|
|
31
35
|
'patch-remove',
|
|
@@ -39,6 +43,7 @@ const commands = [
|
|
|
39
43
|
'rm',
|
|
40
44
|
'root',
|
|
41
45
|
'run',
|
|
46
|
+
'self-update',
|
|
42
47
|
'server',
|
|
43
48
|
'setup',
|
|
44
49
|
'start',
|
package/dist/cli.js
CHANGED
|
@@ -1,103 +1,85 @@
|
|
|
1
1
|
import { main } from './index.js';
|
|
2
2
|
import { perfObserver } from './util/Performance.js';
|
|
3
|
-
import
|
|
3
|
+
import { helpText } from './util/cli-arguments.js';
|
|
4
|
+
import parseArgs from './util/cli-arguments.js';
|
|
5
|
+
import { createOptions } from './util/create-options.js';
|
|
4
6
|
import { getKnownError, isConfigurationError, isDisplayReason, isKnownError } from './util/errors.js';
|
|
5
7
|
import { logError, logWarning } from './util/log.js';
|
|
6
|
-
import { cwd, join, toPosix } from './util/path.js';
|
|
7
8
|
import { runPreprocessors, runReporters } from './util/reporter.js';
|
|
8
9
|
import { prettyMilliseconds } from './util/string.js';
|
|
9
|
-
import { splitTags } from './util/tag.js';
|
|
10
|
-
import { isTrace } from './util/trace.js';
|
|
11
10
|
import { version } from './version.js';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
console.log(helpText);
|
|
16
|
-
process.exit(0);
|
|
11
|
+
let parsedCLIArgs = {};
|
|
12
|
+
try {
|
|
13
|
+
parsedCLIArgs = parseArgs();
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error instanceof Error) {
|
|
17
|
+
console.error(error.message);
|
|
18
|
+
console.log(`\n${helpText}`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
throw error;
|
|
21
22
|
}
|
|
22
|
-
const isShowProgress = isNoProgress === false && process.stdout.isTTY && typeof process.stdout.cursorTo === 'function';
|
|
23
|
-
const workspace = rawWorkspaceArg ? toPosix(rawWorkspaceArg).replace(/^\.\//, '').replace(/\/$/, '') : undefined;
|
|
24
23
|
const run = async () => {
|
|
25
24
|
try {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
isFilesShorthand,
|
|
38
|
-
isFix: isFix || fixTypes.length > 0,
|
|
39
|
-
isFormat,
|
|
40
|
-
isIncludeEntryExports,
|
|
41
|
-
isIncludeLibs,
|
|
42
|
-
isIsolateWorkspaces,
|
|
43
|
-
isProduction: isStrict || isProduction,
|
|
44
|
-
isRemoveFiles,
|
|
45
|
-
isShowProgress,
|
|
46
|
-
isStrict,
|
|
47
|
-
isWatch,
|
|
48
|
-
tags: tags.length > 0 ? splitTags(tags) : splitTags(experimentalTags),
|
|
49
|
-
tsConfigFile: tsConfig,
|
|
50
|
-
workspace,
|
|
51
|
-
});
|
|
52
|
-
const isDisableConfigHints = isNoConfigHints || isProduction || Boolean(workspace);
|
|
53
|
-
if (isWatch || isTrace)
|
|
25
|
+
const options = await createOptions({ parsedCLIArgs });
|
|
26
|
+
if (parsedCLIArgs.help) {
|
|
27
|
+
console.log(helpText);
|
|
28
|
+
process.exit(0);
|
|
29
|
+
}
|
|
30
|
+
if (parsedCLIArgs.version) {
|
|
31
|
+
console.log(version);
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}
|
|
34
|
+
const { issues, counters, tagHints, configurationHints, includedWorkspaceDirs } = await main(options);
|
|
35
|
+
if (options.isWatch || options.isTrace)
|
|
54
36
|
return;
|
|
55
37
|
const initialData = {
|
|
56
|
-
report,
|
|
38
|
+
report: options.includedIssueTypes,
|
|
57
39
|
issues,
|
|
58
40
|
counters,
|
|
59
41
|
tagHints,
|
|
60
42
|
configurationHints,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
43
|
+
includedWorkspaceDirs,
|
|
44
|
+
cwd: options.cwd,
|
|
45
|
+
configFilePath: options.configFilePath,
|
|
46
|
+
isDisableConfigHints: options.isDisableConfigHints,
|
|
47
|
+
isProduction: options.isProduction,
|
|
48
|
+
isShowProgress: options.isShowProgress,
|
|
49
|
+
isTreatConfigHintsAsErrors: options.isTreatConfigHintsAsErrors,
|
|
50
|
+
options: parsedCLIArgs['reporter-options'] ?? '',
|
|
51
|
+
preprocessorOptions: parsedCLIArgs['preprocessor-options'] ?? '',
|
|
70
52
|
};
|
|
71
|
-
const finalData = await runPreprocessors(preprocessor, initialData);
|
|
72
|
-
await runReporters(reporter, finalData);
|
|
53
|
+
const finalData = await runPreprocessors(parsedCLIArgs.preprocessor ?? [], initialData);
|
|
54
|
+
await runReporters(parsedCLIArgs.reporter ?? ['symbols'], finalData);
|
|
73
55
|
const totalErrorCount = Object.keys(finalData.report)
|
|
74
|
-
.filter(reportGroup => finalData.report[reportGroup] && rules[reportGroup] === 'error')
|
|
56
|
+
.filter(reportGroup => finalData.report[reportGroup] && options.rules[reportGroup] === 'error')
|
|
75
57
|
.reduce((errorCount, reportGroup) => errorCount + finalData.counters[reportGroup], 0);
|
|
76
58
|
if (perfObserver.isEnabled)
|
|
77
59
|
await perfObserver.finalize();
|
|
78
60
|
if (perfObserver.isTimerifyFunctions)
|
|
79
61
|
console.log(`\n${perfObserver.getTimerifiedFunctionsTable()}`);
|
|
80
|
-
if (perfObserver.isMemoryUsageEnabled && !
|
|
62
|
+
if (perfObserver.isMemoryUsageEnabled && !parsedCLIArgs['memory-realtime'])
|
|
81
63
|
console.log(`\n${perfObserver.getMemoryUsageTable()}`);
|
|
82
64
|
if (perfObserver.isEnabled) {
|
|
83
65
|
const duration = perfObserver.getCurrentDurationInMs();
|
|
84
66
|
console.log('\nTotal running time:', prettyMilliseconds(duration));
|
|
85
67
|
perfObserver.reset();
|
|
86
68
|
}
|
|
87
|
-
if (
|
|
69
|
+
if (parsedCLIArgs['experimental-tags'] && parsedCLIArgs['experimental-tags'].length > 0) {
|
|
88
70
|
logWarning('DEPRECATION WARNING', '--experimental-tags is deprecated, please start using --tags instead');
|
|
89
71
|
}
|
|
90
|
-
if (isIsolateWorkspaces &&
|
|
72
|
+
if (options.isIsolateWorkspaces && options.includedIssueTypes.classMembers) {
|
|
91
73
|
logWarning('WARNING', 'Class members are not tracked when using the --isolate-workspaces flag');
|
|
92
74
|
}
|
|
93
|
-
if ((!
|
|
94
|
-
(
|
|
75
|
+
if ((!parsedCLIArgs['no-exit-code'] && totalErrorCount > Number(parsedCLIArgs['max-issues'] ?? 0)) ||
|
|
76
|
+
(options.isTreatConfigHintsAsErrors && configurationHints.size > 0)) {
|
|
95
77
|
process.exit(1);
|
|
96
78
|
}
|
|
97
79
|
}
|
|
98
80
|
catch (error) {
|
|
99
81
|
process.exitCode = 2;
|
|
100
|
-
if (!
|
|
82
|
+
if (!parsedCLIArgs.debug && error instanceof Error && isKnownError(error)) {
|
|
101
83
|
const knownError = getKnownError(error);
|
|
102
84
|
logError('ERROR', knownError.message);
|
|
103
85
|
if (isDisplayReason(knownError))
|
|
@@ -4,9 +4,6 @@ import type { AsyncCompilerFn, AsyncCompilers, RawSyncCompilers, SyncCompilerFn,
|
|
|
4
4
|
export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
5
5
|
syncCompilers: Record<string, SyncCompilerFn>;
|
|
6
6
|
asyncCompilers: Record<string, AsyncCompilerFn>;
|
|
7
|
-
exclude?: ("dependencies" | "exports" | "files" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
|
|
8
|
-
tags?: string[] | undefined;
|
|
9
|
-
include?: ("dependencies" | "exports" | "files" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
|
|
10
7
|
node?: string | boolean | string[] | {
|
|
11
8
|
config?: string | string[] | undefined;
|
|
12
9
|
entry?: string | string[] | undefined;
|
|
@@ -324,6 +321,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
324
321
|
entry?: string | string[] | undefined;
|
|
325
322
|
project?: string | string[] | undefined;
|
|
326
323
|
} | undefined;
|
|
324
|
+
pnpm?: string | boolean | string[] | {
|
|
325
|
+
config?: string | string[] | undefined;
|
|
326
|
+
entry?: string | string[] | undefined;
|
|
327
|
+
project?: string | string[] | undefined;
|
|
328
|
+
} | undefined;
|
|
327
329
|
postcss?: string | boolean | string[] | {
|
|
328
330
|
config?: string | string[] | undefined;
|
|
329
331
|
entry?: string | string[] | undefined;
|
|
@@ -564,8 +566,9 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
564
566
|
entry?: string | string[] | undefined;
|
|
565
567
|
project?: string | string[] | undefined;
|
|
566
568
|
} | undefined;
|
|
569
|
+
exclude?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
|
|
567
570
|
$schema?: string | undefined;
|
|
568
|
-
rules?: Partial<Record<"
|
|
571
|
+
rules?: Partial<Record<"files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers", "error" | "warn" | "off">> | undefined;
|
|
569
572
|
paths?: Record<string, string[]> | undefined;
|
|
570
573
|
ignore?: string | string[] | undefined;
|
|
571
574
|
ignoreBinaries?: (string | RegExp)[] | undefined;
|
|
@@ -576,7 +579,9 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
576
579
|
ignoreWorkspaces?: string[] | undefined;
|
|
577
580
|
includeEntryExports?: boolean | undefined;
|
|
578
581
|
compilers?: Record<string, true | ((args_0: string, args_1: string, ...args: unknown[]) => string) | ((args_0: string, args_1: string, ...args: unknown[]) => Promise<string>)> | undefined;
|
|
582
|
+
tags?: string[] | undefined;
|
|
579
583
|
treatConfigHintsAsErrors?: boolean | undefined;
|
|
584
|
+
include?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
|
|
580
585
|
workspaces?: Record<string, {
|
|
581
586
|
node?: string | boolean | string[] | {
|
|
582
587
|
config?: string | string[] | undefined;
|
|
@@ -895,6 +900,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
895
900
|
entry?: string | string[] | undefined;
|
|
896
901
|
project?: string | string[] | undefined;
|
|
897
902
|
} | undefined;
|
|
903
|
+
pnpm?: string | boolean | string[] | {
|
|
904
|
+
config?: string | string[] | undefined;
|
|
905
|
+
entry?: string | string[] | undefined;
|
|
906
|
+
project?: string | string[] | undefined;
|
|
907
|
+
} | undefined;
|
|
898
908
|
postcss?: string | boolean | string[] | {
|
|
899
909
|
config?: string | string[] | undefined;
|
|
900
910
|
entry?: string | string[] | undefined;
|
package/dist/graph/analyze.d.ts
CHANGED
|
@@ -4,9 +4,8 @@ import type { DependencyDeputy } from '../DependencyDeputy.js';
|
|
|
4
4
|
import type { IssueCollector } from '../IssueCollector.js';
|
|
5
5
|
import type { IssueFixer } from '../IssueFixer.js';
|
|
6
6
|
import type { PrincipalFactory } from '../PrincipalFactory.js';
|
|
7
|
-
import type { Tags } from '../types/cli.js';
|
|
8
|
-
import type { Report } from '../types/issues.js';
|
|
9
7
|
import type { ModuleGraph } from '../types/module-graph.js';
|
|
8
|
+
import type { MainOptions } from '../util/create-options.js';
|
|
10
9
|
interface AnalyzeOptions {
|
|
11
10
|
analyzedFiles: Set<string>;
|
|
12
11
|
chief: ConfigurationChief;
|
|
@@ -16,13 +15,9 @@ interface AnalyzeOptions {
|
|
|
16
15
|
factory: PrincipalFactory;
|
|
17
16
|
fixer: IssueFixer;
|
|
18
17
|
graph: ModuleGraph;
|
|
19
|
-
isFix: boolean;
|
|
20
|
-
isIncludeLibs: boolean;
|
|
21
|
-
isProduction: boolean;
|
|
22
|
-
report: Report;
|
|
23
18
|
streamer: ConsoleStreamer;
|
|
24
|
-
tags: Tags;
|
|
25
19
|
unreferencedFiles: Set<string>;
|
|
20
|
+
options: MainOptions;
|
|
26
21
|
}
|
|
27
|
-
export declare const analyze: (options: AnalyzeOptions) => Promise<() => Promise<void>>;
|
|
22
|
+
export declare const analyze: ({ analyzedFiles, chief, collector, deputy, entryPaths, factory, fixer, graph, streamer, unreferencedFiles, options, }: AnalyzeOptions) => Promise<() => Promise<void>>;
|
|
28
23
|
export {};
|
package/dist/graph/analyze.js
CHANGED
|
@@ -4,16 +4,10 @@ import { getPackageNameFromModuleSpecifier } from '../util/modules.js';
|
|
|
4
4
|
import { findMatch } from '../util/regex.js';
|
|
5
5
|
import { getShouldIgnoreHandler, getShouldIgnoreTagHandler } from '../util/tag.js';
|
|
6
6
|
import { createAndPrintTrace, printTrace } from '../util/trace.js';
|
|
7
|
-
export const analyze = async (options) => {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const isReportTypes = report.types || report.nsTypes || report.enumMembers;
|
|
12
|
-
const isReportClassMembers = report.classMembers;
|
|
13
|
-
const isSkipLibs = !(isIncludeLibs || isReportClassMembers);
|
|
14
|
-
const shouldIgnore = getShouldIgnoreHandler(isProduction);
|
|
15
|
-
const shouldIgnoreTags = getShouldIgnoreTagHandler(tags);
|
|
16
|
-
const isIdentifierReferenced = getIsIdentifierReferencedHandler(graph, entryPaths);
|
|
7
|
+
export const analyze = async ({ analyzedFiles, chief, collector, deputy, entryPaths, factory, fixer, graph, streamer, unreferencedFiles, options, }) => {
|
|
8
|
+
const shouldIgnore = getShouldIgnoreHandler(options.isProduction);
|
|
9
|
+
const shouldIgnoreTags = getShouldIgnoreTagHandler(options.tags);
|
|
10
|
+
const isIdentifierReferenced = getIsIdentifierReferencedHandler(graph, entryPaths, options.isTrace);
|
|
17
11
|
const ignoreExportsUsedInFile = chief.config.ignoreExportsUsedInFile;
|
|
18
12
|
const isExportedItemReferenced = (exportedItem) => exportedItem.refs[1] ||
|
|
19
13
|
(exportedItem.refs[0] > 0 &&
|
|
@@ -21,7 +15,7 @@ export const analyze = async (options) => {
|
|
|
21
15
|
? exportedItem.type !== 'unknown' && !!ignoreExportsUsedInFile[exportedItem.type]
|
|
22
16
|
: ignoreExportsUsedInFile));
|
|
23
17
|
const analyzeGraph = async () => {
|
|
24
|
-
if (isReportValues || isReportTypes) {
|
|
18
|
+
if (options.isReportValues || options.isReportTypes) {
|
|
25
19
|
streamer.cast('Connecting the dots');
|
|
26
20
|
for (const [filePath, file] of graph.entries()) {
|
|
27
21
|
const exportItems = file.exports;
|
|
@@ -33,7 +27,7 @@ export const analyze = async (options) => {
|
|
|
33
27
|
const principal = factory.getPrincipalByPackageName(workspace.pkgName);
|
|
34
28
|
const isEntry = entryPaths.has(filePath);
|
|
35
29
|
if (!isIncludeEntryExports && isEntry) {
|
|
36
|
-
createAndPrintTrace(filePath, { isEntry });
|
|
30
|
+
createAndPrintTrace(filePath, options, { isEntry });
|
|
37
31
|
continue;
|
|
38
32
|
}
|
|
39
33
|
const importsForExport = file.imported;
|
|
@@ -45,7 +39,7 @@ export const analyze = async (options) => {
|
|
|
45
39
|
const { isReferenced, reExportingEntryFile, traceNode } = isIdentifierReferenced(filePath, identifier, isIncludeEntryExports);
|
|
46
40
|
if ((isReferenced || exportedItem.refs[1]) && isIgnored) {
|
|
47
41
|
for (const tagName of exportedItem.jsDocTags) {
|
|
48
|
-
if (tags[1].includes(tagName.replace(/^@/, ''))) {
|
|
42
|
+
if (options.tags[1].includes(tagName.replace(/^@/, ''))) {
|
|
49
43
|
collector.addTagHint({ type: 'tag', filePath, identifier, tagName });
|
|
50
44
|
}
|
|
51
45
|
}
|
|
@@ -54,7 +48,7 @@ export const analyze = async (options) => {
|
|
|
54
48
|
continue;
|
|
55
49
|
if (reExportingEntryFile) {
|
|
56
50
|
if (!isIncludeEntryExports) {
|
|
57
|
-
createAndPrintTrace(filePath, { identifier, isEntry, hasRef: isReferenced });
|
|
51
|
+
createAndPrintTrace(filePath, options, { identifier, isEntry, hasRef: isReferenced });
|
|
58
52
|
continue;
|
|
59
53
|
}
|
|
60
54
|
const reExportedItem = graph.get(reExportingEntryFile)?.exports.get(identifier);
|
|
@@ -62,10 +56,10 @@ export const analyze = async (options) => {
|
|
|
62
56
|
continue;
|
|
63
57
|
}
|
|
64
58
|
if (traceNode)
|
|
65
|
-
printTrace(traceNode, filePath, identifier);
|
|
59
|
+
printTrace(traceNode, filePath, options, identifier);
|
|
66
60
|
if (isReferenced) {
|
|
67
|
-
if (
|
|
68
|
-
if (!
|
|
61
|
+
if (options.includedIssueTypes.enumMembers && exportedItem.type === 'enum') {
|
|
62
|
+
if (!options.includedIssueTypes.nsTypes && importsForExport.refs.has(identifier))
|
|
69
63
|
continue;
|
|
70
64
|
if (hasStrictlyEnumReferences(importsForExport, identifier))
|
|
71
65
|
continue;
|
|
@@ -91,12 +85,12 @@ export const analyze = async (options) => {
|
|
|
91
85
|
line: member.line,
|
|
92
86
|
col: member.col,
|
|
93
87
|
});
|
|
94
|
-
if (isFix && isIssueAdded && member.fix)
|
|
88
|
+
if (options.isFix && isIssueAdded && member.fix)
|
|
95
89
|
fixer.addUnusedTypeNode(filePath, [member.fix]);
|
|
96
90
|
}
|
|
97
91
|
else if (isIgnored) {
|
|
98
92
|
for (const tagName of exportedItem.jsDocTags) {
|
|
99
|
-
if (tags[1].includes(tagName.replace(/^@/, ''))) {
|
|
93
|
+
if (options.tags[1].includes(tagName.replace(/^@/, ''))) {
|
|
100
94
|
collector.addTagHint({ type: 'tag', filePath, identifier: id, tagName });
|
|
101
95
|
}
|
|
102
96
|
}
|
|
@@ -104,13 +98,13 @@ export const analyze = async (options) => {
|
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
}
|
|
107
|
-
if (principal && isReportClassMembers && exportedItem.type === 'class') {
|
|
101
|
+
if (principal && options.isReportClassMembers && exportedItem.type === 'class') {
|
|
108
102
|
const members = exportedItem.members.filter(member => !(findMatch(workspace.ignoreMembers, member.identifier) || shouldIgnore(member.jsDocTags)));
|
|
109
103
|
for (const member of principal.findUnusedMembers(filePath, members)) {
|
|
110
104
|
if (shouldIgnoreTags(member.jsDocTags)) {
|
|
111
105
|
const identifier = `${exportedItem.identifier}.${member.identifier}`;
|
|
112
106
|
for (const tagName of exportedItem.jsDocTags) {
|
|
113
|
-
if (tags[1].includes(tagName.replace(/^@/, ''))) {
|
|
107
|
+
if (options.tags[1].includes(tagName.replace(/^@/, ''))) {
|
|
114
108
|
collector.addTagHint({ type: 'tag', filePath, identifier, tagName });
|
|
115
109
|
}
|
|
116
110
|
}
|
|
@@ -126,7 +120,7 @@ export const analyze = async (options) => {
|
|
|
126
120
|
line: member.line,
|
|
127
121
|
col: member.col,
|
|
128
122
|
});
|
|
129
|
-
if (isFix && isIssueAdded && member.fix)
|
|
123
|
+
if (options.isFix && isIssueAdded && member.fix)
|
|
130
124
|
fixer.addUnusedTypeNode(filePath, [member.fix]);
|
|
131
125
|
}
|
|
132
126
|
}
|
|
@@ -135,12 +129,13 @@ export const analyze = async (options) => {
|
|
|
135
129
|
}
|
|
136
130
|
const [hasStrictlyNsRefs, namespace] = hasStrictlyNsReferences(graph, importsForExport, identifier);
|
|
137
131
|
const isType = ['enum', 'type', 'interface'].includes(exportedItem.type);
|
|
138
|
-
if (hasStrictlyNsRefs &&
|
|
132
|
+
if (hasStrictlyNsRefs &&
|
|
133
|
+
((!options.includedIssueTypes.nsTypes && isType) || !(options.includedIssueTypes.nsExports || isType)))
|
|
139
134
|
continue;
|
|
140
135
|
if (!isExportedItemReferenced(exportedItem)) {
|
|
141
136
|
if (isIgnored)
|
|
142
137
|
continue;
|
|
143
|
-
if (!isSkipLibs && principal?.hasExternalReferences(filePath, exportedItem))
|
|
138
|
+
if (!options.isSkipLibs && principal?.hasExternalReferences(filePath, exportedItem))
|
|
144
139
|
continue;
|
|
145
140
|
const type = getType(hasStrictlyNsRefs, isType);
|
|
146
141
|
const isIssueAdded = collector.addIssue({
|
|
@@ -154,7 +149,7 @@ export const analyze = async (options) => {
|
|
|
154
149
|
line: exportedItem.line,
|
|
155
150
|
col: exportedItem.col,
|
|
156
151
|
});
|
|
157
|
-
if (isFix && isIssueAdded) {
|
|
152
|
+
if (options.isFix && isIssueAdded) {
|
|
158
153
|
if (isType)
|
|
159
154
|
fixer.addUnusedTypeNode(filePath, exportedItem.fixes);
|
|
160
155
|
else
|
|
@@ -201,11 +196,11 @@ export const analyze = async (options) => {
|
|
|
201
196
|
const unusedFiles = [...unreferencedFiles].filter(filePath => !analyzedFiles.has(filePath));
|
|
202
197
|
collector.addFilesIssues(unusedFiles);
|
|
203
198
|
collector.addFileCounts({ processed: analyzedFiles.size, unused: unusedFiles.length });
|
|
204
|
-
if (isReportDependencies) {
|
|
199
|
+
if (options.isReportDependencies) {
|
|
205
200
|
const { dependencyIssues, devDependencyIssues, optionalPeerDependencyIssues } = deputy.settleDependencyIssues();
|
|
206
201
|
for (const issue of dependencyIssues)
|
|
207
202
|
collector.addIssue(issue);
|
|
208
|
-
if (!isProduction)
|
|
203
|
+
if (!options.isProduction)
|
|
209
204
|
for (const issue of devDependencyIssues)
|
|
210
205
|
collector.addIssue(issue);
|
|
211
206
|
for (const issue of optionalPeerDependencyIssues)
|
|
@@ -219,6 +214,8 @@ export const analyze = async (options) => {
|
|
|
219
214
|
for (const identifier of unusedIgnoredWorkspaces) {
|
|
220
215
|
collector.addConfigurationHint({ type: 'ignoreWorkspaces', identifier });
|
|
221
216
|
}
|
|
217
|
+
for (const hint of chief.getConfigurationHints())
|
|
218
|
+
collector.addConfigurationHint(hint);
|
|
222
219
|
};
|
|
223
220
|
await analyzeGraph();
|
|
224
221
|
return analyzeGraph;
|