knip 2.32.4 → 2.33.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/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { ProjectPrincipal } from './ProjectPrincipal.js';
9
9
  import { compact } from './util/array.js';
10
10
  import { debugLogObject, debugLogArray, debugLog } from './util/debug.js';
11
11
  import { _glob, negate } from './util/glob.js';
12
- import { getEntryPathFromManifest, getPackageNameFromFilePath, getPackageNameFromModuleSpecifier, } from './util/modules.js';
12
+ import { getEntryPathFromManifest, getPackageNameFromFilePath, getPackageNameFromModuleSpecifier, normalizeSpecifierFromFilePath, } from './util/modules.js';
13
13
  import { dirname, isInNodeModules, join, isInternal } from './util/path.js';
14
14
  import { fromBinary, isBinary } from './util/protocols.js';
15
15
  import { _resolveSpecifier } from './util/require.js';
@@ -67,7 +67,7 @@ export const main = async (unresolvedConfiguration) => {
67
67
  if (packageName && specifier !== packageName) {
68
68
  const otherWorkspace = chief.availableWorkspaceManifests.find(w => w.manifest.name === packageName);
69
69
  if (otherWorkspace) {
70
- const filePath = _resolveSpecifier(otherWorkspace.dir, specifier);
70
+ const filePath = _resolveSpecifier(otherWorkspace.dir, normalizeSpecifierFromFilePath(specifier));
71
71
  if (filePath) {
72
72
  principal.addEntryPath(filePath, { skipExportsAnalysis: true });
73
73
  }
@@ -22,7 +22,7 @@ export class SourceFileManager {
22
22
  const contents = ts.sys.readFile(filePath);
23
23
  if (typeof contents !== 'string') {
24
24
  if (isInternal(filePath))
25
- throw new Error(`Unable to read ${filePath}`);
25
+ debugLog(`Unable to read ${filePath}`);
26
26
  return this.createSourceFile(filePath, '');
27
27
  }
28
28
  const ext = extname(filePath);
@@ -1,4 +1,4 @@
1
- import { parseArgs } from 'node:util';
1
+ import { parseArgs } from './parseArgs.js';
2
2
  export const helpText = `✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects
3
3
 
4
4
  Usage: knip [options]
@@ -1,6 +1,7 @@
1
1
  import type { PackageJson } from '@npmcli/package-json';
2
2
  export declare const getPackageNameFromModuleSpecifier: (moduleSpecifier: string) => string | undefined;
3
3
  export declare const getPackageNameFromFilePath: (value: string) => string;
4
+ export declare const normalizeSpecifierFromFilePath: (value: string) => string;
4
5
  export declare const isMaybePackageName: (specifier: string) => boolean;
5
6
  export declare const isDefinitelyTyped: (packageName: string) => boolean;
6
7
  export declare const getDefinitelyTypedFor: (packageName: string) => string;
@@ -13,6 +13,12 @@ export const getPackageNameFromFilePath = (value) => {
13
13
  return match[match.length - 1];
14
14
  return value;
15
15
  };
16
+ export const normalizeSpecifierFromFilePath = (value) => {
17
+ const match = toPosix(value).match(/.*\/node_modules\/(.+)/);
18
+ if (match)
19
+ return match[match.length - 1];
20
+ return value;
21
+ };
16
22
  export const isMaybePackageName = (specifier) => /^@?[a-z0-9]/.test(specifier);
17
23
  export const isDefinitelyTyped = (packageName) => packageName.startsWith('@types/');
18
24
  export const getDefinitelyTypedFor = (packageName) => {
@@ -41,12 +47,7 @@ export const getEntryPathFromManifest = (cwd, dir, manifest) => {
41
47
  Object.values(bin).forEach(bin => entryPaths.add(bin));
42
48
  }
43
49
  if (exports) {
44
- if (typeof exports === 'string') {
45
- entryPaths.add(exports);
46
- }
47
- else {
48
- getStringValues(exports).forEach(item => entryPaths.add(item));
49
- }
50
+ getStringValues(exports).forEach(item => entryPaths.add(item));
50
51
  }
51
52
  return _glob({ cwd, workingDir: dir, patterns: Array.from(entryPaths) });
52
53
  };
@@ -14,6 +14,8 @@ export const getValuesByKeyDeep = (obj, key) => {
14
14
  return objects;
15
15
  };
16
16
  export const getStringValues = (obj) => {
17
+ if (typeof obj === 'string')
18
+ return [obj];
17
19
  let values = [];
18
20
  for (const prop in obj) {
19
21
  if (obj[prop]) {
@@ -0,0 +1,2 @@
1
+ declare let parseArgs: typeof import('node:util').parseArgs;
2
+ export { parseArgs };
@@ -0,0 +1,8 @@
1
+ let parseArgs;
2
+ try {
3
+ parseArgs = (await import('node:util')).parseArgs;
4
+ }
5
+ catch (error) {
6
+ parseArgs = (await import('@pkgjs/parseargs')).parseArgs;
7
+ }
8
+ export { parseArgs };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.32.4";
1
+ export declare const version = "2.33.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.32.4';
1
+ export const version = '2.33.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.32.4",
3
+ "version": "2.33.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",
@@ -44,8 +44,9 @@
44
44
  "dependencies": {
45
45
  "@ericcornelissen/bash-parser": "^0.5.2",
46
46
  "@npmcli/map-workspaces": "^3.0.4",
47
+ "@pkgjs/parseargs": "0.11.0",
47
48
  "@pnpm/logger": "5.0.0",
48
- "@pnpm/workspace.pkgs-graph": "2.0.6",
49
+ "@pnpm/workspace.pkgs-graph": "2.0.7",
49
50
  "@snyk/github-codeowners": "^1.1.0",
50
51
  "chalk": "^5.2.0",
51
52
  "easy-table": "^1.2.0",
@@ -74,6 +75,7 @@
74
75
  "@types/minimist": "1.2.3",
75
76
  "@types/node": "20.8.3",
76
77
  "@types/npmcli__map-workspaces": "3.0.2",
78
+ "@types/pkgjs__parseargs": "0.10.1",
77
79
  "@types/webpack": "5.28.3",
78
80
  "@typescript-eslint/eslint-plugin": "6.7.4",
79
81
  "@typescript-eslint/parser": "6.7.4",