vite 2.6.13 → 2.7.0-beta.10

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.

@@ -12,11 +12,11 @@ import { EventEmitter } from 'events';
12
12
  import * as events from 'events';
13
13
  import * as fs from 'fs';
14
14
  import * as http from 'http';
15
- import * as https from 'https';
16
15
  import { IncomingMessage } from 'http';
17
16
  import { InputOptions } from 'rollup';
18
17
  import { LoadResult } from 'rollup';
19
18
  import { ModuleFormat } from 'rollup';
19
+ import { ModuleInfo } from 'rollup';
20
20
  import * as net from 'net';
21
21
  import { OutgoingHttpHeaders } from 'http';
22
22
  import { OutputBundle } from 'rollup';
@@ -33,8 +33,9 @@ import { RollupOutput } from 'rollup';
33
33
  import { RollupWatcher } from 'rollup';
34
34
  import { SecureContextOptions } from 'tls';
35
35
  import { Server } from 'http';
36
- import { Server as Server_2 } from 'https';
37
- import { Server as Server_3 } from 'net';
36
+ import { Server as Server_2 } from 'net';
37
+ import { Server as Server_3 } from 'https';
38
+ import { ServerOptions as ServerOptions_2 } from 'https';
38
39
  import { ServerResponse } from 'http';
39
40
  import { Socket } from 'net';
40
41
  import { SourceDescription } from 'rollup';
@@ -46,6 +47,7 @@ import { TransformResult as TransformResult_3 } from 'rollup';
46
47
  import { URL } from 'url';
47
48
  import * as url from 'url';
48
49
  import { WatcherOptions } from 'rollup';
50
+ import { WebSocketServer as WebSocketServer_2 } from 'ws';
49
51
  import { ZlibOptions } from 'zlib';
50
52
 
