vite 3.0.7 → 3.1.0-beta.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.
@@ -21,6 +21,7 @@ import type { LoadResult } from 'rollup';
21
21
  import type { ModuleFormat } from 'rollup';
22
22
  import type { ModuleInfo } from 'rollup';
23
23
  import type * as net from 'node:net';
24
+ import type { ObjectHook } from 'rollup';
24
25
  import type { OutgoingHttpHeaders } from 'node:http';
25
26
  import type { OutputBundle } from 'rollup';
26
27
  import type { OutputChunk } from 'rollup';
@@ -846,6 +847,8 @@ export declare type HMRPayload =
846
847
  | ErrorPayload
847
848
  | PrunePayload
848
849
 
850
+ export declare type HookHandler<T> = T extends ObjectHook<infer H> ? H : T;
851
+
849
852
  export declare interface HtmlTagDescriptor {
850
853
  tag: string;
851
854
  attrs?: Record<string, string | boolean | undefined>;
@@ -894,7 +897,7 @@ export declare namespace HttpProxy {
894
897
  * Used for proxying regular HTTP(S) requests
895
898
  * @param req - Client request.
896
899
  * @param res - Client response.
897
- * @param options - Additionnal options.
900
+ * @param options - Additional options.
898
901
  */
899
902
  web(
900
903
  req: http.IncomingMessage,
@@ -1088,7 +1091,9 @@ export declare namespace HttpProxy {
1088
1091
 
1089
1092
  export declare interface ImportGlobEagerFunction {
1090
1093
  /**
1091
- * 1. No generic provided, infer the type from `as`
1094
+ * Eagerly import a list of files with a glob pattern.
1095
+ *
1096
+ * Overload 1: No generic provided, infer the type from `as`
1092
1097
  */
1093
1098
  <
1094
1099
  As extends string,
@@ -1098,7 +1103,9 @@ export declare interface ImportGlobEagerFunction {
1098
1103
  options?: Omit<ImportGlobOptions<boolean, As>, 'eager'>
1099
1104
  ): Record<string, T>
1100
1105
  /**
1101
- * 2. Module generic provided
1106
+ * Eagerly import a list of files with a glob pattern.
1107
+ *
1108
+ * Overload 2: Module generic provided
1102
1109
  */
1103
1110
  <M>(
1104
1111
  glob: string | string[],
@@ -1108,7 +1115,9 @@ export declare interface ImportGlobEagerFunction {
1108
1115
 
1109
1116
  export declare interface ImportGlobFunction {
1110
1117
  /**
1111
- * 1. No generic provided, infer the type from `eager` and `as`
1118
+ * Import a list of files with a glob pattern.
1119
+ *
1120
+ * Overload 1: No generic provided, infer the type from `eager` and `as`
1112
1121
  */
1113
1122
  <
1114
1123
  Eager extends boolean,
@@ -1121,14 +1130,18 @@ export declare interface ImportGlobFunction {
1121
1130
  ? Record<string, T>
1122
1131
  : Record<string, () => Promise<T>>
1123
1132
  /**
1124
- * 2. Module generic provided, infer the type from `eager: false`
1133
+ * Import a list of files with a glob pattern.
1134
+ *
1135
+ * Overload 2: Module generic provided, infer the type from `eager: false`
1125
1136
  */
1126
1137
  <M>(
1127
1138
  glob: string | string[],
1128
1139
  options?: ImportGlobOptions<false, string>
1129
1140
  ): Record<string, () => Promise<M>>
1130
1141
  /**
1131
- * 3. Module generic provided, infer the type from `eager: true`
1142
+ * Import a list of files with a glob pattern.
1143
+ *
1144
+ * Overload 3: Module generic provided, infer the type from `eager: true`
1132
1145
  */
1133
1146
  <M>(
1134
1147
  glob: string | string[],
@@ -1493,11 +1506,11 @@ declare interface Plugin_2 extends Plugin_3 {
1493
1506
  * Note: User plugins are resolved before running this hook so injecting other
1494
1507
  * plugins inside the `config` hook will have no effect.
1495
1508
  */
1496
- config?: (config: UserConfig, env: ConfigEnv) => UserConfig | null | void | Promise<UserConfig | null | void>;
1509
+ config?: ObjectHook<(config: UserConfig, env: ConfigEnv) => UserConfig | null | void | Promise<UserConfig | null | void>>;
1497
1510
  /**
1498
1511
  * Use this hook to read and store the final resolved vite config.
1499
1512
  */
1500
- configResolved?: (config: ResolvedConfig) => void | Promise<void>;
1513
+ configResolved?: ObjectHook<(config: ResolvedConfig) => void | Promise<void>>;
1501
1514
  /**
1502
1515
  * Configure the vite server. The hook receives the {@link ViteDevServer}
1503
1516
  * instance. This can also be used to store a reference to the server
@@ -1507,7 +1520,7 @@ declare interface Plugin_2 extends Plugin_3 {
1507
1520
  * can return a post hook that will be called after internal middlewares
1508
1521
  * are applied. Hook can be async functions and will be called in series.
1509
1522
  */
1510
- configureServer?: ServerHook;
1523
+ configureServer?: ObjectHook<ServerHook>;
1511
1524
  /**
1512
1525
  * Configure the preview server. The hook receives the connect server and
1513
1526
  * its underlying http server.
@@ -1516,7 +1529,7 @@ declare interface Plugin_2 extends Plugin_3 {
1516
1529
  * return a post hook that will be called after other middlewares are
1517
1530
  * applied. Hooks can be async functions and will be called in series.
1518
1531
  */
1519
- configurePreviewServer?: PreviewServerHook;
1532
+ configurePreviewServer?: ObjectHook<PreviewServerHook>;
1520
1533
  /**
1521
1534
  * Transform index.html.
1522
1535
  * The hook receives the following arguments:
@@ -1548,22 +1561,22 @@ declare interface Plugin_2 extends Plugin_3 {
1548
1561
  * - If the hook doesn't return a value, the hmr update will be performed as
1549
1562
  * normal.
1550
1563
  */
1551
- handleHotUpdate?(ctx: HmrContext): Array<ModuleNode> | void | Promise<Array<ModuleNode> | void>;
1564
+ handleHotUpdate?: ObjectHook<(ctx: HmrContext) => Array<ModuleNode> | void | Promise<Array<ModuleNode> | void>>;
1552
1565
  /**
1553
1566
  * extend hooks with ssr flag
1554
1567
  */
1555
- resolveId?: (this: PluginContext, source: string, importer: string | undefined, options: {
1568
+ resolveId?: ObjectHook<(this: PluginContext, source: string, importer: string | undefined, options: {
1556
1569
  custom?: CustomPluginOptions;
1557
1570
  ssr?: boolean;
1558
1571
  /* Excluded from this release type: scan */
1559
1572
  isEntry: boolean;
1560
- }) => Promise<ResolveIdResult> | ResolveIdResult;
1561
- load?: (this: PluginContext, id: string, options?: {
1573
+ }) => Promise<ResolveIdResult> | ResolveIdResult>;
1574
+ load?: ObjectHook<(this: PluginContext, id: string, options?: {
1562
1575
  ssr?: boolean;
1563
- }) => Promise<LoadResult> | LoadResult;
1564
- transform?: (this: TransformPluginContext, code: string, id: string, options?: {
1576
+ }) => Promise<LoadResult> | LoadResult>;
1577
+ transform?: ObjectHook<(this: TransformPluginContext, code: string, id: string, options?: {
1565
1578
  ssr?: boolean;
1566
- }) => Promise<TransformResult_2> | TransformResult_2;
1579
+ }) => Promise<TransformResult_2> | TransformResult_2>;
1567
1580
  }
1568
1581
  export { Plugin_2 as Plugin }
1569
1582
 
@@ -1588,6 +1601,11 @@ export declare interface PluginContainer {
1588
1601
  close(): Promise<void>;
1589
1602
  }
1590
1603
 
1604
+ export declare interface PluginHookUtils {
1605
+ getSortedPlugins: (hookName: keyof Plugin_2) => Plugin_2[];
1606
+ getSortedPluginHooks: <K extends keyof Plugin_2>(hookName: K) => NonNullable<HookHandler<Plugin_2[K]>>[];
1607
+ }
1608
+
1591
1609
  export declare type PluginOption = Plugin_2 | false | null | undefined | PluginOption[] | Promise<Plugin_2 | false | null | undefined | PluginOption[]>;
1592
1610
 
1593
1611
  /**
@@ -1694,7 +1712,7 @@ export declare type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'asse
1694
1712
  worker: ResolveWorkerOptions;
1695
1713
  appType: AppType;
1696
1714
  experimental: ExperimentalOptions;
1697
- }>;
1715
+ } & PluginHookUtils>;
1698
1716
 
1699
1717
  export declare interface ResolvedPreviewOptions extends PreviewOptions {
1700
1718
  }
@@ -1744,7 +1762,7 @@ export declare interface ResolverObject {
1744
1762
  resolveId: ResolverFunction
1745
1763
  }
1746
1764
 
1747
- export declare interface ResolveWorkerOptions {
1765
+ export declare interface ResolveWorkerOptions extends PluginHookUtils {
1748
1766
  format: 'es' | 'iife';
1749
1767
  plugins: Plugin_2[];
1750
1768
  rollupOptions: RollupOptions;
@@ -2566,7 +2584,7 @@ export declare interface ViteDevServer {
2566
2584
  /**
2567
2585
  * Transform module code into SSR format.
2568
2586
  */
2569
- ssrTransform(code: string, inMap: SourceMap | null, url: string): Promise<TransformResult | null>;
2587
+ ssrTransform(code: string, inMap: SourceMap | null, url: string, originalCode?: string): Promise<TransformResult | null>;
2570
2588
  /**
2571
2589
  * Load a given URL as an instantiated module for SSR.
2572
2590
  */
@@ -3254,7 +3272,7 @@ export declare interface WebSocketServer {
3254
3272
  */
3255
3273
  clients: Set<WebSocketClient>;
3256
3274
  /**
3257
- * Boardcast events to all clients
3275
+ * Broadcast events to all clients
3258
3276
  */
3259
3277
  send(payload: HMRPayload): void;
3260
3278
  /**
@@ -1,4 +1,4 @@
1
- export { b as build, k as createFilter, u as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, h as getDepOptimizationConfig, i as isDepsOptimizerEnabled, l as loadConfigFromFile, w as loadEnv, j as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, g as resolveBaseUrl, e as resolveConfig, x as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, v as searchForWorkspaceRoot, q as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-0f13c890.js';
1
+ export { b as build, k as createFilter, u as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, h as getDepOptimizationConfig, i as isDepsOptimizerEnabled, l as loadConfigFromFile, w as loadEnv, j as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, g as resolveBaseUrl, e as resolveConfig, x as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, v as searchForWorkspaceRoot, q as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-34b4c4eb.js';
2
2
  export { VERSION as version } from './constants.js';
3
3
  export { version as esbuildVersion } from 'esbuild';
4
4
  export { VERSION as rollupVersion } from 'rollup';
@@ -26,13 +26,14 @@ import 'node:dns';
26
26
  import 'resolve';
27
27
  import 'crypto';
28
28
  import 'buffer';
29
+ import 'node:buffer';
29
30
  import 'module';
31
+ import 'worker_threads';
30
32
  import 'zlib';
31
33
  import 'https';
32
34
  import 'tls';
33
35
  import 'node:http';
34
36
  import 'node:https';
35
- import 'worker_threads';
36
37
  import 'querystring';
37
38
  import 'node:readline';
38
39
  import 'node:child_process';
@@ -31,7 +31,7 @@ var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
31
31
  var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
32
32
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
33
33
 
34
- var version = "3.0.7";
34
+ var version = "3.1.0-beta.0";
35
35
 
36
36
  const VERSION = version;
37
37
  const VITE_PACKAGE_DIR = path$3.resolve(
@@ -3434,7 +3434,12 @@ function lookupFile(dir, formats, options) {
3434
3434
  for (const format of formats) {
3435
3435
  const fullPath = path__default.join(dir, format);
3436
3436
  if (fs__default.existsSync(fullPath) && fs__default.statSync(fullPath).isFile()) {
3437
- return options?.pathOnly ? fullPath : fs__default.readFileSync(fullPath, 'utf-8');
3437
+ const result = options?.pathOnly
3438
+ ? fullPath
3439
+ : fs__default.readFileSync(fullPath, 'utf-8');
3440
+ if (!options?.predicate || options.predicate(result)) {
3441
+ return result;
3442
+ }
3438
3443
  }
3439
3444
  }
3440
3445
  const parentDir = path__default.dirname(dir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "3.0.7",
3
+ "version": "3.1.0-beta.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -61,7 +61,7 @@
61
61
  "esbuild": "^0.14.47",
62
62
  "postcss": "^8.4.16",
63
63
  "resolve": "^1.22.1",
64
- "rollup": ">=2.75.6 <2.77.0 || ~2.77.0"
64
+ "rollup": "~2.78.0"
65
65
  },
66
66
  "optionalDependencies": {
67
67
  "fsevents": "~2.3.2"
@@ -70,7 +70,7 @@
70
70
  "@ampproject/remapping": "^2.2.0",
71
71
  "@babel/parser": "^7.18.11",
72
72
  "@babel/types": "^7.18.10",
73
- "@jridgewell/trace-mapping": "^0.3.14",
73
+ "@jridgewell/trace-mapping": "^0.3.15",
74
74
  "@rollup/plugin-alias": "^3.1.9",
75
75
  "@rollup/plugin-commonjs": "^22.0.2",
76
76
  "@rollup/plugin-dynamic-import-vars": "^1.4.4",
@@ -78,7 +78,6 @@
78
78
  "@rollup/plugin-node-resolve": "13.3.0",
79
79
  "@rollup/plugin-typescript": "^8.3.4",
80
80
  "@rollup/pluginutils": "^4.2.1",
81
- "@vue/compiler-dom": "^3.2.37",
82
81
  "acorn": "^8.8.0",
83
82
  "cac": "^6.7.12",
84
83
  "chokidar": "^3.5.3",
@@ -90,24 +89,25 @@
90
89
  "debug": "^4.3.4",
91
90
  "dotenv": "^14.3.2",
92
91
  "dotenv-expand": "^5.1.0",
93
- "es-module-lexer": "^0.10.5",
92
+ "es-module-lexer": "^1.0.3",
94
93
  "estree-walker": "^3.0.1",
95
94
  "etag": "^1.8.1",
96
95
  "fast-glob": "^3.2.11",
97
96
  "http-proxy": "^1.18.1",
98
97
  "json5": "^2.2.1",
99
- "launch-editor-middleware": "^2.5.0",
98
+ "launch-editor-middleware": "^2.6.0",
100
99
  "magic-string": "^0.26.2",
101
100
  "micromatch": "^4.0.5",
102
- "mlly": "^0.5.7",
101
+ "mlly": "^0.5.14",
103
102
  "mrmime": "^1.0.1",
104
103
  "okie": "^1.0.1",
105
104
  "open": "^8.4.0",
105
+ "parse5": "^7.0.0",
106
106
  "periscopic": "^3.0.4",
107
107
  "picocolors": "^1.0.0",
108
108
  "postcss-import": "^14.1.0",
109
109
  "postcss-load-config": "^4.0.1",
110
- "postcss-modules": "^4.3.1",
110
+ "postcss-modules": "^5.0.0",
111
111
  "resolve.exports": "^1.1.0",
112
112
  "rollup-plugin-license": "^2.8.1",
113
113
  "sirv": "^2.0.2",
@@ -101,7 +101,7 @@ function setupWebSocket(
101
101
  }
102
102
 
103
103
  console.log(`[vite] server connection lost. polling for restart...`)
104
- await waitForSuccessfulPing(hostAndPath)
104
+ await waitForSuccessfulPing(protocol, hostAndPath)
105
105
  location.reload()
106
106
  })
107
107
 
@@ -126,6 +126,7 @@ function cleanUrl(pathname: string): string {
126
126
  }
127
127
 
128
128
  let isFirstUpdate = true
129
+ const outdatedLinkTags = new WeakSet<HTMLLinkElement>()
129
130
 
130
131
  async function handleMessage(payload: HMRPayload) {
131
132
  switch (payload.type) {
@@ -166,7 +167,10 @@ async function handleMessage(payload: HMRPayload) {
166
167
  // URL for the include check.
167
168
  const el = Array.from(
168
169
  document.querySelectorAll<HTMLLinkElement>('link')
169
- ).find((e) => cleanUrl(e.href).includes(searchUrl))
170
+ ).find(
171
+ (e) =>
172
+ !outdatedLinkTags.has(e) && cleanUrl(e.href).includes(searchUrl)
173
+ )
170
174
  if (el) {
171
175
  const newPath = `${base}${searchUrl.slice(1)}${
172
176
  searchUrl.includes('?') ? '&' : '?'
@@ -182,6 +186,7 @@ async function handleMessage(payload: HMRPayload) {
182
186
  const removeOldEl = () => el.remove()
183
187
  newLinkTag.addEventListener('load', removeOldEl)
184
188
  newLinkTag.addEventListener('error', removeOldEl)
189
+ outdatedLinkTags.add(el)
185
190
  el.after(newLinkTag)
186
191
  }
187
192
  console.log(`[vite] css hot updated: ${searchUrl}`)
@@ -292,14 +297,22 @@ async function queueUpdate(p: Promise<(() => void) | undefined>) {
292
297
  }
293
298
  }
294
299
 
295
- async function waitForSuccessfulPing(hostAndPath: string, ms = 1000) {
300
+ async function waitForSuccessfulPing(
301
+ socketProtocol: string,
302
+ hostAndPath: string,
303
+ ms = 1000
304
+ ) {
305
+ const pingHostProtocol = socketProtocol === 'wss' ? 'https' : 'http'
306
+
296
307
  // eslint-disable-next-line no-constant-condition
297
308
  while (true) {
298
309
  try {
299
310
  // A fetch on a websocket URL will return a successful promise with status 400,
300
311
  // but will reject a networking error.
301
312
  // When running on middleware mode, it returns status 426, and an cors error happens if mode is not no-cors
302
- await fetch(`${location.protocol}//${hostAndPath}`, { mode: 'no-cors' })
313
+ await fetch(`${pingHostProtocol}://${hostAndPath}`, {
314
+ mode: 'no-cors'
315
+ })
303
316
  break
304
317
  } catch (e) {
305
318
  // wait ms before attempting to ping again
@@ -57,7 +57,7 @@ export namespace HttpProxy {
57
57
  * Used for proxying regular HTTP(S) requests
58
58
  * @param req - Client request.
59
59
  * @param res - Client response.
60
- * @param options - Additionnal options.
60
+ * @param options - Additional options.
61
61
  */
62
62
  web(
63
63
  req: http.IncomingMessage,
@@ -38,7 +38,9 @@ export interface KnownAsTypeMap {
38
38
 
39
39
  export interface ImportGlobFunction {
40
40
  /**
41
- * 1. No generic provided, infer the type from `eager` and `as`
41
+ * Import a list of files with a glob pattern.
42
+ *
43
+ * Overload 1: No generic provided, infer the type from `eager` and `as`
42
44
  */
43
45
  <
44
46
  Eager extends boolean,
@@ -51,14 +53,18 @@ export interface ImportGlobFunction {
51
53
  ? Record<string, T>
52
54
  : Record<string, () => Promise<T>>
53
55
  /**
54
- * 2. Module generic provided, infer the type from `eager: false`
56
+ * Import a list of files with a glob pattern.
57
+ *
58
+ * Overload 2: Module generic provided, infer the type from `eager: false`
55
59
  */
56
60
  <M>(
57
61
  glob: string | string[],
58
62
  options?: ImportGlobOptions<false, string>
59
63
  ): Record<string, () => Promise<M>>
60
64
  /**
61
- * 3. Module generic provided, infer the type from `eager: true`
65
+ * Import a list of files with a glob pattern.
66
+ *
67
+ * Overload 3: Module generic provided, infer the type from `eager: true`
62
68
  */
63
69
  <M>(
64
70
  glob: string | string[],
@@ -68,7 +74,9 @@ export interface ImportGlobFunction {
68
74
 
69
75
  export interface ImportGlobEagerFunction {
70
76
  /**
71
- * 1. No generic provided, infer the type from `as`
77
+ * Eagerly import a list of files with a glob pattern.
78
+ *
79
+ * Overload 1: No generic provided, infer the type from `as`
72
80
  */
73
81
  <
74
82
  As extends string,
@@ -78,7 +86,9 @@ export interface ImportGlobEagerFunction {
78
86
  options?: Omit<ImportGlobOptions<boolean, As>, 'eager'>
79
87
  ): Record<string, T>
80
88
  /**
81
- * 2. Module generic provided
89
+ * Eagerly import a list of files with a glob pattern.
90
+ *
91
+ * Overload 2: Module generic provided
82
92
  */
83
93
  <M>(
84
94
  glob: string | string[],