vike 0.4.259-commit-ac2142e → 0.4.259-commit-aa6fa94
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/node/vite/shared/resolveVikeConfigInternal/assertExtensions.d.ts +2 -0
- package/dist/node/vite/shared/resolveVikeConfigInternal/assertExtensions.js +6 -5
- package/dist/node/vite/shared/resolveVikeConfigInternal/getPlusFilesByLocationId.js +13 -13
- package/dist/node/vite/shared/resolveVikeConfigInternal.js +19 -3
- package/dist/server/runtime/renderPageServer.js +3 -1
- package/dist/types/Config.d.ts +12 -3
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { assertExtensionsConventions };
|
|
2
2
|
export { assertExtensionsRequire };
|
|
3
|
+
export { getExtensionName };
|
|
3
4
|
import type { PlusFile } from './getPlusFilesByLocationId.js';
|
|
4
5
|
import '../../assertEnvVite.js';
|
|
5
6
|
declare function assertExtensionsConventions(plusFile: PlusFile): void;
|
|
6
7
|
declare function assertExtensionsRequire(plusFiles: PlusFile[]): void;
|
|
8
|
+
declare function getExtensionName(plusFile: PlusFile): null | string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { assertExtensionsConventions };
|
|
2
2
|
export { assertExtensionsRequire };
|
|
3
|
+
export { getExtensionName };
|
|
3
4
|
import pc from '@brillout/picocolors';
|
|
4
5
|
import { PROJECT_VERSION } from '../../../../utils/PROJECT_VERSION.js';
|
|
5
6
|
import { assert, assertUsage, assertWarning } from '../../../../utils/assert.js';
|
|
@@ -21,14 +22,14 @@ function assertConfigExportPath(plusFile) {
|
|
|
21
22
|
assert(!p.includes('node_modules'));
|
|
22
23
|
return;
|
|
23
24
|
}
|
|
24
|
-
const name =
|
|
25
|
+
const name = getExtensionName(plusFile);
|
|
25
26
|
assert(name); // already asserted in assertExtensionName()
|
|
26
27
|
const importPathAbsoluteExpected = `${name}/config`;
|
|
27
28
|
assertWarning(importPathAbsolute === importPathAbsoluteExpected, `The Vike configuration of ${pc.bold(name)} is exported at ${pc.bold(importPathAbsolute)}, but it should be exported at ${pc.bold(importPathAbsoluteExpected)} instead.`, { onlyOnce: true });
|
|
28
29
|
}
|
|
29
30
|
function assertExtensionName(plusFile) {
|
|
30
31
|
const filePathToShowToUser = getFilePathToShowToUser(plusFile);
|
|
31
|
-
const name =
|
|
32
|
+
const name = getExtensionName(plusFile);
|
|
32
33
|
assertUsage(name, `Vike extension name missing: the config ${filePathToShowToUser} must define the setting ${pc.cyan('name')}`);
|
|
33
34
|
}
|
|
34
35
|
function assertExtensionsRequire(plusFiles) {
|
|
@@ -36,7 +37,7 @@ function assertExtensionsRequire(plusFiles) {
|
|
|
36
37
|
// Collect extensions
|
|
37
38
|
const extensions = {};
|
|
38
39
|
plusFilesRelevantList.forEach((plusFile) => {
|
|
39
|
-
const name =
|
|
40
|
+
const name = getExtensionName(plusFile);
|
|
40
41
|
if (name) {
|
|
41
42
|
const version = getExtensionVersion(name, plusFile);
|
|
42
43
|
extensions[name] = version;
|
|
@@ -47,7 +48,7 @@ function assertExtensionsRequire(plusFiles) {
|
|
|
47
48
|
const require = resolveRequireSetting(plusFile);
|
|
48
49
|
if (!require)
|
|
49
50
|
return;
|
|
50
|
-
const name =
|
|
51
|
+
const name = getExtensionName(plusFile);
|
|
51
52
|
const filePathToShowToUser = getFilePathToShowToUser(plusFile);
|
|
52
53
|
assertUsage(name, `Setting ${pc.bold('name')} is required for being able to use setting ${pc.bold('require')} in ${filePathToShowToUser}.`);
|
|
53
54
|
Object.entries(require).forEach(([reqName, req]) => {
|
|
@@ -96,7 +97,7 @@ function resolveRequireSetting(plusFile) {
|
|
|
96
97
|
});
|
|
97
98
|
return requireSetting;
|
|
98
99
|
}
|
|
99
|
-
function
|
|
100
|
+
function getExtensionName(plusFile) {
|
|
100
101
|
const confVal = getConfVal(plusFile, 'name');
|
|
101
102
|
if (!confVal)
|
|
102
103
|
return null;
|
|
@@ -25,21 +25,21 @@ async function getPlusFilesByLocationId(userRootDir, esbuildCache) {
|
|
|
25
25
|
plusFilesByLocationId[locationId].push(plusFile);
|
|
26
26
|
extendsConfigs.forEach((extendsConfig) => {
|
|
27
27
|
/* We purposely use the same locationId because the Vike extension's config should only apply to where it's being extended from, for example:
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
```js
|
|
29
|
+
// /pages/admin/+config.js
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
import vikeVue from 'vike-vue/config'
|
|
32
|
+
// Should only apply to /pages/admin/**
|
|
33
|
+
export default { extends: [vikeVue] }
|
|
34
|
+
```
|
|
35
|
+
```js
|
|
36
|
+
// /pages/marketing/+config.js
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
import vikeReact from 'vike-react/config'
|
|
39
|
+
// Should only apply to /pages/marketing/**
|
|
40
|
+
export default { extends: [vikeReact] }
|
|
41
|
+
```
|
|
42
|
+
*/
|
|
43
43
|
const plusFile = getPlusFileFromConfigFile(extendsConfig, true, locationId, userRootDir);
|
|
44
44
|
assertExtensionsConventions(plusFile);
|
|
45
45
|
plusFilesByLocationId[locationId].push(plusFile);
|
|
@@ -45,6 +45,7 @@ import { getConfigValueBuildTime } from '../../../shared-server-client/page-conf
|
|
|
45
45
|
import { resolveGlobalConfigPublic, } from '../../../shared-server-client/page-configs/resolveVikeConfigPublic.js';
|
|
46
46
|
import { getConfigValuesBase, isJsonValue, } from '../../../shared-server-client/page-configs/serialize/serializeConfigValues.js';
|
|
47
47
|
import { getPlusFilesByLocationId, } from './resolveVikeConfigInternal/getPlusFilesByLocationId.js';
|
|
48
|
+
import { getExtensionName } from './resolveVikeConfigInternal/assertExtensions.js';
|
|
48
49
|
import { getEnvVarObject } from './getEnvVarObject.js';
|
|
49
50
|
import { getVikeApiOperation } from '../../../shared-server-node/api-context.js';
|
|
50
51
|
import { getCliOptions } from '../../cli/context.js';
|
|
@@ -649,9 +650,10 @@ function sortPlusFilesSameLocationId(plusFile1, plusFile2, configName) {
|
|
|
649
650
|
return 0;
|
|
650
651
|
}
|
|
651
652
|
function resolveConfigValueSources(configName, configDef, plusFilesRelevant, userRootDir, isGlobal, plusFilesByLocationId) {
|
|
652
|
-
let
|
|
653
|
-
|
|
654
|
-
|
|
653
|
+
let plusFilesConfig = plusFilesRelevant.filter((plusFile) => isDefiningConfig(plusFile, configName));
|
|
654
|
+
// Make Vike extension installation idempotent. (Don't cumulate configs twice of an extension installed twice.) Since `plusFilesRelevant` is ordered by inheritance the occurrence closest to the page's locationId is the one kept.
|
|
655
|
+
plusFilesConfig = dedupeExtensions(plusFilesConfig);
|
|
656
|
+
let sources = plusFilesConfig.flatMap((plusFile) => getConfigValueSources(configName, plusFile, configDef, userRootDir));
|
|
655
657
|
// Filter hydrid global-local configs
|
|
656
658
|
if (!isCallable(configDef.global)) {
|
|
657
659
|
// Already filtered
|
|
@@ -672,6 +674,20 @@ function resolveConfigValueSources(configName, configDef, plusFilesRelevant, use
|
|
|
672
674
|
function isDefiningConfig(plusFile, configName) {
|
|
673
675
|
return getConfigNamesSetByPlusFile(plusFile).includes(configName);
|
|
674
676
|
}
|
|
677
|
+
function dedupeExtensions(plusFiles) {
|
|
678
|
+
const seen = new Set();
|
|
679
|
+
return plusFiles.filter((plusFile) => {
|
|
680
|
+
if (!plusFile.isConfigFile || !plusFile.isExtensionConfig)
|
|
681
|
+
return true;
|
|
682
|
+
const name = getExtensionName(plusFile);
|
|
683
|
+
// The extension's `name` is guaranteed by assertExtensionsConventions()
|
|
684
|
+
assert(name);
|
|
685
|
+
if (seen.has(name))
|
|
686
|
+
return false;
|
|
687
|
+
seen.add(name);
|
|
688
|
+
return true;
|
|
689
|
+
});
|
|
690
|
+
}
|
|
675
691
|
function getConfigValueSources(configName, plusFile, configDef, userRootDir) {
|
|
676
692
|
const confVal = getConfVal(plusFile, configName);
|
|
677
693
|
assert(confVal);
|
|
@@ -319,7 +319,9 @@ function logHttpResponse(urlOriginalPretty, pageContextReturn) {
|
|
|
319
319
|
const headerRedirect = pageContextReturn.httpResponse.headers
|
|
320
320
|
.slice()
|
|
321
321
|
.reverse()
|
|
322
|
-
|
|
322
|
+
// Case-insensitive: a redirect returned by a +middleware comes from a Web Response whose
|
|
323
|
+
// Headers object lower-cases header names (`location`), while Vike's own redirect() uses `Location`.
|
|
324
|
+
.find((header) => header[0].toLowerCase() === 'location');
|
|
323
325
|
assert(headerRedirect);
|
|
324
326
|
const urlRedirect = headerRedirect[1];
|
|
325
327
|
urlOriginalPretty = urlRedirect;
|
package/dist/types/Config.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ import type { CliPreviewConfig } from '../node/api/preview.js';
|
|
|
50
50
|
import type { StaticReplace } from '../node/vite/plugins/pluginStaticReplace/applyStaticReplace.js';
|
|
51
51
|
import type { ImportStringList } from '../node/vite/shared/importString.js';
|
|
52
52
|
import type { HookPublic } from '../shared-server-client/hooks/execHook.js';
|
|
53
|
+
import type { EnhancedMiddleware } from '@universal-middleware/core';
|
|
53
54
|
type HookNameOld = HookName | HookNameOldDesign;
|
|
54
55
|
type HookName = HookNamePage | HookNameGlobal;
|
|
55
56
|
type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data' | 'onData' | 'route';
|
|
@@ -526,8 +527,16 @@ type ConfigBuiltIn = {
|
|
|
526
527
|
* https://vike.dev/keepScrollPosition
|
|
527
528
|
*/
|
|
528
529
|
keepScrollPosition?: KeepScrollPosition;
|
|
529
|
-
/**
|
|
530
|
-
|
|
530
|
+
/**
|
|
531
|
+
* @experimental
|
|
532
|
+
*
|
|
533
|
+
* Add server middlewares.
|
|
534
|
+
*
|
|
535
|
+
* The middlewares defined via `+middleware` are so called "Universal Middleware" — they work with any JavaScript server (Hono, Express, Cloudflare, ...).
|
|
536
|
+
*
|
|
537
|
+
* https://github.com/magne4000/universal-middleware
|
|
538
|
+
*/
|
|
539
|
+
middleware?: EnhancedMiddleware | EnhancedMiddleware[];
|
|
531
540
|
/**
|
|
532
541
|
* Set to `false` to disable Vike's automatic server integration mechanism (e.g. for integrating a JavaScript server manually via `renderPage()`).
|
|
533
542
|
*
|
|
@@ -661,7 +670,7 @@ type ConfigBuiltInResolved = {
|
|
|
661
670
|
passToClient?: string[][];
|
|
662
671
|
redirects?: Record<string, string>[];
|
|
663
672
|
prerender?: Exclude<Config['prerender'], ImportStringList | undefined>[];
|
|
664
|
-
middleware?:
|
|
673
|
+
middleware?: (EnhancedMiddleware | EnhancedMiddleware[])[];
|
|
665
674
|
headersResponse?: Exclude<Config['headersResponse'], ImportStringList | undefined>[];
|
|
666
675
|
staticReplace?: StaticReplace[][];
|
|
667
676
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.259-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.259-commit-aa6fa94";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.259-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.259-commit-aa6fa94';
|