mp-lens
Version:
微信小程序分析工具 (Unused Code, Dependencies, Visualization)
39 lines (38 loc) • 1.93 kB
TypeScript
import { AnalyzerOptions } from '../types/command-options';
import { AliasResolver } from './alias-resolver';
export declare class PathResolver {
private projectRoot;
private aliasResolver;
private hasAliasConfig;
private options;
constructor(projectRoot: string, options: AnalyzerOptions, aliasResolver: AliasResolver | null, hasAliasConfig: boolean);
/**
* Resolves an import path (which could be relative, absolute, alias, or implicit root)
* to an existing file path, considering context-specific allowed extensions.
*
* @param importPath The original import string (e.g., './utils', '/pages/index', '@/comp', 'image.png').
* @param sourcePath The absolute path of the file containing the import.
* @param allowedExtensions An ordered array of extensions to check (e.g., ['.js', '.ts'] or ['.wxml']).
* @returns The absolute path of the resolved existing file, or null if not found.
*/
resolveAnyPath(importPath: string, sourcePath: string, allowedExtensions: string[]): string | null;
/**
* Given a potential absolute base path (without extension or index), finds the
* actual existing file path by checking for the path itself, adding allowed
* extensions, or checking for directory index files with allowed extensions.
*
* @param potentialPath Absolute path, possibly without extension (e.g., '/path/to/file' or '/path/to/dir')
* @param allowedExtensions Ordered list of extensions to check (e.g., ['.js', '.ts'])
* @returns The existing absolute file path, or null.
*/
private findExistingPath;
/**
* Check if the import path looks like an alias based on the loaded configuration.
*/
private isAliasPath;
/**
* Check if the import path looks like an npm package that we shouldn't try to resolve
* on the file system or with aliases.
*/
private isNpmPackageImport;
}