knip 2.14.1 → 2.14.3

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,10 @@
1
1
  import ts from 'typescript';
2
2
  import { DEFAULT_EXTENSIONS } from './constants.js';
3
3
  import { IGNORED_FILE_EXTENSIONS } from './constants.js';
4
+ import { isInModuleBlock } from './typescript/ast-helpers.js';
4
5
  import { createHosts } from './typescript/createHosts.js';
5
6
  import { getImportsAndExports } from './typescript/getImportsAndExports.js';
7
+ import { isMaybePackageName } from './util/modules.js';
6
8
  import { extname, isInNodeModules } from './util/path.js';
7
9
  import { timerify } from './util/Performance.js';
8
10
  const baseCompilerOptions = {
@@ -122,7 +124,7 @@ export class ProjectPrincipal {
122
124
  }
123
125
  }
124
126
  else {
125
- if (/^(@|[a-z])/.test(specifier)) {
127
+ if (isMaybePackageName(specifier)) {
126
128
  external.add(specifier);
127
129
  }
128
130
  else {
@@ -161,6 +163,9 @@ export class ProjectPrincipal {
161
163
  hasReferences.external = true;
162
164
  }
163
165
  }
166
+ if (!hasReferences.external && hasReferences.internal) {
167
+ hasReferences.external = isInModuleBlock(exportedItem.node);
168
+ }
164
169
  return hasReferences;
165
170
  }
166
171
  findUnusedMembers(filePath, members) {
@@ -33,6 +33,9 @@ const findJestDependencies = async (configFilePath, { cwd, manifest }) => {
33
33
  const transform = config.transform
34
34
  ? Object.values(config.transform).map(transform => (typeof transform === 'string' ? transform : transform[0]))
35
35
  : [];
36
+ const moduleNameMapper = config.moduleNameMapper
37
+ ? Object.values(config.moduleNameMapper).map(mapper => (typeof mapper === 'string' ? mapper : mapper[0]))
38
+ : [];
36
39
  return [
37
40
  ...presets,
38
41
  ...environments,
@@ -41,6 +44,7 @@ const findJestDependencies = async (configFilePath, { cwd, manifest }) => {
41
44
  ...setupFiles,
42
45
  ...setupFilesAfterEnv,
43
46
  ...transform,
47
+ ...moduleNameMapper,
44
48
  ].map(replaceRootDir);
45
49
  };
46
50
  export const findDependencies = timerify(findJestDependencies);
@@ -8,8 +8,11 @@ export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABL
8
8
  export const CONFIG_FILE_PATTERNS = ['tsconfig.json'];
9
9
  const findTypeScriptDependencies = async (configFilePath) => {
10
10
  const config = await load(configFilePath);
11
- const extend = config?.extends ? [config.extends].flat().filter(extend => !isInternal(extend)) : [];
12
- const plugins = compact(config?.compilerOptions?.plugins?.map(plugin => plugin.name) ?? []);
13
- return [...extend, ...plugins];
11
+ if (!config)
12
+ return [];
13
+ const extend = config.extends ? [config.extends].flat().filter(extend => !isInternal(extend)) : [];
14
+ const plugins = compact(config.compilerOptions?.plugins?.map(plugin => plugin.name) ?? []);
15
+ const importHelpers = config.compilerOptions?.importHelpers ? ['tslib'] : [];
16
+ return [...extend, ...plugins, ...importHelpers];
14
17
  };
15
18
  export const findDependencies = timerify(findTypeScriptDependencies);
@@ -23,4 +23,5 @@ export declare function stripQuotes(name: string): string;
23
23
  export declare function findAncestor<T>(node: ts.Node | undefined, callback: (element: ts.Node) => boolean | 'STOP'): T | undefined;
24
24
  export declare function findDescendants<T>(node: ts.Node | undefined, callback: (element: ts.Node) => boolean | 'STOP'): T[];
25
25
  export declare const isDeclarationFileExtension: (extension: string) => boolean;
26
+ export declare const isInModuleBlock: (node: ts.Node) => boolean;
26
27
  export {};
@@ -92,3 +92,12 @@ export function findDescendants(node, callback) {
92
92
  return results;
93
93
  }
94
94
  export const isDeclarationFileExtension = (extension) => extension === '.d.ts' || extension === '.d.mts' || extension === '.d.cts';
95
+ export const isInModuleBlock = (node) => {
96
+ node = node?.parent;
97
+ while (node) {
98
+ if (ts.isModuleBlock(node))
99
+ return true;
100
+ node = node.parent;
101
+ }
102
+ return false;
103
+ };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.14.1";
1
+ export declare const version = "2.14.3";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.14.1';
1
+ export const version = '2.14.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.14.1",
3
+ "version": "2.14.3",
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",
@@ -57,7 +57,7 @@
57
57
  "summary": "^2.1.0",
58
58
  "typescript": "^5.0.2",
59
59
  "zod": "^3.20.6",
60
- "zod-validation-error": "1.3.0"
60
+ "zod-validation-error": "1.3.1"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@jest/types": "29.5.0",
@@ -70,14 +70,14 @@
70
70
  "@types/node": "20.3.1",
71
71
  "@types/npmcli__map-workspaces": "3.0.1",
72
72
  "@types/webpack": "5.28.1",
73
- "@typescript-eslint/eslint-plugin": "5.59.11",
74
- "@typescript-eslint/parser": "5.59.11",
73
+ "@typescript-eslint/eslint-plugin": "5.60.0",
74
+ "@typescript-eslint/parser": "5.60.0",
75
75
  "c8": "8.0.0",
76
76
  "eslint": "8.42.0",
77
77
  "eslint-import-resolver-typescript": "3.5.5",
78
78
  "eslint-plugin-import": "2.27.5",
79
- "eslint-plugin-n": "16.0.0",
80
- "glob": "10.2.7",
79
+ "eslint-plugin-n": "16.0.1",
80
+ "glob": "10.3.0",
81
81
  "prettier": "2.8.8",
82
82
  "release-it": "15.11.0",
83
83
  "remark-cli": "11.0.0",