vike 0.4.191-commit-349a3eb → 0.4.191-commit-f6d8845
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 +14 -6
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +5 -2
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +5 -0
- package/dist/cjs/node/prerender/runPrerender.js +4 -5
- package/dist/cjs/node/runtime/globalContext.js +76 -26
- package/dist/cjs/node/runtime/renderPage.js +3 -3
- package/dist/cjs/node/runtime/utils.js +1 -0
- package/dist/cjs/shared/hooks/getHook.js +4 -6
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/genPromise.js +9 -0
- package/dist/esm/__internal/index.d.ts +7 -0
- package/dist/esm/__internal/index.js +15 -6
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +5 -2
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +7 -2
- package/dist/esm/node/prerender/runPrerender.js +7 -8
- package/dist/esm/node/runtime/globalContext.d.ts +12 -6
- package/dist/esm/node/runtime/globalContext.js +76 -26
- package/dist/esm/node/runtime/renderPage.js +4 -4
- package/dist/esm/node/runtime/utils.d.ts +1 -0
- package/dist/esm/node/runtime/utils.js +1 -0
- package/dist/esm/shared/hooks/getHook.d.ts +2 -2
- package/dist/esm/shared/hooks/getHook.js +3 -5
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/genPromise.d.ts +4 -0
- package/dist/esm/utils/genPromise.js +5 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPagesAndRoutes = exports.route = void 0;
|
|
3
|
+
exports.getPageFilesAllSafe = exports.getPagesAndRoutes = exports.route = void 0;
|
|
4
4
|
const index_js_1 = require("../shared/route/index.js");
|
|
5
|
+
const getPageFiles_js_1 = require("../shared/getPageFiles.js");
|
|
5
6
|
const globalContext_js_1 = require("../node/runtime/globalContext.js");
|
|
6
7
|
const assertNodeEnv_js_1 = require("../utils/assertNodeEnv.js");
|
|
7
|
-
const assert_js_1 = require("../utils/assert.js");
|
|
8
8
|
const renderPageAlreadyRouted_js_1 = require("../node/runtime/renderPage/renderPageAlreadyRouted.js");
|
|
9
9
|
/**
|
|
10
10
|
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel}
|
|
@@ -14,11 +14,10 @@ const renderPageAlreadyRouted_js_1 = require("../node/runtime/renderPage/renderP
|
|
|
14
14
|
*/
|
|
15
15
|
async function getPagesAndRoutes() {
|
|
16
16
|
(0, assertNodeEnv_js_1.handleNodeEnv_vitePluginVercel)();
|
|
17
|
-
await (0, globalContext_js_1.initGlobalContext)(true);
|
|
18
|
-
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
19
|
-
(0, assert_js_1.assert)(globalContext.isProduction === true);
|
|
20
17
|
const renderContext = await (0, renderPageAlreadyRouted_js_1.getRenderContext)();
|
|
21
|
-
const {
|
|
18
|
+
const {
|
|
19
|
+
//
|
|
20
|
+
pageRoutes, pageFilesAll, pageConfigs, allPageIds } = renderContext;
|
|
22
21
|
return {
|
|
23
22
|
pageRoutes,
|
|
24
23
|
pageFilesAll,
|
|
@@ -27,6 +26,15 @@ async function getPagesAndRoutes() {
|
|
|
27
26
|
};
|
|
28
27
|
}
|
|
29
28
|
exports.getPagesAndRoutes = getPagesAndRoutes;
|
|
29
|
+
// TODO: make it cleaner once the internal refactoring about global configs is done.
|
|
30
|
+
// Demo usage: https://github.com/vikejs/vike/pull/1823
|
|
31
|
+
async function getPageFilesAllSafe(isProduction) {
|
|
32
|
+
await (0, globalContext_js_1.initGlobalContext_getGlobalContextAsync)(isProduction);
|
|
33
|
+
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
34
|
+
const pageFilesAll = await (0, getPageFiles_js_1.getPageFilesAll)(false, globalContext.isProduction);
|
|
35
|
+
return pageFilesAll;
|
|
36
|
+
}
|
|
37
|
+
exports.getPageFilesAllSafe = getPageFilesAllSafe;
|
|
30
38
|
async function route(pageContext) {
|
|
31
39
|
const pageContextFromRoute = await (0, index_js_1.route)(pageContext);
|
|
32
40
|
// Old interface
|
|
@@ -100,7 +100,7 @@ async function triggerFullBuild(config, configVike, bundle) {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
function abortViteBuildSsr(configVike) {
|
|
103
|
-
if (
|
|
103
|
+
if (configVike.disableAutoFullBuild !== true && (0, isViteCliCall_js_1.isViteCliCall)() && (0, isViteCliCall_js_1.getViteConfigFromCli)()?.build.ssr) {
|
|
104
104
|
(0, utils_js_1.assertWarning)(false, `The CLI call ${picocolors_1.default.cyan('$ vite build --ssr')} is superfluous since ${picocolors_1.default.cyan('$ vite build')} also builds the server-side. If you want two separate build steps then use https://vike.dev/disableAutoFullBuild or use Vite's ${picocolors_1.default.cyan('build()')} API.`, { onlyOnce: true });
|
|
105
105
|
process.exit(0);
|
|
106
106
|
}
|
|
@@ -108,7 +108,10 @@ function abortViteBuildSsr(configVike) {
|
|
|
108
108
|
function isDisabled(configVike) {
|
|
109
109
|
const { disableAutoFullBuild } = configVike;
|
|
110
110
|
if (disableAutoFullBuild === null || disableAutoFullBuild === 'prerender') {
|
|
111
|
-
// TODO/v1-release:
|
|
111
|
+
// TODO/v1-release: remove autoFullBuild for both Vite's build() API and Vite's CLI
|
|
112
|
+
// - Tell users to use `$ vike build` instead of `$ vite build`
|
|
113
|
+
// - Remove the whole writeBundle() hook logic
|
|
114
|
+
// - make `$ vite build` only build the client-side
|
|
112
115
|
return !(0, isViteCliCall_js_1.isViteCliCall)();
|
|
113
116
|
}
|
|
114
117
|
else {
|
|
@@ -18,6 +18,11 @@ function setGlobalContext() {
|
|
|
18
18
|
const isDev = (0, utils_js_1.isDev3)(env);
|
|
19
19
|
(0, globalContext_js_1.setGlobalContext_isDev)(isDev);
|
|
20
20
|
}
|
|
21
|
+
},
|
|
22
|
+
configResolved(config) {
|
|
23
|
+
const { outDirRoot } = (0, utils_js_1.getOutDirs)(config);
|
|
24
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(outDirRoot); // Needed for loadImportBuild(outDir) of @brillout/vite-plugin-server-entry
|
|
25
|
+
(0, globalContext_js_1.setGlobalContext_viteConfig)(config, outDirRoot);
|
|
21
26
|
}
|
|
22
27
|
};
|
|
23
28
|
}
|
|
@@ -83,7 +83,8 @@ async function runPrerenderFromAutoFullBuild(options) {
|
|
|
83
83
|
exports.runPrerenderFromAutoFullBuild = runPrerenderFromAutoFullBuild;
|
|
84
84
|
async function runPrerender(options, manuallyTriggered) {
|
|
85
85
|
checkOutdatedOptions(options);
|
|
86
|
-
(0,
|
|
86
|
+
(0, globalContext_js_1.setGlobalContext_isPrerendering)();
|
|
87
|
+
(0, getHook_js_1.getHook_setIsPrerenderering)();
|
|
87
88
|
const logLevel = !!options.onPagePrerender ? 'warn' : 'info';
|
|
88
89
|
if (logLevel === 'info') {
|
|
89
90
|
console.log(`${picocolors_1.default.cyan(`vike v${utils_js_1.projectInfo.projectVersion}`)} ${picocolors_1.default.green('pre-rendering HTML...')}`);
|
|
@@ -91,10 +92,9 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
91
92
|
(0, utils_js_1.handleNodeEnv_prerender)();
|
|
92
93
|
await disableReactStreaming();
|
|
93
94
|
const viteConfig = await (0, vite_1.resolveConfig)(options.viteConfig || {}, 'vike pre-rendering', 'production');
|
|
94
|
-
(0, globalContext_js_1.setGlobalContext_prerender)(viteConfig);
|
|
95
95
|
assertLoadedConfig(viteConfig, options);
|
|
96
96
|
const configVike = await (0, getConfigVike_js_1.getConfigVike)(viteConfig);
|
|
97
|
-
const { outDirClient
|
|
97
|
+
const { outDirClient } = (0, utils_js_1.getOutDirs)(viteConfig);
|
|
98
98
|
const { root } = viteConfig;
|
|
99
99
|
const prerenderConfig = configVike.prerender;
|
|
100
100
|
if (!prerenderConfig) {
|
|
@@ -105,8 +105,7 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
105
105
|
}
|
|
106
106
|
const { partial = false, noExtraDir = false, parallel = true } = prerenderConfig || {};
|
|
107
107
|
const concurrencyLimit = (0, utils_js_1.pLimit)(parallel === false || parallel === 0 ? 1 : parallel === true || parallel === undefined ? (0, os_1.cpus)().length : parallel);
|
|
108
|
-
(0,
|
|
109
|
-
await (0, globalContext_js_1.initGlobalContext)(true, outDirRoot);
|
|
108
|
+
await (0, globalContext_js_1.initGlobalContext_runPrerender)();
|
|
110
109
|
const renderContext = await (0, renderPageAlreadyRouted_js_1.getRenderContext)();
|
|
111
110
|
renderContext.pageFilesAll.forEach(assertExportNames);
|
|
112
111
|
const prerenderContext = {};
|
|
@@ -3,7 +3,7 @@ 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.
|
|
6
|
+
exports.setGlobalContext_isPrerendering = exports.setGlobalContext_isDev = exports.setGlobalContext_viteConfig = exports.setGlobalContext_viteDevServer = exports.initGlobalContext_getGlobalContextAsync = exports.initGlobalContext_runPrerender = exports.initGlobalContext_renderPage = exports.getRuntimeManifest = exports.getViteConfig = exports.getViteDevServer = exports.getGlobalContext = exports.getGlobalContextAsync = exports.getGlobalContextSync = void 0;
|
|
7
7
|
const utils_js_1 = require("./utils.js");
|
|
8
8
|
const loadImportBuild_js_1 = require("./globalContext/loadImportBuild.js");
|
|
9
9
|
const getPageFiles_js_1 = require("../../shared/getPageFiles.js");
|
|
@@ -12,10 +12,13 @@ const getConfigVike_js_1 = require("../shared/getConfigVike.js");
|
|
|
12
12
|
const assertRuntimeManifest_js_1 = require("../shared/assertRuntimeManifest.js");
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
14
|
const getPageFilesExports_js_1 = require("./page-files/getPageFilesExports.js");
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const globalObject = (0, utils_js_1.getGlobalObject)('globalContext.ts', (() => {
|
|
16
|
+
const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = (0, utils_js_1.genPromise)();
|
|
17
|
+
return {
|
|
18
|
+
viteDevServerPromise,
|
|
19
|
+
viteDevServerPromiseResolve
|
|
20
|
+
};
|
|
21
|
+
})());
|
|
19
22
|
function getGlobalContext() {
|
|
20
23
|
(0, utils_js_1.assert)(globalObject.globalContext);
|
|
21
24
|
return globalObject.globalContext;
|
|
@@ -28,10 +31,12 @@ function getGlobalContextSync() {
|
|
|
28
31
|
}
|
|
29
32
|
exports.getGlobalContextSync = getGlobalContextSync;
|
|
30
33
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
31
|
-
async function getGlobalContextAsync() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
async function getGlobalContextAsync(isProduction) {
|
|
35
|
+
(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')}`}`);
|
|
36
|
+
await initGlobalContext_getGlobalContextAsync(isProduction);
|
|
37
|
+
const { globalContext } = globalObject;
|
|
38
|
+
(0, utils_js_1.assert)(globalContext);
|
|
39
|
+
return makePublic(globalContext);
|
|
35
40
|
}
|
|
36
41
|
exports.getGlobalContextAsync = getGlobalContextAsync;
|
|
37
42
|
function makePublic(globalContext) {
|
|
@@ -61,40 +66,87 @@ function makePublic(globalContext) {
|
|
|
61
66
|
function setGlobalContext_viteDevServer(viteDevServer) {
|
|
62
67
|
if (globalObject.viteDevServer)
|
|
63
68
|
return;
|
|
64
|
-
(
|
|
65
|
-
globalObject.viteConfig
|
|
69
|
+
assertIsNotInitilizedYet();
|
|
70
|
+
(0, utils_js_1.assert)(globalObject.viteConfig);
|
|
66
71
|
globalObject.viteDevServer = viteDevServer;
|
|
72
|
+
globalObject.viteDevServerPromiseResolve(viteDevServer);
|
|
67
73
|
eagerlyLoadUserFiles();
|
|
68
74
|
}
|
|
69
75
|
exports.setGlobalContext_viteDevServer = setGlobalContext_viteDevServer;
|
|
76
|
+
function setGlobalContext_viteConfig(viteConfig, outDirRoot) {
|
|
77
|
+
if (globalObject.viteConfig)
|
|
78
|
+
return;
|
|
79
|
+
assertIsNotInitilizedYet();
|
|
80
|
+
globalObject.viteConfig = viteConfig;
|
|
81
|
+
globalObject.outDirRoot = outDirRoot;
|
|
82
|
+
}
|
|
83
|
+
exports.setGlobalContext_viteConfig = setGlobalContext_viteConfig;
|
|
84
|
+
function assertIsNotInitilizedYet() {
|
|
85
|
+
// In develpoment, globalObject.viteDevServer always needs to be awaited for before initializing globalObject.globalContext
|
|
86
|
+
(0, utils_js_1.assert)(!globalObject.globalContext);
|
|
87
|
+
}
|
|
70
88
|
function setGlobalContext_isDev(isDev) {
|
|
71
89
|
globalObject.isDev = isDev;
|
|
72
90
|
}
|
|
73
91
|
exports.setGlobalContext_isDev = setGlobalContext_isDev;
|
|
92
|
+
function setGlobalContext_isPrerendering() {
|
|
93
|
+
globalObject.isPrerendering = true;
|
|
94
|
+
}
|
|
95
|
+
exports.setGlobalContext_isPrerendering = setGlobalContext_isPrerendering;
|
|
74
96
|
function getViteDevServer() {
|
|
75
97
|
return globalObject.viteDevServer ?? null;
|
|
76
98
|
}
|
|
77
99
|
exports.getViteDevServer = getViteDevServer;
|
|
78
|
-
function setGlobalContext_prerender(viteConfig) {
|
|
79
|
-
if (globalObject.viteConfig)
|
|
80
|
-
return;
|
|
81
|
-
(0, utils_js_1.assert)(!globalObject.globalContext);
|
|
82
|
-
globalObject.viteConfig = viteConfig;
|
|
83
|
-
}
|
|
84
|
-
exports.setGlobalContext_prerender = setGlobalContext_prerender;
|
|
85
100
|
function getViteConfig() {
|
|
86
101
|
return globalObject.viteConfig ?? null;
|
|
87
102
|
}
|
|
88
103
|
exports.getViteConfig = getViteConfig;
|
|
89
|
-
async function
|
|
90
|
-
|
|
104
|
+
async function initGlobalContext_renderPage() {
|
|
105
|
+
await initGlobalContext(!globalObject.isDev);
|
|
106
|
+
}
|
|
107
|
+
exports.initGlobalContext_renderPage = initGlobalContext_renderPage;
|
|
108
|
+
async function initGlobalContext_runPrerender() {
|
|
109
|
+
if (globalObject.initGlobalContext_runPrerender_alreadyCalled)
|
|
91
110
|
return;
|
|
92
|
-
|
|
111
|
+
globalObject.initGlobalContext_runPrerender_alreadyCalled = true;
|
|
112
|
+
(0, utils_js_1.assert)(globalObject.isPrerendering);
|
|
113
|
+
(0, utils_js_1.assert)(globalObject.viteConfig);
|
|
114
|
+
(0, utils_js_1.assert)(globalObject.outDirRoot);
|
|
115
|
+
// We assume initGlobalContext_runPrerender() to be called before:
|
|
116
|
+
// - initGlobalContext_renderPage()
|
|
117
|
+
// - initGlobalContext_getGlobalContextAsync()
|
|
118
|
+
(0, utils_js_1.assert)(!globalObject.globalContext);
|
|
119
|
+
await initGlobalContext(true);
|
|
120
|
+
}
|
|
121
|
+
exports.initGlobalContext_runPrerender = initGlobalContext_runPrerender;
|
|
122
|
+
async function initGlobalContext_getGlobalContextAsync(isProduction) {
|
|
123
|
+
if (!isProduction) {
|
|
124
|
+
const waitFor = 20;
|
|
125
|
+
const timeout = setTimeout(() => {
|
|
126
|
+
(0, utils_js_1.assertWarning)(false, `Vite's development server still not created after ${waitFor} seconds.`, {
|
|
127
|
+
onlyOnce: false,
|
|
128
|
+
showStackTrace: true
|
|
129
|
+
});
|
|
130
|
+
}, waitFor * 1000);
|
|
131
|
+
await globalObject.viteDevServerPromise;
|
|
132
|
+
clearTimeout(timeout);
|
|
133
|
+
}
|
|
134
|
+
await initGlobalContext(isProduction);
|
|
135
|
+
}
|
|
136
|
+
exports.initGlobalContext_getGlobalContextAsync = initGlobalContext_getGlobalContextAsync;
|
|
137
|
+
async function initGlobalContext(isProduction) {
|
|
138
|
+
if (globalObject.globalContext) {
|
|
139
|
+
(0, utils_js_1.assert)(globalObject.globalContext.isProduction === isProduction);
|
|
140
|
+
// We assume setGlobalContext_isPrerendering() is called before initGlobalContext()
|
|
141
|
+
(0, utils_js_1.assert)(globalObject.globalContext.isPrerendering === (globalObject.isPrerendering ?? false));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const { viteDevServer, viteConfig, isDev, isPrerendering } = globalObject;
|
|
93
145
|
(0, utils_js_1.assertNodeEnv_runtime)(isDev ?? false);
|
|
94
|
-
if (
|
|
146
|
+
if (!isProduction) {
|
|
95
147
|
(0, utils_js_1.assert)(viteConfig);
|
|
96
|
-
(0, utils_js_1.assert)(!isPrerendering);
|
|
97
148
|
(0, utils_js_1.assert)(viteDevServer);
|
|
149
|
+
(0, utils_js_1.assert)(!isPrerendering);
|
|
98
150
|
const configVike = await (0, getConfigVike_js_1.getConfigVike)(viteConfig);
|
|
99
151
|
const pluginManifest = getRuntimeManifest(configVike);
|
|
100
152
|
globalObject.globalContext = {
|
|
@@ -113,7 +165,7 @@ async function initGlobalContext(isPrerendering = false, outDir) {
|
|
|
113
165
|
};
|
|
114
166
|
}
|
|
115
167
|
else {
|
|
116
|
-
const buildEntries = await (0, loadImportBuild_js_1.loadImportBuild)(
|
|
168
|
+
const buildEntries = await (0, loadImportBuild_js_1.loadImportBuild)(globalObject.outDirRoot);
|
|
117
169
|
assertBuildEntries(buildEntries, isPrerendering ?? false);
|
|
118
170
|
const { pageFiles, assetsManifest, pluginManifest } = buildEntries;
|
|
119
171
|
(0, getPageFiles_js_1.setPageFiles)(pageFiles);
|
|
@@ -149,9 +201,7 @@ async function initGlobalContext(isPrerendering = false, outDir) {
|
|
|
149
201
|
globalObject.globalContext = globalContext;
|
|
150
202
|
}
|
|
151
203
|
}
|
|
152
|
-
resolveGlobalContext(globalObject.globalContext);
|
|
153
204
|
}
|
|
154
|
-
exports.initGlobalContext = initGlobalContext;
|
|
155
205
|
function getRuntimeManifest(configVike) {
|
|
156
206
|
const { includeAssetsImportedByServer, baseServer, baseAssets, redirects, trailingSlash, disableUrlNormalization } = configVike;
|
|
157
207
|
const manifest = {
|
|
@@ -67,12 +67,12 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
67
67
|
// Prepare context
|
|
68
68
|
let renderContext;
|
|
69
69
|
try {
|
|
70
|
-
await (0, globalContext_js_1.
|
|
70
|
+
await (0, globalContext_js_1.initGlobalContext_renderPage)();
|
|
71
71
|
renderContext = await (0, renderPageAlreadyRouted_js_1.getRenderContext)();
|
|
72
72
|
}
|
|
73
73
|
catch (err) {
|
|
74
|
-
// Errors are expected since assertUsage() is used in both
|
|
75
|
-
//
|
|
74
|
+
// Errors are expected since assertUsage() is used in both initGlobalContext_renderPage() and getRenderContext().
|
|
75
|
+
// initGlobalContext_renderPage() and getRenderContext() don't call any user hooks => err isn't thrown from user code.
|
|
76
76
|
(0, utils_js_1.assert)(!(0, abort_js_1.isAbortError)(err));
|
|
77
77
|
(0, loggerRuntime_js_1.logRuntimeError)(err, httpRequestId);
|
|
78
78
|
const pageContextHttpResponseNull = getPageContextHttpResponseNullWithError(err, pageContextInit);
|
|
@@ -75,3 +75,4 @@ __exportStar(require("../../utils/normalizeHeaders.js"), exports);
|
|
|
75
75
|
__exportStar(require("../../utils/isVikeReactApp.js"), exports);
|
|
76
76
|
__exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
77
77
|
__exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
78
|
+
__exportStar(require("../../utils/genPromise.js"), exports);
|
|
@@ -3,15 +3,13 @@ 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.getHookTimeoutDefault = exports.
|
|
6
|
+
exports.getHookTimeoutDefault = exports.getHook_setIsPrerenderering = exports.assertHook = exports.getHookFromPageConfigGlobal = exports.getHookFromPageConfig = exports.getHook = void 0;
|
|
7
7
|
const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
|
|
8
8
|
const helpers_js_1 = require("../page-configs/helpers.js");
|
|
9
9
|
const getConfigValue_js_1 = require("../page-configs/getConfigValue.js");
|
|
10
10
|
const utils_js_1 = require("../utils.js");
|
|
11
11
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
12
|
-
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('getHook.ts', {
|
|
13
|
-
isPrerendering: false
|
|
14
|
-
});
|
|
12
|
+
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('getHook.ts', {});
|
|
15
13
|
function getHook(pageContext, hookName) {
|
|
16
14
|
if (!(hookName in pageContext.exports)) {
|
|
17
15
|
return null;
|
|
@@ -133,7 +131,7 @@ function getHookTimeoutDefault(hookName) {
|
|
|
133
131
|
};
|
|
134
132
|
}
|
|
135
133
|
exports.getHookTimeoutDefault = getHookTimeoutDefault;
|
|
136
|
-
function
|
|
134
|
+
function getHook_setIsPrerenderering() {
|
|
137
135
|
globalObject.isPrerendering = true;
|
|
138
136
|
}
|
|
139
|
-
exports.
|
|
137
|
+
exports.getHook_setIsPrerenderering = getHook_setIsPrerenderering;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genPromise = void 0;
|
|
4
|
+
function genPromise() {
|
|
5
|
+
let resolve;
|
|
6
|
+
const promise = new Promise((r) => (resolve = r));
|
|
7
|
+
return { promise, resolve };
|
|
8
|
+
}
|
|
9
|
+
exports.genPromise = genPromise;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { route, getPagesAndRoutes };
|
|
2
2
|
export type { PageRoutes, PageFile, PageConfigRuntime as PageConfig };
|
|
3
|
+
export { getPageFilesAllSafe };
|
|
3
4
|
import { route as routeInternal, type PageRoutes } from '../shared/route/index.js';
|
|
4
5
|
import { type PageFile } from '../shared/getPageFiles.js';
|
|
5
6
|
import { PageConfigRuntime } from '../shared/page-configs/PageConfig.js';
|
|
@@ -15,6 +16,12 @@ declare function getPagesAndRoutes(): Promise<{
|
|
|
15
16
|
pageConfigs: PageConfigRuntime[];
|
|
16
17
|
allPageIds: string[];
|
|
17
18
|
}>;
|
|
19
|
+
declare function getPageFilesAllSafe(isProduction: boolean): Promise<{
|
|
20
|
+
pageFilesAll: PageFile[];
|
|
21
|
+
allPageIds: string[];
|
|
22
|
+
pageConfigs: PageConfigRuntime[];
|
|
23
|
+
pageConfigGlobal: import("../shared/page-configs/PageConfig.js").PageConfigGlobalRuntime;
|
|
24
|
+
}>;
|
|
18
25
|
declare function route(pageContext: Parameters<typeof routeInternal>[0]): Promise<{
|
|
19
26
|
pageContextAddendum: import("../shared/route/index.js").PageContextFromRoute;
|
|
20
27
|
}>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// Internals needed by vite-plugin-vercel
|
|
2
2
|
export { route, getPagesAndRoutes };
|
|
3
|
+
// Internals needed by nitedani's experimental implementation of vike-telefunc
|
|
4
|
+
export { getPageFilesAllSafe };
|
|
3
5
|
import { route as routeInternal } from '../shared/route/index.js';
|
|
4
|
-
import {
|
|
6
|
+
import { getPageFilesAll } from '../shared/getPageFiles.js';
|
|
7
|
+
import { getGlobalContext, initGlobalContext_getGlobalContextAsync } from '../node/runtime/globalContext.js';
|
|
5
8
|
import { handleNodeEnv_vitePluginVercel } from '../utils/assertNodeEnv.js';
|
|
6
|
-
import { assert } from '../utils/assert.js';
|
|
7
9
|
import { getRenderContext } from '../node/runtime/renderPage/renderPageAlreadyRouted.js';
|
|
8
10
|
/**
|
|
9
11
|
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel}
|
|
@@ -13,11 +15,10 @@ import { getRenderContext } from '../node/runtime/renderPage/renderPageAlreadyRo
|
|
|
13
15
|
*/
|
|
14
16
|
async function getPagesAndRoutes() {
|
|
15
17
|
handleNodeEnv_vitePluginVercel();
|
|
16
|
-
await initGlobalContext(true);
|
|
17
|
-
const globalContext = getGlobalContext();
|
|
18
|
-
assert(globalContext.isProduction === true);
|
|
19
18
|
const renderContext = await getRenderContext();
|
|
20
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
//
|
|
21
|
+
pageRoutes, pageFilesAll, pageConfigs, allPageIds } = renderContext;
|
|
21
22
|
return {
|
|
22
23
|
pageRoutes,
|
|
23
24
|
pageFilesAll,
|
|
@@ -25,6 +26,14 @@ async function getPagesAndRoutes() {
|
|
|
25
26
|
allPageIds
|
|
26
27
|
};
|
|
27
28
|
}
|
|
29
|
+
// TODO: make it cleaner once the internal refactoring about global configs is done.
|
|
30
|
+
// Demo usage: https://github.com/vikejs/vike/pull/1823
|
|
31
|
+
async function getPageFilesAllSafe(isProduction) {
|
|
32
|
+
await initGlobalContext_getGlobalContextAsync(isProduction);
|
|
33
|
+
const globalContext = getGlobalContext();
|
|
34
|
+
const pageFilesAll = await getPageFilesAll(false, globalContext.isProduction);
|
|
35
|
+
return pageFilesAll;
|
|
36
|
+
}
|
|
28
37
|
async function route(pageContext) {
|
|
29
38
|
const pageContextFromRoute = await routeInternal(pageContext);
|
|
30
39
|
// Old interface
|
|
@@ -94,7 +94,7 @@ async function triggerFullBuild(config, configVike, bundle) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
function abortViteBuildSsr(configVike) {
|
|
97
|
-
if (
|
|
97
|
+
if (configVike.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
|
|
98
98
|
assertWarning(false, `The CLI call ${pc.cyan('$ vite build --ssr')} is superfluous since ${pc.cyan('$ vite build')} also builds the server-side. If you want two separate build steps then use https://vike.dev/disableAutoFullBuild or use Vite's ${pc.cyan('build()')} API.`, { onlyOnce: true });
|
|
99
99
|
process.exit(0);
|
|
100
100
|
}
|
|
@@ -102,7 +102,10 @@ function abortViteBuildSsr(configVike) {
|
|
|
102
102
|
function isDisabled(configVike) {
|
|
103
103
|
const { disableAutoFullBuild } = configVike;
|
|
104
104
|
if (disableAutoFullBuild === null || disableAutoFullBuild === 'prerender') {
|
|
105
|
-
// TODO/v1-release:
|
|
105
|
+
// TODO/v1-release: remove autoFullBuild for both Vite's build() API and Vite's CLI
|
|
106
|
+
// - Tell users to use `$ vike build` instead of `$ vite build`
|
|
107
|
+
// - Remove the whole writeBundle() hook logic
|
|
108
|
+
// - make `$ vite build` only build the client-side
|
|
106
109
|
return !isViteCliCall();
|
|
107
110
|
}
|
|
108
111
|
else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { setGlobalContext };
|
|
2
|
-
import { setGlobalContext_isDev, setGlobalContext_viteDevServer } from '../../runtime/globalContext.js';
|
|
3
|
-
import { isDev3 } from '../utils.js';
|
|
2
|
+
import { setGlobalContext_isDev, setGlobalContext_viteDevServer, setGlobalContext_viteConfig } from '../../runtime/globalContext.js';
|
|
3
|
+
import { assertFilePathAbsoluteFilesystem, getOutDirs, isDev3 } from '../utils.js';
|
|
4
4
|
function setGlobalContext() {
|
|
5
5
|
return {
|
|
6
6
|
name: 'vike:setGlobalContext',
|
|
@@ -16,6 +16,11 @@ function setGlobalContext() {
|
|
|
16
16
|
const isDev = isDev3(env);
|
|
17
17
|
setGlobalContext_isDev(isDev);
|
|
18
18
|
}
|
|
19
|
+
},
|
|
20
|
+
configResolved(config) {
|
|
21
|
+
const { outDirRoot } = getOutDirs(config);
|
|
22
|
+
assertFilePathAbsoluteFilesystem(outDirRoot); // Needed for loadImportBuild(outDir) of @brillout/vite-plugin-server-entry
|
|
23
|
+
setGlobalContext_viteConfig(config, outDirRoot);
|
|
19
24
|
}
|
|
20
25
|
};
|
|
21
26
|
}
|
|
@@ -5,11 +5,11 @@ export { runPrerender_forceExit };
|
|
|
5
5
|
import '../runtime/page-files/setup.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { route } from '../../shared/route/index.js';
|
|
8
|
-
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject, handleNodeEnv_prerender, pLimit,
|
|
8
|
+
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject, handleNodeEnv_prerender, pLimit, isArray, changeEnumerable } from './utils.js';
|
|
9
9
|
import { prerenderPage, prerender404Page, getRenderContext, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { cpus } from 'os';
|
|
12
|
-
import { getGlobalContext,
|
|
12
|
+
import { getGlobalContext, initGlobalContext_runPrerender, setGlobalContext_isPrerendering } from '../runtime/globalContext.js';
|
|
13
13
|
import { resolveConfig } from 'vite';
|
|
14
14
|
import { getConfigVike } from '../shared/getConfigVike.js';
|
|
15
15
|
import { getPageFilesServerSide } from '../../shared/getPageFiles.js';
|
|
@@ -22,7 +22,7 @@ import { isErrorPage } from '../../shared/error-page.js';
|
|
|
22
22
|
import { getPageContextUrlComputed } from '../../shared/getPageContextUrlComputed.js';
|
|
23
23
|
import { isAbortError } from '../../shared/route/abort.js';
|
|
24
24
|
import { loadUserFilesServerSide } from '../runtime/renderPage/loadUserFilesServerSide.js';
|
|
25
|
-
import { getHookFromPageConfig, getHookFromPageConfigGlobal, getHookTimeoutDefault,
|
|
25
|
+
import { getHookFromPageConfig, getHookFromPageConfigGlobal, getHookTimeoutDefault, getHook_setIsPrerenderering } from '../../shared/hooks/getHook.js';
|
|
26
26
|
import { noRouteMatch } from '../../shared/route/noRouteMatch.js';
|
|
27
27
|
import { getVikeConfig } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
28
28
|
import { logErrorHint } from '../runtime/renderPage/logErrorHint.js';
|
|
@@ -55,7 +55,8 @@ async function runPrerenderFromAutoFullBuild(options) {
|
|
|
55
55
|
}
|
|
56
56
|
async function runPrerender(options, manuallyTriggered) {
|
|
57
57
|
checkOutdatedOptions(options);
|
|
58
|
-
|
|
58
|
+
setGlobalContext_isPrerendering();
|
|
59
|
+
getHook_setIsPrerenderering();
|
|
59
60
|
const logLevel = !!options.onPagePrerender ? 'warn' : 'info';
|
|
60
61
|
if (logLevel === 'info') {
|
|
61
62
|
console.log(`${pc.cyan(`vike v${projectInfo.projectVersion}`)} ${pc.green('pre-rendering HTML...')}`);
|
|
@@ -63,10 +64,9 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
63
64
|
handleNodeEnv_prerender();
|
|
64
65
|
await disableReactStreaming();
|
|
65
66
|
const viteConfig = await resolveConfig(options.viteConfig || {}, 'vike pre-rendering', 'production');
|
|
66
|
-
setGlobalContext_prerender(viteConfig);
|
|
67
67
|
assertLoadedConfig(viteConfig, options);
|
|
68
68
|
const configVike = await getConfigVike(viteConfig);
|
|
69
|
-
const { outDirClient
|
|
69
|
+
const { outDirClient } = getOutDirs(viteConfig);
|
|
70
70
|
const { root } = viteConfig;
|
|
71
71
|
const prerenderConfig = configVike.prerender;
|
|
72
72
|
if (!prerenderConfig) {
|
|
@@ -77,8 +77,7 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
77
77
|
}
|
|
78
78
|
const { partial = false, noExtraDir = false, parallel = true } = prerenderConfig || {};
|
|
79
79
|
const concurrencyLimit = pLimit(parallel === false || parallel === 0 ? 1 : parallel === true || parallel === undefined ? cpus().length : parallel);
|
|
80
|
-
|
|
81
|
-
await initGlobalContext(true, outDirRoot);
|
|
80
|
+
await initGlobalContext_runPrerender();
|
|
82
81
|
const renderContext = await getRenderContext();
|
|
83
82
|
renderContext.pageFilesAll.forEach(assertExportNames);
|
|
84
83
|
const prerenderContext = {};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
export { getGlobalContextSync };
|
|
2
2
|
export { getGlobalContextAsync };
|
|
3
|
-
export { initGlobalContext };
|
|
4
3
|
export { getGlobalContext };
|
|
5
4
|
export { getViteDevServer };
|
|
6
5
|
export { getViteConfig };
|
|
6
|
+
export { getRuntimeManifest };
|
|
7
|
+
export { initGlobalContext_renderPage };
|
|
8
|
+
export { initGlobalContext_runPrerender };
|
|
9
|
+
export { initGlobalContext_getGlobalContextAsync };
|
|
7
10
|
export { setGlobalContext_viteDevServer };
|
|
11
|
+
export { setGlobalContext_viteConfig };
|
|
8
12
|
export { setGlobalContext_isDev };
|
|
9
|
-
export {
|
|
10
|
-
export { getRuntimeManifest };
|
|
13
|
+
export { setGlobalContext_isPrerendering };
|
|
11
14
|
import type { ViteManifest } from '../shared/ViteManifest.js';
|
|
12
15
|
import type { ResolvedConfig, ViteDevServer } from 'vite';
|
|
13
16
|
import { PluginManifest } from '../shared/assertPluginManifest.js';
|
|
@@ -46,11 +49,14 @@ declare function getGlobalContext(): GlobalContext;
|
|
|
46
49
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
47
50
|
declare function getGlobalContextSync(): GlobalContextPublic;
|
|
48
51
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
49
|
-
declare function getGlobalContextAsync(): Promise<GlobalContextPublic>;
|
|
52
|
+
declare function getGlobalContextAsync(isProduction: boolean): Promise<GlobalContextPublic>;
|
|
50
53
|
declare function setGlobalContext_viteDevServer(viteDevServer: ViteDevServer): void;
|
|
54
|
+
declare function setGlobalContext_viteConfig(viteConfig: ResolvedConfig, outDirRoot: string): void;
|
|
51
55
|
declare function setGlobalContext_isDev(isDev: boolean): void;
|
|
56
|
+
declare function setGlobalContext_isPrerendering(): void;
|
|
52
57
|
declare function getViteDevServer(): ViteDevServer | null;
|
|
53
|
-
declare function setGlobalContext_prerender(viteConfig: ResolvedConfig): void;
|
|
54
58
|
declare function getViteConfig(): ResolvedConfig | null;
|
|
55
|
-
declare function
|
|
59
|
+
declare function initGlobalContext_renderPage(): Promise<void>;
|
|
60
|
+
declare function initGlobalContext_runPrerender(): Promise<void>;
|
|
61
|
+
declare function initGlobalContext_getGlobalContextAsync(isProduction: boolean): Promise<void>;
|
|
56
62
|
declare function getRuntimeManifest(configVike: ConfigVikeResolved): RuntimeManifest;
|
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
export { getGlobalContextSync };
|
|
3
3
|
export { getGlobalContextAsync };
|
|
4
4
|
// Internal use
|
|
5
|
-
export { initGlobalContext };
|
|
6
5
|
export { getGlobalContext };
|
|
7
6
|
export { getViteDevServer };
|
|
8
7
|
export { getViteConfig };
|
|
8
|
+
export { getRuntimeManifest };
|
|
9
|
+
export { initGlobalContext_renderPage };
|
|
10
|
+
export { initGlobalContext_runPrerender };
|
|
11
|
+
export { initGlobalContext_getGlobalContextAsync };
|
|
9
12
|
export { setGlobalContext_viteDevServer };
|
|
13
|
+
export { setGlobalContext_viteConfig };
|
|
10
14
|
export { setGlobalContext_isDev };
|
|
11
|
-
export {
|
|
12
|
-
|
|
13
|
-
import { assert, assertNodeEnv_runtime, assertUsage, assertWarning, getGlobalObject, isPlainObject, objectAssign, objectKeys } from './utils.js';
|
|
15
|
+
export { setGlobalContext_isPrerendering };
|
|
16
|
+
import { assert, assertNodeEnv_runtime, assertUsage, assertWarning, getGlobalObject, isPlainObject, objectAssign, objectKeys, genPromise } from './utils.js';
|
|
14
17
|
import { loadImportBuild } from './globalContext/loadImportBuild.js';
|
|
15
18
|
import { setPageFiles } from '../../shared/getPageFiles.js';
|
|
16
19
|
import { assertPluginManifest } from '../shared/assertPluginManifest.js';
|
|
@@ -18,10 +21,13 @@ import { getConfigVike } from '../shared/getConfigVike.js';
|
|
|
18
21
|
import { assertRuntimeManifest } from '../shared/assertRuntimeManifest.js';
|
|
19
22
|
import pc from '@brillout/picocolors';
|
|
20
23
|
import { getPageFilesExports } from './page-files/getPageFilesExports.js';
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
const globalObject = getGlobalObject('globalContext.ts', (() => {
|
|
25
|
+
const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = genPromise();
|
|
26
|
+
return {
|
|
27
|
+
viteDevServerPromise,
|
|
28
|
+
viteDevServerPromiseResolve
|
|
29
|
+
};
|
|
30
|
+
})());
|
|
25
31
|
function getGlobalContext() {
|
|
26
32
|
assert(globalObject.globalContext);
|
|
27
33
|
return globalObject.globalContext;
|
|
@@ -32,10 +38,12 @@ function getGlobalContextSync() {
|
|
|
32
38
|
return makePublic(globalObject.globalContext);
|
|
33
39
|
}
|
|
34
40
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
35
|
-
async function getGlobalContextAsync() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
async function getGlobalContextAsync(isProduction) {
|
|
42
|
+
assertUsage(typeof isProduction === 'boolean', `[getGlobalContextAsync(isProduction)] Argument ${pc.cyan('isProduction')} ${isProduction === undefined ? 'is missing' : `should be ${pc.cyan('true')} or ${pc.cyan('false')}`}`);
|
|
43
|
+
await initGlobalContext_getGlobalContextAsync(isProduction);
|
|
44
|
+
const { globalContext } = globalObject;
|
|
45
|
+
assert(globalContext);
|
|
46
|
+
return makePublic(globalContext);
|
|
39
47
|
}
|
|
40
48
|
function makePublic(globalContext) {
|
|
41
49
|
const globalContextPublic = {
|
|
@@ -64,35 +72,78 @@ function makePublic(globalContext) {
|
|
|
64
72
|
function setGlobalContext_viteDevServer(viteDevServer) {
|
|
65
73
|
if (globalObject.viteDevServer)
|
|
66
74
|
return;
|
|
67
|
-
|
|
68
|
-
globalObject.viteConfig
|
|
75
|
+
assertIsNotInitilizedYet();
|
|
76
|
+
assert(globalObject.viteConfig);
|
|
69
77
|
globalObject.viteDevServer = viteDevServer;
|
|
78
|
+
globalObject.viteDevServerPromiseResolve(viteDevServer);
|
|
70
79
|
eagerlyLoadUserFiles();
|
|
71
80
|
}
|
|
81
|
+
function setGlobalContext_viteConfig(viteConfig, outDirRoot) {
|
|
82
|
+
if (globalObject.viteConfig)
|
|
83
|
+
return;
|
|
84
|
+
assertIsNotInitilizedYet();
|
|
85
|
+
globalObject.viteConfig = viteConfig;
|
|
86
|
+
globalObject.outDirRoot = outDirRoot;
|
|
87
|
+
}
|
|
88
|
+
function assertIsNotInitilizedYet() {
|
|
89
|
+
// In develpoment, globalObject.viteDevServer always needs to be awaited for before initializing globalObject.globalContext
|
|
90
|
+
assert(!globalObject.globalContext);
|
|
91
|
+
}
|
|
72
92
|
function setGlobalContext_isDev(isDev) {
|
|
73
93
|
globalObject.isDev = isDev;
|
|
74
94
|
}
|
|
95
|
+
function setGlobalContext_isPrerendering() {
|
|
96
|
+
globalObject.isPrerendering = true;
|
|
97
|
+
}
|
|
75
98
|
function getViteDevServer() {
|
|
76
99
|
return globalObject.viteDevServer ?? null;
|
|
77
100
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
101
|
+
function getViteConfig() {
|
|
102
|
+
return globalObject.viteConfig ?? null;
|
|
103
|
+
}
|
|
104
|
+
async function initGlobalContext_renderPage() {
|
|
105
|
+
await initGlobalContext(!globalObject.isDev);
|
|
106
|
+
}
|
|
107
|
+
async function initGlobalContext_runPrerender() {
|
|
108
|
+
if (globalObject.initGlobalContext_runPrerender_alreadyCalled)
|
|
80
109
|
return;
|
|
110
|
+
globalObject.initGlobalContext_runPrerender_alreadyCalled = true;
|
|
111
|
+
assert(globalObject.isPrerendering);
|
|
112
|
+
assert(globalObject.viteConfig);
|
|
113
|
+
assert(globalObject.outDirRoot);
|
|
114
|
+
// We assume initGlobalContext_runPrerender() to be called before:
|
|
115
|
+
// - initGlobalContext_renderPage()
|
|
116
|
+
// - initGlobalContext_getGlobalContextAsync()
|
|
81
117
|
assert(!globalObject.globalContext);
|
|
82
|
-
|
|
118
|
+
await initGlobalContext(true);
|
|
83
119
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
120
|
+
async function initGlobalContext_getGlobalContextAsync(isProduction) {
|
|
121
|
+
if (!isProduction) {
|
|
122
|
+
const waitFor = 20;
|
|
123
|
+
const timeout = setTimeout(() => {
|
|
124
|
+
assertWarning(false, `Vite's development server still not created after ${waitFor} seconds.`, {
|
|
125
|
+
onlyOnce: false,
|
|
126
|
+
showStackTrace: true
|
|
127
|
+
});
|
|
128
|
+
}, waitFor * 1000);
|
|
129
|
+
await globalObject.viteDevServerPromise;
|
|
130
|
+
clearTimeout(timeout);
|
|
131
|
+
}
|
|
132
|
+
await initGlobalContext(isProduction);
|
|
86
133
|
}
|
|
87
|
-
async function initGlobalContext(
|
|
88
|
-
if (globalObject.globalContext)
|
|
134
|
+
async function initGlobalContext(isProduction) {
|
|
135
|
+
if (globalObject.globalContext) {
|
|
136
|
+
assert(globalObject.globalContext.isProduction === isProduction);
|
|
137
|
+
// We assume setGlobalContext_isPrerendering() is called before initGlobalContext()
|
|
138
|
+
assert(globalObject.globalContext.isPrerendering === (globalObject.isPrerendering ?? false));
|
|
89
139
|
return;
|
|
90
|
-
|
|
140
|
+
}
|
|
141
|
+
const { viteDevServer, viteConfig, isDev, isPrerendering } = globalObject;
|
|
91
142
|
assertNodeEnv_runtime(isDev ?? false);
|
|
92
|
-
if (
|
|
143
|
+
if (!isProduction) {
|
|
93
144
|
assert(viteConfig);
|
|
94
|
-
assert(!isPrerendering);
|
|
95
145
|
assert(viteDevServer);
|
|
146
|
+
assert(!isPrerendering);
|
|
96
147
|
const configVike = await getConfigVike(viteConfig);
|
|
97
148
|
const pluginManifest = getRuntimeManifest(configVike);
|
|
98
149
|
globalObject.globalContext = {
|
|
@@ -111,7 +162,7 @@ async function initGlobalContext(isPrerendering = false, outDir) {
|
|
|
111
162
|
};
|
|
112
163
|
}
|
|
113
164
|
else {
|
|
114
|
-
const buildEntries = await loadImportBuild(
|
|
165
|
+
const buildEntries = await loadImportBuild(globalObject.outDirRoot);
|
|
115
166
|
assertBuildEntries(buildEntries, isPrerendering ?? false);
|
|
116
167
|
const { pageFiles, assetsManifest, pluginManifest } = buildEntries;
|
|
117
168
|
setPageFiles(pageFiles);
|
|
@@ -147,7 +198,6 @@ async function initGlobalContext(isPrerendering = false, outDir) {
|
|
|
147
198
|
globalObject.globalContext = globalContext;
|
|
148
199
|
}
|
|
149
200
|
}
|
|
150
|
-
resolveGlobalContext(globalObject.globalContext);
|
|
151
201
|
}
|
|
152
202
|
function getRuntimeManifest(configVike) {
|
|
153
203
|
const { includeAssetsImportedByServer, baseServer, baseAssets, redirects, trailingSlash, disableUrlNormalization } = configVike;
|
|
@@ -4,7 +4,7 @@ import { getRenderContext, getPageContextInitEnhanced, renderPageAlreadyRouted }
|
|
|
4
4
|
import { route } from '../../shared/route/index.js';
|
|
5
5
|
import { assert, hasProp, objectAssign, isUrl, parseUrl, assertEnv, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, addUrlOrigin, createUrlFromComponents, isUri } from './utils.js';
|
|
6
6
|
import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError, logAbortErrorHandled } from '../../shared/route/abort.js';
|
|
7
|
-
import { getGlobalContext,
|
|
7
|
+
import { getGlobalContext, initGlobalContext_renderPage } from './globalContext.js';
|
|
8
8
|
import { handlePageContextRequestUrl } from './renderPage/handlePageContextRequestUrl.js';
|
|
9
9
|
import { createHttpResponseObjectRedirect, createHttpResponsePageContextJson } from './renderPage/createHttpResponseObject.js';
|
|
10
10
|
import { logRuntimeError, logRuntimeInfo } from './renderPage/loggerRuntime.js';
|
|
@@ -61,12 +61,12 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
61
61
|
// Prepare context
|
|
62
62
|
let renderContext;
|
|
63
63
|
try {
|
|
64
|
-
await
|
|
64
|
+
await initGlobalContext_renderPage();
|
|
65
65
|
renderContext = await getRenderContext();
|
|
66
66
|
}
|
|
67
67
|
catch (err) {
|
|
68
|
-
// Errors are expected since assertUsage() is used in both
|
|
69
|
-
//
|
|
68
|
+
// Errors are expected since assertUsage() is used in both initGlobalContext_renderPage() and getRenderContext().
|
|
69
|
+
// initGlobalContext_renderPage() and getRenderContext() don't call any user hooks => err isn't thrown from user code.
|
|
70
70
|
assert(!isAbortError(err));
|
|
71
71
|
logRuntimeError(err, httpRequestId);
|
|
72
72
|
const pageContextHttpResponseNull = getPageContextHttpResponseNullWithError(err, pageContextInit);
|
|
@@ -2,7 +2,7 @@ export { getHook };
|
|
|
2
2
|
export { getHookFromPageConfig };
|
|
3
3
|
export { getHookFromPageConfigGlobal };
|
|
4
4
|
export { assertHook };
|
|
5
|
-
export {
|
|
5
|
+
export { getHook_setIsPrerenderering };
|
|
6
6
|
export type { Hook };
|
|
7
7
|
export type { HookName };
|
|
8
8
|
export type { HookLoc };
|
|
@@ -33,4 +33,4 @@ declare function assertHook<TPageContext extends PageContextExports, THookName e
|
|
|
33
33
|
exports: Record<THookName, Function | undefined>;
|
|
34
34
|
};
|
|
35
35
|
declare function getHookTimeoutDefault(hookName: HookName): HookTimeout;
|
|
36
|
-
declare function
|
|
36
|
+
declare function getHook_setIsPrerenderering(): void;
|
|
@@ -2,7 +2,7 @@ export { getHook };
|
|
|
2
2
|
export { getHookFromPageConfig };
|
|
3
3
|
export { getHookFromPageConfigGlobal };
|
|
4
4
|
export { assertHook };
|
|
5
|
-
export {
|
|
5
|
+
export { getHook_setIsPrerenderering };
|
|
6
6
|
// TODO/v1-release: remove
|
|
7
7
|
// We export for old V0.4 design which doesn't support configooksTimeout
|
|
8
8
|
export { getHookTimeoutDefault };
|
|
@@ -11,9 +11,7 @@ import { getHookFilePathToShowToUser } from '../page-configs/helpers.js';
|
|
|
11
11
|
import { getConfigValueRuntime } from '../page-configs/getConfigValue.js';
|
|
12
12
|
import { assert, assertUsage, checkType, isCallable, isObject } from '../utils.js';
|
|
13
13
|
import pc from '@brillout/picocolors';
|
|
14
|
-
const globalObject = getGlobalObject('getHook.ts', {
|
|
15
|
-
isPrerendering: false
|
|
16
|
-
});
|
|
14
|
+
const globalObject = getGlobalObject('getHook.ts', {});
|
|
17
15
|
function getHook(pageContext, hookName) {
|
|
18
16
|
if (!(hookName in pageContext.exports)) {
|
|
19
17
|
return null;
|
|
@@ -130,6 +128,6 @@ function getHookTimeoutDefault(hookName) {
|
|
|
130
128
|
warning: 4 * 1000
|
|
131
129
|
};
|
|
132
130
|
}
|
|
133
|
-
function
|
|
131
|
+
function getHook_setIsPrerenderering() {
|
|
134
132
|
globalObject.isPrerendering = true;
|
|
135
133
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.191-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.191-commit-f6d8845";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.191-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.191-commit-f6d8845';
|