ts-alias
Version:
Parse module aliases from tsconfig ; Apply / remove them from pathnames ; Generate config for webpack & module-alias.
64 lines (63 loc) • 2.13 kB
TypeScript
export declare type TInputOptions = ({
rootDir?: string;
} | {
aliases: AliasDefinition[];
}) & {
modulesDir?: string[];
debug?: boolean;
};
export declare type AliasDefinition = {
alias: string;
pathnames: string[];
exact: boolean;
};
declare type TsAliasList = {
[alias: string]: string[];
};
declare type ModuleAliasList = {
[alias: string]: string | Function;
};
declare type TWebpackExternals = (data: {
request: string;
}, callback: (err?: undefined, result?: string) => void) => void;
export declare type TOutputOptions<TNodeExternals extends boolean> = {
modulesPath?: string;
shortenPaths?: boolean;
nodeExternals?: TNodeExternals;
};
declare type TWebpackOutput<TNodeExternals extends boolean> = {
aliases: TsAliasList;
externals: TNodeExternals extends true ? TWebpackExternals : undefined;
};
export default class TsAlias {
private options;
typescript: TsAliasList;
list: AliasDefinition[];
constructor(options?: TInputOptions);
private readTsConfig;
private processTsAliases;
/**
* Replace real path by alias
* @param realpath The path you want to replace with alias
* @param strict true to return null when no alias could be applied to the path
*/
apply(realpath: string, strict?: false): string;
apply(realpath: string, strict: true): string | null;
/**
* Check if the provided path can be shorten with aliases
* @param filename The path to check
* @returns If filename can be shorten an alias
*/
isAliased(filename: string): boolean;
realpath(request: string, strict?: false): string;
realpath(request: string, strict: true): string | null;
/**
* If the provided path contains an alias
* @param filename The path to check
* @returns If filename contains an alias
*/
containsAlias(filename: string): boolean;
forWebpack<TNodeExternals extends boolean>({ modulesPath, shortenPaths, nodeExternals }: TOutputOptions<TNodeExternals>): TWebpackOutput<TNodeExternals>;
forModuleAlias(enableCache?: boolean): ModuleAliasList;
}
export {};