vike 0.4.228 → 0.4.229-commit-2a06dcc
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/__internal/index.js +2 -2
- package/dist/cjs/client/client-routing-runtime/globalContext.js +49 -0
- package/dist/cjs/client/server-routing-runtime/globalContext.js +41 -0
- package/dist/cjs/client/server-routing-runtime/utils.js +1 -1
- package/dist/cjs/client/shared/createGetGlobalContextClient.js +58 -0
- package/dist/cjs/client/shared/getJsonSerializedInHtml.js +31 -0
- package/dist/cjs/client/shared/utils.js +22 -0
- package/dist/cjs/node/plugin/index.js +3 -1
- package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/handleAssetsManifest.js +10 -5
- package/dist/cjs/node/plugin/plugins/build/pluginBuildApp.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/pluginBuildConfig.js +3 -10
- package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +9 -5
- package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +9 -5
- package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +14 -3
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +2 -7
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +17 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +3 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +11 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.js +2 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +13 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +15 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -11
- package/dist/cjs/node/plugin/plugins/replaceConstants.js +76 -0
- package/dist/cjs/node/plugin/shared/applyRegExWithMagicString.js +10 -0
- package/dist/cjs/node/plugin/shared/findPageFiles.js +1 -1
- package/dist/cjs/node/plugin/shared/getFilePath.js +2 -2
- package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +7 -19
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/prerender/runPrerender.js +44 -41
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +102 -125
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +18 -5
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +2 -2
- package/dist/cjs/node/runtime/html/propKeys.js +47 -0
- package/dist/cjs/node/runtime/html/renderHtml.js +7 -1
- package/dist/cjs/node/runtime/html/{serializePageContextClientSide.js → serializeContext.js} +37 -67
- package/dist/cjs/node/runtime/index-deprecated.js +9 -38
- package/dist/cjs/node/runtime/index.js +56 -2
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +8 -3
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +73 -0
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +1 -17
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +2 -2
- package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/log404/index.js +1 -1
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -68
- package/dist/cjs/node/runtime/renderPage.js +102 -81
- package/dist/cjs/node/runtime/universal-middleware.js +7 -1
- package/dist/cjs/node/runtime/utils.js +3 -2
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/cjs/shared/createGlobalContextShared.js +54 -0
- package/dist/cjs/shared/createPageContextShared.js +17 -0
- package/dist/cjs/shared/getPageFiles/fileTypes.js +1 -1
- package/dist/cjs/shared/hooks/executeHookGeneric.js +18 -0
- package/dist/cjs/shared/hooks/getHook.js +45 -27
- package/dist/cjs/shared/htmlElementIds.js +5 -0
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +3 -7
- package/dist/cjs/shared/route/executeGuardHook.js +1 -1
- package/dist/cjs/shared/route/loadPageRoutes.js +2 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/catchInfiniteLoop.js +3 -3
- package/dist/cjs/utils/getPublicProxy.js +27 -0
- package/dist/cjs/utils/isImportPath.js +21 -0
- package/dist/cjs/utils/isScriptFile.js +24 -21
- package/dist/cjs/utils/objectAssign.js +6 -10
- package/dist/cjs/utils/objectReplace.js +4 -4
- package/dist/cjs/utils/{isNpmPackage.js → parseNpmPackage.js} +24 -23
- package/dist/cjs/utils/path.js +12 -2
- package/dist/cjs/utils/requireResolve.js +134 -53
- package/dist/esm/__internal/index.js +3 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +29 -10
- package/dist/esm/client/client-routing-runtime/createPageContext.js +23 -22
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +5 -4
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +20 -0
- package/dist/esm/client/client-routing-runtime/globalContext.js +13 -0
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.js +2 -2
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +8 -7
- package/dist/esm/client/client-routing-runtime/utils.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/utils.js +0 -1
- package/dist/esm/client/index.d.ts +1 -0
- package/dist/esm/client/index.js +4 -0
- package/dist/esm/client/node.js +1 -3
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.d.ts +36 -0
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.js +47 -0
- package/dist/esm/client/server-routing-runtime/entry.js +2 -2
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +17 -0
- package/dist/esm/client/server-routing-runtime/globalContext.js +5 -0
- package/dist/esm/client/server-routing-runtime/utils.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/utils.js +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +23 -0
- package/dist/esm/client/shared/createGetGlobalContextClient.js +58 -0
- package/dist/esm/client/shared/executeOnRenderClientHook.js +5 -4
- package/dist/esm/client/shared/{getPageContextSerializedInHtml.d.ts → getJsonSerializedInHtml.d.ts} +2 -0
- package/dist/esm/client/shared/getJsonSerializedInHtml.js +29 -0
- package/dist/esm/client/shared/removeFoucBuster.js +1 -0
- package/dist/esm/client/shared/utils.d.ts +4 -0
- package/dist/esm/client/shared/utils.js +4 -0
- package/dist/esm/node/plugin/index.js +3 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/esm/node/plugin/plugins/build/handleAssetsManifest.js +11 -6
- package/dist/esm/node/plugin/plugins/build/pluginBuildApp.js +2 -2
- package/dist/esm/node/plugin/plugins/build/pluginBuildConfig.js +4 -11
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +10 -6
- package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +9 -5
- package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +2 -2
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/commonConfig.js +15 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +3 -8
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +7 -2
- package/dist/esm/node/plugin/plugins/envVars.js +18 -20
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +4 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +11 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.js +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.d.ts → pointerImports.d.ts} +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +14 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +15 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -11
- package/dist/esm/node/plugin/plugins/replaceConstants.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/replaceConstants.js +71 -0
- package/dist/esm/node/plugin/shared/applyRegExWithMagicString.d.ts +3 -0
- package/dist/esm/node/plugin/shared/applyRegExWithMagicString.js +8 -0
- package/dist/esm/node/plugin/shared/findPageFiles.js +2 -2
- package/dist/esm/node/plugin/shared/getFilePath.js +3 -3
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +8 -20
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +314 -5
- package/dist/esm/node/prerender/runPrerender.js +48 -45
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +425 -47
- package/dist/esm/node/runtime/globalContext.js +103 -126
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +18 -5
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +2 -2
- package/dist/esm/node/runtime/html/injectAssets.d.ts +3 -3
- package/dist/esm/node/runtime/html/propKeys.d.ts +8 -0
- package/dist/esm/node/runtime/html/propKeys.js +45 -0
- package/dist/esm/node/runtime/html/renderHtml.js +7 -1
- package/dist/esm/node/runtime/html/{serializePageContextClientSide.d.ts → serializeContext.d.ts} +7 -6
- package/dist/esm/node/runtime/html/{serializePageContextClientSide.js → serializeContext.js} +36 -67
- package/dist/esm/node/runtime/index-deprecated.d.ts +1 -16
- package/dist/esm/node/runtime/index-deprecated.js +9 -36
- package/dist/esm/node/runtime/index.d.ts +23 -1
- package/dist/esm/node/runtime/index.js +38 -3
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +5 -4
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +8 -3
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +155 -0
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +71 -0
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +3 -3
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -3
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +1 -17
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.js +1 -1
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +3 -3
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +225 -179
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -69
- package/dist/esm/node/runtime/renderPage.d.ts +146 -7
- package/dist/esm/node/runtime/renderPage.js +105 -84
- package/dist/esm/node/runtime/universal-middleware.js +7 -1
- package/dist/esm/node/runtime/utils.d.ts +3 -2
- package/dist/esm/node/runtime/utils.js +3 -2
- package/dist/esm/shared/VikeNamespace.d.ts +35 -13
- package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/esm/shared/createGlobalContextShared.d.ts +39 -0
- package/dist/esm/shared/createGlobalContextShared.js +51 -0
- package/dist/esm/shared/createPageContextShared.d.ts +9 -0
- package/dist/esm/shared/createPageContextShared.js +15 -0
- package/dist/esm/shared/getPageFiles/fileTypes.js +1 -1
- package/dist/esm/shared/hooks/executeHookGeneric.d.ts +8 -0
- package/dist/esm/shared/hooks/executeHookGeneric.js +16 -0
- package/dist/esm/shared/hooks/getHook.d.ts +5 -3
- package/dist/esm/shared/hooks/getHook.js +47 -29
- package/dist/esm/shared/htmlElementIds.d.ts +2 -0
- package/dist/esm/shared/htmlElementIds.js +2 -0
- package/dist/esm/shared/page-configs/Config.d.ts +12 -2
- package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +1 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +3 -7
- package/dist/esm/shared/route/executeGuardHook.js +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +2 -1
- package/dist/esm/shared/types.d.ts +64 -32
- package/dist/esm/types/index.d.ts +1 -5
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/catchInfiniteLoop.js +4 -4
- package/dist/esm/utils/getGlobalObject.d.ts +1 -1
- package/dist/esm/utils/getPublicProxy.d.ts +2 -0
- package/dist/esm/utils/getPublicProxy.js +25 -0
- package/dist/esm/utils/isImportPath.d.ts +4 -0
- package/dist/esm/utils/isImportPath.js +19 -0
- package/dist/esm/utils/isScriptFile.d.ts +5 -5
- package/dist/esm/utils/isScriptFile.js +23 -20
- package/dist/esm/utils/objectAssign.d.ts +1 -1
- package/dist/esm/utils/objectAssign.js +6 -10
- package/dist/esm/utils/objectReplace.d.ts +1 -1
- package/dist/esm/utils/objectReplace.js +4 -4
- package/dist/esm/utils/parseNpmPackage.d.ts +19 -0
- package/dist/esm/utils/{isNpmPackage.js → parseNpmPackage.js} +24 -24
- package/dist/esm/utils/path.d.ts +1 -1
- package/dist/esm/utils/path.js +12 -2
- package/dist/esm/utils/requireResolve.d.ts +20 -7
- package/dist/esm/utils/requireResolve.js +134 -53
- package/package.json +14 -13
- package/dist/cjs/node/runtime/index-common.js +0 -27
- package/dist/cjs/utils/makePublicCopy.js +0 -32
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +0 -19
- package/dist/esm/client/server-routing-runtime/getPageContext.js +0 -44
- package/dist/esm/client/shared/getPageContextSerializedInHtml.js +0 -20
- package/dist/esm/node/runtime/index-common.d.ts +0 -8
- package/dist/esm/node/runtime/index-common.js +0 -10
- package/dist/esm/utils/isNpmPackage.d.ts +0 -17
- package/dist/esm/utils/makePublicCopy.d.ts +0 -3
- package/dist/esm/utils/makePublicCopy.js +0 -30
|
@@ -3,7 +3,7 @@ export { getGlobalContext };
|
|
|
3
3
|
export { getGlobalContextSync };
|
|
4
4
|
export { getGlobalContextAsync };
|
|
5
5
|
// Internal use
|
|
6
|
-
export {
|
|
6
|
+
export { getGlobalContextServerInternal };
|
|
7
7
|
export { getViteDevServer };
|
|
8
8
|
export { getViteConfig };
|
|
9
9
|
export { initGlobalContext_renderPage };
|
|
@@ -18,32 +18,36 @@ export { clearGlobalContext };
|
|
|
18
18
|
export { assertBuildInfo };
|
|
19
19
|
export { updateUserFiles };
|
|
20
20
|
// The core logic revolves around:
|
|
21
|
-
// -
|
|
21
|
+
// - virtualFileExports is the main requirement
|
|
22
22
|
// - In production: globalObject.buildEntry which is the production entry set by @brillout/vite-plugin-server-entry
|
|
23
|
-
// - loadBuildEntry() sets globalObject.buildEntry and then sets
|
|
23
|
+
// - loadBuildEntry() sets globalObject.buildEntry and then sets virtualFileExports
|
|
24
24
|
// - 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()
|
|
25
25
|
// - Without vike-server it's manually loaded here using importServerProductionEntry() which uses @brillout/vite-plugin-server-entry's autoImporter or crawler
|
|
26
26
|
// - In development: globalObject.viteDevServer which is Vite's development server
|
|
27
|
-
// - globalObject.viteDevServer is used by updateUserFiles() which then sets
|
|
28
|
-
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject,
|
|
27
|
+
// - globalObject.viteDevServer is used by updateUserFiles() which then sets virtualFileExports
|
|
28
|
+
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, debugGlob, getGlobalObject, genPromise, createDebugger, getPublicProxy, checkType, PROJECT_VERSION } from './utils.js';
|
|
29
29
|
import { importServerProductionEntry } from '@brillout/vite-plugin-server-entry/runtime';
|
|
30
30
|
import { virtualFileIdImportUserCodeServer } from '../shared/virtual-files/virtualFileImportUserCode.js';
|
|
31
31
|
import pc from '@brillout/picocolors';
|
|
32
32
|
import { loadPageRoutes } from '../../shared/route/loadPageRoutes.js';
|
|
33
33
|
import { assertV1Design } from '../shared/assertV1Design.js';
|
|
34
|
-
import { getPageConfigsRuntime } from '../../shared/getPageConfigsRuntime.js';
|
|
35
34
|
import { resolveBase } from '../shared/resolveBase.js';
|
|
35
|
+
import { createGlobalContextShared, getGlobalContextSyncErrMsg } from '../../shared/createGlobalContextShared.js';
|
|
36
36
|
const debug = createDebugger('vike:globalContext');
|
|
37
37
|
const globalObject = getGlobalObject('runtime/globalContext.ts', getInitialGlobalContext());
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
// Trick to break down TypeScript circular dependency
|
|
39
|
+
// https://chat.deepseek.com/a/chat/s/d7e9f90a-c7f3-4108-9cd5-4ad6caed3539
|
|
40
|
+
const globalObjectTyped = globalObject;
|
|
41
|
+
async function getGlobalContextServerInternal() {
|
|
42
|
+
// getGlobalContextServerInternal() should always be called after initGlobalContext()
|
|
40
43
|
assert(globalObject.isInitialized);
|
|
41
44
|
assertGlobalContextIsDefined();
|
|
42
45
|
if (globalObject.isProduction !== true)
|
|
43
46
|
await globalObject.waitForUserFilesUpdate;
|
|
44
|
-
const { globalContext } =
|
|
47
|
+
const { globalContext, globalContext_public } = globalObjectTyped;
|
|
45
48
|
assertIsDefined(globalContext);
|
|
46
|
-
|
|
49
|
+
assert(globalContext_public);
|
|
50
|
+
return { globalContext, globalContext_public };
|
|
47
51
|
}
|
|
48
52
|
function assertIsDefined(globalContext) {
|
|
49
53
|
if (!globalContext) {
|
|
@@ -53,9 +57,11 @@ function assertIsDefined(globalContext) {
|
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
function assertGlobalContextIsDefined() {
|
|
56
|
-
assertIsDefined(
|
|
60
|
+
assertIsDefined(globalObjectTyped.globalContext);
|
|
61
|
+
assert(globalObject.globalContext);
|
|
57
62
|
assert(globalObject.globalContext_public);
|
|
58
63
|
}
|
|
64
|
+
// We purposely return GlobalContext instead of GlobalContextServer because `import { getGlobalContext } from 'vike'` can resolve to the client-side implementation.
|
|
59
65
|
/**
|
|
60
66
|
* Get runtime information about your app.
|
|
61
67
|
*
|
|
@@ -83,7 +89,7 @@ async function getGlobalContextAsync(isProduction) {
|
|
|
83
89
|
if (!isProduction)
|
|
84
90
|
await globalObject.waitForUserFilesUpdate;
|
|
85
91
|
assertGlobalContextIsDefined();
|
|
86
|
-
const { globalContext_public } =
|
|
92
|
+
const { globalContext_public } = globalObjectTyped;
|
|
87
93
|
assert(globalContext_public);
|
|
88
94
|
return globalContext_public;
|
|
89
95
|
}
|
|
@@ -96,24 +102,25 @@ async function getGlobalContextAsync(isProduction) {
|
|
|
96
102
|
*/
|
|
97
103
|
function getGlobalContextSync() {
|
|
98
104
|
debug('getGlobalContextSync()');
|
|
99
|
-
const { globalContext_public } =
|
|
100
|
-
assertUsage(globalContext_public,
|
|
105
|
+
const { globalContext_public } = globalObjectTyped;
|
|
106
|
+
assertUsage(globalContext_public, getGlobalContextSyncErrMsg);
|
|
101
107
|
assertWarning(false,
|
|
102
|
-
// We discourage users from using it because
|
|
108
|
+
// We discourage users from using it because `pageContext.globalContext` is safer: I ain't sure but there could be race conditions when using `getGlobalContextSync()` inside React/Vue components upon HMR.
|
|
103
109
|
// We're lying about "is going to be deprecated in the next major release": let's keep it and see if users need it (so far I can't see a use case for it).
|
|
104
110
|
'getGlobalContextSync() is going to be deprecated in the next major release, see https://vike.dev/getGlobalContext', { onlyOnce: true });
|
|
105
111
|
return globalContext_public;
|
|
106
112
|
}
|
|
107
113
|
function makePublic(globalContext) {
|
|
108
|
-
const globalContextPublic =
|
|
114
|
+
const globalContextPublic = getPublicProxy(globalContext, 'globalContext', [
|
|
109
115
|
'assetsManifest',
|
|
110
116
|
'config',
|
|
111
117
|
'viteConfig',
|
|
112
118
|
'viteConfigRuntime',
|
|
113
119
|
'pages',
|
|
114
120
|
'baseServer',
|
|
115
|
-
'baseAssets'
|
|
116
|
-
|
|
121
|
+
'baseAssets',
|
|
122
|
+
'isClientSide'
|
|
123
|
+
], true);
|
|
117
124
|
return globalContextPublic;
|
|
118
125
|
}
|
|
119
126
|
async function setGlobalContext_viteDevServer(viteDevServer) {
|
|
@@ -221,96 +228,6 @@ function setIsProduction(isProduction) {
|
|
|
221
228
|
assert(globalObject.isProduction === isProduction);
|
|
222
229
|
globalObject.isProduction = isProduction;
|
|
223
230
|
}
|
|
224
|
-
function defineGlobalContext() {
|
|
225
|
-
const globalContext = resolveGlobalContext();
|
|
226
|
-
assertIsDefined(globalContext);
|
|
227
|
-
const globalContext_public = makePublic(globalContext);
|
|
228
|
-
objectAssign(globalContext, { globalContext_public });
|
|
229
|
-
globalObject.globalContext = globalContext;
|
|
230
|
-
globalObject.globalContext_public = globalContext_public;
|
|
231
|
-
assertGlobalContextIsDefined();
|
|
232
|
-
onSetupRuntime();
|
|
233
|
-
}
|
|
234
|
-
function resolveGlobalContext() {
|
|
235
|
-
const { viteDevServer, viteConfig, viteConfigRuntime, isPrerendering, isProduction, userFiles } = globalObject;
|
|
236
|
-
assert(typeof isProduction === 'boolean');
|
|
237
|
-
let globalContext;
|
|
238
|
-
if (!isProduction) {
|
|
239
|
-
// Requires globalObject.viteDevServer
|
|
240
|
-
if (!viteDevServer)
|
|
241
|
-
return null;
|
|
242
|
-
assert(userFiles); // main common requiement
|
|
243
|
-
assert(viteConfig);
|
|
244
|
-
assert(viteConfigRuntime);
|
|
245
|
-
assert(!isPrerendering);
|
|
246
|
-
globalContext = {
|
|
247
|
-
isProduction: false,
|
|
248
|
-
isPrerendering: false,
|
|
249
|
-
assetsManifest: null,
|
|
250
|
-
viteDevServer,
|
|
251
|
-
viteConfig,
|
|
252
|
-
...userFiles,
|
|
253
|
-
viteConfigRuntime,
|
|
254
|
-
...resolveBaseRuntime(viteConfigRuntime, userFiles.config)
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
// Requires globalObject.buildEntry
|
|
259
|
-
if (!globalObject.buildEntry)
|
|
260
|
-
return null;
|
|
261
|
-
assert(userFiles); // main common requiement
|
|
262
|
-
const { buildInfo, assetsManifest } = globalObject;
|
|
263
|
-
assert(buildInfo);
|
|
264
|
-
assert(assetsManifest);
|
|
265
|
-
const globalContext_ = {
|
|
266
|
-
isProduction: true,
|
|
267
|
-
assetsManifest,
|
|
268
|
-
...userFiles,
|
|
269
|
-
viteDevServer: null,
|
|
270
|
-
viteConfigRuntime: buildInfo.viteConfigRuntime,
|
|
271
|
-
usesClientRouter: buildInfo.usesClientRouter,
|
|
272
|
-
...resolveBaseRuntime(buildInfo.viteConfigRuntime, userFiles.config)
|
|
273
|
-
};
|
|
274
|
-
if (isPrerendering) {
|
|
275
|
-
assert(viteConfig);
|
|
276
|
-
objectAssign(globalContext_, {
|
|
277
|
-
isPrerendering: true,
|
|
278
|
-
viteConfig
|
|
279
|
-
});
|
|
280
|
-
globalContext = globalContext_;
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
objectAssign(globalContext_, {
|
|
284
|
-
isPrerendering: false,
|
|
285
|
-
viteConfig: null
|
|
286
|
-
});
|
|
287
|
-
globalContext = globalContext_;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return globalContext;
|
|
291
|
-
}
|
|
292
|
-
async function getUserFiles() {
|
|
293
|
-
// Help TypeScript resolve what TypeScript (wrongfully) believes to be cyclic dependency
|
|
294
|
-
const globalObject_ = globalObject;
|
|
295
|
-
const { pageConfigsRuntime } = globalObject_;
|
|
296
|
-
assert(pageConfigsRuntime);
|
|
297
|
-
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig, pageConfigsUserFriendly } = pageConfigsRuntime;
|
|
298
|
-
const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
|
|
299
|
-
const userFiles = {
|
|
300
|
-
pageFilesAll,
|
|
301
|
-
pageConfigs,
|
|
302
|
-
pageConfigGlobal,
|
|
303
|
-
allPageIds,
|
|
304
|
-
pageRoutes,
|
|
305
|
-
onBeforeRouteHook,
|
|
306
|
-
pages: pageConfigsUserFriendly,
|
|
307
|
-
config: globalConfig.config
|
|
308
|
-
};
|
|
309
|
-
assertV1Design(
|
|
310
|
-
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
311
|
-
pageConfigs.length > 0, pageFilesAll);
|
|
312
|
-
return userFiles;
|
|
313
|
-
}
|
|
314
231
|
function assertViteManifest(manifest) {
|
|
315
232
|
assert(isPlainObject(manifest));
|
|
316
233
|
/* We should include these assertions but we don't as a workaround for PWA manifests: https://github.com/vikejs/vike/issues/769
|
|
@@ -326,10 +243,7 @@ function assertViteManifest(manifest) {
|
|
|
326
243
|
}
|
|
327
244
|
async function loadBuildEntry(outDir) {
|
|
328
245
|
debug('loadBuildEntry()');
|
|
329
|
-
if (globalObject.
|
|
330
|
-
assert(globalObject.buildInfo);
|
|
331
|
-
assert(globalObject.assetsManifest);
|
|
332
|
-
assert(globalObject.buildEntry);
|
|
246
|
+
if (globalObject.globalContext) {
|
|
333
247
|
return;
|
|
334
248
|
}
|
|
335
249
|
if (!globalObject.buildEntry) {
|
|
@@ -342,20 +256,18 @@ async function loadBuildEntry(outDir) {
|
|
|
342
256
|
globalObject.buildEntry = globalObject.buildEntryPrevious;
|
|
343
257
|
}
|
|
344
258
|
assert(globalObject.buildEntry);
|
|
259
|
+
// If using `inject` then dist/server/index.js imports dist/server/entry.js and loadBuildEntry() isn't needed.
|
|
260
|
+
// If dist/server/entry.js isn't imported then this means the user is running the original server entry `$ ts-node server/index.ts`.
|
|
345
261
|
assertWarning(
|
|
346
|
-
// vike-server => `
|
|
347
|
-
// vike-node => `
|
|
348
|
-
globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject !== true,
|
|
349
|
-
/* TO-DO/eventually:
|
|
350
|
-
!!globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject,
|
|
351
|
-
*/
|
|
352
|
-
`Run the built server entry (e.g. ${pc.cyan('$ node dist/server/index.mjs')}) instead of the original server entry (e.g. ${pc.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
|
|
262
|
+
// vike-server => `inject === true`
|
|
263
|
+
// vike-node => `inject === [ 'index' ]` => we don't show the warning to vike-node users (I don't remember why).
|
|
264
|
+
globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject !== true || globalObject.isPrerendering, `Run the built server entry (e.g. ${pc.cyan('$ node dist/server/index.mjs')}) instead of the original server entry (e.g. ${pc.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
|
|
353
265
|
}
|
|
354
266
|
const { buildEntry } = globalObject;
|
|
355
267
|
assertBuildEntry(buildEntry);
|
|
356
268
|
globalObject.assetsManifest = buildEntry.assetsManifest;
|
|
357
269
|
globalObject.buildInfo = buildEntry.buildInfo;
|
|
358
|
-
await
|
|
270
|
+
await setGlobalContext(buildEntry.virtualFileExports);
|
|
359
271
|
}
|
|
360
272
|
async function setGlobalContext_buildEntry(buildEntry) {
|
|
361
273
|
debug('setGlobalContext_buildEntry()');
|
|
@@ -415,15 +327,80 @@ async function updateUserFiles() {
|
|
|
415
327
|
// 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).
|
|
416
328
|
if (viteDevServer !== globalObject.viteDevServer)
|
|
417
329
|
return;
|
|
418
|
-
await
|
|
330
|
+
await setGlobalContext(virtualFileExports);
|
|
419
331
|
resolve();
|
|
420
332
|
}
|
|
421
|
-
async function
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
333
|
+
async function setGlobalContext(virtualFileExports) {
|
|
334
|
+
const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext);
|
|
335
|
+
assertV1Design(
|
|
336
|
+
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
337
|
+
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
338
|
+
// Public usage
|
|
339
|
+
globalObject.globalContext_public = makePublic(globalContext);
|
|
426
340
|
assertGlobalContextIsDefined();
|
|
341
|
+
onSetupRuntime();
|
|
342
|
+
// Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
|
|
343
|
+
return globalContext;
|
|
344
|
+
}
|
|
345
|
+
async function addGlobalContext(globalContext) {
|
|
346
|
+
const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
347
|
+
const globalContextBase = {
|
|
348
|
+
isClientSide: false,
|
|
349
|
+
_pageRoutes: pageRoutes,
|
|
350
|
+
_onBeforeRouteHook: onBeforeRouteHook
|
|
351
|
+
};
|
|
352
|
+
const { viteDevServer, viteConfig, viteConfigRuntime, isPrerendering, isProduction } = globalObject;
|
|
353
|
+
assert(typeof isProduction === 'boolean');
|
|
354
|
+
if (!isProduction) {
|
|
355
|
+
assert(viteDevServer);
|
|
356
|
+
assert(globalContext); // main common requirement
|
|
357
|
+
assert(viteConfig);
|
|
358
|
+
assert(viteConfigRuntime);
|
|
359
|
+
assert(!isPrerendering);
|
|
360
|
+
return {
|
|
361
|
+
...globalContext,
|
|
362
|
+
...globalContextBase,
|
|
363
|
+
...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
|
|
364
|
+
_isProduction: false,
|
|
365
|
+
_isPrerendering: false,
|
|
366
|
+
assetsManifest: null,
|
|
367
|
+
_viteDevServer: viteDevServer,
|
|
368
|
+
viteConfig,
|
|
369
|
+
viteConfigRuntime
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
assert(globalObject.buildEntry);
|
|
374
|
+
assert(globalContext); // main common requiement
|
|
375
|
+
const { buildInfo, assetsManifest } = globalObject;
|
|
376
|
+
assert(buildInfo);
|
|
377
|
+
assert(assetsManifest);
|
|
378
|
+
const globalContextBase2 = {
|
|
379
|
+
...globalContext,
|
|
380
|
+
...globalContextBase,
|
|
381
|
+
...resolveBaseRuntime(buildInfo.viteConfigRuntime, globalContext.config),
|
|
382
|
+
_isProduction: true,
|
|
383
|
+
assetsManifest,
|
|
384
|
+
_viteDevServer: null,
|
|
385
|
+
viteConfigRuntime: buildInfo.viteConfigRuntime,
|
|
386
|
+
_usesClientRouter: buildInfo.usesClientRouter
|
|
387
|
+
};
|
|
388
|
+
if (isPrerendering) {
|
|
389
|
+
assert(viteConfig);
|
|
390
|
+
return {
|
|
391
|
+
...globalContextBase2,
|
|
392
|
+
_isPrerendering: true,
|
|
393
|
+
viteConfig
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
return {
|
|
398
|
+
...globalContextBase2,
|
|
399
|
+
_isPrerendering: false,
|
|
400
|
+
viteConfig: null
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
}
|
|
427
404
|
}
|
|
428
405
|
function clearGlobalContext() {
|
|
429
406
|
debug('clearGlobalContext()');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isFontFallback } from '../../renderPage/isFontFallback.js';
|
|
2
2
|
export { getHtmlTags };
|
|
3
3
|
import { assert, assertWarning, assertUsage, isObject, freezePartial } from '../../utils.js';
|
|
4
|
-
import {
|
|
4
|
+
import { getGlobalContextClientSerialized, getPageContextClientSerialized } from '../serializeContext.js';
|
|
5
5
|
import { sanitizeJson } from './sanitizeJson.js';
|
|
6
6
|
import { inferAssetTag, inferPreloadTag } from './inferHtmlTags.js';
|
|
7
7
|
import { mergeScriptTags } from './mergeScriptTags.js';
|
|
@@ -9,11 +9,12 @@ import { getPageConfig } from '../../../../shared/page-configs/helpers.js';
|
|
|
9
9
|
import { getConfigValueRuntime } from '../../../../shared/page-configs/getConfigValueRuntime.js';
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { getConfigDefinedAt } from '../../../../shared/page-configs/getConfigDefinedAt.js';
|
|
12
|
+
import { htmlElementId_globalContext, htmlElementId_pageContext } from '../../../../shared/htmlElementIds.js';
|
|
12
13
|
const stamp = '__injectFilterEntry';
|
|
13
14
|
async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, isStream) {
|
|
14
15
|
assert([true, false].includes(pageContext._isHtmlOnly));
|
|
15
16
|
const isHtmlOnly = pageContext._isHtmlOnly;
|
|
16
|
-
const { isProduction } = pageContext._globalContext;
|
|
17
|
+
const { _isProduction: isProduction } = pageContext._globalContext;
|
|
17
18
|
const injectScriptsAt = getInjectScriptsAt(pageContext.pageId, pageContext._pageConfigs);
|
|
18
19
|
const injectFilterEntries = [];
|
|
19
20
|
pageAssets
|
|
@@ -119,14 +120,21 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
|
|
|
119
120
|
// - https://github.com/vikejs/vike-vue/issues/85
|
|
120
121
|
assertWarning(false, "We recommend against using HTML streaming and a pageContext promise (https://vike.dev/streaming#initial-data-after-stream-end) at the same time, because progressive hydration (https://vike.dev/streaming#progressive-rendering) won't work.", { onlyOnce: true });
|
|
121
122
|
}
|
|
122
|
-
// <script id="vike_pageContext" type="application/json">
|
|
123
123
|
if (!isHtmlOnly) {
|
|
124
|
+
// <script id="vike_pageContext" type="application/json">
|
|
124
125
|
htmlTags.push({
|
|
125
126
|
htmlTag: () =>
|
|
126
127
|
// Needs to be called after resolvePageContextPromise()
|
|
127
128
|
getPageContextJsonScriptTag(pageContext),
|
|
128
129
|
position: positionJavaScriptEntry
|
|
129
130
|
});
|
|
131
|
+
// <script id="vike_globalContext" type="application/json">
|
|
132
|
+
htmlTags.push({
|
|
133
|
+
htmlTag: () =>
|
|
134
|
+
// Needs to be called after resolvePageContextPromise()
|
|
135
|
+
getGlobalContextJsonScriptTag(pageContext),
|
|
136
|
+
position: positionJavaScriptEntry
|
|
137
|
+
});
|
|
130
138
|
}
|
|
131
139
|
// The JavaScript entry <script> tag
|
|
132
140
|
const scriptEntry = mergeScriptEntries(pageAssets, viteDevScript);
|
|
@@ -157,13 +165,18 @@ function mergeScriptEntries(pageAssets, viteDevScript) {
|
|
|
157
165
|
return scriptTag;
|
|
158
166
|
}
|
|
159
167
|
function getPageContextJsonScriptTag(pageContext) {
|
|
160
|
-
const
|
|
161
|
-
const htmlTag = `<script id="
|
|
168
|
+
const pageContextClientSerialized = sanitizeJson(getPageContextClientSerialized(pageContext));
|
|
169
|
+
const htmlTag = `<script id="${htmlElementId_pageContext}" type="application/json">${pageContextClientSerialized}</script>`;
|
|
162
170
|
// Used by contra.com https://github.com/gajus
|
|
163
171
|
// @ts-expect-error
|
|
164
172
|
pageContext._pageContextHtmlTag = htmlTag;
|
|
165
173
|
return htmlTag;
|
|
166
174
|
}
|
|
175
|
+
function getGlobalContextJsonScriptTag(pageContext) {
|
|
176
|
+
const globalContextClientSerialized = sanitizeJson(getGlobalContextClientSerialized(pageContext));
|
|
177
|
+
const htmlTag = `<script id="${htmlElementId_globalContext}" type="application/json">${globalContextClientSerialized}</script>`;
|
|
178
|
+
return htmlTag;
|
|
179
|
+
}
|
|
167
180
|
function assertInjectFilterEntries(injectFilterEntries) {
|
|
168
181
|
try {
|
|
169
182
|
checkForWrongUsage(injectFilterEntries);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getViteDevScript };
|
|
2
|
-
import type {
|
|
2
|
+
import type { GlobalContextServerInternal } from '../../globalContext.js';
|
|
3
3
|
declare function getViteDevScript(pageContext: {
|
|
4
|
-
_globalContext:
|
|
4
|
+
_globalContext: GlobalContextServerInternal;
|
|
5
5
|
}): Promise<string>;
|
|
@@ -4,10 +4,10 @@ import pc from '@brillout/picocolors';
|
|
|
4
4
|
const reachOutCTA = 'Create a new GitHub issue to discuss a solution.';
|
|
5
5
|
async function getViteDevScript(pageContext) {
|
|
6
6
|
const globalContext = pageContext._globalContext;
|
|
7
|
-
if (globalContext.
|
|
7
|
+
if (globalContext._isProduction) {
|
|
8
8
|
return '';
|
|
9
9
|
}
|
|
10
|
-
const { viteDevServer } = globalContext;
|
|
10
|
+
const { _viteDevServer: viteDevServer } = globalContext;
|
|
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;
|
|
@@ -7,8 +7,8 @@ import type { HtmlPart } from './renderHtml.js';
|
|
|
7
7
|
import { type PreloadFilter } from './injectAssets/getHtmlTags.js';
|
|
8
8
|
import type { StreamFromReactStreamingPackage } from './stream/react-streaming.js';
|
|
9
9
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
10
|
-
import type { PageContextSerialization } from './
|
|
11
|
-
import type {
|
|
10
|
+
import type { PageContextSerialization } from './serializeContext.js';
|
|
11
|
+
import type { GlobalContextServerInternal } from '../globalContext.js';
|
|
12
12
|
type PageContextInjectAssets = {
|
|
13
13
|
urlPathname: string;
|
|
14
14
|
__getPageAssets: () => Promise<PageAsset[]>;
|
|
@@ -22,7 +22,7 @@ type PageContextInjectAssets = {
|
|
|
22
22
|
_baseServer: string;
|
|
23
23
|
_pageConfigs: PageConfigRuntime[];
|
|
24
24
|
is404: null | boolean;
|
|
25
|
-
_globalContext:
|
|
25
|
+
_globalContext: GlobalContextServerInternal;
|
|
26
26
|
} & PageContextSerialization;
|
|
27
27
|
declare function injectHtmlTagsToString(htmlParts: HtmlPart[], pageContext: PageContextInjectAssets & {
|
|
28
28
|
_isStream: false;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { getPropVal };
|
|
2
|
+
export { setPropVal };
|
|
3
|
+
export { getPropKeys };
|
|
4
|
+
declare function getPropVal(obj: Record<string, unknown>, prop: string): null | {
|
|
5
|
+
value: unknown;
|
|
6
|
+
};
|
|
7
|
+
declare function setPropVal(obj: Record<string, unknown>, prop: string, val: unknown): void;
|
|
8
|
+
declare function getPropKeys(prop: string): string[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export { getPropVal };
|
|
2
|
+
export { setPropVal };
|
|
3
|
+
export { getPropKeys };
|
|
4
|
+
import { isObject } from '../utils.js';
|
|
5
|
+
// Get a nested property from an object using a dot-separated path such as 'user.id'
|
|
6
|
+
function getPropVal(obj, prop) {
|
|
7
|
+
const keys = getPropKeys(prop);
|
|
8
|
+
let value = obj;
|
|
9
|
+
for (const key of keys) {
|
|
10
|
+
if (isObject(value) && key in value) {
|
|
11
|
+
value = value[key];
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return null; // Property or intermediate property doesn't exist
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return { value };
|
|
18
|
+
}
|
|
19
|
+
// Set a nested property in an object using a dot-separated path such as 'user.id'
|
|
20
|
+
function setPropVal(obj, prop, val) {
|
|
21
|
+
const keys = getPropKeys(prop);
|
|
22
|
+
let currentObj = obj;
|
|
23
|
+
// Creating intermediate objects if necessary
|
|
24
|
+
for (let i = 0; i <= keys.length - 2; i++) {
|
|
25
|
+
const key = keys[i];
|
|
26
|
+
if (!(key in currentObj)) {
|
|
27
|
+
// Create intermediate object
|
|
28
|
+
currentObj[key] = {};
|
|
29
|
+
}
|
|
30
|
+
if (!isObject(currentObj[key])) {
|
|
31
|
+
// Skip value upon data structure conflict
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
currentObj = currentObj[key];
|
|
35
|
+
}
|
|
36
|
+
// Set the final key to the value
|
|
37
|
+
const finalKey = keys[keys.length - 1];
|
|
38
|
+
currentObj[finalKey] = val;
|
|
39
|
+
}
|
|
40
|
+
function getPropKeys(prop) {
|
|
41
|
+
// Like `prop.split('.')` but with added support for `\` escaping, see getPageContextClientSerialized.spec.ts
|
|
42
|
+
return prop
|
|
43
|
+
.split(/(?<!\\)\./) // Split on unescaped dots
|
|
44
|
+
.map((key) => key.replace(/\\\./g, '.')); // Replace escaped dots with literal dots
|
|
45
|
+
}
|
|
@@ -71,7 +71,13 @@ async function renderHtmlStream(streamOriginal, injectString, pageContext, onErr
|
|
|
71
71
|
return injectAtStreamAfterFirstChunk();
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
+
let makeClosableAgain = () => { };
|
|
75
|
+
if (isStreamFromReactStreamingPackage(streamOriginal)) {
|
|
76
|
+
// Make sure Vike injects its HTML fragments, such as `<script id="vike_pageContext" type="application/json">`, before the stream is closed
|
|
77
|
+
makeClosableAgain = streamOriginal.doNotClose();
|
|
78
|
+
}
|
|
74
79
|
const streamWrapper = await processStream(streamOriginal, processStreamOptions);
|
|
80
|
+
makeClosableAgain();
|
|
75
81
|
return streamWrapper;
|
|
76
82
|
}
|
|
77
83
|
function isTemplateWrapped(something) {
|
|
@@ -192,7 +198,7 @@ function renderTemplate(templateContent, pageContext) {
|
|
|
192
198
|
}
|
|
193
199
|
}
|
|
194
200
|
{
|
|
195
|
-
const { isProduction } = pageContext._globalContext;
|
|
201
|
+
const { _isProduction: isProduction } = pageContext._globalContext;
|
|
196
202
|
if (isHtml(templateVar) &&
|
|
197
203
|
// We don't show this warning in production because it's expected that some users may (un)willingly do some XSS injection: we avoid flooding the production logs.
|
|
198
204
|
!isProduction) {
|
package/dist/esm/node/runtime/html/{serializePageContextClientSide.d.ts → serializeContext.d.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { getPageContextClientSerialized };
|
|
2
|
+
export { getPageContextClientSerializedAbort };
|
|
3
|
+
export { getGlobalContextClientSerialized };
|
|
3
4
|
export type { PageContextSerialization };
|
|
4
|
-
export { getPropKeys };
|
|
5
5
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
6
6
|
import type { UrlRedirect } from '../../../shared/route/abort.js';
|
|
7
7
|
type PageContextSerialization = {
|
|
@@ -12,13 +12,14 @@ type PageContextSerialization = {
|
|
|
12
12
|
is404: null | boolean;
|
|
13
13
|
pageProps?: Record<string, unknown>;
|
|
14
14
|
_pageContextInit: Record<string, unknown>;
|
|
15
|
+
globalContext: Record<string, any>;
|
|
15
16
|
};
|
|
16
|
-
declare function
|
|
17
|
-
declare function
|
|
17
|
+
declare function getPageContextClientSerialized(pageContext: PageContextSerialization): string;
|
|
18
|
+
declare function getGlobalContextClientSerialized(pageContext: PageContextSerialization): string;
|
|
19
|
+
declare function getPageContextClientSerializedAbort(pageContext: Record<string, unknown> & ({
|
|
18
20
|
_urlRedirect: UrlRedirect;
|
|
19
21
|
} | {
|
|
20
22
|
_urlRewrite: string;
|
|
21
23
|
} | {
|
|
22
24
|
abortStatusCode: number;
|
|
23
25
|
})): string;
|
|
24
|
-
declare function getPropKeys(prop: string): string[];
|