vike 0.4.144 → 0.4.145-commit-2520555
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/__internal/index.js +6 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +3 -3
- package/dist/cjs/node/plugin/plugins/commonConfig.js +0 -3
- package/dist/cjs/node/plugin/plugins/config/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +8 -8
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -0
- package/dist/cjs/node/plugin/plugins/envVars.js +34 -20
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +249 -228
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +8 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +36 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +15 -17
- package/dist/cjs/node/plugin/plugins/previewConfig.js +11 -2
- package/dist/cjs/node/prerender/runPrerender.js +34 -26
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +20 -6
- package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +5 -5
- package/dist/cjs/node/runtime/renderPage/log404/index.js +28 -17
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
- package/dist/cjs/node/runtime/renderPage.js +3 -3
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
- package/dist/cjs/node/shared/getConfigVike.js +4 -1
- package/dist/cjs/shared/addUrlComputedProps.js +24 -12
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -6
- package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/getExportPath.js +3 -3
- package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +43 -0
- package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +44 -0
- package/dist/cjs/shared/page-configs/helpers.js +33 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +14 -13
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +9 -10
- package/dist/cjs/shared/route/abort.js +1 -1
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +41 -15
- package/dist/cjs/shared/route/index.js +22 -32
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
- package/dist/cjs/shared/route/noRouteMatch.js +4 -0
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -1
- package/dist/cjs/shared/utils.js +1 -1
- package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
- package/dist/cjs/utils/isExternalLink.js +7 -0
- package/dist/cjs/utils/{hasPropertyGetter.js → isPropertyGetter.js} +3 -3
- package/dist/cjs/utils/onPageVisibilityChange.js +19 -0
- package/dist/cjs/utils/parseUrl.js +1 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/truncateString.js +12 -7
- package/dist/esm/__internal/index.d.ts +6 -3
- package/dist/esm/__internal/index.js +8 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.js +3 -4
- package/dist/esm/client/client-routing-runtime/entry.js +2 -2
- package/dist/esm/client/client-routing-runtime/getBaseServer.d.ts +2 -1
- package/dist/esm/client/client-routing-runtime/getBaseServer.js +2 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +39 -0
- package/dist/esm/client/client-routing-runtime/{getPageContext.js → getPageContextFromHooks.js} +50 -79
- package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/history.js +31 -9
- package/dist/esm/client/client-routing-runtime/installClientRouter.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/installClientRouter.js +22 -0
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.d.ts +8 -0
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +12 -0
- package/dist/esm/client/client-routing-runtime/navigate.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/navigate.js +9 -8
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.d.ts +4 -0
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +63 -0
- package/dist/esm/client/client-routing-runtime/onLinkClick.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/onLinkClick.js +40 -0
- package/dist/esm/client/client-routing-runtime/prefetch.js +54 -29
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +19 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +347 -0
- package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +6 -0
- package/dist/esm/client/client-routing-runtime/scrollRestoration.js +25 -0
- package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +7 -0
- package/dist/esm/client/client-routing-runtime/setScrollPosition.js +77 -0
- package/dist/esm/client/client-routing-runtime/skipLink.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/skipLink.js +9 -5
- package/dist/esm/client/client-routing-runtime/utils.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/utils.js +2 -0
- package/dist/esm/client/server-routing-runtime/getPageContext.js +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.js +6 -5
- package/dist/esm/client/shared/getPageContextProxyForUser.js +13 -7
- package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +8 -3
- package/dist/esm/client/shared/loadPageFilesClientSide.js +5 -5
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -3
- package/dist/esm/node/plugin/plugins/commonConfig.js +0 -3
- package/dist/esm/node/plugin/plugins/config/index.js +4 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +9 -9
- package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -0
- package/dist/esm/node/plugin/plugins/envVars.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/envVars.js +35 -20
- package/dist/esm/node/plugin/plugins/importBuild/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +250 -229
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +7 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +37 -15
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +7 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +15 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +16 -18
- package/dist/esm/node/plugin/plugins/previewConfig.js +11 -2
- package/dist/esm/node/prerender/runPrerender.js +29 -21
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +21 -7
- package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +5 -5
- package/dist/esm/node/runtime/renderPage/debugPageFiles.js +5 -5
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.js +28 -16
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/esm/node/runtime/renderPage.js +3 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/node/shared/getClientEntryFilePath.js +1 -1
- package/dist/esm/node/shared/getConfigVike.d.ts +2 -1
- package/dist/esm/node/shared/getConfigVike.js +4 -1
- package/dist/esm/shared/addUrlComputedProps.d.ts +1 -0
- package/dist/esm/shared/addUrlComputedProps.js +25 -13
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +2 -4
- package/dist/esm/shared/getPageFiles/getExports.js +2 -2
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +55 -31
- package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
- package/dist/esm/shared/page-configs/getExportPath.js +3 -3
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +7 -0
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +37 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.d.ts +14 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.js +38 -0
- package/dist/esm/shared/page-configs/helpers.d.ts +13 -0
- package/dist/esm/shared/page-configs/helpers.js +27 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +2 -2
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +4 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +15 -11
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +9 -10
- package/dist/esm/shared/route/abort.js +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.d.ts +5 -8
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +41 -15
- package/dist/esm/shared/route/index.d.ts +12 -10
- package/dist/esm/shared/route/index.js +23 -33
- package/dist/esm/shared/route/loadPageRoutes.js +8 -7
- package/dist/esm/shared/route/noRouteMatch.d.ts +1 -0
- package/dist/esm/shared/route/noRouteMatch.js +1 -0
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -1
- package/dist/esm/shared/utils.d.ts +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/esm/utils/getFilePathAbsolute.d.ts +1 -1
- package/dist/esm/utils/getFilePathAbsolute.js +11 -11
- package/dist/esm/utils/isPropertyGetter.d.ts +1 -0
- package/dist/esm/utils/{hasPropertyGetter.js → isPropertyGetter.js} +1 -1
- package/dist/esm/utils/onPageVisibilityChange.d.ts +4 -0
- package/dist/esm/utils/onPageVisibilityChange.js +16 -0
- package/dist/esm/utils/parseUrl.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/truncateString.d.ts +2 -1
- package/dist/esm/utils/truncateString.js +10 -7
- package/node/cli/bin-entry.js +1 -1
- package/package.json +2 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -16
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
- package/dist/cjs/shared/page-configs/utils.js +0 -103
- package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +0 -29
- package/dist/esm/client/client-routing-runtime/getPageId.d.ts +0 -10
- package/dist/esm/client/client-routing-runtime/getPageId.js +0 -17
- package/dist/esm/client/client-routing-runtime/navigationState.d.ts +0 -5
- package/dist/esm/client/client-routing-runtime/navigationState.js +0 -14
- package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.js +0 -15
- package/dist/esm/client/client-routing-runtime/useClientRouter.d.ts +0 -6
- package/dist/esm/client/client-routing-runtime/useClientRouter.js +0 -493
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +0 -24
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -10
- package/dist/esm/shared/page-configs/utils.d.ts +0 -35
- package/dist/esm/shared/page-configs/utils.js +0 -97
- package/dist/esm/utils/hasPropertyGetter.d.ts +0 -1
- /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.d.ts +0 -0
- /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.js +0 -0
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
export { useClientRouter };
|
|
2
|
-
export { disableClientRouting };
|
|
3
|
-
export { isDisableAutomaticLinkInterception };
|
|
4
|
-
import { assert, getCurrentUrl, isEquivalentError, objectAssign, serverSideRouteTo, throttle, sleep, getGlobalObject, executeHook } from './utils.js';
|
|
5
|
-
import { navigationState } from './navigationState.js';
|
|
6
|
-
import { checkIf404, getPageContext, getPageContextErrorPage, isAlreadyServerSideRouted } from './getPageContext.js';
|
|
7
|
-
import { createPageContext } from './createPageContext.js';
|
|
8
|
-
import { addLinkPrefetchHandlers } from './prefetch.js';
|
|
9
|
-
import { assertInfo, assertWarning, isReact } from './utils.js';
|
|
10
|
-
import { executeOnRenderClientHook } from '../shared/executeOnRenderClientHook.js';
|
|
11
|
-
import { assertHook } from '../../shared/hooks/getHook.js';
|
|
12
|
-
import { isClientSideRoutable, skipLink } from './skipLink.js';
|
|
13
|
-
import { isErrorFetchingStaticAssets } from '../shared/loadPageFilesClientSide.js';
|
|
14
|
-
import { initHistoryState, getHistoryState, pushHistory, saveScrollPosition } from './history.js';
|
|
15
|
-
import { defineNavigate } from './navigate.js';
|
|
16
|
-
import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError, logAbortErrorHandled } from '../../shared/route/abort.js';
|
|
17
|
-
const globalObject = getGlobalObject('useClientRouter.ts', { previousState: getState() });
|
|
18
|
-
setupNativeScrollRestoration();
|
|
19
|
-
initHistoryState();
|
|
20
|
-
function disableClientRouting(err, log) {
|
|
21
|
-
assert(isErrorFetchingStaticAssets(err));
|
|
22
|
-
globalObject.clientRoutingIsDisabled = true;
|
|
23
|
-
if (log) {
|
|
24
|
-
// We don't use console.error() to avoid flooding error trackers such as Sentry
|
|
25
|
-
console.log(err);
|
|
26
|
-
}
|
|
27
|
-
// @ts-ignore Since dist/cjs/client/ is never used, we can ignore this error.
|
|
28
|
-
const isProd = import.meta.env.PROD;
|
|
29
|
-
assertInfo(false, [
|
|
30
|
-
'Failed to fetch static asset.',
|
|
31
|
-
isProd ? 'This usually happens when a new frontend is deployed.' : null,
|
|
32
|
-
'Falling back to Server Routing.',
|
|
33
|
-
'(The next page navigation will use Server Routing instead of Client Routing.)'
|
|
34
|
-
]
|
|
35
|
-
.filter(Boolean)
|
|
36
|
-
.join(' '), { onlyOnce: true });
|
|
37
|
-
}
|
|
38
|
-
function useClientRouter() {
|
|
39
|
-
autoSaveScrollPosition();
|
|
40
|
-
onLinkClick((url, { keepScrollPosition }) => {
|
|
41
|
-
const scrollTarget = keepScrollPosition ? 'preserve-scroll' : 'scroll-to-top-or-hash';
|
|
42
|
-
fetchAndRender({
|
|
43
|
-
scrollTarget,
|
|
44
|
-
urlOriginal: url,
|
|
45
|
-
isBackwardNavigation: false,
|
|
46
|
-
checkClientSideRenderable: true
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
onBrowserHistoryNavigation((scrollTarget, isBackwardNavigation) => {
|
|
50
|
-
fetchAndRender({ scrollTarget, isBackwardNavigation });
|
|
51
|
-
});
|
|
52
|
-
defineNavigate(async (url, { keepScrollPosition = false, overwriteLastHistoryEntry = false } = {}) => {
|
|
53
|
-
const scrollTarget = keepScrollPosition ? 'preserve-scroll' : 'scroll-to-top-or-hash';
|
|
54
|
-
await fetchAndRender({
|
|
55
|
-
scrollTarget,
|
|
56
|
-
urlOriginal: url,
|
|
57
|
-
overwriteLastHistoryEntry,
|
|
58
|
-
isBackwardNavigation: false,
|
|
59
|
-
checkClientSideRenderable: true
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
let renderingCounter = 0;
|
|
63
|
-
let renderPromise;
|
|
64
|
-
let isTransitioning = false;
|
|
65
|
-
fetchAndRender({ scrollTarget: 'preserve-scroll', isBackwardNavigation: null });
|
|
66
|
-
return;
|
|
67
|
-
async function fetchAndRender({ scrollTarget, urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, checkClientSideRenderable, pageContextsFromRewrite = [], redirectCount = 0 }) {
|
|
68
|
-
assertNoInfiniteAbortLoop(pageContextsFromRewrite.length, redirectCount);
|
|
69
|
-
if (globalObject.clientRoutingIsDisabled) {
|
|
70
|
-
serverSideRouteTo(urlOriginal);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const pageContextFromAllRewrites = getPageContextFromAllRewrites(pageContextsFromRewrite);
|
|
74
|
-
if (checkClientSideRenderable) {
|
|
75
|
-
const urlLogical = pageContextFromAllRewrites._urlRewrite ?? urlOriginal;
|
|
76
|
-
let isClientRoutable;
|
|
77
|
-
try {
|
|
78
|
-
isClientRoutable = await isClientSideRoutable(urlLogical);
|
|
79
|
-
}
|
|
80
|
-
catch (err) {
|
|
81
|
-
if (!isAbortError(err)) {
|
|
82
|
-
// If a route() hook has a bug
|
|
83
|
-
throw err;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
// If the user's route() hook throw redirect() / throw render()
|
|
87
|
-
// We handle the abort error down below: the user's route() hook is called again in getPageContext()
|
|
88
|
-
isClientRoutable = true;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (!isClientRoutable) {
|
|
92
|
-
serverSideRouteTo(urlOriginal);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const pageContextBase = {
|
|
97
|
-
urlOriginal,
|
|
98
|
-
isBackwardNavigation,
|
|
99
|
-
...pageContextFromAllRewrites
|
|
100
|
-
};
|
|
101
|
-
const renderingNumber = ++renderingCounter;
|
|
102
|
-
assert(renderingNumber >= 1);
|
|
103
|
-
// Start transition before any await's
|
|
104
|
-
if (renderingNumber > 1) {
|
|
105
|
-
if (isTransitioning === false) {
|
|
106
|
-
await globalObject.onPageTransitionStart?.(pageContextBase);
|
|
107
|
-
isTransitioning = true;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
let hydrationCanBeAborted = false;
|
|
111
|
-
const shouldAbort = () => {
|
|
112
|
-
{
|
|
113
|
-
// We should never abort the hydration if `hydrationCanBeAborted` isn't `true`
|
|
114
|
-
const isHydration = renderingNumber === 1;
|
|
115
|
-
if (isHydration && hydrationCanBeAborted === false) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// If there is a newer rendering, we should abort all previous renderings
|
|
120
|
-
if (renderingNumber !== renderingCounter) {
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
return false;
|
|
124
|
-
};
|
|
125
|
-
const pageContext = await createPageContext(pageContextBase);
|
|
126
|
-
if (shouldAbort()) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
const isFirstRenderAttempt = renderingNumber === 1;
|
|
130
|
-
objectAssign(pageContext, {
|
|
131
|
-
_isFirstRenderAttempt: isFirstRenderAttempt
|
|
132
|
-
});
|
|
133
|
-
let pageContextAddendum;
|
|
134
|
-
let err;
|
|
135
|
-
let hasError = false;
|
|
136
|
-
try {
|
|
137
|
-
pageContextAddendum = await getPageContext(pageContext);
|
|
138
|
-
}
|
|
139
|
-
catch (err_) {
|
|
140
|
-
hasError = true;
|
|
141
|
-
err = err_;
|
|
142
|
-
}
|
|
143
|
-
if (hasError) {
|
|
144
|
-
if (!isAbortError(err)) {
|
|
145
|
-
// We don't swallow 404 errors:
|
|
146
|
-
// - On the server-side, Vike swallows / doesn't show any 404 error log because it's expected that a user may go to some random non-existent URL. (We don't want to flood the app's error tracking with 404 logs.)
|
|
147
|
-
// - On the client-side, if the user navigates to a 404 then it means that the UI has a broken link. (It isn't expected that users can go to some random URL using the client-side router, as it would require, for example, the user to manually change the URL of a link by manually manipulating the DOM which highly unlikely.)
|
|
148
|
-
console.error(err);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
// We swallow throw redirect()/render() called by client-side hooks onBeforeRender() and guard()
|
|
152
|
-
// We handle the abort error down below.
|
|
153
|
-
}
|
|
154
|
-
if (shouldSwallowAndInterrupt(err, pageContext))
|
|
155
|
-
return;
|
|
156
|
-
if (isAbortError(err)) {
|
|
157
|
-
const errAbort = err;
|
|
158
|
-
logAbortErrorHandled(err, pageContext._isProduction, pageContext);
|
|
159
|
-
const pageContextAbort = errAbort._pageContextAbort;
|
|
160
|
-
// throw render('/some-url')
|
|
161
|
-
if (pageContextAbort._urlRewrite) {
|
|
162
|
-
await fetchAndRender({
|
|
163
|
-
scrollTarget,
|
|
164
|
-
urlOriginal,
|
|
165
|
-
overwriteLastHistoryEntry,
|
|
166
|
-
isBackwardNavigation,
|
|
167
|
-
pageContextsFromRewrite: [...pageContextsFromRewrite, pageContextAbort],
|
|
168
|
-
redirectCount
|
|
169
|
-
});
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
// throw redirect('/some-url')
|
|
173
|
-
if (pageContextAbort._urlRedirect) {
|
|
174
|
-
const urlRedirect = pageContextAbort._urlRedirect.url;
|
|
175
|
-
if (urlRedirect.startsWith('http')) {
|
|
176
|
-
// External redirection
|
|
177
|
-
window.location.href = urlRedirect;
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
await fetchAndRender({
|
|
182
|
-
scrollTarget: 'scroll-to-top-or-hash',
|
|
183
|
-
urlOriginal: urlRedirect,
|
|
184
|
-
overwriteLastHistoryEntry: false,
|
|
185
|
-
isBackwardNavigation: false,
|
|
186
|
-
checkClientSideRenderable: true,
|
|
187
|
-
pageContextsFromRewrite,
|
|
188
|
-
redirectCount: redirectCount++
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
// throw render(statusCode)
|
|
194
|
-
assert(pageContextAbort.abortStatusCode);
|
|
195
|
-
objectAssign(pageContext, pageContextAbort);
|
|
196
|
-
if (pageContextAbort.abortStatusCode === 404) {
|
|
197
|
-
objectAssign(pageContext, { is404: true });
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
objectAssign(pageContext, { is404: checkIf404(err) });
|
|
202
|
-
}
|
|
203
|
-
try {
|
|
204
|
-
pageContextAddendum = await getPageContextErrorPage(pageContext);
|
|
205
|
-
}
|
|
206
|
-
catch (err2) {
|
|
207
|
-
// - When user hasn't defined a `_error.page.js` file
|
|
208
|
-
// - Some unpexected vike internal error
|
|
209
|
-
if (shouldSwallowAndInterrupt(err2, pageContext))
|
|
210
|
-
return;
|
|
211
|
-
if (!isFirstRenderAttempt) {
|
|
212
|
-
setTimeout(() => {
|
|
213
|
-
// We let the server show the 404 page
|
|
214
|
-
window.location.pathname = urlOriginal;
|
|
215
|
-
}, 0);
|
|
216
|
-
}
|
|
217
|
-
if (!isEquivalentError(err, err2)) {
|
|
218
|
-
throw err2;
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
// Abort
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
assert(pageContextAddendum);
|
|
227
|
-
objectAssign(pageContext, pageContextAddendum);
|
|
228
|
-
assertHook(pageContext, 'onPageTransitionStart');
|
|
229
|
-
globalObject.onPageTransitionStart = pageContext.exports.onPageTransitionStart;
|
|
230
|
-
if (pageContext.exports.hydrationCanBeAborted) {
|
|
231
|
-
hydrationCanBeAborted = true;
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
assertWarning(!isReact(), 'You seem to be using React; we recommend setting hydrationCanBeAborted to true, see https://vike.dev/clientRouting', { onlyOnce: true });
|
|
235
|
-
}
|
|
236
|
-
if (shouldAbort()) {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
if (renderPromise) {
|
|
240
|
-
// Always make sure that the previous render has finished,
|
|
241
|
-
// otherwise that previous render may finish after this one.
|
|
242
|
-
await renderPromise;
|
|
243
|
-
}
|
|
244
|
-
if (shouldAbort()) {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
changeUrl(urlOriginal, overwriteLastHistoryEntry);
|
|
248
|
-
navigationState.markNavigationChange();
|
|
249
|
-
assert(renderPromise === undefined);
|
|
250
|
-
renderPromise = (async () => {
|
|
251
|
-
await executeOnRenderClientHook(pageContext, true);
|
|
252
|
-
addLinkPrefetchHandlers(pageContext);
|
|
253
|
-
})();
|
|
254
|
-
await renderPromise;
|
|
255
|
-
renderPromise = undefined;
|
|
256
|
-
if (pageContext._isFirstRenderAttempt) {
|
|
257
|
-
assertHook(pageContext, 'onHydrationEnd');
|
|
258
|
-
const { onHydrationEnd } = pageContext.exports;
|
|
259
|
-
if (onHydrationEnd) {
|
|
260
|
-
const hookFilePath = pageContext.exportsAll.onHydrationEnd[0].exportSource;
|
|
261
|
-
assert(hookFilePath);
|
|
262
|
-
await executeHook(() => onHydrationEnd(pageContext), 'onHydrationEnd', hookFilePath);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
else if (renderingNumber === renderingCounter) {
|
|
266
|
-
if (pageContext.exports.onPageTransitionEnd) {
|
|
267
|
-
assertHook(pageContext, 'onPageTransitionEnd');
|
|
268
|
-
await pageContext.exports.onPageTransitionEnd(pageContext);
|
|
269
|
-
}
|
|
270
|
-
isTransitioning = false;
|
|
271
|
-
}
|
|
272
|
-
setScrollPosition(scrollTarget);
|
|
273
|
-
browserNativeScrollRestoration_disable();
|
|
274
|
-
globalObject.initialRenderIsDone = true;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
function onLinkClick(callback) {
|
|
278
|
-
document.addEventListener('click', onClick);
|
|
279
|
-
return;
|
|
280
|
-
// Code adapted from https://github.com/HenrikJoreteg/internal-nav-helper/blob/5199ec5448d0b0db7ec63cf76d88fa6cad878b7d/src/index.js#L11-L29
|
|
281
|
-
function onClick(ev) {
|
|
282
|
-
if (!isNormalLeftClick(ev))
|
|
283
|
-
return;
|
|
284
|
-
const linkTag = findLinkTag(ev.target);
|
|
285
|
-
if (!linkTag)
|
|
286
|
-
return;
|
|
287
|
-
const url = linkTag.getAttribute('href');
|
|
288
|
-
if (skipLink(linkTag))
|
|
289
|
-
return;
|
|
290
|
-
assert(url);
|
|
291
|
-
ev.preventDefault();
|
|
292
|
-
const keepScrollPosition = ![null, 'false'].includes(linkTag.getAttribute('keep-scroll-position'));
|
|
293
|
-
callback(url, { keepScrollPosition });
|
|
294
|
-
}
|
|
295
|
-
function isNormalLeftClick(ev) {
|
|
296
|
-
return ev.button === 0 && !ev.ctrlKey && !ev.shiftKey && !ev.altKey && !ev.metaKey;
|
|
297
|
-
}
|
|
298
|
-
function findLinkTag(target) {
|
|
299
|
-
while (target.tagName !== 'A') {
|
|
300
|
-
const { parentNode } = target;
|
|
301
|
-
if (!parentNode) {
|
|
302
|
-
return null;
|
|
303
|
-
}
|
|
304
|
-
target = parentNode;
|
|
305
|
-
}
|
|
306
|
-
return target;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
function onBrowserHistoryNavigation(callback) {
|
|
310
|
-
// The `event` of `window.addEventListener('popstate', (event) => /*...*/)` is useless:
|
|
311
|
-
// - The History API doesn't provide the previous state (the popped state): https://stackoverflow.com/questions/48055323/is-history-state-always-the-same-as-popstate-event-state
|
|
312
|
-
window.addEventListener('popstate', () => {
|
|
313
|
-
const currentState = getState();
|
|
314
|
-
const scrollTarget = currentState.historyState.scrollPosition || 'scroll-to-top-or-hash';
|
|
315
|
-
const isHashNavigation = currentState.urlWithoutHash === globalObject.previousState.urlWithoutHash;
|
|
316
|
-
const isBackwardNavigation = !currentState.historyState.timestamp || !globalObject.previousState.historyState.timestamp
|
|
317
|
-
? null
|
|
318
|
-
: currentState.historyState.timestamp < globalObject.previousState.historyState.timestamp;
|
|
319
|
-
globalObject.previousState = currentState;
|
|
320
|
-
if (isHashNavigation) {
|
|
321
|
-
// - `history.state` is uninitialized (`null`) when:
|
|
322
|
-
// - The vike app runs `window.location.hash = '#section'`.
|
|
323
|
-
// - The user clicks on an anchor link `<a href="#section">Section</a>`. (Because Vike's `onLinkClick()` handler skips hash links.)
|
|
324
|
-
// - `history.state` is `null` when uninitialized: https://developer.mozilla.org/en-US/docs/Web/API/History/state
|
|
325
|
-
// - Alternatively, we completely take over hash navigation and reproduce the browser's native behavior upon hash navigation.
|
|
326
|
-
// - Problem: we cannot intercept `window.location.hash = '#section'`. (Or maybe we can with the `hashchange` event?)
|
|
327
|
-
// - Other potential problem: would there be a conflict when the user wants to override the browser's default behavior? E.g. for smooth scrolling, or when using hashes for saving states of some fancy animations.
|
|
328
|
-
// - Another alternative: we use the browser's scroll restoration mechanism (see `browserNativeScrollRestoration_enable()` below).
|
|
329
|
-
// - Problem: not clear when to call `browserNativeScrollRestoration_disable()`/`browserNativeScrollRestoration_enable()`
|
|
330
|
-
// - Other potential problem are inconsistencies between browsers: specification says that setting `window.history.scrollRestoration` only affects the current entry in the session history. But this seems to contradict what folks saying.
|
|
331
|
-
// - Specification: https://html.spec.whatwg.org/multipage/history.html#the-history-interface
|
|
332
|
-
// - https://stackoverflow.com/questions/70188241/history-scrollrestoration-manual-doesnt-prevent-safari-from-restoring-scrol
|
|
333
|
-
if (window.history.state === null) {
|
|
334
|
-
// The browser already scrolled to `#${hash}` => the current scroll position is the right one => we save it with `initHistoryState()`.
|
|
335
|
-
initHistoryState();
|
|
336
|
-
globalObject.previousState = getState();
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
// If `history.state !== null` then it means that `popstate` was triggered by the user clicking on his browser's forward/backward history button.
|
|
340
|
-
setScrollPosition(scrollTarget);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
// Fetch & render new page
|
|
345
|
-
callback(scrollTarget, isBackwardNavigation);
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
function changeUrl(url, overwriteLastHistoryEntry) {
|
|
350
|
-
if (getCurrentUrl() === url)
|
|
351
|
-
return;
|
|
352
|
-
browserNativeScrollRestoration_disable();
|
|
353
|
-
pushHistory(url, overwriteLastHistoryEntry);
|
|
354
|
-
globalObject.previousState = getState();
|
|
355
|
-
}
|
|
356
|
-
function getState() {
|
|
357
|
-
return {
|
|
358
|
-
urlWithoutHash: getCurrentUrl({ withoutHash: true }),
|
|
359
|
-
historyState: getHistoryState()
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
function setScrollPosition(scrollTarget) {
|
|
363
|
-
if (scrollTarget === 'preserve-scroll') {
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
let scrollPosition;
|
|
367
|
-
if (scrollTarget === 'scroll-to-top-or-hash') {
|
|
368
|
-
const hash = getUrlHash();
|
|
369
|
-
// We replicate the browser's native behavior
|
|
370
|
-
if (hash && hash !== 'top') {
|
|
371
|
-
const hashTarget = document.getElementById(hash) || document.getElementsByName(hash)[0];
|
|
372
|
-
if (hashTarget) {
|
|
373
|
-
hashTarget.scrollIntoView();
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
scrollPosition = { x: 0, y: 0 };
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
assert('x' in scrollTarget && 'y' in scrollTarget);
|
|
381
|
-
scrollPosition = scrollTarget;
|
|
382
|
-
}
|
|
383
|
-
setScroll(scrollPosition);
|
|
384
|
-
}
|
|
385
|
-
/** Change the browser's scoll position, in a way that works during a repaint. */
|
|
386
|
-
function setScroll(scrollPosition) {
|
|
387
|
-
const scroll = () => window.scrollTo(scrollPosition.x, scrollPosition.y);
|
|
388
|
-
const done = () => window.scrollX === scrollPosition.x && window.scrollY === scrollPosition.y;
|
|
389
|
-
// In principle, this `done()` call should force the repaint to be finished. But that doesn't seem to be the case with `Firefox 97.0.1`.
|
|
390
|
-
if (done())
|
|
391
|
-
return;
|
|
392
|
-
scroll();
|
|
393
|
-
// Because `done()` doesn't seem to always force the repaint to be finished, we potentially need to retry again.
|
|
394
|
-
if (done())
|
|
395
|
-
return;
|
|
396
|
-
requestAnimationFrame(() => {
|
|
397
|
-
scroll();
|
|
398
|
-
if (done())
|
|
399
|
-
return;
|
|
400
|
-
setTimeout(async () => {
|
|
401
|
-
scroll();
|
|
402
|
-
if (done())
|
|
403
|
-
return;
|
|
404
|
-
// In principle, `requestAnimationFrame() -> setTimeout(, 0)` should be enough.
|
|
405
|
-
// - https://stackoverflow.com/questions/61281139/waiting-for-repaint-in-javascript
|
|
406
|
-
// - But it's not enough for `Firefox 97.0.1`.
|
|
407
|
-
// - The following strategy is very agressive. It doesn't need to be that aggressive for Firefox. But we do it to be safe.
|
|
408
|
-
const start = new Date().getTime();
|
|
409
|
-
while (true) {
|
|
410
|
-
await sleep(10);
|
|
411
|
-
scroll();
|
|
412
|
-
if (done())
|
|
413
|
-
return;
|
|
414
|
-
const millisecondsElapsed = new Date().getTime() - start;
|
|
415
|
-
if (millisecondsElapsed > 100)
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
}, 0);
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
function autoSaveScrollPosition() {
|
|
422
|
-
// Safari cannot handle more than 100 `history.replaceState()` calls within 30 seconds (https://github.com/vikejs/vike/issues/46)
|
|
423
|
-
window.addEventListener('scroll', throttle(saveScrollPosition, Math.ceil(1000 / 3)), { passive: true });
|
|
424
|
-
onPageHide(saveScrollPosition);
|
|
425
|
-
}
|
|
426
|
-
function getUrlHash() {
|
|
427
|
-
let { hash } = window.location;
|
|
428
|
-
if (hash === '')
|
|
429
|
-
return null;
|
|
430
|
-
assert(hash.startsWith('#'));
|
|
431
|
-
hash = hash.slice(1);
|
|
432
|
-
return hash;
|
|
433
|
-
}
|
|
434
|
-
// We use the browser's native scroll restoration mechanism only for the first render
|
|
435
|
-
function setupNativeScrollRestoration() {
|
|
436
|
-
browserNativeScrollRestoration_enable();
|
|
437
|
-
onPageHide(browserNativeScrollRestoration_enable);
|
|
438
|
-
onPageShow(() => globalObject.initialRenderIsDone && browserNativeScrollRestoration_disable());
|
|
439
|
-
}
|
|
440
|
-
function browserNativeScrollRestoration_disable() {
|
|
441
|
-
if ('scrollRestoration' in window.history) {
|
|
442
|
-
window.history.scrollRestoration = 'manual';
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
function browserNativeScrollRestoration_enable() {
|
|
446
|
-
if ('scrollRestoration' in window.history) {
|
|
447
|
-
window.history.scrollRestoration = 'auto';
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
function onPageHide(listener) {
|
|
451
|
-
window.addEventListener('visibilitychange', () => {
|
|
452
|
-
if (document.visibilityState === 'hidden') {
|
|
453
|
-
listener();
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
function onPageShow(listener) {
|
|
458
|
-
window.addEventListener('visibilitychange', () => {
|
|
459
|
-
if (document.visibilityState === 'visible') {
|
|
460
|
-
listener();
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
function shouldSwallowAndInterrupt(err, pageContext) {
|
|
465
|
-
if (isAlreadyServerSideRouted(err))
|
|
466
|
-
return true;
|
|
467
|
-
if (handleErrorFetchingStaticAssets(err, pageContext))
|
|
468
|
-
return true;
|
|
469
|
-
return false;
|
|
470
|
-
}
|
|
471
|
-
function handleErrorFetchingStaticAssets(err, pageContext) {
|
|
472
|
-
if (!isErrorFetchingStaticAssets(err)) {
|
|
473
|
-
return false;
|
|
474
|
-
}
|
|
475
|
-
if (pageContext._isFirstRenderAttempt) {
|
|
476
|
-
disableClientRouting(err, false);
|
|
477
|
-
// This may happen if the frontend was newly deployed during hydration.
|
|
478
|
-
// Ideally: re-try a couple of times by reloading the page (not entirely trivial to implement since `localStorage` is needed.)
|
|
479
|
-
throw err;
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
disableClientRouting(err, true);
|
|
483
|
-
}
|
|
484
|
-
serverSideRouteTo(pageContext.urlOriginal);
|
|
485
|
-
return true;
|
|
486
|
-
}
|
|
487
|
-
function isDisableAutomaticLinkInterception() {
|
|
488
|
-
// @ts-ignore
|
|
489
|
-
return !!window._disableAutomaticLinkInterception;
|
|
490
|
-
/* globalObject should be used if we want to make disableAutomaticLinkInterception a page-by-page setting
|
|
491
|
-
return globalObject.disableAutomaticLinkInterception ?? false
|
|
492
|
-
*/
|
|
493
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export { getFilePathToShowToUser };
|
|
2
|
-
export type { FilePath };
|
|
3
|
-
type FilePath = {
|
|
4
|
-
/** The file's path relative to the filesystem root.
|
|
5
|
-
*
|
|
6
|
-
* Example: `/home/rom/code/my-app/pages/some-page/Page.js`
|
|
7
|
-
*/
|
|
8
|
-
filePathAbsolute: string;
|
|
9
|
-
} & ({
|
|
10
|
-
/** The file's path relative to the Vite's root (i.e. the user's project root directory).
|
|
11
|
-
*
|
|
12
|
-
* Example: `/pages/some-page/Page.js`
|
|
13
|
-
*/
|
|
14
|
-
filePathRelativeToUserRootDir: string;
|
|
15
|
-
importPathAbsolute: null;
|
|
16
|
-
} | {
|
|
17
|
-
filePathRelativeToUserRootDir: null;
|
|
18
|
-
/** The file's absolute import path.
|
|
19
|
-
*
|
|
20
|
-
* Example: `vike-react/config`
|
|
21
|
-
*/
|
|
22
|
-
importPathAbsolute: string;
|
|
23
|
-
});
|
|
24
|
-
declare function getFilePathToShowToUser(filePath: FilePath): string;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { getFilePathToShowToUser };
|
|
2
|
-
import { assert } from '../../../utils.js';
|
|
3
|
-
/*
|
|
4
|
-
const f: FilePath = 1 as any
|
|
5
|
-
if (f.filePathRelativeToUserRootDir === null) {
|
|
6
|
-
f.importPathAbsolute
|
|
7
|
-
}
|
|
8
|
-
//*/
|
|
9
|
-
function getFilePathToShowToUser(filePath) {
|
|
10
|
-
const filePathToShowToUser = filePath.filePathRelativeToUserRootDir ?? filePath.filePathAbsolute;
|
|
11
|
-
assert(filePathToShowToUser);
|
|
12
|
-
return filePathToShowToUser;
|
|
13
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { isConfigEnvMatch };
|
|
2
|
-
function isConfigEnvMatch(configEnv, isForClientSide, isClientRouting) {
|
|
3
|
-
if (configEnv === '_routing-eager' || configEnv === 'config-only')
|
|
4
|
-
return false;
|
|
5
|
-
if (configEnv === (isForClientSide ? 'server-only' : 'client-only'))
|
|
6
|
-
return false;
|
|
7
|
-
if (configEnv === '_routing-lazy' && isForClientSide && !isClientRouting)
|
|
8
|
-
return false;
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export { getConfigValue };
|
|
2
|
-
export { getPageConfig };
|
|
3
|
-
export { getConfigDefinedAtString };
|
|
4
|
-
export { getDefinedAtString };
|
|
5
|
-
export { getConfigValueFilePathToShowToUser };
|
|
6
|
-
export { getHookFilePathToShowToUser };
|
|
7
|
-
import type { PageConfigRuntime, PageConfigBuildTime, ConfigValue, DefinedAt } from './PageConfig.js';
|
|
8
|
-
import type { ConfigNameBuiltIn } from './Config.js';
|
|
9
|
-
type PageConfigCommon = PageConfigRuntime | PageConfigBuildTime;
|
|
10
|
-
type ConfigName = ConfigNameBuiltIn;
|
|
11
|
-
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'string'): null | ConfigValue & {
|
|
12
|
-
value: string;
|
|
13
|
-
};
|
|
14
|
-
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'boolean'): null | ConfigValue & {
|
|
15
|
-
value: boolean;
|
|
16
|
-
};
|
|
17
|
-
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName): null | ConfigValue & {
|
|
18
|
-
value: unknown;
|
|
19
|
-
};
|
|
20
|
-
declare function getPageConfig(pageId: string, pageConfigs: PageConfigRuntime[]): PageConfigRuntime;
|
|
21
|
-
type ConfigDefinedAtUppercase<ConfigName extends string> = `Config ${ConfigName} defined ${'internally' | `at ${string}`}`;
|
|
22
|
-
type ConfigDefinedAtLowercase<ConfigName extends string> = `config ${ConfigName} defined ${'internally' | `at ${string}`}`;
|
|
23
|
-
declare function getConfigDefinedAtString<ConfigName extends string>(configName: ConfigName, { definedAt }: {
|
|
24
|
-
definedAt: DefinedAt;
|
|
25
|
-
}, sentenceBegin: true, append?: 'effect'): ConfigDefinedAtUppercase<ConfigName>;
|
|
26
|
-
declare function getConfigDefinedAtString<ConfigName extends string>(configName: ConfigName, { definedAt }: {
|
|
27
|
-
definedAt: DefinedAt;
|
|
28
|
-
}, sentenceBegin: false, append?: 'effect'): ConfigDefinedAtLowercase<ConfigName>;
|
|
29
|
-
declare function getDefinedAtString(configValue: ConfigValue, configName: string): string;
|
|
30
|
-
declare function getConfigValueFilePathToShowToUser({ definedAt }: {
|
|
31
|
-
definedAt: DefinedAt;
|
|
32
|
-
}): null | string;
|
|
33
|
-
declare function getHookFilePathToShowToUser({ definedAt }: {
|
|
34
|
-
definedAt: DefinedAt;
|
|
35
|
-
}): string;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
export { getConfigValue };
|
|
2
|
-
export { getPageConfig };
|
|
3
|
-
export { getConfigDefinedAtString };
|
|
4
|
-
export { getDefinedAtString };
|
|
5
|
-
export { getConfigValueFilePathToShowToUser };
|
|
6
|
-
export { getHookFilePathToShowToUser };
|
|
7
|
-
import { assert, assertUsage, getValuePrintable } from '../utils.js';
|
|
8
|
-
import pc from '@brillout/picocolors';
|
|
9
|
-
import { getExportPath } from './getExportPath.js';
|
|
10
|
-
// prettier-ignore
|
|
11
|
-
function getConfigValue(pageConfig, configName, type) {
|
|
12
|
-
const configValue = getConfigValueEntry(pageConfig, configName);
|
|
13
|
-
if (configValue === null)
|
|
14
|
-
return null;
|
|
15
|
-
const { value, definedAt } = configValue;
|
|
16
|
-
if (type)
|
|
17
|
-
assertConfigValueType(value, type, configName, definedAt);
|
|
18
|
-
return configValue;
|
|
19
|
-
}
|
|
20
|
-
function assertConfigValueType(value, type, configName, definedAt) {
|
|
21
|
-
assert(value !== null);
|
|
22
|
-
const typeActual = typeof value;
|
|
23
|
-
if (typeActual === type)
|
|
24
|
-
return;
|
|
25
|
-
const valuePrintable = getValuePrintable(value);
|
|
26
|
-
const problem = valuePrintable !== null ? `value ${pc.cyan(valuePrintable)}` : `type ${pc.cyan(typeActual)}`;
|
|
27
|
-
const configDefinedAt = getConfigDefinedAtString(configName, { definedAt }, true);
|
|
28
|
-
assertUsage(false, `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`);
|
|
29
|
-
}
|
|
30
|
-
function getConfigValueEntry(pageConfig, configName) {
|
|
31
|
-
const configValue = pageConfig.configValues[configName];
|
|
32
|
-
if (!configValue)
|
|
33
|
-
return null;
|
|
34
|
-
// Enable users to suppress global config values by setting the local config value to null
|
|
35
|
-
if (configValue.value === null)
|
|
36
|
-
return null;
|
|
37
|
-
return configValue;
|
|
38
|
-
}
|
|
39
|
-
function getPageConfig(pageId, pageConfigs) {
|
|
40
|
-
const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
|
|
41
|
-
assert(pageConfigs.length > 0);
|
|
42
|
-
assert(pageConfig);
|
|
43
|
-
return pageConfig;
|
|
44
|
-
}
|
|
45
|
-
function getConfigDefinedAtString(configName, { definedAt }, sentenceBegin) {
|
|
46
|
-
const configDefinedAt = `${sentenceBegin ? `Config` : `config`} ${pc.cyan(configName)} defined ${getSourceString(definedAt, configName)}`;
|
|
47
|
-
return configDefinedAt;
|
|
48
|
-
}
|
|
49
|
-
function getSourceString(definedAt, configName) {
|
|
50
|
-
if (definedAt.isComputed) {
|
|
51
|
-
return 'internally';
|
|
52
|
-
}
|
|
53
|
-
let files;
|
|
54
|
-
if (definedAt.isCumulative) {
|
|
55
|
-
files = definedAt.files;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
files = [definedAt.file];
|
|
59
|
-
}
|
|
60
|
-
assert(files.length >= 1);
|
|
61
|
-
const sourceString = files
|
|
62
|
-
.map((source) => {
|
|
63
|
-
const { filePathToShowToUser, fileExportPath } = source;
|
|
64
|
-
let s = filePathToShowToUser;
|
|
65
|
-
const exportPath = getExportPath(fileExportPath, configName);
|
|
66
|
-
if (exportPath) {
|
|
67
|
-
s = `${s} > ${pc.cyan(exportPath)}`;
|
|
68
|
-
}
|
|
69
|
-
if (definedAt.isEffect) {
|
|
70
|
-
s = `${s} > (${pc.blue('effect')})`;
|
|
71
|
-
}
|
|
72
|
-
return s;
|
|
73
|
-
})
|
|
74
|
-
.join(' / ');
|
|
75
|
-
return `at ${sourceString}`;
|
|
76
|
-
}
|
|
77
|
-
function getDefinedAtString(configValue, configName) {
|
|
78
|
-
let sourceString = getSourceString(configValue.definedAt, configName);
|
|
79
|
-
if (sourceString.startsWith('at '))
|
|
80
|
-
sourceString = sourceString.slice('at '.length);
|
|
81
|
-
return sourceString;
|
|
82
|
-
}
|
|
83
|
-
function getConfigValueFilePathToShowToUser({ definedAt }) {
|
|
84
|
-
// A unique file path only exists if the config value isn't cumulative nor computed:
|
|
85
|
-
// - cumulative config values have multiple file paths
|
|
86
|
-
// - computed values don't have any file path
|
|
87
|
-
if (definedAt.isComputed || definedAt.isCumulative)
|
|
88
|
-
return null;
|
|
89
|
-
const { filePathToShowToUser } = definedAt.file;
|
|
90
|
-
assert(filePathToShowToUser);
|
|
91
|
-
return filePathToShowToUser;
|
|
92
|
-
}
|
|
93
|
-
function getHookFilePathToShowToUser({ definedAt }) {
|
|
94
|
-
const filePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
|
|
95
|
-
assert(filePathToShowToUser);
|
|
96
|
-
return filePathToShowToUser;
|
|
97
|
-
}
|