knip 6.0.5 → 6.0.6
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/graph/build.js
CHANGED
|
@@ -310,14 +310,18 @@ export async function build({ chief, collector, counselor, deputy, principal, is
|
|
|
310
310
|
if (!isIgnored)
|
|
311
311
|
pp.addEntryPath(filePath, { skipExportsAnalysis: true });
|
|
312
312
|
}
|
|
313
|
+
const wsDependencies = deputy.getDependencies(workspace.name);
|
|
313
314
|
for (const _import of file.imports.imports) {
|
|
314
|
-
if (_import.filePath)
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
315
|
+
if (!_import.filePath)
|
|
316
|
+
continue;
|
|
317
|
+
const packageName = getPackageNameFromModuleSpecifier(_import.specifier);
|
|
318
|
+
if (!packageName)
|
|
319
|
+
continue;
|
|
320
|
+
const isWorkspace = isInternalWorkspace(packageName);
|
|
321
|
+
if (isWorkspace || wsDependencies.has(packageName)) {
|
|
322
|
+
file.imports.external.add({ ..._import, specifier: packageName });
|
|
323
|
+
if (isWorkspace && !isGitIgnored(_import.filePath)) {
|
|
324
|
+
pp.addProgramPath(_import.filePath);
|
|
321
325
|
}
|
|
322
326
|
}
|
|
323
327
|
}
|
|
@@ -4,14 +4,28 @@ import { DEFAULT_EXTENSIONS, DTS_EXTENSIONS } from "../constants.js";
|
|
|
4
4
|
import { sanitizeSpecifier } from "../util/modules.js";
|
|
5
5
|
import { timerify } from "../util/Performance.js";
|
|
6
6
|
import { dirname, extname, isAbsolute, isInNodeModules, join } from "../util/path.js";
|
|
7
|
-
import { _createSyncModuleResolver, _resolveModuleSync
|
|
7
|
+
import { _createSyncModuleResolver, _resolveModuleSync } from "../util/resolve.js";
|
|
8
|
+
function compilePathMappings(paths) {
|
|
9
|
+
if (!paths)
|
|
10
|
+
return undefined;
|
|
11
|
+
const mappings = [];
|
|
12
|
+
for (const key in paths) {
|
|
13
|
+
const starIdx = key.indexOf('*');
|
|
14
|
+
if (starIdx >= 0) {
|
|
15
|
+
mappings.push({ prefix: key.slice(0, starIdx), wildcard: true, values: paths[key] });
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
mappings.push({ prefix: key, wildcard: false, values: paths[key] });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return mappings.length > 0 ? mappings : undefined;
|
|
22
|
+
}
|
|
8
23
|
export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath) {
|
|
9
24
|
const customCompilerExtensionsSet = new Set(customCompilerExtensions);
|
|
10
25
|
const hasCustomExts = customCompilerExtensionsSet.size > 0;
|
|
11
26
|
const extensions = [...DEFAULT_EXTENSIONS, ...customCompilerExtensions, ...DTS_EXTENSIONS];
|
|
12
|
-
const alias = convertPathsToAlias(compilerOptions.paths);
|
|
13
27
|
const resolveSync = hasCustomExts ? _createSyncModuleResolver(extensions) : _resolveModuleSync;
|
|
14
|
-
const
|
|
28
|
+
const pathMappings = compilePathMappings(compilerOptions.paths);
|
|
15
29
|
const rootDirs = compilerOptions.rootDirs;
|
|
16
30
|
function toSourcePath(resolvedFileName) {
|
|
17
31
|
if (!hasCustomExts || !customCompilerExtensionsSet.has(extname(resolvedFileName))) {
|
|
@@ -27,24 +41,27 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
|
|
|
27
41
|
};
|
|
28
42
|
}
|
|
29
43
|
function resolveModuleName(name, containingFile) {
|
|
30
|
-
const
|
|
31
|
-
if (isBuiltin(
|
|
44
|
+
const specifier = sanitizeSpecifier(name);
|
|
45
|
+
if (isBuiltin(specifier))
|
|
32
46
|
return undefined;
|
|
33
|
-
const resolvedFileName = resolveSync(
|
|
47
|
+
const resolvedFileName = resolveSync(specifier, containingFile);
|
|
34
48
|
if (resolvedFileName)
|
|
35
49
|
return toResult(resolvedFileName);
|
|
36
|
-
if (
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
if (pathMappings) {
|
|
51
|
+
for (const { prefix, wildcard, values } of pathMappings) {
|
|
52
|
+
if (wildcard ? specifier.startsWith(prefix) : specifier === prefix) {
|
|
53
|
+
const captured = wildcard ? specifier.slice(prefix.length) : '';
|
|
54
|
+
for (const value of values) {
|
|
55
|
+
const starIdx = value.indexOf('*');
|
|
56
|
+
const mapped = starIdx >= 0 ? value.slice(0, starIdx) + captured + value.slice(starIdx + 1) : value;
|
|
57
|
+
const resolved = resolveSync(mapped, containingFile);
|
|
58
|
+
if (resolved)
|
|
59
|
+
return toResult(resolved);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
46
63
|
}
|
|
47
|
-
if (rootDirs && !isAbsolute(
|
|
64
|
+
if (rootDirs && !isAbsolute(specifier)) {
|
|
48
65
|
const containingDir = dirname(containingFile);
|
|
49
66
|
for (const srcRoot of rootDirs) {
|
|
50
67
|
if (!containingDir.startsWith(srcRoot))
|
|
@@ -53,13 +70,17 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
|
|
|
53
70
|
for (const targetRoot of rootDirs) {
|
|
54
71
|
if (targetRoot === srcRoot)
|
|
55
72
|
continue;
|
|
56
|
-
const mapped = join(targetRoot, relPath,
|
|
73
|
+
const mapped = join(targetRoot, relPath, specifier);
|
|
57
74
|
const resolved = resolveSync(mapped, containingFile);
|
|
58
75
|
if (resolved)
|
|
59
76
|
return toResult(resolved);
|
|
60
77
|
}
|
|
61
78
|
}
|
|
62
79
|
}
|
|
80
|
+
const candidate = isAbsolute(specifier) ? specifier : join(dirname(containingFile), specifier);
|
|
81
|
+
if (existsSync(candidate)) {
|
|
82
|
+
return { resolvedFileName: candidate, isExternalLibraryImport: false };
|
|
83
|
+
}
|
|
63
84
|
}
|
|
64
85
|
return timerify(resolveModuleName);
|
|
65
86
|
}
|
|
@@ -150,7 +150,7 @@ const _addParamShadows = (params, body) => {
|
|
|
150
150
|
if (!body || !params)
|
|
151
151
|
return;
|
|
152
152
|
const range = [body.start, body.end];
|
|
153
|
-
const items = Array.isArray(params) ? params : params.items ?? params;
|
|
153
|
+
const items = Array.isArray(params) ? params : (params.items ?? params);
|
|
154
154
|
for (const param of items)
|
|
155
155
|
_collectBindingNames(param, range);
|
|
156
156
|
};
|
package/dist/util/resolve.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const _resolveModuleSync: (specifier: string, basePath: string) => string | undefined;
|
|
2
|
-
export declare const _createSyncModuleResolver: (extensions: string[]
|
|
3
|
-
export declare function convertPathsToAlias(paths: Record<string, string[]> | undefined): Record<string, string[]> | undefined;
|
|
2
|
+
export declare const _createSyncModuleResolver: (extensions: string[]) => (specifier: string, basePath: string) => string | undefined;
|
|
4
3
|
export declare function clearResolverCache(): void;
|
|
5
4
|
export declare const _resolveSync: (specifier: string, baseDir: string) => string | undefined;
|
package/dist/util/resolve.js
CHANGED
|
@@ -34,18 +34,7 @@ const createSyncModuleResolver = (extensions, alias) => {
|
|
|
34
34
|
};
|
|
35
35
|
const resolveModuleSync = createSyncModuleResolver([...DEFAULT_EXTENSIONS, ...DTS_EXTENSIONS, '.json', '.jsonc']);
|
|
36
36
|
export const _resolveModuleSync = timerify(resolveModuleSync, 'resolveModuleSync');
|
|
37
|
-
export const _createSyncModuleResolver = (extensions
|
|
38
|
-
export function convertPathsToAlias(paths) {
|
|
39
|
-
if (!paths)
|
|
40
|
-
return undefined;
|
|
41
|
-
const alias = {};
|
|
42
|
-
for (const key in paths) {
|
|
43
|
-
const stripWildcard = key.endsWith('/*');
|
|
44
|
-
const aliasKey = stripWildcard ? key.slice(0, -2) : key;
|
|
45
|
-
alias[aliasKey] = stripWildcard ? paths[key].map(v => (v.endsWith('/*') ? v.slice(0, -2) : v)) : paths[key];
|
|
46
|
-
}
|
|
47
|
-
return alias;
|
|
48
|
-
}
|
|
37
|
+
export const _createSyncModuleResolver = (extensions) => timerify(createSyncModuleResolver(extensions), 'resolveModuleSync');
|
|
49
38
|
const createSyncResolver = (extensions) => {
|
|
50
39
|
const resolver = new ResolverFactory({
|
|
51
40
|
extensions,
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "6.0.
|
|
1
|
+
export declare const version = "6.0.6";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '6.0.
|
|
1
|
+
export const version = '6.0.6';
|