vike 0.4.228 → 0.4.229
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/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 +5 -1
- 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 +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -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/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 +13 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -11
- 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 +1 -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/objectAssign.js +6 -10
- package/dist/cjs/utils/objectReplace.js +4 -4
- package/dist/cjs/utils/{isNpmPackage.js → parseNpmPackage.js} +23 -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/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 +5 -1
- 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 +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -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/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 +13 -10
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -11
- 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 +1 -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/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 +17 -0
- package/dist/esm/utils/{isNpmPackage.js → parseNpmPackage.js} +23 -23
- 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
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getGlobalContext = getGlobalContext;
|
|
7
7
|
exports.getGlobalContextSync = getGlobalContextSync;
|
|
8
8
|
exports.getGlobalContextAsync = getGlobalContextAsync;
|
|
9
|
-
exports.
|
|
9
|
+
exports.getGlobalContextServerInternal = getGlobalContextServerInternal;
|
|
10
10
|
exports.getViteDevServer = getViteDevServer;
|
|
11
11
|
exports.getViteConfig = getViteConfig;
|
|
12
12
|
exports.initGlobalContext_renderPage = initGlobalContext_renderPage;
|
|
@@ -21,32 +21,36 @@ exports.clearGlobalContext = clearGlobalContext;
|
|
|
21
21
|
exports.assertBuildInfo = assertBuildInfo;
|
|
22
22
|
exports.updateUserFiles = updateUserFiles;
|
|
23
23
|
// The core logic revolves around:
|
|
24
|
-
// -
|
|
24
|
+
// - virtualFileExports is the main requirement
|
|
25
25
|
// - In production: globalObject.buildEntry which is the production entry set by @brillout/vite-plugin-server-entry
|
|
26
|
-
// - loadBuildEntry() sets globalObject.buildEntry and then sets
|
|
26
|
+
// - loadBuildEntry() sets globalObject.buildEntry and then sets virtualFileExports
|
|
27
27
|
// - 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()
|
|
28
28
|
// - Without vike-server it's manually loaded here using importServerProductionEntry() which uses @brillout/vite-plugin-server-entry's autoImporter or crawler
|
|
29
29
|
// - In development: globalObject.viteDevServer which is Vite's development server
|
|
30
|
-
// - globalObject.viteDevServer is used by updateUserFiles() which then sets
|
|
30
|
+
// - globalObject.viteDevServer is used by updateUserFiles() which then sets virtualFileExports
|
|
31
31
|
const utils_js_1 = require("./utils.js");
|
|
32
32
|
const runtime_1 = require("@brillout/vite-plugin-server-entry/runtime");
|
|
33
33
|
const virtualFileImportUserCode_js_1 = require("../shared/virtual-files/virtualFileImportUserCode.js");
|
|
34
34
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
35
35
|
const loadPageRoutes_js_1 = require("../../shared/route/loadPageRoutes.js");
|
|
36
36
|
const assertV1Design_js_1 = require("../shared/assertV1Design.js");
|
|
37
|
-
const getPageConfigsRuntime_js_1 = require("../../shared/getPageConfigsRuntime.js");
|
|
38
37
|
const resolveBase_js_1 = require("../shared/resolveBase.js");
|
|
38
|
+
const createGlobalContextShared_js_1 = require("../../shared/createGlobalContextShared.js");
|
|
39
39
|
const debug = (0, utils_js_1.createDebugger)('vike:globalContext');
|
|
40
40
|
const globalObject = (0, utils_js_1.getGlobalObject)('runtime/globalContext.ts', getInitialGlobalContext());
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
// Trick to break down TypeScript circular dependency
|
|
42
|
+
// https://chat.deepseek.com/a/chat/s/d7e9f90a-c7f3-4108-9cd5-4ad6caed3539
|
|
43
|
+
const globalObjectTyped = globalObject;
|
|
44
|
+
async function getGlobalContextServerInternal() {
|
|
45
|
+
// getGlobalContextServerInternal() should always be called after initGlobalContext()
|
|
43
46
|
(0, utils_js_1.assert)(globalObject.isInitialized);
|
|
44
47
|
assertGlobalContextIsDefined();
|
|
45
48
|
if (globalObject.isProduction !== true)
|
|
46
49
|
await globalObject.waitForUserFilesUpdate;
|
|
47
|
-
const { globalContext } =
|
|
50
|
+
const { globalContext, globalContext_public } = globalObjectTyped;
|
|
48
51
|
assertIsDefined(globalContext);
|
|
49
|
-
|
|
52
|
+
(0, utils_js_1.assert)(globalContext_public);
|
|
53
|
+
return { globalContext, globalContext_public };
|
|
50
54
|
}
|
|
51
55
|
function assertIsDefined(globalContext) {
|
|
52
56
|
if (!globalContext) {
|
|
@@ -56,9 +60,11 @@ function assertIsDefined(globalContext) {
|
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
62
|
function assertGlobalContextIsDefined() {
|
|
59
|
-
assertIsDefined(
|
|
63
|
+
assertIsDefined(globalObjectTyped.globalContext);
|
|
64
|
+
(0, utils_js_1.assert)(globalObject.globalContext);
|
|
60
65
|
(0, utils_js_1.assert)(globalObject.globalContext_public);
|
|
61
66
|
}
|
|
67
|
+
// We purposely return GlobalContext instead of GlobalContextServer because `import { getGlobalContext } from 'vike'` can resolve to the client-side implementation.
|
|
62
68
|
/**
|
|
63
69
|
* Get runtime information about your app.
|
|
64
70
|
*
|
|
@@ -86,7 +92,7 @@ async function getGlobalContextAsync(isProduction) {
|
|
|
86
92
|
if (!isProduction)
|
|
87
93
|
await globalObject.waitForUserFilesUpdate;
|
|
88
94
|
assertGlobalContextIsDefined();
|
|
89
|
-
const { globalContext_public } =
|
|
95
|
+
const { globalContext_public } = globalObjectTyped;
|
|
90
96
|
(0, utils_js_1.assert)(globalContext_public);
|
|
91
97
|
return globalContext_public;
|
|
92
98
|
}
|
|
@@ -99,24 +105,25 @@ async function getGlobalContextAsync(isProduction) {
|
|
|
99
105
|
*/
|
|
100
106
|
function getGlobalContextSync() {
|
|
101
107
|
debug('getGlobalContextSync()');
|
|
102
|
-
const { globalContext_public } =
|
|
103
|
-
(0, utils_js_1.assertUsage)(globalContext_public,
|
|
108
|
+
const { globalContext_public } = globalObjectTyped;
|
|
109
|
+
(0, utils_js_1.assertUsage)(globalContext_public, createGlobalContextShared_js_1.getGlobalContextSyncErrMsg);
|
|
104
110
|
(0, utils_js_1.assertWarning)(false,
|
|
105
|
-
// We discourage users from using it because
|
|
111
|
+
// 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.
|
|
106
112
|
// 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).
|
|
107
113
|
'getGlobalContextSync() is going to be deprecated in the next major release, see https://vike.dev/getGlobalContext', { onlyOnce: true });
|
|
108
114
|
return globalContext_public;
|
|
109
115
|
}
|
|
110
116
|
function makePublic(globalContext) {
|
|
111
|
-
const globalContextPublic = (0, utils_js_1.
|
|
117
|
+
const globalContextPublic = (0, utils_js_1.getPublicProxy)(globalContext, 'globalContext', [
|
|
112
118
|
'assetsManifest',
|
|
113
119
|
'config',
|
|
114
120
|
'viteConfig',
|
|
115
121
|
'viteConfigRuntime',
|
|
116
122
|
'pages',
|
|
117
123
|
'baseServer',
|
|
118
|
-
'baseAssets'
|
|
119
|
-
|
|
124
|
+
'baseAssets',
|
|
125
|
+
'isClientSide'
|
|
126
|
+
], true);
|
|
120
127
|
return globalContextPublic;
|
|
121
128
|
}
|
|
122
129
|
async function setGlobalContext_viteDevServer(viteDevServer) {
|
|
@@ -224,96 +231,6 @@ function setIsProduction(isProduction) {
|
|
|
224
231
|
(0, utils_js_1.assert)(globalObject.isProduction === isProduction);
|
|
225
232
|
globalObject.isProduction = isProduction;
|
|
226
233
|
}
|
|
227
|
-
function defineGlobalContext() {
|
|
228
|
-
const globalContext = resolveGlobalContext();
|
|
229
|
-
assertIsDefined(globalContext);
|
|
230
|
-
const globalContext_public = makePublic(globalContext);
|
|
231
|
-
(0, utils_js_1.objectAssign)(globalContext, { globalContext_public });
|
|
232
|
-
globalObject.globalContext = globalContext;
|
|
233
|
-
globalObject.globalContext_public = globalContext_public;
|
|
234
|
-
assertGlobalContextIsDefined();
|
|
235
|
-
(0, utils_js_1.onSetupRuntime)();
|
|
236
|
-
}
|
|
237
|
-
function resolveGlobalContext() {
|
|
238
|
-
const { viteDevServer, viteConfig, viteConfigRuntime, isPrerendering, isProduction, userFiles } = globalObject;
|
|
239
|
-
(0, utils_js_1.assert)(typeof isProduction === 'boolean');
|
|
240
|
-
let globalContext;
|
|
241
|
-
if (!isProduction) {
|
|
242
|
-
// Requires globalObject.viteDevServer
|
|
243
|
-
if (!viteDevServer)
|
|
244
|
-
return null;
|
|
245
|
-
(0, utils_js_1.assert)(userFiles); // main common requiement
|
|
246
|
-
(0, utils_js_1.assert)(viteConfig);
|
|
247
|
-
(0, utils_js_1.assert)(viteConfigRuntime);
|
|
248
|
-
(0, utils_js_1.assert)(!isPrerendering);
|
|
249
|
-
globalContext = {
|
|
250
|
-
isProduction: false,
|
|
251
|
-
isPrerendering: false,
|
|
252
|
-
assetsManifest: null,
|
|
253
|
-
viteDevServer,
|
|
254
|
-
viteConfig,
|
|
255
|
-
...userFiles,
|
|
256
|
-
viteConfigRuntime,
|
|
257
|
-
...resolveBaseRuntime(viteConfigRuntime, userFiles.config)
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
// Requires globalObject.buildEntry
|
|
262
|
-
if (!globalObject.buildEntry)
|
|
263
|
-
return null;
|
|
264
|
-
(0, utils_js_1.assert)(userFiles); // main common requiement
|
|
265
|
-
const { buildInfo, assetsManifest } = globalObject;
|
|
266
|
-
(0, utils_js_1.assert)(buildInfo);
|
|
267
|
-
(0, utils_js_1.assert)(assetsManifest);
|
|
268
|
-
const globalContext_ = {
|
|
269
|
-
isProduction: true,
|
|
270
|
-
assetsManifest,
|
|
271
|
-
...userFiles,
|
|
272
|
-
viteDevServer: null,
|
|
273
|
-
viteConfigRuntime: buildInfo.viteConfigRuntime,
|
|
274
|
-
usesClientRouter: buildInfo.usesClientRouter,
|
|
275
|
-
...resolveBaseRuntime(buildInfo.viteConfigRuntime, userFiles.config)
|
|
276
|
-
};
|
|
277
|
-
if (isPrerendering) {
|
|
278
|
-
(0, utils_js_1.assert)(viteConfig);
|
|
279
|
-
(0, utils_js_1.objectAssign)(globalContext_, {
|
|
280
|
-
isPrerendering: true,
|
|
281
|
-
viteConfig
|
|
282
|
-
});
|
|
283
|
-
globalContext = globalContext_;
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
(0, utils_js_1.objectAssign)(globalContext_, {
|
|
287
|
-
isPrerendering: false,
|
|
288
|
-
viteConfig: null
|
|
289
|
-
});
|
|
290
|
-
globalContext = globalContext_;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return globalContext;
|
|
294
|
-
}
|
|
295
|
-
async function getUserFiles() {
|
|
296
|
-
// Help TypeScript resolve what TypeScript (wrongfully) believes to be cyclic dependency
|
|
297
|
-
const globalObject_ = globalObject;
|
|
298
|
-
const { pageConfigsRuntime } = globalObject_;
|
|
299
|
-
(0, utils_js_1.assert)(pageConfigsRuntime);
|
|
300
|
-
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig, pageConfigsUserFriendly } = pageConfigsRuntime;
|
|
301
|
-
const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
|
|
302
|
-
const userFiles = {
|
|
303
|
-
pageFilesAll,
|
|
304
|
-
pageConfigs,
|
|
305
|
-
pageConfigGlobal,
|
|
306
|
-
allPageIds,
|
|
307
|
-
pageRoutes,
|
|
308
|
-
onBeforeRouteHook,
|
|
309
|
-
pages: pageConfigsUserFriendly,
|
|
310
|
-
config: globalConfig.config
|
|
311
|
-
};
|
|
312
|
-
(0, assertV1Design_js_1.assertV1Design)(
|
|
313
|
-
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
314
|
-
pageConfigs.length > 0, pageFilesAll);
|
|
315
|
-
return userFiles;
|
|
316
|
-
}
|
|
317
234
|
function assertViteManifest(manifest) {
|
|
318
235
|
(0, utils_js_1.assert)((0, utils_js_1.isPlainObject)(manifest));
|
|
319
236
|
/* We should include these assertions but we don't as a workaround for PWA manifests: https://github.com/vikejs/vike/issues/769
|
|
@@ -329,10 +246,7 @@ function assertViteManifest(manifest) {
|
|
|
329
246
|
}
|
|
330
247
|
async function loadBuildEntry(outDir) {
|
|
331
248
|
debug('loadBuildEntry()');
|
|
332
|
-
if (globalObject.
|
|
333
|
-
(0, utils_js_1.assert)(globalObject.buildInfo);
|
|
334
|
-
(0, utils_js_1.assert)(globalObject.assetsManifest);
|
|
335
|
-
(0, utils_js_1.assert)(globalObject.buildEntry);
|
|
249
|
+
if (globalObject.globalContext) {
|
|
336
250
|
return;
|
|
337
251
|
}
|
|
338
252
|
if (!globalObject.buildEntry) {
|
|
@@ -345,20 +259,18 @@ async function loadBuildEntry(outDir) {
|
|
|
345
259
|
globalObject.buildEntry = globalObject.buildEntryPrevious;
|
|
346
260
|
}
|
|
347
261
|
(0, utils_js_1.assert)(globalObject.buildEntry);
|
|
262
|
+
// If using `inject` then dist/server/index.js imports dist/server/entry.js and loadBuildEntry() isn't needed.
|
|
263
|
+
// If dist/server/entry.js isn't imported then this means the user is running the original server entry `$ ts-node server/index.ts`.
|
|
348
264
|
(0, utils_js_1.assertWarning)(
|
|
349
|
-
// vike-server => `
|
|
350
|
-
// vike-node => `
|
|
351
|
-
globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject !== true,
|
|
352
|
-
/* TO-DO/eventually:
|
|
353
|
-
!!globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject,
|
|
354
|
-
*/
|
|
355
|
-
`Run the built server entry (e.g. ${picocolors_1.default.cyan('$ node dist/server/index.mjs')}) instead of the original server entry (e.g. ${picocolors_1.default.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
|
|
265
|
+
// vike-server => `inject === true`
|
|
266
|
+
// vike-node => `inject === [ 'index' ]` => we don't show the warning to vike-node users (I don't remember why).
|
|
267
|
+
globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject !== true || globalObject.isPrerendering, `Run the built server entry (e.g. ${picocolors_1.default.cyan('$ node dist/server/index.mjs')}) instead of the original server entry (e.g. ${picocolors_1.default.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
|
|
356
268
|
}
|
|
357
269
|
const { buildEntry } = globalObject;
|
|
358
270
|
assertBuildEntry(buildEntry);
|
|
359
271
|
globalObject.assetsManifest = buildEntry.assetsManifest;
|
|
360
272
|
globalObject.buildInfo = buildEntry.buildInfo;
|
|
361
|
-
await
|
|
273
|
+
await setGlobalContext(buildEntry.virtualFileExports);
|
|
362
274
|
}
|
|
363
275
|
async function setGlobalContext_buildEntry(buildEntry) {
|
|
364
276
|
debug('setGlobalContext_buildEntry()');
|
|
@@ -418,15 +330,80 @@ async function updateUserFiles() {
|
|
|
418
330
|
// 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).
|
|
419
331
|
if (viteDevServer !== globalObject.viteDevServer)
|
|
420
332
|
return;
|
|
421
|
-
await
|
|
333
|
+
await setGlobalContext(virtualFileExports);
|
|
422
334
|
resolve();
|
|
423
335
|
}
|
|
424
|
-
async function
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
336
|
+
async function setGlobalContext(virtualFileExports) {
|
|
337
|
+
const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, addGlobalContext);
|
|
338
|
+
(0, assertV1Design_js_1.assertV1Design)(
|
|
339
|
+
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
340
|
+
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
341
|
+
// Public usage
|
|
342
|
+
globalObject.globalContext_public = makePublic(globalContext);
|
|
429
343
|
assertGlobalContextIsDefined();
|
|
344
|
+
(0, utils_js_1.onSetupRuntime)();
|
|
345
|
+
// Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
|
|
346
|
+
return globalContext;
|
|
347
|
+
}
|
|
348
|
+
async function addGlobalContext(globalContext) {
|
|
349
|
+
const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
|
|
350
|
+
const globalContextBase = {
|
|
351
|
+
isClientSide: false,
|
|
352
|
+
_pageRoutes: pageRoutes,
|
|
353
|
+
_onBeforeRouteHook: onBeforeRouteHook
|
|
354
|
+
};
|
|
355
|
+
const { viteDevServer, viteConfig, viteConfigRuntime, isPrerendering, isProduction } = globalObject;
|
|
356
|
+
(0, utils_js_1.assert)(typeof isProduction === 'boolean');
|
|
357
|
+
if (!isProduction) {
|
|
358
|
+
(0, utils_js_1.assert)(viteDevServer);
|
|
359
|
+
(0, utils_js_1.assert)(globalContext); // main common requirement
|
|
360
|
+
(0, utils_js_1.assert)(viteConfig);
|
|
361
|
+
(0, utils_js_1.assert)(viteConfigRuntime);
|
|
362
|
+
(0, utils_js_1.assert)(!isPrerendering);
|
|
363
|
+
return {
|
|
364
|
+
...globalContext,
|
|
365
|
+
...globalContextBase,
|
|
366
|
+
...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
|
|
367
|
+
_isProduction: false,
|
|
368
|
+
_isPrerendering: false,
|
|
369
|
+
assetsManifest: null,
|
|
370
|
+
_viteDevServer: viteDevServer,
|
|
371
|
+
viteConfig,
|
|
372
|
+
viteConfigRuntime
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
(0, utils_js_1.assert)(globalObject.buildEntry);
|
|
377
|
+
(0, utils_js_1.assert)(globalContext); // main common requiement
|
|
378
|
+
const { buildInfo, assetsManifest } = globalObject;
|
|
379
|
+
(0, utils_js_1.assert)(buildInfo);
|
|
380
|
+
(0, utils_js_1.assert)(assetsManifest);
|
|
381
|
+
const globalContextBase2 = {
|
|
382
|
+
...globalContext,
|
|
383
|
+
...globalContextBase,
|
|
384
|
+
...resolveBaseRuntime(buildInfo.viteConfigRuntime, globalContext.config),
|
|
385
|
+
_isProduction: true,
|
|
386
|
+
assetsManifest,
|
|
387
|
+
_viteDevServer: null,
|
|
388
|
+
viteConfigRuntime: buildInfo.viteConfigRuntime,
|
|
389
|
+
_usesClientRouter: buildInfo.usesClientRouter
|
|
390
|
+
};
|
|
391
|
+
if (isPrerendering) {
|
|
392
|
+
(0, utils_js_1.assert)(viteConfig);
|
|
393
|
+
return {
|
|
394
|
+
...globalContextBase2,
|
|
395
|
+
_isPrerendering: true,
|
|
396
|
+
viteConfig
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
return {
|
|
401
|
+
...globalContextBase2,
|
|
402
|
+
_isPrerendering: false,
|
|
403
|
+
viteConfig: null
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
}
|
|
430
407
|
}
|
|
431
408
|
function clearGlobalContext() {
|
|
432
409
|
debug('clearGlobalContext()');
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getHtmlTags = getHtmlTags;
|
|
7
7
|
const isFontFallback_js_1 = require("../../renderPage/isFontFallback.js");
|
|
8
8
|
const utils_js_1 = require("../../utils.js");
|
|
9
|
-
const
|
|
9
|
+
const serializeContext_js_1 = require("../serializeContext.js");
|
|
10
10
|
const sanitizeJson_js_1 = require("./sanitizeJson.js");
|
|
11
11
|
const inferHtmlTags_js_1 = require("./inferHtmlTags.js");
|
|
12
12
|
const mergeScriptTags_js_1 = require("./mergeScriptTags.js");
|
|
@@ -14,11 +14,12 @@ const helpers_js_1 = require("../../../../shared/page-configs/helpers.js");
|
|
|
14
14
|
const getConfigValueRuntime_js_1 = require("../../../../shared/page-configs/getConfigValueRuntime.js");
|
|
15
15
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
16
16
|
const getConfigDefinedAt_js_1 = require("../../../../shared/page-configs/getConfigDefinedAt.js");
|
|
17
|
+
const htmlElementIds_js_1 = require("../../../../shared/htmlElementIds.js");
|
|
17
18
|
const stamp = '__injectFilterEntry';
|
|
18
19
|
async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, isStream) {
|
|
19
20
|
(0, utils_js_1.assert)([true, false].includes(pageContext._isHtmlOnly));
|
|
20
21
|
const isHtmlOnly = pageContext._isHtmlOnly;
|
|
21
|
-
const { isProduction } = pageContext._globalContext;
|
|
22
|
+
const { _isProduction: isProduction } = pageContext._globalContext;
|
|
22
23
|
const injectScriptsAt = getInjectScriptsAt(pageContext.pageId, pageContext._pageConfigs);
|
|
23
24
|
const injectFilterEntries = [];
|
|
24
25
|
pageAssets
|
|
@@ -124,14 +125,21 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
|
|
|
124
125
|
// - https://github.com/vikejs/vike-vue/issues/85
|
|
125
126
|
(0, utils_js_1.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 });
|
|
126
127
|
}
|
|
127
|
-
// <script id="vike_pageContext" type="application/json">
|
|
128
128
|
if (!isHtmlOnly) {
|
|
129
|
+
// <script id="vike_pageContext" type="application/json">
|
|
129
130
|
htmlTags.push({
|
|
130
131
|
htmlTag: () =>
|
|
131
132
|
// Needs to be called after resolvePageContextPromise()
|
|
132
133
|
getPageContextJsonScriptTag(pageContext),
|
|
133
134
|
position: positionJavaScriptEntry
|
|
134
135
|
});
|
|
136
|
+
// <script id="vike_globalContext" type="application/json">
|
|
137
|
+
htmlTags.push({
|
|
138
|
+
htmlTag: () =>
|
|
139
|
+
// Needs to be called after resolvePageContextPromise()
|
|
140
|
+
getGlobalContextJsonScriptTag(pageContext),
|
|
141
|
+
position: positionJavaScriptEntry
|
|
142
|
+
});
|
|
135
143
|
}
|
|
136
144
|
// The JavaScript entry <script> tag
|
|
137
145
|
const scriptEntry = mergeScriptEntries(pageAssets, viteDevScript);
|
|
@@ -162,13 +170,18 @@ function mergeScriptEntries(pageAssets, viteDevScript) {
|
|
|
162
170
|
return scriptTag;
|
|
163
171
|
}
|
|
164
172
|
function getPageContextJsonScriptTag(pageContext) {
|
|
165
|
-
const
|
|
166
|
-
const htmlTag = `<script id="
|
|
173
|
+
const pageContextClientSerialized = (0, sanitizeJson_js_1.sanitizeJson)((0, serializeContext_js_1.getPageContextClientSerialized)(pageContext));
|
|
174
|
+
const htmlTag = `<script id="${htmlElementIds_js_1.htmlElementId_pageContext}" type="application/json">${pageContextClientSerialized}</script>`;
|
|
167
175
|
// Used by contra.com https://github.com/gajus
|
|
168
176
|
// @ts-expect-error
|
|
169
177
|
pageContext._pageContextHtmlTag = htmlTag;
|
|
170
178
|
return htmlTag;
|
|
171
179
|
}
|
|
180
|
+
function getGlobalContextJsonScriptTag(pageContext) {
|
|
181
|
+
const globalContextClientSerialized = (0, sanitizeJson_js_1.sanitizeJson)((0, serializeContext_js_1.getGlobalContextClientSerialized)(pageContext));
|
|
182
|
+
const htmlTag = `<script id="${htmlElementIds_js_1.htmlElementId_globalContext}" type="application/json">${globalContextClientSerialized}</script>`;
|
|
183
|
+
return htmlTag;
|
|
184
|
+
}
|
|
172
185
|
function assertInjectFilterEntries(injectFilterEntries) {
|
|
173
186
|
try {
|
|
174
187
|
checkForWrongUsage(injectFilterEntries);
|
|
@@ -9,10 +9,10 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
9
9
|
const reachOutCTA = 'Create a new GitHub issue to discuss a solution.';
|
|
10
10
|
async function getViteDevScript(pageContext) {
|
|
11
11
|
const globalContext = pageContext._globalContext;
|
|
12
|
-
if (globalContext.
|
|
12
|
+
if (globalContext._isProduction) {
|
|
13
13
|
return '';
|
|
14
14
|
}
|
|
15
|
-
const { viteDevServer } = globalContext;
|
|
15
|
+
const { _viteDevServer: viteDevServer } = globalContext;
|
|
16
16
|
const fakeHtmlBegin = '<html> <head>'; // White space to test whether user is using a minifier
|
|
17
17
|
const fakeHtmlEnd = '</head><body></body></html>';
|
|
18
18
|
let fakeHtml = fakeHtmlBegin + fakeHtmlEnd;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPropVal = getPropVal;
|
|
4
|
+
exports.setPropVal = setPropVal;
|
|
5
|
+
exports.getPropKeys = getPropKeys;
|
|
6
|
+
const utils_js_1 = require("../utils.js");
|
|
7
|
+
// Get a nested property from an object using a dot-separated path such as 'user.id'
|
|
8
|
+
function getPropVal(obj, prop) {
|
|
9
|
+
const keys = getPropKeys(prop);
|
|
10
|
+
let value = obj;
|
|
11
|
+
for (const key of keys) {
|
|
12
|
+
if ((0, utils_js_1.isObject)(value) && key in value) {
|
|
13
|
+
value = value[key];
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return null; // Property or intermediate property doesn't exist
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return { value };
|
|
20
|
+
}
|
|
21
|
+
// Set a nested property in an object using a dot-separated path such as 'user.id'
|
|
22
|
+
function setPropVal(obj, prop, val) {
|
|
23
|
+
const keys = getPropKeys(prop);
|
|
24
|
+
let currentObj = obj;
|
|
25
|
+
// Creating intermediate objects if necessary
|
|
26
|
+
for (let i = 0; i <= keys.length - 2; i++) {
|
|
27
|
+
const key = keys[i];
|
|
28
|
+
if (!(key in currentObj)) {
|
|
29
|
+
// Create intermediate object
|
|
30
|
+
currentObj[key] = {};
|
|
31
|
+
}
|
|
32
|
+
if (!(0, utils_js_1.isObject)(currentObj[key])) {
|
|
33
|
+
// Skip value upon data structure conflict
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
currentObj = currentObj[key];
|
|
37
|
+
}
|
|
38
|
+
// Set the final key to the value
|
|
39
|
+
const finalKey = keys[keys.length - 1];
|
|
40
|
+
currentObj[finalKey] = val;
|
|
41
|
+
}
|
|
42
|
+
function getPropKeys(prop) {
|
|
43
|
+
// Like `prop.split('.')` but with added support for `\` escaping, see getPageContextClientSerialized.spec.ts
|
|
44
|
+
return prop
|
|
45
|
+
.split(/(?<!\\)\./) // Split on unescaped dots
|
|
46
|
+
.map((key) => key.replace(/\\\./g, '.')); // Replace escaped dots with literal dots
|
|
47
|
+
}
|
|
@@ -197,7 +197,7 @@ function renderTemplate(templateContent, pageContext) {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
{
|
|
200
|
-
const { isProduction } = pageContext._globalContext;
|
|
200
|
+
const { _isProduction: isProduction } = pageContext._globalContext;
|
|
201
201
|
if ((0, utils_js_1.isHtml)(templateVar) &&
|
|
202
202
|
// 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.
|
|
203
203
|
!isProduction) {
|
package/dist/cjs/node/runtime/html/{serializePageContextClientSide.js → serializeContext.js}
RENAMED
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
6
|
+
exports.getPageContextClientSerialized = getPageContextClientSerialized;
|
|
7
|
+
exports.getPageContextClientSerializedAbort = getPageContextClientSerializedAbort;
|
|
8
|
+
exports.getGlobalContextClientSerialized = getGlobalContextClientSerialized;
|
|
9
9
|
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
10
10
|
const utils_js_1 = require("../utils.js");
|
|
11
11
|
const error_page_js_1 = require("../../../shared/error-page.js");
|
|
@@ -14,7 +14,8 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
14
14
|
const NOT_SERIALIZABLE_js_1 = require("../../../shared/NOT_SERIALIZABLE.js");
|
|
15
15
|
const pageContextInitIsPassedToClient_js_1 = require("../../../shared/misc/pageContextInitIsPassedToClient.js");
|
|
16
16
|
const isServerSideError_js_1 = require("../../../shared/misc/isServerSideError.js");
|
|
17
|
-
const
|
|
17
|
+
const propKeys_js_1 = require("./propKeys.js");
|
|
18
|
+
const passToClientBuiltInPageContext = [
|
|
18
19
|
'abortReason',
|
|
19
20
|
'_urlRewrite',
|
|
20
21
|
'_urlRedirect',
|
|
@@ -28,29 +29,39 @@ const PASS_TO_CLIENT = [
|
|
|
28
29
|
'routeParams',
|
|
29
30
|
'data' // for data() hook
|
|
30
31
|
];
|
|
31
|
-
const
|
|
32
|
-
function
|
|
33
|
-
const
|
|
34
|
-
const pageContextClient = applyPassToClient(
|
|
35
|
-
if (
|
|
32
|
+
const pageToClientBuiltInPageContextError = ['pageProps', 'is404', isServerSideError_js_1.isServerSideError];
|
|
33
|
+
function getPageContextClientSerialized(pageContext) {
|
|
34
|
+
const passToClientPageContext = getPassToClientPageContext(pageContext);
|
|
35
|
+
const pageContextClient = applyPassToClient(passToClientPageContext, pageContext);
|
|
36
|
+
if (passToClientPageContext.some((prop) => (0, propKeys_js_1.getPropVal)(pageContext._pageContextInit, prop))) {
|
|
36
37
|
pageContextClient[pageContextInitIsPassedToClient_js_1.pageContextInitIsPassedToClient] = true;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
const pageContextClientSerialized = serializeObject(pageContextClient, 'pageContext', passToClientPageContext);
|
|
40
|
+
return pageContextClientSerialized;
|
|
41
|
+
}
|
|
42
|
+
function getGlobalContextClientSerialized(pageContext) {
|
|
43
|
+
const passToClient = pageContext._passToClient;
|
|
44
|
+
const globalContextClient = applyPassToClient(passToClient, pageContext.globalContext);
|
|
45
|
+
const globalContextClientSerialized = serializeObject(globalContextClient, 'globalContext', passToClient);
|
|
46
|
+
return globalContextClientSerialized;
|
|
47
|
+
}
|
|
48
|
+
function serializeObject(obj, objName, passToClient) {
|
|
49
|
+
let serialized;
|
|
39
50
|
try {
|
|
40
|
-
|
|
51
|
+
serialized = serializeValue(obj);
|
|
41
52
|
}
|
|
42
53
|
catch (err) {
|
|
43
54
|
const h = (s) => picocolors_1.default.cyan(s);
|
|
44
55
|
let hasWarned = false;
|
|
45
56
|
const propsNonSerializable = [];
|
|
46
57
|
passToClient.forEach((prop) => {
|
|
47
|
-
const res = getPropVal(
|
|
58
|
+
const res = (0, propKeys_js_1.getPropVal)(obj, prop);
|
|
48
59
|
if (!res)
|
|
49
60
|
return;
|
|
50
61
|
const { value } = res;
|
|
51
|
-
const varName =
|
|
62
|
+
const varName = `${objName}${(0, propKeys_js_1.getPropKeys)(prop).map(utils_js_1.getPropAccessNotation).join('')}`;
|
|
52
63
|
try {
|
|
53
|
-
|
|
64
|
+
serializeValue(value, varName);
|
|
54
65
|
}
|
|
55
66
|
catch (err) {
|
|
56
67
|
propsNonSerializable.push(prop);
|
|
@@ -62,7 +73,7 @@ function serializePageContextClientSide(pageContext) {
|
|
|
62
73
|
}
|
|
63
74
|
(0, utils_js_1.assertUsage)(false, `Cannot serialize config ${h(pathString)} set by useConfig(), see https://vike.dev/useConfig#serialization-error`);
|
|
64
75
|
}
|
|
65
|
-
// Non-serializable
|
|
76
|
+
// Non-serializable property set by the user
|
|
66
77
|
let msg = [
|
|
67
78
|
`${h(varName)} can't be serialized and, therefore, can't be passed to the client side.`,
|
|
68
79
|
`Make sure ${h(varName)} is serializable, or remove ${h(JSON.stringify(prop))} from ${h('passToClient')}.`
|
|
@@ -83,31 +94,31 @@ function serializePageContextClientSide(pageContext) {
|
|
|
83
94
|
});
|
|
84
95
|
(0, utils_js_1.assert)(hasWarned);
|
|
85
96
|
propsNonSerializable.forEach((prop) => {
|
|
86
|
-
|
|
97
|
+
obj[(0, propKeys_js_1.getPropKeys)(prop)[0]] = NOT_SERIALIZABLE_js_1.NOT_SERIALIZABLE;
|
|
87
98
|
});
|
|
88
99
|
try {
|
|
89
|
-
|
|
100
|
+
serialized = serializeValue(obj);
|
|
90
101
|
}
|
|
91
102
|
catch (err) {
|
|
92
103
|
(0, utils_js_1.assert)(false);
|
|
93
104
|
}
|
|
94
105
|
}
|
|
95
|
-
return
|
|
106
|
+
return serialized;
|
|
96
107
|
}
|
|
97
|
-
function
|
|
108
|
+
function serializeValue(value, varName) {
|
|
98
109
|
return (0, stringify_1.stringify)(value, { forbidReactElements: true, valueName: varName });
|
|
99
110
|
}
|
|
100
|
-
function
|
|
101
|
-
let passToClient = [...pageContext._passToClient, ...
|
|
111
|
+
function getPassToClientPageContext(pageContext) {
|
|
112
|
+
let passToClient = [...pageContext._passToClient, ...passToClientBuiltInPageContext];
|
|
102
113
|
if ((0, error_page_js_1.isErrorPage)(pageContext.pageId, pageContext._pageConfigs)) {
|
|
103
114
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, 'is404', 'boolean'));
|
|
104
115
|
(0, addIs404ToPageProps_js_1.addIs404ToPageProps)(pageContext);
|
|
105
|
-
passToClient.push(...
|
|
116
|
+
passToClient.push(...pageToClientBuiltInPageContextError);
|
|
106
117
|
}
|
|
107
118
|
passToClient = (0, utils_js_1.unique)(passToClient);
|
|
108
119
|
return passToClient;
|
|
109
120
|
}
|
|
110
|
-
function
|
|
121
|
+
function getPageContextClientSerializedAbort(pageContext) {
|
|
111
122
|
(0, utils_js_1.assert)(pageContext._urlRedirect || pageContext._urlRewrite || pageContext.abortStatusCode);
|
|
112
123
|
(0, utils_js_1.assert)(pageContext._abortCall);
|
|
113
124
|
(0, utils_js_1.assert)(pageContext._abortCaller);
|
|
@@ -140,59 +151,18 @@ function serializePageContextAbort(pageContext) {
|
|
|
140
151
|
onlyOnce: false
|
|
141
152
|
});
|
|
142
153
|
}
|
|
143
|
-
return
|
|
154
|
+
return serializeValue(pageContext);
|
|
144
155
|
}
|
|
145
156
|
function applyPassToClient(passToClient, pageContext) {
|
|
146
157
|
const pageContextClient = {};
|
|
147
158
|
passToClient.forEach((prop) => {
|
|
148
159
|
// Get value from pageContext
|
|
149
|
-
const res = getPropVal(pageContext, prop);
|
|
160
|
+
const res = (0, propKeys_js_1.getPropVal)(pageContext, prop);
|
|
150
161
|
if (!res)
|
|
151
162
|
return;
|
|
152
163
|
const { value } = res;
|
|
153
164
|
// Set value to pageContextClient
|
|
154
|
-
setPropVal(pageContextClient, prop, value);
|
|
165
|
+
(0, propKeys_js_1.setPropVal)(pageContextClient, prop, value);
|
|
155
166
|
});
|
|
156
167
|
return pageContextClient;
|
|
157
168
|
}
|
|
158
|
-
// Get a nested property from an object using a dot-separated path such as 'user.id'
|
|
159
|
-
function getPropVal(obj, prop) {
|
|
160
|
-
const keys = getPropKeys(prop);
|
|
161
|
-
let value = obj;
|
|
162
|
-
for (const key of keys) {
|
|
163
|
-
if ((0, utils_js_1.isObject)(value) && key in value) {
|
|
164
|
-
value = value[key];
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
return null; // Property or intermediate property doesn't exist
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return { value };
|
|
171
|
-
}
|
|
172
|
-
// Set a nested property in an object using a dot-separated path such as 'user.id'
|
|
173
|
-
function setPropVal(obj, prop, val) {
|
|
174
|
-
const keys = getPropKeys(prop);
|
|
175
|
-
let currentObj = obj;
|
|
176
|
-
// Creating intermediate objects if necessary
|
|
177
|
-
for (let i = 0; i <= keys.length - 2; i++) {
|
|
178
|
-
const key = keys[i];
|
|
179
|
-
if (!(key in currentObj)) {
|
|
180
|
-
// Create intermediate object
|
|
181
|
-
currentObj[key] = {};
|
|
182
|
-
}
|
|
183
|
-
if (!(0, utils_js_1.isObject)(currentObj[key])) {
|
|
184
|
-
// Skip value upon data structure conflict
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
currentObj = currentObj[key];
|
|
188
|
-
}
|
|
189
|
-
// Set the final key to the value
|
|
190
|
-
const finalKey = keys[keys.length - 1];
|
|
191
|
-
currentObj[finalKey] = val;
|
|
192
|
-
}
|
|
193
|
-
function getPropKeys(prop) {
|
|
194
|
-
// Like `prop.split('.')` but with added support for `\` escaping, see serializePageContextClientSide.spec.ts
|
|
195
|
-
return prop
|
|
196
|
-
.split(/(?<!\\)\./) // Split on unescaped dots
|
|
197
|
-
.map((key) => key.replace(/\\\./g, '.')); // Replace escaped dots with literal dots
|
|
198
|
-
}
|