vite 5.1.0-beta.5 → 5.1.0-beta.7
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.
- package/dist/client/client.mjs +8 -0
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/chunks/{dep-Y86Adl1p.js → dep-G1t0FnMB.js} +249 -50
- package/dist/node/chunks/{dep-AgYU8wIQ.js → dep-go6jvlFO.js} +1 -1
- package/dist/node/chunks/{dep-JW1Wr5se.js → dep-ma2Y1b9q.js} +1 -1
- package/dist/node/cli.js +6 -6
- package/dist/node/index.d.ts +76 -3
- package/dist/node/index.js +110 -5
- package/dist/node/runtime.d.ts +12 -0
- package/dist/node/runtime.js +1614 -0
- package/dist/node/types.d-jgA8ss1A.d.ts +324 -0
- package/package.json +13 -2
- package/types/hmrPayload.d.ts +2 -0
package/dist/node/index.d.ts
CHANGED
@@ -15,6 +15,8 @@ import * as url from 'node:url';
|
|
15
15
|
import { URL } from 'node:url';
|
16
16
|
import * as stream from 'node:stream';
|
17
17
|
import { Duplex, DuplexOptions } from 'node:stream';
|
18
|
+
import { F as FetchResult, V as ViteRuntimeOptions, H as HMRLogger, a as ViteModuleRunner, b as ViteRuntime, c as HMRRuntimeConnection } from './types.d-jgA8ss1A.js';
|
19
|
+
export { d as FetchFunction } from './types.d-jgA8ss1A.js';
|
18
20
|
import { SecureContextOptions } from 'node:tls';
|
19
21
|
import { ZlibOptions } from 'node:zlib';
|
20
22
|
import { HMRPayload, CustomPayload } from '../../types/hmrPayload.js';
|
@@ -26,6 +28,7 @@ export { TransformOptions as EsbuildTransformOptions, version as esbuildVersion
|
|
26
28
|
import * as PostCSS from 'postcss';
|
27
29
|
export { GeneralImportGlobOptions, ImportGlobFunction, ImportGlobOptions, KnownAsTypeMap } from '../../types/importGlob.js';
|
28
30
|
export { ChunkMetadata } from '../../types/metadata.js';
|
31
|
+
import '../../types/hot.js';
|
29
32
|
|
30
33
|
interface Alias {
|
31
34
|
find: string | RegExp
|
@@ -72,6 +75,19 @@ declare class FSWatcher extends EventEmitter implements fs.FSWatcher {
|
|
72
75
|
*/
|
73
76
|
constructor(options?: WatchOptions)
|
74
77
|
|
78
|
+
/**
|
79
|
+
* When called, requests that the Node.js event loop not exit so long as the fs.FSWatcher is active.
|
80
|
+
* Calling watcher.ref() multiple times will have no effect.
|
81
|
+
*/
|
82
|
+
ref(): this
|
83
|
+
|
84
|
+
/**
|
85
|
+
* When called, the active fs.FSWatcher object will not require the Node.js event loop to remain active.
|
86
|
+
* If there is no other activity keeping the event loop running, the process may exit before the fs.FSWatcher object's callback is invoked.
|
87
|
+
* Calling watcher.unref() multiple times will have no effect.
|
88
|
+
*/
|
89
|
+
unref(): this
|
90
|
+
|
75
91
|
/**
|
76
92
|
* Add files, directories, or glob patterns for tracking. Takes an array of strings or just one
|
77
93
|
* string.
|
@@ -1487,6 +1503,12 @@ interface HMRBroadcaster extends Omit<HMRChannel, 'close' | 'name'> {
|
|
1487
1503
|
addChannel(connection: HMRChannel): HMRBroadcaster;
|
1488
1504
|
close(): Promise<unknown[]>;
|
1489
1505
|
}
|
1506
|
+
interface ServerHMRChannel extends HMRChannel {
|
1507
|
+
api: {
|
1508
|
+
innerEmitter: EventEmitter;
|
1509
|
+
outsideEmitter: EventEmitter;
|
1510
|
+
};
|
1511
|
+
}
|
1490
1512
|
|
1491
1513
|
type WebSocketCustomListener<T> = (data: T, client: WebSocketClient) => void;
|
1492
1514
|
interface WebSocketServer extends HMRChannel {
|
@@ -1623,10 +1645,10 @@ interface FileSystemServeOptions {
|
|
1623
1645
|
*/
|
1624
1646
|
deny?: string[];
|
1625
1647
|
/**
|
1626
|
-
* Enable caching of fs calls.
|
1648
|
+
* Enable caching of fs calls. It is enabled by default if no custom watch ignored patterns are provided.
|
1627
1649
|
*
|
1628
1650
|
* @experimental
|
1629
|
-
* @default
|
1651
|
+
* @default undefined
|
1630
1652
|
*/
|
1631
1653
|
cachedChecks?: boolean;
|
1632
1654
|
}
|
@@ -1709,6 +1731,11 @@ interface ViteDevServer {
|
|
1709
1731
|
ssrLoadModule(url: string, opts?: {
|
1710
1732
|
fixStacktrace?: boolean;
|
1711
1733
|
}): Promise<Record<string, any>>;
|
1734
|
+
/**
|
1735
|
+
* Fetch information about the module for Vite SSR runtime.
|
1736
|
+
* @experimental
|
1737
|
+
*/
|
1738
|
+
ssrFetchModule(id: string, importer?: string): Promise<FetchResult>;
|
1712
1739
|
/**
|
1713
1740
|
* Returns a fixed version of the given stack
|
1714
1741
|
*/
|
@@ -3367,6 +3394,16 @@ declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: string, c
|
|
3367
3394
|
|
3368
3395
|
declare function buildErrorMessage(err: RollupError, args?: string[], includeStack?: boolean): string;
|
3369
3396
|
|
3397
|
+
interface FetchModuleOptions {
|
3398
|
+
inlineSourceMap?: boolean;
|
3399
|
+
processSourceMap?<T extends NonNullable<TransformResult['map']>>(map: T): T;
|
3400
|
+
}
|
3401
|
+
/**
|
3402
|
+
* Fetch module information for Vite runtime.
|
3403
|
+
* @experimental
|
3404
|
+
*/
|
3405
|
+
declare function fetchModule(server: ViteDevServer, url: string, importer?: string, options?: FetchModuleOptions): Promise<FetchResult>;
|
3406
|
+
|
3370
3407
|
declare const VERSION: string;
|
3371
3408
|
|
3372
3409
|
declare const isCSSRequest: (request: string) => boolean;
|
@@ -3427,4 +3464,40 @@ interface ManifestChunk {
|
|
3427
3464
|
dynamicImports?: string[];
|
3428
3465
|
}
|
3429
3466
|
|
3430
|
-
|
3467
|
+
/**
|
3468
|
+
* @experimental
|
3469
|
+
*/
|
3470
|
+
interface MainThreadRuntimeOptions extends Omit<ViteRuntimeOptions, 'root' | 'fetchModule' | 'hmr'> {
|
3471
|
+
/**
|
3472
|
+
* Disable HMR or configure HMR logger.
|
3473
|
+
*/
|
3474
|
+
hmr?: false | {
|
3475
|
+
logger?: false | HMRLogger;
|
3476
|
+
};
|
3477
|
+
/**
|
3478
|
+
* Provide a custom module runner. This controls how the code is executed.
|
3479
|
+
*/
|
3480
|
+
runner?: ViteModuleRunner;
|
3481
|
+
}
|
3482
|
+
/**
|
3483
|
+
* Create an instance of the Vite SSR runtime that support HMR.
|
3484
|
+
* @experimental
|
3485
|
+
*/
|
3486
|
+
declare function createViteRuntime(server: ViteDevServer, options?: MainThreadRuntimeOptions): Promise<ViteRuntime>;
|
3487
|
+
|
3488
|
+
/**
|
3489
|
+
* The connector class to establish HMR communication between the server and the Vite runtime.
|
3490
|
+
* @experimental
|
3491
|
+
*/
|
3492
|
+
declare class ServerHMRConnector implements HMRRuntimeConnection {
|
3493
|
+
private handlers;
|
3494
|
+
private hmrChannel;
|
3495
|
+
private hmrClient;
|
3496
|
+
private connected;
|
3497
|
+
constructor(server: ViteDevServer);
|
3498
|
+
isReady(): boolean;
|
3499
|
+
send(message: string): void;
|
3500
|
+
onUpdate(handler: (payload: HMRPayload) => void): void;
|
3501
|
+
}
|
3502
|
+
|
3503
|
+
export { type Alias, type AliasOptions, type AnymatchFn, type AnymatchPattern, type AppType, type AwaitWriteFinishOptions, type BindCLIShortcutsOptions, type BuildOptions, type CLIShortcut, type CSSModulesOptions, type CSSOptions, type CommonServerOptions, type ConfigEnv, Connect, type CorsOptions, type CorsOrigin, type DepOptimizationConfig, type DepOptimizationMetadata, type DepOptimizationOptions, type ESBuildOptions, type ESBuildTransformResult, type ExperimentalOptions, type ExportsData, FSWatcher, type FetchModuleOptions, type FileSystemServeOptions, type FilterPattern, type HMRBroadcaster, type HMRBroadcasterClient, type HMRChannel, type HmrContext, type HmrOptions, type HookHandler, type HtmlTagDescriptor, HttpProxy, type IndexHtmlTransform, type IndexHtmlTransformContext, type IndexHtmlTransformHook, type IndexHtmlTransformResult, type InlineConfig, type InternalResolveOptions, type JsonOptions, type LegacyOptions, type LibraryFormats, type LibraryOptions, type LightningCSSOptions, type LogErrorOptions, type LogLevel, type LogOptions, type LogType, type Logger, type LoggerOptions, type MainThreadRuntimeOptions, type Manifest, type ManifestChunk, type MapToFunction, type AnymatchMatcher as Matcher, ModuleGraph, ModuleNode, type ModulePreloadOptions, type OptimizedDepInfo, type Plugin, type PluginContainer, type PluginHookUtils, type PluginOption, type PreprocessCSSResult, type PreviewOptions, type PreviewServer, type PreviewServerHook, type ProxyOptions, type RenderBuiltAssetUrl, type ResolveFn, type ResolveModulePreloadDependenciesFn, type ResolveOptions, type ResolvedBuildOptions, type ResolvedCSSOptions, type ResolvedConfig, type ResolvedModulePreloadOptions, type ResolvedPreviewOptions, type ResolvedSSROptions, type ResolvedServerOptions, type ResolvedServerUrls, type ResolvedUrl, type ResolvedWorkerOptions, type ResolverFunction, type ResolverObject, type RollupCommonJSOptions, type RollupDynamicImportVarsOptions, type SSROptions, type SSRTarget, type SendOptions, type ServerHMRChannel, ServerHMRConnector, type ServerHook, type ServerOptions, SplitVendorChunkCache, type SsrDepOptimizationOptions, Terser, type TerserOptions, type TransformOptions, type TransformResult, type UserConfig, type UserConfigExport, type UserConfigFn, type UserConfigFnObject, type UserConfigFnPromise, type ViteDevServer, type WatchOptions, WebSocket, WebSocketAlias, type WebSocketClient, type WebSocketCustomListener, WebSocketServer, build, buildErrorMessage, createFilter, createLogger, createServer, createViteRuntime, defineConfig, fetchModule, formatPostcssSourceMap, isCSSRequest, isFileServingAllowed, loadConfigFromFile, loadEnv, mergeAlias, mergeConfig, normalizePath, optimizeDeps, preprocessCSS, preview, resolveConfig, resolveEnvPrefix, rollupVersion, searchForWorkspaceRoot, send, sortUserPlugins, splitVendorChunk, splitVendorChunkPlugin, transformWithEsbuild, VERSION as version };
|
package/dist/node/index.js
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
export { parseAst, parseAstAsync } from 'rollup/parseAst';
|
2
|
-
import { i as isInNodeModules,
|
3
|
-
export {
|
2
|
+
import { i as isInNodeModules, b as arraify } from './chunks/dep-G1t0FnMB.js';
|
3
|
+
export { f as build, j as buildErrorMessage, u as createFilter, a as createLogger, e as createServer, d as defineConfig, k as fetchModule, g as formatPostcssSourceMap, y as isFileServingAllowed, l as loadConfigFromFile, z as loadEnv, q as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, h as preprocessCSS, p as preview, r as resolveConfig, A as resolveEnvPrefix, v as rollupVersion, x as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-G1t0FnMB.js';
|
4
4
|
export { VERSION as version } from './constants.js';
|
5
5
|
export { version as esbuildVersion } from 'esbuild';
|
6
|
-
import 'node:fs';
|
6
|
+
import { existsSync, readFileSync } from 'node:fs';
|
7
|
+
import { ViteRuntime, ESModulesRunner } from './runtime.js';
|
7
8
|
import 'node:fs/promises';
|
8
9
|
import 'node:path';
|
9
10
|
import 'node:url';
|
@@ -34,9 +35,9 @@ import 'node:assert';
|
|
34
35
|
import 'node:v8';
|
35
36
|
import 'node:worker_threads';
|
36
37
|
import 'node:buffer';
|
38
|
+
import 'node:events';
|
37
39
|
import 'querystring';
|
38
40
|
import 'node:readline';
|
39
|
-
import 'node:events';
|
40
41
|
import 'zlib';
|
41
42
|
import 'buffer';
|
42
43
|
import 'https';
|
@@ -155,4 +156,108 @@ function splitVendorChunkPlugin() {
|
|
155
156
|
};
|
156
157
|
}
|
157
158
|
|
158
|
-
|
159
|
+
class ServerHMRBroadcasterClient {
|
160
|
+
hmrChannel;
|
161
|
+
constructor(hmrChannel) {
|
162
|
+
this.hmrChannel = hmrChannel;
|
163
|
+
}
|
164
|
+
send(...args) {
|
165
|
+
let payload;
|
166
|
+
if (typeof args[0] === 'string') {
|
167
|
+
payload = {
|
168
|
+
type: 'custom',
|
169
|
+
event: args[0],
|
170
|
+
data: args[1],
|
171
|
+
};
|
172
|
+
}
|
173
|
+
else {
|
174
|
+
payload = args[0];
|
175
|
+
}
|
176
|
+
if (payload.type !== 'custom') {
|
177
|
+
throw new Error('Cannot send non-custom events from the client to the server.');
|
178
|
+
}
|
179
|
+
this.hmrChannel.send(payload);
|
180
|
+
}
|
181
|
+
}
|
182
|
+
/**
|
183
|
+
* The connector class to establish HMR communication between the server and the Vite runtime.
|
184
|
+
* @experimental
|
185
|
+
*/
|
186
|
+
class ServerHMRConnector {
|
187
|
+
handlers = [];
|
188
|
+
hmrChannel;
|
189
|
+
hmrClient;
|
190
|
+
connected = false;
|
191
|
+
constructor(server) {
|
192
|
+
const hmrChannel = server.hot?.channels.find((c) => c.name === 'ssr');
|
193
|
+
if (!hmrChannel) {
|
194
|
+
throw new Error("Your version of Vite doesn't support HMR during SSR. Please, use Vite 5.1 or higher.");
|
195
|
+
}
|
196
|
+
this.hmrClient = new ServerHMRBroadcasterClient(hmrChannel);
|
197
|
+
hmrChannel.api.outsideEmitter.on('send', (payload) => {
|
198
|
+
this.handlers.forEach((listener) => listener(payload));
|
199
|
+
});
|
200
|
+
this.hmrChannel = hmrChannel;
|
201
|
+
}
|
202
|
+
isReady() {
|
203
|
+
return this.connected;
|
204
|
+
}
|
205
|
+
send(message) {
|
206
|
+
const payload = JSON.parse(message);
|
207
|
+
this.hmrChannel.api.innerEmitter.emit(payload.event, payload.data, this.hmrClient);
|
208
|
+
}
|
209
|
+
onUpdate(handler) {
|
210
|
+
this.handlers.push(handler);
|
211
|
+
handler({ type: 'connected' });
|
212
|
+
this.connected = true;
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
function createHMROptions(server, options) {
|
217
|
+
if (server.config.server.hmr === false || options.hmr === false) {
|
218
|
+
return false;
|
219
|
+
}
|
220
|
+
const connection = new ServerHMRConnector(server);
|
221
|
+
return {
|
222
|
+
connection,
|
223
|
+
logger: options.hmr?.logger,
|
224
|
+
};
|
225
|
+
}
|
226
|
+
const prepareStackTrace = {
|
227
|
+
retrieveFile(id) {
|
228
|
+
if (existsSync(id)) {
|
229
|
+
return readFileSync(id, 'utf-8');
|
230
|
+
}
|
231
|
+
},
|
232
|
+
};
|
233
|
+
function resolveSourceMapOptions(options) {
|
234
|
+
if (options.sourcemapInterceptor != null) {
|
235
|
+
if (options.sourcemapInterceptor === 'prepareStackTrace') {
|
236
|
+
return prepareStackTrace;
|
237
|
+
}
|
238
|
+
if (typeof options.sourcemapInterceptor === 'object') {
|
239
|
+
return { ...prepareStackTrace, ...options.sourcemapInterceptor };
|
240
|
+
}
|
241
|
+
return options.sourcemapInterceptor;
|
242
|
+
}
|
243
|
+
if (typeof process !== 'undefined' && 'setSourceMapsEnabled' in process) {
|
244
|
+
return 'node';
|
245
|
+
}
|
246
|
+
return prepareStackTrace;
|
247
|
+
}
|
248
|
+
/**
|
249
|
+
* Create an instance of the Vite SSR runtime that support HMR.
|
250
|
+
* @experimental
|
251
|
+
*/
|
252
|
+
async function createViteRuntime(server, options = {}) {
|
253
|
+
const hmr = createHMROptions(server, options);
|
254
|
+
return new ViteRuntime({
|
255
|
+
...options,
|
256
|
+
root: server.config.root,
|
257
|
+
fetchModule: server.ssrFetchModule,
|
258
|
+
hmr,
|
259
|
+
sourcemapInterceptor: resolveSourceMapOptions(options),
|
260
|
+
}, options.runner || new ESModulesRunner());
|
261
|
+
}
|
262
|
+
|
263
|
+
export { ServerHMRConnector, createViteRuntime, isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { a as ViteModuleRunner, e as ViteRuntimeModuleContext } from './types.d-jgA8ss1A.js';
|
2
|
+
export { d as FetchFunction, F as FetchResult, f as HMRConnection, H as HMRLogger, c as HMRRuntimeConnection, g as ModuleCache, M as ModuleCacheMap, R as ResolvedResult, S as SSRImportMetadata, b as ViteRuntime, h as ViteRuntimeImportMeta, V as ViteRuntimeOptions, s as ssrDynamicImportKey, i as ssrExportAllKey, j as ssrImportKey, k as ssrImportMetaKey, l as ssrModuleExportsKey } from './types.d-jgA8ss1A.js';
|
3
|
+
import '../../types/hot.js';
|
4
|
+
import '../../types/hmrPayload.js';
|
5
|
+
import '../../types/customEvent.js';
|
6
|
+
|
7
|
+
declare class ESModulesRunner implements ViteModuleRunner {
|
8
|
+
runViteModule(context: ViteRuntimeModuleContext, code: string): Promise<any>;
|
9
|
+
runExternalModule(filepath: string): Promise<any>;
|
10
|
+
}
|
11
|
+
|
12
|
+
export { ESModulesRunner, ViteModuleRunner, ViteRuntimeModuleContext };
|