-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.d.ts
100 lines (83 loc) · 2.75 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
export type Options = {
/**
* When true, adds the "browser" conditions.
* Otherwise the "node" condition is enabled.
* @default false
*/
browser?: boolean;
/**
* Any custom conditions to match.
* @note Array order does not matter. Priority is determined by the key-order of conditions defined within a package's imports/exports mapping.
* @default []
*/
conditions?: readonly string[];
/**
* When true, adds the "require" condition.
* Otherwise the "import" condition is enabled.
* @default false
*/
require?: boolean;
/**
* Prevents "require", "import", "browser", and/or "node" conditions from being added automatically.
* When enabled, only `options.conditions` are added alongside the "default" condition.
* @important Enabling this deviates from Node.js default behavior.
* @default false
*/
unsafe?: boolean;
}
export function resolve<T=Package>(pkg: T, entry?: string, options?: Options): Imports.Output | Exports.Output | void;
export function imports<T=Package>(pkg: T, entry?: string, options?: Options): Imports.Output | void;
export function exports<T=Package>(pkg: T, target: string, options?: Options): Exports.Output | void;
export function legacy<T=Package>(pkg: T, options: { browser: true, fields?: readonly string[] }): Browser | void;
export function legacy<T=Package>(pkg: T, options: { browser: string, fields?: readonly string[] }): string | false | void;
export function legacy<T=Package>(pkg: T, options: { browser: false, fields?: readonly string[] }): string | void;
export function legacy<T=Package>(pkg: T, options?: {
browser?: boolean | string;
fields?: readonly string[];
}): Browser | string;
// ---
/**
* A resolve condition
* @example "node", "default", "production"
*/
export type Condition = string;
/** An internal file path */
export type Path = `./${string}`;
export type Imports = {
[entry: Imports.Entry]: Imports.Value;
}
export namespace Imports {
export type Entry = `#${string}`;
type External = string;
/** strings are dependency names OR internal paths */
export type Value = External | Path | null | {
[c: Condition]: Value;
} | Value[];
export type Output = Array<External|Path>;
}
export type Exports = Path | {
[path: Exports.Entry]: Exports.Value;
[cond: Condition]: Exports.Value;
}
export namespace Exports {
/** Allows "." and "./{name}" */
export type Entry = `.${string}`;
/** strings must be internal paths */
export type Value = Path | null | {
[c: Condition]: Value;
} | Value[];
export type Output = Path[];
}
export type Package = {
name: string;
version?: string;
module?: string;
main?: string;
imports?: Imports;
exports?: Exports;
browser?: Browser;
[key: string]: any;
}
export type Browser = string[] | string | {
[file: Path | string]: string | false;
}