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
|
@@ -2,7 +2,7 @@ export { loadConfigValues };
|
|
|
2
2
|
import { objectAssign } from '../utils.js';
|
|
3
3
|
import { parseConfigValuesImported } from './serialize/parseConfigValuesImported.js';
|
|
4
4
|
async function loadConfigValues(pageConfig, isDev) {
|
|
5
|
-
if ('
|
|
5
|
+
if ('isAllLoaded' in pageConfig &&
|
|
6
6
|
// We don't need to cache in dev, since Vite already caches the virtual module
|
|
7
7
|
!isDev) {
|
|
8
8
|
return pageConfig;
|
|
@@ -10,6 +10,6 @@ async function loadConfigValues(pageConfig, isDev) {
|
|
|
10
10
|
const configValuesImported = await pageConfig.loadConfigValuesAll();
|
|
11
11
|
const configValuesAddendum = parseConfigValuesImported(configValuesImported);
|
|
12
12
|
Object.assign(pageConfig.configValues, configValuesAddendum);
|
|
13
|
-
objectAssign(pageConfig, {
|
|
13
|
+
objectAssign(pageConfig, { isAllLoaded: true });
|
|
14
14
|
return pageConfig;
|
|
15
15
|
}
|
|
@@ -3,9 +3,9 @@ export type { PageConfigGlobalRuntimeSerialized };
|
|
|
3
3
|
export type { ConfigValueSerialized };
|
|
4
4
|
export type { ConfigValueImported };
|
|
5
5
|
import type { DefinedAt, PageConfigRuntime } from '../PageConfig.js';
|
|
6
|
-
/**
|
|
6
|
+
/** Page config data structure serialized in virtual files: parsing it results in PageConfigRuntime */
|
|
7
7
|
type PageConfigRuntimeSerialized = Omit<PageConfigRuntime, 'configValues'> & {
|
|
8
|
-
/** Config values that are loaded eagerly
|
|
8
|
+
/** Config values that are serializable and loaded eagerly such as config.passToClient */
|
|
9
9
|
configValuesSerialized: Record<string, ConfigValueSerialized>;
|
|
10
10
|
/** Config values imported eagerly such as config.route */
|
|
11
11
|
configValuesImported: ConfigValueImported[];
|
|
@@ -13,12 +13,12 @@ type PageConfigRuntimeSerialized = Omit<PageConfigRuntime, 'configValues'> & {
|
|
|
13
13
|
type PageConfigGlobalRuntimeSerialized = {
|
|
14
14
|
configValuesImported: ConfigValueImported[];
|
|
15
15
|
};
|
|
16
|
-
/** Value is serialized
|
|
16
|
+
/** Value is serialized */
|
|
17
17
|
type ConfigValueSerialized = {
|
|
18
18
|
valueSerialized: string;
|
|
19
19
|
definedAt: DefinedAt;
|
|
20
20
|
};
|
|
21
|
-
/** Value is imported
|
|
21
|
+
/** Value is imported */
|
|
22
22
|
type ConfigValueImported = {
|
|
23
23
|
configName: string;
|
|
24
24
|
importPath: string;
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
export { parseConfigValuesImported };
|
|
2
|
-
import { assert
|
|
2
|
+
import { assert } from '../../utils.js';
|
|
3
3
|
import { assertExportsOfValueFile } from '../assertExports.js';
|
|
4
|
-
import pc from '@brillout/picocolors';
|
|
5
4
|
function parseConfigValuesImported(configValuesImported) {
|
|
6
5
|
const configValues = {};
|
|
7
6
|
const addConfigValue = (configName, value, importPath, exportName) => {
|
|
8
7
|
configValues[configName] = {
|
|
9
8
|
value,
|
|
10
9
|
definedAt: {
|
|
11
|
-
file
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
[exportName]
|
|
18
|
-
}
|
|
10
|
+
// importPath cannot be relative to the current file, since the current file is a virtual file
|
|
11
|
+
filePathToShowToUser: importPath,
|
|
12
|
+
fileExportPathToShowToUser: [configName, 'default'].includes(exportName)
|
|
13
|
+
? []
|
|
14
|
+
: // Side-effect config
|
|
15
|
+
[exportName]
|
|
19
16
|
}
|
|
20
17
|
};
|
|
21
18
|
assertIsNotNull(value, configName, importPath);
|
|
@@ -46,5 +43,12 @@ function parseConfigValuesImported(configValuesImported) {
|
|
|
46
43
|
}
|
|
47
44
|
function assertIsNotNull(configValue, configName, importPath) {
|
|
48
45
|
assert(!importPath.includes('+config.'));
|
|
49
|
-
|
|
46
|
+
/* Re-use this for:
|
|
47
|
+
* - upcoming config.requestPageContextOnNavigation
|
|
48
|
+
* - for cumulative values in the future: we don't need this for now because, currently, cumulative values are never imported.
|
|
49
|
+
assertUsage(
|
|
50
|
+
configValue !== null,
|
|
51
|
+
`Set ${pc.cyan(configName)} to ${pc.cyan('null')} in a +config.h.js file instead of ${importPath}`
|
|
52
|
+
)
|
|
53
|
+
*/
|
|
50
54
|
}
|
|
@@ -2,7 +2,7 @@ export { parsePageConfigs };
|
|
|
2
2
|
import { parse } from '@brillout/json-serializer/parse';
|
|
3
3
|
import { parseConfigValuesImported } from './parseConfigValuesImported.js';
|
|
4
4
|
import { assert, assertUsage, isCallable } from '../../utils.js';
|
|
5
|
-
import { getConfigDefinedAtString } from '../
|
|
5
|
+
import { getConfigDefinedAtString } from '../helpers.js';
|
|
6
6
|
function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
7
7
|
const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
|
|
8
8
|
const configValues = {};
|
|
@@ -49,7 +49,7 @@ function assertRouteConfigValue(configValues) {
|
|
|
49
49
|
return;
|
|
50
50
|
const { value } = configValue;
|
|
51
51
|
const configValueType = typeof value;
|
|
52
|
-
const configDefinedAt = getConfigDefinedAtString(configName, configValue
|
|
52
|
+
const configDefinedAt = getConfigDefinedAtString('Config', configName, configValue);
|
|
53
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
54
|
/* We don't use assertRouteString() in order to avoid unnecessarily bloating the client-side bundle when using Server Routing:
|
|
55
55
|
* - When using Server Routing, this file is loaded => loading assertRouteString() would bloat the client bundle.
|
|
@@ -23,29 +23,28 @@ function serializeConfigValue(lines, configName, configValueSerialized) {
|
|
|
23
23
|
function serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements) {
|
|
24
24
|
assert(!configValueSource.valueIsFilePath);
|
|
25
25
|
assert(whitespace.replaceAll(' ', '').length === 0);
|
|
26
|
-
const { valueIsImportedAtRuntime,
|
|
26
|
+
const { valueIsImportedAtRuntime, definedAt } = configValueSource;
|
|
27
27
|
assert(valueIsImportedAtRuntime);
|
|
28
|
-
const {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const fileName = path.posix.basename(importPath);
|
|
28
|
+
const { filePathAbsoluteVite, fileExportName } = definedAt;
|
|
29
|
+
assertPosixPath(filePathAbsoluteVite);
|
|
30
|
+
const fileName = path.posix.basename(filePathAbsoluteVite);
|
|
32
31
|
const isValueFile = fileName.startsWith('+');
|
|
33
32
|
if (isValueFile)
|
|
34
|
-
assert(
|
|
35
|
-
const { importName, importStatement } = generateEagerImport(
|
|
33
|
+
assert(fileExportName === undefined);
|
|
34
|
+
const { importName, importStatement } = generateEagerImport(filePathAbsoluteVite, varCounterContainer.varCounter++, fileExportName);
|
|
36
35
|
importStatements.push(importStatement);
|
|
37
36
|
const lines = [];
|
|
38
37
|
lines.push(` {`);
|
|
39
38
|
lines.push(` configName: '${configName}',`);
|
|
40
|
-
lines.push(` importPath: '${
|
|
39
|
+
lines.push(` importPath: '${filePathAbsoluteVite}',`);
|
|
41
40
|
lines.push(` isValueFile: ${JSON.stringify(isValueFile)},`);
|
|
42
41
|
if (isValueFile) {
|
|
43
42
|
lines.push(` exportValues: ${importName},`);
|
|
44
43
|
}
|
|
45
44
|
else {
|
|
46
45
|
lines.push(` exportValue: ${importName},`);
|
|
47
|
-
assert(
|
|
48
|
-
lines.push(` exportName: ${JSON.stringify(
|
|
46
|
+
assert(fileExportName);
|
|
47
|
+
lines.push(` exportName: ${JSON.stringify(fileExportName)},`);
|
|
49
48
|
}
|
|
50
49
|
lines.push(` },`);
|
|
51
50
|
return lines;
|
|
@@ -41,7 +41,7 @@ function redirect(url, statusCode) {
|
|
|
41
41
|
function render(value, abortReason) {
|
|
42
42
|
const args = [typeof value === 'number' ? String(value) : JSON.stringify(value)];
|
|
43
43
|
if (abortReason !== undefined)
|
|
44
|
-
args.push(truncateString(JSON.stringify(abortReason), 30
|
|
44
|
+
args.push(truncateString(JSON.stringify(abortReason), 30));
|
|
45
45
|
const abortCaller = 'throw render()';
|
|
46
46
|
const abortCall = `throw render(${args.join(', ')})`;
|
|
47
47
|
return render_(value, abortReason, abortCall, abortCaller);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PageContextForRoute, PageContextFromRoute } from './index.js';
|
|
1
2
|
export { executeOnBeforeRouteHook };
|
|
2
3
|
export type { OnBeforeRouteHook };
|
|
3
4
|
type OnBeforeRouteHook = {
|
|
@@ -6,12 +7,8 @@ type OnBeforeRouteHook = {
|
|
|
6
7
|
urlOriginal: string;
|
|
7
8
|
} & Record<string, unknown>) => unknown;
|
|
8
9
|
};
|
|
9
|
-
declare function executeOnBeforeRouteHook(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
urlOriginal?: string;
|
|
14
|
-
_urlOriginalPristine?: string;
|
|
15
|
-
_pageId?: string | null;
|
|
16
|
-
routeParams?: Record<string, string>;
|
|
10
|
+
declare function executeOnBeforeRouteHook(pageContext: PageContextForRoute): Promise<null | ({
|
|
11
|
+
_routingProvidedByOnBeforeRouteHook: true;
|
|
12
|
+
} & PageContextFromRoute) | {
|
|
13
|
+
_routingProvidedByOnBeforeRouteHook: false;
|
|
17
14
|
}>;
|
|
@@ -1,11 +1,40 @@
|
|
|
1
1
|
import { assertPageContextProvidedByUser } from '../assertPageContextProvidedByUser.js';
|
|
2
|
-
import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrl, joinEnglish } from './utils.js';
|
|
2
|
+
import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrl, joinEnglish, assert } from './utils.js';
|
|
3
3
|
import { assertRouteParams, assertSyncRouting } from './resolveRouteFunction.js';
|
|
4
4
|
import pc from '@brillout/picocolors';
|
|
5
5
|
export { executeOnBeforeRouteHook };
|
|
6
|
-
async function executeOnBeforeRouteHook(
|
|
6
|
+
async function executeOnBeforeRouteHook(pageContext) {
|
|
7
|
+
const pageContextFromOnBeforeRouteHook = {};
|
|
8
|
+
if (!pageContext._onBeforeRouteHook)
|
|
9
|
+
return null;
|
|
10
|
+
const pageContextFromHook = await executeHook(pageContext._onBeforeRouteHook, pageContext);
|
|
11
|
+
if (pageContextFromHook) {
|
|
12
|
+
objectAssign(pageContextFromOnBeforeRouteHook, pageContextFromHook);
|
|
13
|
+
if (hasProp(pageContextFromOnBeforeRouteHook, '_pageId', 'string') ||
|
|
14
|
+
hasProp(pageContextFromOnBeforeRouteHook, '_pageId', 'null')) {
|
|
15
|
+
// We bypass Vike's routing
|
|
16
|
+
if (!hasProp(pageContextFromOnBeforeRouteHook, 'routeParams')) {
|
|
17
|
+
objectAssign(pageContextFromOnBeforeRouteHook, { routeParams: {} });
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
assert(hasProp(pageContextFromOnBeforeRouteHook, 'routeParams', 'object'));
|
|
21
|
+
}
|
|
22
|
+
objectAssign(pageContextFromOnBeforeRouteHook, {
|
|
23
|
+
_routingProvidedByOnBeforeRouteHook: true,
|
|
24
|
+
_debugRouteMatches: 'CUSTOM_ROUTING'
|
|
25
|
+
});
|
|
26
|
+
return pageContextFromOnBeforeRouteHook;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
objectAssign(pageContextFromOnBeforeRouteHook, {
|
|
30
|
+
_routingProvidedByOnBeforeRouteHook: false
|
|
31
|
+
});
|
|
32
|
+
return pageContextFromOnBeforeRouteHook;
|
|
33
|
+
}
|
|
34
|
+
async function executeHook(onBeforeRouteHook, pageContext) {
|
|
7
35
|
let hookReturn = onBeforeRouteHook.onBeforeRoute(pageContext);
|
|
8
36
|
assertSyncRouting(hookReturn, `The onBeforeRoute() hook ${onBeforeRouteHook.hookFilePath}`);
|
|
37
|
+
// TODO/v1-release: make executeOnBeforeRouteHook() and route() sync
|
|
9
38
|
hookReturn = await hookReturn;
|
|
10
39
|
const errPrefix = `The onBeforeRoute() hook defined by ${onBeforeRouteHook.hookFilePath}`;
|
|
11
40
|
assertUsage(hookReturn === null ||
|
|
@@ -23,28 +52,25 @@ async function executeOnBeforeRouteHook(onBeforeRouteHook, pageContext) {
|
|
|
23
52
|
if (hasProp(hookReturn.pageContext, 'routeParams')) {
|
|
24
53
|
assertRouteParams(hookReturn.pageContext, `${errPrefix} returned ${pc.cyan('{ pageContext: { routeParams } }')} but routeParams should`);
|
|
25
54
|
}
|
|
26
|
-
const
|
|
55
|
+
const deprecatedReturn = (prop) => `${errPrefix} returned ${pc.cyan(`{ pageContext: { ${prop} } }`)} which is deprecated. Return ${pc.cyan('{ pageContext: { urlLogical } }')} instead.`;
|
|
27
56
|
if (hasProp(hookReturn.pageContext, 'url')) {
|
|
28
|
-
assertWarning(false,
|
|
29
|
-
hookReturn.pageContext.
|
|
57
|
+
assertWarning(false, deprecatedReturn('url'), { onlyOnce: true });
|
|
58
|
+
hookReturn.pageContext.urlLogical = hookReturn.pageContext.url;
|
|
30
59
|
delete hookReturn.pageContext.url;
|
|
31
60
|
}
|
|
32
61
|
if (hasProp(hookReturn.pageContext, 'urlOriginal')) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// pageContext.urlReal / pageContext.urlModified
|
|
40
|
-
// VS
|
|
41
|
-
// pageContext.urlOriginal / pageContext.urlModified
|
|
42
|
-
objectAssign(pageContextAddendumHook, { _urlOriginalPristine: pageContext.urlOriginal });
|
|
62
|
+
assertWarning(false, deprecatedReturn('urlOriginal'), { onlyOnce: true });
|
|
63
|
+
hookReturn.pageContext.urlLogical = hookReturn.pageContext.urlOriginal;
|
|
64
|
+
delete hookReturn.pageContext.urlOriginal;
|
|
65
|
+
}
|
|
66
|
+
if (hasProp(hookReturn.pageContext, 'urlLogical')) {
|
|
67
|
+
assertUsageUrl(hookReturn.pageContext.urlLogical, `${errPrefix} returned ${pc.cyan('{ pageContext: { urlLogical } }')} but ${pc.cyan('urlLogical')}`);
|
|
43
68
|
}
|
|
44
69
|
assertPageContextProvidedByUser(hookReturn.pageContext, {
|
|
45
70
|
hookFilePath: onBeforeRouteHook.hookFilePath,
|
|
46
71
|
hookName: 'onBeforeRoute'
|
|
47
72
|
});
|
|
73
|
+
const pageContextAddendumHook = {};
|
|
48
74
|
objectAssign(pageContextAddendumHook, hookReturn.pageContext);
|
|
49
75
|
return pageContextAddendumHook;
|
|
50
76
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { route };
|
|
2
|
-
export type {
|
|
2
|
+
export type { PageContextForRoute };
|
|
3
|
+
export type { PageContextFromRoute };
|
|
4
|
+
export type { PageRoutes };
|
|
5
|
+
export type { RouteMatches };
|
|
3
6
|
import type { PageFile } from '../getPageFiles.js';
|
|
4
7
|
import { PageContextUrlComputedPropsInternal, PageContextUrlSources } from '../addUrlComputedProps.js';
|
|
5
8
|
import { type OnBeforeRouteHook } from './executeOnBeforeRouteHook.js';
|
|
@@ -13,6 +16,12 @@ type PageContextForRoute = PageContextUrlComputedPropsInternal & {
|
|
|
13
16
|
_pageRoutes: PageRoutes;
|
|
14
17
|
_onBeforeRouteHook: OnBeforeRouteHook | null;
|
|
15
18
|
} & PageContextUrlSources;
|
|
19
|
+
type PageContextFromRoute = {
|
|
20
|
+
_pageId: string | null;
|
|
21
|
+
routeParams: Record<string, string>;
|
|
22
|
+
_routingProvidedByOnBeforeRouteHook?: boolean;
|
|
23
|
+
_debugRouteMatches: RouteMatches;
|
|
24
|
+
};
|
|
16
25
|
type RouteMatch = {
|
|
17
26
|
pageId: string;
|
|
18
27
|
routeString?: string;
|
|
@@ -20,12 +29,5 @@ type RouteMatch = {
|
|
|
20
29
|
routeType: RouteType;
|
|
21
30
|
routeParams: Record<string, string>;
|
|
22
31
|
};
|
|
23
|
-
type RouteMatches = '
|
|
24
|
-
declare function route(
|
|
25
|
-
pageContextAddendum: {
|
|
26
|
-
_pageId: string | null;
|
|
27
|
-
routeParams: Record<string, string>;
|
|
28
|
-
_routingProvidedByOnBeforeRouteHook: boolean;
|
|
29
|
-
_routeMatches: RouteMatches;
|
|
30
|
-
} & Record<string, unknown>;
|
|
31
|
-
}>;
|
|
32
|
+
type RouteMatches = 'CUSTOM_ROUTING' | RouteMatch[];
|
|
33
|
+
declare function route(pageContextForRoute: PageContextForRoute): Promise<PageContextFromRoute>;
|
|
@@ -5,7 +5,7 @@ import { isBrowser } from '../../utils/isBrowser.js';
|
|
|
5
5
|
if (isBrowser()) {
|
|
6
6
|
assertClientRouting();
|
|
7
7
|
}
|
|
8
|
-
import { assert, assertUsage,
|
|
8
|
+
import { assert, assertUsage, isPlainObject, objectAssign } from './utils.js';
|
|
9
9
|
import { addUrlComputedProps } from '../addUrlComputedProps.js';
|
|
10
10
|
import { resolvePrecendence } from './resolvePrecedence.js';
|
|
11
11
|
import { resolveRouteString } from './resolveRouteString.js';
|
|
@@ -13,35 +13,25 @@ import { resolveRouteFunction } from './resolveRouteFunction.js';
|
|
|
13
13
|
import { executeOnBeforeRouteHook } from './executeOnBeforeRouteHook.js';
|
|
14
14
|
import { debug } from './debug.js';
|
|
15
15
|
import pc from '@brillout/picocolors';
|
|
16
|
-
async function route(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
else {
|
|
30
|
-
assert(hasProp(pageContextAddendum, 'routeParams', 'object'));
|
|
31
|
-
}
|
|
32
|
-
objectAssign(pageContextAddendum, {
|
|
33
|
-
_routingProvidedByOnBeforeRouteHook: true,
|
|
34
|
-
_routeMatches: 'CUSTOM_ROUTE'
|
|
35
|
-
});
|
|
36
|
-
return { pageContextAddendum };
|
|
37
|
-
}
|
|
38
|
-
// We already assign so that `pageContext.urlOriginal === pageContextAddendum.urlOriginal`; enabling the `onBeforeRoute()` hook to mutate `pageContext.urlOriginal` before routing.
|
|
39
|
-
objectAssign(pageContext, pageContextAddendum);
|
|
16
|
+
async function route(pageContextForRoute) {
|
|
17
|
+
debug('Pages routes:', pageContextForRoute._pageRoutes);
|
|
18
|
+
addUrlComputedProps(pageContextForRoute);
|
|
19
|
+
const pageContextFromRoute = {};
|
|
20
|
+
// onBeforeRoute()
|
|
21
|
+
const pageContextFromOnBeforeRouteHook = await executeOnBeforeRouteHook(pageContextForRoute);
|
|
22
|
+
if (pageContextFromOnBeforeRouteHook) {
|
|
23
|
+
if (pageContextFromOnBeforeRouteHook._routingProvidedByOnBeforeRouteHook) {
|
|
24
|
+
assert(pageContextFromOnBeforeRouteHook._pageId);
|
|
25
|
+
return pageContextFromOnBeforeRouteHook;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
objectAssign(pageContextFromRoute, pageContextFromOnBeforeRouteHook);
|
|
40
29
|
}
|
|
41
30
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
// We take into account pageContext.urlLogical set by onBeforeRoute()
|
|
32
|
+
const pageContext = {};
|
|
33
|
+
objectAssign(pageContext, pageContextForRoute);
|
|
34
|
+
objectAssign(pageContext, pageContextFromOnBeforeRouteHook);
|
|
45
35
|
// Vike's routing
|
|
46
36
|
const allPageIds = pageContext._allPageIds;
|
|
47
37
|
assert(allPageIds.length >= 0);
|
|
@@ -93,21 +83,21 @@ async function route(pageContext) {
|
|
|
93
83
|
resolvePrecendence(routeMatches);
|
|
94
84
|
const winner = routeMatches[0];
|
|
95
85
|
debug(`Route matches for URL ${pc.cyan(urlPathname)} (in precedence order):`, routeMatches);
|
|
96
|
-
objectAssign(
|
|
86
|
+
objectAssign(pageContextFromRoute, { _debugRouteMatches: routeMatches });
|
|
97
87
|
if (!winner) {
|
|
98
|
-
objectAssign(
|
|
88
|
+
objectAssign(pageContextFromRoute, {
|
|
99
89
|
_pageId: null,
|
|
100
90
|
routeParams: {}
|
|
101
91
|
});
|
|
102
|
-
return
|
|
92
|
+
return pageContextFromRoute;
|
|
103
93
|
}
|
|
104
94
|
{
|
|
105
95
|
const { routeParams } = winner;
|
|
106
96
|
assert(isPlainObject(routeParams));
|
|
107
|
-
objectAssign(
|
|
97
|
+
objectAssign(pageContextFromRoute, {
|
|
108
98
|
_pageId: winner.pageId,
|
|
109
99
|
routeParams: winner.routeParams
|
|
110
100
|
});
|
|
111
101
|
}
|
|
112
|
-
return
|
|
102
|
+
return pageContextFromRoute;
|
|
113
103
|
}
|
|
@@ -3,10 +3,10 @@ import { isErrorPageId } from '../error-page.js';
|
|
|
3
3
|
import { assert, assertUsage, hasProp, slice } from './utils.js';
|
|
4
4
|
import { deduceRouteStringFromFilesystemPath } from './deduceRouteStringFromFilesystemPath.js';
|
|
5
5
|
import { isCallable } from '../utils.js';
|
|
6
|
-
import { getConfigValue, getDefinedAtString, getHookFilePathToShowToUser } from '../page-configs/
|
|
6
|
+
import { getConfigDefinedAtString, getConfigValue, getDefinedAtString, getHookFilePathToShowToUser } from '../page-configs/helpers.js';
|
|
7
7
|
import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
|
|
8
8
|
async function loadPageRoutes(
|
|
9
|
-
//
|
|
9
|
+
// Remove all arguments and use GlobalContext instead?
|
|
10
10
|
pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
|
|
11
11
|
await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
|
|
12
12
|
const { onBeforeRouteHook, filesystemRoots } = getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal);
|
|
@@ -31,7 +31,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
31
31
|
const configValue = getConfigValue(pageConfig, configName);
|
|
32
32
|
if (configValue) {
|
|
33
33
|
const route = configValue.value;
|
|
34
|
-
const definedAt = getDefinedAtString(configValue, configName);
|
|
34
|
+
const definedAt = getDefinedAtString(configValue.definedAt, configName);
|
|
35
35
|
if (typeof route === 'string') {
|
|
36
36
|
pageRoute = {
|
|
37
37
|
pageId,
|
|
@@ -136,12 +136,13 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
136
136
|
function getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal) {
|
|
137
137
|
// V1 Design
|
|
138
138
|
if (pageConfigs.length > 0) {
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
const hookName = 'onBeforeRoute';
|
|
140
|
+
if (pageConfigGlobal.configValues[hookName]?.value) {
|
|
141
|
+
const configValue = pageConfigGlobal.configValues[hookName];
|
|
141
142
|
const { value: hookFn } = configValue;
|
|
142
143
|
const hookFilePath = getHookFilePathToShowToUser(configValue);
|
|
143
|
-
|
|
144
|
-
assertUsage(isCallable(hookFn),
|
|
144
|
+
const hookDefinedAt = getConfigDefinedAtString('Hook', hookName, configValue);
|
|
145
|
+
assertUsage(isCallable(hookFn), `${hookDefinedAt} should be a function.`);
|
|
145
146
|
const onBeforeRouteHook = {
|
|
146
147
|
hookFilePath: hookFilePath,
|
|
147
148
|
onBeforeRoute: hookFn
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const noRouteMatch = "doesn't match the route of any of your pages";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const noRouteMatch = "doesn't match the route of any of your pages";
|
|
@@ -9,7 +9,7 @@ async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAt)
|
|
|
9
9
|
assertPageContextUrlComputedProps(pageContext);
|
|
10
10
|
let result = routeFunction(pageContext);
|
|
11
11
|
assertSyncRouting(result, `The Route Function ${routeDefinedAt}`);
|
|
12
|
-
// TODO/v1-release
|
|
12
|
+
// TODO/v1-release: make resolveRouteFunction() and route() sync
|
|
13
13
|
//* We disallow asynchronous routing, because we need to check whether a link is a Vike link in a synchronous fashion before calling ev.preventDefault() in the 'click' event listener
|
|
14
14
|
result = await result;
|
|
15
15
|
//*/
|
|
@@ -15,7 +15,7 @@ export * from '../utils/stringifyStringArray.js';
|
|
|
15
15
|
export * from '../utils/filesystemPathHandling.js';
|
|
16
16
|
export * from '../utils/cast.js';
|
|
17
17
|
export * from '../utils/projectInfo.js';
|
|
18
|
-
export * from '../utils/
|
|
18
|
+
export * from '../utils/isPropertyGetter.js';
|
|
19
19
|
export * from '../utils/isPromise.js';
|
|
20
20
|
export * from '../utils/checkType.js';
|
|
21
21
|
export * from '../utils/objectEntries.js';
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -19,7 +19,7 @@ export * from '../utils/stringifyStringArray.js';
|
|
|
19
19
|
export * from '../utils/filesystemPathHandling.js';
|
|
20
20
|
export * from '../utils/cast.js';
|
|
21
21
|
export * from '../utils/projectInfo.js';
|
|
22
|
-
export * from '../utils/
|
|
22
|
+
export * from '../utils/isPropertyGetter.js';
|
|
23
23
|
export * from '../utils/isPromise.js';
|
|
24
24
|
export * from '../utils/checkType.js';
|
|
25
25
|
export * from '../utils/objectEntries.js';
|
|
@@ -2,4 +2,4 @@ export { getFilePathAbsolute };
|
|
|
2
2
|
export { getFilePathRelativeToUserRootDir };
|
|
3
3
|
import type { ResolvedConfig } from 'vite';
|
|
4
4
|
declare function getFilePathAbsolute(filePath: string, config: ResolvedConfig): string;
|
|
5
|
-
declare function getFilePathRelativeToUserRootDir(
|
|
5
|
+
declare function getFilePathRelativeToUserRootDir(filePathAbsoluteFilesystem: string, userRootDir: string, alwaysRelative?: boolean): string;
|
|
@@ -30,26 +30,26 @@ function getFilePathAbsolute(filePath, config) {
|
|
|
30
30
|
filePathUnresolved = path.posix.join(root, filePath);
|
|
31
31
|
assertPathIsFilesystemAbsolute(filePathUnresolved);
|
|
32
32
|
}
|
|
33
|
-
let
|
|
33
|
+
let filePathAbsoluteFilesystem;
|
|
34
34
|
try {
|
|
35
|
-
|
|
35
|
+
filePathAbsoluteFilesystem = require_.resolve(filePathUnresolved, { paths: [config.root] });
|
|
36
36
|
}
|
|
37
37
|
catch (err) {
|
|
38
38
|
console.error(err);
|
|
39
39
|
assert(false);
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
assertPathIsFilesystemAbsolute(
|
|
43
|
-
return
|
|
41
|
+
filePathAbsoluteFilesystem = toPosixPath(filePathAbsoluteFilesystem);
|
|
42
|
+
assertPathIsFilesystemAbsolute(filePathAbsoluteFilesystem);
|
|
43
|
+
return filePathAbsoluteFilesystem;
|
|
44
44
|
}
|
|
45
|
-
function getFilePathRelativeToUserRootDir(
|
|
46
|
-
assertPosixPath(
|
|
45
|
+
function getFilePathRelativeToUserRootDir(filePathAbsoluteFilesystem, userRootDir, alwaysRelative = false) {
|
|
46
|
+
assertPosixPath(filePathAbsoluteFilesystem);
|
|
47
47
|
assertPosixPath(userRootDir);
|
|
48
|
-
let filePathRelativeToUserRootDir = path.posix.relative(userRootDir,
|
|
49
|
-
if (
|
|
48
|
+
let filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem);
|
|
49
|
+
if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
50
50
|
assert(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'),
|
|
51
51
|
// Surprinsingly, this assertion seem to fail sometimes: https://github.com/vikejs/vike/issues/1139
|
|
52
|
-
{ filePathRelativeToUserRootDir,
|
|
52
|
+
{ filePathRelativeToUserRootDir, filePathAbsoluteFilesystem, userRootDir });
|
|
53
53
|
filePathRelativeToUserRootDir = `/${filePathRelativeToUserRootDir}`;
|
|
54
54
|
return filePathRelativeToUserRootDir;
|
|
55
55
|
}
|
|
@@ -58,7 +58,7 @@ function getFilePathRelativeToUserRootDir(filePathAbsolute, userRootDir, alwaysR
|
|
|
58
58
|
return filePathRelativeToUserRootDir;
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
61
|
-
return
|
|
61
|
+
return filePathAbsoluteFilesystem;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isPropertyGetter(obj: Object, prop: string): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { onPageHide };
|
|
2
|
+
export { onPageShow };
|
|
3
|
+
function onPageHide(listener) {
|
|
4
|
+
window.addEventListener('visibilitychange', () => {
|
|
5
|
+
if (document.visibilityState === 'hidden') {
|
|
6
|
+
listener();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function onPageShow(listener) {
|
|
11
|
+
window.addEventListener('visibilitychange', () => {
|
|
12
|
+
if (document.visibilityState === 'visible') {
|
|
13
|
+
listener();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -51,7 +51,7 @@ function parseUrl(url, baseServer) {
|
|
|
51
51
|
const searchAll = {};
|
|
52
52
|
Array.from(new URLSearchParams(searchOriginal || '')).forEach(([key, val]) => {
|
|
53
53
|
search[key] = val;
|
|
54
|
-
searchAll[key] = [...(searchAll[key]
|
|
54
|
+
searchAll[key] = [...(searchAll.hasOwnProperty(key) ? searchAll[key] : []), val];
|
|
55
55
|
});
|
|
56
56
|
// Origin + pathname
|
|
57
57
|
const { origin, pathname: pathnameResolved } = parsePathname(urlWithoutHashNorSearch, baseServer);
|
|
@@ -5,7 +5,7 @@ type ProjectVersion = typeof projectInfo.projectVersion;
|
|
|
5
5
|
type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
|
|
6
6
|
declare const projectInfo: {
|
|
7
7
|
projectName: "Vike";
|
|
8
|
-
projectVersion: "0.4.
|
|
8
|
+
projectVersion: "0.4.145-commit-2520555";
|
|
9
9
|
npmPackageName: "vike";
|
|
10
10
|
githubRepository: "https://github.com/vikejs/vike";
|
|
11
11
|
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { truncateString };
|
|
2
|
+
declare function truncateString(str: string, lenMax: number): string;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { truncateString };
|
|
2
|
+
import pc from '@brillout/picocolors';
|
|
3
|
+
import { assert } from './assert.js';
|
|
4
|
+
function truncateString(str, lenMax) {
|
|
5
|
+
const lenMaxReal = lenMax - 3;
|
|
6
|
+
assert(lenMaxReal >= 1); // Show at least one character before the ellipsis
|
|
2
7
|
if (str.length < lenMax) {
|
|
3
8
|
return str;
|
|
4
9
|
}
|
|
5
10
|
else {
|
|
6
|
-
//
|
|
7
|
-
// - So far, the str we pass to truncateString(str)
|
|
8
|
-
str = str.substring(0,
|
|
9
|
-
|
|
10
|
-
if (dim)
|
|
11
|
-
ellipsis = dim(ellipsis);
|
|
11
|
+
// Breaks ANSI codes.
|
|
12
|
+
// - So far, the `str` we pass to truncateString(str) is always expected to not contain any ANSI code
|
|
13
|
+
str = str.substring(0, lenMaxReal);
|
|
14
|
+
const ellipsis = pc.dim('...');
|
|
12
15
|
str = str + ellipsis;
|
|
13
16
|
return str;
|
|
14
17
|
}
|
package/node/cli/bin-entry.js
CHANGED