vike 0.4.240 → 0.4.241
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/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +1 -1
- package/dist/esm/client/runtime-client-routing/logErrorClient.d.ts +2 -0
- package/dist/esm/client/runtime-client-routing/logErrorClient.js +11 -0
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +95 -84
- package/dist/esm/client/runtime-client-routing/utils.d.ts +0 -1
- package/dist/esm/client/runtime-client-routing/utils.js +0 -1
- package/dist/esm/node/cli/parseCli.js +10 -6
- package/dist/esm/node/prerender/runPrerender.js +2 -1
- package/dist/esm/node/runtime/globalContext.d.ts +92 -0
- package/dist/esm/node/runtime/globalContext.js +12 -3
- package/dist/esm/node/runtime/logErrorServer.d.ts +2 -0
- package/dist/esm/node/runtime/logErrorServer.js +11 -0
- package/dist/esm/node/runtime/renderPage/execHookOnError.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/execHookOnError.js +26 -0
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -5
- package/dist/esm/node/runtime/renderPage.js +8 -7
- package/dist/esm/node/vite/index.js +6 -6
- package/dist/esm/node/vite/onLoad.js +3 -8
- package/dist/esm/node/vite/plugins/build/handleAssetsManifest.js +0 -1
- package/dist/esm/node/vite/plugins/build/pluginDistFileNames.js +2 -2
- package/dist/esm/node/vite/plugins/pluginCommon.js +13 -2
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +9 -6
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsEnvVars.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsEnvVars.js +129 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsGlobalThis.d.ts +10 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +77 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsPageContext.d.ts +3 -0
- package/dist/esm/node/vite/plugins/{pluginReplaceIsClientSide.js → pluginReplaceConstantsPageContext.js} +5 -3
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.js +7 -1
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +3 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +2 -2
- package/dist/esm/node/vite/shared/getFilePath.d.ts +4 -6
- package/dist/esm/node/vite/shared/getFilePath.js +6 -11
- package/dist/esm/node/vite/shared/isViteServerSide.d.ts +6 -3
- package/dist/esm/node/vite/shared/isViteServerSide.js +13 -4
- package/dist/esm/node/vite/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
- package/dist/esm/node/vite/shared/loggerNotProd/log.js +8 -2
- package/dist/esm/node/vite/shared/loggerNotProd.d.ts +1 -1
- package/dist/esm/node/vite/shared/loggerNotProd.js +11 -11
- package/dist/esm/node/vite/shared/loggerVite.js +4 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +12 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +1 -6
- package/dist/esm/shared/createGlobalContextShared.d.ts +2 -1
- package/dist/esm/shared/createGlobalContextShared.js +1 -1
- package/dist/esm/shared/hooks/execHook.d.ts +1 -1
- package/dist/esm/shared/hooks/getHook.d.ts +5 -4
- package/dist/esm/shared/route/abort.d.ts +1 -0
- package/dist/esm/shared/route/abort.js +12 -4
- package/dist/esm/shared/route/index.js +13 -4
- package/dist/esm/shared/route/utils.d.ts +1 -0
- package/dist/esm/shared/route/utils.js +1 -0
- package/dist/esm/types/Config.d.ts +14 -3
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.js +1 -0
- package/dist/esm/utils/assertNodeVersion.js +1 -1
- package/dist/esm/utils/assertViteVersion.d.ts +2 -0
- package/dist/esm/utils/assertViteVersion.js +11 -0
- package/dist/esm/utils/debug.d.ts +5 -3
- package/dist/esm/utils/debug.js +20 -16
- package/dist/esm/utils/getGlobalObject.d.ts +5 -1
- package/dist/esm/utils/getGlobalObject.js +5 -1
- package/dist/esm/utils/isVikeReactApp.js +2 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +3 -3
- package/dist/esm/node/vite/plugins/pluginEnvVars.d.ts +0 -3
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +0 -110
- package/dist/esm/node/vite/plugins/pluginReplaceGlobalThisConstants.d.ts +0 -9
- package/dist/esm/node/vite/plugins/pluginReplaceGlobalThisConstants.js +0 -45
- package/dist/esm/node/vite/plugins/pluginReplaceIsClientSide.d.ts +0 -3
- package/dist/esm/shared/route/debug.d.ts +0 -6
- package/dist/esm/shared/route/debug.js +0 -21
|
@@ -6,6 +6,7 @@ import { assert, stripAnsi, hasProp, assertIsNotProductionRuntime, PROJECT_VERSI
|
|
|
6
6
|
import pc from '@brillout/picocolors';
|
|
7
7
|
import { isErrorDebug } from '../../../shared/isErrorDebug.js';
|
|
8
8
|
import { getViteDevServer } from '../../../runtime/globalContext.js';
|
|
9
|
+
import { logErrorServer } from '../../../runtime/logErrorServer.js';
|
|
9
10
|
assertIsNotProductionRuntime();
|
|
10
11
|
function logWithVikeTag(msg, logType, category, showVikeVersion = false) {
|
|
11
12
|
const projectTag = getProjectTag(showVikeVersion);
|
|
@@ -39,10 +40,15 @@ function logDirectly(thing, logType) {
|
|
|
39
40
|
console.warn(thing);
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
|
-
if (logType === 'error') {
|
|
43
|
+
if (logType === 'error-note') {
|
|
43
44
|
console.error(thing);
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
47
|
+
if (logType === 'error-thrown') {
|
|
48
|
+
// console.error()
|
|
49
|
+
logErrorServer(thing);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
46
52
|
if (logType === 'error-recover') {
|
|
47
53
|
// stderr because user will most likely want to know about error recovering
|
|
48
54
|
console.error(thing);
|
|
@@ -63,7 +69,7 @@ function applyViteSourceMapToStackTrace(thing) {
|
|
|
63
69
|
}
|
|
64
70
|
function prependTags(msg, projectTag, category, logType) {
|
|
65
71
|
const color = (s) => {
|
|
66
|
-
if (logType === 'error' && !hasRed(msg))
|
|
72
|
+
if (logType === 'error-thrown' && !hasRed(msg))
|
|
67
73
|
return pc.bold(pc.red(s));
|
|
68
74
|
if (logType === 'error-recover' && !hasGreen(msg))
|
|
69
75
|
return pc.bold(pc.green(s));
|
|
@@ -10,7 +10,7 @@ export type { LogError };
|
|
|
10
10
|
export type { LogErrorArgs };
|
|
11
11
|
export type { LogType };
|
|
12
12
|
export type { LogCategory };
|
|
13
|
-
type LogType = 'info' | 'warn' | 'error' | 'error-recover';
|
|
13
|
+
type LogType = 'info' | 'warn' | 'error-thrown' | 'error-recover' | 'error-note';
|
|
14
14
|
type LogCategory = 'config' | `request(${number})`;
|
|
15
15
|
type LogInfo = (...args: LogInfoArgs) => void;
|
|
16
16
|
type LogInfoArgs = Parameters<typeof logRuntimeInfo>;
|
|
@@ -89,7 +89,7 @@ function logErr(err, httpRequestId = null, errorComesFromVite) {
|
|
|
89
89
|
assert(viteConfig);
|
|
90
90
|
const prettyErr = getPrettyErrorWithCodeSnippet(err, viteConfig.root);
|
|
91
91
|
assert(stripAnsi(prettyErr).startsWith('Failed to transpile'));
|
|
92
|
-
logWithViteTag(prettyErr, 'error', category);
|
|
92
|
+
logWithViteTag(prettyErr, 'error-thrown', category);
|
|
93
93
|
logErrorDebugNote();
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
@@ -103,12 +103,12 @@ function logErr(err, httpRequestId = null, errorComesFromVite) {
|
|
|
103
103
|
const hook = isUserHookError(err);
|
|
104
104
|
if (hook) {
|
|
105
105
|
const { hookName, hookFilePath } = hook;
|
|
106
|
-
logWithVikeTag(pc.red(`Following error was thrown by the ${hookName}() hook defined at ${hookFilePath}`), 'error', category);
|
|
106
|
+
logWithVikeTag(pc.red(`Following error was thrown by the ${hookName}() hook defined at ${hookFilePath}`), 'error-note', category);
|
|
107
107
|
}
|
|
108
108
|
else if (category) {
|
|
109
109
|
logFallbackErrIntro(category, errorComesFromVite);
|
|
110
110
|
}
|
|
111
|
-
logDirectly(err, 'error');
|
|
111
|
+
logDirectly(err, 'error-thrown');
|
|
112
112
|
// Needs to be called after logging the error.
|
|
113
113
|
onRuntimeError(err);
|
|
114
114
|
}
|
|
@@ -119,8 +119,8 @@ function logConfigError(err) {
|
|
|
119
119
|
const errIntroMsg = getConfigExecutionErrorIntroMsg(err);
|
|
120
120
|
if (errIntroMsg) {
|
|
121
121
|
assert(stripAnsi(errIntroMsg).startsWith('Failed to execute'));
|
|
122
|
-
logWithVikeTag(errIntroMsg, 'error', category);
|
|
123
|
-
logDirectly(err, 'error');
|
|
122
|
+
logWithVikeTag(errIntroMsg, 'error-note', category);
|
|
123
|
+
logDirectly(err, 'error-thrown');
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -129,10 +129,10 @@ function logConfigError(err) {
|
|
|
129
129
|
if (errMsgFormatted) {
|
|
130
130
|
assert(stripAnsi(errMsgFormatted).startsWith('Failed to transpile'));
|
|
131
131
|
if (!isErrorDebug()) {
|
|
132
|
-
logWithVikeTag(errMsgFormatted, 'error', category);
|
|
132
|
+
logWithVikeTag(errMsgFormatted, 'error-thrown', category);
|
|
133
133
|
}
|
|
134
134
|
else {
|
|
135
|
-
logDirectly(err, 'error');
|
|
135
|
+
logDirectly(err, 'error-thrown');
|
|
136
136
|
}
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
@@ -144,11 +144,11 @@ function logConfigError(err) {
|
|
|
144
144
|
}
|
|
145
145
|
if (category)
|
|
146
146
|
logFallbackErrIntro(category, false);
|
|
147
|
-
logDirectly(err, 'error');
|
|
147
|
+
logDirectly(err, 'error-thrown');
|
|
148
148
|
}
|
|
149
149
|
function logFallbackErrIntro(category, errorComesFromVite) {
|
|
150
150
|
const msg = errorComesFromVite ? 'Transpilation error' : 'An error was thrown';
|
|
151
|
-
logWithVikeTag(pc.bold(pc.red(`[Error] ${msg}:`)), 'error', category);
|
|
151
|
+
logWithVikeTag(pc.bold(pc.red(`[Error] ${msg}:`)), 'error-note', category);
|
|
152
152
|
}
|
|
153
153
|
function getConfigCategory() {
|
|
154
154
|
const category = getCategory() ?? 'config';
|
|
@@ -159,7 +159,7 @@ function handleAssertMsg(err, category) {
|
|
|
159
159
|
if (!res)
|
|
160
160
|
return false;
|
|
161
161
|
const { assertMsg, showVikeVersion } = res;
|
|
162
|
-
logWithVikeTag(assertMsg, 'error', category, showVikeVersion);
|
|
162
|
+
logWithVikeTag(assertMsg, 'error-thrown', category, showVikeVersion);
|
|
163
163
|
return true;
|
|
164
164
|
}
|
|
165
165
|
function assertLogger(thing, logType) {
|
|
@@ -189,7 +189,7 @@ function logErrorDebugNote() {
|
|
|
189
189
|
store.errorDebugNoteAlreadyShown = true;
|
|
190
190
|
}
|
|
191
191
|
const msg = pc.dim(formatHintLog("Error isn't helpful? See https://vike.dev/debug#verbose-errors"));
|
|
192
|
-
logDirectly(msg, 'error');
|
|
192
|
+
logDirectly(msg, 'error-note');
|
|
193
193
|
}
|
|
194
194
|
function getCategory(httpRequestId = null) {
|
|
195
195
|
const store = getHttpRequestAsyncStore();
|
|
@@ -9,8 +9,8 @@ function improveViteLogs(config) {
|
|
|
9
9
|
intercept('warn', config);
|
|
10
10
|
intercept('error', config);
|
|
11
11
|
}
|
|
12
|
-
function intercept(
|
|
13
|
-
config.logger[
|
|
12
|
+
function intercept(loggerType, config) {
|
|
13
|
+
config.logger[loggerType] = (msg, options = {}) => {
|
|
14
14
|
assert(!isErrorDebug());
|
|
15
15
|
if (removeSuperfluousViteLog(msg))
|
|
16
16
|
return;
|
|
@@ -38,6 +38,8 @@ function intercept(logType, config) {
|
|
|
38
38
|
}
|
|
39
39
|
// Vite's default logger preprends the "[vite]" tag if and only if options.timestamp is true
|
|
40
40
|
const prependViteTag = options.timestamp || !!store?.httpRequestId;
|
|
41
|
+
// If it's an actual error => options.error is set => it's handled with logViteError() above
|
|
42
|
+
const logType = loggerType === 'error' ? 'error-note' : loggerType;
|
|
41
43
|
logViteAny(msg, logType, store?.httpRequestId ?? null, prependViteTag);
|
|
42
44
|
};
|
|
43
45
|
}
|
|
@@ -27,6 +27,11 @@ const configDefinitionsBuiltIn = {
|
|
|
27
27
|
global: true,
|
|
28
28
|
cumulative: true,
|
|
29
29
|
},
|
|
30
|
+
onError: {
|
|
31
|
+
env: { server: true },
|
|
32
|
+
global: true,
|
|
33
|
+
cumulative: true,
|
|
34
|
+
},
|
|
30
35
|
onBeforeRender: {
|
|
31
36
|
env: { server: true },
|
|
32
37
|
},
|
|
@@ -96,11 +101,11 @@ const configDefinitionsBuiltIn = {
|
|
|
96
101
|
meta: {
|
|
97
102
|
env: { config: true },
|
|
98
103
|
},
|
|
99
|
-
|
|
104
|
+
hasServerOnlyHook: {
|
|
100
105
|
env: { client: true },
|
|
101
106
|
eager: true,
|
|
102
107
|
_computed: (pageConfig) => {
|
|
103
|
-
const sources = ['data', 'onBeforeRender', 'onCreatePageContext']
|
|
108
|
+
const sources = ['data', 'onBeforeRender', 'onCreatePageContext', 'guard']
|
|
104
109
|
.map((hookName) => getConfigValueSourcesRelevant(hookName, {
|
|
105
110
|
isForClientSide: false,
|
|
106
111
|
// TO-DO/eventually/remove-server-router: let's eventually remove support for Server Routing
|
|
@@ -171,6 +176,10 @@ const configDefinitionsBuiltIn = {
|
|
|
171
176
|
env: { config: true },
|
|
172
177
|
global: true,
|
|
173
178
|
},
|
|
179
|
+
force: {
|
|
180
|
+
env: { config: true },
|
|
181
|
+
global: true,
|
|
182
|
+
},
|
|
174
183
|
csp: {
|
|
175
184
|
env: { server: true },
|
|
176
185
|
},
|
|
@@ -207,6 +216,7 @@ const configDefinitionsBuiltIn = {
|
|
|
207
216
|
env: { config: true },
|
|
208
217
|
global: true,
|
|
209
218
|
},
|
|
219
|
+
// This is deprecated (since Summer 2025). But don't remove this (yet) — otherwise it will break older Vike extensions that still use it.
|
|
210
220
|
vite6BuilderApp: {
|
|
211
221
|
env: { config: true },
|
|
212
222
|
global: true,
|
|
@@ -382,12 +382,7 @@ function triggerPrepareStackTrace(err) {
|
|
|
382
382
|
}
|
|
383
383
|
function getErrIntroMsg(operation, filePath) {
|
|
384
384
|
const { filePathToShowToUserResolved } = filePath;
|
|
385
|
-
const msg =
|
|
386
|
-
// prettier ignore
|
|
387
|
-
pc.red(`Failed to ${operation}`),
|
|
388
|
-
pc.bold(pc.red(filePathToShowToUserResolved)),
|
|
389
|
-
pc.red(`because:`),
|
|
390
|
-
].join(' ');
|
|
385
|
+
const msg = `${pc.red(`Failed to ${operation}`)} ${pc.bold(pc.red(filePathToShowToUserResolved))} ${pc.red(`because:`)}`;
|
|
391
386
|
return msg;
|
|
392
387
|
}
|
|
393
388
|
function cleanEsbuildErrors(errors) {
|
|
@@ -5,13 +5,14 @@ export type { GlobalContextBasePublic };
|
|
|
5
5
|
export type GlobalContextInternal = GlobalContextServerInternal | GlobalContextClientInternal;
|
|
6
6
|
import type { PageFile } from './getPageFiles.js';
|
|
7
7
|
import type { PageConfigRuntime } from '../types/PageConfig.js';
|
|
8
|
+
import { type GlobalContextPrepareMinimum } from './prepareGlobalContextForPublicUsage.js';
|
|
8
9
|
import type { GlobalContextServerInternal } from '../node/runtime/globalContext.js';
|
|
9
10
|
import type { GlobalContextClientInternal } from '../client/runtime-client-routing/getGlobalContextClientInternal.js';
|
|
10
11
|
import { type Hook } from './hooks/getHook.js';
|
|
11
12
|
declare const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
|
|
12
13
|
declare function createGlobalContextShared<GlobalContextAdded extends {}, GlobalContextAddedAsync extends {}>(virtualFileExportsGlobalEntry: unknown, globalObject: {
|
|
13
14
|
globalContext?: {};
|
|
14
|
-
onCreateGlobalContextHooks?: Hook[];
|
|
15
|
+
onCreateGlobalContextHooks?: Hook<GlobalContextPrepareMinimum>[];
|
|
15
16
|
previousCreateGlobalContextPromise?: Promise<void>;
|
|
16
17
|
}, addGlobalContext?: (globalContext: GlobalContextBase) => GlobalContextAdded, addGlobalContextTmp?: (globalContext: GlobalContextBase) => Promise<GlobalContextAdded>, addGlobalContextAsync?: (globalContext: GlobalContextBase) => Promise<GlobalContextAddedAsync>): Promise<{
|
|
17
18
|
_globalConfigPublic: {
|
|
@@ -4,7 +4,7 @@ import { assert, changeEnumerable, genPromise, objectAssign, objectReplace, uniq
|
|
|
4
4
|
import { parseVirtualFileExportsGlobalEntry } from './getPageFiles/parseVirtualFileExportsGlobalEntry.js';
|
|
5
5
|
import { resolveGlobalContextConfig } from './page-configs/resolveVikeConfigPublic.js';
|
|
6
6
|
import { execHookGlobal } from './hooks/execHook.js';
|
|
7
|
-
import { prepareGlobalContextForPublicUsage } from './prepareGlobalContextForPublicUsage.js';
|
|
7
|
+
import { prepareGlobalContextForPublicUsage, } from './prepareGlobalContextForPublicUsage.js';
|
|
8
8
|
import { getHookFromPageConfigGlobalCumulative } from './hooks/getHook.js';
|
|
9
9
|
const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
|
|
10
10
|
// TO-DO/eventually use flat globalContext — like flat pageContext
|
|
@@ -24,7 +24,7 @@ type HookWithResult = Hook & {
|
|
|
24
24
|
hookReturn: unknown;
|
|
25
25
|
};
|
|
26
26
|
declare function execHook<PageContext extends PageContextExecHook>(hookName: HookName, pageContext: PageContext, preparePageContextForPublicUsage: (pageContext: PageContext) => PageContext): Promise<HookWithResult[]>;
|
|
27
|
-
declare function execHookGlobal<HookArg extends
|
|
27
|
+
declare function execHookGlobal<HookArg extends GlobalContextPrepareMinimum>(hookName: HookNameGlobal, pageConfigGlobal: PageConfigGlobalRuntime, pageContext: PageContextPrepareMinimum | null, hookArg: HookArg, prepareForPublicUsage: (hookArg: HookArg) => HookArg): Promise<void>;
|
|
28
28
|
declare function execHookDirect<PageContext extends PageContextPrepareMinimum>(hooks: Hook[], pageContext: PageContext, preparePageContextForPublicUsage: (pageContext: PageContext) => PageContext): Promise<HookWithResult[]>;
|
|
29
29
|
declare function execHookDirectSingle<PageContext extends PageContextExecHook>(hook: Hook, pageContext: PageContext, preparePageContextForPublicUsage: (pageContext: PageContext) => PageContext): Promise<void>;
|
|
30
30
|
declare function execHookDirectSingleWithReturn<PageContext extends PageContextExecHook>(hook: Hook, pageContext: PageContext, preparePageContextForPublicUsage: (pageContext: PageContext) => PageContext): Promise<{
|
|
@@ -14,15 +14,16 @@ import type { HookNameOld, HookNamePage, HookNameGlobal, HookName } from '../../
|
|
|
14
14
|
import type { PageConfigGlobalRuntime, PageConfigRuntime } from '../../types/PageConfig.js';
|
|
15
15
|
import type { GlobalContextPrepareMinimum } from '../prepareGlobalContextForPublicUsage.js';
|
|
16
16
|
import type { PageContextPrepareMinimum } from '../preparePageContextForPublicUsage.js';
|
|
17
|
-
type
|
|
18
|
-
|
|
17
|
+
type HookArgDefault = PageContextPrepareMinimum;
|
|
18
|
+
type Hook<HookArg = HookArgDefault> = HookLoc & {
|
|
19
|
+
hookFn: HookFn<HookArg>;
|
|
19
20
|
hookTimeout: HookTimeout;
|
|
20
21
|
};
|
|
21
22
|
type HookLoc = {
|
|
22
23
|
hookName: HookNameOld;
|
|
23
24
|
hookFilePath: string;
|
|
24
25
|
};
|
|
25
|
-
type HookFn = (arg:
|
|
26
|
+
type HookFn<HookArg = HookArgDefault> = (arg: HookArg) => unknown;
|
|
26
27
|
type HookTimeout = {
|
|
27
28
|
error: number | false;
|
|
28
29
|
warning: number | false;
|
|
@@ -32,6 +33,6 @@ declare function getHookFromPageContext(pageContext: PageContextConfig, hookName
|
|
|
32
33
|
declare function getHookFromPageContextNew(hookName: HookName, pageContext: PageContextConfig): Hook[];
|
|
33
34
|
declare function getHookFromPageConfig(pageConfig: PageConfigRuntime, hookName: HookNamePage): null | Hook;
|
|
34
35
|
declare function getHookFromPageConfigGlobal(pageConfigGlobal: PageConfigGlobalRuntime, hookName: HookNameGlobal): null | Hook;
|
|
35
|
-
declare function getHookFromPageConfigGlobalCumulative(pageConfigGlobal: PageConfigGlobalRuntime, hookName: HookNameGlobal): Hook[];
|
|
36
|
+
declare function getHookFromPageConfigGlobalCumulative<HookArg = GlobalContextPrepareMinimum>(pageConfigGlobal: PageConfigGlobalRuntime, hookName: HookNameGlobal): Hook<HookArg>[];
|
|
36
37
|
declare function getHookTimeoutDefault(hookName: HookNameOld): HookTimeout;
|
|
37
38
|
declare function getHook_setIsPrerenderering(): void;
|
|
@@ -12,6 +12,7 @@ export type { AbortStatusCode };
|
|
|
12
12
|
export type { ErrorAbort };
|
|
13
13
|
export type { PageContextFromRewrite };
|
|
14
14
|
export type { UrlRedirect };
|
|
15
|
+
export type { PageContextAbort };
|
|
15
16
|
type RedirectStatusCode = number & Parameters<typeof redirect>[1];
|
|
16
17
|
type AbortStatusCode = number & Parameters<InferTwoOverloads<typeof render>[0]>[0];
|
|
17
18
|
type UrlRedirect = {
|
|
@@ -26,7 +26,11 @@ function redirect(url, statusCode) {
|
|
|
26
26
|
statusCode = 302;
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
|
-
if (
|
|
29
|
+
if (
|
|
30
|
+
// Tree-shaking to save client-side KBs
|
|
31
|
+
!globalThis.__VIKE__IS_CLIENT ||
|
|
32
|
+
globalThis.__VIKE__IS_DEV ||
|
|
33
|
+
globalThis.__VIKE__IS_DEBUG) {
|
|
30
34
|
assertStatusCode(statusCode, [301, 302], 'redirect');
|
|
31
35
|
}
|
|
32
36
|
args.push(String(statusCode));
|
|
@@ -69,7 +73,11 @@ function render_(urlOrStatusCode, abortReason, abortCall, abortCaller, pageConte
|
|
|
69
73
|
return AbortRender(pageContextAbort);
|
|
70
74
|
}
|
|
71
75
|
else {
|
|
72
|
-
if (
|
|
76
|
+
if (
|
|
77
|
+
// Tree-shaking to save client-side KBs
|
|
78
|
+
!globalThis.__VIKE__IS_CLIENT ||
|
|
79
|
+
globalThis.__VIKE__IS_DEV ||
|
|
80
|
+
globalThis.__VIKE__IS_DEBUG) {
|
|
73
81
|
assertStatusCode(urlOrStatusCode, [401, 403, 404, 410, 429, 500, 503], 'render');
|
|
74
82
|
}
|
|
75
83
|
const abortStatusCode = urlOrStatusCode;
|
|
@@ -136,8 +144,8 @@ function logAbortErrorHandled(err, isProduction, pageContext) {
|
|
|
136
144
|
});
|
|
137
145
|
}
|
|
138
146
|
function assertStatusCode(statusCode, expected, caller) {
|
|
139
|
-
assert(!globalThis.__VIKE__IS_CLIENT || globalThis.__VIKE__IS_DEV); //
|
|
140
|
-
// double check vike:
|
|
147
|
+
assert(!globalThis.__VIKE__IS_CLIENT || globalThis.__VIKE__IS_DEV || globalThis.__VIKE__IS_DEBUG); // assert tree-shaking
|
|
148
|
+
// double check vike:pluginReplaceConstantsGlobalThis
|
|
141
149
|
if (globalThis.__VIKE__IS_CLIENT) {
|
|
142
150
|
assert(isBrowser());
|
|
143
151
|
assert(typeof globalThis.__VIKE__IS_DEV === 'boolean');
|
|
@@ -5,17 +5,21 @@ import { isBrowser } from '../../utils/isBrowser.js';
|
|
|
5
5
|
if (isBrowser()) {
|
|
6
6
|
assertClientRouting();
|
|
7
7
|
}
|
|
8
|
-
import { assert, assertUsage, isPlainObject, objectAssign } from './utils.js';
|
|
8
|
+
import { assert, assertUsage, isPlainObject, objectAssign, debug } from './utils.js';
|
|
9
9
|
import { resolvePrecedence } from './resolvePrecedence.js';
|
|
10
10
|
import { resolveRouteString } from './resolveRouteString.js';
|
|
11
11
|
import { resolveRouteFunction } from './resolveRouteFunction.js';
|
|
12
12
|
import { execHookOnBeforeRoute } from './execHookOnBeforeRoute.js';
|
|
13
|
-
import { debug } from './debug.js';
|
|
14
13
|
import pc from '@brillout/picocolors';
|
|
15
14
|
// TO-DO/next-major-release: make it sync
|
|
16
15
|
async function route(pageContext, skipOnBeforeRouteHook) {
|
|
17
|
-
debug('Pages routes:', pageContext._globalContext._pageRoutes);
|
|
18
16
|
const pageContextFromRoute = {};
|
|
17
|
+
if (
|
|
18
|
+
// Tree-shaking to save client-side KBs
|
|
19
|
+
!globalThis.__VIKE__IS_CLIENT ||
|
|
20
|
+
globalThis.__VIKE__IS_DEBUG) {
|
|
21
|
+
debug('vike:routing', 'Pages routes:', pageContext._globalContext._pageRoutes);
|
|
22
|
+
}
|
|
19
23
|
// onBeforeRoute()
|
|
20
24
|
if (!skipOnBeforeRouteHook) {
|
|
21
25
|
const pageContextFromOnBeforeRouteHook = await execHookOnBeforeRoute(pageContext);
|
|
@@ -80,7 +84,12 @@ async function route(pageContext, skipOnBeforeRouteHook) {
|
|
|
80
84
|
}));
|
|
81
85
|
resolvePrecedence(routeMatches);
|
|
82
86
|
const winner = routeMatches[0] ?? null;
|
|
83
|
-
|
|
87
|
+
if (
|
|
88
|
+
// Tree-shaking to save client-side KBs
|
|
89
|
+
!globalThis.__VIKE__IS_CLIENT ||
|
|
90
|
+
globalThis.__VIKE__IS_DEBUG) {
|
|
91
|
+
debug('vike:routing', `Route matches for URL ${pc.cyan(urlPathname)} (in precedence order):`, routeMatches);
|
|
92
|
+
}
|
|
84
93
|
// For vite-plugin-vercel https://github.com/magne4000/vite-plugin-vercel/blob/main/packages/vike-integration/vike.ts#L173
|
|
85
94
|
objectAssign(pageContextFromRoute, { _routeMatch: winner });
|
|
86
95
|
if (!winner) {
|
|
@@ -48,9 +48,9 @@ import type { PassToClientPublic } from '../node/runtime/renderPage/html/seriali
|
|
|
48
48
|
type HookNameOld = HookName | HookNameOldDesign;
|
|
49
49
|
type HookName = HookNamePage | HookNameGlobal;
|
|
50
50
|
type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data' | 'onData' | 'route';
|
|
51
|
-
type HookNameGlobal = 'onBeforeRoute' | 'onPrerenderStart' | 'onCreatePageContext' | 'onCreateGlobalContext';
|
|
51
|
+
type HookNameGlobal = 'onBeforeRoute' | 'onPrerenderStart' | 'onCreatePageContext' | 'onCreateGlobalContext' | 'onError';
|
|
52
52
|
type HookNameOldDesign = 'render' | 'prerender' | 'onBeforePrerender';
|
|
53
|
-
type ConfigNameBuiltIn = Exclude<keyof ConfigBuiltIn, keyof VikeVitePluginOptions | 'onBeforeRoute' | 'onPrerenderStart' | 'vite' | 'redirects'> | 'prerender' | '
|
|
53
|
+
type ConfigNameBuiltIn = Exclude<keyof ConfigBuiltIn, keyof VikeVitePluginOptions | 'onBeforeRoute' | 'onPrerenderStart' | 'vite' | 'redirects'> | 'prerender' | 'hasServerOnlyHook' | 'isClientRuntimeLoaded' | 'onBeforeRenderEnv' | 'dataEnv' | 'hooksTimeout' | 'clientHooks' | 'middleware';
|
|
54
54
|
type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization' | 'vite';
|
|
55
55
|
type Config = ConfigBuiltIn & Vike.Config;
|
|
56
56
|
/** @deprecated This type is deprecated, see https://vike.dev/data */
|
|
@@ -268,7 +268,7 @@ type ConfigBuiltIn = {
|
|
|
268
268
|
*
|
|
269
269
|
* https://vike.dev/extends
|
|
270
270
|
*/
|
|
271
|
-
extends?: Config |
|
|
271
|
+
extends?: Config | ImportString | (Config | ImportString)[];
|
|
272
272
|
/** Hook called before the page is rendered.
|
|
273
273
|
*
|
|
274
274
|
* https://vike.dev/onBeforeRender
|
|
@@ -279,6 +279,11 @@ type ConfigBuiltIn = {
|
|
|
279
279
|
* https://vike.dev/onCreatePageContext
|
|
280
280
|
*/
|
|
281
281
|
onCreatePageContext?: ((pageContext: PageContextServer) => void) | ImportString | null;
|
|
282
|
+
/** Hook called when an error occurs during server-side rendering.
|
|
283
|
+
*
|
|
284
|
+
* https://vike.dev/onError
|
|
285
|
+
*/
|
|
286
|
+
onError?: ((error: unknown) => void) | ImportString | null;
|
|
282
287
|
/** Hook called when the `globalContext` object is created.
|
|
283
288
|
*
|
|
284
289
|
* https://vike.dev/onCreateGlobalContext
|
|
@@ -468,6 +473,12 @@ type ConfigBuiltIn = {
|
|
|
468
473
|
* https://vike.dev/mode
|
|
469
474
|
*/
|
|
470
475
|
mode?: string;
|
|
476
|
+
/**
|
|
477
|
+
* Disable Vite's cache.
|
|
478
|
+
*
|
|
479
|
+
* https://vike.dev/force
|
|
480
|
+
*/
|
|
481
|
+
force?: boolean;
|
|
471
482
|
/**
|
|
472
483
|
* Content Security Policy (CSP).
|
|
473
484
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.241";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.241';
|
package/dist/esm/utils/assert.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { assertNodeVersion };
|
|
2
2
|
import { isNodeJS } from './isNodeJS.js';
|
|
3
3
|
import { assertVersion } from './assertVersion.js';
|
|
4
|
-
// node_modules/vike/package.json#engines.node isn't enough as users
|
|
4
|
+
// node_modules/vike/package.json#engines.node isn't enough, as users often ignore it
|
|
5
5
|
function assertNodeVersion() {
|
|
6
6
|
if (!isNodeJS())
|
|
7
7
|
return;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { assertViteVersion };
|
|
2
|
+
import { assertVersion } from './assertVersion.js';
|
|
3
|
+
// node_modules/vike/package.json#peerDependencies isn't enough, as users often ignore it
|
|
4
|
+
function assertViteVersion(viteVersion) {
|
|
5
|
+
// - This assertion isn't reliable: the user may still use a Vite version older than 6.0.0 — see https://github.com/vitejs/vite/pull/19355
|
|
6
|
+
// - TO-DO/eventually: let's also use this.meta.viteVersion
|
|
7
|
+
// - this.meta.viteVersion was released in vite@7.0.0 => let's use it only after Vike requires a Vite version above 7.0.0
|
|
8
|
+
// - https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md#700-2025-06-24
|
|
9
|
+
// - https://github.com/vitejs/vite/pull/20088
|
|
10
|
+
assertVersion('Vite', viteVersion, ['6.3.0']);
|
|
11
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
export { debug };
|
|
1
2
|
export { createDebugger };
|
|
3
|
+
export { isDebug };
|
|
2
4
|
export { isDebugActivated };
|
|
3
|
-
|
|
4
|
-
declare const flags: readonly ["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:resolve", "vike:routing", "vike:setup", "vike:stream", "vike:virtualFiles", "vike:vite-rpc"];
|
|
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
6
|
type Flag = (typeof flags)[number];
|
|
6
|
-
type Debug = ReturnType<typeof createDebugger>;
|
|
7
7
|
type Options = {
|
|
8
8
|
serialization?: {
|
|
9
9
|
emptyArray?: string;
|
|
@@ -13,4 +13,6 @@ declare function createDebugger(flag: Flag, optionsGlobal?: Options): ((...msgs:
|
|
|
13
13
|
options: (optionsLocal: Options) => (...msgs: unknown[]) => void;
|
|
14
14
|
isActivated: boolean;
|
|
15
15
|
};
|
|
16
|
+
declare function debug(flag: Flag, ...msgs: unknown[]): void;
|
|
16
17
|
declare function isDebugActivated(flag: Flag): boolean;
|
|
18
|
+
declare function isDebug(): boolean;
|
package/dist/esm/utils/debug.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
export { debug };
|
|
1
2
|
export { createDebugger };
|
|
3
|
+
export { isDebug };
|
|
2
4
|
export { isDebugActivated };
|
|
3
5
|
import { isCallable } from './isCallable.js';
|
|
4
6
|
import { objectAssign } from './objectAssign.js';
|
|
5
7
|
import { assert, assertUsage } from './assert.js';
|
|
6
|
-
import { checkType } from './checkType.js';
|
|
7
8
|
import { getTerminalWidth } from './getTerminalWidth.js';
|
|
8
9
|
import pc from '@brillout/picocolors';
|
|
9
10
|
import { isArray } from './isArray.js';
|
|
10
11
|
import { isObject } from './isObject.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
// Assert tree-shaking (ensure this module is loaded on the client-side only if debug is enabled).
|
|
13
|
+
assert(!globalThis.__VIKE__IS_CLIENT ||
|
|
14
|
+
globalThis.__VIKE__IS_DEBUG ||
|
|
15
|
+
// Vite doesn't do tree-shaking in dev (maybe it will with Rolldown?)
|
|
16
|
+
import.meta.env.DEV);
|
|
15
17
|
const flags = [
|
|
18
|
+
'vike',
|
|
16
19
|
'vike:crawl',
|
|
17
20
|
'vike:error',
|
|
18
21
|
'vike:esbuild-resolve',
|
|
@@ -25,7 +28,7 @@ const flags = [
|
|
|
25
28
|
'vike:outDir',
|
|
26
29
|
'vike:pageFiles',
|
|
27
30
|
'vike:pointer-imports',
|
|
28
|
-
'vike:
|
|
31
|
+
'vike:requireResolve',
|
|
29
32
|
'vike:routing',
|
|
30
33
|
'vike:setup',
|
|
31
34
|
'vike:stream',
|
|
@@ -33,14 +36,12 @@ const flags = [
|
|
|
33
36
|
'vike:vite-rpc',
|
|
34
37
|
];
|
|
35
38
|
const flagsSkipWildcard = ['vike:log'];
|
|
36
|
-
const flagRegex = /\bvike:[a-zA-Z-]+/g;
|
|
37
39
|
// We purposely read process.env.DEBUG early, in order to avoid users from the temptation to set process.env.DEBUG with JavaScript, since reading & writing process.env.DEBUG dynamically leads to inconsistencies such as https://github.com/vikejs/vike/issues/2239
|
|
38
40
|
const DEBUG = getDEBUG() ?? '';
|
|
39
41
|
if (isDebug())
|
|
40
42
|
Error.stackTraceLimit = Infinity;
|
|
41
43
|
assertFlagsActivated();
|
|
42
44
|
function createDebugger(flag, optionsGlobal) {
|
|
43
|
-
checkType(flag);
|
|
44
45
|
assert(flags.includes(flag));
|
|
45
46
|
const debugWithOptions = (optionsLocal) => {
|
|
46
47
|
return (...msgs) => {
|
|
@@ -52,6 +53,9 @@ function createDebugger(flag, optionsGlobal) {
|
|
|
52
53
|
objectAssign(debug, { options: debugWithOptions, isActivated: isDebugActivated(flag) });
|
|
53
54
|
return debug;
|
|
54
55
|
}
|
|
56
|
+
function debug(flag, ...msgs) {
|
|
57
|
+
return debug_(flag, {}, ...msgs);
|
|
58
|
+
}
|
|
55
59
|
function debug_(flag, options, ...msgs) {
|
|
56
60
|
if (!isDebugActivated(flag))
|
|
57
61
|
return;
|
|
@@ -80,10 +84,9 @@ function debug_(flag, options, ...msgs) {
|
|
|
80
84
|
});
|
|
81
85
|
}
|
|
82
86
|
function isDebugActivated(flag) {
|
|
83
|
-
checkType(flag);
|
|
84
87
|
assert(flags.includes(flag));
|
|
85
|
-
const { flagsActivated,
|
|
86
|
-
const isActivated = flagsActivated.includes(flag) || (
|
|
88
|
+
const { flagsActivated, isAll } = getFlagsActivated();
|
|
89
|
+
const isActivated = flagsActivated.includes(flag) || (isAll && !flagsSkipWildcard.includes(flag));
|
|
87
90
|
return isActivated;
|
|
88
91
|
}
|
|
89
92
|
function formatMsg(info, options, padding, position) {
|
|
@@ -153,13 +156,14 @@ function assertFlagsActivated() {
|
|
|
153
156
|
});
|
|
154
157
|
}
|
|
155
158
|
function getFlagsActivated() {
|
|
156
|
-
const flagsActivated = DEBUG.match(
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
+
const flagsActivated = DEBUG.match(/\bvike:[a-zA-Z-]+/g) ?? [];
|
|
160
|
+
const isAll = DEBUG.includes('vike:*');
|
|
161
|
+
const isGlobal = /\bvike\b([^:]|$)/.test(DEBUG);
|
|
162
|
+
return { flagsActivated, isAll, isGlobal };
|
|
159
163
|
}
|
|
160
164
|
function isDebug() {
|
|
161
|
-
const { flagsActivated,
|
|
162
|
-
return
|
|
165
|
+
const { flagsActivated, isAll, isGlobal } = getFlagsActivated();
|
|
166
|
+
return isAll || flagsActivated.length > 0 || isGlobal;
|
|
163
167
|
}
|
|
164
168
|
function getDEBUG() {
|
|
165
169
|
let DEBUG;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export { getGlobalObject };
|
|
2
2
|
import type { VikeGlobalInternal } from '../types/VikeGlobalInternal.js';
|
|
3
3
|
type ModuleId = `${string}.ts`;
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Share information across module instances.
|
|
6
|
+
*
|
|
7
|
+
* @__NO_SIDE_EFFECTS__
|
|
8
|
+
*/
|
|
5
9
|
declare function getGlobalObject<T extends Record<string, unknown> = never>(moduleId: ModuleId, defaultValue: T): T;
|
|
6
10
|
declare global {
|
|
7
11
|
var _vike: VikeGlobalInternal;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export { getGlobalObject };
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Share information across module instances.
|
|
4
|
+
*
|
|
5
|
+
* @__NO_SIDE_EFFECTS__
|
|
6
|
+
*/
|
|
3
7
|
function getGlobalObject(moduleId, defaultValue) {
|
|
4
8
|
const globals = getGlobals();
|
|
5
9
|
const globalObject = (globals[moduleId] ?? (globals[moduleId] = defaultValue));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export function isVikeReactApp() {
|
|
2
2
|
const g = globalThis;
|
|
3
|
-
// Set by vike-react
|
|
3
|
+
// Set by vike-react
|
|
4
|
+
// https://github.com/vikejs/vike-react/blob/23e92434424f10e7e742b6bf587edee5aa8832df/packages/vike-react/src/renderer/onRenderHtml.tsx#L75
|
|
4
5
|
return !!g._isVikeReactApp;
|
|
5
6
|
}
|
|
@@ -17,7 +17,7 @@ const importMetaUrl = import.meta.url;
|
|
|
17
17
|
assertPosixPath(importMetaUrl);
|
|
18
18
|
assertIsNotBrowser();
|
|
19
19
|
assertIsNotProductionRuntime();
|
|
20
|
-
const debug = createDebugger('vike:
|
|
20
|
+
const debug = createDebugger('vike:requireResolve');
|
|
21
21
|
// - We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
22
22
|
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
23
23
|
// - Passing context to createRequire(context) isn't equivalent to passing it to the `paths` argument of require.resolve()
|