vike 0.4.142 → 0.4.143-commit-dc6fea0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/plugin/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +4 -5
- package/dist/cjs/node/plugin/plugins/commonConfig.js +2 -7
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
- package/dist/cjs/node/plugin/plugins/envVars.js +3 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +122 -124
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +37 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +50 -80
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +19 -16
- package/dist/cjs/node/plugin/plugins/suppressRollupWarning.js +16 -3
- package/dist/cjs/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +1 -12
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +3 -3
- package/dist/cjs/node/plugin/utils.js +1 -2
- package/dist/cjs/node/prerender/runPrerender.js +13 -16
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/html/stream.js +4 -1
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
- package/dist/cjs/node/runtime/renderPage/log404/index.js +10 -5
- package/dist/cjs/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +1 -1
- package/dist/cjs/shared/error-page.js +1 -1
- package/dist/cjs/shared/getPageFiles/assertPageConfigs.js +13 -13
- package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +9 -43
- package/dist/cjs/shared/getPageFiles/parsePageConfigsSerialized.js +62 -0
- package/dist/cjs/shared/page-configs/assertExports.js +60 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +18 -0
- package/dist/cjs/shared/page-configs/parseConfigValuesImported.js +50 -0
- package/dist/cjs/shared/page-configs/utils.js +1 -1
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -13
- package/dist/cjs/shared/route/resolvePrecedence.js +32 -11
- package/dist/cjs/shared/route/resolveRedirects.js +1 -1
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -0
- package/dist/cjs/shared/route/resolveRouteString.js +99 -43
- package/dist/cjs/shared/utils.js +1 -1
- package/dist/cjs/types/defineConfig.js +7 -0
- package/dist/cjs/types/index.js +3 -0
- package/dist/cjs/utils/getFilePathAbsolute.js +16 -12
- package/dist/cjs/utils/objectAssign.js +3 -1
- package/dist/cjs/utils/parseUrl.js +6 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/requireResolve.js +60 -0
- package/dist/esm/__internal/index.d.ts +3 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageId.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.js +3 -1
- package/dist/esm/client/client-routing-runtime/useClientRouter.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/loadPageFilesClientSide.d.ts +2 -2
- package/dist/esm/client/shared/loadPageFilesClientSide.js +2 -2
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/plugin/index.js +3 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +4 -5
- package/dist/esm/node/plugin/plugins/commonConfig.js +2 -7
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/esm/node/plugin/plugins/envVars.js +4 -6
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +13 -2
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +19 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +123 -125
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +35 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +49 -79
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +10 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.d.ts +18 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- 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 +19 -16
- package/dist/esm/node/plugin/plugins/suppressRollupWarning.js +16 -3
- package/dist/esm/node/plugin/shared/{getConfigValueSource.d.ts → getConfigValueSourcesRelevant.d.ts} +0 -2
- package/dist/esm/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +0 -11
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
- package/dist/esm/node/plugin/shared/loggerNotProd.js +4 -4
- package/dist/esm/node/plugin/utils.d.ts +1 -2
- package/dist/esm/node/plugin/utils.js +1 -2
- package/dist/esm/node/prerender/runPrerender.js +13 -16
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -2
- package/dist/esm/node/runtime/html/stream.js +4 -1
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.js +10 -5
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +13 -13
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +2 -2
- package/dist/esm/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/shared/addIs404ToPageProps.d.ts +2 -2
- package/dist/esm/shared/addUrlComputedProps.d.ts +4 -2
- package/dist/esm/shared/error-page.d.ts +3 -3
- package/dist/esm/shared/error-page.js +1 -1
- package/dist/esm/shared/getPageFiles/analyzeClientSide.d.ts +2 -2
- package/dist/esm/shared/getPageFiles/assertPageConfigs.d.ts +5 -5
- package/dist/esm/shared/getPageFiles/assertPageConfigs.js +12 -12
- package/dist/esm/shared/getPageFiles/getExports.d.ts +2 -2
- package/dist/esm/shared/getPageFiles/getExports.js +1 -1
- package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +3 -3
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +9 -43
- package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.d.ts +6 -0
- package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.js +59 -0
- package/dist/esm/shared/getPageFiles/setPageFiles.d.ts +3 -3
- package/dist/esm/shared/page-configs/Config.d.ts +201 -14
- package/dist/esm/shared/page-configs/PageConfig.d.ts +60 -39
- package/dist/esm/shared/page-configs/assertExports.d.ts +6 -0
- package/dist/esm/shared/page-configs/assertExports.js +54 -0
- package/dist/esm/shared/page-configs/findPageConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/loadConfigValues.d.ts +3 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +15 -0
- package/dist/esm/shared/page-configs/parseConfigValuesImported.d.ts +3 -0
- package/dist/esm/shared/page-configs/parseConfigValuesImported.js +44 -0
- package/dist/esm/shared/page-configs/utils.d.ts +3 -2
- package/dist/esm/shared/page-configs/utils.js +1 -1
- package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/shared/route/index.d.ts +3 -3
- package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +11 -13
- package/dist/esm/shared/route/resolvePrecedence.js +33 -12
- package/dist/esm/shared/route/resolveRedirects.js +1 -1
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -0
- package/dist/esm/shared/route/resolveRouteString.d.ts +21 -4
- package/dist/esm/shared/route/resolveRouteString.js +98 -42
- package/dist/esm/shared/types.d.ts +8 -6
- package/dist/esm/shared/utils.d.ts +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/esm/types/defineConfig.d.ts +3 -0
- package/dist/esm/types/defineConfig.js +4 -0
- package/dist/esm/types/index.d.ts +3 -1
- package/dist/esm/types/index.js +1 -1
- package/dist/esm/utils/getFilePathAbsolute.d.ts +2 -2
- package/dist/esm/utils/getFilePathAbsolute.js +15 -11
- package/dist/esm/utils/objectAssign.js +3 -1
- package/dist/esm/utils/parseUrl.js +6 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/requireResolve.d.ts +2 -0
- package/dist/esm/utils/requireResolve.js +57 -0
- package/package.json +3 -3
- package/dist/cjs/shared/page-configs/loadPageCode.js +0 -63
- package/dist/cjs/utils/addFileExtensionsToRequireResolve.js +0 -23
- package/dist/cjs/utils/assertDefaultExport.js +0 -53
- package/dist/esm/shared/page-configs/loadPageCode.d.ts +0 -3
- package/dist/esm/shared/page-configs/loadPageCode.js +0 -57
- package/dist/esm/utils/addFileExtensionsToRequireResolve.d.ts +0 -2
- package/dist/esm/utils/addFileExtensionsToRequireResolve.js +0 -20
- package/dist/esm/utils/assertDefaultExport.d.ts +0 -8
- package/dist/esm/utils/assertDefaultExport.js +0 -47
- /package/dist/cjs/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
- /package/dist/esm/shared/getPageFiles/{assertExports.d.ts → assert_exports_old_design.d.ts} +0 -0
- /package/dist/esm/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
|
@@ -9,7 +9,7 @@ const debugPageFiles_js_1 = require("./debugPageFiles.js");
|
|
|
9
9
|
const findPageConfig_js_1 = require("../../../shared/page-configs/findPageConfig.js");
|
|
10
10
|
const analyzePage_js_1 = require("./analyzePage.js");
|
|
11
11
|
const globalContext_js_1 = require("../globalContext.js");
|
|
12
|
-
const
|
|
12
|
+
const loadConfigValues_js_1 = require("../../../shared/page-configs/loadConfigValues.js");
|
|
13
13
|
async function loadPageFilesServerSide(pageContext) {
|
|
14
14
|
const pageConfig = (0, findPageConfig_js_1.findPageConfig)(pageContext._pageConfigs, pageContext._pageId); // Make pageConfig globally available as pageContext._pageConfig?
|
|
15
15
|
const [{ config, configEntries, exports, exportsAll, pageExports, pageFilesLoaded, pageConfigLoaded }] = await Promise.all([
|
|
@@ -85,7 +85,7 @@ async function loadPageFilesServerSide(pageContext) {
|
|
|
85
85
|
exports.loadPageFilesServerSide = loadPageFilesServerSide;
|
|
86
86
|
async function loadPageFiles(pageFilesAll, pageConfig, pageId, isDev) {
|
|
87
87
|
const pageFilesServerSide = (0, getPageFiles_js_1.getPageFilesServerSide)(pageFilesAll, pageId);
|
|
88
|
-
const pageConfigLoaded = !pageConfig ? null : await (0,
|
|
88
|
+
const pageConfigLoaded = !pageConfig ? null : await (0, loadConfigValues_js_1.loadConfigValues)(pageConfig, isDev);
|
|
89
89
|
await Promise.all(pageFilesServerSide.map((p) => p.loadFile?.()));
|
|
90
90
|
const { config, configEntries, exports, exportsAll, pageExports } = (0, getPageFiles_js_1.getExports)(pageFilesServerSide, pageConfigLoaded);
|
|
91
91
|
return {
|
|
@@ -72,8 +72,8 @@ function getPagesAndRoutesInfo(pageRoutes) {
|
|
|
72
72
|
...entries
|
|
73
73
|
];
|
|
74
74
|
const terminalWidth = (0, utils_js_1.getTerminalWidth)() || 134;
|
|
75
|
-
let width2 = Math.max(...linesContent.map(({ routeTypeSrc }) => routeTypeSrc.length));
|
|
76
|
-
let width3 = Math.max(...linesContent.map(({ routeDefinedBy }) => routeDefinedBy.length));
|
|
75
|
+
let width2 = Math.max(...linesContent.map(({ routeTypeSrc }) => (0, utils_js_1.stripAnsi)(routeTypeSrc).length));
|
|
76
|
+
let width3 = Math.max(...linesContent.map(({ routeDefinedBy }) => (0, utils_js_1.stripAnsi)(routeDefinedBy).length));
|
|
77
77
|
let width1 = terminalWidth - width3 - width2 - 10;
|
|
78
78
|
linesContent.forEach((lineContent) => {
|
|
79
79
|
let { routeStr } = lineContent;
|
|
@@ -88,9 +88,9 @@ function getPagesAndRoutesInfo(pageRoutes) {
|
|
|
88
88
|
});
|
|
89
89
|
width1 = Math.max(...linesContent.map(({ routeStr }) => (0, utils_js_1.stripAnsi)(routeStr).length));
|
|
90
90
|
let lines = linesContent.map(({ routeStr, routeTypeSrc, routeDefinedBy }, i) => {
|
|
91
|
-
let cell1 =
|
|
92
|
-
let cell2 =
|
|
93
|
-
let cell3 =
|
|
91
|
+
let cell1 = padEnd(routeStr, width1 + ((0, utils_js_1.stripAnsi)(routeStr).length - (0, utils_js_1.stripAnsi)(routeStr).length));
|
|
92
|
+
let cell2 = padEnd(routeTypeSrc, width2);
|
|
93
|
+
let cell3 = padEnd(routeDefinedBy, width3);
|
|
94
94
|
const isHeader = i === 0;
|
|
95
95
|
if (isHeader) {
|
|
96
96
|
cell1 = picocolors_1.default.dim(cell1);
|
|
@@ -125,6 +125,11 @@ function truncateRouteFunction(routeStr, lenMax) {
|
|
|
125
125
|
routeStr = (0, utils_js_1.truncateString)(routeStr, lenMax, (s) => picocolors_1.default.dim(s));
|
|
126
126
|
return routeStr;
|
|
127
127
|
}
|
|
128
|
+
/** Same as String.prototype.padEnd but with stripAnsi() */
|
|
129
|
+
function padEnd(str, width) {
|
|
130
|
+
const padWidth = Math.max(0, width - (0, utils_js_1.stripAnsi)(str).length);
|
|
131
|
+
return str + ''.padEnd(padWidth, ' ');
|
|
132
|
+
}
|
|
128
133
|
function removeNonAscii(str) {
|
|
129
134
|
// https://stackoverflow.com/questions/20856197/remove-non-ascii-character-in-string/20856346#20856346
|
|
130
135
|
return str.replace(/[^\x00-\x7F]/g, '');
|
|
@@ -7,7 +7,7 @@ const idBase = 'virtual:vike:pageConfigValuesAll:';
|
|
|
7
7
|
const idBaseClient = `${idBase}client:`;
|
|
8
8
|
const idBaseServer = `${idBase}server:`;
|
|
9
9
|
function getVirtualFileIdPageConfigValuesAll(pageId, isForClientSide) {
|
|
10
|
-
const id = `${
|
|
10
|
+
const id = `${isForClientSide ? idBaseClient : idBaseServer}${pageId}`;
|
|
11
11
|
return id;
|
|
12
12
|
}
|
|
13
13
|
exports.getVirtualFileIdPageConfigValuesAll = getVirtualFileIdPageConfigValuesAll;
|
|
@@ -32,7 +32,7 @@ function isErrorPage(pageId, pageConfigs) {
|
|
|
32
32
|
if (pageConfigs.length > 0) {
|
|
33
33
|
const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
|
|
34
34
|
(0, utils_js_1.assert)(pageConfig);
|
|
35
|
-
return pageConfig.isErrorPage;
|
|
35
|
+
return !!pageConfig.isErrorPage;
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
return isErrorPageId(pageId, false);
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.assertPageConfigGlobalSerialized = exports.assertPageConfigsSerialized = void 0;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
|
-
function
|
|
6
|
-
(0, utils_js_1.assert)(Array.isArray(
|
|
7
|
-
|
|
8
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(
|
|
9
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(
|
|
10
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(
|
|
5
|
+
function assertPageConfigsSerialized(pageConfigsSerialized) {
|
|
6
|
+
(0, utils_js_1.assert)(Array.isArray(pageConfigsSerialized));
|
|
7
|
+
pageConfigsSerialized.forEach((pageConfigSerialized) => {
|
|
8
|
+
(0, utils_js_1.assert)((0, utils_js_1.isObject)(pageConfigSerialized));
|
|
9
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'pageId', 'string'));
|
|
10
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'routeFilesystem'));
|
|
11
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'configValuesSerialized'));
|
|
12
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'configValuesImported'));
|
|
11
13
|
});
|
|
12
14
|
}
|
|
13
|
-
exports.
|
|
14
|
-
function
|
|
15
|
-
(0, utils_js_1.assert)(
|
|
16
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigGlobal, 'onBeforeRoute'));
|
|
17
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigGlobal, 'onPrerenderStart'));
|
|
15
|
+
exports.assertPageConfigsSerialized = assertPageConfigsSerialized;
|
|
16
|
+
function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized) {
|
|
17
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigGlobalSerialized, 'configValuesImported'));
|
|
18
18
|
}
|
|
19
|
-
exports.
|
|
19
|
+
exports.assertPageConfigGlobalSerialized = assertPageConfigGlobalSerialized;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getExports = exports.getExportUnion = void 0;
|
|
7
7
|
const isScriptFile_js_1 = require("../../utils/isScriptFile.js");
|
|
8
8
|
const utils_js_1 = require("../utils.js");
|
|
9
|
-
const
|
|
9
|
+
const assert_exports_old_design_js_1 = require("./assert_exports_old_design.js");
|
|
10
10
|
const utils_js_2 = require("../page-configs/utils.js");
|
|
11
11
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
12
12
|
function getExports(pageFiles, pageConfig) {
|
|
@@ -102,7 +102,7 @@ function getExportValues(pageFile) {
|
|
|
102
102
|
else {
|
|
103
103
|
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(exportValue), `The ${picocolors_1.default.cyan('export default')} of ${filePath} should be an object.`);
|
|
104
104
|
Object.entries(exportValue).forEach(([defaultExportName, defaultExportValue]) => {
|
|
105
|
-
(0,
|
|
105
|
+
(0, assert_exports_old_design_js_1.assertDefaultExports)(defaultExportName, filePath);
|
|
106
106
|
exportValues.push({
|
|
107
107
|
exportName: defaultExportName,
|
|
108
108
|
exportValue: defaultExportValue,
|
|
@@ -119,7 +119,7 @@ function getExportValues(pageFile) {
|
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
121
|
exportValues.forEach(({ exportName, isFromDefaultExport }) => {
|
|
122
|
-
(0, utils_js_1.assert)(!(isFromDefaultExport &&
|
|
122
|
+
(0, utils_js_1.assert)(!(isFromDefaultExport && assert_exports_old_design_js_1.forbiddenDefaultExports.includes(exportName)));
|
|
123
123
|
});
|
|
124
124
|
return exportValues;
|
|
125
125
|
}
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseGlobResults = void 0;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
|
-
const
|
|
5
|
+
const assert_exports_old_design_js_1 = require("./assert_exports_old_design.js");
|
|
6
6
|
const getPageFileObject_js_1 = require("./getPageFileObject.js");
|
|
7
7
|
const fileTypes_js_1 = require("./fileTypes.js");
|
|
8
8
|
const assertPageConfigs_js_1 = require("./assertPageConfigs.js");
|
|
9
|
+
const parsePageConfigsSerialized_js_1 = require("./parsePageConfigsSerialized.js");
|
|
9
10
|
function parseGlobResults(pageFilesExports) {
|
|
10
11
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'isGeneratedFile'));
|
|
11
12
|
(0, utils_js_1.assert)(pageFilesExports.isGeneratedFile !== false, `vike was re-installed(/re-built). Restart your app.`);
|
|
@@ -17,12 +18,12 @@ function parseGlobResults(pageFilesExports) {
|
|
|
17
18
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports.pageFilesLazy, '.page'));
|
|
18
19
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports.pageFilesLazy, '.page.client') || (0, utils_js_1.hasProp)(pageFilesExports.pageFilesLazy, '.page.server'));
|
|
19
20
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageFilesList', 'string[]'));
|
|
20
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, '
|
|
21
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, '
|
|
22
|
-
const {
|
|
23
|
-
(0, assertPageConfigs_js_1.
|
|
24
|
-
|
|
25
|
-
(0,
|
|
21
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageConfigsSerialized'));
|
|
22
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageConfigGlobalSerialized'));
|
|
23
|
+
const { pageConfigsSerialized, pageConfigGlobalSerialized } = pageFilesExports;
|
|
24
|
+
(0, assertPageConfigs_js_1.assertPageConfigsSerialized)(pageConfigsSerialized);
|
|
25
|
+
(0, assertPageConfigs_js_1.assertPageConfigGlobalSerialized)(pageConfigGlobalSerialized);
|
|
26
|
+
const { pageConfigs, pageConfigGlobal } = (0, parsePageConfigsSerialized_js_1.parsePageConfigsSerialized)(pageConfigsSerialized, pageConfigGlobalSerialized);
|
|
26
27
|
const pageFilesMap = {};
|
|
27
28
|
parseGlobResult(pageFilesExports.pageFilesLazy).forEach(({ filePath, pageFile, globValue }) => {
|
|
28
29
|
pageFile = pageFilesMap[filePath] = pageFilesMap[filePath] ?? pageFile;
|
|
@@ -31,7 +32,7 @@ function parseGlobResults(pageFilesExports) {
|
|
|
31
32
|
pageFile.loadFile = async () => {
|
|
32
33
|
if (!('fileExports' in pageFile)) {
|
|
33
34
|
pageFile.fileExports = await loadModule();
|
|
34
|
-
(0,
|
|
35
|
+
(0, assert_exports_old_design_js_1.assertExportValues)(pageFile);
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
});
|
|
@@ -90,38 +91,3 @@ function parseGlobResult(globObject) {
|
|
|
90
91
|
function assertLoadModule(globValue) {
|
|
91
92
|
(0, utils_js_1.assert)((0, utils_js_1.isCallable)(globValue));
|
|
92
93
|
}
|
|
93
|
-
function parsePageConfigs(pageConfigs) {
|
|
94
|
-
// TODO: remove
|
|
95
|
-
/*
|
|
96
|
-
pageConfigs.forEach((pageConfig) => {
|
|
97
|
-
Object.entries(pageConfig.configElements).forEach(([configName, configElement]) => {
|
|
98
|
-
{
|
|
99
|
-
const { configValueSerialized } = configElement
|
|
100
|
-
if (configValueSerialized !== undefined) {
|
|
101
|
-
configElement.configValue = parse(configValueSerialized)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (configName === 'route') {
|
|
105
|
-
assertRouteConfigValue(configElement)
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
})
|
|
109
|
-
*/
|
|
110
|
-
}
|
|
111
|
-
// TODO: use again
|
|
112
|
-
// function assertRouteConfigValue(configElement: ConfigElement) {
|
|
113
|
-
// assert(hasProp(configElement, 'configValue')) // route files are eagerly loaded
|
|
114
|
-
// const { configValue } = configElement
|
|
115
|
-
// const configValueType = typeof configValue
|
|
116
|
-
// assertUsage(
|
|
117
|
-
// configValueType === 'string' || isCallable(configValue),
|
|
118
|
-
// `${configElement.configDefinedAt} has an invalid type '${configValueType}': it should be a string or a function instead, see https://vike.dev/route`
|
|
119
|
-
// )
|
|
120
|
-
// /* We don't do that to avoid unnecessarily bloating the client-side bundle when using Server Routing
|
|
121
|
-
// * - When using Server Routing, this file is loaded as well
|
|
122
|
-
// * - When using Server Routing, client-side validation is superfluous as Route Strings only need to be validated on the server-side
|
|
123
|
-
// if (typeof configValue === 'string') {
|
|
124
|
-
// assertRouteString(configValue, `${configElement.configDefinedAt} defines an`)
|
|
125
|
-
// }
|
|
126
|
-
// */
|
|
127
|
-
// }
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePageConfigsSerialized = void 0;
|
|
4
|
+
const parse_1 = require("@brillout/json-serializer/parse");
|
|
5
|
+
const parseConfigValuesImported_js_1 = require("../page-configs/parseConfigValuesImported.js");
|
|
6
|
+
const utils_js_1 = require("../utils.js");
|
|
7
|
+
function parsePageConfigsSerialized(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
8
|
+
const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
|
|
9
|
+
const configValues = {};
|
|
10
|
+
{
|
|
11
|
+
const { configValuesSerialized } = pageConfigSerialized;
|
|
12
|
+
Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
|
|
13
|
+
{
|
|
14
|
+
const { valueSerialized, definedAtInfo } = configValueSeriliazed;
|
|
15
|
+
(0, utils_js_1.assert)(valueSerialized);
|
|
16
|
+
(0, utils_js_1.assert)(!configValues[configName]);
|
|
17
|
+
configValues[configName] = {
|
|
18
|
+
value: (0, parse_1.parse)(valueSerialized),
|
|
19
|
+
definedAtInfo
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
{
|
|
25
|
+
const { configValuesImported } = pageConfigSerialized;
|
|
26
|
+
const configValuesAddendum = (0, parseConfigValuesImported_js_1.parseConfigValuesImported)(configValuesImported);
|
|
27
|
+
Object.assign(configValues, configValuesAddendum);
|
|
28
|
+
}
|
|
29
|
+
const { pageId, isErrorPage, routeFilesystem, loadConfigValuesAll } = pageConfigSerialized;
|
|
30
|
+
assertRouteConfigValue(configValues);
|
|
31
|
+
return {
|
|
32
|
+
pageId,
|
|
33
|
+
isErrorPage,
|
|
34
|
+
routeFilesystem,
|
|
35
|
+
configValues,
|
|
36
|
+
loadConfigValuesAll
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
const pageConfigGlobal = { configValues: {} };
|
|
40
|
+
{
|
|
41
|
+
const configValuesAddendum = (0, parseConfigValuesImported_js_1.parseConfigValuesImported)(pageConfigGlobalSerialized.configValuesImported);
|
|
42
|
+
Object.assign(pageConfigGlobal.configValues, configValuesAddendum);
|
|
43
|
+
}
|
|
44
|
+
return { pageConfigs, pageConfigGlobal };
|
|
45
|
+
}
|
|
46
|
+
exports.parsePageConfigsSerialized = parsePageConfigsSerialized;
|
|
47
|
+
function assertRouteConfigValue(configValues) {
|
|
48
|
+
if (!configValues.route)
|
|
49
|
+
return;
|
|
50
|
+
const { value, definedAtInfo } = configValues.route;
|
|
51
|
+
const configValueType = typeof value;
|
|
52
|
+
(0, utils_js_1.assert)(definedAtInfo);
|
|
53
|
+
(0, utils_js_1.assertUsage)(configValueType === 'string' || (0, utils_js_1.isCallable)(value), `${definedAtInfo.filePath} has an invalid type '${configValueType}': it should be a string or a function instead, see https://vike.dev/route`);
|
|
54
|
+
/* We don't use assertRouteString() in order to avoid unnecessarily bloating the client-side bundle when using Server Routing:
|
|
55
|
+
* - When using Server Routing, this file is loaded => loading assertRouteString() would bloat the client bundle.
|
|
56
|
+
* - assertRouteString() is already called on the server-side
|
|
57
|
+
* - When using Server Routing, client-side validation is superfluous as Route Strings only need to be validated on the server-side
|
|
58
|
+
if (typeof configValue === 'string') {
|
|
59
|
+
assertRouteString(configValue, `${configElement.configDefinedAt} defines an`)
|
|
60
|
+
}
|
|
61
|
+
*/
|
|
62
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.assertExportsOfConfigFile = exports.assertExportsOfValueFile = void 0;
|
|
7
|
+
const utils_js_1 = require("../utils.js");
|
|
8
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
|
+
const EXPORTS_IGNORE = [
|
|
10
|
+
// vite-plugin-solid adds `export { $$registrations }`
|
|
11
|
+
'$$registrations',
|
|
12
|
+
// @vitejs/plugin-vue adds `export { _rerender_only }`
|
|
13
|
+
'_rerender_only'
|
|
14
|
+
];
|
|
15
|
+
// Tolerate `export { frontmatter }` in .mdx files
|
|
16
|
+
const TOLERATE_SIDE_EXPORTS = ['.md', '.mdx'];
|
|
17
|
+
function assertExportsOfValueFile(fileExports, filePathToShowToUser, configName) {
|
|
18
|
+
assertExports(fileExports, filePathToShowToUser, configName);
|
|
19
|
+
}
|
|
20
|
+
exports.assertExportsOfValueFile = assertExportsOfValueFile;
|
|
21
|
+
function assertExportsOfConfigFile(fileExports, filePathToShowToUser) {
|
|
22
|
+
assertExports(fileExports, filePathToShowToUser);
|
|
23
|
+
const exportDefault = fileExports.default;
|
|
24
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(exportDefault), `The ${picocolors_1.default.cyan('export default')} of ${filePathToShowToUser} should be an object (but it's ${picocolors_1.default.cyan(`typeof exportDefault === ${JSON.stringify(typeof exportDefault)}`)} instead)`);
|
|
25
|
+
}
|
|
26
|
+
exports.assertExportsOfConfigFile = assertExportsOfConfigFile;
|
|
27
|
+
function assertExports(fileExports, filePathToShowToUser, configName) {
|
|
28
|
+
const exportsAll = Object.keys(fileExports);
|
|
29
|
+
const exportsRelevant = exportsAll.filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
|
|
30
|
+
const exportsInvalid = exportsRelevant.filter((e) => e !== 'default' &&
|
|
31
|
+
// !!configName => isValueFile
|
|
32
|
+
e !== configName);
|
|
33
|
+
if (exportsInvalid.length === 0) {
|
|
34
|
+
if (exportsRelevant.length === 1) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
(0, utils_js_1.assert)(exportsRelevant.length === 0);
|
|
39
|
+
let errMsg = `${filePathToShowToUser} doesn't export any value, but it should have a ${picocolors_1.default.cyan('export default')}`;
|
|
40
|
+
if (configName)
|
|
41
|
+
errMsg += ` or ${picocolors_1.default.cyan(`export { ${configName} }`)}`;
|
|
42
|
+
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// !configName => isConfigFile
|
|
47
|
+
if (!configName) {
|
|
48
|
+
const exportsInvalidStr = exportsInvalid.join(', ');
|
|
49
|
+
(0, utils_js_1.assertUsage)(false, `${filePathToShowToUser} replace ${picocolors_1.default.cyan(`export { ${exportsInvalidStr} }`)} with ${picocolors_1.default.cyan(`export default { ${exportsInvalidStr} }`)}`);
|
|
50
|
+
}
|
|
51
|
+
// !!configName => isValueFile
|
|
52
|
+
else {
|
|
53
|
+
if (TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext)))
|
|
54
|
+
return;
|
|
55
|
+
exportsInvalid.forEach((exportInvalid) => {
|
|
56
|
+
(0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} should have only a single export: move ${picocolors_1.default.cyan(`export { ${exportInvalid} }`)} to +config.h.js or its own +${exportsInvalid}.js`, { onlyOnce: true });
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadConfigValues = void 0;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
const parseConfigValuesImported_js_1 = require("./parseConfigValuesImported.js");
|
|
6
|
+
async function loadConfigValues(pageConfig, isDev) {
|
|
7
|
+
if ('isLoaded' in pageConfig &&
|
|
8
|
+
// We don't need to cache in dev, since Vite already caches the virtual module
|
|
9
|
+
!isDev) {
|
|
10
|
+
return pageConfig;
|
|
11
|
+
}
|
|
12
|
+
const configValuesImported = await pageConfig.loadConfigValuesAll();
|
|
13
|
+
const configValuesAddendum = (0, parseConfigValuesImported_js_1.parseConfigValuesImported)(configValuesImported);
|
|
14
|
+
Object.assign(pageConfig.configValues, configValuesAddendum);
|
|
15
|
+
(0, utils_js_1.objectAssign)(pageConfig, { isLoaded: true });
|
|
16
|
+
return pageConfig;
|
|
17
|
+
}
|
|
18
|
+
exports.loadConfigValues = loadConfigValues;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseConfigValuesImported = void 0;
|
|
7
|
+
const utils_js_1 = require("../utils.js");
|
|
8
|
+
const assertExports_js_1 = require("./assertExports.js");
|
|
9
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
|
+
function parseConfigValuesImported(configValuesImported) {
|
|
11
|
+
const configValues = {};
|
|
12
|
+
const addConfigValue = (configName, value, filePath, exportName) => {
|
|
13
|
+
configValues[configName] = {
|
|
14
|
+
value,
|
|
15
|
+
definedAtInfo: {
|
|
16
|
+
filePath,
|
|
17
|
+
fileExportPath: [exportName]
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
assertIsNotNull(value, configName, filePath);
|
|
21
|
+
};
|
|
22
|
+
configValuesImported.forEach((configValueLoaded) => {
|
|
23
|
+
if (configValueLoaded.isValueFile) {
|
|
24
|
+
const { importFileExports, importPath, configName } = configValueLoaded;
|
|
25
|
+
if (configName !== 'client') {
|
|
26
|
+
(0, assertExports_js_1.assertExportsOfValueFile)(importFileExports, importPath, configName);
|
|
27
|
+
}
|
|
28
|
+
Object.entries(importFileExports).forEach(([exportName, exportValue]) => {
|
|
29
|
+
const isSideExport = exportName !== 'default'; // .md files may have "side-exports" such as `export { frontmatter }`
|
|
30
|
+
const configName = isSideExport ? exportName : configValueLoaded.configName;
|
|
31
|
+
if (isSideExport && configName in configValues) {
|
|
32
|
+
// We can't avoid side-export conflicts upstream. (Because we cannot know about side-exports upstream at build-time.)
|
|
33
|
+
// Side-exports have the lowest priority.
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
addConfigValue(configName, exportValue, importPath, exportName);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const { configName, importPath, importFileExportValue, exportName } = configValueLoaded;
|
|
41
|
+
addConfigValue(configName, importFileExportValue, importPath, exportName);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return configValues;
|
|
45
|
+
}
|
|
46
|
+
exports.parseConfigValuesImported = parseConfigValuesImported;
|
|
47
|
+
function assertIsNotNull(configValue, configName, importPath) {
|
|
48
|
+
(0, utils_js_1.assert)(!importPath.includes('+config.'));
|
|
49
|
+
(0, utils_js_1.assertUsage)(configValue !== null, `Set ${picocolors_1.default.cyan(configName)} to ${picocolors_1.default.cyan('null')} in a +config.h.js file instead of ${importPath}`);
|
|
50
|
+
}
|
|
@@ -55,7 +55,7 @@ function assertConfigValueType(value, type, configName, definedAtInfo) {
|
|
|
55
55
|
const valuePrintable = (0, utils_js_1.getValuePrintable)(value);
|
|
56
56
|
const problem = valuePrintable !== null ? `value ${picocolors_1.default.cyan(valuePrintable)}` : `type ${picocolors_1.default.cyan(typeActual)}`;
|
|
57
57
|
const configDefinedAt = getConfigDefinedAtString(configName, { definedAtInfo }, true);
|
|
58
|
-
(0, utils_js_1.assertUsage)(false, `${configDefinedAt} has an invalid ${problem}:
|
|
58
|
+
(0, utils_js_1.assertUsage)(false, `${configDefinedAt} has an invalid ${problem}: it should be a ${picocolors_1.default.cyan(type)} instead`);
|
|
59
59
|
}
|
|
60
60
|
function getConfigDefinedAtString(configName, { definedAtInfo }, sentenceBegin, append) {
|
|
61
61
|
let configDefinedAt = `${sentenceBegin ? `Config` : `config`} ${picocolors_1.default.cyan(configName)}`;
|
|
@@ -140,19 +140,17 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
140
140
|
function getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal) {
|
|
141
141
|
// V1 Design
|
|
142
142
|
if (pageConfigs.length > 0) {
|
|
143
|
-
if (pageConfigGlobal.onBeforeRoute) {
|
|
144
|
-
const hookFn = pageConfigGlobal.onBeforeRoute
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return { onBeforeRouteHook, filesystemRoots: null };
|
|
155
|
-
}
|
|
143
|
+
if (pageConfigGlobal.configValues.onBeforeRoute?.value) {
|
|
144
|
+
const { value: hookFn, definedAtInfo } = pageConfigGlobal.configValues.onBeforeRoute;
|
|
145
|
+
// config.onBeforeRoute isn't a computed nor a cumulative config => definedAtInfo should always be defined
|
|
146
|
+
(0, utils_js_1.assert)(definedAtInfo);
|
|
147
|
+
const hookFilePath = definedAtInfo.filePath;
|
|
148
|
+
(0, utils_js_1.assertUsage)((0, utils_js_2.isCallable)(hookFn), `The hook onBeforeRoute() defined by ${hookFilePath} should be a function.`);
|
|
149
|
+
const onBeforeRouteHook = {
|
|
150
|
+
hookFilePath: hookFilePath,
|
|
151
|
+
onBeforeRoute: hookFn
|
|
152
|
+
};
|
|
153
|
+
return { onBeforeRouteHook, filesystemRoots: null };
|
|
156
154
|
}
|
|
157
155
|
return { onBeforeRouteHook: null, filesystemRoots: null };
|
|
158
156
|
}
|
|
@@ -35,37 +35,58 @@ function sortMatches(routeMatch1, routeMatch2) {
|
|
|
35
35
|
if (!routeMatch1.routeString) {
|
|
36
36
|
return 0;
|
|
37
37
|
}
|
|
38
|
+
/* DEBUG
|
|
39
|
+
console.log('routeMatch1.routeString', routeMatch1.routeString)
|
|
40
|
+
console.log('routeMatch2.routeString', routeMatch2.routeString)
|
|
41
|
+
console.log('parseRouteString(routeMatch1.routeString)', parseRouteString(routeMatch1.routeString))
|
|
42
|
+
console.log('parseRouteString(routeMatch2.routeString)', parseRouteString(routeMatch2.routeString))
|
|
43
|
+
//*/
|
|
38
44
|
// Return route with highest number of static path segments at beginning first
|
|
39
45
|
{
|
|
40
|
-
const getValue = (routeString) => (0, resolveRouteString_js_1.analyzeRouteString)(routeString).
|
|
46
|
+
const getValue = (routeString) => (0, resolveRouteString_js_1.analyzeRouteString)(routeString).numberOfStaticPartsBeginning;
|
|
41
47
|
const result = (0, utils_js_1.higherFirst)(getValue)(routeMatch1.routeString, routeMatch2.routeString);
|
|
42
48
|
if (result !== 0) {
|
|
49
|
+
/* DEBUG
|
|
50
|
+
console.log('analyzeRouteString(routeMatch1.routeString).numberOfStaticPartsBeginning', getValue(routeMatch1.routeString))
|
|
51
|
+
console.log('analyzeRouteString(routeMatch2.routeString).numberOfStaticPartsBeginning', getValue(routeMatch2.routeString))
|
|
52
|
+
//*/
|
|
43
53
|
return result;
|
|
44
54
|
}
|
|
45
55
|
}
|
|
46
56
|
// Return route with highest number of static path segments in total first
|
|
47
57
|
{
|
|
48
|
-
const getValue = (routeString) => (0, resolveRouteString_js_1.analyzeRouteString)(routeString).
|
|
58
|
+
const getValue = (routeString) => (0, resolveRouteString_js_1.analyzeRouteString)(routeString).numberOfStaticParts;
|
|
49
59
|
const result = (0, utils_js_1.higherFirst)(getValue)(routeMatch1.routeString, routeMatch2.routeString);
|
|
50
60
|
if (result !== 0) {
|
|
61
|
+
/* DEBUG
|
|
62
|
+
console.log('analyzeRouteString(routeMatch1.routeString).numberOfStaticParts', getValue(routeMatch1.routeString))
|
|
63
|
+
console.log('analyzeRouteString(routeMatch2.routeString).numberOfStaticParts', getValue(routeMatch2.routeString))
|
|
64
|
+
//*/
|
|
51
65
|
return result;
|
|
52
66
|
}
|
|
53
67
|
}
|
|
54
|
-
// Return route with
|
|
68
|
+
// Return route with least amount of globs first
|
|
55
69
|
{
|
|
56
|
-
const getValue = (routeString) => (0, resolveRouteString_js_1.analyzeRouteString)(routeString).
|
|
57
|
-
const result = (0, utils_js_1.
|
|
70
|
+
const getValue = (routeString) => (0, resolveRouteString_js_1.analyzeRouteString)(routeString).numberOfGlobs;
|
|
71
|
+
const result = (0, utils_js_1.lowerFirst)(getValue)(routeMatch1.routeString, routeMatch2.routeString);
|
|
58
72
|
if (result !== 0) {
|
|
73
|
+
/* DEBUG
|
|
74
|
+
console.log('analyzeRouteString(routeMatch1.routeString).numberOfGlobs', getValue(routeMatch1.routeString))
|
|
75
|
+
console.log('analyzeRouteString(routeMatch2.routeString).numberOfGlobs', getValue(routeMatch2.routeString))
|
|
76
|
+
//*/
|
|
59
77
|
return result;
|
|
60
78
|
}
|
|
61
79
|
}
|
|
62
|
-
// Return
|
|
80
|
+
// Return route with highest number of parameters first
|
|
63
81
|
{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
82
|
+
const getValue = (routeString) => (0, resolveRouteString_js_1.analyzeRouteString)(routeString).numberOfParams;
|
|
83
|
+
const result = (0, utils_js_1.higherFirst)(getValue)(routeMatch1.routeString, routeMatch2.routeString);
|
|
84
|
+
if (result !== 0) {
|
|
85
|
+
/* DEBUG
|
|
86
|
+
console.log('analyzeRouteString(routeMatch1.routeString).numberOfParams', getValue(routeMatch1.routeString))
|
|
87
|
+
console.log('analyzeRouteString(routeMatch2.routeString).numberOfParams', getValue(routeMatch2.routeString))
|
|
88
|
+
//*/
|
|
89
|
+
return result;
|
|
69
90
|
}
|
|
70
91
|
}
|
|
71
92
|
return 0;
|
|
@@ -10,7 +10,7 @@ const resolveRouteString_js_1 = require("./resolveRouteString.js");
|
|
|
10
10
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
11
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)(); // Don't bloat the client
|
|
12
12
|
// TODO/v1-release: update
|
|
13
|
-
const configSrc = '[vite.config.js >
|
|
13
|
+
const configSrc = '[vite.config.js > vike({ redirects })]';
|
|
14
14
|
function resolveRedirects(redirects, urlPathname) {
|
|
15
15
|
for (const [urlSource, urlTarget] of Object.entries(redirects)) {
|
|
16
16
|
const urlResolved = resolveRouteStringRedirect(urlSource, urlTarget, urlPathname);
|
|
@@ -22,6 +22,7 @@ async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAt)
|
|
|
22
22
|
result = {};
|
|
23
23
|
}
|
|
24
24
|
(0, utils_js_1.assertUsage)((0, utils_js_1.isPlainObject)(result), `The Route Function ${routeDefinedAt} should return a boolean or a plain JavaScript object (but it's ${picocolors_1.default.cyan(`typeof result === ${JSON.stringify(typeof result)}`)} instead)`);
|
|
25
|
+
// AFAICT this return interface is superfluous. Should we soft-deprecate it and remove it?
|
|
25
26
|
if ('match' in result) {
|
|
26
27
|
const { match } = result;
|
|
27
28
|
(0, utils_js_1.assertUsage)(typeof match === 'boolean', `The ${picocolors_1.default.cyan('match')} value returned by the Route Function ${routeDefinedAt} should be a boolean.`);
|