vite 6.0.0-beta.8 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of vite might be problematic. Click here for more details.

@@ -6,7 +6,7 @@ export { parseAst, parseAstAsync } from 'rollup/parseAst';
6
6
  import * as http from 'node:http';
7
7
  import { OutgoingHttpHeaders, ClientRequestArgs, IncomingMessage, ClientRequest, Agent, Server, ServerResponse } from 'node:http';
8
8
  import { Http2SecureServer } from 'node:http2';
9
- import { Stats } from 'node:fs';
9
+ import * as fs from 'node:fs';
10
10
  import * as events from 'node:events';
11
11
  import { EventEmitter } from 'node:events';
12
12
  import { ServerOptions as HttpsServerOptions, Server as HttpsServer } from 'node:https';
@@ -15,7 +15,7 @@ import * as url from 'node:url';
15
15
  import { URL } from 'node:url';
16
16
  import * as stream from 'node:stream';
17
17
  import { Duplex, DuplexOptions } from 'node:stream';
18
- import { FetchFunctionOptions, FetchResult, ModuleRunnerOptions, ModuleRunnerHMRConnection, ModuleRunnerHmr, ModuleEvaluator, ModuleRunner } from 'vite/module-runner';
18
+ import { FetchFunctionOptions, FetchResult, ModuleRunnerOptions, ModuleRunnerHmr, ModuleEvaluator, ModuleRunner } from 'vite/module-runner';
19
19
  export { FetchFunction, FetchResult } from 'vite/module-runner';
20
20
  import { BuildOptions as esbuild_BuildOptions, TransformOptions as esbuild_TransformOptions, TransformResult as esbuild_TransformResult } from 'esbuild';
21
21
  export { TransformOptions as EsbuildTransformOptions, version as esbuildVersion } from 'esbuild';
