vike 0.4.191 → 0.4.192
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 +9 -5
- package/dist/cjs/node/plugin/plugins/config/assertVikeConfig.js +4 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +12 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +0 -3
- 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 +83 -26
- package/dist/cjs/node/runtime/html/stream.js +37 -24
- package/dist/cjs/node/runtime/page-files/getPageFilesExports.js +23 -0
- package/dist/cjs/node/runtime/page-files/setup.js +2 -20
- 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/shared/page-configs/serialize/serializeConfigValues.js +3 -1
- 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 +9 -5
- package/dist/esm/node/plugin/plugins/config/assertVikeConfig.js +4 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +8 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +12 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +0 -3
- 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 +83 -26
- package/dist/esm/node/runtime/html/stream.js +37 -24
- package/dist/esm/node/runtime/page-files/getPageFilesExports.d.ts +2 -0
- package/dist/esm/node/runtime/page-files/getPageFilesExports.js +20 -0
- package/dist/esm/node/runtime/page-files/setup.js +1 -19
- 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/ConfigVike.d.ts +3 -3
- package/dist/esm/shared/hooks/executeHook.d.ts +1 -1
- package/dist/esm/shared/hooks/getHook.d.ts +2 -2
- package/dist/esm/shared/hooks/getHook.js +3 -5
- package/dist/esm/shared/page-configs/PageConfig.d.ts +0 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +3 -1
- package/dist/esm/types/index.d.ts +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/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 +3 -3
|
@@ -17,7 +17,7 @@ const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
|
17
17
|
// - vike/shared/page-configs/serialize/parsePageConfigs.ts
|
|
18
18
|
// - parsePageConfigs() is loaded on both the client- and server-side.
|
|
19
19
|
(0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
|
|
20
|
-
function serializeConfigValues(pageConfig, importStatements, isEnvMatch, tabspace) {
|
|
20
|
+
function serializeConfigValues(pageConfig, importStatements, isEnvMatch, { isEager }, tabspace) {
|
|
21
21
|
const lines = [];
|
|
22
22
|
tabspace += ' ';
|
|
23
23
|
Object.entries(pageConfig.configValuesComputed ?? {}).forEach(([configName, configValuesComputed]) => {
|
|
@@ -36,6 +36,8 @@ function serializeConfigValues(pageConfig, importStatements, isEnvMatch, tabspac
|
|
|
36
36
|
Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
|
|
37
37
|
const configDef = pageConfig.configDefinitions[configName];
|
|
38
38
|
(0, utils_js_1.assert)(configDef);
|
|
39
|
+
if (isEager !== !!configDef.eager)
|
|
40
|
+
return;
|
|
39
41
|
if (!configDef.cumulative) {
|
|
40
42
|
const configValueSource = sources[0];
|
|
41
43
|
(0, utils_js_1.assert)(configValueSource);
|
|
@@ -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
|
|
@@ -88,23 +88,27 @@ async function triggerFullBuild(config, configVike, bundle) {
|
|
|
88
88
|
logErrorHint(err);
|
|
89
89
|
process.exit(1);
|
|
90
90
|
}
|
|
91
|
-
if (configVike.prerender && !configVike.prerender.disableAutoRun) {
|
|
91
|
+
if (configVike.prerender && !configVike.prerender.disableAutoRun && configVike.disableAutoFullBuild !== 'prerender') {
|
|
92
92
|
await runPrerenderFromAutoFullBuild({ viteConfig: configInline });
|
|
93
93
|
forceExit = true;
|
|
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
|
}
|
|
101
101
|
}
|
|
102
102
|
function isDisabled(configVike) {
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
const { disableAutoFullBuild } = configVike;
|
|
104
|
+
if (disableAutoFullBuild === null || disableAutoFullBuild === 'prerender') {
|
|
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
|
|
105
109
|
return !isViteCliCall();
|
|
106
110
|
}
|
|
107
111
|
else {
|
|
108
|
-
return
|
|
112
|
+
return disableAutoFullBuild;
|
|
109
113
|
}
|
|
110
114
|
}
|
|
@@ -27,8 +27,10 @@ function checkConfigVike(configVike) {
|
|
|
27
27
|
}
|
|
28
28
|
{
|
|
29
29
|
const prop = 'disableAutoFullBuild';
|
|
30
|
-
if (!hasProp(configVike, prop, 'boolean') &&
|
|
31
|
-
|
|
30
|
+
if (!hasProp(configVike, prop, 'boolean') &&
|
|
31
|
+
!hasProp(configVike, prop, 'undefined') &&
|
|
32
|
+
!(configVike[prop] === 'prerender'))
|
|
33
|
+
return { prop, errMsg: "should be a boolean or 'prerender'" };
|
|
32
34
|
}
|
|
33
35
|
{
|
|
34
36
|
const prop = 'includeAssetsImportedByServer';
|
|
@@ -31,6 +31,14 @@ type ConfigDefinition = {
|
|
|
31
31
|
* https://vike.dev/meta
|
|
32
32
|
*/
|
|
33
33
|
effect?: ConfigEffect;
|
|
34
|
+
/**
|
|
35
|
+
* Always load the configuration value, and as soon as possible.
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*
|
|
39
|
+
* https://vike.dev/meta
|
|
40
|
+
*/
|
|
41
|
+
eager?: boolean;
|
|
34
42
|
/**
|
|
35
43
|
* Whether the configuration always applies to all pages (no config inheritance).
|
|
36
44
|
*
|
|
@@ -32,7 +32,8 @@ const configDefinitionsBuiltIn = {
|
|
|
32
32
|
cumulative: true
|
|
33
33
|
},
|
|
34
34
|
route: {
|
|
35
|
-
env: { server: true, client: 'if-client-routing'
|
|
35
|
+
env: { server: true, client: 'if-client-routing' },
|
|
36
|
+
eager: true
|
|
36
37
|
},
|
|
37
38
|
guard: {
|
|
38
39
|
env: { server: true, client: 'if-client-routing' }
|
|
@@ -41,7 +42,8 @@ const configDefinitionsBuiltIn = {
|
|
|
41
42
|
env: { server: true }
|
|
42
43
|
},
|
|
43
44
|
iKnowThePerformanceRisksOfAsyncRouteFunctions: {
|
|
44
|
-
env: { server: true, client: 'if-client-routing'
|
|
45
|
+
env: { server: true, client: 'if-client-routing' },
|
|
46
|
+
eager: true
|
|
45
47
|
},
|
|
46
48
|
filesystemRoutingRoot: {
|
|
47
49
|
env: { config: true }
|
|
@@ -53,7 +55,8 @@ const configDefinitionsBuiltIn = {
|
|
|
53
55
|
},
|
|
54
56
|
clientRouting: {
|
|
55
57
|
// We could make it { client: false } but we don't yet because of some legacy V0.4 design code
|
|
56
|
-
env: { server: true, client: true, config: true
|
|
58
|
+
env: { server: true, client: true, config: true },
|
|
59
|
+
eager: true
|
|
57
60
|
},
|
|
58
61
|
clientHooks: {
|
|
59
62
|
env: { config: true }
|
|
@@ -74,7 +77,8 @@ const configDefinitionsBuiltIn = {
|
|
|
74
77
|
env: { config: true }
|
|
75
78
|
},
|
|
76
79
|
clientEntryLoaded: {
|
|
77
|
-
env: { server: true, client: true
|
|
80
|
+
env: { server: true, client: true },
|
|
81
|
+
eager: true,
|
|
78
82
|
_computed: (configValueSources) => {
|
|
79
83
|
{
|
|
80
84
|
const source = getConfigValueSource(configValueSources, 'clientHooks');
|
|
@@ -116,10 +120,12 @@ const configDefinitionsBuiltIn = {
|
|
|
116
120
|
};
|
|
117
121
|
const configDefinitionsBuiltInGlobal = {
|
|
118
122
|
onPrerenderStart: {
|
|
119
|
-
env: { server: true, production: true
|
|
123
|
+
env: { server: true, production: true },
|
|
124
|
+
eager: true
|
|
120
125
|
},
|
|
121
126
|
onBeforeRoute: {
|
|
122
|
-
env: { server: true, client: 'if-client-routing'
|
|
127
|
+
env: { server: true, client: 'if-client-routing' },
|
|
128
|
+
eager: true
|
|
123
129
|
},
|
|
124
130
|
prerender: {
|
|
125
131
|
env: { config: true }
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -32,7 +32,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
32
32
|
const importStatements = [];
|
|
33
33
|
const isClientRouting = getConfigValueBuildTime(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
34
34
|
lines.push('export const configValuesSerialized = {');
|
|
35
|
-
lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: false
|
|
35
|
+
lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), { isEager: false }, ''));
|
|
36
36
|
lines.push('};');
|
|
37
37
|
if (!fixServerAssets_isEnabled() && includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
38
38
|
importStatements.push(`import '${extractAssetsAddQuery(getVirtualFileIdPageConfigValuesAll(pageId, false))}'`);
|
|
@@ -32,7 +32,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
32
32
|
lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
|
|
33
33
|
lines.push(` loadConfigValuesAll: () => import(${JSON.stringify(virtualFileIdPageConfigValuesAll)}),`);
|
|
34
34
|
lines.push(` configValuesSerialized: {`);
|
|
35
|
-
lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true
|
|
35
|
+
lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), { isEager: true }, ' '));
|
|
36
36
|
lines.push(` },`);
|
|
37
37
|
lines.push(` },`);
|
|
38
38
|
});
|
|
@@ -42,7 +42,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
42
42
|
function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements) {
|
|
43
43
|
const lines = [];
|
|
44
44
|
lines.push(` configValuesSerialized: {`);
|
|
45
|
-
lines.push(...serializeConfigValues(pageConfigGlobal, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true
|
|
45
|
+
lines.push(...serializeConfigValues(pageConfigGlobal, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), { isEager: true }, ' '));
|
|
46
46
|
lines.push(` },`);
|
|
47
47
|
const code = lines.join('\n');
|
|
48
48
|
return code;
|
|
@@ -11,9 +11,6 @@ function isRuntimeEnvMatch(configEnv, runtime) {
|
|
|
11
11
|
if (configEnv.client === 'if-client-routing' && !runtime.isClientRouting)
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
|
-
// Eager
|
|
15
|
-
if (runtime.isEager !== !!configEnv.eager)
|
|
16
|
-
return false;
|
|
17
14
|
// Production/development
|
|
18
15
|
if (
|
|
19
16
|
//
|
|
@@ -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,25 +2,32 @@
|
|
|
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';
|
|
17
20
|
import { getConfigVike } from '../shared/getConfigVike.js';
|
|
18
21
|
import { assertRuntimeManifest } from '../shared/assertRuntimeManifest.js';
|
|
19
22
|
import pc from '@brillout/picocolors';
|
|
20
|
-
|
|
21
|
-
const globalObject = getGlobalObject('globalContext.ts', {
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
import { getPageFilesExports } from './page-files/getPageFilesExports.js';
|
|
24
|
+
const globalObject = getGlobalObject('globalContext.ts', (() => {
|
|
25
|
+
const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = genPromise();
|
|
26
|
+
return {
|
|
27
|
+
viteDevServerPromise,
|
|
28
|
+
viteDevServerPromiseResolve
|
|
29
|
+
};
|
|
30
|
+
})());
|
|
24
31
|
function getGlobalContext() {
|
|
25
32
|
assert(globalObject.globalContext);
|
|
26
33
|
return globalObject.globalContext;
|
|
@@ -31,10 +38,12 @@ function getGlobalContextSync() {
|
|
|
31
38
|
return makePublic(globalObject.globalContext);
|
|
32
39
|
}
|
|
33
40
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
34
|
-
async function getGlobalContextAsync() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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);
|
|
38
47
|
}
|
|
39
48
|
function makePublic(globalContext) {
|
|
40
49
|
const globalContextPublic = {
|
|
@@ -63,34 +72,78 @@ function makePublic(globalContext) {
|
|
|
63
72
|
function setGlobalContext_viteDevServer(viteDevServer) {
|
|
64
73
|
if (globalObject.viteDevServer)
|
|
65
74
|
return;
|
|
66
|
-
|
|
67
|
-
globalObject.viteConfig
|
|
75
|
+
assertIsNotInitilizedYet();
|
|
76
|
+
assert(globalObject.viteConfig);
|
|
68
77
|
globalObject.viteDevServer = viteDevServer;
|
|
78
|
+
globalObject.viteDevServerPromiseResolve(viteDevServer);
|
|
79
|
+
eagerlyLoadUserFiles();
|
|
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);
|
|
69
91
|
}
|
|
70
92
|
function setGlobalContext_isDev(isDev) {
|
|
71
93
|
globalObject.isDev = isDev;
|
|
72
94
|
}
|
|
95
|
+
function setGlobalContext_isPrerendering() {
|
|
96
|
+
globalObject.isPrerendering = true;
|
|
97
|
+
}
|
|
73
98
|
function getViteDevServer() {
|
|
74
99
|
return globalObject.viteDevServer ?? null;
|
|
75
100
|
}
|
|
76
|
-
function
|
|
77
|
-
|
|
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)
|
|
78
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()
|
|
79
117
|
assert(!globalObject.globalContext);
|
|
80
|
-
|
|
118
|
+
await initGlobalContext(true);
|
|
81
119
|
}
|
|
82
|
-
function
|
|
83
|
-
|
|
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);
|
|
84
133
|
}
|
|
85
|
-
async function initGlobalContext(
|
|
86
|
-
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));
|
|
87
139
|
return;
|
|
88
|
-
|
|
140
|
+
}
|
|
141
|
+
const { viteDevServer, viteConfig, isDev, isPrerendering } = globalObject;
|
|
89
142
|
assertNodeEnv_runtime(isDev ?? false);
|
|
90
|
-
if (
|
|
143
|
+
if (!isProduction) {
|
|
91
144
|
assert(viteConfig);
|
|
92
|
-
assert(!isPrerendering);
|
|
93
145
|
assert(viteDevServer);
|
|
146
|
+
assert(!isPrerendering);
|
|
94
147
|
const configVike = await getConfigVike(viteConfig);
|
|
95
148
|
const pluginManifest = getRuntimeManifest(configVike);
|
|
96
149
|
globalObject.globalContext = {
|
|
@@ -109,7 +162,7 @@ async function initGlobalContext(isPrerendering = false, outDir) {
|
|
|
109
162
|
};
|
|
110
163
|
}
|
|
111
164
|
else {
|
|
112
|
-
const buildEntries = await loadImportBuild(
|
|
165
|
+
const buildEntries = await loadImportBuild(globalObject.outDirRoot);
|
|
113
166
|
assertBuildEntries(buildEntries, isPrerendering ?? false);
|
|
114
167
|
const { pageFiles, assetsManifest, pluginManifest } = buildEntries;
|
|
115
168
|
setPageFiles(pageFiles);
|
|
@@ -145,7 +198,6 @@ async function initGlobalContext(isPrerendering = false, outDir) {
|
|
|
145
198
|
globalObject.globalContext = globalContext;
|
|
146
199
|
}
|
|
147
200
|
}
|
|
148
|
-
resolveGlobalContext(globalObject.globalContext);
|
|
149
201
|
}
|
|
150
202
|
function getRuntimeManifest(configVike) {
|
|
151
203
|
const { includeAssetsImportedByServer, baseServer, baseAssets, redirects, trailingSlash, disableUrlNormalization } = configVike;
|
|
@@ -182,3 +234,8 @@ function assertViteManifest(manifest) {
|
|
|
182
234
|
})
|
|
183
235
|
*/
|
|
184
236
|
}
|
|
237
|
+
function eagerlyLoadUserFiles() {
|
|
238
|
+
// Other than here, the getPageFilesExports() function is only called only upon calling the renderPage() function.
|
|
239
|
+
// We call it as early as possible here for better performance.
|
|
240
|
+
getPageFilesExports();
|
|
241
|
+
}
|