vite 2.9.0-beta.1 → 2.9.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.

package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "2.9.0-beta.1",
3
+ "version": "2.9.0-beta.10",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "description": "Native-ESM powered web dev build tool",
@@ -43,8 +43,8 @@
43
43
  },
44
44
  "//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
45
45
  "dependencies": {
46
- "esbuild": "^0.14.14",
47
- "postcss": "^8.4.6",
46
+ "esbuild": "^0.14.27",
47
+ "postcss": "^8.4.12",
48
48
  "resolve": "^1.22.0",
49
49
  "rollup": "^2.59.0"
50
50
  },
@@ -52,17 +52,17 @@
52
52
  "fsevents": "~2.3.2"
53
53
  },
54
54
  "devDependencies": {
55
- "@ampproject/remapping": "^2.1.0",
56
- "@babel/parser": "^7.17.0",
55
+ "@ampproject/remapping": "^2.1.2",
56
+ "@babel/parser": "^7.17.8",
57
57
  "@babel/types": "^7.17.0",
58
- "@jridgewell/trace-mapping": "^0.3.2",
58
+ "@jridgewell/trace-mapping": "^0.3.4",
59
59
  "@rollup/plugin-alias": "^3.1.9",
60
- "@rollup/plugin-commonjs": "^21.0.1",
60
+ "@rollup/plugin-commonjs": "^21.0.3",
61
61
  "@rollup/plugin-dynamic-import-vars": "^1.4.2",
62
62
  "@rollup/plugin-json": "^4.1.0",
63
63
  "@rollup/plugin-node-resolve": "13.1.3",
64
- "@rollup/plugin-typescript": "^8.3.0",
65
- "@rollup/pluginutils": "^4.1.2",
64
+ "@rollup/plugin-typescript": "^8.3.1",
65
+ "@rollup/pluginutils": "^4.2.0",
66
66
  "@types/convert-source-map": "^1.5.2",
67
67
  "@types/cross-spawn": "^6.0.2",
68
68
  "@types/debug": "^4.1.7",
@@ -71,12 +71,12 @@
71
71
  "@types/less": "^3.0.3",
72
72
  "@types/micromatch": "^4.0.2",
73
73
  "@types/mime": "^2.0.3",
74
- "@types/node": "^16.11.22",
74
+ "@types/node": "^16.11.26",
75
75
  "@types/resolve": "^1.20.1",
76
76
  "@types/sass": "~1.43.1",
77
77
  "@types/stylus": "^0.48.36",
78
- "@types/ws": "^8.2.2",
79
- "@vue/compiler-dom": "^3.2.30",
78
+ "@types/ws": "^8.5.3",
79
+ "@vue/compiler-dom": "^3.2.31",
80
80
  "acorn": "^8.7.0",
81
81
  "cac": "6.7.9",
82
82
  "chokidar": "^3.5.3",
@@ -85,34 +85,35 @@
85
85
  "convert-source-map": "^1.8.0",
86
86
  "cors": "^2.8.5",
87
87
  "cross-spawn": "^7.0.3",
88
- "debug": "^4.3.3",
88
+ "debug": "^4.3.4",
89
89
  "dotenv": "^14.3.2",
90
90
  "dotenv-expand": "^5.1.0",
91
- "es-module-lexer": "^0.9.3",
91
+ "es-module-lexer": "^0.10.4",
92
92
  "estree-walker": "^2.0.2",
93
93
  "etag": "^1.8.1",
94
94
  "fast-glob": "^3.2.11",
95
95
  "http-proxy": "^1.18.1",
96
- "json5": "^2.2.0",
96
+ "json5": "^2.2.1",
97
97
  "launch-editor-middleware": "^2.3.0",
98
- "magic-string": "^0.25.7",
99
- "micromatch": "^4.0.4",
98
+ "magic-string": "^0.26.1",
99
+ "micromatch": "^4.0.5",
100
100
  "mrmime": "^1.0.0",
101
- "node-forge": "^1.2.1",
101
+ "node-forge": "^1.3.0",
102
102
  "okie": "^1.0.1",
103
103
  "open": "^8.4.0",
104
104
  "periscopic": "^2.0.3",
105
105
  "picocolors": "^1.0.0",
106
- "postcss-import": "^14.0.2",
106
+ "postcss-import": "^14.1.0",
107
107
  "postcss-load-config": "^3.1.3",
108
- "postcss-modules": "^4.3.0",
108
+ "postcss-modules": "^4.3.1",
109
109
  "resolve.exports": "^1.1.0",
110
110
  "rollup-plugin-license": "^2.6.1",
111
111
  "sirv": "^2.0.2",
112
+ "source-map-js": "^1.0.2",
112
113
  "source-map-support": "^0.5.21",
113
114
  "strip-ansi": "^6.0.1",
114
- "terser": "^5.10.0",
115
- "tsconfck": "^1.2.0",
115
+ "terser": "^5.12.1",
116
+ "tsconfck": "^1.2.1",
116
117
  "tslib": "^2.3.1",
117
118
  "types": "link:./types",
118
119
  "ws": "^8.5.0"
@@ -1,12 +1,6 @@
1
- import type {
2
- ErrorPayload,
3
- FullReloadPayload,
4
- HMRPayload,
5
- PrunePayload,
6
- Update,
7
- UpdatePayload
8
- } from 'types/hmrPayload'
9
- import type { CustomEventName } from 'types/customEvent'
1
+ import type { ErrorPayload, HMRPayload, Update } from 'types/hmrPayload'
2
+ import type { ViteHotContext } from 'types/hot'
3
+ import type { InferCustomEventPayload } from 'types/customEvent'
10
4
  import { ErrorOverlay, overlayId } from './overlay'
11
5
  // eslint-disable-next-line node/no-missing-import
12
6
  import '@vite/env'
@@ -30,6 +24,7 @@ const socketHost = __HMR_PORT__
30
24
 
31
25
  const socket = new WebSocket(`${socketProtocol}://${socketHost}`, 'vite-hmr')
32
26
  const base = __BASE__ || '/'
27
+ const messageBuffer: string[] = []
33
28
 
34
29
  function warnFailedFetch(err: Error, path: string | string[]) {
35
30
  if (!err.message.match('fetch')) {
@@ -59,9 +54,10 @@ async function handleMessage(payload: HMRPayload) {
59
54
  switch (payload.type) {
60
55
  case 'connected':
61
56
  console.log(`[vite] connected.`)
57
+ sendMessageBuffer()
62
58
  // proxy(nginx, docker) hmr ws maybe caused timeout,
63
59
  // so send ping package let ws keep alive.
64
- setInterval(() => socket.send('ping'), __HMR_TIMEOUT__)
60
+ setInterval(() => socket.send('{"type":"ping"}'), __HMR_TIMEOUT__)
65
61
  break
66
62
  case 'update':
67
63
  notifyListeners('vite:beforeUpdate', payload)
@@ -101,7 +97,7 @@ async function handleMessage(payload: HMRPayload) {
101
97
  })
102
98
  break
103
99
  case 'custom': {
104
- notifyListeners(payload.event as CustomEventName<any>, payload.data)
100
+ notifyListeners(payload.event, payload.data)
105
101
  break
106
102
  }
107
103
  case 'full-reload':
@@ -154,19 +150,9 @@ async function handleMessage(payload: HMRPayload) {
154
150
  }
155
151
  }
156
152
 
157
- function notifyListeners(
158
- event: 'vite:beforeUpdate',
159
- payload: UpdatePayload
160
- ): void
161
- function notifyListeners(event: 'vite:beforePrune', payload: PrunePayload): void
162
- function notifyListeners(
163
- event: 'vite:beforeFullReload',
164
- payload: FullReloadPayload
165
- ): void
166
- function notifyListeners(event: 'vite:error', payload: ErrorPayload): void
167
153
  function notifyListeners<T extends string>(
168
- event: CustomEventName<T>,
169
- data: any
154
+ event: T,
155
+ data: InferCustomEventPayload<T>
170
156
  ): void
171
157
  function notifyListeners(event: string, data: any): void {
172
158
  const cbs = customListenersMap.get(event)
@@ -361,6 +347,13 @@ async function fetchUpdate({ path, acceptedPath, timestamp }: Update) {
361
347
  }
362
348
  }
363
349
 
350
+ function sendMessageBuffer() {
351
+ if (socket.readyState === 1) {
352
+ messageBuffer.forEach((msg) => socket.send(msg))
353
+ messageBuffer.length = 0
354
+ }
355
+ }
356
+
364
357
  interface HotModule {
365
358
  id: string
366
359
  callbacks: HotCallback[]
@@ -382,9 +375,7 @@ const ctxToListenersMap = new Map<
382
375
  Map<string, ((data: any) => void)[]>
383
376
  >()
384
377
 
385
- // Just infer the return type for now
386
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
387
- export const createHotContext = (ownerPath: string) => {
378
+ export function createHotContext(ownerPath: string): ViteHotContext {
388
379
  if (!dataMap.has(ownerPath)) {
389
380
  dataMap.set(ownerPath, {})
390
381
  }
@@ -425,12 +416,12 @@ export const createHotContext = (ownerPath: string) => {
425
416
  hotModulesMap.set(ownerPath, mod)
426
417
  }
427
418
 
428
- const hot = {
419
+ const hot: ViteHotContext = {
429
420
  get data() {
430
421
  return dataMap.get(ownerPath)
431
422
  },
432
423
 
433
- accept(deps: any, callback?: any) {
424
+ accept(deps?: any, callback?: any) {
434
425
  if (typeof deps === 'function' || !deps) {
435
426
  // self-accept: hot.accept(() => {})
436
427
  acceptDeps([ownerPath], ([mod]) => deps && deps(mod))
@@ -451,10 +442,11 @@ export const createHotContext = (ownerPath: string) => {
451
442
  )
452
443
  },
453
444
 
454
- dispose(cb: (data: any) => void) {
445
+ dispose(cb) {
455
446
  disposeMap.set(ownerPath, cb)
456
447
  },
457
448
 
449
+ // @ts-expect-error untyped
458
450
  prune(cb: (data: any) => void) {
459
451
  pruneMap.set(ownerPath, cb)
460
452
  },
@@ -470,7 +462,7 @@ export const createHotContext = (ownerPath: string) => {
470
462
  },
471
463
 
472
464
  // custom events
473
- on: (event: string, cb: (data: any) => void) => {
465
+ on(event, cb) {
474
466
  const addToMap = (map: Map<string, any[]>) => {
475
467
  const existing = map.get(event) || []
476
468
  existing.push(cb)
@@ -478,6 +470,11 @@ export const createHotContext = (ownerPath: string) => {
478
470
  }
479
471
  addToMap(customListenersMap)
480
472
  addToMap(newListeners)
473
+ },
474
+
475
+ send(event, data) {
476
+ messageBuffer.push(JSON.stringify({ type: 'custom', event, data }))
477
+ sendMessageBuffer()
481
478
  }
482
479
  }
483
480
 
@@ -1,5 +1,16 @@
1
- // See https://stackoverflow.com/a/63549561.
2
- export type CustomEventName<T extends string> = (T extends `vite:${T}`
3
- ? never
4
- : T) &
5
- (`vite:${T}` extends T ? never : T)
1
+ import type {
2
+ ErrorPayload,
3
+ FullReloadPayload,
4
+ PrunePayload,
5
+ UpdatePayload
6
+ } from './hmrPayload'
7
+
8
+ export interface CustomEventMap {
9
+ 'vite:beforeUpdate': UpdatePayload
10
+ 'vite:beforePrune': PrunePayload
11
+ 'vite:beforeFullReload': FullReloadPayload
12
+ 'vite:error': ErrorPayload
13
+ }
14
+
15
+ export type InferCustomEventPayload<T extends string> =
16
+ T extends keyof CustomEventMap ? CustomEventMap[T] : any
package/types/hot.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { InferCustomEventPayload } from './customEvent'
2
+
3
+ export interface ViteHotContext {
4
+ readonly data: any
5
+
6
+ accept(): void
7
+ accept(cb: (mod: any) => void): void
8
+ accept(dep: string, cb: (mod: any) => void): void
9
+ accept(deps: readonly string[], cb: (mods: any[]) => void): void
10
+
11
+ /**
12
+ * @deprecated
13
+ */
14
+ acceptDeps(): never
15
+
16
+ dispose(cb: (data: any) => void): void
17
+ decline(): void
18
+ invalidate(): void
19
+
20
+ on<T extends string>(
21
+ event: T,
22
+ cb: (payload: InferCustomEventPayload<T>) => void
23
+ ): void
24
+ send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
25
+ }
@@ -20,46 +20,7 @@ interface GlobOptions {
20
20
  interface ImportMeta {
21
21
  url: string
22
22
 
23
- readonly hot?: {
24
- readonly data: any
25
-
26
- accept(): void
27
- accept(cb: (mod: any) => void): void
28
- accept(dep: string, cb: (mod: any) => void): void
29
- accept(deps: readonly string[], cb: (mods: any[]) => void): void
30
-
31
- /**
32
- * @deprecated
33
- */
34
- acceptDeps(): never
35
-
36
- dispose(cb: (data: any) => void): void
37
- decline(): void
38
- invalidate(): void
39
-
40
- on: {
41
- (
42
- event: 'vite:beforeUpdate',
43
- cb: (payload: import('./hmrPayload').UpdatePayload) => void
44
- ): void
45
- (
46
- event: 'vite:beforePrune',
47
- cb: (payload: import('./hmrPayload').PrunePayload) => void
48
- ): void
49
- (
50
- event: 'vite:beforeFullReload',
51
- cb: (payload: import('./hmrPayload').FullReloadPayload) => void
52
- ): void
53
- (
54
- event: 'vite:error',
55
- cb: (payload: import('./hmrPayload').ErrorPayload) => void
56
- ): void
57
- <T extends string>(
58
- event: import('./customEvent').CustomEventName<T>,
59
- cb: (data: any) => void
60
- ): void
61
- }
62
- }
23
+ readonly hot?: import('./hot').ViteHotContext
63
24
 
64
25
  readonly env: ImportMetaEnv
65
26
 
package/types/ws.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- // Type definitions for ws 8.2
1
+ // Modified and inlined to avoid extra dependency
2
+ // Source: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/ws/index.d.ts
3
+
4
+ // Type definitions for ws 8.5
2
5
  // Project: https://github.com/websockets/ws
3
6
  // Definitions by: Paul Loyd <https://github.com/loyd>
4
7
  // Margus Lamp <https://github.com/mlamp>
@@ -7,6 +10,7 @@
7
10
  // teidesu <https://github.com/teidesu>
8
11
  // Bartosz Wojtkowiak <https://github.com/wojtkowiak>
9
12
  // Kyle Hensel <https://github.com/k-yle>
13
+ // Samuel Skeen <https://github.com/cwadrupldijjit>
10
14
  // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
11
15
 
12
16
  /// <reference types="node" />
@@ -40,6 +44,8 @@ declare class WebSocket extends EventEmitter {
40
44
  binaryType: 'nodebuffer' | 'arraybuffer' | 'fragments'
41
45
  readonly bufferedAmount: number
42
46
  readonly extensions: string
47
+ /** Indicates whether the websocket is paused */
48
+ readonly isPaused: boolean
43
49
  readonly protocol: string
44
50
  /** The current state of the connection */
45
51
  readonly readyState:
@@ -58,11 +64,12 @@ declare class WebSocket extends EventEmitter {
58
64
  /** The connection is closed. */
59
65
  readonly CLOSED: 3
60
66
 
61
- onopen: (event: WebSocket.Event) => void
62
- onerror: (event: WebSocket.ErrorEvent) => void
63
- onclose: (event: WebSocket.CloseEvent) => void
64
- onmessage: (event: WebSocket.MessageEvent) => void
67
+ onopen: ((event: WebSocket.Event) => void) | null
68
+ onerror: ((event: WebSocket.ErrorEvent) => void) | null
69
+ onclose: ((event: WebSocket.CloseEvent) => void) | null
70
+ onmessage: ((event: WebSocket.MessageEvent) => void) | null
65
71
 
72
+ constructor(address: null)
66
73
  constructor(
67
74
  address: string | URL,
68
75
  options?: WebSocket.ClientOptions | ClientRequestArgs
@@ -89,6 +96,18 @@ declare class WebSocket extends EventEmitter {
89
96
  ): void
90
97
  terminate(): void
91
98
 
99
+ /**
100
+ * Pause the websocket causing it to stop emitting events. Some events can still be
101
+ * emitted after this is called, until all buffered data is consumed. This method
102
+ * is a noop if the ready state is `CONNECTING` or `CLOSED`.
103
+ */
104
+ pause(): void
105
+ /**
106
+ * Make a paused socket resume emitting events. This method is a noop if the ready
107
+ * state is `CONNECTING` or `CLOSED`.
108
+ */
109
+ resume(): void
110
+
92
111
  // HTML5 WebSocket events
93
112
  addEventListener(
94
113
  method: 'message',
@@ -281,7 +300,7 @@ declare class WebSocket extends EventEmitter {
281
300
  }
282
301
 
283
302
  declare const WebSocketAlias: typeof WebSocket
284
- type WebSocketAlias = WebSocket
303
+ interface WebSocketAlias extends WebSocket {} // tslint:disable-line no-empty-interface
285
304
 
286
305
  declare namespace WebSocket {
287
306
  /**
@@ -328,6 +347,7 @@ declare namespace WebSocket {
328
347
  interface ClientOptions extends SecureContextOptions {
329
348
  protocol?: string | undefined
330
349
  followRedirects?: boolean | undefined
350
+ generateMask?(mask: Buffer): void
331
351
  handshakeTimeout?: number | undefined
332
352
  maxRedirects?: number | undefined
333
353
  perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined
@@ -341,6 +361,7 @@ declare namespace WebSocket {
341
361
  checkServerIdentity?(servername: string, cert: CertMeta): boolean
342
362
  rejectUnauthorized?: boolean | undefined
343
363
  maxPayload?: number | undefined
364
+ skipUTF8Validation?: boolean | undefined
344
365
  }
345
366
 
346
367
  interface PerMessageDeflateOptions {
@@ -415,6 +436,7 @@ declare namespace WebSocket {
415
436
  perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined
416
437
  maxPayload?: number | undefined
417
438
  skipUTF8Validation?: boolean | undefined
439
+ WebSocket?: typeof WebSocket.WebSocket | undefined
418
440
  }
419
441
 
420
442
  interface AddressInfo {
@@ -424,10 +446,10 @@ declare namespace WebSocket {
424
446
  }
425
447
 
426
448
  // WebSocket Server
427
- class Server extends EventEmitter {
449
+ class Server<T extends WebSocket = WebSocket> extends EventEmitter {
428
450
  options: ServerOptions
429
451
  path: string
430
- clients: Set<WebSocket>
452
+ clients: Set<T>
431
453
 
432
454
  constructor(options?: ServerOptions, callback?: () => void)
433
455
 
@@ -437,56 +459,59 @@ declare namespace WebSocket {
437
459
  request: IncomingMessage,
438
460
  socket: Duplex,
439
461
  upgradeHead: Buffer,
440
- callback: (client: WebSocket, request: IncomingMessage) => void
462
+ callback: (client: T, request: IncomingMessage) => void
441
463
  ): void
442
464
  shouldHandle(request: IncomingMessage): boolean | Promise<boolean>
443
465
 
444
466
  // Events
445
467
  on(
446
468
  event: 'connection',
447
- cb: (this: Server, socket: WebSocket, request: IncomingMessage) => void
469
+ cb: (this: Server<T>, socket: T, request: IncomingMessage) => void
448
470
  ): this
449
- on(event: 'error', cb: (this: Server, error: Error) => void): this
471
+ on(event: 'error', cb: (this: Server<T>, error: Error) => void): this
450
472
  on(
451
473
  event: 'headers',
452
- cb: (this: Server, headers: string[], request: IncomingMessage) => void
474
+ cb: (this: Server<T>, headers: string[], request: IncomingMessage) => void
453
475
  ): this
454
- on(event: 'close' | 'listening', cb: (this: Server) => void): this
476
+ on(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
455
477
  on(
456
478
  event: string | symbol,
457
- listener: (this: Server, ...args: any[]) => void
479
+ listener: (this: Server<T>, ...args: any[]) => void
458
480
  ): this
459
481
 
460
482
  once(
461
483
  event: 'connection',
462
- cb: (this: Server, socket: WebSocket, request: IncomingMessage) => void
484
+ cb: (this: Server<T>, socket: T, request: IncomingMessage) => void
463
485
  ): this
464
- once(event: 'error', cb: (this: Server, error: Error) => void): this
486
+ once(event: 'error', cb: (this: Server<T>, error: Error) => void): this
465
487
  once(
466
488
  event: 'headers',
467
- cb: (this: Server, headers: string[], request: IncomingMessage) => void
489
+ cb: (this: Server<T>, headers: string[], request: IncomingMessage) => void
490
+ ): this
491
+ once(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
492
+ once(
493
+ event: string | symbol,
494
+ listener: (this: Server<T>, ...args: any[]) => void
468
495
  ): this
469
- once(event: 'close' | 'listening', cb: (this: Server) => void): this
470
- once(event: string | symbol, listener: (...args: any[]) => void): this
471
496
 
472
497
  off(
473
498
  event: 'connection',
474
- cb: (this: Server, socket: WebSocket, request: IncomingMessage) => void
499
+ cb: (this: Server<T>, socket: T, request: IncomingMessage) => void
475
500
  ): this
476
- off(event: 'error', cb: (this: Server, error: Error) => void): this
501
+ off(event: 'error', cb: (this: Server<T>, error: Error) => void): this
477
502
  off(
478
503
  event: 'headers',
479
- cb: (this: Server, headers: string[], request: IncomingMessage) => void
504
+ cb: (this: Server<T>, headers: string[], request: IncomingMessage) => void
480
505
  ): this
481
- off(event: 'close' | 'listening', cb: (this: Server) => void): this
506
+ off(event: 'close' | 'listening', cb: (this: Server<T>) => void): this
482
507
  off(
483
508
  event: string | symbol,
484
- listener: (this: Server, ...args: any[]) => void
509
+ listener: (this: Server<T>, ...args: any[]) => void
485
510
  ): this
486
511
 
487
512
  addListener(
488
513
  event: 'connection',
489
- cb: (client: WebSocket, request: IncomingMessage) => void
514
+ cb: (client: T, request: IncomingMessage) => void
490
515
  ): this
491
516
  addListener(event: 'error', cb: (err: Error) => void): this
492
517
  addListener(
@@ -499,7 +524,7 @@ declare namespace WebSocket {
499
524
  listener: (...args: any[]) => void
500
525
  ): this
501
526
 
502
- removeListener(event: 'connection', cb: (client: WebSocket) => void): this
527
+ removeListener(event: 'connection', cb: (client: T) => void): this
503
528
  removeListener(event: 'error', cb: (err: Error) => void): this
504
529
  removeListener(
505
530
  event: 'headers',
@@ -513,9 +538,9 @@ declare namespace WebSocket {
513
538
  }
514
539
 
515
540
  const WebSocketServer: typeof Server
516
- type WebSocketServer = Server
541
+ interface WebSocketServer extends Server {} // tslint:disable-line no-empty-interface
517
542
  const WebSocket: typeof WebSocketAlias
518
- type WebSocket = WebSocketAlias
543
+ interface WebSocket extends WebSocketAlias {} // tslint:disable-line no-empty-interface
519
544
 
520
545
  // WebSocket stream
521
546
  function createWebSocketStream(
@@ -524,5 +549,5 @@ declare namespace WebSocket {
524
549
  ): Duplex
525
550
  }
526
551
 
527
- //export = WebSocket;
552
+ // export = WebSocket
528
553
  export { WebSocket, WebSocketAlias }