@@ -63,107 +63,211 @@ interface ResolverObject {
63
63
  */
64
64
  type AliasOptions = readonly Alias[] | { [find: string]: string }
65
65
 
66
- // Inlined with the following changes:
67
- // 1. Rename `ChokidarOptions` to `WatchOptions` (compat with chokidar v3)
68
- // 2. Remove internal properties exposed from `FSWatcher`
69
- // 3. Remove unneeded types from the tweaks above
70
- // 4. Add spacing and formatted for readability
66
+ type AnymatchFn = (testString: string) => boolean
67
+ type AnymatchPattern = string | RegExp | AnymatchFn
68
+ type AnymatchMatcher = AnymatchPattern | AnymatchPattern[]
71
69
 
72
- // #region handler.d.ts
70
+ // Inlined to avoid extra dependency (chokidar is bundled in the published build)
73
71
 
74
- declare const EVENTS: {
75
- readonly ALL: 'all'
76
- readonly READY: 'ready'
77
- readonly ADD: 'add'
78
- readonly CHANGE: 'change'
79
- readonly ADD_DIR: 'addDir'
80
- readonly UNLINK: 'unlink'
81
- readonly UNLINK_DIR: 'unlinkDir'
82
- readonly RAW: 'raw'
83
- readonly ERROR: 'error'
84
- }
85
- type EventName = (typeof EVENTS)[keyof typeof EVENTS]
72
+ declare class FSWatcher extends EventEmitter implements fs.FSWatcher {
73
+ options: WatchOptions
86
74
 
87
- type Path = string
75
+ /**
76
+ * Constructs a new FSWatcher instance with optional WatchOptions parameter.
77
+ */
78
+ constructor(options?: WatchOptions)
88
79
 
89
- // #endregion
80
+ /**
81
+ * When called, requests that the Node.js event loop not exit so long as the fs.FSWatcher is active.
82
+ * Calling watcher.ref() multiple times will have no effect.
83
+ */
84
+ ref(): this
90
85
 
91
- // #region index.d.ts
86
+ /**
87
+ * When called, the active fs.FSWatcher object will not require the Node.js event loop to remain active.
88
+ * If there is no other activity keeping the event loop running, the process may exit before the fs.FSWatcher object's callback is invoked.
89
+ * Calling watcher.unref() multiple times will have no effect.
90
+ */
91
+ unref(): this
92
92
 
93
- type AWF = {
94
- stabilityThreshold: number
95
- pollInterval: number
96
- }
97
- type BasicOpts = {
98
- persistent: boolean
99
- ignoreInitial: boolean
100
- followSymlinks: boolean
101
- cwd?: string
102
- usePolling: boolean
103
- interval: number
104
- binaryInterval: number
105
- alwaysStat?: boolean
106
- depth?: number
107
- ignorePermissionErrors: boolean
108
- atomic: boolean | number
109
- }
93
+ /**
94
+ * Add files, directories, or glob patterns for tracking. Takes an array of strings or just one
95
+ * string.
96
+ */
97
+ add(paths: string | ReadonlyArray<string>): this
98
+
99
+ /**
100
+ * Stop watching files, directories, or glob patterns. Takes an array of strings or just one
101
+ * string.
102
+ */
103
+ unwatch(paths: string | ReadonlyArray<string>): this
110
104
 
111
- type WatchOptions = Partial<
112
- BasicOpts & {
113
- ignored: Matcher | Matcher[]
114
- awaitWriteFinish: boolean | Partial<AWF>
105
+ /**
106
+ * Returns an object representing all the paths on the file system being watched by this
107
+ * `FSWatcher` instance. The object's keys are all the directories (using absolute paths unless
108
+ * the `cwd` option was used), and the values are arrays of the names of the items contained in
109
+ * each directory.
110
+ */
111
+ getWatched(): {
112
+ [directory: string]: string[]
115
113
  }
116
- >
117
114
 
118
- type FSWInstanceOptions = BasicOpts & {
119
- ignored: Matcher[]
120
- awaitWriteFinish: false | AWF
121
- }
115
+ /**
116
+ * Removes all listeners from watched files.
117
+ */
118
+ close(): Promise<void>
119
+
120
+ on(
121
+ event: 'add' | 'addDir' | 'change',
122
+ listener: (path: string, stats?: fs.Stats) => void,
123
+ ): this
124
+
125
+ on(
126
+ event: 'all',
127
+ listener: (
128
+ eventName: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir',
129
+ path: string,
130
+ stats?: fs.Stats,
131
+ ) => void,
132
+ ): this
133
+
134
+ /**
135
+ * Error occurred
136
+ */
137
+ on(event: 'error', listener: (error: Error) => void): this
138
+
139
+ /**
140
+ * Exposes the native Node `fs.FSWatcher events`
141
+ */
142
+ on(
143
+ event: 'raw',
144
+ listener: (eventName: string, path: string, details: any) => void,
145
+ ): this
122
146
 
123
- type EmitArgs = [EventName, Path | Error, any?, any?, any?]
147
+ /**
148
+ * Fires when the initial scan is complete
149
+ */
150
+ on(event: 'ready', listener: () => void): this
124
151
 
125
- type MatchFunction = (val: string, stats?: Stats) => boolean
152
+ on(event: 'unlink' | 'unlinkDir', listener: (path: string) => void): this
126
153
 
127
- interface MatcherObject {
128
- path: string
129
- recursive?: boolean
154
+ on(event: string, listener: (...args: any[]) => void): this
130
155
  }
131
156
 
132
- type Matcher = string | RegExp | MatchFunction | MatcherObject
157
+ interface WatchOptions {
158
+ /**
159
+ * Indicates whether the process should continue to run as long as files are being watched. If
160
+ * set to `false` when using `fsevents` to watch, no more events will be emitted after `ready`,
161
+ * even if the process continues to run.
162
+ */
163
+ persistent?: boolean
133
164
 
134
- /**
135
- * Watches files & directories for changes. Emitted events:
136
- * `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
137
- *
138
- * new FSWatcher()
139
- * .add(directories)
140
- * .on('add', path => log('File', path, 'was added'))
141
- */
142
- declare class FSWatcher extends EventEmitter {
143
- closed: boolean
144
- options: FSWInstanceOptions
165
+ /**
166
+ * ([anymatch](https://github.com/micromatch/anymatch)-compatible definition) Defines files/paths to
167
+ * be ignored. The whole relative or absolute path is tested, not just filename. If a function
168
+ * with two arguments is provided, it gets called twice per path - once with a single argument
169
+ * (the path), second time with two arguments (the path and the
170
+ * [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object of that path).
171
+ */
172
+ ignored?: AnymatchMatcher
173
+
174
+ /**
175
+ * If set to `false` then `add`/`addDir` events are also emitted for matching paths while
176
+ * instantiating the watching as chokidar discovers these file paths (before the `ready` event).
177
+ */
178
+ ignoreInitial?: boolean
145
179
 
146
- constructor(_opts?: WatchOptions)
180
+ /**
181
+ * When `false`, only the symlinks themselves will be watched for changes instead of following
182
+ * the link references and bubbling events through the link's path.
183
+ */
184
+ followSymlinks?: boolean
147
185
 
148
186
  /**
149
- * Adds paths to be watched on an existing FSWatcher instance.
150
- * @param paths_ file or file list. Other arguments are unused
187
+ * The base directory from which watch `paths` are to be derived. Paths emitted with events will
188
+ * be relative to this.
151
189
  */
152
- add(paths_: Path | Path[], _origAdd?: string, _internal?: boolean): FSWatcher
190
+ cwd?: string
191
+
153
192
  /**
154
- * Close watchers or start ignoring events from specified paths.
193
+ * If set to true then the strings passed to .watch() and .add() are treated as literal path
194
+ * names, even if they look like globs.
195
+ *
196
+ * @default false
155
197
  */
156
- unwatch(paths_: Path | Path[]): FSWatcher
198
+ disableGlobbing?: boolean
199
+
157
200
  /**
158
- * Close watchers and remove all listeners from watched paths.
201
+ * Whether to use fs.watchFile (backed by polling), or fs.watch. If polling leads to high CPU
202
+ * utilization, consider setting this to `false`. It is typically necessary to **set this to
203
+ * `true` to successfully watch files over a network**, and it may be necessary to successfully
204
+ * watch files in other non-standard situations. Setting to `true` explicitly on OS X overrides
205
+ * the `useFsEvents` default.
159
206
  */
160
- close(): Promise<void>
207
+ usePolling?: boolean
208
+
209
+ /**
210
+ * Whether to use the `fsevents` watching interface if available. When set to `true` explicitly
211
+ * and `fsevents` is available this supersedes the `usePolling` setting. When set to `false` on
212
+ * OS X, `usePolling: true` becomes the default.
213
+ */
214
+ useFsEvents?: boolean
215
+
216
+ /**
217
+ * If relying upon the [`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object that
218
+ * may get passed with `add`, `addDir`, and `change` events, set this to `true` to ensure it is
219
+ * provided even in cases where it wasn't already available from the underlying watch events.
220
+ */
221
+ alwaysStat?: boolean
222
+
223
+ /**
224
+ * If set, limits how many levels of subdirectories will be traversed.
225
+ */
226
+ depth?: number
227
+
228
+ /**
229
+ * Interval of file system polling.
230
+ */
231
+ interval?: number
232
+
233
+ /**
234
+ * Interval of file system polling for binary files. ([see list of binary extensions](https://gi
235
+ * thub.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json))
236
+ */
237
+ binaryInterval?: number
238
+
161
239
  /**
162
- * Expose list of watched paths
163
- * @returns for chaining
240
+ * Indicates whether to watch files that don't have read permissions if possible. If watching
241
+ * fails due to `EPERM` or `EACCES` with this set to `true`, the errors will be suppressed
242
+ * silently.
164
243
  */
165
- getWatched(): Record<string, string[]>
166
- emitWithAll(event: EventName, args: EmitArgs): void
244
+ ignorePermissionErrors?: boolean
245
+
246
+ /**
247
+ * `true` if `useFsEvents` and `usePolling` are `false`. Automatically filters out artifacts
248
+ * that occur when using editors that use "atomic writes" instead of writing directly to the
249
+ * source file. If a file is re-added within 100 ms of being deleted, Chokidar emits a `change`
250
+ * event rather than `unlink` then `add`. If the default of 100 ms does not work well for you,
251
+ * you can override it by setting `atomic` to a custom value, in milliseconds.
252
+ */
253
+ atomic?: boolean | number
254
+
255
+ /**
256
+ * can be set to an object in order to adjust timing params:
257
+ */
258
+ awaitWriteFinish?: AwaitWriteFinishOptions | boolean
259
+ }
260
+
261
+ interface AwaitWriteFinishOptions {
262
+ /**
263
+ * Amount of time in milliseconds for a file size to remain constant before emitting its event.
264
+ */
265
+ stabilityThreshold?: number
266
+
267
+ /**
268
+ * File size polling interval.
269
+ */
270
+ pollInterval?: number
167
271
  }
168
272
 
169
273
  // Inlined to avoid extra dependency
@@ -1085,6 +1189,38 @@ interface HmrContext {
1085
1189
  server: ViteDevServer;
1086
1190
  }
1087
1191
  interface HotChannelClient {
1192
+ send(payload: HotPayload): void;
1193
+ }
1194
+ /** @deprecated use `HotChannelClient` instead */
1195
+ type HMRBroadcasterClient = HotChannelClient;
1196
+ type HotChannelListener<T extends string = string> = (data: InferCustomEventPayload<T>, client: HotChannelClient) => void;
1197
+ interface HotChannel<Api = any> {
1198
+ /**
1199
+ * Broadcast events to all clients
1200
+ */
1201
+ send?(payload: HotPayload): void;
1202
+ /**
1203
+ * Handle custom event emitted by `import.meta.hot.send`
1204
+ */
1205
+ on?<T extends string>(event: T, listener: HotChannelListener<T>): void;
1206
+ on?(event: 'connection', listener: () => void): void;
1207
+ /**
1208
+ * Unregister event listener
1209
+ */
1210
+ off?(event: string, listener: Function): void;
1211
+ /**
1212
+ * Start listening for messages
1213
+ */
1214
+ listen?(): void;
1215
+ /**
1216
+ * Disconnect all clients, called when server is closed or restarted.
1217
+ */
1218
+ close?(): Promise<unknown> | void;
1219
+ api?: Api;
1220
+ }
1221
+ /** @deprecated use `HotChannel` instead */
1222
+ type HMRChannel = HotChannel;
1223
+ interface NormalizedHotChannelClient {
1088
1224
  /**
1089
1225
  * Send event to the client
1090
1226
  */
@@ -1094,9 +1230,7 @@ interface HotChannelClient {
1094
1230
  */
1095
1231
  send(event: string, payload?: CustomPayload['data']): void;
1096
1232
  }
1097
- /** @deprecated use `HotChannelClient` instead */
1098
- type HMRBroadcasterClient = HotChannelClient;
1099
- interface HotChannel {
1233
+ interface NormalizedHotChannel<Api = any> {
1100
1234
  /**
1101
1235
  * Broadcast events to all clients
1102
1236
  */
@@ -1108,12 +1242,17 @@ interface HotChannel {
1108
1242
  /**
1109
1243
  * Handle custom event emitted by `import.meta.hot.send`
1110
1244
  */
1111
- on<T extends string>(event: T, listener: (data: InferCustomEventPayload<T>, client: HotChannelClient, ...args: any[]) => void): void;
1245
+ on<T extends string>(event: T, listener: (data: InferCustomEventPayload<T>, client: NormalizedHotChannelClient) => void): void;
1112
1246
  on(event: 'connection', listener: () => void): void;
1113
1247
  /**
1114
1248
  * Unregister event listener
1115
1249
  */
1116
1250
  off(event: string, listener: Function): void;
1251
+ handleInvoke(payload: HotPayload): Promise<{
1252
+ r: any;
1253
+ } | {
1254
+ e: any;
1255
+ }>;
1117
1256
  /**
1118
1257
  * Start listening for messages
1119
1258
  */
@@ -1122,21 +1261,19 @@ interface HotChannel {
1122
1261
  * Disconnect all clients, called when server is closed or restarted.
1123
1262
  */
1124
1263
  close(): Promise<unknown> | void;
1264
+ api?: Api;
1125
1265
  }
1126
- /** @deprecated use `HotChannel` instead */
1127
- type HMRChannel = HotChannel;
1128
- interface ServerHotChannel extends HotChannel {
1129
- api: {
1130
- innerEmitter: EventEmitter;
1131
- outsideEmitter: EventEmitter;
1132
- };
1133
- }
1266
+ type ServerHotChannelApi = {
1267
+ innerEmitter: EventEmitter;
1268
+ outsideEmitter: EventEmitter;
1269
+ };
1270
+ type ServerHotChannel = HotChannel<ServerHotChannelApi>;
1134
1271
  /** @deprecated use `ServerHotChannel` instead */
1135
1272
  type ServerHMRChannel = ServerHotChannel;
1136
1273
  declare function createServerHotChannel(): ServerHotChannel;
1137
1274
  /** @deprecated use `environment.hot` instead */
1138
- interface HotBroadcaster extends HotChannel {
1139
- readonly channels: HotChannel[];
1275
+ interface HotBroadcaster extends NormalizedHotChannel {
1276
+ readonly channels: NormalizedHotChannel[];
1140
1277
  /**
1141
1278
  * A noop.
1142
1279
  * @deprecated
@@ -1147,1576 +1284,1578 @@ interface HotBroadcaster extends HotChannel {
1147
1284
  /** @deprecated use `environment.hot` instead */
1148
1285
  type HMRBroadcaster = HotBroadcaster;
1149
1286
 
1150
- declare class RemoteEnvironmentTransport {
1151
- private readonly options;
1152
- constructor(options: {
1153
- send: (data: any) => void;
1154
- onMessage: (handler: (data: any) => void) => void;
1155
- });
1156
- register(environment: DevEnvironment): void;
1157
- }
1287
+ // Modified and inlined to avoid extra dependency
1288
+ // Source: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/ws/index.d.ts
1158
1289
 
1159
- interface DevEnvironmentContext {
1160
- hot: false | HotChannel;
1161
- options?: EnvironmentOptions;
1162
- remoteRunner?: {
1163
- inlineSourceMap?: boolean;
1164
- transport?: RemoteEnvironmentTransport;
1165
- };
1166
- depsOptimizer?: DepsOptimizer;
1167
- }
1168
- declare class DevEnvironment extends BaseEnvironment {
1169
- mode: "dev";
1170
- moduleGraph: EnvironmentModuleGraph;
1171
- depsOptimizer?: DepsOptimizer;
1172
- get pluginContainer(): EnvironmentPluginContainer;
1173
- /**
1174
- * Hot channel for this environment. If not provided or disabled,
1175
- * it will be a noop channel that does nothing.
1176
- *
1177
- * @example
1178
- * environment.hot.send({ type: 'full-reload' })
1179
- */
1180
- hot: HotChannel;
1181
- constructor(name: string, config: ResolvedConfig, context: DevEnvironmentContext);
1182
- init(options?: {
1183
- watcher?: FSWatcher;
1184
- /**
1185
- * the previous instance used for the environment with the same name
1186
- *
1187
- * when using, the consumer should check if it's an instance generated from the same class or factory function
1188
- */
1189
- previousInstance?: DevEnvironment;
1190
- }): Promise<void>;
1191
- /**
1192
- * When the dev server is restarted, the methods are called in the following order:
1193
- * - new instance `init`
1194
- * - previous instance `close`
1195
- * - new instance `listen`
1196
- */
1197
- listen(server: ViteDevServer): Promise<void>;
1198
- fetchModule(id: string, importer?: string, options?: FetchFunctionOptions): Promise<FetchResult>;
1199
- reloadModule(module: EnvironmentModuleNode): Promise<void>;
1200
- transformRequest(url: string): Promise<TransformResult | null>;
1201
- warmupRequest(url: string): Promise<void>;
1202
- close(): Promise<void>;
1203
- /**
1204
- * Calling `await environment.waitForRequestsIdle(id)` will wait until all static imports
1205
- * are processed after the first transformRequest call. If called from a load or transform
1206
- * plugin hook, the id needs to be passed as a parameter to avoid deadlocks.
1207
- * Calling this function after the first static imports section of the module graph has been
1208
- * processed will resolve immediately.
1209
- * @experimental
1210
- */
1211
- waitForRequestsIdle(ignoredId?: string): Promise<void>;
1212
- }
1290
+ declare const WebSocketAlias: typeof WebSocket
1291
+ interface WebSocketAlias extends WebSocket {}
1292
+
1293
+ // WebSocket socket.
1294
+ declare class WebSocket extends EventEmitter {
1295
+ /** The connection is not yet open. */
1296
+ static readonly CONNECTING: 0
1297
+ /** The connection is open and ready to communicate. */
1298
+ static readonly OPEN: 1
1299
+ /** The connection is in the process of closing. */
1300
+ static readonly CLOSING: 2
1301
+ /** The connection is closed. */
1302
+ static readonly CLOSED: 3
1303
+
1304
+ binaryType: 'nodebuffer' | 'arraybuffer' | 'fragments'
1305
+ readonly bufferedAmount: number
1306
+ readonly extensions: string
1307
+ /** Indicates whether the websocket is paused */
1308
+ readonly isPaused: boolean
1309
+ readonly protocol: string
1310
+ /** The current state of the connection */
1311
+ readonly readyState:
1312
+ | typeof WebSocket.CONNECTING
1313
+ | typeof WebSocket.OPEN
1314
+ | typeof WebSocket.CLOSING
1315
+ | typeof WebSocket.CLOSED
1316
+ readonly url: string
1317
+
1318
+ /** The connection is not yet open. */
1319
+ readonly CONNECTING: 0
1320
+ /** The connection is open and ready to communicate. */
1321
+ readonly OPEN: 1
1322
+ /** The connection is in the process of closing. */
1323
+ readonly CLOSING: 2
1324
+ /** The connection is closed. */
1325
+ readonly CLOSED: 3
1326
+
1327
+ onopen: ((event: WebSocket.Event) => void) | null
1328
+ onerror: ((event: WebSocket.ErrorEvent) => void) | null
1329
+ onclose: ((event: WebSocket.CloseEvent) => void) | null
1330
+ onmessage: ((event: WebSocket.MessageEvent) => void) | null
1331
+
1332
+ constructor(address: null)
1333
+ constructor(
1334
+ address: string | URL,
1335
+ options?: WebSocket.ClientOptions | ClientRequestArgs,
1336
+ )
1337
+ constructor(
1338
+ address: string | URL,
1339
+ protocols?: string | string[],
1340
+ options?: WebSocket.ClientOptions | ClientRequestArgs,
1341
+ )
1342
+
1343
+ close(code?: number, data?: string | Buffer): void
1344
+ ping(data?: any, mask?: boolean, cb?: (err: Error) => void): void
1345
+ pong(data?: any, mask?: boolean, cb?: (err: Error) => void): void
1346
+ send(data: any, cb?: (err?: Error) => void): void
1347
+ send(
1348
+ data: any,
1349
+ options: {
1350
+ mask?: boolean | undefined
1351
+ binary?: boolean | undefined
1352
+ compress?: boolean | undefined
1353
+ fin?: boolean | undefined
1354
+ },
1355
+ cb?: (err?: Error) => void,
1356
+ ): void
1357
+ terminate(): void
1213
1358
 
1214
- interface RollupCommonJSOptions {
1215
1359
  /**
1216
- * A minimatch pattern, or array of patterns, which specifies the files in
1217
- * the build the plugin should operate on. By default, all files with
1218
- * extension `".cjs"` or those in `extensions` are included, but you can
1219
- * narrow this list by only including specific files. These files will be
1220
- * analyzed and transpiled if either the analysis does not find ES module
1221
- * specific statements or `transformMixedEsModules` is `true`.
1222
- * @default undefined
1223
- */
1224
- include?: string | RegExp | readonly (string | RegExp)[]
1225
- /**
1226
- * A minimatch pattern, or array of patterns, which specifies the files in
1227
- * the build the plugin should _ignore_. By default, all files with
1228
- * extensions other than those in `extensions` or `".cjs"` are ignored, but you
1229
- * can exclude additional files. See also the `include` option.
1230
- * @default undefined
1360
+ * Pause the websocket causing it to stop emitting events. Some events can still be
1361
+ * emitted after this is called, until all buffered data is consumed. This method
1362
+ * is a noop if the ready state is `CONNECTING` or `CLOSED`.
1231
1363
  */
1232
- exclude?: string | RegExp | readonly (string | RegExp)[]
1364
+ pause(): void
1233
1365
  /**
1234
- * For extensionless imports, search for extensions other than .js in the
1235
- * order specified. Note that you need to make sure that non-JavaScript files
1236
- * are transpiled by another plugin first.
1237
- * @default [ '.js' ]
1366
+ * Make a paused socket resume emitting events. This method is a noop if the ready
1367
+ * state is `CONNECTING` or `CLOSED`.
1238
1368
  */
1239
- extensions?: ReadonlyArray<string>
1369
+ resume(): void
1370
+
1371
+ // HTML5 WebSocket events
1372
+ addEventListener(
1373
+ method: 'message',
1374
+ cb: (event: WebSocket.MessageEvent) => void,
1375
+ options?: WebSocket.EventListenerOptions,
1376
+ ): void
1377
+ addEventListener(
1378
+ method: 'close',
1379
+ cb: (event: WebSocket.CloseEvent) => void,
1380
+ options?: WebSocket.EventListenerOptions,
1381
+ ): void
1382
+ addEventListener(
1383
+ method: 'error',
1384
+ cb: (event: WebSocket.ErrorEvent) => void,
1385
+ options?: WebSocket.EventListenerOptions,
1386
+ ): void
1387
+ addEventListener(
1388
+ method: 'open',
1389
+ cb: (event: WebSocket.Event) => void,
1390
+ options?: WebSocket.EventListenerOptions,
1391
+ ): void
1392
+
1393
+ removeEventListener(
1394
+ method: 'message',
1395
+ cb: (event: WebSocket.MessageEvent) => void,
1396
+ ): void
1397
+ removeEventListener(
1398
+ method: 'close',
1399
+ cb: (event: WebSocket.CloseEvent) => void,
1400
+ ): void
1401
+ removeEventListener(
1402
+ method: 'error',
1403
+ cb: (event: WebSocket.ErrorEvent) => void,
1404
+ ): void
1405
+ removeEventListener(
1406
+ method: 'open',
1407
+ cb: (event: WebSocket.Event) => void,
1408
+ ): void
1409
+
1410
+ // Events
1411
+ on(
1412
+ event: 'close',
1413
+ listener: (this: WebSocket, code: number, reason: Buffer) => void,
1414
+ ): this
1415
+ on(event: 'error', listener: (this: WebSocket, err: Error) => void): this
1416
+ on(
1417
+ event: 'upgrade',
1418
+ listener: (this: WebSocket, request: IncomingMessage) => void,
1419
+ ): this
1420
+ on(
1421
+ event: 'message',
1422
+ listener: (
1423
+ this: WebSocket,
1424
+ data: WebSocket.RawData,
1425
+ isBinary: boolean,
1426
+ ) => void,
1427
+ ): this
1428
+ on(event: 'open', listener: (this: WebSocket) => void): this
1429
+ on(
1430
+ event: 'ping' | 'pong',
1431
+ listener: (this: WebSocket, data: Buffer) => void,
1432
+ ): this
1433
+ on(
1434
+ event: 'unexpected-response',
1435
+ listener: (
1436
+ this: WebSocket,
1437
+ request: ClientRequest,
1438
+ response: IncomingMessage,
1439
+ ) => void,
1440
+ ): this
1441
+ on(
1442
+ event: string | symbol,
1443
+ listener: (this: WebSocket, ...args: any[]) => void,
1444
+ ): this
1445
+
1446
+ once(
1447
+ event: 'close',
1448
+ listener: (this: WebSocket, code: number, reason: Buffer) => void,
1449
+ ): this
1450
+ once(event: 'error', listener: (this: WebSocket, err: Error) => void): this
1451
+ once(
1452
+ event: 'upgrade',
1453
+ listener: (this: WebSocket, request: IncomingMessage) => void,
1454
+ ): this
1455
+ once(
1456
+ event: 'message',
1457
+ listener: (
1458
+ this: WebSocket,
1459
+ data: WebSocket.RawData,
1460
+ isBinary: boolean,
1461
+ ) => void,
1462
+ ): this
1463
+ once(event: 'open', listener: (this: WebSocket) => void): this
1464
+ once(
1465
+ event: 'ping' | 'pong',
1466
+ listener: (this: WebSocket, data: Buffer) => void,
1467
+ ): this
1468
+ once(
1469
+ event: 'unexpected-response',
1470
+ listener: (
1471
+ this: WebSocket,
1472
+ request: ClientRequest,
1473
+ response: IncomingMessage,
1474
+ ) => void,
1475
+ ): this
1476
+ once(
1477
+ event: string | symbol,
1478
+ listener: (this: WebSocket, ...args: any[]) => void,
1479
+ ): this
1480
+
1481
+ off(
1482
+ event: 'close',
1483
+ listener: (this: WebSocket, code: number, reason: Buffer) => void,
1484
+ ): this
1485
+ off(event: 'error', listener: (this: WebSocket, err: Error) => void): this
1486
+ off(
1487
+ event: 'upgrade',
1488
+ listener: (this: WebSocket, request: IncomingMessage) => void,
1489
+ ): this
1490
+ off(
1491
+ event: 'message',
1492
+ listener: (
1493
+ this: WebSocket,
1494
+ data: WebSocket.RawData,
1495
+ isBinary: boolean,
1496
+ ) => void,
1497
+ ): this
1498
+ off(event: 'open', listener: (this: WebSocket) => void): this
1499
+ off(
1500
+ event: 'ping' | 'pong',
1501
+ listener: (this: WebSocket, data: Buffer) => void,
1502
+ ): this
1503
+ off(
1504
+ event: 'unexpected-response',
1505
+ listener: (
1506
+ this: WebSocket,
1507
+ request: ClientRequest,
1508
+ response: IncomingMessage,
1509
+ ) => void,
1510
+ ): this
1511
+ off(
1512
+ event: string | symbol,
1513
+ listener: (this: WebSocket, ...args: any[]) => void,
1514
+ ): this
1515
+
1516
+ addListener(
1517
+ event: 'close',
1518
+ listener: (code: number, reason: Buffer) => void,
1519
+ ): this
1520
+ addListener(event: 'error', listener: (err: Error) => void): this
1521
+ addListener(
1522
+ event: 'upgrade',
1523
+ listener: (request: IncomingMessage) => void,
1524
+ ): this
1525
+ addListener(
1526
+ event: 'message',
1527
+ listener: (data: WebSocket.RawData, isBinary: boolean) => void,
1528
+ ): this
1529
+ addListener(event: 'open', listener: () => void): this
1530
+ addListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this
1531
+ addListener(
1532
+ event: 'unexpected-response',
1533
+ listener: (request: ClientRequest, response: IncomingMessage) => void,
1534
+ ): this
1535
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this
1536
+
1537
+ removeListener(
1538
+ event: 'close',
1539
+ listener: (code: number, reason: Buffer) => void,
1540
+ ): this
1541
+ removeListener(event: 'error', listener: (err: Error) => void): this
1542
+ removeListener(
1543
+ event: 'upgrade',
1544
+ listener: (request: IncomingMessage) => void,
1545
+ ): this
1546
+ removeListener(
1547
+ event: 'message',
1548
+ listener: (data: WebSocket.RawData, isBinary: boolean) => void,
1549
+ ): this
1550
+ removeListener(event: 'open', listener: () => void): this
1551
+ removeListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this
1552
+ removeListener(
1553
+ event: 'unexpected-response',
1554
+ listener: (request: ClientRequest, response: IncomingMessage) => void,
1555
+ ): this
1556
+ removeListener(
1557
+ event: string | symbol,
1558
+ listener: (...args: any[]) => void,
1559
+ ): this
1560
+ }
1561
+
1562
+ declare namespace WebSocket {
1240
1563
  /**
1241
- * If true then uses of `global` won't be dealt with by this plugin
1242
- * @default false
1564
+ * Data represents the raw message payload received over the WebSocket.
1243
1565
  */
1244
- ignoreGlobal?: boolean
1566
+ type RawData = Buffer | ArrayBuffer | Buffer[]
1567
+
1245
1568
  /**
1246
- * If false, skips source map generation for CommonJS modules. This will
1247
- * improve performance.
1248
- * @default true
1569
+ * Data represents the message payload received over the WebSocket.
1249
1570
  */
1250
- sourceMap?: boolean
1571
+ type Data = string | Buffer | ArrayBuffer | Buffer[]
1572
+
1251
1573
  /**
1252
- * Some `require` calls cannot be resolved statically to be translated to
1253
- * imports.
1254
- * When this option is set to `false`, the generated code will either
1255
- * directly throw an error when such a call is encountered or, when
1256
- * `dynamicRequireTargets` is used, when such a call cannot be resolved with a
1257
- * configured dynamic require target.
1258
- * Setting this option to `true` will instead leave the `require` call in the
1259
- * code or use it as a fallback for `dynamicRequireTargets`.
1260
- * @default false
1574
+ * CertMeta represents the accepted types for certificate & key data.
1261
1575
  */
1262
- ignoreDynamicRequires?: boolean
1576
+ type CertMeta = string | string[] | Buffer | Buffer[]
1577
+
1263
1578
  /**
1264
- * Instructs the plugin whether to enable mixed module transformations. This
1265
- * is useful in scenarios with modules that contain a mix of ES `import`
1266
- * statements and CommonJS `require` expressions. Set to `true` if `require`
1267
- * calls should be transformed to imports in mixed modules, or `false` if the
1268
- * `require` expressions should survive the transformation. The latter can be
1269
- * important if the code contains environment detection, or you are coding
1270
- * for an environment with special treatment for `require` calls such as
1271
- * ElectronJS. See also the `ignore` option.
1272
- * @default false
1579
+ * VerifyClientCallbackSync is a synchronous callback used to inspect the
1580
+ * incoming message. The return value (boolean) of the function determines
1581
+ * whether or not to accept the handshake.
1273
1582
  */
1274
- transformMixedEsModules?: boolean
1275
- /**
1276
- * By default, this plugin will try to hoist `require` statements as imports
1277
- * to the top of each file. While this works well for many code bases and
1278
- * allows for very efficient ESM output, it does not perfectly capture
1279
- * CommonJS semantics as the order of side effects like log statements may
1280
- * change. But it is especially problematic when there are circular `require`
1281
- * calls between CommonJS modules as those often rely on the lazy execution of
1282
- * nested `require` calls.
1283
- *
1284
- * Setting this option to `true` will wrap all CommonJS files in functions
1285
- * which are executed when they are required for the first time, preserving
1286
- * NodeJS semantics. Note that this can have an impact on the size and
1287
- * performance of the generated code.
1288
- *
1289
- * The default value of `"auto"` will only wrap CommonJS files when they are
1290
- * part of a CommonJS dependency cycle, e.g. an index file that is required by
1291
- * many of its dependencies. All other CommonJS files are hoisted. This is the
1292
- * recommended setting for most code bases.
1293
- *
1294
- * `false` will entirely prevent wrapping and hoist all files. This may still
1295
- * work depending on the nature of cyclic dependencies but will often cause
1296
- * problems.
1297
- *
1298
- * You can also provide a minimatch pattern, or array of patterns, to only
1299
- * specify a subset of files which should be wrapped in functions for proper
1300
- * `require` semantics.
1301
- *
1302
- * `"debug"` works like `"auto"` but after bundling, it will display a warning
1303
- * containing a list of ids that have been wrapped which can be used as
1304
- * minimatch pattern for fine-tuning.
1305
- * @default "auto"
1306
- */
1307
- strictRequires?: boolean | string | RegExp | readonly (string | RegExp)[]
1308
- /**
1309
- * Sometimes you have to leave require statements unconverted. Pass an array
1310
- * containing the IDs or a `id => boolean` function.
1311
- * @default []
1312
- */
1313
- ignore?: ReadonlyArray<string> | ((id: string) => boolean)
1314
- /**
1315
- * In most cases, where `require` calls are inside a `try-catch` clause,
1316
- * they should be left unconverted as it requires an optional dependency
1317
- * that may or may not be installed beside the rolled up package.
1318
- * Due to the conversion of `require` to a static `import` - the call is
1319
- * hoisted to the top of the file, outside the `try-catch` clause.
1320
- *
1321
- * - `true`: Default. All `require` calls inside a `try` will be left unconverted.
1322
- * - `false`: All `require` calls inside a `try` will be converted as if the
1323
- * `try-catch` clause is not there.
1324
- * - `remove`: Remove all `require` calls from inside any `try` block.
1325
- * - `string[]`: Pass an array containing the IDs to left unconverted.
1326
- * - `((id: string) => boolean|'remove')`: Pass a function that controls
1327
- * individual IDs.
1328
- *
1329
- * @default true
1330
- */
1331
- ignoreTryCatch?:
1332
- | boolean
1333
- | 'remove'
1334
- | ReadonlyArray<string>
1335
- | ((id: string) => boolean | 'remove')
1336
- /**
1337
- * Controls how to render imports from external dependencies. By default,
1338
- * this plugin assumes that all external dependencies are CommonJS. This
1339
- * means they are rendered as default imports to be compatible with e.g.
1340
- * NodeJS where ES modules can only import a default export from a CommonJS
1341
- * dependency.
1342
- *
1343
- * If you set `esmExternals` to `true`, this plugin assumes that all
1344
- * external dependencies are ES modules and respect the
1345
- * `requireReturnsDefault` option. If that option is not set, they will be
1346
- * rendered as namespace imports.
1347
- *
1348
- * You can also supply an array of ids to be treated as ES modules, or a
1349
- * function that will be passed each external id to determine whether it is
1350
- * an ES module.
1351
- * @default false
1352
- */
1353
- esmExternals?: boolean | ReadonlyArray<string> | ((id: string) => boolean)
1354
- /**
1355
- * Controls what is returned when requiring an ES module from a CommonJS file.
1356
- * When using the `esmExternals` option, this will also apply to external
1357
- * modules. By default, this plugin will render those imports as namespace
1358
- * imports i.e.
1359
- *
1360
- * ```js
1361
- * // input
1362
- * const foo = require('foo');
1363
- *
1364
- * // output
1365
- * import * as foo from 'foo';
1366
- * ```
1367
- *
1368
- * However, there are some situations where this may not be desired.
1369
- * For these situations, you can change Rollup's behaviour either globally or
1370
- * per module. To change it globally, set the `requireReturnsDefault` option
1371
- * to one of the following values:
1372
- *
1373
- * - `false`: This is the default, requiring an ES module returns its
1374
- * namespace. This is the only option that will also add a marker
1375
- * `__esModule: true` to the namespace to support interop patterns in
1376
- * CommonJS modules that are transpiled ES modules.
1377
- * - `"namespace"`: Like `false`, requiring an ES module returns its
1378
- * namespace, but the plugin does not add the `__esModule` marker and thus
1379
- * creates more efficient code. For external dependencies when using
1380
- * `esmExternals: true`, no additional interop code is generated.
1381
- * - `"auto"`: This is complementary to how `output.exports: "auto"` works in
1382
- * Rollup: If a module has a default export and no named exports, requiring
1383
- * that module returns the default export. In all other cases, the namespace
1384
- * is returned. For external dependencies when using `esmExternals: true`, a
1385
- * corresponding interop helper is added.
1386
- * - `"preferred"`: If a module has a default export, requiring that module
1387
- * always returns the default export, no matter whether additional named
1388
- * exports exist. This is similar to how previous versions of this plugin
1389
- * worked. Again for external dependencies when using `esmExternals: true`,
1390
- * an interop helper is added.
1391
- * - `true`: This will always try to return the default export on require
1392
- * without checking if it actually exists. This can throw at build time if
1393
- * there is no default export. This is how external dependencies are handled
1394
- * when `esmExternals` is not used. The advantage over the other options is
1395
- * that, like `false`, this does not add an interop helper for external
1396
- * dependencies, keeping the code lean.
1397
- *
1398
- * To change this for individual modules, you can supply a function for
1399
- * `requireReturnsDefault` instead. This function will then be called once for
1400
- * each required ES module or external dependency with the corresponding id
1401
- * and allows you to return different values for different modules.
1402
- * @default false
1403
- */
1404
- requireReturnsDefault?:
1405
- | boolean
1406
- | 'auto'
1407
- | 'preferred'
1408
- | 'namespace'
1409
- | ((id: string) => boolean | 'auto' | 'preferred' | 'namespace')
1410
-
1411
- /**
1412
- * @default "auto"
1413
- */
1414
- defaultIsModuleExports?: boolean | 'auto' | ((id: string) => boolean | 'auto')
1415
- /**
1416
- * Some modules contain dynamic `require` calls, or require modules that
1417
- * contain circular dependencies, which are not handled well by static
1418
- * imports. Including those modules as `dynamicRequireTargets` will simulate a
1419
- * CommonJS (NodeJS-like) environment for them with support for dynamic
1420
- * dependencies. It also enables `strictRequires` for those modules.
1421
- *
1422
- * Note: In extreme cases, this feature may result in some paths being
1423
- * rendered as absolute in the final bundle. The plugin tries to avoid
1424
- * exposing paths from the local machine, but if you are `dynamicRequirePaths`
1425
- * with paths that are far away from your project's folder, that may require
1426
- * replacing strings like `"/Users/John/Desktop/foo-project/"` -\> `"/"`.
1427
- */
1428
- dynamicRequireTargets?: string | ReadonlyArray<string>
1429
- /**
1430
- * To avoid long paths when using the `dynamicRequireTargets` option, you can use this option to specify a directory
1431
- * that is a common parent for all files that use dynamic require statements. Using a directory higher up such as `/`
1432
- * may lead to unnecessarily long paths in the generated code and may expose directory names on your machine like your
1433
- * home directory name. By default, it uses the current working directory.
1434
- */
1435
- dynamicRequireRoot?: string
1436
- }
1583
+ type VerifyClientCallbackSync = (info: {
1584
+ origin: string
1585
+ secure: boolean
1586
+ req: IncomingMessage
1587
+ }) => boolean
1437
1588
 
1438
- interface RollupDynamicImportVarsOptions {
1439
- /**
1440
- * Files to include in this plugin (default all).
1441
- * @default []
1442
- */
1443
- include?: string | RegExp | (string | RegExp)[]
1444
1589
  /**
1445
- * Files to exclude in this plugin (default none).
1446
- * @default []
1447
- */
1448
- exclude?: string | RegExp | (string | RegExp)[]
1449
- /**
1450
- * By default, the plugin quits the build process when it encounters an error. If you set this option to true, it will throw a warning instead and leave the code untouched.
1451
- * @default false
1590
+ * VerifyClientCallbackAsync is an asynchronous callback used to inspect the
1591
+ * incoming message. The return value (boolean) of the function determines
1592
+ * whether or not to accept the handshake.
1452
1593
  */
1453
- warnOnError?: boolean
1454
- }
1594
+ type VerifyClientCallbackAsync = (
1595
+ info: { origin: string; secure: boolean; req: IncomingMessage },
1596
+ callback: (
1597
+ res: boolean,
1598
+ code?: number,
1599
+ message?: string,
1600
+ headers?: OutgoingHttpHeaders,
1601
+ ) => void,
1602
+ ) => void
1455
1603
 
1456
- // Modified and inlined to avoid extra dependency
1457
- // Source: https://github.com/terser/terser/blob/master/tools/terser.d.ts
1458
- // BSD Licensed https://github.com/terser/terser/blob/master/LICENSE
1604
+ interface ClientOptions extends SecureContextOptions {
1605
+ protocol?: string | undefined
1606
+ followRedirects?: boolean | undefined
1607
+ generateMask?(mask: Buffer): void
1608
+ handshakeTimeout?: number | undefined
1609
+ maxRedirects?: number | undefined
1610
+ perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined
1611
+ localAddress?: string | undefined
1612
+ protocolVersion?: number | undefined
1613
+ headers?: { [key: string]: string } | undefined
1614
+ origin?: string | undefined
1615
+ agent?: Agent | undefined
1616
+ host?: string | undefined
1617
+ family?: number | undefined
1618
+ checkServerIdentity?(servername: string, cert: CertMeta): boolean
1619
+ rejectUnauthorized?: boolean | undefined
1620
+ maxPayload?: number | undefined
1621
+ skipUTF8Validation?: boolean | undefined
1622
+ }
1459
1623
 
1460
- declare namespace Terser {
1461
- export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020
1624
+ interface PerMessageDeflateOptions {
1625
+ serverNoContextTakeover?: boolean | undefined
1626
+ clientNoContextTakeover?: boolean | undefined
1627
+ serverMaxWindowBits?: number | undefined
1628
+ clientMaxWindowBits?: number | undefined
1629
+ zlibDeflateOptions?:
1630
+ | {
1631
+ flush?: number | undefined
1632
+ finishFlush?: number | undefined
1633
+ chunkSize?: number | undefined
1634
+ windowBits?: number | undefined
1635
+ level?: number | undefined
1636
+ memLevel?: number | undefined
1637
+ strategy?: number | undefined
1638
+ dictionary?: Buffer | Buffer[] | DataView | undefined
1639
+ info?: boolean | undefined
1640
+ }
1641
+ | undefined
1642
+ zlibInflateOptions?: ZlibOptions | undefined
1643
+ threshold?: number | undefined
1644
+ concurrencyLimit?: number | undefined
1645
+ }
1462
1646
 
1463
- export type ConsoleProperty = keyof typeof console
1464
- type DropConsoleOption = boolean | ConsoleProperty[]
1647
+ interface Event {
1648
+ type: string
1649
+ target: WebSocket
1650
+ }
1465
1651
 
1466
- export interface ParseOptions {
1467
- bare_returns?: boolean
1468
- /** @deprecated legacy option. Currently, all supported EcmaScript is valid to parse. */
1469
- ecma?: ECMA
1470
- html5_comments?: boolean
1471
- shebang?: boolean
1652
+ interface ErrorEvent {
1653
+ error: any
1654
+ message: string
1655
+ type: string
1656
+ target: WebSocket
1472
1657
  }
1473
1658
 
1474
- export interface CompressOptions {
1475
- arguments?: boolean
1476
- arrows?: boolean
1477
- booleans_as_integers?: boolean
1478
- booleans?: boolean
1479
- collapse_vars?: boolean
1480
- comparisons?: boolean
1481
- computed_props?: boolean
1482
- conditionals?: boolean
1483
- dead_code?: boolean
1484
- defaults?: boolean
1485
- directives?: boolean
1486
- drop_console?: DropConsoleOption
1487
- drop_debugger?: boolean
1488
- ecma?: ECMA
1489
- evaluate?: boolean
1490
- expression?: boolean
1491
- global_defs?: object
1492
- hoist_funs?: boolean
1493
- hoist_props?: boolean
1494
- hoist_vars?: boolean
1495
- ie8?: boolean
1496
- if_return?: boolean
1497
- inline?: boolean | InlineFunctions
1498
- join_vars?: boolean
1499
- keep_classnames?: boolean | RegExp
1500
- keep_fargs?: boolean
1501
- keep_fnames?: boolean | RegExp
1502
- keep_infinity?: boolean
1503
- loops?: boolean
1504
- module?: boolean
1505
- negate_iife?: boolean
1506
- passes?: number
1507
- properties?: boolean
1508
- pure_funcs?: string[]
1509
- pure_new?: boolean
1510
- pure_getters?: boolean | 'strict'
1511
- reduce_funcs?: boolean
1512
- reduce_vars?: boolean
1513
- sequences?: boolean | number
1514
- side_effects?: boolean
1515
- switches?: boolean
1516
- toplevel?: boolean
1517
- top_retain?: null | string | string[] | RegExp
1518
- typeofs?: boolean
1519
- unsafe_arrows?: boolean
1520
- unsafe?: boolean
1521
- unsafe_comps?: boolean
1522
- unsafe_Function?: boolean
1523
- unsafe_math?: boolean
1524
- unsafe_symbols?: boolean
1525
- unsafe_methods?: boolean
1526
- unsafe_proto?: boolean
1527
- unsafe_regexp?: boolean
1528
- unsafe_undefined?: boolean
1529
- unused?: boolean
1530
- }
1531
-
1532
- export enum InlineFunctions {
1533
- Disabled = 0,
1534
- SimpleFunctions = 1,
1535
- WithArguments = 2,
1536
- WithArgumentsAndVariables = 3,
1659
+ interface CloseEvent {
1660
+ wasClean: boolean
1661
+ code: number
1662
+ reason: string
1663
+ type: string
1664
+ target: WebSocket
1537
1665
  }
1538
1666
 
1539
- export interface MangleOptions {
1540
- eval?: boolean
1541
- keep_classnames?: boolean | RegExp
1542
- keep_fnames?: boolean | RegExp
1543
- module?: boolean
1544
- nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
1545
- properties?: boolean | ManglePropertiesOptions
1546
- reserved?: string[]
1547
- safari10?: boolean
1548
- toplevel?: boolean
1667
+ interface MessageEvent {
1668
+ data: Data
1669
+ type: string
1670
+ target: WebSocket
1549
1671
  }
1550
1672
 
1551
- /**
1552
- * An identifier mangler for which the output is invariant with respect to the source code.
1553
- */
1554
- export interface SimpleIdentifierMangler {
1555
- /**
1556
- * Obtains the nth most favored (usually shortest) identifier to rename a variable to.
1557
- * The mangler will increment n and retry until the return value is not in use in scope, and is not a reserved word.
1558
- * This function is expected to be stable; Evaluating get(n) === get(n) should always return true.
1559
- * @param n The ordinal of the identifier.
1560
- */
1561
- get(n: number): string
1673
+ interface EventListenerOptions {
1674
+ once?: boolean | undefined
1562
1675
  }
1563
1676
 
1564
- /**
1565
- * An identifier mangler that leverages character frequency analysis to determine identifier precedence.
1566
- */
1567
- export interface WeightedIdentifierMangler extends SimpleIdentifierMangler {
1568
- /**
1569
- * Modifies the internal weighting of the input characters by the specified delta.
1570
- * Will be invoked on the entire printed AST, and then deduct mangleable identifiers.
1571
- * @param chars The characters to modify the weighting of.
1572
- * @param delta The numeric weight to add to the characters.
1573
- */
1574
- consider(chars: string, delta: number): number
1575
- /**
1576
- * Resets character weights.
1577
- */
1578
- reset(): void
1579
- /**
1580
- * Sorts identifiers by character frequency, in preparation for calls to get(n).
1581
- */
1582
- sort(): void
1677
+ interface ServerOptions {
1678
+ host?: string | undefined
1679
+ port?: number | undefined
1680
+ backlog?: number | undefined
1681
+ server?: Server | HttpsServer | undefined
1682
+ verifyClient?:
1683
+ | VerifyClientCallbackAsync
1684
+ | VerifyClientCallbackSync
1685
+ | undefined
1686
+ handleProtocols?: (
1687
+ protocols: Set<string>,
1688
+ request: IncomingMessage,
1689
+ ) => string | false
1690
+ path?: string | undefined
1691
+ noServer?: boolean | undefined
1692
+ clientTracking?: boolean | undefined
1693
+ perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined
1694
+ maxPayload?: number | undefined
1695
+ skipUTF8Validation?: boolean | undefined
1696
+ WebSocket?: typeof WebSocket.WebSocket | undefined
1583
1697
  }
1584
1698
 
1585
- export interface ManglePropertiesOptions {
1586
- builtins?: boolean
1587
- debug?: boolean
1588
- keep_quoted?: boolean | 'strict'
1589
- nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
1590
- regex?: RegExp | string
1591
- reserved?: string[]
1699
+ interface AddressInfo {
1700
+ address: string
1701
+ family: string
1702
+ port: number
1592
1703
  }
1593
1704
 
1594
- export interface FormatOptions {
1595
- ascii_only?: boolean
1596
- /** @deprecated Not implemented anymore */
1597
- beautify?: boolean
1598
- braces?: boolean
1599
- comments?:
1600
- | boolean
1601
- | 'all'
1602
- | 'some'
1603
- | RegExp
1604
- | ((
1605
- node: any,
1606
- comment: {
1607
- value: string
1608
- type: 'comment1' | 'comment2' | 'comment3' | 'comment4'
1609
- pos: number
1610
- line: number
1611
- col: number
1612
- },
1613
- ) => boolean)
1614
- ecma?: ECMA
1615
- ie8?: boolean
1616
- keep_numbers?: boolean
1617
- indent_level?: number
1618
- indent_start?: number
1619
- inline_script?: boolean
1620
- keep_quoted_props?: boolean
1621
- max_line_len?: number | false
1622
- preamble?: string
1623
- preserve_annotations?: boolean
1624
- quote_keys?: boolean
1625
- quote_style?: OutputQuoteStyle
1626
- safari10?: boolean
1627
- semicolons?: boolean
1628
- shebang?: boolean
1629
- shorthand?: boolean
1630
- source_map?: SourceMapOptions
1631
- webkit?: boolean
1632
- width?: number
1633
- wrap_iife?: boolean
1634
- wrap_func_args?: boolean
1635
- }
1705
+ // WebSocket Server
1706
+ class Server<T extends WebSocket = WebSocket> extends EventEmitter {
1707
+ options: ServerOptions
1708
+ path: string
1709
+ clients: Set<T>
1636
1710
 
1637
- export enum OutputQuoteStyle {
1638
- PreferDouble = 0,
1639
- AlwaysSingle = 1,
1640
- AlwaysDouble = 2,
1641
- AlwaysOriginal = 3,
1642
- }
1711
+ constructor(options?: ServerOptions, callback?: () => void)
1643
1712
 
1644
- export interface MinifyOptions {
1645
- compress?: boolean | CompressOptions
1646
- ecma?: ECMA
1647
- enclose?: boolean | string
1648
- ie8?: boolean
1649
- keep_classnames?: boolean | RegExp
1650
- keep_fnames?: boolean | RegExp
1651
- mangle?: boolean | MangleOptions
1652
- module?: boolean
1653
- nameCache?: object
1654
- format?: FormatOptions
1655
- /** @deprecated */
1656
- output?: FormatOptions
1657
- parse?: ParseOptions
1658
- safari10?: boolean
1659
- sourceMap?: boolean | SourceMapOptions
1660
- toplevel?: boolean
1661
- }
1713
+ address(): AddressInfo | string
1714
+ close(cb?: (err?: Error) => void): void
1715
+ handleUpgrade(
1716
+ request: IncomingMessage,
1717
+ socket: Duplex,
1718
+ upgradeHead: Buffer,
1719
+ callback: (client: T, request: IncomingMessage) => void,
1720
+ ): void
1721
+ shouldHandle(request: IncomingMessage): boolean | Promise<boolean>
1662
1722
 
1663
- export interface MinifyOutput {
1664
- code?: string
1665
- map?: object | string
1666
- decoded_map?: object | null
1667
- }
1723
+ // Events
1724
+ on(
1725
+ event: 'connection',
1726
+ cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
1727
+ ): this
1728
+ on(event: 'error', cb: (this: Server<T>, error: Error) => void): this
1729
+ on(
1730
+ event: 'headers',
1731
+ cb: (
1732
+ this: Server<T>,
1733
+ headers: string[],
1734
+ request: IncomingMessage,
1735
+ ) => void,
1736
+ ): this
1737
+ on(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
1738
+ on(
1739
+ event: string | symbol,
1740
+ listener: (this: Server<T>, ...args: any[]) => void,
1741
+ ): this
1668
1742
 
1669
- export interface SourceMapOptions {
1670
- /** Source map object, 'inline' or source map file content */
1671
- content?: object | string
1672
- includeSources?: boolean
1673
- filename?: string
1674
- root?: string
1675
- asObject?: boolean
1676
- url?: string | 'inline'
1677
- }
1678
- }
1743
+ once(
1744
+ event: 'connection',
1745
+ cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
1746
+ ): this
1747
+ once(event: 'error', cb: (this: Server<T>, error: Error) => void): this
1748
+ once(
1749
+ event: 'headers',
1750
+ cb: (
1751
+ this: Server<T>,
1752
+ headers: string[],
1753
+ request: IncomingMessage,
1754
+ ) => void,
1755
+ ): this
1756
+ once(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
1757
+ once(
1758
+ event: string | symbol,
1759
+ listener: (this: Server<T>, ...args: any[]) => void,
1760
+ ): this
1679
1761
 
1680
- interface TerserOptions extends Terser.MinifyOptions {
1681
- /**
1682
- * Vite-specific option to specify the max number of workers to spawn
1683
- * when minifying files with terser.
1684
- *
1685
- * @default number of CPUs minus 1
1686
- */
1687
- maxWorkers?: number;
1762
+ off(
1763
+ event: 'connection',
1764
+ cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
1765
+ ): this
1766
+ off(event: 'error', cb: (this: Server<T>, error: Error) => void): this
1767
+ off(
1768
+ event: 'headers',
1769
+ cb: (
1770
+ this: Server<T>,
1771
+ headers: string[],
1772
+ request: IncomingMessage,
1773
+ ) => void,
1774
+ ): this
1775
+ off(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
1776
+ off(
1777
+ event: string | symbol,
1778
+ listener: (this: Server<T>, ...args: any[]) => void,
1779
+ ): this
1780
+
1781
+ addListener(
1782
+ event: 'connection',
1783
+ cb: (client: T, request: IncomingMessage) => void,
1784
+ ): this
1785
+ addListener(event: 'error', cb: (err: Error) => void): this
1786
+ addListener(
1787
+ event: 'headers',
1788
+ cb: (headers: string[], request: IncomingMessage) => void,
1789
+ ): this
1790
+ addListener(event: 'close' | 'listening', cb: () => void): this
1791
+ addListener(
1792
+ event: string | symbol,
1793
+ listener: (...args: any[]) => void,
1794
+ ): this
1795
+
1796
+ removeListener(event: 'connection', cb: (client: T) => void): this
1797
+ removeListener(event: 'error', cb: (err: Error) => void): this
1798
+ removeListener(
1799
+ event: 'headers',
1800
+ cb: (headers: string[], request: IncomingMessage) => void,
1801
+ ): this
1802
+ removeListener(event: 'close' | 'listening', cb: () => void): this
1803
+ removeListener(
1804
+ event: string | symbol,
1805
+ listener: (...args: any[]) => void,
1806
+ ): this
1807
+ }
1808
+
1809
+ const WebSocketServer: typeof Server
1810
+ interface WebSocketServer extends Server {}
1811
+ const WebSocket: typeof WebSocketAlias
1812
+ interface WebSocket extends WebSocketAlias {}
1813
+
1814
+ // WebSocket stream
1815
+ function createWebSocketStream(
1816
+ websocket: WebSocket,
1817
+ options?: DuplexOptions,
1818
+ ): Duplex
1688
1819
  }
1689
1820
 
1690
- interface EnvironmentResolveOptions {
1821
+ type WebSocketCustomListener<T> = (data: T, client: WebSocketClient, invoke?: 'send' | `send:${string}`) => void;
1822
+ declare const isWebSocketServer: unique symbol;
1823
+ interface WebSocketServer extends NormalizedHotChannel {
1691
1824
  /**
1692
- * @default ['browser', 'module', 'jsnext:main', 'jsnext']
1825
+ * Handle custom event emitted by `import.meta.hot.send`
1693
1826
  */
1694
- mainFields?: string[];
1695
- conditions?: string[];
1696
- externalConditions?: string[];
1827
+ on: WebSocket.Server['on'] & {
1828
+ <T extends string>(event: T, listener: WebSocketCustomListener<InferCustomEventPayload<T>>): void;
1829
+ };
1697
1830
  /**
1698
- * @default ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']
1831
+ * Unregister event listener.
1699
1832
  */
1700
- extensions?: string[];
1701
- dedupe?: string[];
1833
+ off: WebSocket.Server['off'] & {
1834
+ (event: string, listener: Function): void;
1835
+ };
1702
1836
  /**
1703
- * Prevent listed dependencies from being externalized and will get bundled in build.
1704
- * Only works in server environments for now. Previously this was `ssr.noExternal`.
1705
- * @experimental
1837
+ * Listen on port and host
1706
1838
  */
1707
- noExternal?: string | RegExp | (string | RegExp)[] | true;
1839
+ listen(): void;
1708
1840
  /**
1709
- * Externalize the given dependencies and their transitive dependencies.
1710
- * Only works in server environments for now. Previously this was `ssr.external`.
1711
- * @experimental
1841
+ * Disconnect all clients and terminate the server.
1712
1842
  */
1713
- external?: string[] | true;
1714
- }
1715
- interface ResolveOptions extends EnvironmentResolveOptions {
1843
+ close(): Promise<void>;
1844
+ [isWebSocketServer]: true;
1716
1845
  /**
1717
- * @default false
1846
+ * Get all connected clients.
1718
1847
  */
1719
- preserveSymlinks?: boolean;
1848
+ clients: Set<WebSocketClient>;
1720
1849
  }
1721
- interface ResolvePluginOptions {
1722
- root: string;
1723
- isBuild: boolean;
1724
- isProduction: boolean;
1725
- packageCache?: PackageCache;
1726
- /**
1727
- * src code mode also attempts the following:
1728
- * - resolving /xxx as URLs
1729
- * - resolving bare imports from optimized deps
1730
- */
1731
- asSrc?: boolean;
1732
- tryIndex?: boolean;
1733
- tryPrefix?: string;
1734
- preferRelative?: boolean;
1735
- isRequire?: boolean;
1736
- isFromTsImporter?: boolean;
1737
- scan?: boolean;
1850
+ interface WebSocketClient extends HotChannelClient {
1738
1851
  /**
1739
- * @deprecated environment.config are used instead
1852
+ * The raw WebSocket instance
1853
+ * @advanced
1740
1854
  */
1741
- ssrConfig?: SSROptions;
1742
- }
1743
- interface InternalResolveOptions extends Required<ResolveOptions>, ResolvePluginOptions {
1855
+ socket: WebSocket;
1744
1856
  }
1745
1857
 
1746
- /** Cache for package.json resolution and package.json contents */
1747
- type PackageCache = Map<string, PackageData>;
1748
- interface PackageData {
1749
- dir: string;
1750
- hasSideEffects: (id: string) => boolean | 'no-treeshake' | null;
1751
- setResolvedCache: (key: string, entry: string, options: InternalResolveOptions) => void;
1752
- getResolvedCache: (key: string, options: InternalResolveOptions) => string | undefined;
1753
- data: {
1754
- [field: string]: any;
1755
- name: string;
1756
- type: string;
1757
- version: string;
1758
- main: string;
1759
- module: string;
1760
- browser: string | Record<string, string | false>;
1761
- exports: string | Record<string, any> | string[];
1762
- imports: Record<string, any>;
1763
- dependencies: Record<string, string>;
1858
+ interface DevEnvironmentContext {
1859
+ hot: boolean;
1860
+ transport?: HotChannel | WebSocketServer;
1861
+ options?: EnvironmentOptions;
1862
+ remoteRunner?: {
1863
+ inlineSourceMap?: boolean;
1764
1864
  };
1865
+ depsOptimizer?: DepsOptimizer;
1765
1866
  }
1766
-
1767
- interface BuildEnvironmentOptions {
1867
+ declare class DevEnvironment extends BaseEnvironment {
1868
+ mode: "dev";
1869
+ moduleGraph: EnvironmentModuleGraph;
1870
+ depsOptimizer?: DepsOptimizer;
1871
+ get pluginContainer(): EnvironmentPluginContainer;
1768
1872
  /**
1769
- * Compatibility transform target. The transform is performed with esbuild
1770
- * and the lowest supported target is es2015/es6. Note this only handles
1771
- * syntax transformation and does not cover polyfills (except for dynamic
1772
- * import)
1773
- *
1774
- * Default: 'modules' - Similar to `@babel/preset-env`'s targets.esmodules,
1775
- * transpile targeting browsers that natively support dynamic es module imports.
1776
- * https://caniuse.com/es6-module-dynamic-import
1777
- *
1778
- * Another special value is 'esnext' - which only performs minimal transpiling
1779
- * (for minification compat) and assumes native dynamic imports support.
1873
+ * Hot channel for this environment. If not provided or disabled,
1874
+ * it will be a noop channel that does nothing.
1780
1875
  *
1781
- * For custom targets, see https://esbuild.github.io/api/#target and
1782
- * https://esbuild.github.io/content-types/#javascript for more details.
1783
- * @default 'modules'
1784
- */
1785
- target?: 'modules' | esbuild_TransformOptions['target'] | false;
1786
- /**
1787
- * whether to inject module preload polyfill.
1788
- * Note: does not apply to library mode.
1789
- * @default true
1790
- * @deprecated use `modulePreload.polyfill` instead
1791
- */
1792
- polyfillModulePreload?: boolean;
1793
- /**
1794
- * Configure module preload
1795
- * Note: does not apply to library mode.
1796
- * @default true
1797
- */
1798
- modulePreload?: boolean | ModulePreloadOptions;
1799
- /**
1800
- * Directory relative from `root` where build output will be placed. If the
1801
- * directory exists, it will be removed before the build.
1802
- * @default 'dist'
1803
- */
1804
- outDir?: string;
1805
- /**
1806
- * Directory relative from `outDir` where the built js/css/image assets will
1807
- * be placed.
1808
- * @default 'assets'
1876
+ * @example
1877
+ * environment.hot.send({ type: 'full-reload' })
1809
1878
  */
1810
- assetsDir?: string;
1879
+ hot: NormalizedHotChannel;
1880
+ constructor(name: string, config: ResolvedConfig, context: DevEnvironmentContext);
1881
+ init(options?: {
1882
+ watcher?: FSWatcher;
1883
+ /**
1884
+ * the previous instance used for the environment with the same name
1885
+ *
1886
+ * when using, the consumer should check if it's an instance generated from the same class or factory function
1887
+ */
1888
+ previousInstance?: DevEnvironment;
1889
+ }): Promise<void>;
1811
1890
  /**
1812
- * Static asset files smaller than this number (in bytes) will be inlined as
1813
- * base64 strings. Default limit is `4096` (4 KiB). Set to `0` to disable.
1814
- * @default 4096
1891
+ * When the dev server is restarted, the methods are called in the following order:
1892
+ * - new instance `init`
1893
+ * - previous instance `close`
1894
+ * - new instance `listen`
1815
1895
  */
1816
- assetsInlineLimit?: number | ((filePath: string, content: Buffer) => boolean | undefined);
1896
+ listen(server: ViteDevServer): Promise<void>;
1897
+ fetchModule(id: string, importer?: string, options?: FetchFunctionOptions): Promise<FetchResult>;
1898
+ reloadModule(module: EnvironmentModuleNode): Promise<void>;
1899
+ transformRequest(url: string): Promise<TransformResult | null>;
1900
+ warmupRequest(url: string): Promise<void>;
1901
+ close(): Promise<void>;
1817
1902
  /**
1818
- * Whether to code-split CSS. When enabled, CSS in async chunks will be
1819
- * inlined as strings in the chunk and inserted via dynamically created
1820
- * style tags when the chunk is loaded.
1821
- * @default true
1903
+ * Calling `await environment.waitForRequestsIdle(id)` will wait until all static imports
1904
+ * are processed after the first transformRequest call. If called from a load or transform
1905
+ * plugin hook, the id needs to be passed as a parameter to avoid deadlocks.
1906
+ * Calling this function after the first static imports section of the module graph has been
1907
+ * processed will resolve immediately.
1908
+ * @experimental
1822
1909
  */
1823
- cssCodeSplit?: boolean;
1824
- /**
1825
- * An optional separate target for CSS minification.
1826
- * As esbuild only supports configuring targets to mainstream
1827
- * browsers, users may need this option when they are targeting
1828
- * a niche browser that comes with most modern JavaScript features
1829
- * but has poor CSS support, e.g. Android WeChat WebView, which
1830
- * doesn't support the #RGBA syntax.
1831
- * @default target
1832
- */
1833
- cssTarget?: esbuild_TransformOptions['target'] | false;
1834
- /**
1835
- * Override CSS minification specifically instead of defaulting to `build.minify`,
1836
- * so you can configure minification for JS and CSS separately.
1837
- * @default 'esbuild'
1838
- */
1839
- cssMinify?: boolean | 'esbuild' | 'lightningcss';
1840
- /**
1841
- * If `true`, a separate sourcemap file will be created. If 'inline', the
1842
- * sourcemap will be appended to the resulting output file as data URI.
1843
- * 'hidden' works like `true` except that the corresponding sourcemap
1844
- * comments in the bundled files are suppressed.
1845
- * @default false
1846
- */
1847
- sourcemap?: boolean | 'inline' | 'hidden';
1848
- /**
1849
- * Set to `false` to disable minification, or specify the minifier to use.
1850
- * Available options are 'terser' or 'esbuild'.
1851
- * @default 'esbuild'
1852
- */
1853
- minify?: boolean | 'terser' | 'esbuild';
1854
- /**
1855
- * Options for terser
1856
- * https://terser.org/docs/api-reference#minify-options
1857
- *
1858
- * In addition, you can also pass a `maxWorkers: number` option to specify the
1859
- * max number of workers to spawn. Defaults to the number of CPUs minus 1.
1860
- */
1861
- terserOptions?: TerserOptions;
1862
- /**
1863
- * Will be merged with internal rollup options.
1864
- * https://rollupjs.org/configuration-options/
1865
- */
1866
- rollupOptions?: RollupOptions;
1867
- /**
1868
- * Options to pass on to `@rollup/plugin-commonjs`
1869
- */
1870
- commonjsOptions?: RollupCommonJSOptions;
1871
- /**
1872
- * Options to pass on to `@rollup/plugin-dynamic-import-vars`
1873
- */
1874
- dynamicImportVarsOptions?: RollupDynamicImportVarsOptions;
1875
- /**
1876
- * Whether to write bundle to disk
1877
- * @default true
1878
- */
1879
- write?: boolean;
1880
- /**
1881
- * Empty outDir on write.
1882
- * @default true when outDir is a sub directory of project root
1883
- */
1884
- emptyOutDir?: boolean | null;
1885
- /**
1886
- * Copy the public directory to outDir on write.
1887
- * @default true
1888
- */
1889
- copyPublicDir?: boolean;
1890
- /**
1891
- * Whether to emit a .vite/manifest.json under assets dir to map hash-less filenames
1892
- * to their hashed versions. Useful when you want to generate your own HTML
1893
- * instead of using the one generated by Vite.
1894
- *
1895
- * Example:
1896
- *
1897
- * ```json
1898
- * {
1899
- * "main.js": {
1900
- * "file": "main.68fe3fad.js",
1901
- * "css": "main.e6b63442.css",
1902
- * "imports": [...],
1903
- * "dynamicImports": [...]
1904
- * }
1905
- * }
1906
- * ```
1907
- * @default false
1908
- */
1909
- manifest?: boolean | string;
1910
- /**
1911
- * Build in library mode. The value should be the global name of the lib in
1912
- * UMD mode. This will produce esm + cjs + umd bundle formats with default
1913
- * configurations that are suitable for distributing libraries.
1914
- * @default false
1915
- */
1916
- lib?: LibraryOptions | false;
1917
- /**
1918
- * Produce SSR oriented build. Note this requires specifying SSR entry via
1919
- * `rollupOptions.input`.
1920
- * @default false
1921
- */
1922
- ssr?: boolean | string;
1923
- /**
1924
- * Generate SSR manifest for determining style links and asset preload
1925
- * directives in production.
1926
- * @default false
1927
- */
1928
- ssrManifest?: boolean | string;
1929
- /**
1930
- * Emit assets during SSR.
1931
- * @default false
1932
- */
1933
- ssrEmitAssets?: boolean;
1934
- /**
1935
- * Emit assets during build. Frameworks can set environments.ssr.build.emitAssets
1936
- * By default, it is true for the client and false for other environments.
1937
- */
1938
- emitAssets?: boolean;
1939
- /**
1940
- * Set to false to disable reporting compressed chunk sizes.
1941
- * Can slightly improve build speed.
1942
- * @default true
1943
- */
1944
- reportCompressedSize?: boolean;
1945
- /**
1946
- * Adjust chunk size warning limit (in kB).
1947
- * @default 500
1948
- */
1949
- chunkSizeWarningLimit?: number;
1950
- /**
1951
- * Rollup watch options
1952
- * https://rollupjs.org/configuration-options/#watch
1953
- * @default null
1954
- */
1955
- watch?: WatcherOptions | null;
1956
- /**
1957
- * create the Build Environment instance
1958
- */
1959
- createEnvironment?: (name: string, config: ResolvedConfig) => Promise<BuildEnvironment> | BuildEnvironment;
1960
- }
1961
- type BuildOptions = BuildEnvironmentOptions;
1962
- interface LibraryOptions {
1963
- /**
1964
- * Path of library entry
1965
- */
1966
- entry: InputOption;
1967
- /**
1968
- * The name of the exposed global variable. Required when the `formats` option includes
1969
- * `umd` or `iife`
1970
- */
1971
- name?: string;
1972
- /**
1973
- * Output bundle formats
1974
- * @default ['es', 'umd']
1975
- */
1976
- formats?: LibraryFormats[];
1977
- /**
1978
- * The name of the package file output. The default file name is the name option
1979
- * of the project package.json. It can also be defined as a function taking the
1980
- * format as an argument.
1981
- */
1982
- fileName?: string | ((format: ModuleFormat, entryName: string) => string);
1983
- /**
1984
- * The name of the CSS file output if the library imports CSS. Defaults to the
1985
- * same value as `build.lib.fileName` if it's set a string, otherwise it falls
1986
- * back to the name option of the project package.json.
1987
- */
1988
- cssFileName?: string;
1989
- }
1990
- type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife' | 'system';
1991
- interface ModulePreloadOptions {
1992
- /**
1993
- * Whether to inject a module preload polyfill.
1994
- * Note: does not apply to library mode.
1995
- * @default true
1996
- */
1997
- polyfill?: boolean;
1998
- /**
1999
- * Resolve the list of dependencies to preload for a given dynamic import
2000
- * @experimental
2001
- */
2002
- resolveDependencies?: ResolveModulePreloadDependenciesFn;
2003
- }
2004
- interface ResolvedModulePreloadOptions {
2005
- polyfill: boolean;
2006
- resolveDependencies?: ResolveModulePreloadDependenciesFn;
2007
- }
2008
- type ResolveModulePreloadDependenciesFn = (filename: string, deps: string[], context: {
2009
- hostId: string;
2010
- hostType: 'html' | 'js';
2011
- }) => string[];
2012
- interface ResolvedBuildEnvironmentOptions extends Required<Omit<BuildEnvironmentOptions, 'polyfillModulePreload'>> {
2013
- modulePreload: false | ResolvedModulePreloadOptions;
2014
- }
2015
- interface ResolvedBuildOptions extends Required<Omit<BuildOptions, 'polyfillModulePreload'>> {
2016
- modulePreload: false | ResolvedModulePreloadOptions;
2017
- }
2018
- /**
2019
- * Bundles a single environment for production.
2020
- * Returns a Promise containing the build result.
2021
- */
2022
- declare function build(inlineConfig?: InlineConfig): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;
2023
- type RenderBuiltAssetUrl = (filename: string, type: {
2024
- type: 'asset' | 'public';
2025
- hostId: string;
2026
- hostType: 'js' | 'css' | 'html';
2027
- ssr: boolean;
2028
- }) => string | {
2029
- relative?: boolean;
2030
- runtime?: string;
2031
- } | undefined;
2032
- declare class BuildEnvironment extends BaseEnvironment {
2033
- mode: "build";
2034
- constructor(name: string, config: ResolvedConfig, setup?: {
2035
- options?: EnvironmentOptions;
2036
- });
2037
- init(): Promise<void>;
2038
- }
2039
- interface ViteBuilder {
2040
- environments: Record<string, BuildEnvironment>;
2041
- config: ResolvedConfig;
2042
- buildApp(): Promise<void>;
2043
- build(environment: BuildEnvironment): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;
2044
- }
2045
- interface BuilderOptions {
2046
- /**
2047
- * Whether to share the config instance among environments to align with the behavior of dev server.
2048
- *
2049
- * @default false
2050
- * @experimental
2051
- */
2052
- sharedConfigBuild?: boolean;
2053
- /**
2054
- * Whether to share the plugin instances among environments to align with the behavior of dev server.
2055
- *
2056
- * @default false
2057
- * @experimental
2058
- */
2059
- sharedPlugins?: boolean;
2060
- buildApp?: (builder: ViteBuilder) => Promise<void>;
2061
- }
2062
- type ResolvedBuilderOptions = Required<BuilderOptions>;
2063
- /**
2064
- * Creates a ViteBuilder to orchestrate building multiple environments.
2065
- * @experimental
2066
- */
2067
- declare function createBuilder(inlineConfig?: InlineConfig, useLegacyBuilder?: null | boolean): Promise<ViteBuilder>;
2068
-
2069
- type Environment = DevEnvironment | BuildEnvironment | UnknownEnvironment;
2070
-
2071
- declare class EnvironmentPluginContainer {
2072
- environment: Environment;
2073
- plugins: Plugin[];
2074
- watcher?: FSWatcher | undefined;
2075
- private _pluginContextMap;
2076
- private _resolvedRollupOptions?;
2077
- private _processesing;
2078
- private _seenResolves;
2079
- private _moduleNodeToLoadAddedImports;
2080
- getSortedPluginHooks: PluginHookUtils['getSortedPluginHooks'];
2081
- getSortedPlugins: PluginHookUtils['getSortedPlugins'];
2082
- moduleGraph: EnvironmentModuleGraph | undefined;
2083
- watchFiles: Set<string>;
2084
- minimalContext: MinimalPluginContext;
2085
- private _started;
2086
- private _buildStartPromise;
2087
- private _closed;
2088
- private _updateModuleLoadAddedImports;
2089
- private _getAddedImports;
2090
- getModuleInfo(id: string): ModuleInfo | null;
2091
- private handleHookPromise;
2092
- get options(): InputOptions;
2093
- resolveRollupOptions(): Promise<InputOptions>;
2094
- private _getPluginContext;
2095
- private hookParallel;
2096
- buildStart(_options?: InputOptions): Promise<void>;
2097
- resolveId(rawId: string, importer?: string | undefined, options?: {
2098
- attributes?: Record<string, string>;
2099
- custom?: CustomPluginOptions;
2100
- skip?: Set<Plugin>;
2101
- isEntry?: boolean;
2102
- }): Promise<PartialResolvedId | null>;
2103
- load(id: string): Promise<LoadResult | null>;
2104
- transform(code: string, id: string, options?: {
2105
- inMap?: SourceDescription['map'];
2106
- }): Promise<{
2107
- code: string;
2108
- map: SourceMap | {
2109
- mappings: '';
2110
- } | null;
2111
- }>;
2112
- watchChange(id: string, change: {
2113
- event: 'create' | 'update' | 'delete';
2114
- }): Promise<void>;
2115
- close(): Promise<void>;
2116
- }
2117
- declare class PluginContainer {
2118
- private environments;
2119
- constructor(environments: Record<string, Environment>);
2120
- private _getEnvironment;
2121
- private _getPluginContainer;
2122
- getModuleInfo(id: string): ModuleInfo | null;
2123
- get options(): InputOptions;
2124
- buildStart(_options?: InputOptions): Promise<void>;
2125
- watchChange(id: string, change: {
2126
- event: 'create' | 'update' | 'delete';
2127
- }): Promise<void>;
2128
- resolveId(rawId: string, importer?: string, options?: {
2129
- attributes?: Record<string, string>;
2130
- custom?: CustomPluginOptions;
2131
- skip?: Set<Plugin>;
2132
- ssr?: boolean;
2133
- isEntry?: boolean;
2134
- }): Promise<PartialResolvedId | null>;
2135
- load(id: string, options?: {
2136
- ssr?: boolean;
2137
- }): Promise<LoadResult | null>;
2138
- transform(code: string, id: string, options?: {
2139
- ssr?: boolean;
2140
- environment?: Environment;
2141
- inMap?: SourceDescription['map'];
2142
- }): Promise<{
2143
- code: string;
2144
- map: SourceMap | {
2145
- mappings: '';
2146
- } | null;
2147
- }>;
2148
- close(): Promise<void>;
1910
+ waitForRequestsIdle(ignoredId?: string): Promise<void>;
2149
1911
  }
2150
1912
 
2151
- // Modified and inlined to avoid extra dependency
2152
- // Source: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/ws/index.d.ts
2153
-
2154
- declare const WebSocketAlias: typeof WebSocket
2155
- interface WebSocketAlias extends WebSocket {}
2156
-
2157
- // WebSocket socket.
2158
- declare class WebSocket extends EventEmitter {
2159
- /** The connection is not yet open. */
2160
- static readonly CONNECTING: 0
2161
- /** The connection is open and ready to communicate. */
2162
- static readonly OPEN: 1
2163
- /** The connection is in the process of closing. */
2164
- static readonly CLOSING: 2
2165
- /** The connection is closed. */
2166
- static readonly CLOSED: 3
2167
-
2168
- binaryType: 'nodebuffer' | 'arraybuffer' | 'fragments'
2169
- readonly bufferedAmount: number
2170
- readonly extensions: string
2171
- /** Indicates whether the websocket is paused */
2172
- readonly isPaused: boolean
2173
- readonly protocol: string
2174
- /** The current state of the connection */
2175
- readonly readyState:
2176
- | typeof WebSocket.CONNECTING
2177
- | typeof WebSocket.OPEN
2178
- | typeof WebSocket.CLOSING
2179
- | typeof WebSocket.CLOSED
2180
- readonly url: string
2181
-
2182
- /** The connection is not yet open. */
2183
- readonly CONNECTING: 0
2184
- /** The connection is open and ready to communicate. */
2185
- readonly OPEN: 1
2186
- /** The connection is in the process of closing. */
2187
- readonly CLOSING: 2
2188
- /** The connection is closed. */
2189
- readonly CLOSED: 3
2190
-
2191
- onopen: ((event: WebSocket.Event) => void) | null
2192
- onerror: ((event: WebSocket.ErrorEvent) => void) | null
2193
- onclose: ((event: WebSocket.CloseEvent) => void) | null
2194
- onmessage: ((event: WebSocket.MessageEvent) => void) | null
2195
-
2196
- constructor(address: null)
2197
- constructor(
2198
- address: string | URL,
2199
- options?: WebSocket.ClientOptions | ClientRequestArgs,
2200
- )
2201
- constructor(
2202
- address: string | URL,
2203
- protocols?: string | string[],
2204
- options?: WebSocket.ClientOptions | ClientRequestArgs,
2205
- )
2206
-
2207
- close(code?: number, data?: string | Buffer): void
2208
- ping(data?: any, mask?: boolean, cb?: (err: Error) => void): void
2209
- pong(data?: any, mask?: boolean, cb?: (err: Error) => void): void
2210
- send(data: any, cb?: (err?: Error) => void): void
2211
- send(
2212
- data: any,
2213
- options: {
2214
- mask?: boolean | undefined
2215
- binary?: boolean | undefined
2216
- compress?: boolean | undefined
2217
- fin?: boolean | undefined
2218
- },
2219
- cb?: (err?: Error) => void,
2220
- ): void
2221
- terminate(): void
2222
-
1913
+ interface RollupCommonJSOptions {
1914
+ /**
1915
+ * A minimatch pattern, or array of patterns, which specifies the files in
1916
+ * the build the plugin should operate on. By default, all files with
1917
+ * extension `".cjs"` or those in `extensions` are included, but you can
1918
+ * narrow this list by only including specific files. These files will be
1919
+ * analyzed and transpiled if either the analysis does not find ES module
1920
+ * specific statements or `transformMixedEsModules` is `true`.
1921
+ * @default undefined
1922
+ */
1923
+ include?: string | RegExp | readonly (string | RegExp)[]
1924
+ /**
1925
+ * A minimatch pattern, or array of patterns, which specifies the files in
1926
+ * the build the plugin should _ignore_. By default, all files with
1927
+ * extensions other than those in `extensions` or `".cjs"` are ignored, but you
1928
+ * can exclude additional files. See also the `include` option.
1929
+ * @default undefined
1930
+ */
1931
+ exclude?: string | RegExp | readonly (string | RegExp)[]
1932
+ /**
1933
+ * For extensionless imports, search for extensions other than .js in the
1934
+ * order specified. Note that you need to make sure that non-JavaScript files
1935
+ * are transpiled by another plugin first.
1936
+ * @default [ '.js' ]
1937
+ */
1938
+ extensions?: ReadonlyArray<string>
1939
+ /**
1940
+ * If true then uses of `global` won't be dealt with by this plugin
1941
+ * @default false
1942
+ */
1943
+ ignoreGlobal?: boolean
1944
+ /**
1945
+ * If false, skips source map generation for CommonJS modules. This will
1946
+ * improve performance.
1947
+ * @default true
1948
+ */
1949
+ sourceMap?: boolean
1950
+ /**
1951
+ * Some `require` calls cannot be resolved statically to be translated to
1952
+ * imports.
1953
+ * When this option is set to `false`, the generated code will either
1954
+ * directly throw an error when such a call is encountered or, when
1955
+ * `dynamicRequireTargets` is used, when such a call cannot be resolved with a
1956
+ * configured dynamic require target.
1957
+ * Setting this option to `true` will instead leave the `require` call in the
1958
+ * code or use it as a fallback for `dynamicRequireTargets`.
1959
+ * @default false
1960
+ */
1961
+ ignoreDynamicRequires?: boolean
1962
+ /**
1963
+ * Instructs the plugin whether to enable mixed module transformations. This
1964
+ * is useful in scenarios with modules that contain a mix of ES `import`
1965
+ * statements and CommonJS `require` expressions. Set to `true` if `require`
1966
+ * calls should be transformed to imports in mixed modules, or `false` if the
1967
+ * `require` expressions should survive the transformation. The latter can be
1968
+ * important if the code contains environment detection, or you are coding
1969
+ * for an environment with special treatment for `require` calls such as
1970
+ * ElectronJS. See also the `ignore` option.
1971
+ * @default false
1972
+ */
1973
+ transformMixedEsModules?: boolean
1974
+ /**
1975
+ * By default, this plugin will try to hoist `require` statements as imports
1976
+ * to the top of each file. While this works well for many code bases and
1977
+ * allows for very efficient ESM output, it does not perfectly capture
1978
+ * CommonJS semantics as the order of side effects like log statements may
1979
+ * change. But it is especially problematic when there are circular `require`
1980
+ * calls between CommonJS modules as those often rely on the lazy execution of
1981
+ * nested `require` calls.
1982
+ *
1983
+ * Setting this option to `true` will wrap all CommonJS files in functions
1984
+ * which are executed when they are required for the first time, preserving
1985
+ * NodeJS semantics. Note that this can have an impact on the size and
1986
+ * performance of the generated code.
1987
+ *
1988
+ * The default value of `"auto"` will only wrap CommonJS files when they are
1989
+ * part of a CommonJS dependency cycle, e.g. an index file that is required by
1990
+ * many of its dependencies. All other CommonJS files are hoisted. This is the
1991
+ * recommended setting for most code bases.
1992
+ *
1993
+ * `false` will entirely prevent wrapping and hoist all files. This may still
1994
+ * work depending on the nature of cyclic dependencies but will often cause
1995
+ * problems.
1996
+ *
1997
+ * You can also provide a minimatch pattern, or array of patterns, to only
1998
+ * specify a subset of files which should be wrapped in functions for proper
1999
+ * `require` semantics.
2000
+ *
2001
+ * `"debug"` works like `"auto"` but after bundling, it will display a warning
2002
+ * containing a list of ids that have been wrapped which can be used as
2003
+ * minimatch pattern for fine-tuning.
2004
+ * @default "auto"
2005
+ */
2006
+ strictRequires?: boolean | string | RegExp | readonly (string | RegExp)[]
2007
+ /**
2008
+ * Sometimes you have to leave require statements unconverted. Pass an array
2009
+ * containing the IDs or a `id => boolean` function.
2010
+ * @default []
2011
+ */
2012
+ ignore?: ReadonlyArray<string> | ((id: string) => boolean)
2223
2013
  /**
2224
- * Pause the websocket causing it to stop emitting events. Some events can still be
2225
- * emitted after this is called, until all buffered data is consumed. This method
2226
- * is a noop if the ready state is `CONNECTING` or `CLOSED`.
2014
+ * In most cases, where `require` calls are inside a `try-catch` clause,
2015
+ * they should be left unconverted as it requires an optional dependency
2016
+ * that may or may not be installed beside the rolled up package.
2017
+ * Due to the conversion of `require` to a static `import` - the call is
2018
+ * hoisted to the top of the file, outside the `try-catch` clause.
2019
+ *
2020
+ * - `true`: Default. All `require` calls inside a `try` will be left unconverted.
2021
+ * - `false`: All `require` calls inside a `try` will be converted as if the
2022
+ * `try-catch` clause is not there.
2023
+ * - `remove`: Remove all `require` calls from inside any `try` block.
2024
+ * - `string[]`: Pass an array containing the IDs to left unconverted.
2025
+ * - `((id: string) => boolean|'remove')`: Pass a function that controls
2026
+ * individual IDs.
2027
+ *
2028
+ * @default true
2227
2029
  */
2228
- pause(): void
2030
+ ignoreTryCatch?:
2031
+ | boolean
2032
+ | 'remove'
2033
+ | ReadonlyArray<string>
2034
+ | ((id: string) => boolean | 'remove')
2229
2035
  /**
2230
- * Make a paused socket resume emitting events. This method is a noop if the ready
2231
- * state is `CONNECTING` or `CLOSED`.
2036
+ * Controls how to render imports from external dependencies. By default,
2037
+ * this plugin assumes that all external dependencies are CommonJS. This
2038
+ * means they are rendered as default imports to be compatible with e.g.
2039
+ * NodeJS where ES modules can only import a default export from a CommonJS
2040
+ * dependency.
2041
+ *
2042
+ * If you set `esmExternals` to `true`, this plugin assumes that all
2043
+ * external dependencies are ES modules and respect the
2044
+ * `requireReturnsDefault` option. If that option is not set, they will be
2045
+ * rendered as namespace imports.
2046
+ *
2047
+ * You can also supply an array of ids to be treated as ES modules, or a
2048
+ * function that will be passed each external id to determine whether it is
2049
+ * an ES module.
2050
+ * @default false
2232
2051
  */
2233
- resume(): void
2234
-
2235
- // HTML5 WebSocket events
2236
- addEventListener(
2237
- method: 'message',
2238
- cb: (event: WebSocket.MessageEvent) => void,
2239
- options?: WebSocket.EventListenerOptions,
2240
- ): void
2241
- addEventListener(
2242
- method: 'close',
2243
- cb: (event: WebSocket.CloseEvent) => void,
2244
- options?: WebSocket.EventListenerOptions,
2245
- ): void
2246
- addEventListener(
2247
- method: 'error',
2248
- cb: (event: WebSocket.ErrorEvent) => void,
2249
- options?: WebSocket.EventListenerOptions,
2250
- ): void
2251
- addEventListener(
2252
- method: 'open',
2253
- cb: (event: WebSocket.Event) => void,
2254
- options?: WebSocket.EventListenerOptions,
2255
- ): void
2256
-
2257
- removeEventListener(
2258
- method: 'message',
2259
- cb: (event: WebSocket.MessageEvent) => void,
2260
- ): void
2261
- removeEventListener(
2262
- method: 'close',
2263
- cb: (event: WebSocket.CloseEvent) => void,
2264
- ): void
2265
- removeEventListener(
2266
- method: 'error',
2267
- cb: (event: WebSocket.ErrorEvent) => void,
2268
- ): void
2269
- removeEventListener(
2270
- method: 'open',
2271
- cb: (event: WebSocket.Event) => void,
2272
- ): void
2273
-
2274
- // Events
2275
- on(
2276
- event: 'close',
2277
- listener: (this: WebSocket, code: number, reason: Buffer) => void,
2278
- ): this
2279
- on(event: 'error', listener: (this: WebSocket, err: Error) => void): this
2280
- on(
2281
- event: 'upgrade',
2282
- listener: (this: WebSocket, request: IncomingMessage) => void,
2283
- ): this
2284
- on(
2285
- event: 'message',
2286
- listener: (
2287
- this: WebSocket,
2288
- data: WebSocket.RawData,
2289
- isBinary: boolean,
2290
- ) => void,
2291
- ): this
2292
- on(event: 'open', listener: (this: WebSocket) => void): this
2293
- on(
2294
- event: 'ping' | 'pong',
2295
- listener: (this: WebSocket, data: Buffer) => void,
2296
- ): this
2297
- on(
2298
- event: 'unexpected-response',
2299
- listener: (
2300
- this: WebSocket,
2301
- request: ClientRequest,
2302
- response: IncomingMessage,
2303
- ) => void,
2304
- ): this
2305
- on(
2306
- event: string | symbol,
2307
- listener: (this: WebSocket, ...args: any[]) => void,
2308
- ): this
2309
-
2310
- once(
2311
- event: 'close',
2312
- listener: (this: WebSocket, code: number, reason: Buffer) => void,
2313
- ): this
2314
- once(event: 'error', listener: (this: WebSocket, err: Error) => void): this
2315
- once(
2316
- event: 'upgrade',
2317
- listener: (this: WebSocket, request: IncomingMessage) => void,
2318
- ): this
2319
- once(
2320
- event: 'message',
2321
- listener: (
2322
- this: WebSocket,
2323
- data: WebSocket.RawData,
2324
- isBinary: boolean,
2325
- ) => void,
2326
- ): this
2327
- once(event: 'open', listener: (this: WebSocket) => void): this
2328
- once(
2329
- event: 'ping' | 'pong',
2330
- listener: (this: WebSocket, data: Buffer) => void,
2331
- ): this
2332
- once(
2333
- event: 'unexpected-response',
2334
- listener: (
2335
- this: WebSocket,
2336
- request: ClientRequest,
2337
- response: IncomingMessage,
2338
- ) => void,
2339
- ): this
2340
- once(
2341
- event: string | symbol,
2342
- listener: (this: WebSocket, ...args: any[]) => void,
2343
- ): this
2344
-
2345
- off(
2346
- event: 'close',
2347
- listener: (this: WebSocket, code: number, reason: Buffer) => void,
2348
- ): this
2349
- off(event: 'error', listener: (this: WebSocket, err: Error) => void): this
2350
- off(
2351
- event: 'upgrade',
2352
- listener: (this: WebSocket, request: IncomingMessage) => void,
2353
- ): this
2354
- off(
2355
- event: 'message',
2356
- listener: (
2357
- this: WebSocket,
2358
- data: WebSocket.RawData,
2359
- isBinary: boolean,
2360
- ) => void,
2361
- ): this
2362
- off(event: 'open', listener: (this: WebSocket) => void): this
2363
- off(
2364
- event: 'ping' | 'pong',
2365
- listener: (this: WebSocket, data: Buffer) => void,
2366
- ): this
2367
- off(
2368
- event: 'unexpected-response',
2369
- listener: (
2370
- this: WebSocket,
2371
- request: ClientRequest,
2372
- response: IncomingMessage,
2373
- ) => void,
2374
- ): this
2375
- off(
2376
- event: string | symbol,
2377
- listener: (this: WebSocket, ...args: any[]) => void,
2378
- ): this
2379
-
2380
- addListener(
2381
- event: 'close',
2382
- listener: (code: number, reason: Buffer) => void,
2383
- ): this
2384
- addListener(event: 'error', listener: (err: Error) => void): this
2385
- addListener(
2386
- event: 'upgrade',
2387
- listener: (request: IncomingMessage) => void,
2388
- ): this
2389
- addListener(
2390
- event: 'message',
2391
- listener: (data: WebSocket.RawData, isBinary: boolean) => void,
2392
- ): this
2393
- addListener(event: 'open', listener: () => void): this
2394
- addListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this
2395
- addListener(
2396
- event: 'unexpected-response',
2397
- listener: (request: ClientRequest, response: IncomingMessage) => void,
2398
- ): this
2399
- addListener(event: string | symbol, listener: (...args: any[]) => void): this
2400
-
2401
- removeListener(
2402
- event: 'close',
2403
- listener: (code: number, reason: Buffer) => void,
2404
- ): this
2405
- removeListener(event: 'error', listener: (err: Error) => void): this
2406
- removeListener(
2407
- event: 'upgrade',
2408
- listener: (request: IncomingMessage) => void,
2409
- ): this
2410
- removeListener(
2411
- event: 'message',
2412
- listener: (data: WebSocket.RawData, isBinary: boolean) => void,
2413
- ): this
2414
- removeListener(event: 'open', listener: () => void): this
2415
- removeListener(event: 'ping' | 'pong', listener: (data: Buffer) => void): this
2416
- removeListener(
2417
- event: 'unexpected-response',
2418
- listener: (request: ClientRequest, response: IncomingMessage) => void,
2419
- ): this
2420
- removeListener(
2421
- event: string | symbol,
2422
- listener: (...args: any[]) => void,
2423
- ): this
2424
- }
2052
+ esmExternals?: boolean | ReadonlyArray<string> | ((id: string) => boolean)
2053
+ /**
2054
+ * Controls what is returned when requiring an ES module from a CommonJS file.
2055
+ * When using the `esmExternals` option, this will also apply to external
2056
+ * modules. By default, this plugin will render those imports as namespace
2057
+ * imports i.e.
2058
+ *
2059
+ * ```js
2060
+ * // input
2061
+ * const foo = require('foo');
2062
+ *
2063
+ * // output
2064
+ * import * as foo from 'foo';
2065
+ * ```
2066
+ *
2067
+ * However, there are some situations where this may not be desired.
2068
+ * For these situations, you can change Rollup's behaviour either globally or
2069
+ * per module. To change it globally, set the `requireReturnsDefault` option
2070
+ * to one of the following values:
2071
+ *
2072
+ * - `false`: This is the default, requiring an ES module returns its
2073
+ * namespace. This is the only option that will also add a marker
2074
+ * `__esModule: true` to the namespace to support interop patterns in
2075
+ * CommonJS modules that are transpiled ES modules.
2076
+ * - `"namespace"`: Like `false`, requiring an ES module returns its
2077
+ * namespace, but the plugin does not add the `__esModule` marker and thus
2078
+ * creates more efficient code. For external dependencies when using
2079
+ * `esmExternals: true`, no additional interop code is generated.
2080
+ * - `"auto"`: This is complementary to how `output.exports: "auto"` works in
2081
+ * Rollup: If a module has a default export and no named exports, requiring
2082
+ * that module returns the default export. In all other cases, the namespace
2083
+ * is returned. For external dependencies when using `esmExternals: true`, a
2084
+ * corresponding interop helper is added.
2085
+ * - `"preferred"`: If a module has a default export, requiring that module
2086
+ * always returns the default export, no matter whether additional named
2087
+ * exports exist. This is similar to how previous versions of this plugin
2088
+ * worked. Again for external dependencies when using `esmExternals: true`,
2089
+ * an interop helper is added.
2090
+ * - `true`: This will always try to return the default export on require
2091
+ * without checking if it actually exists. This can throw at build time if
2092
+ * there is no default export. This is how external dependencies are handled
2093
+ * when `esmExternals` is not used. The advantage over the other options is
2094
+ * that, like `false`, this does not add an interop helper for external
2095
+ * dependencies, keeping the code lean.
2096
+ *
2097
+ * To change this for individual modules, you can supply a function for
2098
+ * `requireReturnsDefault` instead. This function will then be called once for
2099
+ * each required ES module or external dependency with the corresponding id
2100
+ * and allows you to return different values for different modules.
2101
+ * @default false
2102
+ */
2103
+ requireReturnsDefault?:
2104
+ | boolean
2105
+ | 'auto'
2106
+ | 'preferred'
2107
+ | 'namespace'
2108
+ | ((id: string) => boolean | 'auto' | 'preferred' | 'namespace')
2425
2109
 
2426
- declare namespace WebSocket {
2427
2110
  /**
2428
- * Data represents the raw message payload received over the WebSocket.
2111
+ * @default "auto"
2429
2112
  */
2430
- type RawData = Buffer | ArrayBuffer | Buffer[]
2431
-
2113
+ defaultIsModuleExports?: boolean | 'auto' | ((id: string) => boolean | 'auto')
2432
2114
  /**
2433
- * Data represents the message payload received over the WebSocket.
2115
+ * Some modules contain dynamic `require` calls, or require modules that
2116
+ * contain circular dependencies, which are not handled well by static
2117
+ * imports. Including those modules as `dynamicRequireTargets` will simulate a
2118
+ * CommonJS (NodeJS-like) environment for them with support for dynamic
2119
+ * dependencies. It also enables `strictRequires` for those modules.
2120
+ *
2121
+ * Note: In extreme cases, this feature may result in some paths being
2122
+ * rendered as absolute in the final bundle. The plugin tries to avoid
2123
+ * exposing paths from the local machine, but if you are `dynamicRequirePaths`
2124
+ * with paths that are far away from your project's folder, that may require
2125
+ * replacing strings like `"/Users/John/Desktop/foo-project/"` -\> `"/"`.
2434
2126
  */
2435
- type Data = string | Buffer | ArrayBuffer | Buffer[]
2436
-
2127
+ dynamicRequireTargets?: string | ReadonlyArray<string>
2437
2128
  /**
2438
- * CertMeta represents the accepted types for certificate & key data.
2129
+ * To avoid long paths when using the `dynamicRequireTargets` option, you can use this option to specify a directory
2130
+ * that is a common parent for all files that use dynamic require statements. Using a directory higher up such as `/`
2131
+ * may lead to unnecessarily long paths in the generated code and may expose directory names on your machine like your
2132
+ * home directory name. By default, it uses the current working directory.
2439
2133
  */
2440
- type CertMeta = string | string[] | Buffer | Buffer[]
2134
+ dynamicRequireRoot?: string
2135
+ }
2441
2136
 
2137
+ interface RollupDynamicImportVarsOptions {
2442
2138
  /**
2443
- * VerifyClientCallbackSync is a synchronous callback used to inspect the
2444
- * incoming message. The return value (boolean) of the function determines
2445
- * whether or not to accept the handshake.
2139
+ * Files to include in this plugin (default all).
2140
+ * @default []
2446
2141
  */
2447
- type VerifyClientCallbackSync = (info: {
2448
- origin: string
2449
- secure: boolean
2450
- req: IncomingMessage
2451
- }) => boolean
2452
-
2142
+ include?: string | RegExp | (string | RegExp)[]
2453
2143
  /**
2454
- * VerifyClientCallbackAsync is an asynchronous callback used to inspect the
2455
- * incoming message. The return value (boolean) of the function determines
2456
- * whether or not to accept the handshake.
2144
+ * Files to exclude in this plugin (default none).
2145
+ * @default []
2457
2146
  */
2458
- type VerifyClientCallbackAsync = (
2459
- info: { origin: string; secure: boolean; req: IncomingMessage },
2460
- callback: (
2461
- res: boolean,
2462
- code?: number,
2463
- message?: string,
2464
- headers?: OutgoingHttpHeaders,
2465
- ) => void,
2466
- ) => void
2147
+ exclude?: string | RegExp | (string | RegExp)[]
2148
+ /**
2149
+ * By default, the plugin quits the build process when it encounters an error. If you set this option to true, it will throw a warning instead and leave the code untouched.
2150
+ * @default false
2151
+ */
2152
+ warnOnError?: boolean
2153
+ }
2467
2154
 
2468
- interface ClientOptions extends SecureContextOptions {
2469
- protocol?: string | undefined
2470
- followRedirects?: boolean | undefined
2471
- generateMask?(mask: Buffer): void
2472
- handshakeTimeout?: number | undefined
2473
- maxRedirects?: number | undefined
2474
- perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined
2475
- localAddress?: string | undefined
2476
- protocolVersion?: number | undefined
2477
- headers?: { [key: string]: string } | undefined
2478
- origin?: string | undefined
2479
- agent?: Agent | undefined
2480
- host?: string | undefined
2481
- family?: number | undefined
2482
- checkServerIdentity?(servername: string, cert: CertMeta): boolean
2483
- rejectUnauthorized?: boolean | undefined
2484
- maxPayload?: number | undefined
2485
- skipUTF8Validation?: boolean | undefined
2155
+ // Modified and inlined to avoid extra dependency
2156
+ // Source: https://github.com/terser/terser/blob/master/tools/terser.d.ts
2157
+ // BSD Licensed https://github.com/terser/terser/blob/master/LICENSE
2158
+
2159
+ declare namespace Terser {
2160
+ export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020
2161
+
2162
+ export type ConsoleProperty = keyof typeof console
2163
+ type DropConsoleOption = boolean | ConsoleProperty[]
2164
+
2165
+ export interface ParseOptions {
2166
+ bare_returns?: boolean
2167
+ /** @deprecated legacy option. Currently, all supported EcmaScript is valid to parse. */
2168
+ ecma?: ECMA
2169
+ html5_comments?: boolean
2170
+ shebang?: boolean
2486
2171
  }
2487
2172
 
2488
- interface PerMessageDeflateOptions {
2489
- serverNoContextTakeover?: boolean | undefined
2490
- clientNoContextTakeover?: boolean | undefined
2491
- serverMaxWindowBits?: number | undefined
2492
- clientMaxWindowBits?: number | undefined
2493
- zlibDeflateOptions?:
2494
- | {
2495
- flush?: number | undefined
2496
- finishFlush?: number | undefined
2497
- chunkSize?: number | undefined
2498
- windowBits?: number | undefined
2499
- level?: number | undefined
2500
- memLevel?: number | undefined
2501
- strategy?: number | undefined
2502
- dictionary?: Buffer | Buffer[] | DataView | undefined
2503
- info?: boolean | undefined
2504
- }
2505
- | undefined
2506
- zlibInflateOptions?: ZlibOptions | undefined
2507
- threshold?: number | undefined
2508
- concurrencyLimit?: number | undefined
2173
+ export interface CompressOptions {
2174
+ arguments?: boolean
2175
+ arrows?: boolean
2176
+ booleans_as_integers?: boolean
2177
+ booleans?: boolean
2178
+ collapse_vars?: boolean
2179
+ comparisons?: boolean
2180
+ computed_props?: boolean
2181
+ conditionals?: boolean
2182
+ dead_code?: boolean
2183
+ defaults?: boolean
2184
+ directives?: boolean
2185
+ drop_console?: DropConsoleOption
2186
+ drop_debugger?: boolean
2187
+ ecma?: ECMA
2188
+ evaluate?: boolean
2189
+ expression?: boolean
2190
+ global_defs?: object
2191
+ hoist_funs?: boolean
2192
+ hoist_props?: boolean
2193
+ hoist_vars?: boolean
2194
+ ie8?: boolean
2195
+ if_return?: boolean
2196
+ inline?: boolean | InlineFunctions
2197
+ join_vars?: boolean
2198
+ keep_classnames?: boolean | RegExp
2199
+ keep_fargs?: boolean
2200
+ keep_fnames?: boolean | RegExp
2201
+ keep_infinity?: boolean
2202
+ loops?: boolean
2203
+ module?: boolean
2204
+ negate_iife?: boolean
2205
+ passes?: number
2206
+ properties?: boolean
2207
+ pure_funcs?: string[]
2208
+ pure_new?: boolean
2209
+ pure_getters?: boolean | 'strict'
2210
+ reduce_funcs?: boolean
2211
+ reduce_vars?: boolean
2212
+ sequences?: boolean | number
2213
+ side_effects?: boolean
2214
+ switches?: boolean
2215
+ toplevel?: boolean
2216
+ top_retain?: null | string | string[] | RegExp
2217
+ typeofs?: boolean
2218
+ unsafe_arrows?: boolean
2219
+ unsafe?: boolean
2220
+ unsafe_comps?: boolean
2221
+ unsafe_Function?: boolean
2222
+ unsafe_math?: boolean
2223
+ unsafe_symbols?: boolean
2224
+ unsafe_methods?: boolean
2225
+ unsafe_proto?: boolean
2226
+ unsafe_regexp?: boolean
2227
+ unsafe_undefined?: boolean
2228
+ unused?: boolean
2509
2229
  }
2510
2230
 
2511
- interface Event {
2512
- type: string
2513
- target: WebSocket
2231
+ export enum InlineFunctions {
2232
+ Disabled = 0,
2233
+ SimpleFunctions = 1,
2234
+ WithArguments = 2,
2235
+ WithArgumentsAndVariables = 3,
2236
+ }
2237
+
2238
+ export interface MangleOptions {
2239
+ eval?: boolean
2240
+ keep_classnames?: boolean | RegExp
2241
+ keep_fnames?: boolean | RegExp
2242
+ module?: boolean
2243
+ nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
2244
+ properties?: boolean | ManglePropertiesOptions
2245
+ reserved?: string[]
2246
+ safari10?: boolean
2247
+ toplevel?: boolean
2248
+ }
2249
+
2250
+ /**
2251
+ * An identifier mangler for which the output is invariant with respect to the source code.
2252
+ */
2253
+ export interface SimpleIdentifierMangler {
2254
+ /**
2255
+ * Obtains the nth most favored (usually shortest) identifier to rename a variable to.
2256
+ * The mangler will increment n and retry until the return value is not in use in scope, and is not a reserved word.
2257
+ * This function is expected to be stable; Evaluating get(n) === get(n) should always return true.
2258
+ * @param n The ordinal of the identifier.
2259
+ */
2260
+ get(n: number): string
2261
+ }
2262
+
2263
+ /**
2264
+ * An identifier mangler that leverages character frequency analysis to determine identifier precedence.
2265
+ */
2266
+ export interface WeightedIdentifierMangler extends SimpleIdentifierMangler {
2267
+ /**
2268
+ * Modifies the internal weighting of the input characters by the specified delta.
2269
+ * Will be invoked on the entire printed AST, and then deduct mangleable identifiers.
2270
+ * @param chars The characters to modify the weighting of.
2271
+ * @param delta The numeric weight to add to the characters.
2272
+ */
2273
+ consider(chars: string, delta: number): number
2274
+ /**
2275
+ * Resets character weights.
2276
+ */
2277
+ reset(): void
2278
+ /**
2279
+ * Sorts identifiers by character frequency, in preparation for calls to get(n).
2280
+ */
2281
+ sort(): void
2514
2282
  }
2515
2283
 
2516
- interface ErrorEvent {
2517
- error: any
2518
- message: string
2519
- type: string
2520
- target: WebSocket
2284
+ export interface ManglePropertiesOptions {
2285
+ builtins?: boolean
2286
+ debug?: boolean
2287
+ keep_quoted?: boolean | 'strict'
2288
+ nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler
2289
+ regex?: RegExp | string
2290
+ reserved?: string[]
2521
2291
  }
2522
2292
 
2523
- interface CloseEvent {
2524
- wasClean: boolean
2525
- code: number
2526
- reason: string
2527
- type: string
2528
- target: WebSocket
2293
+ export interface FormatOptions {
2294
+ ascii_only?: boolean
2295
+ /** @deprecated Not implemented anymore */
2296
+ beautify?: boolean
2297
+ braces?: boolean
2298
+ comments?:
2299
+ | boolean
2300
+ | 'all'
2301
+ | 'some'
2302
+ | RegExp
2303
+ | ((
2304
+ node: any,
2305
+ comment: {
2306
+ value: string
2307
+ type: 'comment1' | 'comment2' | 'comment3' | 'comment4'
2308
+ pos: number
2309
+ line: number
2310
+ col: number
2311
+ },
2312
+ ) => boolean)
2313
+ ecma?: ECMA
2314
+ ie8?: boolean
2315
+ keep_numbers?: boolean
2316
+ indent_level?: number
2317
+ indent_start?: number
2318
+ inline_script?: boolean
2319
+ keep_quoted_props?: boolean
2320
+ max_line_len?: number | false
2321
+ preamble?: string
2322
+ preserve_annotations?: boolean
2323
+ quote_keys?: boolean
2324
+ quote_style?: OutputQuoteStyle
2325
+ safari10?: boolean
2326
+ semicolons?: boolean
2327
+ shebang?: boolean
2328
+ shorthand?: boolean
2329
+ source_map?: SourceMapOptions
2330
+ webkit?: boolean
2331
+ width?: number
2332
+ wrap_iife?: boolean
2333
+ wrap_func_args?: boolean
2529
2334
  }
2530
2335
 
2531
- interface MessageEvent {
2532
- data: Data
2533
- type: string
2534
- target: WebSocket
2336
+ export enum OutputQuoteStyle {
2337
+ PreferDouble = 0,
2338
+ AlwaysSingle = 1,
2339
+ AlwaysDouble = 2,
2340
+ AlwaysOriginal = 3,
2535
2341
  }
2536
2342
 
2537
- interface EventListenerOptions {
2538
- once?: boolean | undefined
2343
+ export interface MinifyOptions {
2344
+ compress?: boolean | CompressOptions
2345
+ ecma?: ECMA
2346
+ enclose?: boolean | string
2347
+ ie8?: boolean
2348
+ keep_classnames?: boolean | RegExp
2349
+ keep_fnames?: boolean | RegExp
2350
+ mangle?: boolean | MangleOptions
2351
+ module?: boolean
2352
+ nameCache?: object
2353
+ format?: FormatOptions
2354
+ /** @deprecated */
2355
+ output?: FormatOptions
2356
+ parse?: ParseOptions
2357
+ safari10?: boolean
2358
+ sourceMap?: boolean | SourceMapOptions
2359
+ toplevel?: boolean
2539
2360
  }
2540
2361
 
2541
- interface ServerOptions {
2542
- host?: string | undefined
2543
- port?: number | undefined
2544
- backlog?: number | undefined
2545
- server?: Server | HttpsServer | undefined
2546
- verifyClient?:
2547
- | VerifyClientCallbackAsync
2548
- | VerifyClientCallbackSync
2549
- | undefined
2550
- handleProtocols?: (
2551
- protocols: Set<string>,
2552
- request: IncomingMessage,
2553
- ) => string | false
2554
- path?: string | undefined
2555
- noServer?: boolean | undefined
2556
- clientTracking?: boolean | undefined
2557
- perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined
2558
- maxPayload?: number | undefined
2559
- skipUTF8Validation?: boolean | undefined
2560
- WebSocket?: typeof WebSocket.WebSocket | undefined
2362
+ export interface MinifyOutput {
2363
+ code?: string
2364
+ map?: object | string
2365
+ decoded_map?: object | null
2561
2366
  }
2562
2367
 
2563
- interface AddressInfo {
2564
- address: string
2565
- family: string
2566
- port: number
2368
+ export interface SourceMapOptions {
2369
+ /** Source map object, 'inline' or source map file content */
2370
+ content?: object | string
2371
+ includeSources?: boolean
2372
+ filename?: string
2373
+ root?: string
2374
+ asObject?: boolean
2375
+ url?: string | 'inline'
2567
2376
  }
2377
+ }
2568
2378
 
2569
- // WebSocket Server
2570
- class Server<T extends WebSocket = WebSocket> extends EventEmitter {
2571
- options: ServerOptions
2572
- path: string
2573
- clients: Set<T>
2574
-
2575
- constructor(options?: ServerOptions, callback?: () => void)
2576
-
2577
- address(): AddressInfo | string
2578
- close(cb?: (err?: Error) => void): void
2579
- handleUpgrade(
2580
- request: IncomingMessage,
2581
- socket: Duplex,
2582
- upgradeHead: Buffer,
2583
- callback: (client: T, request: IncomingMessage) => void,
2584
- ): void
2585
- shouldHandle(request: IncomingMessage): boolean | Promise<boolean>
2586
-
2587
- // Events
2588
- on(
2589
- event: 'connection',
2590
- cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
2591
- ): this
2592
- on(event: 'error', cb: (this: Server<T>, error: Error) => void): this
2593
- on(
2594
- event: 'headers',
2595
- cb: (
2596
- this: Server<T>,
2597
- headers: string[],
2598
- request: IncomingMessage,
2599
- ) => void,
2600
- ): this
2601
- on(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
2602
- on(
2603
- event: string | symbol,
2604
- listener: (this: Server<T>, ...args: any[]) => void,
2605
- ): this
2606
-
2607
- once(
2608
- event: 'connection',
2609
- cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
2610
- ): this
2611
- once(event: 'error', cb: (this: Server<T>, error: Error) => void): this
2612
- once(
2613
- event: 'headers',
2614
- cb: (
2615
- this: Server<T>,
2616
- headers: string[],
2617
- request: IncomingMessage,
2618
- ) => void,
2619
- ): this
2620
- once(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
2621
- once(
2622
- event: string | symbol,
2623
- listener: (this: Server<T>, ...args: any[]) => void,
2624
- ): this
2625
-
2626
- off(
2627
- event: 'connection',
2628
- cb: (this: Server<T>, socket: T, request: IncomingMessage) => void,
2629
- ): this
2630
- off(event: 'error', cb: (this: Server<T>, error: Error) => void): this
2631
- off(
2632
- event: 'headers',
2633
- cb: (
2634
- this: Server<T>,
2635
- headers: string[],
2636
- request: IncomingMessage,
2637
- ) => void,
2638
- ): this
2639
- off(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
2640
- off(
2641
- event: string | symbol,
2642
- listener: (this: Server<T>, ...args: any[]) => void,
2643
- ): this
2644
-
2645
- addListener(
2646
- event: 'connection',
2647
- cb: (client: T, request: IncomingMessage) => void,
2648
- ): this
2649
- addListener(event: 'error', cb: (err: Error) => void): this
2650
- addListener(
2651
- event: 'headers',
2652
- cb: (headers: string[], request: IncomingMessage) => void,
2653
- ): this
2654
- addListener(event: 'close' | 'listening', cb: () => void): this
2655
- addListener(
2656
- event: string | symbol,
2657
- listener: (...args: any[]) => void,
2658
- ): this
2379
+ interface TerserOptions extends Terser.MinifyOptions {
2380
+ /**
2381
+ * Vite-specific option to specify the max number of workers to spawn
2382
+ * when minifying files with terser.
2383
+ *
2384
+ * @default number of CPUs minus 1
2385
+ */
2386
+ maxWorkers?: number;
2387
+ }
2659
2388
 
2660
- removeListener(event: 'connection', cb: (client: T) => void): this
2661
- removeListener(event: 'error', cb: (err: Error) => void): this
2662
- removeListener(
2663
- event: 'headers',
2664
- cb: (headers: string[], request: IncomingMessage) => void,
2665
- ): this
2666
- removeListener(event: 'close' | 'listening', cb: () => void): this
2667
- removeListener(
2668
- event: string | symbol,
2669
- listener: (...args: any[]) => void,
2670
- ): this
2671
- }
2389
+ interface EnvironmentResolveOptions {
2390
+ /**
2391
+ * @default ['browser', 'module', 'jsnext:main', 'jsnext']
2392
+ */
2393
+ mainFields?: string[];
2394
+ conditions?: string[];
2395
+ externalConditions?: string[];
2396
+ /**
2397
+ * @default ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']
2398
+ */
2399
+ extensions?: string[];
2400
+ dedupe?: string[];
2401
+ /**
2402
+ * Prevent listed dependencies from being externalized and will get bundled in build.
2403
+ * Only works in server environments for now. Previously this was `ssr.noExternal`.
2404
+ * @experimental
2405
+ */
2406
+ noExternal?: string | RegExp | (string | RegExp)[] | true;
2407
+ /**
2408
+ * Externalize the given dependencies and their transitive dependencies.
2409
+ * Only works in server environments for now. Previously this was `ssr.external`.
2410
+ * @experimental
2411
+ */
2412
+ external?: string[] | true;
2413
+ }
2414
+ interface ResolveOptions extends EnvironmentResolveOptions {
2415
+ /**
2416
+ * @default false
2417
+ */
2418
+ preserveSymlinks?: boolean;
2419
+ }
2420
+ interface ResolvePluginOptions {
2421
+ root: string;
2422
+ isBuild: boolean;
2423
+ isProduction: boolean;
2424
+ packageCache?: PackageCache;
2425
+ /**
2426
+ * src code mode also attempts the following:
2427
+ * - resolving /xxx as URLs
2428
+ * - resolving bare imports from optimized deps
2429
+ */
2430
+ asSrc?: boolean;
2431
+ tryIndex?: boolean;
2432
+ tryPrefix?: string;
2433
+ preferRelative?: boolean;
2434
+ isRequire?: boolean;
2435
+ isFromTsImporter?: boolean;
2436
+ scan?: boolean;
2437
+ /**
2438
+ * @deprecated environment.config are used instead
2439
+ */
2440
+ ssrConfig?: SSROptions;
2441
+ }
2442
+ interface InternalResolveOptions extends Required<ResolveOptions>, ResolvePluginOptions {
2443
+ }
2672
2444
 
2673
- const WebSocketServer: typeof Server
2674
- interface WebSocketServer extends Server {}
2675
- const WebSocket: typeof WebSocketAlias
2676
- interface WebSocket extends WebSocketAlias {}
2445
+ /** Cache for package.json resolution and package.json contents */
2446
+ type PackageCache = Map<string, PackageData>;
2447
+ interface PackageData {
2448
+ dir: string;
2449
+ hasSideEffects: (id: string) => boolean | 'no-treeshake' | null;
2450
+ setResolvedCache: (key: string, entry: string, options: InternalResolveOptions) => void;
2451
+ getResolvedCache: (key: string, options: InternalResolveOptions) => string | undefined;
2452
+ data: {
2453
+ [field: string]: any;
2454
+ name: string;
2455
+ type: string;
2456
+ version: string;
2457
+ main: string;
2458
+ module: string;
2459
+ browser: string | Record<string, string | false>;
2460
+ exports: string | Record<string, any> | string[];
2461
+ imports: Record<string, any>;
2462
+ dependencies: Record<string, string>;
2463
+ };
2464
+ }
2677
2465
 
2678
- // WebSocket stream
2679
- function createWebSocketStream(
2680
- websocket: WebSocket,
2681
- options?: DuplexOptions,
2682
- ): Duplex
2466
+ interface BuildEnvironmentOptions {
2467
+ /**
2468
+ * Compatibility transform target. The transform is performed with esbuild
2469
+ * and the lowest supported target is es2015/es6. Note this only handles
2470
+ * syntax transformation and does not cover polyfills (except for dynamic
2471
+ * import)
2472
+ *
2473
+ * Default: 'modules' - Similar to `@babel/preset-env`'s targets.esmodules,
2474
+ * transpile targeting browsers that natively support dynamic es module imports.
2475
+ * https://caniuse.com/es6-module-dynamic-import
2476
+ *
2477
+ * Another special value is 'esnext' - which only performs minimal transpiling
2478
+ * (for minification compat) and assumes native dynamic imports support.
2479
+ *
2480
+ * For custom targets, see https://esbuild.github.io/api/#target and
2481
+ * https://esbuild.github.io/content-types/#javascript for more details.
2482
+ * @default 'modules'
2483
+ */
2484
+ target?: 'modules' | esbuild_TransformOptions['target'] | false;
2485
+ /**
2486
+ * whether to inject module preload polyfill.
2487
+ * Note: does not apply to library mode.
2488
+ * @default true
2489
+ * @deprecated use `modulePreload.polyfill` instead
2490
+ */
2491
+ polyfillModulePreload?: boolean;
2492
+ /**
2493
+ * Configure module preload
2494
+ * Note: does not apply to library mode.
2495
+ * @default true
2496
+ */
2497
+ modulePreload?: boolean | ModulePreloadOptions;
2498
+ /**
2499
+ * Directory relative from `root` where build output will be placed. If the
2500
+ * directory exists, it will be removed before the build.
2501
+ * @default 'dist'
2502
+ */
2503
+ outDir?: string;
2504
+ /**
2505
+ * Directory relative from `outDir` where the built js/css/image assets will
2506
+ * be placed.
2507
+ * @default 'assets'
2508
+ */
2509
+ assetsDir?: string;
2510
+ /**
2511
+ * Static asset files smaller than this number (in bytes) will be inlined as
2512
+ * base64 strings. If a callback is passed, a boolean can be returned to opt-in
2513
+ * or opt-out of inlining. If nothing is returned the default logic applies.
2514
+ *
2515
+ * Default limit is `4096` (4 KiB). Set to `0` to disable.
2516
+ * @default 4096
2517
+ */
2518
+ assetsInlineLimit?: number | ((filePath: string, content: Buffer) => boolean | undefined);
2519
+ /**
2520
+ * Whether to code-split CSS. When enabled, CSS in async chunks will be
2521
+ * inlined as strings in the chunk and inserted via dynamically created
2522
+ * style tags when the chunk is loaded.
2523
+ * @default true
2524
+ */
2525
+ cssCodeSplit?: boolean;
2526
+ /**
2527
+ * An optional separate target for CSS minification.
2528
+ * As esbuild only supports configuring targets to mainstream
2529
+ * browsers, users may need this option when they are targeting
2530
+ * a niche browser that comes with most modern JavaScript features
2531
+ * but has poor CSS support, e.g. Android WeChat WebView, which
2532
+ * doesn't support the #RGBA syntax.
2533
+ * @default target
2534
+ */
2535
+ cssTarget?: esbuild_TransformOptions['target'] | false;
2536
+ /**
2537
+ * Override CSS minification specifically instead of defaulting to `build.minify`,
2538
+ * so you can configure minification for JS and CSS separately.
2539
+ * @default 'esbuild'
2540
+ */
2541
+ cssMinify?: boolean | 'esbuild' | 'lightningcss';
2542
+ /**
2543
+ * If `true`, a separate sourcemap file will be created. If 'inline', the
2544
+ * sourcemap will be appended to the resulting output file as data URI.
2545
+ * 'hidden' works like `true` except that the corresponding sourcemap
2546
+ * comments in the bundled files are suppressed.
2547
+ * @default false
2548
+ */
2549
+ sourcemap?: boolean | 'inline' | 'hidden';
2550
+ /**
2551
+ * Set to `false` to disable minification, or specify the minifier to use.
2552
+ * Available options are 'terser' or 'esbuild'.
2553
+ * @default 'esbuild'
2554
+ */
2555
+ minify?: boolean | 'terser' | 'esbuild';
2556
+ /**
2557
+ * Options for terser
2558
+ * https://terser.org/docs/api-reference#minify-options
2559
+ *
2560
+ * In addition, you can also pass a `maxWorkers: number` option to specify the
2561
+ * max number of workers to spawn. Defaults to the number of CPUs minus 1.
2562
+ */
2563
+ terserOptions?: TerserOptions;
2564
+ /**
2565
+ * Will be merged with internal rollup options.
2566
+ * https://rollupjs.org/configuration-options/
2567
+ */
2568
+ rollupOptions?: RollupOptions;
2569
+ /**
2570
+ * Options to pass on to `@rollup/plugin-commonjs`
2571
+ */
2572
+ commonjsOptions?: RollupCommonJSOptions;
2573
+ /**
2574
+ * Options to pass on to `@rollup/plugin-dynamic-import-vars`
2575
+ */
2576
+ dynamicImportVarsOptions?: RollupDynamicImportVarsOptions;
2577
+ /**
2578
+ * Whether to write bundle to disk
2579
+ * @default true
2580
+ */
2581
+ write?: boolean;
2582
+ /**
2583
+ * Empty outDir on write.
2584
+ * @default true when outDir is a sub directory of project root
2585
+ */
2586
+ emptyOutDir?: boolean | null;
2587
+ /**
2588
+ * Copy the public directory to outDir on write.
2589
+ * @default true
2590
+ */
2591
+ copyPublicDir?: boolean;
2592
+ /**
2593
+ * Whether to emit a .vite/manifest.json under assets dir to map hash-less filenames
2594
+ * to their hashed versions. Useful when you want to generate your own HTML
2595
+ * instead of using the one generated by Vite.
2596
+ *
2597
+ * Example:
2598
+ *
2599
+ * ```json
2600
+ * {
2601
+ * "main.js": {
2602
+ * "file": "main.68fe3fad.js",
2603
+ * "css": "main.e6b63442.css",
2604
+ * "imports": [...],
2605
+ * "dynamicImports": [...]
2606
+ * }
2607
+ * }
2608
+ * ```
2609
+ * @default false
2610
+ */
2611
+ manifest?: boolean | string;
2612
+ /**
2613
+ * Build in library mode. The value should be the global name of the lib in
2614
+ * UMD mode. This will produce esm + cjs + umd bundle formats with default
2615
+ * configurations that are suitable for distributing libraries.
2616
+ * @default false
2617
+ */
2618
+ lib?: LibraryOptions | false;
2619
+ /**
2620
+ * Produce SSR oriented build. Note this requires specifying SSR entry via
2621
+ * `rollupOptions.input`.
2622
+ * @default false
2623
+ */
2624
+ ssr?: boolean | string;
2625
+ /**
2626
+ * Generate SSR manifest for determining style links and asset preload
2627
+ * directives in production.
2628
+ * @default false
2629
+ */
2630
+ ssrManifest?: boolean | string;
2631
+ /**
2632
+ * Emit assets during SSR.
2633
+ * @default false
2634
+ */
2635
+ ssrEmitAssets?: boolean;
2636
+ /**
2637
+ * Emit assets during build. Frameworks can set environments.ssr.build.emitAssets
2638
+ * By default, it is true for the client and false for other environments.
2639
+ */
2640
+ emitAssets?: boolean;
2641
+ /**
2642
+ * Set to false to disable reporting compressed chunk sizes.
2643
+ * Can slightly improve build speed.
2644
+ * @default true
2645
+ */
2646
+ reportCompressedSize?: boolean;
2647
+ /**
2648
+ * Adjust chunk size warning limit (in kB).
2649
+ * @default 500
2650
+ */
2651
+ chunkSizeWarningLimit?: number;
2652
+ /**
2653
+ * Rollup watch options
2654
+ * https://rollupjs.org/configuration-options/#watch
2655
+ * @default null
2656
+ */
2657
+ watch?: WatcherOptions | null;
2658
+ /**
2659
+ * create the Build Environment instance
2660
+ */
2661
+ createEnvironment?: (name: string, config: ResolvedConfig) => Promise<BuildEnvironment> | BuildEnvironment;
2683
2662
  }
2684
-
2685
- type WebSocketCustomListener<T> = (data: T, client: WebSocketClient) => void;
2686
- declare const isWebSocketServer: unique symbol;
2687
- interface WebSocketServer extends HotChannel {
2688
- [isWebSocketServer]: true;
2663
+ type BuildOptions = BuildEnvironmentOptions;
2664
+ interface LibraryOptions {
2689
2665
  /**
2690
- * Listen on port and host
2666
+ * Path of library entry
2691
2667
  */
2692
- listen(): void;
2668
+ entry: InputOption;
2693
2669
  /**
2694
- * Get all connected clients.
2670
+ * The name of the exposed global variable. Required when the `formats` option includes
2671
+ * `umd` or `iife`
2695
2672
  */
2696
- clients: Set<WebSocketClient>;
2673
+ name?: string;
2697
2674
  /**
2698
- * Disconnect all clients and terminate the server.
2675
+ * Output bundle formats
2676
+ * @default ['es', 'umd']
2699
2677
  */
2700
- close(): Promise<void>;
2678
+ formats?: LibraryFormats[];
2701
2679
  /**
2702
- * Handle custom event emitted by `import.meta.hot.send`
2680
+ * The name of the package file output. The default file name is the name option
2681
+ * of the project package.json. It can also be defined as a function taking the
2682
+ * format as an argument.
2703
2683
  */
2704
- on: WebSocket.Server['on'] & {
2705
- <T extends string>(event: T, listener: WebSocketCustomListener<InferCustomEventPayload<T>>): void;
2706
- };
2684
+ fileName?: string | ((format: ModuleFormat, entryName: string) => string);
2707
2685
  /**
2708
- * Unregister event listener.
2686
+ * The name of the CSS file output if the library imports CSS. Defaults to the
2687
+ * same value as `build.lib.fileName` if it's set a string, otherwise it falls
2688
+ * back to the name option of the project package.json.
2709
2689
  */
2710
- off: WebSocket.Server['off'] & {
2711
- (event: string, listener: Function): void;
2712
- };
2690
+ cssFileName?: string;
2713
2691
  }
2714
- interface WebSocketClient extends HotChannelClient {
2692
+ type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife' | 'system';
2693
+ interface ModulePreloadOptions {
2715
2694
  /**
2716
- * The raw WebSocket instance
2717
- * @advanced
2695
+ * Whether to inject a module preload polyfill.
2696
+ * Note: does not apply to library mode.
2697
+ * @default true
2718
2698
  */
2719
- socket: WebSocket;
2699
+ polyfill?: boolean;
2700
+ /**
2701
+ * Resolve the list of dependencies to preload for a given dynamic import
2702
+ * @experimental
2703
+ */
2704
+ resolveDependencies?: ResolveModulePreloadDependenciesFn;
2705
+ }
2706
+ interface ResolvedModulePreloadOptions {
2707
+ polyfill: boolean;
2708
+ resolveDependencies?: ResolveModulePreloadDependenciesFn;
2709
+ }
2710
+ type ResolveModulePreloadDependenciesFn = (filename: string, deps: string[], context: {
2711
+ hostId: string;
2712
+ hostType: 'html' | 'js';
2713
+ }) => string[];
2714
+ interface ResolvedBuildEnvironmentOptions extends Required<Omit<BuildEnvironmentOptions, 'polyfillModulePreload'>> {
2715
+ modulePreload: false | ResolvedModulePreloadOptions;
2716
+ }
2717
+ interface ResolvedBuildOptions extends Required<Omit<BuildOptions, 'polyfillModulePreload'>> {
2718
+ modulePreload: false | ResolvedModulePreloadOptions;
2719
+ }
2720
+ /**
2721
+ * Bundles a single environment for production.
2722
+ * Returns a Promise containing the build result.
2723
+ */
2724
+ declare function build(inlineConfig?: InlineConfig): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;
2725
+ type RenderBuiltAssetUrl = (filename: string, type: {
2726
+ type: 'asset' | 'public';
2727
+ hostId: string;
2728
+ hostType: 'js' | 'css' | 'html';
2729
+ ssr: boolean;
2730
+ }) => string | {
2731
+ relative?: boolean;
2732
+ runtime?: string;
2733
+ } | undefined;
2734
+ declare class BuildEnvironment extends BaseEnvironment {
2735
+ mode: "build";
2736
+ constructor(name: string, config: ResolvedConfig, setup?: {
2737
+ options?: EnvironmentOptions;
2738
+ });
2739
+ init(): Promise<void>;
2740
+ }
2741
+ interface ViteBuilder {
2742
+ environments: Record<string, BuildEnvironment>;
2743
+ config: ResolvedConfig;
2744
+ buildApp(): Promise<void>;
2745
+ build(environment: BuildEnvironment): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;
2746
+ }
2747
+ interface BuilderOptions {
2748
+ /**
2749
+ * Whether to share the config instance among environments to align with the behavior of dev server.
2750
+ *
2751
+ * @default false
2752
+ * @experimental
2753
+ */
2754
+ sharedConfigBuild?: boolean;
2755
+ /**
2756
+ * Whether to share the plugin instances among environments to align with the behavior of dev server.
2757
+ *
2758
+ * @default false
2759
+ * @experimental
2760
+ */
2761
+ sharedPlugins?: boolean;
2762
+ buildApp?: (builder: ViteBuilder) => Promise<void>;
2763
+ }
2764
+ type ResolvedBuilderOptions = Required<BuilderOptions>;
2765
+ /**
2766
+ * Creates a ViteBuilder to orchestrate building multiple environments.
2767
+ * @experimental
2768
+ */
2769
+ declare function createBuilder(inlineConfig?: InlineConfig, useLegacyBuilder?: null | boolean): Promise<ViteBuilder>;
2770
+
2771
+ type Environment = DevEnvironment | BuildEnvironment | UnknownEnvironment;
2772
+ /**
2773
+ * Creates a function that hides the complexities of a WeakMap with an initial value
2774
+ * to implement object metadata. Used by plugins to implement cross hooks per
2775
+ * environment metadata
2776
+ *
2777
+ * @experimental
2778
+ */
2779
+ declare function perEnvironmentState<State>(initial: (environment: Environment) => State): (context: PluginContext) => State;
2780
+
2781
+ declare class EnvironmentPluginContainer {
2782
+ environment: Environment;
2783
+ plugins: Plugin[];
2784
+ watcher?: FSWatcher | undefined;
2785
+ private _pluginContextMap;
2786
+ private _resolvedRollupOptions?;
2787
+ private _processesing;
2788
+ private _seenResolves;
2789
+ private _moduleNodeToLoadAddedImports;
2790
+ getSortedPluginHooks: PluginHookUtils['getSortedPluginHooks'];
2791
+ getSortedPlugins: PluginHookUtils['getSortedPlugins'];
2792
+ moduleGraph: EnvironmentModuleGraph | undefined;
2793
+ watchFiles: Set<string>;
2794
+ minimalContext: MinimalPluginContext;
2795
+ private _started;
2796
+ private _buildStartPromise;
2797
+ private _closed;
2798
+ private _updateModuleLoadAddedImports;
2799
+ private _getAddedImports;
2800
+ getModuleInfo(id: string): ModuleInfo | null;
2801
+ private handleHookPromise;
2802
+ get options(): InputOptions;
2803
+ resolveRollupOptions(): Promise<InputOptions>;
2804
+ private _getPluginContext;
2805
+ private hookParallel;
2806
+ buildStart(_options?: InputOptions): Promise<void>;
2807
+ resolveId(rawId: string, importer?: string | undefined, options?: {
2808
+ attributes?: Record<string, string>;
2809
+ custom?: CustomPluginOptions;
2810
+ skip?: Set<Plugin>;
2811
+ isEntry?: boolean;
2812
+ }): Promise<PartialResolvedId | null>;
2813
+ load(id: string): Promise<LoadResult | null>;
2814
+ transform(code: string, id: string, options?: {
2815
+ inMap?: SourceDescription['map'];
2816
+ }): Promise<{
2817
+ code: string;
2818
+ map: SourceMap | {
2819
+ mappings: '';
2820
+ } | null;
2821
+ }>;
2822
+ watchChange(id: string, change: {
2823
+ event: 'create' | 'update' | 'delete';
2824
+ }): Promise<void>;
2825
+ close(): Promise<void>;
2826
+ }
2827
+ declare class PluginContainer {
2828
+ private environments;
2829
+ constructor(environments: Record<string, Environment>);
2830
+ private _getEnvironment;
2831
+ private _getPluginContainer;
2832
+ getModuleInfo(id: string): ModuleInfo | null;
2833
+ get options(): InputOptions;
2834
+ buildStart(_options?: InputOptions): Promise<void>;
2835
+ watchChange(id: string, change: {
2836
+ event: 'create' | 'update' | 'delete';
2837
+ }): Promise<void>;
2838
+ resolveId(rawId: string, importer?: string, options?: {
2839
+ attributes?: Record<string, string>;
2840
+ custom?: CustomPluginOptions;
2841
+ skip?: Set<Plugin>;
2842
+ ssr?: boolean;
2843
+ isEntry?: boolean;
2844
+ }): Promise<PartialResolvedId | null>;
2845
+ load(id: string, options?: {
2846
+ ssr?: boolean;
2847
+ }): Promise<LoadResult | null>;
2848
+ transform(code: string, id: string, options?: {
2849
+ ssr?: boolean;
2850
+ environment?: Environment;
2851
+ inMap?: SourceDescription['map'];
2852
+ }): Promise<{
2853
+ code: string;
2854
+ map: SourceMap | {
2855
+ mappings: '';
2856
+ } | null;
2857
+ }>;
2858
+ close(): Promise<void>;
2720
2859
  }
2721
2860
 
2722
2861
  interface ServerOptions extends CommonServerOptions {
@@ -2745,7 +2884,7 @@ interface ServerOptions extends CommonServerOptions {
2745
2884
  };
2746
2885
  /**
2747
2886
  * chokidar watch options or null to disable FS watching
2748
- * https://github.com/paulmillr/chokidar#getting-started
2887
+ * https://github.com/paulmillr/chokidar/tree/3.6.0#api
2749
2888
  */
2750
2889
  watch?: WatchOptions | null;
2751
2890
  /**
@@ -2851,8 +2990,8 @@ interface ViteDevServer {
2851
2990
  httpServer: HttpServer | null;
2852
2991
  /**
2853
2992
  * Chokidar watcher instance. If `config.server.watch` is set to `null`,
2854
- * it will not watch any files and calling `add` will have no effect.
2855
- * https://github.com/paulmillr/chokidar#getting-started
2993
+ * it will not watch any files and calling `add` or `unwatch` will have no effect.
2994
+ * https://github.com/paulmillr/chokidar/tree/3.6.0#api
2856
2995
  */
2857
2996
  watcher: FSWatcher;
2858
2997
  /**
@@ -2964,10 +3103,6 @@ interface ResolvedServerUrls {
2964
3103
  }
2965
3104
  declare function createServer(inlineConfig?: InlineConfig): Promise<ViteDevServer>;
2966
3105
 
2967
- type AnymatchFn = (testString: string) => boolean
2968
- type AnymatchPattern = string | RegExp | AnymatchFn
2969
- type AnymatchMatcher = AnymatchPattern | AnymatchPattern[]
2970
-
2971
3106
  interface ESBuildOptions extends esbuild_TransformOptions {
2972
3107
  include?: string | RegExp | string[] | RegExp[];
2973
3108
  exclude?: string | RegExp | string[] | RegExp[];
@@ -2982,6 +3117,21 @@ type ESBuildTransformResult = Omit<esbuild_TransformResult, 'map'> & {
2982
3117
  };
2983
3118
  declare function transformWithEsbuild(code: string, filename: string, options?: esbuild_TransformOptions, inMap?: object, config?: ResolvedConfig, watcher?: FSWatcher): Promise<ESBuildTransformResult>;
2984
3119
 
3120
+ interface JsonOptions {
3121
+ /**
3122
+ * Generate a named export for every property of the JSON object
3123
+ * @default true
3124
+ */
3125
+ namedExports?: boolean;
3126
+ /**
3127
+ * Generate performant output as JSON.parse("stringified").
3128
+ *
3129
+ * When set to 'auto', the data will be stringified only if the data is bigger than 10kB.
3130
+ * @default 'auto'
3131
+ */
3132
+ stringify?: boolean | 'auto';
3133
+ }
3134
+
2985
3135
  interface CSSOptions {
2986
3136
  /**
2987
3137
  * Using lightningcss is an experimental option to handle CSS modules,
@@ -3043,7 +3193,7 @@ interface CSSModulesOptions {
3043
3193
  */
3044
3194
  localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly' | ((originalClassName: string, generatedClassName: string, inputFile: string) => string);
3045
3195
  }
3046
- type ResolvedCSSOptions = Omit<CSSOptions, 'lightningcss'> & {
3196
+ type ResolvedCSSOptions = Omit<CSSOptions, 'lightningcss'> & Required<Pick<CSSOptions, 'transformer'>> & {
3047
3197
  lightningcss?: LightningCSSOptions;
3048
3198
  };
3049
3199
  interface PreprocessCSSResult {
@@ -3248,8 +3398,9 @@ interface Plugin<A = any> extends rollup.Plugin<A> {
3248
3398
  /**
3249
3399
  * Define environments where this plugin should be active
3250
3400
  * By default, the plugin is active in all environments
3401
+ * @experimental
3251
3402
  */
3252
- applyToEnvironment?: (environment: Environment) => boolean;
3403
+ applyToEnvironment?: (environment: PartialEnvironment) => boolean | Promise<boolean> | PluginOption;
3253
3404
  /**
3254
3405
  * Modify vite config before it's resolved. The hook can either mutate the
3255
3406
  * passed-in config directly, or return a partial config object that will be
@@ -3269,7 +3420,13 @@ interface Plugin<A = any> extends rollup.Plugin<A> {
3269
3420
  * hook instead of the config hook. Leaving the config hook only for modifying the root
3270
3421
  * default environment config.
3271
3422
  */
3272
- configEnvironment?: ObjectHook<(this: void, name: string, config: EnvironmentOptions, env: ConfigEnv) => EnvironmentOptions | null | void | Promise<EnvironmentOptions | null | void>>;
3423
+ configEnvironment?: ObjectHook<(this: void, name: string, config: EnvironmentOptions, env: ConfigEnv & {
3424
+ /**
3425
+ * Whether this environment is SSR environment and `ssr.target` is set to `'webworker'`.
3426
+ * Only intended to be used for backward compatibility.
3427
+ */
3428
+ isSsrTargetWebworker?: boolean;
3429
+ }) => EnvironmentOptions | null | void | Promise<EnvironmentOptions | null | void>>;
3273
3430
  /**
3274
3431
  * Use this hook to read and store the final resolved vite config.
3275
3432
  */
@@ -3334,21 +3491,10 @@ type PluginWithRequiredHook<K extends keyof Plugin> = Plugin & {
3334
3491
  type Thenable<T> = T | Promise<T>;
3335
3492
  type FalsyPlugin = false | null | undefined;
3336
3493
  type PluginOption = Thenable<Plugin | FalsyPlugin | PluginOption[]>;
3337
-
3338
- interface JsonOptions {
3339
- /**
3340
- * Generate a named export for every property of the JSON object
3341
- * @default true
3342
- */
3343
- namedExports?: boolean;
3344
- /**
3345
- * Generate performant output as JSON.parse("stringified").
3346
- *
3347
- * When set to 'auto', the data will be stringified only if the data is bigger than 10kB.
3348
- * @default 'auto'
3349
- */
3350
- stringify?: boolean | 'auto';
3351
- }
3494
+ /**
3495
+ * @experimental
3496
+ */
3497
+ declare function perEnvironmentPlugin(name: string, applyToEnvironment: (environment: PartialEnvironment) => boolean | Promise<boolean> | PluginOption): Plugin;
3352
3498
 
3353
3499
  type SSRTarget = 'node' | 'webworker';
3354
3500
  type SsrDepOptimizationConfig = DepOptimizationConfig;
@@ -3386,6 +3532,7 @@ interface SSROptions {
3386
3532
  * @default []
3387
3533
  */
3388
3534
  externalConditions?: string[];
3535
+ mainFields?: string[];
3389
3536
  };
3390
3537
  }
3391
3538
  interface ResolvedSSROptions extends SSROptions {
@@ -3475,7 +3622,9 @@ interface DevEnvironmentOptions {
3475
3622
  */
3476
3623
  moduleRunnerTransform?: boolean;
3477
3624
  }
3478
- type ResolvedDevEnvironmentOptions = Required<DevEnvironmentOptions>;
3625
+ type ResolvedDevEnvironmentOptions = Omit<Required<DevEnvironmentOptions>, 'sourcemapIgnoreList'> & {
3626
+ sourcemapIgnoreList: Exclude<DevEnvironmentOptions['sourcemapIgnoreList'], false | undefined>;
3627
+ };
3479
3628
  type AllResolveOptions = ResolveOptions & {
3480
3629
  alias?: AliasOptions;
3481
3630
  };
@@ -3757,7 +3906,7 @@ interface InlineConfig extends UserConfig {
3757
3906
  configFile?: string | false;
3758
3907
  envFile?: false;
3759
3908
  }
3760
- type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'css' | 'assetsInclude' | 'optimizeDeps' | 'worker' | 'build' | 'dev' | 'environments'> & {
3909
+ type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'css' | 'json' | 'assetsInclude' | 'optimizeDeps' | 'worker' | 'build' | 'dev' | 'environments' | 'server' | 'preview'> & {
3761
3910
  configFile: string | undefined;
3762
3911
  configFileDependencies: string[];
3763
3912
  inlineConfig: InlineConfig;
@@ -3776,6 +3925,7 @@ type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'css' | 'assetsInclu
3776
3925
  };
3777
3926
  plugins: readonly Plugin[];
3778
3927
  css: ResolvedCSSOptions;
3928
+ json: Required<JsonOptions>;
3779
3929
  esbuild: ESBuildOptions | false;
3780
3930
  server: ResolvedServerOptions;
3781
3931
  dev: ResolvedDevEnvironmentOptions;
@@ -3825,7 +3975,6 @@ interface ServerModuleRunnerOptions extends Omit<ModuleRunnerOptions, 'root' | '
3825
3975
  * Disable HMR or configure HMR logger.
3826
3976
  */
3827
3977
  hmr?: false | {
3828
- connection?: ModuleRunnerHMRConnection;
3829
3978
  logger?: ModuleRunnerHmr['logger'];
3830
3979
  };
3831
3980
  /**
@@ -3839,11 +3988,11 @@ interface ServerModuleRunnerOptions extends Omit<ModuleRunnerOptions, 'root' | '
3839
3988
  */
3840
3989
  declare function createServerModuleRunner(environment: DevEnvironment, options?: ServerModuleRunnerOptions): ModuleRunner;
3841
3990
 
3842
- declare function createRunnableDevEnvironment(name: string, config: ResolvedConfig, context?: RunnableDevEnvironmentContext): DevEnvironment;
3991
+ declare function createRunnableDevEnvironment(name: string, config: ResolvedConfig, context?: RunnableDevEnvironmentContext): RunnableDevEnvironment;
3843
3992
  interface RunnableDevEnvironmentContext extends Omit<DevEnvironmentContext, 'hot'> {
3844
3993
  runner?: (environment: RunnableDevEnvironment, options?: ServerModuleRunnerOptions) => ModuleRunner;
3845
3994
  runnerOptions?: ServerModuleRunnerOptions;
3846
- hot?: false | HotChannel;
3995
+ hot?: boolean;
3847
3996
  }
3848
3997
  declare function isRunnableDevEnvironment(environment: Environment): environment is RunnableDevEnvironment;
3849
3998
  declare class RunnableDevEnvironment extends DevEnvironment {
@@ -3866,21 +4015,6 @@ interface FetchModuleOptions {
3866
4015
  */
3867
4016
  declare function fetchModule(environment: DevEnvironment, url: string, importer?: string, options?: FetchModuleOptions): Promise<FetchResult>;
3868
4017
 
3869
- /**
3870
- * The connector class to establish HMR communication between the server and the Vite runtime.
3871
- * @experimental
3872
- */
3873
- declare class ServerHMRConnector implements ModuleRunnerHMRConnection {
3874
- private hotChannel;
3875
- private handlers;
3876
- private hmrClient;
3877
- private connected;
3878
- constructor(hotChannel: ServerHotChannel);
3879
- isReady(): boolean;
3880
- send(payload_: HotPayload): void;
3881
- onUpdate(handler: (payload: HotPayload) => void): void;
3882
- }
3883
-
3884
4018
  interface ModuleRunnerTransformOptions {
3885
4019
  json?: {
3886
4020
  stringify?: boolean;
@@ -3891,6 +4025,10 @@ declare function ssrTransform(code: string, inMap: SourceMap | {
3891
4025
  } | null, url: string, originalCode: string, options?: ModuleRunnerTransformOptions): Promise<TransformResult | null>;
3892
4026
 
3893
4027
  declare const VERSION: string;
4028
+ declare const DEFAULT_CLIENT_MAIN_FIELDS: readonly string[];
4029
+ declare const DEFAULT_SERVER_MAIN_FIELDS: readonly string[];
4030
+ declare const DEFAULT_CLIENT_CONDITIONS: readonly string[];
4031
+ declare const DEFAULT_SERVER_CONDITIONS: readonly string[];
3894
4032
 
3895
4033
  declare const isCSSRequest: (request: string) => boolean;
3896
4034
  /**
@@ -3965,4 +4103,4 @@ interface ManifestChunk {
3965
4103
  dynamicImports?: string[];
3966
4104
  }
3967
4105
 
3968
- export { type Alias, type AliasOptions, type AnymatchFn, type AnymatchPattern, type AppType, type BindCLIShortcutsOptions, BuildEnvironment, type BuildEnvironmentOptions, type BuildOptions, type BuilderOptions, type CLIShortcut, type CSSModulesOptions, type CSSOptions, type CommonServerOptions, type ConfigEnv, Connect, type CorsOptions, type CorsOrigin, type DepOptimizationConfig, type DepOptimizationMetadata, type DepOptimizationOptions, DevEnvironment, type DevEnvironmentContext, type DevEnvironmentOptions, type ESBuildOptions, type ESBuildTransformResult, type Environment, EnvironmentModuleGraph, EnvironmentModuleNode, type EnvironmentOptions, type ExperimentalOptions, type ExportsData, FSWatcher, type FetchModuleOptions, type FileSystemServeOptions, type FilterPattern, type HMRBroadcaster, type HMRBroadcasterClient, type HMRChannel, type HTMLOptions, type HmrContext, type HmrOptions, type HookHandler, type HotChannel, type HotChannelClient, type HotUpdateOptions, type HtmlTagDescriptor, HttpProxy, type HttpServer, type IndexHtmlTransform, type IndexHtmlTransformContext, type IndexHtmlTransformHook, type IndexHtmlTransformResult, type InlineConfig, type InternalResolveOptions, type JsonOptions, type LegacyOptions, type LessPreprocessorOptions, type LibraryFormats, type LibraryOptions, type LogErrorOptions, type LogLevel, type LogOptions, type LogType, type Logger, type LoggerOptions, type Manifest, type ManifestChunk, type MapToFunction, type AnymatchMatcher as Matcher, ModuleGraph, ModuleNode, type ModulePreloadOptions, type ModuleRunnerTransformOptions, type OptimizedDepInfo, type Plugin, PluginContainer, type PluginHookUtils, type PluginOption, type PreprocessCSSResult, type PreviewOptions, type PreviewServer, type PreviewServerHook, type ProxyOptions, RemoteEnvironmentTransport, type RenderBuiltAssetUrl, type ResolveFn, type ResolveModulePreloadDependenciesFn, type ResolveOptions, type ResolvedBuildEnvironmentOptions, type ResolvedBuildOptions, type ResolvedCSSOptions, type ResolvedConfig, type ResolvedDevEnvironmentOptions, type ResolvedModulePreloadOptions, type ResolvedPreviewOptions, type ResolvedSSROptions, type ResolvedServerOptions, type ResolvedServerUrls, type ResolvedUrl, type ResolvedWorkerOptions, type ResolverFunction, type ResolverObject, type RollupCommonJSOptions, type RollupDynamicImportVarsOptions, RunnableDevEnvironment, type RunnableDevEnvironmentContext, type SSROptions, type SSRTarget, type SassPreprocessorOptions, type SendOptions, type ServerHMRChannel, ServerHMRConnector, type ServerHook, type ServerHotChannel, type ServerModuleRunnerOptions, type ServerOptions, SplitVendorChunkCache, type SsrDepOptimizationConfig, type StylusPreprocessorOptions, Terser, type TerserOptions, type TransformOptions, type TransformResult, type UserConfig, type UserConfigExport, type UserConfigFn, type UserConfigFnObject, type UserConfigFnPromise, type ViteBuilder, type ViteDevServer, type WatchOptions, WebSocket, WebSocketAlias, type WebSocketClient, type WebSocketCustomListener, WebSocketServer, build, buildErrorMessage, createBuilder, createFilter, createIdResolver, createLogger, createRunnableDevEnvironment, createServer, createServerHotChannel, createServerModuleRunner, defineConfig, fetchModule, formatPostcssSourceMap, isCSSRequest, isFileLoadingAllowed, isFileServingAllowed, isRunnableDevEnvironment, loadConfigFromFile, loadEnv, mergeAlias, mergeConfig, ssrTransform as moduleRunnerTransform, normalizePath, optimizeDeps, preprocessCSS, preview, resolveConfig, resolveEnvPrefix, rollupVersion, searchForWorkspaceRoot, send, sortUserPlugins, splitVendorChunk, splitVendorChunkPlugin, transformWithEsbuild, VERSION as version };
4106
+ export { type Alias, type AliasOptions, type AnymatchFn, type AnymatchPattern, type AppType, type BindCLIShortcutsOptions, BuildEnvironment, type BuildEnvironmentOptions, type BuildOptions, type BuilderOptions, type CLIShortcut, type CSSModulesOptions, type CSSOptions, type CommonServerOptions, type ConfigEnv, Connect, type CorsOptions, type CorsOrigin, type DepOptimizationConfig, type DepOptimizationMetadata, type DepOptimizationOptions, DevEnvironment, type DevEnvironmentContext, type DevEnvironmentOptions, type ESBuildOptions, type ESBuildTransformResult, type Environment, EnvironmentModuleGraph, EnvironmentModuleNode, type EnvironmentOptions, type ExperimentalOptions, type ExportsData, FSWatcher, type FetchModuleOptions, type FileSystemServeOptions, type FilterPattern, type HMRBroadcaster, type HMRBroadcasterClient, type HMRChannel, type HTMLOptions, type HmrContext, type HmrOptions, type HookHandler, type HotChannel, type HotChannelClient, type HotChannelListener, type HotUpdateOptions, type HtmlTagDescriptor, HttpProxy, type HttpServer, type IndexHtmlTransform, type IndexHtmlTransformContext, type IndexHtmlTransformHook, type IndexHtmlTransformResult, type InlineConfig, type InternalResolveOptions, type JsonOptions, type LegacyOptions, type LessPreprocessorOptions, type LibraryFormats, type LibraryOptions, type LogErrorOptions, type LogLevel, type LogOptions, type LogType, type Logger, type LoggerOptions, type Manifest, type ManifestChunk, type MapToFunction, type AnymatchMatcher as Matcher, ModuleGraph, ModuleNode, type ModulePreloadOptions, type ModuleRunnerTransformOptions, type OptimizedDepInfo, type Plugin, PluginContainer, type PluginHookUtils, type PluginOption, type PreprocessCSSResult, type PreviewOptions, type PreviewServer, type PreviewServerHook, type ProxyOptions, type RenderBuiltAssetUrl, type ResolveFn, type ResolveModulePreloadDependenciesFn, type ResolveOptions, type ResolvedBuildEnvironmentOptions, type ResolvedBuildOptions, type ResolvedCSSOptions, type ResolvedConfig, type ResolvedDevEnvironmentOptions, type ResolvedModulePreloadOptions, type ResolvedPreviewOptions, type ResolvedSSROptions, type ResolvedServerOptions, type ResolvedServerUrls, type ResolvedUrl, type ResolvedWorkerOptions, type ResolverFunction, type ResolverObject, type RollupCommonJSOptions, type RollupDynamicImportVarsOptions, RunnableDevEnvironment, type RunnableDevEnvironmentContext, type SSROptions, type SSRTarget, type SassPreprocessorOptions, type SendOptions, type ServerHMRChannel, type ServerHook, type ServerHotChannel, type ServerModuleRunnerOptions, type ServerOptions, SplitVendorChunkCache, type SsrDepOptimizationConfig, type StylusPreprocessorOptions, Terser, type TerserOptions, type TransformOptions, type TransformResult, type UserConfig, type UserConfigExport, type UserConfigFn, type UserConfigFnObject, type UserConfigFnPromise, type ViteBuilder, type ViteDevServer, type WatchOptions, WebSocket, WebSocketAlias, type WebSocketClient, type WebSocketCustomListener, WebSocketServer, build, buildErrorMessage, createBuilder, createFilter, createIdResolver, createLogger, createRunnableDevEnvironment, createServer, createServerHotChannel, createServerModuleRunner, DEFAULT_CLIENT_CONDITIONS as defaultClientConditions, DEFAULT_CLIENT_MAIN_FIELDS as defaultClientMainFields, DEFAULT_SERVER_CONDITIONS as defaultServerConditions, DEFAULT_SERVER_MAIN_FIELDS as defaultServerMainFields, defineConfig, fetchModule, formatPostcssSourceMap, isCSSRequest, isFileLoadingAllowed, isFileServingAllowed, isRunnableDevEnvironment, loadConfigFromFile, loadEnv, mergeAlias, mergeConfig, ssrTransform as moduleRunnerTransform, normalizePath, optimizeDeps, perEnvironmentPlugin, perEnvironmentState, preprocessCSS, preview, resolveConfig, resolveEnvPrefix, rollupVersion, searchForWorkspaceRoot, send, sortUserPlugins, splitVendorChunk, splitVendorChunkPlugin, transformWithEsbuild, VERSION as version };