vike 0.4.236 → 0.4.237
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/createGetGlobalContextClient.js +20 -12
- package/dist/cjs/client/shared/getJsonSerializedInHtml.js +10 -1
- package/dist/cjs/client/shared/utils.js +1 -0
- package/dist/cjs/node/runtime/globalContext.js +118 -31
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +3 -1
- package/dist/cjs/node/runtime/html/serializeContext.js +25 -64
- package/dist/cjs/node/runtime/html/stream.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +4 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +15 -12
- package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +50 -14
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +20 -6
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -5
- package/dist/cjs/node/runtime/renderPage.js +9 -8
- package/dist/cjs/node/runtime/utils.js +4 -0
- package/dist/cjs/node/shared/utils.js +1 -0
- package/dist/cjs/node/shared/virtualFiles/virtualFileEntry.js +16 -14
- package/dist/cjs/node/shared/virtualFiles/virtualFilePageConfigLazy.js +10 -4
- package/dist/cjs/node/vite/index.js +2 -0
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +22 -14
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +28 -13
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -3
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +17 -5
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +118 -72
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +3 -3
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +3 -4
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +51 -0
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +67 -0
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +6 -3
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +4 -5
- package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/cjs/node/vite/shared/getMagicString.js +18 -0
- package/dist/cjs/node/vite/shared/getManifestFilePathRelative.js +10 -0
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -3
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +7 -18
- package/dist/cjs/node/vite/utils.js +1 -0
- package/dist/cjs/shared/createGlobalContextShared.js +27 -6
- package/dist/cjs/shared/getPageFiles/parseVirtualFileExports.js +6 -0
- package/dist/cjs/shared/getProxyForPublicUsage.js +2 -2
- package/dist/cjs/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +13 -13
- package/dist/cjs/shared/utils.js +2 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +7 -5
- package/dist/cjs/utils/cast.js +1 -1
- package/dist/cjs/utils/debug.js +1 -0
- package/dist/cjs/utils/getViteRPC.js +79 -0
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +1 -0
- package/dist/cjs/utils/isRunnableDevEnvironment.js +9 -0
- package/dist/cjs/utils/virtualFileId.js +39 -0
- package/dist/esm/client/node.js +1 -1
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +35 -48
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/history.d.ts +3 -5
- package/dist/esm/client/runtime-client-routing/history.js +39 -22
- package/dist/esm/client/runtime-client-routing/initClientRouter.js +2 -3
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +43 -30
- package/dist/esm/client/runtime-client-routing/utils.d.ts +2 -0
- package/dist/esm/client/runtime-client-routing/utils.js +2 -0
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.js +20 -12
- package/dist/esm/client/shared/getJsonSerializedInHtml.js +10 -1
- package/dist/esm/client/shared/utils.d.ts +1 -0
- package/dist/esm/client/shared/utils.js +1 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +40 -132
- package/dist/esm/node/runtime/globalContext.d.ts +35 -55
- package/dist/esm/node/runtime/globalContext.js +119 -32
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +4 -2
- package/dist/esm/node/runtime/html/serializeContext.d.ts +11 -6
- package/dist/esm/node/runtime/html/serializeContext.js +25 -64
- package/dist/esm/node/runtime/html/stream.js +1 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +11 -34
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +4 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +16 -13
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.js +51 -15
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +21 -7
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +0 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +24 -71
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -5
- package/dist/esm/node/runtime/renderPage.d.ts +11 -33
- package/dist/esm/node/runtime/renderPage.js +9 -8
- package/dist/esm/node/runtime/utils.d.ts +4 -0
- package/dist/esm/node/runtime/utils.js +4 -0
- package/dist/esm/node/shared/utils.d.ts +1 -0
- package/dist/esm/node/shared/utils.js +1 -0
- package/dist/esm/node/shared/virtualFiles/virtualFileEntry.js +16 -14
- package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.js +11 -5
- package/dist/esm/node/vite/index.js +2 -0
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +22 -14
- package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +2 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +28 -13
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +0 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +17 -5
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +2 -2
- package/dist/esm/node/vite/plugins/pluginCommon.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +120 -74
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +3 -4
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.d.ts +26 -0
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +49 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +14 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +65 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +2 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +6 -3
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +3 -4
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/esm/node/vite/shared/getMagicString.d.ts +9 -0
- package/dist/esm/node/vite/shared/getMagicString.js +13 -0
- package/dist/esm/node/vite/shared/getManifestFilePathRelative.d.ts +2 -0
- package/dist/esm/node/vite/shared/getManifestFilePathRelative.js +8 -0
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +1 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +8 -19
- package/dist/esm/node/vite/utils.d.ts +1 -0
- package/dist/esm/node/vite/utils.js +1 -0
- package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
- package/dist/esm/shared/createGlobalContextShared.js +28 -7
- package/dist/esm/shared/getPageFiles/parseVirtualFileExports.js +6 -0
- package/dist/esm/shared/modifyUrlSameOrigin.d.ts +1 -1
- package/dist/esm/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +14 -14
- package/dist/esm/shared/utils.d.ts +2 -0
- package/dist/esm/shared/utils.js +2 -0
- package/dist/esm/types/Config.d.ts +33 -98
- package/dist/esm/types/index.d.ts +3 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.js +7 -5
- package/dist/esm/utils/cast.d.ts +2 -2
- package/dist/esm/utils/cast.js +1 -1
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +1 -0
- package/dist/esm/utils/getViteRPC.d.ts +6 -0
- package/dist/esm/utils/getViteRPC.js +77 -0
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.d.ts +7 -0
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -0
- package/dist/esm/utils/isRunnableDevEnvironment.d.ts +3 -0
- package/dist/esm/utils/isRunnableDevEnvironment.js +7 -0
- package/dist/esm/utils/objectFilter.d.ts +1 -1
- package/dist/esm/utils/virtualFileId.d.ts +6 -0
- package/dist/esm/{node/shared/virtualFiles.js → utils/virtualFileId.js} +15 -17
- package/package.json +14 -5
- package/dist/cjs/node/shared/virtualFiles.js +0 -41
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -23
- package/dist/esm/node/shared/virtualFiles.d.ts +0 -8
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.d.ts +0 -7
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -21
|
@@ -16,18 +16,11 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
16
16
|
const globalContext = pageContext._globalContext;
|
|
17
17
|
const { _isProduction: isProduction } = globalContext;
|
|
18
18
|
const isDev = !isProduction;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
assetUrls = await (0, retrieveAssetsDev_js_1.retrieveAssetsDev)(clientDependencies, viteDevServer);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
const { assetsManifest } = globalContext;
|
|
28
|
-
clientEntriesSrc = clientEntries.map((clientEntry) => resolveClientEntriesProd(clientEntry, assetsManifest));
|
|
29
|
-
assetUrls = (0, retrieveAssetsProd_js_1.retrieveAssetsProd)(clientDependencies, assetsManifest, resolveIncludeAssetsImportedByServer(pageContext._globalContext.config));
|
|
30
|
-
}
|
|
19
|
+
const { assetUrls, clientEntriesSrc } = isDev
|
|
20
|
+
? !globalContext._viteDevServer
|
|
21
|
+
? await (0, utils_js_1.getViteRPC)().retrievePageAssetsDevRPC(clientDependencies, clientEntries)
|
|
22
|
+
: await retrievePageAssetsDev(globalContext._viteDevServer, clientDependencies, clientEntries)
|
|
23
|
+
: retrievePageAssetsProd(globalContext.assetsManifest, clientDependencies, clientEntries, resolveIncludeAssetsImportedByServer(globalContext.config));
|
|
31
24
|
let pageAssets = [];
|
|
32
25
|
(0, utils_js_1.unique)([...clientEntriesSrc, ...assetUrls]).forEach((src) => {
|
|
33
26
|
const { mediaType = null, assetType = null } = (0, inferMediaType_js_1.inferMediaType)(src) || {};
|
|
@@ -61,6 +54,16 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
61
54
|
await (0, sortPageAssetsForEarlyHintsHeader_js_1.sortPageAssetsForEarlyHintsHeader)(pageAssets, isProduction);
|
|
62
55
|
return pageAssets;
|
|
63
56
|
}
|
|
57
|
+
async function retrievePageAssetsDev(viteDevServer, clientDependencies, clientEntries) {
|
|
58
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => globalObject.resolveClientEntriesDev(clientEntry, viteDevServer));
|
|
59
|
+
const assetUrls = await (0, retrieveAssetsDev_js_1.retrieveAssetsDev)(clientDependencies, viteDevServer);
|
|
60
|
+
return { clientEntriesSrc, assetUrls };
|
|
61
|
+
}
|
|
62
|
+
function retrievePageAssetsProd(assetsManifest, clientDependencies, clientEntries, includeAssetsImportedByServer) {
|
|
63
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => resolveClientEntriesProd(clientEntry, assetsManifest));
|
|
64
|
+
const assetUrls = (0, retrieveAssetsProd_js_1.retrieveAssetsProd)(clientDependencies, assetsManifest, resolveIncludeAssetsImportedByServer(includeAssetsImportedByServer));
|
|
65
|
+
return { clientEntriesSrc, assetUrls };
|
|
66
|
+
}
|
|
64
67
|
function resolveClientEntriesProd(clientEntry, assetsManifest) {
|
|
65
68
|
const { manifestEntry } = (0, getManifestEntry_js_1.getManifestEntry)(clientEntry, assetsManifest);
|
|
66
69
|
(0, utils_js_1.assert)(manifestEntry.isEntry || manifestEntry.isDynamicEntry || clientEntry.endsWith('.css'), { clientEntry });
|
|
@@ -2,31 +2,67 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handlePageContextRequestUrl = handlePageContextRequestUrl;
|
|
4
4
|
const getPageContextRequestUrl_js_1 = require("../../../shared/getPageContextRequestUrl.js");
|
|
5
|
+
const modifyUrl_js_1 = require("../../../shared/modifyUrl.js");
|
|
5
6
|
const utils_js_1 = require("../utils.js");
|
|
6
7
|
// See also shared/getPageContextRequestUrl.ts
|
|
7
8
|
function handlePageContextRequestUrl(url) {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const urlParsed = (0, utils_js_1.parseUrl)(url, utils_js_1.baseServer);
|
|
10
|
+
if (!isMatch(urlParsed)) {
|
|
11
|
+
return {
|
|
12
|
+
isPageContextJsonRequest: false,
|
|
13
|
+
urlWithoutPageContextRequestSuffix: url,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const { urlWithoutPageContextRequestSuffix, searchVikeArgs } = processUrl(urlParsed, url);
|
|
18
|
+
const previousUrl = parseSearchVikeArgs(searchVikeArgs);
|
|
19
|
+
return {
|
|
20
|
+
/* TO-DO/soon/once: pass & use previousUrl
|
|
21
|
+
isPageContextJsonRequest: { previousUrl },
|
|
22
|
+
/*/
|
|
23
|
+
isPageContextJsonRequest: true,
|
|
24
|
+
//*/
|
|
25
|
+
urlWithoutPageContextRequestSuffix,
|
|
26
|
+
};
|
|
10
27
|
}
|
|
11
|
-
return { urlWithoutPageContextRequestSuffix: removePageContextUrlSuffix(url), isPageContextRequest: true };
|
|
12
28
|
}
|
|
13
|
-
function
|
|
14
|
-
const { pathnameOriginal, pathname } =
|
|
15
|
-
(0, utils_js_1.assert)(
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
return pathnameOriginal.endsWith(getPageContextRequestUrl_js_1.pageContextJsonFileExtension);
|
|
29
|
+
function isMatch(urlParsed) {
|
|
30
|
+
const { pathnameOriginal, pathname } = urlParsed;
|
|
31
|
+
(0, utils_js_1.assert)(pathname.endsWith(getPageContextRequestUrl_js_1.pageContextJsonFileExtension) === pathnameOriginal.endsWith(getPageContextRequestUrl_js_1.pageContextJsonFileExtension));
|
|
32
|
+
return pathname.endsWith(getPageContextRequestUrl_js_1.pageContextJsonFileExtension);
|
|
19
33
|
}
|
|
20
|
-
function
|
|
21
|
-
const urlParsed = (0, utils_js_1.parseUrl)(url, utils_js_1.baseServer);
|
|
34
|
+
function processUrl(urlParsed, url) {
|
|
22
35
|
// We cannot use `urlParsed.pathname` because it would break the `urlParsed.pathnameOriginal` value of subsequent `parseUrl()` calls.
|
|
23
|
-
const {
|
|
36
|
+
const { pathnameOriginal, search } = urlParsed;
|
|
24
37
|
(0, utils_js_1.assert)(getPageContextRequestUrl_js_1.doNotCreateExtraDirectory === false);
|
|
25
38
|
const urlSuffix = `/index${getPageContextRequestUrl_js_1.pageContextJsonFileExtension}`;
|
|
26
39
|
(0, utils_js_1.assert)(pathnameOriginal.endsWith(urlSuffix), { url });
|
|
27
40
|
let pathnameModified = (0, utils_js_1.slice)(pathnameOriginal, 0, -1 * urlSuffix.length);
|
|
28
41
|
if (pathnameModified === '')
|
|
29
42
|
pathnameModified = '/';
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
const searchVikeArgs = search?._vike;
|
|
44
|
+
const urlWithoutPageContextRequestSuffix = (0, modifyUrl_js_1.modifyUrl)(url, {
|
|
45
|
+
pathname: pathnameModified,
|
|
46
|
+
search: {
|
|
47
|
+
_vike: searchVikeArgs ? null : undefined,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
searchVikeArgs,
|
|
52
|
+
urlWithoutPageContextRequestSuffix,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function parseSearchVikeArgs(searchVikeArgs) {
|
|
56
|
+
const args = {
|
|
57
|
+
previousUrl: null,
|
|
58
|
+
};
|
|
59
|
+
if (searchVikeArgs) {
|
|
60
|
+
const parsed = JSON.parse(searchVikeArgs);
|
|
61
|
+
(0, utils_js_1.assert)((0, utils_js_1.isObject)(parsed));
|
|
62
|
+
if ('previousUrl' in parsed) {
|
|
63
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(parsed, 'previousUrl', 'string'));
|
|
64
|
+
args.previousUrl = parsed.previousUrl;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return args;
|
|
32
68
|
}
|
|
@@ -18,6 +18,7 @@ async function loadPageConfigsLazyServerSideAndExecHook(pageContext) {
|
|
|
18
18
|
await (0, execHookServer_js_1.execHookServer)('onCreatePageContext', pageContext);
|
|
19
19
|
return pageContext;
|
|
20
20
|
}
|
|
21
|
+
// TODO/now: define new function resolveAfterLoad() ?
|
|
21
22
|
async function loadPageConfigsLazyServerSide(pageContext) {
|
|
22
23
|
const pageConfig = (0, findPageConfig_js_1.findPageConfig)(pageContext._globalContext._pageConfigs, pageContext.pageId); // Make pageConfig globally available as pageContext._pageConfig ?
|
|
23
24
|
const globalContext = pageContext._globalContext;
|
|
@@ -30,19 +31,32 @@ async function loadPageConfigsLazyServerSide(pageContext) {
|
|
|
30
31
|
const { isHtmlOnly, isClientRouting, clientEntries, clientDependencies, pageFilesClientSide, pageFilesServerSide } = await (0, analyzePage_js_1.analyzePage)(pageContext._globalContext._pageFilesAll, pageConfig, pageContext.pageId, globalContext);
|
|
31
32
|
const isV1Design = !!pageConfig;
|
|
32
33
|
const passToClient = [];
|
|
33
|
-
const
|
|
34
|
+
const errMsgSuffix = ' should be an array of strings.';
|
|
34
35
|
if (!isV1Design) {
|
|
35
36
|
configPublicPageLazy.exportsAll.passToClient?.forEach((e) => {
|
|
36
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(e, 'exportValue', 'string[]'), `${e.exportSource}${
|
|
37
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(e, 'exportValue', 'string[]'), `${e.exportSource}${errMsgSuffix}`);
|
|
37
38
|
passToClient.push(...e.exportValue);
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
41
|
else {
|
|
41
42
|
configPublicPageLazy.from.configsCumulative.passToClient?.values.forEach((v) => {
|
|
42
|
-
const { value } = v;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
const { value, definedAt } = v;
|
|
44
|
+
const errMsg = `+passToClient value defined at ${definedAt}${errMsgSuffix}`;
|
|
45
|
+
//*/ TO-DO/next-major-release: remove the passToClient once setting from the public API
|
|
46
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isArray)(value), `+passToClient value defined at ${definedAt} should be an array`);
|
|
47
|
+
const valS = value.map((el) => {
|
|
48
|
+
if ((0, utils_js_1.isObject)(el)) {
|
|
49
|
+
(0, utils_js_1.assertWarning)(!('once' in el), 'The passToClient once setting is deprecated and no longer has any effect. Instead, see the upcoming .once.js suffix (see https://github.com/vikejs/vike/issues/2566 for more information).', { onlyOnce: true });
|
|
50
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(el, 'prop', 'string'), errMsg);
|
|
51
|
+
return el.prop;
|
|
52
|
+
}
|
|
53
|
+
(0, utils_js_1.assertUsage)(typeof el === 'string', errMsg);
|
|
54
|
+
return el;
|
|
55
|
+
});
|
|
56
|
+
/*/
|
|
57
|
+
assertUsage(isArrayOfStrings(value), errMsg)
|
|
58
|
+
//*/
|
|
59
|
+
passToClient.push(...valS);
|
|
46
60
|
});
|
|
47
61
|
}
|
|
48
62
|
const pageContextAddendum = {};
|
|
@@ -50,7 +50,7 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
50
50
|
if (isError) {
|
|
51
51
|
(0, utils_js_1.objectAssign)(pageContext, { [isServerSideError_js_1.isServerSideError]: true });
|
|
52
52
|
}
|
|
53
|
-
const pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext);
|
|
53
|
+
const pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext, false);
|
|
54
54
|
const httpResponse = await (0, createHttpResponse_js_1.createHttpResponsePageContextJson)(pageContextSerialized);
|
|
55
55
|
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
56
56
|
return pageContext;
|
|
@@ -63,8 +63,7 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
63
63
|
}
|
|
64
64
|
async function prerenderPage(pageContext) {
|
|
65
65
|
(0, utils_js_1.objectAssign)(pageContext, {
|
|
66
|
-
|
|
67
|
-
_urlHandler: null,
|
|
66
|
+
_isPageContextJsonRequest: null,
|
|
68
67
|
});
|
|
69
68
|
/* Should we execute the guard() hook upon pre-rendering? Is there a use case for this?
|
|
70
69
|
* - It isn't trivial to implement, as it requires to duplicate / factor out the isAbortError() handling
|
|
@@ -73,14 +72,13 @@ async function prerenderPage(pageContext) {
|
|
|
73
72
|
await (0, execHookDataAndOnBeforeRender_js_1.execHookDataAndOnBeforeRender)(pageContext);
|
|
74
73
|
const { htmlRender, renderHook } = await (0, execHookOnRenderHtml_js_1.execHookOnRenderHtml)(pageContext);
|
|
75
74
|
(0, utils_js_1.assertUsage)(htmlRender !== null, `Cannot pre-render ${picocolors_1.default.cyan(pageContext.urlOriginal)} because the ${renderHook.hookName}() hook defined by ${renderHook.hookFilePath} didn't return an HTML string.`);
|
|
76
|
-
(0, utils_js_1.assert)(pageContext.isClientSideNavigation === false);
|
|
77
75
|
const documentHtml = await (0, renderHtml_js_1.getHtmlString)(htmlRender);
|
|
78
76
|
(0, utils_js_1.assert)(typeof documentHtml === 'string');
|
|
79
77
|
if (!pageContext._usesClientRouter) {
|
|
80
78
|
return { documentHtml, pageContextSerialized: null, pageContext };
|
|
81
79
|
}
|
|
82
80
|
else {
|
|
83
|
-
const pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext);
|
|
81
|
+
const pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext, false);
|
|
84
82
|
return { documentHtml, pageContextSerialized, pageContext };
|
|
85
83
|
}
|
|
86
84
|
}
|
|
@@ -312,7 +312,7 @@ async function getPageContextErrorPageInit(pageContextBegin, errNominalPage, pag
|
|
|
312
312
|
return pageContext;
|
|
313
313
|
}
|
|
314
314
|
function getPageContextBegin(pageContextInit, globalContext, httpRequestId) {
|
|
315
|
-
const { isClientSideNavigation, _urlHandler } = handlePageContextUrl(pageContextInit.urlOriginal);
|
|
315
|
+
const { isClientSideNavigation, _urlHandler, _isPageContextJsonRequest } = handlePageContextUrl(pageContextInit.urlOriginal);
|
|
316
316
|
const pageContextBegin = (0, createPageContextServerSide_js_1.createPageContextServerSide)(pageContextInit, globalContext, {
|
|
317
317
|
isPrerendering: false,
|
|
318
318
|
ssr: {
|
|
@@ -320,13 +320,14 @@ function getPageContextBegin(pageContextInit, globalContext, httpRequestId) {
|
|
|
320
320
|
isClientSideNavigation,
|
|
321
321
|
},
|
|
322
322
|
});
|
|
323
|
-
(0, utils_js_1.objectAssign)(pageContextBegin, { _httpRequestId: httpRequestId });
|
|
323
|
+
(0, utils_js_1.objectAssign)(pageContextBegin, { _httpRequestId: httpRequestId, _isPageContextJsonRequest });
|
|
324
324
|
return pageContextBegin;
|
|
325
325
|
}
|
|
326
326
|
function handlePageContextUrl(urlOriginal) {
|
|
327
|
-
const {
|
|
327
|
+
const { isPageContextJsonRequest } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
|
|
328
328
|
return {
|
|
329
|
-
isClientSideNavigation:
|
|
329
|
+
isClientSideNavigation: !!isPageContextJsonRequest,
|
|
330
|
+
_isPageContextJsonRequest: isPageContextJsonRequest,
|
|
330
331
|
_urlHandler: (url) => (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(url).urlWithoutPageContextRequestSuffix,
|
|
331
332
|
};
|
|
332
333
|
}
|
|
@@ -350,8 +351,8 @@ async function normalizeUrl(pageContextBegin, globalContext, httpRequestId) {
|
|
|
350
351
|
if (disableUrlNormalization)
|
|
351
352
|
return null;
|
|
352
353
|
const { urlOriginal } = pageContext;
|
|
353
|
-
const {
|
|
354
|
-
if (
|
|
354
|
+
const { isPageContextJsonRequest } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
|
|
355
|
+
if (isPageContextJsonRequest)
|
|
355
356
|
return null;
|
|
356
357
|
const urlNormalized = (0, utils_js_1.normalizeUrlPathname)(urlOriginal, trailingSlash ?? false, globalContext.baseServer);
|
|
357
358
|
if (!urlNormalized)
|
|
@@ -424,10 +425,10 @@ pageContextNominalPageBegin, httpRequestId, pageContextErrorPageInit, globalCont
|
|
|
424
425
|
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit, true);
|
|
425
426
|
(0, utils_js_1.augmentType)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.loadPageConfigsLazyServerSideAndExecHook)(pageContext));
|
|
426
427
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
427
|
-
pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext);
|
|
428
|
+
pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext, false);
|
|
428
429
|
}
|
|
429
430
|
else {
|
|
430
|
-
pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerializedAbort)(pageContextAbort);
|
|
431
|
+
pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerializedAbort)(pageContextAbort, false);
|
|
431
432
|
}
|
|
432
433
|
const httpResponse = await (0, createHttpResponse_js_1.createHttpResponsePageContextJson)(pageContextSerialized);
|
|
433
434
|
const pageContextReturn = { httpResponse };
|
|
@@ -62,6 +62,7 @@ __exportStar(require("../../utils/assertSetup.js"), exports);
|
|
|
62
62
|
__exportStar(require("../../utils/path.js"), exports);
|
|
63
63
|
__exportStar(require("../../utils/isHtml.js"), exports);
|
|
64
64
|
__exportStar(require("../../utils/warnIfErrorIsNotObject.js"), exports);
|
|
65
|
+
__exportStar(require("../../utils/virtualFileId.js"), exports);
|
|
65
66
|
__exportStar(require("../../utils/stripAnsi.js"), exports);
|
|
66
67
|
__exportStar(require("../../utils/getTerminWidth.js"), exports);
|
|
67
68
|
__exportStar(require("../../utils/truncateString.js"), exports);
|
|
@@ -76,3 +77,6 @@ __exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
|
76
77
|
__exportStar(require("../../utils/genPromise.js"), exports);
|
|
77
78
|
__exportStar(require("../../utils/augmentType.js"), exports);
|
|
78
79
|
__exportStar(require("../../utils/changeEnumerable.js"), exports);
|
|
80
|
+
__exportStar(require("../../utils/getViteRPC.js"), exports);
|
|
81
|
+
__exportStar(require("../../utils/isRunnableDevEnvironment.js"), exports);
|
|
82
|
+
__exportStar(require("../../utils/assertIsNotBrowser.js"), exports);
|
|
@@ -32,3 +32,4 @@ __exportStar(require("../../utils/assertIsNotBrowser.js"), exports);
|
|
|
32
32
|
__exportStar(require("../../utils/isNullish.js"), exports);
|
|
33
33
|
__exportStar(require("../../utils/unique.js"), exports);
|
|
34
34
|
__exportStar(require("../../utils/debug.js"), exports);
|
|
35
|
+
__exportStar(require("../../utils/virtualFileId.js"), exports);
|
|
@@ -2,27 +2,29 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.virtualFileIdEntryClientCR = exports.virtualFileIdEntryClientSR = exports.virtualFileIdEntryServer = void 0;
|
|
4
4
|
exports.isVirtualFileIdEntry = isVirtualFileIdEntry;
|
|
5
|
+
// TODO/now: merge virtualFileEntry.ts and virtualFilePageConfigLazy.ts
|
|
6
|
+
// - One function parseVirtualFileIdEntry() to rule them all?
|
|
5
7
|
const utils_js_1 = require("../utils.js");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
(0, utils_js_1.assertIsNotBrowser)();
|
|
9
|
+
// TODO/now: rename:
|
|
10
|
+
// ```diff
|
|
11
|
+
// - virtual:vike:entry:server
|
|
12
|
+
// + virtual:vike:entry:global:server
|
|
13
|
+
// ```
|
|
14
|
+
const virtualFileIdEntryServer = 'virtual:vike:entry:server';
|
|
9
15
|
exports.virtualFileIdEntryServer = virtualFileIdEntryServer;
|
|
10
|
-
const virtualFileIdEntryClientSR =
|
|
16
|
+
const virtualFileIdEntryClientSR = 'virtual:vike:entry:client:server-routing';
|
|
11
17
|
exports.virtualFileIdEntryClientSR = virtualFileIdEntryClientSR;
|
|
12
|
-
const virtualFileIdEntryClientCR =
|
|
18
|
+
const virtualFileIdEntryClientCR = 'virtual:vike:entry:client:client-routing';
|
|
13
19
|
exports.virtualFileIdEntryClientCR = virtualFileIdEntryClientCR;
|
|
20
|
+
const virtualFileIdEntries = [virtualFileIdEntryServer, virtualFileIdEntryClientCR, virtualFileIdEntryClientSR];
|
|
21
|
+
const idBase = 'virtual:vike:entry';
|
|
22
|
+
(0, utils_js_1.assert)(virtualFileIdEntries.every((v) => v.startsWith(`${idBase}:`)));
|
|
14
23
|
function isVirtualFileIdEntry(id) {
|
|
15
|
-
id = (0,
|
|
24
|
+
id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
|
|
16
25
|
if (!id.startsWith(idBase))
|
|
17
26
|
return false;
|
|
18
|
-
(0, utils_js_1.assert)(
|
|
19
|
-
// prettier-ignore
|
|
20
|
-
// biome-ignore format:
|
|
21
|
-
[
|
|
22
|
-
virtualFileIdEntryServer,
|
|
23
|
-
virtualFileIdEntryClientCR,
|
|
24
|
-
virtualFileIdEntryClientSR
|
|
25
|
-
].includes(id));
|
|
27
|
+
(0, utils_js_1.assert)(virtualFileIdEntries.includes(id));
|
|
26
28
|
const isForClientSide = id !== virtualFileIdEntryServer;
|
|
27
29
|
const isClientRouting = id === virtualFileIdEntryClientCR;
|
|
28
30
|
return { isForClientSide, isClientRouting };
|
|
@@ -4,16 +4,22 @@ exports.isVirtualFileIdPageConfigLazy = isVirtualFileIdPageConfigLazy;
|
|
|
4
4
|
exports.getVirtualFileIdPageConfigLazy = getVirtualFileIdPageConfigLazy;
|
|
5
5
|
const extractAssetsQuery_js_1 = require("../extractAssetsQuery.js");
|
|
6
6
|
const utils_js_1 = require("../utils.js");
|
|
7
|
-
|
|
7
|
+
(0, utils_js_1.assertIsNotBrowser)();
|
|
8
|
+
// TODO/now: rename:
|
|
9
|
+
// ```diff
|
|
10
|
+
// - virtual:vike:pageConfigLazy:server:
|
|
11
|
+
// + virtual:vike:entry:page:server:
|
|
12
|
+
// ```
|
|
13
|
+
const idBaseClient = 'virtual:vike:pageConfigLazy:client:';
|
|
14
|
+
const idBaseServer = 'virtual:vike:pageConfigLazy:server:';
|
|
8
15
|
const idBase = 'virtual:vike:pageConfigLazy:';
|
|
9
|
-
|
|
10
|
-
const idBaseServer = `${idBase}server:`;
|
|
16
|
+
// TODO/now: rename to generateVirtualFileIdEntry()
|
|
11
17
|
function getVirtualFileIdPageConfigLazy(pageId, isForClientSide) {
|
|
12
18
|
const id = `${isForClientSide ? idBaseClient : idBaseServer}${pageId}`;
|
|
13
19
|
return id;
|
|
14
20
|
}
|
|
15
21
|
function isVirtualFileIdPageConfigLazy(id) {
|
|
16
|
-
id = (0,
|
|
22
|
+
id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
|
|
17
23
|
if (!id.includes(idBase))
|
|
18
24
|
return false;
|
|
19
25
|
(0, utils_js_1.assert)(id.startsWith(idBase));
|
|
@@ -29,6 +29,7 @@ const resolveClientEntriesDev_js_1 = require("./shared/resolveClientEntriesDev.j
|
|
|
29
29
|
const pluginWorkaroundCssModuleHmr_js_1 = require("./plugins/pluginWorkaroundCssModuleHmr.js");
|
|
30
30
|
const pluginWorkaroundVite6HmrRegression_js_1 = require("./plugins/pluginWorkaroundVite6HmrRegression.js");
|
|
31
31
|
const pluginReplaceConstants_js_1 = require("./plugins/pluginReplaceConstants.js");
|
|
32
|
+
const pluginNonRunnableDev_js_1 = require("./plugins/pluginNonRunnableDev.js");
|
|
32
33
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
33
34
|
(0, getPageAssets_js_1.setResolveClientEntriesDev)(resolveClientEntriesDev_js_1.resolveClientEntriesDev);
|
|
34
35
|
// Return `PluginInterop` instead of `Plugin` to avoid type mismatch upon different Vite versions
|
|
@@ -48,6 +49,7 @@ function plugin(vikeVitePluginOptions = {}) {
|
|
|
48
49
|
(0, pluginWorkaroundCssModuleHmr_js_1.pluginWorkaroundCssModuleHmr)(),
|
|
49
50
|
(0, pluginWorkaroundVite6HmrRegression_js_1.pluginWorkaroundVite6HmrRegression)(),
|
|
50
51
|
(0, pluginReplaceConstants_js_1.pluginReplaceConstants)(),
|
|
52
|
+
(0, pluginNonRunnableDev_js_1.pluginNonRunnableDev)(),
|
|
51
53
|
];
|
|
52
54
|
Object.assign(plugins, { _vikeVitePluginOptions: vikeVitePluginOptions });
|
|
53
55
|
return plugins;
|
|
@@ -14,13 +14,13 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
14
14
|
const node_fs_2 = require("node:fs");
|
|
15
15
|
const utils_js_1 = require("../../utils.js");
|
|
16
16
|
const virtualFilePageConfigLazy_js_1 = require("../../../shared/virtualFiles/virtualFilePageConfigLazy.js");
|
|
17
|
-
const pluginBuildConfig_js_1 = require("./pluginBuildConfig.js");
|
|
18
17
|
const getAssetsDir_js_1 = require("../../shared/getAssetsDir.js");
|
|
19
18
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
20
19
|
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
21
20
|
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
22
21
|
const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
23
22
|
const pluginBuildEntry_js_1 = require("./pluginBuildEntry.js");
|
|
23
|
+
const getManifestFilePathRelative_js_1 = require("../../shared/getManifestFilePathRelative.js");
|
|
24
24
|
(0, utils_js_1.assertIsSingleModuleInstance)('build/handleAssetsManifest.ts');
|
|
25
25
|
let assetsJsonFilePath;
|
|
26
26
|
// true => use workaround config.build.ssrEmitAssets
|
|
@@ -31,9 +31,8 @@ function handleAssetsManifest_isFixEnabled(config) {
|
|
|
31
31
|
}
|
|
32
32
|
/** https://github.com/vikejs/vike/issues/1339 */
|
|
33
33
|
async function fixServerAssets(config) {
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const serverManifest = await readManifestFile(outDirs.outDirServer);
|
|
34
|
+
const clientManifest = await readManifestFile(config, true);
|
|
35
|
+
const serverManifest = await readManifestFile(config, false);
|
|
37
36
|
const { clientManifestMod, serverManifestMod, filesToMove, filesToRemove } = addServerAssets(clientManifest, serverManifest);
|
|
38
37
|
await copyAssets(filesToMove, filesToRemove, config);
|
|
39
38
|
return { clientManifestMod, serverManifestMod };
|
|
@@ -270,8 +269,8 @@ function removeEmptyDirectories(dirPath) {
|
|
|
270
269
|
node_fs_1.default.rmdirSync(dirPath);
|
|
271
270
|
}
|
|
272
271
|
}
|
|
273
|
-
async function readManifestFile(
|
|
274
|
-
const manifestFilePath =
|
|
272
|
+
async function readManifestFile(config, client) {
|
|
273
|
+
const manifestFilePath = getManifestFilePath(config, client);
|
|
275
274
|
const manifestFileContent = await promises_1.default.readFile(manifestFilePath, 'utf-8');
|
|
276
275
|
(0, utils_js_1.assert)(manifestFileContent);
|
|
277
276
|
const manifest = JSON.parse(manifestFileContent);
|
|
@@ -292,7 +291,7 @@ async function handleAssetsManifest_getBuildConfig(config) {
|
|
|
292
291
|
ssrEmitAssets: isFixEnabled ? true : undefined,
|
|
293
292
|
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
|
|
294
293
|
cssMinify: isFixEnabled ? 'esbuild' : undefined,
|
|
295
|
-
manifest:
|
|
294
|
+
manifest: true,
|
|
296
295
|
copyPublicDir: vikeConfig.config.vite6BuilderApp
|
|
297
296
|
? // Already set by vike:build:pluginBuildApp
|
|
298
297
|
undefined
|
|
@@ -300,12 +299,12 @@ async function handleAssetsManifest_getBuildConfig(config) {
|
|
|
300
299
|
};
|
|
301
300
|
}
|
|
302
301
|
async function handleAssetsManifest(config, viteEnv, options, bundle) {
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
302
|
+
const isSsrEnv = (0, isViteServerBuild_js_1.isViteServerBuild_onlySsrEnv)(config, viteEnv);
|
|
303
|
+
if (isSsrEnv) {
|
|
305
304
|
(0, utils_js_1.assert)(!assetsJsonFilePath);
|
|
306
305
|
const outDirs = (0, getOutDirs_js_1.getOutDirs)(config, viteEnv);
|
|
307
306
|
assetsJsonFilePath = node_path_1.default.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
308
|
-
await writeAssetsManifestFile(
|
|
307
|
+
await writeAssetsManifestFile(assetsJsonFilePath, config);
|
|
309
308
|
}
|
|
310
309
|
if ((0, isViteServerBuild_js_1.isViteServerBuild)(config, viteEnv)) {
|
|
311
310
|
const outDir = options.dir;
|
|
@@ -315,14 +314,14 @@ async function handleAssetsManifest(config, viteEnv, options, bundle) {
|
|
|
315
314
|
// - Also in some other server builds such as dist/vercel/ from vike-vercel
|
|
316
315
|
// - Don't replace it in dist/rsc/ from vike-react-rsc since __VITE_ASSETS_MANIFEST__ doesn't exist there
|
|
317
316
|
const noop = await (0, pluginBuildEntry_js_1.set_macro_ASSETS_MANIFEST)(assetsJsonFilePath, bundle, outDir);
|
|
318
|
-
if (
|
|
317
|
+
if (isSsrEnv)
|
|
319
318
|
(0, utils_js_1.assert)(!noop); // dist/server should always contain __VITE_ASSETS_MANIFEST__
|
|
320
319
|
}
|
|
321
320
|
}
|
|
322
|
-
async function writeAssetsManifestFile(
|
|
321
|
+
async function writeAssetsManifestFile(assetsJsonFilePath, config) {
|
|
323
322
|
const isFixEnabled = handleAssetsManifest_isFixEnabled(config);
|
|
324
|
-
const clientManifestFilePath =
|
|
325
|
-
const serverManifestFilePath =
|
|
323
|
+
const clientManifestFilePath = getManifestFilePath(config, true);
|
|
324
|
+
const serverManifestFilePath = getManifestFilePath(config, false);
|
|
326
325
|
if (!isFixEnabled) {
|
|
327
326
|
await promises_1.default.copyFile(clientManifestFilePath, assetsJsonFilePath);
|
|
328
327
|
}
|
|
@@ -333,3 +332,12 @@ async function writeAssetsManifestFile(outDirs, assetsJsonFilePath, config) {
|
|
|
333
332
|
await promises_1.default.rm(clientManifestFilePath);
|
|
334
333
|
await promises_1.default.rm(serverManifestFilePath);
|
|
335
334
|
}
|
|
335
|
+
function getManifestFilePath(config, client) {
|
|
336
|
+
const outDirs = (0, getOutDirs_js_1.getOutDirs)(config);
|
|
337
|
+
const outDir = client ? outDirs.outDirClient : outDirs.outDirServer;
|
|
338
|
+
const env = client ? config.environments.client : config.environments.ssr;
|
|
339
|
+
(0, utils_js_1.assert)(env);
|
|
340
|
+
const manifestFilePathRelative = (0, getManifestFilePathRelative_js_1.getManifestFilePathRelative)(env.build.manifest);
|
|
341
|
+
const manifestFilePath = node_path_1.default.posix.join(outDir, manifestFilePathRelative);
|
|
342
|
+
return manifestFilePath;
|
|
343
|
+
}
|
|
@@ -11,12 +11,12 @@ const context_js_1 = require("../../../prerender/context.js");
|
|
|
11
11
|
const isViteCliCall_js_1 = require("../../shared/isViteCliCall.js");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
13
|
const logErrorHint_js_1 = require("../../../runtime/renderPage/logErrorHint.js");
|
|
14
|
-
const pluginBuildConfig_js_1 = require("./pluginBuildConfig.js");
|
|
15
14
|
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
16
15
|
const context_js_2 = require("../../../api/context.js");
|
|
17
16
|
const handleAssetsManifest_js_1 = require("./handleAssetsManifest.js");
|
|
18
17
|
const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
19
18
|
const runPrerenderEntry_js_1 = require("../../../prerender/runPrerenderEntry.js");
|
|
19
|
+
const getManifestFilePathRelative_js_1 = require("../../shared/getManifestFilePathRelative.js");
|
|
20
20
|
(0, utils_js_1.assertIsSingleModuleInstance)('build/pluginAutoFullBuild.ts');
|
|
21
21
|
let forceExit = false;
|
|
22
22
|
function pluginAutoFullBuild() {
|
|
@@ -87,7 +87,7 @@ async function triggerFullBuild(config, viteEnv, bundle) {
|
|
|
87
87
|
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
88
88
|
// - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
|
|
89
89
|
// - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
|
|
90
|
-
if (!bundle[
|
|
90
|
+
if (!bundle[(0, getManifestFilePathRelative_js_1.getManifestFilePathRelative)(config.build.manifest)])
|
|
91
91
|
return;
|
|
92
92
|
const configInline = getFullBuildInlineConfig(config);
|
|
93
93
|
if (!isBuilderApp) {
|
|
@@ -8,6 +8,34 @@ const pluginAutoFullBuild_js_1 = require("./pluginAutoFullBuild.js");
|
|
|
8
8
|
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
9
9
|
function pluginBuildApp() {
|
|
10
10
|
return [
|
|
11
|
+
{
|
|
12
|
+
name: 'vike:build:pluginBuildApp:pre',
|
|
13
|
+
apply: 'build',
|
|
14
|
+
enforce: 'pre',
|
|
15
|
+
config: {
|
|
16
|
+
order: 'pre',
|
|
17
|
+
async handler(_config) {
|
|
18
|
+
const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
19
|
+
if (!vikeConfig.config.vite6BuilderApp)
|
|
20
|
+
return;
|
|
21
|
+
return {
|
|
22
|
+
builder: {
|
|
23
|
+
// Can be overridden by another plugin e.g vike-vercel https://github.com/vikejs/vike/pull/2184#issuecomment-2659425195
|
|
24
|
+
async buildApp(builder) {
|
|
25
|
+
(0, utils_js_1.assert)(builder.environments.client);
|
|
26
|
+
(0, utils_js_1.assert)(builder.environments.ssr);
|
|
27
|
+
await builder.build(builder.environments.client);
|
|
28
|
+
await builder.build(builder.environments.ssr);
|
|
29
|
+
if ((0, pluginAutoFullBuild_js_1.isPrerenderForceExit)()) {
|
|
30
|
+
(0, runPrerenderEntry_js_1.runPrerender_forceExit)();
|
|
31
|
+
(0, utils_js_1.assert)(false);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
11
39
|
{
|
|
12
40
|
name: 'vike:build:pluginBuildApp',
|
|
13
41
|
apply: 'build',
|
|
@@ -16,19 +44,6 @@ function pluginBuildApp() {
|
|
|
16
44
|
if (!vikeConfig.config.vite6BuilderApp)
|
|
17
45
|
return;
|
|
18
46
|
return {
|
|
19
|
-
builder: {
|
|
20
|
-
// Can be overridden by another plugin e.g vike-vercel https://github.com/vikejs/vike/pull/2184#issuecomment-2659425195
|
|
21
|
-
async buildApp(builder) {
|
|
22
|
-
(0, utils_js_1.assert)(builder.environments.client);
|
|
23
|
-
(0, utils_js_1.assert)(builder.environments.ssr);
|
|
24
|
-
await builder.build(builder.environments.client);
|
|
25
|
-
await builder.build(builder.environments.ssr);
|
|
26
|
-
if ((0, pluginAutoFullBuild_js_1.isPrerenderForceExit)()) {
|
|
27
|
-
(0, runPrerenderEntry_js_1.runPrerender_forceExit)();
|
|
28
|
-
(0, utils_js_1.assert)(false);
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
47
|
environments: {
|
|
33
48
|
ssr: {
|
|
34
49
|
consumer: 'server',
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.manifestTempFile = void 0;
|
|
4
3
|
exports.pluginBuildConfig = pluginBuildConfig;
|
|
5
4
|
exports.assertRollupInput = assertRollupInput;
|
|
6
5
|
exports.analyzeClientEntries = analyzeClientEntries;
|
|
@@ -16,8 +15,6 @@ const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
|
16
15
|
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
17
16
|
const handleAssetsManifest_js_1 = require("./handleAssetsManifest.js");
|
|
18
17
|
const getPageAssets_js_1 = require("../../../runtime/renderPage/getPageAssets.js");
|
|
19
|
-
const manifestTempFile = '_temp_manifest.json';
|
|
20
|
-
exports.manifestTempFile = manifestTempFile;
|
|
21
18
|
function pluginBuildConfig() {
|
|
22
19
|
let config;
|
|
23
20
|
return [
|
|
@@ -106,6 +106,7 @@ function getIdHash(id) {
|
|
|
106
106
|
return node_crypto_1.default.createHash('md5').update(id).digest('hex').slice(0, 8);
|
|
107
107
|
}
|
|
108
108
|
function getAssetFileName(assetInfo, config) {
|
|
109
|
+
const userRootDir = config.root;
|
|
109
110
|
const assetsDir = (0, getAssetsDir_js_1.getAssetsDir)(config);
|
|
110
111
|
const dir = assetsDir + '/static';
|
|
111
112
|
let { name } = assetInfo;
|
|
@@ -123,11 +124,11 @@ function getAssetFileName(assetInfo, config) {
|
|
|
123
124
|
// Vite 3
|
|
124
125
|
name?.endsWith('?extractAssets&lang.css')) {
|
|
125
126
|
name = name.split('.').slice(0, -2).join('.');
|
|
126
|
-
name = clean(name);
|
|
127
|
+
name = clean(name, userRootDir);
|
|
127
128
|
return `${dir}/${name}.[hash][extname]`;
|
|
128
129
|
}
|
|
129
130
|
name = name.split('.').slice(0, -1).join('.');
|
|
130
|
-
name = clean(name);
|
|
131
|
+
name = clean(name, userRootDir);
|
|
131
132
|
return `${dir}/${name}.[hash][extname]`;
|
|
132
133
|
}
|
|
133
134
|
function getChunkFileName(_chunkInfo, config) {
|
|
@@ -140,11 +141,12 @@ function getChunkFileName(_chunkInfo, config) {
|
|
|
140
141
|
return name;
|
|
141
142
|
}
|
|
142
143
|
function getEntryFileName(chunkInfo, config, isEntry) {
|
|
144
|
+
const userRootDir = config.root;
|
|
143
145
|
const assetsDir = (0, getAssetsDir_js_1.getAssetsDir)(config);
|
|
144
146
|
const isForClientSide = !config.build.ssr;
|
|
145
147
|
let { name } = chunkInfo;
|
|
146
148
|
(0, utils_js_1.assertPosixPath)(name);
|
|
147
|
-
name = clean(name, true,
|
|
149
|
+
name = clean(name, userRootDir, true,
|
|
148
150
|
// Not needed for client-side because dist/ filenames contain `.[hash].js`
|
|
149
151
|
!isForClientSide);
|
|
150
152
|
if (isForClientSide) {
|
|
@@ -156,7 +158,7 @@ function getEntryFileName(chunkInfo, config, isEntry) {
|
|
|
156
158
|
}
|
|
157
159
|
function removePathSeparators(name) {
|
|
158
160
|
(0, utils_js_1.assertPosixPath)(name);
|
|
159
|
-
(0, utils_js_1.assert)(!name.startsWith('/'));
|
|
161
|
+
(0, utils_js_1.assert)(!name.startsWith('/'), { name });
|
|
160
162
|
const entryDir = 'entries/';
|
|
161
163
|
const hasEntryDir = name.startsWith(entryDir);
|
|
162
164
|
if (hasEntryDir) {
|
|
@@ -169,7 +171,17 @@ function removePathSeparators(name) {
|
|
|
169
171
|
}
|
|
170
172
|
return name;
|
|
171
173
|
}
|
|
172
|
-
function
|
|
174
|
+
function removeUserRootDir(name, userRootDir) {
|
|
175
|
+
if (name.startsWith(userRootDir)) {
|
|
176
|
+
name = name.slice(userRootDir.length);
|
|
177
|
+
if (name.startsWith('/'))
|
|
178
|
+
name = name.slice(1);
|
|
179
|
+
}
|
|
180
|
+
(0, utils_js_1.assert)(!name.startsWith('/'), { name });
|
|
181
|
+
return name;
|
|
182
|
+
}
|
|
183
|
+
function clean(name, userRootDir, removePathSep, fixGlob) {
|
|
184
|
+
name = removeUserRootDir(name, userRootDir);
|
|
173
185
|
name = fixExtractAssetsQuery(name);
|
|
174
186
|
if (fixGlob) {
|
|
175
187
|
name = workaroundGlob(name);
|