knip 5.30.1 → 5.30.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/dist/ConfigurationChief.d.ts +1 -1
- package/dist/ConfigurationChief.js +3 -3
- package/dist/index.js +2 -1
- package/dist/typescript/get-imports-and-exports.js +4 -2
- package/dist/typescript/resolve-module-names.js +1 -1
- package/dist/util/handle-dependency.js +11 -4
- package/dist/util/modules.d.ts +0 -7
- package/dist/util/modules.js +0 -24
- package/dist/util/package-json.d.ts +6 -0
- package/dist/util/package-json.js +24 -0
- package/dist/util/package-name.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -37,7 +37,7 @@ export declare class ConfigurationChief {
|
|
|
37
37
|
manifest?: PackageJson;
|
|
38
38
|
ignoredWorkspacePatterns: string[];
|
|
39
39
|
workspacePackages: Map<string, Package>;
|
|
40
|
-
|
|
40
|
+
workspacePackagesByPkgName: Map<string, Package>;
|
|
41
41
|
additionalWorkspaceNames: Set<string>;
|
|
42
42
|
availableWorkspaceNames: string[];
|
|
43
43
|
availableWorkspacePkgNames: Set<string>;
|
|
@@ -54,7 +54,7 @@ export class ConfigurationChief {
|
|
|
54
54
|
manifest;
|
|
55
55
|
ignoredWorkspacePatterns = [];
|
|
56
56
|
workspacePackages = new Map();
|
|
57
|
-
|
|
57
|
+
workspacePackagesByPkgName = new Map();
|
|
58
58
|
additionalWorkspaceNames = new Set();
|
|
59
59
|
availableWorkspaceNames = [];
|
|
60
60
|
availableWorkspacePkgNames = new Set();
|
|
@@ -157,7 +157,7 @@ export class ConfigurationChief {
|
|
|
157
157
|
const workspaceNames = compact([...this.getListedWorkspaces(), ...this.additionalWorkspaceNames]);
|
|
158
158
|
const [byName, byPkgName] = await mapWorkspaces(this.cwd, workspaceNames);
|
|
159
159
|
this.workspacePackages = byName;
|
|
160
|
-
this.
|
|
160
|
+
this.workspacePackagesByPkgName = byPkgName;
|
|
161
161
|
this.addRootPackage();
|
|
162
162
|
this.availableWorkspaceNames = this.getAvailableWorkspaceNames(byName.keys());
|
|
163
163
|
this.availableWorkspacePkgNames = this.getAvailableWorkspacePkgNames(byPkgName.keys());
|
|
@@ -178,7 +178,7 @@ export class ConfigurationChief {
|
|
|
178
178
|
manifest: this.manifest,
|
|
179
179
|
};
|
|
180
180
|
this.workspacePackages.set('.', rootPackage);
|
|
181
|
-
this.
|
|
181
|
+
this.workspacePackagesByPkgName.set(pkgName, rootPackage);
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
getListedWorkspaces() {
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,8 @@ import { _glob, negate } from './util/glob.js';
|
|
|
16
16
|
import { getReferencedDependencyHandler } from './util/handle-dependency.js';
|
|
17
17
|
import { getHasStrictlyNsReferences, getType } from './util/has-strictly-ns-references.js';
|
|
18
18
|
import { getIsIdentifierReferencedHandler } from './util/is-identifier-referenced.js';
|
|
19
|
-
import {
|
|
19
|
+
import { getPackageNameFromModuleSpecifier } from './util/modules.js';
|
|
20
|
+
import { getEntryPathsFromManifest } from './util/package-json.js';
|
|
20
21
|
import { dirname, join } from './util/path.js';
|
|
21
22
|
import { findMatch } from './util/regex.js';
|
|
22
23
|
import { getShouldIgnoreHandler, getShouldIgnoreTagHandler } from './util/tag.js';
|
|
@@ -3,7 +3,7 @@ import ts from 'typescript';
|
|
|
3
3
|
import { ALIAS_TAG, ANONYMOUS, DEFAULT_EXTENSIONS, IMPORT_STAR } from '../constants.js';
|
|
4
4
|
import { timerify } from '../util/Performance.js';
|
|
5
5
|
import { addNsValue, addValue, createImports } from '../util/dependency-graph.js';
|
|
6
|
-
import { isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
|
|
6
|
+
import { getPackageNameFromFilePath, isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
|
|
7
7
|
import { extname, isInNodeModules } from '../util/path.js';
|
|
8
8
|
import { shouldIgnore } from '../util/tag.js';
|
|
9
9
|
import { getAccessMembers, getDestructuredIds, getJSDocTags, getLineAndCharacterOfPosition, getTypeName, isAccessExpression, isConsiderReferencedNS, isDestructuring, isImportSpecifier, isReferencedInExportedType, } from './ast-helpers.js';
|
|
@@ -102,7 +102,9 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
|
|
|
102
102
|
if (module.isExternalLibraryImport) {
|
|
103
103
|
if (skipTypeOnly && isTypeOnly)
|
|
104
104
|
return;
|
|
105
|
-
const sanitizedSpecifier =
|
|
105
|
+
const sanitizedSpecifier = isInNodeModules(specifier)
|
|
106
|
+
? getPackageNameFromFilePath(specifier)
|
|
107
|
+
: sanitizeSpecifier(specifier);
|
|
106
108
|
if (!isStartsLikePackageName(sanitizedSpecifier)) {
|
|
107
109
|
return;
|
|
108
110
|
}
|
|
@@ -55,7 +55,7 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
|
|
|
55
55
|
}
|
|
56
56
|
function resolveModuleName(name, containingFile) {
|
|
57
57
|
const sanitizedSpecifier = sanitizeSpecifier(name);
|
|
58
|
-
if (isBuiltin(sanitizedSpecifier)
|
|
58
|
+
if (isBuiltin(sanitizedSpecifier))
|
|
59
59
|
return undefined;
|
|
60
60
|
const resolvedFileName = resolveSync(sanitizedSpecifier, dirname(containingFile));
|
|
61
61
|
if (resolvedFileName) {
|
|
@@ -39,10 +39,17 @@ export const getReferencedDependencyHandler = (collector, deputy, chief) => (spe
|
|
|
39
39
|
symbol: specifier,
|
|
40
40
|
});
|
|
41
41
|
if (packageName && specifier !== packageName) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
|
|
42
|
+
const specifierWorkspace = chief.workspacePackagesByPkgName.get(packageName);
|
|
43
|
+
if (specifierWorkspace) {
|
|
44
|
+
if (specifier.startsWith(packageName)) {
|
|
45
|
+
const dir = specifier.replace(new RegExp(`^${packageName}`), `./${specifierWorkspace.name}`);
|
|
46
|
+
const resolvedFilePath = _resolveSync(dir, chief.cwd);
|
|
47
|
+
if (resolvedFilePath)
|
|
48
|
+
return resolvedFilePath;
|
|
49
|
+
}
|
|
50
|
+
const resolvedFilePath = _resolveSync(specifier, dirname(containingFilePath));
|
|
51
|
+
if (resolvedFilePath)
|
|
52
|
+
return resolvedFilePath;
|
|
46
53
|
collector.addIssue({
|
|
47
54
|
type: 'unresolved',
|
|
48
55
|
filePath: containingFilePath,
|
package/dist/util/modules.d.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import type { PackageJson } from '../types/package-json.js';
|
|
2
1
|
export declare const getPackageNameFromModuleSpecifier: (moduleSpecifier: string) => string | undefined;
|
|
3
2
|
export declare const getPackageNameFromFilePath: (value: string) => string;
|
|
4
3
|
export declare const isStartsLikePackageName: (specifier: string) => boolean;
|
|
5
4
|
export declare const isDefinitelyTyped: (packageName: string) => boolean;
|
|
6
5
|
export declare const getDefinitelyTypedFor: (packageName: string) => string;
|
|
7
6
|
export declare const getPackageFromDefinitelyTyped: (typedDependency: string) => string;
|
|
8
|
-
export declare const getEntryPathsFromManifest: (manifest: PackageJson, sharedGlobOptions: {
|
|
9
|
-
cwd: string;
|
|
10
|
-
dir: string;
|
|
11
|
-
gitignore: boolean;
|
|
12
|
-
ignore: string[];
|
|
13
|
-
}) => Promise<string[]>;
|
|
14
7
|
export declare const sanitizeSpecifier: (specifier: string) => string;
|
package/dist/util/modules.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { isBuiltin } from 'node:module';
|
|
2
2
|
import { DT_SCOPE } from '../constants.js';
|
|
3
|
-
import { _glob } from './glob.js';
|
|
4
|
-
import { getStringValues } from './object.js';
|
|
5
3
|
import { isAbsolute, toPosix } from './path.js';
|
|
6
4
|
export const getPackageNameFromModuleSpecifier = (moduleSpecifier) => {
|
|
7
5
|
if (!isStartsLikePackageName(moduleSpecifier))
|
|
@@ -32,28 +30,6 @@ export const getPackageFromDefinitelyTyped = (typedDependency) => {
|
|
|
32
30
|
}
|
|
33
31
|
return typedDependency;
|
|
34
32
|
};
|
|
35
|
-
export const getEntryPathsFromManifest = (manifest, sharedGlobOptions) => {
|
|
36
|
-
const { main, bin, exports, types, typings } = manifest;
|
|
37
|
-
const entryPaths = new Set();
|
|
38
|
-
if (typeof main === 'string')
|
|
39
|
-
entryPaths.add(main);
|
|
40
|
-
if (bin) {
|
|
41
|
-
if (typeof bin === 'string')
|
|
42
|
-
entryPaths.add(bin);
|
|
43
|
-
if (typeof bin === 'object')
|
|
44
|
-
for (const id of Object.values(bin))
|
|
45
|
-
entryPaths.add(id);
|
|
46
|
-
}
|
|
47
|
-
if (exports) {
|
|
48
|
-
for (const item of getStringValues(exports))
|
|
49
|
-
entryPaths.add(item);
|
|
50
|
-
}
|
|
51
|
-
if (typeof types === 'string')
|
|
52
|
-
entryPaths.add(types);
|
|
53
|
-
if (typeof typings === 'string')
|
|
54
|
-
entryPaths.add(typings);
|
|
55
|
-
return _glob({ ...sharedGlobOptions, patterns: Array.from(entryPaths) });
|
|
56
|
-
};
|
|
57
33
|
const matchDirectives = /^([?!|-]+)?([^!?:]+).*/;
|
|
58
34
|
export const sanitizeSpecifier = (specifier) => {
|
|
59
35
|
if (isBuiltin(specifier))
|
|
@@ -7,4 +7,10 @@ interface ExtendedPackageJson extends PackageJson {
|
|
|
7
7
|
}
|
|
8
8
|
export declare const load: (filePath: string) => Promise<ExtendedPackageJson>;
|
|
9
9
|
export declare const save: (filePath: string, content: ExtendedPackageJson) => Promise<void>;
|
|
10
|
+
export declare const getEntryPathsFromManifest: (manifest: PackageJson, sharedGlobOptions: {
|
|
11
|
+
cwd: string;
|
|
12
|
+
dir: string;
|
|
13
|
+
gitignore: boolean;
|
|
14
|
+
ignore: string[];
|
|
15
|
+
}) => Promise<string[]>;
|
|
10
16
|
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { _glob } from './glob.js';
|
|
3
|
+
import { getStringValues } from './object.js';
|
|
2
4
|
const INDENT = Symbol.for('indent');
|
|
3
5
|
const NEWLINE = Symbol.for('newline');
|
|
4
6
|
const DEFAULT_NEWLINE = '\n';
|
|
@@ -28,3 +30,25 @@ export const save = async (filePath, content) => {
|
|
|
28
30
|
const fileContent = `${JSON.stringify(content, null, space)}\n`.replace(/\n/g, EOL);
|
|
29
31
|
await writeFile(filePath, fileContent);
|
|
30
32
|
};
|
|
33
|
+
export const getEntryPathsFromManifest = (manifest, sharedGlobOptions) => {
|
|
34
|
+
const { main, bin, exports, types, typings } = manifest;
|
|
35
|
+
const entryPaths = new Set();
|
|
36
|
+
if (typeof main === 'string')
|
|
37
|
+
entryPaths.add(main);
|
|
38
|
+
if (bin) {
|
|
39
|
+
if (typeof bin === 'string')
|
|
40
|
+
entryPaths.add(bin);
|
|
41
|
+
if (typeof bin === 'object')
|
|
42
|
+
for (const id of Object.values(bin))
|
|
43
|
+
entryPaths.add(id);
|
|
44
|
+
}
|
|
45
|
+
if (exports) {
|
|
46
|
+
for (const item of getStringValues(exports))
|
|
47
|
+
entryPaths.add(item);
|
|
48
|
+
}
|
|
49
|
+
if (typeof types === 'string')
|
|
50
|
+
entryPaths.add(types);
|
|
51
|
+
if (typeof typings === 'string')
|
|
52
|
+
entryPaths.add(typings);
|
|
53
|
+
return _glob({ ...sharedGlobOptions, patterns: Array.from(entryPaths) });
|
|
54
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { basename, dirname } from './path.js';
|
|
2
|
-
const
|
|
3
|
-
const getName = (dir) => (dir ?
|
|
2
|
+
const getPkgName = (parent, base) => (parent.charAt(0) === '@' ? `${parent}/${base}` : base);
|
|
3
|
+
const getName = (dir) => (dir ? getPkgName(basename(dirname(dir)), basename(dir)) : undefined);
|
|
4
4
|
export function getPackageName(pkg, pathname) {
|
|
5
5
|
const { name } = pkg;
|
|
6
6
|
return name || getName(pathname);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.30.
|
|
1
|
+
export declare const version = "5.30.2";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.30.
|
|
1
|
+
export const version = '5.30.2';
|