knip 6.10.0 → 6.11.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/dist/cli.js +1 -0
- package/dist/graph/analyze.js +8 -5
- package/dist/graph/build.js +15 -1
- package/dist/reporters/symbols.js +5 -2
- package/dist/reporters/util/configuration-hints.d.ts +1 -0
- package/dist/reporters/util/configuration-hints.js +2 -0
- package/dist/types/issues.d.ts +1 -0
- package/dist/util/create-options.d.ts +1 -0
- package/dist/util/create-options.js +1 -0
- package/dist/util/load-tsconfig.d.ts +6 -2
- package/dist/util/load-tsconfig.js +31 -34
- package/dist/util/tag.d.ts +1 -0
- package/dist/util/tag.js +2 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -46,6 +46,7 @@ const main = async () => {
|
|
|
46
46
|
cwd: options.cwd,
|
|
47
47
|
configFilePath: options.configFilePath,
|
|
48
48
|
isDisableConfigHints: options.isDisableConfigHints,
|
|
49
|
+
isDisableTagHints: options.isDisableTagHints,
|
|
49
50
|
isProduction: options.isProduction,
|
|
50
51
|
isShowProgress: options.isShowProgress,
|
|
51
52
|
isTreatConfigHintsAsErrors: options.isTreatConfigHintsAsErrors,
|
package/dist/graph/analyze.js
CHANGED
|
@@ -5,7 +5,8 @@ import { shouldCountRefs } from '../typescript/visitors/helpers.js';
|
|
|
5
5
|
import { getPackageNameFromModuleSpecifier } from '../util/modules.js';
|
|
6
6
|
import { perfObserver } from '../util/Performance.js';
|
|
7
7
|
import { findMatch } from '../util/regex.js';
|
|
8
|
-
import { getShouldIgnoreHandler, getShouldIgnoreTagHandler } from '../util/tag.js';
|
|
8
|
+
import { getShouldIgnoreHandler, getShouldIgnoreTagHandler, isAlwaysIgnored } from '../util/tag.js';
|
|
9
|
+
import { INTERNAL_TAG } from '../constants.js';
|
|
9
10
|
export const analyze = async ({ analyzedFiles, counselor, chief, collector, deputy, entryPaths, graph, streamer, unreferencedFiles, options, }) => {
|
|
10
11
|
const shouldIgnore = getShouldIgnoreHandler(options.isProduction);
|
|
11
12
|
const shouldIgnoreTags = getShouldIgnoreTagHandler(options.tags);
|
|
@@ -54,9 +55,10 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
|
|
|
54
55
|
}
|
|
55
56
|
const importsForExport = file.importedBy;
|
|
56
57
|
for (const [identifier, exportedItem] of exportItems) {
|
|
57
|
-
if (
|
|
58
|
+
if (isAlwaysIgnored(exportedItem.jsDocTags))
|
|
58
59
|
continue;
|
|
59
|
-
const
|
|
60
|
+
const isInternalProd = options.isProduction && exportedItem.jsDocTags.has(INTERNAL_TAG);
|
|
61
|
+
const isIgnored = shouldIgnoreTags(exportedItem.jsDocTags) || isInternalProd;
|
|
60
62
|
if (importsForExport) {
|
|
61
63
|
const [isReferenced, reExportingEntryFile] = explorer.isReferenced(filePath, identifier, {
|
|
62
64
|
includeEntryExports: isIncludeEntryExports,
|
|
@@ -64,7 +66,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
|
|
|
64
66
|
if (isIgnored &&
|
|
65
67
|
(isReferenced || isReferencedInUsedExport(exportedItem, filePath, isIncludeEntryExports))) {
|
|
66
68
|
for (const tagName of exportedItem.jsDocTags) {
|
|
67
|
-
if (options.tags[1].includes(tagName)) {
|
|
69
|
+
if (options.tags[1].includes(tagName) || (isInternalProd && tagName === INTERNAL_TAG)) {
|
|
68
70
|
collector.addTagHint({ type: 'tag', filePath, identifier, tagName });
|
|
69
71
|
}
|
|
70
72
|
}
|
|
@@ -171,7 +173,8 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
|
|
|
171
173
|
if (file.imports?.external) {
|
|
172
174
|
for (const extImport of file.imports.external) {
|
|
173
175
|
const packageName = getPackageNameFromModuleSpecifier(extImport.specifier);
|
|
174
|
-
const isHandled = packageName &&
|
|
176
|
+
const isHandled = packageName &&
|
|
177
|
+
deputy.maybeAddReferencedExternalDependency(ws, packageName, undefined, extImport.isTypeOnly);
|
|
175
178
|
if (!isHandled)
|
|
176
179
|
collector.addIssue({
|
|
177
180
|
type: 'unlisted',
|
package/dist/graph/build.js
CHANGED
|
@@ -5,6 +5,7 @@ import { partition } from '../util/array.js';
|
|
|
5
5
|
import { createInputHandler } from '../util/create-input-handler.js';
|
|
6
6
|
import { debugLog, debugLogArray } from '../util/debug.js';
|
|
7
7
|
import { existsSync } from 'node:fs';
|
|
8
|
+
import picomatch from 'picomatch';
|
|
8
9
|
import { tryRealpath } from '../util/fs.js';
|
|
9
10
|
import { createManifest } from '../util/package-json.js';
|
|
10
11
|
import { _glob, _syncGlob, negate, prependDirToPattern as prependDir } from '../util/glob.js';
|
|
@@ -57,7 +58,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
|
|
|
57
58
|
const dependencies = deputy.getDependencies(name);
|
|
58
59
|
const baseConfig = chief.getConfigForWorkspace(name);
|
|
59
60
|
const tsConfigFilePath = join(dir, options.tsConfigFile ?? 'tsconfig.json');
|
|
60
|
-
const { isFile, compilerOptions, fileNames } = await loadTSConfig(tsConfigFilePath);
|
|
61
|
+
const { isFile, compilerOptions, fileNames, include, exclude } = await loadTSConfig(tsConfigFilePath);
|
|
61
62
|
const [definitionPaths, tscSourcePaths] = partition(fileNames, filePath => IS_DTS.test(filePath));
|
|
62
63
|
const worker = new WorkspaceWorker({
|
|
63
64
|
name,
|
|
@@ -249,6 +250,19 @@ export async function build({ chief, collector, counselor, deputy, principal, is
|
|
|
249
250
|
principal.addProjectPath(filePath);
|
|
250
251
|
}
|
|
251
252
|
}
|
|
253
|
+
if (extensions.length > 0) {
|
|
254
|
+
const extPart = extensions.length === 1 ? extensions[0] : `.{${extensions.map(ext => ext.slice(1)).join(',')}}`;
|
|
255
|
+
const bases = include ? new Set(include.map(p => picomatch.scan(p).base || dir)) : new Set([dir]);
|
|
256
|
+
const patterns = [
|
|
257
|
+
...Array.from(bases, base => `${base}/**/*${extPart}`),
|
|
258
|
+
...(exclude?.map(p => `!${p}`) ?? []),
|
|
259
|
+
];
|
|
260
|
+
const compilerPaths = await _glob({ ...sharedGlobOptions, patterns, label: 'compiler extension paths' });
|
|
261
|
+
for (const compilerPath of compilerPaths) {
|
|
262
|
+
if (!isIgnoredWorkspace(compilerPath))
|
|
263
|
+
principal.addProjectPath(compilerPath);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
252
266
|
}
|
|
253
267
|
else {
|
|
254
268
|
const patterns = options.isProduction
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { printConfigurationHints } from './util/configuration-hints.js';
|
|
1
|
+
import { printConfigurationHints, printTagHints } from './util/configuration-hints.js';
|
|
2
2
|
import { dim, flattenIssues, getColoredTitle, getIssueTypeTitle, getTableForType } from './util/util.js';
|
|
3
3
|
export default (options) => {
|
|
4
|
-
const { report, issues, isDisableConfigHints, isShowProgress } = options;
|
|
4
|
+
const { report, issues, isDisableConfigHints, isDisableTagHints, isShowProgress } = options;
|
|
5
5
|
const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1;
|
|
6
6
|
let totalIssues = 0;
|
|
7
7
|
for (const [reportType, isReportType] of Object.entries(report)) {
|
|
@@ -24,6 +24,9 @@ export default (options) => {
|
|
|
24
24
|
if (!isDisableConfigHints) {
|
|
25
25
|
printConfigurationHints(options);
|
|
26
26
|
}
|
|
27
|
+
if (!isDisableTagHints) {
|
|
28
|
+
printTagHints(options);
|
|
29
|
+
}
|
|
27
30
|
if (totalIssues === 0 &&
|
|
28
31
|
isShowProgress &&
|
|
29
32
|
(!options.isTreatConfigHintsAsErrors || options.configurationHints.length === 0)) {
|
|
@@ -19,4 +19,5 @@ export declare const finalizeConfigurationHints: (results: Results, options: {
|
|
|
19
19
|
configFilePath?: string;
|
|
20
20
|
}) => ProcessedHint[];
|
|
21
21
|
export declare const printConfigurationHints: ({ cwd, counters, issues, tagHints, configurationHints, enabledPlugins, isTreatConfigHintsAsErrors, includedWorkspaceDirs, selectedWorkspaces, configFilePath, }: ReporterOptions) => void;
|
|
22
|
+
export declare const printTagHints: ({ cwd, tagHints }: ReporterOptions) => void;
|
|
22
23
|
export {};
|
|
@@ -127,6 +127,8 @@ export const printConfigurationHints = ({ cwd, counters, issues, tagHints, confi
|
|
|
127
127
|
console.log(getTitle('Configuration hints', configurationHints.length));
|
|
128
128
|
console.warn(getTableForHints(rows).toString());
|
|
129
129
|
}
|
|
130
|
+
};
|
|
131
|
+
export const printTagHints = ({ cwd, tagHints }) => {
|
|
130
132
|
if (tagHints.size > 0) {
|
|
131
133
|
console.log(getDimmedTitle('Tag hints', tagHints.size));
|
|
132
134
|
for (const hint of tagHints) {
|
package/dist/types/issues.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ export type ReporterOptions = {
|
|
|
54
54
|
configurationHints: ConfigurationHint[];
|
|
55
55
|
enabledPlugins: Record<string, string[]>;
|
|
56
56
|
isDisableConfigHints: boolean;
|
|
57
|
+
isDisableTagHints: boolean;
|
|
57
58
|
isTreatConfigHintsAsErrors: boolean;
|
|
58
59
|
cwd: string;
|
|
59
60
|
isProduction: boolean;
|
|
@@ -107,6 +107,7 @@ export const createOptions = async (options) => {
|
|
|
107
107
|
isCache: args.cache ?? false,
|
|
108
108
|
isDebug,
|
|
109
109
|
isDisableConfigHints: args['no-config-hints'] || isProduction || Boolean(workspace),
|
|
110
|
+
isDisableTagHints: Boolean(args['no-config-hints']),
|
|
110
111
|
isFix: args.fix ?? options.isFix ?? isFixFiles ?? fixTypes.length > 0,
|
|
111
112
|
isFixCatalog: fixTypes.length === 0 || fixTypes.includes('catalog'),
|
|
112
113
|
isFixDependencies: fixTypes.length === 0 || fixTypes.includes('dependencies'),
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { CompilerOptions } from '../types/project.ts';
|
|
2
|
-
|
|
2
|
+
interface TSConfigInfo {
|
|
3
3
|
isFile: boolean;
|
|
4
4
|
compilerOptions: CompilerOptions;
|
|
5
5
|
fileNames: string[];
|
|
6
|
-
|
|
6
|
+
include: string[] | undefined;
|
|
7
|
+
exclude: string[] | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare const loadTSConfig: (tsConfigFilePath: string) => Promise<TSConfigInfo>;
|
|
10
|
+
export {};
|
|
@@ -73,42 +73,39 @@ const fillFromReferences = (target, references, dir, visited) => {
|
|
|
73
73
|
fillFromReferences(target, refConfig.references, refDir, visited);
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
+
const EMPTY = {
|
|
77
|
+
compilerOptions: {},
|
|
78
|
+
fileNames: [],
|
|
79
|
+
include: undefined,
|
|
80
|
+
exclude: undefined,
|
|
81
|
+
};
|
|
76
82
|
export const loadTSConfig = async (tsConfigFilePath) => {
|
|
77
|
-
if (isFile(tsConfigFilePath))
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if ((!compilerOptions.outDir || !compilerOptions.rootDir) && config.references?.length) {
|
|
93
|
-
fillFromReferences(compilerOptions, config.references, dir, new Set([tsConfigFilePath]));
|
|
94
|
-
}
|
|
95
|
-
const include = resolvePatterns(config.include, dir, true);
|
|
96
|
-
const exclude = resolvePatterns(config.exclude, dir, true);
|
|
97
|
-
const files = resolvePatterns(config.files, dir);
|
|
98
|
-
const fileNames = expandFileNames(dir, compilerOptions, include, exclude, files);
|
|
99
|
-
return { isFile: true, compilerOptions, fileNames };
|
|
83
|
+
if (!isFile(tsConfigFilePath))
|
|
84
|
+
return { isFile: false, ...EMPTY };
|
|
85
|
+
try {
|
|
86
|
+
const config = parseTsconfig(tsConfigFilePath);
|
|
87
|
+
const dir = dirname(tsConfigFilePath);
|
|
88
|
+
const compilerOptions = (config.compilerOptions ?? {});
|
|
89
|
+
if (compilerOptions.outDir)
|
|
90
|
+
compilerOptions.outDir = toAbsolute(compilerOptions.outDir, dir).replace(/\/+$/, '');
|
|
91
|
+
if (compilerOptions.rootDir)
|
|
92
|
+
compilerOptions.rootDir = toAbsolute(compilerOptions.rootDir, dir).replace(/\/+$/, '');
|
|
93
|
+
if (compilerOptions.paths) {
|
|
94
|
+
compilerOptions.pathsBasePath ??= dir;
|
|
95
|
+
}
|
|
96
|
+
if (compilerOptions.rootDirs) {
|
|
97
|
+
compilerOptions.rootDirs = compilerOptions.rootDirs.map((d) => (isAbsolute(d) ? d : join(dir, d)));
|
|
100
98
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
isFile: true,
|
|
104
|
-
compilerOptions: {},
|
|
105
|
-
fileNames: [],
|
|
106
|
-
};
|
|
99
|
+
if ((!compilerOptions.outDir || !compilerOptions.rootDir) && config.references?.length) {
|
|
100
|
+
fillFromReferences(compilerOptions, config.references, dir, new Set([tsConfigFilePath]));
|
|
107
101
|
}
|
|
102
|
+
const include = resolvePatterns(config.include, dir, true);
|
|
103
|
+
const exclude = resolvePatterns(config.exclude, dir, true);
|
|
104
|
+
const files = resolvePatterns(config.files, dir);
|
|
105
|
+
const fileNames = expandFileNames(dir, compilerOptions, include, exclude, files);
|
|
106
|
+
return { isFile: true, compilerOptions, fileNames, include, exclude };
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return { isFile: true, ...EMPTY };
|
|
108
110
|
}
|
|
109
|
-
return {
|
|
110
|
-
isFile: false,
|
|
111
|
-
compilerOptions: {},
|
|
112
|
-
fileNames: [],
|
|
113
|
-
};
|
|
114
111
|
};
|
package/dist/util/tag.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Tags } from '../types/options.ts';
|
|
2
2
|
export declare const splitTags: (rawTags: string[]) => Tags;
|
|
3
3
|
export declare const shouldIgnore: (jsDocTags: Set<string>, tags: Tags) => boolean;
|
|
4
|
+
export declare const isAlwaysIgnored: (jsDocTags: Set<string>) => boolean;
|
|
4
5
|
export declare const getShouldIgnoreHandler: (isProduction: boolean) => (jsDocTags: Set<string>) => boolean;
|
|
5
6
|
export declare const getShouldIgnoreTagHandler: (tags: Tags) => (jsDocTags: Set<string>) => boolean;
|
package/dist/util/tag.js
CHANGED
|
@@ -17,8 +17,6 @@ export const shouldIgnore = (jsDocTags, tags) => {
|
|
|
17
17
|
return true;
|
|
18
18
|
return false;
|
|
19
19
|
};
|
|
20
|
-
export const
|
|
21
|
-
|
|
22
|
-
jsDocTags.has(ALIAS_TAG) ||
|
|
23
|
-
(isProduction && jsDocTags.has(INTERNAL_TAG));
|
|
20
|
+
export const isAlwaysIgnored = (jsDocTags) => jsDocTags.has(PUBLIC_TAG) || jsDocTags.has(BETA_TAG) || jsDocTags.has(ALIAS_TAG);
|
|
21
|
+
export const getShouldIgnoreHandler = (isProduction) => (jsDocTags) => isAlwaysIgnored(jsDocTags) || (isProduction && jsDocTags.has(INTERNAL_TAG));
|
|
24
22
|
export const getShouldIgnoreTagHandler = (tags) => (jsDocTags) => shouldIgnore(jsDocTags, tags);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "6.
|
|
1
|
+
export declare const version = "6.11.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '6.
|
|
1
|
+
export const version = '6.11.0';
|