vite 5.1.0-beta.4 → 5.1.0-beta.6
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-y3MfcbcG.js → dep-0ozvs92U.js} +1 -1
- package/dist/node/chunks/{dep-0RU5--AQ.js → dep-4a4aOlj8.js} +1 -1
- package/dist/node/chunks/{dep-2l_yqaZo.js → dep-ZX7UfftI.js} +198 -34
- package/dist/node/cli.js +6 -6
- package/dist/node/index.d.ts +74 -1
- 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/dist/node-cjs/publicUtils.cjs +8 -4
- package/package.json +15 -4
- package/types/hmrPayload.d.ts +2 -0
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-ZX7UfftI.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-ZX7UfftI.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 };
|