knip 2.36.0 → 2.38.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 +3 -1
- package/dist/ConfigurationValidator.d.ts +56 -0
- package/dist/ConfigurationValidator.js +1 -0
- package/dist/ProjectPrincipal.d.ts +6 -1
- package/dist/ProjectPrincipal.js +7 -5
- package/dist/WorkspaceWorker.d.ts +1 -1
- package/dist/index.js +27 -4
- package/dist/plugins/graphql-codegen/index.d.ts +7 -0
- package/dist/plugins/graphql-codegen/index.js +35 -0
- package/dist/plugins/graphql-codegen/types.d.ts +25 -0
- package/dist/plugins/graphql-codegen/types.js +3 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -0
- package/dist/reporters/index.d.ts +1 -0
- package/dist/reporters/index.js +2 -0
- package/dist/reporters/jsonExt.d.ts +3 -0
- package/dist/reporters/jsonExt.js +73 -0
- package/dist/types/issues.d.ts +3 -0
- package/dist/typescript/ast-helpers.d.ts +1 -0
- package/dist/typescript/ast-helpers.js +3 -0
- package/dist/typescript/getImportsAndExports.js +2 -2
- package/dist/util/cli-arguments.d.ts +1 -1
- package/dist/util/cli-arguments.js +1 -1
- package/dist/util/compilers.d.ts +10 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/schema.json +4 -0
package/README.md
CHANGED
|
@@ -277,6 +277,7 @@ Knip contains a growing list of plugins:
|
|
|
277
277
|
- [ESLint][plugin-eslint]
|
|
278
278
|
- [Gatsby][plugin-gatsby]
|
|
279
279
|
- [GitHub Actions][plugin-github-actions]
|
|
280
|
+
- [Graphql Codegen][plugin-graphql-codegen]
|
|
280
281
|
- [husky][plugin-husky]
|
|
281
282
|
- [Jest][plugin-jest]
|
|
282
283
|
- [Lefthook][plugin-lefthook]
|
|
@@ -704,7 +705,7 @@ $ npx knip --help
|
|
|
704
705
|
-n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
|
|
705
706
|
--preprocessor Preprocess the results before providing it to the reporter(s), can be repeated
|
|
706
707
|
--preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)
|
|
707
|
-
--reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)
|
|
708
|
+
--reporter Select reporter: symbols, compact, codeowners, json, jsonExt, can be repeated (default: symbols)
|
|
708
709
|
--reporter-options Pass extra options to the reporter (as JSON string, see example)
|
|
709
710
|
--no-config-hints Suppress configuration hints
|
|
710
711
|
--no-exit-code Always exit with code zero (0)
|
|
@@ -928,6 +929,7 @@ Special thanks to the wonderful people who have contributed to this project:
|
|
|
928
929
|
[plugin-eslint]: ./src/plugins/eslint
|
|
929
930
|
[plugin-gatsby]: ./src/plugins/gatsby
|
|
930
931
|
[plugin-github-actions]: ./src/plugins/github-actions
|
|
932
|
+
[plugin-graphql-codegen]: ./src/plugins/graphql-codegen
|
|
931
933
|
[plugin-husky]: ./src/plugins/husky
|
|
932
934
|
[plugin-jest]: ./src/plugins/jest
|
|
933
935
|
[plugin-lefthook]: ./src/plugins/lefthook
|
|
@@ -34,6 +34,19 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
34
34
|
ignore: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
35
35
|
ignoreBinaries: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
36
36
|
ignoreDependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
37
|
+
'graphql-codegen': z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
38
|
+
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
39
|
+
entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
40
|
+
project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
config?: string | string[] | undefined;
|
|
43
|
+
entry?: string | string[] | undefined;
|
|
44
|
+
project?: string | string[] | undefined;
|
|
45
|
+
}, {
|
|
46
|
+
config?: string | string[] | undefined;
|
|
47
|
+
entry?: string | string[] | undefined;
|
|
48
|
+
project?: string | string[] | undefined;
|
|
49
|
+
}>]>>;
|
|
37
50
|
astro: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
38
51
|
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
39
52
|
entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
@@ -587,6 +600,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
587
600
|
ignore?: string | string[] | undefined;
|
|
588
601
|
ignoreBinaries?: string[] | undefined;
|
|
589
602
|
ignoreDependencies?: string[] | undefined;
|
|
603
|
+
'graphql-codegen'?: string | boolean | string[] | {
|
|
604
|
+
config?: string | string[] | undefined;
|
|
605
|
+
entry?: string | string[] | undefined;
|
|
606
|
+
project?: string | string[] | undefined;
|
|
607
|
+
} | undefined;
|
|
590
608
|
astro?: string | boolean | string[] | {
|
|
591
609
|
config?: string | string[] | undefined;
|
|
592
610
|
entry?: string | string[] | undefined;
|
|
@@ -804,6 +822,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
804
822
|
ignore?: string | string[] | undefined;
|
|
805
823
|
ignoreBinaries?: string[] | undefined;
|
|
806
824
|
ignoreDependencies?: string[] | undefined;
|
|
825
|
+
'graphql-codegen'?: string | boolean | string[] | {
|
|
826
|
+
config?: string | string[] | undefined;
|
|
827
|
+
entry?: string | string[] | undefined;
|
|
828
|
+
project?: string | string[] | undefined;
|
|
829
|
+
} | undefined;
|
|
807
830
|
astro?: string | boolean | string[] | {
|
|
808
831
|
config?: string | string[] | undefined;
|
|
809
832
|
entry?: string | string[] | undefined;
|
|
@@ -1015,6 +1038,19 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
1015
1038
|
project?: string | string[] | undefined;
|
|
1016
1039
|
} | undefined;
|
|
1017
1040
|
}>>>;
|
|
1041
|
+
'graphql-codegen': z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
1042
|
+
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
1043
|
+
entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
1044
|
+
project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
1045
|
+
}, "strip", z.ZodTypeAny, {
|
|
1046
|
+
config?: string | string[] | undefined;
|
|
1047
|
+
entry?: string | string[] | undefined;
|
|
1048
|
+
project?: string | string[] | undefined;
|
|
1049
|
+
}, {
|
|
1050
|
+
config?: string | string[] | undefined;
|
|
1051
|
+
entry?: string | string[] | undefined;
|
|
1052
|
+
project?: string | string[] | undefined;
|
|
1053
|
+
}>]>>;
|
|
1018
1054
|
astro: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
1019
1055
|
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
1020
1056
|
entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
@@ -1583,6 +1619,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
1583
1619
|
ignore?: string | string[] | undefined;
|
|
1584
1620
|
ignoreBinaries?: string[] | undefined;
|
|
1585
1621
|
ignoreDependencies?: string[] | undefined;
|
|
1622
|
+
'graphql-codegen'?: string | boolean | string[] | {
|
|
1623
|
+
config?: string | string[] | undefined;
|
|
1624
|
+
entry?: string | string[] | undefined;
|
|
1625
|
+
project?: string | string[] | undefined;
|
|
1626
|
+
} | undefined;
|
|
1586
1627
|
astro?: string | boolean | string[] | {
|
|
1587
1628
|
config?: string | string[] | undefined;
|
|
1588
1629
|
entry?: string | string[] | undefined;
|
|
@@ -1794,6 +1835,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
1794
1835
|
project?: string | string[] | undefined;
|
|
1795
1836
|
} | undefined;
|
|
1796
1837
|
}> | undefined;
|
|
1838
|
+
'graphql-codegen'?: string | boolean | string[] | {
|
|
1839
|
+
config?: string | string[] | undefined;
|
|
1840
|
+
entry?: string | string[] | undefined;
|
|
1841
|
+
project?: string | string[] | undefined;
|
|
1842
|
+
} | undefined;
|
|
1797
1843
|
astro?: string | boolean | string[] | {
|
|
1798
1844
|
config?: string | string[] | undefined;
|
|
1799
1845
|
entry?: string | string[] | undefined;
|
|
@@ -2026,6 +2072,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
2026
2072
|
ignore?: string | string[] | undefined;
|
|
2027
2073
|
ignoreBinaries?: string[] | undefined;
|
|
2028
2074
|
ignoreDependencies?: string[] | undefined;
|
|
2075
|
+
'graphql-codegen'?: string | boolean | string[] | {
|
|
2076
|
+
config?: string | string[] | undefined;
|
|
2077
|
+
entry?: string | string[] | undefined;
|
|
2078
|
+
project?: string | string[] | undefined;
|
|
2079
|
+
} | undefined;
|
|
2029
2080
|
astro?: string | boolean | string[] | {
|
|
2030
2081
|
config?: string | string[] | undefined;
|
|
2031
2082
|
entry?: string | string[] | undefined;
|
|
@@ -2237,6 +2288,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
2237
2288
|
project?: string | string[] | undefined;
|
|
2238
2289
|
} | undefined;
|
|
2239
2290
|
}> | undefined;
|
|
2291
|
+
'graphql-codegen'?: string | boolean | string[] | {
|
|
2292
|
+
config?: string | string[] | undefined;
|
|
2293
|
+
entry?: string | string[] | undefined;
|
|
2294
|
+
project?: string | string[] | undefined;
|
|
2295
|
+
} | undefined;
|
|
2240
2296
|
astro?: string | boolean | string[] | {
|
|
2241
2297
|
config?: string | string[] | undefined;
|
|
2242
2298
|
entry?: string | string[] | undefined;
|
|
@@ -58,7 +58,12 @@ export declare class ProjectPrincipal {
|
|
|
58
58
|
external: boolean;
|
|
59
59
|
internal: boolean;
|
|
60
60
|
};
|
|
61
|
-
findUnusedMembers(filePath: string, members: ExportItemMember[]):
|
|
61
|
+
findUnusedMembers(filePath: string, members: ExportItemMember[]): ExportItemMember[];
|
|
62
62
|
private findReferences;
|
|
63
|
+
getPos(node: ts.Node, pos: number): {
|
|
64
|
+
pos: number;
|
|
65
|
+
line: number;
|
|
66
|
+
col: number;
|
|
67
|
+
};
|
|
63
68
|
}
|
|
64
69
|
export {};
|
package/dist/ProjectPrincipal.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isGitIgnoredSync } from 'globby';
|
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { DEFAULT_EXTENSIONS } from './constants.js';
|
|
4
4
|
import { IGNORED_FILE_EXTENSIONS } from './constants.js';
|
|
5
|
-
import { getJSDocTags, isInModuleBlock } from './typescript/ast-helpers.js';
|
|
5
|
+
import { getJSDocTags, getLineAndCharacterOfPosition, isInModuleBlock } from './typescript/ast-helpers.js';
|
|
6
6
|
import { createHosts } from './typescript/createHosts.js';
|
|
7
7
|
import { getImportsAndExports } from './typescript/getImportsAndExports.js';
|
|
8
8
|
import { SourceFileManager } from './typescript/SourceFileManager.js';
|
|
@@ -176,8 +176,7 @@ export class ProjectPrincipal {
|
|
|
176
176
|
return hasReferences;
|
|
177
177
|
}
|
|
178
178
|
findUnusedMembers(filePath, members) {
|
|
179
|
-
return members
|
|
180
|
-
.filter(member => {
|
|
179
|
+
return members.filter(member => {
|
|
181
180
|
if (getJSDocTags(member.node).has('@public'))
|
|
182
181
|
return false;
|
|
183
182
|
const referencedSymbols = this.findReferences(filePath, member.pos);
|
|
@@ -188,8 +187,7 @@ export class ProjectPrincipal {
|
|
|
188
187
|
const internalRefs = files.filter(f => f === filePath);
|
|
189
188
|
const externalRefs = files.filter(f => f !== filePath);
|
|
190
189
|
return externalRefs.length === 0 && internalRefs.length === 0;
|
|
191
|
-
})
|
|
192
|
-
.map(member => member.identifier);
|
|
190
|
+
});
|
|
193
191
|
}
|
|
194
192
|
findReferences(filePath, pos) {
|
|
195
193
|
try {
|
|
@@ -199,4 +197,8 @@ export class ProjectPrincipal {
|
|
|
199
197
|
return [];
|
|
200
198
|
}
|
|
201
199
|
}
|
|
200
|
+
getPos(node, pos) {
|
|
201
|
+
const { line, character } = getLineAndCharacterOfPosition(node, pos);
|
|
202
|
+
return { pos, line: line + 1, col: character + 1 };
|
|
203
|
+
}
|
|
202
204
|
}
|
|
@@ -52,7 +52,7 @@ export declare class WorkspaceWorker {
|
|
|
52
52
|
installedBinaries: InstalledBinaries;
|
|
53
53
|
referencedDependencies: ReferencedDependencies;
|
|
54
54
|
hasTypesIncluded: Set<string>;
|
|
55
|
-
enabledPlugins: ("astro" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "markdownlint" | "mocha" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "typedoc" | "typescript" | "vite" | "vitest" | "webpack" | "drizzle" | "githubActions" | "lintStaged" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "svelte")[];
|
|
55
|
+
enabledPlugins: ("astro" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "markdownlint" | "mocha" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "typedoc" | "typescript" | "vite" | "vitest" | "webpack" | "drizzle" | "githubActions" | "lintStaged" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "svelte" | "graphqlCodegen")[];
|
|
56
56
|
entryFilePatterns: string[];
|
|
57
57
|
productionEntryFilePatterns: string[];
|
|
58
58
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -304,12 +304,24 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
304
304
|
if (isProduction)
|
|
305
305
|
continue;
|
|
306
306
|
principal.findUnusedMembers(filePath, exportedItem.members).forEach(member => {
|
|
307
|
-
collector.addIssue({
|
|
307
|
+
collector.addIssue({
|
|
308
|
+
type: 'enumMembers',
|
|
309
|
+
filePath,
|
|
310
|
+
symbol: member.identifier,
|
|
311
|
+
parentSymbol: symbol,
|
|
312
|
+
...principal.getPos(member.node, member.pos),
|
|
313
|
+
});
|
|
308
314
|
});
|
|
309
315
|
}
|
|
310
316
|
if (report.classMembers && exportedItem.type === 'class' && exportedItem.members) {
|
|
311
317
|
principal.findUnusedMembers(filePath, exportedItem.members).forEach(member => {
|
|
312
|
-
collector.addIssue({
|
|
318
|
+
collector.addIssue({
|
|
319
|
+
type: 'classMembers',
|
|
320
|
+
filePath,
|
|
321
|
+
symbol: member.identifier,
|
|
322
|
+
parentSymbol: symbol,
|
|
323
|
+
...principal.getPos(member.node, member.pos),
|
|
324
|
+
});
|
|
313
325
|
});
|
|
314
326
|
}
|
|
315
327
|
continue;
|
|
@@ -321,11 +333,22 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
321
333
|
if (isProduction)
|
|
322
334
|
continue;
|
|
323
335
|
const type = isStar ? 'nsTypes' : 'types';
|
|
324
|
-
collector.addIssue({
|
|
336
|
+
collector.addIssue({
|
|
337
|
+
type,
|
|
338
|
+
filePath,
|
|
339
|
+
symbol,
|
|
340
|
+
symbolType: exportedItem.type,
|
|
341
|
+
...principal.getPos(exportedItem.node, exportedItem.pos),
|
|
342
|
+
});
|
|
325
343
|
}
|
|
326
344
|
else {
|
|
327
345
|
const type = isStar ? 'nsExports' : 'exports';
|
|
328
|
-
collector.addIssue({
|
|
346
|
+
collector.addIssue({
|
|
347
|
+
type,
|
|
348
|
+
filePath,
|
|
349
|
+
symbol,
|
|
350
|
+
...principal.getPos(exportedItem.node, exportedItem.pos),
|
|
351
|
+
});
|
|
329
352
|
}
|
|
330
353
|
}
|
|
331
354
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
|
|
2
|
+
export declare const NAME = "Graphql Codegen";
|
|
3
|
+
export declare const ENABLERS: RegExp[];
|
|
4
|
+
export declare const PACKAGE_JSON_PATH = "codegen";
|
|
5
|
+
export declare const isEnabled: IsPluginEnabledCallback;
|
|
6
|
+
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
7
|
+
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { timerify } from '../../util/Performance.js';
|
|
2
|
+
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
|
+
import { isConfigurationOutput } from './types.js';
|
|
4
|
+
export const NAME = 'Graphql Codegen';
|
|
5
|
+
export const ENABLERS = [/^@graphql-codegen\//];
|
|
6
|
+
export const PACKAGE_JSON_PATH = 'codegen';
|
|
7
|
+
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
8
|
+
export const CONFIG_FILE_PATTERNS = ['codegen.{ts,js,json,yml,mjs,cts}', 'package.json'];
|
|
9
|
+
const findPluginDependencies = async (configFilePath, options) => {
|
|
10
|
+
const { manifest, isProduction } = options;
|
|
11
|
+
if (isProduction)
|
|
12
|
+
return [];
|
|
13
|
+
const localConfig = configFilePath.endsWith('package.json')
|
|
14
|
+
? manifest[PACKAGE_JSON_PATH]
|
|
15
|
+
: await load(configFilePath);
|
|
16
|
+
if (!localConfig)
|
|
17
|
+
return [];
|
|
18
|
+
const generateSet = Object.values(localConfig.generates);
|
|
19
|
+
const configurationOutput = generateSet.filter(isConfigurationOutput);
|
|
20
|
+
const presets = configurationOutput
|
|
21
|
+
.map(configOutput => (configOutput.preset ? configOutput.preset : undefined))
|
|
22
|
+
.filter((preset) => typeof preset === 'string')
|
|
23
|
+
.map(presetName => `@graphql-codegen/${presetName}${presetName.endsWith('-preset') ? '' : '-preset'}`);
|
|
24
|
+
const flatPlugins = generateSet
|
|
25
|
+
.filter((config) => !isConfigurationOutput(config))
|
|
26
|
+
.map(item => Object.keys(item))
|
|
27
|
+
.flat()
|
|
28
|
+
.map(plugin => `@graphql-codegen/${plugin}`);
|
|
29
|
+
const nestedPlugins = configurationOutput
|
|
30
|
+
.map(configOutput => (configOutput.plugins ? configOutput.plugins : []))
|
|
31
|
+
.flat()
|
|
32
|
+
.map(plugin => `@graphql-codegen/${plugin}`);
|
|
33
|
+
return [...presets, ...flatPlugins, ...nestedPlugins];
|
|
34
|
+
};
|
|
35
|
+
export const findDependencies = timerify(findPluginDependencies);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type PluginConfig<T = unknown> = {
|
|
2
|
+
[key: string]: T;
|
|
3
|
+
};
|
|
4
|
+
export interface ConfiguredPlugin {
|
|
5
|
+
[name: string]: PluginConfig;
|
|
6
|
+
}
|
|
7
|
+
type NamedPlugin = string;
|
|
8
|
+
type OutputConfig = NamedPlugin | ConfiguredPlugin;
|
|
9
|
+
type PresetNamesBase = 'client' | 'near-operation-file' | 'gql-tag-operations' | 'graphql-modules' | 'import-types';
|
|
10
|
+
export type PresetNames = `${PresetNamesBase}-preset` | PresetNamesBase;
|
|
11
|
+
type OutputPreset = {
|
|
12
|
+
buildGeneratesSection: (options: unknown) => Promise<unknown>;
|
|
13
|
+
prepareDocuments?: (outputFilePath: string, outputSpecificDocuments: unknown) => Promise<unknown>;
|
|
14
|
+
};
|
|
15
|
+
export declare function isConfigurationOutput(config: ConfiguredOutput | ConfiguredPlugin[]): config is ConfiguredOutput;
|
|
16
|
+
interface ConfiguredOutput {
|
|
17
|
+
plugins?: OutputConfig[];
|
|
18
|
+
preset?: PresetNames | OutputPreset;
|
|
19
|
+
}
|
|
20
|
+
export interface GraphqlCodegenTypes {
|
|
21
|
+
generates: {
|
|
22
|
+
[outputPath: string]: ConfiguredOutput | ConfiguredPlugin[];
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export {};
|
package/dist/plugins/index.d.ts
CHANGED
package/dist/plugins/index.js
CHANGED
|
@@ -3,5 +3,6 @@ declare const _default: {
|
|
|
3
3
|
compact: ({ report, issues, isShowProgress }: import("../index.js").ReporterOptions) => void;
|
|
4
4
|
codeowners: ({ report, issues, isShowProgress, options }: import("../index.js").ReporterOptions) => void;
|
|
5
5
|
json: ({ report, issues, options }: import("../index.js").ReporterOptions) => Promise<void>;
|
|
6
|
+
jsonExt: ({ report, issues, options }: import("../index.js").ReporterOptions) => Promise<void>;
|
|
6
7
|
};
|
|
7
8
|
export default _default;
|
package/dist/reporters/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import codeowners from './codeowners.js';
|
|
2
2
|
import compact from './compact.js';
|
|
3
3
|
import json from './json.js';
|
|
4
|
+
import jsonExt from './jsonExt.js';
|
|
4
5
|
import symbols from './symbols.js';
|
|
5
6
|
export default {
|
|
6
7
|
symbols,
|
|
7
8
|
compact,
|
|
8
9
|
codeowners,
|
|
9
10
|
json,
|
|
11
|
+
jsonExt,
|
|
10
12
|
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { OwnershipEngine } from '@snyk/github-codeowners/dist/lib/ownership/index.js';
|
|
2
|
+
import { isFile } from '../util/fs.js';
|
|
3
|
+
import { relative, resolve } from '../util/path.js';
|
|
4
|
+
const mergeTypes = (type) => type === 'exports' || type === 'nsExports' ? 'exports' : type === 'types' || type === 'nsTypes' ? 'types' : type;
|
|
5
|
+
export default async ({ report, issues, options }) => {
|
|
6
|
+
let opts = {};
|
|
7
|
+
try {
|
|
8
|
+
opts = options ? JSON.parse(options) : opts;
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
console.error(error);
|
|
12
|
+
}
|
|
13
|
+
const json = {};
|
|
14
|
+
const codeownersFilePath = resolve(opts.codeowners ?? '.github/CODEOWNERS');
|
|
15
|
+
const codeownersEngine = isFile(codeownersFilePath) && OwnershipEngine.FromCodeownersFile(codeownersFilePath);
|
|
16
|
+
const flatten = (issues) => Object.values(issues).flatMap(Object.values);
|
|
17
|
+
const initRow = (filePath) => {
|
|
18
|
+
const file = relative(filePath);
|
|
19
|
+
const row = {
|
|
20
|
+
file,
|
|
21
|
+
...(codeownersEngine && { owners: codeownersEngine.calcFileOwnership(file) }),
|
|
22
|
+
...(report.files && { files: false }),
|
|
23
|
+
...(report.dependencies && { dependencies: [] }),
|
|
24
|
+
...(report.devDependencies && { devDependencies: [] }),
|
|
25
|
+
...(report.optionalPeerDependencies && { optionalPeerDependencies: [] }),
|
|
26
|
+
...(report.unlisted && { unlisted: [] }),
|
|
27
|
+
...(report.binaries && { binaries: [] }),
|
|
28
|
+
...(report.unresolved && { unresolved: [] }),
|
|
29
|
+
...((report.exports || report.nsExports) && { exports: [] }),
|
|
30
|
+
...((report.types || report.nsTypes) && { types: [] }),
|
|
31
|
+
...(report.enumMembers && { enumMembers: {} }),
|
|
32
|
+
...(report.classMembers && { classMembers: {} }),
|
|
33
|
+
...(report.duplicates && { duplicates: [] }),
|
|
34
|
+
};
|
|
35
|
+
return row;
|
|
36
|
+
};
|
|
37
|
+
for (const [reportType, isReportType] of Object.entries(report)) {
|
|
38
|
+
if (isReportType) {
|
|
39
|
+
if (reportType === 'files') {
|
|
40
|
+
Array.from(issues[reportType]).forEach(filePath => {
|
|
41
|
+
json[filePath] = json[filePath] ?? initRow(filePath);
|
|
42
|
+
json[filePath][reportType] = true;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const type = mergeTypes(reportType);
|
|
47
|
+
flatten(issues[reportType]).forEach(issue => {
|
|
48
|
+
const { filePath, symbol, symbols, parentSymbol } = issue;
|
|
49
|
+
json[filePath] = json[filePath] ?? initRow(filePath);
|
|
50
|
+
if (type === 'duplicates') {
|
|
51
|
+
symbols && json[filePath][type]?.push(symbols.map(symbol => ({ name: symbol })));
|
|
52
|
+
}
|
|
53
|
+
else if (type === 'enumMembers' || type === 'classMembers') {
|
|
54
|
+
const item = json[filePath][type];
|
|
55
|
+
if (parentSymbol && item) {
|
|
56
|
+
item[parentSymbol] = item[parentSymbol] ?? [];
|
|
57
|
+
item[parentSymbol].push({ name: issue.symbol, line: issue.line, col: issue.col, pos: issue.pos });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (type === 'exports' || type === 'types') {
|
|
62
|
+
json[filePath][type]?.push({ name: issue.symbol, line: issue.line, col: issue.col, pos: issue.pos });
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
json[filePath][type]?.push({ name: symbol });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
console.log(JSON.stringify(Object.values(json)));
|
|
73
|
+
};
|
package/dist/types/issues.d.ts
CHANGED
|
@@ -15,6 +15,9 @@ export type Issue = {
|
|
|
15
15
|
symbolType?: SymbolType;
|
|
16
16
|
parentSymbol?: string;
|
|
17
17
|
severity?: IssueSeverity;
|
|
18
|
+
pos?: number;
|
|
19
|
+
line?: number;
|
|
20
|
+
col?: number;
|
|
18
21
|
};
|
|
19
22
|
export type IssueSet = Set<string>;
|
|
20
23
|
export type IssueRecords = Record<string, Record<string, Issue>>;
|
|
@@ -25,4 +25,5 @@ export declare function findDescendants<T>(node: ts.Node | undefined, callback:
|
|
|
25
25
|
export declare const isDeclarationFileExtension: (extension: string) => boolean;
|
|
26
26
|
export declare const isInModuleBlock: (node: ts.Node) => boolean;
|
|
27
27
|
export declare const getJSDocTags: (node: ts.Node) => Set<string>;
|
|
28
|
+
export declare const getLineAndCharacterOfPosition: (node: ts.Node, pos: number) => ts.LineAndCharacter;
|
|
28
29
|
export {};
|
|
@@ -95,10 +95,10 @@ export const getImportsAndExports = (sourceFile, options) => {
|
|
|
95
95
|
const item = exports.get(identifier);
|
|
96
96
|
const crew = [...item.members, ...members];
|
|
97
97
|
const tags = new Set([...item.jsDocTags, ...jsDocTags]);
|
|
98
|
-
exports.set(identifier, { ...item,
|
|
98
|
+
exports.set(identifier, { ...item, members: crew, jsDocTags: tags });
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
101
|
-
exports.set(identifier, { node, type,
|
|
101
|
+
exports.set(identifier, { node, type, members, jsDocTags, pos });
|
|
102
102
|
}
|
|
103
103
|
if (!jsDocTags.has('@alias')) {
|
|
104
104
|
if (ts.isExportAssignment(node))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no tests, devDependencies, exported types)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n --ignore-internal Ignore exports with tag @internal (JSDoc/TSDoc)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --include-entry-exports Include entry files when reporting unused exports\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --debug-file-filter Filter for files in debug output (regex as string)\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --debug --debug-file-filter '(specific|particular)-module'\n\nMore documentation and bug reports: https://github.com/webpro/knip";
|
|
1
|
+
export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no tests, devDependencies, exported types)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n --ignore-internal Ignore exports with tag @internal (JSDoc/TSDoc)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --include-entry-exports Include entry files when reporting unused exports\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter: symbols, compact, codeowners, json, jsonExt, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --debug-file-filter Filter for files in debug output (regex as string)\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --debug --debug-file-filter '(specific|particular)-module'\n\nMore documentation and bug reports: https://github.com/webpro/knip";
|
|
2
2
|
declare const _default: {
|
|
3
3
|
config: string | undefined;
|
|
4
4
|
debug: boolean | undefined;
|
|
@@ -20,7 +20,7 @@ Options:
|
|
|
20
20
|
-n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
|
|
21
21
|
--preprocessor Preprocess the results before providing it to the reporter(s), can be repeated
|
|
22
22
|
--preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)
|
|
23
|
-
--reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)
|
|
23
|
+
--reporter Select reporter: symbols, compact, codeowners, json, jsonExt, can be repeated (default: symbols)
|
|
24
24
|
--reporter-options Pass extra options to the reporter (as JSON string, see example)
|
|
25
25
|
--no-config-hints Suppress configuration hints
|
|
26
26
|
--no-exit-code Always exit with code zero (0)
|
package/dist/util/compilers.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
22
22
|
ignore?: string | string[] | undefined;
|
|
23
23
|
ignoreBinaries?: string[] | undefined;
|
|
24
24
|
ignoreDependencies?: string[] | undefined;
|
|
25
|
+
'graphql-codegen'?: string | boolean | string[] | {
|
|
26
|
+
config?: string | string[] | undefined;
|
|
27
|
+
entry?: string | string[] | undefined;
|
|
28
|
+
project?: string | string[] | undefined;
|
|
29
|
+
} | undefined;
|
|
25
30
|
astro?: string | boolean | string[] | {
|
|
26
31
|
config?: string | string[] | undefined;
|
|
27
32
|
entry?: string | string[] | undefined;
|
|
@@ -233,6 +238,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
233
238
|
project?: string | string[] | undefined;
|
|
234
239
|
} | undefined;
|
|
235
240
|
}> | undefined;
|
|
241
|
+
'graphql-codegen'?: string | boolean | string[] | {
|
|
242
|
+
config?: string | string[] | undefined;
|
|
243
|
+
entry?: string | string[] | undefined;
|
|
244
|
+
project?: string | string[] | undefined;
|
|
245
|
+
} | undefined;
|
|
236
246
|
astro?: string | boolean | string[] | {
|
|
237
247
|
config?: string | string[] | undefined;
|
|
238
248
|
entry?: string | string[] | undefined;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.
|
|
1
|
+
export declare const version = "2.38.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.38.0';
|
package/package.json
CHANGED
package/schema.json
CHANGED
|
@@ -276,6 +276,10 @@
|
|
|
276
276
|
"title": "github-actions plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/github-actions/README.md)",
|
|
277
277
|
"$ref": "#/definitions/plugin"
|
|
278
278
|
},
|
|
279
|
+
"graphql-codegen": {
|
|
280
|
+
"title": "graphql-codegen plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/graphql-codegen/README.md)",
|
|
281
|
+
"$ref": "#/definitions/plugin"
|
|
282
|
+
},
|
|
279
283
|
"husky": {
|
|
280
284
|
"title": "husky plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/husky/README.md)",
|
|
281
285
|
"$ref": "#/definitions/plugin"
|