51
53
  export declare interface Alias {
@@ -255,6 +257,63 @@ export declare interface BuildOptions {
255
257
  watch?: WatcherOptions | null;
256
258
  }
257
259
 
260
+ export declare interface CommonServerOptions {
261
+ /**
262
+ * Specify server port. Note if the port is already being used, Vite will
263
+ * automatically try the next available port so this may not be the actual
264
+ * port the server ends up listening on.
265
+ */
266
+ port?: number;
267
+ /**
268
+ * If enabled, vite will exit if specified port is already in use
269
+ */
270
+ strictPort?: boolean;
271
+ /**
272
+ * Specify which IP addresses the server should listen on.
273
+ * Set to 0.0.0.0 to listen on all addresses, including LAN and public addresses.
274
+ */
275
+ host?: string | boolean;
276
+ /**
277
+ * Enable TLS + HTTP/2.
278
+ * Note: this downgrades to TLS only when the proxy option is also used.
279
+ */
280
+ https?: boolean | ServerOptions_2;
281
+ /**
282
+ * Open browser window on startup
283
+ */
284
+ open?: boolean | string;
285
+ /**
286
+ * Configure custom proxy rules for the dev server. Expects an object
287
+ * of `{ key: options }` pairs.
288
+ * Uses [`http-proxy`](https://github.com/http-party/node-http-proxy).
289
+ * Full options [here](https://github.com/http-party/node-http-proxy#options).
290
+ *
291
+ * Example `vite.config.js`:
292
+ * ``` js
293
+ * module.exports = {
294
+ * proxy: {
295
+ * // string shorthand
296
+ * '/foo': 'http://localhost:4567/foo',
297
+ * // with options
298
+ * '/api': {
299
+ * target: 'http://jsonplaceholder.typicode.com',
300
+ * changeOrigin: true,
301
+ * rewrite: path => path.replace(/^\/api/, '')
302
+ * }
303
+ * }
304
+ * }
305
+ * ```
306
+ */
307
+ proxy?: Record<string, string | ProxyOptions>;
308
+ /**
309
+ * Configure CORS for the dev server.
310
+ * Uses https://github.com/expressjs/cors.
311
+ * Set to `true` to allow all methods from any origin, or configure separately
312
+ * using an object.
313
+ */
314
+ cors?: CorsOptions | boolean;
315
+ }
316
+
258
317
  export declare interface ConfigEnv {
259
318
  command: 'build' | 'serve';
260
319
  mode: string;
@@ -516,21 +575,28 @@ export declare interface FileSystemServeOptions {
516
575
  * Strictly restrict file accessing outside of allowing paths.
517
576
  *
518
577
  * Set to `false` to disable the warning
519
- * Default to false at this moment, will enabled by default in the future versions.
520
578
  *
521
- * @experimental
522
- * @default undefined
579
+ * @default true
523
580
  */
524
- strict?: boolean | undefined;
581
+ strict?: boolean;
525
582
  /**
526
583
  * Restrict accessing files outside the allowed directories.
527
584
  *
528
585
  * Accepts absolute path or a path relative to project root.
529
586
  * Will try to search up for workspace root by default.
587
+ */
588
+ allow?: string[];
589
+ /**
590
+ * Restrict accessing files that matches the patterns.
591
+ *
592
+ * This will have higher priority than `allow`.
593
+ * Glob patterns are supported.
594
+ *
595
+ * @default ['.env', '.env.*', '*.crt', '*.pem']
530
596
  *
531
597
  * @experimental
532
598
  */
533
- allow?: string[];
599
+ deny?: string[];
534
600
  }
535
601
 
536
602
  export declare interface FSWatcher extends fs.FSWatcher {
@@ -906,6 +972,7 @@ export declare interface InternalResolveOptions extends ResolveOptions {
906
972
  isBuild: boolean;
907
973
  isProduction: boolean;
908
974
  ssrConfig?: SSROptions;
975
+ packageCache?: PackageCache;
909
976
  /**
910
977
  * src code mode also attempts the following:
911
978
  * - resolving /xxx as URLs
@@ -916,7 +983,10 @@ export declare interface InternalResolveOptions extends ResolveOptions {
916
983
  tryPrefix?: string;
917
984
  skipPackageJson?: boolean;
918
985
  preferRelative?: boolean;
986
+ preserveSymlinks?: boolean;
919
987
  isRequire?: boolean;
988
+ isFromTsImporter?: boolean;
989
+ tryEsmOnly?: boolean;
920
990
  }
921
991
 
922
992
  export declare interface JsonOptions {
@@ -997,12 +1067,12 @@ export declare type Matcher = AnymatchPattern | AnymatchPattern[]
997
1067
  export declare function mergeConfig(a: Record<string, any>, b: Record<string, any>, isRoot?: boolean): Record<string, any>;
998
1068
 
999
1069
  export declare class ModuleGraph {
1070
+ private resolveId;
1000
1071
  urlToModuleMap: Map<string, ModuleNode>;
1001
1072
  idToModuleMap: Map<string, ModuleNode>;
1002
1073
  fileToModulesMap: Map<string, Set<ModuleNode>>;
1003
1074
  safeModulesPath: Set<string>;
1004
- container: PluginContainer;
1005
- constructor(container: PluginContainer);
1075
+ constructor(resolveId: (url: string) => Promise<PartialResolvedId | null>);
1006
1076
  getModuleByUrl(rawUrl: string): Promise<ModuleNode | undefined>;
1007
1077
  getModuleById(id: string): ModuleNode | undefined;
1008
1078
  getModulesByFile(file: string): Set<ModuleNode> | undefined;
@@ -1017,7 +1087,7 @@ export declare class ModuleGraph {
1017
1087
  updateModuleInfo(mod: ModuleNode, importedModules: Set<string | ModuleNode>, acceptedModules: Set<string | ModuleNode>, isSelfAccepting: boolean): Promise<Set<ModuleNode> | undefined>;
1018
1088
  ensureEntryFromUrl(rawUrl: string): Promise<ModuleNode>;
1019
1089
  createFileOnlyEntry(file: string): ModuleNode;
1020
- resolveUrl(url: string): Promise<[string, string]>;
1090
+ resolveUrl(url: string): Promise<ResolvedUrl>;
1021
1091
  }
1022
1092
 
1023
1093
  export declare class ModuleNode {
@@ -1031,6 +1101,8 @@ export declare class ModuleNode {
1031
1101
  id: string | null;
1032
1102
  file: string | null;
1033
1103
  type: 'js' | 'css';
1104
+ info?: ModuleInfo;
1105
+ meta?: Record<string, any>;
1034
1106
  importers: Set<ModuleNode>;
1035
1107
  importedModules: Set<ModuleNode>;
1036
1108
  acceptedHmrDeps: Set<ModuleNode>;
@@ -1047,9 +1119,12 @@ export declare function normalizePath(id: string): string;
1047
1119
  export declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean, newDeps?: Record<string, string>, // missing imports encountered after server has started
1048
1120
  ssr?: boolean): Promise<DepOptimizationMetadata | null>;
1049
1121
 
1122
+ /** Cache for package.json resolution and package.json contents */
1123
+ export declare type PackageCache = Map<string, PackageData>;
1124
+
1050
1125
  export declare interface PackageData {
1051
1126
  dir: string;
1052
- hasSideEffects: (id: string) => boolean;
1127
+ hasSideEffects: (id: string) => boolean | 'no-treeshake';
1053
1128
  webResolvedImports: Record<string, string | undefined>;
1054
1129
  nodeResolvedImports: Record<string, string | undefined>;
1055
1130
  setResolvedCache: (key: string, entry: string, targetWeb: boolean) => void;
@@ -1164,17 +1239,31 @@ export declare interface Plugin extends Plugin_2 {
1164
1239
  */
1165
1240
  resolveId?(this: PluginContext, source: string, importer: string | undefined, options: {
1166
1241
  custom?: CustomPluginOptions;
1167
- }, ssr?: boolean): Promise<ResolveIdResult> | ResolveIdResult;
1168
- load?(this: PluginContext, id: string, ssr?: boolean): Promise<LoadResult> | LoadResult;
1169
- transform?(this: TransformPluginContext, code: string, id: string, ssr?: boolean): Promise<TransformResult_3> | TransformResult_3;
1242
+ ssr?: boolean;
1243
+ }): Promise<ResolveIdResult> | ResolveIdResult;
1244
+ load?(this: PluginContext, id: string, options?: {
1245
+ ssr?: boolean;
1246
+ }): Promise<LoadResult> | LoadResult;
1247
+ transform?(this: TransformPluginContext, code: string, id: string, options?: {
1248
+ ssr?: boolean;
1249
+ }): Promise<TransformResult_3> | TransformResult_3;
1170
1250
  }
1171
1251
 
1172
1252
  export declare interface PluginContainer {
1173
1253
  options: InputOptions;
1254
+ getModuleInfo(id: string): ModuleInfo | null;
1174
1255
  buildStart(options: InputOptions): Promise<void>;
1175
- resolveId(id: string, importer?: string, skip?: Set<Plugin>, ssr?: boolean): Promise<PartialResolvedId | null>;
1176
- transform(code: string, id: string, inMap?: SourceDescription['map'], ssr?: boolean): Promise<SourceDescription | null>;
1177
- load(id: string, ssr?: boolean): Promise<LoadResult | null>;
1256
+ resolveId(id: string, importer?: string, options?: {
1257
+ skip?: Set<Plugin>;
1258
+ ssr?: boolean;
1259
+ }): Promise<PartialResolvedId | null>;
1260
+ transform(code: string, id: string, options?: {
1261
+ inMap?: SourceDescription['map'];
1262
+ ssr?: boolean;
1263
+ }): Promise<SourceDescription | null>;
1264
+ load(id: string, options?: {
1265
+ ssr?: boolean;
1266
+ }): Promise<LoadResult | null>;
1178
1267
  close(): Promise<void>;
1179
1268
  }
1180
1269
 
@@ -1186,9 +1275,30 @@ export declare type PluginOption = Plugin | false | null | undefined;
1186
1275
  * @param serverOptions - what host and port to use
1187
1276
  * @experimental
1188
1277
  */
1189
- export declare function preview(config: ResolvedConfig, serverOptions: Pick<ServerOptions, 'port' | 'host'>): Promise<Server>;
1278
+ export declare function preview(inlineConfig: InlineConfig): Promise<PreviewServer>;
1190
1279
 
1191
- export declare function printHttpServerUrls(server: Server_3, config: ResolvedConfig): void;
1280
+ export declare interface PreviewOptions extends CommonServerOptions {
1281
+ }
1282
+
1283
+ export declare interface PreviewServer {
1284
+ /**
1285
+ * The resolved vite config object
1286
+ */
1287
+ config: ResolvedConfig;
1288
+ /**
1289
+ * native Node http server instance
1290
+ */
1291
+ httpServer: Server;
1292
+ /**
1293
+ * Print server urls
1294
+ */
1295
+ printUrls: () => void;
1296
+ }
1297
+
1298
+ /**
1299
+ * @deprecated Use `server.printUrls()` instead
1300
+ */
1301
+ export declare function printHttpServerUrls(server: Server_2, config: ResolvedConfig): void;
1192
1302
 
1193
1303
  export declare interface ProxyOptions extends HttpProxy.ServerOptions {
1194
1304
  /**
@@ -1231,16 +1341,27 @@ export declare type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'alia
1231
1341
  plugins: readonly Plugin[];
1232
1342
  server: ResolvedServerOptions;
1233
1343
  build: ResolvedBuildOptions;
1344
+ preview: ResolvedPreviewOptions;
1234
1345
  assetsInclude: (file: string) => boolean;
1235
1346
  logger: Logger;
1236
1347
  createResolver: (options?: Partial<InternalResolveOptions>) => ResolveFn;
1237
1348
  optimizeDeps: Omit<DepOptimizationOptions, 'keepNames'>;
1349
+ /* Excluded from this release type: packageCache */
1238
1350
  }>;
1239
1351
 
1352
+ export declare interface ResolvedPreviewOptions extends PreviewOptions {
1353
+ }
1354
+
1240
1355
  export declare interface ResolvedServerOptions extends ServerOptions {
1241
1356
  fs: Required<FileSystemServeOptions>;
1242
1357
  }
1243
1358
 
1359
+ export declare type ResolvedUrl = [
1360
+ url: string,
1361
+ resolvedId: string,
1362
+ meta: object | null | undefined
1363
+ ];
1364
+
1244
1365
  export declare function resolveEnvPrefix({ envPrefix }: UserConfig): string[];
1245
1366
 
1246
1367
  export declare type ResolveFn = (id: string, importer?: string, aliasOnly?: boolean, ssr?: boolean) => Promise<string | undefined>;
@@ -1253,9 +1374,9 @@ export declare interface ResolveOptions {
1253
1374
  preserveSymlinks?: boolean;
1254
1375
  }
1255
1376
 
1256
- export declare function resolvePackageData(id: string, basedir: string, preserveSymlinks?: boolean): PackageData | undefined;
1377
+ export declare function resolvePackageData(id: string, basedir: string, preserveSymlinks?: boolean, packageCache?: PackageCache): PackageData | null;
1257
1378
 
1258
- export declare function resolvePackageEntry(id: string, { dir, data, setResolvedCache, getResolvedCache }: PackageData, options: InternalResolveOptions, targetWeb: boolean, preserveSymlinks?: boolean): string | undefined;
1379
+ export declare function resolvePackageEntry(id: string, { dir, data, setResolvedCache, getResolvedCache }: PackageData, targetWeb: boolean, options: InternalResolveOptions): string | undefined;
1259
1380
 
1260
1381
  export declare type ResolverFunction = PluginHooks['resolveId']
1261
1382
 
@@ -1273,7 +1394,7 @@ export declare interface ResolverObject {
1273
1394
  */
1274
1395
  export declare interface RollupCommonJSOptions {
1275
1396
  /**
1276
- * A minimatch pattern, or array of patterns, which specifies the files in
1397
+ * A picomatch pattern, or array of patterns, which specifies the files in
1277
1398
  * the build the plugin should operate on. By default, all files with
1278
1399
  * extension `".cjs"` or those in `extensions` are included, but you can narrow
1279
1400
  * this list by only including specific files. These files will be analyzed
@@ -1283,7 +1404,7 @@ export declare interface RollupCommonJSOptions {
1283
1404
  */
1284
1405
  include?: string | RegExp | readonly (string | RegExp)[]
1285
1406
  /**
1286
- * A minimatch pattern, or array of patterns, which specifies the files in
1407
+ * A picomatch pattern, or array of patterns, which specifies the files in
1287
1408
  * the build the plugin should _ignore_. By default, all files with
1288
1409
  * extensions other than those in `extensions` or `".cjs"` are ignored, but you
1289
1410
  * can exclude additional files. See also the `include` option.
@@ -1337,6 +1458,26 @@ export declare interface RollupCommonJSOptions {
1337
1458
  * @default []
1338
1459
  */
1339
1460
  ignore?: ReadonlyArray<string> | ((id: string) => boolean)
1461
+ /**
1462
+ * In most cases, where `require` calls are inside a `try-catch` clause,
1463
+ * they should be left unconverted as it requires an optional dependency
1464
+ * that may or may not be installed beside the rolled up package.
1465
+ * Due to the conversion of `require` to a static `import` - the call is hoisted
1466
+ * to the top of the file, outside of the `try-catch` clause.
1467
+ *
1468
+ * - `true`: All `require` calls inside a `try` will be left unconverted.
1469
+ * - `false`: All `require` calls inside a `try` will be converted as if the `try-catch` clause is not there.
1470
+ * - `remove`: Remove all `require` calls from inside any `try` block.
1471
+ * - `string[]`: Pass an array containing the IDs to left unconverted.
1472
+ * - `((id: string) => boolean|'remove')`: Pass a function that control individual IDs.
1473
+ *
1474
+ * @default false
1475
+ */
1476
+ ignoreTryCatch?:
1477
+ | boolean
1478
+ | 'remove'
1479
+ | ReadonlyArray<string>
1480
+ | ((id: string) => boolean | 'remove')
1340
1481
  /**
1341
1482
  * Controls how to render imports from external dependencies. By default,
1342
1483
  * this plugin assumes that all external dependencies are CommonJS. This
@@ -1454,18 +1595,7 @@ export declare function send(req: IncomingMessage, res: ServerResponse, content:
1454
1595
 
1455
1596
  export declare type ServerHook = (server: ViteDevServer) => (() => void) | void | Promise<(() => void) | void>;
1456
1597
 
1457
- export declare interface ServerOptions {
1458
- host?: string | boolean;
1459
- port?: number;
1460
- /**
1461
- * Enable TLS + HTTP/2.
1462
- * Note: this downgrades to TLS only when the proxy option is also used.
1463
- */
1464
- https?: boolean | https.ServerOptions;
1465
- /**
1466
- * Open browser window on startup
1467
- */
1468
- open?: boolean | string;
1598
+ export declare interface ServerOptions extends CommonServerOptions {
1469
1599
  /**
1470
1600
  * Force dep pre-optimization regardless of whether deps have changed.
1471
1601
  */
@@ -1479,40 +1609,6 @@ export declare interface ServerOptions {
1479
1609
  * https://github.com/paulmillr/chokidar#api
1480
1610
  */
1481
1611
  watch?: WatchOptions;
1482
- /**
1483
- * Configure custom proxy rules for the dev server. Expects an object
1484
- * of `{ key: options }` pairs.
1485
- * Uses [`http-proxy`](https://github.com/http-party/node-http-proxy).
1486
- * Full options [here](https://github.com/http-party/node-http-proxy#options).
1487
- *
1488
- * Example `vite.config.js`:
1489
- * ``` js
1490
- * module.exports = {
1491
- * proxy: {
1492
- * // string shorthand
1493
- * '/foo': 'http://localhost:4567/foo',
1494
- * // with options
1495
- * '/api': {
1496
- * target: 'http://jsonplaceholder.typicode.com',
1497
- * changeOrigin: true,
1498
- * rewrite: path => path.replace(/^\/api/, '')
1499
- * }
1500
- * }
1501
- * }
1502
- * ```
1503
- */
1504
- proxy?: Record<string, string | ProxyOptions>;
1505
- /**
1506
- * Configure CORS for the dev server.
1507
- * Uses https://github.com/expressjs/cors.
1508
- * Set to `true` to allow all methods from any origin, or configure separately
1509
- * using an object.
1510
- */
1511
- cors?: CorsOptions | boolean;
1512
- /**
1513
- * If enabled, vite will exit if specified port is already in use
1514
- */
1515
- strictPort?: boolean;
1516
1612
  /**
1517
1613
  * Create Vite dev server to be used as a middleware in an existing server
1518
1614
  */
@@ -1823,6 +1919,10 @@ export declare interface UserConfig {
1823
1919
  * Build specific options
1824
1920
  */
1825
1921
  build?: BuildOptions;
1922
+ /**
1923
+ * Preview specific options, e.g. host, port, https...
1924
+ */
1925
+ preview?: PreviewOptions;
1826
1926
  /**
1827
1927
  * Dep optimization options
1828
1928
  */
@@ -1946,9 +2046,17 @@ export declare interface ViteDevServer {
1946
2046
  * Print server urls
1947
2047
  */
1948
2048
  printUrls(): void;
2049
+ /**
2050
+ * Restart the server.
2051
+ *
2052
+ * @param forceOptimize - force the optimizer to re-bundle, same as --force cli flag
2053
+ */
2054
+ restart(forceOptimize?: boolean): Promise<void>;
1949
2055
  /* Excluded from this release type: _optimizeDepsMetadata */
1950
2056
  /* Excluded from this release type: _ssrExternals */
1951
2057
  /* Excluded from this release type: _globImporters */
2058
+ /* Excluded from this release type: _restartPromise */
2059
+ /* Excluded from this release type: _forceOptimizeOnRestart */
1952
2060
  /* Excluded from this release type: _isRunningOptimizer */
1953
2061
  /* Excluded from this release type: _registerMissingImport */
1954
2062
  /* Excluded from this release type: _pendingReload */
@@ -2455,7 +2563,7 @@ export declare namespace WebSocket {
2455
2563
  host?: string | undefined
2456
2564
  port?: number | undefined
2457
2565
  backlog?: number | undefined
2458
- server?: Server | Server_2 | undefined
2566
+ server?: Server | Server_3 | undefined
2459
2567
  verifyClient?:
2460
2568
  | VerifyClientCallbackAsync
2461
2569
  | VerifyClientCallbackSync
@@ -2571,8 +2679,8 @@ export declare namespace WebSocket {
2571
2679
  }
2572
2680
 
2573
2681
  export declare interface WebSocketServer {
2574
- on: WebSocket.Server['on'];
2575
- off: WebSocket.Server['off'];
2682
+ on: WebSocketServer_2['on'];
2683
+ off: WebSocketServer_2['off'];
2576
2684
  send(payload: HMRPayload): void;
2577
2685
  close(): Promise<void>;
2578
2686
  }
@@ -2,31 +2,31 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var build = require('./chunks/dep-85dbaaa7.js');
5
+ var build = require('./chunks/dep-e6ce7715.js');
6
6
  require('fs');
7
7
  require('path');
8
- require('events');
8
+ require('os');
9
+ require('tty');
9
10
  require('util');
11
+ require('net');
12
+ require('events');
13
+ require('url');
14
+ require('http');
10
15
  require('stream');
11
- require('os');
16
+ require('resolve');
17
+ require('module');
12
18
  require('perf_hooks');
13
- require('url');
19
+ require('https');
20
+ require('zlib');
14
21
  require('crypto');
15
- require('module');
16
- require('esbuild');
17
- require('worker_threads');
22
+ require('tls');
18
23
  require('assert');
24
+ require('buffer');
25
+ require('querystring');
26
+ require('esbuild');
19
27
  require('child_process');
28
+ require('worker_threads');
20
29
  require('readline');
21
- require('zlib');
22
- require('resolve');
23
- require('querystring');
24
- require('tty');
25
- require('net');
26
- require('http');
27
- require('buffer');
28
- require('https');
29
- require('tls');
30
30
 
31
31
 
32
32