vike 0.4.143 → 0.4.144-commit-e40e9b1
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 +1 -1
- package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +31 -30
- package/dist/cjs/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +19 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +228 -186
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -35
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +60 -95
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +14 -13
- package/dist/cjs/node/plugin/shared/findPageFiles.js +2 -1
- package/dist/cjs/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +1 -12
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/cjs/node/plugin/utils.js +2 -3
- package/dist/cjs/node/prerender/runPrerender.js +18 -20
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -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/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
- package/dist/cjs/node/runtime/renderPage.js +1 -1
- package/dist/cjs/node/shared/getClientEntryFilePath.js +1 -7
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/cjs/shared/error-page.js +1 -1
- package/dist/cjs/shared/getPageFiles/getExports.js +8 -11
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +10 -44
- package/dist/cjs/shared/hooks/getHook.js +3 -1
- package/dist/cjs/shared/page-configs/assertExports.js +60 -0
- package/dist/cjs/shared/page-configs/getExportPath.js +9 -10
- package/dist/cjs/shared/page-configs/loadConfigValues.js +18 -0
- package/dist/cjs/shared/page-configs/serialize/PageConfigSerialized.js +2 -0
- package/dist/cjs/shared/page-configs/serialize/assertPageConfigs.js +19 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +56 -0
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +65 -0
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +58 -0
- package/dist/cjs/shared/page-configs/utils.js +65 -42
- package/dist/cjs/shared/route/loadPageRoutes.js +12 -15
- package/dist/cjs/shared/route/resolveRedirects.js +1 -1
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -0
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/getOutDirs.js +25 -18
- package/dist/cjs/utils/getValuePrintable.js +1 -1
- package/dist/cjs/utils/objectAssign.js +3 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/{resolve.js → requireResolve.js} +3 -3
- package/dist/cjs/utils/warnIfErrorIsNotObject.js +1 -1
- 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/useClientRouter.js +3 -3
- 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 +2 -2
- package/dist/esm/node/plugin/plugins/config/index.js +2 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +31 -30
- 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 +20 -11
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
- 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 +5 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +229 -187
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -32
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +60 -95
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -5
- 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/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 +14 -13
- package/dist/esm/node/plugin/shared/findPageFiles.js +3 -2
- 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.js +2 -2
- package/dist/esm/node/plugin/utils.d.ts +1 -2
- package/dist/esm/node/plugin/utils.js +2 -3
- package/dist/esm/node/prerender/runPrerender.js +20 -22
- 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/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/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
- package/dist/esm/node/runtime/renderPage.js +1 -1
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +2 -2
- package/dist/esm/node/shared/getClientEntryFilePath.js +2 -8
- package/dist/esm/shared/addIs404ToPageProps.d.ts +2 -2
- package/dist/esm/shared/addUrlComputedProps.d.ts +4 -2
- package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
- 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/getExports.d.ts +3 -4
- package/dist/esm/shared/getPageFiles/getExports.js +7 -10
- package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +3 -3
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +9 -43
- package/dist/esm/shared/getPageFiles/setPageFiles.d.ts +3 -3
- package/dist/esm/shared/hooks/getHook.js +3 -1
- package/dist/esm/shared/page-configs/Config.d.ts +201 -14
- package/dist/esm/shared/page-configs/PageConfig.d.ts +80 -73
- 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/getExportPath.d.ts +1 -1
- package/dist/esm/shared/page-configs/getExportPath.js +9 -10
- 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/serialize/PageConfigSerialized.d.ts +32 -0
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.js +1 -0
- package/dist/esm/shared/page-configs/serialize/assertPageConfigs.d.ts +5 -0
- package/dist/esm/shared/page-configs/serialize/assertPageConfigs.js +16 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.d.ts +4 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +50 -0
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +7 -0
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +62 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.d.ts +8 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +52 -0
- package/dist/esm/shared/page-configs/utils.d.ts +21 -14
- package/dist/esm/shared/page-configs/utils.js +64 -41
- 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 +13 -16
- package/dist/esm/shared/route/resolveRedirects.js +1 -1
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -0
- package/dist/esm/shared/types.d.ts +8 -6
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/utils/getOutDirs.d.ts +0 -2
- package/dist/esm/utils/getOutDirs.js +24 -17
- package/dist/esm/utils/getValuePrintable.js +1 -1
- package/dist/esm/utils/objectAssign.js +3 -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/{resolve.js → requireResolve.js} +2 -2
- package/dist/esm/utils/warnIfErrorIsNotObject.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
- package/dist/cjs/shared/getPageFiles/assertPageConfigs.js +0 -19
- package/dist/cjs/shared/page-configs/loadPageCode.js +0 -63
- package/dist/cjs/utils/assertDefaultExport.js +0 -53
- 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/getPageFiles/assertPageConfigs.d.ts +0 -5
- package/dist/esm/shared/getPageFiles/assertPageConfigs.js +0 -16
- 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/assertDefaultExport.d.ts +0 -8
- package/dist/esm/utils/assertDefaultExport.js +0 -47
- package/dist/esm/utils/resolve.d.ts +0 -2
- /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
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export { assertExportsOfValueFile };
|
|
2
|
+
export { assertExportsOfConfigFile };
|
|
3
|
+
import { assert, assertUsage, assertWarning, isObject } from '../utils.js';
|
|
4
|
+
import pc from '@brillout/picocolors';
|
|
5
|
+
const EXPORTS_IGNORE = [
|
|
6
|
+
// vite-plugin-solid adds `export { $$registrations }`
|
|
7
|
+
'$$registrations',
|
|
8
|
+
// @vitejs/plugin-vue adds `export { _rerender_only }`
|
|
9
|
+
'_rerender_only'
|
|
10
|
+
];
|
|
11
|
+
// Tolerate `export { frontmatter }` in .mdx files
|
|
12
|
+
const TOLERATE_SIDE_EXPORTS = ['.md', '.mdx'];
|
|
13
|
+
function assertExportsOfValueFile(fileExports, filePathToShowToUser, configName) {
|
|
14
|
+
assertExports(fileExports, filePathToShowToUser, configName);
|
|
15
|
+
}
|
|
16
|
+
function assertExportsOfConfigFile(fileExports, filePathToShowToUser) {
|
|
17
|
+
assertExports(fileExports, filePathToShowToUser);
|
|
18
|
+
const exportDefault = fileExports.default;
|
|
19
|
+
assertUsage(isObject(exportDefault), `The ${pc.cyan('export default')} of ${filePathToShowToUser} should be an object (but it's ${pc.cyan(`typeof exportDefault === ${JSON.stringify(typeof exportDefault)}`)} instead)`);
|
|
20
|
+
}
|
|
21
|
+
function assertExports(fileExports, filePathToShowToUser, configName) {
|
|
22
|
+
const exportsAll = Object.keys(fileExports);
|
|
23
|
+
const exportsRelevant = exportsAll.filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
|
|
24
|
+
const exportsInvalid = exportsRelevant.filter((e) => e !== 'default' &&
|
|
25
|
+
// !!configName => isValueFile
|
|
26
|
+
e !== configName);
|
|
27
|
+
if (exportsInvalid.length === 0) {
|
|
28
|
+
if (exportsRelevant.length === 1) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
assert(exportsRelevant.length === 0);
|
|
33
|
+
let errMsg = `${filePathToShowToUser} doesn't export any value, but it should have a ${pc.cyan('export default')}`;
|
|
34
|
+
if (configName)
|
|
35
|
+
errMsg += ` or ${pc.cyan(`export { ${configName} }`)}`;
|
|
36
|
+
assertUsage(false, errMsg);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// !configName => isConfigFile
|
|
41
|
+
if (!configName) {
|
|
42
|
+
const exportsInvalidStr = exportsInvalid.join(', ');
|
|
43
|
+
assertUsage(false, `${filePathToShowToUser} replace ${pc.cyan(`export { ${exportsInvalidStr} }`)} with ${pc.cyan(`export default { ${exportsInvalidStr} }`)}`);
|
|
44
|
+
}
|
|
45
|
+
// !!configName => isValueFile
|
|
46
|
+
else {
|
|
47
|
+
if (TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext)))
|
|
48
|
+
return;
|
|
49
|
+
exportsInvalid.forEach((exportInvalid) => {
|
|
50
|
+
assertWarning(false, `${filePathToShowToUser} should have only a single export: move ${pc.cyan(`export { ${exportInvalid} }`)} to +config.h.js or its own +${exportsInvalid}.js`, { onlyOnce: true });
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { findPageConfig };
|
|
2
|
-
import type {
|
|
3
|
-
declare function findPageConfig(pageConfigs:
|
|
2
|
+
import type { PageConfigRuntime } from './PageConfig.js';
|
|
3
|
+
declare function findPageConfig(pageConfigs: PageConfigRuntime[], pageId: string): null | PageConfigRuntime;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { getExportPath };
|
|
2
|
-
declare function getExportPath(fileExportPath: string[]): null | string;
|
|
2
|
+
declare function getExportPath(fileExportPath: null | string[], configName: string): null | string;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
export { getExportPath };
|
|
2
2
|
import { assert } from '../utils.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let prefix = '';
|
|
7
|
-
let suffix = '';
|
|
3
|
+
function getExportPath(fileExportPath, configName) {
|
|
4
|
+
if (!fileExportPath)
|
|
5
|
+
return null;
|
|
8
6
|
let [exportName, ...exportObjectPath] = fileExportPath;
|
|
9
7
|
if (!exportName)
|
|
10
8
|
return null;
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
if (exportObjectPath.length === 0 && ['*', 'default', configName].includes(exportName))
|
|
10
|
+
return null;
|
|
11
|
+
assert(exportName !== '*');
|
|
12
|
+
let prefix = '';
|
|
13
|
+
let suffix = '';
|
|
14
|
+
if (exportName === 'default') {
|
|
16
15
|
prefix = 'export default';
|
|
17
16
|
}
|
|
18
17
|
else {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { loadConfigValues };
|
|
2
|
+
import { objectAssign } from '../utils.js';
|
|
3
|
+
import { parseConfigValuesImported } from './serialize/parseConfigValuesImported.js';
|
|
4
|
+
async function loadConfigValues(pageConfig, isDev) {
|
|
5
|
+
if ('isLoaded' in pageConfig &&
|
|
6
|
+
// We don't need to cache in dev, since Vite already caches the virtual module
|
|
7
|
+
!isDev) {
|
|
8
|
+
return pageConfig;
|
|
9
|
+
}
|
|
10
|
+
const configValuesImported = await pageConfig.loadConfigValuesAll();
|
|
11
|
+
const configValuesAddendum = parseConfigValuesImported(configValuesImported);
|
|
12
|
+
Object.assign(pageConfig.configValues, configValuesAddendum);
|
|
13
|
+
objectAssign(pageConfig, { isLoaded: true });
|
|
14
|
+
return pageConfig;
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type { PageConfigRuntimeSerialized };
|
|
2
|
+
export type { PageConfigGlobalRuntimeSerialized };
|
|
3
|
+
export type { ConfigValueSerialized };
|
|
4
|
+
export type { ConfigValueImported };
|
|
5
|
+
import type { DefinedAt, PageConfigRuntime } from '../PageConfig.js';
|
|
6
|
+
/** page config data structure serialized in virtual files: parsing it results in PageConfigRuntime */
|
|
7
|
+
type PageConfigRuntimeSerialized = Omit<PageConfigRuntime, 'configValues'> & {
|
|
8
|
+
/** Config values that are loaded eagerly and serializable such as config.passToClient */
|
|
9
|
+
configValuesSerialized: Record<string, ConfigValueSerialized>;
|
|
10
|
+
/** Config values imported eagerly such as config.route */
|
|
11
|
+
configValuesImported: ConfigValueImported[];
|
|
12
|
+
};
|
|
13
|
+
type PageConfigGlobalRuntimeSerialized = {
|
|
14
|
+
configValuesImported: ConfigValueImported[];
|
|
15
|
+
};
|
|
16
|
+
/** Value is serialized. */
|
|
17
|
+
type ConfigValueSerialized = {
|
|
18
|
+
valueSerialized: string;
|
|
19
|
+
definedAt: DefinedAt;
|
|
20
|
+
};
|
|
21
|
+
/** Value is imported. */
|
|
22
|
+
type ConfigValueImported = {
|
|
23
|
+
configName: string;
|
|
24
|
+
importPath: string;
|
|
25
|
+
} & ({
|
|
26
|
+
isValueFile: true;
|
|
27
|
+
exportValues: Record<string, unknown>;
|
|
28
|
+
} | {
|
|
29
|
+
isValueFile: false;
|
|
30
|
+
exportName: string;
|
|
31
|
+
exportValue: unknown;
|
|
32
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { assertPageConfigsSerialized };
|
|
2
|
+
export { assertPageConfigGlobalSerialized };
|
|
3
|
+
import type { PageConfigGlobalRuntimeSerialized, PageConfigRuntimeSerialized } from './PageConfigSerialized.js';
|
|
4
|
+
declare function assertPageConfigsSerialized(pageConfigsSerialized: unknown): asserts pageConfigsSerialized is PageConfigRuntimeSerialized[];
|
|
5
|
+
declare function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized: unknown): asserts pageConfigGlobalSerialized is PageConfigGlobalRuntimeSerialized;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { assertPageConfigsSerialized };
|
|
2
|
+
export { assertPageConfigGlobalSerialized };
|
|
3
|
+
import { assert, isObject, hasProp } from '../../utils.js';
|
|
4
|
+
function assertPageConfigsSerialized(pageConfigsSerialized) {
|
|
5
|
+
assert(Array.isArray(pageConfigsSerialized));
|
|
6
|
+
pageConfigsSerialized.forEach((pageConfigSerialized) => {
|
|
7
|
+
assert(isObject(pageConfigSerialized));
|
|
8
|
+
assert(hasProp(pageConfigSerialized, 'pageId', 'string'));
|
|
9
|
+
assert(hasProp(pageConfigSerialized, 'routeFilesystem'));
|
|
10
|
+
assert(hasProp(pageConfigSerialized, 'configValuesSerialized'));
|
|
11
|
+
assert(hasProp(pageConfigSerialized, 'configValuesImported'));
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized) {
|
|
15
|
+
assert(hasProp(pageConfigGlobalSerialized, 'configValuesImported'));
|
|
16
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export { parseConfigValuesImported };
|
|
2
|
+
import { assert, assertUsage } from '../../utils.js';
|
|
3
|
+
import { assertExportsOfValueFile } from '../assertExports.js';
|
|
4
|
+
import pc from '@brillout/picocolors';
|
|
5
|
+
function parseConfigValuesImported(configValuesImported) {
|
|
6
|
+
const configValues = {};
|
|
7
|
+
const addConfigValue = (configName, value, importPath, exportName) => {
|
|
8
|
+
configValues[configName] = {
|
|
9
|
+
value,
|
|
10
|
+
definedAt: {
|
|
11
|
+
file: {
|
|
12
|
+
// importPath cannot be relative to the current file, since the current file is a virtual file
|
|
13
|
+
filePathToShowToUser: importPath,
|
|
14
|
+
fileExportPath: [configName, 'default'].includes(exportName)
|
|
15
|
+
? []
|
|
16
|
+
: // Side-effect config
|
|
17
|
+
[exportName]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
assertIsNotNull(value, configName, importPath);
|
|
22
|
+
};
|
|
23
|
+
configValuesImported.forEach((configValueLoaded) => {
|
|
24
|
+
if (configValueLoaded.isValueFile) {
|
|
25
|
+
const { exportValues, importPath, configName } = configValueLoaded;
|
|
26
|
+
if (configName !== 'client') {
|
|
27
|
+
assertExportsOfValueFile(exportValues, importPath, configName);
|
|
28
|
+
}
|
|
29
|
+
Object.entries(exportValues).forEach(([exportName, exportValue]) => {
|
|
30
|
+
const isSideExport = exportName !== 'default'; // .md files may have "side-exports" such as `export { frontmatter }`
|
|
31
|
+
const configName = isSideExport ? exportName : configValueLoaded.configName;
|
|
32
|
+
if (isSideExport && configName in configValues) {
|
|
33
|
+
// We can't avoid side-export conflicts upstream. (Because we cannot know about side-exports upstream at build-time.)
|
|
34
|
+
// Side-exports have the lowest priority.
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
addConfigValue(configName, exportValue, importPath, exportName);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const { configName, importPath, exportValue, exportName } = configValueLoaded;
|
|
42
|
+
addConfigValue(configName, exportValue, importPath, exportName);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return configValues;
|
|
46
|
+
}
|
|
47
|
+
function assertIsNotNull(configValue, configName, importPath) {
|
|
48
|
+
assert(!importPath.includes('+config.'));
|
|
49
|
+
assertUsage(configValue !== null, `Set ${pc.cyan(configName)} to ${pc.cyan('null')} in a +config.h.js file instead of ${importPath}`);
|
|
50
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { parsePageConfigs };
|
|
2
|
+
import type { PageConfigRuntime, PageConfigGlobalRuntime } from '../PageConfig.js';
|
|
3
|
+
import type { PageConfigGlobalRuntimeSerialized, PageConfigRuntimeSerialized } from './PageConfigSerialized.js';
|
|
4
|
+
declare function parsePageConfigs(pageConfigsSerialized: PageConfigRuntimeSerialized[], pageConfigGlobalSerialized: PageConfigGlobalRuntimeSerialized): {
|
|
5
|
+
pageConfigs: PageConfigRuntime[];
|
|
6
|
+
pageConfigGlobal: PageConfigGlobalRuntime;
|
|
7
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export { parsePageConfigs };
|
|
2
|
+
import { parse } from '@brillout/json-serializer/parse';
|
|
3
|
+
import { parseConfigValuesImported } from './parseConfigValuesImported.js';
|
|
4
|
+
import { assert, assertUsage, isCallable } from '../../utils.js';
|
|
5
|
+
import { getConfigDefinedAtString } from '../utils.js';
|
|
6
|
+
function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
7
|
+
const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
|
|
8
|
+
const configValues = {};
|
|
9
|
+
{
|
|
10
|
+
const { configValuesSerialized } = pageConfigSerialized;
|
|
11
|
+
Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
|
|
12
|
+
{
|
|
13
|
+
const { valueSerialized, definedAt } = configValueSeriliazed;
|
|
14
|
+
assert(valueSerialized);
|
|
15
|
+
assert(!configValues[configName]);
|
|
16
|
+
configValues[configName] = {
|
|
17
|
+
value: parse(valueSerialized),
|
|
18
|
+
definedAt
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
{
|
|
24
|
+
const { configValuesImported } = pageConfigSerialized;
|
|
25
|
+
const configValuesAddendum = parseConfigValuesImported(configValuesImported);
|
|
26
|
+
Object.assign(configValues, configValuesAddendum);
|
|
27
|
+
}
|
|
28
|
+
const { pageId, isErrorPage, routeFilesystem, loadConfigValuesAll } = pageConfigSerialized;
|
|
29
|
+
assertRouteConfigValue(configValues);
|
|
30
|
+
return {
|
|
31
|
+
pageId,
|
|
32
|
+
isErrorPage,
|
|
33
|
+
routeFilesystem,
|
|
34
|
+
configValues,
|
|
35
|
+
loadConfigValuesAll
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
const pageConfigGlobal = { configValues: {} };
|
|
39
|
+
{
|
|
40
|
+
const configValuesAddendum = parseConfigValuesImported(pageConfigGlobalSerialized.configValuesImported);
|
|
41
|
+
Object.assign(pageConfigGlobal.configValues, configValuesAddendum);
|
|
42
|
+
}
|
|
43
|
+
return { pageConfigs, pageConfigGlobal };
|
|
44
|
+
}
|
|
45
|
+
function assertRouteConfigValue(configValues) {
|
|
46
|
+
const configName = 'route';
|
|
47
|
+
const configValue = configValues[configName];
|
|
48
|
+
if (!configValue)
|
|
49
|
+
return;
|
|
50
|
+
const { value } = configValue;
|
|
51
|
+
const configValueType = typeof value;
|
|
52
|
+
const configDefinedAt = getConfigDefinedAtString(configName, configValue, true);
|
|
53
|
+
assertUsage(configValueType === 'string' || isCallable(value), `${configDefinedAt} 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,8 @@
|
|
|
1
|
+
export { serializeConfigValue };
|
|
2
|
+
export { serializeConfigValueImported };
|
|
3
|
+
import { ConfigValueSource } from '../PageConfig.js';
|
|
4
|
+
import { ConfigValueSerialized } from './PageConfigSerialized.js';
|
|
5
|
+
declare function serializeConfigValue(lines: string[], configName: string, configValueSerialized: ConfigValueSerialized): void;
|
|
6
|
+
declare function serializeConfigValueImported(configValueSource: ConfigValueSource, configName: string, whitespace: string, varCounterContainer: {
|
|
7
|
+
varCounter: number;
|
|
8
|
+
}, importStatements: string[]): string[];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export { serializeConfigValue };
|
|
2
|
+
export { serializeConfigValueImported };
|
|
3
|
+
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with:
|
|
4
|
+
// - vike/shared/page-configs/serialize/parsePageConfigs.ts
|
|
5
|
+
// - vike/shared/page-configs/serialize/parseConfigValuesImported.ts
|
|
6
|
+
// Both parsePageConfigs() parseConfigValuesImported() and are loaded on the client-side and server-side
|
|
7
|
+
import { assertIsNotProductionRuntime } from '../../../utils/assertIsNotProductionRuntime.js';
|
|
8
|
+
assertIsNotProductionRuntime();
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { assert, assertPosixPath } from '../../utils.js';
|
|
11
|
+
import { generateEagerImport } from '../../../node/plugin/plugins/importUserCode/generateEagerImport.js';
|
|
12
|
+
function serializeConfigValue(lines, configName, configValueSerialized) {
|
|
13
|
+
let whitespace = ' ';
|
|
14
|
+
lines.push(`${whitespace}['${configName}']: {`);
|
|
15
|
+
whitespace += ' ';
|
|
16
|
+
Object.entries(configValueSerialized).forEach(([key, val]) => {
|
|
17
|
+
const valSerialized = key === 'definedAt' ? JSON.stringify(val) : val;
|
|
18
|
+
lines.push(`${whitespace} ${key}: ${valSerialized},`);
|
|
19
|
+
});
|
|
20
|
+
whitespace = whitespace.slice(2);
|
|
21
|
+
lines.push(`${whitespace}},`);
|
|
22
|
+
}
|
|
23
|
+
function serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements) {
|
|
24
|
+
assert(!configValueSource.valueIsFilePath);
|
|
25
|
+
assert(whitespace.replaceAll(' ', '').length === 0);
|
|
26
|
+
const { valueIsImportedAtRuntime, definedAtInfo } = configValueSource;
|
|
27
|
+
assert(valueIsImportedAtRuntime);
|
|
28
|
+
const { filePathRelativeToUserRootDir, importPathAbsolute, exportName } = definedAtInfo;
|
|
29
|
+
const importPath = filePathRelativeToUserRootDir ?? importPathAbsolute;
|
|
30
|
+
assertPosixPath(importPath);
|
|
31
|
+
const fileName = path.posix.basename(importPath);
|
|
32
|
+
const isValueFile = fileName.startsWith('+');
|
|
33
|
+
if (isValueFile)
|
|
34
|
+
assert(exportName === undefined);
|
|
35
|
+
const { importName, importStatement } = generateEagerImport(importPath, varCounterContainer.varCounter++, exportName);
|
|
36
|
+
importStatements.push(importStatement);
|
|
37
|
+
const lines = [];
|
|
38
|
+
lines.push(` {`);
|
|
39
|
+
lines.push(` configName: '${configName}',`);
|
|
40
|
+
lines.push(` importPath: '${importPath}',`);
|
|
41
|
+
lines.push(` isValueFile: ${JSON.stringify(isValueFile)},`);
|
|
42
|
+
if (isValueFile) {
|
|
43
|
+
lines.push(` exportValues: ${importName},`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
lines.push(` exportValue: ${importName},`);
|
|
47
|
+
assert(exportName);
|
|
48
|
+
lines.push(` exportName: ${JSON.stringify(exportName)},`);
|
|
49
|
+
}
|
|
50
|
+
lines.push(` },`);
|
|
51
|
+
return lines;
|
|
52
|
+
}
|
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
export { getConfigValue };
|
|
2
2
|
export { getPageConfig };
|
|
3
3
|
export { getConfigDefinedAtString };
|
|
4
|
-
export { getConfigDefinedAtInfo };
|
|
5
4
|
export { getDefinedAtString };
|
|
6
|
-
|
|
5
|
+
export { getConfigValueFilePathToShowToUser };
|
|
6
|
+
export { getHookFilePathToShowToUser };
|
|
7
|
+
import type { PageConfigRuntime, PageConfigBuildTime, ConfigValue, DefinedAt } from './PageConfig.js';
|
|
7
8
|
import type { ConfigNameBuiltIn } from './Config.js';
|
|
9
|
+
type PageConfigCommon = PageConfigRuntime | PageConfigBuildTime;
|
|
8
10
|
type ConfigName = ConfigNameBuiltIn;
|
|
9
|
-
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'string'): null | {
|
|
11
|
+
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'string'): null | ConfigValue & {
|
|
10
12
|
value: string;
|
|
11
13
|
};
|
|
12
|
-
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'boolean'): null | {
|
|
14
|
+
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'boolean'): null | ConfigValue & {
|
|
13
15
|
value: boolean;
|
|
14
16
|
};
|
|
15
|
-
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName): null | {
|
|
17
|
+
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName): null | ConfigValue & {
|
|
16
18
|
value: unknown;
|
|
17
19
|
};
|
|
18
|
-
declare function
|
|
19
|
-
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
definedAtInfo: null | DefinedAtInfo;
|
|
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;
|
|
24
25
|
}, sentenceBegin: true, append?: 'effect'): ConfigDefinedAtUppercase<ConfigName>;
|
|
25
|
-
declare function getConfigDefinedAtString<ConfigName extends string>(configName: ConfigName, {
|
|
26
|
-
|
|
26
|
+
declare function getConfigDefinedAtString<ConfigName extends string>(configName: ConfigName, { definedAt }: {
|
|
27
|
+
definedAt: DefinedAt;
|
|
27
28
|
}, sentenceBegin: false, append?: 'effect'): ConfigDefinedAtLowercase<ConfigName>;
|
|
28
|
-
declare function getDefinedAtString(
|
|
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,8 +1,9 @@
|
|
|
1
1
|
export { getConfigValue };
|
|
2
2
|
export { getPageConfig };
|
|
3
3
|
export { getConfigDefinedAtString };
|
|
4
|
-
export { getConfigDefinedAtInfo };
|
|
5
4
|
export { getDefinedAtString };
|
|
5
|
+
export { getConfigValueFilePathToShowToUser };
|
|
6
|
+
export { getHookFilePathToShowToUser };
|
|
6
7
|
import { assert, assertUsage, getValuePrintable } from '../utils.js';
|
|
7
8
|
import pc from '@brillout/picocolors';
|
|
8
9
|
import { getExportPath } from './getExportPath.js';
|
|
@@ -11,31 +12,29 @@ function getConfigValue(pageConfig, configName, type) {
|
|
|
11
12
|
const configValue = getConfigValueEntry(pageConfig, configName);
|
|
12
13
|
if (configValue === null)
|
|
13
14
|
return null;
|
|
14
|
-
const { value,
|
|
15
|
+
const { value, definedAt } = configValue;
|
|
15
16
|
if (type)
|
|
16
|
-
assertConfigValueType(value, type, configName,
|
|
17
|
-
return
|
|
17
|
+
assertConfigValueType(value, type, configName, definedAt);
|
|
18
|
+
return configValue;
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return definedAtInfo;
|
|
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
29
|
}
|
|
30
30
|
function getConfigValueEntry(pageConfig, configName) {
|
|
31
31
|
const configValue = pageConfig.configValues[configName];
|
|
32
32
|
if (!configValue)
|
|
33
33
|
return null;
|
|
34
|
-
const { value, definedAtInfo } = configValue;
|
|
35
34
|
// Enable users to suppress global config values by setting the local config value to null
|
|
36
|
-
if (value === null)
|
|
35
|
+
if (configValue.value === null)
|
|
37
36
|
return null;
|
|
38
|
-
return
|
|
37
|
+
return configValue;
|
|
39
38
|
}
|
|
40
39
|
function getPageConfig(pageId, pageConfigs) {
|
|
41
40
|
const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
|
|
@@ -43,32 +42,56 @@ function getPageConfig(pageId, pageConfigs) {
|
|
|
43
42
|
assert(pageConfig);
|
|
44
43
|
return pageConfig;
|
|
45
44
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
const typeActual = typeof value;
|
|
49
|
-
if (typeActual === type)
|
|
50
|
-
return;
|
|
51
|
-
const valuePrintable = getValuePrintable(value);
|
|
52
|
-
const problem = valuePrintable !== null ? `value ${pc.cyan(valuePrintable)}` : `type ${pc.cyan(typeActual)}`;
|
|
53
|
-
const configDefinedAt = getConfigDefinedAtString(configName, { definedAtInfo }, true);
|
|
54
|
-
assertUsage(false, `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`);
|
|
55
|
-
}
|
|
56
|
-
function getConfigDefinedAtString(configName, { definedAtInfo }, sentenceBegin, append) {
|
|
57
|
-
let configDefinedAt = `${sentenceBegin ? `Config` : `config`} ${pc.cyan(configName)}`;
|
|
58
|
-
if (definedAtInfo !== null) {
|
|
59
|
-
configDefinedAt = `${configDefinedAt} defined at ${getDefinedAtString(definedAtInfo, append)}`;
|
|
60
|
-
}
|
|
45
|
+
function getConfigDefinedAtString(configName, { definedAt }, sentenceBegin) {
|
|
46
|
+
const configDefinedAt = `${sentenceBegin ? `Config` : `config`} ${pc.cyan(configName)} defined ${getSourceString(definedAt, configName)}`;
|
|
61
47
|
return configDefinedAt;
|
|
62
48
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const exportPath = getExportPath(fileExportPath);
|
|
67
|
-
if (exportPath) {
|
|
68
|
-
definedAt = `${definedAt} > ${pc.cyan(exportPath)}`;
|
|
49
|
+
function getSourceString(definedAt, configName) {
|
|
50
|
+
if (definedAt.isComputed) {
|
|
51
|
+
return 'internally';
|
|
69
52
|
}
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
let files;
|
|
54
|
+
if (definedAt.isCumulative) {
|
|
55
|
+
files = definedAt.files;
|
|
72
56
|
}
|
|
73
|
-
|
|
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;
|
|
74
97
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { executeGuardHook };
|
|
2
2
|
import type { PageContextExports, PageFile } from '../getPageFiles.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { PageConfigRuntime } from '../page-configs/PageConfig.js';
|
|
4
4
|
declare function executeGuardHook<T extends PageContextExports & {
|
|
5
5
|
_pageId: string;
|
|
6
6
|
_pageFilesAll: PageFile[];
|
|
7
|
-
_pageConfigs:
|
|
7
|
+
_pageConfigs: PageConfigRuntime[];
|
|
8
8
|
}>(pageContext: T, prepareForUserConsumption: (pageConfig: T) => T | void): Promise<void>;
|
|
@@ -4,12 +4,12 @@ import type { PageFile } from '../getPageFiles.js';
|
|
|
4
4
|
import { PageContextUrlComputedPropsInternal, PageContextUrlSources } from '../addUrlComputedProps.js';
|
|
5
5
|
import { type OnBeforeRouteHook } from './executeOnBeforeRouteHook.js';
|
|
6
6
|
import type { PageRoutes, RouteType } from './loadPageRoutes.js';
|
|
7
|
-
import type {
|
|
7
|
+
import type { PageConfigRuntime, PageConfigGlobalRuntime } from '../page-configs/PageConfig.js';
|
|
8
8
|
type PageContextForRoute = PageContextUrlComputedPropsInternal & {
|
|
9
9
|
_pageFilesAll: PageFile[];
|
|
10
|
-
_pageConfigs:
|
|
10
|
+
_pageConfigs: PageConfigRuntime[];
|
|
11
11
|
_allPageIds: string[];
|
|
12
|
-
_pageConfigGlobal:
|
|
12
|
+
_pageConfigGlobal: PageConfigGlobalRuntime;
|
|
13
13
|
_pageRoutes: PageRoutes;
|
|
14
14
|
_onBeforeRouteHook: OnBeforeRouteHook | null;
|
|
15
15
|
} & PageContextUrlSources;
|
|
@@ -3,7 +3,7 @@ export type { PageRoutes };
|
|
|
3
3
|
export type { RouteType };
|
|
4
4
|
import type { PageFile } from '../getPageFiles.js';
|
|
5
5
|
import type { OnBeforeRouteHook } from './executeOnBeforeRouteHook.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { PageConfigRuntime, PageConfigGlobalRuntime } from '../page-configs/PageConfig.js';
|
|
7
7
|
type PageRoute = {
|
|
8
8
|
pageId: string;
|
|
9
9
|
comesFromV1PageConfig: boolean;
|
|
@@ -23,7 +23,7 @@ type PageRoute = {
|
|
|
23
23
|
});
|
|
24
24
|
type PageRoutes = PageRoute[];
|
|
25
25
|
type RouteType = 'STRING' | 'FUNCTION' | 'FILESYSTEM';
|
|
26
|
-
declare function loadPageRoutes(pageFilesAll: PageFile[], pageConfigs:
|
|
26
|
+
declare function loadPageRoutes(pageFilesAll: PageFile[], pageConfigs: PageConfigRuntime[], pageConfigGlobal: PageConfigGlobalRuntime, allPageIds: string[]): Promise<{
|
|
27
27
|
pageRoutes: PageRoutes;
|
|
28
28
|
onBeforeRouteHook: null | OnBeforeRouteHook;
|
|
29
29
|
}>;
|