vite 2.9.0-beta.9 → 2.9.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.
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-277ed9f7.js} +1 -1
- package/dist/node/chunks/{dep-368120f8.js → dep-57123445.js} +1 -1
- package/dist/node/chunks/{dep-f5b7cdd7.js → dep-8db0e223.js} +36463 -33805
- package/dist/node/chunks/{dep-5633cdf8.js → dep-bcc0af00.js} +103 -25
- package/dist/node/chunks/{dep-051d3e69.js → dep-e67ca846.js} +1 -1
- package/dist/node/cli.js +5 -5
- package/dist/node/index.d.ts +14 -4
- package/dist/node/index.js +1 -1
- package/package.json +4 -4
- 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 +1 -42
|
@@ -39,6 +39,14 @@ var joinMedia$1 = function (parentMedia, childMedia) {
|
|
|
39
39
|
return media
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
var joinLayer$1 = function (parentLayer, childLayer) {
|
|
43
|
+
if (!parentLayer.length && childLayer.length) return childLayer
|
|
44
|
+
if (parentLayer.length && !childLayer.length) return parentLayer
|
|
45
|
+
if (!parentLayer.length && !childLayer.length) return []
|
|
46
|
+
|
|
47
|
+
return parentLayer.concat(childLayer)
|
|
48
|
+
};
|
|
49
|
+
|
|
42
50
|
// external tooling
|
|
43
51
|
const resolve$1 = resolve__default;
|
|
44
52
|
|
|
@@ -330,6 +338,7 @@ var parseStatements$1 = function (result, styles) {
|
|
|
330
338
|
type: "nodes",
|
|
331
339
|
nodes,
|
|
332
340
|
media: [],
|
|
341
|
+
layer: [],
|
|
333
342
|
});
|
|
334
343
|
nodes = [];
|
|
335
344
|
}
|
|
@@ -342,6 +351,7 @@ var parseStatements$1 = function (result, styles) {
|
|
|
342
351
|
type: "nodes",
|
|
343
352
|
nodes,
|
|
344
353
|
media: [],
|
|
354
|
+
layer: [],
|
|
345
355
|
});
|
|
346
356
|
}
|
|
347
357
|
|
|
@@ -354,6 +364,7 @@ function parseMedia(result, atRule) {
|
|
|
354
364
|
type: "media",
|
|
355
365
|
node: atRule,
|
|
356
366
|
media: split(params, 0),
|
|
367
|
+
layer: [],
|
|
357
368
|
}
|
|
358
369
|
}
|
|
359
370
|
|
|
@@ -367,6 +378,7 @@ function parseCharset(result, atRule) {
|
|
|
367
378
|
type: "charset",
|
|
368
379
|
node: atRule,
|
|
369
380
|
media: [],
|
|
381
|
+
layer: [],
|
|
370
382
|
}
|
|
371
383
|
}
|
|
372
384
|
|
|
@@ -377,10 +389,12 @@ function parseImport(result, atRule) {
|
|
|
377
389
|
if (
|
|
378
390
|
prev.type !== "comment" &&
|
|
379
391
|
(prev.type !== "atrule" ||
|
|
380
|
-
(prev.name !== "import" &&
|
|
392
|
+
(prev.name !== "import" &&
|
|
393
|
+
prev.name !== "charset" &&
|
|
394
|
+
!(prev.name === "layer" && !prev.nodes)))
|
|
381
395
|
) {
|
|
382
396
|
return result.warn(
|
|
383
|
-
"@import must precede all other statements (besides @charset)",
|
|
397
|
+
"@import must precede all other statements (besides @charset or empty @layer)",
|
|
384
398
|
{ node: atRule }
|
|
385
399
|
)
|
|
386
400
|
}
|
|
@@ -401,6 +415,7 @@ function parseImport(result, atRule) {
|
|
|
401
415
|
type: "import",
|
|
402
416
|
node: atRule,
|
|
403
417
|
media: [],
|
|
418
|
+
layer: [],
|
|
404
419
|
};
|
|
405
420
|
|
|
406
421
|
// prettier-ignore
|
|
@@ -426,11 +441,31 @@ function parseImport(result, atRule) {
|
|
|
426
441
|
else stmt.uri = params[0].nodes[0].value;
|
|
427
442
|
stmt.fullUri = stringify(params[0]);
|
|
428
443
|
|
|
429
|
-
|
|
430
|
-
|
|
444
|
+
let remainder = params;
|
|
445
|
+
if (remainder.length > 2) {
|
|
446
|
+
if (
|
|
447
|
+
(remainder[2].type === "word" || remainder[2].type === "function") &&
|
|
448
|
+
remainder[2].value === "layer"
|
|
449
|
+
) {
|
|
450
|
+
if (remainder[1].type !== "space") {
|
|
451
|
+
return result.warn("Invalid import layer statement", { node: atRule })
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (remainder[2].nodes) {
|
|
455
|
+
stmt.layer = [stringify(remainder[2].nodes)];
|
|
456
|
+
} else {
|
|
457
|
+
stmt.layer = [""];
|
|
458
|
+
}
|
|
459
|
+
remainder = remainder.slice(2);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (remainder.length > 2) {
|
|
464
|
+
if (remainder[1].type !== "space") {
|
|
431
465
|
return result.warn("Invalid import media statement", { node: atRule })
|
|
432
466
|
}
|
|
433
|
-
|
|
467
|
+
|
|
468
|
+
stmt.media = split(remainder, 2);
|
|
434
469
|
}
|
|
435
470
|
|
|
436
471
|
return stmt
|
|
@@ -441,6 +476,7 @@ const path = path__default;
|
|
|
441
476
|
|
|
442
477
|
// internal tooling
|
|
443
478
|
const joinMedia = joinMedia$1;
|
|
479
|
+
const joinLayer = joinLayer$1;
|
|
444
480
|
const resolveId = resolveId$1;
|
|
445
481
|
const loadContent = loadContent$1;
|
|
446
482
|
const processContent = processContent$1;
|
|
@@ -483,11 +519,13 @@ function AtImport(options) {
|
|
|
483
519
|
throw new Error("plugins option must be an array")
|
|
484
520
|
}
|
|
485
521
|
|
|
486
|
-
return parseStyles(result, styles, options, state, []).then(
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
522
|
+
return parseStyles(result, styles, options, state, [], []).then(
|
|
523
|
+
bundle => {
|
|
524
|
+
applyRaws(bundle);
|
|
525
|
+
applyMedia(bundle);
|
|
526
|
+
applyStyles(bundle, styles);
|
|
527
|
+
}
|
|
528
|
+
)
|
|
491
529
|
|
|
492
530
|
function applyRaws(bundle) {
|
|
493
531
|
bundle.forEach((stmt, index) => {
|
|
@@ -505,21 +543,60 @@ function AtImport(options) {
|
|
|
505
543
|
|
|
506
544
|
function applyMedia(bundle) {
|
|
507
545
|
bundle.forEach(stmt => {
|
|
508
|
-
if (
|
|
546
|
+
if (
|
|
547
|
+
(!stmt.media.length && !stmt.layer.length) ||
|
|
548
|
+
stmt.type === "charset"
|
|
549
|
+
) {
|
|
550
|
+
return
|
|
551
|
+
}
|
|
552
|
+
|
|
509
553
|
if (stmt.type === "import") {
|
|
510
554
|
stmt.node.params = `${stmt.fullUri} ${stmt.media.join(", ")}`;
|
|
511
|
-
} else if (stmt.type === "media")
|
|
555
|
+
} else if (stmt.type === "media") {
|
|
512
556
|
stmt.node.params = stmt.media.join(", ");
|
|
513
|
-
else {
|
|
557
|
+
} else {
|
|
514
558
|
const { nodes } = stmt;
|
|
515
559
|
const { parent } = nodes[0];
|
|
516
|
-
const mediaNode = atRule({
|
|
517
|
-
name: "media",
|
|
518
|
-
params: stmt.media.join(", "),
|
|
519
|
-
source: parent.source,
|
|
520
|
-
});
|
|
521
560
|
|
|
522
|
-
|
|
561
|
+
let outerAtRule;
|
|
562
|
+
let innerAtRule;
|
|
563
|
+
if (stmt.media.length && stmt.layer.length) {
|
|
564
|
+
const mediaNode = atRule({
|
|
565
|
+
name: "media",
|
|
566
|
+
params: stmt.media.join(", "),
|
|
567
|
+
source: parent.source,
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
const layerNode = atRule({
|
|
571
|
+
name: "layer",
|
|
572
|
+
params: stmt.layer.filter(layer => layer !== "").join("."),
|
|
573
|
+
source: parent.source,
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
mediaNode.append(layerNode);
|
|
577
|
+
innerAtRule = layerNode;
|
|
578
|
+
outerAtRule = mediaNode;
|
|
579
|
+
} else if (stmt.media.length) {
|
|
580
|
+
const mediaNode = atRule({
|
|
581
|
+
name: "media",
|
|
582
|
+
params: stmt.media.join(", "),
|
|
583
|
+
source: parent.source,
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
innerAtRule = mediaNode;
|
|
587
|
+
outerAtRule = mediaNode;
|
|
588
|
+
} else if (stmt.layer.length) {
|
|
589
|
+
const layerNode = atRule({
|
|
590
|
+
name: "layer",
|
|
591
|
+
params: stmt.layer.filter(layer => layer !== "").join("."),
|
|
592
|
+
source: parent.source,
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
innerAtRule = layerNode;
|
|
596
|
+
outerAtRule = layerNode;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
parent.insertBefore(nodes[0], outerAtRule);
|
|
523
600
|
|
|
524
601
|
// remove nodes
|
|
525
602
|
nodes.forEach(node => {
|
|
@@ -529,11 +606,11 @@ function AtImport(options) {
|
|
|
529
606
|
// better output
|
|
530
607
|
nodes[0].raws.before = nodes[0].raws.before || "\n";
|
|
531
608
|
|
|
532
|
-
// wrap new rules with media query
|
|
533
|
-
|
|
609
|
+
// wrap new rules with media query and/or layer at rule
|
|
610
|
+
innerAtRule.append(nodes);
|
|
534
611
|
|
|
535
612
|
stmt.type = "media";
|
|
536
|
-
stmt.node =
|
|
613
|
+
stmt.node = outerAtRule;
|
|
537
614
|
delete stmt.nodes;
|
|
538
615
|
}
|
|
539
616
|
});
|
|
@@ -556,7 +633,7 @@ function AtImport(options) {
|
|
|
556
633
|
});
|
|
557
634
|
}
|
|
558
635
|
|
|
559
|
-
function parseStyles(result, styles, options, state, media) {
|
|
636
|
+
function parseStyles(result, styles, options, state, media, layer) {
|
|
560
637
|
const statements = parseStatements(result, styles);
|
|
561
638
|
|
|
562
639
|
return Promise.resolve(statements)
|
|
@@ -565,6 +642,7 @@ function AtImport(options) {
|
|
|
565
642
|
return stmts.reduce((promise, stmt) => {
|
|
566
643
|
return promise.then(() => {
|
|
567
644
|
stmt.media = joinMedia(media, stmt.media || []);
|
|
645
|
+
stmt.layer = joinLayer(layer, stmt.layer || []);
|
|
568
646
|
|
|
569
647
|
// skip protocol base uri (protocol://url) or protocol-relative
|
|
570
648
|
if (
|
|
@@ -676,7 +754,7 @@ function AtImport(options) {
|
|
|
676
754
|
|
|
677
755
|
function loadImportContent(result, stmt, filename, options, state) {
|
|
678
756
|
const atRule = stmt.node;
|
|
679
|
-
const { media } = stmt;
|
|
757
|
+
const { media, layer } = stmt;
|
|
680
758
|
if (options.skipDuplicates) {
|
|
681
759
|
// skip files already imported at the same scope
|
|
682
760
|
if (
|
|
@@ -724,7 +802,7 @@ function AtImport(options) {
|
|
|
724
802
|
}
|
|
725
803
|
|
|
726
804
|
// recursion: import @import from imported file
|
|
727
|
-
return parseStyles(result, styles, options, state, media)
|
|
805
|
+
return parseStyles(result, styles, options, state, media, layer)
|
|
728
806
|
})
|
|
729
807
|
}
|
|
730
808
|
)
|
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-8db0e223.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-8db0e223.js'); }).then(function (n) { return n.index$1; });
|
|
687
687
|
try {
|
|
688
688
|
const server = await createServer({
|
|
689
689
|
root,
|
|
@@ -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-8db0e223.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-8db0e223.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-8db0e223.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
|
@@ -495,6 +495,13 @@ export declare interface CSSOptions {
|
|
|
495
495
|
devSourcemap?: boolean;
|
|
496
496
|
}
|
|
497
497
|
|
|
498
|
+
export declare interface CustomEventMap {
|
|
499
|
+
'vite:beforeUpdate': UpdatePayload
|
|
500
|
+
'vite:beforePrune': PrunePayload
|
|
501
|
+
'vite:beforeFullReload': FullReloadPayload
|
|
502
|
+
'vite:error': ErrorPayload
|
|
503
|
+
}
|
|
504
|
+
|
|
498
505
|
export declare interface CustomPayload {
|
|
499
506
|
type: 'custom'
|
|
500
507
|
event: string
|
|
@@ -755,7 +762,7 @@ export declare interface HmrContext {
|
|
|
755
762
|
export declare interface HmrOptions {
|
|
756
763
|
protocol?: string;
|
|
757
764
|
host?: string;
|
|
758
|
-
port?: number
|
|
765
|
+
port?: number;
|
|
759
766
|
clientPort?: number;
|
|
760
767
|
path?: string;
|
|
761
768
|
timeout?: number;
|
|
@@ -1030,6 +1037,9 @@ export declare type IndexHtmlTransformResult = string | HtmlTagDescriptor[] | {
|
|
|
1030
1037
|
tags: HtmlTagDescriptor[];
|
|
1031
1038
|
};
|
|
1032
1039
|
|
|
1040
|
+
export declare type InferCustomEventPayload<T extends string> =
|
|
1041
|
+
T extends keyof CustomEventMap ? CustomEventMap[T] : any
|
|
1042
|
+
|
|
1033
1043
|
export declare interface InlineConfig extends UserConfig {
|
|
1034
1044
|
configFile?: string | false;
|
|
1035
1045
|
envFile?: false;
|
|
@@ -2870,7 +2880,7 @@ export declare interface WebSocketServer {
|
|
|
2870
2880
|
/**
|
|
2871
2881
|
* Send custom event
|
|
2872
2882
|
*/
|
|
2873
|
-
send(event:
|
|
2883
|
+
send<T extends string>(event: T, payload?: InferCustomEventPayload<T>): void;
|
|
2874
2884
|
/**
|
|
2875
2885
|
* Disconnect all clients and terminate the server.
|
|
2876
2886
|
*/
|
|
@@ -2879,13 +2889,13 @@ export declare interface WebSocketServer {
|
|
|
2879
2889
|
* Handle custom event emitted by `import.meta.hot.send`
|
|
2880
2890
|
*/
|
|
2881
2891
|
on: WebSocketServer_2['on'] & {
|
|
2882
|
-
(event:
|
|
2892
|
+
<T extends string>(event: T, listener: WebSocketCustomListener<InferCustomEventPayload<T>>): void;
|
|
2883
2893
|
};
|
|
2884
2894
|
/**
|
|
2885
2895
|
* Unregister event listener.
|
|
2886
2896
|
*/
|
|
2887
2897
|
off: WebSocketServer_2['off'] & {
|
|
2888
|
-
(event: string, listener:
|
|
2898
|
+
(event: string, listener: Function): void;
|
|
2889
2899
|
};
|
|
2890
2900
|
}
|
|
2891
2901
|
|
package/dist/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite",
|
|
3
|
-
"version": "2.9.0
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Evan You",
|
|
6
6
|
"description": "Native-ESM powered web dev build tool",
|
|
@@ -57,7 +57,7 @@
|
|
|
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",
|
|
@@ -96,14 +96,14 @@
|
|
|
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
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
|
|
106
|
+
"postcss-import": "^14.1.0",
|
|
107
107
|
"postcss-load-config": "^3.1.3",
|
|
108
108
|
"postcss-modules": "^4.3.1",
|
|
109
109
|
"resolve.exports": "^1.1.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
|
|