vike 0.4.164 → 0.4.165-commit-2598887
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 +7 -1
- package/dist/cjs/node/plugin/plugins/buildConfig.js +67 -57
- 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 +8 -2
- package/dist/esm/node/plugin/plugins/buildConfig.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +67 -57
- 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/page-configs/Config/PageContextConfig.d.ts +1 -1
- 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
|
@@ -25,71 +25,81 @@ function buildConfig() {
|
|
|
25
25
|
let isSsrBuild;
|
|
26
26
|
let outDirs;
|
|
27
27
|
let config;
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
name: 'vike:buildConfig:configResolved',
|
|
31
|
+
apply: 'build',
|
|
32
|
+
enforce: 'post',
|
|
33
|
+
configResolved: {
|
|
34
|
+
order: 'post',
|
|
35
|
+
async handler(config_) {
|
|
36
|
+
config = config_;
|
|
37
|
+
assertNodeEnv_build();
|
|
38
|
+
assertRollupInput(config);
|
|
39
|
+
const entries = await getEntries(config);
|
|
40
|
+
assert(Object.keys(entries).length > 0);
|
|
41
|
+
config.build.rollupOptions.input = injectRollupInputs(entries, config);
|
|
42
|
+
addLogHook();
|
|
43
|
+
outDirs = getOutDirs(config);
|
|
44
|
+
{
|
|
45
|
+
isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config, false));
|
|
46
|
+
if (isServerAssetsFixEnabled) {
|
|
47
|
+
// https://github.com/vikejs/vike/issues/1339
|
|
48
|
+
config.build.ssrEmitAssets = true;
|
|
49
|
+
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
|
|
50
|
+
config.build.cssMinify = 'esbuild';
|
|
51
|
+
}
|
|
50
52
|
}
|
|
51
53
|
}
|
|
54
|
+
},
|
|
55
|
+
config(config) {
|
|
56
|
+
assertNodeEnv_build();
|
|
57
|
+
isSsrBuild = viteIsSSR(config);
|
|
58
|
+
return {
|
|
59
|
+
build: {
|
|
60
|
+
outDir: resolveOutDir(config),
|
|
61
|
+
manifest: manifestTempFile,
|
|
62
|
+
copyPublicDir: !isSsrBuild
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
buildStart() {
|
|
67
|
+
assertNodeEnv_build();
|
|
52
68
|
}
|
|
53
69
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
await fs.
|
|
81
|
-
|
|
82
|
-
else {
|
|
83
|
-
const clientManifestMod = await fixServerAssets(config);
|
|
84
|
-
await fs.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
|
|
70
|
+
{
|
|
71
|
+
name: 'vike:buildConfig:writeBundle',
|
|
72
|
+
apply: 'build',
|
|
73
|
+
// Make sure other writeBundle() hooks are called after this writeBundle() hook.
|
|
74
|
+
// - set_constant_ASSETS_MAP() needs to be called before dist/server/ code is executed.
|
|
75
|
+
// - For example, the writeBundle() hook of vite-plugin-vercel needs to be called after this writeBundle() hook, otherwise: https://github.com/vikejs/vike/issues/1527
|
|
76
|
+
enforce: 'pre',
|
|
77
|
+
writeBundle: {
|
|
78
|
+
order: 'pre',
|
|
79
|
+
sequential: true,
|
|
80
|
+
async handler(options, bundle) {
|
|
81
|
+
if (isSsrBuild) {
|
|
82
|
+
// Ideally we'd move dist/_temp_manifest.json to dist/server/client-assets.json instead of dist/assets.json
|
|
83
|
+
// - But we can't because there is no guarentee whether dist/server/ is generated before or after dist/client/ (generating dist/server/ after dist/client/ erases dist/server/client-assets.json)
|
|
84
|
+
// - We'll able to do so once we replace `$ vite build` with `$ vike build`
|
|
85
|
+
const assetsJsonFilePath = path.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
86
|
+
const clientManifestFilePath = path.posix.join(outDirs.outDirClient, manifestTempFile);
|
|
87
|
+
const serverManifestFilePath = path.posix.join(outDirs.outDirServer, manifestTempFile);
|
|
88
|
+
if (!isServerAssetsFixEnabled) {
|
|
89
|
+
await fs.copyFile(clientManifestFilePath, assetsJsonFilePath);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const clientManifestMod = await fixServerAssets(config);
|
|
93
|
+
await fs.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
|
|
94
|
+
}
|
|
95
|
+
await fs.rm(clientManifestFilePath);
|
|
96
|
+
await fs.rm(serverManifestFilePath);
|
|
97
|
+
await set_constant_ASSETS_MAP(options, bundle);
|
|
85
98
|
}
|
|
86
|
-
await fs.rm(clientManifestFilePath);
|
|
87
|
-
await fs.rm(serverManifestFilePath);
|
|
88
|
-
await set_constant_ASSETS_MAP(options, bundle);
|
|
89
99
|
}
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
|
-
|
|
102
|
+
];
|
|
93
103
|
}
|
|
94
104
|
async function getEntries(config) {
|
|
95
105
|
const configVike = await getConfigVike(config);
|
|
@@ -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
|
}
|
|
@@ -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,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-2598887";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.
|
|
6
|
+
projectVersion: "0.4.165-commit-2598887";
|
|
7
7
|
};
|