+11
-7
@@ -313,10 +313,14 @@ import { _getInputsFromScripts } from "../binaries/index.js"; | ||
| } | ||
| const wsDependencies = deputy.getDependencies(workspace.name); | ||
| for (const _import of file.imports.imports) { | ||
| if (_import.filePath) { | ||
| const packageName = getPackageNameFromModuleSpecifier(_import.specifier); | ||
| if (packageName && isInternalWorkspace(packageName)) { | ||
| file.imports.external.add({ ..._import, specifier: packageName }); | ||
| if (!isGitIgnored(_import.filePath)) { | ||
| pp.addProgramPath(_import.filePath); | ||
| } | ||
| if (!_import.filePath) | ||
| continue; | ||
| const packageName = getPackageNameFromModuleSpecifier(_import.specifier); | ||
| if (!packageName) | ||
| continue; | ||
| const isWorkspace = isInternalWorkspace(packageName); | ||
| if (isWorkspace || wsDependencies.has(packageName)) { | ||
| file.imports.external.add({ ..._import, specifier: packageName }); | ||
| if (isWorkspace && !isGitIgnored(_import.filePath)) { | ||
| pp.addProgramPath(_import.filePath); | ||
| } | ||
@@ -323,0 +327,0 @@ } |
@@ -7,3 +7,18 @@ import { existsSync } from 'node:fs'; | ||
| import { dirname, extname, isAbsolute, isInNodeModules, join } from "../util/path.js"; | ||
| import { _createSyncModuleResolver, _resolveModuleSync, convertPathsToAlias } from "../util/resolve.js"; | ||
| import { _createSyncModuleResolver, _resolveModuleSync } from "../util/resolve.js"; | ||
| function compilePathMappings(paths) { | ||
| if (!paths) | ||
| return undefined; | ||
| const mappings = []; | ||
| for (const key in paths) { | ||
| const starIdx = key.indexOf('*'); | ||
| if (starIdx >= 0) { | ||
| mappings.push({ prefix: key.slice(0, starIdx), wildcard: true, values: paths[key] }); | ||
| } | ||
| else { | ||
| mappings.push({ prefix: key, wildcard: false, values: paths[key] }); | ||
| } | ||
| } | ||
| return mappings.length > 0 ? mappings : undefined; | ||
| } | ||
| export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath) { | ||
@@ -13,5 +28,4 @@ const customCompilerExtensionsSet = new Set(customCompilerExtensions); | ||
| const extensions = [...DEFAULT_EXTENSIONS, ...customCompilerExtensions, ...DTS_EXTENSIONS]; | ||
| const alias = convertPathsToAlias(compilerOptions.paths); | ||
| const resolveSync = hasCustomExts ? _createSyncModuleResolver(extensions) : _resolveModuleSync; | ||
| const resolveWithAlias = alias ? _createSyncModuleResolver(extensions, alias) : undefined; | ||
| const pathMappings = compilePathMappings(compilerOptions.paths); | ||
| const rootDirs = compilerOptions.rootDirs; | ||
@@ -32,20 +46,23 @@ function toSourcePath(resolvedFileName) { | ||
| function resolveModuleName(name, containingFile) { | ||
| const sanitizedSpecifier = sanitizeSpecifier(name); | ||
| if (isBuiltin(sanitizedSpecifier)) | ||
| const specifier = sanitizeSpecifier(name); | ||
| if (isBuiltin(specifier)) | ||
| return undefined; | ||
| const resolvedFileName = resolveSync(sanitizedSpecifier, containingFile); | ||
| const resolvedFileName = resolveSync(specifier, containingFile); | ||
| if (resolvedFileName) | ||
| return toResult(resolvedFileName); | ||
| if (resolveWithAlias) { | ||
| const aliasResolved = resolveWithAlias(sanitizedSpecifier, containingFile); | ||
| if (aliasResolved) | ||
| return toResult(aliasResolved); | ||
| if (pathMappings) { | ||
| for (const { prefix, wildcard, values } of pathMappings) { | ||
| if (wildcard ? specifier.startsWith(prefix) : specifier === prefix) { | ||
| const captured = wildcard ? specifier.slice(prefix.length) : ''; | ||
| for (const value of values) { | ||
| const starIdx = value.indexOf('*'); | ||
| const mapped = starIdx >= 0 ? value.slice(0, starIdx) + captured + value.slice(starIdx + 1) : value; | ||
| const resolved = resolveSync(mapped, containingFile); | ||
| if (resolved) | ||
| return toResult(resolved); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| const candidate = isAbsolute(sanitizedSpecifier) | ||
| ? sanitizedSpecifier | ||
| : join(dirname(containingFile), sanitizedSpecifier); | ||
| if (existsSync(candidate)) { | ||
| return { resolvedFileName: candidate, isExternalLibraryImport: false }; | ||
| } | ||
| if (rootDirs && !isAbsolute(sanitizedSpecifier)) { | ||
| if (rootDirs && !isAbsolute(specifier)) { | ||
| const containingDir = dirname(containingFile); | ||
@@ -59,3 +76,3 @@ for (const srcRoot of rootDirs) { | ||
| continue; | ||
| const mapped = join(targetRoot, relPath, sanitizedSpecifier); | ||
| const mapped = join(targetRoot, relPath, specifier); | ||
| const resolved = resolveSync(mapped, containingFile); | ||
@@ -67,4 +84,8 @@ if (resolved) | ||
| } | ||
| const candidate = isAbsolute(specifier) ? specifier : join(dirname(containingFile), specifier); | ||
| if (existsSync(candidate)) { | ||
| return { resolvedFileName: candidate, isExternalLibraryImport: false }; | ||
| } | ||
| } | ||
| return timerify(resolveModuleName); | ||
| } |
@@ -153,3 +153,3 @@ import { Visitor } from 'oxc-parser'; | ||
| const range = [body.start, body.end]; | ||
| const items = Array.isArray(params) ? params : params.items ?? params; | ||
| const items = Array.isArray(params) ? params : (params.items ?? params); | ||
| for (const param of items) | ||
@@ -156,0 +156,0 @@ _collectBindingNames(param, range); |
| export declare const _resolveModuleSync: (specifier: string, basePath: string) => string | undefined; | ||
| export declare const _createSyncModuleResolver: (extensions: string[], alias?: Record<string, string[]>) => (specifier: string, basePath: string) => string | undefined; | ||
| export declare function convertPathsToAlias(paths: Record<string, string[]> | undefined): Record<string, string[]> | undefined; | ||
| export declare const _createSyncModuleResolver: (extensions: string[]) => (specifier: string, basePath: string) => string | undefined; | ||
| export declare function clearResolverCache(): void; | ||
| export declare const _resolveSync: (specifier: string, baseDir: string) => string | undefined; |
+1
-12
@@ -37,14 +37,3 @@ import { ResolverFactory } from 'oxc-resolver'; | ||
| export const _resolveModuleSync = timerify(resolveModuleSync, 'resolveModuleSync'); | ||
| export const _createSyncModuleResolver = (extensions, alias) => timerify(createSyncModuleResolver(extensions, alias), 'resolveModuleSync'); | ||
| export function convertPathsToAlias(paths) { | ||
| if (!paths) | ||
| return undefined; | ||
| const alias = {}; | ||
| for (const key in paths) { | ||
| const stripWildcard = key.endsWith('/*'); | ||
| const aliasKey = stripWildcard ? key.slice(0, -2) : key; | ||
| alias[aliasKey] = stripWildcard ? paths[key].map(v => (v.endsWith('/*') ? v.slice(0, -2) : v)) : paths[key]; | ||
| } | ||
| return alias; | ||
| } | ||
| export const _createSyncModuleResolver = (extensions) => timerify(createSyncModuleResolver(extensions), 'resolveModuleSync'); | ||
| const createSyncResolver = (extensions) => { | ||
@@ -51,0 +40,0 @@ const resolver = new ResolverFactory({ |
@@ -1,1 +0,1 @@ | ||
| export declare const version = "6.0.5"; | ||
| export declare const version = "6.0.6"; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| export const version = '6.0.5'; | ||
| export const version = '6.0.6'; |
+1
-1
| { | ||
| "name": "knip", | ||
| "version": "6.0.5", | ||
| "version": "6.0.6", | ||
| "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
1509436
0.03%30826
0.04%