import { PortablePath } from '@yarnpkg/fslib'; import { Readable, Transform } from 'stream'; import type { DurationUnit } from './Configuration'; /** * @internal */ export declare function isTaggedYarnVersion(version: string | null): boolean; export declare function plural(n: number, { one, more, zero }: { zero?: string; one: string; more: string; }): string; export declare function escapeRegExp(str: string): string; export declare function overrideType(val: unknown): asserts val is T; export declare function assertNever(arg: never): never; export declare function validateEnum(def: { [key: string]: T; }, value: string): T; export declare function mapAndFilter(iterable: Iterable, cb: (value: In) => Out | typeof mapAndFilterSkip): Array; export declare namespace mapAndFilter { var skip: typeof mapAndFilterSkip; } declare const mapAndFilterSkip: unique symbol; export declare function mapAndFind(iterable: Iterable, cb: (value: In) => Out | typeof mapAndFindSkip): Out | undefined; export declare namespace mapAndFind { var skip: typeof mapAndFindSkip; } declare const mapAndFindSkip: unique symbol; export declare function isIndexableObject(value: unknown): value is { [key: string]: unknown; }; export type MapValue = T extends Map ? V : never; export interface ToMapValue { get(key: K): T[K]; } export type MapValueToObjectValue = T extends Map ? (K extends string | number | symbol ? MapValueToObjectValue> : never) : T extends ToMapValue ? MapValueToObjectValue : T extends PortablePath ? PortablePath : T extends object ? { [K in keyof T]: MapValueToObjectValue; } : T; export declare function allSettledSafe(promises: Array>): Promise; /** * Converts Maps to indexable objects recursively. */ export declare function convertMapsToIndexableObjects(arg: T): MapValueToObjectValue; export interface GetSetMap { get(k: K): V | undefined; set(k: K, v: V): void; } export declare function getFactoryWithDefault(map: GetSetMap, key: K, factory: () => T): T; export declare function getArrayWithDefault(map: GetSetMap>, key: K): T[]; export declare function getSetWithDefault(map: GetSetMap>, key: K): Set; export declare function getMapWithDefault(map: GetSetMap>, key: K): Map; export declare function releaseAfterUseAsync(fn: () => Promise, cleanup?: (() => any) | null): Promise; export declare function prettifyAsyncErrors(fn: () => Promise, update: (message: string) => string): Promise; export declare function prettifySyncErrors(fn: () => T, update: (message: string) => string): T; export declare function bufferStream(stream: Readable): Promise>; export declare class BufferStream extends Transform { private readonly chunks; _transform(chunk: Buffer, encoding: string, cb: any): void; _flush(cb: any): void; } export type Deferred = { promise: Promise; resolve: (val: T) => void; reject: (err: Error) => void; }; export declare function makeDeferred(): Deferred; export declare class AsyncActions { private deferred; private promises; private limit; constructor(limit: number); set(key: string, factory: () => Promise): Promise; reduce(key: string, factory: (action: Promise) => Promise): void; wait(): Promise; } export declare class DefaultStream extends Transform { private readonly ifEmpty; active: boolean; constructor(ifEmpty?: Buffer); _transform(chunk: Buffer, encoding: string, cb: any): void; _flush(cb: any): void; } export declare enum CachingStrategy { NoCache = 0, FsTime = 1, Node = 2 } export declare function dynamicRequire(path: string, opts?: { cachingStrategy?: CachingStrategy; }): any; export declare function dynamicRequire(path: PortablePath, opts: { cachingStrategy: CachingStrategy.FsTime; }): any; export declare function sortMap(values: Iterable, mappers: ((value: T) => string) | Array<(value: T) => string>): T[]; /** * Combines an Array of glob patterns into a regular expression. * * @param ignorePatterns An array of glob patterns * * @returns A `string` representing a regular expression or `null` if no glob patterns are provided */ export declare function buildIgnorePattern(ignorePatterns: Array): string | null; export declare function replaceEnvVariables(input: string, { env }: { env: { [key: string]: string | undefined; }; }): string; export declare function parseBoolean(value: unknown): boolean; export declare function parseOptionalBoolean(value: unknown): boolean | undefined; export declare function tryParseOptionalBoolean(value: unknown): boolean | undefined | null; export type FilterKeys = { [K in keyof T]: T[K] extends Filter ? K : never; }[keyof T]; export declare function isPathLike(value: string): boolean; type MergeObjects, Accumulator> = T extends [infer U, ...infer Rest] ? MergeObjects : Accumulator; /** * Merges multiple objects into the target argument. * * **Important:** This function mutates the target argument. * * Custom classes inside the target parameter are supported (e.g. comment-json's `CommentArray` - comments from target will be preserved). * * @see toMerged for a version that doesn't mutate the target argument * */ export declare function mergeIntoTarget>(target: T, ...sources: S): MergeObjects; /** * Merges multiple objects into a single one, without mutating any arguments. * * Custom classes are not supported (i.e. comment-json's comments will be lost). */ export declare function toMerged>(...sources: S): MergeObjects; export declare function groupBy, K extends keyof T>(items: Iterable, key: K): { [V in T[K]]?: Array>; }; export declare function parseInt(val: string | number): number; export declare function parseDuration(value: string, unit: DurationUnit): number; export {};