UNPKG

5.23 kBTypeScriptView Raw
1/// <reference types="node" />
2import { SpawnOptions } from 'child_process';
3/**
4 * Find the directory that contains a given dependency, identified by its 'package.json', from a starting search directory
5 *
6 * (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all
7 * 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236)
8 */
9export declare function findDependencyDirectory(dependencyName: string, searchStart: string): Promise<string>;
10/**
11 * Whether the given dependency is a built-in
12 *
13 * Some dependencies that occur in `package.json` are also built-ins in modern Node
14 * versions (most egregious example: 'punycode'). Detect those and filter them out.
15 */
16export declare function isBuiltinModule(depName: string): any;
17/**
18 * Find the package.json for a given package upwards from the given directory
19 *
20 * (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all
21 * 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236)
22 */
23export declare function findPackageJsonUp(packageName: string, directory: string): Promise<string | undefined>;
24/**
25 * Find a directory up the tree from a starting directory matching a condition
26 *
27 * Will return `undefined` if no directory matches
28 *
29 * (This code is duplicated among jsii/jsii-pacmak/jsii-reflect. Changes should be done in all
30 * 3 locations, and we should unify these at some point: https://github.com/aws/jsii/issues/3236)
31 */
32export declare function findUp(directory: string, pred: (dir: string) => Promise<boolean>): Promise<string | undefined>;
33export interface RetryOptions {
34 /**
35 * The maximum amount of attempts to make.
36 *
37 * @default 5
38 */
39 maxAttempts?: number;
40 /**
41 * The amount of time (in milliseconds) to wait after the first failed attempt.
42 *
43 * @default 150
44 */
45 backoffBaseMilliseconds?: number;
46 /**
47 * The multiplier to apply after each failed attempts. If the backoff before
48 * the previous attempt was `B`, the next backoff is computed as
49 * `B * backoffMultiplier`, creating an exponential series.
50 *
51 * @default 2
52 */
53 backoffMultiplier?: number;
54 /**
55 * An optionnal callback that gets invoked when an attempt failed. This can be
56 * used to give the user indications of what is happening.
57 *
58 * This callback must not throw.
59 *
60 * @param error the error that just occurred
61 * @param attemptsLeft the number of attempts left
62 * @param backoffMilliseconds the amount of milliseconds of back-off that will
63 * be awaited before making the next attempt (if
64 * there are attempts left)
65 */
66 onFailedAttempt?: (error: unknown, attemptsLeft: number, backoffMilliseconds: number) => void;
67}
68export declare class AllAttemptsFailed<R> extends Error {
69 readonly callback: () => Promise<R>;
70 readonly errors: readonly Error[];
71 constructor(callback: () => Promise<R>, errors: readonly Error[]);
72}
73/**
74 * Adds back-off and retry logic around the provided callback.
75 *
76 * @param cb the callback which is to be retried.
77 * @param opts the backoff-and-retry configuration
78 *
79 * @returns the result of `cb`
80 */
81export declare function retry<R>(cb: () => Promise<R>, opts?: RetryOptions, waiter?: (ms: number) => Promise<void>): Promise<R>;
82export interface ShellOptions extends Omit<SpawnOptions, 'shell' | 'stdio'> {
83 /**
84 * Configure in-line retries if the execution fails.
85 *
86 * @default - no retries
87 */
88 readonly retry?: RetryOptions;
89}
90/**
91 * Spawns a child process with the provided command and arguments. The child
92 * process is always spawned using `shell: true`, and the contents of
93 * `process.env` is used as the initial value of the `env` spawn option (values
94 * provided in `options.env` can override those).
95 *
96 * @param cmd the command to shell out to.
97 * @param args the arguments to provide to `cmd`
98 * @param options any options to pass to `spawn`
99 */
100export declare function shell(cmd: string, args: string[], { retry: retryOptions, ...options }?: ShellOptions): Promise<string>;
101/**
102 * Strip filesystem unsafe characters from a string
103 */
104export declare function slugify(x: string): string;
105/**
106 * Class that makes a temporary directory and holds on to an operation object
107 */
108export declare class Scratch<A> {
109 readonly directory: string;
110 readonly object: A;
111 private readonly fake;
112 static make<A>(factory: (dir: string) => Promise<A>): Promise<Scratch<A>>;
113 static make<A>(factory: (dir: string) => A): Promise<Scratch<A>>;
114 static fake<A>(directory: string, object: A): Scratch<A>;
115 static cleanupAll<A>(tempDirs: Array<Scratch<A>>): Promise<void>;
116 private constructor();
117 cleanup(): Promise<void>;
118}
119export declare function setExtend<A>(xs: Set<A>, els: Iterable<A>): void;
120export declare function filterAsync<A>(xs: A[], pred: (x: A) => Promise<boolean>): Promise<A[]>;
121export declare function wait(ms: number): Promise<void>;
122export declare function flatten<A>(xs: readonly A[][]): A[];
123//# sourceMappingURL=util.d.ts.map
\No newline at end of file