UNPKG

11.3 kBTypeScriptView Raw
1/// <reference types="node" />
2import { Filename, PortablePath } from '@yarnpkg/fslib';
3import { Limit } from 'p-limit';
4import { Writable } from 'stream';
5import { PeerDependencyMeta } from './Manifest';
6import { MultiFetcher } from './MultiFetcher';
7import { MultiResolver } from './MultiResolver';
8import { Plugin, Hooks } from './Plugin';
9import { Report } from './Report';
10import { TelemetryManager } from './TelemetryManager';
11import * as formatUtils from './formatUtils';
12import { IdentHash, Package, Descriptor } from './types';
13export declare const ENVIRONMENT_PREFIX = "yarn_";
14export declare const DEFAULT_RC_FILENAME: Filename;
15export declare const DEFAULT_LOCK_FILENAME: Filename;
16export declare const SECRET = "********";
17export declare enum SettingsType {
18 ANY = "ANY",
19 BOOLEAN = "BOOLEAN",
20 ABSOLUTE_PATH = "ABSOLUTE_PATH",
21 LOCATOR = "LOCATOR",
22 LOCATOR_LOOSE = "LOCATOR_LOOSE",
23 NUMBER = "NUMBER",
24 STRING = "STRING",
25 SECRET = "SECRET",
26 SHAPE = "SHAPE",
27 MAP = "MAP"
28}
29export declare type FormatType = formatUtils.Type;
30export declare const FormatType: typeof formatUtils.Type;
31export declare type BaseSettingsDefinition<T extends SettingsType = SettingsType> = {
32 description: string;
33 type: T;
34 isArray?: boolean;
35};
36export declare type ShapeSettingsDefinition = BaseSettingsDefinition<SettingsType.SHAPE> & {
37 properties: {
38 [propertyName: string]: SettingsDefinition;
39 };
40};
41export declare type MapSettingsDefinition = BaseSettingsDefinition<SettingsType.MAP> & {
42 valueDefinition: SettingsDefinitionNoDefault;
43 normalizeKeys?: (key: string) => string;
44};
45export declare type SimpleSettingsDefinition = BaseSettingsDefinition<Exclude<SettingsType, SettingsType.SHAPE | SettingsType.MAP>> & {
46 default: any;
47 defaultText?: any;
48 isNullable?: boolean;
49 values?: Array<any>;
50};
51export declare type SettingsDefinitionNoDefault = MapSettingsDefinition | ShapeSettingsDefinition | Omit<SimpleSettingsDefinition, 'default'>;
52export declare type SettingsDefinition = MapSettingsDefinition | ShapeSettingsDefinition | SimpleSettingsDefinition;
53export declare type PluginConfiguration = {
54 modules: Map<string, any>;
55 plugins: Set<string>;
56};
57export declare const coreDefinitions: {
58 [coreSettingName: string]: SettingsDefinition;
59};
60export interface MapConfigurationValue<T extends object> {
61 get<K extends keyof T>(key: K): T[K];
62}
63export interface ConfigurationValueMap {
64 lastUpdateCheck: string | null;
65 yarnPath: PortablePath;
66 ignorePath: boolean;
67 ignoreCwd: boolean;
68 cacheKeyOverride: string | null;
69 globalFolder: PortablePath;
70 cacheFolder: PortablePath;
71 compressionLevel: `mixed` | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
72 virtualFolder: PortablePath;
73 bstatePath: PortablePath;
74 lockfileFilename: Filename;
75 installStatePath: PortablePath;
76 immutablePatterns: Array<string>;
77 rcFilename: Filename;
78 enableGlobalCache: boolean;
79 enableAbsoluteVirtuals: boolean;
80 enableColors: boolean;
81 enableHyperlinks: boolean;
82 enableInlineBuilds: boolean;
83 enableProgressBars: boolean;
84 enableTimers: boolean;
85 preferAggregateCacheInfo: boolean;
86 preferInteractive: boolean;
87 preferTruncatedLines: boolean;
88 progressBarStyle: string | undefined;
89 defaultLanguageName: string;
90 defaultProtocol: string;
91 enableTransparentWorkspaces: boolean;
92 enableMirror: boolean;
93 enableNetwork: boolean;
94 httpProxy: string;
95 httpsProxy: string;
96 unsafeHttpWhitelist: Array<string>;
97 httpTimeout: number;
98 httpRetry: number;
99 networkConcurrency: number;
100 enableTelemetry: boolean;
101 telemetryInterval: number;
102 telemetryUserId: string | null;
103 enableScripts: boolean;
104 enableImmutableCache: boolean;
105 checksumBehavior: string;
106 packageExtensions: Map<string, any>;
107}
108declare type SimpleDefinitionForType<T> = SimpleSettingsDefinition & {
109 type: (T extends boolean ? SettingsType.BOOLEAN : never) | (T extends number ? SettingsType.NUMBER : never) | (T extends PortablePath ? SettingsType.ABSOLUTE_PATH : never) | (T extends string ? SettingsType.LOCATOR | SettingsType.LOCATOR_LOOSE | SettingsType.SECRET | SettingsType.STRING : never) | SettingsType.ANY;
110};
111declare type DefinitionForTypeHelper<T> = T extends Map<string, infer U> ? (MapSettingsDefinition & {
112 valueDefinition: Omit<DefinitionForType<U>, 'default'>;
113}) : T extends MapConfigurationValue<infer U> ? (ShapeSettingsDefinition & {
114 properties: ConfigurationDefinitionMap<U>;
115}) : SimpleDefinitionForType<T>;
116declare type DefinitionForType<T> = T extends Array<infer U> ? (DefinitionForTypeHelper<U> & {
117 isArray: true;
118}) : (DefinitionForTypeHelper<T> & {
119 isArray?: false;
120});
121export declare type ConfigurationDefinitionMap<V = ConfigurationValueMap> = {
122 [K in keyof V]: DefinitionForType<V[K]>;
123};
124declare type SettingTransforms = {
125 hideSecrets: boolean;
126 getNativePaths: boolean;
127};
128export declare enum ProjectLookup {
129 LOCKFILE = 0,
130 MANIFEST = 1,
131 NONE = 2
132}
133export declare type FindProjectOptions = {
134 lookup?: ProjectLookup;
135 strict?: boolean;
136 usePath?: boolean;
137 useRc?: boolean;
138};
139export declare enum PackageExtensionType {
140 Dependency = "Dependency",
141 PeerDependency = "PeerDependency",
142 PeerDependencyMeta = "PeerDependencyMeta"
143}
144export declare type PackageExtension = ({
145 type: PackageExtensionType.Dependency;
146 descriptor: Descriptor;
147} | {
148 type: PackageExtensionType.PeerDependency;
149 descriptor: Descriptor;
150} | {
151 type: PackageExtensionType.PeerDependencyMeta;
152 selector: string;
153 key: keyof PeerDependencyMeta;
154 value: any;
155}) & {
156 active: boolean;
157 description: string;
158};
159export declare class Configuration {
160 static telemetry: TelemetryManager | null;
161 startingCwd: PortablePath;
162 projectCwd: PortablePath | null;
163 plugins: Map<string, Plugin>;
164 settings: Map<string, SettingsDefinition>;
165 values: Map<string, any>;
166 sources: Map<string, string>;
167 invalid: Map<string, string>;
168 packageExtensions: Map<IdentHash, Array<[string, Array<PackageExtension>]>>;
169 limits: Map<string, Limit>;
170 /**
171 * Instantiate a new configuration object with the default values from the
172 * core. You typically don't want to use this, as it will ignore the values
173 * configured in the rc files. Instead, prefer to use `Configuration#find`.
174 */
175 static create(startingCwd: PortablePath, plugins?: Map<string, Plugin>): Configuration;
176 static create(startingCwd: PortablePath, projectCwd: PortablePath | null, plugins?: Map<string, Plugin>): Configuration;
177 /**
178 * Instantiate a new configuration object exposing the configuration obtained
179 * from reading the various rc files and the environment settings.
180 *
181 * The `pluginConfiguration` parameter is expected to indicate:
182 *
183 * 1. which modules should be made available to plugins when they require a
184 * package (this is the dynamic linking part - for example we want all the
185 * plugins to use the exact same version of @yarnpkg/core, which also is the
186 * version used by the running Yarn instance).
187 *
188 * 2. which of those modules are actually plugins that need to be injected
189 * within the configuration.
190 *
191 * Note that some extra plugins will be automatically added based on the
192 * content of the rc files - with the rc plugins taking precedence over
193 * the other ones.
194 *
195 * One particularity: the plugin initialization order is quite strict, with
196 * plugins listed in /foo/bar/.yarnrc.yml taking precedence over plugins
197 * listed in /foo/.yarnrc.yml and /.yarnrc.yml. Additionally, while plugins
198 * can depend on one another, they can only depend on plugins that have been
199 * instantiated before them (so a plugin listed in /foo/.yarnrc.yml can
200 * depend on another one listed on /foo/bar/.yarnrc.yml, but not the other
201 * way around).
202 */
203 static find(startingCwd: PortablePath, pluginConfiguration: PluginConfiguration | null, { lookup, strict, usePath, useRc }?: FindProjectOptions): Promise<Configuration>;
204 static findRcFiles(startingCwd: PortablePath): Promise<{
205 path: PortablePath;
206 cwd: PortablePath;
207 data: any;
208 }[]>;
209 static findHomeRcFile(): Promise<{
210 path: PortablePath;
211 cwd: PortablePath;
212 data: any;
213 } | null>;
214 static findProjectCwd(startingCwd: PortablePath, lockfileFilename: Filename | null): Promise<PortablePath | null>;
215 static updateConfiguration(cwd: PortablePath, patch: {
216 [key: string]: ((current: unknown) => unknown) | {} | undefined;
217 } | ((current: {
218 [key: string]: unknown;
219 }) => {
220 [key: string]: unknown;
221 })): Promise<void>;
222 static updateHomeConfiguration(patch: {
223 [key: string]: ((current: unknown) => unknown) | {} | undefined;
224 } | ((current: {
225 [key: string]: unknown;
226 }) => {
227 [key: string]: unknown;
228 })): Promise<void>;
229 private constructor();
230 activatePlugin(name: string, plugin: Plugin): void;
231 private importSettings;
232 useWithSource(source: string, data: {
233 [key: string]: unknown;
234 }, folder: PortablePath, opts?: {
235 strict?: boolean;
236 overwrite?: boolean;
237 }): void;
238 use(source: string, data: {
239 [key: string]: unknown;
240 }, folder: PortablePath, { strict, overwrite }?: {
241 strict?: boolean;
242 overwrite?: boolean;
243 }): void;
244 get<K extends keyof ConfigurationValueMap>(key: K): ConfigurationValueMap[K];
245 /** @deprecated pass in a known configuration key instead */
246 get<T>(key: string): T;
247 /** @note Type will change to unknown in a future major version */
248 get(key: string): any;
249 getSpecial<T = any>(key: string, { hideSecrets, getNativePaths }: Partial<SettingTransforms>): T;
250 getSubprocessStreams(logFile: PortablePath, { header, prefix, report }: {
251 header?: string;
252 prefix: string;
253 report: Report;
254 }): {
255 stdout: Writable;
256 stderr: Writable;
257 };
258 makeResolver(): MultiResolver;
259 makeFetcher(): MultiFetcher;
260 getLinkers(): import("./Linker").Linker[];
261 refreshPackageExtensions(): Promise<void>;
262 normalizePackage(original: Package): Package;
263 getLimit(key: string): Limit;
264 triggerHook<U extends Array<any>, V, HooksDefinition = Hooks>(get: (hooks: HooksDefinition) => ((...args: U) => V) | undefined, ...args: U): Promise<void>;
265 triggerMultipleHooks<U extends Array<any>, V, HooksDefinition = Hooks>(get: (hooks: HooksDefinition) => ((...args: U) => V) | undefined, argsList: Array<U>): Promise<void>;
266 reduceHook<U extends Array<any>, V, HooksDefinition = Hooks>(get: (hooks: HooksDefinition) => ((reduced: V, ...args: U) => Promise<V>) | undefined, initialValue: V, ...args: U): Promise<V>;
267 firstHook<U extends Array<any>, V, HooksDefinition = Hooks>(get: (hooks: HooksDefinition) => ((...args: U) => Promise<V>) | undefined, ...args: U): Promise<Exclude<V, void> | null>;
268 /**
269 * @deprecated Prefer using formatUtils.pretty instead, which is type-safe
270 */
271 format(value: string, formatType: formatUtils.Type | string): string;
272}
273export {};
274
\No newline at end of file