vite 2.7.0-beta.1 → 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,7 +575,6 @@ 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
579
  * @default true
522
580
  */
@@ -914,6 +972,7 @@ export declare interface InternalResolveOptions extends ResolveOptions {
914
972
  isBuild: boolean;
915
973
  isProduction: boolean;
916
974
  ssrConfig?: SSROptions;
975
+ packageCache?: PackageCache;
917
976
  /**
918
977
  * src code mode also attempts the following:
919
978
  * - resolving /xxx as URLs
@@ -924,7 +983,10 @@ export declare interface InternalResolveOptions extends ResolveOptions {
924
983
  tryPrefix?: string;
925
984
  skipPackageJson?: boolean;
926
985
  preferRelative?: boolean;
986
+ preserveSymlinks?: boolean;
927
987
  isRequire?: boolean;
988
+ isFromTsImporter?: boolean;
989
+ tryEsmOnly?: boolean;
928
990
  }
929
991
 
930
992
  export declare interface JsonOptions {
@@ -1005,12 +1067,12 @@ export declare type Matcher = AnymatchPattern | AnymatchPattern[]
1005
1067
  export declare function mergeConfig(a: Record<string, any>, b: Record<string, any>, isRoot?: boolean): Record<string, any>;
1006
1068
 
1007
1069
  export declare class ModuleGraph {
1070
+ private resolveId;
1008
1071
  urlToModuleMap: Map<string, ModuleNode>;
1009
1072
  idToModuleMap: Map<string, ModuleNode>;
1010
1073
  fileToModulesMap: Map<string, Set<ModuleNode>>;
1011
1074
  safeModulesPath: Set<string>;
1012
- container: PluginContainer;
1013
- constructor(container: PluginContainer);
1075
+ constructor(resolveId: (url: string) => Promise<PartialResolvedId | null>);
1014
1076
  getModuleByUrl(rawUrl: string): Promise<ModuleNode | undefined>;
1015
1077
  getModuleById(id: string): ModuleNode | undefined;
1016
1078
  getModulesByFile(file: string): Set<ModuleNode> | undefined;
@@ -1025,7 +1087,7 @@ export declare class ModuleGraph {
1025
1087
  updateModuleInfo(mod: ModuleNode, importedModules: Set<string | ModuleNode>, acceptedModules: Set<string | ModuleNode>, isSelfAccepting: boolean): Promise<Set<ModuleNode> | undefined>;
1026
1088
  ensureEntryFromUrl(rawUrl: string): Promise<ModuleNode>;
1027
1089
  createFileOnlyEntry(file: string): ModuleNode;
1028
- resolveUrl(url: string): Promise<[string, string]>;
1090
+ resolveUrl(url: string): Promise<ResolvedUrl>;
1029
1091
  }
1030
1092
 
1031
1093
  export declare class ModuleNode {
@@ -1039,6 +1101,8 @@ export declare class ModuleNode {
1039
1101
  id: string | null;
1040
1102
  file: string | null;
1041
1103
  type: 'js' | 'css';
1104
+ info?: ModuleInfo;
1105
+ meta?: Record<string, any>;
1042
1106
  importers: Set<ModuleNode>;
1043
1107
  importedModules: Set<ModuleNode>;
1044
1108
  acceptedHmrDeps: Set<ModuleNode>;
@@ -1055,9 +1119,12 @@ export declare function normalizePath(id: string): string;
1055
1119
  export declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean, newDeps?: Record<string, string>, // missing imports encountered after server has started
1056
1120
  ssr?: boolean): Promise<DepOptimizationMetadata | null>;
1057
1121
 
1122
+ /** Cache for package.json resolution and package.json contents */
1123
+ export declare type PackageCache = Map<string, PackageData>;
1124
+
1058
1125
  export declare interface PackageData {
1059
1126
  dir: string;
1060
- hasSideEffects: (id: string) => boolean;
1127
+ hasSideEffects: (id: string) => boolean | 'no-treeshake';
1061
1128
  webResolvedImports: Record<string, string | undefined>;
1062
1129
  nodeResolvedImports: Record<string, string | undefined>;
1063
1130
  setResolvedCache: (key: string, entry: string, targetWeb: boolean) => void;
@@ -1184,6 +1251,7 @@ export declare interface Plugin extends Plugin_2 {
1184
1251
 
1185
1252
  export declare interface PluginContainer {
1186
1253
  options: InputOptions;
1254
+ getModuleInfo(id: string): ModuleInfo | null;
1187
1255
  buildStart(options: InputOptions): Promise<void>;
1188
1256
  resolveId(id: string, importer?: string, options?: {
1189
1257
  skip?: Set<Plugin>;
@@ -1209,6 +1277,9 @@ export declare type PluginOption = Plugin | false | null | undefined;
1209
1277
  */
1210
1278
  export declare function preview(inlineConfig: InlineConfig): Promise<PreviewServer>;
1211
1279
 
1280
+ export declare interface PreviewOptions extends CommonServerOptions {
1281
+ }
1282
+
1212
1283
  export declare interface PreviewServer {
1213
1284
  /**
1214
1285
  * The resolved vite config object
@@ -1224,7 +1295,10 @@ export declare interface PreviewServer {
1224
1295
  printUrls: () => void;
1225
1296
  }
1226
1297
 
1227
- export declare function printHttpServerUrls(server: Server_3, config: ResolvedConfig): void;
1298
+ /**
1299
+ * @deprecated Use `server.printUrls()` instead
1300
+ */
1301
+ export declare function printHttpServerUrls(server: Server_2, config: ResolvedConfig): void;
1228
1302
 
1229
1303
  export declare interface ProxyOptions extends HttpProxy.ServerOptions {
1230
1304
  /**
@@ -1267,16 +1341,27 @@ export declare type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'alia
1267
1341
  plugins: readonly Plugin[];
1268
1342
  server: ResolvedServerOptions;
1269
1343
  build: ResolvedBuildOptions;
1344
+ preview: ResolvedPreviewOptions;
1270
1345
  assetsInclude: (file: string) => boolean;
1271
1346
  logger: Logger;
1272
1347
  createResolver: (options?: Partial<InternalResolveOptions>) => ResolveFn;
1273
1348
  optimizeDeps: Omit<DepOptimizationOptions, 'keepNames'>;
1349
+ /* Excluded from this release type: packageCache */
1274
1350
  }>;
1275
1351
 
1352
+ export declare interface ResolvedPreviewOptions extends PreviewOptions {
1353
+ }
1354
+
1276
1355
  export declare interface ResolvedServerOptions extends ServerOptions {
1277
1356
  fs: Required<FileSystemServeOptions>;
1278
1357
  }
1279
1358
 
1359
+ export declare type ResolvedUrl = [
1360
+ url: string,
1361
+ resolvedId: string,
1362
+ meta: object | null | undefined
1363
+ ];
1364
+
1280
1365
  export declare function resolveEnvPrefix({ envPrefix }: UserConfig): string[];
1281
1366
 
1282
1367
  export declare type ResolveFn = (id: string, importer?: string, aliasOnly?: boolean, ssr?: boolean) => Promise<string | undefined>;
@@ -1289,9 +1374,9 @@ export declare interface ResolveOptions {
1289
1374
  preserveSymlinks?: boolean;
1290
1375
  }
1291
1376
 
1292
- 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;
1293
1378
 
1294
- 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;
1295
1380
 
1296
1381
  export declare type ResolverFunction = PluginHooks['resolveId']
1297
1382
 
@@ -1309,7 +1394,7 @@ export declare interface ResolverObject {
1309
1394
  */
1310
1395
  export declare interface RollupCommonJSOptions {
1311
1396
  /**
1312
- * 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
1313
1398
  * the build the plugin should operate on. By default, all files with
1314
1399
  * extension `".cjs"` or those in `extensions` are included, but you can narrow
1315
1400
  * this list by only including specific files. These files will be analyzed
@@ -1319,7 +1404,7 @@ export declare interface RollupCommonJSOptions {
1319
1404
  */
1320
1405
  include?: string | RegExp | readonly (string | RegExp)[]
1321
1406
  /**
1322
- * 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
1323
1408
  * the build the plugin should _ignore_. By default, all files with
1324
1409
  * extensions other than those in `extensions` or `".cjs"` are ignored, but you
1325
1410
  * can exclude additional files. See also the `include` option.
@@ -1373,6 +1458,26 @@ export declare interface RollupCommonJSOptions {
1373
1458
  * @default []
1374
1459
  */
1375
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')
1376
1481
  /**
1377
1482
  * Controls how to render imports from external dependencies. By default,
1378
1483
  * this plugin assumes that all external dependencies are CommonJS. This
@@ -1490,52 +1595,7 @@ export declare function send(req: IncomingMessage, res: ServerResponse, content:
1490
1595
 
1491
1596
  export declare type ServerHook = (server: ViteDevServer) => (() => void) | void | Promise<(() => void) | void>;
1492
1597
 
1493
- export declare interface ServerOptions {
1494
- host?: string | boolean;
1495
- port?: number;
1496
- /**
1497
- * If enabled, vite will exit if specified port is already in use
1498
- */
1499
- strictPort?: boolean;
1500
- /**
1501
- * Enable TLS + HTTP/2.
1502
- * Note: this downgrades to TLS only when the proxy option is also used.
1503
- */
1504
- https?: boolean | https.ServerOptions;
1505
- /**
1506
- * Open browser window on startup
1507
- */
1508
- open?: boolean | string;
1509
- /**
1510
- * Configure custom proxy rules for the dev server. Expects an object
1511
- * of `{ key: options }` pairs.
1512
- * Uses [`http-proxy`](https://github.com/http-party/node-http-proxy).
1513
- * Full options [here](https://github.com/http-party/node-http-proxy#options).
1514
- *
1515
- * Example `vite.config.js`:
1516
- * ``` js
1517
- * module.exports = {
1518
- * proxy: {
1519
- * // string shorthand
1520
- * '/foo': 'http://localhost:4567/foo',
1521
- * // with options
1522
- * '/api': {
1523
- * target: 'http://jsonplaceholder.typicode.com',
1524
- * changeOrigin: true,
1525
- * rewrite: path => path.replace(/^\/api/, '')
1526
- * }
1527
- * }
1528
- * }
1529
- * ```
1530
- */
1531
- proxy?: Record<string, string | ProxyOptions>;
1532
- /**
1533
- * Configure CORS for the dev server.
1534
- * Uses https://github.com/expressjs/cors.
1535
- * Set to `true` to allow all methods from any origin, or configure separately
1536
- * using an object.
1537
- */
1538
- cors?: CorsOptions | boolean;
1598
+ export declare interface ServerOptions extends CommonServerOptions {
1539
1599
  /**
1540
1600
  * Force dep pre-optimization regardless of whether deps have changed.
1541
1601
  */
@@ -1859,6 +1919,10 @@ export declare interface UserConfig {
1859
1919
  * Build specific options
1860
1920
  */
1861
1921
  build?: BuildOptions;
1922
+ /**
1923
+ * Preview specific options, e.g. host, port, https...
1924
+ */
1925
+ preview?: PreviewOptions;
1862
1926
  /**
1863
1927
  * Dep optimization options
1864
1928
  */
@@ -1982,9 +2046,17 @@ export declare interface ViteDevServer {
1982
2046
  * Print server urls
1983
2047
  */
1984
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>;
1985
2055
  /* Excluded from this release type: _optimizeDepsMetadata */
1986
2056
  /* Excluded from this release type: _ssrExternals */
1987
2057
  /* Excluded from this release type: _globImporters */
2058
+ /* Excluded from this release type: _restartPromise */
2059
+ /* Excluded from this release type: _forceOptimizeOnRestart */
1988
2060
  /* Excluded from this release type: _isRunningOptimizer */
1989
2061
  /* Excluded from this release type: _registerMissingImport */
1990
2062
  /* Excluded from this release type: _pendingReload */
@@ -2491,7 +2563,7 @@ export declare namespace WebSocket {
2491
2563
  host?: string | undefined
2492
2564
  port?: number | undefined
2493
2565
  backlog?: number | undefined
2494
- server?: Server | Server_2 | undefined
2566
+ server?: Server | Server_3 | undefined
2495
2567
  verifyClient?:
2496
2568
  | VerifyClientCallbackAsync
2497
2569
  | VerifyClientCallbackSync
@@ -2607,8 +2679,8 @@ export declare namespace WebSocket {
2607
2679
  }
2608
2680
 
2609
2681
  export declare interface WebSocketServer {
2610
- on: WebSocket.Server['on'];
2611
- off: WebSocket.Server['off'];
2682
+ on: WebSocketServer_2['on'];
2683
+ off: WebSocketServer_2['off'];
2612
2684
  send(payload: HMRPayload): void;
2613
2685
  close(): Promise<void>;
2614
2686
  }
@@ -2,31 +2,31 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var build = require('./chunks/dep-966eddc9.js');
6
- require('path');
5
+ var build = require('./chunks/dep-e6ce7715.js');
7
6
  require('fs');
8
- require('querystring');
7
+ require('path');
8
+ require('os');
9
9
  require('tty');
10
10
  require('util');
11
11
  require('net');
12
12
  require('events');
13
13
  require('url');
14
14
  require('http');
15
- require('buffer');
16
- require('zlib');
17
- require('os');
15
+ require('stream');
18
16
  require('resolve');
19
17
  require('module');
20
18
  require('perf_hooks');
21
- require('readline');
22
- require('crypto');
23
- require('stream');
24
- require('esbuild');
25
- require('worker_threads');
26
- require('assert');
27
19
  require('https');
20
+ require('zlib');
21
+ require('crypto');
28
22
  require('tls');
23
+ require('assert');
24
+ require('buffer');
25
+ require('querystring');
26
+ require('esbuild');
29
27
  require('child_process');
28
+ require('worker_threads');
29
+ require('readline');
30
30
 
31
31
 
32
32