vike 0.4.144-commit-6aef8a6 → 0.4.144-commit-7f5e99a
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 +2 -2
- package/dist/cjs/node/plugin/plugins/commonConfig.js +0 -3
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +29 -42
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +14 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/cjs/node/plugin/plugins/previewConfig.js +11 -2
- package/dist/cjs/node/prerender/runPrerender.js +16 -17
- 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/renderPageAlreadyRouted.js +2 -2
- package/dist/cjs/node/runtime/renderPage.js +2 -2
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
- 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/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/serialize/parseConfigValuesImported.js +6 -8
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +2 -2
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +11 -13
- package/dist/cjs/shared/route/index.js +3 -3
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -1
- package/dist/cjs/shared/utils.js +1 -1
- package/dist/cjs/utils/{hasPropertyGetter.js → isPropertyGetter.js} +3 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- 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 -3
- package/dist/esm/client/client-routing-runtime/entry.js +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/getPageContext.js +4 -7
- package/dist/esm/client/client-routing-runtime/getPageId.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/getPageId.js +4 -7
- package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/history.js +26 -8
- package/dist/esm/client/client-routing-runtime/installClientRouter.d.ts +21 -0
- package/dist/esm/client/client-routing-runtime/{useClientRouter.js → installClientRouter.js} +248 -242
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.d.ts +8 -0
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +15 -0
- package/dist/esm/client/client-routing-runtime/navigate.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/navigate.js +10 -8
- package/dist/esm/client/client-routing-runtime/prefetch.js +12 -5
- package/dist/esm/client/client-routing-runtime/skipLink.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/skipLink.js +1 -2
- package/dist/esm/client/shared/executeOnRenderClientHook.js +6 -5
- package/dist/esm/client/shared/getPageContextProxyForUser.js +13 -7
- package/dist/esm/node/plugin/plugins/buildConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +0 -3
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +29 -42
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +15 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/esm/node/plugin/plugins/previewConfig.js +11 -2
- package/dist/esm/node/prerender/runPrerender.js +11 -12
- 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/renderPageAlreadyRouted.js +1 -1
- package/dist/esm/node/runtime/renderPage.js +2 -2
- 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/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 +4 -12
- 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/serialize/parseConfigValuesImported.js +6 -8
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +2 -2
- package/dist/esm/shared/route/executeOnBeforeRouteHook.d.ts +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +11 -13
- package/dist/esm/shared/route/index.d.ts +11 -9
- package/dist/esm/shared/route/index.js +3 -3
- package/dist/esm/shared/route/loadPageRoutes.js +7 -6
- 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/isPropertyGetter.d.ts +1 -0
- package/dist/esm/utils/{hasPropertyGetter.js → isPropertyGetter.js} +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/shared/page-configs/utils.js +0 -96
- 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/shared/page-configs/utils.d.ts +0 -35
- package/dist/esm/shared/page-configs/utils.js +0 -90
- package/dist/esm/utils/hasPropertyGetter.d.ts +0 -1
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export { prefetch };
|
|
2
2
|
export { addLinkPrefetchHandlers };
|
|
3
|
-
import { assert, assertClientRouting, assertUsage, checkIfClientRouting } from './utils.js';
|
|
3
|
+
import { assert, assertClientRouting, assertUsage, checkIfClientRouting, objectAssign } from './utils.js';
|
|
4
4
|
import { isErrorFetchingStaticAssets, loadPageFilesClientSide } from '../shared/loadPageFilesClientSide.js';
|
|
5
|
-
import {
|
|
5
|
+
import { skipLink } from './skipLink.js';
|
|
6
6
|
import { getPageId } from './getPageId.js';
|
|
7
7
|
import { getPrefetchSettings } from './prefetch/getPrefetchSettings.js';
|
|
8
8
|
import { isAlreadyPrefetched, markAsAlreadyPrefetched } from './prefetch/alreadyPrefetched.js';
|
|
9
|
-
import { disableClientRouting } from './
|
|
9
|
+
import { disableClientRouting } from './installClientRouter.js';
|
|
10
10
|
import { isExternalLink } from './isExternalLink.js';
|
|
11
|
+
import { isClientSideRoutable } from './isClientSideRoutable.js';
|
|
12
|
+
import { createPageContext } from './createPageContext.js';
|
|
13
|
+
import { route } from '../../shared/route/index.js';
|
|
11
14
|
assertClientRouting();
|
|
12
15
|
const linkPrefetchHandlerAdded = new Map();
|
|
13
16
|
/**
|
|
@@ -79,13 +82,17 @@ function addLinkPrefetchHandlers(pageContext) {
|
|
|
79
82
|
});
|
|
80
83
|
}
|
|
81
84
|
async function prefetchIfClientSideRoutable(url) {
|
|
85
|
+
const pageContext = await createPageContext(url);
|
|
86
|
+
let pageContextFromRoute;
|
|
82
87
|
try {
|
|
83
|
-
|
|
84
|
-
return;
|
|
88
|
+
pageContextFromRoute = await route(pageContext);
|
|
85
89
|
}
|
|
86
90
|
catch {
|
|
87
91
|
// If a route() hook has a bug or `throw render()` / `throw redirect()`
|
|
88
92
|
return;
|
|
89
93
|
}
|
|
94
|
+
objectAssign(pageContext, pageContextFromRoute);
|
|
95
|
+
if (!(await isClientSideRoutable(pageContext)))
|
|
96
|
+
return;
|
|
90
97
|
await prefetch(url);
|
|
91
98
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { skipLink };
|
|
2
|
-
export { isClientSideRoutable } from './skipLink/isClientSideRoutable.js';
|
|
3
2
|
import { getBaseServer } from './getBaseServer.js';
|
|
4
3
|
import { isExternalLink } from './isExternalLink.js';
|
|
5
4
|
import { assert, parseUrl, isBaseServer, isParsable } from './utils.js';
|
|
6
|
-
import { isDisableAutomaticLinkInterception } from './
|
|
5
|
+
import { isDisableAutomaticLinkInterception } from './installClientRouter.js';
|
|
7
6
|
function skipLink(linkTag) {
|
|
8
7
|
const url = linkTag.getAttribute('href');
|
|
9
8
|
if (url === null)
|
|
@@ -19,10 +19,11 @@ async function executeOnRenderClientHook(pageContext, isClientRouting) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
if (!hook) {
|
|
22
|
-
const
|
|
22
|
+
const urlToShowToUser = getUrlToShowToUser(pageContext);
|
|
23
|
+
assert(urlToShowToUser);
|
|
23
24
|
if (pageContext._pageConfigs.length > 0) {
|
|
24
25
|
// V1 design
|
|
25
|
-
assertUsage(false, `No onRenderClient() hook defined for URL '${
|
|
26
|
+
assertUsage(false, `No onRenderClient() hook defined for URL '${urlToShowToUser}', but it's needed, see https://vike.dev/onRenderClient`);
|
|
26
27
|
}
|
|
27
28
|
else {
|
|
28
29
|
// TODO/v1-release: remove
|
|
@@ -30,11 +31,11 @@ async function executeOnRenderClientHook(pageContext, isClientRouting) {
|
|
|
30
31
|
const pageClientsFilesLoaded = pageContext._pageFilesLoaded.filter((p) => p.fileType === '.page.client');
|
|
31
32
|
let errMsg;
|
|
32
33
|
if (pageClientsFilesLoaded.length === 0) {
|
|
33
|
-
errMsg = 'No file `*.page.client.*` found for URL ' +
|
|
34
|
+
errMsg = 'No file `*.page.client.*` found for URL ' + urlToShowToUser;
|
|
34
35
|
}
|
|
35
36
|
else {
|
|
36
37
|
errMsg =
|
|
37
|
-
'One of the following files should export a
|
|
38
|
+
'One of the following files should export a render() hook: ' +
|
|
38
39
|
pageClientsFilesLoaded.map((p) => p.filePath).join(' ');
|
|
39
40
|
}
|
|
40
41
|
assertUsage(false, errMsg);
|
|
@@ -47,7 +48,7 @@ async function executeOnRenderClientHook(pageContext, isClientRouting) {
|
|
|
47
48
|
const hookResult = await executeHook(() => renderHook(pageContextForUserConsumption), hookName, hook.hookFilePath);
|
|
48
49
|
assertUsage(hookResult === undefined, `The ${hookName}() hook defined by ${hook.hookFilePath} isn't allowed to return a value`);
|
|
49
50
|
}
|
|
50
|
-
function
|
|
51
|
+
function getUrlToShowToUser(pageContext) {
|
|
51
52
|
let url;
|
|
52
53
|
// try/catch to avoid passToClient assertUsage() (although: this may not be needed anymore, since we're now accessing pageContext and not pageContextForUserConsumption)
|
|
53
54
|
try {
|
|
@@ -14,14 +14,14 @@ function getPageContextProxyForUser(pageContext) {
|
|
|
14
14
|
const val = pageContext[prop];
|
|
15
15
|
const propName = JSON.stringify(prop);
|
|
16
16
|
assertUsage(val !== notSerializable, `pageContext[${propName}] couldn't be serialized and, therefore, is missing on the client-side. Check the server logs for more information.`);
|
|
17
|
-
|
|
17
|
+
assertIsDefined(pageContext, prop);
|
|
18
18
|
return val;
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
// We disable
|
|
24
|
-
// - Vue tries to read its old value first. This triggers a `
|
|
22
|
+
function assertIsDefined(pageContext, prop) {
|
|
23
|
+
// We disable assertIsDefined() for the next attempt to read `prop`, because of how Vue's reactivity work. When changing a reactive object:
|
|
24
|
+
// - Vue tries to read its old value first. This triggers a `assertIsDefined()` failure if e.g. `pageContextOldReactive.routeParams = pageContextNew.routeParams` and `pageContextOldReactive` has no `routeParams`.
|
|
25
25
|
// - Vue seems to read __v_raw before reading the property
|
|
26
26
|
if (globalObject.prev === prop || globalObject.prev === '__v_raw')
|
|
27
27
|
return;
|
|
@@ -30,17 +30,23 @@ function assertPassToClient(pageContext, prop, errMsg) {
|
|
|
30
30
|
return;
|
|
31
31
|
if (isExpected(prop))
|
|
32
32
|
return;
|
|
33
|
+
const propName = JSON.stringify(prop);
|
|
34
|
+
/* This handling would be the clearest but, unfortunately, it's fundamentally problematic:
|
|
35
|
+
* - It would force the pageContext value consumer to be synchronized with the pageContext value provider. For example, if vike-react wants to conditionally do something dependening on wehther some optional pageContext value was provided by some optional vike-react-* integration package.
|
|
36
|
+
* - If a pageContext value is set by an optional hook, then it's expected that the value is undefined if the hook doesn't exist.
|
|
37
|
+
const errMsg = `pageContext[${propName}] is \`undefined\` on the client-side. If it's defined on the server-side then add ${propName} to passToClient (https://vike.dev/passToClient), otherwise make sure your client-side hooks always define it (e.g. set it to \`null\` instead of \`undefined\`).`
|
|
38
|
+
assertUsage(false, errMsg)
|
|
39
|
+
*/
|
|
33
40
|
if (pageContext._hasPageContextFromServer && !pageContext._hasPageContextFromClient) {
|
|
34
41
|
// We can safely assume that the property is missing in passToClient, because the server-side defines all passToClient properties even if they have an undefined value:
|
|
35
42
|
// ```
|
|
36
43
|
// <script id="vike_pageContext" type="application/json">{"_pageId":"/pages/admin","user":"!undefined","pageProps":"!undefined","title":"!undefined","abortReason":"!undefined","_urlRewrite":null}</script>
|
|
37
44
|
// ```
|
|
38
45
|
// Note how properties have "!undefined" values => we can tell whether an undefined pageContext value exists in passToClient.
|
|
39
|
-
assertUsage(false,
|
|
46
|
+
assertUsage(false, `pageContext[${propName}] isn't available on the client-side because ${propName} is missing in passToClient, see https://vike.dev/passToClient`);
|
|
40
47
|
}
|
|
41
48
|
else {
|
|
42
|
-
// Do nothing, not even a warning.
|
|
43
|
-
// Because we don't know whether the user expects the pageContext value to be undefined. (E.g. a client-side onBeforeRender() hook conditionally setting a pageContext value.)
|
|
49
|
+
// Do nothing, not even a warning, because we don't know whether the user expects that the pageContext value can be undefined. (E.g. a pageContext value that is defined by an optional hook.)
|
|
44
50
|
}
|
|
45
51
|
}
|
|
46
52
|
const IGNORE_LIST = [
|
|
@@ -4,7 +4,7 @@ export { analyzeClientEntries };
|
|
|
4
4
|
import { assert, resolveOutDir, isObject, viteIsSSR, getFilePathAbsolute, addOnBeforeLogHook, removeFileExtention, unique, assertPosixPath, assertUsage, getOutDirs } from '../utils.js';
|
|
5
5
|
import { virtualFileIdImportUserCodeServer } from '../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
6
6
|
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
7
|
-
import { getConfigValue } from '../../../shared/page-configs/
|
|
7
|
+
import { getConfigValue } from '../../../shared/page-configs/helpers.js';
|
|
8
8
|
import { findPageFiles } from '../shared/findPageFiles.js';
|
|
9
9
|
import { getConfigVike } from '../../shared/getConfigVike.js';
|
|
10
10
|
import { getVirtualFileIdPageConfigValuesAll } from '../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
@@ -34,18 +34,18 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
34
34
|
configValueSourcesRelevant.forEach((configValueSource) => {
|
|
35
35
|
if (!configValueSource.valueIsImportedAtRuntime)
|
|
36
36
|
return;
|
|
37
|
-
const {
|
|
37
|
+
const { definedAt, configEnv } = configValueSource;
|
|
38
38
|
if (configEnv !== 'client-only' && configEnv !== 'server-and-client')
|
|
39
39
|
return;
|
|
40
|
-
if (
|
|
41
|
-
const { filePathAbsoluteFilesystem } =
|
|
40
|
+
if (definedAt.filePathRelativeToUserRootDir !== null) {
|
|
41
|
+
const { filePathAbsoluteFilesystem } = definedAt;
|
|
42
42
|
assert(filePathAbsoluteFilesystem);
|
|
43
43
|
// Surprisingly Vite expects entries to be absolute paths
|
|
44
44
|
entries.push(filePathAbsoluteFilesystem);
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
|
-
// Adding
|
|
48
|
-
const { importPathAbsolute } =
|
|
47
|
+
// Adding definedAt.filePathAbsoluteFilesystem doesn't work for npm packages, I guess because of Vite's config.server.fs.allow
|
|
48
|
+
const { importPathAbsolute } = definedAt;
|
|
49
49
|
assert(importPathAbsolute);
|
|
50
50
|
// We need to differentiate between npm package imports and path aliases.
|
|
51
51
|
// There are path aliases that cannot be distinguished from npm package names.
|
|
@@ -4,7 +4,7 @@ export type { ConfigDefinition };
|
|
|
4
4
|
export type { ConfigDefinitionInternal };
|
|
5
5
|
export type { ConfigNameGlobal };
|
|
6
6
|
export type { ConfigEffect };
|
|
7
|
-
import type { ConfigEnvInternal, ConfigEnv, ConfigValueSources,
|
|
7
|
+
import type { ConfigEnvInternal, ConfigEnv, ConfigValueSources, DefinedAtFileFullInfo } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
8
8
|
import type { Config, ConfigNameBuiltIn } from '../../../../../../shared/page-configs/Config.js';
|
|
9
9
|
/** The meta definition of a config.
|
|
10
10
|
*
|
|
@@ -46,7 +46,7 @@ type ConfigEffect = (config: {
|
|
|
46
46
|
type ConfigDefinitionInternal = Omit<ConfigDefinition, 'env'> & {
|
|
47
47
|
_computed?: (configValueSources: ConfigValueSources) => unknown;
|
|
48
48
|
_valueIsFilePath?: true;
|
|
49
|
-
_userEffectDefinedAt?:
|
|
49
|
+
_userEffectDefinedAt?: DefinedAtFileFullInfo;
|
|
50
50
|
env: ConfigEnvInternal;
|
|
51
51
|
};
|
|
52
52
|
type ConfigDefinitionsBuiltIn = Record<ConfigNameBuiltIn, ConfigDefinitionInternal>;
|
|
@@ -48,16 +48,17 @@ const configDefinitionsBuiltIn = {
|
|
|
48
48
|
_valueIsFilePath: true
|
|
49
49
|
},
|
|
50
50
|
clientRouting: {
|
|
51
|
-
|
|
51
|
+
// We could make it 'server-only' (we don't yet because of some legacy V0.4 design code)
|
|
52
|
+
env: 'server-and-client'
|
|
52
53
|
},
|
|
53
54
|
prerender: {
|
|
54
55
|
env: 'server-only'
|
|
55
56
|
},
|
|
56
57
|
hydrationCanBeAborted: {
|
|
57
|
-
env: 'client-only'
|
|
58
|
+
env: 'client-only'
|
|
58
59
|
},
|
|
59
60
|
prefetchStaticAssets: {
|
|
60
|
-
env: 'client-only'
|
|
61
|
+
env: 'client-only'
|
|
61
62
|
},
|
|
62
63
|
extends: {
|
|
63
64
|
env: 'config-only'
|
|
@@ -14,7 +14,7 @@ import { getViteDevServer } from '../../../../runtime/globalContext.js';
|
|
|
14
14
|
import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNotProd.js';
|
|
15
15
|
import { removeSuperfluousViteLog_enable, removeSuperfluousViteLog_disable } from '../../../shared/loggerVite/removeSuperfluousViteLog.js';
|
|
16
16
|
import pc from '@brillout/picocolors';
|
|
17
|
-
import { getConfigDefinedAtString } from '../../../../../shared/page-configs/
|
|
17
|
+
import { getConfigDefinedAtString } from '../../../../../shared/page-configs/helpers.js';
|
|
18
18
|
import { assertExportsOfConfigFile, assertExportsOfValueFile } from '../../../../../shared/page-configs/assertExports.js';
|
|
19
19
|
import { getConfigValueSerialized } from './getVirtualFilePageConfigs.js';
|
|
20
20
|
assertIsNotProductionRuntime();
|
|
@@ -329,7 +329,7 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
329
329
|
assert('value' in configValueSource);
|
|
330
330
|
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
331
331
|
return;
|
|
332
|
-
const { filePathToShowToUser } = configValueSource.
|
|
332
|
+
const { filePathToShowToUser } = configValueSource.definedAt;
|
|
333
333
|
assertWarning(false, `Being able to define config ${pc.cyan(configName)} in ${filePathToShowToUser} is experimental and will likely be removed. Define the config ${pc.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
334
334
|
globalVikeConfig[configName] = configValueSource.value;
|
|
335
335
|
}
|
|
@@ -411,9 +411,14 @@ function makeOrderDeterministic(interfaceFile1, interfaceFile2) {
|
|
|
411
411
|
}
|
|
412
412
|
function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName, configDef, userRootDir) {
|
|
413
413
|
interfaceFilesOverriden.forEach((interfaceFileLoser) => {
|
|
414
|
+
const configValueSourceLoser_ = getConfigValueSource(configName, interfaceFileLoser, configDef, userRootDir);
|
|
414
415
|
const configValueSourceWinner = getConfigValueSource(configName, interfaceFileWinner, configDef, userRootDir);
|
|
415
|
-
|
|
416
|
-
|
|
416
|
+
// prettier-ignore
|
|
417
|
+
const configLoser_DefinedAt = getConfigDefinedAtString('Config', configName, configValueSourceLoser_);
|
|
418
|
+
// prettier-ignore
|
|
419
|
+
const configWinnerDefinedAt = getConfigDefinedAtString('config', configName, configValueSourceWinner);
|
|
420
|
+
const errMsg = `${configLoser_DefinedAt} is overriden by another ${configWinnerDefinedAt}, remove one of the two`;
|
|
421
|
+
assertWarning(false, errMsg, { onlyOnce: false });
|
|
417
422
|
});
|
|
418
423
|
}
|
|
419
424
|
function isInterfaceFileUserLand(interfaceFile) {
|
|
@@ -428,20 +433,20 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
428
433
|
fileExportPathToShowToUser: ['default', configName]
|
|
429
434
|
};
|
|
430
435
|
if (configDef._valueIsFilePath) {
|
|
431
|
-
let
|
|
436
|
+
let definedAt;
|
|
432
437
|
let valueFilePath;
|
|
433
438
|
if (interfaceFile.isConfigFile) {
|
|
434
439
|
const { configValue } = conf;
|
|
435
440
|
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
436
|
-
const configDefinedAt =
|
|
441
|
+
const configDefinedAt = getConfigDefinedAtString('Config', configName, { definedAt: definedAtConfigFile });
|
|
437
442
|
assertUsage(import_, `${configDefinedAt} should be an import`);
|
|
438
443
|
valueFilePath = import_.filePathAbsoluteVite;
|
|
439
|
-
|
|
444
|
+
definedAt = import_;
|
|
440
445
|
}
|
|
441
446
|
else {
|
|
442
447
|
assert(interfaceFile.isValueFile);
|
|
443
448
|
valueFilePath = interfaceFile.filePath.filePathAbsoluteVite;
|
|
444
|
-
|
|
449
|
+
definedAt = {
|
|
445
450
|
...interfaceFile.filePath,
|
|
446
451
|
fileExportPathToShowToUser: []
|
|
447
452
|
};
|
|
@@ -451,7 +456,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
451
456
|
valueIsFilePath: true,
|
|
452
457
|
configEnv,
|
|
453
458
|
valueIsImportedAtRuntime: true,
|
|
454
|
-
|
|
459
|
+
definedAt
|
|
455
460
|
};
|
|
456
461
|
return configValueSource;
|
|
457
462
|
}
|
|
@@ -463,7 +468,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
463
468
|
const configValueSource = {
|
|
464
469
|
configEnv,
|
|
465
470
|
valueIsImportedAtRuntime: true,
|
|
466
|
-
|
|
471
|
+
definedAt: import_
|
|
467
472
|
};
|
|
468
473
|
return configValueSource;
|
|
469
474
|
}
|
|
@@ -472,7 +477,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
472
477
|
value: configValue,
|
|
473
478
|
configEnv,
|
|
474
479
|
valueIsImportedAtRuntime: false,
|
|
475
|
-
|
|
480
|
+
definedAt: definedAtConfigFile
|
|
476
481
|
};
|
|
477
482
|
return configValueSource;
|
|
478
483
|
}
|
|
@@ -482,7 +487,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
482
487
|
const configValueSource = {
|
|
483
488
|
configEnv,
|
|
484
489
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
485
|
-
|
|
490
|
+
definedAt: {
|
|
486
491
|
...interfaceFile.filePath,
|
|
487
492
|
fileExportPathToShowToUser: configName === interfaceFile.configName
|
|
488
493
|
? []
|
|
@@ -615,9 +620,7 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
615
620
|
if (!configMeta)
|
|
616
621
|
return;
|
|
617
622
|
const meta = configMeta.configValue;
|
|
618
|
-
assertMetaValue(meta,
|
|
619
|
-
// TODO: Maybe we should use the getConfigDefinedAtString() helper?
|
|
620
|
-
`Config ${pc.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
|
|
623
|
+
assertMetaValue(meta, `Config ${pc.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
|
|
621
624
|
// Set configDef._userEffectDefinedAt
|
|
622
625
|
Object.entries(meta).forEach(([configName, configDef]) => {
|
|
623
626
|
if (!configDef.effect)
|
|
@@ -705,7 +708,7 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
|
|
|
705
708
|
// Call effect
|
|
706
709
|
const configModFromEffect = configDef.effect({
|
|
707
710
|
configValue: source.value,
|
|
708
|
-
configDefinedAt:
|
|
711
|
+
configDefinedAt: getConfigDefinedAtString('Config', configName, source)
|
|
709
712
|
});
|
|
710
713
|
if (!configModFromEffect)
|
|
711
714
|
return;
|
|
@@ -719,8 +722,8 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
719
722
|
if (configName === 'meta') {
|
|
720
723
|
let configDefinedAtString;
|
|
721
724
|
if (configDefEffect._userEffectDefinedAt) {
|
|
722
|
-
configDefinedAtString =
|
|
723
|
-
|
|
725
|
+
configDefinedAtString = getConfigDefinedAtString('Config', configName, {
|
|
726
|
+
definedAt: configDefEffect._userEffectDefinedAt
|
|
724
727
|
});
|
|
725
728
|
}
|
|
726
729
|
else {
|
|
@@ -744,7 +747,7 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
744
747
|
else {
|
|
745
748
|
assertUsage(false, notSupported);
|
|
746
749
|
// If we do end implementing being able to set the value of a config:
|
|
747
|
-
// - For setting
|
|
750
|
+
// - For setting definedAt: we could take the definedAt of the effect config while appending '(effect)' to definedAt.fileExportPathToShowToUser
|
|
748
751
|
}
|
|
749
752
|
});
|
|
750
753
|
}
|
|
@@ -874,8 +877,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
874
877
|
const extendsConfigFiles = [];
|
|
875
878
|
extendsImportData.map((importData) => {
|
|
876
879
|
const { importPath: importPath } = importData;
|
|
877
|
-
// TODO
|
|
878
|
-
// - validate extends configs
|
|
879
880
|
const filePathAbsoluteFilesystem = resolveImportPath(importData, configFilePath);
|
|
880
881
|
assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
881
882
|
assertExtendsImportPath(importPath, filePathAbsoluteFilesystem, configFilePath);
|
|
@@ -1019,10 +1020,10 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
|
|
|
1019
1020
|
// Eagerly loaded since it's config-only
|
|
1020
1021
|
assert('value' in configFilesystemRoutingRoot);
|
|
1021
1022
|
const { value } = configFilesystemRoutingRoot;
|
|
1022
|
-
const configDefinedAt =
|
|
1023
|
+
const configDefinedAt = getConfigDefinedAtString('Config', configName, configFilesystemRoutingRoot);
|
|
1023
1024
|
assertUsage(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
1024
1025
|
assertUsage(value.startsWith('/'), `${configDefinedAt} is ${pc.cyan(value)} but it should start with a leading slash ${pc.cyan('/')}`);
|
|
1025
|
-
const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.
|
|
1026
|
+
const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.definedAt;
|
|
1026
1027
|
assert(filePathRelativeToUserRootDir);
|
|
1027
1028
|
const before = getFilesystemRouteString(getLocationId(filePathRelativeToUserRootDir));
|
|
1028
1029
|
const after = value;
|
|
@@ -1086,7 +1087,6 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
1086
1087
|
configValues[configName] = {
|
|
1087
1088
|
value,
|
|
1088
1089
|
definedAt: {
|
|
1089
|
-
isCumulative: true,
|
|
1090
1090
|
files: sources.map((source) => getDefinedAtFile(source))
|
|
1091
1091
|
}
|
|
1092
1092
|
};
|
|
@@ -1096,21 +1096,19 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
1096
1096
|
}
|
|
1097
1097
|
function getDefinedAtFile(configValueSource) {
|
|
1098
1098
|
return {
|
|
1099
|
-
filePathToShowToUser: configValueSource.
|
|
1100
|
-
fileExportPathToShowToUser: configValueSource.
|
|
1099
|
+
filePathToShowToUser: configValueSource.definedAt.filePathToShowToUser,
|
|
1100
|
+
fileExportPathToShowToUser: configValueSource.definedAt.fileExportPathToShowToUser
|
|
1101
1101
|
};
|
|
1102
1102
|
}
|
|
1103
1103
|
function getDefinedAt(configValueSource) {
|
|
1104
|
-
return
|
|
1105
|
-
file: getDefinedAtFile(configValueSource)
|
|
1106
|
-
};
|
|
1104
|
+
return getDefinedAtFile(configValueSource);
|
|
1107
1105
|
}
|
|
1108
1106
|
function mergeCumulative(configName, configValueSources) {
|
|
1109
1107
|
const valuesArr = [];
|
|
1110
1108
|
const valuesSet = [];
|
|
1111
1109
|
let configValueSourcePrevious = null;
|
|
1112
1110
|
configValueSources.forEach((configValueSource) => {
|
|
1113
|
-
const configDefinedAt =
|
|
1111
|
+
const configDefinedAt = getConfigDefinedAtString('Config', configName, configValueSource);
|
|
1114
1112
|
const configNameColored = pc.cyan(configName);
|
|
1115
1113
|
// We could, in principle, also support cumulative values to be defined in +${configName}.js but it ins't completely trivial to implement
|
|
1116
1114
|
assertUsage('value' in configValueSource, `${configDefinedAt} is only allowed to be defined in a +config.h.js file. (Because the values of ${configNameColored} are cumulative.)`);
|
|
@@ -1128,7 +1126,7 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1128
1126
|
if (vals2.length === 0)
|
|
1129
1127
|
return;
|
|
1130
1128
|
assert(configValueSourcePrevious);
|
|
1131
|
-
const configPreviousDefinedAt =
|
|
1129
|
+
const configPreviousDefinedAt = getConfigDefinedAtString('Config', configName, configValueSourcePrevious);
|
|
1132
1130
|
assertUsage(false, `${configDefinedAt} sets ${t1} but another ${configPreviousDefinedAt} sets ${t2} which is forbidden: the values must be all arrays or all sets (you cannot mix).`);
|
|
1133
1131
|
};
|
|
1134
1132
|
const { value } = configValueSource;
|
|
@@ -1159,14 +1157,3 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1159
1157
|
}
|
|
1160
1158
|
assert(false);
|
|
1161
1159
|
}
|
|
1162
|
-
// TODO: rename and/or refactor
|
|
1163
|
-
function getConfigSourceDefinedAtString(configName, { definedAtInfo }, sentenceBegin = true) {
|
|
1164
|
-
return getConfigDefinedAtString(configName, {
|
|
1165
|
-
definedAt: {
|
|
1166
|
-
file: {
|
|
1167
|
-
filePathToShowToUser: definedAtInfo.filePathToShowToUser,
|
|
1168
|
-
fileExportPathToShowToUser: definedAtInfo.fileExportPathToShowToUser
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
}, sentenceBegin);
|
|
1172
|
-
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getVirtualFileIdPageConfigValuesAll, isVirtualFileIdPageConfigValuesAll
|
|
|
4
4
|
import { getVikeConfig } from './getVikeConfig.js';
|
|
5
5
|
import { extractAssetsAddQuery } from '../../../../shared/extractAssetsQuery.js';
|
|
6
6
|
import { debug } from './debug.js';
|
|
7
|
-
import { getConfigValue } from '../../../../../shared/page-configs/
|
|
7
|
+
import { getConfigValue } from '../../../../../shared/page-configs/helpers.js';
|
|
8
8
|
import { getConfigValueSourcesRelevant } from '../../../shared/getConfigValueSourcesRelevant.js';
|
|
9
9
|
import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
|
|
10
10
|
import { serializeConfigValueImported } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigs };
|
|
2
2
|
export { getConfigValueSerialized };
|
|
3
|
-
import { assert, assertUsage, getPropAccessNotation,
|
|
3
|
+
import { assert, assertUsage, getPropAccessNotation, objectEntries } from '../../../utils.js';
|
|
4
4
|
import { getVirtualFileIdPageConfigValuesAll } from '../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
5
5
|
import { debug } from './debug.js';
|
|
6
|
-
import { stringify } from '@brillout/json-serializer/stringify';
|
|
6
|
+
import { isJsonSerializerError, stringify } from '@brillout/json-serializer/stringify';
|
|
7
7
|
import { getConfigEnv } from './helpers.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { getVikeConfig } from './getVikeConfig.js';
|
|
10
10
|
import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
|
|
11
|
-
import { getConfigValueFilePathToShowToUser } from '../../../../../shared/page-configs/
|
|
11
|
+
import { getConfigValueFilePathToShowToUser } from '../../../../../shared/page-configs/helpers.js';
|
|
12
12
|
import { serializeConfigValue, serializeConfigValueImported } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
|
|
13
13
|
async function getVirtualFilePageConfigs(userRootDir, outDirRoot, isForClientSide, isDev, id, configVike, isClientRouting) {
|
|
14
14
|
const { pageConfigs, pageConfigGlobal } = await getVikeConfig(userRootDir, outDirRoot, isDev, configVike.extensions, true);
|
|
@@ -105,15 +105,24 @@ function getConfigValueSerialized(value, configName, definedAt) {
|
|
|
105
105
|
const valueName = `config${getPropAccessNotation(configName)}`;
|
|
106
106
|
let configValueSerialized;
|
|
107
107
|
try {
|
|
108
|
-
configValueSerialized = stringify(value, { valueName });
|
|
108
|
+
configValueSerialized = stringify(value, { valueName, forbidReactElements: true });
|
|
109
109
|
}
|
|
110
110
|
catch (err) {
|
|
111
|
-
|
|
111
|
+
let serializationErrMsg = '';
|
|
112
|
+
if (isJsonSerializerError(err)) {
|
|
113
|
+
serializationErrMsg = err.messageCore;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// When a property getter throws an error
|
|
117
|
+
console.error('Serialization error:');
|
|
118
|
+
console.error(err);
|
|
119
|
+
serializationErrMsg = 'see serialization error printed above';
|
|
120
|
+
}
|
|
112
121
|
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
|
|
113
122
|
assert(configValueFilePathToShowToUser);
|
|
114
123
|
assertUsage(false, [
|
|
115
124
|
`The value of the config ${pc.cyan(configName)} cannot be defined inside the file ${configValueFilePathToShowToUser}:`,
|
|
116
|
-
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because
|
|
125
|
+
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because its value isn't serializable: ${serializationErrMsg}.)`,
|
|
117
126
|
`Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
|
|
118
127
|
].join(' '));
|
|
119
128
|
}
|
|
@@ -6,20 +6,7 @@ function getConfigEnv(configValueSources, configName) {
|
|
|
6
6
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
7
7
|
if (!configValueSource)
|
|
8
8
|
return null;
|
|
9
|
-
|
|
10
|
-
return configValueSource.configEnv;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
// In case of effect/computed config values, there isn't any configValueSource
|
|
14
|
-
// TODO: make it work for custom config definitions
|
|
15
|
-
// - Ideally set configValueSource also for effect/computed config values?
|
|
16
|
-
assert(false, 'TODO');
|
|
17
|
-
/*
|
|
18
|
-
const configDef = configDefinitionsBuiltIn[configName as keyof typeof configDefinitionsBuiltIn]
|
|
19
|
-
if (!configDef) return null
|
|
20
|
-
return configDef.env
|
|
21
|
-
*/
|
|
22
|
-
}
|
|
9
|
+
return configValueSource.configEnv;
|
|
23
10
|
}
|
|
24
11
|
function isConfigSet(configValueSources, configName) {
|
|
25
12
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
@@ -13,6 +13,7 @@ function previewConfig() {
|
|
|
13
13
|
apply: 'serve',
|
|
14
14
|
config(config) {
|
|
15
15
|
return {
|
|
16
|
+
appType: 'custom',
|
|
16
17
|
build: {
|
|
17
18
|
outDir: resolveOutDir(config)
|
|
18
19
|
}
|
|
@@ -23,12 +24,20 @@ function previewConfig() {
|
|
|
23
24
|
configVike = await getConfigVike(config);
|
|
24
25
|
},
|
|
25
26
|
configurePreviewServer(server) {
|
|
27
|
+
/* - Couldn't make `appType: 'mpa'` work as of npm:@brillout/vite@5.0.0-beta.14.0426910c
|
|
28
|
+
- This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
|
|
29
|
+
config.appType = 'mpa'
|
|
30
|
+
*/
|
|
26
31
|
markEnvAsPreview();
|
|
27
32
|
return () => {
|
|
28
33
|
assertDist();
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
/* We don't use this condition (we wrongfully always use the SSR middleware) because of the regression introduced by https://github.com/vitejs/vite/pull/14756 which stops servering .html files when `appType: 'custom'`.
|
|
35
|
+
if (!configVike.prerender || configVike.prerender.partial) {
|
|
36
|
+
addSsrMiddleware(server.middlewares)
|
|
31
37
|
}
|
|
38
|
+
/*/
|
|
39
|
+
addSsrMiddleware(server.middlewares);
|
|
40
|
+
//*/
|
|
32
41
|
addStatic404Middleware(server.middlewares);
|
|
33
42
|
};
|
|
34
43
|
}
|