vike 0.4.222-commit-5513d32 → 0.4.222-commit-fab3841
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/client/shared/getPageContextProxyForUser.js +1 -1
- package/dist/cjs/node/api/prepareViteApiCall.js +1 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +2 -17
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +2 -2
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +5 -5
- package/dist/cjs/node/plugin/shared/viteIsSSR.js +19 -10
- package/dist/cjs/node/runtime/globalContext.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +24 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +1 -1
- package/dist/cjs/node/runtime/renderPage/isNewError.js +1 -1
- package/dist/cjs/node/runtime/renderPage/isVikeConfigInvalid.js +10 -0
- package/dist/cjs/node/runtime/renderPage.js +44 -30
- package/dist/cjs/shared/getPageContextRequestUrl.js +1 -1
- package/dist/cjs/shared/getPageContextUrlComputed.js +10 -7
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +1 -1
- package/dist/cjs/utils/assertSingleInstance.js +1 -1
- package/dist/cjs/utils/getGlobalObject.js +2 -6
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.js +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +1 -1
- package/dist/esm/client/client-routing-runtime/history.js +1 -1
- package/dist/esm/client/client-routing-runtime/prefetch.js +1 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
- package/dist/esm/client/client-routing-runtime/scrollRestoration.js +1 -1
- package/dist/esm/client/shared/getPageContextProxyForUser.js +1 -1
- package/dist/esm/node/api/prepareViteApiCall.js +1 -1
- package/dist/esm/node/plugin/plugins/envVars.js +2 -17
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +3 -3
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +5 -5
- package/dist/esm/node/plugin/shared/viteIsSSR.d.ts +7 -4
- package/dist/esm/node/plugin/shared/viteIsSSR.js +20 -11
- package/dist/esm/node/runtime/globalContext.js +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +24 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.js +1 -1
- package/dist/esm/node/runtime/renderPage/isNewError.js +1 -1
- package/dist/esm/node/runtime/renderPage/isVikeConfigInvalid.d.ts +6 -0
- package/dist/esm/node/runtime/renderPage/isVikeConfigInvalid.js +8 -0
- package/dist/esm/node/runtime/renderPage.js +45 -31
- package/dist/esm/shared/getPageContextRequestUrl.js +1 -1
- package/dist/esm/shared/getPageContextUrlComputed.js +10 -7
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/types.d.ts +6 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.js +1 -1
- package/dist/esm/utils/assertSingleInstance.js +1 -1
- package/dist/esm/utils/getGlobalObject.d.ts +3 -2
- package/dist/esm/utils/getGlobalObject.js +2 -6
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/runtime/renderPage/isConfigInvalid.js +0 -10
- package/dist/esm/node/runtime/renderPage/isConfigInvalid.d.ts +0 -6
- package/dist/esm/node/runtime/renderPage/isConfigInvalid.js +0 -8
|
@@ -4,6 +4,7 @@ import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArr
|
|
|
4
4
|
import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
|
|
5
5
|
import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
6
6
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
7
|
+
import { viteIsSSR_safe } from '../shared/viteIsSSR.js';
|
|
7
8
|
// TODO/enventually: (after we implemented vike.config.js)
|
|
8
9
|
// - Make import.meta.env work inside +config.js
|
|
9
10
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
@@ -36,7 +37,7 @@ function envVarsPlugin() {
|
|
|
36
37
|
if (!code.includes('import.meta.env.'))
|
|
37
38
|
return;
|
|
38
39
|
const isBuild = config.command === 'build';
|
|
39
|
-
const isClientSide =
|
|
40
|
+
const isClientSide = !viteIsSSR_safe(config, options);
|
|
40
41
|
Object.entries(envsAll)
|
|
41
42
|
.filter(([key]) => {
|
|
42
43
|
// Already handled by Vite
|
|
@@ -82,19 +83,3 @@ function envVarsPlugin() {
|
|
|
82
83
|
function applyEnvVar(envStatementRegEx, envVal, code) {
|
|
83
84
|
return code.replace(envStatementRegEx, JSON.stringify(envVal));
|
|
84
85
|
}
|
|
85
|
-
function getIsClientSide(config, options) {
|
|
86
|
-
const isBuild = config.command === 'build';
|
|
87
|
-
if (isBuild) {
|
|
88
|
-
assert(typeof config.build.ssr === 'boolean');
|
|
89
|
-
const isServerSide = config.build.ssr;
|
|
90
|
-
if (options !== undefined) {
|
|
91
|
-
assert(options.ssr === isServerSide);
|
|
92
|
-
}
|
|
93
|
-
return !isServerSide;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
assert(typeof options?.ssr === 'boolean');
|
|
97
|
-
const isServerSide = options.ssr;
|
|
98
|
-
return !isServerSide;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
@@ -17,7 +17,7 @@ import { fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
|
|
|
17
17
|
import { getVikeConfig, isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
|
|
18
18
|
import { assertV1Design } from '../../shared/assertV1Design.js';
|
|
19
19
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
20
|
-
import {
|
|
20
|
+
import { viteIsSSR_safe } from '../shared/viteIsSSR.js';
|
|
21
21
|
const extractAssetsRE = /(\?|&)extractAssets(?:&|$)/;
|
|
22
22
|
const rawRE = /(\?|&)raw(?:&|$)/;
|
|
23
23
|
const urlRE = /(\?|&)url(?:&|$)/;
|
|
@@ -46,7 +46,7 @@ function extractAssetsPlugin() {
|
|
|
46
46
|
}
|
|
47
47
|
// TODO/now: add meta.default
|
|
48
48
|
assert(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
|
|
49
|
-
assert(!
|
|
49
|
+
assert(!viteIsSSR_safe(config, options));
|
|
50
50
|
const importStatements = await getImportStatements(src);
|
|
51
51
|
const moduleNames = getImportedModules(importStatements);
|
|
52
52
|
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
@@ -63,7 +63,7 @@ function extractAssetsPlugin() {
|
|
|
63
63
|
// - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
64
64
|
enforce: 'pre',
|
|
65
65
|
async resolveId(source, importer, options) {
|
|
66
|
-
if (
|
|
66
|
+
if (viteIsSSR_safe(config, options)) {
|
|
67
67
|
// When building for the server, there should never be a `?extractAssets` query
|
|
68
68
|
assert(!extractAssetsRE.test(source));
|
|
69
69
|
assert(importer === undefined || !extractAssetsRE.test(importer));
|
|
@@ -8,7 +8,7 @@ import { normalizeId } from '../shared/normalizeId.js';
|
|
|
8
8
|
import { viteIsSSR_options } from '../shared/viteIsSSR.js';
|
|
9
9
|
const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
|
|
10
10
|
const debug = createDebugger('vike:extractExportNames');
|
|
11
|
-
const globalObject = getGlobalObject('extractExportNamesPlugin.ts', {});
|
|
11
|
+
const globalObject = getGlobalObject('plugins/extractExportNamesPlugin.ts', {});
|
|
12
12
|
function extractExportNamesPlugin() {
|
|
13
13
|
let isDev = false;
|
|
14
14
|
return {
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -11,7 +11,7 @@ import { getEnvVarObject } from '../../../../shared/getEnvVarObject.js';
|
|
|
11
11
|
const execA = promisify(exec);
|
|
12
12
|
const debug = createDebugger('vike:crawl');
|
|
13
13
|
assertIsNotProductionRuntime();
|
|
14
|
-
assertIsSingleModuleInstance('crawlPlusFiles.ts');
|
|
14
|
+
assertIsSingleModuleInstance('getVikeConfig/crawlPlusFiles.ts');
|
|
15
15
|
let gitIsNotUsable = false;
|
|
16
16
|
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
|
|
17
17
|
assertPosixPath(userRootDir);
|
|
@@ -8,7 +8,7 @@ export { getConfigDefinitionOptional };
|
|
|
8
8
|
import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, includes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, assertKeys, objectKeys, objectFromEntries, unique, isCallable, makeFirst, lowerFirst } from '../../../utils.js';
|
|
9
9
|
import { configDefinitionsBuiltIn } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
10
10
|
import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
|
|
11
|
-
import {
|
|
11
|
+
import { isVikeConfigInvalid, isVikeConfigInvalid_set } from '../../../../runtime/renderPage/isVikeConfigInvalid.js';
|
|
12
12
|
import { getViteDevServer } from '../../../../runtime/globalContext.js';
|
|
13
13
|
import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNotProd.js';
|
|
14
14
|
import { removeSuperfluousViteLog_enable, removeSuperfluousViteLog_disable } from '../../../shared/loggerVite/removeSuperfluousViteLog.js';
|
|
@@ -37,7 +37,7 @@ function reloadVikeConfig(config) {
|
|
|
37
37
|
handleReloadSideEffects();
|
|
38
38
|
}
|
|
39
39
|
async function handleReloadSideEffects() {
|
|
40
|
-
wasConfigInvalid = !!
|
|
40
|
+
wasConfigInvalid = !!isVikeConfigInvalid;
|
|
41
41
|
const vikeConfigPromisePrevious = vikeConfigPromise;
|
|
42
42
|
try {
|
|
43
43
|
await vikeConfigPromise;
|
|
@@ -52,7 +52,7 @@ async function handleReloadSideEffects() {
|
|
|
52
52
|
// Let the next handleReloadSideEffects() call handle side effects
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
|
-
if (!
|
|
55
|
+
if (!isVikeConfigInvalid) {
|
|
56
56
|
if (wasConfigInvalid) {
|
|
57
57
|
wasConfigInvalid = false;
|
|
58
58
|
logConfigErrorRecover();
|
|
@@ -105,13 +105,13 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
|
|
|
105
105
|
if (!hasError) {
|
|
106
106
|
assert(ret);
|
|
107
107
|
assert(err === undefined);
|
|
108
|
-
|
|
108
|
+
isVikeConfigInvalid_set(false);
|
|
109
109
|
return ret;
|
|
110
110
|
}
|
|
111
111
|
else {
|
|
112
112
|
assert(ret === undefined);
|
|
113
113
|
assert(err);
|
|
114
|
-
|
|
114
|
+
isVikeConfigInvalid_set({ err });
|
|
115
115
|
if (!isDev) {
|
|
116
116
|
assert(getViteDevServer() === null);
|
|
117
117
|
throw err;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type { ResolvedConfig, UserConfig } from 'vite';
|
|
2
1
|
export { viteIsSSR };
|
|
3
2
|
export { viteIsSSR_options };
|
|
3
|
+
export { viteIsSSR_safe };
|
|
4
|
+
import type { ResolvedConfig, UserConfig } from 'vite';
|
|
4
5
|
declare function viteIsSSR(config: ResolvedConfig | UserConfig): boolean;
|
|
5
|
-
|
|
6
|
+
declare function viteIsSSR_options(options: {
|
|
7
|
+
ssr?: boolean;
|
|
8
|
+
} | undefined): boolean;
|
|
9
|
+
declare function viteIsSSR_safe(config: ResolvedConfig, options: {
|
|
6
10
|
ssr?: boolean;
|
|
7
|
-
};
|
|
8
|
-
declare function viteIsSSR_options(options: Options): boolean;
|
|
11
|
+
} | undefined): boolean;
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
import { assert } from '../../../utils/assert.js';
|
|
2
|
-
import { isObject } from '../../../utils/isObject.js';
|
|
3
1
|
export { viteIsSSR };
|
|
4
2
|
export { viteIsSSR_options };
|
|
3
|
+
export { viteIsSSR_safe };
|
|
4
|
+
import { assert } from '../../../utils/assert.js';
|
|
5
5
|
function viteIsSSR(config) {
|
|
6
6
|
return !!config?.build?.ssr;
|
|
7
7
|
}
|
|
8
|
-
// https://github.com/vitejs/vite/discussions/5109#discussioncomment-1450726
|
|
9
8
|
function viteIsSSR_options(options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
return !!options?.ssr;
|
|
10
|
+
}
|
|
11
|
+
// Vite is quite messy about setting `ssr: boolean`, thus we use an extra safe implemention for security purposes.
|
|
12
|
+
// It's used for .client.js and .server.js guarantee thus we use agressive assert() calls for added safety.
|
|
13
|
+
function viteIsSSR_safe(config, options) {
|
|
14
|
+
if (config.command === 'build') {
|
|
15
|
+
assert(typeof config.build.ssr === 'boolean');
|
|
16
|
+
const val = config.build.ssr;
|
|
17
|
+
if (options?.ssr !== undefined)
|
|
18
|
+
assert(val === options.ssr);
|
|
19
|
+
return val;
|
|
15
20
|
}
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
else {
|
|
22
|
+
assert(typeof options?.ssr === 'boolean');
|
|
23
|
+
const val = options.ssr;
|
|
24
|
+
/* This assert() fails (which is very unexpected).
|
|
25
|
+
if (typeof config.build.ssr === 'boolean') assert(val === config.build.ssr)
|
|
26
|
+
//*/
|
|
27
|
+
return val;
|
|
18
28
|
}
|
|
19
|
-
assert(false);
|
|
20
29
|
}
|
|
@@ -34,7 +34,7 @@ import { assertV1Design } from '../shared/assertV1Design.js';
|
|
|
34
34
|
import { getPageConfigsRuntime } from '../../shared/getPageConfigsRuntime.js';
|
|
35
35
|
import { resolveBase } from '../shared/resolveBase.js';
|
|
36
36
|
const debug = createDebugger('vike:globalContext');
|
|
37
|
-
const globalObject = getGlobalObject('globalContext.ts', getInitialGlobalContext());
|
|
37
|
+
const globalObject = getGlobalObject('runtime/globalContext.ts', getInitialGlobalContext());
|
|
38
38
|
async function getGlobalContextInternal() {
|
|
39
39
|
// getGlobalContextInternal() should always be called after initGlobalContext()
|
|
40
40
|
assert(globalObject.isInitialized);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { assertNoInfiniteHttpRedirect };
|
|
2
2
|
import { assert, assertUsage, getGlobalObject } from '../../utils.js';
|
|
3
3
|
import pc from '@brillout/picocolors';
|
|
4
|
-
const globalObject = getGlobalObject('assertNoInfiniteHttpRedirect.ts', {
|
|
4
|
+
const globalObject = getGlobalObject('createHttpResponse/assertNoInfiniteHttpRedirect.ts', {
|
|
5
5
|
redirectGraph: {}
|
|
6
6
|
});
|
|
7
7
|
function assertNoInfiniteHttpRedirect(urlRedirectTarget, urlLogical) {
|
|
@@ -3,6 +3,7 @@ export { createHttpResponsePageContextJson };
|
|
|
3
3
|
export { createHttpResponseError };
|
|
4
4
|
export { createHttpResponseRedirect };
|
|
5
5
|
export { createHttpResponseFavicon404 };
|
|
6
|
+
export { createHttpResponseBaseIsMissing };
|
|
6
7
|
export type { HttpResponse };
|
|
7
8
|
import type { GetPageAssets } from './getPageAssets.js';
|
|
8
9
|
import type { HtmlRender } from '../html/renderHtml.js';
|
|
@@ -28,6 +29,7 @@ declare function createHttpResponsePage(htmlRender: HtmlRender, renderHook: null
|
|
|
28
29
|
abortStatusCode?: AbortStatusCode;
|
|
29
30
|
}): Promise<HttpResponse>;
|
|
30
31
|
declare function createHttpResponseFavicon404(): HttpResponse;
|
|
32
|
+
declare function createHttpResponseBaseIsMissing(urlOriginal: string, baseServer: string): HttpResponse;
|
|
31
33
|
declare function createHttpResponseError(pageContext: null | {
|
|
32
34
|
_pageFilesAll: PageFile[];
|
|
33
35
|
_pageConfigs: PageConfigRuntime[];
|
|
@@ -3,6 +3,7 @@ export { createHttpResponsePageContextJson };
|
|
|
3
3
|
export { createHttpResponseError };
|
|
4
4
|
export { createHttpResponseRedirect };
|
|
5
5
|
export { createHttpResponseFavicon404 };
|
|
6
|
+
export { createHttpResponseBaseIsMissing };
|
|
6
7
|
import { assert, assertWarning, escapeHtml } from '../utils.js';
|
|
7
8
|
import { getErrorPageId, isErrorPage } from '../../../shared/error-page.js';
|
|
8
9
|
import { getHttpResponseBody, getHttpResponseBodyStreamHandlers } from './getHttpResponseBody.js';
|
|
@@ -38,6 +39,29 @@ function createHttpResponseFavicon404() {
|
|
|
38
39
|
const httpResponse = createHttpResponse(404, 'text/html;charset=utf-8', [], "<p>No favicon.ico found.</p><script>console.log('This HTTP response was generated by Vike.')</script>");
|
|
39
40
|
return httpResponse;
|
|
40
41
|
}
|
|
42
|
+
function createHttpResponseBaseIsMissing(urlOriginal, baseServer) {
|
|
43
|
+
const httpResponse = createHttpResponse(
|
|
44
|
+
// We use the error code `500` to signal a failing state because this HTTP response should never be used, see https://vike.dev/base-url#setup
|
|
45
|
+
// In other words: this HTTP response is expected to be generated but isn't expected to be actually used.
|
|
46
|
+
500, 'text/html;charset=utf-8', [], `
|
|
47
|
+
<h1>Error: Base URL is missing</h1>
|
|
48
|
+
<p>
|
|
49
|
+
<a href="https://vike.dev/renderPage"><code>renderPage(pageContextInit)</code></a> called with <code>pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}</code> which doesn't start with the Base URL <code>${baseServer}</code>.
|
|
50
|
+
</p>
|
|
51
|
+
<p>
|
|
52
|
+
See <a href="https://vike.dev/base-url#setup">vike.dev/base-url#setup</a> for how to properly setup your server while using a Base URL.
|
|
53
|
+
</p>
|
|
54
|
+
<style>
|
|
55
|
+
code {
|
|
56
|
+
font-family: monospace;
|
|
57
|
+
background-color: #eaeaea;
|
|
58
|
+
padding: 3px 5px;
|
|
59
|
+
border-radius: 4px;
|
|
60
|
+
}
|
|
61
|
+
</style>
|
|
62
|
+
`);
|
|
63
|
+
return httpResponse;
|
|
64
|
+
}
|
|
41
65
|
function createHttpResponseError(pageContext) {
|
|
42
66
|
const reason = (() => {
|
|
43
67
|
if (!pageContext) {
|
|
@@ -6,7 +6,7 @@ import { retrieveAssetsProd } from './getPageAssets/retrieveAssetsProd.js';
|
|
|
6
6
|
import { inferMediaType } from './inferMediaType.js';
|
|
7
7
|
import { getManifestEntry } from './getPageAssets/getManifestEntry.js';
|
|
8
8
|
import { sortPageAssetsForEarlyHintsHeader } from './getPageAssets/sortPageAssetsForEarlyHintsHeader.js';
|
|
9
|
-
const globalObject = getGlobalObject('getPageAssets.ts', {
|
|
9
|
+
const globalObject = getGlobalObject('renderPage/getPageAssets.ts', {
|
|
10
10
|
resolveClientEntriesDev: null
|
|
11
11
|
});
|
|
12
12
|
async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { handlePageContextRequestUrl };
|
|
2
2
|
import { pageContextJsonFileExtension, doNotCreateExtraDirectory } from '../../../shared/getPageContextRequestUrl.js';
|
|
3
3
|
import { baseServer, parseUrl, assert, slice } from '../utils.js';
|
|
4
|
-
// See shared/getPageContextRequestUrl.ts
|
|
4
|
+
// See also shared/getPageContextRequestUrl.ts
|
|
5
5
|
function handlePageContextRequestUrl(url) {
|
|
6
6
|
if (!hasSuffix(url)) {
|
|
7
7
|
return { urlWithoutPageContextRequestSuffix: url, isPageContextRequest: false };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { isNewError };
|
|
2
2
|
export { setAlreadyLogged };
|
|
3
3
|
import { getGlobalObject, isObject, isSameErrorMessage, warnIfErrorIsNotObject } from '../utils.js';
|
|
4
|
-
const globalObject = getGlobalObject('
|
|
4
|
+
const globalObject = getGlobalObject('renderPage/isNewError.ts', {
|
|
5
5
|
wasAlreadyLogged: new WeakSet()
|
|
6
6
|
});
|
|
7
7
|
function isNewError(errErrorPage, errNominalPage) {
|
|
@@ -6,12 +6,12 @@ import { assert, hasProp, objectAssign, isUrl, parseUrl, onSetupRuntime, assertW
|
|
|
6
6
|
import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError, logAbortErrorHandled } from '../../shared/route/abort.js';
|
|
7
7
|
import { getGlobalContextInternal, initGlobalContext_renderPage } from './globalContext.js';
|
|
8
8
|
import { handlePageContextRequestUrl } from './renderPage/handlePageContextRequestUrl.js';
|
|
9
|
-
import { createHttpResponseFavicon404, createHttpResponseRedirect, createHttpResponsePageContextJson, createHttpResponseError } from './renderPage/createHttpResponse.js';
|
|
9
|
+
import { createHttpResponseFavicon404, createHttpResponseRedirect, createHttpResponsePageContextJson, createHttpResponseError, createHttpResponseBaseIsMissing } from './renderPage/createHttpResponse.js';
|
|
10
10
|
import { logRuntimeError, logRuntimeInfo } from './renderPage/loggerRuntime.js';
|
|
11
11
|
import { isNewError } from './renderPage/isNewError.js';
|
|
12
12
|
import { assertArguments } from './renderPage/assertArguments.js';
|
|
13
13
|
import { log404 } from './renderPage/log404/index.js';
|
|
14
|
-
import {
|
|
14
|
+
import { isVikeConfigInvalid } from './renderPage/isVikeConfigInvalid.js';
|
|
15
15
|
import pc from '@brillout/picocolors';
|
|
16
16
|
import { serializePageContextAbort, serializePageContextClientSide } from './html/serializePageContextClientSide.js';
|
|
17
17
|
import { getErrorPageId } from '../../shared/error-page.js';
|
|
@@ -25,12 +25,11 @@ const globalObject = getGlobalObject('runtime/renderPage.ts', {
|
|
|
25
25
|
async function renderPage(pageContextInit) {
|
|
26
26
|
assertArguments(...arguments);
|
|
27
27
|
assert(hasProp(pageContextInit, 'urlOriginal', 'string')); // assertUsage() already implemented at assertArguments()
|
|
28
|
-
onSetupRuntime();
|
|
29
28
|
assertIsUrl(pageContextInit.urlOriginal);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
return
|
|
29
|
+
onSetupRuntime();
|
|
30
|
+
const pageContextInvalidRequest = renderInvalidRequest(pageContextInit);
|
|
31
|
+
if (pageContextInvalidRequest)
|
|
32
|
+
return pageContextInvalidRequest;
|
|
34
33
|
const httpRequestId = getRequestId();
|
|
35
34
|
const urlOriginalPretty = getUrlPretty(pageContextInit.urlOriginal);
|
|
36
35
|
logHttpRequest(urlOriginalPretty, httpRequestId);
|
|
@@ -50,15 +49,10 @@ function renderPage_addAsyncHookwrapper(wrapper) {
|
|
|
50
49
|
}
|
|
51
50
|
async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
52
51
|
// Invalid config
|
|
53
|
-
|
|
54
|
-
logRuntimeInfo?.(pc.bold(pc.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
|
|
55
|
-
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
|
|
56
|
-
return pageContextWithError;
|
|
57
|
-
};
|
|
58
|
-
if (isConfigInvalid) {
|
|
52
|
+
if (isVikeConfigInvalid) {
|
|
59
53
|
if (1 < 2 // Make TS happy
|
|
60
54
|
) {
|
|
61
|
-
return
|
|
55
|
+
return renderInvalidVikeConfig(isVikeConfigInvalid.err, pageContextInit, httpRequestId);
|
|
62
56
|
}
|
|
63
57
|
}
|
|
64
58
|
// Prepare context
|
|
@@ -76,15 +70,19 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
76
70
|
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
|
|
77
71
|
return pageContextWithError;
|
|
78
72
|
}
|
|
79
|
-
if (
|
|
80
|
-
return
|
|
73
|
+
if (isVikeConfigInvalid) {
|
|
74
|
+
return renderInvalidVikeConfig(isVikeConfigInvalid.err, pageContextInit, httpRequestId);
|
|
81
75
|
}
|
|
82
76
|
else {
|
|
83
|
-
//
|
|
77
|
+
// `globalContext` now contains the entire Vike config and getVikeConfig() isn't called anymore for this request.
|
|
84
78
|
}
|
|
85
79
|
const globalContext = await getGlobalContextInternal();
|
|
86
80
|
// Check Base URL
|
|
87
|
-
|
|
81
|
+
{
|
|
82
|
+
const pageContextHttpResponse = await checkBaseUrl(pageContextInit, globalContext);
|
|
83
|
+
if (pageContextHttpResponse)
|
|
84
|
+
return pageContextHttpResponse;
|
|
85
|
+
}
|
|
88
86
|
// Normalize URL
|
|
89
87
|
{
|
|
90
88
|
const pageContextHttpResponse = await normalizeUrl(pageContextInit, globalContext, httpRequestId);
|
|
@@ -252,15 +250,6 @@ function getPageContextHttpResponseError(err, pageContextInit, pageContext) {
|
|
|
252
250
|
});
|
|
253
251
|
return pageContextWithError;
|
|
254
252
|
}
|
|
255
|
-
function getPageContextHttpResponseFavicon404(pageContextInit) {
|
|
256
|
-
const pageContext = createPageContext(pageContextInit);
|
|
257
|
-
const httpResponse = createHttpResponseFavicon404();
|
|
258
|
-
objectAssign(pageContext, {
|
|
259
|
-
httpResponse
|
|
260
|
-
});
|
|
261
|
-
checkType(pageContext);
|
|
262
|
-
return pageContext;
|
|
263
|
-
}
|
|
264
253
|
function createPageContext(pageContextInit) {
|
|
265
254
|
const pageContext = {
|
|
266
255
|
_isPageContextObject: true
|
|
@@ -453,10 +442,35 @@ pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalConte
|
|
|
453
442
|
assert(pageContextAbort.abortStatusCode);
|
|
454
443
|
return { pageContextAbort };
|
|
455
444
|
}
|
|
456
|
-
async function
|
|
445
|
+
async function checkBaseUrl(pageContextInit, globalContext) {
|
|
457
446
|
const { baseServer } = globalContext;
|
|
458
447
|
const { urlOriginal } = pageContextInit;
|
|
459
|
-
const {
|
|
460
|
-
|
|
461
|
-
|
|
448
|
+
const { isBaseMissing } = parseUrl(urlOriginal, baseServer);
|
|
449
|
+
if (!isBaseMissing)
|
|
450
|
+
return;
|
|
451
|
+
const pageContext = createPageContext(pageContextInit);
|
|
452
|
+
const httpResponse = createHttpResponseBaseIsMissing(urlOriginal, baseServer);
|
|
453
|
+
objectAssign(pageContext, {
|
|
454
|
+
httpResponse,
|
|
455
|
+
isBaseMissing: true
|
|
456
|
+
});
|
|
457
|
+
checkType(pageContext);
|
|
458
|
+
return pageContext;
|
|
459
|
+
}
|
|
460
|
+
function renderInvalidRequest(pageContextInit) {
|
|
461
|
+
const urlPathnameWithBase = parseUrl(pageContextInit.urlOriginal, '/').pathname;
|
|
462
|
+
assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
|
|
463
|
+
if (urlPathnameWithBase.endsWith('/favicon.ico')) {
|
|
464
|
+
const pageContext = createPageContext(pageContextInit);
|
|
465
|
+
const httpResponse = createHttpResponseFavicon404();
|
|
466
|
+
objectAssign(pageContext, { httpResponse });
|
|
467
|
+
checkType(pageContext);
|
|
468
|
+
return pageContext;
|
|
469
|
+
}
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
function renderInvalidVikeConfig(err, pageContextInit, httpRequestId) {
|
|
473
|
+
logRuntimeInfo?.(pc.bold(pc.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
|
|
474
|
+
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
|
|
475
|
+
return pageContextWithError;
|
|
462
476
|
}
|
|
@@ -6,7 +6,7 @@ import { urlToFile } from '../utils/urlToFile.js';
|
|
|
6
6
|
const pageContextJsonFileExtension = '.pageContext.json';
|
|
7
7
|
// `/some-base-url/index.pageContext.json` instead of `/some-base-url.pageContext.json` in order to comply to common reverse proxy setups, see https://github.com/vikejs/vike/issues/443
|
|
8
8
|
const doNotCreateExtraDirectory = false;
|
|
9
|
-
// See node/renderPage/handlePageContextRequestUrl.ts
|
|
9
|
+
// See also node/renderPage/handlePageContextRequestUrl.ts
|
|
10
10
|
function getPageContextRequestUrl(url) {
|
|
11
11
|
const pageContextRequestUrl = urlToFile(url, pageContextJsonFileExtension, doNotCreateExtraDirectory);
|
|
12
12
|
return pageContextRequestUrl;
|
|
@@ -37,26 +37,29 @@ function getUrlParsed(pageContext) {
|
|
|
37
37
|
// 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
|
|
38
38
|
// Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
|
|
39
39
|
// Determine logical URL
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const assertUrlResolved = (src) => assert(urlResolved && typeof urlResolved === 'string',
|
|
41
|
+
// TODO/eventually: remove debug logs, see:
|
|
42
|
+
// - https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
|
|
43
|
+
// - https://github.com/vikejs/vike/commit/5c7810f3080ab62536950f26e019bb2a3a517082
|
|
44
|
+
{ src, urlResolved });
|
|
42
45
|
let urlResolved;
|
|
43
|
-
let
|
|
46
|
+
let isBaseToBeRemoved;
|
|
44
47
|
if (pageContext.urlLogical) {
|
|
45
48
|
// Set by onBeforeRoute()
|
|
46
49
|
urlResolved = pageContext.urlLogical;
|
|
47
|
-
|
|
50
|
+
isBaseToBeRemoved = false;
|
|
48
51
|
assertUrlResolved(1);
|
|
49
52
|
}
|
|
50
53
|
else if (pageContext._urlRewrite) {
|
|
51
54
|
// Set by `throw render()`
|
|
52
55
|
urlResolved = pageContext._urlRewrite;
|
|
53
|
-
|
|
56
|
+
isBaseToBeRemoved = false;
|
|
54
57
|
assertUrlResolved(2);
|
|
55
58
|
}
|
|
56
59
|
else {
|
|
57
60
|
// Set by renderPage()
|
|
58
61
|
urlResolved = pageContext.urlOriginal;
|
|
59
|
-
|
|
62
|
+
isBaseToBeRemoved = true;
|
|
60
63
|
assertUrlResolved(3);
|
|
61
64
|
}
|
|
62
65
|
assertUrlResolved(4);
|
|
@@ -69,7 +72,7 @@ function getUrlParsed(pageContext) {
|
|
|
69
72
|
// - We assume there isn't any Base URL to the URLs set by the user at `throw render()` and onBeforeRoute()
|
|
70
73
|
// - This makes sense because the Base URL is merely a setting: ideally the user should write code that doesn't know anything about it (so that the user can remove/add/change Base URL without having to modify any code).
|
|
71
74
|
// - pageContext.urlOriginal is the URL of the HTTP request and thus contains the Base URL.
|
|
72
|
-
const baseServer = !
|
|
75
|
+
const baseServer = !isBaseToBeRemoved ? '/' : pageContext._baseServer;
|
|
73
76
|
// Parse URL
|
|
74
77
|
return parseUrl(urlResolved, baseServer);
|
|
75
78
|
}
|
|
@@ -11,7 +11,7 @@ import { getHookFilePathToShowToUser } from '../page-configs/helpers.js';
|
|
|
11
11
|
import { getConfigValueRuntime } from '../page-configs/getConfigValueRuntime.js';
|
|
12
12
|
import { assert, assertUsage, checkType, isCallable, isObject } from '../utils.js';
|
|
13
13
|
import pc from '@brillout/picocolors';
|
|
14
|
-
const globalObject = getGlobalObject('getHook.ts', {});
|
|
14
|
+
const globalObject = getGlobalObject('hooks/getHook.ts', {});
|
|
15
15
|
function getHook(pageContext, hookName) {
|
|
16
16
|
if (!(hookName in pageContext.exports)) {
|
|
17
17
|
return null;
|
|
@@ -131,6 +131,12 @@ type PageContextBuiltInCommon<Data> = {
|
|
|
131
131
|
url: string;
|
|
132
132
|
/** @deprecated */
|
|
133
133
|
pageExports: Record<string, unknown>;
|
|
134
|
+
/**
|
|
135
|
+
* Whether the Base URL is missing in the URL of the HTTP request made to the SSR server.
|
|
136
|
+
*
|
|
137
|
+
* https://vike.dev/base-url#setup
|
|
138
|
+
*/
|
|
139
|
+
isBaseMissing?: true;
|
|
134
140
|
};
|
|
135
141
|
type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageContextUrlServer;
|
|
136
142
|
type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'routeParams' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason' | 'data' | 'pageId' | 'source' | 'sources' | 'from'> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.222-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.222-commit-fab3841";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.222-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.222-commit-fab3841';
|
|
@@ -16,7 +16,7 @@ import { isVitest } from './isVitest.js';
|
|
|
16
16
|
import pc from '@brillout/picocolors';
|
|
17
17
|
assertIsNotBrowser();
|
|
18
18
|
const debug = createDebugger('vike:setup');
|
|
19
|
-
const setup = getGlobalObject('utils/
|
|
19
|
+
const setup = getGlobalObject('utils/assertSetup.ts', {});
|
|
20
20
|
// Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
|
|
21
21
|
function assertIsNotProductionRuntime() {
|
|
22
22
|
if (debug.isActivated)
|
|
@@ -11,7 +11,7 @@ import pc from '@brillout/picocolors';
|
|
|
11
11
|
/* Use original assertUsage() & assertWarning() after all CJS is removed from node_modules/vike/dist/
|
|
12
12
|
import { assertUsage, assertWarning } from './assert.js'
|
|
13
13
|
*/
|
|
14
|
-
const globalObject = getGlobalObject('assertSingleInstance.ts', {
|
|
14
|
+
const globalObject = getGlobalObject('utils/assertSingleInstance.ts', {
|
|
15
15
|
instances: [],
|
|
16
16
|
alreadyLogged: new Set()
|
|
17
17
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { getGlobalObject };
|
|
2
2
|
export { assertIsSingleModuleInstance };
|
|
3
|
+
type Key = `${string}/${string}.ts`;
|
|
3
4
|
/** Share information across module instances. */
|
|
4
|
-
declare function getGlobalObject<T extends Record<string, unknown> = never>(key:
|
|
5
|
+
declare function getGlobalObject<T extends Record<string, unknown> = never>(key: Key, defaultValue: T): T;
|
|
5
6
|
/** Assert that the module is instantiated only once. */
|
|
6
|
-
declare function assertIsSingleModuleInstance(key:
|
|
7
|
+
declare function assertIsSingleModuleInstance(key: Key): void;
|
|
@@ -2,17 +2,13 @@ export { getGlobalObject };
|
|
|
2
2
|
export { assertIsSingleModuleInstance };
|
|
3
3
|
import { assert } from './assert.js';
|
|
4
4
|
/** Share information across module instances. */
|
|
5
|
-
function getGlobalObject(
|
|
6
|
-
// We use the filename (or file path) as key. There should be only one getGlobalObject() usage per file. Thus the key should be unique, assuming the filename (or file path) is unique.
|
|
7
|
-
key, defaultValue) {
|
|
5
|
+
function getGlobalObject(key, defaultValue) {
|
|
8
6
|
const globalObjects = getGlobalObjects();
|
|
9
7
|
const globalObject = (globalObjects[key] = globalObjects[key] || defaultValue);
|
|
10
8
|
return globalObject;
|
|
11
9
|
}
|
|
12
10
|
/** Assert that the module is instantiated only once. */
|
|
13
|
-
function assertIsSingleModuleInstance(
|
|
14
|
-
// We use the filename (or file path) as key.
|
|
15
|
-
key) {
|
|
11
|
+
function assertIsSingleModuleInstance(key) {
|
|
16
12
|
const globalObjects = getGlobalObjects();
|
|
17
13
|
assert(!(key in globalObjects));
|
|
18
14
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isConfigInvalid_set = exports.isConfigInvalid = void 0;
|
|
4
|
-
const utils_js_1 = require("../utils.js");
|
|
5
|
-
let isConfigInvalid;
|
|
6
|
-
const isConfigInvalid_set = (val) => {
|
|
7
|
-
(0, utils_js_1.assert)(val === false || val.err);
|
|
8
|
-
exports.isConfigInvalid = isConfigInvalid = val;
|
|
9
|
-
};
|
|
10
|
-
exports.isConfigInvalid_set = isConfigInvalid_set;
|