vike 0.4.220-commit-af5c91f → 0.4.221-commit-8577456
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 +5 -23
- package/dist/cjs/node/api/build.js +55 -11
- package/dist/cjs/node/api/prepareViteApiCall.js +20 -17
- package/dist/cjs/node/api/prerender.js +1 -0
- package/dist/cjs/node/api/utils.js +1 -0
- package/dist/cjs/node/plugin/index.js +2 -0
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +9 -20
- package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/cjs/node/plugin/plugins/buildApp.js +72 -0
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +8 -10
- package/dist/cjs/node/plugin/plugins/buildConfig.js +5 -5
- package/dist/cjs/node/plugin/plugins/buildEntry/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +8 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{assertExtensions.js → getVikeConfig/assertExtensions.js} +31 -31
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +53 -21
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{getConfigFileExport.js → getVikeConfig/getConfigFileExport.js} +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +159 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +205 -343
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{debug.js → virtual-files/debug.js} +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigValuesAll.js → virtual-files/getVirtualFilePageConfigValuesAll.js} +7 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigs.js → virtual-files/getVirtualFilePageConfigs.js} +3 -3
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +1 -4
- package/dist/cjs/node/plugin/shared/getFullBuildInlineConfig.js +20 -0
- package/dist/cjs/node/plugin/shared/getOutDirs.js +50 -38
- package/dist/cjs/node/prerender/runPrerender.js +29 -30
- package/dist/cjs/node/runtime/globalContext.js +186 -100
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -3
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +2 -3
- package/dist/cjs/node/runtime/html/injectAssets.js +4 -4
- package/dist/cjs/node/runtime/html/renderHtml.js +4 -5
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -3
- package/dist/cjs/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.js +2 -4
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +4 -4
- package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +3 -5
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +5 -4
- package/dist/cjs/node/runtime/renderPage/log404/index.js +1 -2
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +10 -9
- package/dist/cjs/node/runtime/renderPage.js +27 -30
- package/dist/cjs/node/runtime/utils.js +1 -0
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +5 -3
- package/dist/cjs/node/shared/resolveBase.js +3 -5
- package/dist/cjs/shared/getPageConfigsRuntime.js +20 -0
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +4 -3
- package/dist/cjs/shared/getPageFiles.js +1 -3
- package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +13 -4
- package/dist/cjs/shared/route/loadPageRoutes.js +1 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +1 -1
- package/dist/cjs/utils/debug.js +8 -6
- package/dist/cjs/utils/findFile.js +1 -0
- package/dist/cjs/utils/objectAssignSafe.js +7 -0
- package/dist/esm/__internal/index.d.ts +2 -2
- package/dist/esm/__internal/index.js +7 -26
- package/dist/esm/client/client-routing-runtime/createPageContext.js +5 -9
- package/dist/esm/client/server-routing-runtime/getPageContext.js +3 -4
- package/dist/esm/client/shared/loadUserFilesClientSide.js +3 -2
- package/dist/esm/node/api/build.js +23 -12
- package/dist/esm/node/api/prepareViteApiCall.d.ts +4 -2
- package/dist/esm/node/api/prepareViteApiCall.js +20 -17
- package/dist/esm/node/api/prerender.js +1 -0
- package/dist/esm/node/api/utils.d.ts +1 -0
- package/dist/esm/node/api/utils.js +1 -0
- package/dist/esm/node/plugin/index.js +2 -0
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +10 -21
- package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/esm/node/plugin/plugins/buildApp.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/buildApp.js +70 -0
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +0 -2
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +8 -10
- package/dist/esm/node/plugin/plugins/buildConfig.js +6 -6
- package/dist/esm/node/plugin/plugins/buildEntry/index.js +2 -2
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +8 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.d.ts +6 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{assertExtensions.js → getVikeConfig/assertExtensions.js} +31 -31
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +52 -20
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getConfigFileExport.js → getVikeConfig/getConfigFileExport.js} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.d.ts +39 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +154 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -38
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +208 -346
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{debug.js → virtual-files/debug.js} +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigValuesAll.js → virtual-files/getVirtualFilePageConfigValuesAll.js} +7 -7
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigs.js → virtual-files/getVirtualFilePageConfigs.js} +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{isRuntimeEnvMatch.d.ts → virtual-files/isRuntimeEnvMatch.d.ts} +1 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +2 -5
- package/dist/esm/node/plugin/shared/getFullBuildInlineConfig.d.ts +2 -0
- package/dist/esm/node/plugin/shared/getFullBuildInlineConfig.js +17 -0
- package/dist/esm/node/plugin/shared/getOutDirs.d.ts +1 -1
- package/dist/esm/node/plugin/shared/getOutDirs.js +50 -38
- package/dist/esm/node/plugin/shared/viteIsSSR.d.ts +2 -5
- package/dist/esm/node/prerender/runPrerender.d.ts +2 -2
- package/dist/esm/node/prerender/runPrerender.js +30 -31
- package/dist/esm/node/runtime/globalContext.d.ts +31 -29
- package/dist/esm/node/runtime/globalContext.js +186 -100
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.d.ts +1 -1
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -3
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +4 -1
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +2 -3
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -0
- package/dist/esm/node/runtime/html/injectAssets.js +4 -4
- package/dist/esm/node/runtime/html/renderHtml.js +4 -5
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -1
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -3
- package/dist/esm/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.js +2 -4
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +4 -4
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +3 -5
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +6 -5
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/log404/index.js +1 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +3 -0
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +21 -5
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +10 -9
- package/dist/esm/node/runtime/renderPage.js +28 -31
- package/dist/esm/node/runtime/utils.d.ts +1 -0
- package/dist/esm/node/runtime/utils.js +1 -0
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +5 -3
- package/dist/esm/node/shared/resolveBase.d.ts +2 -1
- package/dist/esm/node/shared/resolveBase.js +3 -5
- package/dist/esm/shared/getPageConfigsRuntime.d.ts +13 -0
- package/dist/esm/shared/getPageConfigsRuntime.js +18 -0
- package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +1 -1
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +4 -3
- package/dist/esm/shared/getPageFiles.d.ts +0 -1
- package/dist/esm/shared/getPageFiles.js +0 -1
- package/dist/esm/shared/page-configs/Config.d.ts +7 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +9 -5
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +5 -7
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +13 -4
- package/dist/esm/shared/route/loadPageRoutes.js +1 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.js +1 -1
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +8 -6
- package/dist/esm/utils/findFile.js +1 -0
- package/dist/esm/utils/objectAssignSafe.d.ts +1 -0
- package/dist/esm/utils/objectAssignSafe.js +4 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +2 -2
- package/dist/cjs/shared/getPageFiles/getPageFiles.js +0 -48
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.d.ts +0 -6
- package/dist/esm/shared/getPageFiles/getPageFiles.d.ts +0 -15
- package/dist/esm/shared/getPageFiles/getPageFiles.js +0 -46
- /package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{isRuntimeEnvMatch.js → virtual-files/isRuntimeEnvMatch.js} +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getConfigFileExport.d.ts → getVikeConfig/getConfigFileExport.d.ts} +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{debug.d.ts → virtual-files/debug.d.ts} +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigValuesAll.d.ts → virtual-files/getVirtualFilePageConfigValuesAll.d.ts} +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{getVirtualFilePageConfigs.d.ts → virtual-files/getVirtualFilePageConfigs.d.ts} +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{isRuntimeEnvMatch.js → virtual-files/isRuntimeEnvMatch.js} +0 -0
|
@@ -5,64 +5,94 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getGlobalContextSync = getGlobalContextSync;
|
|
7
7
|
exports.getGlobalContextAsync = getGlobalContextAsync;
|
|
8
|
-
exports.
|
|
8
|
+
exports.getGlobalContextInternal = getGlobalContextInternal;
|
|
9
9
|
exports.getViteDevServer = getViteDevServer;
|
|
10
10
|
exports.getViteConfig = getViteConfig;
|
|
11
11
|
exports.initGlobalContext_renderPage = initGlobalContext_renderPage;
|
|
12
12
|
exports.initGlobalContext_runPrerender = initGlobalContext_runPrerender;
|
|
13
|
-
exports.
|
|
13
|
+
exports.initGlobalContext_getPagesAndRoutes = initGlobalContext_getPagesAndRoutes;
|
|
14
14
|
exports.setGlobalContext_viteDevServer = setGlobalContext_viteDevServer;
|
|
15
15
|
exports.setGlobalContext_viteConfig = setGlobalContext_viteConfig;
|
|
16
|
-
exports.setGlobalContext_vikeConfig = setGlobalContext_vikeConfig;
|
|
17
|
-
exports.setGlobalContext_isViteDev = setGlobalContext_isViteDev;
|
|
18
16
|
exports.setGlobalContext_isPrerendering = setGlobalContext_isPrerendering;
|
|
17
|
+
exports.setGlobalContext_isProduction = setGlobalContext_isProduction;
|
|
19
18
|
exports.setGlobalContext_buildEntry = setGlobalContext_buildEntry;
|
|
20
19
|
exports.clearGlobalContext = clearGlobalContext;
|
|
21
20
|
exports.assertBuildInfo = assertBuildInfo;
|
|
22
21
|
exports.getViteConfigRuntime = getViteConfigRuntime;
|
|
22
|
+
exports.updateUserFiles = updateUserFiles;
|
|
23
|
+
// The core logic revolves around:
|
|
24
|
+
// - globalObject.userFiles which is the main requirement for assembleGlobalContext()
|
|
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 globalObject.userFiles
|
|
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
|
+
// - Without vike-server it's manually loaded here using importServerProductionEntry() which uses @brillout/vite-plugin-server-entry's autoImporter or crawler
|
|
29
|
+
// - In development: globalObject.viteDevServer which is Vite's development server
|
|
30
|
+
// - globalObject.viteDevServer is used by updateUserFiles() which then sets globalConfig.userFiles
|
|
23
31
|
const utils_js_1 = require("./utils.js");
|
|
24
32
|
const runtime_1 = require("@brillout/vite-plugin-server-entry/runtime");
|
|
25
33
|
const virtualFileImportUserCode_js_1 = require("../shared/virtual-files/virtualFileImportUserCode.js");
|
|
26
|
-
const getPageFiles_js_1 = require("../../shared/getPageFiles/getPageFiles.js");
|
|
27
34
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
28
35
|
const loadPageRoutes_js_1 = require("../../shared/route/loadPageRoutes.js");
|
|
29
36
|
const assertV1Design_js_1 = require("../shared/assertV1Design.js");
|
|
37
|
+
const getPageConfigsRuntime_js_1 = require("../../shared/getPageConfigsRuntime.js");
|
|
30
38
|
const debug = (0, utils_js_1.createDebugger)('vike:globalContext');
|
|
31
39
|
const globalObject = (0, utils_js_1.getGlobalObject)('globalContext.ts', getInitialGlobalContext());
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
async function getGlobalContextInternal() {
|
|
41
|
+
// getGlobalContextInternal() should always be called after initGlobalContext()
|
|
42
|
+
(0, utils_js_1.assert)(globalObject.isInitialized);
|
|
43
|
+
assertGlobalContextIsDefined();
|
|
44
|
+
if (globalObject.isProduction !== true)
|
|
45
|
+
await globalObject.waitForUserFilesUpdate;
|
|
46
|
+
const { globalContext } = globalObject;
|
|
47
|
+
assertIsDefined(globalContext);
|
|
48
|
+
return globalContext;
|
|
49
|
+
}
|
|
50
|
+
function assertIsDefined(globalContext) {
|
|
51
|
+
if (!globalContext) {
|
|
52
|
+
debug('globalContext', globalContext);
|
|
53
|
+
debug('assertIsDefined()', new Error().stack);
|
|
36
54
|
(0, utils_js_1.assert)(false);
|
|
37
55
|
}
|
|
38
|
-
|
|
56
|
+
}
|
|
57
|
+
function assertGlobalContextIsDefined() {
|
|
58
|
+
assertIsDefined(globalObject.globalContext);
|
|
59
|
+
(0, utils_js_1.assert)(globalObject.globalContext_public);
|
|
39
60
|
}
|
|
40
61
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
41
62
|
function getGlobalContextSync() {
|
|
42
|
-
|
|
43
|
-
|
|
63
|
+
const { globalContext_public } = globalObject;
|
|
64
|
+
(0, utils_js_1.assertUsage)(globalContext_public, "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContextAsync() instead.");
|
|
65
|
+
return globalContext_public;
|
|
44
66
|
}
|
|
45
67
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
46
68
|
async function getGlobalContextAsync(isProduction) {
|
|
47
69
|
(0, utils_js_1.assertUsage)(typeof isProduction === 'boolean', `[getGlobalContextAsync(isProduction)] Argument ${picocolors_1.default.cyan('isProduction')} ${isProduction === undefined ? 'is missing' : `should be ${picocolors_1.default.cyan('true')} or ${picocolors_1.default.cyan('false')}`}`);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
70
|
+
setIsProduction(isProduction);
|
|
71
|
+
if (!globalObject.globalContext)
|
|
72
|
+
await initGlobalContext_getGlobalContextAsync();
|
|
73
|
+
if (!isProduction)
|
|
74
|
+
await globalObject.waitForUserFilesUpdate;
|
|
75
|
+
assertGlobalContextIsDefined();
|
|
76
|
+
const { globalContext_public } = globalObject;
|
|
77
|
+
(0, utils_js_1.assert)(globalContext_public);
|
|
78
|
+
return globalContext_public;
|
|
52
79
|
}
|
|
53
80
|
function makePublic(globalContext) {
|
|
54
|
-
// TODO/
|
|
55
|
-
const globalContextPublic = (0, utils_js_1.makePublicCopy)(globalContext, 'globalContext', ['assetsManifest']);
|
|
81
|
+
// TODO/soon: add `pages`
|
|
82
|
+
const globalContextPublic = (0, utils_js_1.makePublicCopy)(globalContext, 'globalContext', ['assetsManifest', 'config', 'viteConfig']);
|
|
56
83
|
return globalContextPublic;
|
|
57
84
|
}
|
|
58
|
-
function setGlobalContext_viteDevServer(viteDevServer) {
|
|
85
|
+
async function setGlobalContext_viteDevServer(viteDevServer) {
|
|
86
|
+
debug('setGlobalContext_viteDevServer()');
|
|
87
|
+
setIsProduction(false);
|
|
59
88
|
if (globalObject.viteDevServer)
|
|
60
89
|
return;
|
|
61
90
|
assertIsNotInitilizedYet();
|
|
62
91
|
(0, utils_js_1.assert)(globalObject.viteConfig);
|
|
63
92
|
globalObject.viteDevServer = viteDevServer;
|
|
93
|
+
await updateUserFiles();
|
|
94
|
+
assertGlobalContextIsDefined();
|
|
64
95
|
globalObject.viteDevServerPromiseResolve(viteDevServer);
|
|
65
|
-
eagerlyLoadUserFiles();
|
|
66
96
|
}
|
|
67
97
|
function setGlobalContext_viteConfig(viteConfig, outDirRoot) {
|
|
68
98
|
if (globalObject.viteConfig)
|
|
@@ -71,21 +101,16 @@ function setGlobalContext_viteConfig(viteConfig, outDirRoot) {
|
|
|
71
101
|
globalObject.viteConfig = viteConfig;
|
|
72
102
|
globalObject.outDirRoot = outDirRoot;
|
|
73
103
|
}
|
|
74
|
-
function setGlobalContext_vikeConfig(vikeConfig) {
|
|
75
|
-
if (globalObject.vikeConfig)
|
|
76
|
-
return;
|
|
77
|
-
assertIsNotInitilizedYet();
|
|
78
|
-
globalObject.vikeConfig = vikeConfig;
|
|
79
|
-
}
|
|
80
104
|
function assertIsNotInitilizedYet() {
|
|
81
|
-
// In
|
|
105
|
+
// In development, globalObject.viteDevServer always needs to be awaited for before initializing globalObject.globalContext
|
|
82
106
|
(0, utils_js_1.assert)(!globalObject.globalContext);
|
|
83
107
|
}
|
|
84
|
-
function setGlobalContext_isViteDev(isViteDev) {
|
|
85
|
-
globalObject.isViteDev = isViteDev;
|
|
86
|
-
}
|
|
87
108
|
function setGlobalContext_isPrerendering() {
|
|
88
109
|
globalObject.isPrerendering = true;
|
|
110
|
+
setIsProduction(true);
|
|
111
|
+
}
|
|
112
|
+
function setGlobalContext_isProduction(isProduction) {
|
|
113
|
+
setIsProduction(isProduction);
|
|
89
114
|
}
|
|
90
115
|
function getViteDevServer() {
|
|
91
116
|
return globalObject.viteDevServer ?? null;
|
|
@@ -95,10 +120,15 @@ function getViteConfig() {
|
|
|
95
120
|
}
|
|
96
121
|
async function initGlobalContext_renderPage() {
|
|
97
122
|
debug('initGlobalContext_renderPage()');
|
|
98
|
-
|
|
123
|
+
// globalObject.isProduction isn't set upon production server without vike-server (there isn't any signal we can use)
|
|
124
|
+
if (globalObject.isProduction === undefined)
|
|
125
|
+
setIsProduction(true);
|
|
126
|
+
await initGlobalContext();
|
|
99
127
|
}
|
|
100
128
|
async function initGlobalContext_runPrerender() {
|
|
101
129
|
debug('initGlobalContext_runPrerender()');
|
|
130
|
+
(0, utils_js_1.assert)(globalObject.isPrerendering === true);
|
|
131
|
+
(0, utils_js_1.assert)(globalObject.isProduction === true);
|
|
102
132
|
if (globalObject.initGlobalContext_runPrerender_alreadyCalled)
|
|
103
133
|
return;
|
|
104
134
|
globalObject.initGlobalContext_runPrerender_alreadyCalled = true;
|
|
@@ -108,65 +138,93 @@ async function initGlobalContext_runPrerender() {
|
|
|
108
138
|
// We assume initGlobalContext_runPrerender() to be called before:
|
|
109
139
|
// - initGlobalContext_renderPage()
|
|
110
140
|
// - initGlobalContext_getGlobalContextAsync()
|
|
111
|
-
(
|
|
112
|
-
await initGlobalContext(
|
|
141
|
+
assertIsNotInitilizedYet();
|
|
142
|
+
await initGlobalContext();
|
|
113
143
|
}
|
|
114
|
-
async function initGlobalContext_getGlobalContextAsync(
|
|
144
|
+
async function initGlobalContext_getGlobalContextAsync() {
|
|
115
145
|
debug('initGlobalContext_getGlobalContextAsync()');
|
|
146
|
+
await initGlobalContext();
|
|
147
|
+
}
|
|
148
|
+
async function initGlobalContext_getPagesAndRoutes() {
|
|
149
|
+
debug('initGlobalContext_getPagesAndRoutes()');
|
|
150
|
+
setIsProduction(true);
|
|
151
|
+
await initGlobalContext();
|
|
152
|
+
}
|
|
153
|
+
async function waitForViteDevServer() {
|
|
154
|
+
debug('waitForViteDevServer()');
|
|
155
|
+
const waitFor = 20;
|
|
156
|
+
const timeout = setTimeout(() => {
|
|
157
|
+
(0, utils_js_1.assertWarning)(false, `Vite's development server still not created after ${waitFor} seconds.`, {
|
|
158
|
+
onlyOnce: false,
|
|
159
|
+
showStackTrace: true
|
|
160
|
+
});
|
|
161
|
+
}, waitFor * 1000);
|
|
162
|
+
await globalObject.viteDevServerPromise;
|
|
163
|
+
clearTimeout(timeout);
|
|
164
|
+
assertGlobalContextIsDefined();
|
|
165
|
+
}
|
|
166
|
+
async function initGlobalContext() {
|
|
167
|
+
const { isProduction } = globalObject;
|
|
168
|
+
(0, utils_js_1.assert)(typeof isProduction === 'boolean');
|
|
116
169
|
if (!isProduction) {
|
|
117
|
-
|
|
118
|
-
const timeout = setTimeout(() => {
|
|
119
|
-
(0, utils_js_1.assertWarning)(false, `Vite's development server still not created after ${waitFor} seconds.`, {
|
|
120
|
-
onlyOnce: false,
|
|
121
|
-
showStackTrace: true
|
|
122
|
-
});
|
|
123
|
-
}, waitFor * 1000);
|
|
124
|
-
await globalObject.viteDevServerPromise;
|
|
125
|
-
clearTimeout(timeout);
|
|
170
|
+
await waitForViteDevServer();
|
|
126
171
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// TODO/now: refactor: move this to the top of the file
|
|
130
|
-
async function initGlobalContext(isProduction) {
|
|
131
|
-
if (globalObject.globalContext) {
|
|
132
|
-
(0, utils_js_1.assert)(globalObject.globalContext.isProduction === isProduction);
|
|
133
|
-
// We assume setGlobalContext_isPrerendering() is called before initGlobalContext()
|
|
134
|
-
(0, utils_js_1.assert)(globalObject.globalContext.isPrerendering === (globalObject.isPrerendering ?? false));
|
|
135
|
-
return;
|
|
172
|
+
else {
|
|
173
|
+
await loadBuildEntry(globalObject.outDirRoot);
|
|
136
174
|
}
|
|
137
|
-
|
|
175
|
+
assertGlobalContextIsDefined();
|
|
176
|
+
globalObject.isInitialized = true;
|
|
177
|
+
}
|
|
178
|
+
function setIsProduction(isProduction) {
|
|
179
|
+
debug('setIsProduction', isProduction);
|
|
180
|
+
(0, utils_js_1.assert)(typeof isProduction === 'boolean');
|
|
181
|
+
if (globalObject.isProduction !== undefined)
|
|
182
|
+
(0, utils_js_1.assert)(globalObject.isProduction === isProduction);
|
|
183
|
+
globalObject.isProduction = isProduction;
|
|
184
|
+
}
|
|
185
|
+
function defineGlobalContext() {
|
|
186
|
+
const globalContext = assembleGlobalContext();
|
|
187
|
+
assertIsDefined(globalContext);
|
|
188
|
+
const globalContext_public = makePublic(globalContext);
|
|
189
|
+
(0, utils_js_1.objectAssign)(globalContext, { globalContext_public });
|
|
190
|
+
globalObject.globalContext = globalContext;
|
|
191
|
+
globalObject.globalContext_public = globalContext_public;
|
|
192
|
+
assertGlobalContextIsDefined();
|
|
138
193
|
(0, utils_js_1.onSetupRuntime)();
|
|
194
|
+
}
|
|
195
|
+
function assembleGlobalContext() {
|
|
196
|
+
const { viteDevServer, viteConfig, isPrerendering, isProduction, userFiles } = globalObject;
|
|
197
|
+
(0, utils_js_1.assert)(typeof isProduction === 'boolean');
|
|
198
|
+
let globalContext;
|
|
139
199
|
if (!isProduction) {
|
|
200
|
+
// Requires globalObject.viteDevServer
|
|
201
|
+
if (!viteDevServer)
|
|
202
|
+
return null;
|
|
203
|
+
(0, utils_js_1.assert)(userFiles); // main common requiement
|
|
140
204
|
(0, utils_js_1.assert)(viteConfig);
|
|
141
|
-
(0, utils_js_1.assert)(vikeConfig);
|
|
142
|
-
(0, utils_js_1.assert)(viteDevServer);
|
|
143
205
|
(0, utils_js_1.assert)(!isPrerendering);
|
|
144
|
-
const { globalConfig, userFiles } = await getPageRuntimeInfo(isProduction);
|
|
145
206
|
const viteConfigRuntime = getViteConfigRuntime(viteConfig);
|
|
146
|
-
|
|
207
|
+
globalContext = {
|
|
147
208
|
isProduction: false,
|
|
148
209
|
isPrerendering: false,
|
|
149
210
|
assetsManifest: null,
|
|
150
211
|
viteDevServer,
|
|
151
212
|
viteConfig,
|
|
152
|
-
vikeConfig: {
|
|
153
|
-
global: globalConfig
|
|
154
|
-
},
|
|
155
213
|
...userFiles,
|
|
156
214
|
viteConfigRuntime
|
|
157
215
|
};
|
|
158
216
|
}
|
|
159
217
|
else {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const
|
|
218
|
+
// Requires globalObject.buildEntry
|
|
219
|
+
if (!globalObject.buildEntry)
|
|
220
|
+
return null;
|
|
221
|
+
(0, utils_js_1.assert)(userFiles); // main common requiement
|
|
222
|
+
const { buildInfo, assetsManifest } = globalObject;
|
|
223
|
+
(0, utils_js_1.assert)(buildInfo);
|
|
224
|
+
(0, utils_js_1.assert)(assetsManifest);
|
|
225
|
+
const globalContext_ = {
|
|
165
226
|
isProduction: true,
|
|
166
227
|
assetsManifest,
|
|
167
|
-
vikeConfig: {
|
|
168
|
-
global: globalConfig
|
|
169
|
-
},
|
|
170
228
|
...userFiles,
|
|
171
229
|
viteDevServer: null,
|
|
172
230
|
viteConfigRuntime: buildInfo.viteConfigRuntime,
|
|
@@ -174,23 +232,28 @@ async function initGlobalContext(isProduction) {
|
|
|
174
232
|
};
|
|
175
233
|
if (isPrerendering) {
|
|
176
234
|
(0, utils_js_1.assert)(viteConfig);
|
|
177
|
-
(0, utils_js_1.objectAssign)(
|
|
235
|
+
(0, utils_js_1.objectAssign)(globalContext_, {
|
|
178
236
|
isPrerendering: true,
|
|
179
237
|
viteConfig
|
|
180
238
|
});
|
|
181
|
-
|
|
239
|
+
globalContext = globalContext_;
|
|
182
240
|
}
|
|
183
241
|
else {
|
|
184
|
-
(0, utils_js_1.objectAssign)(
|
|
242
|
+
(0, utils_js_1.objectAssign)(globalContext_, {
|
|
185
243
|
isPrerendering: false,
|
|
186
244
|
viteConfig: null
|
|
187
245
|
});
|
|
188
|
-
|
|
246
|
+
globalContext = globalContext_;
|
|
189
247
|
}
|
|
190
248
|
}
|
|
249
|
+
return globalContext;
|
|
191
250
|
}
|
|
192
|
-
async function
|
|
193
|
-
|
|
251
|
+
async function getUserFiles() {
|
|
252
|
+
// Help TypeScript resolve what TypeScript (wrongfully) believes to be cyclic dependency
|
|
253
|
+
const globalObject_ = globalObject;
|
|
254
|
+
const { pageConfigsRuntime } = globalObject_;
|
|
255
|
+
(0, utils_js_1.assert)(pageConfigsRuntime);
|
|
256
|
+
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig } = pageConfigsRuntime;
|
|
194
257
|
const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
|
|
195
258
|
const userFiles = {
|
|
196
259
|
pageFilesAll,
|
|
@@ -198,12 +261,13 @@ async function getPageRuntimeInfo(isProduction) {
|
|
|
198
261
|
pageConfigGlobal,
|
|
199
262
|
allPageIds,
|
|
200
263
|
pageRoutes,
|
|
201
|
-
onBeforeRouteHook
|
|
264
|
+
onBeforeRouteHook,
|
|
265
|
+
config: globalConfig.config
|
|
202
266
|
};
|
|
203
267
|
(0, assertV1Design_js_1.assertV1Design)(
|
|
204
268
|
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
205
269
|
pageConfigs.length > 0, pageFilesAll);
|
|
206
|
-
return
|
|
270
|
+
return userFiles;
|
|
207
271
|
}
|
|
208
272
|
function assertViteManifest(manifest) {
|
|
209
273
|
(0, utils_js_1.assert)((0, utils_js_1.isPlainObject)(manifest));
|
|
@@ -218,45 +282,56 @@ function assertViteManifest(manifest) {
|
|
|
218
282
|
})
|
|
219
283
|
*/
|
|
220
284
|
}
|
|
221
|
-
function
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
285
|
+
async function loadBuildEntry(outDir) {
|
|
286
|
+
debug('loadBuildEntry()');
|
|
287
|
+
if (globalObject.userFiles) {
|
|
288
|
+
(0, utils_js_1.assert)(globalObject.buildInfo);
|
|
289
|
+
(0, utils_js_1.assert)(globalObject.assetsManifest);
|
|
290
|
+
(0, utils_js_1.assert)(globalObject.buildEntry);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
228
293
|
if (!globalObject.buildEntry) {
|
|
229
294
|
debug('importServerProductionEntry()');
|
|
230
295
|
// importServerProductionEntry() loads dist/server/entry.mjs which calls setGlobalContext_buildEntry()
|
|
231
|
-
await (0, runtime_1.importServerProductionEntry)({ outDir
|
|
296
|
+
await (0, runtime_1.importServerProductionEntry)({ outDir });
|
|
232
297
|
if (!globalObject.buildEntry) {
|
|
233
298
|
debug('globalObject.buildEntryPrevious');
|
|
234
299
|
// Needed, for example, when calling the API prerender() then preview() because both trigger a importServerProductionEntry() call but only the first only is applied because of the import() cache. (A proper implementation would be to clear the import() cache, but it probably isn't possible on platforms such as Cloudflare Workers.)
|
|
235
300
|
globalObject.buildEntry = globalObject.buildEntryPrevious;
|
|
236
301
|
}
|
|
237
302
|
(0, utils_js_1.assert)(globalObject.buildEntry);
|
|
303
|
+
(0, utils_js_1.assertWarning)(!globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject,
|
|
304
|
+
// TODO/soon: show precise path
|
|
305
|
+
// TODO/soon: make this warning work on test/vike-node/
|
|
306
|
+
`Run the server production build (e.g. ${picocolors_1.default.cyan('$ node dist/server/index.mjs')}) instead of running the original server entry (e.g. ${picocolors_1.default.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
|
|
238
307
|
}
|
|
239
308
|
const { buildEntry } = globalObject;
|
|
240
309
|
assertBuildEntry(buildEntry);
|
|
241
|
-
|
|
310
|
+
globalObject.assetsManifest = buildEntry.assetsManifest;
|
|
311
|
+
globalObject.buildInfo = buildEntry.buildInfo;
|
|
312
|
+
await setUserFiles(buildEntry.virtualFileExports);
|
|
242
313
|
}
|
|
243
|
-
function setGlobalContext_buildEntry(buildEntry) {
|
|
314
|
+
async function setGlobalContext_buildEntry(buildEntry) {
|
|
244
315
|
debug('setGlobalContext_buildEntry()');
|
|
316
|
+
setIsProduction(true);
|
|
245
317
|
assertBuildEntry(buildEntry);
|
|
246
318
|
globalObject.buildEntry = buildEntry;
|
|
247
319
|
globalObject.buildEntryPrevious = buildEntry;
|
|
320
|
+
(0, utils_js_1.assert)(globalObject.buildEntry); // ensure no infinite loop
|
|
321
|
+
await loadBuildEntry();
|
|
322
|
+
assertGlobalContextIsDefined();
|
|
248
323
|
}
|
|
249
324
|
function assertBuildEntry(buildEntry) {
|
|
250
325
|
(0, utils_js_1.assert)((0, utils_js_1.isObject)(buildEntry));
|
|
251
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildEntry, '
|
|
252
|
-
const {
|
|
326
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildEntry, 'virtualFileExports', 'object'));
|
|
327
|
+
const { virtualFileExports } = buildEntry;
|
|
253
328
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildEntry, 'assetsManifest', 'object'));
|
|
254
329
|
const { assetsManifest } = buildEntry;
|
|
255
330
|
assertViteManifest(assetsManifest);
|
|
256
331
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildEntry, 'buildInfo', 'object'));
|
|
257
332
|
const { buildInfo } = buildEntry;
|
|
258
333
|
assertBuildInfo(buildInfo);
|
|
259
|
-
(0, utils_js_1.checkType)({
|
|
334
|
+
(0, utils_js_1.checkType)({ virtualFileExports, assetsManifest, buildInfo });
|
|
260
335
|
}
|
|
261
336
|
function assertBuildInfo(buildInfo) {
|
|
262
337
|
(0, utils_js_1.assert)((0, utils_js_1.isObject)(buildInfo));
|
|
@@ -264,6 +339,7 @@ function assertBuildInfo(buildInfo) {
|
|
|
264
339
|
assertVersionAtBuildTime(buildInfo.versionAtBuildTime);
|
|
265
340
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildInfo, 'viteConfigRuntime', 'object'));
|
|
266
341
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildInfo.viteConfigRuntime, '_baseViteOriginal', 'string'));
|
|
342
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildInfo.viteConfigRuntime, 'vitePluginServerEntry', 'object'));
|
|
267
343
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(buildInfo, 'usesClientRouter', 'boolean'));
|
|
268
344
|
(0, utils_js_1.checkType)({ ...buildInfo, viteConfigRuntime: buildInfo.viteConfigRuntime });
|
|
269
345
|
}
|
|
@@ -275,28 +351,38 @@ function assertVersionAtBuildTime(versionAtBuildTime) {
|
|
|
275
351
|
function getViteConfigRuntime(viteConfig) {
|
|
276
352
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(viteConfig, '_baseViteOriginal', 'string'));
|
|
277
353
|
const viteConfigRuntime = {
|
|
278
|
-
_baseViteOriginal: viteConfig._baseViteOriginal
|
|
354
|
+
_baseViteOriginal: viteConfig._baseViteOriginal,
|
|
355
|
+
vitePluginServerEntry: {
|
|
356
|
+
inject: viteConfig.vitePluginServerEntry?.inject
|
|
357
|
+
}
|
|
279
358
|
};
|
|
280
359
|
return viteConfigRuntime;
|
|
281
360
|
}
|
|
282
|
-
function
|
|
283
|
-
(0,
|
|
284
|
-
|
|
285
|
-
|
|
361
|
+
async function updateUserFiles() {
|
|
362
|
+
const { promise, resolve } = (0, utils_js_1.genPromise)();
|
|
363
|
+
(0, utils_js_1.assert)(!globalObject.isProduction);
|
|
364
|
+
globalObject.waitForUserFilesUpdate = promise;
|
|
286
365
|
const viteDevServer = getViteDevServer();
|
|
287
366
|
(0, utils_js_1.assert)(viteDevServer);
|
|
288
|
-
let
|
|
367
|
+
let virtualFileExports;
|
|
289
368
|
try {
|
|
290
|
-
|
|
369
|
+
virtualFileExports = await viteDevServer.ssrLoadModule(virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer);
|
|
291
370
|
}
|
|
292
371
|
catch (err) {
|
|
293
372
|
(0, utils_js_1.debugGlob)(`Glob error: ${virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer} transpile error: `, err);
|
|
294
373
|
throw err;
|
|
295
374
|
}
|
|
296
|
-
|
|
297
|
-
(0, utils_js_1.debugGlob)('Glob result: ',
|
|
298
|
-
|
|
299
|
-
|
|
375
|
+
virtualFileExports = virtualFileExports.default || virtualFileExports;
|
|
376
|
+
(0, utils_js_1.debugGlob)('Glob result: ', virtualFileExports);
|
|
377
|
+
await setUserFiles(virtualFileExports);
|
|
378
|
+
resolve();
|
|
379
|
+
}
|
|
380
|
+
async function setUserFiles(virtualFileExports) {
|
|
381
|
+
globalObject.pageConfigsRuntime = (0, getPageConfigsRuntime_js_1.getPageConfigsRuntime)(virtualFileExports);
|
|
382
|
+
const userFiles = await getUserFiles();
|
|
383
|
+
globalObject.userFiles = userFiles;
|
|
384
|
+
defineGlobalContext();
|
|
385
|
+
assertGlobalContextIsDefined();
|
|
300
386
|
}
|
|
301
387
|
function clearGlobalContext() {
|
|
302
388
|
debug('clearGlobalContext()');
|
|
@@ -12,14 +12,13 @@ const inferHtmlTags_js_1 = require("./inferHtmlTags.js");
|
|
|
12
12
|
const mergeScriptTags_js_1 = require("./mergeScriptTags.js");
|
|
13
13
|
const helpers_js_1 = require("../../../../shared/page-configs/helpers.js");
|
|
14
14
|
const getConfigValueRuntime_js_1 = require("../../../../shared/page-configs/getConfigValueRuntime.js");
|
|
15
|
-
const globalContext_js_1 = require("../../globalContext.js");
|
|
16
15
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
17
16
|
const getConfigDefinedAt_js_1 = require("../../../../shared/page-configs/getConfigDefinedAt.js");
|
|
18
17
|
const stamp = '__injectFilterEntry';
|
|
19
|
-
function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, isStream) {
|
|
18
|
+
async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, isStream) {
|
|
20
19
|
(0, utils_js_1.assert)([true, false].includes(pageContext._isHtmlOnly));
|
|
21
20
|
const isHtmlOnly = pageContext._isHtmlOnly;
|
|
22
|
-
const { isProduction } =
|
|
21
|
+
const { isProduction } = pageContext._globalContext;
|
|
23
22
|
const injectScriptsAt = getInjectScriptsAt(pageContext.pageId, pageContext._pageConfigs);
|
|
24
23
|
const injectFilterEntries = [];
|
|
25
24
|
pageAssets
|
|
@@ -4,11 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getViteDevScript = getViteDevScript;
|
|
7
|
-
const globalContext_js_1 = require("../../globalContext.js");
|
|
8
7
|
const utils_js_1 = require("../../utils.js");
|
|
9
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
|
-
async function getViteDevScript() {
|
|
11
|
-
const globalContext =
|
|
9
|
+
async function getViteDevScript(pageContext) {
|
|
10
|
+
const globalContext = pageContext._globalContext;
|
|
12
11
|
if (globalContext.isProduction) {
|
|
13
12
|
return '';
|
|
14
13
|
}
|
|
@@ -9,8 +9,8 @@ const getHtmlTags_js_1 = require("./injectAssets/getHtmlTags.js");
|
|
|
9
9
|
const getViteDevScript_js_1 = require("./injectAssets/getViteDevScript.js");
|
|
10
10
|
async function injectHtmlTagsToString(htmlParts, pageContext, injectFilter) {
|
|
11
11
|
const pageAssets = await pageContext.__getPageAssets();
|
|
12
|
-
const viteDevScript = await (0, getViteDevScript_js_1.getViteDevScript)();
|
|
13
|
-
const htmlTags = (0, getHtmlTags_js_1.getHtmlTags)(pageContext, null, injectFilter, pageAssets, viteDevScript, false);
|
|
12
|
+
const viteDevScript = await (0, getViteDevScript_js_1.getViteDevScript)(pageContext);
|
|
13
|
+
const htmlTags = await (0, getHtmlTags_js_1.getHtmlTags)(pageContext, null, injectFilter, pageAssets, viteDevScript, false);
|
|
14
14
|
let htmlString = htmlPartsToString(htmlParts, pageAssets);
|
|
15
15
|
htmlString = injectToHtmlBegin(htmlString, htmlTags);
|
|
16
16
|
htmlString = injectToHtmlEnd(htmlString, htmlTags);
|
|
@@ -26,8 +26,8 @@ function injectHtmlTagsToStream(pageContext, streamFromReactStreamingPackage, in
|
|
|
26
26
|
};
|
|
27
27
|
async function injectAtStreamBegin(htmlPartsBegin) {
|
|
28
28
|
const pageAssets = await pageContext.__getPageAssets();
|
|
29
|
-
const viteDevScript = await (0, getViteDevScript_js_1.getViteDevScript)();
|
|
30
|
-
htmlTags = (0, getHtmlTags_js_1.getHtmlTags)(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, true);
|
|
29
|
+
const viteDevScript = await (0, getViteDevScript_js_1.getViteDevScript)(pageContext);
|
|
30
|
+
htmlTags = await (0, getHtmlTags_js_1.getHtmlTags)(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, true);
|
|
31
31
|
let htmlBegin = htmlPartsToString(htmlPartsBegin, pageAssets);
|
|
32
32
|
htmlBegin = injectToHtmlBegin(htmlBegin, htmlTags);
|
|
33
33
|
if (streamFromReactStreamingPackage) {
|
|
@@ -12,7 +12,6 @@ const utils_js_1 = require("../utils.js");
|
|
|
12
12
|
const injectAssets_js_1 = require("./injectAssets.js");
|
|
13
13
|
const stream_js_1 = require("./stream.js");
|
|
14
14
|
const react_streaming_js_1 = require("./stream/react-streaming.js");
|
|
15
|
-
const globalContext_js_1 = require("../globalContext.js");
|
|
16
15
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
17
16
|
function isDocumentHtml(something) {
|
|
18
17
|
if (isTemplateWrapped(something) || isEscapedString(something) || (0, stream_js_1.isStream)(something)) {
|
|
@@ -36,7 +35,7 @@ async function renderDocumentHtml(documentHtml, pageContext, onErrorWhileStreami
|
|
|
36
35
|
}
|
|
37
36
|
if (isTemplateWrapped(documentHtml)) {
|
|
38
37
|
const templateContent = documentHtml._template;
|
|
39
|
-
const render =
|
|
38
|
+
const render = renderTemplate(templateContent, pageContext);
|
|
40
39
|
if (!('htmlStream' in render)) {
|
|
41
40
|
(0, utils_js_1.objectAssign)(pageContext, { _isStream: false });
|
|
42
41
|
const { htmlPartsAll } = render;
|
|
@@ -125,7 +124,7 @@ function _dangerouslySkipEscape(arg) {
|
|
|
125
124
|
});
|
|
126
125
|
return { _escaped: String(arg) };
|
|
127
126
|
}
|
|
128
|
-
|
|
127
|
+
function renderTemplate(templateContent, pageContext) {
|
|
129
128
|
const htmlPartsBegin = [];
|
|
130
129
|
const htmlPartsEnd = [];
|
|
131
130
|
let htmlStream = null;
|
|
@@ -156,7 +155,7 @@ async function renderTemplate(templateContent, pageContext) {
|
|
|
156
155
|
// Process `escapeInject` fragments
|
|
157
156
|
if (isTemplateWrapped(templateVar)) {
|
|
158
157
|
const templateContentInner = templateVar._template;
|
|
159
|
-
const result =
|
|
158
|
+
const result = renderTemplate(templateContentInner, pageContext);
|
|
160
159
|
if (!('htmlStream' in result)) {
|
|
161
160
|
result.htmlPartsAll.forEach(addHtmlPart);
|
|
162
161
|
}
|
|
@@ -198,7 +197,7 @@ async function renderTemplate(templateContent, pageContext) {
|
|
|
198
197
|
}
|
|
199
198
|
}
|
|
200
199
|
{
|
|
201
|
-
const { isProduction } =
|
|
200
|
+
const { isProduction } = pageContext._globalContext;
|
|
202
201
|
if ((0, utils_js_1.isHtml)(templateVar) &&
|
|
203
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.
|
|
204
203
|
!isProduction) {
|
|
@@ -5,9 +5,8 @@ const determineClientEntry_js_1 = require("../../../shared/getPageFiles/analyzeP
|
|
|
5
5
|
const analyzePageClientSide_js_1 = require("../../../shared/getPageFiles/analyzePageClientSide.js");
|
|
6
6
|
const virtualFilePageConfigValuesAll_js_1 = require("../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
7
7
|
const analyzeClientSide_js_1 = require("../../../shared/getPageFiles/analyzeClientSide.js");
|
|
8
|
-
const globalContext_js_1 = require("../globalContext.js");
|
|
9
8
|
const getConfigValueRuntime_js_1 = require("../../../shared/page-configs/getConfigValueRuntime.js");
|
|
10
|
-
function analyzePage(pageFilesAll, pageConfig, pageId) {
|
|
9
|
+
async function analyzePage(pageFilesAll, pageConfig, pageId, globalContext) {
|
|
11
10
|
if (pageConfig) {
|
|
12
11
|
const { isClientRuntimeLoaded, isClientRouting } = (0, analyzeClientSide_js_1.analyzeClientSide)(pageConfig, pageFilesAll, pageId);
|
|
13
12
|
const clientEntries = [];
|
|
@@ -23,7 +22,7 @@ function analyzePage(pageFilesAll, pageConfig, pageId) {
|
|
|
23
22
|
eagerlyImported: false
|
|
24
23
|
});
|
|
25
24
|
// In production we inject the import of the server virtual module with ?extractAssets inside the client virtual module
|
|
26
|
-
if (!
|
|
25
|
+
if (!globalContext.isProduction) {
|
|
27
26
|
clientDependencies.push({
|
|
28
27
|
id: (0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageConfig.pageId, false),
|
|
29
28
|
onlyAssets: true,
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sortPageAssetsForEarlyHintsHeader = sortPageAssetsForEarlyHintsHeader;
|
|
4
|
-
const globalContext_js_1 = require("../../globalContext.js");
|
|
5
4
|
const utils_js_1 = require("../../utils.js");
|
|
6
|
-
function sortPageAssetsForEarlyHintsHeader(pageAssets) {
|
|
7
|
-
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
5
|
+
async function sortPageAssetsForEarlyHintsHeader(pageAssets, isProduction) {
|
|
8
6
|
pageAssets.sort((0, utils_js_1.higherFirst)(({ assetType }) => {
|
|
9
7
|
// In dev, we load scripts first in order to parallelize I/O and CPU
|
|
10
|
-
if (!
|
|
8
|
+
if (!isProduction && assetType === 'script') {
|
|
11
9
|
return 1;
|
|
12
10
|
}
|
|
13
11
|
let priority = 0;
|
|
@@ -8,13 +8,13 @@ const retrieveAssetsProd_js_1 = require("./getPageAssets/retrieveAssetsProd.js")
|
|
|
8
8
|
const inferMediaType_js_1 = require("./inferMediaType.js");
|
|
9
9
|
const getManifestEntry_js_1 = require("./getPageAssets/getManifestEntry.js");
|
|
10
10
|
const sortPageAssetsForEarlyHintsHeader_js_1 = require("./getPageAssets/sortPageAssetsForEarlyHintsHeader.js");
|
|
11
|
-
const globalContext_js_1 = require("../globalContext.js");
|
|
12
11
|
const globalObject = (0, utils_js_1.getGlobalObject)('getPageAssets.ts', {
|
|
13
12
|
resolveClientEntriesDev: null
|
|
14
13
|
});
|
|
15
14
|
async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
16
|
-
const globalContext =
|
|
17
|
-
const
|
|
15
|
+
const globalContext = pageContext._globalContext;
|
|
16
|
+
const { isProduction } = globalContext;
|
|
17
|
+
const isDev = !isProduction;
|
|
18
18
|
let assetUrls;
|
|
19
19
|
let clientEntriesSrc;
|
|
20
20
|
if (isDev) {
|
|
@@ -57,7 +57,7 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
57
57
|
pageAsset.src = (0, utils_js_1.prependBase)((0, utils_js_1.toPosixPath)(pageAsset.src), baseServerAssets);
|
|
58
58
|
return pageAsset;
|
|
59
59
|
});
|
|
60
|
-
(0, sortPageAssetsForEarlyHintsHeader_js_1.sortPageAssetsForEarlyHintsHeader)(pageAssets);
|
|
60
|
+
await (0, sortPageAssetsForEarlyHintsHeader_js_1.sortPageAssetsForEarlyHintsHeader)(pageAssets, isProduction);
|
|
61
61
|
return pageAssets;
|
|
62
62
|
}
|
|
63
63
|
function resolveClientEntriesProd(clientEntry, assetsManifest) {
|