knip 2.1.1 → 2.1.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.
- package/README.md +6 -2
- package/dist/binaries/bash-parser.js +9 -2
- package/dist/cli.js +4 -7
- package/dist/index.js +2 -2
- package/dist/principal-factory.d.ts +1 -1
- package/dist/principal-factory.js +9 -10
- package/dist/util/errors.d.ts +1 -0
- package/dist/util/errors.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,14 +72,15 @@ file. Let's say you are using `.ts` files excusively and have all source files o
|
|
|
72
72
|
The `entry` files target the starting point(s) to resolve the rest of the imported code. The `project` files should
|
|
73
73
|
contain all files to match against the files resolved from the entry files, including potentially unused files.
|
|
74
74
|
|
|
75
|
-
Places where Knip looks for configuration:
|
|
75
|
+
Places where Knip looks for configuration (ordered by priority):
|
|
76
76
|
|
|
77
77
|
- `knip.json`
|
|
78
78
|
- `knip.jsonc`
|
|
79
79
|
- `.knip.json`
|
|
80
80
|
- `.knip.jsonc`
|
|
81
|
-
- `knip.js`
|
|
82
81
|
- `knip.ts`
|
|
82
|
+
- `knip.js`
|
|
83
|
+
- `package.json#knip`
|
|
83
84
|
|
|
84
85
|
So you can use a dynamic `knip.ts` with TypeScript if you prefer:
|
|
85
86
|
|
|
@@ -510,6 +511,9 @@ Such variables and types can be marked with the JSDoc `@public` tag:
|
|
|
510
511
|
*/
|
|
511
512
|
|
|
512
513
|
export const merge = function () {};
|
|
514
|
+
|
|
515
|
+
/** @public */
|
|
516
|
+
export const split = function () {};
|
|
513
517
|
```
|
|
514
518
|
|
|
515
519
|
Knip does not report public exports and types as unused.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import parse from 'bash-parser';
|
|
2
2
|
import parseArgs from 'minimist';
|
|
3
|
+
import { debugLogObject } from '../util/debug.js';
|
|
3
4
|
import * as FallbackResolver from './resolvers/fallback.js';
|
|
4
5
|
import * as KnownResolvers from './resolvers/index.js';
|
|
5
6
|
const spawningBinaries = ['cross-env', 'dotenv'];
|
|
@@ -52,6 +53,12 @@ export const getBinariesFromScript = (script, { cwd, manifest, knownGlobalsOnly
|
|
|
52
53
|
return [];
|
|
53
54
|
}
|
|
54
55
|
});
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
try {
|
|
57
|
+
const parsed = parse(script);
|
|
58
|
+
return parsed?.commands ? getBinariesFromNodes(parsed.commands) : [];
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
debugLogObject('Bash parser error', error);
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
57
64
|
};
|
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import './util/register.js';
|
|
|
3
3
|
import prettyMilliseconds from 'pretty-ms';
|
|
4
4
|
import reporters from './reporters/index.js';
|
|
5
5
|
import parsedArgs, { helpText } from './util/cli-arguments.js';
|
|
6
|
-
import {
|
|
6
|
+
import { isKnownError, ConfigurationError } from './util/errors.js';
|
|
7
7
|
import { _load } from './util/loader.js';
|
|
8
8
|
import { cwd, resolve } from './util/path.js';
|
|
9
9
|
import { Performance } from './util/performance.js';
|
|
@@ -46,15 +46,12 @@ const run = async () => {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
catch (error) {
|
|
49
|
-
if (error instanceof
|
|
50
|
-
console.error(error.message + '\n');
|
|
51
|
-
console.log(helpText);
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
else if (error instanceof LoaderError) {
|
|
49
|
+
if (error instanceof Error && isKnownError(error)) {
|
|
55
50
|
console.error(error.message);
|
|
56
51
|
if (error.cause instanceof Error)
|
|
57
52
|
console.error('Reason:', error.cause.message);
|
|
53
|
+
if (error instanceof ConfigurationError)
|
|
54
|
+
console.log('\n' + helpText);
|
|
58
55
|
process.exit(1);
|
|
59
56
|
}
|
|
60
57
|
throw error;
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { IssueCollector } from './issue-collector.js';
|
|
|
6
6
|
import { PrincipalFactory } from './principal-factory.js';
|
|
7
7
|
import { compact } from './util/array.js';
|
|
8
8
|
import { debugLogObject, debugLogArray, debugLog } from './util/debug.js';
|
|
9
|
-
import {
|
|
9
|
+
import { LoaderError } from './util/errors.js';
|
|
10
10
|
import { findFile } from './util/fs.js';
|
|
11
11
|
import { _glob } from './util/glob.js';
|
|
12
12
|
import { getPackageNameFromFilePath, getPackageNameFromModuleSpecifier } from './util/modules.js';
|
|
@@ -38,7 +38,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
38
38
|
const manifestPath = isRoot ? chief.manifestPath : findFile(dir, 'package.json');
|
|
39
39
|
const manifest = isRoot ? chief.manifest : manifestPath && _require(manifestPath);
|
|
40
40
|
if (!manifestPath || !manifest)
|
|
41
|
-
throw new
|
|
41
|
+
throw new LoaderError(`Unable to load package.json for ${name}`);
|
|
42
42
|
deputy.addWorkspace({ name, dir, manifestPath, manifest, ignoreDependencies });
|
|
43
43
|
const compilerOptions = await loadCompilerOptions(join(dir, tsConfigFile ?? 'tsconfig.json'));
|
|
44
44
|
const principal = factory.getPrincipal({ cwd: dir, report: report, paths, compilerOptions, compilers });
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { ProjectPrincipal } from './project-principal.js';
|
|
2
2
|
import { join, isAbsolute } from './util/path.js';
|
|
3
|
-
const mergePaths = (cwd, compilerOptions
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
paths[key] = mergedPaths[key].map(entry => isAbsolute(entry) ? entry : isAbsolute(baseUrl) ? join(baseUrl, entry) : join(cwd, baseUrl, entry));
|
|
8
|
-
return paths;
|
|
3
|
+
const mergePaths = (cwd, compilerOptions, paths = {}) => {
|
|
4
|
+
const overridePaths = Object.keys(paths).reduce((overridePaths, key) => {
|
|
5
|
+
overridePaths[key] = paths[key].map(entry => (isAbsolute(entry) ? entry : join(cwd, entry)));
|
|
6
|
+
return overridePaths;
|
|
9
7
|
}, {});
|
|
8
|
+
compilerOptions.paths = { ...compilerOptions.paths, ...overridePaths };
|
|
10
9
|
return compilerOptions;
|
|
11
10
|
};
|
|
12
11
|
export class PrincipalFactory {
|
|
@@ -26,22 +25,22 @@ export class PrincipalFactory {
|
|
|
26
25
|
const workspacePaths = compilerOptions?.paths ? Object.keys(compilerOptions.paths) : [];
|
|
27
26
|
const principal = Array.from(this.principals).find(principal => {
|
|
28
27
|
if (compilerOptions.baseUrl === principal.principal.compilerOptions.baseUrl) {
|
|
29
|
-
return workspacePaths.every(p => !principal.
|
|
28
|
+
return workspacePaths.every(p => !principal.pathKeys.has(p));
|
|
30
29
|
}
|
|
31
30
|
return !compilerOptions.baseUrl;
|
|
32
31
|
});
|
|
33
32
|
return principal;
|
|
34
33
|
}
|
|
35
34
|
linkPrincipal(principal, cwd, paths) {
|
|
36
|
-
Object.keys(paths ?? {}).forEach(p => principal.
|
|
35
|
+
Object.keys(paths ?? {}).forEach(p => principal.pathKeys.add(p));
|
|
37
36
|
principal.principal.compilerOptions.paths = { ...principal.principal.compilerOptions.paths, ...paths };
|
|
38
37
|
principal.cwds.add(cwd);
|
|
39
38
|
}
|
|
40
39
|
addNewPrincipal({ cwd, compilerOptions, report, compilers }) {
|
|
41
40
|
const principal = new ProjectPrincipal({ cwd, compilerOptions, report, compilers });
|
|
42
|
-
const
|
|
41
|
+
const pathKeys = new Set(Object.keys(compilerOptions?.paths ?? {}));
|
|
43
42
|
compilerOptions.baseUrl = join(cwd, compilerOptions.baseUrl ?? '.');
|
|
44
|
-
this.principals.add({ principal, cwds: new Set([cwd]),
|
|
43
|
+
this.principals.add({ principal, cwds: new Set([cwd]), pathKeys });
|
|
45
44
|
return principal;
|
|
46
45
|
}
|
|
47
46
|
getPrincipals() {
|
package/dist/util/errors.d.ts
CHANGED
package/dist/util/errors.js
CHANGED
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.1.
|
|
1
|
+
export declare const version = "2.1.2";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.1.
|
|
1
|
+
export const version = '2.1.2';
|
package/package.json
CHANGED