knip 2.25.0 → 2.25.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.
@@ -1,8 +1,7 @@
1
1
  /// <reference types="npmcli__package-json" />
2
2
  import type { Workspace } from './ConfigurationChief.js';
3
3
  import type { ConfigurationHints, Issue } from './types/issues.js';
4
- import type { WorkspaceManifests } from './types/workspace.js';
5
- import type { PeerDependencies, InstalledBinaries } from './types/workspace.js';
4
+ import type { WorkspaceManifests, HostDependencies, InstalledBinaries } from './types/workspace.js';
6
5
  import type { PackageJson } from '@npmcli/package-json';
7
6
  type Options = {
8
7
  isStrict: boolean;
@@ -12,7 +11,7 @@ export declare class DependencyDeputy {
12
11
  _manifests: WorkspaceManifests;
13
12
  referencedDependencies: Map<string, Set<string>>;
14
13
  referencedBinaries: Map<string, Set<string>>;
15
- peerDependencies: Map<string, PeerDependencies>;
14
+ hostDependencies: Map<string, HostDependencies>;
16
15
  installedBinaries: Map<string, InstalledBinaries>;
17
16
  ignoreBinaries: string[];
18
17
  ignoreDependencies: string[];
@@ -45,8 +44,8 @@ export declare class DependencyDeputy {
45
44
  getInstalledBinaries(workspaceName: string): InstalledBinaries | undefined;
46
45
  addReferencedDependency(workspaceName: string, packageName: string): void;
47
46
  addReferencedBinary(workspaceName: string, binaryName: string): void;
48
- addPeerDependencies(workspaceName: string, peerDependencies: Map<string, Set<string>>): void;
49
- getPeerDependenciesOf(workspaceName: string, dependency: string): string[];
47
+ addHostDependencies(workspaceName: string, hostDependencies: HostDependencies): void;
48
+ getHostDependenciesFor(workspaceName: string, dependency: string): string[];
50
49
  getPeerDependencies(workspaceName: string): string[];
51
50
  getOptionalPeerDependencies(workspaceName: string): string[];
52
51
  maybeAddReferencedExternalDependency(workspace: Workspace, packageName: string): boolean;
@@ -6,7 +6,7 @@ export class DependencyDeputy {
6
6
  _manifests = new Map();
7
7
  referencedDependencies;
8
8
  referencedBinaries;
9
- peerDependencies;
9
+ hostDependencies;
10
10
  installedBinaries;
11
11
  ignoreBinaries = [];
12
12
  ignoreDependencies = [];
@@ -14,7 +14,7 @@ export class DependencyDeputy {
14
14
  this.isStrict = isStrict;
15
15
  this.referencedDependencies = new Map();
16
16
  this.referencedBinaries = new Map();
17
- this.peerDependencies = new Map();
17
+ this.hostDependencies = new Map();
18
18
  this.installedBinaries = new Map();
19
19
  }
20
20
  addWorkspace({ name, dir, manifestPath, manifest, ignoreDependencies, ignoreBinaries, }) {
@@ -79,11 +79,11 @@ export class DependencyDeputy {
79
79
  }
80
80
  this.referencedBinaries.get(workspaceName)?.add(binaryName);
81
81
  }
82
- addPeerDependencies(workspaceName, peerDependencies) {
83
- this.peerDependencies.set(workspaceName, peerDependencies);
82
+ addHostDependencies(workspaceName, hostDependencies) {
83
+ this.hostDependencies.set(workspaceName, hostDependencies);
84
84
  }
85
- getPeerDependenciesOf(workspaceName, dependency) {
86
- return Array.from(this.peerDependencies.get(workspaceName)?.get(dependency) ?? []);
85
+ getHostDependenciesFor(workspaceName, dependency) {
86
+ return Array.from(this.hostDependencies.get(workspaceName)?.get(dependency) ?? []);
87
87
  }
88
88
  getPeerDependencies(workspaceName) {
89
89
  const manifest = this._manifests.get(workspaceName);
@@ -179,17 +179,19 @@ export class DependencyDeputy {
179
179
  const typedPackageName = getPackageFromDefinitelyTyped(typedDependency);
180
180
  if (IGNORE_DEFINITELY_TYPED.includes(typedPackageName))
181
181
  return true;
182
- const peerDependencies = this.getPeerDependenciesOf(workspaceName, typedPackageName);
183
- if (peerDependencies.length) {
184
- return !!peerDependencies.find(peerDependency => isReferencedDependency(peerDependency, true));
185
- }
182
+ const hostDependencies = [
183
+ ...this.getHostDependenciesFor(workspaceName, dependency),
184
+ ...this.getHostDependenciesFor(workspaceName, typedPackageName),
185
+ ];
186
+ if (hostDependencies.length)
187
+ return !!hostDependencies.find(host => isReferencedDependency(host, true));
186
188
  if (!referencedDependencies)
187
189
  return false;
188
190
  return referencedDependencies.has(typedPackageName);
189
191
  }
190
- const peerDependenciesOf = this.getPeerDependenciesOf(workspaceName, dependency);
191
- peerDependenciesOf.forEach(dep => (!peerDepRecs[dep] ? (peerDepRecs[dep] = 1) : peerDepRecs[dep]++));
192
- return peerDependenciesOf.some(peerDependency => isReferencedDependency(peerDependency, true));
192
+ const hostDependencies = this.getHostDependenciesFor(workspaceName, dependency);
193
+ hostDependencies.forEach(dep => (!peerDepRecs[dep] ? (peerDepRecs[dep] = 1) : peerDepRecs[dep]++));
194
+ return hostDependencies.some(peerDependency => isReferencedDependency(peerDependency, true));
193
195
  };
194
196
  const isNotReferencedDependency = (dependency) => !isReferencedDependency(dependency);
195
197
  const pd = this.getProductionDependencies(workspaceName);
@@ -51,6 +51,6 @@ export class PrincipalFactory {
51
51
  return principal;
52
52
  }
53
53
  getPrincipals() {
54
- return Array.from(this.principals).map(p => p.principal);
54
+ return Array.from(this.principals, p => p.principal);
55
55
  }
56
56
  }
@@ -1,6 +1,6 @@
1
1
  import type { Configuration, PluginName, WorkspaceConfiguration } from './types/config.js';
2
2
  import type { PackageJsonWithPlugins } from './types/plugins.js';
3
- import type { InstalledBinaries, PeerDependencies } from './types/workspace.js';
3
+ import type { InstalledBinaries, HostDependencies } from './types/workspace.js';
4
4
  type WorkspaceManagerOptions = {
5
5
  name: string;
6
6
  dir: string;
@@ -28,7 +28,7 @@ export declare class WorkspaceWorker {
28
28
  enabled: Record<PluginName, boolean>;
29
29
  enabledPlugins: PluginName[];
30
30
  referencedDependencies: ReferencedDependencies;
31
- peerDependencies: PeerDependencies;
31
+ hostDependencies: HostDependencies;
32
32
  installedBinaries: InstalledBinaries;
33
33
  constructor({ name, dir, cwd, config, manifest, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }: WorkspaceManagerOptions);
34
34
  init(): Promise<void>;
@@ -47,7 +47,7 @@ export declare class WorkspaceWorker {
47
47
  getIgnorePatterns(): string[];
48
48
  private findDependenciesByPlugins;
49
49
  findAllDependencies(): Promise<{
50
- peerDependencies: PeerDependencies;
50
+ hostDependencies: HostDependencies;
51
51
  installedBinaries: InstalledBinaries;
52
52
  referencedDependencies: ReferencedDependencies;
53
53
  enabledPlugins: ("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" | "githubActions" | "lintStaged" | "npmPackageJsonLint" | "releaseIt" | "semanticRelease" | "svelte")[];
@@ -20,7 +20,7 @@ export class WorkspaceWorker {
20
20
  enabled;
21
21
  enabledPlugins = [];
22
22
  referencedDependencies = new Set();
23
- peerDependencies = new Map();
23
+ hostDependencies = new Map();
24
24
  installedBinaries = new Map();
25
25
  constructor({ name, dir, cwd, config, manifest, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }) {
26
26
  this.name = name;
@@ -59,7 +59,7 @@ export class WorkspaceWorker {
59
59
  debugLogObject(`Enabled plugins (${this.name})`, enabledPluginNames);
60
60
  }
61
61
  async initReferencedDependencies() {
62
- const { dependencies, peerDependencies, installedBinaries } = await npm.findDependencies({
62
+ const { dependencies, hostDependencies, installedBinaries } = await npm.findDependencies({
63
63
  manifest: this.manifest,
64
64
  isProduction: this.isProduction,
65
65
  isStrict: this.isStrict,
@@ -68,7 +68,7 @@ export class WorkspaceWorker {
68
68
  });
69
69
  const filePath = join(this.dir, 'package.json');
70
70
  dependencies.forEach(dependency => this.referencedDependencies.add([filePath, dependency]));
71
- this.peerDependencies = peerDependencies;
71
+ this.hostDependencies = hostDependencies;
72
72
  this.installedBinaries = installedBinaries;
73
73
  }
74
74
  getConfigForPlugin(pluginName) {
@@ -235,7 +235,7 @@ export class WorkspaceWorker {
235
235
  async findAllDependencies() {
236
236
  await this.findDependenciesByPlugins();
237
237
  return {
238
- peerDependencies: this.peerDependencies,
238
+ hostDependencies: this.hostDependencies,
239
239
  installedBinaries: this.installedBinaries,
240
240
  referencedDependencies: this.referencedDependencies,
241
241
  enabledPlugins: this.enabledPlugins,
package/dist/index.js CHANGED
@@ -109,7 +109,7 @@ export const main = async (unresolvedConfiguration) => {
109
109
  await worker.init();
110
110
  const sharedGlobOptions = { cwd, workingDir: dir, gitignore, ignore: worker.getIgnorePatterns() };
111
111
  const entryPathsFromManifest = await getEntryPathFromManifest(cwd, dir, manifest);
112
- debugLogArray(`Found entry paths from manifest (${name})`, entryPathsFromManifest);
112
+ debugLogArray(`Found entry paths in package.json (${name})`, entryPathsFromManifest);
113
113
  principal.addEntryPaths(entryPathsFromManifest);
114
114
  if (isProduction) {
115
115
  {
@@ -166,8 +166,8 @@ export const main = async (unresolvedConfiguration) => {
166
166
  if (chief.resolvedConfigFilePath)
167
167
  principal.addEntryPath(chief.resolvedConfigFilePath, { skipExportsAnalysis: true });
168
168
  const dependencies = await worker.findAllDependencies();
169
- const { referencedDependencies, peerDependencies, installedBinaries, enabledPlugins } = dependencies;
170
- deputy.addPeerDependencies(name, peerDependencies);
169
+ const { referencedDependencies, hostDependencies, installedBinaries, enabledPlugins } = dependencies;
170
+ deputy.addHostDependencies(name, hostDependencies);
171
171
  deputy.setInstalledBinaries(name, installedBinaries);
172
172
  enabledPluginsStore.set(name, enabledPlugins);
173
173
  referencedDependencies.forEach(([containingFilePath, specifier]) => {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="npmcli__package-json" />
2
- import type { InstalledBinaries, PeerDependencies } from '../types/workspace.js';
2
+ import type { InstalledBinaries, HostDependencies } from '../types/workspace.js';
3
3
  import type { PackageJson } from '@npmcli/package-json';
4
4
  type Options = {
5
5
  manifest: PackageJson;
@@ -10,7 +10,7 @@ type Options = {
10
10
  };
11
11
  export declare const findDependencies: ({ manifest, isProduction, isStrict, dir, cwd }: Options) => Promise<{
12
12
  dependencies: string[];
13
- peerDependencies: PeerDependencies;
13
+ hostDependencies: HostDependencies;
14
14
  installedBinaries: InstalledBinaries;
15
15
  }>;
16
16
  export {};
@@ -3,7 +3,7 @@ import { timerify } from '../util/Performance.js';
3
3
  import { getPackageManifest } from './helpers.js';
4
4
  const findManifestDependencies = async ({ manifest, isProduction, isStrict, dir, cwd }) => {
5
5
  const scriptFilter = isProduction ? ['start', 'postinstall'] : [];
6
- const peerDependencies = new Map();
6
+ const hostDependencies = new Map();
7
7
  const scripts = Object.entries(manifest.scripts ?? {}).reduce((scripts, [scriptName, script]) => {
8
8
  if (script && (scriptFilter.length === 0 || scriptFilter.includes(scriptName))) {
9
9
  return [...scripts, script];
@@ -38,18 +38,18 @@ const findManifestDependencies = async ({ manifest, isProduction, isStrict, dir,
38
38
  });
39
39
  const packagePeerDependencies = Object.keys(manifest.peerDependencies ?? {});
40
40
  packagePeerDependencies.forEach(packagePeerDependency => {
41
- if (peerDependencies.has(packagePeerDependency)) {
42
- peerDependencies.get(packagePeerDependency)?.add(packageName);
41
+ if (hostDependencies.has(packagePeerDependency)) {
42
+ hostDependencies.get(packagePeerDependency)?.add(packageName);
43
43
  }
44
44
  else {
45
- peerDependencies.set(packagePeerDependency, new Set([packageName]));
45
+ hostDependencies.set(packagePeerDependency, new Set([packageName]));
46
46
  }
47
47
  });
48
48
  }
49
49
  }
50
50
  return {
51
51
  dependencies,
52
- peerDependencies,
52
+ hostDependencies,
53
53
  installedBinaries,
54
54
  };
55
55
  };
@@ -13,7 +13,7 @@ export default ({ report, issues, isShowProgress }) => {
13
13
  const issuesForType = isSet
14
14
  ? Array.from(issues[reportType])
15
15
  : reportType === 'duplicates'
16
- ? Object.values(issues[reportType]).map(Object.values).flat()
16
+ ? Object.values(issues[reportType]).flatMap(Object.values)
17
17
  : Object.values(issues[reportType]).map(issues => {
18
18
  const items = Object.values(issues);
19
19
  return { ...items[0], symbols: items.map(issue => issue.symbol) };
@@ -13,7 +13,7 @@ export default async ({ report, issues, options }) => {
13
13
  const json = {};
14
14
  const codeownersFilePath = resolve(opts.codeowners ?? '.github/CODEOWNERS');
15
15
  const codeownersEngine = isFile(codeownersFilePath) && OwnershipEngine.FromCodeownersFile(codeownersFilePath);
16
- const flatten = (issues) => Object.values(issues).map(Object.values).flat();
16
+ const flatten = (issues) => Object.values(issues).flatMap(Object.values);
17
17
  const initRow = (filePath) => {
18
18
  const file = relative(filePath);
19
19
  const row = {
@@ -12,6 +12,6 @@ type WorkspaceManifest = {
12
12
  ignoreBinaries: string[];
13
13
  };
14
14
  export type WorkspaceManifests = Map<string, WorkspaceManifest>;
15
- export type PeerDependencies = Map<string, Set<string>>;
15
+ export type HostDependencies = Map<string, Set<string>>;
16
16
  export type InstalledBinaries = Map<string, Set<string>>;
17
17
  export {};
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.25.0";
1
+ export declare const version = "2.25.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.25.0';
1
+ export const version = '2.25.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.25.0",
3
+ "version": "2.25.2",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://github.com/webpro/knip",
6
6
  "repository": "github:webpro/knip",