UNPKG

eslint-import-resolver-next

Version:

The next resolver for `eslint-plugin-import` or `eslint-plugin-import-x`

172 lines (171 loc) 6.26 kB
import type { TsconfigOptions } from "unrs-resolver"; import type { ConfigFileOptions, PackageGlobOptions, PackageOptions } from "./types.js"; /** * Remove duplicates from an array. * * @param {T[]} arr - the array to remove duplicates from * * @returns {T[]} the array without duplicates */ export declare function unique<T>(arr: T[]): T[]; /** * Check if the module has a Node.js prefix. * * @param modulePath - the module path * @returns {boolean} true if the module has a Node.js prefix, false otherwise */ export declare function hasNodePrefix(modulePath: string): boolean; /** * Check if the module has a Bun prefix. * * @param modulePath - the module path * @returns {boolean} true if the module has a Bun prefix, false otherwise */ export declare function hasBunPrefix(modulePath: string): boolean; /** * Remove querystrings from the module path. * * Some imports may have querystrings, for example: * * import "foo?bar"; * * @param {string} modulePath - the import module path * * @returns {string} cleaned module path */ export declare function removeQueryString(modulePath: string): string; /** * Check if the module is a built-in module with a prefix. * * @param {string} modulePath - the module path * * @returns {boolean} true if the module is a built-in module with a prefix, false otherwise */ export declare function isNodeBuiltin(modulePath: string): boolean; /** * Normalize patterns to include all possible package descriptor files. * * @param {string[]} patterns - the patterns to normalize * * @returns {string[]} the normalized patterns */ export declare function normalizePatterns(patterns: string[]): string[]; /** * Get the depth of a path. * * @param {string} p - the path * * @returns {number} the depth of the path */ export declare function getPathDepth(p: string): number; /** * Sort paths by the depth of the path. The deeper the path, the higher the priority. * * @param {string[]} paths - the paths to sort * * @returns {string[]} the sorted paths */ export declare function sortPathsByDepth(paths: string[]): string[]; /** * Read a yaml file. * * @param {string} filePath - the file path to read * * @returns {T | null} the parsed yaml file */ export declare function readYamlFile<T>(filePath: string): T | null; /** * Normalize package glob options. * * @param {PackageOptions | string[]} opts - the package options * @param {string} root - the root path * * @returns {PackageGlobOptions} the normalized package glob options */ export declare function normalizePackageGlobOptions(opts: PackageOptions | string[], root: string): PackageGlobOptions; /** * Find all packages in the root path. * * Copy from https://github.com/pnpm/pnpm/blob/b8b0c687f2e3403d07381822fe81c08478413916/fs/find-packages/src/index.ts * * @param {string} root - the root path * @param {PackageOptions | string[]} packageOpts - the package options * * @returns {string[]} the found package paths */ export declare function findAllPackages(root: string, packageOpts: PackageOptions | string[]): string[]; /** * Find the closest package from the source file. * * @param {string} sourceFile - the source file * @param {string[]} sortedPaths - the paths to search * * @returns {string | undefined} the closest package root */ export declare function findClosestPackageRoot(sourceFile: string, sortedPaths: string[]): string | undefined; /** * Sort config files by depth and specific filename. * * @param {string[]} configFiles - the config files to sort * @param {string} tsconfigFilename - the TypeScript config filename * * @returns {string[]} the sorted config files */ export declare function sortConfigFiles(configFiles: string[], tsconfigFilename?: string): string[]; /** * Find the closest config file from the source file. * * @param {string} sourceFile - the source file * @param {string[]} sortedConfigFiles - the config files to search * * @returns {string | undefined} the closest config file */ export declare function findClosestConfigFile(sourceFile: string, sortedConfigFiles: string[]): string | undefined; /** * Get the config files in the specified directory. * * @param {boolean | string | ConfigFileOptions | undefined} config - the config option * @param {string} root - the root path * @param {{ ignore?: string[]; filename: string }} defaults - the default options * * @returns {[string | undefined, string[] | undefined]} the filename and config files */ export declare function getConfigFiles(config: boolean | string | ConfigFileOptions | undefined, root: string, defaults: { ignore?: string[]; filename: string; }): [filename: undefined, configFiles: undefined] | [filename: string, configFiles: string[]]; /** * Normalize the config file options. * * @param {Record<"tsconfig" | "jsconfig", boolean | string | ConfigFileOptions | undefined>} configs - the config file options * @param {string} packageDir - the directory of the package * @param {string} sourceFile - the source file * * @returns {ConfigFileOptions | undefined} the normalized config file options */ export declare function normalizeConfigFileOptions(configs: Record<"tsconfig" | "jsconfig", boolean | string | ConfigFileOptions | undefined>, packageDir: string, sourceFile: string): TsconfigOptions | undefined; /** * Normalize the alias mapping. * * @param {Record<string, string | string[]> | undefined} alias - the alias mapping * @param {string} parent - the parent directory * * @returns {Record<string, string[]> | undefined} the normalized alias mapping */ export declare function normalizeAlias(alias: Record<string, string | string[]> | undefined, parent: string): Record<string, string[]> | undefined; /** * Get the hash of an object. * * @param {unknown} obj - the object to hash * * @returns {string} the hash of the object */ export declare function hashObject(obj: unknown): string; /** * Find all workspace packages. * * @param {string[]} roots - the roots to search * @param {string[] | PackageOptions} packages - the package options * * @returns {string[]} the sorted workspace packages */ export declare function findWorkspacePackages(roots: string[], packages?: string[] | PackageOptions): string[];