knip 2.12.2 → 2.12.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.
- package/dist/binaries/index.js +1 -3
- package/dist/binaries/util.js +6 -3
- package/dist/index.js +4 -4
- package/dist/plugins/eslint/helpers.js +5 -3
- package/dist/typescript/getImportsAndExports.js +4 -1
- package/dist/util/modules.d.ts +2 -1
- package/dist/util/modules.js +3 -0
- package/dist/util/require.js +5 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/binaries/index.js
CHANGED
|
@@ -12,9 +12,7 @@ const getDependenciesFromScripts = (npmScripts, options = {}) => {
|
|
|
12
12
|
return compact(results.map(identifier => {
|
|
13
13
|
if (isBinary(identifier) || isInternal(identifier))
|
|
14
14
|
return identifier;
|
|
15
|
-
|
|
16
|
-
if (!packageName.startsWith('.'))
|
|
17
|
-
return packageName;
|
|
15
|
+
return getPackageNameFromModuleSpecifier(identifier);
|
|
18
16
|
}));
|
|
19
17
|
};
|
|
20
18
|
export const _getDependenciesFromScripts = timerify(getDependenciesFromScripts);
|
package/dist/binaries/util.js
CHANGED
|
@@ -6,10 +6,13 @@ export const tryResolveFilePath = (cwd, specifier, acceptModuleSpecifier) => {
|
|
|
6
6
|
const filePath = join(cwd, specifier);
|
|
7
7
|
if (!isInNodeModules(filePath)) {
|
|
8
8
|
const resolvedFilePath = _tryResolve(filePath, cwd);
|
|
9
|
-
if (resolvedFilePath)
|
|
9
|
+
if (resolvedFilePath) {
|
|
10
10
|
return [resolvedFilePath];
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
else if (acceptModuleSpecifier) {
|
|
13
|
+
const packageName = getPackageNameFromModuleSpecifier(specifier);
|
|
14
|
+
return packageName ? [packageName] : [];
|
|
15
|
+
}
|
|
13
16
|
}
|
|
14
17
|
else {
|
|
15
18
|
return [getPackageNameFromFilePath(specifier)];
|
package/dist/index.js
CHANGED
|
@@ -63,10 +63,10 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
63
63
|
const packageName = isInNodeModules(specifier)
|
|
64
64
|
? getPackageNameFromFilePath(specifier)
|
|
65
65
|
: getPackageNameFromModuleSpecifier(specifier);
|
|
66
|
-
const isHandled = deputy.maybeAddReferencedExternalDependency(workspace, packageName);
|
|
66
|
+
const isHandled = packageName && deputy.maybeAddReferencedExternalDependency(workspace, packageName);
|
|
67
67
|
if (!isHandled)
|
|
68
68
|
collector.addIssue({ type: 'unlisted', filePath: containingFilePath, symbol: specifier });
|
|
69
|
-
if (specifier !== packageName) {
|
|
69
|
+
if (packageName && specifier !== packageName) {
|
|
70
70
|
const otherWorkspace = chief.findWorkspaceByPackageName(packageName);
|
|
71
71
|
if (otherWorkspace) {
|
|
72
72
|
const filePath = _resolveSpecifier(otherWorkspace.dir, specifier);
|
|
@@ -194,7 +194,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
194
194
|
exportedSymbols.set(filePath, exported);
|
|
195
195
|
for (const [specifierFilePath, importItems] of internal.entries()) {
|
|
196
196
|
const packageName = getPackageNameFromModuleSpecifier(importItems.specifier);
|
|
197
|
-
if (chief.localWorkspaces.has(packageName))
|
|
197
|
+
if (packageName && chief.localWorkspaces.has(packageName))
|
|
198
198
|
external.add(packageName);
|
|
199
199
|
if (!importedSymbols.has(specifierFilePath)) {
|
|
200
200
|
importedSymbols.set(specifierFilePath, importItems);
|
|
@@ -220,7 +220,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
220
220
|
});
|
|
221
221
|
external.forEach(specifier => {
|
|
222
222
|
const packageName = getPackageNameFromModuleSpecifier(specifier);
|
|
223
|
-
const isHandled = deputy.maybeAddReferencedExternalDependency(workspace, packageName);
|
|
223
|
+
const isHandled = packageName && deputy.maybeAddReferencedExternalDependency(workspace, packageName);
|
|
224
224
|
if (!isHandled)
|
|
225
225
|
collector.addIssue({ type: 'unlisted', filePath, symbol: specifier });
|
|
226
226
|
});
|
|
@@ -57,10 +57,12 @@ const resolveExtendsSpecifier = (specifier) => {
|
|
|
57
57
|
.replace(/\/(eslint-)?(recommended.*|strict|all)$/, '');
|
|
58
58
|
if (/eslint-(config|plugin)-/.test(strippedSpecifier))
|
|
59
59
|
return strippedSpecifier;
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
60
|
+
const packageName = getPackageNameFromModuleSpecifier(strippedSpecifier);
|
|
61
|
+
if (!packageName)
|
|
62
62
|
return;
|
|
63
|
-
|
|
63
|
+
if (packageName === 'eslint')
|
|
64
|
+
return;
|
|
65
|
+
return resolvePackageName(specifier.startsWith('plugin:') ? 'eslint-plugin' : 'eslint-config', packageName);
|
|
64
66
|
};
|
|
65
67
|
const getDependenciesFromSettings = (settings = {}) => {
|
|
66
68
|
return compact(Object.entries(settings).flatMap(([settingKey, settings]) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isBuiltin } from 'node:module';
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { getOrSet } from '../util/map.js';
|
|
4
|
+
import { isMaybePackageName } from '../util/modules.js';
|
|
4
5
|
import { isInNodeModules } from '../util/path.js';
|
|
5
6
|
import { isDeclarationFileExtension, isAccessExpression, getAccessExpressionName } from './ast-helpers.js';
|
|
6
7
|
import getExportVisitors from './visitors/exports/index.js';
|
|
@@ -56,7 +57,9 @@ export const getImportsAndExports = (sourceFile, options) => {
|
|
|
56
57
|
if (!isInNodeModules(filePath)) {
|
|
57
58
|
addInternalImport({ identifier, specifier, symbol, filePath, isDynamic, isReExport });
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
+
if (!isMaybePackageName(specifier))
|
|
61
|
+
return;
|
|
62
|
+
if (isDeclarationFileExtension(module.resolvedModule.extension)) {
|
|
60
63
|
externalImports.add(specifier);
|
|
61
64
|
}
|
|
62
65
|
else {
|
package/dist/util/modules.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PackageJson } from '@npmcli/package-json';
|
|
2
|
-
export declare const getPackageNameFromModuleSpecifier: (moduleSpecifier: string) => string;
|
|
2
|
+
export declare const getPackageNameFromModuleSpecifier: (moduleSpecifier: string) => string | undefined;
|
|
3
3
|
export declare const getPackageNameFromFilePath: (value: string) => string;
|
|
4
|
+
export declare const isMaybePackageName: (specifier: string) => boolean;
|
|
4
5
|
export declare const isDefinitelyTyped: (packageName: string) => boolean;
|
|
5
6
|
export declare const getDefinitelyTypedFor: (packageName: string) => string;
|
|
6
7
|
export declare const getPackageFromDefinitelyTyped: (typedDependency: string) => string;
|
package/dist/util/modules.js
CHANGED
|
@@ -2,6 +2,8 @@ import { _glob } from './glob.js';
|
|
|
2
2
|
import { getStringValues } from './object.js';
|
|
3
3
|
import { toPosix } from './path.js';
|
|
4
4
|
export const getPackageNameFromModuleSpecifier = (moduleSpecifier) => {
|
|
5
|
+
if (!isMaybePackageName(moduleSpecifier))
|
|
6
|
+
return;
|
|
5
7
|
const parts = moduleSpecifier.split('/').slice(0, 2);
|
|
6
8
|
return moduleSpecifier.startsWith('@') ? parts.join('/') : parts[0];
|
|
7
9
|
};
|
|
@@ -11,6 +13,7 @@ export const getPackageNameFromFilePath = (value) => {
|
|
|
11
13
|
return match[match.length - 1];
|
|
12
14
|
return value;
|
|
13
15
|
};
|
|
16
|
+
export const isMaybePackageName = (specifier) => /^@?[a-z0-9]/.test(specifier);
|
|
14
17
|
export const isDefinitelyTyped = (packageName) => packageName.startsWith('@types/');
|
|
15
18
|
export const getDefinitelyTypedFor = (packageName) => {
|
|
16
19
|
if (isDefinitelyTyped(packageName))
|
package/dist/util/require.js
CHANGED
|
@@ -21,8 +21,11 @@ const resolveSpecifier = (dir, specifier) => {
|
|
|
21
21
|
return toPosix(require.resolve(specifier));
|
|
22
22
|
}
|
|
23
23
|
catch {
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const packageName = getPackageNameFromModuleSpecifier(specifier);
|
|
25
|
+
if (packageName) {
|
|
26
|
+
const relativeSpecifier = specifier.replace(packageName, '.');
|
|
27
|
+
return tryResolve(join(dir, relativeSpecifier), dir);
|
|
28
|
+
}
|
|
26
29
|
}
|
|
27
30
|
};
|
|
28
31
|
export const _require = timerify(require);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.12.
|
|
1
|
+
export declare const version = "2.12.3";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.12.
|
|
1
|
+
export const version = '2.12.3';
|
package/package.json
CHANGED