vite 2.9.0-beta.9 → 2.9.2
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/dist/client/client.mjs +6 -9
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/chunks/{dep-f61a3114.js → dep-1df7b07f.js} +1 -1
- package/dist/node/chunks/{dep-051d3e69.js → dep-559163d5.js} +1 -1
- package/dist/node/chunks/{dep-368120f8.js → dep-aae62ed4.js} +14 -1
- package/dist/node/chunks/{dep-5633cdf8.js → dep-bcc0af00.js} +103 -25
- package/dist/node/chunks/{dep-f5b7cdd7.js → dep-e7afa13e.js} +33233 -30383
- package/dist/node/cli.js +6 -6
- package/dist/node/index.d.ts +31 -17
- package/dist/node/index.js +1 -1
- package/package.json +10 -10
- package/src/client/client.ts +15 -35
- package/types/customEvent.d.ts +16 -5
- package/types/hot.d.ts +25 -0
- package/types/importMeta.d.ts +2 -43
package/dist/node/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var require$$0 = require('events');
|
|
4
|
-
var index = require('./chunks/dep-
|
|
4
|
+
var index = require('./chunks/dep-e7afa13e.js');
|
|
5
5
|
var perf_hooks = require('perf_hooks');
|
|
6
6
|
require('fs');
|
|
7
7
|
require('path');
|
|
@@ -683,7 +683,7 @@ cli
|
|
|
683
683
|
.action(async (root, options) => {
|
|
684
684
|
// output structure is preserved even after bundling so require()
|
|
685
685
|
// is ok here
|
|
686
|
-
const { createServer } = await Promise.resolve().then(function () { return require('./chunks/dep-
|
|
686
|
+
const { createServer } = await Promise.resolve().then(function () { return require('./chunks/dep-e7afa13e.js'); }).then(function (n) { return n.index$1; });
|
|
687
687
|
try {
|
|
688
688
|
const server = await createServer({
|
|
689
689
|
root,
|
|
@@ -721,7 +721,7 @@ cli
|
|
|
721
721
|
.command('build [root]', 'build for production')
|
|
722
722
|
.option('--target <target>', `[string] transpile target (default: 'modules')`)
|
|
723
723
|
.option('--outDir <dir>', `[string] output directory (default: dist)`)
|
|
724
|
-
.option('--assetsDir <dir>', `[string] directory under outDir to place assets in (default:
|
|
724
|
+
.option('--assetsDir <dir>', `[string] directory under outDir to place assets in (default: assets)`)
|
|
725
725
|
.option('--assetsInlineLimit <number>', `[number] static asset base64 inline threshold in bytes (default: 4096)`)
|
|
726
726
|
.option('--ssr [entry]', `[string] build specified entry for server-side rendering`)
|
|
727
727
|
.option('--sourcemap', `[boolean] output source maps for build (default: false)`)
|
|
@@ -732,7 +732,7 @@ cli
|
|
|
732
732
|
.option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
|
|
733
733
|
.option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
|
|
734
734
|
.action(async (root, options) => {
|
|
735
|
-
const { build } = await Promise.resolve().then(function () { return require('./chunks/dep-
|
|
735
|
+
const { build } = await Promise.resolve().then(function () { return require('./chunks/dep-e7afa13e.js'); }).then(function (n) { return n.build$1; });
|
|
736
736
|
const buildOptions = cleanOptions(options);
|
|
737
737
|
try {
|
|
738
738
|
await build({
|
|
@@ -755,7 +755,7 @@ cli
|
|
|
755
755
|
.command('optimize [root]', 'pre-bundle dependencies')
|
|
756
756
|
.option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
|
|
757
757
|
.action(async (root, options) => {
|
|
758
|
-
const { optimizeDeps } = await Promise.resolve().then(function () { return require('./chunks/dep-
|
|
758
|
+
const { optimizeDeps } = await Promise.resolve().then(function () { return require('./chunks/dep-e7afa13e.js'); }).then(function (n) { return n.index; });
|
|
759
759
|
try {
|
|
760
760
|
const config = await index.resolveConfig({
|
|
761
761
|
root,
|
|
@@ -778,7 +778,7 @@ cli
|
|
|
778
778
|
.option('--https', `[boolean] use TLS + HTTP/2`)
|
|
779
779
|
.option('--open [path]', `[boolean | string] open browser on startup`)
|
|
780
780
|
.action(async (root, options) => {
|
|
781
|
-
const { preview } = await Promise.resolve().then(function () { return require('./chunks/dep-
|
|
781
|
+
const { preview } = await Promise.resolve().then(function () { return require('./chunks/dep-e7afa13e.js'); }).then(function (n) { return n.preview$1; });
|
|
782
782
|
try {
|
|
783
783
|
const server = await preview({
|
|
784
784
|
root,
|
package/dist/node/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ import type { PartialResolvedId } from 'rollup';
|
|
|
27
27
|
import type { Plugin as Plugin_2 } from 'rollup';
|
|
28
28
|
import type { PluginContext } from 'rollup';
|
|
29
29
|
import type { PluginHooks } from 'rollup';
|
|
30
|
-
import type * as
|
|
30
|
+
import type * as PostCSS from 'postcss';
|
|
31
31
|
import type { ResolveIdResult } from 'rollup';
|
|
32
32
|
import type { RollupError } from 'rollup';
|
|
33
33
|
import type { RollupOptions } from 'rollup';
|
|
@@ -35,8 +35,8 @@ import type { RollupOutput } from 'rollup';
|
|
|
35
35
|
import type { RollupWatcher } from 'rollup';
|
|
36
36
|
import type { SecureContextOptions } from 'tls';
|
|
37
37
|
import type { Server } from 'http';
|
|
38
|
-
import type { Server as Server_2 } from '
|
|
39
|
-
import type { Server as Server_3 } from '
|
|
38
|
+
import type { Server as Server_2 } from 'https';
|
|
39
|
+
import type { Server as Server_3 } from 'net';
|
|
40
40
|
import type { ServerOptions as ServerOptions_2 } from 'https';
|
|
41
41
|
import type { ServerResponse } from 'http';
|
|
42
42
|
import type { SourceDescription } from 'rollup';
|
|
@@ -48,8 +48,6 @@ import type { TransformResult as TransformResult_3 } from 'rollup';
|
|
|
48
48
|
import type * as url from 'url';
|
|
49
49
|
import type { URL as URL_2 } from 'url';
|
|
50
50
|
import type { WatcherOptions } from 'rollup';
|
|
51
|
-
import type { WebSocket as WebSocket_2 } from 'ws';
|
|
52
|
-
import { WebSocketServer as WebSocketServer_2 } from 'ws';
|
|
53
51
|
import type { ZlibOptions } from 'zlib';
|
|
54
52
|
|
|
55
53
|
export declare interface Alias {
|
|
@@ -484,8 +482,8 @@ export declare interface CSSOptions {
|
|
|
484
482
|
*/
|
|
485
483
|
modules?: CSSModulesOptions | false;
|
|
486
484
|
preprocessorOptions?: Record<string, any>;
|
|
487
|
-
postcss?: string | (
|
|
488
|
-
plugins?:
|
|
485
|
+
postcss?: string | (PostCSS.ProcessOptions & {
|
|
486
|
+
plugins?: PostCSS.Plugin[];
|
|
489
487
|
});
|
|
490
488
|
/**
|
|
491
489
|
* Enables css sourcemaps during dev
|
|
@@ -495,6 +493,13 @@ export declare interface CSSOptions {
|
|
|
495
493
|
devSourcemap?: boolean;
|
|
496
494
|
}
|
|
497
495
|
|
|
496
|
+
export declare interface CustomEventMap {
|
|
497
|
+
'vite:beforeUpdate': UpdatePayload
|
|
498
|
+
'vite:beforePrune': PrunePayload
|
|
499
|
+
'vite:beforeFullReload': FullReloadPayload
|
|
500
|
+
'vite:error': ErrorPayload
|
|
501
|
+
}
|
|
502
|
+
|
|
498
503
|
export declare interface CustomPayload {
|
|
499
504
|
type: 'custom'
|
|
500
505
|
event: string
|
|
@@ -588,6 +593,12 @@ export declare interface DepOptimizationOptions {
|
|
|
588
593
|
* @experimental
|
|
589
594
|
*/
|
|
590
595
|
extensions?: string[];
|
|
596
|
+
/**
|
|
597
|
+
* Disables dependencies optimizations
|
|
598
|
+
* @default false
|
|
599
|
+
* @experimental
|
|
600
|
+
*/
|
|
601
|
+
disabled?: boolean;
|
|
591
602
|
}
|
|
592
603
|
|
|
593
604
|
export declare interface DepOptimizationProcessing {
|
|
@@ -755,7 +766,7 @@ export declare interface HmrContext {
|
|
|
755
766
|
export declare interface HmrOptions {
|
|
756
767
|
protocol?: string;
|
|
757
768
|
host?: string;
|
|
758
|
-
port?: number
|
|
769
|
+
port?: number;
|
|
759
770
|
clientPort?: number;
|
|
760
771
|
path?: string;
|
|
761
772
|
timeout?: number;
|
|
@@ -1030,6 +1041,9 @@ export declare type IndexHtmlTransformResult = string | HtmlTagDescriptor[] | {
|
|
|
1030
1041
|
tags: HtmlTagDescriptor[];
|
|
1031
1042
|
};
|
|
1032
1043
|
|
|
1044
|
+
export declare type InferCustomEventPayload<T extends string> =
|
|
1045
|
+
T extends keyof CustomEventMap ? CustomEventMap[T] : any
|
|
1046
|
+
|
|
1033
1047
|
export declare interface InlineConfig extends UserConfig {
|
|
1034
1048
|
configFile?: string | false;
|
|
1035
1049
|
envFile?: false;
|
|
@@ -1175,7 +1189,7 @@ export declare class ModuleNode {
|
|
|
1175
1189
|
importers: Set<ModuleNode>;
|
|
1176
1190
|
importedModules: Set<ModuleNode>;
|
|
1177
1191
|
acceptedHmrDeps: Set<ModuleNode>;
|
|
1178
|
-
isSelfAccepting
|
|
1192
|
+
isSelfAccepting?: boolean;
|
|
1179
1193
|
transformResult: TransformResult | null;
|
|
1180
1194
|
ssrTransformResult: TransformResult | null;
|
|
1181
1195
|
ssrModule: Record<string, any> | null;
|
|
@@ -1392,7 +1406,7 @@ export declare interface PreviewServer {
|
|
|
1392
1406
|
/**
|
|
1393
1407
|
* @deprecated Use `server.printUrls()` instead
|
|
1394
1408
|
*/
|
|
1395
|
-
export declare function printHttpServerUrls(server:
|
|
1409
|
+
export declare function printHttpServerUrls(server: Server_3, config: ResolvedConfig): void;
|
|
1396
1410
|
|
|
1397
1411
|
export declare interface ProxyOptions extends HttpProxy.ServerOptions {
|
|
1398
1412
|
/**
|
|
@@ -2708,7 +2722,7 @@ export declare namespace WebSocket {
|
|
|
2708
2722
|
host?: string | undefined
|
|
2709
2723
|
port?: number | undefined
|
|
2710
2724
|
backlog?: number | undefined
|
|
2711
|
-
server?: Server |
|
|
2725
|
+
server?: Server | Server_2 | undefined
|
|
2712
2726
|
verifyClient?:
|
|
2713
2727
|
| VerifyClientCallbackAsync
|
|
2714
2728
|
| VerifyClientCallbackSync
|
|
@@ -2853,7 +2867,7 @@ export declare interface WebSocketClient {
|
|
|
2853
2867
|
* The raw WebSocket instance
|
|
2854
2868
|
* @advanced
|
|
2855
2869
|
*/
|
|
2856
|
-
socket:
|
|
2870
|
+
socket: WebSocket;
|
|
2857
2871
|
}
|
|
2858
2872
|
|
|
2859
2873
|
export declare type WebSocketCustomListener<T> = (data: T, client: WebSocketClient) => void;
|
|
@@ -2870,7 +2884,7 @@ export declare interface WebSocketServer {
|
|
|
2870
2884
|
/**
|
|
2871
2885
|
* Send custom event
|
|
2872
2886
|
*/
|
|
2873
|
-
send(event:
|
|
2887
|
+
send<T extends string>(event: T, payload?: InferCustomEventPayload<T>): void;
|
|
2874
2888
|
/**
|
|
2875
2889
|
* Disconnect all clients and terminate the server.
|
|
2876
2890
|
*/
|
|
@@ -2878,14 +2892,14 @@ export declare interface WebSocketServer {
|
|
|
2878
2892
|
/**
|
|
2879
2893
|
* Handle custom event emitted by `import.meta.hot.send`
|
|
2880
2894
|
*/
|
|
2881
|
-
on:
|
|
2882
|
-
(event:
|
|
2895
|
+
on: WebSocket.Server['on'] & {
|
|
2896
|
+
<T extends string>(event: T, listener: WebSocketCustomListener<InferCustomEventPayload<T>>): void;
|
|
2883
2897
|
};
|
|
2884
2898
|
/**
|
|
2885
2899
|
* Unregister event listener.
|
|
2886
2900
|
*/
|
|
2887
|
-
off:
|
|
2888
|
-
(event: string, listener:
|
|
2901
|
+
off: WebSocket.Server['off'] & {
|
|
2902
|
+
(event: string, listener: Function): void;
|
|
2889
2903
|
};
|
|
2890
2904
|
}
|
|
2891
2905
|
|
package/dist/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Evan You",
|
|
6
6
|
"description": "Native-ESM powered web dev build tool",
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@ampproject/remapping": "^2.1.2",
|
|
56
|
-
"@babel/parser": "^7.17.
|
|
56
|
+
"@babel/parser": "^7.17.9",
|
|
57
57
|
"@babel/types": "^7.17.0",
|
|
58
58
|
"@jridgewell/trace-mapping": "^0.3.4",
|
|
59
59
|
"@rollup/plugin-alias": "^3.1.9",
|
|
60
|
-
"@rollup/plugin-commonjs": "^21.0.
|
|
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",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@types/node": "^16.11.26",
|
|
75
75
|
"@types/resolve": "^1.20.1",
|
|
76
76
|
"@types/sass": "~1.43.1",
|
|
77
|
-
"@types/stylus": "^0.48.
|
|
77
|
+
"@types/stylus": "^0.48.37",
|
|
78
78
|
"@types/ws": "^8.5.3",
|
|
79
79
|
"@vue/compiler-dom": "^3.2.31",
|
|
80
80
|
"acorn": "^8.7.0",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"debug": "^4.3.4",
|
|
89
89
|
"dotenv": "^14.3.2",
|
|
90
90
|
"dotenv-expand": "^5.1.0",
|
|
91
|
-
"es-module-lexer": "^0.10.
|
|
91
|
+
"es-module-lexer": "^0.10.5",
|
|
92
92
|
"estree-walker": "^2.0.2",
|
|
93
93
|
"etag": "^1.8.1",
|
|
94
94
|
"fast-glob": "^3.2.11",
|
|
@@ -96,15 +96,15 @@
|
|
|
96
96
|
"json5": "^2.2.1",
|
|
97
97
|
"launch-editor-middleware": "^2.3.0",
|
|
98
98
|
"magic-string": "^0.26.1",
|
|
99
|
-
"micromatch": "^4.0.
|
|
99
|
+
"micromatch": "^4.0.5",
|
|
100
100
|
"mrmime": "^1.0.0",
|
|
101
|
-
"node-forge": "^1.3.
|
|
101
|
+
"node-forge": "^1.3.1",
|
|
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
|
|
107
|
-
"postcss-load-config": "^3.1.
|
|
106
|
+
"postcss-import": "^14.1.0",
|
|
107
|
+
"postcss-load-config": "^3.1.4",
|
|
108
108
|
"postcss-modules": "^4.3.1",
|
|
109
109
|
"resolve.exports": "^1.1.0",
|
|
110
110
|
"rollup-plugin-license": "^2.6.1",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"source-map-support": "^0.5.21",
|
|
114
114
|
"strip-ansi": "^6.0.1",
|
|
115
115
|
"terser": "^5.12.1",
|
|
116
|
-
"tsconfck": "^1.2.
|
|
116
|
+
"tsconfck": "^1.2.2",
|
|
117
117
|
"tslib": "^2.3.1",
|
|
118
118
|
"types": "link:./types",
|
|
119
119
|
"ws": "^8.5.0"
|
package/src/client/client.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
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'
|
|
@@ -15,7 +9,7 @@ import '@vite/env'
|
|
|
15
9
|
declare const __BASE__: string
|
|
16
10
|
declare const __HMR_PROTOCOL__: string
|
|
17
11
|
declare const __HMR_HOSTNAME__: string
|
|
18
|
-
declare const __HMR_PORT__: string
|
|
12
|
+
declare const __HMR_PORT__: string
|
|
19
13
|
declare const __HMR_TIMEOUT__: number
|
|
20
14
|
declare const __HMR_ENABLE_OVERLAY__: boolean
|
|
21
15
|
|
|
@@ -24,10 +18,7 @@ console.log('[vite] connecting...')
|
|
|
24
18
|
// use server configuration, then fallback to inference
|
|
25
19
|
const socketProtocol =
|
|
26
20
|
__HMR_PROTOCOL__ || (location.protocol === 'https:' ? 'wss' : 'ws')
|
|
27
|
-
const socketHost = __HMR_PORT__
|
|
28
|
-
? `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__}`
|
|
29
|
-
: `${__HMR_HOSTNAME__ || location.hostname}`
|
|
30
|
-
|
|
21
|
+
const socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__}`
|
|
31
22
|
const socket = new WebSocket(`${socketProtocol}://${socketHost}`, 'vite-hmr')
|
|
32
23
|
const base = __BASE__ || '/'
|
|
33
24
|
const messageBuffer: string[] = []
|
|
@@ -103,7 +94,7 @@ async function handleMessage(payload: HMRPayload) {
|
|
|
103
94
|
})
|
|
104
95
|
break
|
|
105
96
|
case 'custom': {
|
|
106
|
-
notifyListeners(payload.event
|
|
97
|
+
notifyListeners(payload.event, payload.data)
|
|
107
98
|
break
|
|
108
99
|
}
|
|
109
100
|
case 'full-reload':
|
|
@@ -156,19 +147,9 @@ async function handleMessage(payload: HMRPayload) {
|
|
|
156
147
|
}
|
|
157
148
|
}
|
|
158
149
|
|
|
159
|
-
function notifyListeners(
|
|
160
|
-
event: 'vite:beforeUpdate',
|
|
161
|
-
payload: UpdatePayload
|
|
162
|
-
): void
|
|
163
|
-
function notifyListeners(event: 'vite:beforePrune', payload: PrunePayload): void
|
|
164
|
-
function notifyListeners(
|
|
165
|
-
event: 'vite:beforeFullReload',
|
|
166
|
-
payload: FullReloadPayload
|
|
167
|
-
): void
|
|
168
|
-
function notifyListeners(event: 'vite:error', payload: ErrorPayload): void
|
|
169
150
|
function notifyListeners<T extends string>(
|
|
170
|
-
event:
|
|
171
|
-
data:
|
|
151
|
+
event: T,
|
|
152
|
+
data: InferCustomEventPayload<T>
|
|
172
153
|
): void
|
|
173
154
|
function notifyListeners(event: string, data: any): void {
|
|
174
155
|
const cbs = customListenersMap.get(event)
|
|
@@ -391,9 +372,7 @@ const ctxToListenersMap = new Map<
|
|
|
391
372
|
Map<string, ((data: any) => void)[]>
|
|
392
373
|
>()
|
|
393
374
|
|
|
394
|
-
|
|
395
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
396
|
-
export const createHotContext = (ownerPath: string) => {
|
|
375
|
+
export function createHotContext(ownerPath: string): ViteHotContext {
|
|
397
376
|
if (!dataMap.has(ownerPath)) {
|
|
398
377
|
dataMap.set(ownerPath, {})
|
|
399
378
|
}
|
|
@@ -434,12 +413,12 @@ export const createHotContext = (ownerPath: string) => {
|
|
|
434
413
|
hotModulesMap.set(ownerPath, mod)
|
|
435
414
|
}
|
|
436
415
|
|
|
437
|
-
const hot = {
|
|
416
|
+
const hot: ViteHotContext = {
|
|
438
417
|
get data() {
|
|
439
418
|
return dataMap.get(ownerPath)
|
|
440
419
|
},
|
|
441
420
|
|
|
442
|
-
accept(deps
|
|
421
|
+
accept(deps?: any, callback?: any) {
|
|
443
422
|
if (typeof deps === 'function' || !deps) {
|
|
444
423
|
// self-accept: hot.accept(() => {})
|
|
445
424
|
acceptDeps([ownerPath], ([mod]) => deps && deps(mod))
|
|
@@ -460,10 +439,11 @@ export const createHotContext = (ownerPath: string) => {
|
|
|
460
439
|
)
|
|
461
440
|
},
|
|
462
441
|
|
|
463
|
-
dispose(cb
|
|
442
|
+
dispose(cb) {
|
|
464
443
|
disposeMap.set(ownerPath, cb)
|
|
465
444
|
},
|
|
466
445
|
|
|
446
|
+
// @ts-expect-error untyped
|
|
467
447
|
prune(cb: (data: any) => void) {
|
|
468
448
|
pruneMap.set(ownerPath, cb)
|
|
469
449
|
},
|
|
@@ -479,7 +459,7 @@ export const createHotContext = (ownerPath: string) => {
|
|
|
479
459
|
},
|
|
480
460
|
|
|
481
461
|
// custom events
|
|
482
|
-
on
|
|
462
|
+
on(event, cb) {
|
|
483
463
|
const addToMap = (map: Map<string, any[]>) => {
|
|
484
464
|
const existing = map.get(event) || []
|
|
485
465
|
existing.push(cb)
|
|
@@ -489,7 +469,7 @@ export const createHotContext = (ownerPath: string) => {
|
|
|
489
469
|
addToMap(newListeners)
|
|
490
470
|
},
|
|
491
471
|
|
|
492
|
-
send
|
|
472
|
+
send(event, data) {
|
|
493
473
|
messageBuffer.push(JSON.stringify({ type: 'custom', event, data }))
|
|
494
474
|
sendMessageBuffer()
|
|
495
475
|
}
|
package/types/customEvent.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
}
|
package/types/importMeta.d.ts
CHANGED
|
@@ -20,48 +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
|
-
|
|
63
|
-
send(event: string, data?: any): void
|
|
64
|
-
}
|
|
23
|
+
readonly hot?: import('./hot').ViteHotContext
|
|
65
24
|
|
|
66
25
|
readonly env: ImportMetaEnv
|
|
67
26
|
|
|
@@ -77,7 +36,7 @@ interface ImportMeta {
|
|
|
77
36
|
}
|
|
78
37
|
|
|
79
38
|
interface ImportMetaEnv {
|
|
80
|
-
[key: string]:
|
|
39
|
+
[key: string]: any
|
|
81
40
|
BASE_URL: string
|
|
82
41
|
MODE: string
|
|
83
42
|
DEV: boolean
|