vike 0.4.163 → 0.4.165-commit-74b18b0
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/cjs/__internal/index.js +1 -1
- package/dist/cjs/node/plugin/index.js +6 -18
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +7 -4
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +8 -4
- package/dist/cjs/node/plugin/plugins/buildConfig.js +7 -8
- package/dist/cjs/node/plugin/plugins/distFileNames.js +4 -9
- package/dist/cjs/node/plugin/shared/getAssetsDir.js +11 -0
- package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +15 -23
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/{errMdx.js → errMdx1.js} +2 -2
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errMdx2.js +85 -0
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +15 -11
- package/dist/cjs/node/plugin/shared/loggerVite.js +12 -18
- package/dist/cjs/node/plugin/utils.js +1 -1
- package/dist/cjs/node/prerender/runPrerender.js +1 -8
- package/dist/cjs/node/runtime/globalContext.js +1 -13
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +2 -13
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +5 -1
- package/dist/cjs/node/runtime/renderPage.js +2 -4
- package/dist/cjs/shared/route/resolveRouteString.js +0 -1
- package/dist/cjs/utils/assertNodeEnv.js +65 -10
- package/dist/cjs/utils/assertNodeVersion.js +3 -4
- package/dist/cjs/utils/{isVersionOrAbove.js → assertVersion.js} +5 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/__internal/index.js +2 -2
- package/dist/esm/node/plugin/index.js +7 -19
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +7 -4
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +9 -5
- package/dist/esm/node/plugin/plugins/buildConfig.js +8 -9
- package/dist/esm/node/plugin/plugins/distFileNames.js +1 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -3
- package/dist/esm/node/plugin/shared/getAssetsDir.d.ts +3 -0
- package/dist/esm/node/plugin/shared/getAssetsDir.js +8 -0
- package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.d.ts +0 -1
- package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +16 -24
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/{errMdx.d.ts → errMdx1.d.ts} +1 -1
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/{errMdx.js → errMdx1.js} +1 -1
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errMdx2.d.ts +44 -0
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errMdx2.js +82 -0
- package/dist/esm/node/plugin/shared/loggerNotProd.d.ts +3 -6
- package/dist/esm/node/plugin/shared/loggerNotProd.js +14 -10
- package/dist/esm/node/plugin/shared/loggerVite.js +13 -19
- package/dist/esm/node/plugin/utils.d.ts +1 -1
- package/dist/esm/node/plugin/utils.js +1 -1
- package/dist/esm/node/prerender/runPrerender.js +2 -9
- package/dist/esm/node/runtime/globalContext.js +2 -14
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +3 -11
- package/dist/esm/node/runtime/renderPage/loggerProd.js +5 -1
- package/dist/esm/node/runtime/renderPage.d.ts +0 -1
- package/dist/esm/node/runtime/renderPage.js +2 -4
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +1 -1
- package/dist/esm/shared/route/resolveRouteString.js +0 -1
- package/dist/esm/utils/assertNodeEnv.d.ts +10 -10
- package/dist/esm/utils/assertNodeEnv.js +67 -10
- package/dist/esm/utils/assertNodeVersion.js +3 -4
- package/dist/esm/utils/assertVersion.d.ts +4 -0
- package/dist/esm/utils/{isVersionOrAbove.js → assertVersion.js} +5 -1
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +3 -2
- package/dist/esm/utils/isVersionOrAbove.d.ts +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { logViteAny };
|
|
2
|
-
export {
|
|
2
|
+
export { logViteError };
|
|
3
3
|
export { logConfigInfo };
|
|
4
4
|
export { logConfigError };
|
|
5
5
|
export { logConfigErrorRecover };
|
|
@@ -11,7 +11,6 @@ export type { LogError };
|
|
|
11
11
|
export type { LogErrorArgs };
|
|
12
12
|
export type { LogType };
|
|
13
13
|
export type { LogCategory };
|
|
14
|
-
import { type ErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js';
|
|
15
14
|
type LogType = 'info' | 'warn' | 'error' | 'error-recover';
|
|
16
15
|
type LogCategory = 'config' | `request(${number})`;
|
|
17
16
|
type LogInfo = (...args: LogInfoArgs) => void;
|
|
@@ -22,10 +21,8 @@ declare function logRuntimeInfo(msg: string, httpRequestId: number, logType: Log
|
|
|
22
21
|
declare function logViteAny(msg: string, logType: LogType, httpRequestId: number | null, prependViteTag: boolean): void;
|
|
23
22
|
declare function logConfigInfo(msg: string, logType: LogType): void;
|
|
24
23
|
declare function logConfigErrorRecover(): void;
|
|
25
|
-
declare function logRuntimeError(err: unknown,
|
|
26
|
-
|
|
27
|
-
httpRequestId: number | null): void;
|
|
28
|
-
declare function logViteErrorContainingCodeSnippet(err: ErrorWithCodeSnippet): void;
|
|
24
|
+
declare function logRuntimeError(err: unknown, httpRequestId: number | null): void;
|
|
25
|
+
declare function logViteError(err: unknown, httpRequestId: number | undefined): void;
|
|
29
26
|
declare function logConfigError(err: unknown): void;
|
|
30
27
|
declare function clearLogs(conditions?: {
|
|
31
28
|
clearErrors?: boolean;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// - Pre-rendering
|
|
6
6
|
// In other words: everywhere except in production
|
|
7
7
|
export { logViteAny };
|
|
8
|
-
export {
|
|
8
|
+
export { logViteError };
|
|
9
9
|
export { logConfigInfo };
|
|
10
10
|
export { logConfigError };
|
|
11
11
|
export { logConfigErrorRecover };
|
|
@@ -54,14 +54,16 @@ function logConfigErrorRecover() {
|
|
|
54
54
|
logWithVikeTag(msg, 'error-recover', category);
|
|
55
55
|
}
|
|
56
56
|
function logRuntimeError(err,
|
|
57
|
-
|
|
57
|
+
// httpRequestId is `null` when pre-rendering
|
|
58
58
|
httpRequestId) {
|
|
59
|
-
logErr(err, httpRequestId);
|
|
59
|
+
logErr(err, httpRequestId, false);
|
|
60
60
|
}
|
|
61
|
-
function
|
|
62
|
-
|
|
61
|
+
function logViteError(err,
|
|
62
|
+
// httpRequestId is `undefined` if development environment doesn't support async stores
|
|
63
|
+
httpRequestId) {
|
|
64
|
+
logErr(err, httpRequestId, true);
|
|
63
65
|
}
|
|
64
|
-
function logErr(err, httpRequestId = null) {
|
|
66
|
+
function logErr(err, httpRequestId = null, errorComesFromVite) {
|
|
65
67
|
warnIfErrorIsNotObject(err);
|
|
66
68
|
if (isAbortError(err) && !isErrorDebug()) {
|
|
67
69
|
return;
|
|
@@ -100,9 +102,10 @@ function logErr(err, httpRequestId = null) {
|
|
|
100
102
|
logWithVikeTag(pc.red(`Following error was thrown by the ${hookName}() hook defined at ${hookFilePath}`), 'error', category);
|
|
101
103
|
}
|
|
102
104
|
else if (category) {
|
|
103
|
-
logFallbackErrIntro(category);
|
|
105
|
+
logFallbackErrIntro(category, errorComesFromVite);
|
|
104
106
|
}
|
|
105
107
|
logDirectly(err, 'error');
|
|
108
|
+
// Needs to be called after logging the error.
|
|
106
109
|
onRuntimeError(err);
|
|
107
110
|
}
|
|
108
111
|
function logConfigError(err) {
|
|
@@ -137,11 +140,12 @@ function logConfigError(err) {
|
|
|
137
140
|
return;
|
|
138
141
|
}
|
|
139
142
|
if (category)
|
|
140
|
-
logFallbackErrIntro(category);
|
|
143
|
+
logFallbackErrIntro(category, false);
|
|
141
144
|
logDirectly(err, 'error');
|
|
142
145
|
}
|
|
143
|
-
function logFallbackErrIntro(category) {
|
|
144
|
-
|
|
146
|
+
function logFallbackErrIntro(category, errorComesFromVite) {
|
|
147
|
+
const msg = errorComesFromVite ? 'Transpilation error' : 'An error was thrown';
|
|
148
|
+
logWithVikeTag(pc.bold(pc.red(`[Error] ${msg}:`)), 'error', category);
|
|
145
149
|
}
|
|
146
150
|
function getConfigCategory() {
|
|
147
151
|
const category = getCategory() ?? 'config';
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
export { improveViteLogs };
|
|
2
2
|
import { assert, removeEmptyLines, trimWithAnsi, trimWithAnsiTrailOnly } from '../utils.js';
|
|
3
|
-
import {
|
|
4
|
-
import { isErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js';
|
|
3
|
+
import { logViteError, logViteAny, clearLogs } from './loggerNotProd.js';
|
|
5
4
|
import { getHttpRequestAsyncStore } from './getHttpRequestAsyncStore.js';
|
|
6
5
|
import { removeSuperfluousViteLog } from './loggerVite/removeSuperfluousViteLog.js';
|
|
7
6
|
import { isErrorDebug } from './isErrorDebug.js';
|
|
8
|
-
import { onRuntimeError } from '../../runtime/renderPage/loggerProd.js';
|
|
9
7
|
function improveViteLogs(config) {
|
|
10
8
|
intercept('info', config);
|
|
11
9
|
intercept('warn', config);
|
|
@@ -25,29 +23,25 @@ function intercept(logType, config) {
|
|
|
25
23
|
}
|
|
26
24
|
msg = cleanFirstViteLog(msg);
|
|
27
25
|
const store = getHttpRequestAsyncStore();
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
if (options.error) {
|
|
27
|
+
// Vite does a poor job of handling errors.
|
|
28
|
+
// - It doesn't format error code snippets.
|
|
29
|
+
// - It only shows error.message which means that crucial information such as error.id isn't shown to the user.
|
|
30
|
+
logViteError(options.error, store?.httpRequestId);
|
|
31
|
+
// We swallow Vite's message: we didn't see it add any value so far.
|
|
32
|
+
// - It can even be confusing, such as the following:
|
|
33
|
+
// ```
|
|
34
|
+
// Error when evaluating SSR module virtual:vike:pageConfigValuesAll:server:/pages/abort: failed to import "/pages/abort/+Page.mdx"
|
|
35
|
+
// ```
|
|
36
|
+
assert(!isErrorDebug());
|
|
30
37
|
return;
|
|
31
38
|
}
|
|
32
|
-
//
|
|
33
|
-
if (msg.startsWith('Transform failed with ') && store && logType === 'error') {
|
|
34
|
-
store.markErrorMessageAsLogged(msg);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (options.error && isErrorWithCodeSnippet(options.error)) {
|
|
38
|
-
logViteErrorContainingCodeSnippet(options.error);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
// Only allow Vite to clear its first log. All other clearing is controlled by vike.
|
|
39
|
+
// Only allow Vite to clear for its first log. All other clearing is controlled by vike.
|
|
42
40
|
if (options.clear)
|
|
43
41
|
clearLogs({ clearIfFirstLog: true });
|
|
44
|
-
if (options.error)
|
|
45
|
-
store?.markErrorAsLogged(options.error);
|
|
46
42
|
// Vite's default logger preprends the "[vite]" tag if and only if options.timestamp is true
|
|
47
43
|
const prependViteTag = options.timestamp || !!store?.httpRequestId;
|
|
48
44
|
logViteAny(msg, logType, store?.httpRequestId ?? null, prependViteTag);
|
|
49
|
-
if (options.error)
|
|
50
|
-
onRuntimeError(options.error);
|
|
51
45
|
};
|
|
52
46
|
}
|
|
53
47
|
function cleanFirstViteLog(msg) {
|
|
@@ -19,4 +19,4 @@ export * from '../../utils/assertKeys.js';
|
|
|
19
19
|
export * from '../../utils/injectRollupInputs.js';
|
|
20
20
|
export * from '../../utils/humanizeTime.js';
|
|
21
21
|
export * from '../../utils/pLimit.js';
|
|
22
|
-
export * from '../../utils/
|
|
22
|
+
export * from '../../utils/assertVersion.js';
|
|
@@ -25,4 +25,4 @@ export * from '../../utils/assertKeys.js';
|
|
|
25
25
|
export * from '../../utils/injectRollupInputs.js';
|
|
26
26
|
export * from '../../utils/humanizeTime.js';
|
|
27
27
|
export * from '../../utils/pLimit.js';
|
|
28
|
-
export * from '../../utils/
|
|
28
|
+
export * from '../../utils/assertVersion.js';
|
|
@@ -5,7 +5,7 @@ export { runPrerender_forceExit };
|
|
|
5
5
|
import '../runtime/page-files/setup.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { route } from '../../shared/route/index.js';
|
|
8
|
-
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, executeHook, isPlainObject,
|
|
8
|
+
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, executeHook, isPlainObject, isUserHookError, handleNodeEnv_prerender } from './utils.js';
|
|
9
9
|
import { pLimit } from '../../utils/pLimit.js';
|
|
10
10
|
import { prerenderPage, prerender404Page, getRenderContext, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
|
|
11
11
|
import pc from '@brillout/picocolors';
|
|
@@ -59,7 +59,7 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
59
59
|
if (logLevel === 'info') {
|
|
60
60
|
console.log(`${pc.cyan(`vike v${projectInfo.projectVersion}`)} ${pc.green('pre-rendering HTML...')}`);
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
handleNodeEnv_prerender();
|
|
63
63
|
await disableReactStreaming();
|
|
64
64
|
const viteConfig = await resolveConfig(options.viteConfig || {}, 'vike pre-rendering', 'production');
|
|
65
65
|
setGlobalContext_prerender(viteConfig);
|
|
@@ -714,10 +714,3 @@ function assertIsNotAbort(err, urlOr404) {
|
|
|
714
714
|
assert(abortCall);
|
|
715
715
|
assertUsage(false, `${pc.cyan(abortCall)} thrown${thrownBy} while pre-rendering ${urlOr404} but ${pc.cyan(abortCaller)} isn't supported for pre-rendered pages`);
|
|
716
716
|
}
|
|
717
|
-
function handleNodeEnv() {
|
|
718
|
-
const assertNodeEnv = () => assertNodeEnvIsNotDev('pre-rendering');
|
|
719
|
-
if (getNodeEnv())
|
|
720
|
-
assertNodeEnv();
|
|
721
|
-
setNodeEnvToProduction();
|
|
722
|
-
assertNodeEnv();
|
|
723
|
-
}
|
|
@@ -9,7 +9,7 @@ export { getViteConfig };
|
|
|
9
9
|
export { setGlobalContext_viteDevServer };
|
|
10
10
|
export { setGlobalContext_prerender };
|
|
11
11
|
export { getRuntimeManifest };
|
|
12
|
-
import { assert, assertUsage, assertWarning, getGlobalObject,
|
|
12
|
+
import { assert, assertNodeEnv_runtime, assertUsage, assertWarning, getGlobalObject, isPlainObject, objectAssign, objectKeys } from './utils.js';
|
|
13
13
|
import { loadImportBuild } from './globalContext/loadImportBuild.js';
|
|
14
14
|
import { setPageFiles } from '../../shared/getPageFiles.js';
|
|
15
15
|
import { assertPluginManifest } from '../shared/assertPluginManifest.js';
|
|
@@ -83,7 +83,7 @@ async function initGlobalContext(isPrerendering = false, outDir) {
|
|
|
83
83
|
if (globalObject.globalContext)
|
|
84
84
|
return;
|
|
85
85
|
const { viteDevServer, viteConfig } = globalObject;
|
|
86
|
-
|
|
86
|
+
assertNodeEnv_runtime(!!viteDevServer);
|
|
87
87
|
const isProduction = !viteDevServer;
|
|
88
88
|
if (!isProduction) {
|
|
89
89
|
assert(viteConfig);
|
|
@@ -179,15 +179,3 @@ function assertViteManifest(manifest) {
|
|
|
179
179
|
})
|
|
180
180
|
*/
|
|
181
181
|
}
|
|
182
|
-
function assertNodeEnv(hasViteDevServer) {
|
|
183
|
-
const nodeEnv = getNodeEnv();
|
|
184
|
-
if (nodeEnv === null || nodeEnv === 'test')
|
|
185
|
-
return;
|
|
186
|
-
const isDev = isNodeEnvDev();
|
|
187
|
-
// Calling Vite's createServer() is enough for hasViteDevServer to be true, even without actually adding Vite's development middleware to the server: https://github.com/vikejs/vike/issues/792#issuecomment-1516830759
|
|
188
|
-
if (hasViteDevServer === isDev)
|
|
189
|
-
return;
|
|
190
|
-
const nodeEnvDesc = getNodeEnvDesc();
|
|
191
|
-
// We should change this to be a warning if it blocks users (e.g. if a bad-citizen tool sets a wrong process.env.NODE_ENV value)
|
|
192
|
-
assertUsage(false, `Vite's development server was${hasViteDevServer ? '' : "n't"} instantiated while the ${nodeEnvDesc} which is contradictory, see https://vike.dev/NODE_ENV`);
|
|
193
|
-
}
|
|
@@ -3,8 +3,7 @@ export { logErrorHint };
|
|
|
3
3
|
export { isCjsEsmError };
|
|
4
4
|
export { isKnownError };
|
|
5
5
|
export { getHint };
|
|
6
|
-
import
|
|
7
|
-
import { assert, formatHintLog, isNotNullish, isObject, unique, joinEnglish } from '../utils.js';
|
|
6
|
+
import { assert, formatHintLog, isNotNullish, isObject, unique } from '../utils.js';
|
|
8
7
|
const knownErrors = [
|
|
9
8
|
{
|
|
10
9
|
errMsg: 'jsxDEV is not a function',
|
|
@@ -38,15 +37,7 @@ function getHint(error) {
|
|
|
38
37
|
}
|
|
39
38
|
const res = isCjsEsmError(error);
|
|
40
39
|
if (res) {
|
|
41
|
-
const
|
|
42
|
-
const hint = [
|
|
43
|
-
'Error could be a CJS/ESM issue, consider ',
|
|
44
|
-
!packageNames || packageNames.length === 0
|
|
45
|
-
? 'using'
|
|
46
|
-
: `adding ${joinEnglish(packageNames.map((p) => pc.cyan(p)), 'or')} to`,
|
|
47
|
-
` ${pc.cyan('ssr.noExternal')}`,
|
|
48
|
-
', see https://vike.dev/broken-npm-package'
|
|
49
|
-
].join('');
|
|
40
|
+
const hint = 'The error seems to be a CJS/ESM issue, see https://vike.dev/broken-npm-package';
|
|
50
41
|
return hint;
|
|
51
42
|
}
|
|
52
43
|
return null;
|
|
@@ -77,6 +68,7 @@ function isCjsEsmError(error) {
|
|
|
77
68
|
packageNames.forEach((packageName) => {
|
|
78
69
|
assert(!['vite', 'vike'].includes(packageName));
|
|
79
70
|
});
|
|
71
|
+
// We don't use this anymore: we could return `true` instead. Shall we remove returning a list of npm packages?
|
|
80
72
|
return packageNames;
|
|
81
73
|
}
|
|
82
74
|
function normalizeRes(res) {
|
|
@@ -16,9 +16,13 @@ function logErrorProd(err, _httpRquestId) {
|
|
|
16
16
|
// We ensure we print a string; Cloudflare Workers doesn't seem to properly stringify `Error` objects.
|
|
17
17
|
const errStr = isObject(err) && 'stack' in err ? String(err.stack) : String(err);
|
|
18
18
|
console.error(pc.red(errStr));
|
|
19
|
+
// Needs to be called after logging the error.
|
|
19
20
|
onRuntimeError(err);
|
|
20
21
|
}
|
|
21
|
-
// Every server-side runtime error is expected to go through onRuntimeError()
|
|
22
|
+
// Every server-side runtime error is expected to go through `onRuntimeError()`.
|
|
23
|
+
// - onRuntimeError(err) should always be called after `console.error(err)`.
|
|
24
|
+
// - Because the error hint of logErrorHint(err) should be shown *after* the error.
|
|
25
|
+
// - In principle, any runtime error is (or at least should) be catched by Vike, otherwise Vike couldn't render the error page.
|
|
22
26
|
function onRuntimeError(err) {
|
|
23
27
|
// The more runtime errors we pass to logErrorHint() the better.
|
|
24
28
|
logErrorHint(err);
|
|
@@ -4,7 +4,6 @@ import { HttpResponse } from './renderPage/createHttpResponseObject.js';
|
|
|
4
4
|
import type { PageContextBuiltInServer } from '../../types/index.js';
|
|
5
5
|
declare let renderPage_wrapper: <PageContext>(_httpRequestId: number, ret: () => Promise<PageContext>) => Promise<{
|
|
6
6
|
pageContextReturn: Awaited<PageContext>;
|
|
7
|
-
onRequestDone: () => void;
|
|
8
7
|
}>;
|
|
9
8
|
declare const renderPage_addWrapper: (wrapper: typeof renderPage_wrapper) => void;
|
|
10
9
|
declare function renderPage<PageContextUserAdded extends {}, PageContextInit extends {
|
|
@@ -23,8 +23,7 @@ const globalObject = getGlobalObject('runtime/renderPage.ts', {
|
|
|
23
23
|
pendingRequestsCount: 0
|
|
24
24
|
});
|
|
25
25
|
let renderPage_wrapper = async (_httpRequestId, ret) => ({
|
|
26
|
-
pageContextReturn: await ret()
|
|
27
|
-
onRequestDone: () => { }
|
|
26
|
+
pageContextReturn: await ret()
|
|
28
27
|
});
|
|
29
28
|
const renderPage_addWrapper = (wrapper) => {
|
|
30
29
|
renderPage_wrapper = wrapper;
|
|
@@ -43,10 +42,9 @@ async function renderPage(pageContextInit) {
|
|
|
43
42
|
const { urlOriginal } = pageContextInit;
|
|
44
43
|
logHttpRequest(urlOriginal, httpRequestId);
|
|
45
44
|
globalObject.pendingRequestsCount++;
|
|
46
|
-
const { pageContextReturn
|
|
45
|
+
const { pageContextReturn } = await renderPage_wrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
|
|
47
46
|
logHttpResponse(urlOriginal, httpRequestId, pageContextReturn);
|
|
48
47
|
globalObject.pendingRequestsCount--;
|
|
49
|
-
onRequestDone();
|
|
50
48
|
checkType(pageContextReturn);
|
|
51
49
|
return pageContextReturn;
|
|
52
50
|
}
|
|
@@ -2,7 +2,7 @@ export type { PageContextConfig };
|
|
|
2
2
|
import type { VikePackages } from '../../VikeNamespace.js';
|
|
3
3
|
import type { ConfigBuiltIn } from '../Config.js';
|
|
4
4
|
import type { Combine, IsNotEmpty, XOR5 } from './helpers.ts';
|
|
5
|
-
type PageContextConfig = ConfigBuiltIn & (ConfigVikePackagesNotEmptyXor extends true ? ConfigVikePackagesIntersection : ConfigVikePackagesCombined);
|
|
5
|
+
type PageContextConfig = ConfigBuiltIn & Vike.Config & (ConfigVikePackagesNotEmptyXor extends true ? ConfigVikePackagesIntersection : ConfigVikePackagesCombined);
|
|
6
6
|
type ConfigVikePackagesIntersection = VikePackages.ConfigVikeReact & VikePackages.ConfigVikeVue & VikePackages.ConfigVikeSolid & VikePackages.ConfigVikeSvelte & VikePackages.ConfigVikeAngular;
|
|
7
7
|
type ConfigVikePackagesCombined = Combine<VikePackages.ConfigVikeReact, Combine<VikePackages.ConfigVikeVue, Combine<VikePackages.ConfigVikeSolid, Combine<VikePackages.ConfigVikeSvelte, VikePackages.ConfigVikeAngular>>>>;
|
|
8
8
|
type ConfigVikePackagesNotEmptyXor = XOR5<IsNotEmpty<VikePackages.ConfigVikeReact>, IsNotEmpty<VikePackages.ConfigVikeVue>, IsNotEmpty<VikePackages.ConfigVikeSolid>, IsNotEmpty<VikePackages.ConfigVikeSvelte>, IsNotEmpty<VikePackages.ConfigVikeAngular>>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
declare function
|
|
7
|
-
declare function
|
|
8
|
-
declare function
|
|
9
|
-
declare function
|
|
10
|
-
declare function
|
|
1
|
+
export { assertNodeEnv_build };
|
|
2
|
+
export { assertNodeEnv_runtime };
|
|
3
|
+
export { assertNodeEnv_onVikePluginLoad };
|
|
4
|
+
export { handleNodeEnv_prerender };
|
|
5
|
+
export { handleNodeEnv_vitePluginVercel };
|
|
6
|
+
declare function assertNodeEnv_build(): void;
|
|
7
|
+
declare function assertNodeEnv_runtime(viteDevServerExists: boolean): void;
|
|
8
|
+
declare function assertNodeEnv_onVikePluginLoad(): void;
|
|
9
|
+
declare function handleNodeEnv_prerender(): void;
|
|
10
|
+
declare function handleNodeEnv_vitePluginVercel(): void;
|
|
@@ -1,15 +1,69 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
// This file serves the following three purposes:
|
|
2
|
+
// 1. Upon building the app, we ensure the right NODE_ENV value is set.
|
|
3
|
+
// - Both Vue and React use NODE_ENV for enabling production-specific features:
|
|
4
|
+
// - Vue: https://github.com/vuejs/core/blob/f66a75ea75c8aece065b61e2126b4c5b2338aa6e/packages/vue/index.js
|
|
5
|
+
// - React: https://github.com/facebook/react/blob/01ab35a9a731dec69995fbd28f3ac7eaad11e183/packages/react/npm/index.js
|
|
6
|
+
// - Setting NODE_ENV to 'production' doesn't seem to make any sense in development.
|
|
7
|
+
// - With React upon building the app, setting NODE_ENV to a value other than 'production' triggers an error: https://github.com/vikejs/vike/issues/1469#issuecomment-1969301797
|
|
8
|
+
// - With Vue upon building the app, NODE_ENV can be set to a value other than 'production', e.g. 'development'.
|
|
9
|
+
// 2. Ensure Vite isn't loaded in production.
|
|
10
|
+
// - We currently only check whether Vite's development middleware is instantiated (i.e. whether Vite's `createServer()` was called). Is there a way to detect whether Vite's code is loaded?
|
|
11
|
+
// 3. Ensure NODE_ENV isn't mistakenly set to a wrong value.
|
|
12
|
+
// TODO: to fully implement the aforementioned points we need to implement a [new setting `allowNodeEnv`](https://github.com/vikejs/vike/issues/1528)
|
|
13
|
+
export { assertNodeEnv_build };
|
|
14
|
+
export { assertNodeEnv_runtime };
|
|
15
|
+
export { assertNodeEnv_onVikePluginLoad };
|
|
16
|
+
// Vite already handles build
|
|
17
|
+
export { handleNodeEnv_prerender };
|
|
18
|
+
export { handleNodeEnv_vitePluginVercel };
|
|
9
19
|
import pc from '@brillout/picocolors';
|
|
10
20
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
11
|
-
import {
|
|
21
|
+
import { assertWarning } from './assert.js';
|
|
22
|
+
import { vikeVitePluginLoadedInProductionError } from './assertIsNotProductionRuntime.js';
|
|
12
23
|
assertIsNotBrowser();
|
|
24
|
+
function assertNodeEnv_build() {
|
|
25
|
+
assertNodeEnvIsNotDev('building');
|
|
26
|
+
}
|
|
27
|
+
function assertNodeEnv_runtime(viteDevServerExists) {
|
|
28
|
+
const nodeEnv = getNodeEnv();
|
|
29
|
+
if (nodeEnv === null || nodeEnv === 'test')
|
|
30
|
+
return;
|
|
31
|
+
const isDev = isNodeEnvDev();
|
|
32
|
+
// Calling Vite's createServer() is enough for hasViteDevServer to be true, even without actually adding Vite's development middleware to the server: https://github.com/vikejs/vike/issues/792#issuecomment-1516830759
|
|
33
|
+
if (viteDevServerExists === isDev)
|
|
34
|
+
return;
|
|
35
|
+
const nodeEnvDesc = getNodeEnvDesc();
|
|
36
|
+
// TODO: make it assertUsage() again once #1528 is implemented.
|
|
37
|
+
assertWarning(false, `Vite's development server was${viteDevServerExists ? '' : "n't"} instantiated while the ${nodeEnvDesc} which is contradictory, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
38
|
+
}
|
|
39
|
+
function assertNodeEnv_onVikePluginLoad() {
|
|
40
|
+
const nodeEnv = getNodeEnv();
|
|
41
|
+
if (nodeEnv === 'test')
|
|
42
|
+
return;
|
|
43
|
+
// TODO: make it assertUsage() again once #1528 is implemented.
|
|
44
|
+
assertWarning(
|
|
45
|
+
/* We can enable this assertion after Vike's CLI is implemented and using Vite's CLI is deprecated (we can then check whether the context is a `$ vike build`).
|
|
46
|
+
isNodeEnvDev() || isVikeCliBuild(),
|
|
47
|
+
/*/
|
|
48
|
+
isNodeEnvDev() || true,
|
|
49
|
+
///*/
|
|
50
|
+
[
|
|
51
|
+
pc.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`),
|
|
52
|
+
'(which Vike interprets as a non-development environment https://vike.dev/NODE_ENV)',
|
|
53
|
+
'while the vike/plugin module is loaded.',
|
|
54
|
+
vikeVitePluginLoadedInProductionError
|
|
55
|
+
].join(' '), { onlyOnce: true });
|
|
56
|
+
}
|
|
57
|
+
function handleNodeEnv_prerender() {
|
|
58
|
+
const assertNodeEnv = () => assertNodeEnvIsNotDev('pre-rendering');
|
|
59
|
+
if (getNodeEnv())
|
|
60
|
+
assertNodeEnv();
|
|
61
|
+
setNodeEnvToProduction();
|
|
62
|
+
assertNodeEnv();
|
|
63
|
+
}
|
|
64
|
+
function handleNodeEnv_vitePluginVercel() {
|
|
65
|
+
setNodeEnvToProduction();
|
|
66
|
+
}
|
|
13
67
|
function getNodeEnv() {
|
|
14
68
|
if (typeof process === 'undefined')
|
|
15
69
|
return null;
|
|
@@ -41,5 +95,8 @@ function assertNodeEnvIsNotDev(operation) {
|
|
|
41
95
|
if (!isDev)
|
|
42
96
|
return;
|
|
43
97
|
const nodeEnvDesc = getNodeEnvDesc();
|
|
44
|
-
|
|
98
|
+
// TODO: make it assertUsage() again once #1528 is implemented.
|
|
99
|
+
assertWarning(false, `The ${nodeEnvDesc} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`, {
|
|
100
|
+
onlyOnce: true
|
|
101
|
+
});
|
|
45
102
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export { assertNodeVersion };
|
|
2
|
-
import { assertUsage } from './assert.js';
|
|
3
2
|
import { isNodeJS } from './isNodeJS.js';
|
|
4
|
-
import {
|
|
5
|
-
// package.json#engines.node isn't enough as users can ignore it
|
|
3
|
+
import { assertVersion } from './assertVersion.js';
|
|
4
|
+
// node_modules/vike/package.json#engines.node isn't enough as users can ignore it
|
|
6
5
|
function assertNodeVersion() {
|
|
7
6
|
if (!isNodeJS())
|
|
8
7
|
return;
|
|
9
8
|
const version = process.versions.node;
|
|
10
|
-
|
|
9
|
+
assertVersion('Node.js', version, '16.0.0');
|
|
11
10
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { assertVersion };
|
|
2
|
+
export { isVersionOrAbove };
|
|
3
|
+
declare function assertVersion(dependencyName: 'Vite' | 'Node.js', versionActual: string, versionExpected: `${number}.${number}.${number}`): void;
|
|
4
|
+
declare function isVersionOrAbove(versionActual: string, versionExpected: `${number}.${number}.${number}`): boolean;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
export { assertVersion };
|
|
1
2
|
export { isVersionOrAbove };
|
|
2
|
-
import { assert } from './assert.js';
|
|
3
|
+
import { assert, assertUsage } from './assert.js';
|
|
4
|
+
function assertVersion(dependencyName, versionActual, versionExpected) {
|
|
5
|
+
assertUsage(isVersionOrAbove(versionActual, versionExpected), `${dependencyName} ${versionActual} isn't supported, use ${dependencyName} >= ${versionExpected} instead.`);
|
|
6
|
+
}
|
|
3
7
|
function isVersionOrAbove(versionActual, versionExpected) {
|
|
4
8
|
const p1 = parseVersion(versionActual);
|
|
5
9
|
const p2 = parseVersion(versionExpected);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.165-commit-74b18b0";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.
|
|
6
|
+
projectVersion: "0.4.165-commit-74b18b0";
|
|
7
7
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
3
|
import { onProjectInfo } from './assertSingleInstance.js';
|
|
4
|
-
const PROJECT_VERSION = '0.4.
|
|
4
|
+
const PROJECT_VERSION = '0.4.165-commit-74b18b0';
|
|
5
5
|
const projectInfo = {
|
|
6
6
|
projectName: 'Vike',
|
|
7
7
|
projectVersion: PROJECT_VERSION
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.165-commit-74b18b0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
},
|
|
117
117
|
"peerDependencies": {
|
|
118
118
|
"react-streaming": ">=0.3.5",
|
|
119
|
-
"vite": ">=
|
|
119
|
+
"vite": ">=4.4.0"
|
|
120
120
|
},
|
|
121
121
|
"peerDependenciesMeta": {
|
|
122
122
|
"react-streaming": {
|
|
@@ -169,6 +169,7 @@
|
|
|
169
169
|
"vike": "./node/cli/bin-entry.js"
|
|
170
170
|
},
|
|
171
171
|
"devDependencies": {
|
|
172
|
+
"@biomejs/biome": "^1.5.3",
|
|
172
173
|
"@brillout/import": "^0.2.3",
|
|
173
174
|
"@brillout/json-serializer": "^0.5.8",
|
|
174
175
|
"@brillout/picocolors": "^1.0.10",
|