knip 2.41.5 → 2.42.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.
@@ -4,6 +4,7 @@ import { SourceFileManager } from './typescript/SourceFileManager.js';
4
4
  import type { PrincipalOptions } from './PrincipalFactory.js';
5
5
  import type { SyncCompilers, AsyncCompilers } from './types/compilers.js';
6
6
  import type { ExportItem, ExportItemMember } from './types/exports.js';
7
+ import type { ProgramMaybe53 } from './typescript/SourceFile.js';
7
8
  import type { GlobbyFilterFunction } from 'globby';
8
9
  export declare class ProjectPrincipal {
9
10
  entryPaths: Set<string>;
@@ -20,7 +21,7 @@ export declare class ProjectPrincipal {
20
21
  compilerHost: ts.CompilerHost;
21
22
  resolveModuleNames: ReturnType<typeof createCustomModuleResolver>;
22
23
  lsFindReferences: ts.LanguageService['findReferences'];
23
- program?: ts.Program;
24
+ program?: ProgramMaybe53;
24
25
  };
25
26
  constructor({ compilerOptions, cwd, compilers, isGitIgnored }: PrincipalOptions);
26
27
  private createProgram;
@@ -111,7 +111,13 @@ export class ProjectPrincipal {
111
111
  if (!sourceFile)
112
112
  throw new Error(`Unable to find ${filePath}`);
113
113
  const skipExports = this.skipExportsAnalysis.has(filePath);
114
- const { imports, exports, scripts } = getImportsAndExports(sourceFile, { skipTypeOnly, skipExports });
114
+ const getResolvedModule = specifier => this.backend.program?.getResolvedModule
115
+ ? this.backend.program.getResolvedModule(sourceFile, specifier, undefined)
116
+ : sourceFile.resolvedModules?.get(specifier, undefined);
117
+ const { imports, exports, scripts } = getImportsAndExports(sourceFile, getResolvedModule, {
118
+ skipTypeOnly,
119
+ skipExports,
120
+ });
115
121
  const { internal, unresolved, external } = imports;
116
122
  const unresolvedImports = new Set();
117
123
  unresolved.forEach(specifier => {
@@ -3,6 +3,7 @@ import { getPackageNameFromModuleSpecifier } from '../../util/modules.js';
3
3
  import { isInternal, dirname, toAbsolute } from '../../util/path.js';
4
4
  import { load } from '../../util/plugin.js';
5
5
  import { _resolve } from '../../util/require.js';
6
+ import { getDependenciesFromConfig } from '../babel/index.js';
6
7
  import { fallback } from './fallback.js';
7
8
  import { PACKAGE_JSON_PATH } from './index.js';
8
9
  const getDependencies = (config) => {
@@ -11,19 +12,12 @@ const getDependencies = (config) => {
11
12
  extendsSpecifiers.push('eslint-config-prettier');
12
13
  const plugins = config.plugins ? config.plugins.map(resolvePluginSpecifier) : [];
13
14
  const parser = config.parser;
14
- const extraPlugins = config.parserOptions?.babelOptions?.plugins ?? [];
15
- const extraParsers = config.parserOptions?.babelOptions?.presets ?? [];
15
+ const babelDependencies = config.parserOptions?.babelOptions
16
+ ? getDependenciesFromConfig(config.parserOptions.babelOptions)
17
+ : [];
16
18
  const settings = config.settings ? getDependenciesFromSettings(config.settings) : [];
17
19
  const overrides = config.overrides ? [config.overrides].flat().flatMap(getDependencies) : [];
18
- return compact([
19
- ...extendsSpecifiers,
20
- ...plugins,
21
- ...extraPlugins,
22
- parser,
23
- ...extraParsers,
24
- ...settings,
25
- ...overrides,
26
- ]);
20
+ return compact([...extendsSpecifiers, ...plugins, parser, ...babelDependencies, ...settings, ...overrides]);
27
21
  };
28
22
  export const getDependenciesDeep = async (configFilePath, options, dependencies = new Set()) => {
29
23
  const addAll = (deps) => deps.forEach(dependency => dependencies.add(dependency));
@@ -15,4 +15,8 @@ export interface BoundSourceFile extends ts.SourceFile {
15
15
  scriptKind?: ts.ScriptKind;
16
16
  pragmas?: Map<string, PragmaMap | PragmaMap[]>;
17
17
  }
18
+ export interface ProgramMaybe53 extends ts.Program {
19
+ getResolvedModule?: (f: ts.SourceFile, moduleName: string, mode: ts.ResolutionMode) => ts.ResolvedModuleWithFailedLookupLocations | undefined;
20
+ }
21
+ export type GetResolvedModule = (name: string) => ts.ResolvedModuleWithFailedLookupLocations | undefined;
18
22
  export {};
@@ -1,5 +1,5 @@
1
1
  import ts from 'typescript';
2
- import type { BoundSourceFile } from './SourceFile.js';
2
+ import type { BoundSourceFile, GetResolvedModule } from './SourceFile.js';
3
3
  import type { ExportItems as Exports, ExportItem } from '../types/exports.js';
4
4
  import type { Imports } from '../types/imports.js';
5
5
  export type GetImportsAndExportsOptions = {
@@ -15,7 +15,7 @@ export type AddImportOptions = {
15
15
  export type AddExportOptions = ExportItem & {
16
16
  identifier: string;
17
17
  };
18
- export declare const getImportsAndExports: (sourceFile: BoundSourceFile, options: GetImportsAndExportsOptions) => {
18
+ export declare const getImportsAndExports: (sourceFile: BoundSourceFile, getResolvedModule: GetResolvedModule, options: GetImportsAndExportsOptions) => {
19
19
  imports: {
20
20
  internal: Imports;
21
21
  external: Set<string>;
@@ -13,7 +13,7 @@ const getVisitors = (sourceFile) => ({
13
13
  import: getImportVisitors(sourceFile),
14
14
  script: getScriptVisitors(sourceFile),
15
15
  });
16
- export const getImportsAndExports = (sourceFile, options) => {
16
+ export const getImportsAndExports = (sourceFile, getResolvedModule, options) => {
17
17
  const internalImports = new Map();
18
18
  const externalImports = new Set();
19
19
  const unresolvedImports = new Set();
@@ -50,7 +50,7 @@ export const getImportsAndExports = (sourceFile, options) => {
50
50
  const { specifier, symbol, identifier = '__anonymous', isReExport = false } = options;
51
51
  if (isBuiltin(specifier))
52
52
  return;
53
- const module = sourceFile.resolvedModules?.get(specifier, undefined);
53
+ const module = getResolvedModule(specifier);
54
54
  if (module?.resolvedModule) {
55
55
  const filePath = module.resolvedModule.resolvedFileName;
56
56
  if (filePath) {
package/dist/util/fs.js CHANGED
@@ -34,7 +34,7 @@ export const parseJSON = async (filePath, contents) => {
34
34
  return JSON.parse(stripJsonComments(contents, { trailingCommas: true }));
35
35
  }
36
36
  catch (error) {
37
- throw new LoaderError(`Error loading ${filePath}`, { cause: error });
37
+ throw new LoaderError(`Error parsing ${filePath}`, { cause: error });
38
38
  }
39
39
  };
40
40
  export const parseYAML = async (contents) => {
@@ -1,2 +1,3 @@
1
+ /// <reference types="node" resolution-mode="require"/>
1
2
  declare let parseArgs: typeof import('node:util').parseArgs;
2
3
  export { parseArgs };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.41.5";
1
+ export declare const version = "2.42.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.41.5';
1
+ export const version = '2.42.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.41.5",
3
+ "version": "2.42.0",
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",
@@ -46,11 +46,11 @@
46
46
  "@npmcli/map-workspaces": "^3.0.4",
47
47
  "@pkgjs/parseargs": "0.11.0",
48
48
  "@pnpm/logger": "5.0.0",
49
- "@pnpm/workspace.pkgs-graph": "2.0.10",
49
+ "@pnpm/workspace.pkgs-graph": "2.0.11",
50
50
  "@snyk/github-codeowners": "^1.1.0",
51
51
  "chalk": "^5.2.0",
52
52
  "easy-table": "^1.2.0",
53
- "fast-glob": "^3.2.12",
53
+ "fast-glob": "3.3.2",
54
54
  "globby": "^13.1.3",
55
55
  "jiti": "1.21.0",
56
56
  "js-yaml": "^4.1.0",
@@ -67,30 +67,30 @@
67
67
  "@jest/types": "29.6.3",
68
68
  "@npmcli/package-json": "5.0.0",
69
69
  "@release-it/bumper": "5.1.0",
70
- "@swc/cli": "0.1.62",
71
- "@swc/core": "1.3.95",
72
- "@types/eslint": "8.44.6",
73
- "@types/js-yaml": "4.0.8",
74
- "@types/micromatch": "4.0.4",
75
- "@types/minimist": "1.2.4",
76
- "@types/node": "20.8.10",
77
- "@types/npmcli__map-workspaces": "3.0.3",
78
- "@types/pkgjs__parseargs": "0.10.2",
79
- "@types/webpack": "5.28.4",
80
- "@typescript-eslint/eslint-plugin": "6.9.1",
81
- "@typescript-eslint/parser": "6.9.1",
70
+ "@swc/cli": "0.1.63",
71
+ "@swc/core": "1.3.99",
72
+ "@types/eslint": "8.44.7",
73
+ "@types/js-yaml": "4.0.9",
74
+ "@types/micromatch": "4.0.6",
75
+ "@types/minimist": "1.2.5",
76
+ "@types/node": "20.9.4",
77
+ "@types/npmcli__map-workspaces": "3.0.4",
78
+ "@types/pkgjs__parseargs": "0.10.3",
79
+ "@types/webpack": "5.28.5",
80
+ "@typescript-eslint/eslint-plugin": "6.12.0",
81
+ "@typescript-eslint/parser": "6.12.0",
82
82
  "c8": "8.0.1",
83
- "eslint": "8.52.0",
83
+ "eslint": "8.54.0",
84
84
  "eslint-import-resolver-typescript": "3.6.1",
85
85
  "eslint-plugin-import": "2.29.0",
86
- "eslint-plugin-n": "16.2.0",
87
- "playwright": "1.39.0",
88
- "prettier": "3.0.3",
86
+ "eslint-plugin-n": "16.3.1",
87
+ "playwright": "1.40.0",
88
+ "prettier": "3.1.0",
89
89
  "release-it": "16.2.1",
90
90
  "remark-cli": "12.0.0",
91
91
  "remark-preset-webpro": "1.0.0",
92
92
  "tsx": "3.14.0",
93
- "type-fest": "4.6.0"
93
+ "type-fest": "4.8.2"
94
94
  },
95
95
  "engines": {
96
96
  "node": ">=16.17.0 <17 || >=18.6.0"