vike 0.4.222 → 0.4.223-commit-586dbfb
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/client/shared/getPageContextProxyForUser.js +1 -1
- package/dist/cjs/node/api/prepareViteApiCall.js +1 -1
- package/dist/cjs/node/plugin/index.js +6 -4
- package/dist/cjs/node/plugin/plugins/baseUrls.js +9 -2
- package/dist/cjs/node/plugin/plugins/buildApp.js +14 -7
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +49 -19
- package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +17 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +2 -18
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +2 -2
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +4 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +6 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +11 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +8 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +36 -71
- package/dist/cjs/node/plugin/shared/findPageFiles.js +3 -3
- package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
- package/dist/cjs/node/plugin/shared/viteIsSSR.js +19 -10
- package/dist/cjs/node/prerender/runPrerender.js +3 -1
- package/dist/cjs/node/runtime/globalContext.js +19 -8
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +24 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +1 -1
- package/dist/cjs/node/runtime/renderPage/isNewError.js +1 -1
- package/dist/cjs/node/runtime/renderPage/isVikeConfigInvalid.js +10 -0
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +7 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -4
- package/dist/cjs/node/runtime/renderPage.js +63 -49
- package/dist/cjs/node/runtime/universal-middleware.js +14 -0
- package/dist/cjs/node/shared/resolveBase.js +0 -13
- package/dist/cjs/shared/getPageConfigsRuntime.js +2 -8
- package/dist/cjs/shared/getPageContextRequestUrl.js +1 -1
- package/dist/cjs/shared/getPageContextUrlComputed.js +12 -9
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +44 -12
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -8
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +16 -6
- package/dist/cjs/shared/route/loadPageRoutes.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +1 -1
- package/dist/cjs/utils/assertSetup.js +1 -1
- package/dist/cjs/utils/assertSingleInstance.js +2 -2
- package/dist/cjs/utils/findFile.js +1 -1
- package/dist/cjs/utils/getGlobalObject.js +2 -6
- package/dist/cjs/utils/parseUrl-extras.js +2 -2
- package/dist/cjs/utils/parseUrl.js +5 -5
- package/dist/cjs/utils/requireResolve.js +3 -3
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.js +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +4 -4
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +1 -1
- package/dist/esm/client/client-routing-runtime/history.js +1 -1
- package/dist/esm/client/client-routing-runtime/index.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/index.js +1 -0
- package/dist/esm/client/client-routing-runtime/prefetch/getPrefetchSettings.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.js +3 -3
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +8 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +12 -3
- package/dist/esm/client/client-routing-runtime/scrollRestoration.js +1 -1
- package/dist/esm/client/client-routing-runtime/skipLink.js +2 -2
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
- package/dist/esm/client/shared/getPageContextProxyForUser.js +1 -1
- package/dist/esm/client/shared/loadUserFilesClientSide.d.ts +2 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.js +2 -2
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/api/prepareViteApiCall.js +1 -1
- package/dist/esm/node/plugin/index.d.ts +6 -2
- package/dist/esm/node/plugin/index.js +2 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +9 -2
- package/dist/esm/node/plugin/plugins/buildApp.js +14 -7
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +49 -19
- package/dist/esm/node/plugin/plugins/buildConfig.js +6 -1
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +14 -6
- package/dist/esm/node/plugin/plugins/commonConfig.js +17 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/esm/node/plugin/plugins/envVars.js +2 -18
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +3 -3
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +6 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +10 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +8 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +5 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +38 -73
- package/dist/esm/node/plugin/shared/findPageFiles.js +3 -3
- package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +2 -2
- package/dist/esm/node/plugin/shared/viteIsSSR.d.ts +7 -4
- package/dist/esm/node/plugin/shared/viteIsSSR.js +20 -11
- package/dist/esm/node/prerender/runPrerender.js +3 -1
- package/dist/esm/node/runtime/globalContext.d.ts +9 -8
- package/dist/esm/node/runtime/globalContext.js +19 -8
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +24 -0
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.js +1 -1
- package/dist/esm/node/runtime/renderPage/isNewError.js +1 -1
- package/dist/esm/node/runtime/renderPage/isVikeConfigInvalid.d.ts +6 -0
- package/dist/esm/node/runtime/renderPage/isVikeConfigInvalid.js +8 -0
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +3 -3
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +7 -1
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +4 -4
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +12 -12
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -4
- package/dist/esm/node/runtime/renderPage.d.ts +5 -5
- package/dist/esm/node/runtime/renderPage.js +64 -49
- package/dist/esm/node/runtime/universal-middleware.d.ts +1 -0
- package/dist/esm/node/runtime/universal-middleware.js +11 -0
- package/dist/esm/node/shared/resolveBase.d.ts +1 -9
- package/dist/esm/node/shared/resolveBase.js +0 -13
- package/dist/esm/shared/getPageConfigsRuntime.d.ts +2 -2
- package/dist/esm/shared/getPageConfigsRuntime.js +3 -9
- package/dist/esm/shared/getPageContextRequestUrl.js +1 -1
- package/dist/esm/shared/getPageContextUrlComputed.js +12 -9
- package/dist/esm/shared/getPageFiles.d.ts +1 -1
- package/dist/esm/shared/hooks/getHook.d.ts +3 -3
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +3 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +12 -4
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +24 -16
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +44 -12
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +3 -2
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -8
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +2 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +16 -6
- package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +1 -1
- package/dist/esm/shared/types.d.ts +6 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.js +1 -1
- package/dist/esm/utils/assertSetup.js +1 -1
- package/dist/esm/utils/assertSingleInstance.js +2 -2
- package/dist/esm/utils/findFile.js +1 -1
- package/dist/esm/utils/getGlobalObject.d.ts +3 -2
- package/dist/esm/utils/getGlobalObject.js +2 -6
- package/dist/esm/utils/parseUrl-extras.js +2 -2
- package/dist/esm/utils/parseUrl.d.ts +3 -4
- package/dist/esm/utils/parseUrl.js +5 -5
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/requireResolve.js +3 -3
- package/package.json +18 -6
- package/universal-middleware.js +3 -0
- package/dist/cjs/node/runtime/renderPage/isConfigInvalid.js +0 -10
- package/dist/esm/node/runtime/renderPage/isConfigInvalid.d.ts +0 -6
- package/dist/esm/node/runtime/renderPage/isConfigInvalid.js +0 -8
- package/dist-cjs-fixup.mjs +0 -41
|
@@ -37,26 +37,29 @@ function getUrlParsed(pageContext) {
|
|
|
37
37
|
// 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
|
|
38
38
|
// Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
|
|
39
39
|
// Determine logical URL
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const assertUrlResolved = (src) => assert(typeof urlResolved === 'string',
|
|
41
|
+
// TODO/eventually: remove debug logs, see:
|
|
42
|
+
// - https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
|
|
43
|
+
// - https://github.com/vikejs/vike/commit/5c7810f3080ab62536950f26e019bb2a3a517082
|
|
44
|
+
{ src, urlResolved });
|
|
42
45
|
let urlResolved;
|
|
43
|
-
let
|
|
46
|
+
let isBaseToBeRemoved;
|
|
44
47
|
if (pageContext.urlLogical) {
|
|
45
48
|
// Set by onBeforeRoute()
|
|
46
49
|
urlResolved = pageContext.urlLogical;
|
|
47
|
-
|
|
50
|
+
isBaseToBeRemoved = false;
|
|
48
51
|
assertUrlResolved(1);
|
|
49
52
|
}
|
|
50
53
|
else if (pageContext._urlRewrite) {
|
|
51
54
|
// Set by `throw render()`
|
|
52
55
|
urlResolved = pageContext._urlRewrite;
|
|
53
|
-
|
|
56
|
+
isBaseToBeRemoved = false;
|
|
54
57
|
assertUrlResolved(2);
|
|
55
58
|
}
|
|
56
59
|
else {
|
|
57
60
|
// Set by renderPage()
|
|
58
61
|
urlResolved = pageContext.urlOriginal;
|
|
59
|
-
|
|
62
|
+
isBaseToBeRemoved = true;
|
|
60
63
|
assertUrlResolved(3);
|
|
61
64
|
}
|
|
62
65
|
assertUrlResolved(4);
|
|
@@ -69,7 +72,7 @@ function getUrlParsed(pageContext) {
|
|
|
69
72
|
// - We assume there isn't any Base URL to the URLs set by the user at `throw render()` and onBeforeRoute()
|
|
70
73
|
// - This makes sense because the Base URL is merely a setting: ideally the user should write code that doesn't know anything about it (so that the user can remove/add/change Base URL without having to modify any code).
|
|
71
74
|
// - pageContext.urlOriginal is the URL of the HTTP request and thus contains the Base URL.
|
|
72
|
-
const baseServer = !
|
|
75
|
+
const baseServer = !isBaseToBeRemoved ? '/' : pageContext._baseServer;
|
|
73
76
|
// Parse URL
|
|
74
77
|
return parseUrl(urlResolved, baseServer);
|
|
75
78
|
}
|
|
@@ -86,8 +89,8 @@ function urlGetter() {
|
|
|
86
89
|
}
|
|
87
90
|
function urlParsedGetter() {
|
|
88
91
|
const {
|
|
89
|
-
// remove
|
|
90
|
-
|
|
92
|
+
// remove isBaseMissing as it isn't part of UrlPublic
|
|
93
|
+
isBaseMissing: _, ...urlParsed } = getUrlParsed(this);
|
|
91
94
|
const hashIsAvailable = isBrowser();
|
|
92
95
|
const warnHashNotAvailable = (prop) => {
|
|
93
96
|
assertWarning(hashIsAvailable, `pageContext.urlParsed.${prop} isn't available on the server-side (HTTP requests don't include the URL hash)`, { onlyOnce: true, showStackTrace: true });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { PageFile } from './getPageFiles/getPageFileObject.js';
|
|
2
|
-
export type { ExportsAll,
|
|
2
|
+
export type { ExportsAll, PageConfigUserFriendlyOld } from './page-configs/getPageConfigUserFriendly.js';
|
|
3
3
|
export { getPageFilesClientSide } from './getPageFiles/getAllPageIdFiles.js';
|
|
4
4
|
export { getPageFilesServerSide } from './getPageFiles/getAllPageIdFiles.js';
|
|
@@ -9,7 +9,7 @@ export type { HookLoc };
|
|
|
9
9
|
export type { HookTimeout };
|
|
10
10
|
export type { HooksTimeoutProvidedByUser };
|
|
11
11
|
export { getHookTimeoutDefault };
|
|
12
|
-
import type {
|
|
12
|
+
import type { PageConfigUserFriendlyOld } from '../getPageFiles.js';
|
|
13
13
|
import type { HookName, HookNamePage, HookNameGlobal } from '../page-configs/Config.js';
|
|
14
14
|
import type { PageConfigGlobalRuntime, PageConfigRuntime } from '../page-configs/PageConfig.js';
|
|
15
15
|
type Hook = HookLoc & {
|
|
@@ -26,10 +26,10 @@ type HookTimeout = {
|
|
|
26
26
|
warning: number | false;
|
|
27
27
|
};
|
|
28
28
|
type HooksTimeoutProvidedByUser = false | Partial<Record<HookName, false | Partial<HookTimeout>>>;
|
|
29
|
-
declare function getHook(pageContext:
|
|
29
|
+
declare function getHook(pageContext: PageConfigUserFriendlyOld, hookName: HookName): null | Hook;
|
|
30
30
|
declare function getHookFromPageConfig(pageConfig: PageConfigRuntime, hookName: HookNamePage): null | Hook;
|
|
31
31
|
declare function getHookFromPageConfigGlobal(pageConfigGlobal: PageConfigGlobalRuntime, hookName: HookNameGlobal): null | Hook;
|
|
32
|
-
declare function assertHook<TPageContext extends
|
|
32
|
+
declare function assertHook<TPageContext extends PageConfigUserFriendlyOld, THookName extends PropertyKey & HookName>(pageContext: TPageContext, hookName: THookName): asserts pageContext is TPageContext & {
|
|
33
33
|
exports: Record<THookName, Function | undefined>;
|
|
34
34
|
};
|
|
35
35
|
declare function getHookTimeoutDefault(hookName: HookName): HookTimeout;
|
|
@@ -11,7 +11,7 @@ import { getHookFilePathToShowToUser } from '../page-configs/helpers.js';
|
|
|
11
11
|
import { getConfigValueRuntime } from '../page-configs/getConfigValueRuntime.js';
|
|
12
12
|
import { assert, assertUsage, checkType, isCallable, isObject } from '../utils.js';
|
|
13
13
|
import pc from '@brillout/picocolors';
|
|
14
|
-
const globalObject = getGlobalObject('getHook.ts', {});
|
|
14
|
+
const globalObject = getGlobalObject('hooks/getHook.ts', {});
|
|
15
15
|
function getHook(pageContext, hookName) {
|
|
16
16
|
if (!(hookName in pageContext.exports)) {
|
|
17
17
|
return null;
|
|
@@ -32,6 +32,7 @@ export type { OnRenderHtmlAsync };
|
|
|
32
32
|
export type { OnRenderHtmlSync };
|
|
33
33
|
export type { RouteAsync };
|
|
34
34
|
export type { RouteSync };
|
|
35
|
+
export type { Route };
|
|
35
36
|
export type { KeepScrollPosition };
|
|
36
37
|
import type { PrefetchSetting, PrefetchStaticAssets } from '../../client/client-routing-runtime/prefetch/PrefetchSetting.js';
|
|
37
38
|
import type { ConfigDefinition } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
|
|
@@ -223,6 +224,7 @@ type RouteSync = (pageContext: PageContextServer | PageContextClient) => {
|
|
|
223
224
|
routeParams?: Record<string, string>;
|
|
224
225
|
precedence?: number;
|
|
225
226
|
} | boolean;
|
|
227
|
+
type Route = string | RouteSync | RouteAsync;
|
|
226
228
|
/** Whether the page scrolls to the top upon navigation.
|
|
227
229
|
*
|
|
228
230
|
* https://vike.dev/keepScrollPosition
|
|
@@ -239,7 +241,7 @@ type ConfigBuiltIn = {
|
|
|
239
241
|
*
|
|
240
242
|
* https://vike.dev/route
|
|
241
243
|
*/
|
|
242
|
-
route?:
|
|
244
|
+
route?: Route | ImportString;
|
|
243
245
|
/** Protect page(s), e.g. forbid unauthorized access.
|
|
244
246
|
*
|
|
245
247
|
* https://vike.dev/guard
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type { PageConfigRuntime };
|
|
2
2
|
export type { PageConfigRuntimeLoaded };
|
|
3
3
|
export type { PageConfigBuildTime };
|
|
4
|
+
export type { PageConfigCommon };
|
|
5
|
+
export type { PageConfigRoute };
|
|
4
6
|
export type { ConfigEnv };
|
|
5
7
|
export type { ConfigEnvInternal };
|
|
6
8
|
export type { PageConfigGlobalRuntime };
|
|
@@ -23,8 +25,13 @@ import type { ConfigDefinitions } from '../../node/plugin/plugins/importUserCode
|
|
|
23
25
|
import type { PlusFile, PlusFilesByLocationId } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js';
|
|
24
26
|
type PageConfigCommon = {
|
|
25
27
|
pageId: string;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
} & PageConfigRoute;
|
|
29
|
+
type PageConfigRoute = {
|
|
30
|
+
isErrorPage: true;
|
|
31
|
+
routeFilesystem?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
isErrorPage?: undefined;
|
|
34
|
+
routeFilesystem: {
|
|
28
35
|
routeString: string;
|
|
29
36
|
definedBy: string;
|
|
30
37
|
};
|
|
@@ -87,10 +94,11 @@ type ConfigValueSource = {
|
|
|
87
94
|
locationId: LocationId;
|
|
88
95
|
isOverriden: boolean;
|
|
89
96
|
/** Wether the config value is loaded at runtime, for example config.Page or config.onBeforeRender */
|
|
90
|
-
|
|
97
|
+
valueIsLoadedWithImport: boolean;
|
|
91
98
|
/** Whether the config value is a file path, for example config.client */
|
|
92
99
|
valueIsFilePath?: true;
|
|
93
|
-
|
|
100
|
+
/** Whether the config value is defined by a +{configName}.js file */
|
|
101
|
+
valueIsDefinedByPlusValueFile: boolean;
|
|
94
102
|
} & ({
|
|
95
103
|
valueIsLoaded: false;
|
|
96
104
|
} | {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export type { PageConfigUserFriendly };
|
|
1
|
+
export { getPageConfigUserFriendly };
|
|
2
|
+
export { getPageConfigUserFriendly_oldDesign };
|
|
3
|
+
export { getPageConfigGlobalUserFriendly };
|
|
5
4
|
export type { PageConfigsUserFriendly };
|
|
5
|
+
export type { PageConfigUserFriendly };
|
|
6
|
+
export type { PageConfigUserFriendlyOld };
|
|
6
7
|
export type { Source };
|
|
7
8
|
export type { Sources };
|
|
8
9
|
export type { From };
|
|
@@ -10,9 +11,10 @@ export type { ExportsAll };
|
|
|
10
11
|
export type { ConfigEntries };
|
|
11
12
|
import type { FileType } from '../getPageFiles/fileTypes.js';
|
|
12
13
|
import type { PageFile } from '../getPageFiles/getPageFileObject.js';
|
|
13
|
-
import type { ConfigValues, PageConfigGlobalRuntime, PageConfigRuntimeLoaded } from './PageConfig.js';
|
|
14
|
+
import type { ConfigValues, PageConfigBuildTime, PageConfigGlobalRuntime, PageConfigRuntime, PageConfigRuntimeLoaded } from './PageConfig.js';
|
|
14
15
|
import { type ConfigDefinedAtOptional } from './getConfigDefinedAt.js';
|
|
15
16
|
import type { ConfigResolved } from './Config/PageContextConfig.js';
|
|
17
|
+
import type { Route } from './Config.js';
|
|
16
18
|
type ExportsAll = Record<string, {
|
|
17
19
|
exportValue: unknown;
|
|
18
20
|
exportSource: string;
|
|
@@ -33,7 +35,7 @@ type ConfigEntries = Record<string, {
|
|
|
33
35
|
configDefinedAt: ConfigDefinedAtOptional;
|
|
34
36
|
configDefinedByFile: string | null;
|
|
35
37
|
}[]>;
|
|
36
|
-
type
|
|
38
|
+
type PageConfigUserFriendlyOld = {
|
|
37
39
|
config: ConfigResolved;
|
|
38
40
|
source: Source;
|
|
39
41
|
sources: Sources;
|
|
@@ -74,18 +76,24 @@ type SourceConfigsComputed = {
|
|
|
74
76
|
type: 'configsComputed';
|
|
75
77
|
value: unknown;
|
|
76
78
|
};
|
|
77
|
-
type
|
|
78
|
-
// pageId
|
|
79
|
-
ConfigUserFriendly & {
|
|
80
|
-
route: string | null;
|
|
81
|
-
}>;
|
|
82
|
-
type ConfigUserFriendly = {
|
|
79
|
+
type PageConfigUserFriendly = {
|
|
83
80
|
config: ConfigResolved;
|
|
84
81
|
_source: Source;
|
|
85
82
|
_sources: Sources;
|
|
86
83
|
_from: From;
|
|
87
84
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
type PageConfigsUserFriendly = Record<string, // pageId
|
|
86
|
+
PageConfigUserFriendlyWithRoute>;
|
|
87
|
+
type WithRoute = {
|
|
88
|
+
route: Route;
|
|
89
|
+
isErrorPage?: undefined;
|
|
90
|
+
} | {
|
|
91
|
+
route?: undefined;
|
|
92
|
+
isErrorPage: true;
|
|
93
|
+
};
|
|
94
|
+
type PageConfigUserFriendlyWithRoute = PageConfigUserFriendly & WithRoute;
|
|
95
|
+
declare function getPageConfigUserFriendly(pageConfigGlobalValues: ConfigValues, pageConfig: PageConfigRuntime | PageConfigBuildTime, pageConfigValues: ConfigValues): [string, PageConfigUserFriendlyWithRoute];
|
|
96
|
+
declare function getPageConfigGlobalUserFriendly({ pageConfigGlobalValues }: {
|
|
97
|
+
pageConfigGlobalValues: ConfigValues;
|
|
98
|
+
}): PageConfigUserFriendly;
|
|
99
|
+
declare function getPageConfigUserFriendly_oldDesign(pageFiles: PageFile[], pageConfig: PageConfigRuntimeLoaded | null, pageConfigGlobal: PageConfigGlobalRuntime): PageConfigUserFriendlyOld;
|
|
@@ -1,20 +1,51 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { getPageConfigUserFriendly };
|
|
2
|
+
export { getPageConfigUserFriendly_oldDesign };
|
|
3
|
+
export { getPageConfigGlobalUserFriendly };
|
|
3
4
|
import { assertDefaultExports, forbiddenDefaultExports } from '../getPageFiles/assert_exports_old_design.js';
|
|
4
5
|
import { getConfigDefinedAtOptional, getDefinedAtString } from './getConfigDefinedAt.js';
|
|
5
6
|
import { getConfigValueFilePathToShowToUser } from './helpers.js';
|
|
6
7
|
import { assert, isObject, assertWarning, assertUsage, makeLast, isBrowser, isScriptFile, isTemplateFile } from '../utils.js';
|
|
7
8
|
import pc from '@brillout/picocolors';
|
|
8
|
-
function
|
|
9
|
-
const
|
|
9
|
+
function getPageConfigUserFriendly(pageConfigGlobalValues, pageConfig, pageConfigValues) {
|
|
10
|
+
const pageConfigUserFriendly = getPageConfigUserFriendly_public({ pageConfigGlobalValues, pageConfigValues });
|
|
11
|
+
let page;
|
|
12
|
+
if (!pageConfig.isErrorPage) {
|
|
13
|
+
const route = pageConfigUserFriendly.config.route ?? pageConfig.routeFilesystem.routeString;
|
|
14
|
+
page = {
|
|
15
|
+
...pageConfigUserFriendly,
|
|
16
|
+
route
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
page = {
|
|
21
|
+
...pageConfigUserFriendly,
|
|
22
|
+
isErrorPage: true
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return [pageConfig.pageId, page];
|
|
26
|
+
}
|
|
27
|
+
function getPageConfigUserFriendly_public({ pageConfigGlobalValues, pageConfigValues }) {
|
|
28
|
+
const pageConfigUserFriendly = getPageConfigUserFriendly_base({ pageConfigGlobalValues, pageConfigValues });
|
|
29
|
+
return getPublicCopy(pageConfigUserFriendly);
|
|
30
|
+
}
|
|
31
|
+
function getPublicCopy(pageConfigUserFriendly) {
|
|
32
|
+
const p = pageConfigUserFriendly;
|
|
10
33
|
return {
|
|
11
|
-
config:
|
|
12
|
-
_source:
|
|
13
|
-
_sources:
|
|
14
|
-
_from:
|
|
34
|
+
config: p.config,
|
|
35
|
+
_source: p.source,
|
|
36
|
+
_sources: p.sources,
|
|
37
|
+
_from: p.from
|
|
15
38
|
};
|
|
16
39
|
}
|
|
17
|
-
function
|
|
40
|
+
function getPageConfigUserFriendly_base({ pageConfigGlobalValues, pageConfigValues }) {
|
|
41
|
+
const configValues = { ...pageConfigGlobalValues, ...pageConfigValues };
|
|
42
|
+
return getPageConfigUserFriendly_V1Design({ configValues });
|
|
43
|
+
}
|
|
44
|
+
function getPageConfigGlobalUserFriendly({ pageConfigGlobalValues }) {
|
|
45
|
+
const pageConfigGlobalUserFriendly = getPageConfigUserFriendly_V1Design({ configValues: pageConfigGlobalValues });
|
|
46
|
+
return getPublicCopy(pageConfigGlobalUserFriendly);
|
|
47
|
+
}
|
|
48
|
+
function getPageConfigUserFriendly_oldDesign(pageFiles, pageConfig, pageConfigGlobal) {
|
|
18
49
|
const config = {};
|
|
19
50
|
const configEntries = {}; // TODO/v1-release: remove
|
|
20
51
|
const exportsAll = {}; // TODO/v1-release: remove
|
|
@@ -39,8 +70,9 @@ function getPageConfigUserFriendlyOld(pageFiles, pageConfig, pageConfigGlobal) {
|
|
|
39
70
|
let sources;
|
|
40
71
|
let from;
|
|
41
72
|
if (pageConfig) {
|
|
42
|
-
const res =
|
|
43
|
-
|
|
73
|
+
const res = getPageConfigUserFriendly_base({
|
|
74
|
+
pageConfigGlobalValues: pageConfigGlobal.configValues,
|
|
75
|
+
pageConfigValues: pageConfig.configValues
|
|
44
76
|
});
|
|
45
77
|
source = res.source;
|
|
46
78
|
sources = res.sources;
|
|
@@ -87,7 +119,7 @@ function getPageConfigUserFriendlyOld(pageFiles, pageConfig, pageConfigGlobal) {
|
|
|
87
119
|
return pageContextExports;
|
|
88
120
|
}
|
|
89
121
|
// V1 design
|
|
90
|
-
function
|
|
122
|
+
function getPageConfigUserFriendly_V1Design(pageConfig) {
|
|
91
123
|
const config = {};
|
|
92
124
|
const configEntries = {};
|
|
93
125
|
const exportsAll = {};
|
|
@@ -2,11 +2,12 @@ export type { PageConfigRuntimeSerialized };
|
|
|
2
2
|
export type { PageConfigGlobalRuntimeSerialized };
|
|
3
3
|
export type { ConfigValueSerialized };
|
|
4
4
|
export type { ValueSerialized };
|
|
5
|
-
import type { ConfigValueStandard, ConfigValueComputed, ConfigValueCumulative, PageConfigRuntime } from '../PageConfig.js';
|
|
5
|
+
import type { ConfigValueStandard, ConfigValueComputed, ConfigValueCumulative, PageConfigCommon, PageConfigRuntime } from '../PageConfig.js';
|
|
6
6
|
/** Page config data structure serialized in virtual files: parsing it results in PageConfigRuntime */
|
|
7
|
-
type PageConfigRuntimeSerialized =
|
|
7
|
+
type PageConfigRuntimeSerialized = PageConfigCommon & {
|
|
8
8
|
/** Config values that are serializable and loaded eagerly such as config.passToClient */
|
|
9
9
|
configValuesSerialized: Record<string, ConfigValueSerialized>;
|
|
10
|
+
loadConfigValuesAll: PageConfigRuntime['loadConfigValuesAll'];
|
|
10
11
|
};
|
|
11
12
|
type PageConfigGlobalRuntimeSerialized = {
|
|
12
13
|
configValuesSerialized: Record<string, ConfigValueSerialized>;
|
|
@@ -12,15 +12,9 @@ function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
|
12
12
|
// pageConfigs
|
|
13
13
|
const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
|
|
14
14
|
const configValues = parseConfigValuesSerialized(pageConfigSerialized.configValuesSerialized);
|
|
15
|
-
const { pageId, isErrorPage, routeFilesystem, loadConfigValuesAll } = pageConfigSerialized;
|
|
16
15
|
assertRouteConfigValue(configValues);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
isErrorPage,
|
|
20
|
-
routeFilesystem,
|
|
21
|
-
configValues,
|
|
22
|
-
loadConfigValuesAll
|
|
23
|
-
};
|
|
16
|
+
const pageConfig = { ...pageConfigSerialized, configValues };
|
|
17
|
+
return pageConfig;
|
|
24
18
|
});
|
|
25
19
|
// pageConfigsGlobal
|
|
26
20
|
const pageConfigGlobal = { configValues: {} };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { serializeConfigValues };
|
|
2
2
|
export { getConfigValuesBase };
|
|
3
|
+
export { isJsonValue };
|
|
3
4
|
export type { FilesEnv };
|
|
4
5
|
import type { ConfigEnvInternal, ConfigValueSource, DefinedAtFile, PageConfigBuildTime, PageConfigGlobalBuildTime } from '../PageConfig.js';
|
|
5
6
|
declare function serializeConfigValues(pageConfig: PageConfigBuildTime | PageConfigGlobalBuildTime, importStatements: string[], filesEnv: FilesEnv, isEnvMatch: (configEnv: ConfigEnvInternal) => boolean, tabspace: string, isEager: boolean | null): string[];
|
|
7
|
+
declare function isJsonValue(value: unknown): boolean;
|
|
6
8
|
declare function getConfigValuesBase(pageConfig: PageConfigBuildTime | PageConfigGlobalBuildTime, isEnvMatch: (configEnv: ConfigEnvInternal) => boolean, isEager: boolean | null): ConfigValuesBase;
|
|
7
9
|
type ConfigValuesBase = ({
|
|
8
10
|
configValueBase: {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export { serializeConfigValues };
|
|
2
2
|
export { getConfigValuesBase };
|
|
3
|
+
export { isJsonValue };
|
|
3
4
|
import { assertIsNotProductionRuntime } from '../../../utils/assertSetup.js';
|
|
4
5
|
import { assert, assertPosixPath, assertUsage, deepEqual, getPropAccessNotation } from '../../../node/plugin/utils.js';
|
|
5
6
|
import { parsePointerImportData } from '../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformPointerImports.js';
|
|
6
7
|
import { getConfigValueFilePathToShowToUser } from '../helpers.js';
|
|
7
8
|
import { stringify } from '@brillout/json-serializer/stringify';
|
|
8
9
|
import pc from '@brillout/picocolors';
|
|
10
|
+
const stringifyOptions = { forbidReactElements: true };
|
|
9
11
|
const REPLACE_ME_BEFORE = '__VIKE__REPLACE_ME_BEFORE__';
|
|
10
12
|
const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
11
13
|
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with parsePageConfigs()
|
|
@@ -44,7 +46,7 @@ function serializeConfigValues(pageConfig, importStatements, filesEnv, isEnvMatc
|
|
|
44
46
|
function getValueSerializedFromSource(configValueSource, configName, importStatements, filesEnv) {
|
|
45
47
|
assert(configValueSource.isOverriden === false);
|
|
46
48
|
let valueData;
|
|
47
|
-
if ('value' in configValueSource) {
|
|
49
|
+
if ('value' in configValueSource && !configValueSource.valueIsLoadedWithImport) {
|
|
48
50
|
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAtFilePath, importStatements, filesEnv, configValueSource.configEnv);
|
|
49
51
|
}
|
|
50
52
|
else {
|
|
@@ -96,14 +98,13 @@ function serializeConfigValue(configValueBase, valueData, configName, lines, tab
|
|
|
96
98
|
}
|
|
97
99
|
function getValueSerializedWithImport(configValueSource, importStatements, filesEnv, configName) {
|
|
98
100
|
assert(!configValueSource.valueIsFilePath);
|
|
99
|
-
const {
|
|
100
|
-
assert(valueIsImportedAtRuntime);
|
|
101
|
+
const { valueIsDefinedByPlusValueFile, definedAtFilePath, configEnv } = configValueSource;
|
|
101
102
|
const { filePathAbsoluteVite, fileExportName } = definedAtFilePath;
|
|
102
|
-
if (
|
|
103
|
+
if (valueIsDefinedByPlusValueFile)
|
|
103
104
|
assert(fileExportName === undefined);
|
|
104
105
|
const { importName } = addImportStatement(importStatements, filePathAbsoluteVite, fileExportName || '*', filesEnv, configEnv, configName);
|
|
105
106
|
return {
|
|
106
|
-
type:
|
|
107
|
+
type: valueIsDefinedByPlusValueFile ? 'plus-file' : 'pointer-import',
|
|
107
108
|
valueAsJsCode: importName
|
|
108
109
|
};
|
|
109
110
|
}
|
|
@@ -120,7 +121,7 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
|
|
|
120
121
|
try {
|
|
121
122
|
configValueSerialized = stringify(value, {
|
|
122
123
|
valueName,
|
|
123
|
-
|
|
124
|
+
...stringifyOptions,
|
|
124
125
|
// Replace import strings with import variables.
|
|
125
126
|
// - We don't need this anymore and could remove it.
|
|
126
127
|
// - We temporarily needed it for nested document configs (`config.document.{title,description,favicon}`), but we finally decided to go for flat document configs instead (`config.{title,description,favicon}`).
|
|
@@ -147,6 +148,15 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
|
|
|
147
148
|
assert(!configValueSerialized.includes(REPLACE_ME_AFTER));
|
|
148
149
|
return configValueSerialized;
|
|
149
150
|
}
|
|
151
|
+
function isJsonValue(value) {
|
|
152
|
+
try {
|
|
153
|
+
stringify(value, stringifyOptions);
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
150
160
|
function logJsonSerializeError(err, configName, definedAtData) {
|
|
151
161
|
/*
|
|
152
162
|
// import { isJsonSerializerError } from '@brillout/json-serializer/stringify'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { executeGuardHook };
|
|
2
|
-
import type {
|
|
2
|
+
import type { PageConfigUserFriendlyOld, PageFile } from '../getPageFiles.js';
|
|
3
3
|
import type { PageConfigRuntime } from '../page-configs/PageConfig.js';
|
|
4
|
-
declare function executeGuardHook<T extends
|
|
4
|
+
declare function executeGuardHook<T extends PageConfigUserFriendlyOld & {
|
|
5
5
|
pageId: string;
|
|
6
6
|
_pageFilesAll: PageFile[];
|
|
7
7
|
_pageConfigs: PageConfigRuntime[];
|
|
@@ -8,7 +8,7 @@ import { getDefinedAtString } from '../page-configs/getConfigDefinedAt.js';
|
|
|
8
8
|
import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
|
|
9
9
|
import { getHookFromPageConfigGlobal, getHookTimeoutDefault } from '../hooks/getHook.js';
|
|
10
10
|
async function loadPageRoutes(
|
|
11
|
-
// Remove all arguments and use
|
|
11
|
+
// Remove all arguments and use GlobalContextInternal instead?
|
|
12
12
|
pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
|
|
13
13
|
// TODO/next-major: remove & make this function sync
|
|
14
14
|
await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
|
|
@@ -131,6 +131,12 @@ type PageContextBuiltInCommon<Data> = {
|
|
|
131
131
|
url: string;
|
|
132
132
|
/** @deprecated */
|
|
133
133
|
pageExports: Record<string, unknown>;
|
|
134
|
+
/**
|
|
135
|
+
* Whether the Base URL is missing in the URL of the HTTP request made to the SSR server.
|
|
136
|
+
*
|
|
137
|
+
* https://vike.dev/base-url#setup
|
|
138
|
+
*/
|
|
139
|
+
isBaseMissing?: true;
|
|
134
140
|
};
|
|
135
141
|
type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageContextUrlServer;
|
|
136
142
|
type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'routeParams' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason' | 'data' | 'pageId' | 'source' | 'sources' | 'from'> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.223-commit-586dbfb";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.223-commit-586dbfb';
|
package/dist/esm/utils/assert.js
CHANGED
|
@@ -42,7 +42,7 @@ function assert(condition, debugInfo) {
|
|
|
42
42
|
const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
|
|
43
43
|
return pc.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
|
|
44
44
|
})();
|
|
45
|
-
const link = pc.blue('https://github.com/vikejs/vike/issues/new');
|
|
45
|
+
const link = pc.blue('https://github.com/vikejs/vike/issues/new?template=bug.yml');
|
|
46
46
|
let errMsg = [
|
|
47
47
|
`You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually within 24 hours).`,
|
|
48
48
|
debugStr
|
|
@@ -16,7 +16,7 @@ import { isVitest } from './isVitest.js';
|
|
|
16
16
|
import pc from '@brillout/picocolors';
|
|
17
17
|
assertIsNotBrowser();
|
|
18
18
|
const debug = createDebugger('vike:setup');
|
|
19
|
-
const setup = getGlobalObject('utils/
|
|
19
|
+
const setup = getGlobalObject('utils/assertSetup.ts', {});
|
|
20
20
|
// Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
|
|
21
21
|
function assertIsNotProductionRuntime() {
|
|
22
22
|
if (debug.isActivated)
|
|
@@ -11,7 +11,7 @@ import pc from '@brillout/picocolors';
|
|
|
11
11
|
/* Use original assertUsage() & assertWarning() after all CJS is removed from node_modules/vike/dist/
|
|
12
12
|
import { assertUsage, assertWarning } from './assert.js'
|
|
13
13
|
*/
|
|
14
|
-
const globalObject = getGlobalObject('assertSingleInstance.ts', {
|
|
14
|
+
const globalObject = getGlobalObject('utils/assertSingleInstance.ts', {
|
|
15
15
|
instances: [],
|
|
16
16
|
alreadyLogged: new Set()
|
|
17
17
|
});
|
|
@@ -22,7 +22,7 @@ function assertSingleInstance() {
|
|
|
22
22
|
const versions = unique(globalObject.instances);
|
|
23
23
|
assertUsage(versions.length <= 1,
|
|
24
24
|
// DO *NOT* patch vike to remove this error: because of multiple conflicting versions, you *will* eventually encounter insidious issues that hard to debug and potentially a security hazard, see for example https://github.com/vikejs/vike/issues/1108
|
|
25
|
-
`vike@${pc.bold(versions[0])} and vike@${pc.bold(versions[1])} loaded but
|
|
25
|
+
`vike@${pc.bold(versions[0])} and vike@${pc.bold(versions[1])} loaded but it's forbidden to load different versions`);
|
|
26
26
|
}
|
|
27
27
|
if (globalObject.checkSingleInstance && globalObject.instances.length > 1) {
|
|
28
28
|
/*/ Not sure whether circular dependency can cause problems? In principle not since client-side code is ESM.
|
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { isArray } from './isArray.js';
|
|
5
5
|
import { assertPosixPath } from './path.js';
|
|
6
|
-
// We need to be able to crawl the filesystem, regardless of Vike's `$ git ls-files` command call, because we need to fallback if the user didn't setup Git (e.g. we cannot remove the
|
|
6
|
+
// We need to be able to crawl the filesystem, regardless of Vike's `$ git ls-files` command call, because we need to fallback if the user didn't setup Git (e.g. we cannot remove the tinyglobby fallback).
|
|
7
7
|
function findFile(arg, cwd) {
|
|
8
8
|
assertPosixPath(cwd);
|
|
9
9
|
const filenames = isArray(arg) ? arg : [arg];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { getGlobalObject };
|
|
2
2
|
export { assertIsSingleModuleInstance };
|
|
3
|
+
type Key = `${string}/${string}.ts`;
|
|
3
4
|
/** Share information across module instances. */
|
|
4
|
-
declare function getGlobalObject<T extends Record<string, unknown> = never>(key:
|
|
5
|
+
declare function getGlobalObject<T extends Record<string, unknown> = never>(key: Key, defaultValue: T): T;
|
|
5
6
|
/** Assert that the module is instantiated only once. */
|
|
6
|
-
declare function assertIsSingleModuleInstance(key:
|
|
7
|
+
declare function assertIsSingleModuleInstance(key: Key): void;
|
|
@@ -2,17 +2,13 @@ export { getGlobalObject };
|
|
|
2
2
|
export { assertIsSingleModuleInstance };
|
|
3
3
|
import { assert } from './assert.js';
|
|
4
4
|
/** Share information across module instances. */
|
|
5
|
-
function getGlobalObject(
|
|
6
|
-
// We use the filename (or file path) as key. There should be only one getGlobalObject() usage per file. Thus the key should be unique, assuming the filename (or file path) is unique.
|
|
7
|
-
key, defaultValue) {
|
|
5
|
+
function getGlobalObject(key, defaultValue) {
|
|
8
6
|
const globalObjects = getGlobalObjects();
|
|
9
7
|
const globalObject = (globalObjects[key] = globalObjects[key] || defaultValue);
|
|
10
8
|
return globalObject;
|
|
11
9
|
}
|
|
12
10
|
/** Assert that the module is instantiated only once. */
|
|
13
|
-
function assertIsSingleModuleInstance(
|
|
14
|
-
// We use the filename (or file path) as key.
|
|
15
|
-
key) {
|
|
11
|
+
function assertIsSingleModuleInstance(key) {
|
|
16
12
|
const globalObjects = getGlobalObjects();
|
|
17
13
|
assert(!(key in globalObjects));
|
|
18
14
|
}
|
|
@@ -28,8 +28,8 @@ function prependBase(url, baseServer) {
|
|
|
28
28
|
return `${baseServerNormalized}${url}`;
|
|
29
29
|
}
|
|
30
30
|
function removeBaseServer(url, baseServer) {
|
|
31
|
-
const {
|
|
32
|
-
assert(
|
|
31
|
+
const { isBaseMissing, origin, pathname, pathnameOriginal, searchOriginal, hashOriginal } = parseUrl(url, baseServer);
|
|
32
|
+
assert(!isBaseMissing);
|
|
33
33
|
assertUrlComponents(url, origin, pathnameOriginal, searchOriginal, hashOriginal);
|
|
34
34
|
const urlWithoutBase = createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal);
|
|
35
35
|
return urlWithoutBase;
|
|
@@ -10,7 +10,6 @@ export { isBaseServer };
|
|
|
10
10
|
export { assertUrlComponents };
|
|
11
11
|
export { createUrlFromComponents };
|
|
12
12
|
export type { UrlPublic };
|
|
13
|
-
export type { UrlPrivate };
|
|
14
13
|
type UrlPublic = {
|
|
15
14
|
/** The full URL. */
|
|
16
15
|
href: string;
|
|
@@ -41,10 +40,10 @@ type UrlPublic = {
|
|
|
41
40
|
/** @deprecated */
|
|
42
41
|
searchString: null | string;
|
|
43
42
|
};
|
|
44
|
-
type
|
|
45
|
-
|
|
43
|
+
type UrlInternal = Omit<UrlPublic, 'hashString' | 'searchString'> & {
|
|
44
|
+
isBaseMissing: boolean;
|
|
46
45
|
};
|
|
47
|
-
declare function parseUrl(url: string, baseServer: string):
|
|
46
|
+
declare function parseUrl(url: string, baseServer: string): UrlInternal;
|
|
48
47
|
declare function isBaseServer(baseServer: string): boolean;
|
|
49
48
|
declare function assertUrlComponents(url: string, origin: string | null, pathnameOriginal: string, searchOriginal: string | null, hashOriginal: string | null): void;
|
|
50
49
|
declare function createUrlFromComponents(origin: string | null, pathname: string, search: string | null, hash: string | null): string;
|
|
@@ -45,7 +45,7 @@ function parseUrl(url, baseServer) {
|
|
|
45
45
|
const pathnameOriginal = urlWithoutHashNorSearch.slice((origin || '').length);
|
|
46
46
|
assertUrlComponents(url, origin, pathnameOriginal, searchOriginal, hashOriginal);
|
|
47
47
|
// Base URL
|
|
48
|
-
let { pathname,
|
|
48
|
+
let { pathname, isBaseMissing } = removeBaseServer(pathnameAbsoluteWithBase, baseServer);
|
|
49
49
|
// pageContext.urlParsed.href
|
|
50
50
|
const href = createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal);
|
|
51
51
|
// pageContext.urlParsed.{hostname, port}
|
|
@@ -62,7 +62,7 @@ function parseUrl(url, baseServer) {
|
|
|
62
62
|
origin,
|
|
63
63
|
pathname,
|
|
64
64
|
pathnameOriginal: pathnameOriginal,
|
|
65
|
-
|
|
65
|
+
isBaseMissing,
|
|
66
66
|
search,
|
|
67
67
|
searchAll,
|
|
68
68
|
searchOriginal,
|
|
@@ -231,7 +231,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
|
|
|
231
231
|
assert(baseServer.startsWith('/'));
|
|
232
232
|
if (baseServer === '/') {
|
|
233
233
|
const pathname = pathnameAbsoluteWithBase;
|
|
234
|
-
return { pathname,
|
|
234
|
+
return { pathname, isBaseMissing: false };
|
|
235
235
|
}
|
|
236
236
|
// Support `url === '/some-base-url' && baseServer === '/some-base-url/'`
|
|
237
237
|
let baseServerNormalized = baseServer;
|
|
@@ -241,7 +241,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
|
|
|
241
241
|
}
|
|
242
242
|
if (!urlPathname.startsWith(baseServerNormalized)) {
|
|
243
243
|
const pathname = pathnameAbsoluteWithBase;
|
|
244
|
-
return { pathname,
|
|
244
|
+
return { pathname, isBaseMissing: true };
|
|
245
245
|
}
|
|
246
246
|
assert(urlPathname.startsWith('/') || urlPathname.startsWith('http'));
|
|
247
247
|
assert(urlPathname.startsWith(baseServerNormalized));
|
|
@@ -249,7 +249,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
|
|
|
249
249
|
if (!urlPathname.startsWith('/'))
|
|
250
250
|
urlPathname = '/' + urlPathname;
|
|
251
251
|
assert(urlPathname.startsWith('/'));
|
|
252
|
-
return { pathname: urlPathname,
|
|
252
|
+
return { pathname: urlPathname, isBaseMissing: false };
|
|
253
253
|
}
|
|
254
254
|
function isBaseServer(baseServer) {
|
|
255
255
|
return baseServer.startsWith('/');
|