vike 0.4.221 → 0.4.222-commit-6647d1e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/api/prepareViteApiCall.js +18 -16
- package/dist/cjs/node/plugin/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/baseUrls.js +6 -1
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +8 -10
- package/dist/cjs/node/plugin/plugins/buildConfig.js +0 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +4 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +73 -39
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +64 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +0 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +2 -40
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +6 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +45 -21
- package/dist/cjs/node/runtime/globalContext.js +24 -8
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +3 -3
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -4
- package/dist/cjs/node/runtime/renderPage.js +4 -8
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +3 -3
- package/dist/cjs/node/shared/resolveBase.js +0 -13
- package/dist/cjs/shared/getPageConfigsRuntime.js +5 -2
- package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +45 -11
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -8
- package/dist/cjs/shared/route/loadPageRoutes.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSingleInstance.js +1 -1
- package/dist/cjs/utils/debug.js +9 -6
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +4 -4
- 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 +5 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +9 -2
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +2 -1
- package/dist/esm/client/server-routing-runtime/getPageContext.js +4 -3
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.d.ts +5 -4
- package/dist/esm/client/shared/loadUserFilesClientSide.js +3 -3
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/api/prepareViteApiCall.d.ts +2 -2
- package/dist/esm/node/api/prepareViteApiCall.js +18 -16
- package/dist/esm/node/plugin/index.d.ts +4 -1
- package/dist/esm/node/plugin/index.js +1 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +6 -1
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +0 -2
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +8 -10
- package/dist/esm/node/plugin/plugins/buildConfig.js +1 -2
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -0
- package/dist/esm/node/plugin/plugins/commonConfig.js +4 -1
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +73 -39
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +4 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +65 -15
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +0 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.d.ts +0 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +2 -37
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +6 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +47 -23
- package/dist/esm/node/runtime/globalContext.d.ts +11 -8
- package/dist/esm/node/runtime/globalContext.js +24 -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/executeOnBeforeRenderAndDataHooks.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +3 -3
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +4 -4
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- 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.js +4 -8
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +3 -3
- 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 +3 -2
- package/dist/esm/shared/getPageConfigsRuntime.js +6 -3
- package/dist/esm/shared/getPageFiles.d.ts +1 -1
- package/dist/esm/shared/hooks/getHook.d.ts +3 -3
- package/dist/esm/shared/page-configs/Config.d.ts +3 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +9 -2
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +24 -10
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +45 -11
- 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/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +1 -1
- package/dist/esm/shared/types.d.ts +9 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSingleInstance.js +1 -1
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +9 -6
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ export { getPageContextFromClientHooks };
|
|
|
5
5
|
export { setPageContextInitIsPassedToClient };
|
|
6
6
|
export type { PageContextFromServerHooks };
|
|
7
7
|
export type { PageContextFromClientHooks };
|
|
8
|
-
import type {
|
|
8
|
+
import type { PageConfigUserFriendlyOld, PageFile } from '../../shared/getPageFiles.js';
|
|
9
9
|
import type { PageConfigRuntime } from '../../shared/page-configs/PageConfig.js';
|
|
10
10
|
type PageContext = {
|
|
11
11
|
urlOriginal: string;
|
|
@@ -21,9 +21,9 @@ declare function getPageContextFromHooks_serialized(): PageContextSerialized & {
|
|
|
21
21
|
routeParams: Record<string, string>;
|
|
22
22
|
_hasPageContextFromServer: true;
|
|
23
23
|
};
|
|
24
|
-
declare function getPageContextFromHooks_isHydration(pageContext: PageContextSerialized & PageContext &
|
|
24
|
+
declare function getPageContextFromHooks_isHydration(pageContext: PageContextSerialized & PageContext & PageConfigUserFriendlyOld & {
|
|
25
25
|
_hasPageContextFromServer: true;
|
|
26
|
-
}): Promise<PageContextSerialized & PageContext &
|
|
26
|
+
}): Promise<PageContextSerialized & PageContext & PageConfigUserFriendlyOld & {
|
|
27
27
|
_hasPageContextFromServer: true;
|
|
28
28
|
} & {
|
|
29
29
|
_hasPageContextFromClient: boolean;
|
|
@@ -45,5 +45,5 @@ type PageContextFromClientHooks = {
|
|
|
45
45
|
declare function getPageContextFromClientHooks(pageContext: {
|
|
46
46
|
pageId: string;
|
|
47
47
|
_hasPageContextFromServer: boolean;
|
|
48
|
-
} & PageContext &
|
|
48
|
+
} & PageContext & PageConfigUserFriendlyOld, isErrorPage: boolean): Promise<PageContextFromClientHooks>;
|
|
49
49
|
declare function setPageContextInitIsPassedToClient(pageContext: Record<string, unknown>): void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { getPrefetchSettings };
|
|
2
2
|
export { PAGE_CONTEXT_MAX_AGE_DEFAULT };
|
|
3
3
|
export type { PrefetchSettingResolved };
|
|
4
|
-
import type {
|
|
4
|
+
import type { PageConfigUserFriendlyOld } from '../../../shared/getPageFiles.js';
|
|
5
5
|
declare const PAGE_CONTEXT_MAX_AGE_DEFAULT = 5000;
|
|
6
6
|
type PrefetchSettingResolved = {
|
|
7
7
|
staticAssets: false | 'hover' | 'viewport';
|
|
8
8
|
pageContext: false | number;
|
|
9
9
|
};
|
|
10
|
-
declare function getPrefetchSettings(pageContext:
|
|
10
|
+
declare function getPrefetchSettings(pageContext: PageConfigUserFriendlyOld, linkTag: null | HTMLElement): PrefetchSettingResolved;
|
|
@@ -6,7 +6,7 @@ export { addLinkPrefetchHandlers };
|
|
|
6
6
|
export { addLinkPrefetchHandlers_watch };
|
|
7
7
|
export { addLinkPrefetchHandlers_unwatch };
|
|
8
8
|
import { type PageContextFromServerHooks, getPageContextFromServerHooks } from './getPageContextFromHooks.js';
|
|
9
|
-
import type {
|
|
9
|
+
import type { PageConfigUserFriendlyOld, PageFile } from '../../shared/getPageFiles.js';
|
|
10
10
|
import { type PageConfigRuntime } from '../../shared/page-configs/PageConfig.js';
|
|
11
11
|
type ResultPageContextFromServer = Awaited<ReturnType<typeof getPageContextFromServerHooks>>;
|
|
12
12
|
type PageContextForPrefetch = {
|
|
@@ -19,7 +19,7 @@ type PageContextForPrefetch = {
|
|
|
19
19
|
};
|
|
20
20
|
declare function getPageContextPrefetched(pageContext: {
|
|
21
21
|
urlPathname: string;
|
|
22
|
-
} &
|
|
22
|
+
} & PageConfigUserFriendlyOld): null | PageContextFromServerHooks;
|
|
23
23
|
declare function populatePageContextPrefetchCache(pageContext: PageContextForPrefetch, result: ResultPageContextFromServer): void;
|
|
24
24
|
/**
|
|
25
25
|
* Programmatically prefetch client assets.
|
|
@@ -45,7 +45,7 @@ function getPageContextPrefetched(pageContext) {
|
|
|
45
45
|
}
|
|
46
46
|
async function prefetchAssets(pageContextLink) {
|
|
47
47
|
try {
|
|
48
|
-
await loadUserFilesClientSide(pageContextLink.pageId, pageContextLink._pageFilesAll, pageContextLink._pageConfigs);
|
|
48
|
+
await loadUserFilesClientSide(pageContextLink.pageId, pageContextLink._pageFilesAll, pageContextLink._pageConfigs, pageContextLink._pageConfigGlobal);
|
|
49
49
|
}
|
|
50
50
|
catch (err) {
|
|
51
51
|
if (isErrorFetchingStaticAssets(err)) {
|
|
@@ -60,8 +60,8 @@ async function prefetchPageContextFromServerHooks(pageContextLink, resultMaxAge)
|
|
|
60
60
|
const result = await getPageContextFromServerHooks(pageContextLink, false);
|
|
61
61
|
setPageContextPrefetchCache(pageContextLink, result, resultMaxAge);
|
|
62
62
|
}
|
|
63
|
-
function populatePageContextPrefetchCache(pageContext /*&
|
|
64
|
-
// TODO/pageContext-prefetch: replace with using pageContext.config.prerender instead. (For being able to do that: eager configs need to be accessible without have to use
|
|
63
|
+
function populatePageContextPrefetchCache(pageContext /*& PageConfigUserFriendlyOld*/, result) {
|
|
64
|
+
// TODO/pageContext-prefetch: replace with using pageContext.config.prerender instead. (For being able to do that: eager configs need to be accessible without have to use PageConfigUserFriendlyOld as it isn't available here.)
|
|
65
65
|
if (!isBrilloutDocpress())
|
|
66
66
|
return;
|
|
67
67
|
setPageContextPrefetchCache(pageContext, result, null);
|
|
@@ -17,5 +17,10 @@ type RenderArgs = {
|
|
|
17
17
|
pageContextInitClient?: Record<string, unknown>;
|
|
18
18
|
};
|
|
19
19
|
declare function renderPageClientSide(renderArgs: RenderArgs): Promise<void>;
|
|
20
|
+
declare global {
|
|
21
|
+
var _vike: {
|
|
22
|
+
fullyRenderedUrl?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
20
25
|
declare function disableClientRouting(err: unknown, log: boolean): void;
|
|
21
26
|
declare function getRenderCount(): number;
|
|
@@ -131,7 +131,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
131
131
|
objectAssign(pageContext, pageContextFromRoute);
|
|
132
132
|
}
|
|
133
133
|
try {
|
|
134
|
-
objectAssign(pageContext, await loadUserFilesClientSide(pageContext.pageId, pageContext._pageFilesAll, pageContext._pageConfigs));
|
|
134
|
+
objectAssign(pageContext, await loadUserFilesClientSide(pageContext.pageId, pageContext._pageFilesAll, pageContext._pageConfigs, pageContext._pageConfigGlobal));
|
|
135
135
|
}
|
|
136
136
|
catch (err) {
|
|
137
137
|
if (handleErrorFetchingStaticAssets(err, pageContext, isFirstRender)) {
|
|
@@ -336,7 +336,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
336
336
|
return;
|
|
337
337
|
}
|
|
338
338
|
try {
|
|
339
|
-
objectAssign(pageContext, await loadUserFilesClientSide(pageContext.pageId, pageContext._pageFilesAll, pageContext._pageConfigs));
|
|
339
|
+
objectAssign(pageContext, await loadUserFilesClientSide(pageContext.pageId, pageContext._pageFilesAll, pageContext._pageConfigs, pageContext._pageConfigGlobal));
|
|
340
340
|
}
|
|
341
341
|
catch (err) {
|
|
342
342
|
if (handleErrorFetchingStaticAssets(err, pageContext, isFirstRender)) {
|
|
@@ -484,8 +484,15 @@ async function renderPageClientSide(renderArgs) {
|
|
|
484
484
|
// Add link prefetch handlers
|
|
485
485
|
addLinkPrefetchHandlers_watch();
|
|
486
486
|
addLinkPrefetchHandlers();
|
|
487
|
+
stampFinished(urlOriginal);
|
|
487
488
|
}
|
|
488
489
|
}
|
|
490
|
+
// For Vike tests (but also potentially for Vike users)
|
|
491
|
+
// https://github.com/vikejs/vike/blob/ffbc5cf16407bcc075f414447e50d997c87c0c94/test/playground/pages/nested-layout/e2e-test.ts#L59
|
|
492
|
+
function stampFinished(urlOriginal) {
|
|
493
|
+
window._vike ?? (window._vike = {});
|
|
494
|
+
window._vike.fullyRenderedUrl = urlOriginal;
|
|
495
|
+
}
|
|
489
496
|
function changeUrl(url, overwriteLastHistoryEntry) {
|
|
490
497
|
if (getCurrentUrl() === url)
|
|
491
498
|
return;
|
|
@@ -10,6 +10,7 @@ declare function getPageContext(): Promise<{
|
|
|
10
10
|
} & {
|
|
11
11
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
12
12
|
_pageConfigs: import("../../__internal/index.js").PageConfig[];
|
|
13
|
-
|
|
13
|
+
_pageConfigGlobal: import("../../shared/page-configs/PageConfig.js").PageConfigGlobalRuntime;
|
|
14
|
+
} & import("../../shared/getPageFiles.js").PageConfigUserFriendlyOld & {
|
|
14
15
|
_pageFilesLoaded: import("../../shared/getPageFiles.js").PageFile[];
|
|
15
16
|
}>;
|
|
@@ -6,7 +6,7 @@ import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
|
6
6
|
import { getPageConfigsRuntime } from '../../shared/getPageConfigsRuntime.js';
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
import * as virtualFileExports from 'virtual:vike:importUserCode:client:server-routing';
|
|
9
|
-
const { pageFilesAll, pageConfigs } = getPageConfigsRuntime(virtualFileExports);
|
|
9
|
+
const { pageFilesAll, pageConfigs, pageConfigGlobal } = getPageConfigsRuntime(virtualFileExports);
|
|
10
10
|
const urlFirst = getCurrentUrl({ withoutHash: true });
|
|
11
11
|
async function getPageContext() {
|
|
12
12
|
const pageContext = getPageContextSerializedInHtml();
|
|
@@ -28,9 +28,10 @@ async function loadPageUserFiles(pageId) {
|
|
|
28
28
|
const pageContextAddendum = {};
|
|
29
29
|
objectAssign(pageContextAddendum, {
|
|
30
30
|
_pageFilesAll: pageFilesAll,
|
|
31
|
-
_pageConfigs: pageConfigs
|
|
31
|
+
_pageConfigs: pageConfigs,
|
|
32
|
+
_pageConfigGlobal: pageConfigGlobal
|
|
32
33
|
});
|
|
33
|
-
objectAssign(pageContextAddendum, await loadUserFilesClientSide(pageId, pageContextAddendum._pageFilesAll, pageContextAddendum._pageConfigs));
|
|
34
|
+
objectAssign(pageContextAddendum, await loadUserFilesClientSide(pageId, pageContextAddendum._pageFilesAll, pageContextAddendum._pageConfigs, pageContextAddendum._pageConfigGlobal));
|
|
34
35
|
pageFilesAll
|
|
35
36
|
.filter((p) => p.fileType !== '.page.server')
|
|
36
37
|
.forEach((p) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { executeOnRenderClientHook };
|
|
2
2
|
export type { PageContextBeforeRenderClient };
|
|
3
|
-
import type { PageFile,
|
|
3
|
+
import type { PageFile, PageConfigUserFriendlyOld } from '../../shared/getPageFiles.js';
|
|
4
4
|
import { type PageContextForUserConsumptionClientSide } from './preparePageContextForUserConsumptionClientSide.js';
|
|
5
5
|
import type { PageConfigRuntime } from '../../shared/page-configs/PageConfig.js';
|
|
6
6
|
type PageContextBeforeRenderClient = {
|
|
@@ -9,5 +9,5 @@ type PageContextBeforeRenderClient = {
|
|
|
9
9
|
urlPathname?: string;
|
|
10
10
|
pageId: string;
|
|
11
11
|
_pageConfigs: PageConfigRuntime[];
|
|
12
|
-
} &
|
|
12
|
+
} & PageConfigUserFriendlyOld & PageContextForUserConsumptionClientSide;
|
|
13
13
|
declare function executeOnRenderClientHook<PC extends PageContextBeforeRenderClient>(pageContext: PC, isClientRouting: boolean): Promise<void>;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export { loadUserFilesClientSide };
|
|
2
2
|
export { isErrorFetchingStaticAssets };
|
|
3
3
|
export type { PageContextUserFiles };
|
|
4
|
-
import { type PageFile, type
|
|
5
|
-
import type { PageConfigRuntime } from '../../shared/page-configs/PageConfig.js';
|
|
6
|
-
type PageContextUserFilesLoaded =
|
|
4
|
+
import { type PageFile, type PageConfigUserFriendlyOld } from '../../shared/getPageFiles.js';
|
|
5
|
+
import type { PageConfigGlobalRuntime, PageConfigRuntime } from '../../shared/page-configs/PageConfig.js';
|
|
6
|
+
type PageContextUserFilesLoaded = PageConfigUserFriendlyOld & {
|
|
7
7
|
_pageFilesLoaded: PageFile[];
|
|
8
8
|
};
|
|
9
9
|
type PageContextUserFiles = {
|
|
10
10
|
_pageFilesAll: PageFile[];
|
|
11
11
|
_pageConfigs: PageConfigRuntime[];
|
|
12
|
+
_pageConfigGlobal: PageConfigGlobalRuntime;
|
|
12
13
|
};
|
|
13
|
-
declare function loadUserFilesClientSide(pageId: string, pageFilesAll: PageFile[], pageConfigs: PageConfigRuntime[]): Promise<PageContextUserFilesLoaded>;
|
|
14
|
+
declare function loadUserFilesClientSide(pageId: string, pageFilesAll: PageFile[], pageConfigs: PageConfigRuntime[], pageConfigGlobal: PageConfigGlobalRuntime): Promise<PageContextUserFilesLoaded>;
|
|
14
15
|
declare function isErrorFetchingStaticAssets(err: unknown): boolean;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export { loadUserFilesClientSide };
|
|
2
2
|
export { isErrorFetchingStaticAssets };
|
|
3
3
|
import { getPageFilesClientSide } from '../../shared/getPageFiles.js';
|
|
4
|
-
import {
|
|
4
|
+
import { getPageConfigUserFriendly_oldDesign } from '../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
5
5
|
import { findPageConfig } from '../../shared/page-configs/findPageConfig.js';
|
|
6
6
|
import { loadConfigValues } from '../../shared/page-configs/loadConfigValues.js';
|
|
7
7
|
import { objectAssign } from '../server-routing-runtime/utils.js';
|
|
8
8
|
const stamp = '__whileFetchingAssets';
|
|
9
|
-
async function loadUserFilesClientSide(pageId, pageFilesAll, pageConfigs) {
|
|
9
|
+
async function loadUserFilesClientSide(pageId, pageFilesAll, pageConfigs, pageConfigGlobal) {
|
|
10
10
|
const pageFilesClientSide = getPageFilesClientSide(pageFilesAll, pageId);
|
|
11
11
|
const pageConfig = findPageConfig(pageConfigs, pageId);
|
|
12
12
|
let pageConfigLoaded;
|
|
@@ -30,7 +30,7 @@ async function loadUserFilesClientSide(pageId, pageFilesAll, pageConfigs) {
|
|
|
30
30
|
}
|
|
31
31
|
throw err;
|
|
32
32
|
}
|
|
33
|
-
const pageContextExports =
|
|
33
|
+
const pageContextExports = getPageConfigUserFriendly_oldDesign(pageFilesClientSide, pageConfigLoaded, pageConfigGlobal);
|
|
34
34
|
const pageContextAddendum = {};
|
|
35
35
|
objectAssign(pageContextAddendum, pageContextExports);
|
|
36
36
|
objectAssign(pageContextAddendum, { _pageFilesLoaded: pageFilesClientSide });
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { preparePageContextForUserConsumptionClientSide };
|
|
2
2
|
export type { PageContextForUserConsumptionClientSide };
|
|
3
|
-
import type {
|
|
3
|
+
import type { PageConfigUserFriendlyOld } from '../../shared/getPageFiles.js';
|
|
4
4
|
import type { PageConfigRuntime } from '../../shared/page-configs/PageConfig.js';
|
|
5
5
|
import { PageContextForPassToClientWarning } from './getPageContextProxyForUser.js';
|
|
6
|
-
type PageContextForUserConsumptionClientSide =
|
|
6
|
+
type PageContextForUserConsumptionClientSide = PageConfigUserFriendlyOld & PageContextForPassToClientWarning & {
|
|
7
7
|
pageId: string;
|
|
8
8
|
_pageConfigs: PageConfigRuntime[];
|
|
9
9
|
};
|
|
@@ -5,10 +5,10 @@ export { normalizeViteRoot };
|
|
|
5
5
|
import type { InlineConfig, ResolvedConfig } from 'vite';
|
|
6
6
|
import type { Operation } from './types.js';
|
|
7
7
|
import { type VikeConfigObject } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
8
|
-
declare function prepareViteApiCall(
|
|
8
|
+
declare function prepareViteApiCall(viteConfigFromOptions: InlineConfig | undefined, operation: Operation): Promise<{
|
|
9
9
|
vikeConfig: VikeConfigObject;
|
|
10
10
|
viteConfigEnhanced: InlineConfig | undefined;
|
|
11
11
|
}>;
|
|
12
|
-
declare function getViteRoot(operation:
|
|
12
|
+
declare function getViteRoot(operation: Operation): Promise<string>;
|
|
13
13
|
declare function normalizeViteRoot(root: string): string;
|
|
14
14
|
declare function assertViteRoot(root: string, config: ResolvedConfig): void;
|
|
@@ -11,18 +11,18 @@ import { assert, assertUsage, getGlobalObject, isObject, toPosixPath } from './u
|
|
|
11
11
|
import pc from '@brillout/picocolors';
|
|
12
12
|
import { clearGlobalContext } from '../runtime/globalContext.js';
|
|
13
13
|
const globalObject = getGlobalObject('prepareViteApiCall.ts', {});
|
|
14
|
-
async function prepareViteApiCall(
|
|
14
|
+
async function prepareViteApiCall(viteConfigFromOptions, operation) {
|
|
15
15
|
clear();
|
|
16
16
|
setContextApiOperation(operation);
|
|
17
|
-
return enhanceViteConfig(
|
|
17
|
+
return enhanceViteConfig(viteConfigFromOptions, operation);
|
|
18
18
|
}
|
|
19
19
|
// For subsequent API calls, e.g. calling prerender() after build()
|
|
20
20
|
function clear() {
|
|
21
21
|
clearContextApiOperation();
|
|
22
22
|
clearGlobalContext();
|
|
23
23
|
}
|
|
24
|
-
async function enhanceViteConfig(
|
|
25
|
-
const viteInfo = await getInfoFromVite(
|
|
24
|
+
async function enhanceViteConfig(viteConfigFromOptions, operation) {
|
|
25
|
+
const viteInfo = await getInfoFromVite(viteConfigFromOptions, operation);
|
|
26
26
|
await assertViteRoot2(viteInfo.root, viteInfo.viteConfigEnhanced, operation);
|
|
27
27
|
const vikeConfig = await getVikeConfig2(viteInfo.root, operation === 'dev', viteInfo.vikeVitePluginOptions);
|
|
28
28
|
const viteConfigEnhanced = addViteSettingsSetByVikeConfig(viteInfo.viteConfigEnhanced, vikeConfig);
|
|
@@ -38,6 +38,7 @@ function addViteSettingsSetByVikeConfig(viteConfigEnhanced, vikeConfig) {
|
|
|
38
38
|
viteConfigs.values.forEach((v) => {
|
|
39
39
|
assertUsage(isObject(v.value), `${v.definedAt} should be an object`);
|
|
40
40
|
viteConfigEnhanced = mergeConfig(viteConfigEnhanced ?? {}, v.value);
|
|
41
|
+
assertUsage(!findVikeVitePlugin(v.value), "Using the +vite setting to add Vike's Vite plugin is forbidden");
|
|
41
42
|
});
|
|
42
43
|
return viteConfigEnhanced;
|
|
43
44
|
}
|
|
@@ -47,13 +48,14 @@ async function getViteRoot(operation) {
|
|
|
47
48
|
assert(globalObject.root);
|
|
48
49
|
return globalObject.root;
|
|
49
50
|
}
|
|
50
|
-
async function getInfoFromVite(
|
|
51
|
-
const
|
|
52
|
-
const root = normalizeViteRoot(
|
|
51
|
+
async function getInfoFromVite(viteConfigFromOptions, operation) {
|
|
52
|
+
const viteConfigFromUserViteFile = await loadViteConfigFile(viteConfigFromOptions, operation);
|
|
53
|
+
const root = normalizeViteRoot(viteConfigFromUserViteFile?.root ?? viteConfigFromOptions?.root ?? process.cwd());
|
|
53
54
|
globalObject.root = root;
|
|
54
55
|
let vikeVitePluginOptions;
|
|
55
|
-
let viteConfigEnhanced =
|
|
56
|
-
|
|
56
|
+
let viteConfigEnhanced = viteConfigFromOptions;
|
|
57
|
+
// If Vike's Vite plugin is found in both viteConfigFromOptions and viteConfigFromUserViteFile then Vike will later throw an error
|
|
58
|
+
const found = findVikeVitePlugin(viteConfigFromOptions) || findVikeVitePlugin(viteConfigFromUserViteFile);
|
|
57
59
|
if (found) {
|
|
58
60
|
vikeVitePluginOptions = found.vikeVitePluginOptions;
|
|
59
61
|
}
|
|
@@ -62,20 +64,20 @@ async function getInfoFromVite(viteConfig, operation) {
|
|
|
62
64
|
// Using a dynamic import because the script calling the Vike API may not live in the same place as vite.config.js, thus vike/plugin may resolved to two different node_modules/vike directories.
|
|
63
65
|
const { plugin: vikePlugin } = await import('../plugin/index.js');
|
|
64
66
|
viteConfigEnhanced = {
|
|
65
|
-
...
|
|
66
|
-
plugins: [...(
|
|
67
|
+
...viteConfigFromOptions,
|
|
68
|
+
plugins: [...(viteConfigFromOptions?.plugins ?? []), vikePlugin()]
|
|
67
69
|
};
|
|
68
|
-
const res = findVikeVitePlugin(viteConfigEnhanced
|
|
70
|
+
const res = findVikeVitePlugin(viteConfigEnhanced);
|
|
69
71
|
assert(res);
|
|
70
72
|
vikeVitePluginOptions = res.vikeVitePluginOptions;
|
|
71
73
|
}
|
|
72
74
|
assert(vikeVitePluginOptions);
|
|
73
75
|
return { root, vikeVitePluginOptions, viteConfigEnhanced };
|
|
74
76
|
}
|
|
75
|
-
function findVikeVitePlugin(
|
|
77
|
+
function findVikeVitePlugin(viteConfig) {
|
|
76
78
|
let vikeVitePluginOptions;
|
|
77
79
|
let vikeVitePuginFound = false;
|
|
78
|
-
plugins
|
|
80
|
+
viteConfig?.plugins?.forEach((p) => {
|
|
79
81
|
if (p && '__vikeVitePluginOptions' in p) {
|
|
80
82
|
vikeVitePuginFound = true;
|
|
81
83
|
const options = p.__vikeVitePluginOptions;
|
|
@@ -88,8 +90,8 @@ function findVikeVitePlugin(plugins) {
|
|
|
88
90
|
return { vikeVitePluginOptions };
|
|
89
91
|
}
|
|
90
92
|
// Copied from https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L961-L1005
|
|
91
|
-
async function loadViteConfigFile(
|
|
92
|
-
const [inlineConfig, command, defaultMode, _defaultNodeEnv, isPreview] = getResolveConfigArgs(
|
|
93
|
+
async function loadViteConfigFile(viteConfigFromOptions, operation) {
|
|
94
|
+
const [inlineConfig, command, defaultMode, _defaultNodeEnv, isPreview] = getResolveConfigArgs(viteConfigFromOptions, operation);
|
|
93
95
|
let config = inlineConfig;
|
|
94
96
|
let mode = inlineConfig.mode || defaultMode;
|
|
95
97
|
const configEnv = {
|
|
@@ -4,7 +4,10 @@ export { plugin as ssr };
|
|
|
4
4
|
export type { VikeVitePluginOptions as UserConfig };
|
|
5
5
|
export type { VikeVitePluginOptions };
|
|
6
6
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
7
|
-
|
|
7
|
+
type PluginInterop = Record<string, unknown> & {
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
declare function plugin(vikeVitePluginOptions?: VikeVitePluginOptions): PluginInterop[];
|
|
8
11
|
/** @deprecated Define Vike settings in +config.js instead of vite.config.js */
|
|
9
12
|
type VikeVitePluginOptions = {
|
|
10
13
|
/** @deprecated Define Vike settings in +config.js instead of vite.config.js */
|
|
@@ -29,7 +29,7 @@ import { workaroundVite6HmrRegression } from './plugins/workaroundVite6HmrRegres
|
|
|
29
29
|
import { buildApp } from './plugins/buildApp.js';
|
|
30
30
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
31
31
|
setResolveClientEntriesDev(resolveClientEntriesDev);
|
|
32
|
-
// Return
|
|
32
|
+
// Return `PluginInterop` instead of `Plugin` to avoid type mismatch upon different Vite versions
|
|
33
33
|
function plugin(vikeVitePluginOptions = {}) {
|
|
34
34
|
const plugins = [
|
|
35
35
|
...commonConfig(vikeVitePluginOptions),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { baseUrls };
|
|
2
|
-
import { resolveBase
|
|
2
|
+
import { resolveBase } from '../../shared/resolveBase.js';
|
|
3
3
|
import { assert } from '../utils.js';
|
|
4
4
|
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
5
5
|
function baseUrls() {
|
|
@@ -38,3 +38,8 @@ function baseUrls() {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
+
function resolveBaseFromResolvedConfig(baseServer, baseAssets, config) {
|
|
42
|
+
let baseViteOriginal = config._baseViteOriginal;
|
|
43
|
+
assert(baseViteOriginal === null || typeof baseViteOriginal == 'string');
|
|
44
|
+
return resolveBase(baseViteOriginal, baseServer, baseAssets);
|
|
45
|
+
}
|
|
@@ -2,7 +2,6 @@ export { fixServerAssets };
|
|
|
2
2
|
export { fixServerAssets_isEnabled };
|
|
3
3
|
export { fixServerAssets_assertCssCodeSplit };
|
|
4
4
|
export { fixServerAssets_assertCssTarget };
|
|
5
|
-
export { fixServerAssets_assertCssTarget_populate };
|
|
6
5
|
import { ViteManifest } from '../../../shared/ViteManifest.js';
|
|
7
6
|
import { ResolvedConfig } from 'vite';
|
|
8
7
|
/**
|
|
@@ -18,5 +17,4 @@ declare function fixServerAssets(config: ResolvedConfig): Promise<{
|
|
|
18
17
|
serverManifestMod: ViteManifest;
|
|
19
18
|
}>;
|
|
20
19
|
declare function fixServerAssets_assertCssCodeSplit(config: ResolvedConfig): void;
|
|
21
|
-
declare function fixServerAssets_assertCssTarget_populate(config: ResolvedConfig): void;
|
|
22
20
|
declare function fixServerAssets_assertCssTarget(config: ResolvedConfig): Promise<void>;
|
|
@@ -2,7 +2,6 @@ export { fixServerAssets };
|
|
|
2
2
|
export { fixServerAssets_isEnabled };
|
|
3
3
|
export { fixServerAssets_assertCssCodeSplit };
|
|
4
4
|
export { fixServerAssets_assertCssTarget };
|
|
5
|
-
export { fixServerAssets_assertCssTarget_populate };
|
|
6
5
|
import fs from 'fs/promises';
|
|
7
6
|
import fs_sync from 'fs';
|
|
8
7
|
import path from 'path';
|
|
@@ -195,17 +194,15 @@ function fixServerAssets_assertCssCodeSplit(config) {
|
|
|
195
194
|
assertWarning(config.build.cssCodeSplit, `${pc.cyan('build.cssCodeSplit')} shouldn't be set to ${pc.cyan('false')} (https://github.com/vikejs/vike/issues/1993)`, { onlyOnce: true });
|
|
196
195
|
}
|
|
197
196
|
const targets = [];
|
|
198
|
-
function fixServerAssets_assertCssTarget_populate(config) {
|
|
199
|
-
const isServerSide = viteIsSSR(config);
|
|
200
|
-
assert(typeof isServerSide === 'boolean');
|
|
201
|
-
assert(config.build.target !== undefined);
|
|
202
|
-
targets.push({ global: config.build.target, css: config.build.cssTarget, isServerSide });
|
|
203
|
-
}
|
|
204
197
|
async function fixServerAssets_assertCssTarget(config) {
|
|
205
198
|
if (!fixServerAssets_isEnabled())
|
|
206
199
|
return;
|
|
207
200
|
if (!(await isV1Design(config)))
|
|
208
201
|
return;
|
|
202
|
+
const isServerSide = viteIsSSR(config);
|
|
203
|
+
assert(typeof isServerSide === 'boolean');
|
|
204
|
+
assert(config.build.target !== undefined);
|
|
205
|
+
targets.push({ global: config.build.target, css: config.build.cssTarget, isServerSide });
|
|
209
206
|
const targetsServer = targets.filter((t) => t.isServerSide);
|
|
210
207
|
const targetsClient = targets.filter((t) => !t.isServerSide);
|
|
211
208
|
targetsClient.forEach((targetClient) => {
|
|
@@ -213,9 +210,10 @@ async function fixServerAssets_assertCssTarget(config) {
|
|
|
213
210
|
targetsServer.forEach((targetServer) => {
|
|
214
211
|
const targetCssResolvedServer = resolveCssTarget(targetServer);
|
|
215
212
|
assertWarning(isEqualStringList(targetCssResolvedClient, targetCssResolvedServer), [
|
|
216
|
-
'The CSS browser target should be the same for both client
|
|
217
|
-
`Client
|
|
218
|
-
`Server
|
|
213
|
+
'The CSS browser target should be the same for both client and server, but we got:',
|
|
214
|
+
`Client: ${pc.cyan(JSON.stringify(targetCssResolvedClient))}`,
|
|
215
|
+
`Server: ${pc.cyan(JSON.stringify(targetCssResolvedServer))}`,
|
|
216
|
+
`Different targets lead to CSS duplication, see ${pc.underline('https://github.com/vikejs/vike/issues/1815#issuecomment-2507002979')} for more information.`
|
|
219
217
|
].join('\n'), {
|
|
220
218
|
showStackTrace: true,
|
|
221
219
|
onlyOnce: 'different-css-target'
|
|
@@ -10,7 +10,7 @@ import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
|
|
|
10
10
|
import { createRequire } from 'module';
|
|
11
11
|
import fs from 'fs/promises';
|
|
12
12
|
import path from 'path';
|
|
13
|
-
import { fixServerAssets, fixServerAssets_assertCssCodeSplit, fixServerAssets_assertCssTarget,
|
|
13
|
+
import { fixServerAssets, fixServerAssets_assertCssCodeSplit, fixServerAssets_assertCssTarget, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
|
|
14
14
|
import { set_ASSETS_MANIFEST } from './buildEntry/index.js';
|
|
15
15
|
import { prependEntriesDir } from '../../shared/prependEntriesDir.js';
|
|
16
16
|
import { getFilePathResolved } from '../shared/getFilePath.js';
|
|
@@ -48,7 +48,6 @@ function buildConfig() {
|
|
|
48
48
|
config.build.ssrEmitAssets = true;
|
|
49
49
|
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
|
|
50
50
|
config.build.cssMinify = 'esbuild';
|
|
51
|
-
fixServerAssets_assertCssTarget_populate(config);
|
|
52
51
|
fixServerAssets_assertCssCodeSplit(config);
|
|
53
52
|
}
|
|
54
53
|
}
|
|
@@ -30,7 +30,10 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
30
30
|
_isDev: isDev,
|
|
31
31
|
_root: root,
|
|
32
32
|
_vikeVitePluginOptions: vikeVitePluginOptions,
|
|
33
|
-
vike: {
|
|
33
|
+
vike: {
|
|
34
|
+
pages: vikeConfig.pages,
|
|
35
|
+
config: vikeConfig.global.config
|
|
36
|
+
},
|
|
34
37
|
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
35
38
|
configVikePromise: Promise.resolve({
|
|
36
39
|
prerender: isPrerenderEnabled(vikeConfig)
|
|
@@ -10,8 +10,8 @@ import { vikeConfigDependencies, reloadVikeConfig, isV1Design, getVikeConfig } f
|
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { logConfigInfo } from '../../shared/loggerNotProd.js';
|
|
12
12
|
import { getModuleFilePathAbsolute } from '../../shared/getFilePath.js';
|
|
13
|
-
import { getPlusFileValueConfigName } from './v1-design/getVikeConfig/getPlusFilesAll.js';
|
|
14
13
|
import { updateUserFiles } from '../../../runtime/globalContext.js';
|
|
14
|
+
import { isPlusFile } from './v1-design/getVikeConfig/crawlPlusFiles.js';
|
|
15
15
|
function importUserCode() {
|
|
16
16
|
let config;
|
|
17
17
|
let vikeConfig;
|
|
@@ -68,50 +68,55 @@ function handleFileAddRemove(server, config) {
|
|
|
68
68
|
return;
|
|
69
69
|
function listener(file, isRemove) {
|
|
70
70
|
file = normalizePath(file);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const virtualModules = getVirtualModules(server);
|
|
74
|
-
virtualModules.forEach((mod) => {
|
|
75
|
-
server.moduleGraph.invalidateModule(mod);
|
|
76
|
-
});
|
|
71
|
+
if (isPlusFile(file) || isVikeConfigDependency(file, server.moduleGraph)?.modifiesVikeVirtualFiles) {
|
|
72
|
+
invalidateVikeVirtualFiles(server);
|
|
77
73
|
reloadConfig(file, config, isRemove ? 'removed' : 'created');
|
|
78
74
|
}
|
|
79
75
|
}
|
|
80
76
|
}
|
|
77
|
+
function invalidateVikeVirtualFiles(server) {
|
|
78
|
+
const vikeVirtualFiles = getVikeVirtualFiles(server);
|
|
79
|
+
vikeVirtualFiles.forEach((mod) => {
|
|
80
|
+
server.moduleGraph.invalidateModule(mod);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
81
83
|
function handleHotUpdate(ctx, config) {
|
|
82
84
|
const { file, server } = ctx;
|
|
83
|
-
const isVikeConfig =
|
|
84
|
-
const isViteModule = ctx.modules.length > 0;
|
|
85
|
-
/* Should we show this?
|
|
86
|
-
// - Can be useful for server files that aren't processed by Vite.
|
|
87
|
-
// - Can be annoying for files that obviously aren't processed by Vite.
|
|
88
|
-
if (!isVikeConfig && !isViteModule) {
|
|
89
|
-
logViteAny(
|
|
90
|
-
`${msg} — ${pc.cyan('no HMR')}, see https://vike.dev/on-demand-compiler`,
|
|
91
|
-
'info',
|
|
92
|
-
null,
|
|
93
|
-
true
|
|
94
|
-
)
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
//*/
|
|
98
|
-
// It can hide an error it shouldn't hide (because the error isn't shown again), but it's ok since users can reload the page and the error will be shown again (Vite transpilation errors are shown again upon a page reload).
|
|
99
|
-
if (!isVikeConfig && isViteModule) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
85
|
+
const isVikeConfig = isVikeConfigDependency(ctx.file, ctx.server.moduleGraph);
|
|
102
86
|
if (isVikeConfig) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
87
|
+
if (isVikeConfig.modifiesVikeVirtualFiles) {
|
|
88
|
+
/* Tailwind breaks this assertion, see https://github.com/vikejs/vike/discussions/1330#discussioncomment-7787238
|
|
89
|
+
const isViteModule = ctx.modules.length > 0
|
|
90
|
+
assert(!isViteModule)
|
|
91
|
+
*/
|
|
92
|
+
// Ensure server.ssrLoadModule() loads fresh Vike virtual files (`reloadConfig()` > `updateUserFiles()` > `server.ssrLoadModule()`)
|
|
93
|
+
invalidateVikeVirtualFiles(server);
|
|
94
|
+
reloadConfig(file, config, 'modified');
|
|
95
|
+
// Triggers a full page reload
|
|
96
|
+
const vikeVirtualFiles = getVikeVirtualFiles(server);
|
|
97
|
+
return vikeVirtualFiles;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Ensure we invalidate `file` *before* server.ssrLoadModule() in updateUserFiles()
|
|
101
|
+
// Vite already invalidates it, but possibly *after* handleHotUpdate() and thus after server.ssrLoadModule()
|
|
102
|
+
ctx.modules.forEach((mod) => server.moduleGraph.invalidateModule(mod));
|
|
103
|
+
updateUserFiles();
|
|
104
|
+
}
|
|
109
105
|
}
|
|
110
106
|
}
|
|
111
|
-
function
|
|
107
|
+
function isVikeConfigDependency(filePathAbsoluteFilesystem, moduleGraph) {
|
|
108
|
+
// Check config-only files, for example all pages/+config.js dependencies. (There aren't part of Vite's module graph.)
|
|
112
109
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
113
110
|
vikeConfigDependencies.forEach((f) => assertPosixPath(f));
|
|
114
|
-
|
|
111
|
+
if (vikeConfigDependencies.has(filePathAbsoluteFilesystem))
|
|
112
|
+
return { modifiesVikeVirtualFiles: true };
|
|
113
|
+
// Check using Vite's module graph, for example all +htmlAttributes dependencies.
|
|
114
|
+
// Alternatively, simply call updateUserFiles() on every handleHotUpdate() call.
|
|
115
|
+
const importers = getImporters(filePathAbsoluteFilesystem, moduleGraph);
|
|
116
|
+
const isPlusValueFileDependency = Array.from(importers).some((importer) => importer.file && isPlusFile(importer.file));
|
|
117
|
+
if (isPlusValueFileDependency)
|
|
118
|
+
return { modifiesVikeVirtualFiles: false };
|
|
119
|
+
return null;
|
|
115
120
|
}
|
|
116
121
|
function reloadConfig(filePath, config, op) {
|
|
117
122
|
{
|
|
@@ -122,16 +127,45 @@ function reloadConfig(filePath, config, op) {
|
|
|
122
127
|
reloadVikeConfig(config);
|
|
123
128
|
updateUserFiles();
|
|
124
129
|
}
|
|
125
|
-
function
|
|
126
|
-
const
|
|
130
|
+
function getVikeVirtualFiles(server) {
|
|
131
|
+
const vikeVirtualFiles = Array.from(server.moduleGraph.urlToModuleMap.keys())
|
|
127
132
|
.filter((url) => isVirtualFileIdPageConfigValuesAll(url) || isVirtualFileIdImportUserCode(url))
|
|
128
133
|
.map((url) => {
|
|
129
134
|
const mod = server.moduleGraph.urlToModuleMap.get(url);
|
|
130
135
|
assert(mod);
|
|
131
136
|
return mod;
|
|
132
137
|
});
|
|
133
|
-
return
|
|
138
|
+
return vikeVirtualFiles;
|
|
139
|
+
}
|
|
140
|
+
// Get all transitive importers (including the module itself)
|
|
141
|
+
function getImporters(file, moduleGraph) {
|
|
142
|
+
const importers = new Set();
|
|
143
|
+
const mods = moduleGraph.getModulesByFile(file);
|
|
144
|
+
if (!mods)
|
|
145
|
+
return importers;
|
|
146
|
+
for (const mod of mods) {
|
|
147
|
+
getModuleImporters(mod).forEach((importer) => {
|
|
148
|
+
if (importer)
|
|
149
|
+
importers.add(importer);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return importers;
|
|
134
153
|
}
|
|
135
|
-
function
|
|
136
|
-
|
|
154
|
+
function getModuleImporters(mod, seen = new Set()) {
|
|
155
|
+
if (seen.has(mod))
|
|
156
|
+
return new Set();
|
|
157
|
+
seen.add(mod);
|
|
158
|
+
const importers = new Set();
|
|
159
|
+
if (mod.id)
|
|
160
|
+
importers.add(mod);
|
|
161
|
+
// Traverse through the importers (modules that import this module)
|
|
162
|
+
for (const importer of mod.importers) {
|
|
163
|
+
if (importer.id)
|
|
164
|
+
importers.add(importer);
|
|
165
|
+
getModuleImporters(importer, seen).forEach((importerTransitive) => {
|
|
166
|
+
if (importerTransitive)
|
|
167
|
+
importers.add(importerTransitive);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return importers;
|
|
137
171
|
}
|