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
|
@@ -6,7 +6,7 @@ function debugPageFiles({ pageContext, isHtmlOnly, isClientRouting, pageFilesLoa
|
|
|
6
6
|
const padding = ' - ';
|
|
7
7
|
debug('All page files:', printPageFiles(pageContext._pageFilesAll, true)); // TODO
|
|
8
8
|
debug(`URL:`, pageContext.urlOriginal);
|
|
9
|
-
debug.options({ serialization: { emptyArray: 'No match' } })(`Routing:`, printRouteMatches(pageContext.
|
|
9
|
+
debug.options({ serialization: { emptyArray: 'No match' } })(`Routing:`, printRouteMatches(pageContext._debugRouteMatches));
|
|
10
10
|
debug(`pageId:`, pageContext._pageId);
|
|
11
11
|
debug('Page type:', isHtmlOnly ? 'HTML-only' : 'SSR/SPA');
|
|
12
12
|
debug(`Routing type:`, !isHtmlOnly && isClientRouting ? 'Client Routing' : 'Server Routing');
|
|
@@ -16,14 +16,14 @@ function debugPageFiles({ pageContext, isHtmlOnly, isClientRouting, pageFilesLoa
|
|
|
16
16
|
debug('Client-side entries:', clientEntries);
|
|
17
17
|
debug('Client-side dependencies:', clientDependencies);
|
|
18
18
|
return;
|
|
19
|
-
function printRouteMatches(
|
|
20
|
-
if (
|
|
19
|
+
function printRouteMatches(debugRouteMatches) {
|
|
20
|
+
if (debugRouteMatches === 'ROUTING_ERROR') {
|
|
21
21
|
return 'Routing Failed';
|
|
22
22
|
}
|
|
23
|
-
if (
|
|
23
|
+
if (debugRouteMatches === 'CUSTOM_ROUTING') {
|
|
24
24
|
return 'Custom Routing';
|
|
25
25
|
}
|
|
26
|
-
return
|
|
26
|
+
return debugRouteMatches;
|
|
27
27
|
}
|
|
28
28
|
function printPageFiles(pageFiles, genericPageFilesLast = false) {
|
|
29
29
|
if (pageFiles.length === 0) {
|
|
@@ -4,9 +4,9 @@ export type { PageContext_loadPageFilesServerSide };
|
|
|
4
4
|
import { type PageFile } from '../../../shared/getPageFiles.js';
|
|
5
5
|
import { PromiseType } from '../utils.js';
|
|
6
6
|
import { PageContextGetPageAssets, type PageAsset } from './getPageAssets.js';
|
|
7
|
-
import { type
|
|
7
|
+
import { type PageContextDebugRouteMatches } from './debugPageFiles.js';
|
|
8
8
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
9
|
-
type PageContext_loadPageFilesServerSide = PageContextGetPageAssets &
|
|
9
|
+
type PageContext_loadPageFilesServerSide = PageContextGetPageAssets & PageContextDebugRouteMatches & {
|
|
10
10
|
urlOriginal: string;
|
|
11
11
|
_pageFilesAll: PageFile[];
|
|
12
12
|
_pageConfigs: PageConfigRuntime[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { log404 };
|
|
2
|
-
export {
|
|
2
|
+
export { getRoutesInfo };
|
|
3
3
|
import type { PageRoutes } from '../../../../shared/route/index.js';
|
|
4
4
|
declare function log404(pageContext: {
|
|
5
5
|
urlPathname: string;
|
|
@@ -7,4 +7,4 @@ declare function log404(pageContext: {
|
|
|
7
7
|
isClientSideNavigation: boolean;
|
|
8
8
|
_pageRoutes: PageRoutes;
|
|
9
9
|
}): Promise<void>;
|
|
10
|
-
declare function
|
|
10
|
+
declare function getRoutesInfo(pageRoutes: PageRoutes): string | null;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { log404 };
|
|
2
|
-
|
|
2
|
+
// Exported for ./index.spec.ts
|
|
3
|
+
export { getRoutesInfo };
|
|
4
|
+
import { noRouteMatch } from '../../../../shared/route/noRouteMatch.js';
|
|
3
5
|
import { getGlobalContext } from '../../globalContext.js';
|
|
4
6
|
import { assert, assertUsage, assertInfo, compareString, stripAnsi, getTerminalWidth, truncateString } from '../../utils.js';
|
|
5
7
|
import pc from '@brillout/picocolors';
|
|
@@ -13,14 +15,19 @@ async function log404(pageContext) {
|
|
|
13
15
|
);
|
|
14
16
|
const globalContext = getGlobalContext();
|
|
15
17
|
if (!globalContext.isProduction && !isFileRequest(urlPathname) && !pageContext.isClientSideNavigation) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const routesInfo = getRoutesInfo(pageRoutes);
|
|
19
|
+
let msg = `URL ${pc.cyan(urlPathname)} ${noRouteMatch}`;
|
|
20
|
+
const outro = 'See https://vike.dev/routing for more information about routing.';
|
|
21
|
+
if (!routesInfo) {
|
|
22
|
+
msg = `${msg}. ${pc.dim(outro)}`;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
msg = `${msg}:\n${routesInfo}\n${outro}`;
|
|
26
|
+
}
|
|
27
|
+
assertInfo(false, msg, { onlyOnce: false });
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
|
-
function
|
|
30
|
+
function getRoutesInfo(pageRoutes) {
|
|
24
31
|
const entries = pageRoutes
|
|
25
32
|
.map((pageRoute) => {
|
|
26
33
|
let routeStr;
|
|
@@ -69,19 +76,24 @@ function getPagesAndRoutesInfo(pageRoutes) {
|
|
|
69
76
|
const terminalWidth = getTerminalWidth() || 134;
|
|
70
77
|
let width2 = Math.max(...linesContent.map(({ routeTypeSrc }) => stripAnsi(routeTypeSrc).length));
|
|
71
78
|
let width3 = Math.max(...linesContent.map(({ routeDefinedBy }) => stripAnsi(routeDefinedBy).length));
|
|
72
|
-
|
|
79
|
+
const width1_max = terminalWidth -
|
|
80
|
+
width3 -
|
|
81
|
+
width2 -
|
|
82
|
+
// Total width of table border & padding
|
|
83
|
+
10;
|
|
84
|
+
if (width1_max < 10)
|
|
85
|
+
return null;
|
|
73
86
|
linesContent.forEach((lineContent) => {
|
|
74
87
|
let { routeStr } = lineContent;
|
|
75
|
-
if (lineContent.routeTypeSrc
|
|
76
|
-
routeStr =
|
|
77
|
-
|
|
78
|
-
else {
|
|
79
|
-
routeStr = truncateRouteFunction(routeStr, width1);
|
|
88
|
+
if (lineContent.routeTypeSrc === 'Route Function') {
|
|
89
|
+
routeStr = truncateRouteFunction(routeStr, width1_max);
|
|
90
|
+
assert(stripAnsi(routeStr).length <= width1_max);
|
|
80
91
|
}
|
|
81
|
-
assert(stripAnsi(routeStr).length <= width1);
|
|
82
92
|
lineContent.routeStr = routeStr;
|
|
83
93
|
});
|
|
84
|
-
width1 = Math.max(...linesContent.map(({ routeStr }) => stripAnsi(routeStr).length));
|
|
94
|
+
let width1 = Math.max(...linesContent.map(({ routeStr }) => stripAnsi(routeStr).length));
|
|
95
|
+
if (width1 > width1_max)
|
|
96
|
+
return null;
|
|
85
97
|
let lines = linesContent.map(({ routeStr, routeTypeSrc, routeDefinedBy }, i) => {
|
|
86
98
|
let cell1 = padEnd(routeStr, width1 + (stripAnsi(routeStr).length - stripAnsi(routeStr).length));
|
|
87
99
|
let cell2 = padEnd(routeTypeSrc, width2);
|
|
@@ -116,7 +128,7 @@ function truncateRouteFunction(routeStr, lenMax) {
|
|
|
116
128
|
routeStr = stripAnsi(routeStr);
|
|
117
129
|
routeStr = removeNonAscii(routeStr);
|
|
118
130
|
routeStr = routeStr.split(/\s/).filter(Boolean).join(' ');
|
|
119
|
-
routeStr = truncateString(routeStr, lenMax
|
|
131
|
+
routeStr = truncateString(routeStr, lenMax);
|
|
120
132
|
return routeStr;
|
|
121
133
|
}
|
|
122
134
|
/** Same as String.prototype.padEnd but with stripAnsi() */
|
|
@@ -20,7 +20,7 @@ import { preparePageContextForUserConsumptionServerSide } from './preparePageCon
|
|
|
20
20
|
import { executeGuardHook } from '../../../shared/route/executeGuardHook.js';
|
|
21
21
|
import { loadPageRoutes } from '../../../shared/route/loadPageRoutes.js';
|
|
22
22
|
import pc from '@brillout/picocolors';
|
|
23
|
-
import { getConfigValueFilePathToShowToUser } from '../../../shared/page-configs/
|
|
23
|
+
import { getConfigValueFilePathToShowToUser } from '../../../shared/page-configs/helpers.js';
|
|
24
24
|
async function renderPageAlreadyRouted(pageContext) {
|
|
25
25
|
// pageContext._pageId can either be the:
|
|
26
26
|
// - ID of the page matching the routing, or the
|
|
@@ -102,7 +102,7 @@ async function prerender404Page(renderContext, pageContextInit_) {
|
|
|
102
102
|
routeParams: {},
|
|
103
103
|
// `prerender404Page()` is about generating `dist/client/404.html` for static hosts; there is no Client Routing.
|
|
104
104
|
_usesClientRouter: false,
|
|
105
|
-
|
|
105
|
+
_debugRouteMatches: []
|
|
106
106
|
};
|
|
107
107
|
const pageContextInit = {
|
|
108
108
|
urlOriginal: '/fake-404-url',
|
|
@@ -240,8 +240,8 @@ async function renderPageNominal(pageContext) {
|
|
|
240
240
|
}
|
|
241
241
|
// Route
|
|
242
242
|
{
|
|
243
|
-
const
|
|
244
|
-
objectAssign(pageContext,
|
|
243
|
+
const pageContextFromRoute = await route(pageContext);
|
|
244
|
+
objectAssign(pageContext, pageContextFromRoute);
|
|
245
245
|
objectAssign(pageContext, { is404: pageContext._pageId ? null : true });
|
|
246
246
|
if (pageContext._pageId === null) {
|
|
247
247
|
const errorPageId = getErrorPageId(pageContext._pageFilesAll, pageContext._pageConfigs);
|
|
@@ -268,7 +268,7 @@ async function getPageContextErrorPageInit(pageContextInit, errNominalPage, page
|
|
|
268
268
|
routeParams: {}
|
|
269
269
|
};
|
|
270
270
|
objectAssign(pageContext, {
|
|
271
|
-
|
|
271
|
+
_debugRouteMatches: pageContextNominalPagePartial._debugRouteMatches || 'ROUTING_ERROR'
|
|
272
272
|
});
|
|
273
273
|
assert(pageContext.errorWhileRendering);
|
|
274
274
|
return pageContext;
|
|
@@ -25,7 +25,7 @@ export * from '../../utils/capitalizeFirstLetter.js';
|
|
|
25
25
|
export * from '../../utils/debugGlob.js';
|
|
26
26
|
export * from '../../utils/isEquivalentError.js';
|
|
27
27
|
export * from '../../utils/styleFileRE.js';
|
|
28
|
-
export * from '../../utils/
|
|
28
|
+
export * from '../../utils/isPropertyGetter.js';
|
|
29
29
|
export * from '../../utils/debug.js';
|
|
30
30
|
export * from '../../utils/urlToFile.js';
|
|
31
31
|
export * from '../../utils/getGlobalObject.js';
|
|
@@ -28,7 +28,7 @@ export * from '../../utils/capitalizeFirstLetter.js';
|
|
|
28
28
|
export * from '../../utils/debugGlob.js';
|
|
29
29
|
export * from '../../utils/isEquivalentError.js';
|
|
30
30
|
export * from '../../utils/styleFileRE.js';
|
|
31
|
-
export * from '../../utils/
|
|
31
|
+
export * from '../../utils/isPropertyGetter.js';
|
|
32
32
|
export * from '../../utils/debug.js';
|
|
33
33
|
export * from '../../utils/urlToFile.js';
|
|
34
34
|
export * from '../../utils/getGlobalObject.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getClientEntryFilePath };
|
|
2
|
-
import { getConfigValue } from '../../shared/page-configs/
|
|
2
|
+
import { getConfigValue } from '../../shared/page-configs/helpers.js';
|
|
3
3
|
function getClientEntryFilePath(pageConfig) {
|
|
4
4
|
const configName = 'client';
|
|
5
5
|
const configValue = getConfigValue(pageConfig, configName, 'string');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { getConfigVike };
|
|
2
|
+
import { ResolvedConfig } from 'vite';
|
|
2
3
|
import type { ConfigVikeResolved } from '../../shared/ConfigVike.js';
|
|
3
|
-
declare function getConfigVike(config:
|
|
4
|
+
declare function getConfigVike(config: ResolvedConfig): Promise<ConfigVikeResolved>;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { getConfigVike };
|
|
2
|
+
import { assert } from './utils.js';
|
|
2
3
|
async function getConfigVike(config) {
|
|
3
|
-
const
|
|
4
|
+
const { configVikePromise } = config;
|
|
5
|
+
assert(configVikePromise);
|
|
6
|
+
const configVike = await configVikePromise;
|
|
4
7
|
return configVike;
|
|
5
8
|
}
|
|
@@ -55,6 +55,7 @@ type PageContextUrlComputedPropsServer = PageContextUrlComputedPropsClient & {
|
|
|
55
55
|
declare function addUrlComputedProps<PageContext extends Record<string, unknown> & PageContextUrlSources>(pageContext: PageContext, enumerable?: boolean): asserts pageContext is PageContext & PageContextUrlComputedPropsInternal;
|
|
56
56
|
type PageContextUrlSources = {
|
|
57
57
|
urlOriginal: string;
|
|
58
|
+
urlLogical?: string;
|
|
58
59
|
_urlRewrite: string | null;
|
|
59
60
|
_baseServer: string;
|
|
60
61
|
_urlHandler: null | ((url: string) => string);
|
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
// URLs props need to be computed props, because the user can modify the URL e.g. with onBeforeRoute() for i18n
|
|
2
2
|
export { addUrlComputedProps };
|
|
3
3
|
export { assertPageContextUrlComputedProps };
|
|
4
|
-
import { assert, parseUrl, assertWarning, isPlainObject,
|
|
4
|
+
import { assert, parseUrl, assertWarning, isPlainObject, isPropertyGetter, isBrowser } from './utils.js';
|
|
5
5
|
function addUrlComputedProps(pageContext, enumerable = true) {
|
|
6
6
|
assert(pageContext.urlOriginal);
|
|
7
7
|
if ('urlPathname' in pageContext) {
|
|
8
|
-
assert(
|
|
8
|
+
assert(typeof pageContext.urlPathname === 'string');
|
|
9
|
+
/* If this assert() fails then it's most likely because Object.assign() was used instead of objectAssign(), i.e.:
|
|
10
|
+
```js
|
|
11
|
+
// Add property getters such as pageContext.urlPathname to pageContext
|
|
12
|
+
addUrlComputedProps(pageContext)
|
|
13
|
+
// ❌ Breaks the property getters of pageContext set by addUrlComputedProps() such as pageContext.urlPathname
|
|
14
|
+
Object.assign(pageContext2, pageContext)
|
|
15
|
+
// ❌ Also breaks the property getters
|
|
16
|
+
const pageContext3 = { ...pageContext }
|
|
17
|
+
// ✅ Preserves property getters of pageContext (see objectAssign() implementation)
|
|
18
|
+
objectAssign(pageContext2, pageContext)
|
|
19
|
+
```
|
|
20
|
+
*/
|
|
21
|
+
assert(isPropertyGetter(pageContext, 'urlPathname'));
|
|
9
22
|
}
|
|
23
|
+
if ('urlParsed' in pageContext)
|
|
24
|
+
assert(isPropertyGetter(pageContext, 'urlParsed'));
|
|
25
|
+
// TODO/v1-release: move pageContext.urlParsed to pageContext.url
|
|
26
|
+
if ('url' in pageContext)
|
|
27
|
+
assert(isPropertyGetter(pageContext, 'url'));
|
|
10
28
|
Object.defineProperty(pageContext, 'urlPathname', {
|
|
11
29
|
get: urlPathnameGetter,
|
|
12
30
|
enumerable,
|
|
13
31
|
configurable: true
|
|
14
32
|
});
|
|
15
|
-
// TODO/v1-release: move pageContext.urlParsed to pageContext.url
|
|
16
|
-
if ('url' in pageContext)
|
|
17
|
-
assert(hasPropertyGetter(pageContext, 'url'));
|
|
18
33
|
Object.defineProperty(pageContext, 'url', {
|
|
19
34
|
get: urlGetter,
|
|
20
35
|
enumerable: false,
|
|
21
36
|
configurable: true
|
|
22
37
|
});
|
|
23
|
-
if ('urlParsed' in pageContext) {
|
|
24
|
-
assert(hasPropertyGetter(pageContext, 'urlParsed'));
|
|
25
|
-
}
|
|
26
38
|
Object.defineProperty(pageContext, 'urlParsed', {
|
|
27
39
|
get: urlParsedGetter,
|
|
28
40
|
enumerable,
|
|
@@ -30,17 +42,17 @@ function addUrlComputedProps(pageContext, enumerable = true) {
|
|
|
30
42
|
});
|
|
31
43
|
}
|
|
32
44
|
function getUrlParsed(pageContext) {
|
|
33
|
-
// We
|
|
45
|
+
// We need a url handler function because the onBeforeRoute() hook may set pageContext.urlLogical (typically for i18n)
|
|
34
46
|
let urlHandler = pageContext._urlHandler;
|
|
35
47
|
if (!urlHandler) {
|
|
36
48
|
urlHandler = (url) => url;
|
|
37
49
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const urlLogical = urlHandler(url);
|
|
50
|
+
let urlResolved = pageContext._urlRewrite ?? pageContext.urlLogical ?? pageContext.urlOriginal;
|
|
51
|
+
urlResolved = urlHandler(urlResolved);
|
|
41
52
|
const baseServer = pageContext._baseServer;
|
|
53
|
+
assert(urlResolved && typeof urlResolved === 'string');
|
|
42
54
|
assert(baseServer.startsWith('/'));
|
|
43
|
-
return parseUrl(
|
|
55
|
+
return parseUrl(urlResolved, baseServer);
|
|
44
56
|
}
|
|
45
57
|
function urlPathnameGetter() {
|
|
46
58
|
const { pathname } = getUrlParsed(this);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { analyzeClientSide };
|
|
2
|
-
import { getConfigValue } from '../page-configs/
|
|
2
|
+
import { getConfigValue } from '../page-configs/helpers.js';
|
|
3
3
|
import { analyzePageClientSide } from './analyzePageClientSide.js';
|
|
4
4
|
function analyzeClientSide(pageConfig, pageFilesAll, pageId) {
|
|
5
5
|
// V1 design
|
|
@@ -9,9 +9,7 @@ function analyzeClientSide(pageConfig, pageFilesAll, pageId) {
|
|
|
9
9
|
return { isClientSideRenderable, isClientRouting };
|
|
10
10
|
}
|
|
11
11
|
else {
|
|
12
|
-
// TODO/v1-release:
|
|
13
|
-
// - remove V0.4 implementation
|
|
14
|
-
// - globally rename isHtmlOnly to !isClientSideRenderable
|
|
12
|
+
// TODO/v1-release: remove
|
|
15
13
|
// V0.4 design
|
|
16
14
|
const { isHtmlOnly, isClientRouting } = analyzePageClientSide(pageFilesAll, pageId);
|
|
17
15
|
return { isClientSideRenderable: !isHtmlOnly, isClientRouting };
|
|
@@ -3,7 +3,7 @@ export { getExports };
|
|
|
3
3
|
import { isScriptFile, isTemplateFile } from '../../utils/isScriptFile.js';
|
|
4
4
|
import { assert, hasProp, isObject, assertWarning, assertUsage, makeLast, isBrowser } from '../utils.js';
|
|
5
5
|
import { assertDefaultExports, forbiddenDefaultExports } from './assert_exports_old_design.js';
|
|
6
|
-
import { getConfigDefinedAtString, getConfigValueFilePathToShowToUser } from '../page-configs/
|
|
6
|
+
import { getConfigDefinedAtString, getConfigValueFilePathToShowToUser } from '../page-configs/helpers.js';
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
8
8
|
function getExports(pageFiles, pageConfig) {
|
|
9
9
|
const configEntries = {};
|
|
@@ -31,7 +31,7 @@ function getExports(pageFiles, pageConfig) {
|
|
|
31
31
|
Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
|
|
32
32
|
const { value } = configValue;
|
|
33
33
|
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser(configValue);
|
|
34
|
-
const configDefinedAt = getConfigDefinedAtString(configName, configValue
|
|
34
|
+
const configDefinedAt = getConfigDefinedAtString('Config', configName, configValue);
|
|
35
35
|
config[configName] = config[configName] ?? value;
|
|
36
36
|
configEntries[configName] = configEntries[configName] ?? [];
|
|
37
37
|
// Currently each configName has only one entry. Adding an entry for each overriden config value isn't implemented yet. (This is an isomorphic file and it isn't clear whether this can/should be implemented on the client-side. We should load a minimum amount of code on the client-side.)
|
|
@@ -23,6 +23,6 @@ function assertHook(pageContext, hookName) {
|
|
|
23
23
|
function assertHookFn(hookFn, { hookName, hookFilePath }) {
|
|
24
24
|
assert(hookName && hookFilePath);
|
|
25
25
|
assert(!hookName.endsWith(')'));
|
|
26
|
-
assertUsage(isCallable(hookFn), `
|
|
26
|
+
assertUsage(isCallable(hookFn), `Hook ${hookName}() defined by ${hookFilePath} should be a function`);
|
|
27
27
|
checkType(hookFn);
|
|
28
28
|
}
|
|
@@ -13,7 +13,9 @@ export type { ConfigValueComputed };
|
|
|
13
13
|
export type { ConfigValuesComputed };
|
|
14
14
|
export type { DefinedAt };
|
|
15
15
|
export type { DefinedAtFile };
|
|
16
|
-
export type {
|
|
16
|
+
export type { DefinedAtFileFullInfo };
|
|
17
|
+
export type { FilePathResolved };
|
|
18
|
+
export type { FilePath };
|
|
17
19
|
import type { ConfigValueImported } from './serialize/PageConfigSerialized.js';
|
|
18
20
|
type PageConfigBase = {
|
|
19
21
|
pageId: string;
|
|
@@ -23,9 +25,9 @@ type PageConfigBase = {
|
|
|
23
25
|
definedBy: string;
|
|
24
26
|
};
|
|
25
27
|
};
|
|
26
|
-
/** Page config data structure available
|
|
28
|
+
/** Page config data structure available at runtime */
|
|
27
29
|
type PageConfigRuntime = PageConfigBase & {
|
|
28
|
-
/**
|
|
30
|
+
/** All loaded config values */
|
|
29
31
|
configValues: ConfigValues;
|
|
30
32
|
/** Load config values that are lazily loaded such as config.Page */
|
|
31
33
|
loadConfigValuesAll: () => Promise<ConfigValueImported[]>;
|
|
@@ -33,9 +35,9 @@ type PageConfigRuntime = PageConfigBase & {
|
|
|
33
35
|
/** Same as PageConfigRuntime but also contains all lazily loaded config values such as config.Page */
|
|
34
36
|
type PageConfigRuntimeLoaded = PageConfigRuntime & {
|
|
35
37
|
/** Whether loadConfigValuesAll() was called */
|
|
36
|
-
|
|
38
|
+
isAllLoaded: true;
|
|
37
39
|
};
|
|
38
|
-
/** Page config data structure available
|
|
40
|
+
/** Page config data structure available at build-time */
|
|
39
41
|
type PageConfigBuildTime = PageConfigBase & {
|
|
40
42
|
configValues: ConfigValues;
|
|
41
43
|
configValueSources: ConfigValueSources;
|
|
@@ -54,50 +56,72 @@ type ConfigEnvInternal = ConfigEnv | '_routing-eager' | '_routing-lazy';
|
|
|
54
56
|
type ConfigValueSource = {
|
|
55
57
|
value?: unknown;
|
|
56
58
|
configEnv: ConfigEnvInternal;
|
|
57
|
-
|
|
59
|
+
definedAt: DefinedAtFileFullInfo;
|
|
60
|
+
/** Wether the config value is loaded at runtime, for example config.Page or config.onBeforeRender */
|
|
58
61
|
valueIsImportedAtRuntime: boolean;
|
|
62
|
+
/** Whether the config value is a file path, for example config.client */
|
|
59
63
|
valueIsFilePath?: true;
|
|
60
64
|
};
|
|
65
|
+
type DefinedAtFileFullInfo = DefinedAtFile & FilePath & {
|
|
66
|
+
fileExportName?: string;
|
|
67
|
+
};
|
|
68
|
+
type ConfigValueSources = Record<string, ConfigValueSource[]>;
|
|
61
69
|
type ConfigValueComputed = {
|
|
62
70
|
configEnv: ConfigEnvInternal;
|
|
63
71
|
value: unknown;
|
|
64
72
|
};
|
|
65
73
|
type ConfigValuesComputed = Record<string, ConfigValueComputed>;
|
|
66
|
-
type ConfigValueSources = Record<string, ConfigValueSource[]>;
|
|
67
74
|
type ConfigValue = {
|
|
68
75
|
value: unknown;
|
|
69
76
|
definedAt: DefinedAt;
|
|
70
77
|
};
|
|
71
|
-
type
|
|
72
|
-
type DefinedAt = {
|
|
73
|
-
file: DefinedAtFile;
|
|
74
|
-
isEffect?: true;
|
|
75
|
-
isComputed?: undefined;
|
|
76
|
-
isCumulative?: undefined;
|
|
77
|
-
} | {
|
|
78
|
-
isCumulative: true;
|
|
78
|
+
type DefinedAt = DefinedAtFile | {
|
|
79
79
|
files: DefinedAtFile[];
|
|
80
|
-
isEffect?: undefined;
|
|
81
|
-
isComputed?: undefined;
|
|
82
80
|
} | {
|
|
83
81
|
isComputed: true;
|
|
84
|
-
isEffect?: undefined;
|
|
85
|
-
isCumulative?: undefined;
|
|
86
82
|
};
|
|
87
83
|
type DefinedAtFile = {
|
|
88
84
|
filePathToShowToUser: string;
|
|
89
|
-
|
|
85
|
+
fileExportPathToShowToUser: null | string[];
|
|
90
86
|
};
|
|
91
|
-
type
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
type ConfigValues = Record<string, ConfigValue>;
|
|
88
|
+
type FilePathResolved = FilePath & {
|
|
89
|
+
filePathAbsoluteFilesystem: string;
|
|
90
|
+
};
|
|
91
|
+
type FilePath = {
|
|
92
|
+
/** The file's path, absolute from Vite's perspective.
|
|
93
|
+
*
|
|
94
|
+
* We use this to generate import paths in virtual modules. (Virtual modules cannot have relative import paths.)
|
|
95
|
+
*
|
|
96
|
+
* Its value is equivalent to `filePath.filePathRelativeToUserRootDir ?? filePath.importPathAbsolute`, for example:
|
|
97
|
+
* - `vike-react/config`, or
|
|
98
|
+
* - `/pages/+config.h.js`.
|
|
99
|
+
*/
|
|
100
|
+
filePathAbsoluteVite: string;
|
|
101
|
+
/** The file's path, absolute from the filesystem root.
|
|
102
|
+
*
|
|
103
|
+
* Example: `/home/rom/code/my-app/pages/some-page/Page.js`
|
|
104
|
+
*
|
|
105
|
+
* The value is `null` upon aliased import paths which we cannot resolve (we'd need to re-implement https://www.npmjs.com/package/@rollup/plugin-alias).
|
|
106
|
+
*/
|
|
107
|
+
filePathAbsoluteFilesystem: string | null;
|
|
108
|
+
/** The file's path, shown to user upon logging.
|
|
109
|
+
*
|
|
110
|
+
* Currently, its value is equivalent to `FilePath['filePathAbsoluteVite']`.
|
|
111
|
+
*/
|
|
112
|
+
filePathToShowToUser: string;
|
|
113
|
+
} & ({
|
|
97
114
|
filePathRelativeToUserRootDir: null;
|
|
98
|
-
|
|
115
|
+
/** The file's path, as absolute import path. It's either:
|
|
116
|
+
* - an npm package import (e.g. `vike-react/config`), or
|
|
117
|
+
* - an alias (`#components/Counter').
|
|
118
|
+
*/
|
|
99
119
|
importPathAbsolute: string;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
120
|
+
} | {
|
|
121
|
+
/** The file's path, relative to Vite's root (i.e. the user project's root directory).
|
|
122
|
+
*
|
|
123
|
+
* Example: `/pages/some-page/Page.js`
|
|
124
|
+
*/
|
|
125
|
+
filePathRelativeToUserRootDir: string;
|
|
126
|
+
importPathAbsolute: null | string;
|
|
127
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { getExportPath };
|
|
2
|
-
declare function getExportPath(
|
|
2
|
+
declare function getExportPath(fileExportPathToShowToUser: null | string[], configName: string): null | string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { getExportPath };
|
|
2
2
|
import { assert } from '../utils.js';
|
|
3
|
-
function getExportPath(
|
|
4
|
-
if (!
|
|
3
|
+
function getExportPath(fileExportPathToShowToUser, configName) {
|
|
4
|
+
if (!fileExportPathToShowToUser)
|
|
5
5
|
return null;
|
|
6
|
-
let [exportName, ...exportObjectPath] =
|
|
6
|
+
let [exportName, ...exportObjectPath] = fileExportPathToShowToUser;
|
|
7
7
|
if (!exportName)
|
|
8
8
|
return null;
|
|
9
9
|
if (exportObjectPath.length === 0 && ['*', 'default', configName].includes(exportName))
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { getConfigDefinedAtString };
|
|
2
|
+
export { getDefinedAtString };
|
|
3
|
+
import type { DefinedAt } from '../PageConfig.js';
|
|
4
|
+
declare function getConfigDefinedAtString<ConfigName extends string, SentenceBegin extends 'Config' | 'config' | 'Hook'>(sentenceBegin: SentenceBegin, configName: ConfigName, { definedAt }: {
|
|
5
|
+
definedAt: DefinedAt;
|
|
6
|
+
}): `${SentenceBegin} ${ConfigName}${string} defined ${'internally' | `at ${string}`}`;
|
|
7
|
+
declare function getDefinedAtString(definedAt: DefinedAt, configName: string): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export { getConfigDefinedAtString };
|
|
2
|
+
export { getDefinedAtString };
|
|
3
|
+
import { assert } from '../../utils.js';
|
|
4
|
+
import pc from '@brillout/picocolors';
|
|
5
|
+
import { getExportPath } from '../getExportPath.js';
|
|
6
|
+
function getConfigDefinedAtString(sentenceBegin, configName, { definedAt }) {
|
|
7
|
+
const definedAtString = getDefinedAtString(definedAt, configName);
|
|
8
|
+
const definedAtStr = definedAtString === 'internally' ? definedAtString : `at ${definedAtString}`;
|
|
9
|
+
let configNameStr = `${configName}${sentenceBegin === 'Hook' ? '()' : ''}`;
|
|
10
|
+
const configDefinedAt = `${sentenceBegin} ${pc.cyan(configNameStr)} defined ${definedAtStr}`;
|
|
11
|
+
return configDefinedAt;
|
|
12
|
+
}
|
|
13
|
+
function getDefinedAtString(definedAt, configName) {
|
|
14
|
+
if ('isComputed' in definedAt) {
|
|
15
|
+
return 'internally';
|
|
16
|
+
}
|
|
17
|
+
let files;
|
|
18
|
+
if ('files' in definedAt) {
|
|
19
|
+
files = definedAt.files;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
files = [definedAt];
|
|
23
|
+
}
|
|
24
|
+
assert(files.length >= 1);
|
|
25
|
+
const definedAtString = files
|
|
26
|
+
.map((source) => {
|
|
27
|
+
const { filePathToShowToUser, fileExportPathToShowToUser } = source;
|
|
28
|
+
let s = filePathToShowToUser;
|
|
29
|
+
const exportPath = getExportPath(fileExportPathToShowToUser, configName);
|
|
30
|
+
if (exportPath) {
|
|
31
|
+
s = `${s} > ${pc.cyan(exportPath)}`;
|
|
32
|
+
}
|
|
33
|
+
return s;
|
|
34
|
+
})
|
|
35
|
+
.join(' / ');
|
|
36
|
+
return definedAtString;
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { getConfigValue };
|
|
2
|
+
import type { PageConfigRuntime, PageConfigBuildTime, ConfigValue } from '../PageConfig.js';
|
|
3
|
+
import type { ConfigNameBuiltIn } from '../Config.js';
|
|
4
|
+
type PageConfigCommon = PageConfigRuntime | PageConfigBuildTime;
|
|
5
|
+
type ConfigName = ConfigNameBuiltIn;
|
|
6
|
+
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'string'): null | ConfigValue & {
|
|
7
|
+
value: string;
|
|
8
|
+
};
|
|
9
|
+
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'boolean'): null | ConfigValue & {
|
|
10
|
+
value: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName): null | ConfigValue & {
|
|
13
|
+
value: unknown;
|
|
14
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export { getConfigValue };
|
|
2
|
+
import { assert, assertUsage, getValuePrintable } from '../../utils.js';
|
|
3
|
+
import pc from '@brillout/picocolors';
|
|
4
|
+
import { getConfigDefinedAtString } from './getConfigDefinedAtString.js';
|
|
5
|
+
// prettier-ignore
|
|
6
|
+
function getConfigValue(pageConfig, configName, type) {
|
|
7
|
+
const configValue = getConfigValueEntry(pageConfig, configName);
|
|
8
|
+
if (configValue === null)
|
|
9
|
+
return null;
|
|
10
|
+
const { value, definedAt } = configValue;
|
|
11
|
+
if (type)
|
|
12
|
+
assertConfigValueType(value, type, configName, definedAt);
|
|
13
|
+
return configValue;
|
|
14
|
+
}
|
|
15
|
+
function assertConfigValueType(value, type, configName, definedAt) {
|
|
16
|
+
assert(value !== null);
|
|
17
|
+
const typeActual = typeof value;
|
|
18
|
+
if (typeActual === type)
|
|
19
|
+
return;
|
|
20
|
+
const valuePrintable = getValuePrintable(value);
|
|
21
|
+
const problem = valuePrintable !== null
|
|
22
|
+
? `value ${pc.cyan(valuePrintable)}`
|
|
23
|
+
: `type ${pc.cyan(typeActual)}`;
|
|
24
|
+
const configDefinedAt = getConfigDefinedAtString('Config', configName, {
|
|
25
|
+
definedAt
|
|
26
|
+
});
|
|
27
|
+
const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`;
|
|
28
|
+
assertUsage(false, errMsg);
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { getPageConfig };
|
|
2
|
+
export { getConfigValueFilePathToShowToUser };
|
|
3
|
+
export { getHookFilePathToShowToUser };
|
|
4
|
+
export { getConfigDefinedAtString, getDefinedAtString } from './helpers/getConfigDefinedAtString.js';
|
|
5
|
+
export { getConfigValue } from './helpers/getConfigValue.js';
|
|
6
|
+
import type { PageConfigRuntime, DefinedAt } from './PageConfig.js';
|
|
7
|
+
declare function getPageConfig(pageId: string, pageConfigs: PageConfigRuntime[]): PageConfigRuntime;
|
|
8
|
+
declare function getConfigValueFilePathToShowToUser({ definedAt }: {
|
|
9
|
+
definedAt: DefinedAt;
|
|
10
|
+
}): null | string;
|
|
11
|
+
declare function getHookFilePathToShowToUser({ definedAt }: {
|
|
12
|
+
definedAt: DefinedAt;
|
|
13
|
+
}): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { getPageConfig };
|
|
2
|
+
export { getConfigValueFilePathToShowToUser };
|
|
3
|
+
export { getHookFilePathToShowToUser };
|
|
4
|
+
export { getConfigDefinedAtString, getDefinedAtString } from './helpers/getConfigDefinedAtString.js';
|
|
5
|
+
export { getConfigValue } from './helpers/getConfigValue.js';
|
|
6
|
+
import { assert } from '../utils.js';
|
|
7
|
+
function getPageConfig(pageId, pageConfigs) {
|
|
8
|
+
const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
|
|
9
|
+
assert(pageConfigs.length > 0);
|
|
10
|
+
assert(pageConfig);
|
|
11
|
+
return pageConfig;
|
|
12
|
+
}
|
|
13
|
+
function getConfigValueFilePathToShowToUser({ definedAt }) {
|
|
14
|
+
// A unique file path only exists if the config value isn't cumulative nor computed:
|
|
15
|
+
// - cumulative config values have multiple file paths
|
|
16
|
+
// - computed values don't have any file path
|
|
17
|
+
if ('isComputed' in definedAt || 'files' in definedAt)
|
|
18
|
+
return null;
|
|
19
|
+
const { filePathToShowToUser } = definedAt;
|
|
20
|
+
assert(filePathToShowToUser);
|
|
21
|
+
return filePathToShowToUser;
|
|
22
|
+
}
|
|
23
|
+
function getHookFilePathToShowToUser({ definedAt }) {
|
|
24
|
+
const filePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
|
|
25
|
+
assert(filePathToShowToUser);
|
|
26
|
+
return filePathToShowToUser;
|
|
27
|
+
}
|