vike 0.4.236 → 0.4.237-commit-8749e81
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/runtime-client-routing/globalContext.js +2 -2
- package/dist/cjs/client/runtime-server-routing/globalContext.js +2 -2
- package/dist/cjs/client/shared/createGetGlobalContextClient.js +21 -13
- package/dist/cjs/client/shared/getJsonSerializedInHtml.js +10 -1
- package/dist/cjs/client/shared/utils.js +1 -0
- package/dist/cjs/node/api/preview.js +1 -1
- package/dist/cjs/node/prerender/runPrerender.js +4 -4
- package/dist/cjs/node/runtime/globalContext.js +127 -41
- 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/analyzePage.js +3 -3
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +5 -4
- package/dist/cjs/node/runtime/renderPage/getPageAssets/{retrieveAssetsDev.js → retrievePageAssetsDev.js} +21 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets/{retrieveAssetsProd.js → retrievePageAssetsProd.js} +19 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +8 -34
- package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +50 -14
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +23 -9
- 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/virtualFileId.js +110 -0
- package/dist/cjs/node/vite/index.js +5 -3
- package/dist/cjs/node/vite/onLoad.js +5 -3
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +31 -23
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +3 -3
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +29 -13
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +20 -14
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildEntry.js +4 -4
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +17 -5
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +6 -12
- package/dist/cjs/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +119 -73
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +8 -15
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +8 -9
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +7 -3
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +47 -0
- package/dist/cjs/node/vite/plugins/pluginPreview.js +11 -4
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +6 -13
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigsEager.js → generateVirtualFileGlobalEntry.js} +11 -9
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFileEntry.js → generateVirtualFileGlobalEntryWithOldDesign.js} +11 -11
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigLazy.js → generateVirtualFilePageEntry.js} +10 -11
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +67 -0
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +18 -17
- package/dist/cjs/node/vite/shared/findPageFiles.js +1 -1
- package/dist/cjs/node/vite/shared/{resolveClientEntriesDev.js → getClientEntrySrcDev.js} +2 -2
- 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/getOutDirs.js +18 -12
- package/dist/cjs/node/vite/shared/getViteConfigRuntime.js +1 -1
- package/dist/cjs/node/vite/shared/isViteServerBuild.js +56 -31
- package/dist/cjs/node/vite/shared/loggerVite.js +1 -1
- 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 +8 -19
- package/dist/cjs/node/vite/utils.js +1 -0
- package/dist/cjs/shared/createGlobalContextShared.js +36 -15
- package/dist/cjs/shared/getPageFiles/{parseVirtualFileExports.js → parseVirtualFileExportsGlobalEntry.js} +20 -20
- package/dist/cjs/shared/getProxyForPublicUsage.js +2 -2
- package/dist/cjs/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/cjs/shared/page-configs/loadPageEntry.js +25 -0
- package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +4 -4
- package/dist/cjs/shared/page-configs/serialize/{parsePageConfigs.js → parsePageConfigsSerialized.js} +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +16 -16
- 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 +3 -3
- package/dist/esm/client/runtime-client-routing/getPageContextCurrent.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +14 -14
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +35 -48
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +3 -3
- package/dist/esm/client/runtime-client-routing/globalContext.js +2 -2
- 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/prefetch/getPrefetchSettings.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/prefetch.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/prefetch.js +2 -2
- package/dist/esm/client/runtime-client-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +5 -5
- 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 +4 -4
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +3 -3
- package/dist/esm/client/runtime-server-routing/globalContext.js +2 -2
- package/dist/esm/client/runtime-server-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +4 -4
- package/dist/esm/client/shared/createGetGlobalContextClient.js +21 -13
- package/dist/esm/client/shared/execHookOnRenderClient.d.ts +2 -2
- package/dist/esm/client/shared/getJsonSerializedInHtml.js +10 -1
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.d.ts +1 -1
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +4 -4
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +2 -2
- package/dist/esm/client/shared/utils.d.ts +1 -0
- package/dist/esm/client/shared/utils.js +1 -0
- package/dist/esm/node/api/preview.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +49 -141
- package/dist/esm/node/prerender/runPrerender.js +4 -4
- package/dist/esm/node/runtime/globalContext.d.ts +43 -63
- package/dist/esm/node/runtime/globalContext.js +128 -42
- 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/analyzePage.js +3 -3
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +13 -36
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +5 -4
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrievePageAssetsDev.d.ts +10 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets/{retrieveAssetsDev.js → retrievePageAssetsDev.js} +22 -3
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrievePageAssetsProd.d.ts +10 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets/{retrieveAssetsProd.js → retrievePageAssetsProd.js} +19 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +0 -6
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +8 -34
- 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.d.ts +3 -3
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +26 -12
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +2 -3
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +30 -77
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -5
- package/dist/esm/node/runtime/renderPage.d.ts +13 -35
- 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/virtualFileId.d.ts +28 -0
- package/dist/esm/node/shared/virtualFileId.js +107 -0
- package/dist/esm/node/vite/index.js +5 -3
- package/dist/esm/node/vite/onLoad.js +5 -3
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +3 -3
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +32 -24
- package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +3 -3
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +29 -13
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +0 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +21 -14
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildEntry.js +4 -4
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +17 -5
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +7 -10
- 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 +121 -75
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +6 -10
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +7 -8
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +6 -2
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.d.ts +26 -0
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +45 -0
- package/dist/esm/node/vite/plugins/pluginPreview.js +13 -6
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +6 -10
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.d.ts +2 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigsEager.js → generateVirtualFileGlobalEntry.js} +11 -9
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.d.ts +6 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFileEntry.js → generateVirtualFileGlobalEntryWithOldDesign.js} +11 -11
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigLazy.js → generateVirtualFilePageEntry.js} +10 -11
- 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.js +17 -16
- package/dist/esm/node/vite/shared/findPageFiles.js +1 -1
- package/dist/esm/node/vite/shared/getClientEntrySrcDev.d.ts +4 -0
- package/dist/esm/node/vite/shared/{resolveClientEntriesDev.js → getClientEntrySrcDev.js} +2 -2
- 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/getOutDirs.d.ts +6 -3
- package/dist/esm/node/vite/shared/getOutDirs.js +19 -13
- package/dist/esm/node/vite/shared/getViteConfigRuntime.js +1 -1
- package/dist/esm/node/vite/shared/isViteServerBuild.d.ts +14 -11
- package/dist/esm/node/vite/shared/isViteServerBuild.js +58 -31
- package/dist/esm/node/vite/shared/loggerVite.js +1 -1
- 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 +3 -5
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +10 -21
- 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 +8 -8
- package/dist/esm/shared/createGlobalContextShared.js +38 -17
- package/dist/esm/shared/getPageFiles/{parseVirtualFileExports.d.ts → parseVirtualFileExportsGlobalEntry.d.ts} +2 -2
- package/dist/esm/shared/getPageFiles/{parseVirtualFileExports.js → parseVirtualFileExportsGlobalEntry.js} +20 -20
- package/dist/esm/shared/getPageFiles.d.ts +1 -1
- package/dist/esm/shared/hooks/execHook.d.ts +2 -2
- package/dist/esm/shared/hooks/getHook.d.ts +3 -3
- package/dist/esm/shared/modifyUrlSameOrigin.d.ts +1 -1
- package/dist/esm/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/esm/shared/page-configs/loadPageEntry.d.ts +3 -0
- package/dist/esm/shared/page-configs/loadPageEntry.js +23 -0
- package/dist/esm/shared/page-configs/resolveVikeConfigPublic.d.ts +9 -9
- package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +4 -4
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +1 -1
- package/dist/esm/shared/page-configs/serialize/{parsePageConfigs.d.ts → parsePageConfigsSerialized.d.ts} +2 -2
- package/dist/esm/shared/page-configs/serialize/{parsePageConfigs.js → parsePageConfigsSerialized.js} +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +17 -17
- 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/PageConfig.d.ts +9 -7
- package/dist/esm/types/VikeNamespace.d.ts +13 -0
- 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 +16 -7
- package/dist/cjs/node/shared/virtualFiles/virtualFileEntry.js +0 -29
- package/dist/cjs/node/shared/virtualFiles/virtualFilePageConfigLazy.js +0 -39
- package/dist/cjs/node/shared/virtualFiles.js +0 -41
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -23
- package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +0 -10
- package/dist/cjs/shared/page-configs/loadConfigValues.js +0 -21
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.d.ts +0 -4
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +0 -4
- package/dist/esm/node/shared/virtualFiles/virtualFileEntry.d.ts +0 -11
- package/dist/esm/node/shared/virtualFiles/virtualFileEntry.js +0 -26
- package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.d.ts +0 -9
- package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.js +0 -37
- package/dist/esm/node/shared/virtualFiles.d.ts +0 -8
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFileEntry.d.ts +0 -5
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.d.ts +0 -3
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.d.ts +0 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.d.ts +0 -7
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -21
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.d.ts +0 -3
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +0 -8
- package/dist/esm/node/vite/shared/resolveClientEntriesDev.d.ts +0 -4
- package/dist/esm/shared/page-configs/loadConfigValues.d.ts +0 -3
- package/dist/esm/shared/page-configs/loadConfigValues.js +0 -19
|
@@ -18,17 +18,23 @@ export { clearGlobalContext };
|
|
|
18
18
|
export { assertBuildInfo };
|
|
19
19
|
export { updateUserFiles };
|
|
20
20
|
export { vikeConfigErrorRecoverMsg };
|
|
21
|
+
// TODO/now: use isProductionEnvironment() instead of globalObject.isProduction
|
|
22
|
+
// TODO/now: rename:
|
|
23
|
+
// - isProduction => isProductionEnvironment
|
|
24
|
+
// - setIsProduction => setIsProductionEnvironment
|
|
25
|
+
// - setGlobalContext_isProduction => setGlobalContext_isProductionEnvironment
|
|
26
|
+
// - sProductionEnvironment => sDevEnv
|
|
21
27
|
// The core logic revolves around:
|
|
22
|
-
// -
|
|
28
|
+
// - virtualFileExportsGlobalEntry is the main requirement
|
|
23
29
|
// - In production: globalObject.buildEntry which is the production entry set by @brillout/vite-plugin-server-entry
|
|
24
|
-
// - loadBuildEntry() sets globalObject.buildEntry and then sets
|
|
30
|
+
// - loadBuildEntry() sets globalObject.buildEntry and then sets virtualFileExportsGlobalEntry
|
|
25
31
|
// - With vike-server it's set at server start: @brillout/vite-plugin-server-entry injects `import './entry.mjs'` (the production entry generated by @brillout/vite-plugin-server-entry) as first line of code of dist/server/index.mjs while dist/server/entry.mjs calls setGlobalContext_buildEntry()
|
|
26
32
|
// - Without vike-server it's manually loaded here using importServerProductionEntry() which uses @brillout/vite-plugin-server-entry's autoImporter or crawler
|
|
27
33
|
// - In development: globalObject.viteDevServer which is Vite's development server
|
|
28
|
-
// - globalObject.viteDevServer is used by updateUserFiles() which then sets
|
|
29
|
-
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, } from './utils.js';
|
|
34
|
+
// - globalObject.viteDevServer is used by updateUserFiles() which then sets virtualFileExportsGlobalEntry
|
|
35
|
+
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, getViteRPC, isRunnableDevEnvironment, assertIsNotBrowser, } from './utils.js';
|
|
30
36
|
import { importServerProductionEntry } from '@brillout/vite-plugin-server-entry/runtime';
|
|
31
|
-
import {
|
|
37
|
+
import { virtualFileIdGlobalEntryServer } from '../shared/virtualFileId.js';
|
|
32
38
|
import pc from '@brillout/picocolors';
|
|
33
39
|
import { loadPageRoutes, loadPageRoutesSync } from '../../shared/route/loadPageRoutes.js';
|
|
34
40
|
import { assertV1Design } from '../shared/assertV1Design.js';
|
|
@@ -44,6 +50,7 @@ const globalObject = getGlobalObject('runtime/globalContext.ts', getInitialGloba
|
|
|
44
50
|
// https://chat.deepseek.com/a/chat/s/d7e9f90a-c7f3-4108-9cd5-4ad6caed3539
|
|
45
51
|
const globalObjectTyped = globalObject;
|
|
46
52
|
const vikeConfigErrorRecoverMsg = pc.bold(pc.green('Vike config loaded'));
|
|
53
|
+
assertIsNotBrowser();
|
|
47
54
|
async function getGlobalContextServerInternal() {
|
|
48
55
|
// getGlobalContextServerInternal() should always be called after initGlobalContext()
|
|
49
56
|
assert(globalObject.isInitialized);
|
|
@@ -130,10 +137,12 @@ async function setGlobalContext_viteDevServer(viteDevServer) {
|
|
|
130
137
|
assert(globalObject.viteConfig);
|
|
131
138
|
globalObject.viteDevServer = viteDevServer;
|
|
132
139
|
globalObject.viteDevServerPromiseResolve(viteDevServer);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
140
|
+
if (isRunnable(viteDevServer)) {
|
|
141
|
+
const { success } = await updateUserFiles();
|
|
142
|
+
if (!success)
|
|
143
|
+
return;
|
|
144
|
+
assertGlobalContextIsDefined();
|
|
145
|
+
}
|
|
137
146
|
}
|
|
138
147
|
function setGlobalContext_viteConfig(viteConfig, viteConfigRuntime) {
|
|
139
148
|
if (globalObject.viteConfig)
|
|
@@ -150,12 +159,14 @@ function setGlobalContext_isPrerendering() {
|
|
|
150
159
|
globalObject.isPrerendering = true;
|
|
151
160
|
setIsProduction(true);
|
|
152
161
|
}
|
|
153
|
-
function setGlobalContext_isProduction(isProduction,
|
|
162
|
+
function setGlobalContext_isProduction(isProduction, tolerateContradiction = false) {
|
|
163
|
+
if (debug.isActivated)
|
|
164
|
+
debug('setGlobalContext_isProduction()', { isProduction, tolerateContradiction });
|
|
154
165
|
if (globalObject.isProduction === undefined) {
|
|
155
166
|
setIsProduction(isProduction);
|
|
156
167
|
}
|
|
157
168
|
else {
|
|
158
|
-
assert(globalObject.isProduction === isProduction ||
|
|
169
|
+
assert(globalObject.isProduction === isProduction || tolerateContradiction);
|
|
159
170
|
}
|
|
160
171
|
}
|
|
161
172
|
function getViteDevServer() {
|
|
@@ -199,7 +210,13 @@ async function initGlobalContext() {
|
|
|
199
210
|
const { isProduction } = globalObject;
|
|
200
211
|
assert(typeof isProduction === 'boolean');
|
|
201
212
|
if (!isProduction) {
|
|
202
|
-
|
|
213
|
+
if (isProcessSharedWithVite()) {
|
|
214
|
+
await globalObject.viteDevServerPromise;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
assert(isNonRunnableDev());
|
|
218
|
+
await updateUserFiles();
|
|
219
|
+
}
|
|
203
220
|
assert(globalObject.waitForUserFilesUpdate);
|
|
204
221
|
await globalObject.waitForUserFilesUpdate;
|
|
205
222
|
}
|
|
@@ -256,7 +273,7 @@ async function loadBuildEntry(outDir) {
|
|
|
256
273
|
assertBuildEntry(buildEntry);
|
|
257
274
|
globalObject.assetsManifest = buildEntry.assetsManifest;
|
|
258
275
|
globalObject.buildInfo = buildEntry.buildInfo;
|
|
259
|
-
await
|
|
276
|
+
await createGlobalContext(buildEntry.virtualFileExportsGlobalEntry);
|
|
260
277
|
}
|
|
261
278
|
// This is the production entry, see:
|
|
262
279
|
// https://github.com/vikejs/vike/blob/798e5465dc3e3e6723b38b601a50350c0a006fb8/packages/vike/node/vite/plugins/pluginBuild/pluginBuildEntry.ts#L47
|
|
@@ -273,15 +290,15 @@ async function setGlobalContext_buildEntry(buildEntry) {
|
|
|
273
290
|
}
|
|
274
291
|
function assertBuildEntry(buildEntry) {
|
|
275
292
|
assert(isObject(buildEntry));
|
|
276
|
-
assert(hasProp(buildEntry, '
|
|
277
|
-
const {
|
|
293
|
+
assert(hasProp(buildEntry, 'virtualFileExportsGlobalEntry', 'object'));
|
|
294
|
+
const { virtualFileExportsGlobalEntry } = buildEntry;
|
|
278
295
|
assert(hasProp(buildEntry, 'assetsManifest', 'object'));
|
|
279
296
|
const { assetsManifest } = buildEntry;
|
|
280
297
|
assertViteManifest(assetsManifest);
|
|
281
298
|
assert(hasProp(buildEntry, 'buildInfo', 'object'));
|
|
282
299
|
const { buildInfo } = buildEntry;
|
|
283
300
|
assertBuildInfo(buildInfo);
|
|
284
|
-
checkType({
|
|
301
|
+
checkType({ virtualFileExportsGlobalEntry, assetsManifest, buildInfo });
|
|
285
302
|
}
|
|
286
303
|
function assertBuildInfo(buildInfo) {
|
|
287
304
|
assert(isObject(buildInfo));
|
|
@@ -301,6 +318,7 @@ function assertVersionAtBuildTime(versionAtBuildTime) {
|
|
|
301
318
|
assertUsage(versionAtBuildTime === versionAtRuntime, `Re-build your app (you're using ${pretty(versionAtRuntime)} but your app was built with ${pretty(versionAtBuildTime)})`);
|
|
302
319
|
}
|
|
303
320
|
async function updateUserFiles() {
|
|
321
|
+
debug('updateUserFiles()');
|
|
304
322
|
assert(!globalObject.isProduction);
|
|
305
323
|
const { promise, resolve } = genPromise();
|
|
306
324
|
globalObject.waitForUserFilesUpdate = promise;
|
|
@@ -333,27 +351,57 @@ async function updateUserFiles() {
|
|
|
333
351
|
// Avoid race condition: abort if there is a new globalObject.viteDevServer (happens when vite.config.js is modified => Vite's dev server is fully reloaded).
|
|
334
352
|
viteDevServer !== globalObject.viteDevServer;
|
|
335
353
|
const { viteDevServer } = globalObject;
|
|
336
|
-
assert(viteDevServer);
|
|
337
354
|
let hasError = false;
|
|
338
|
-
let
|
|
355
|
+
let virtualFileExportsGlobalEntry;
|
|
339
356
|
let err;
|
|
340
|
-
|
|
341
|
-
|
|
357
|
+
if (viteDevServer) {
|
|
358
|
+
assert(isRunnable(viteDevServer));
|
|
359
|
+
/* We don't use runner.import() yet, because as of vite@7.0.6 (July 2025) runner.import() unexpectedly invalidates the module graph, which is a unexpected behavior that doesn't happen with ssrLoadModule()
|
|
360
|
+
// Vite 6
|
|
361
|
+
try {
|
|
362
|
+
virtualFileExportsGlobalEntry = await (viteDevServer.environments.ssr as RunnableDevEnvironment).runner.import(
|
|
363
|
+
'virtual:vike:global-entry:server',
|
|
364
|
+
)
|
|
365
|
+
} catch (err_) {
|
|
366
|
+
hasError = true
|
|
367
|
+
err = err_
|
|
368
|
+
}
|
|
369
|
+
*/
|
|
370
|
+
// Vite 5
|
|
371
|
+
try {
|
|
372
|
+
virtualFileExportsGlobalEntry = await viteDevServer.ssrLoadModule(virtualFileIdGlobalEntryServer);
|
|
373
|
+
}
|
|
374
|
+
catch (err_) {
|
|
375
|
+
hasError = true;
|
|
376
|
+
err = err_;
|
|
377
|
+
}
|
|
342
378
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
379
|
+
else {
|
|
380
|
+
try {
|
|
381
|
+
/* We use __VIKE__DYNAMIC_IMPORT instead of directly using import() to workaround what seems to be a Vite HMR bug:
|
|
382
|
+
```js
|
|
383
|
+
assert(false)
|
|
384
|
+
// This line breaks the HMR of regular (runnable) apps, even though (as per the assert() above) it's never run. It seems to be a Vite bug: handleHotUpdate() receives an empty `modules` list.
|
|
385
|
+
import('virtual:vike:global-entry:server')
|
|
386
|
+
```
|
|
387
|
+
*/
|
|
388
|
+
virtualFileExportsGlobalEntry = await __VIKE__DYNAMIC_IMPORT('virtual:vike:global-entry:server');
|
|
389
|
+
}
|
|
390
|
+
catch (err_) {
|
|
391
|
+
hasError = true;
|
|
392
|
+
err = err_;
|
|
393
|
+
}
|
|
346
394
|
}
|
|
347
395
|
if (isOutdated())
|
|
348
396
|
return { success: false };
|
|
349
397
|
if (hasError)
|
|
350
398
|
return onError(err);
|
|
351
|
-
|
|
399
|
+
virtualFileExportsGlobalEntry = virtualFileExportsGlobalEntry.default || virtualFileExportsGlobalEntry;
|
|
352
400
|
if (getVikeConfigErrorBuild()) {
|
|
353
401
|
return { success: false };
|
|
354
402
|
}
|
|
355
403
|
try {
|
|
356
|
-
await
|
|
404
|
+
await createGlobalContext(virtualFileExportsGlobalEntry);
|
|
357
405
|
}
|
|
358
406
|
catch (err_) {
|
|
359
407
|
hasError = true;
|
|
@@ -365,26 +413,26 @@ async function updateUserFiles() {
|
|
|
365
413
|
return onError(err);
|
|
366
414
|
return onSuccess();
|
|
367
415
|
}
|
|
368
|
-
async function
|
|
369
|
-
debug('
|
|
416
|
+
async function createGlobalContext(virtualFileExportsGlobalEntry) {
|
|
417
|
+
debug('createGlobalContext()');
|
|
370
418
|
assert(!getVikeConfigErrorBuild());
|
|
371
|
-
const globalContext = await createGlobalContextShared(
|
|
419
|
+
const globalContext = await createGlobalContextShared(virtualFileExportsGlobalEntry, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
|
|
372
420
|
assertV1Design(
|
|
373
421
|
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
374
422
|
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
375
423
|
assertGlobalContextIsDefined();
|
|
376
424
|
onSetupRuntime();
|
|
377
|
-
debug('
|
|
378
|
-
// Never actually used, only used for TypeScript `ReturnType<typeof
|
|
425
|
+
debug('createGlobalContext() - done');
|
|
426
|
+
// Never actually used, only used for TypeScript `ReturnType<typeof createGlobalContext>`
|
|
379
427
|
return globalContext;
|
|
380
428
|
}
|
|
381
|
-
async function
|
|
382
|
-
debug('
|
|
429
|
+
async function addGlobalContextTmp(globalContext) {
|
|
430
|
+
debug('addGlobalContextTmp()');
|
|
383
431
|
const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
384
432
|
return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
|
|
385
433
|
}
|
|
386
|
-
function
|
|
387
|
-
debug('
|
|
434
|
+
function addGlobalContext(globalContext) {
|
|
435
|
+
debug('addGlobalContext()');
|
|
388
436
|
const { pageRoutes, onBeforeRouteHook } = loadPageRoutesSync(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
389
437
|
return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
|
|
390
438
|
}
|
|
@@ -394,23 +442,18 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
|
|
|
394
442
|
_pageRoutes: pageRoutes,
|
|
395
443
|
_onBeforeRouteHook: onBeforeRouteHook,
|
|
396
444
|
};
|
|
397
|
-
const { viteDevServer, viteConfig,
|
|
445
|
+
const { viteDevServer, viteConfig, isPrerendering, isProduction } = globalObject;
|
|
398
446
|
assert(typeof isProduction === 'boolean');
|
|
399
447
|
if (!isProduction) {
|
|
400
|
-
assert(viteDevServer);
|
|
401
448
|
assert(globalContext); // main common requirement
|
|
402
|
-
assert(viteConfig);
|
|
403
|
-
assert(viteConfigRuntime);
|
|
404
449
|
assert(!isPrerendering);
|
|
405
450
|
return {
|
|
406
451
|
...globalContextBase,
|
|
407
|
-
...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
|
|
408
452
|
_isProduction: false,
|
|
409
453
|
_isPrerendering: false,
|
|
410
454
|
assetsManifest: null,
|
|
411
455
|
_viteDevServer: viteDevServer,
|
|
412
456
|
viteConfig,
|
|
413
|
-
viteConfigRuntime,
|
|
414
457
|
};
|
|
415
458
|
}
|
|
416
459
|
else {
|
|
@@ -421,11 +464,9 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
|
|
|
421
464
|
assert(assetsManifest);
|
|
422
465
|
const globalContextBase2 = {
|
|
423
466
|
...globalContextBase,
|
|
424
|
-
...resolveBaseRuntime(buildInfo.viteConfigRuntime, globalContext.config),
|
|
425
467
|
_isProduction: true,
|
|
426
468
|
assetsManifest,
|
|
427
469
|
_viteDevServer: null,
|
|
428
|
-
viteConfigRuntime: buildInfo.viteConfigRuntime,
|
|
429
470
|
_usesClientRouter: buildInfo.usesClientRouter,
|
|
430
471
|
};
|
|
431
472
|
if (isPrerendering) {
|
|
@@ -445,6 +486,27 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
|
|
|
445
486
|
}
|
|
446
487
|
}
|
|
447
488
|
}
|
|
489
|
+
async function addGlobalContextAsync(globalContext) {
|
|
490
|
+
debug('addGlobalContextAsync()');
|
|
491
|
+
let { viteConfigRuntime, buildInfo } = globalObject;
|
|
492
|
+
if (!viteConfigRuntime) {
|
|
493
|
+
if (buildInfo) {
|
|
494
|
+
viteConfigRuntime = buildInfo.viteConfigRuntime;
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
assert(!isProcessSharedWithVite()); // process shared with Vite => globalObject.viteConfigRuntime should be set
|
|
498
|
+
assert(!globalObject.isProduction); // production => globalObject.buildInfo.viteConfigRuntime should be set
|
|
499
|
+
assert(isNonRunnableDev());
|
|
500
|
+
const rpc = getViteRPC();
|
|
501
|
+
viteConfigRuntime = await rpc.getViteConfigRuntimeRPC();
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
assert(viteConfigRuntime);
|
|
505
|
+
return {
|
|
506
|
+
viteConfigRuntime,
|
|
507
|
+
...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
|
|
508
|
+
};
|
|
509
|
+
}
|
|
448
510
|
function clearGlobalContext() {
|
|
449
511
|
debug('clearGlobalContext()');
|
|
450
512
|
objectReplace(globalObject, getInitialGlobalObject(), ['buildEntryPrevious']);
|
|
@@ -453,6 +515,7 @@ function getInitialGlobalObject() {
|
|
|
453
515
|
debug('getInitialGlobalObject()');
|
|
454
516
|
const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = genPromise();
|
|
455
517
|
return {
|
|
518
|
+
isProduction: isNonRunnableDev() ? false : undefined,
|
|
456
519
|
viteDevServerPromise,
|
|
457
520
|
viteDevServerPromiseResolve,
|
|
458
521
|
};
|
|
@@ -463,3 +526,26 @@ function resolveBaseRuntime(viteConfigRuntime, config) {
|
|
|
463
526
|
const baseAssetsUnresolved = config.baseAssets ?? null;
|
|
464
527
|
return resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
|
|
465
528
|
}
|
|
529
|
+
function isProcessSharedWithVite() {
|
|
530
|
+
const yes = globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE ?? false;
|
|
531
|
+
if (yes)
|
|
532
|
+
assert(!isNonRunnableDev());
|
|
533
|
+
return yes;
|
|
534
|
+
}
|
|
535
|
+
function isRunnable(viteDevServer) {
|
|
536
|
+
const yes =
|
|
537
|
+
// Vite 5
|
|
538
|
+
!viteDevServer.environments ||
|
|
539
|
+
// Vite 6 or above
|
|
540
|
+
isRunnableDevEnvironment(viteDevServer.environments.ssr);
|
|
541
|
+
if (yes)
|
|
542
|
+
assert(!isNonRunnableDev());
|
|
543
|
+
return yes;
|
|
544
|
+
}
|
|
545
|
+
function isNonRunnableDev() {
|
|
546
|
+
if (typeof __VIKE__IS_NON_RUNNABLE_DEV === 'undefined')
|
|
547
|
+
return null;
|
|
548
|
+
const yes = __VIKE__IS_NON_RUNNABLE_DEV;
|
|
549
|
+
assert(typeof yes === 'boolean');
|
|
550
|
+
return yes;
|
|
551
|
+
}
|
|
@@ -182,7 +182,7 @@ function mergeScriptEntries(pageAssets, viteDevScript) {
|
|
|
182
182
|
return scriptEntry;
|
|
183
183
|
}
|
|
184
184
|
function getPageContextJsonScriptTag(pageContext) {
|
|
185
|
-
const pageContextClientSerialized = sanitizeJson(getPageContextClientSerialized(pageContext));
|
|
185
|
+
const pageContextClientSerialized = sanitizeJson(getPageContextClientSerialized(pageContext, true));
|
|
186
186
|
const htmlTag = `<script id="${htmlElementId_pageContext}" type="application/json">${pageContextClientSerialized}</script>`;
|
|
187
187
|
// Used by contra.com https://github.com/gajus
|
|
188
188
|
// @ts-expect-error
|
|
@@ -190,7 +190,7 @@ function getPageContextJsonScriptTag(pageContext) {
|
|
|
190
190
|
return htmlTag;
|
|
191
191
|
}
|
|
192
192
|
function getGlobalContextJsonScriptTag(pageContext) {
|
|
193
|
-
const globalContextClientSerialized = sanitizeJson(getGlobalContextClientSerialized(pageContext));
|
|
193
|
+
const globalContextClientSerialized = sanitizeJson(getGlobalContextClientSerialized(pageContext, true));
|
|
194
194
|
const htmlTag = `<script id="${htmlElementId_globalContext}" type="application/json">${globalContextClientSerialized}</script>`;
|
|
195
195
|
return htmlTag;
|
|
196
196
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getViteDevScript };
|
|
2
|
-
import { assert, assertUsage, assertWarning } from '../../utils.js';
|
|
2
|
+
import { assert, assertUsage, assertWarning, getViteRPC } from '../../utils.js';
|
|
3
3
|
import pc from '@brillout/picocolors';
|
|
4
4
|
const reachOutCTA = 'Create a new GitHub issue to discuss a solution.';
|
|
5
5
|
async function getViteDevScript(pageContext) {
|
|
@@ -11,7 +11,9 @@ async function getViteDevScript(pageContext) {
|
|
|
11
11
|
const fakeHtmlBegin = '<html> <head>'; // White space to test whether user is using a minifier
|
|
12
12
|
const fakeHtmlEnd = '</head><body></body></html>';
|
|
13
13
|
let fakeHtml = fakeHtmlBegin + fakeHtmlEnd;
|
|
14
|
-
fakeHtml =
|
|
14
|
+
fakeHtml = viteDevServer
|
|
15
|
+
? await viteDevServer.transformIndexHtml('/', fakeHtml)
|
|
16
|
+
: await getViteRPC().transformIndexHtmlRPC(fakeHtml);
|
|
15
17
|
assertUsage(!fakeHtml.includes('vite-plugin-pwa'), `The HTML transformer of ${pc.cyan('vite-plugin-pwa')} cannot be applied, see workaround at https://github.com/vikejs/vike/issues/388#issuecomment-1199280084`);
|
|
16
18
|
assertUsage(!fakeHtml.startsWith(fakeHtmlBegin.replace(' ', '')), `Vite plugins that minify the HTML cannot be applied, see https://github.com/vikejs/vike/issues/224`);
|
|
17
19
|
assertUsage(fakeHtml.startsWith(fakeHtmlBegin) && fakeHtml.endsWith(fakeHtmlEnd), `You are using a Vite Plugin that transforms the HTML in a way that conflicts with Vike. ${reachOutCTA}`);
|
|
@@ -3,9 +3,12 @@ export { getPageContextClientSerializedAbort };
|
|
|
3
3
|
export { getGlobalContextClientSerialized };
|
|
4
4
|
export type { PageContextSerialization };
|
|
5
5
|
export type { PassToClient };
|
|
6
|
+
export type { PassToClientPublic };
|
|
6
7
|
import type { UrlRedirect } from '../../../shared/route/abort.js';
|
|
7
8
|
import type { GlobalContextServerInternal } from '../globalContext.js';
|
|
8
|
-
type
|
|
9
|
+
import type { PageContextCreated } from '../renderPage/createPageContextServerSide.js';
|
|
10
|
+
import type { PageContextBegin } from '../renderPage.js';
|
|
11
|
+
type PageContextSerialization = PageContextCreated & {
|
|
9
12
|
pageId: string;
|
|
10
13
|
routeParams: Record<string, string>;
|
|
11
14
|
_passToClient: PassToClient;
|
|
@@ -13,12 +16,14 @@ type PageContextSerialization = {
|
|
|
13
16
|
pageProps?: Record<string, unknown>;
|
|
14
17
|
_pageContextInit: Record<string, unknown>;
|
|
15
18
|
_globalContext: GlobalContextServerInternal;
|
|
16
|
-
|
|
19
|
+
_isPageContextJsonRequest: null | PageContextBegin['_isPageContextJsonRequest'];
|
|
17
20
|
};
|
|
18
|
-
declare function getPageContextClientSerialized(pageContext: PageContextSerialization): string;
|
|
19
|
-
declare function getGlobalContextClientSerialized(pageContext: PageContextSerialization): string;
|
|
20
|
-
type PassToClient =
|
|
21
|
+
declare function getPageContextClientSerialized(pageContext: PageContextSerialization, isHtmlJsonScript: boolean): string;
|
|
22
|
+
declare function getGlobalContextClientSerialized(pageContext: PageContextSerialization, isHtmlJsonScript: boolean): string;
|
|
23
|
+
type PassToClient = string[];
|
|
24
|
+
type PassToClientPublic = (string | {
|
|
21
25
|
prop: string;
|
|
26
|
+
/** @deprecated 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). */
|
|
22
27
|
once?: boolean;
|
|
23
28
|
})[];
|
|
24
29
|
declare function getPageContextClientSerializedAbort(pageContext: Record<string, unknown> & ({
|
|
@@ -27,4 +32,4 @@ declare function getPageContextClientSerializedAbort(pageContext: Record<string,
|
|
|
27
32
|
_urlRewrite: string;
|
|
28
33
|
} | {
|
|
29
34
|
abortStatusCode: number;
|
|
30
|
-
})): string;
|
|
35
|
+
}), isHtmlJsonScript: false): string;
|
|
@@ -25,63 +25,42 @@ const passToClientBuiltInPageContext = [
|
|
|
25
25
|
'data', // for data() hook
|
|
26
26
|
];
|
|
27
27
|
const pageToClientBuiltInPageContextError = ['pageProps', 'is404', isServerSideError];
|
|
28
|
-
function getPageContextClientSerialized(pageContext) {
|
|
28
|
+
function getPageContextClientSerialized(pageContext, isHtmlJsonScript) {
|
|
29
29
|
const passToClientPageContext = getPassToClientPageContext(pageContext);
|
|
30
|
-
const
|
|
31
|
-
if (passToClientEntry.once)
|
|
32
|
-
return undefined; // pass it to client-side globalContext
|
|
33
|
-
return { obj: pageContext, objName: 'pageContext' };
|
|
34
|
-
};
|
|
35
|
-
const res = applyPassToClient(passToClientPageContext, getObj);
|
|
30
|
+
const res = applyPassToClient(passToClientPageContext, pageContext);
|
|
36
31
|
const pageContextClient = res.objClient;
|
|
37
32
|
const pageContextClientProps = res.objClientProps;
|
|
38
33
|
if (pageContextClientProps.some((prop) => getPropVal(pageContext._pageContextInit, prop))) {
|
|
39
34
|
pageContextClient[pageContextInitIsPassedToClient] = true;
|
|
40
35
|
}
|
|
41
|
-
const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext,
|
|
36
|
+
const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext, 'pageContext', isHtmlJsonScript);
|
|
42
37
|
return pageContextClientSerialized;
|
|
43
38
|
}
|
|
44
|
-
function getGlobalContextClientSerialized(pageContext) {
|
|
39
|
+
function getGlobalContextClientSerialized(pageContext, isHtmlJsonScript) {
|
|
45
40
|
const passToClient = pageContext._passToClient;
|
|
46
41
|
const globalContext = pageContext._globalContext;
|
|
47
|
-
const
|
|
48
|
-
if (once && getPropVal(pageContext, prop)) {
|
|
49
|
-
assert(typeof pageContext.isClientSideNavigation === 'boolean');
|
|
50
|
-
if (!pageContext.isClientSideNavigation) {
|
|
51
|
-
return { obj: pageContext, objName: 'pageContext' }; // pass it to client-side globalContext
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
return undefined; // already passed to client-side
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return { obj: globalContext, objName: 'globalContext' };
|
|
58
|
-
};
|
|
59
|
-
const res = applyPassToClient(passToClient, getObj);
|
|
42
|
+
const res = applyPassToClient(passToClient, globalContext);
|
|
60
43
|
const globalContextClient = res.objClient;
|
|
61
|
-
const globalContextClientSerialized = serializeObject(globalContextClient, passToClient,
|
|
44
|
+
const globalContextClientSerialized = serializeObject(globalContextClient, passToClient, 'globalContext', isHtmlJsonScript);
|
|
62
45
|
return globalContextClientSerialized;
|
|
63
46
|
}
|
|
64
|
-
function serializeObject(obj, passToClient,
|
|
47
|
+
function serializeObject(obj, passToClient, objName, isHtmlJsonScript) {
|
|
65
48
|
let serialized;
|
|
66
49
|
try {
|
|
67
|
-
serialized = serializeValue(obj);
|
|
50
|
+
serialized = serializeValue(obj, isHtmlJsonScript);
|
|
68
51
|
}
|
|
69
52
|
catch (err) {
|
|
70
53
|
const h = (s) => pc.cyan(s);
|
|
71
54
|
let hasWarned = false;
|
|
72
55
|
const propsNonSerializable = [];
|
|
73
|
-
passToClient.forEach((
|
|
74
|
-
const entryNormalized = normalizePassToClientEntry(entry);
|
|
75
|
-
const { prop } = entryNormalized;
|
|
56
|
+
passToClient.forEach((prop) => {
|
|
76
57
|
const res = getPropVal(obj, prop);
|
|
77
58
|
if (!res)
|
|
78
59
|
return;
|
|
79
60
|
const { value } = res;
|
|
80
|
-
const { objName } = getObj(entryNormalized) ?? {};
|
|
81
|
-
assert(objName);
|
|
82
61
|
const varName = `${objName}${getPropKeys(prop).map(getPropAccessNotation).join('')}`;
|
|
83
62
|
try {
|
|
84
|
-
serializeValue(value, varName);
|
|
63
|
+
serializeValue(value, isHtmlJsonScript, varName);
|
|
85
64
|
}
|
|
86
65
|
catch (err) {
|
|
87
66
|
propsNonSerializable.push(prop);
|
|
@@ -119,7 +98,7 @@ function serializeObject(obj, passToClient, getObj) {
|
|
|
119
98
|
obj[getPropKeys(prop)[0]] = NOT_SERIALIZABLE;
|
|
120
99
|
});
|
|
121
100
|
try {
|
|
122
|
-
serialized = serializeValue(obj);
|
|
101
|
+
serialized = serializeValue(obj, isHtmlJsonScript);
|
|
123
102
|
}
|
|
124
103
|
catch (err) {
|
|
125
104
|
assert(false);
|
|
@@ -127,20 +106,20 @@ function serializeObject(obj, passToClient, getObj) {
|
|
|
127
106
|
}
|
|
128
107
|
return serialized;
|
|
129
108
|
}
|
|
130
|
-
function serializeValue(value, varName) {
|
|
109
|
+
function serializeValue(value, isHtmlJsonScript, varName) {
|
|
131
110
|
return stringify(value, {
|
|
132
111
|
forbidReactElements: true,
|
|
133
112
|
valueName: varName,
|
|
134
113
|
// Prevent Google from crawling URLs in JSON:
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
114
|
+
// - https://github.com/vikejs/vike/pull/2603
|
|
115
|
+
// - https://github.com/brillout/json-serializer/blob/38edbb9945de4938da1e65d6285ce1dd123a45ef/test/main.spec.ts#L44-L95
|
|
116
|
+
replacer: !isHtmlJsonScript
|
|
117
|
+
? undefined
|
|
118
|
+
: (_key, value) => {
|
|
119
|
+
if (typeof value === 'string') {
|
|
120
|
+
return { replacement: value.replaceAll('/', '\\/'), resolved: false };
|
|
121
|
+
}
|
|
122
|
+
},
|
|
144
123
|
});
|
|
145
124
|
}
|
|
146
125
|
function getPassToClientPageContext(pageContext) {
|
|
@@ -153,7 +132,7 @@ function getPassToClientPageContext(pageContext) {
|
|
|
153
132
|
passToClient = unique(passToClient);
|
|
154
133
|
return passToClient;
|
|
155
134
|
}
|
|
156
|
-
function getPageContextClientSerializedAbort(pageContext) {
|
|
135
|
+
function getPageContextClientSerializedAbort(pageContext, isHtmlJsonScript) {
|
|
157
136
|
assert(pageContext._urlRedirect || pageContext._urlRewrite || pageContext.abortStatusCode);
|
|
158
137
|
assert(pageContext._abortCall);
|
|
159
138
|
assert(pageContext._abortCaller);
|
|
@@ -186,17 +165,12 @@ function getPageContextClientSerializedAbort(pageContext) {
|
|
|
186
165
|
onlyOnce: false,
|
|
187
166
|
});
|
|
188
167
|
}
|
|
189
|
-
return serializeValue(pageContext);
|
|
168
|
+
return serializeValue(pageContext, isHtmlJsonScript);
|
|
190
169
|
}
|
|
191
|
-
function applyPassToClient(passToClient,
|
|
170
|
+
function applyPassToClient(passToClient, obj) {
|
|
192
171
|
const objClient = {};
|
|
193
172
|
const objClientProps = [];
|
|
194
|
-
passToClient.forEach((
|
|
195
|
-
const entryNormalized = normalizePassToClientEntry(entry);
|
|
196
|
-
const { prop } = entryNormalized;
|
|
197
|
-
const { obj } = getObj(entryNormalized) ?? {};
|
|
198
|
-
if (!obj)
|
|
199
|
-
return;
|
|
173
|
+
passToClient.forEach((prop) => {
|
|
200
174
|
// Get value from pageContext
|
|
201
175
|
const res = getPropVal(obj, prop);
|
|
202
176
|
if (!res)
|
|
@@ -208,16 +182,3 @@ function applyPassToClient(passToClient, getObj) {
|
|
|
208
182
|
});
|
|
209
183
|
return { objClient, objClientProps };
|
|
210
184
|
}
|
|
211
|
-
function normalizePassToClientEntry(entry) {
|
|
212
|
-
let once;
|
|
213
|
-
let prop;
|
|
214
|
-
if (typeof entry === 'string') {
|
|
215
|
-
prop = entry;
|
|
216
|
-
once = false;
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
prop = entry.prop;
|
|
220
|
-
once = entry.once ?? false;
|
|
221
|
-
}
|
|
222
|
-
return { prop, once };
|
|
223
|
-
}
|
|
@@ -522,8 +522,8 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
522
522
|
const closeStream = async () => {
|
|
523
523
|
if (isClosed)
|
|
524
524
|
return;
|
|
525
|
-
isClosed = true;
|
|
526
525
|
await onEnd(isCancel);
|
|
526
|
+
isClosed = true;
|
|
527
527
|
controllerProxy.close();
|
|
528
528
|
};
|
|
529
529
|
let controllerProxy;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { analyzePage };
|
|
2
2
|
import { getVikeClientEntry } from '../../../shared/getPageFiles/analyzePageClientSide/determineClientEntry.js';
|
|
3
3
|
import { analyzePageClientSide } from '../../../shared/getPageFiles/analyzePageClientSide.js';
|
|
4
|
-
import {
|
|
4
|
+
import { generateVirtualFileId } from '../../shared/virtualFileId.js';
|
|
5
5
|
import { analyzeClientSide } from '../../../shared/getPageFiles/analyzeClientSide.js';
|
|
6
6
|
import { getConfigValueRuntime } from '../../../shared/page-configs/getConfigValueRuntime.js';
|
|
7
7
|
async function analyzePage(pageFilesAll, pageConfig, pageId, globalContext) {
|
|
@@ -15,14 +15,14 @@ async function analyzePage(pageFilesAll, pageConfig, pageId, globalContext) {
|
|
|
15
15
|
clientEntries.push(getVikeClientEntry(isClientRouting));
|
|
16
16
|
const clientDependencies = [];
|
|
17
17
|
clientDependencies.push({
|
|
18
|
-
id:
|
|
18
|
+
id: generateVirtualFileId({ type: 'page-entry', pageId: pageConfig.pageId, isForClientSide: true }),
|
|
19
19
|
onlyAssets: isClientRuntimeLoaded ? false : true,
|
|
20
20
|
eagerlyImported: false,
|
|
21
21
|
});
|
|
22
22
|
// In production we inject the import of the server virtual module with ?extractAssets inside the client virtual module
|
|
23
23
|
if (!globalContext._isProduction) {
|
|
24
24
|
clientDependencies.push({
|
|
25
|
-
id:
|
|
25
|
+
id: generateVirtualFileId({ type: 'page-entry', pageId: pageConfig.pageId, isForClientSide: false }),
|
|
26
26
|
onlyAssets: true,
|
|
27
27
|
eagerlyImported: false,
|
|
28
28
|
});
|