knip 3.3.0 → 3.3.2

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.
@@ -35,6 +35,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
35
35
  ignore: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
36
36
  ignoreBinaries: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
37
37
  ignoreDependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
38
+ includeEntryExports: z.ZodOptional<z.ZodBoolean>;
38
39
  astro: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
39
40
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
40
41
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -614,6 +615,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
614
615
  ignore?: string | string[] | undefined;
615
616
  ignoreBinaries?: string[] | undefined;
616
617
  ignoreDependencies?: string[] | undefined;
618
+ includeEntryExports?: boolean | undefined;
617
619
  astro?: string | boolean | string[] | {
618
620
  config?: string | string[] | undefined;
619
621
  entry?: string | string[] | undefined;
@@ -841,6 +843,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
841
843
  ignore?: string | string[] | undefined;
842
844
  ignoreBinaries?: string[] | undefined;
843
845
  ignoreDependencies?: string[] | undefined;
846
+ includeEntryExports?: boolean | undefined;
844
847
  astro?: string | boolean | string[] | {
845
848
  config?: string | string[] | undefined;
846
849
  entry?: string | string[] | undefined;
@@ -1657,6 +1660,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
1657
1660
  ignore?: string | string[] | undefined;
1658
1661
  ignoreBinaries?: string[] | undefined;
1659
1662
  ignoreDependencies?: string[] | undefined;
1663
+ includeEntryExports?: boolean | undefined;
1660
1664
  astro?: string | boolean | string[] | {
1661
1665
  config?: string | string[] | undefined;
1662
1666
  entry?: string | string[] | undefined;
@@ -2121,6 +2125,7 @@ export declare const ConfigurationValidator: z.ZodObject<{
2121
2125
  ignore?: string | string[] | undefined;
2122
2126
  ignoreBinaries?: string[] | undefined;
2123
2127
  ignoreDependencies?: string[] | undefined;
2128
+ includeEntryExports?: boolean | undefined;
2124
2129
  astro?: string | boolean | string[] | {
2125
2130
  config?: string | string[] | undefined;
2126
2131
  entry?: string | string[] | undefined;
@@ -113,6 +113,7 @@ const baseWorkspaceConfigurationSchema = z.object({
113
113
  ignore: globSchema.optional(),
114
114
  ignoreBinaries: z.array(z.string()).optional(),
115
115
  ignoreDependencies: z.array(z.string()).optional(),
116
+ includeEntryExports: z.boolean().optional(),
116
117
  });
117
118
  const workspaceConfigurationSchema = baseWorkspaceConfigurationSchema.merge(pluginsSchema.partial());
118
119
  const workspacesConfigurationSchema = z.object({
@@ -48,7 +48,10 @@ export declare class DependencyDeputy {
48
48
  addReferencedDependency(workspaceName: string, packageName: string): void;
49
49
  addReferencedBinary(workspaceName: string, binaryName: string): void;
50
50
  addHostDependencies(workspaceName: string, hostDependencies: HostDependencies): void;
51
- getHostDependenciesFor(workspaceName: string, dependency: string): string[];
51
+ getHostDependenciesFor(workspaceName: string, dependency: string): {
52
+ name: string;
53
+ isPeerOptional: boolean;
54
+ }[];
52
55
  getPeerDependencies(workspaceName: string): string[];
53
56
  getOptionalPeerDependencies(workspaceName: string): string[];
54
57
  maybeAddReferencedExternalDependency(workspace: Workspace, packageName: string): boolean;
@@ -195,16 +195,16 @@ export class DependencyDeputy {
195
195
  ...this.getHostDependenciesFor(workspaceName, typedPackageName),
196
196
  ];
197
197
  if (hostDependencies.length)
198
- return !!hostDependencies.find(host => isReferencedDependency(host, true));
198
+ return !!hostDependencies.find(host => isReferencedDependency(host.name, true));
199
199
  if (!referencedDependencies)
200
200
  return false;
201
201
  return referencedDependencies.has(typedPackageName);
202
202
  }
203
203
  const hostDependencies = this.getHostDependenciesFor(workspaceName, dependency);
204
- hostDependencies.forEach(dep => (!peerDepRecs[dep] ? (peerDepRecs[dep] = 1) : peerDepRecs[dep]++));
205
- return hostDependencies.some(peerDependency => isReferencedDependency(peerDependency, true));
204
+ hostDependencies.forEach(({ name }) => (!peerDepRecs[name] ? (peerDepRecs[name] = 1) : peerDepRecs[name]++));
205
+ return hostDependencies.some(hostDependency => (isPeerDep === false || !hostDependency.isPeerOptional) && isReferencedDependency(hostDependency.name, true));
206
206
  };
207
- const isNotReferencedDependency = (dependency) => !isReferencedDependency(dependency);
207
+ const isNotReferencedDependency = (dependency) => !isReferencedDependency(dependency, false);
208
208
  const pd = this.getProductionDependencies(workspaceName);
209
209
  const dd = this.getDevDependencies(workspaceName);
210
210
  const od = this.getOptionalPeerDependencies(workspaceName);
@@ -39,14 +39,18 @@ const findManifestDependencies = async ({ manifest, isProduction, isStrict, dir,
39
39
  }
40
40
  });
41
41
  const packagePeerDependencies = Object.keys(manifest.peerDependencies ?? {});
42
- packagePeerDependencies.forEach(packagePeerDependency => {
42
+ for (const packagePeerDependency of packagePeerDependencies) {
43
+ const hostDependency = {
44
+ name: packageName,
45
+ isPeerOptional: manifest.peerDependenciesMeta?.[packagePeerDependency]?.optional ?? false,
46
+ };
43
47
  if (hostDependencies.has(packagePeerDependency)) {
44
- hostDependencies.get(packagePeerDependency)?.add(packageName);
48
+ hostDependencies.get(packagePeerDependency)?.add(hostDependency);
45
49
  }
46
50
  else {
47
- hostDependencies.set(packagePeerDependency, new Set([packageName]));
51
+ hostDependencies.set(packagePeerDependency, new Set([hostDependency]));
48
52
  }
49
- });
53
+ }
50
54
  if (!isDefinitelyTyped(packageName) && (manifest.types || manifest.typings))
51
55
  hasTypesIncluded.add(packageName);
52
56
  }
@@ -12,6 +12,9 @@ type WorkspaceManifest = {
12
12
  ignoreBinaries: string[];
13
13
  };
14
14
  export type WorkspaceManifests = Map<string, WorkspaceManifest>;
15
- export type HostDependencies = Map<string, Set<string>>;
15
+ export type HostDependencies = Map<string, Set<{
16
+ name: string;
17
+ isPeerOptional: boolean;
18
+ }>>;
16
19
  export type InstalledBinaries = Map<string, Set<string>>;
17
20
  export {};
@@ -23,6 +23,7 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
23
23
  ignore?: string | string[] | undefined;
24
24
  ignoreBinaries?: string[] | undefined;
25
25
  ignoreDependencies?: string[] | undefined;
26
+ includeEntryExports?: boolean | undefined;
26
27
  astro?: string | boolean | string[] | {
27
28
  config?: string | string[] | undefined;
28
29
  entry?: string | string[] | undefined;
@@ -1,30 +1,24 @@
1
1
  import { ISSUE_TYPES } from '../constants.js';
2
2
  import { ConfigurationError } from './errors.js';
3
+ const normalize = (values) => values.map(value => value.split(',')).flat();
3
4
  export const getIncludedIssueTypes = (cliArgs, { include = [], exclude = [], isProduction = false } = {}) => {
4
- [...cliArgs.include, ...cliArgs.exclude, ...include, ...exclude].forEach(type => {
5
+ let incl = normalize(cliArgs.include);
6
+ let excl = normalize(cliArgs.exclude);
7
+ [...incl, ...excl, ...include, ...exclude].forEach(type => {
5
8
  if (!ISSUE_TYPES.includes(type))
6
9
  throw new ConfigurationError(`Invalid issue type: ${type}`);
7
10
  });
11
+ const excludes = exclude.filter(exclude => !incl.includes(exclude));
12
+ const includes = include.filter(include => !excl.includes(include));
8
13
  if (cliArgs.dependencies) {
9
- cliArgs.include = [
10
- ...cliArgs.include,
11
- 'dependencies',
12
- 'optionalPeerDependencies',
13
- 'unlisted',
14
- 'binaries',
15
- 'unresolved',
16
- ];
14
+ incl = [...incl, 'dependencies', 'optionalPeerDependencies', 'unlisted', 'binaries', 'unresolved'];
17
15
  }
18
16
  if (cliArgs.exports) {
19
17
  const exports = ['exports', 'nsExports', 'classMembers', 'types', 'nsTypes', 'enumMembers', 'duplicates'];
20
- cliArgs.include = [...cliArgs.include, ...exports];
18
+ incl = [...incl, ...exports];
21
19
  }
22
- const normalizedIncludesArg = cliArgs.include.map(value => value.split(',')).flat();
23
- const normalizedExcludesArg = cliArgs.exclude.map(value => value.split(',')).flat();
24
- const excludes = exclude.filter(exclude => !normalizedIncludesArg.includes(exclude));
25
- const includes = include.filter(include => !normalizedExcludesArg.includes(include));
26
- const _include = [normalizedIncludesArg, includes].flat();
27
- const _exclude = [normalizedExcludesArg, excludes].flat();
20
+ const _include = [...incl, ...includes];
21
+ const _exclude = [...excl, ...excludes];
28
22
  if (isProduction) {
29
23
  _exclude.push('devDependencies');
30
24
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "3.3.0";
1
+ export declare const version = "3.3.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '3.3.0';
1
+ export const version = '3.3.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "3.3.0",
3
+ "version": "3.3.2",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
package/schema.json CHANGED
@@ -75,6 +75,7 @@
75
75
  ]
76
76
  },
77
77
  "includeEntryExports": {
78
+ "title": "Include entry files when reporting unused exports",
78
79
  "type": "boolean"
79
80
  },
80
81
  "workspaces": {
@@ -187,6 +188,10 @@
187
188
  "title": "Dependencies from package.json to ignore",
188
189
  "examples": ["husky", "lint-staged"],
189
190
  "$ref": "#/definitions/list"
191
+ },
192
+ "includeEntryExports": {
193
+ "title": "Include entry files when reporting unused exports",
194
+ "type": "boolean"
190
195
  }
191
196
  }
192
197
  },