vike 0.4.164 → 0.4.165
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/node/plugin/index.js +6 -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/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/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/node/plugin/index.js +7 -1
- 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/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/route/resolveRouteString.js +0 -1
- 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 +2 -2
- package/dist/esm/utils/isVersionOrAbove.d.ts +0 -2
|
@@ -7,6 +7,7 @@ exports.version = exports.ssr = exports.plugin = void 0;
|
|
|
7
7
|
exports.default = plugin;
|
|
8
8
|
var utils_js_1 = require("./utils.js");
|
|
9
9
|
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return utils_js_1.PROJECT_VERSION; } });
|
|
10
|
+
const vite_1 = require("vite");
|
|
10
11
|
const utils_js_2 = require("./utils.js");
|
|
11
12
|
const buildConfig_js_1 = require("./plugins/buildConfig.js");
|
|
12
13
|
const previewConfig_js_1 = require("./plugins/previewConfig.js");
|
|
@@ -29,6 +30,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
29
30
|
const fileEnv_js_1 = require("./plugins/fileEnv.js");
|
|
30
31
|
(0, utils_js_2.assertNodeEnv_onVikePluginLoad)();
|
|
31
32
|
(0, utils_js_2.markEnvAsVikePluginLoaded)();
|
|
33
|
+
assertViteVersion();
|
|
32
34
|
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
33
35
|
function plugin(vikeConfig) {
|
|
34
36
|
const plugins = [
|
|
@@ -69,3 +71,7 @@ Object.defineProperty(plugin, 'apply', {
|
|
|
69
71
|
(0, utils_js_2.assertUsage)(false, `Add ${picocolors_1.default.cyan('vike()')} instead of ${picocolors_1.default.cyan('vike')} to vite.config.js#plugins (i.e. call the function and add the return value instead of adding the function itself)`, { showStackTrace: true });
|
|
70
72
|
}
|
|
71
73
|
});
|
|
74
|
+
// node_modules/vike/package.json#peerDependencies.vite isn't enough as users can ignore it
|
|
75
|
+
function assertViteVersion() {
|
|
76
|
+
(0, utils_js_2.assertVersion)('Vite', vite_1.version, '4.4.0');
|
|
77
|
+
}
|
|
@@ -32,6 +32,7 @@ const utils_js_1 = require("../utils.js");
|
|
|
32
32
|
const transpileAndExecuteFile_js_1 = require("../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js");
|
|
33
33
|
const loggerNotProd_js_1 = require("./loggerNotProd.js");
|
|
34
34
|
const errorWithCodeSnippet_js_1 = require("./loggerNotProd/errorWithCodeSnippet.js");
|
|
35
|
+
const node_util_1 = require("node:util");
|
|
35
36
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
36
37
|
let asyncLocalStorage = null;
|
|
37
38
|
async function installHttpRequestAsyncStore() {
|
|
@@ -61,29 +62,14 @@ async function installHttpRequestAsyncStore() {
|
|
|
61
62
|
return false;
|
|
62
63
|
}
|
|
63
64
|
};
|
|
64
|
-
// Remove once https://github.com/vitejs/vite/pull/13495 is released
|
|
65
|
-
const swallowedErrorMessages = new Set();
|
|
66
|
-
const markErrorMessageAsLogged = (errMsg) => {
|
|
67
|
-
swallowedErrorMessages.add(errMsg);
|
|
68
|
-
};
|
|
69
|
-
const onRequestDone = () => {
|
|
70
|
-
swallowedErrorMessages.forEach((errMsg) => {
|
|
71
|
-
if (!Array.from(loggedErrors).some((err) => String(err).includes(errMsg))) {
|
|
72
|
-
console.error('loggedErrors', loggedErrors);
|
|
73
|
-
console.error('swallowedErrorMessages', swallowedErrorMessages);
|
|
74
|
-
(0, utils_js_1.assert)(false);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
65
|
const store = {
|
|
79
66
|
httpRequestId,
|
|
80
67
|
markErrorAsLogged,
|
|
81
|
-
markErrorMessageAsLogged,
|
|
82
68
|
shouldErrorBeSwallowed,
|
|
83
69
|
errorDebugNoteAlreadyShown: false
|
|
84
70
|
};
|
|
85
71
|
const pageContextReturn = await asyncLocalStorage.run(store, renderPage);
|
|
86
|
-
return { pageContextReturn
|
|
72
|
+
return { pageContextReturn };
|
|
87
73
|
});
|
|
88
74
|
return;
|
|
89
75
|
}
|
|
@@ -109,14 +95,20 @@ function isEquivalent(err1, err2) {
|
|
|
109
95
|
}
|
|
110
96
|
if ((0, errorWithCodeSnippet_js_1.isEquivalentErrorWithCodeSnippet)(err1, err2))
|
|
111
97
|
return true;
|
|
112
|
-
if (
|
|
113
|
-
Object.keys(
|
|
114
|
-
|
|
115
|
-
|
|
98
|
+
if ((0, utils_js_1.unique)([
|
|
99
|
+
// error.message and error.stack aren't enumerable and therefore not listed by Object.keys()
|
|
100
|
+
'message',
|
|
101
|
+
'stack',
|
|
102
|
+
...Object.keys(err1),
|
|
103
|
+
...Object.keys(err2)
|
|
104
|
+
]).every((k) => {
|
|
105
|
+
// isDeepStrictEqual() need to compare error.position wich is an object.
|
|
106
|
+
if ((0, node_util_1.isDeepStrictEqual)(err1[k], err2[k]))
|
|
107
|
+
return true;
|
|
108
|
+
// console.log('diff', k)
|
|
109
|
+
return false;
|
|
110
|
+
})) {
|
|
116
111
|
return true;
|
|
117
112
|
}
|
|
118
113
|
return false;
|
|
119
114
|
}
|
|
120
|
-
function isDefinedAndSame(val1, val2) {
|
|
121
|
-
return val1 && val1 === val2;
|
|
122
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.errMdx1 = void 0;
|
|
4
|
+
exports.errMdx1 = {
|
|
5
5
|
name: '5:5-5:6',
|
|
6
6
|
message: 'Unexpected closing slash `/` in tag, expected an open tag first',
|
|
7
7
|
reason: 'Unexpected closing slash `/` in tag, expected an open tag first',
|
package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errMdx2.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errMdx2 = void 0;
|
|
4
|
+
exports.errMdx2 = {
|
|
5
|
+
reason: 'Unexpected closing slash `/` in tag, expected an open tag first',
|
|
6
|
+
line: 23,
|
|
7
|
+
column: 450,
|
|
8
|
+
position: {
|
|
9
|
+
start: {
|
|
10
|
+
line: 23,
|
|
11
|
+
column: 450,
|
|
12
|
+
offset: 1967,
|
|
13
|
+
_index: 0,
|
|
14
|
+
_bufferIndex: 444
|
|
15
|
+
},
|
|
16
|
+
end: {
|
|
17
|
+
line: 23,
|
|
18
|
+
column: 451,
|
|
19
|
+
offset: 1968,
|
|
20
|
+
_index: 0,
|
|
21
|
+
_bufferIndex: 445
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
source: 'mdast-util-mdx-jsx',
|
|
25
|
+
ruleId: 'unexpected-closing-slash',
|
|
26
|
+
plugin: '@mdx-js/rollup',
|
|
27
|
+
id: '/home/rom/code/vike/docs/pages/abort/+Page.mdx',
|
|
28
|
+
pluginCode: "import { Link } from '@brillout/docpress'\n" +
|
|
29
|
+
'\n' +
|
|
30
|
+
'By using <Link href="/render" text={<code>throw render()</code>}></Link> or <Link href="/redirect" text={<code>throw redirect()</code>}></Link> you abort the rendering of the current page and render something else instead.\n' +
|
|
31
|
+
'\n' +
|
|
32
|
+
`<h2 id="throw-redirect-vs-throw-render"><code>{'throw redirect()'}</code>{' VS '}<code>{'throw render()'}</code></h2>\n` +
|
|
33
|
+
'\n' +
|
|
34
|
+
'While `throw redirect()` changes the URL, `throw render()` preserves it:\n' +
|
|
35
|
+
" - If a user goes to `/admin` and `throw redirect('/login')` is called, then the user will see the new URL `/login` in the browser's address bar.\n" +
|
|
36
|
+
" - If a user goes to `/admin` and `throw render('/login')` is called, then the user keeps seeing the same URL `/admin` in the browser's address bar.\n" +
|
|
37
|
+
'\n' +
|
|
38
|
+
"In general, we recommend using `throw render('/login')` instead of `throw redirect('/login')` as it preserves the URL and, therefore, the user's intention. We further explain this techniue at <Link href=\"/auth#login-flow\" />.\n" +
|
|
39
|
+
'\n' +
|
|
40
|
+
'\n' +
|
|
41
|
+
`<h2 id="debug">{'Debug'}</h2>\n` +
|
|
42
|
+
'\n' +
|
|
43
|
+
"If `throw redirect()` or `throw render()` doesn't work:\n" +
|
|
44
|
+
" - **Make sure `throw redirect()` / `throw render()` isn't intercepted.** \n" +
|
|
45
|
+
" In developement, check your server logs for the following log. If this log is missing then it means that Vike didn't catch the `throw redirect()` / `throw render()` exception: some other code is intercepting it preventing Vike from catching it.\n" +
|
|
46
|
+
' ```\n' +
|
|
47
|
+
" 10:00:00 AM [vike][request(42)] throw redirect('/some-url') intercepted while\n" +
|
|
48
|
+
' rendering /some-other-url\n' +
|
|
49
|
+
' ```\n' +
|
|
50
|
+
' > Most notably, using `throw redirect()` / `throw render()` inside a UI component usually doesn\'t work because most <Link href="/ui-framework">UI framework</Link> will intercept the execption and thus Vike won\'t be able to catch it. Instead, consider using `throw redirect()` / `throw render()` in a Vike hook such as <Link href="/guard">guard()</Link> or <Link href="/data">data()</Link>, or consider using <Link href="/navigate" />`navigate()`</Link>.\n' +
|
|
51
|
+
' - **Make sure to use `throw redirect()` / `throw render()` within a Vike hook.** \n' +
|
|
52
|
+
" If you use `throw redirect()` / `throw render()` outside of Vike hooks, for example in some server middleware code then Vike won't be able to intercept it.\n" +
|
|
53
|
+
'\n' +
|
|
54
|
+
"If `throw redirect()` doesn't work:\n" +
|
|
55
|
+
' - **Make sure to add `pageContext.httpResponse.headers` to the HTTP response.** \n' +
|
|
56
|
+
' If you\'ve embedded Vike into your server using <Link text={<code>renderPage()</code>} href="/renderPage" />, then insepct whether `pageContext.httpResponse.headers` contains the `Location` header and double check that you\'re correctly adding all the headers defined by `pageContext.httpResponse.headers` to the HTTP response.\n' +
|
|
57
|
+
'\n' +
|
|
58
|
+
'\n' +
|
|
59
|
+
`<h2 id="see-also">{'See also'}</h2>\n` +
|
|
60
|
+
'\n' +
|
|
61
|
+
' - <Link href="/redirect" />\n' +
|
|
62
|
+
' - <Link href="/render" />\n' +
|
|
63
|
+
' - <Link href="/navigate" />\n' +
|
|
64
|
+
'\n' +
|
|
65
|
+
'\n' +
|
|
66
|
+
'export const headings = [{"headingId":"throw-redirect-vs-throw-render","headingLevel":2,"title":"`throw redirect()` VS `throw render()`"}, {"headingId":"debug","headingLevel":2,"title":"Debug"}, {"headingId":"see-also","headingLevel":2,"title":"See also"}];\n',
|
|
67
|
+
loc: {
|
|
68
|
+
file: '/home/rom/code/vike/docs/pages/abort/+Page.mdx',
|
|
69
|
+
start: {
|
|
70
|
+
line: 23,
|
|
71
|
+
column: 450,
|
|
72
|
+
offset: 1967,
|
|
73
|
+
_index: 0,
|
|
74
|
+
_bufferIndex: 444
|
|
75
|
+
},
|
|
76
|
+
end: {
|
|
77
|
+
line: 23,
|
|
78
|
+
column: 451,
|
|
79
|
+
offset: 1968,
|
|
80
|
+
_index: 0,
|
|
81
|
+
_bufferIndex: 445
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
frame: ''
|
|
85
|
+
};
|
|
@@ -9,7 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.clearLogs = exports.logErrorDebugNote = exports.logConfigErrorRecover = exports.logConfigError = exports.logConfigInfo = exports.
|
|
12
|
+
exports.clearLogs = exports.logErrorDebugNote = exports.logConfigErrorRecover = exports.logConfigError = exports.logConfigInfo = exports.logViteError = exports.logViteAny = void 0;
|
|
13
13
|
const abort_js_1 = require("../../../shared/route/abort.js");
|
|
14
14
|
const globalContext_js_1 = require("../../runtime/globalContext.js");
|
|
15
15
|
const loggerRuntime_js_1 = require("../../runtime/renderPage/loggerRuntime.js");
|
|
@@ -56,15 +56,17 @@ function logConfigErrorRecover() {
|
|
|
56
56
|
}
|
|
57
57
|
exports.logConfigErrorRecover = logConfigErrorRecover;
|
|
58
58
|
function logRuntimeError(err,
|
|
59
|
-
|
|
59
|
+
// httpRequestId is `null` when pre-rendering
|
|
60
60
|
httpRequestId) {
|
|
61
|
-
logErr(err, httpRequestId);
|
|
61
|
+
logErr(err, httpRequestId, false);
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
63
|
+
function logViteError(err,
|
|
64
|
+
// httpRequestId is `undefined` if development environment doesn't support async stores
|
|
65
|
+
httpRequestId) {
|
|
66
|
+
logErr(err, httpRequestId, true);
|
|
65
67
|
}
|
|
66
|
-
exports.
|
|
67
|
-
function logErr(err, httpRequestId = null) {
|
|
68
|
+
exports.logViteError = logViteError;
|
|
69
|
+
function logErr(err, httpRequestId = null, errorComesFromVite) {
|
|
68
70
|
(0, utils_js_1.warnIfErrorIsNotObject)(err);
|
|
69
71
|
if ((0, abort_js_1.isAbortError)(err) && !(0, isErrorDebug_js_1.isErrorDebug)()) {
|
|
70
72
|
return;
|
|
@@ -103,9 +105,10 @@ function logErr(err, httpRequestId = null) {
|
|
|
103
105
|
(0, log_js_1.logWithVikeTag)(picocolors_1.default.red(`Following error was thrown by the ${hookName}() hook defined at ${hookFilePath}`), 'error', category);
|
|
104
106
|
}
|
|
105
107
|
else if (category) {
|
|
106
|
-
logFallbackErrIntro(category);
|
|
108
|
+
logFallbackErrIntro(category, errorComesFromVite);
|
|
107
109
|
}
|
|
108
110
|
(0, log_js_1.logDirectly)(err, 'error');
|
|
111
|
+
// Needs to be called after logging the error.
|
|
109
112
|
(0, loggerProd_js_1.onRuntimeError)(err);
|
|
110
113
|
}
|
|
111
114
|
function logConfigError(err) {
|
|
@@ -140,12 +143,13 @@ function logConfigError(err) {
|
|
|
140
143
|
return;
|
|
141
144
|
}
|
|
142
145
|
if (category)
|
|
143
|
-
logFallbackErrIntro(category);
|
|
146
|
+
logFallbackErrIntro(category, false);
|
|
144
147
|
(0, log_js_1.logDirectly)(err, 'error');
|
|
145
148
|
}
|
|
146
149
|
exports.logConfigError = logConfigError;
|
|
147
|
-
function logFallbackErrIntro(category) {
|
|
148
|
-
|
|
150
|
+
function logFallbackErrIntro(category, errorComesFromVite) {
|
|
151
|
+
const msg = errorComesFromVite ? 'Transpilation error' : 'An error was thrown';
|
|
152
|
+
(0, log_js_1.logWithVikeTag)(picocolors_1.default.bold(picocolors_1.default.red(`[Error] ${msg}:`)), 'error', category);
|
|
149
153
|
}
|
|
150
154
|
function getConfigCategory() {
|
|
151
155
|
const category = getCategory() ?? 'config';
|
|
@@ -3,11 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.improveViteLogs = void 0;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
5
|
const loggerNotProd_js_1 = require("./loggerNotProd.js");
|
|
6
|
-
const errorWithCodeSnippet_js_1 = require("./loggerNotProd/errorWithCodeSnippet.js");
|
|
7
6
|
const getHttpRequestAsyncStore_js_1 = require("./getHttpRequestAsyncStore.js");
|
|
8
7
|
const removeSuperfluousViteLog_js_1 = require("./loggerVite/removeSuperfluousViteLog.js");
|
|
9
8
|
const isErrorDebug_js_1 = require("./isErrorDebug.js");
|
|
10
|
-
const loggerProd_js_1 = require("../../runtime/renderPage/loggerProd.js");
|
|
11
9
|
function improveViteLogs(config) {
|
|
12
10
|
intercept('info', config);
|
|
13
11
|
intercept('warn', config);
|
|
@@ -28,29 +26,25 @@ function intercept(logType, config) {
|
|
|
28
26
|
}
|
|
29
27
|
msg = cleanFirstViteLog(msg);
|
|
30
28
|
const store = (0, getHttpRequestAsyncStore_js_1.getHttpRequestAsyncStore)();
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if (options.error) {
|
|
30
|
+
// Vite does a poor job of handling errors.
|
|
31
|
+
// - It doesn't format error code snippets.
|
|
32
|
+
// - It only shows error.message which means that crucial information such as error.id isn't shown to the user.
|
|
33
|
+
(0, loggerNotProd_js_1.logViteError)(options.error, store?.httpRequestId);
|
|
34
|
+
// We swallow Vite's message: we didn't see it add any value so far.
|
|
35
|
+
// - It can even be confusing, such as the following:
|
|
36
|
+
// ```
|
|
37
|
+
// Error when evaluating SSR module virtual:vike:pageConfigValuesAll:server:/pages/abort: failed to import "/pages/abort/+Page.mdx"
|
|
38
|
+
// ```
|
|
39
|
+
(0, utils_js_1.assert)(!(0, isErrorDebug_js_1.isErrorDebug)());
|
|
33
40
|
return;
|
|
34
41
|
}
|
|
35
|
-
//
|
|
36
|
-
if (msg.startsWith('Transform failed with ') && store && logType === 'error') {
|
|
37
|
-
store.markErrorMessageAsLogged(msg);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (options.error && (0, errorWithCodeSnippet_js_1.isErrorWithCodeSnippet)(options.error)) {
|
|
41
|
-
(0, loggerNotProd_js_1.logViteErrorContainingCodeSnippet)(options.error);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
// Only allow Vite to clear its first log. All other clearing is controlled by vike.
|
|
42
|
+
// Only allow Vite to clear for its first log. All other clearing is controlled by vike.
|
|
45
43
|
if (options.clear)
|
|
46
44
|
(0, loggerNotProd_js_1.clearLogs)({ clearIfFirstLog: true });
|
|
47
|
-
if (options.error)
|
|
48
|
-
store?.markErrorAsLogged(options.error);
|
|
49
45
|
// Vite's default logger preprends the "[vite]" tag if and only if options.timestamp is true
|
|
50
46
|
const prependViteTag = options.timestamp || !!store?.httpRequestId;
|
|
51
47
|
(0, loggerNotProd_js_1.logViteAny)(msg, logType, store?.httpRequestId ?? null, prependViteTag);
|
|
52
|
-
if (options.error)
|
|
53
|
-
(0, loggerProd_js_1.onRuntimeError)(options.error);
|
|
54
48
|
};
|
|
55
49
|
}
|
|
56
50
|
function cleanFirstViteLog(msg) {
|
|
@@ -41,4 +41,4 @@ __exportStar(require("../../utils/assertKeys.js"), exports);
|
|
|
41
41
|
__exportStar(require("../../utils/injectRollupInputs.js"), exports);
|
|
42
42
|
__exportStar(require("../../utils/humanizeTime.js"), exports);
|
|
43
43
|
__exportStar(require("../../utils/pLimit.js"), exports);
|
|
44
|
-
__exportStar(require("../../utils/
|
|
44
|
+
__exportStar(require("../../utils/assertVersion.js"), exports);
|
|
@@ -20,10 +20,14 @@ function logErrorProd(err, _httpRquestId) {
|
|
|
20
20
|
// We ensure we print a string; Cloudflare Workers doesn't seem to properly stringify `Error` objects.
|
|
21
21
|
const errStr = (0, utils_js_1.isObject)(err) && 'stack' in err ? String(err.stack) : String(err);
|
|
22
22
|
console.error(picocolors_1.default.red(errStr));
|
|
23
|
+
// Needs to be called after logging the error.
|
|
23
24
|
onRuntimeError(err);
|
|
24
25
|
}
|
|
25
26
|
exports.logErrorProd = logErrorProd;
|
|
26
|
-
// Every server-side runtime error is expected to go through onRuntimeError()
|
|
27
|
+
// Every server-side runtime error is expected to go through `onRuntimeError()`.
|
|
28
|
+
// - onRuntimeError(err) should always be called after `console.error(err)`.
|
|
29
|
+
// - Because the error hint of logErrorHint(err) should be shown *after* the error.
|
|
30
|
+
// - In principle, any runtime error is (or at least should) be catched by Vike, otherwise Vike couldn't render the error page.
|
|
27
31
|
function onRuntimeError(err) {
|
|
28
32
|
// The more runtime errors we pass to logErrorHint() the better.
|
|
29
33
|
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
@@ -27,8 +27,7 @@ const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage.ts', {
|
|
|
27
27
|
pendingRequestsCount: 0
|
|
28
28
|
});
|
|
29
29
|
let renderPage_wrapper = async (_httpRequestId, ret) => ({
|
|
30
|
-
pageContextReturn: await ret()
|
|
31
|
-
onRequestDone: () => { }
|
|
30
|
+
pageContextReturn: await ret()
|
|
32
31
|
});
|
|
33
32
|
const renderPage_addWrapper = (wrapper) => {
|
|
34
33
|
renderPage_wrapper = wrapper;
|
|
@@ -48,10 +47,9 @@ async function renderPage(pageContextInit) {
|
|
|
48
47
|
const { urlOriginal } = pageContextInit;
|
|
49
48
|
logHttpRequest(urlOriginal, httpRequestId);
|
|
50
49
|
globalObject.pendingRequestsCount++;
|
|
51
|
-
const { pageContextReturn
|
|
50
|
+
const { pageContextReturn } = await renderPage_wrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
|
|
52
51
|
logHttpResponse(urlOriginal, httpRequestId, pageContextReturn);
|
|
53
52
|
globalObject.pendingRequestsCount--;
|
|
54
|
-
onRequestDone();
|
|
55
53
|
(0, utils_js_1.checkType)(pageContextReturn);
|
|
56
54
|
return pageContextReturn;
|
|
57
55
|
}
|
|
@@ -111,7 +111,6 @@ function parseRouteString(routeString) {
|
|
|
111
111
|
}
|
|
112
112
|
exports.parseRouteString = parseRouteString;
|
|
113
113
|
function getUrlFromRouteString(routeString) {
|
|
114
|
-
(0, utils_js_2.assert)(routeString.startsWith('/'));
|
|
115
114
|
if (isStaticRouteString(routeString)) {
|
|
116
115
|
const url = routeString;
|
|
117
116
|
return url;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.assertNodeVersion = void 0;
|
|
4
|
-
const assert_js_1 = require("./assert.js");
|
|
5
4
|
const isNodeJS_js_1 = require("./isNodeJS.js");
|
|
6
|
-
const
|
|
7
|
-
// package.json#engines.node isn't enough as users can ignore it
|
|
5
|
+
const assertVersion_js_1 = require("./assertVersion.js");
|
|
6
|
+
// node_modules/vike/package.json#engines.node isn't enough as users can ignore it
|
|
8
7
|
function assertNodeVersion() {
|
|
9
8
|
if (!(0, isNodeJS_js_1.isNodeJS)())
|
|
10
9
|
return;
|
|
11
10
|
const version = process.versions.node;
|
|
12
|
-
(0,
|
|
11
|
+
(0, assertVersion_js_1.assertVersion)('Node.js', version, '16.0.0');
|
|
13
12
|
}
|
|
14
13
|
exports.assertNodeVersion = assertNodeVersion;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isVersionOrAbove = void 0;
|
|
3
|
+
exports.isVersionOrAbove = exports.assertVersion = void 0;
|
|
4
4
|
const assert_js_1 = require("./assert.js");
|
|
5
|
+
function assertVersion(dependencyName, versionActual, versionExpected) {
|
|
6
|
+
(0, assert_js_1.assertUsage)(isVersionOrAbove(versionActual, versionExpected), `${dependencyName} ${versionActual} isn't supported, use ${dependencyName} >= ${versionExpected} instead.`);
|
|
7
|
+
}
|
|
8
|
+
exports.assertVersion = assertVersion;
|
|
5
9
|
function isVersionOrAbove(versionActual, versionExpected) {
|
|
6
10
|
const p1 = parseVersion(versionActual);
|
|
7
11
|
const p2 = parseVersion(versionExpected);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PROJECT_VERSION = exports.projectInfo = void 0;
|
|
4
4
|
const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
|
|
5
|
-
const PROJECT_VERSION = '0.4.
|
|
5
|
+
const PROJECT_VERSION = '0.4.165';
|
|
6
6
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
7
7
|
const projectInfo = {
|
|
8
8
|
projectName: 'Vike',
|
|
@@ -3,7 +3,8 @@ export { plugin };
|
|
|
3
3
|
// TODO/v1-release: remove
|
|
4
4
|
export { plugin as ssr };
|
|
5
5
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
6
|
-
import {
|
|
6
|
+
import { version } from 'vite';
|
|
7
|
+
import { assertNodeEnv_onVikePluginLoad, assertUsage, assertVersion, markEnvAsVikePluginLoaded } from './utils.js';
|
|
7
8
|
import { buildConfig } from './plugins/buildConfig.js';
|
|
8
9
|
import { previewConfig } from './plugins/previewConfig.js';
|
|
9
10
|
import { autoFullBuild } from './plugins/autoFullBuild.js';
|
|
@@ -25,6 +26,7 @@ import pc from '@brillout/picocolors';
|
|
|
25
26
|
import { fileEnv } from './plugins/fileEnv.js';
|
|
26
27
|
assertNodeEnv_onVikePluginLoad();
|
|
27
28
|
markEnvAsVikePluginLoaded();
|
|
29
|
+
assertViteVersion();
|
|
28
30
|
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
29
31
|
function plugin(vikeConfig) {
|
|
30
32
|
const plugins = [
|
|
@@ -63,3 +65,7 @@ Object.defineProperty(plugin, 'apply', {
|
|
|
63
65
|
assertUsage(false, `Add ${pc.cyan('vike()')} instead of ${pc.cyan('vike')} to vite.config.js#plugins (i.e. call the function and add the return value instead of adding the function itself)`, { showStackTrace: true });
|
|
64
66
|
}
|
|
65
67
|
});
|
|
68
|
+
// node_modules/vike/package.json#peerDependencies.vite isn't enough as users can ignore it
|
|
69
|
+
function assertViteVersion() {
|
|
70
|
+
assertVersion('Vite', version, '4.4.0');
|
|
71
|
+
}
|
|
@@ -4,7 +4,6 @@ type HttpRequestAsyncStore = {
|
|
|
4
4
|
httpRequestId: number;
|
|
5
5
|
shouldErrorBeSwallowed: (err: unknown) => boolean;
|
|
6
6
|
markErrorAsLogged: (err: unknown) => void;
|
|
7
|
-
markErrorMessageAsLogged: (errMsg: string) => void;
|
|
8
7
|
errorDebugNoteAlreadyShown: boolean;
|
|
9
8
|
};
|
|
10
9
|
declare function installHttpRequestAsyncStore(): Promise<void>;
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
export { getHttpRequestAsyncStore };
|
|
12
12
|
export { installHttpRequestAsyncStore };
|
|
13
13
|
import { renderPage_addWrapper } from '../../runtime/renderPage.js';
|
|
14
|
-
import { assert, assertIsNotProductionRuntime, isObject } from '../utils.js';
|
|
14
|
+
import { assert, assertIsNotProductionRuntime, isObject, unique } from '../utils.js';
|
|
15
15
|
import { getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js';
|
|
16
16
|
import { logErrorDebugNote } from './loggerNotProd.js';
|
|
17
17
|
import { isEquivalentErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js';
|
|
18
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
18
19
|
assertIsNotProductionRuntime();
|
|
19
20
|
let asyncLocalStorage = null;
|
|
20
21
|
async function installHttpRequestAsyncStore() {
|
|
@@ -44,29 +45,14 @@ async function installHttpRequestAsyncStore() {
|
|
|
44
45
|
return false;
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
|
-
// Remove once https://github.com/vitejs/vite/pull/13495 is released
|
|
48
|
-
const swallowedErrorMessages = new Set();
|
|
49
|
-
const markErrorMessageAsLogged = (errMsg) => {
|
|
50
|
-
swallowedErrorMessages.add(errMsg);
|
|
51
|
-
};
|
|
52
|
-
const onRequestDone = () => {
|
|
53
|
-
swallowedErrorMessages.forEach((errMsg) => {
|
|
54
|
-
if (!Array.from(loggedErrors).some((err) => String(err).includes(errMsg))) {
|
|
55
|
-
console.error('loggedErrors', loggedErrors);
|
|
56
|
-
console.error('swallowedErrorMessages', swallowedErrorMessages);
|
|
57
|
-
assert(false);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
48
|
const store = {
|
|
62
49
|
httpRequestId,
|
|
63
50
|
markErrorAsLogged,
|
|
64
|
-
markErrorMessageAsLogged,
|
|
65
51
|
shouldErrorBeSwallowed,
|
|
66
52
|
errorDebugNoteAlreadyShown: false
|
|
67
53
|
};
|
|
68
54
|
const pageContextReturn = await asyncLocalStorage.run(store, renderPage);
|
|
69
|
-
return { pageContextReturn
|
|
55
|
+
return { pageContextReturn };
|
|
70
56
|
});
|
|
71
57
|
return;
|
|
72
58
|
}
|
|
@@ -90,14 +76,20 @@ function isEquivalent(err1, err2) {
|
|
|
90
76
|
}
|
|
91
77
|
if (isEquivalentErrorWithCodeSnippet(err1, err2))
|
|
92
78
|
return true;
|
|
93
|
-
if (
|
|
94
|
-
Object.keys(
|
|
95
|
-
|
|
96
|
-
|
|
79
|
+
if (unique([
|
|
80
|
+
// error.message and error.stack aren't enumerable and therefore not listed by Object.keys()
|
|
81
|
+
'message',
|
|
82
|
+
'stack',
|
|
83
|
+
...Object.keys(err1),
|
|
84
|
+
...Object.keys(err2)
|
|
85
|
+
]).every((k) => {
|
|
86
|
+
// isDeepStrictEqual() need to compare error.position wich is an object.
|
|
87
|
+
if (isDeepStrictEqual(err1[k], err2[k]))
|
|
88
|
+
return true;
|
|
89
|
+
// console.log('diff', k)
|
|
90
|
+
return false;
|
|
91
|
+
})) {
|
|
97
92
|
return true;
|
|
98
93
|
}
|
|
99
94
|
return false;
|
|
100
95
|
}
|
|
101
|
-
function isDefinedAndSame(val1, val2) {
|
|
102
|
-
return val1 && val1 === val2;
|
|
103
|
-
}
|
package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errMdx2.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare const errMdx2: {
|
|
2
|
+
reason: string;
|
|
3
|
+
line: number;
|
|
4
|
+
column: number;
|
|
5
|
+
position: {
|
|
6
|
+
start: {
|
|
7
|
+
line: number;
|
|
8
|
+
column: number;
|
|
9
|
+
offset: number;
|
|
10
|
+
_index: number;
|
|
11
|
+
_bufferIndex: number;
|
|
12
|
+
};
|
|
13
|
+
end: {
|
|
14
|
+
line: number;
|
|
15
|
+
column: number;
|
|
16
|
+
offset: number;
|
|
17
|
+
_index: number;
|
|
18
|
+
_bufferIndex: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
source: string;
|
|
22
|
+
ruleId: string;
|
|
23
|
+
plugin: string;
|
|
24
|
+
id: string;
|
|
25
|
+
pluginCode: string;
|
|
26
|
+
loc: {
|
|
27
|
+
file: string;
|
|
28
|
+
start: {
|
|
29
|
+
line: number;
|
|
30
|
+
column: number;
|
|
31
|
+
offset: number;
|
|
32
|
+
_index: number;
|
|
33
|
+
_bufferIndex: number;
|
|
34
|
+
};
|
|
35
|
+
end: {
|
|
36
|
+
line: number;
|
|
37
|
+
column: number;
|
|
38
|
+
offset: number;
|
|
39
|
+
_index: number;
|
|
40
|
+
_bufferIndex: number;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
frame: string;
|
|
44
|
+
};
|
package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errMdx2.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export const errMdx2 = {
|
|
2
|
+
reason: 'Unexpected closing slash `/` in tag, expected an open tag first',
|
|
3
|
+
line: 23,
|
|
4
|
+
column: 450,
|
|
5
|
+
position: {
|
|
6
|
+
start: {
|
|
7
|
+
line: 23,
|
|
8
|
+
column: 450,
|
|
9
|
+
offset: 1967,
|
|
10
|
+
_index: 0,
|
|
11
|
+
_bufferIndex: 444
|
|
12
|
+
},
|
|
13
|
+
end: {
|
|
14
|
+
line: 23,
|
|
15
|
+
column: 451,
|
|
16
|
+
offset: 1968,
|
|
17
|
+
_index: 0,
|
|
18
|
+
_bufferIndex: 445
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
source: 'mdast-util-mdx-jsx',
|
|
22
|
+
ruleId: 'unexpected-closing-slash',
|
|
23
|
+
plugin: '@mdx-js/rollup',
|
|
24
|
+
id: '/home/rom/code/vike/docs/pages/abort/+Page.mdx',
|
|
25
|
+
pluginCode: "import { Link } from '@brillout/docpress'\n" +
|
|
26
|
+
'\n' +
|
|
27
|
+
'By using <Link href="/render" text={<code>throw render()</code>}></Link> or <Link href="/redirect" text={<code>throw redirect()</code>}></Link> you abort the rendering of the current page and render something else instead.\n' +
|
|
28
|
+
'\n' +
|
|
29
|
+
`<h2 id="throw-redirect-vs-throw-render"><code>{'throw redirect()'}</code>{' VS '}<code>{'throw render()'}</code></h2>\n` +
|
|
30
|
+
'\n' +
|
|
31
|
+
'While `throw redirect()` changes the URL, `throw render()` preserves it:\n' +
|
|
32
|
+
" - If a user goes to `/admin` and `throw redirect('/login')` is called, then the user will see the new URL `/login` in the browser's address bar.\n" +
|
|
33
|
+
" - If a user goes to `/admin` and `throw render('/login')` is called, then the user keeps seeing the same URL `/admin` in the browser's address bar.\n" +
|
|
34
|
+
'\n' +
|
|
35
|
+
"In general, we recommend using `throw render('/login')` instead of `throw redirect('/login')` as it preserves the URL and, therefore, the user's intention. We further explain this techniue at <Link href=\"/auth#login-flow\" />.\n" +
|
|
36
|
+
'\n' +
|
|
37
|
+
'\n' +
|
|
38
|
+
`<h2 id="debug">{'Debug'}</h2>\n` +
|
|
39
|
+
'\n' +
|
|
40
|
+
"If `throw redirect()` or `throw render()` doesn't work:\n" +
|
|
41
|
+
" - **Make sure `throw redirect()` / `throw render()` isn't intercepted.** \n" +
|
|
42
|
+
" In developement, check your server logs for the following log. If this log is missing then it means that Vike didn't catch the `throw redirect()` / `throw render()` exception: some other code is intercepting it preventing Vike from catching it.\n" +
|
|
43
|
+
' ```\n' +
|
|
44
|
+
" 10:00:00 AM [vike][request(42)] throw redirect('/some-url') intercepted while\n" +
|
|
45
|
+
' rendering /some-other-url\n' +
|
|
46
|
+
' ```\n' +
|
|
47
|
+
' > Most notably, using `throw redirect()` / `throw render()` inside a UI component usually doesn\'t work because most <Link href="/ui-framework">UI framework</Link> will intercept the execption and thus Vike won\'t be able to catch it. Instead, consider using `throw redirect()` / `throw render()` in a Vike hook such as <Link href="/guard">guard()</Link> or <Link href="/data">data()</Link>, or consider using <Link href="/navigate" />`navigate()`</Link>.\n' +
|
|
48
|
+
' - **Make sure to use `throw redirect()` / `throw render()` within a Vike hook.** \n' +
|
|
49
|
+
" If you use `throw redirect()` / `throw render()` outside of Vike hooks, for example in some server middleware code then Vike won't be able to intercept it.\n" +
|
|
50
|
+
'\n' +
|
|
51
|
+
"If `throw redirect()` doesn't work:\n" +
|
|
52
|
+
' - **Make sure to add `pageContext.httpResponse.headers` to the HTTP response.** \n' +
|
|
53
|
+
' If you\'ve embedded Vike into your server using <Link text={<code>renderPage()</code>} href="/renderPage" />, then insepct whether `pageContext.httpResponse.headers` contains the `Location` header and double check that you\'re correctly adding all the headers defined by `pageContext.httpResponse.headers` to the HTTP response.\n' +
|
|
54
|
+
'\n' +
|
|
55
|
+
'\n' +
|
|
56
|
+
`<h2 id="see-also">{'See also'}</h2>\n` +
|
|
57
|
+
'\n' +
|
|
58
|
+
' - <Link href="/redirect" />\n' +
|
|
59
|
+
' - <Link href="/render" />\n' +
|
|
60
|
+
' - <Link href="/navigate" />\n' +
|
|
61
|
+
'\n' +
|
|
62
|
+
'\n' +
|
|
63
|
+
'export const headings = [{"headingId":"throw-redirect-vs-throw-render","headingLevel":2,"title":"`throw redirect()` VS `throw render()`"}, {"headingId":"debug","headingLevel":2,"title":"Debug"}, {"headingId":"see-also","headingLevel":2,"title":"See also"}];\n',
|
|
64
|
+
loc: {
|
|
65
|
+
file: '/home/rom/code/vike/docs/pages/abort/+Page.mdx',
|
|
66
|
+
start: {
|
|
67
|
+
line: 23,
|
|
68
|
+
column: 450,
|
|
69
|
+
offset: 1967,
|
|
70
|
+
_index: 0,
|
|
71
|
+
_bufferIndex: 444
|
|
72
|
+
},
|
|
73
|
+
end: {
|
|
74
|
+
line: 23,
|
|
75
|
+
column: 451,
|
|
76
|
+
offset: 1968,
|
|
77
|
+
_index: 0,
|
|
78
|
+
_bufferIndex: 445
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
frame: ''
|
|
82
|
+
};
|
|
@@ -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';
|
|
@@ -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
|
}
|
|
@@ -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
3
|
import { onProjectInfo } from './assertSingleInstance.js';
|
|
4
|
-
const PROJECT_VERSION = '0.4.
|
|
4
|
+
const PROJECT_VERSION = '0.4.165';
|
|
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",
|
|
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": {
|