vite 2.8.4 → 2.9.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.

Potentially problematic release.


This version of vite might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var build = require('./dep-971d9e33.js');
3
+ var index = require('./dep-429629d5.js');
4
4
  var require$$1 = require('crypto');
5
5
  require('fs');
6
6
  require('path');
@@ -353,7 +353,7 @@ util$1.isNodejs =
353
353
  // is not available.
354
354
  util$1.globalScope = (function() {
355
355
  if(util$1.isNodejs) {
356
- return build.commonjsGlobal;
356
+ return index.commonjsGlobal;
357
357
  }
358
358
 
359
359
  return typeof self === 'undefined' ? window : self;
@@ -19367,12 +19367,12 @@ pki.privateKeyInfoToPem = function(pki, maxline) {
19367
19367
  // this RFC in section 4.1.2.2 requires serial numbers to be positive
19368
19368
  // http://www.ietf.org/rfc/rfc5280.txt
19369
19369
  function toPositiveHex(hexString) {
19370
- let mostSiginficativeHexAsInt = parseInt(hexString[0], 16);
19371
- if (mostSiginficativeHexAsInt < 8) {
19370
+ let mostSignificativeHexAsInt = parseInt(hexString[0], 16);
19371
+ if (mostSignificativeHexAsInt < 8) {
19372
19372
  return hexString;
19373
19373
  }
19374
- mostSiginficativeHexAsInt -= 8;
19375
- return mostSiginficativeHexAsInt.toString() + hexString.substring(1);
19374
+ mostSignificativeHexAsInt -= 8;
19375
+ return mostSignificativeHexAsInt.toString() + hexString.substring(1);
19376
19376
  }
19377
19377
  function createCertificate() {
19378
19378
  const days = 30;
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 build = require('./chunks/dep-971d9e33.js');
4
+ var index = require('./chunks/dep-429629d5.js');
5
5
  var perf_hooks = require('perf_hooks');
6
6
  require('fs');
7
7
  require('path');
@@ -670,7 +670,7 @@ cli
670
670
  .option('-m, --mode <mode>', `[string] set env mode`);
671
671
  // dev
672
672
  cli
673
- .command('[root]') // default command
673
+ .command('[root]', 'start dev server') // default command
674
674
  .alias('serve') // the command is called 'serve' in Vite's API
675
675
  .alias('dev') // alias to align with the script name
676
676
  .option('--host [host]', `[string] specify hostname`)
@@ -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-971d9e33.js'); }).then(function (n) { return n.index$1; });
686
+ const { createServer } = await Promise.resolve().then(function () { return require('./chunks/dep-429629d5.js'); }).then(function (n) { return n.index$1; });
687
687
  try {
688
688
  const server = await createServer({
689
689
  root,
@@ -699,8 +699,8 @@ cli
699
699
  }
700
700
  await server.listen();
701
701
  const info = server.config.logger.info;
702
- info(build.colors.cyan(`\n vite v${require('vite/package.json').version}`) +
703
- build.colors.green(` dev server running at:\n`), {
702
+ info(index.colors.cyan(`\n vite v${require('vite/package.json').version}`) +
703
+ index.colors.green(` dev server running at:\n`), {
704
704
  clear: !server.config.logger.hasWarned
705
705
  });
706
706
  server.printUrls();
@@ -708,17 +708,17 @@ cli
708
708
  if (global.__vite_start_time) {
709
709
  // @ts-ignore
710
710
  const startupDuration = perf_hooks.performance.now() - global.__vite_start_time;
711
- info(`\n ${build.colors.cyan(`ready in ${Math.ceil(startupDuration)}ms.`)}\n`);
711
+ info(`\n ${index.colors.cyan(`ready in ${Math.ceil(startupDuration)}ms.`)}\n`);
712
712
  }
713
713
  }
714
714
  catch (e) {
715
- build.createLogger(options.logLevel).error(build.colors.red(`error when starting dev server:\n${e.stack}`), { error: e });
715
+ index.createLogger(options.logLevel).error(index.colors.red(`error when starting dev server:\n${e.stack}`), { error: e });
716
716
  process.exit(1);
717
717
  }
718
718
  });
719
719
  // build
720
720
  cli
721
- .command('build [root]')
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
724
  .option('--assetsDir <dir>', `[string] directory under outDir to place assets in (default: _assets)`)
@@ -732,10 +732,10 @@ 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: build$1 } = await Promise.resolve().then(function () { return require('./chunks/dep-971d9e33.js'); }).then(function (n) { return n.build$1; });
735
+ const { build } = await Promise.resolve().then(function () { return require('./chunks/dep-429629d5.js'); }).then(function (n) { return n.build$1; });
736
736
  const buildOptions = cleanOptions(options);
737
737
  try {
738
- await build$1({
738
+ await build({
739
739
  root,
740
740
  base: options.base,
741
741
  mode: options.mode,
@@ -746,18 +746,18 @@ cli
746
746
  });
747
747
  }
748
748
  catch (e) {
749
- build.createLogger(options.logLevel).error(build.colors.red(`error during build:\n${e.stack}`), { error: e });
749
+ index.createLogger(options.logLevel).error(index.colors.red(`error during build:\n${e.stack}`), { error: e });
750
750
  process.exit(1);
751
751
  }
752
752
  });
753
753
  // optimize
754
754
  cli
755
- .command('optimize [root]')
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-971d9e33.js'); }).then(function (n) { return n.index; });
758
+ const { optimizeDeps } = await Promise.resolve().then(function () { return require('./chunks/dep-429629d5.js'); }).then(function (n) { return n.index; });
759
759
  try {
760
- const config = await build.resolveConfig({
760
+ const config = await index.resolveConfig({
761
761
  root,
762
762
  base: options.base,
763
763
  configFile: options.config,
@@ -766,19 +766,19 @@ cli
766
766
  await optimizeDeps(config, options.force, true);
767
767
  }
768
768
  catch (e) {
769
- build.createLogger(options.logLevel).error(build.colors.red(`error when optimizing deps:\n${e.stack}`), { error: e });
769
+ index.createLogger(options.logLevel).error(index.colors.red(`error when optimizing deps:\n${e.stack}`), { error: e });
770
770
  process.exit(1);
771
771
  }
772
772
  });
773
773
  cli
774
- .command('preview [root]')
774
+ .command('preview [root]', 'locally preview production build')
775
775
  .option('--host [host]', `[string] specify hostname`)
776
776
  .option('--port <port>', `[number] specify port`)
777
777
  .option('--strictPort', `[boolean] exit if specified port is already in use`)
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-971d9e33.js'); }).then(function (n) { return n.preview$1; });
781
+ const { preview } = await Promise.resolve().then(function () { return require('./chunks/dep-429629d5.js'); }).then(function (n) { return n.preview$1; });
782
782
  try {
783
783
  const server = await preview({
784
784
  root,
@@ -797,7 +797,7 @@ cli
797
797
  server.printUrls();
798
798
  }
799
799
  catch (e) {
800
- build.createLogger(options.logLevel).error(build.colors.red(`error when starting preview server:\n${e.stack}`), { error: e });
800
+ index.createLogger(options.logLevel).error(index.colors.red(`error when starting preview server:\n${e.stack}`), { error: e });
801
801
  process.exit(1);
802
802
  }
803
803
  });
@@ -11,6 +11,7 @@ import { TransformOptions as EsbuildTransformOptions } from 'esbuild';
11
11
  import { EventEmitter } from 'events';
12
12
  import * as events from 'events';
13
13
  import type * as fs from 'fs';
14
+ import type { GetManualChunk } from 'rollup';
14
15
  import * as http from 'http';
15
16
  import type { IncomingMessage } from 'http';
16
17
  import type { InputOptions } from 'rollup';
@@ -267,6 +268,11 @@ export declare interface BuildOptions {
267
268
  watch?: WatcherOptions | null;
268
269
  }
269
270
 
271
+ export declare interface ChunkMetadata {
272
+ importedAssets: Set<string>;
273
+ importedCss: Set<string>;
274
+ }
275
+
270
276
  export declare interface CommonServerOptions {
271
277
  /**
272
278
  * Specify server port. Note if the port is already being used, Vite will
@@ -506,11 +512,19 @@ export declare interface DepOptimizationMetadata {
506
512
  * optimized deps.
507
513
  */
508
514
  browserHash: string;
509
- optimized: Record<string, {
510
- file: string;
511
- src: string;
512
- needsInterop: boolean;
513
- }>;
515
+ /**
516
+ * Metadata for each already optimized dependency
517
+ */
518
+ optimized: Record<string, OptimizedDepInfo>;
519
+ /**
520
+ * Metadata for each newly discovered dependency after processing
521
+ */
522
+ discovered: Record<string, OptimizedDepInfo>;
523
+ /**
524
+ * During optimization, ids can still be resolved to their final location
525
+ * but the bundles may not yet be saved to disk
526
+ */
527
+ processing: Promise<DepOptimizationResult | undefined>;
514
528
  }
515
529
 
516
530
  export declare interface DepOptimizationOptions {
@@ -552,6 +566,31 @@ export declare interface DepOptimizationOptions {
552
566
  * @deprecated use `esbuildOptions.keepNames`
553
567
  */
554
568
  keepNames?: boolean;
569
+ /**
570
+ * List of file extensions that can be optimized. A corresponding esbuild
571
+ * plugin must exist to handle the specific extension.
572
+ *
573
+ * By default, Vite can optimize `.mjs`, `.js`, and `.ts` files. This option
574
+ * allows specifying additional extensions.
575
+ *
576
+ * @experimental
577
+ */
578
+ extensions?: string[];
579
+ }
580
+
581
+ export declare interface DepOptimizationProcessing {
582
+ promise: Promise<DepOptimizationResult | undefined>;
583
+ resolve: (result?: DepOptimizationResult) => void;
584
+ }
585
+
586
+ export declare interface DepOptimizationResult {
587
+ /**
588
+ * After a re-optimization, the internal bundled chunks may change
589
+ * and a full page reload is required if that is the case
590
+ * If the files are stable, we can avoid the reload that is expensive
591
+ * for large applications
592
+ */
593
+ alteredFiles: boolean;
555
594
  }
556
595
 
557
596
  export declare interface ErrorPayload {
@@ -701,7 +740,7 @@ export declare interface HmrContext {
701
740
  export declare interface HmrOptions {
702
741
  protocol?: string;
703
742
  host?: string;
704
- port?: number;
743
+ port?: number | false;
705
744
  clientPort?: number;
706
745
  path?: string;
707
746
  timeout?: number;
@@ -1130,8 +1169,24 @@ export declare class ModuleNode {
1130
1169
 
1131
1170
  export declare function normalizePath(id: string): string;
1132
1171
 
1133
- export declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean, newDeps?: Record<string, string>, // missing imports encountered after server has started
1134
- ssr?: boolean): Promise<DepOptimizationMetadata | null>;
1172
+ export declare interface OptimizedDepInfo {
1173
+ file: string;
1174
+ src: string;
1175
+ needsInterop?: boolean;
1176
+ browserHash?: string;
1177
+ fileHash?: string;
1178
+ /**
1179
+ * During optimization, ids can still be resolved to their final location
1180
+ * but the bundles may not yet be saved to disk
1181
+ */
1182
+ processing: Promise<DepOptimizationResult | undefined>;
1183
+ }
1184
+
1185
+ /**
1186
+ * Used by Vite CLI when running `vite optimize`
1187
+ */
1188
+ export declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean, newDeps?: Record<string, OptimizedDepInfo>, // missing imports encountered after server has started
1189
+ ssr?: boolean): Promise<DepOptimizationMetadata>;
1135
1190
 
1136
1191
  /** Cache for package.json resolution and package.json contents */
1137
1192
  export declare type PackageCache = Map<string, PackageData>;
@@ -1666,6 +1721,18 @@ export declare interface ServerOptions extends CommonServerOptions {
1666
1721
 
1667
1722
  export declare function sortUserPlugins(plugins: (Plugin | Plugin[])[] | undefined): [Plugin[], Plugin[], Plugin[]];
1668
1723
 
1724
+ export declare function splitVendorChunk(options?: {
1725
+ cache?: SplitVendorChunkCache;
1726
+ }): GetManualChunk;
1727
+
1728
+ export declare class SplitVendorChunkCache {
1729
+ cache: Map<string, boolean>;
1730
+ constructor();
1731
+ reset(): void;
1732
+ }
1733
+
1734
+ export declare function splitVendorChunkPlugin(): Plugin;
1735
+
1669
1736
  export declare interface SSROptions {
1670
1737
  external?: string[];
1671
1738
  noExternal?: string | RegExp | (string | RegExp)[] | true;
@@ -2089,7 +2156,9 @@ export declare interface ViteDevServer {
2089
2156
  /**
2090
2157
  * Load a given URL as an instantiated module for SSR.
2091
2158
  */
2092
- ssrLoadModule(url: string): Promise<Record<string, any>>;
2159
+ ssrLoadModule(url: string, opts?: {
2160
+ fixStacktrace?: boolean;
2161
+ }): Promise<Record<string, any>>;
2093
2162
  /**
2094
2163
  * Fix ssr error stacktrace
2095
2164
  */
@@ -2117,9 +2186,7 @@ export declare interface ViteDevServer {
2117
2186
  /* Excluded from this release type: _globImporters */
2118
2187
  /* Excluded from this release type: _restartPromise */
2119
2188
  /* Excluded from this release type: _forceOptimizeOnRestart */
2120
- /* Excluded from this release type: _isRunningOptimizer */
2121
2189
  /* Excluded from this release type: _registerMissingImport */
2122
- /* Excluded from this release type: _pendingReload */
2123
2190
  /* Excluded from this release type: _pendingRequests */
2124
2191
  }
2125
2192
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var build = require('./chunks/dep-971d9e33.js');
5
+ var index = require('./chunks/dep-429629d5.js');
6
6
  require('fs');
7
7
  require('path');
8
8
  require('tty');
@@ -28,24 +28,129 @@ require('child_process');
28
28
  require('worker_threads');
29
29
  require('readline');
30
30
 
31
+ // Use splitVendorChunkPlugin() to get the same manualChunks strategy as Vite 2.7
32
+ // We don't recommend using this strategy as a general solution moving forward
33
+ // splitVendorChunk is a simple index/vendor strategy that was used in Vite
34
+ // until v2.8. It is exposed to let people continue to use it in case it was
35
+ // working well for their setups.
36
+ // The cache needs to be reset on buildStart for watch mode to work correctly
37
+ // Don't use this manualChunks strategy for ssr, lib mode, and 'umd' or 'iife'
38
+ class SplitVendorChunkCache {
39
+ constructor() {
40
+ this.cache = new Map();
41
+ }
42
+ reset() {
43
+ this.cache = new Map();
44
+ }
45
+ }
46
+ function splitVendorChunk(options = {}) {
47
+ var _a;
48
+ const cache = (_a = options.cache) !== null && _a !== void 0 ? _a : new SplitVendorChunkCache();
49
+ return (id, { getModuleInfo }) => {
50
+ if (id.includes('node_modules') &&
51
+ !index.isCSSRequest(id) &&
52
+ staticImportedByEntry(id, getModuleInfo, cache.cache)) {
53
+ return 'vendor';
54
+ }
55
+ };
56
+ }
57
+ function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
58
+ if (cache.has(id)) {
59
+ return cache.get(id);
60
+ }
61
+ if (importStack.includes(id)) {
62
+ // circular deps!
63
+ cache.set(id, false);
64
+ return false;
65
+ }
66
+ const mod = getModuleInfo(id);
67
+ if (!mod) {
68
+ cache.set(id, false);
69
+ return false;
70
+ }
71
+ if (mod.isEntry) {
72
+ cache.set(id, true);
73
+ return true;
74
+ }
75
+ const someImporterIs = mod.importers.some((importer) => staticImportedByEntry(importer, getModuleInfo, cache, importStack.concat(id)));
76
+ cache.set(id, someImporterIs);
77
+ return someImporterIs;
78
+ }
79
+ function splitVendorChunkPlugin() {
80
+ const caches = [];
81
+ function createSplitVendorChunk(output, config) {
82
+ var _a;
83
+ const cache = new SplitVendorChunkCache();
84
+ caches.push(cache);
85
+ const build = (_a = config.build) !== null && _a !== void 0 ? _a : {};
86
+ const format = output === null || output === void 0 ? void 0 : output.format;
87
+ if (!build.ssr && !build.lib && format !== 'umd' && format !== 'iife') {
88
+ return splitVendorChunk({ cache });
89
+ }
90
+ }
91
+ return {
92
+ name: 'vite:split-vendor-chunk',
93
+ config(config) {
94
+ var _a, _b;
95
+ let outputs = (_b = (_a = config === null || config === void 0 ? void 0 : config.build) === null || _a === void 0 ? void 0 : _a.rollupOptions) === null || _b === void 0 ? void 0 : _b.output;
96
+ if (outputs) {
97
+ outputs = Array.isArray(outputs) ? outputs : [outputs];
98
+ for (const output of outputs) {
99
+ const viteManualChunks = createSplitVendorChunk(output, config);
100
+ if (viteManualChunks) {
101
+ if (output.manualChunks) {
102
+ if (typeof output.manualChunks === 'function') {
103
+ const userManualChunks = output.manualChunks;
104
+ output.manualChunks = (id, api) => {
105
+ var _a;
106
+ return (_a = userManualChunks(id, api)) !== null && _a !== void 0 ? _a : viteManualChunks(id, api);
107
+ };
108
+ }
109
+ // else, leave the object form of manualChunks untouched, as
110
+ // we can't safely replicate rollup handling.
111
+ }
112
+ else {
113
+ output.manualChunks = viteManualChunks;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ else {
119
+ return {
120
+ build: {
121
+ rollupOptions: {
122
+ output: {
123
+ manualChunks: createSplitVendorChunk({}, config)
124
+ }
125
+ }
126
+ }
127
+ };
128
+ }
129
+ },
130
+ buildStart() {
131
+ caches.forEach((cache) => cache.reset());
132
+ }
133
+ };
134
+ }
31
135
 
32
-
33
- exports.build = build.build;
34
- exports.createLogger = build.createLogger;
35
- exports.createServer = build.createServer;
36
- exports.defineConfig = build.defineConfig;
37
- exports.loadConfigFromFile = build.loadConfigFromFile;
38
- exports.loadEnv = build.loadEnv;
39
- exports.mergeConfig = build.mergeConfig;
40
- exports.normalizePath = build.normalizePath;
41
- exports.optimizeDeps = build.optimizeDeps;
42
- exports.preview = build.preview;
43
- exports.printHttpServerUrls = build.printHttpServerUrls;
44
- exports.resolveConfig = build.resolveConfig;
45
- exports.resolveEnvPrefix = build.resolveEnvPrefix;
46
- exports.resolvePackageData = build.resolvePackageData;
47
- exports.resolvePackageEntry = build.resolvePackageEntry;
48
- exports.searchForWorkspaceRoot = build.searchForWorkspaceRoot;
49
- exports.send = build.send;
50
- exports.sortUserPlugins = build.sortUserPlugins;
51
- exports.transformWithEsbuild = build.transformWithEsbuild;
136
+ exports.build = index.build;
137
+ exports.createLogger = index.createLogger;
138
+ exports.createServer = index.createServer;
139
+ exports.defineConfig = index.defineConfig;
140
+ exports.loadConfigFromFile = index.loadConfigFromFile;
141
+ exports.loadEnv = index.loadEnv;
142
+ exports.mergeConfig = index.mergeConfig;
143
+ exports.normalizePath = index.normalizePath;
144
+ exports.optimizeDeps = index.optimizeDeps;
145
+ exports.preview = index.preview;
146
+ exports.printHttpServerUrls = index.printHttpServerUrls;
147
+ exports.resolveConfig = index.resolveConfig;
148
+ exports.resolveEnvPrefix = index.resolveEnvPrefix;
149
+ exports.resolvePackageData = index.resolvePackageData;
150
+ exports.resolvePackageEntry = index.resolvePackageEntry;
151
+ exports.searchForWorkspaceRoot = index.searchForWorkspaceRoot;
152
+ exports.send = index.send;
153
+ exports.sortUserPlugins = index.sortUserPlugins;
154
+ exports.transformWithEsbuild = index.transformWithEsbuild;
155
+ exports.splitVendorChunk = splitVendorChunk;
156
+ exports.splitVendorChunkPlugin = splitVendorChunkPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "2.8.4",
3
+ "version": "2.9.0-beta.0",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "description": "Native-ESM powered web dev build tool",
@@ -55,6 +55,7 @@
55
55
  "@ampproject/remapping": "^2.1.0",
56
56
  "@babel/parser": "^7.17.0",
57
57
  "@babel/types": "^7.17.0",
58
+ "@jridgewell/trace-mapping": "^0.3.2",
58
59
  "@rollup/plugin-alias": "^3.1.9",
59
60
  "@rollup/plugin-commonjs": "^21.0.1",
60
61
  "@rollup/plugin-dynamic-import-vars": "^1.4.2",
@@ -79,7 +80,6 @@
79
80
  "acorn": "^8.7.0",
80
81
  "cac": "6.7.9",
81
82
  "chokidar": "^3.5.3",
82
- "compression": "^1.7.4",
83
83
  "connect": "^3.7.0",
84
84
  "connect-history-api-fallback": "^1.6.0",
85
85
  "convert-source-map": "^1.8.0",
@@ -104,16 +104,15 @@
104
104
  "periscopic": "^2.0.3",
105
105
  "picocolors": "^1.0.0",
106
106
  "postcss-import": "^14.0.2",
107
- "postcss-load-config": "^3.1.1",
107
+ "postcss-load-config": "^3.1.3",
108
108
  "postcss-modules": "^4.3.0",
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",
113
112
  "source-map-support": "^0.5.21",
114
113
  "strip-ansi": "^6.0.1",
115
114
  "terser": "^5.10.0",
116
- "tsconfck": "1.1.2",
115
+ "tsconfck": "^1.2.0",
117
116
  "tslib": "^2.3.1",
118
117
  "types": "link:./types",
119
118
  "ws": "^8.5.0"
@@ -15,7 +15,7 @@ import '@vite/env'
15
15
  declare const __BASE__: string
16
16
  declare const __HMR_PROTOCOL__: string
17
17
  declare const __HMR_HOSTNAME__: string
18
- declare const __HMR_PORT__: string
18
+ declare const __HMR_PORT__: string | false
19
19
  declare const __HMR_TIMEOUT__: number
20
20
  declare const __HMR_ENABLE_OVERLAY__: boolean
21
21
 
@@ -24,7 +24,10 @@ console.log('[vite] connecting...')
24
24
  // use server configuration, then fallback to inference
25
25
  const socketProtocol =
26
26
  __HMR_PROTOCOL__ || (location.protocol === 'https:' ? 'wss' : 'ws')
27
- const socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__}`
27
+ const socketHost = __HMR_PORT__
28
+ ? `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__}`
29
+ : `${__HMR_HOSTNAME__ || location.hostname}`
30
+
28
31
  const socket = new WebSocket(`${socketProtocol}://${socketHost}`, 'vite-hmr')
29
32
  const base = __BASE__ || '/'
30
33
 
@@ -214,9 +217,14 @@ async function waitForSuccessfulPing(ms = 1000) {
214
217
  // eslint-disable-next-line no-constant-condition
215
218
  while (true) {
216
219
  try {
217
- await fetch(`${base}__vite_ping`)
218
- break
220
+ const pingResponse = await fetch(`${base}__vite_ping`)
221
+
222
+ // success - 2xx status code
223
+ if (pingResponse.ok) break
224
+ // failure - non-2xx status code
225
+ else throw new Error()
219
226
  } catch (e) {
227
+ // wait ms before attempting to ping again
220
228
  await new Promise((resolve) => setTimeout(resolve, ms))
221
229
  }
222
230
  }
@@ -254,7 +262,7 @@ export function updateStyle(id: string, content: string): void {
254
262
  if (!style) {
255
263
  style = new CSSStyleSheet()
256
264
  style.replaceSync(content)
257
- // @ts-ignore
265
+ // @ts-expect-error: using experimental API
258
266
  document.adoptedStyleSheets = [...document.adoptedStyleSheets, style]
259
267
  } else {
260
268
  style.replaceSync(content)
@@ -281,7 +289,7 @@ export function removeStyle(id: string): void {
281
289
  const style = sheetsMap.get(id)
282
290
  if (style) {
283
291
  if (style instanceof CSSStyleSheet) {
284
- // @ts-ignore
292
+ // @ts-expect-error: using experimental API
285
293
  document.adoptedStyleSheets = document.adoptedStyleSheets.filter(
286
294
  (s: CSSStyleSheet) => s !== style
287
295
  )
@@ -4,10 +4,14 @@
4
4
 
5
5
  /* eslint-disable @typescript-eslint/consistent-type-imports */
6
6
 
7
- // Duplicate import('../src/node/importGlob').AssertOptions
8
- // Avoid breaking the production client type because this file is referenced
9
- // in vite/client.d.ts and in production src/node/importGlob.ts doesn't exist
10
- interface AssertOptions {
7
+ // Duplicate of import('../src/node/importGlob').GlobOptions in order to
8
+ // avoid breaking the production client type. Because this file is referenced
9
+ // in vite/client.d.ts and in production src/node/importGlob.ts doesn't exist.
10
+ interface GlobOptions {
11
+ as?: string
12
+ /**
13
+ * @deprecated
14
+ */
11
15
  assert?: {
12
16
  type: string
13
17
  }
@@ -61,12 +65,12 @@ interface ImportMeta {
61
65
 
62
66
  glob<Module = { [key: string]: any }>(
63
67
  pattern: string,
64
- options?: AssertOptions
68
+ options?: GlobOptions
65
69
  ): Record<string, () => Promise<Module>>
66
70
 
67
71
  globEager<Module = { [key: string]: any }>(
68
72
  pattern: string,
69
- options?: AssertOptions
73
+ options?: GlobOptions
70
74
  ): Record<string, Module>
71
75
  }
72
76
 
package/types/shims.d.ts CHANGED
@@ -93,11 +93,6 @@ declare module 'micromatch' {
93
93
  ): boolean
94
94
  }
95
95
 
96
- declare module 'compression' {
97
- function compression(): any
98
- export default compression
99
- }
100
-
101
96
  // LESS' types somewhat references this which doesn't make sense in Node,
102
97
  // so we have to shim it
103
98
  declare interface HTMLLinkElement {}