vike 0.4.222 → 0.4.223-commit-586dbfb
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/index.js +6 -4
- package/dist/cjs/node/plugin/plugins/baseUrls.js +9 -2
- package/dist/cjs/node/plugin/plugins/buildApp.js +14 -7
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +49 -19
- package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +17 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +2 -18
- 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/assertExtensions.js +4 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +6 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +11 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +8 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +36 -71
- package/dist/cjs/node/plugin/shared/findPageFiles.js +3 -3
- package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
- package/dist/cjs/node/plugin/shared/viteIsSSR.js +19 -10
- package/dist/cjs/node/prerender/runPrerender.js +3 -1
- package/dist/cjs/node/runtime/globalContext.js +19 -8
- 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/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +7 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -4
- package/dist/cjs/node/runtime/renderPage.js +63 -49
- package/dist/cjs/node/runtime/universal-middleware.js +14 -0
- package/dist/cjs/node/shared/resolveBase.js +0 -13
- package/dist/cjs/shared/getPageConfigsRuntime.js +2 -8
- package/dist/cjs/shared/getPageContextRequestUrl.js +1 -1
- package/dist/cjs/shared/getPageContextUrlComputed.js +12 -9
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +44 -12
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -8
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +16 -6
- package/dist/cjs/shared/route/loadPageRoutes.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +1 -1
- package/dist/cjs/utils/assertSetup.js +1 -1
- package/dist/cjs/utils/assertSingleInstance.js +2 -2
- package/dist/cjs/utils/findFile.js +1 -1
- package/dist/cjs/utils/getGlobalObject.js +2 -6
- package/dist/cjs/utils/parseUrl-extras.js +2 -2
- package/dist/cjs/utils/parseUrl.js +5 -5
- package/dist/cjs/utils/requireResolve.js +3 -3
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.js +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +4 -4
- 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/index.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/index.js +1 -0
- package/dist/esm/client/client-routing-runtime/prefetch/getPrefetchSettings.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.js +3 -3
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +8 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +12 -3
- package/dist/esm/client/client-routing-runtime/scrollRestoration.js +1 -1
- package/dist/esm/client/client-routing-runtime/skipLink.js +2 -2
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
- package/dist/esm/client/shared/getPageContextProxyForUser.js +1 -1
- package/dist/esm/client/shared/loadUserFilesClientSide.d.ts +2 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.js +2 -2
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/api/prepareViteApiCall.js +1 -1
- package/dist/esm/node/plugin/index.d.ts +6 -2
- package/dist/esm/node/plugin/index.js +2 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +9 -2
- package/dist/esm/node/plugin/plugins/buildApp.js +14 -7
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +49 -19
- package/dist/esm/node/plugin/plugins/buildConfig.js +6 -1
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +14 -6
- package/dist/esm/node/plugin/plugins/commonConfig.js +17 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/esm/node/plugin/plugins/envVars.js +2 -18
- 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/assertExtensions.js +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +6 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +10 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +8 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +5 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +38 -73
- package/dist/esm/node/plugin/shared/findPageFiles.js +3 -3
- package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +2 -2
- 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/prerender/runPrerender.js +3 -1
- package/dist/esm/node/runtime/globalContext.d.ts +9 -8
- package/dist/esm/node/runtime/globalContext.js +19 -8
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- 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/executeOnBeforeRenderAndDataHooks.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- 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/loadUserFilesServerSide.d.ts +3 -3
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +7 -1
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +4 -4
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +12 -12
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -4
- package/dist/esm/node/runtime/renderPage.d.ts +5 -5
- package/dist/esm/node/runtime/renderPage.js +64 -49
- package/dist/esm/node/runtime/universal-middleware.d.ts +1 -0
- package/dist/esm/node/runtime/universal-middleware.js +11 -0
- package/dist/esm/node/shared/resolveBase.d.ts +1 -9
- package/dist/esm/node/shared/resolveBase.js +0 -13
- package/dist/esm/shared/getPageConfigsRuntime.d.ts +2 -2
- package/dist/esm/shared/getPageConfigsRuntime.js +3 -9
- package/dist/esm/shared/getPageContextRequestUrl.js +1 -1
- package/dist/esm/shared/getPageContextUrlComputed.js +12 -9
- package/dist/esm/shared/getPageFiles.d.ts +1 -1
- package/dist/esm/shared/hooks/getHook.d.ts +3 -3
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +3 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +12 -4
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +24 -16
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +44 -12
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +3 -2
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -8
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +2 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +16 -6
- package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.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/assert.js +1 -1
- package/dist/esm/utils/assertSetup.js +1 -1
- package/dist/esm/utils/assertSingleInstance.js +2 -2
- package/dist/esm/utils/findFile.js +1 -1
- package/dist/esm/utils/getGlobalObject.d.ts +3 -2
- package/dist/esm/utils/getGlobalObject.js +2 -6
- package/dist/esm/utils/parseUrl-extras.js +2 -2
- package/dist/esm/utils/parseUrl.d.ts +3 -4
- package/dist/esm/utils/parseUrl.js +5 -5
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/requireResolve.js +3 -3
- package/package.json +18 -6
- package/universal-middleware.js +3 -0
- 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
- package/dist-cjs-fixup.mjs +0 -41
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.renderPage_addWrapper = void 0;
|
|
7
6
|
exports.renderPage = renderPage;
|
|
7
|
+
exports.renderPage_addAsyncHookwrapper = renderPage_addAsyncHookwrapper;
|
|
8
8
|
const renderPageAlreadyRouted_js_1 = require("./renderPage/renderPageAlreadyRouted.js");
|
|
9
9
|
const index_js_1 = require("../../shared/route/index.js");
|
|
10
10
|
const utils_js_1 = require("./utils.js");
|
|
@@ -16,54 +16,48 @@ const loggerRuntime_js_1 = require("./renderPage/loggerRuntime.js");
|
|
|
16
16
|
const isNewError_js_1 = require("./renderPage/isNewError.js");
|
|
17
17
|
const assertArguments_js_1 = require("./renderPage/assertArguments.js");
|
|
18
18
|
const index_js_2 = require("./renderPage/log404/index.js");
|
|
19
|
-
const
|
|
19
|
+
const isVikeConfigInvalid_js_1 = require("./renderPage/isVikeConfigInvalid.js");
|
|
20
20
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
21
21
|
const serializePageContextClientSide_js_1 = require("./html/serializePageContextClientSide.js");
|
|
22
22
|
const error_page_js_1 = require("../../shared/error-page.js");
|
|
23
23
|
const handleErrorWithoutErrorPage_js_1 = require("./renderPage/handleErrorWithoutErrorPage.js");
|
|
24
24
|
const loadUserFilesServerSide_js_1 = require("./renderPage/loadUserFilesServerSide.js");
|
|
25
25
|
const resolveRedirects_js_1 = require("./renderPage/resolveRedirects.js");
|
|
26
|
-
const resolveBase_js_1 = require("../shared/resolveBase.js");
|
|
27
26
|
const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage.ts', {
|
|
28
27
|
httpRequestsCount: 0
|
|
29
28
|
});
|
|
30
|
-
let renderPage_wrapper = async (_httpRequestId, ret) => ({
|
|
31
|
-
pageContextReturn: await ret()
|
|
32
|
-
});
|
|
33
|
-
const renderPage_addWrapper = (wrapper) => {
|
|
34
|
-
renderPage_wrapper = wrapper;
|
|
35
|
-
};
|
|
36
|
-
exports.renderPage_addWrapper = renderPage_addWrapper;
|
|
37
29
|
// `renderPage()` calls `renderPageNominal()` while ensuring that errors are `console.error(err)` instead of `throw err`, so that Vike never triggers a server shut down. (Throwing an error in an Express.js middleware shuts down the whole Express.js server.)
|
|
38
30
|
async function renderPage(pageContextInit) {
|
|
39
31
|
(0, assertArguments_js_1.assertArguments)(...arguments);
|
|
40
32
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextInit, 'urlOriginal', 'string')); // assertUsage() already implemented at assertArguments()
|
|
41
|
-
(0, utils_js_1.onSetupRuntime)();
|
|
42
33
|
assertIsUrl(pageContextInit.urlOriginal);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
return
|
|
34
|
+
(0, utils_js_1.onSetupRuntime)();
|
|
35
|
+
const pageContextInvalidRequest = renderInvalidRequest(pageContextInit);
|
|
36
|
+
if (pageContextInvalidRequest)
|
|
37
|
+
return pageContextInvalidRequest;
|
|
47
38
|
const httpRequestId = getRequestId();
|
|
48
39
|
const urlOriginalPretty = (0, utils_js_1.getUrlPretty)(pageContextInit.urlOriginal);
|
|
49
40
|
logHttpRequest(urlOriginalPretty, httpRequestId);
|
|
50
|
-
const { pageContextReturn } = await
|
|
41
|
+
const { pageContextReturn } = await asyncHookWrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
|
|
51
42
|
logHttpResponse(urlOriginalPretty, httpRequestId, pageContextReturn);
|
|
52
43
|
(0, utils_js_1.checkType)(pageContextReturn);
|
|
53
44
|
(0, utils_js_1.assert)(pageContextReturn.httpResponse);
|
|
54
45
|
return pageContextReturn;
|
|
55
46
|
}
|
|
47
|
+
// Fallback wrapper if node:async_hooks isn't available
|
|
48
|
+
let asyncHookWrapper = async (_httpRequestId, ret) => ({
|
|
49
|
+
pageContextReturn: await ret()
|
|
50
|
+
});
|
|
51
|
+
// Add node:async_hooks wrapper
|
|
52
|
+
function renderPage_addAsyncHookwrapper(wrapper) {
|
|
53
|
+
asyncHookWrapper = wrapper;
|
|
54
|
+
}
|
|
56
55
|
async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
57
56
|
// Invalid config
|
|
58
|
-
|
|
59
|
-
(0, loggerRuntime_js_1.logRuntimeInfo)?.(picocolors_1.default.bold(picocolors_1.default.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
|
|
60
|
-
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
|
|
61
|
-
return pageContextWithError;
|
|
62
|
-
};
|
|
63
|
-
if (isConfigInvalid_js_1.isConfigInvalid) {
|
|
57
|
+
if (isVikeConfigInvalid_js_1.isVikeConfigInvalid) {
|
|
64
58
|
if (1 < 2 // Make TS happy
|
|
65
59
|
) {
|
|
66
|
-
return
|
|
60
|
+
return renderInvalidVikeConfig(isVikeConfigInvalid_js_1.isVikeConfigInvalid.err, pageContextInit, httpRequestId);
|
|
67
61
|
}
|
|
68
62
|
}
|
|
69
63
|
// Prepare context
|
|
@@ -71,22 +65,29 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
71
65
|
await (0, globalContext_js_1.initGlobalContext_renderPage)();
|
|
72
66
|
}
|
|
73
67
|
catch (err) {
|
|
74
|
-
// Errors are expected since assertUsage() is used in
|
|
75
|
-
//
|
|
68
|
+
// Errors are expected since assertUsage() is used in initGlobalContext_renderPage() such as:
|
|
69
|
+
// ```bash
|
|
70
|
+
// Re-build your app (you're using 1.2.3 but your app was built with 1.2.2)
|
|
71
|
+
// ```
|
|
72
|
+
// initGlobalContext_renderPage() doens't call any user hook => err isn't thrown from user code.
|
|
76
73
|
(0, utils_js_1.assert)(!(0, abort_js_1.isAbortError)(err));
|
|
77
74
|
(0, loggerRuntime_js_1.logRuntimeError)(err, httpRequestId);
|
|
78
75
|
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
|
|
79
76
|
return pageContextWithError;
|
|
80
77
|
}
|
|
81
|
-
if (
|
|
82
|
-
return
|
|
78
|
+
if (isVikeConfigInvalid_js_1.isVikeConfigInvalid) {
|
|
79
|
+
return renderInvalidVikeConfig(isVikeConfigInvalid_js_1.isVikeConfigInvalid.err, pageContextInit, httpRequestId);
|
|
83
80
|
}
|
|
84
81
|
else {
|
|
85
|
-
//
|
|
82
|
+
// `globalContext` now contains the entire Vike config and getVikeConfig() isn't called anymore for this request.
|
|
86
83
|
}
|
|
87
84
|
const globalContext = await (0, globalContext_js_1.getGlobalContextInternal)();
|
|
88
85
|
// Check Base URL
|
|
89
|
-
|
|
86
|
+
{
|
|
87
|
+
const pageContextHttpResponse = await checkBaseUrl(pageContextInit, globalContext);
|
|
88
|
+
if (pageContextHttpResponse)
|
|
89
|
+
return pageContextHttpResponse;
|
|
90
|
+
}
|
|
90
91
|
// Normalize URL
|
|
91
92
|
{
|
|
92
93
|
const pageContextHttpResponse = await normalizeUrl(pageContextInit, globalContext, httpRequestId);
|
|
@@ -254,15 +255,6 @@ function getPageContextHttpResponseError(err, pageContextInit, pageContext) {
|
|
|
254
255
|
});
|
|
255
256
|
return pageContextWithError;
|
|
256
257
|
}
|
|
257
|
-
function getPageContextHttpResponseFavicon404(pageContextInit) {
|
|
258
|
-
const pageContext = createPageContext(pageContextInit);
|
|
259
|
-
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseFavicon404)();
|
|
260
|
-
(0, utils_js_1.objectAssign)(pageContext, {
|
|
261
|
-
httpResponse
|
|
262
|
-
});
|
|
263
|
-
(0, utils_js_1.checkType)(pageContext);
|
|
264
|
-
return pageContext;
|
|
265
|
-
}
|
|
266
258
|
function createPageContext(pageContextInit) {
|
|
267
259
|
const pageContext = {
|
|
268
260
|
_isPageContextObject: true
|
|
@@ -343,7 +335,6 @@ function assertIsNotViteRequest(urlPathname, urlOriginal) {
|
|
|
343
335
|
(0, utils_js_1.assertUsage)(false, `${picocolors_1.default.code('renderPage(pageContextInit)')} called with ${picocolors_1.default.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which is unexpected because the URL ${picocolors_1.default.bold(urlOriginal)} should have already been handled by the development middleware: make sure the ${picocolors_1.default.cyan('createDevMiddleware()')} middleware is executed *before* the ${picocolors_1.default.cyan('renderPage()')} middleware, see ${picocolors_1.default.underline('https://vike.dev/renderPage')}`);
|
|
344
336
|
}
|
|
345
337
|
async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
346
|
-
const { baseServer } = (0, resolveBase_js_1.resolveBaseRuntime)(globalContext);
|
|
347
338
|
const { trailingSlash, disableUrlNormalization } = globalContext.config;
|
|
348
339
|
if (disableUrlNormalization)
|
|
349
340
|
return null;
|
|
@@ -351,7 +342,7 @@ async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
|
351
342
|
const { isPageContextRequest } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
|
|
352
343
|
if (isPageContextRequest)
|
|
353
344
|
return null;
|
|
354
|
-
const urlNormalized = (0, utils_js_1.normalizeUrlPathname)(urlOriginal, trailingSlash ?? false, baseServer);
|
|
345
|
+
const urlNormalized = (0, utils_js_1.normalizeUrlPathname)(urlOriginal, trailingSlash ?? false, globalContext.baseServer);
|
|
355
346
|
if (!urlNormalized)
|
|
356
347
|
return null;
|
|
357
348
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`URL normalized from ${picocolors_1.default.cyan(urlOriginal)} to ${picocolors_1.default.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
@@ -361,8 +352,7 @@ async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
|
361
352
|
return pageContextHttpResponse;
|
|
362
353
|
}
|
|
363
354
|
async function getPermanentRedirect(pageContextInit, globalContext, httpRequestId) {
|
|
364
|
-
const
|
|
365
|
-
const urlWithoutBase = (0, utils_js_1.removeBaseServer)(pageContextInit.urlOriginal, baseServer);
|
|
355
|
+
const urlWithoutBase = (0, utils_js_1.removeBaseServer)(pageContextInit.urlOriginal, globalContext.baseServer);
|
|
366
356
|
let origin = null;
|
|
367
357
|
let urlTargetExternal = null;
|
|
368
358
|
let urlTarget = (0, utils_js_1.modifyUrlPathname)(urlWithoutBase, (urlPathname) => {
|
|
@@ -393,9 +383,8 @@ async function getPermanentRedirect(pageContextInit, globalContext, httpRequestI
|
|
|
393
383
|
}
|
|
394
384
|
if (normalize(urlTarget) === normalize(urlWithoutBase))
|
|
395
385
|
return null;
|
|
396
|
-
const { baseServer } = (0, resolveBase_js_1.resolveBaseRuntime)(globalContext);
|
|
397
386
|
if (!originChanged)
|
|
398
|
-
urlTarget = (0, utils_js_1.prependBase)(urlTarget, baseServer);
|
|
387
|
+
urlTarget = (0, utils_js_1.prependBase)(urlTarget, globalContext.baseServer);
|
|
399
388
|
(0, utils_js_1.assert)(urlTarget !== pageContextInit.urlOriginal);
|
|
400
389
|
}
|
|
401
390
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`Permanent redirection defined by config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
@@ -458,10 +447,35 @@ pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalConte
|
|
|
458
447
|
(0, utils_js_1.assert)(pageContextAbort.abortStatusCode);
|
|
459
448
|
return { pageContextAbort };
|
|
460
449
|
}
|
|
461
|
-
async function
|
|
462
|
-
const { baseServer } =
|
|
450
|
+
async function checkBaseUrl(pageContextInit, globalContext) {
|
|
451
|
+
const { baseServer } = globalContext;
|
|
463
452
|
const { urlOriginal } = pageContextInit;
|
|
464
|
-
const {
|
|
465
|
-
|
|
466
|
-
|
|
453
|
+
const { isBaseMissing } = (0, utils_js_1.parseUrl)(urlOriginal, baseServer);
|
|
454
|
+
if (!isBaseMissing)
|
|
455
|
+
return;
|
|
456
|
+
const pageContext = createPageContext(pageContextInit);
|
|
457
|
+
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseBaseIsMissing)(urlOriginal, baseServer);
|
|
458
|
+
(0, utils_js_1.objectAssign)(pageContext, {
|
|
459
|
+
httpResponse,
|
|
460
|
+
isBaseMissing: true
|
|
461
|
+
});
|
|
462
|
+
(0, utils_js_1.checkType)(pageContext);
|
|
463
|
+
return pageContext;
|
|
464
|
+
}
|
|
465
|
+
function renderInvalidRequest(pageContextInit) {
|
|
466
|
+
const urlPathnameWithBase = (0, utils_js_1.parseUrl)(pageContextInit.urlOriginal, '/').pathname;
|
|
467
|
+
assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
|
|
468
|
+
if (urlPathnameWithBase.endsWith('/favicon.ico')) {
|
|
469
|
+
const pageContext = createPageContext(pageContextInit);
|
|
470
|
+
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseFavicon404)();
|
|
471
|
+
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
472
|
+
(0, utils_js_1.checkType)(pageContext);
|
|
473
|
+
return pageContext;
|
|
474
|
+
}
|
|
475
|
+
return null;
|
|
476
|
+
}
|
|
477
|
+
function renderInvalidVikeConfig(err, pageContextInit, httpRequestId) {
|
|
478
|
+
(0, loggerRuntime_js_1.logRuntimeInfo)?.(picocolors_1.default.bold(picocolors_1.default.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
|
|
479
|
+
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
|
|
480
|
+
return pageContextWithError;
|
|
467
481
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = universalVikeHandler;
|
|
4
|
+
const index_js_1 = require("./index.js");
|
|
5
|
+
async function universalVikeHandler(request, context, runtime) {
|
|
6
|
+
const pageContextInit = { ...context, ...runtime, urlOriginal: request.url, headersOriginal: request.headers };
|
|
7
|
+
const pageContext = await (0, index_js_1.renderPage)(pageContextInit);
|
|
8
|
+
const response = pageContext.httpResponse;
|
|
9
|
+
const readable = response.getReadableWebStream();
|
|
10
|
+
return new Response(readable, {
|
|
11
|
+
status: response.statusCode,
|
|
12
|
+
headers: response.headers
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -4,21 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resolveBase = resolveBase;
|
|
7
|
-
exports.resolveBaseRuntime = resolveBaseRuntime;
|
|
8
|
-
exports.resolveBaseFromResolvedConfig = resolveBaseFromResolvedConfig;
|
|
9
7
|
const utils_js_1 = require("./utils.js");
|
|
10
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
|
-
function resolveBaseFromResolvedConfig(baseServer, baseAssets, config) {
|
|
12
|
-
let baseViteOriginal = config._baseViteOriginal;
|
|
13
|
-
(0, utils_js_1.assert)(baseViteOriginal === null || typeof baseViteOriginal == 'string');
|
|
14
|
-
return resolveBase(baseViteOriginal, baseServer, baseAssets);
|
|
15
|
-
}
|
|
16
|
-
function resolveBaseRuntime(globalContext) {
|
|
17
|
-
const baseViteOriginal = globalContext.viteConfigRuntime._baseViteOriginal;
|
|
18
|
-
const baseServerUnresolved = globalContext.config.baseServer ?? null;
|
|
19
|
-
const baseAssetsUnresolved = globalContext.config.baseAssets ?? null;
|
|
20
|
-
return resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
|
|
21
|
-
}
|
|
22
9
|
function resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved) {
|
|
23
10
|
if (baseViteOriginal === '/__UNSET__')
|
|
24
11
|
baseViteOriginal = null;
|
|
@@ -9,15 +9,9 @@ function getPageConfigsRuntime(virtualFileExports) {
|
|
|
9
9
|
const { pageFilesAll, pageConfigs, pageConfigGlobal } = (0, parseGlobResults_js_1.parseGlobResults)(virtualFileExports);
|
|
10
10
|
const allPageIds = getAllPageIds(pageFilesAll, pageConfigs);
|
|
11
11
|
// TODO/now: re-use this call, instead of calling it twice
|
|
12
|
-
const globalConfig = (0, getPageConfigUserFriendly_js_1.
|
|
13
|
-
// TODO/now DEDUPE
|
|
12
|
+
const globalConfig = (0, getPageConfigUserFriendly_js_1.getPageConfigGlobalUserFriendly)({ pageConfigGlobalValues: pageConfigGlobal.configValues });
|
|
14
13
|
const pageConfigsUserFriendly = Object.fromEntries(pageConfigs.map((pageConfig) => {
|
|
15
|
-
|
|
16
|
-
const page = {
|
|
17
|
-
...(0, getPageConfigUserFriendly_js_1.getPageConfigUserFriendlyNew)({ configValues }),
|
|
18
|
-
route: pageConfig.routeFilesystem?.routeString ?? null
|
|
19
|
-
};
|
|
20
|
-
return [pageConfig.pageId, page];
|
|
14
|
+
return (0, getPageConfigUserFriendly_js_1.getPageConfigUserFriendly)(pageConfigGlobal.configValues, pageConfig, pageConfig.configValues);
|
|
21
15
|
}));
|
|
22
16
|
return { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig, pageConfigsUserFriendly };
|
|
23
17
|
}
|
|
@@ -9,7 +9,7 @@ exports.pageContextJsonFileExtension = pageContextJsonFileExtension;
|
|
|
9
9
|
// `/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
|
|
10
10
|
const doNotCreateExtraDirectory = false;
|
|
11
11
|
exports.doNotCreateExtraDirectory = doNotCreateExtraDirectory;
|
|
12
|
-
// See node/renderPage/handlePageContextRequestUrl.ts
|
|
12
|
+
// See also node/renderPage/handlePageContextRequestUrl.ts
|
|
13
13
|
function getPageContextRequestUrl(url) {
|
|
14
14
|
const pageContextRequestUrl = (0, urlToFile_js_1.urlToFile)(url, pageContextJsonFileExtension, doNotCreateExtraDirectory);
|
|
15
15
|
return pageContextRequestUrl;
|
|
@@ -39,26 +39,29 @@ function getUrlParsed(pageContext) {
|
|
|
39
39
|
// 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
|
|
40
40
|
// Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
|
|
41
41
|
// Determine logical URL
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const assertUrlResolved = (src) => (0, utils_js_1.assert)(typeof urlResolved === 'string',
|
|
43
|
+
// TODO/eventually: remove debug logs, see:
|
|
44
|
+
// - https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
|
|
45
|
+
// - https://github.com/vikejs/vike/commit/5c7810f3080ab62536950f26e019bb2a3a517082
|
|
46
|
+
{ src, urlResolved });
|
|
44
47
|
let urlResolved;
|
|
45
|
-
let
|
|
48
|
+
let isBaseToBeRemoved;
|
|
46
49
|
if (pageContext.urlLogical) {
|
|
47
50
|
// Set by onBeforeRoute()
|
|
48
51
|
urlResolved = pageContext.urlLogical;
|
|
49
|
-
|
|
52
|
+
isBaseToBeRemoved = false;
|
|
50
53
|
assertUrlResolved(1);
|
|
51
54
|
}
|
|
52
55
|
else if (pageContext._urlRewrite) {
|
|
53
56
|
// Set by `throw render()`
|
|
54
57
|
urlResolved = pageContext._urlRewrite;
|
|
55
|
-
|
|
58
|
+
isBaseToBeRemoved = false;
|
|
56
59
|
assertUrlResolved(2);
|
|
57
60
|
}
|
|
58
61
|
else {
|
|
59
62
|
// Set by renderPage()
|
|
60
63
|
urlResolved = pageContext.urlOriginal;
|
|
61
|
-
|
|
64
|
+
isBaseToBeRemoved = true;
|
|
62
65
|
assertUrlResolved(3);
|
|
63
66
|
}
|
|
64
67
|
assertUrlResolved(4);
|
|
@@ -71,7 +74,7 @@ function getUrlParsed(pageContext) {
|
|
|
71
74
|
// - We assume there isn't any Base URL to the URLs set by the user at `throw render()` and onBeforeRoute()
|
|
72
75
|
// - 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).
|
|
73
76
|
// - pageContext.urlOriginal is the URL of the HTTP request and thus contains the Base URL.
|
|
74
|
-
const baseServer = !
|
|
77
|
+
const baseServer = !isBaseToBeRemoved ? '/' : pageContext._baseServer;
|
|
75
78
|
// Parse URL
|
|
76
79
|
return (0, utils_js_1.parseUrl)(urlResolved, baseServer);
|
|
77
80
|
}
|
|
@@ -88,8 +91,8 @@ function urlGetter() {
|
|
|
88
91
|
}
|
|
89
92
|
function urlParsedGetter() {
|
|
90
93
|
const {
|
|
91
|
-
// remove
|
|
92
|
-
|
|
94
|
+
// remove isBaseMissing as it isn't part of UrlPublic
|
|
95
|
+
isBaseMissing: _, ...urlParsed } = getUrlParsed(this);
|
|
93
96
|
const hashIsAvailable = (0, utils_js_1.isBrowser)();
|
|
94
97
|
const warnHashNotAvailable = (prop) => {
|
|
95
98
|
(0, utils_js_1.assertWarning)(hashIsAvailable, `pageContext.urlParsed.${prop} isn't available on the server-side (HTTP requests don't include the URL hash)`, { onlyOnce: true, showStackTrace: true });
|
|
@@ -14,7 +14,7 @@ const helpers_js_1 = require("../page-configs/helpers.js");
|
|
|
14
14
|
const getConfigValueRuntime_js_1 = require("../page-configs/getConfigValueRuntime.js");
|
|
15
15
|
const utils_js_1 = require("../utils.js");
|
|
16
16
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
17
|
-
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('getHook.ts', {});
|
|
17
|
+
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('hooks/getHook.ts', {});
|
|
18
18
|
function getHook(pageContext, hookName) {
|
|
19
19
|
if (!(hookName in pageContext.exports)) {
|
|
20
20
|
return null;
|
|
@@ -3,23 +3,54 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
6
|
+
exports.getPageConfigUserFriendly = getPageConfigUserFriendly;
|
|
7
|
+
exports.getPageConfigUserFriendly_oldDesign = getPageConfigUserFriendly_oldDesign;
|
|
8
|
+
exports.getPageConfigGlobalUserFriendly = getPageConfigGlobalUserFriendly;
|
|
8
9
|
const assert_exports_old_design_js_1 = require("../getPageFiles/assert_exports_old_design.js");
|
|
9
10
|
const getConfigDefinedAt_js_1 = require("./getConfigDefinedAt.js");
|
|
10
11
|
const helpers_js_1 = require("./helpers.js");
|
|
11
12
|
const utils_js_1 = require("../utils.js");
|
|
12
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
function
|
|
14
|
-
const
|
|
14
|
+
function getPageConfigUserFriendly(pageConfigGlobalValues, pageConfig, pageConfigValues) {
|
|
15
|
+
const pageConfigUserFriendly = getPageConfigUserFriendly_public({ pageConfigGlobalValues, pageConfigValues });
|
|
16
|
+
let page;
|
|
17
|
+
if (!pageConfig.isErrorPage) {
|
|
18
|
+
const route = pageConfigUserFriendly.config.route ?? pageConfig.routeFilesystem.routeString;
|
|
19
|
+
page = {
|
|
20
|
+
...pageConfigUserFriendly,
|
|
21
|
+
route
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
page = {
|
|
26
|
+
...pageConfigUserFriendly,
|
|
27
|
+
isErrorPage: true
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return [pageConfig.pageId, page];
|
|
31
|
+
}
|
|
32
|
+
function getPageConfigUserFriendly_public({ pageConfigGlobalValues, pageConfigValues }) {
|
|
33
|
+
const pageConfigUserFriendly = getPageConfigUserFriendly_base({ pageConfigGlobalValues, pageConfigValues });
|
|
34
|
+
return getPublicCopy(pageConfigUserFriendly);
|
|
35
|
+
}
|
|
36
|
+
function getPublicCopy(pageConfigUserFriendly) {
|
|
37
|
+
const p = pageConfigUserFriendly;
|
|
15
38
|
return {
|
|
16
|
-
config:
|
|
17
|
-
_source:
|
|
18
|
-
_sources:
|
|
19
|
-
_from:
|
|
39
|
+
config: p.config,
|
|
40
|
+
_source: p.source,
|
|
41
|
+
_sources: p.sources,
|
|
42
|
+
_from: p.from
|
|
20
43
|
};
|
|
21
44
|
}
|
|
22
|
-
function
|
|
45
|
+
function getPageConfigUserFriendly_base({ pageConfigGlobalValues, pageConfigValues }) {
|
|
46
|
+
const configValues = { ...pageConfigGlobalValues, ...pageConfigValues };
|
|
47
|
+
return getPageConfigUserFriendly_V1Design({ configValues });
|
|
48
|
+
}
|
|
49
|
+
function getPageConfigGlobalUserFriendly({ pageConfigGlobalValues }) {
|
|
50
|
+
const pageConfigGlobalUserFriendly = getPageConfigUserFriendly_V1Design({ configValues: pageConfigGlobalValues });
|
|
51
|
+
return getPublicCopy(pageConfigGlobalUserFriendly);
|
|
52
|
+
}
|
|
53
|
+
function getPageConfigUserFriendly_oldDesign(pageFiles, pageConfig, pageConfigGlobal) {
|
|
23
54
|
const config = {};
|
|
24
55
|
const configEntries = {}; // TODO/v1-release: remove
|
|
25
56
|
const exportsAll = {}; // TODO/v1-release: remove
|
|
@@ -44,8 +75,9 @@ function getPageConfigUserFriendlyOld(pageFiles, pageConfig, pageConfigGlobal) {
|
|
|
44
75
|
let sources;
|
|
45
76
|
let from;
|
|
46
77
|
if (pageConfig) {
|
|
47
|
-
const res =
|
|
48
|
-
|
|
78
|
+
const res = getPageConfigUserFriendly_base({
|
|
79
|
+
pageConfigGlobalValues: pageConfigGlobal.configValues,
|
|
80
|
+
pageConfigValues: pageConfig.configValues
|
|
49
81
|
});
|
|
50
82
|
source = res.source;
|
|
51
83
|
sources = res.sources;
|
|
@@ -92,7 +124,7 @@ function getPageConfigUserFriendlyOld(pageFiles, pageConfig, pageConfigGlobal) {
|
|
|
92
124
|
return pageContextExports;
|
|
93
125
|
}
|
|
94
126
|
// V1 design
|
|
95
|
-
function
|
|
127
|
+
function getPageConfigUserFriendly_V1Design(pageConfig) {
|
|
96
128
|
const config = {};
|
|
97
129
|
const configEntries = {};
|
|
98
130
|
const exportsAll = {};
|
|
@@ -14,15 +14,9 @@ function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
|
14
14
|
// pageConfigs
|
|
15
15
|
const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
|
|
16
16
|
const configValues = parseConfigValuesSerialized(pageConfigSerialized.configValuesSerialized);
|
|
17
|
-
const { pageId, isErrorPage, routeFilesystem, loadConfigValuesAll } = pageConfigSerialized;
|
|
18
17
|
assertRouteConfigValue(configValues);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
isErrorPage,
|
|
22
|
-
routeFilesystem,
|
|
23
|
-
configValues,
|
|
24
|
-
loadConfigValuesAll
|
|
25
|
-
};
|
|
18
|
+
const pageConfig = { ...pageConfigSerialized, configValues };
|
|
19
|
+
return pageConfig;
|
|
26
20
|
});
|
|
27
21
|
// pageConfigsGlobal
|
|
28
22
|
const pageConfigGlobal = { configValues: {} };
|
|
@@ -5,12 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.serializeConfigValues = serializeConfigValues;
|
|
7
7
|
exports.getConfigValuesBase = getConfigValuesBase;
|
|
8
|
+
exports.isJsonValue = isJsonValue;
|
|
8
9
|
const assertSetup_js_1 = require("../../../utils/assertSetup.js");
|
|
9
10
|
const utils_js_1 = require("../../../node/plugin/utils.js");
|
|
10
11
|
const transformPointerImports_js_1 = require("../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformPointerImports.js");
|
|
11
12
|
const helpers_js_1 = require("../helpers.js");
|
|
12
13
|
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
13
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
15
|
+
const stringifyOptions = { forbidReactElements: true };
|
|
14
16
|
const REPLACE_ME_BEFORE = '__VIKE__REPLACE_ME_BEFORE__';
|
|
15
17
|
const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
16
18
|
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with parsePageConfigs()
|
|
@@ -49,7 +51,7 @@ function serializeConfigValues(pageConfig, importStatements, filesEnv, isEnvMatc
|
|
|
49
51
|
function getValueSerializedFromSource(configValueSource, configName, importStatements, filesEnv) {
|
|
50
52
|
(0, utils_js_1.assert)(configValueSource.isOverriden === false);
|
|
51
53
|
let valueData;
|
|
52
|
-
if ('value' in configValueSource) {
|
|
54
|
+
if ('value' in configValueSource && !configValueSource.valueIsLoadedWithImport) {
|
|
53
55
|
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAtFilePath, importStatements, filesEnv, configValueSource.configEnv);
|
|
54
56
|
}
|
|
55
57
|
else {
|
|
@@ -101,14 +103,13 @@ function serializeConfigValue(configValueBase, valueData, configName, lines, tab
|
|
|
101
103
|
}
|
|
102
104
|
function getValueSerializedWithImport(configValueSource, importStatements, filesEnv, configName) {
|
|
103
105
|
(0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
|
|
104
|
-
const {
|
|
105
|
-
(0, utils_js_1.assert)(valueIsImportedAtRuntime);
|
|
106
|
+
const { valueIsDefinedByPlusValueFile, definedAtFilePath, configEnv } = configValueSource;
|
|
106
107
|
const { filePathAbsoluteVite, fileExportName } = definedAtFilePath;
|
|
107
|
-
if (
|
|
108
|
+
if (valueIsDefinedByPlusValueFile)
|
|
108
109
|
(0, utils_js_1.assert)(fileExportName === undefined);
|
|
109
110
|
const { importName } = addImportStatement(importStatements, filePathAbsoluteVite, fileExportName || '*', filesEnv, configEnv, configName);
|
|
110
111
|
return {
|
|
111
|
-
type:
|
|
112
|
+
type: valueIsDefinedByPlusValueFile ? 'plus-file' : 'pointer-import',
|
|
112
113
|
valueAsJsCode: importName
|
|
113
114
|
};
|
|
114
115
|
}
|
|
@@ -125,7 +126,7 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
|
|
|
125
126
|
try {
|
|
126
127
|
configValueSerialized = (0, stringify_1.stringify)(value, {
|
|
127
128
|
valueName,
|
|
128
|
-
|
|
129
|
+
...stringifyOptions,
|
|
129
130
|
// Replace import strings with import variables.
|
|
130
131
|
// - We don't need this anymore and could remove it.
|
|
131
132
|
// - We temporarily needed it for nested document configs (`config.document.{title,description,favicon}`), but we finally decided to go for flat document configs instead (`config.{title,description,favicon}`).
|
|
@@ -152,6 +153,15 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
|
|
|
152
153
|
(0, utils_js_1.assert)(!configValueSerialized.includes(REPLACE_ME_AFTER));
|
|
153
154
|
return configValueSerialized;
|
|
154
155
|
}
|
|
156
|
+
function isJsonValue(value) {
|
|
157
|
+
try {
|
|
158
|
+
(0, stringify_1.stringify)(value, stringifyOptions);
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
155
165
|
function logJsonSerializeError(err, configName, definedAtData) {
|
|
156
166
|
/*
|
|
157
167
|
// import { isJsonSerializerError } from '@brillout/json-serializer/stringify'
|
|
@@ -10,7 +10,7 @@ const getConfigDefinedAt_js_1 = require("../page-configs/getConfigDefinedAt.js")
|
|
|
10
10
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
11
11
|
const getHook_js_1 = require("../hooks/getHook.js");
|
|
12
12
|
async function loadPageRoutes(
|
|
13
|
-
// Remove all arguments and use
|
|
13
|
+
// Remove all arguments and use GlobalContextInternal instead?
|
|
14
14
|
pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
|
|
15
15
|
// TODO/next-major: remove & make this function sync
|
|
16
16
|
await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
|
package/dist/cjs/utils/assert.js
CHANGED
|
@@ -47,7 +47,7 @@ function assert(condition, debugInfo) {
|
|
|
47
47
|
const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
|
|
48
48
|
return picocolors_1.default.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
|
|
49
49
|
})();
|
|
50
|
-
const link = picocolors_1.default.blue('https://github.com/vikejs/vike/issues/new');
|
|
50
|
+
const link = picocolors_1.default.blue('https://github.com/vikejs/vike/issues/new?template=bug.yml');
|
|
51
51
|
let errMsg = [
|
|
52
52
|
`You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually within 24 hours).`,
|
|
53
53
|
debugStr
|
|
@@ -21,7 +21,7 @@ const isVitest_js_1 = require("./isVitest.js");
|
|
|
21
21
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
22
22
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
23
23
|
const debug = (0, debug_js_1.createDebugger)('vike:setup');
|
|
24
|
-
const setup = (0, getGlobalObject_js_1.getGlobalObject)('utils/
|
|
24
|
+
const setup = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertSetup.ts', {});
|
|
25
25
|
// Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
|
|
26
26
|
function assertIsNotProductionRuntime() {
|
|
27
27
|
if (debug.isActivated)
|
|
@@ -16,7 +16,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
16
16
|
/* Use original assertUsage() & assertWarning() after all CJS is removed from node_modules/vike/dist/
|
|
17
17
|
import { assertUsage, assertWarning } from './assert.js'
|
|
18
18
|
*/
|
|
19
|
-
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('assertSingleInstance.ts', {
|
|
19
|
+
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertSingleInstance.ts', {
|
|
20
20
|
instances: [],
|
|
21
21
|
alreadyLogged: new Set()
|
|
22
22
|
});
|
|
@@ -27,7 +27,7 @@ function assertSingleInstance() {
|
|
|
27
27
|
const versions = (0, unique_js_1.unique)(globalObject.instances);
|
|
28
28
|
assertUsage(versions.length <= 1,
|
|
29
29
|
// DO *NOT* patch vike to remove this error: because of multiple conflicting versions, you *will* eventually encounter insidious issues that hard to debug and potentially a security hazard, see for example https://github.com/vikejs/vike/issues/1108
|
|
30
|
-
`vike@${picocolors_1.default.bold(versions[0])} and vike@${picocolors_1.default.bold(versions[1])} loaded but
|
|
30
|
+
`vike@${picocolors_1.default.bold(versions[0])} and vike@${picocolors_1.default.bold(versions[1])} loaded but it's forbidden to load different versions`);
|
|
31
31
|
}
|
|
32
32
|
if (globalObject.checkSingleInstance && globalObject.instances.length > 1) {
|
|
33
33
|
/*/ Not sure whether circular dependency can cause problems? In principle not since client-side code is ESM.
|
|
@@ -8,7 +8,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const isArray_js_1 = require("./isArray.js");
|
|
10
10
|
const path_js_1 = require("./path.js");
|
|
11
|
-
// We need to be able to crawl the filesystem, regardless of Vike's `$ git ls-files` command call, because we need to fallback if the user didn't setup Git (e.g. we cannot remove the
|
|
11
|
+
// We need to be able to crawl the filesystem, regardless of Vike's `$ git ls-files` command call, because we need to fallback if the user didn't setup Git (e.g. we cannot remove the tinyglobby fallback).
|
|
12
12
|
function findFile(arg, cwd) {
|
|
13
13
|
(0, path_js_1.assertPosixPath)(cwd);
|
|
14
14
|
const filenames = (0, isArray_js_1.isArray)(arg) ? arg : [arg];
|
|
@@ -4,17 +4,13 @@ exports.getGlobalObject = getGlobalObject;
|
|
|
4
4
|
exports.assertIsSingleModuleInstance = assertIsSingleModuleInstance;
|
|
5
5
|
const assert_js_1 = require("./assert.js");
|
|
6
6
|
/** Share information across module instances. */
|
|
7
|
-
function getGlobalObject(
|
|
8
|
-
// 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.
|
|
9
|
-
key, defaultValue) {
|
|
7
|
+
function getGlobalObject(key, defaultValue) {
|
|
10
8
|
const globalObjects = getGlobalObjects();
|
|
11
9
|
const globalObject = (globalObjects[key] = globalObjects[key] || defaultValue);
|
|
12
10
|
return globalObject;
|
|
13
11
|
}
|
|
14
12
|
/** Assert that the module is instantiated only once. */
|
|
15
|
-
function assertIsSingleModuleInstance(
|
|
16
|
-
// We use the filename (or file path) as key.
|
|
17
|
-
key) {
|
|
13
|
+
function assertIsSingleModuleInstance(key) {
|
|
18
14
|
const globalObjects = getGlobalObjects();
|
|
19
15
|
(0, assert_js_1.assert)(!(key in globalObjects));
|
|
20
16
|
}
|
|
@@ -30,8 +30,8 @@ function prependBase(url, baseServer) {
|
|
|
30
30
|
return `${baseServerNormalized}${url}`;
|
|
31
31
|
}
|
|
32
32
|
function removeBaseServer(url, baseServer) {
|
|
33
|
-
const {
|
|
34
|
-
(0, assert_js_1.assert)(
|
|
33
|
+
const { isBaseMissing, origin, pathname, pathnameOriginal, searchOriginal, hashOriginal } = (0, parseUrl_js_1.parseUrl)(url, baseServer);
|
|
34
|
+
(0, assert_js_1.assert)(!isBaseMissing);
|
|
35
35
|
(0, parseUrl_js_1.assertUrlComponents)(url, origin, pathnameOriginal, searchOriginal, hashOriginal);
|
|
36
36
|
const urlWithoutBase = (0, parseUrl_js_1.createUrlFromComponents)(origin, pathname, searchOriginal, hashOriginal);
|
|
37
37
|
return urlWithoutBase;
|