vike 0.4.247-commit-e331796 → 0.4.247-commit-1250e38
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/runtime-client-routing/getPageContext.js +1 -0
- package/dist/node/api/dev.d.ts +6 -0
- package/dist/node/api/dev.js +23 -9
- package/dist/node/vite/index.js +2 -2
- package/dist/node/vite/plugins/build/pluginModuleBanner.js +6 -5
- package/dist/node/vite/plugins/pluginAssertFileEnv.d.ts +3 -0
- package/dist/node/vite/plugins/{pluginFileEnv.js → pluginAssertFileEnv.js} +44 -39
- package/dist/node/vite/plugins/pluginCommon/assertResolveAlias.js +1 -1
- package/dist/node/vite/plugins/pluginCommon.d.ts +1 -1
- package/dist/node/vite/plugins/pluginCommon.js +3 -2
- package/dist/node/vite/plugins/pluginDev/optimizeDeps.d.ts +15 -0
- package/dist/node/vite/plugins/pluginDev/{determineOptimizeDeps.js → optimizeDeps.js} +45 -4
- package/dist/node/vite/plugins/pluginDev.d.ts +1 -1
- package/dist/node/vite/plugins/pluginDev.js +3 -19
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.js +1 -1
- package/dist/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +3 -2
- package/dist/node/vite/plugins/pluginVirtualFiles.js +11 -9
- package/dist/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +8 -0
- package/dist/node/vite/shared/resolveVikeConfigInternal.js +5 -4
- package/dist/server/__internal/vite.d.ts +1 -0
- package/dist/server/__internal/vite.js +1 -0
- package/dist/server/runtime/globalContext.d.ts +0 -2
- package/dist/server/runtime/globalContext.js +69 -50
- package/dist/server/runtime/renderPageServer/execHookServer.js +9 -2
- package/dist/server/runtime/renderPageServer.js +6 -9
- package/dist/server/utils.d.ts +1 -1
- package/dist/server/utils.js +1 -1
- package/dist/shared-server-client/assertVirtualFileExports.d.ts +2 -0
- package/dist/shared-server-client/assertVirtualFileExports.js +16 -0
- package/dist/shared-server-client/createGlobalContextShared.js +44 -40
- package/dist/shared-server-client/getPageFiles/parseVirtualFileExportsGlobalEntry.js +2 -0
- package/dist/shared-server-client/page-configs/loadAndParseVirtualFilePageEntry.js +9 -5
- package/dist/shared-server-node/getFileSuffixes.d.ts +6 -0
- package/dist/shared-server-node/getFileSuffixes.js +22 -0
- package/dist/shared-server-node/getVikeConfigError.d.ts +9 -0
- package/dist/shared-server-node/getVikeConfigError.js +4 -1
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/dist/utils/assertSetup.js +3 -3
- package/dist/utils/debug.d.ts +1 -1
- package/dist/utils/debug.js +1 -0
- package/dist/utils/getBetterError.js +3 -0
- package/dist/utils/isNonRunnableDevProcess.d.ts +2 -0
- package/dist/utils/{isNonRunnableDev.js → isNonRunnableDevProcess.js} +2 -2
- package/package.json +7 -3
- package/dist/node/vite/plugins/pluginDev/determineOptimizeDeps.d.ts +0 -3
- package/dist/node/vite/plugins/pluginFileEnv.d.ts +0 -3
- package/dist/utils/isNonRunnableDev.d.ts +0 -2
|
@@ -17,7 +17,6 @@ export { setGlobalContext_prodBuildEntry };
|
|
|
17
17
|
export { clearGlobalContext };
|
|
18
18
|
export { assertBuildInfo };
|
|
19
19
|
export { updateUserFiles };
|
|
20
|
-
export { isRunnable };
|
|
21
20
|
export { vikeConfigErrorRecoverMsg };
|
|
22
21
|
export type { BuildInfo };
|
|
23
22
|
export type { GlobalContextServerInternal };
|
|
@@ -466,4 +465,3 @@ declare function createGlobalContext(virtualFileExportsGlobalEntry: unknown): Pr
|
|
|
466
465
|
prerenderContext: PrerenderContext | undefined;
|
|
467
466
|
}>;
|
|
468
467
|
declare function clearGlobalContext(): void;
|
|
469
|
-
declare function isRunnable(viteDevServer: ViteDevServer): boolean;
|
|
@@ -19,7 +19,6 @@ export { setGlobalContext_prodBuildEntry }; // production entry
|
|
|
19
19
|
export { clearGlobalContext };
|
|
20
20
|
export { assertBuildInfo };
|
|
21
21
|
export { updateUserFiles };
|
|
22
|
-
export { isRunnable };
|
|
23
22
|
export { vikeConfigErrorRecoverMsg };
|
|
24
23
|
// The core logic revolves around:
|
|
25
24
|
// - virtualFileExportsGlobalEntry is the main requirement
|
|
@@ -29,7 +28,7 @@ export { vikeConfigErrorRecoverMsg };
|
|
|
29
28
|
// - Without vike-server it's manually loaded here using importServerProductionEntry() which uses @brillout/vite-plugin-server-entry's autoImporter or crawler
|
|
30
29
|
// - In development: globalObject.viteDevServer which is Vite's development server
|
|
31
30
|
// - globalObject.viteDevServer is used by updateUserFiles() which then sets virtualFileExportsGlobalEntry
|
|
32
|
-
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebug, checkType, PROJECT_VERSION, getViteRPC, isRunnableDevEnvironment, assertIsNotBrowser,
|
|
31
|
+
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebug, checkType, PROJECT_VERSION, getViteRPC, isRunnableDevEnvironment, assertIsNotBrowser, isNonRunnableDevProcess, objectAssign, setNodeEnvProductionIfUndefined, } from '../utils.js';
|
|
33
32
|
import { importServerProductionEntry } from '@brillout/vite-plugin-server-entry/runtime';
|
|
34
33
|
import { virtualFileIdGlobalEntryServer } from '../../shared-server-node/virtualFileId.js';
|
|
35
34
|
import pc from '@brillout/picocolors';
|
|
@@ -39,7 +38,7 @@ import { resolveBase } from '../../shared-server-node/resolveBase.js';
|
|
|
39
38
|
import { createGlobalContextShared, getGlobalContextSyncErrMsg, } from '../../shared-server-client/createGlobalContextShared.js';
|
|
40
39
|
import { prepareGlobalContextForPublicUsage } from '../../shared-server-client/prepareGlobalContextForPublicUsage.js';
|
|
41
40
|
import { logRuntimeError, logRuntimeInfo } from './loggerRuntime.js';
|
|
42
|
-
import { getVikeConfigErrorBuild, setVikeConfigError } from '../../shared-server-node/getVikeConfigError.js';
|
|
41
|
+
import { debugFileChange, getVikeConfigErrorBuild, setVikeConfigError, } from '../../shared-server-node/getVikeConfigError.js';
|
|
43
42
|
import { getVikeApiOperation } from '../../shared-server-node/api-context.js';
|
|
44
43
|
import { hasAlreadyLogged } from './logErrorServer.js';
|
|
45
44
|
const debug = createDebug('vike:globalContext');
|
|
@@ -130,6 +129,7 @@ function getGlobalContextForPublicUsage() {
|
|
|
130
129
|
}
|
|
131
130
|
async function setGlobalContext_viteDevServer(viteDevServer) {
|
|
132
131
|
debug('setGlobalContext_viteDevServer()');
|
|
132
|
+
assert(!isNonRunnableDevProcess()); // if `viteDevServer` exists => cannot be inside a non-runnable process
|
|
133
133
|
// We cannot cache globalObject.viteDevServer because it's fully replaced when the user modifies vite.config.js => Vite's dev server is fully reloaded and a new viteDevServer replaces the previous one.
|
|
134
134
|
if (!globalObject.viteDevServer) {
|
|
135
135
|
assertIsNotInitializedYet();
|
|
@@ -137,12 +137,10 @@ async function setGlobalContext_viteDevServer(viteDevServer) {
|
|
|
137
137
|
assert(globalObject.viteConfig);
|
|
138
138
|
globalObject.viteDevServer = viteDevServer;
|
|
139
139
|
globalObject.viteDevServerPromiseResolve(viteDevServer);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
assertGlobalContextIsDefined();
|
|
145
|
-
}
|
|
140
|
+
const { success } = await updateUserFiles();
|
|
141
|
+
if (!success)
|
|
142
|
+
return;
|
|
143
|
+
assertGlobalContextIsDefined();
|
|
146
144
|
}
|
|
147
145
|
function setGlobalContext_viteConfig(viteConfig, viteConfigRuntime) {
|
|
148
146
|
if (globalObject.viteConfig)
|
|
@@ -210,7 +208,7 @@ async function initGlobalContext() {
|
|
|
210
208
|
await globalObject.viteDevServerPromise;
|
|
211
209
|
}
|
|
212
210
|
else {
|
|
213
|
-
assert(
|
|
211
|
+
assert(isNonRunnableDevProcess());
|
|
214
212
|
await updateUserFiles();
|
|
215
213
|
}
|
|
216
214
|
assert(globalObject.waitForUserFilesUpdate);
|
|
@@ -268,7 +266,7 @@ async function loadProdBuildEntry(outDir) {
|
|
|
268
266
|
// https://github.com/vikejs/vike/blob/8c350e8105a626469e87594d983090919e82099b/packages/vike/node/vite/plugins/pluginBuild/pluginProdBuildEntry.ts#L47
|
|
269
267
|
async function setGlobalContext_prodBuildEntry(prodBuildEntry) {
|
|
270
268
|
debug('setGlobalContext_prodBuildEntry()');
|
|
271
|
-
assert(!
|
|
269
|
+
assert(!isNonRunnableDevProcess());
|
|
272
270
|
assertProdBuildEntry(prodBuildEntry);
|
|
273
271
|
setNodeEnvProductionIfUndefined();
|
|
274
272
|
globalObject.prodBuildEntry = prodBuildEntry;
|
|
@@ -307,48 +305,28 @@ function assertVersionAtBuildTime(versionAtBuildTime) {
|
|
|
307
305
|
const pretty = (version) => pc.bold(`vike@${version}`);
|
|
308
306
|
assertUsage(versionAtBuildTime === versionAtRuntime, `Re-build your app (you're using ${pretty(versionAtRuntime)} but your app was built with ${pretty(versionAtBuildTime)})`);
|
|
309
307
|
}
|
|
310
|
-
// TODO: recover from +onCreateGlobalContext runtime error doesn't work
|
|
311
308
|
async function updateUserFiles() {
|
|
312
|
-
|
|
309
|
+
debugUpdate();
|
|
313
310
|
assert(!isProd());
|
|
311
|
+
const { viteDevServer } = globalObject;
|
|
312
|
+
const isRunnableServer = !!viteDevServer && isRunnableDevServer(viteDevServer);
|
|
313
|
+
const isNonRunnableProcess = isNonRunnableDevProcess();
|
|
314
|
+
if (!isRunnableServer && !isNonRunnableProcess) {
|
|
315
|
+
// Not the runtime process — it's the Vite process and not the non-runnable process
|
|
316
|
+
debugUpdate('=> aborted: not runtime');
|
|
317
|
+
return { success: false };
|
|
318
|
+
}
|
|
314
319
|
const { promise, resolve } = genPromise();
|
|
315
320
|
globalObject.waitForUserFilesUpdate = promise;
|
|
316
321
|
globalObject.waitForUserFilesUpdateResolve ?? (globalObject.waitForUserFilesUpdateResolve = []);
|
|
317
322
|
globalObject.waitForUserFilesUpdateResolve.push(resolve);
|
|
318
|
-
const onError = (err) => {
|
|
319
|
-
if (
|
|
320
|
-
// We must check whether the error was already logged to avoid printing it twice, e.g. when +onCreateGlobalContext.js has a syntax error
|
|
321
|
-
!hasAlreadyLogged(err)) {
|
|
322
|
-
logRuntimeError(err, null);
|
|
323
|
-
}
|
|
324
|
-
setVikeConfigError({ errorRuntime: { err } });
|
|
325
|
-
globalObject.vikeConfigHasRuntimeError = true;
|
|
326
|
-
return { success: false };
|
|
327
|
-
};
|
|
328
|
-
const onSuccess = () => {
|
|
329
|
-
if (globalObject.vikeConfigHasRuntimeError) {
|
|
330
|
-
assert(logRuntimeInfo); // always defined in dev
|
|
331
|
-
logRuntimeInfo(vikeConfigErrorRecoverMsg, null, 'error-resolve');
|
|
332
|
-
}
|
|
333
|
-
globalObject.vikeConfigHasRuntimeError = false;
|
|
334
|
-
setVikeConfigError({ errorRuntime: false });
|
|
335
|
-
globalObject.waitForUserFilesUpdateResolve.forEach((resolve) => resolve());
|
|
336
|
-
globalObject.waitForUserFilesUpdateResolve = [];
|
|
337
|
-
resolve();
|
|
338
|
-
return { success: true };
|
|
339
|
-
};
|
|
340
|
-
const isOutdated = () =>
|
|
341
|
-
// There is a newer call — let the new call supersede the old one.
|
|
342
|
-
// We deliberately swallow the intermetidate state (including any potential error) — it's now outdated and has existed only for a very short period of time.
|
|
343
|
-
globalObject.waitForUserFilesUpdate !== promise ||
|
|
344
|
-
// Avoid race condition: abort if there is a new globalObject.viteDevServer (happens when vite.config.js is modified => Vite's dev server is fully reloaded).
|
|
345
|
-
viteDevServer !== globalObject.viteDevServer;
|
|
346
|
-
const { viteDevServer } = globalObject;
|
|
347
323
|
let hasError = false;
|
|
348
324
|
let virtualFileExportsGlobalEntry;
|
|
349
325
|
let err;
|
|
350
|
-
if (
|
|
351
|
-
assert(
|
|
326
|
+
if (isRunnableServer) {
|
|
327
|
+
assert(viteDevServer);
|
|
328
|
+
assert(isRunnableDevServer(viteDevServer));
|
|
329
|
+
assert(!isNonRunnableProcess);
|
|
352
330
|
/* We don't use runner.import() yet, because as of vite@7.0.6 (July 2025) runner.import() unexpectedly invalidates the module graph, which is a unexpected behavior that doesn't happen with ssrLoadModule()
|
|
353
331
|
// Vite 6
|
|
354
332
|
try {
|
|
@@ -370,6 +348,8 @@ async function updateUserFiles() {
|
|
|
370
348
|
}
|
|
371
349
|
}
|
|
372
350
|
else {
|
|
351
|
+
assert(isNonRunnableProcess);
|
|
352
|
+
assert(!viteDevServer);
|
|
373
353
|
try {
|
|
374
354
|
// We don't directly use import() because:
|
|
375
355
|
// - Avoid Cloudflare Workers (without @cloudflare/vite-plugin) to try to bundle `import('virtual:id')`.
|
|
@@ -392,6 +372,7 @@ async function updateUserFiles() {
|
|
|
392
372
|
return onError(err);
|
|
393
373
|
virtualFileExportsGlobalEntry = virtualFileExportsGlobalEntry.default || virtualFileExportsGlobalEntry;
|
|
394
374
|
if (getVikeConfigErrorBuild()) {
|
|
375
|
+
debugUpdate('=> aborted: build error');
|
|
395
376
|
return { success: false };
|
|
396
377
|
}
|
|
397
378
|
try {
|
|
@@ -406,6 +387,45 @@ async function updateUserFiles() {
|
|
|
406
387
|
if (hasError)
|
|
407
388
|
return onError(err);
|
|
408
389
|
return onSuccess();
|
|
390
|
+
function onSuccess() {
|
|
391
|
+
debugUpdate('=> onSuccess()');
|
|
392
|
+
if (globalObject.vikeConfigHasRuntimeError) {
|
|
393
|
+
assert(logRuntimeInfo); // always defined in dev
|
|
394
|
+
logRuntimeInfo(vikeConfigErrorRecoverMsg, null, 'error-resolve');
|
|
395
|
+
}
|
|
396
|
+
globalObject.vikeConfigHasRuntimeError = false;
|
|
397
|
+
setVikeConfigError({ errorRuntime: false });
|
|
398
|
+
globalObject.waitForUserFilesUpdateResolve.forEach((resolve) => resolve());
|
|
399
|
+
globalObject.waitForUserFilesUpdateResolve = [];
|
|
400
|
+
resolve();
|
|
401
|
+
return { success: true };
|
|
402
|
+
}
|
|
403
|
+
function onError(err) {
|
|
404
|
+
debugUpdate('=> onError()');
|
|
405
|
+
if (
|
|
406
|
+
// We must check whether the error was already logged to avoid printing it twice, e.g. when +onCreateGlobalContext.js has a syntax error
|
|
407
|
+
!hasAlreadyLogged(err)) {
|
|
408
|
+
logRuntimeError(err, null);
|
|
409
|
+
}
|
|
410
|
+
setVikeConfigError({ errorRuntime: { err } });
|
|
411
|
+
globalObject.vikeConfigHasRuntimeError = true;
|
|
412
|
+
return { success: false };
|
|
413
|
+
}
|
|
414
|
+
function isOutdated() {
|
|
415
|
+
const yes =
|
|
416
|
+
// There is a newer call — let the new call supersede the old one.
|
|
417
|
+
// We deliberately swallow the intermetidate state (including any potential error) — it's now outdated and has existed only for a very short period of time.
|
|
418
|
+
globalObject.waitForUserFilesUpdate !== promise ||
|
|
419
|
+
// Avoid race condition: abort if there is a new globalObject.viteDevServer (happens when vite.config.js is modified => Vite's dev server is fully reloaded).
|
|
420
|
+
viteDevServer !== globalObject.viteDevServer;
|
|
421
|
+
if (yes)
|
|
422
|
+
debugUpdate('=> aborted: isOutdated');
|
|
423
|
+
return yes;
|
|
424
|
+
}
|
|
425
|
+
function debugUpdate(...args) {
|
|
426
|
+
debug('updateUserFiles()', ...args);
|
|
427
|
+
debugFileChange('updateUserFiles()', ...args);
|
|
428
|
+
}
|
|
409
429
|
}
|
|
410
430
|
async function createGlobalContext(virtualFileExportsGlobalEntry) {
|
|
411
431
|
debug('createGlobalContext()');
|
|
@@ -496,7 +516,7 @@ async function addGlobalContextAsync(globalContext) {
|
|
|
496
516
|
else {
|
|
497
517
|
assert(!isProcessSharedWithVite()); // process shared with Vite => globalObject.viteConfigRuntime should be set
|
|
498
518
|
assert(!isProd()); // production => globalObject.buildInfo.viteConfigRuntime should be set
|
|
499
|
-
assert(
|
|
519
|
+
assert(isNonRunnableDevProcess());
|
|
500
520
|
const rpc = getViteRPC();
|
|
501
521
|
viteConfigRuntime = await rpc.getViteConfigRuntimeRPC();
|
|
502
522
|
}
|
|
@@ -528,17 +548,16 @@ function resolveBaseRuntime(viteConfigRuntime, config) {
|
|
|
528
548
|
function isProcessSharedWithVite() {
|
|
529
549
|
const yes = globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE ?? false;
|
|
530
550
|
if (yes)
|
|
531
|
-
assert(!
|
|
551
|
+
assert(!isNonRunnableDevProcess());
|
|
532
552
|
return yes;
|
|
533
553
|
}
|
|
534
|
-
function
|
|
554
|
+
function isRunnableDevServer(viteDevServer) {
|
|
555
|
+
assert(!isNonRunnableDevProcess()); // if `viteDevServer` exists => cannot be inside a non-runnable process
|
|
535
556
|
const yes =
|
|
536
557
|
// Vite 5
|
|
537
558
|
!viteDevServer.environments ||
|
|
538
559
|
// Vite 6 or above
|
|
539
560
|
isRunnableDevEnvironment(viteDevServer.environments.ssr);
|
|
540
|
-
if (yes)
|
|
541
|
-
assert(!isNonRunnableDev());
|
|
542
561
|
return yes;
|
|
543
562
|
}
|
|
544
563
|
function isProd() {
|
|
@@ -577,7 +596,7 @@ function isProdOptional() {
|
|
|
577
596
|
// getGlobalContextAsync(isProduction)
|
|
578
597
|
const no4 = globalObject.isProductionAccordingToUser === false;
|
|
579
598
|
// @cloudflare/vite-plugin
|
|
580
|
-
const no5 =
|
|
599
|
+
const no5 = isNonRunnableDevProcess();
|
|
581
600
|
const no6 = globalThis.__VIKE__IS_DEV === true;
|
|
582
601
|
const no = no1 || no2 || no3 || no4 || no5 || no6;
|
|
583
602
|
const debug = { yes1, yes2, yes3, yes4, yes5, yes6, yes7, no1, no2, no3, no4, no5, no6 };
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export { execHookServer };
|
|
2
|
-
import {
|
|
2
|
+
import { execHookDirect } from '../../../shared-server-client/hooks/execHook.js';
|
|
3
3
|
import { preparePageContextForPublicUsageServer, } from './preparePageContextForPublicUsageServer.js';
|
|
4
|
+
import { getHookFromPageContextNew } from '../../../shared-server-client/hooks/getHook.js';
|
|
5
|
+
import { getFileSuffixes } from '../../../shared-server-node/getFileSuffixes.js';
|
|
4
6
|
async function execHookServer(hookName, pageContext) {
|
|
5
|
-
|
|
7
|
+
const allHooks = getHookFromPageContextNew(hookName, pageContext);
|
|
8
|
+
const hooks = !pageContext.isClientSideNavigation
|
|
9
|
+
? allHooks
|
|
10
|
+
: // Don't execute `.ssr.js` hooks upon client-side navigation
|
|
11
|
+
allHooks.filter((hook) => !getFileSuffixes(hook.hookFilePath).includes('ssr'));
|
|
12
|
+
return await execHookDirect(hooks, pageContext, preparePageContextForPublicUsageServer);
|
|
6
13
|
}
|
|
@@ -219,17 +219,14 @@ function logHttpRequest(urlOriginal, pageContextInit, requestId) {
|
|
|
219
219
|
const pageContext_logRuntime = getPageContext_logRuntimeEarly(pageContextInit, requestId);
|
|
220
220
|
logRuntimeInfo?.(getRequestInfoMessage(urlOriginal), pageContext_logRuntime, 'info');
|
|
221
221
|
}
|
|
222
|
-
/*
|
|
223
|
-
const arrowRight = pc.dim('
|
|
224
|
-
const arrowLeft = pc.dim('
|
|
225
|
-
*/
|
|
226
|
-
/*
|
|
222
|
+
/* Alternative icons:
|
|
223
|
+
const arrowRight = pc.dim('»')
|
|
224
|
+
const arrowLeft = pc.dim('«')
|
|
227
225
|
const arrowRight = pc.dim('>>')
|
|
228
226
|
const arrowLeft = pc.dim('<<')
|
|
229
|
-
|
|
230
|
-
const arrowRight = pc.dim('
|
|
231
|
-
const arrowLeft = pc.dim('
|
|
232
|
-
//*/
|
|
227
|
+
*/
|
|
228
|
+
const arrowRight = pc.dim('→');
|
|
229
|
+
const arrowLeft = pc.dim('←');
|
|
233
230
|
function getRequestInfoMessage(urlOriginal) {
|
|
234
231
|
return `HTTP request ${arrowRight} ${prettyUrl(urlOriginal)}`;
|
|
235
232
|
}
|
package/dist/server/utils.d.ts
CHANGED
|
@@ -60,6 +60,6 @@ export * from '../utils/changeEnumerable.js';
|
|
|
60
60
|
export * from '../utils/getViteRPC.js';
|
|
61
61
|
export * from '../utils/isRunnableDevEnvironment.js';
|
|
62
62
|
export * from '../utils/assertIsNotBrowser.js';
|
|
63
|
-
export * from '../utils/
|
|
63
|
+
export * from '../utils/isNonRunnableDevProcess.js';
|
|
64
64
|
export * from '../utils/catchInfiniteLoop.js';
|
|
65
65
|
export * from '../utils/getBetterError.js';
|
package/dist/server/utils.js
CHANGED
|
@@ -64,6 +64,6 @@ export * from '../utils/changeEnumerable.js';
|
|
|
64
64
|
export * from '../utils/getViteRPC.js';
|
|
65
65
|
export * from '../utils/isRunnableDevEnvironment.js';
|
|
66
66
|
export * from '../utils/assertIsNotBrowser.js';
|
|
67
|
-
export * from '../utils/
|
|
67
|
+
export * from '../utils/isNonRunnableDevProcess.js';
|
|
68
68
|
export * from '../utils/catchInfiniteLoop.js';
|
|
69
69
|
export * from '../utils/getBetterError.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { assertVirtualFileExports };
|
|
2
|
+
import { assert } from './utils.js';
|
|
3
|
+
function assertVirtualFileExports(moduleExports, test, moduleId) {
|
|
4
|
+
if (!moduleExports || !test(moduleExports)) {
|
|
5
|
+
/* https://github.com/vikejs/vike/issues/2903#issuecomment-3642285811
|
|
6
|
+
throw getProjectError('@cloudflare/vite-plugin error https://github.com/vikejs/vike/issues/2903#issuecomment-3642285811')
|
|
7
|
+
/*/
|
|
8
|
+
assert(false, { moduleExports, moduleExportsKeys: getKeys(moduleExports), moduleId });
|
|
9
|
+
//*/
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function getKeys(obj) {
|
|
13
|
+
if (obj === undefined)
|
|
14
|
+
return null;
|
|
15
|
+
return [...Object.getOwnPropertyNames(obj), ...Object.getOwnPropertySymbols(obj), ...Object.keys(obj)];
|
|
16
|
+
}
|
|
@@ -24,50 +24,54 @@ addGlobalContextTmp, addGlobalContextAsync) {
|
|
|
24
24
|
assert(globalObject.globalContext);
|
|
25
25
|
await previousCreateGlobalContextPromise;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
else {
|
|
36
|
-
isNewGlobalContext = true;
|
|
37
|
-
}
|
|
38
|
-
if (addGlobalContext &&
|
|
39
|
-
// TO-DO/next-major-release: remove
|
|
40
|
-
globalContext._pageConfigs.length > 0) {
|
|
41
|
-
const globalContextAdded = addGlobalContext?.(globalContext);
|
|
42
|
-
objectAssign(globalContext, globalContextAdded);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
const globalContextAdded = await addGlobalContextTmp?.(globalContext);
|
|
46
|
-
objectAssign(globalContext, globalContextAdded);
|
|
47
|
-
}
|
|
48
|
-
{
|
|
49
|
-
const globalContextAddedAsync = await addGlobalContextAsync?.(globalContext);
|
|
50
|
-
objectAssign(globalContext, globalContextAddedAsync);
|
|
51
|
-
}
|
|
52
|
-
const onCreateGlobalContextHooks = getHookFromPageConfigGlobalCumulative(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
|
|
53
|
-
let hooksCalled = false;
|
|
54
|
-
if (!hooksAreEqual(globalObject.onCreateGlobalContextHooks ?? [], onCreateGlobalContextHooks)) {
|
|
55
|
-
globalObject.onCreateGlobalContextHooks = onCreateGlobalContextHooks;
|
|
56
|
-
await execHookGlobal('onCreateGlobalContext', globalContext._pageConfigGlobal, null, globalContext, prepareGlobalContextForPublicUsage);
|
|
57
|
-
hooksCalled = true;
|
|
58
|
-
}
|
|
59
|
-
if (isNewGlobalContext) {
|
|
60
|
-
// Singleton: ensure all `globalContext` user-land references are preserved & updated.
|
|
61
|
-
if (hooksCalled) {
|
|
62
|
-
objectReplace(globalObject.globalContext, globalContext);
|
|
27
|
+
try {
|
|
28
|
+
const globalContext = createGlobalContextBase(virtualFileExportsGlobalEntry);
|
|
29
|
+
let isNewGlobalContext;
|
|
30
|
+
if (!globalObject.globalContext) {
|
|
31
|
+
// We set globalObject.globalContext early and before any async operations, so that getGlobalContextSync() can be used early.
|
|
32
|
+
// - Required by vike-vercel
|
|
33
|
+
globalObject.globalContext = globalContext;
|
|
34
|
+
isNewGlobalContext = false;
|
|
63
35
|
}
|
|
64
36
|
else {
|
|
65
|
-
|
|
66
|
-
|
|
37
|
+
isNewGlobalContext = true;
|
|
38
|
+
}
|
|
39
|
+
if (addGlobalContext &&
|
|
40
|
+
// TO-DO/next-major-release: remove
|
|
41
|
+
globalContext._pageConfigs.length > 0) {
|
|
42
|
+
const globalContextAdded = addGlobalContext?.(globalContext);
|
|
43
|
+
objectAssign(globalContext, globalContextAdded);
|
|
67
44
|
}
|
|
45
|
+
else {
|
|
46
|
+
const globalContextAdded = await addGlobalContextTmp?.(globalContext);
|
|
47
|
+
objectAssign(globalContext, globalContextAdded);
|
|
48
|
+
}
|
|
49
|
+
{
|
|
50
|
+
const globalContextAddedAsync = await addGlobalContextAsync?.(globalContext);
|
|
51
|
+
objectAssign(globalContext, globalContextAddedAsync);
|
|
52
|
+
}
|
|
53
|
+
const onCreateGlobalContextHooks = getHookFromPageConfigGlobalCumulative(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
|
|
54
|
+
let hooksCalled = false;
|
|
55
|
+
if (!hooksAreEqual(globalObject.onCreateGlobalContextHooks ?? [], onCreateGlobalContextHooks)) {
|
|
56
|
+
globalObject.onCreateGlobalContextHooks = onCreateGlobalContextHooks;
|
|
57
|
+
await execHookGlobal('onCreateGlobalContext', globalContext._pageConfigGlobal, null, globalContext, prepareGlobalContextForPublicUsage);
|
|
58
|
+
hooksCalled = true;
|
|
59
|
+
}
|
|
60
|
+
if (isNewGlobalContext) {
|
|
61
|
+
// Singleton: ensure all `globalContext` user-land references are preserved & updated.
|
|
62
|
+
if (hooksCalled) {
|
|
63
|
+
objectReplace(globalObject.globalContext, globalContext);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// We don't use objectReplace() in order to keep user-land properties.
|
|
67
|
+
objectAssign(globalObject.globalContext, globalContext, true);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return globalObject.globalContext;
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
resolve();
|
|
68
74
|
}
|
|
69
|
-
resolve();
|
|
70
|
-
return globalObject.globalContext;
|
|
71
75
|
}
|
|
72
76
|
function createGlobalContextBase(virtualFileExportsGlobalEntry) {
|
|
73
77
|
const { pageFilesAll, pageConfigs, pageConfigGlobal } = parseVirtualFileExportsGlobalEntry(virtualFileExportsGlobalEntry);
|
|
@@ -5,7 +5,9 @@ import { assertExportValues } from './assert_exports_old_design.js';
|
|
|
5
5
|
import { getPageFileObject } from './getPageFileObject.js';
|
|
6
6
|
import { fileTypes } from './fileTypes.js';
|
|
7
7
|
import { parsePageConfigsSerialized } from '../page-configs/serialize/parsePageConfigsSerialized.js';
|
|
8
|
+
import { assertVirtualFileExports } from '../assertVirtualFileExports.js';
|
|
8
9
|
function parseVirtualFileExportsGlobalEntry(virtualFileExportsGlobalEntry) {
|
|
10
|
+
assertVirtualFileExports(virtualFileExportsGlobalEntry, (moduleExports) => 'pageFilesLazy' in moduleExports);
|
|
9
11
|
assert(hasProp(virtualFileExportsGlobalEntry, 'pageFilesLazy', 'object'));
|
|
10
12
|
assert(hasProp(virtualFileExportsGlobalEntry, 'pageFilesEager', 'object'));
|
|
11
13
|
assert(hasProp(virtualFileExportsGlobalEntry, 'pageFilesExportNamesLazy', 'object'));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { loadAndParseVirtualFilePageEntry };
|
|
2
|
-
import {
|
|
2
|
+
import { objectAssign } from '../utils.js';
|
|
3
3
|
import { parseConfigValuesSerialized } from './serialize/parsePageConfigsSerialized.js';
|
|
4
|
+
import { assertVirtualFileExports } from '../assertVirtualFileExports.js';
|
|
4
5
|
async function loadAndParseVirtualFilePageEntry(pageConfig, isDev) {
|
|
5
6
|
if ('isPageEntryLoaded' in pageConfig &&
|
|
6
7
|
// We don't need to cache in dev, since Vite already caches the virtual module
|
|
@@ -8,10 +9,13 @@ async function loadAndParseVirtualFilePageEntry(pageConfig, isDev) {
|
|
|
8
9
|
return pageConfig;
|
|
9
10
|
}
|
|
10
11
|
const { moduleId, moduleExportsPromise } = pageConfig.loadVirtualFilePageEntry();
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const moduleExports = await moduleExportsPromise;
|
|
13
|
+
/* `moduleExports` is sometimes `undefined` https://github.com/vikejs/vike/discussions/2092
|
|
14
|
+
assert(moduleExports)
|
|
15
|
+
//*/
|
|
16
|
+
// Catch @cloudflare/vite-plugin bug
|
|
17
|
+
assertVirtualFileExports(moduleExports, () => 'configValuesSerialized' in moduleExports, moduleId);
|
|
18
|
+
const virtualFileExportsPageEntry = moduleExports;
|
|
15
19
|
const configValues = parseVirtualFileExportsPageEntry(virtualFileExportsPageEntry);
|
|
16
20
|
Object.assign(pageConfig.configValues, configValues);
|
|
17
21
|
objectAssign(pageConfig, { isPageEntryLoaded: true });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { getFileSuffixes };
|
|
2
|
+
export { suffixesAssertFileEnv };
|
|
3
|
+
declare const suffixesAssertFileEnv: readonly ["server", "client", "ssr"];
|
|
4
|
+
declare const suffixes: readonly ["server", "client", "ssr", "shared", "clear", "default"];
|
|
5
|
+
type Suffix = (typeof suffixes)[number];
|
|
6
|
+
declare function getFileSuffixes(fileName: string): Suffix[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { getFileSuffixes };
|
|
2
|
+
export { suffixesAssertFileEnv };
|
|
3
|
+
const suffixesAssertFileEnv = [
|
|
4
|
+
// .server.js
|
|
5
|
+
'server',
|
|
6
|
+
// .client.js
|
|
7
|
+
'client',
|
|
8
|
+
// .ssr.js
|
|
9
|
+
'ssr',
|
|
10
|
+
];
|
|
11
|
+
const suffixes = [
|
|
12
|
+
...suffixesAssertFileEnv,
|
|
13
|
+
// .shared.js
|
|
14
|
+
'shared',
|
|
15
|
+
// .clear.js
|
|
16
|
+
'clear',
|
|
17
|
+
// .default.js
|
|
18
|
+
'default',
|
|
19
|
+
];
|
|
20
|
+
function getFileSuffixes(fileName) {
|
|
21
|
+
return suffixes.filter((suffix) => fileName.includes(`.${suffix}.`));
|
|
22
|
+
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
export { getVikeConfigError };
|
|
2
2
|
export { getVikeConfigErrorBuild };
|
|
3
3
|
export { setVikeConfigError };
|
|
4
|
+
export { debugFileChange };
|
|
5
|
+
declare const debugFileChange: ((...msgs: unknown[]) => void) & {
|
|
6
|
+
options: (optionsLocal: {
|
|
7
|
+
serialization?: {
|
|
8
|
+
emptyArray?: string;
|
|
9
|
+
};
|
|
10
|
+
}) => (...msgs: unknown[]) => void;
|
|
11
|
+
isActivated: boolean;
|
|
12
|
+
};
|
|
4
13
|
type VikeConfigHasError = false | {
|
|
5
14
|
err: unknown;
|
|
6
15
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
export { getVikeConfigError };
|
|
2
2
|
export { getVikeConfigErrorBuild };
|
|
3
3
|
export { setVikeConfigError };
|
|
4
|
-
|
|
4
|
+
export { debugFileChange };
|
|
5
|
+
import { getGlobalObject, createDebug } from './utils.js';
|
|
5
6
|
const globalObject = getGlobalObject('server/shared/getVikeConfigError.ts', {
|
|
6
7
|
errorRuntime: false,
|
|
7
8
|
errorBuild: false,
|
|
8
9
|
});
|
|
10
|
+
const debugFileChange = createDebug('vike:file-change');
|
|
9
11
|
function setVikeConfigError(val) {
|
|
12
|
+
debugFileChange('setVikeConfigError()', val);
|
|
10
13
|
if ('errorRuntime' in val)
|
|
11
14
|
globalObject.errorRuntime = val.errorRuntime;
|
|
12
15
|
if ('errorBuild' in val)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.247-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.247-commit-1250e38";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.247-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.247-commit-1250e38';
|
|
@@ -12,7 +12,7 @@ import { assert, assertUsage, assertWarning } from './assert.js';
|
|
|
12
12
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
13
13
|
import { createDebug } from './debug.js';
|
|
14
14
|
import { getGlobalObject } from './getGlobalObject.js';
|
|
15
|
-
import {
|
|
15
|
+
import { isNonRunnableDevProcess } from './isNonRunnableDevProcess.js';
|
|
16
16
|
import { isVitest } from './isVitest.js';
|
|
17
17
|
import pc from '@brillout/picocolors';
|
|
18
18
|
assertIsNotBrowser();
|
|
@@ -32,9 +32,9 @@ function onSetupRuntime() {
|
|
|
32
32
|
assertNodeEnvIsNotUndefinedString();
|
|
33
33
|
if (!setup.viteDevServer && setup.isViteDev === undefined) {
|
|
34
34
|
// TO-DO/eventually: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
35
|
-
assertWarning(!isNodeEnvDev() ||
|
|
35
|
+
assertWarning(!isNodeEnvDev() || isNonRunnableDevProcess(), `The ${getEnvDescription()}, which is contradictory because the environment seems to be a production environment (Vite isn't loaded), see ${pc.underline('https://vike.dev/NODE_ENV')} and ${pc.underline('https://vike.dev/warning/setup')}`, { onlyOnce: true });
|
|
36
36
|
assertUsage(!setup.vikeVitePlugin, `Vike's Vite plugin (the ${pc.cyan('vike/plugin')} module) shouldn't be loaded in production, see ${pc.underline('https://vike.dev/warning/setup')}`);
|
|
37
|
-
// This assert() one of the main goal of this file: it
|
|
37
|
+
// This assert() one of the main goal of this file: it implements assertIsNotProductionRuntime()
|
|
38
38
|
assert(!setup.shouldNotBeProduction);
|
|
39
39
|
}
|
|
40
40
|
else {
|
package/dist/utils/debug.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { createDebug };
|
|
|
2
2
|
export { isDebug };
|
|
3
3
|
export { isDebugError };
|
|
4
4
|
export { debug };
|
|
5
|
-
declare const flags: ["vike", "vike:crawl", "vike:error", "vike:esbuild-resolve", "vike:pluginExtractAssets", "vike:pluginExtractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:requireResolve", "vike:routing", "vike:setup", "vike:stream", "vike:virtualFiles", "vike:vite-rpc"];
|
|
5
|
+
declare const flags: ["vike", "vike:crawl", "vike:file-change", "vike:error", "vike:esbuild-resolve", "vike:pluginExtractAssets", "vike:pluginExtractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:requireResolve", "vike:routing", "vike:setup", "vike:stream", "vike:virtualFiles", "vike:vite-rpc"];
|
|
6
6
|
type Flag = (typeof flags)[number];
|
|
7
7
|
type Options = {
|
|
8
8
|
serialization?: {
|
package/dist/utils/debug.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { getBetterError };
|
|
2
2
|
// TO-DO/maybe: make it a library `@brillout/better-error`
|
|
3
|
+
// Copies:
|
|
4
|
+
// - https://github.com/brillout/react-streaming/blob/b8565c1257c63a665bda31b9be42112e458859d1/src/utils/getBetterError.ts
|
|
5
|
+
// - https://github.com/vikejs/vike-react/blob/5477461e67592e24d2aa38a552703b9e76a01d2a/packages/vike-react/src/utils/getBetterErrorLight.ts
|
|
3
6
|
import { isObject } from './isObject.js';
|
|
4
7
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
5
8
|
import { objectAssign } from './objectAssign.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { isNonRunnableDevProcess };
|
|
2
2
|
import { assert } from './assert.js';
|
|
3
3
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
4
4
|
assertIsNotBrowser();
|
|
5
|
-
function
|
|
5
|
+
function isNonRunnableDevProcess() {
|
|
6
6
|
if (globalThis.__VIKE__IS_NON_RUNNABLE_DEV === undefined)
|
|
7
7
|
return false;
|
|
8
8
|
assert(globalThis.__VIKE__IS_NON_RUNNABLE_DEV === true);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.247-commit-
|
|
3
|
+
"version": "0.4.247-commit-1250e38",
|
|
4
4
|
"repository": "https://github.com/vikejs/vike",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
@@ -104,6 +104,10 @@
|
|
|
104
104
|
"types": "./dist/server/runtime/page-files/setup.d.ts",
|
|
105
105
|
"default": "./dist/server/runtime/page-files/setup.js"
|
|
106
106
|
},
|
|
107
|
+
"./__internal/vite": {
|
|
108
|
+
"types": "./dist/server/__internal/vite.d.ts",
|
|
109
|
+
"default": "./dist/server/__internal/vite.js"
|
|
110
|
+
},
|
|
107
111
|
".": {
|
|
108
112
|
"worker": "./dist/server/runtime/index.js",
|
|
109
113
|
"workerd": "./dist/server/runtime/index.js",
|
|
@@ -240,13 +244,13 @@
|
|
|
240
244
|
"./universal-middleware.js"
|
|
241
245
|
],
|
|
242
246
|
"devDependencies": {
|
|
243
|
-
"@brillout/release-me": "^0.4.
|
|
247
|
+
"@brillout/release-me": "^0.4.9",
|
|
244
248
|
"@types/estree": "^1.0.5",
|
|
245
249
|
"@types/node": "^20.10.5",
|
|
246
250
|
"@types/picomatch": "^3.0.2",
|
|
247
251
|
"@types/semver": "^7.5.8",
|
|
248
252
|
"@types/source-map-support": "^0.5.10",
|
|
249
|
-
"react-streaming": "^0.4.
|
|
253
|
+
"react-streaming": "^0.4.14",
|
|
250
254
|
"rimraf": "^5.0.5",
|
|
251
255
|
"typescript": "^5.9.3",
|
|
252
256
|
"vite": "^7.2.6"
|