File size: 1,966 Bytes
d8ae8ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * Configure a target environment.
 */
export declare function defineEnv(opts?: CreateEnvOptions): {
  env: ResolvedEnvironment;
  presets: Preset[];
};

export interface CreateEnvOptions {
  /**
   * Node.js compatibility.
   *
   * - Add `alias` entries for Node.js builtins as `<id>` and `node:<id>`.
   * - Add `inject` entries for Node.js globals `global`, `Buffer`, and `process`.
   *
   * Default: `true`
   */
  nodeCompat?: boolean;

  /**
   * Add `alias` entries to replace npm packages like `node-fetch` with lighter shims.
   *
   * Default: `false`
   */
  npmShims?: boolean;

  /**
   * Additional presets.
   */
  presets?: Preset[];

  /**
   * Additional overrides.
   */
  overrides?: Partial<Environment>;

  /**
   * Resolve paths in the environment to absolute paths.
   *
   * Default: `false`
   */
  resolve?: boolean | EnvResolveOptions;
}

export interface EnvResolveOptions {
  /**
   * Paths to resolve imports from.
   *
   * Always unenv path is appended.
   */
  paths?: (string | URL)[];
}

/**
 * Environment defined by presets.
 */
export interface Environment {
  alias: Readonly<Record<string, string>>;
  // A `false` value is used to drop an inject entry from a parent Environment.
  inject: Readonly<Record<string, string | readonly string[] | false>>;
  polyfill: readonly string[];
  external: readonly string[];
}

/**
 * Environment returned by `defineEnv`.
 *
 * It differs from the preset's Environment as the `inject` map nevers contains a `false` value.
 */
export interface ResolvedEnvironment extends Environment {
  inject: Readonly<Record<string, string | readonly string[]>>;
}

export interface Preset extends Partial<Environment> {
  meta?: {
    /**
     * Preset name.
     */
    readonly name?: string;
    /**
     * Preset version.
     */
    readonly version?: string;
    /**
     * Path or URL to preset entry (used for resolving absolute paths).
     */
    readonly url?: string | URL;
  };
}