vike 0.4.191 → 0.4.193-commit-38002cb
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/buildConfig.js +2 -2
- package/dist/cjs/node/plugin/plugins/config/assertVikeConfig.js +4 -2
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +24 -14
- 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/loadImportBuild.js +2 -2
- 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/inferMediaType.js +3 -0
- 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/assertPlusFileExport.js +1 -2
- 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/cjs/utils/isArray.js +1 -1
- 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/buildConfig.js +3 -3
- package/dist/esm/node/plugin/plugins/config/assertVikeConfig.js +4 -2
- package/dist/esm/node/plugin/plugins/importBuild/index.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/index.js +22 -12
- 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/loadImportBuild.js +1 -1
- 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/inferMediaType.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/inferMediaType.js +3 -0
- 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/assertPlusFileExport.js +1 -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/isArray.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +67 -67
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPageFilesExports = void 0;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
const globalContext_js_1 = require("../globalContext.js");
|
|
6
|
+
const virtualFileImportUserCode_js_1 = require("../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
7
|
+
async function getPageFilesExports() {
|
|
8
|
+
const viteDevServer = (0, globalContext_js_1.getViteDevServer)();
|
|
9
|
+
(0, utils_js_1.assert)(viteDevServer);
|
|
10
|
+
let moduleExports;
|
|
11
|
+
try {
|
|
12
|
+
moduleExports = await viteDevServer.ssrLoadModule(virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer);
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
(0, utils_js_1.debugGlob)(`Glob error: ${virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer} transpile error: `, err);
|
|
16
|
+
throw err;
|
|
17
|
+
}
|
|
18
|
+
moduleExports = moduleExports.default || moduleExports;
|
|
19
|
+
(0, utils_js_1.debugGlob)('Glob result: ', moduleExports);
|
|
20
|
+
(0, utils_js_1.assert)((0, utils_js_1.isObject)(moduleExports));
|
|
21
|
+
return moduleExports;
|
|
22
|
+
}
|
|
23
|
+
exports.getPageFilesExports = getPageFilesExports;
|
|
@@ -1,23 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const getPageFiles_js_1 = require("../../../shared/getPageFiles.js");
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const virtualFileImportUserCode_js_1 = require("../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
7
|
-
(0, getPageFiles_js_1.setPageFilesAsync)(getPageFilesExports);
|
|
8
|
-
async function getPageFilesExports() {
|
|
9
|
-
const viteDevServer = (0, globalContext_js_1.getViteDevServer)();
|
|
10
|
-
(0, utils_js_1.assert)(viteDevServer);
|
|
11
|
-
let moduleExports;
|
|
12
|
-
try {
|
|
13
|
-
moduleExports = await viteDevServer.ssrLoadModule(virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer);
|
|
14
|
-
}
|
|
15
|
-
catch (err) {
|
|
16
|
-
(0, utils_js_1.debugGlob)(`Glob error: ${virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer} transpile error: `, err);
|
|
17
|
-
throw err;
|
|
18
|
-
}
|
|
19
|
-
moduleExports = moduleExports.default || moduleExports;
|
|
20
|
-
(0, utils_js_1.debugGlob)('Glob result: ', moduleExports);
|
|
21
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(moduleExports));
|
|
22
|
-
return moduleExports;
|
|
23
|
-
}
|
|
4
|
+
const getPageFilesExports_js_1 = require("./getPageFilesExports.js");
|
|
5
|
+
(0, getPageFiles_js_1.setPageFilesAsync)(getPageFilesExports_js_1.getPageFilesExports);
|
|
@@ -26,6 +26,9 @@ function inferMediaType(href) {
|
|
|
26
26
|
if (href.endsWith('.svg')) {
|
|
27
27
|
return { assetType: 'image', mediaType: 'image/svg+xml' };
|
|
28
28
|
}
|
|
29
|
+
if (href.endsWith('.avif')) {
|
|
30
|
+
return { assetType: 'image', mediaType: 'image/avif' };
|
|
31
|
+
}
|
|
29
32
|
// Fonts
|
|
30
33
|
if (href.endsWith('.ttf')) {
|
|
31
34
|
return { assetType: 'font', mediaType: 'font/ttf' };
|
|
@@ -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;
|
|
@@ -24,6 +24,7 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
|
|
|
24
24
|
}
|
|
25
25
|
const exportDefault = picocolors_1.default.code('export default');
|
|
26
26
|
const exportNamed = picocolors_1.default.code(`export { ${configName} }`);
|
|
27
|
+
(0, utils_js_1.assert)(exportNamesValid.length <= 2);
|
|
27
28
|
if (exportNamesValid.length === 0) {
|
|
28
29
|
(0, utils_js_1.assertUsage)(false, `${filePathToShowToUser} should have a ${exportNamed} or ${exportDefault}`);
|
|
29
30
|
}
|
|
@@ -32,8 +33,6 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
|
|
|
32
33
|
onlyOnce: true
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
|
-
(0, utils_js_1.assert)(exportNamesValid.length === 1);
|
|
36
|
-
(0, utils_js_1.assert)(exportNamesInvalid.length > 0);
|
|
37
36
|
if (!TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext))) {
|
|
38
37
|
exportNamesInvalid.forEach((exportInvalid) => {
|
|
39
38
|
(0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} unexpected ${picocolors_1.default.cyan(`export { ${exportInvalid} }`)}`, {
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isArray = void 0;
|
|
4
|
-
//
|
|
4
|
+
// Same as Array.isArray() but typesafe: asserts unknown[] instead of any[]
|
|
5
5
|
function isArray(value) {
|
|
6
6
|
return Array.isArray(value);
|
|
7
7
|
}
|
|
@@ -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
|
}
|
|
@@ -12,7 +12,7 @@ import { createRequire } from 'module';
|
|
|
12
12
|
import fs from 'fs/promises';
|
|
13
13
|
import path from 'path';
|
|
14
14
|
import { fixServerAssets, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
|
|
15
|
-
import {
|
|
15
|
+
import { set_ASSETS_MAP } from './importBuild/index.js';
|
|
16
16
|
import { prependEntriesDir } from '../../shared/prependEntriesDir.js';
|
|
17
17
|
import { getFilePathResolved } from '../shared/getFilePath.js';
|
|
18
18
|
import { getConfigValueBuildTime } from '../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
@@ -71,7 +71,7 @@ function buildConfig() {
|
|
|
71
71
|
name: 'vike:buildConfig:writeBundle',
|
|
72
72
|
apply: 'build',
|
|
73
73
|
// Make sure other writeBundle() hooks are called after this writeBundle() hook.
|
|
74
|
-
// -
|
|
74
|
+
// - set_ASSETS_MAP() needs to be called before dist/server/ code is executed.
|
|
75
75
|
// - For example, the writeBundle() hook of vite-plugin-vercel needs to be called after this writeBundle() hook, otherwise: https://github.com/vikejs/vike/issues/1527
|
|
76
76
|
enforce: 'pre',
|
|
77
77
|
writeBundle: {
|
|
@@ -94,7 +94,7 @@ function buildConfig() {
|
|
|
94
94
|
}
|
|
95
95
|
await fs.rm(clientManifestFilePath);
|
|
96
96
|
await fs.rm(serverManifestFilePath);
|
|
97
|
-
await
|
|
97
|
+
await set_ASSETS_MAP(options, bundle);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -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';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { importBuild };
|
|
2
|
-
export {
|
|
2
|
+
export { set_ASSETS_MAP };
|
|
3
3
|
import type { Plugin, Rollup } from 'vite';
|
|
4
4
|
type Bundle = Rollup.OutputBundle;
|
|
5
5
|
type Options = Rollup.NormalizedOutputOptions;
|
|
6
6
|
declare function importBuild(): Plugin[];
|
|
7
7
|
/** Set the value of the ASSETS_MAP constant inside dist/server/entry.js (or dist/server/index.js) */
|
|
8
|
-
declare function
|
|
8
|
+
declare function set_ASSETS_MAP(options: Options, bundle: Bundle): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { importBuild };
|
|
2
|
-
export {
|
|
3
|
-
import { serverEntryPlugin
|
|
2
|
+
export { set_ASSETS_MAP };
|
|
3
|
+
import { serverEntryPlugin } from '@brillout/vite-plugin-server-entry/plugin';
|
|
4
4
|
import { assert, getOutDirs, toPosixPath } from '../../utils.js';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { createRequire } from 'module';
|
|
@@ -54,21 +54,31 @@ function getEntryCode(config, configVike) {
|
|
|
54
54
|
return importerCode;
|
|
55
55
|
}
|
|
56
56
|
/** Set the value of the ASSETS_MAP constant inside dist/server/entry.js (or dist/server/index.js) */
|
|
57
|
-
async function
|
|
57
|
+
async function set_ASSETS_MAP(options, bundle) {
|
|
58
58
|
const { dir } = options;
|
|
59
59
|
assert(dir);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const serverEntry = findServerEntry(bundle);
|
|
63
|
-
const serverEntryFilePath = path.join(dir, serverEntry.fileName);
|
|
60
|
+
const chunkPath = find_ASSETS_MAP(bundle);
|
|
61
|
+
const chunkFilePath = path.join(dir, chunkPath);
|
|
64
62
|
const assetsJsonFilePath = path.join(dir, '..', 'assets.json');
|
|
65
|
-
const [assetsJsonString,
|
|
63
|
+
const [assetsJsonString, chunkFileContent] = await Promise.all([
|
|
66
64
|
await fs.readFile(assetsJsonFilePath, 'utf8'),
|
|
67
|
-
await fs.readFile(
|
|
65
|
+
await fs.readFile(chunkFilePath, 'utf8')
|
|
68
66
|
]);
|
|
69
|
-
const serverEntryFileContentPatched =
|
|
70
|
-
assert(serverEntryFileContentPatched !==
|
|
71
|
-
await fs.writeFile(
|
|
67
|
+
const serverEntryFileContentPatched = chunkFileContent.replace(ASSETS_MAP, assetsJsonString);
|
|
68
|
+
assert(serverEntryFileContentPatched !== chunkFileContent);
|
|
69
|
+
await fs.writeFile(chunkFilePath, serverEntryFileContentPatched);
|
|
70
|
+
}
|
|
71
|
+
function find_ASSETS_MAP(bundle) {
|
|
72
|
+
let chunkPath;
|
|
73
|
+
for (const filePath in bundle) {
|
|
74
|
+
const chunk = bundle[filePath];
|
|
75
|
+
if ('code' in chunk && chunk.code.includes(ASSETS_MAP)) {
|
|
76
|
+
assert(!chunkPath);
|
|
77
|
+
chunkPath = filePath;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
assert(chunkPath);
|
|
81
|
+
return chunkPath;
|
|
72
82
|
}
|
|
73
83
|
function getImportPath(config) {
|
|
74
84
|
// We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
export { loadImportBuild };
|
|
2
2
|
export { setImportBuildGetters };
|
|
3
|
-
import { importServerEntry } from '@brillout/vite-plugin-server-entry/
|
|
3
|
+
import { importServerEntry } from '@brillout/vite-plugin-server-entry/runtime';
|
|
4
4
|
import { assert } from '../utils.js';
|
|
5
5
|
const buildGetters = (globalThis.__vike_buildGetters = globalThis.__vike_buildGetters || {
|
|
6
6
|
getters: null
|
|
@@ -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;
|