vike 0.4.223 → 0.4.224
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/node/api/build.js +4 -37
- package/dist/cjs/node/api/prepareViteApiCall.js +9 -3
- package/dist/cjs/node/plugin/index.js +8 -20
- package/dist/cjs/node/plugin/plugins/baseUrls.js +3 -1
- package/dist/cjs/node/plugin/plugins/{buildConfig/fixServerAssets.js → build/handleAssetsManifest.js} +130 -52
- package/dist/cjs/node/plugin/plugins/build/pluginAutoFullBuild.js +145 -0
- package/dist/cjs/node/plugin/plugins/build/pluginBuildApp.js +52 -0
- package/dist/cjs/node/plugin/plugins/{buildConfig.js → build/pluginBuildConfig.js} +22 -84
- package/dist/cjs/node/plugin/plugins/{buildEntry/index.js → build/pluginBuildEntry.js} +9 -9
- package/dist/cjs/node/plugin/plugins/{distFileNames.js → build/pluginDistFileNames.js} +7 -7
- package/dist/cjs/node/plugin/plugins/{packageJsonFile.js → build/pluginDistPackageJsonFile.js} +6 -6
- package/dist/cjs/node/plugin/plugins/{suppressRollupWarning.js → build/pluginSuppressRollupWarning.js} +3 -3
- package/dist/cjs/node/plugin/plugins/build.js +21 -0
- package/dist/cjs/node/plugin/plugins/commonConfig.js +22 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/envVars.js +2 -2
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +9 -9
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/cjs/node/plugin/plugins/fileEnv.js +5 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +2 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +7 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.js +16 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +50 -64
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +2 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +19 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +277 -212
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/virtual-files/getVirtualFilePageConfigValuesAll.js +4 -4
- package/dist/cjs/node/plugin/shared/findPageFiles.js +3 -3
- package/dist/cjs/node/plugin/shared/getOutDirs.js +8 -7
- package/dist/cjs/node/plugin/shared/isViteServerBuild.js +47 -0
- package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +1 -1
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/prerender/context.js +3 -8
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +23 -21
- package/dist/cjs/node/prerender/runPrerender.js +28 -28
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +7 -1
- package/dist/cjs/shared/getPageContextUrlComputed.js +1 -1
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +2 -5
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +3 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +20 -9
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/findFile.js +1 -1
- package/dist/cjs/utils/findPackageJson.js +1 -1
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +10 -4
- package/dist/cjs/utils/path.js +1 -0
- package/dist/cjs/utils/requireResolve.js +11 -4
- package/dist/cjs/utils/sorter.js +0 -3
- package/dist/esm/client/client-routing-runtime/index.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/index.js +1 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +8 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +10 -1
- package/dist/esm/node/api/build.js +4 -4
- package/dist/esm/node/api/prepareViteApiCall.js +9 -3
- package/dist/esm/node/plugin/index.d.ts +2 -1
- package/dist/esm/node/plugin/index.js +4 -17
- package/dist/esm/node/plugin/plugins/baseUrls.js +3 -1
- package/dist/esm/node/plugin/plugins/build/handleAssetsManifest.d.ts +18 -0
- package/dist/esm/node/plugin/plugins/{buildConfig/fixServerAssets.js → build/handleAssetsManifest.js} +131 -53
- package/dist/esm/node/plugin/plugins/build/pluginAutoFullBuild.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/build/pluginAutoFullBuild.js +140 -0
- package/dist/esm/node/plugin/plugins/build/pluginBuildApp.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/build/pluginBuildApp.js +50 -0
- package/dist/esm/node/plugin/plugins/{buildConfig.d.ts → build/pluginBuildConfig.d.ts} +3 -3
- package/dist/esm/node/plugin/plugins/{buildConfig.js → build/pluginBuildConfig.js} +22 -81
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.d.ts +7 -0
- package/dist/esm/node/plugin/plugins/{buildEntry/index.js → build/pluginBuildEntry.js} +9 -9
- package/dist/esm/node/plugin/plugins/build/pluginDistFileNames.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/{distFileNames.js → build/pluginDistFileNames.js} +7 -7
- package/dist/esm/node/plugin/plugins/build/pluginDistPackageJsonFile.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/{packageJsonFile.js → build/pluginDistPackageJsonFile.js} +7 -6
- package/dist/esm/node/plugin/plugins/build/pluginSuppressRollupWarning.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/{suppressRollupWarning.js → build/pluginSuppressRollupWarning.js} +3 -3
- package/dist/esm/node/plugin/plugins/build.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/build.js +19 -0
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +15 -6
- package/dist/esm/node/plugin/plugins/commonConfig.js +22 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/envVars.js +2 -2
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +10 -10
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/esm/node/plugin/plugins/fileEnv.js +5 -2
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +5 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +7 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.d.ts +1 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.js +13 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +50 -64
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +20 -8
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +279 -214
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/virtual-files/getVirtualFilePageConfigValuesAll.js +4 -4
- package/dist/esm/node/plugin/shared/findPageFiles.js +3 -3
- package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +1 -3
- package/dist/esm/node/plugin/shared/getOutDirs.d.ts +2 -2
- package/dist/esm/node/plugin/shared/getOutDirs.js +8 -7
- package/dist/esm/node/plugin/shared/isViteServerBuild.d.ts +15 -0
- package/dist/esm/node/plugin/shared/isViteServerBuild.js +45 -0
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +1 -1
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/prerender/context.d.ts +0 -2
- package/dist/esm/node/prerender/context.js +4 -9
- package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +10 -6
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +24 -22
- package/dist/esm/node/prerender/runPrerender.d.ts +7 -25
- package/dist/esm/node/prerender/runPrerender.js +29 -29
- package/dist/esm/node/prerender/utils.d.ts +1 -0
- package/dist/esm/node/prerender/utils.js +1 -0
- package/dist/esm/node/runtime/globalContext.d.ts +2 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +7 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +165 -5
- package/dist/esm/shared/getPageContextUrlComputed.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +12 -2
- package/dist/esm/shared/page-configs/PageConfig.d.ts +5 -5
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +2 -5
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +3 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +2 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +20 -9
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/findFile.js +1 -1
- package/dist/esm/utils/findPackageJson.js +1 -1
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +8 -2
- package/dist/esm/utils/path.js +1 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/requireResolve.js +11 -4
- package/dist/esm/utils/sorter.d.ts +18 -5
- package/dist/esm/utils/sorter.js +0 -3
- package/package.json +8 -16
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +0 -119
- package/dist/cjs/node/plugin/plugins/buildApp.js +0 -76
- package/dist/cjs/node/plugin/plugins/removeRequireHookPlugin.js +0 -17
- package/dist/cjs/node/plugin/shared/getFullBuildInlineConfig.js +0 -20
- package/dist/cjs/node/plugin/shared/viteIsSSR.js +0 -31
- package/dist/esm/node/plugin/plugins/autoFullBuild.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +0 -114
- package/dist/esm/node/plugin/plugins/buildApp.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/buildApp.js +0 -74
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +0 -20
- package/dist/esm/node/plugin/plugins/buildEntry/index.d.ts +0 -8
- package/dist/esm/node/plugin/plugins/distFileNames.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/packageJsonFile.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/removeRequireHookPlugin.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/removeRequireHookPlugin.js +0 -15
- package/dist/esm/node/plugin/plugins/suppressRollupWarning.d.ts +0 -3
- package/dist/esm/node/plugin/shared/getFullBuildInlineConfig.d.ts +0 -2
- package/dist/esm/node/plugin/shared/getFullBuildInlineConfig.js +0 -17
- package/dist/esm/node/plugin/shared/viteIsSSR.d.ts +0 -11
- package/dist/esm/node/plugin/shared/viteIsSSR.js +0 -29
- package/dist-cjs-fixup.mjs +0 -41
|
@@ -8,7 +8,7 @@ const extractAssetsQuery_js_1 = require("../../../../../shared/extractAssetsQuer
|
|
|
8
8
|
const debug_js_1 = require("./debug.js");
|
|
9
9
|
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
10
10
|
const serializeConfigValues_js_1 = require("../../../../../../shared/page-configs/serialize/serializeConfigValues.js");
|
|
11
|
-
const
|
|
11
|
+
const handleAssetsManifest_js_1 = require("../../../build/handleAssetsManifest.js");
|
|
12
12
|
const getConfigValueBuildTime_js_1 = require("../../../../../../shared/page-configs/getConfigValueBuildTime.js");
|
|
13
13
|
async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
14
14
|
const result = (0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id);
|
|
@@ -26,11 +26,11 @@ async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
|
26
26
|
(0, utils_js_1.assert)(pageConfig, { id, pageId });
|
|
27
27
|
const code = getLoadConfigValuesAll(pageConfig, isForClientSide, pageId,
|
|
28
28
|
// TODO/now: add meta.default
|
|
29
|
-
vikeConfig.global.config.includeAssetsImportedByServer ?? true, isDev);
|
|
29
|
+
vikeConfig.global.config.includeAssetsImportedByServer ?? true, config, isDev);
|
|
30
30
|
(0, debug_js_1.debug)(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
31
31
|
return code;
|
|
32
32
|
}
|
|
33
|
-
function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer, isDev) {
|
|
33
|
+
function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer, config, isDev) {
|
|
34
34
|
const lines = [];
|
|
35
35
|
const importStatements = [];
|
|
36
36
|
const filesEnv = new Map();
|
|
@@ -38,7 +38,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
38
38
|
lines.push('export const configValuesSerialized = {');
|
|
39
39
|
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, filesEnv, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isDev }), '', false));
|
|
40
40
|
lines.push('};');
|
|
41
|
-
if (!(0,
|
|
41
|
+
if (!(0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)(config) && includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
42
42
|
importStatements.push(`import '${(0, extractAssetsQuery_js_1.extractAssetsAddQuery)((0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageId, false))}'`);
|
|
43
43
|
}
|
|
44
44
|
const code = [...importStatements, ...lines].join('\n');
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.findPageFiles = findPageFiles;
|
|
7
|
-
const
|
|
7
|
+
const tinyglobby_1 = require("tinyglobby");
|
|
8
8
|
const utils_js_1 = require("../utils.js");
|
|
9
9
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
10
|
const getOutDirs_js_1 = require("./getOutDirs.js");
|
|
@@ -12,11 +12,11 @@ async function findPageFiles(config, fileTypes, isDev) {
|
|
|
12
12
|
const cwd = config.root;
|
|
13
13
|
const { outDirRoot } = (0, getOutDirs_js_1.getOutDirs)(config);
|
|
14
14
|
const timeBase = new Date().getTime();
|
|
15
|
-
let pageFiles = await (0,
|
|
15
|
+
let pageFiles = await (0, tinyglobby_1.glob)(fileTypes.map((fileType) => `**/*${fileType}.${utils_js_1.scriptFileExtensions}`), { ignore: ['**/node_modules/**', `${outDirRoot}/**`], cwd, dot: false, expandDirectories: false });
|
|
16
16
|
pageFiles = pageFiles.map((p) => '/' + (0, utils_js_1.toPosixPath)(p));
|
|
17
17
|
const time = new Date().getTime() - timeBase;
|
|
18
18
|
if (isDev) {
|
|
19
|
-
// We only warn in dev, because while building it's expected to take a long time as
|
|
19
|
+
// We only warn in dev, because while building it's expected to take a long time as tinyglobby is competing for resources with other tasks
|
|
20
20
|
(0, utils_js_1.assertWarning)(time < 1.5 * 1000, `Finding your page files ${picocolors_1.default.cyan('**/*.page.*')} took an unexpected long time (${time}ms). Reach out to the vike maintainer.`, {
|
|
21
21
|
onlyOnce: 'slow-page-files-search'
|
|
22
22
|
});
|
|
@@ -7,20 +7,21 @@ exports.getOutDirs = getOutDirs;
|
|
|
7
7
|
exports.resolveOutDir = resolveOutDir;
|
|
8
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
9
|
const utils_js_1 = require("../utils.js");
|
|
10
|
-
const
|
|
10
|
+
const isViteServerBuild_js_1 = require("./isViteServerBuild.js");
|
|
11
11
|
const debug = (0, utils_js_1.createDebugger)('vike:outDir');
|
|
12
|
-
function getOutDirs(
|
|
12
|
+
function getOutDirs(configGlobal, viteEnv) {
|
|
13
|
+
const configEnv = viteEnv?.config ?? configGlobal;
|
|
13
14
|
debug('getOutDirs()', new Error().stack);
|
|
14
|
-
const outDir = getOutDirFromViteResolvedConfig(
|
|
15
|
+
const outDir = getOutDirFromViteResolvedConfig(configEnv);
|
|
15
16
|
if (!isOutDirRoot(outDir))
|
|
16
|
-
assertOutDirResolved(outDir,
|
|
17
|
-
const outDirs = getOutDirsAll(outDir,
|
|
17
|
+
assertOutDirResolved(outDir, configEnv);
|
|
18
|
+
const outDirs = getOutDirsAll(outDir, configEnv.root);
|
|
18
19
|
return outDirs;
|
|
19
20
|
}
|
|
20
21
|
/** Appends `client/` or `server/` to `config.build.outDir` */
|
|
21
22
|
function resolveOutDir(config, isSSR) {
|
|
22
23
|
debug('resolveOutDir()', new Error().stack);
|
|
23
|
-
const isServerSide = (0,
|
|
24
|
+
const isServerSide = (0, isViteServerBuild_js_1.isViteServerBuild)(config) || isSSR;
|
|
24
25
|
debug('isServerSide', isServerSide);
|
|
25
26
|
const outDir = getOutDirFromViteUserConfig(config) || 'dist';
|
|
26
27
|
debug('outDir', outDir);
|
|
@@ -109,7 +110,7 @@ function assertOutDirResolved(outDir, config) {
|
|
|
109
110
|
(0, utils_js_1.assert)('/client'.length === '/server'.length);
|
|
110
111
|
const outDirCorrected = outDir.slice(0, -1 * '/client'.length);
|
|
111
112
|
const wrongUsage = `You've set Vite's config.build.outDir to ${picocolors_1.default.cyan(outDir)} but you should set it to ${picocolors_1.default.cyan(outDirCorrected)} instead.`;
|
|
112
|
-
if ((0,
|
|
113
|
+
if ((0, isViteServerBuild_js_1.isViteServerBuild)(config)) {
|
|
113
114
|
(0, utils_js_1.assertUsage)(outDir.endsWith('/server'), wrongUsage);
|
|
114
115
|
}
|
|
115
116
|
else {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isViteServerBuild = isViteServerBuild;
|
|
4
|
+
exports.isViteClientBuild = isViteClientBuild;
|
|
5
|
+
exports.isViteServerBuild_options = isViteServerBuild_options;
|
|
6
|
+
exports.isViteServerBuild_safe = isViteServerBuild_safe;
|
|
7
|
+
exports.isViteServerBuild_onlySsrEnv = isViteServerBuild_onlySsrEnv;
|
|
8
|
+
const assert_js_1 = require("../../../utils/assert.js");
|
|
9
|
+
function isViteServerBuild(configGlobal, viteEnv) {
|
|
10
|
+
const configEnv = viteEnv?.config ?? configGlobal;
|
|
11
|
+
return !!configEnv?.build?.ssr;
|
|
12
|
+
}
|
|
13
|
+
// Only `ssr` env: for example don't include `vercel_edge` nor `vercel_node`.
|
|
14
|
+
function isViteServerBuild_onlySsrEnv(configGlobal, viteEnv) {
|
|
15
|
+
return viteEnv ? viteEnv.name === 'ssr' : isViteServerBuild(configGlobal);
|
|
16
|
+
}
|
|
17
|
+
function isViteClientBuild(configGlobal, viteEnv) {
|
|
18
|
+
const yes = !isViteServerBuild(configGlobal, viteEnv);
|
|
19
|
+
const isVite5 = viteEnv === undefined;
|
|
20
|
+
if (!isVite5) {
|
|
21
|
+
const yes2 = viteEnv.name === 'client';
|
|
22
|
+
(0, assert_js_1.assert)(yes === yes2);
|
|
23
|
+
}
|
|
24
|
+
return yes;
|
|
25
|
+
}
|
|
26
|
+
function isViteServerBuild_options(options) {
|
|
27
|
+
return !!options?.ssr;
|
|
28
|
+
}
|
|
29
|
+
// Vite is quite messy about setting `ssr: boolean`, thus we use an extra safe implemention for security purposes.
|
|
30
|
+
// It's used for .client.js and .server.js guarantee thus we use agressive assert() calls for added safety.
|
|
31
|
+
function isViteServerBuild_safe(config, options) {
|
|
32
|
+
if (config.command === 'build') {
|
|
33
|
+
(0, assert_js_1.assert)(typeof config.build.ssr === 'boolean');
|
|
34
|
+
const val = config.build.ssr;
|
|
35
|
+
if (options?.ssr !== undefined)
|
|
36
|
+
(0, assert_js_1.assert)(val === options.ssr);
|
|
37
|
+
return val;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
(0, assert_js_1.assert)(typeof options?.ssr === 'boolean');
|
|
41
|
+
const val = options.ssr;
|
|
42
|
+
/* This assert() fails (which is very unexpected).
|
|
43
|
+
if (typeof config.build.ssr === 'boolean') assert(val === config.build.ssr)
|
|
44
|
+
//*/
|
|
45
|
+
return val;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.resolveClientEntriesDev = resolveClientEntriesDev;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
5
|
const module_1 = require("module");
|
|
6
|
-
// @ts-ignore
|
|
6
|
+
// @ts-ignore `file://${__filename}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
7
7
|
const importMetaUrl = `file://${__filename}`;
|
|
8
8
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
9
9
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
@@ -44,3 +44,4 @@ __exportStar(require("../../utils/isArray.js"), exports);
|
|
|
44
44
|
__exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
45
45
|
__exportStar(require("../../utils/isEqualStringList.js"), exports);
|
|
46
46
|
__exportStar(require("../../utils/isDocker.js"), exports);
|
|
47
|
+
__exportStar(require("../../utils/isVitest.js"), exports);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPrerenderEnabled = isPrerenderEnabled;
|
|
4
3
|
exports.isPrerenderAutoRunEnabled = isPrerenderAutoRunEnabled;
|
|
5
4
|
exports.temp_disablePrerenderAutoRun = temp_disablePrerenderAutoRun;
|
|
6
5
|
exports.isPrerendering = isPrerendering;
|
|
@@ -8,14 +7,10 @@ exports.setContextIsPrerendering = setContextIsPrerendering;
|
|
|
8
7
|
const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
|
|
9
8
|
const resolvePrerenderConfig_js_1 = require("./resolvePrerenderConfig.js");
|
|
10
9
|
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('prerender/context.ts', {});
|
|
11
|
-
function isPrerenderEnabled(vikeConfig) {
|
|
12
|
-
const prerenderConfig = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfig)(vikeConfig);
|
|
13
|
-
return !!prerenderConfig;
|
|
14
|
-
}
|
|
15
10
|
function isPrerenderAutoRunEnabled(vikeConfig) {
|
|
16
|
-
const
|
|
17
|
-
return (
|
|
18
|
-
!(
|
|
11
|
+
const prerenderConfigGlobal = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig);
|
|
12
|
+
return (prerenderConfigGlobal.isEnabled &&
|
|
13
|
+
!(prerenderConfigGlobal || {}).disableAutoRun &&
|
|
19
14
|
!globalObject.isDisabled &&
|
|
20
15
|
vikeConfig.global.config.disableAutoFullBuild !== 'prerender');
|
|
21
16
|
}
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolvePrerenderConfigGlobal = resolvePrerenderConfigGlobal;
|
|
4
4
|
exports.resolvePrerenderConfigLocal = resolvePrerenderConfigLocal;
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
6
|
const getConfigValueBuildTime_js_1 = require("../../shared/page-configs/getConfigValueBuildTime.js");
|
|
7
|
-
|
|
8
|
-
// TODO/now:
|
|
9
|
-
// - prerender.value
|
|
10
|
-
function resolvePrerenderConfig(vikeConfig) {
|
|
7
|
+
function resolvePrerenderConfigGlobal(vikeConfig) {
|
|
11
8
|
const prerenderConfigs = vikeConfig.global.config.prerender;
|
|
12
|
-
|
|
13
|
-
!vikeConfig.pageConfigs.some((pageConfig) => resolvePrerenderConfigLocal(pageConfig)?.value)) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
let prerenderSettings = prerenderConfigs || [];
|
|
9
|
+
let prerenderConfigList = prerenderConfigs || [];
|
|
17
10
|
// Needed because of backwards compatibility of `vike({prerender:true})` in `vite.config.js`; after we remove it we can remove this line.
|
|
18
|
-
|
|
19
|
-
(0, utils_js_1.assert)(
|
|
20
|
-
const
|
|
21
|
-
partial: pickFirst(
|
|
22
|
-
noExtraDir: pickFirst(
|
|
23
|
-
parallel: pickFirst(
|
|
24
|
-
disableAutoRun: pickFirst(
|
|
11
|
+
prerenderConfigList = prerenderConfigList.filter(isObject2);
|
|
12
|
+
(0, utils_js_1.assert)(prerenderConfigList.every(isObject2)); // Help TS
|
|
13
|
+
const prerenderConfigGlobal = {
|
|
14
|
+
partial: pickFirst(prerenderConfigList.map((c) => c.partial)) ?? false,
|
|
15
|
+
noExtraDir: pickFirst(prerenderConfigList.map((c) => c.noExtraDir)) ?? false,
|
|
16
|
+
parallel: pickFirst(prerenderConfigList.map((c) => c.parallel)) ?? true,
|
|
17
|
+
disableAutoRun: pickFirst(prerenderConfigList.map((c) => c.disableAutoRun)) ?? false
|
|
25
18
|
};
|
|
26
|
-
|
|
19
|
+
const prerenderConfigGlobalLocalValue = prerenderConfigList.map((c) => c.value).filter((v) => v !== null);
|
|
20
|
+
const defaultLocalValue = pickFirst(prerenderConfigGlobalLocalValue) ??
|
|
21
|
+
(prerenderConfigGlobalLocalValue.length > 0 ||
|
|
22
|
+
// Backwards compatibility for with vike({ prerender: true }) in vite.config.js
|
|
23
|
+
prerenderConfigs?.some((p) => p === true) ||
|
|
24
|
+
false);
|
|
25
|
+
(0, utils_js_1.objectAssign)(prerenderConfigGlobal, {
|
|
26
|
+
defaultLocalValue,
|
|
27
|
+
isEnabled: defaultLocalValue || vikeConfig.pageConfigs.some((pageConfig) => resolvePrerenderConfigLocal(pageConfig)?.value)
|
|
28
|
+
});
|
|
29
|
+
return prerenderConfigGlobal;
|
|
27
30
|
}
|
|
28
31
|
function resolvePrerenderConfigLocal(pageConfig) {
|
|
29
32
|
const configValue = (0, getConfigValueBuildTime_js_1.getConfigValueBuildTime)(pageConfig, 'prerender');
|
|
@@ -34,9 +37,8 @@ function resolvePrerenderConfigLocal(pageConfig) {
|
|
|
34
37
|
const value = values[0];
|
|
35
38
|
(0, utils_js_1.assert)(typeof value === 'boolean');
|
|
36
39
|
(0, utils_js_1.assert)((0, utils_js_1.isArray)(configValue.definedAtData));
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
return { value, configValueFilePathToShowToUser };
|
|
40
|
+
const prerenderConfigLocal = { value };
|
|
41
|
+
return prerenderConfigLocal;
|
|
40
42
|
}
|
|
41
43
|
function isObject2(p) {
|
|
42
44
|
return typeof p === 'object' && p !== null;
|
|
@@ -68,6 +68,7 @@ const resolvePrerenderConfig_js_1 = require("./resolvePrerenderConfig.js");
|
|
|
68
68
|
const getOutDirs_js_1 = require("../plugin/shared/getOutDirs.js");
|
|
69
69
|
const context_js_2 = require("../cli/context.js");
|
|
70
70
|
const isViteCliCall_js_1 = require("../plugin/shared/isViteCliCall.js");
|
|
71
|
+
const commonConfig_js_1 = require("../plugin/plugins/commonConfig.js");
|
|
71
72
|
async function runPrerenderFromAPI(options = {}) {
|
|
72
73
|
return await runPrerender(options, 'prerender()');
|
|
73
74
|
// - We purposely propagate the error to the user land, so that the error interrupts the user land. It's also, I guess, a nice-to-have that the user has control over the error.
|
|
@@ -94,11 +95,13 @@ async function runPrerenderFromAutoRun(viteConfig, config) {
|
|
|
94
95
|
prerenderContextPublic = ret.prerenderContextPublic;
|
|
95
96
|
}
|
|
96
97
|
catch (err) {
|
|
98
|
+
// Avoid Rollup prefixing the error with [vike:build:pluginAutoFullBuild], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
97
99
|
console.error(err);
|
|
98
100
|
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
99
101
|
process.exit(1);
|
|
100
102
|
}
|
|
101
|
-
|
|
103
|
+
const vike = (0, commonConfig_js_1.getVikeConfigPublic)(config);
|
|
104
|
+
vike.prerenderContext = prerenderContextPublic;
|
|
102
105
|
const forceExit = (0, context_js_2.isVikeCli)() || (0, isViteCliCall_js_1.isViteCliCall)();
|
|
103
106
|
return { forceExit };
|
|
104
107
|
}
|
|
@@ -117,15 +120,16 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
117
120
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(viteConfig);
|
|
118
121
|
const { outDirClient } = (0, getOutDirs_js_1.getOutDirs)(viteConfig);
|
|
119
122
|
const { root } = viteConfig;
|
|
120
|
-
const
|
|
121
|
-
validatePrerenderConfig(
|
|
122
|
-
|
|
123
|
+
const prerenderConfigGlobal = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig);
|
|
124
|
+
validatePrerenderConfig(prerenderConfigGlobal);
|
|
125
|
+
const { partial, noExtraDir, parallel, defaultLocalValue, isEnabled } = prerenderConfigGlobal;
|
|
126
|
+
if (!isEnabled) {
|
|
123
127
|
(0, utils_js_1.assert)(standaloneTrigger);
|
|
124
|
-
|
|
128
|
+
// TODO/now: make it assertUsage() and remove dist/server/entry.mjs whenever possible
|
|
129
|
+
(0, utils_js_1.assertWarning)(prerenderConfigGlobal, `You're executing ${picocolors_1.default.cyan(standaloneTrigger)} but you didn't enable pre-rendering. Use the config ${picocolors_1.default.cyan('prerender')} (${picocolors_1.default.underline('https://vike.dev/prerender')}) to enable it.`, {
|
|
125
130
|
onlyOnce: true
|
|
126
131
|
});
|
|
127
132
|
}
|
|
128
|
-
const { partial = false, noExtraDir = false, parallel = true } = prerenderConfig || {};
|
|
129
133
|
const concurrencyLimit = (0, utils_js_1.pLimit)(parallel === false || parallel === 0 ? 1 : parallel === true || parallel === undefined ? (0, os_1.cpus)().length : parallel);
|
|
130
134
|
await (0, globalContext_js_1.initGlobalContext_runPrerender)();
|
|
131
135
|
const globalContext = await (0, globalContext_js_1.getGlobalContextInternal)();
|
|
@@ -138,7 +142,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
138
142
|
output: []
|
|
139
143
|
};
|
|
140
144
|
const doNotPrerenderList = [];
|
|
141
|
-
await collectDoNoPrerenderList(vikeConfig.pageConfigs, doNotPrerenderList, concurrencyLimit, globalContext);
|
|
145
|
+
await collectDoNoPrerenderList(vikeConfig.pageConfigs, doNotPrerenderList, defaultLocalValue, concurrencyLimit, globalContext);
|
|
142
146
|
await callOnBeforePrerenderStartHooks(prerenderContext, globalContext, concurrencyLimit, doNotPrerenderList);
|
|
143
147
|
await handlePagesWithStaticRoutes(prerenderContext, globalContext, doNotPrerenderList, concurrencyLimit);
|
|
144
148
|
await callOnPrerenderStartHook(prerenderContext, globalContext);
|
|
@@ -161,20 +165,21 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
161
165
|
const prerenderContextPublic = makePublic(prerenderContext);
|
|
162
166
|
return { viteConfig, prerenderContextPublic };
|
|
163
167
|
}
|
|
164
|
-
async function collectDoNoPrerenderList(pageConfigs, doNotPrerenderList, concurrencyLimit, globalContext) {
|
|
168
|
+
async function collectDoNoPrerenderList(pageConfigs, doNotPrerenderList, defaultLocalValue, concurrencyLimit, globalContext) {
|
|
165
169
|
// V1 design
|
|
166
170
|
pageConfigs.forEach((pageConfig) => {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
171
|
+
const prerenderConfigLocal = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigLocal)(pageConfig);
|
|
172
|
+
const { pageId } = pageConfig;
|
|
173
|
+
if (!prerenderConfigLocal) {
|
|
174
|
+
if (!defaultLocalValue) {
|
|
175
|
+
doNotPrerenderList.push({ pageId });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const { value } = prerenderConfigLocal;
|
|
180
|
+
if (value === false) {
|
|
181
|
+
doNotPrerenderList.push({ pageId });
|
|
182
|
+
}
|
|
178
183
|
}
|
|
179
184
|
});
|
|
180
185
|
// Old design
|
|
@@ -207,12 +212,7 @@ async function collectDoNoPrerenderList(pageConfigs, doNotPrerenderList, concurr
|
|
|
207
212
|
}
|
|
208
213
|
else {
|
|
209
214
|
// Don't pre-render `pageId`
|
|
210
|
-
doNotPrerenderList.push({
|
|
211
|
-
pageId,
|
|
212
|
-
setByConfigFile: p.filePath,
|
|
213
|
-
setByConfigName: 'doNotPrerender',
|
|
214
|
-
setByConfigValue: doNotPrerender
|
|
215
|
-
});
|
|
215
|
+
doNotPrerenderList.push({ pageId });
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
});
|
|
@@ -565,8 +565,7 @@ function warnContradictoryNoPrerenderList(prerenderedPageContexts, doNotPrerende
|
|
|
565
565
|
if (!isContradictory)
|
|
566
566
|
return;
|
|
567
567
|
}
|
|
568
|
-
|
|
569
|
-
(0, utils_js_1.assertWarning)(false, `The ${providedByHook.hookName}() hook defined by ${providedByHook.hookFilePath} returns the URL ${picocolors_1.default.cyan(urlOriginal)}, while ${setByConfigFile} sets the config ${picocolors_1.default.cyan(setByConfigName)} to ${picocolors_1.default.cyan(String(setByConfigValue))}. This is contradictory: either don't set the config ${picocolors_1.default.cyan(setByConfigName)} to ${picocolors_1.default.cyan(String(setByConfigValue))} or remove the URL ${picocolors_1.default.cyan(urlOriginal)} from the list of URLs to be pre-rendered.`, { onlyOnce: true });
|
|
568
|
+
(0, utils_js_1.assertWarning)(false, `The ${providedByHook.hookName}() hook defined by ${providedByHook.hookFilePath} returns the URL ${picocolors_1.default.cyan(urlOriginal)} matching the route of the page ${picocolors_1.default.cyan(pageId)} which isn't configured to be pre-rendered. This is contradictory: either enable pre-rendering for ${picocolors_1.default.cyan(pageId)} or remove the URL ${picocolors_1.default.cyan(urlOriginal)} from the list of URLs to be pre-rendered.`, { onlyOnce: true });
|
|
570
569
|
});
|
|
571
570
|
}
|
|
572
571
|
async function warnMissingPages(prerenderedPageContexts, globalContext, doNotPrerenderList, partial) {
|
|
@@ -813,7 +812,8 @@ prerenderConfig) {
|
|
|
813
812
|
}
|
|
814
813
|
function makePublic(prerenderContext) {
|
|
815
814
|
const prerenderContextPublic = (0, utils_js_1.makePublicCopy)(prerenderContext, 'prerenderContext', [
|
|
816
|
-
'
|
|
815
|
+
'output', // vite-plugin-vercel
|
|
816
|
+
'pageContexts' // https://vike.dev/i18n#pre-rendering
|
|
817
817
|
]);
|
|
818
818
|
return prerenderContextPublic;
|
|
819
819
|
}
|
|
@@ -33,3 +33,4 @@ __exportStar(require("../../utils/isArray.js"), exports);
|
|
|
33
33
|
__exportStar(require("../../utils/isObject.js"), exports);
|
|
34
34
|
__exportStar(require("../../utils/changeEnumerable.js"), exports);
|
|
35
35
|
__exportStar(require("../../utils/makePublicCopy.js"), exports);
|
|
36
|
+
__exportStar(require("../../utils/isNotNullish.js"), exports);
|
|
@@ -29,13 +29,19 @@ const errorsMisc = [
|
|
|
29
29
|
mustMentionNodeModules: false
|
|
30
30
|
}
|
|
31
31
|
];
|
|
32
|
+
const reactInvalidEelement = 'https://vike.dev/broken-npm-package#react-invalid-component';
|
|
32
33
|
const errorsReact = [
|
|
33
34
|
{
|
|
34
35
|
errMsg: 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)',
|
|
35
|
-
link:
|
|
36
|
+
link: reactInvalidEelement,
|
|
36
37
|
// The stack trace can be user-land while the import is coming from node_modules
|
|
37
38
|
mustMentionNodeModules: false
|
|
38
39
|
},
|
|
40
|
+
{
|
|
41
|
+
errMsg: 'Objects are not valid as a React child',
|
|
42
|
+
link: reactInvalidEelement,
|
|
43
|
+
mustMentionNodeModules: false
|
|
44
|
+
},
|
|
39
45
|
{
|
|
40
46
|
// React's "Invalid hook call.", see https://github.com/vikejs/vike/discussions/1637#discussioncomment-9424712
|
|
41
47
|
errMsg: "Cannot read properties of null (reading 'useContext')"
|
|
@@ -39,7 +39,7 @@ function getUrlParsed(pageContext) {
|
|
|
39
39
|
// 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
|
|
40
40
|
// Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
|
|
41
41
|
// Determine logical URL
|
|
42
|
-
const assertUrlResolved = (src) => (0, utils_js_1.assert)(
|
|
42
|
+
const assertUrlResolved = (src) => (0, utils_js_1.assert)(typeof urlResolved === 'string',
|
|
43
43
|
// TODO/eventually: remove debug logs, see:
|
|
44
44
|
// - https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
|
|
45
45
|
// - https://github.com/vikejs/vike/commit/5c7810f3080ab62536950f26e019bb2a3a517082
|
|
@@ -29,9 +29,7 @@ function getConfigValue(pageConfig, configName) {
|
|
|
29
29
|
if (!configDef.cumulative) {
|
|
30
30
|
const configValueSource = sources[0];
|
|
31
31
|
(0, utils_js_1.assert)(configValueSource);
|
|
32
|
-
(0, utils_js_1.assert)(configValueSource.
|
|
33
|
-
(0, utils_js_1.assert)(sources.slice(1).every((s) => s.isOverriden === true));
|
|
34
|
-
(0, utils_js_1.assert)('value' in configValueSource);
|
|
32
|
+
(0, utils_js_1.assert)(configValueSource.valueIsLoaded);
|
|
35
33
|
return {
|
|
36
34
|
type: 'standard',
|
|
37
35
|
value: configValueSource.value,
|
|
@@ -52,9 +50,8 @@ function mergeCumulative(configValueSources) {
|
|
|
52
50
|
const value = [];
|
|
53
51
|
const definedAtData = [];
|
|
54
52
|
configValueSources.forEach((configValueSource) => {
|
|
55
|
-
(0, utils_js_1.assert)(configValueSource.isOverriden === false);
|
|
56
53
|
(0, utils_js_1.assert)(configValueSource.configEnv.config === true);
|
|
57
|
-
(0, utils_js_1.assert)(
|
|
54
|
+
(0, utils_js_1.assert)(configValueSource.valueIsLoaded);
|
|
58
55
|
value.push(configValueSource.value);
|
|
59
56
|
definedAtData.push(getDefinedAtFile(configValueSource));
|
|
60
57
|
});
|
|
@@ -66,7 +66,9 @@ function parseConfigValuesSerialized_tmp(configValuesSerialized) {
|
|
|
66
66
|
const { valueSerialized, ...common } = configValueSeriliazed;
|
|
67
67
|
const { value, sideExports } = parseValueSerialized(valueSerialized, configName, () => {
|
|
68
68
|
(0, utils_js_1.assert)(configValueSeriliazed.type !== 'computed');
|
|
69
|
-
|
|
69
|
+
const { definedAtData } = configValueSeriliazed;
|
|
70
|
+
const definedAtFile = Array.isArray(definedAtData) ? definedAtData[0] : definedAtData;
|
|
71
|
+
return definedAtFile;
|
|
70
72
|
});
|
|
71
73
|
addSideExports(sideExports);
|
|
72
74
|
configValue = { value, ...common };
|
|
@@ -5,12 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.serializeConfigValues = serializeConfigValues;
|
|
7
7
|
exports.getConfigValuesBase = getConfigValuesBase;
|
|
8
|
+
exports.isJsonValue = isJsonValue;
|
|
8
9
|
const assertSetup_js_1 = require("../../../utils/assertSetup.js");
|
|
9
10
|
const utils_js_1 = require("../../../node/plugin/utils.js");
|
|
10
11
|
const transformPointerImports_js_1 = require("../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformPointerImports.js");
|
|
11
12
|
const helpers_js_1 = require("../helpers.js");
|
|
12
13
|
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
13
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
15
|
+
const getVikeConfig_js_1 = require("../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js");
|
|
16
|
+
const stringifyOptions = { forbidReactElements: true };
|
|
14
17
|
const REPLACE_ME_BEFORE = '__VIKE__REPLACE_ME_BEFORE__';
|
|
15
18
|
const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
16
19
|
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with parsePageConfigs()
|
|
@@ -47,9 +50,8 @@ function serializeConfigValues(pageConfig, importStatements, filesEnv, isEnvMatc
|
|
|
47
50
|
return lines;
|
|
48
51
|
}
|
|
49
52
|
function getValueSerializedFromSource(configValueSource, configName, importStatements, filesEnv) {
|
|
50
|
-
(0, utils_js_1.assert)(configValueSource.isOverriden === false);
|
|
51
53
|
let valueData;
|
|
52
|
-
if (
|
|
54
|
+
if (configValueSource.valueIsLoaded && !configValueSource.valueIsLoadedWithImport) {
|
|
53
55
|
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAtFilePath, importStatements, filesEnv, configValueSource.configEnv);
|
|
54
56
|
}
|
|
55
57
|
else {
|
|
@@ -101,14 +103,13 @@ function serializeConfigValue(configValueBase, valueData, configName, lines, tab
|
|
|
101
103
|
}
|
|
102
104
|
function getValueSerializedWithImport(configValueSource, importStatements, filesEnv, configName) {
|
|
103
105
|
(0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
|
|
104
|
-
const {
|
|
105
|
-
(0, utils_js_1.assert)(valueIsImportedAtRuntime);
|
|
106
|
+
const { valueIsDefinedByPlusValueFile, definedAtFilePath, configEnv } = configValueSource;
|
|
106
107
|
const { filePathAbsoluteVite, fileExportName } = definedAtFilePath;
|
|
107
|
-
if (
|
|
108
|
+
if (valueIsDefinedByPlusValueFile)
|
|
108
109
|
(0, utils_js_1.assert)(fileExportName === undefined);
|
|
109
110
|
const { importName } = addImportStatement(importStatements, filePathAbsoluteVite, fileExportName || '*', filesEnv, configEnv, configName);
|
|
110
111
|
return {
|
|
111
|
-
type:
|
|
112
|
+
type: valueIsDefinedByPlusValueFile ? 'plus-file' : 'pointer-import',
|
|
112
113
|
valueAsJsCode: importName
|
|
113
114
|
};
|
|
114
115
|
}
|
|
@@ -125,7 +126,7 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
|
|
|
125
126
|
try {
|
|
126
127
|
configValueSerialized = (0, stringify_1.stringify)(value, {
|
|
127
128
|
valueName,
|
|
128
|
-
|
|
129
|
+
...stringifyOptions,
|
|
129
130
|
// Replace import strings with import variables.
|
|
130
131
|
// - We don't need this anymore and could remove it.
|
|
131
132
|
// - We temporarily needed it for nested document configs (`config.document.{title,description,favicon}`), but we finally decided to go for flat document configs instead (`config.{title,description,favicon}`).
|
|
@@ -152,6 +153,15 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
|
|
|
152
153
|
(0, utils_js_1.assert)(!configValueSerialized.includes(REPLACE_ME_AFTER));
|
|
153
154
|
return configValueSerialized;
|
|
154
155
|
}
|
|
156
|
+
function isJsonValue(value) {
|
|
157
|
+
try {
|
|
158
|
+
(0, stringify_1.stringify)(value, stringifyOptions);
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
155
165
|
function logJsonSerializeError(err, configName, definedAtData) {
|
|
156
166
|
/*
|
|
157
167
|
// import { isJsonSerializerError } from '@brillout/json-serializer/stringify'
|
|
@@ -191,7 +201,6 @@ function getConfigValuesBase(pageConfig, isEnvMatch, isEager) {
|
|
|
191
201
|
if (!configDef.cumulative) {
|
|
192
202
|
const source = sources[0];
|
|
193
203
|
(0, utils_js_1.assert)(source);
|
|
194
|
-
(0, utils_js_1.assert)(sources.slice(1).every((s) => s.isOverriden === true));
|
|
195
204
|
if (!isEnvMatch(source.configEnv))
|
|
196
205
|
return 'SKIP';
|
|
197
206
|
const definedAtFile = getDefinedAtFileSource(source);
|
|
@@ -202,7 +211,9 @@ function getConfigValuesBase(pageConfig, isEnvMatch, isEager) {
|
|
|
202
211
|
return { configValueBase, sourceRelevant: source, configName };
|
|
203
212
|
}
|
|
204
213
|
else {
|
|
205
|
-
const sourcesRelevant = sources
|
|
214
|
+
const sourcesRelevant = sources
|
|
215
|
+
.filter((source) => !(0, getVikeConfig_js_1.isOverriden)(source, configName, pageConfig))
|
|
216
|
+
.filter((source) => isEnvMatch(source.configEnv));
|
|
206
217
|
if (sourcesRelevant.length === 0)
|
|
207
218
|
return 'SKIP';
|
|
208
219
|
const definedAtData = [];
|
|
@@ -8,7 +8,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const isArray_js_1 = require("./isArray.js");
|
|
10
10
|
const path_js_1 = require("./path.js");
|
|
11
|
-
// We need to be able to crawl the filesystem, regardless of Vike's `$ git ls-files` command call, because we need to fallback if the user didn't setup Git (e.g. we cannot remove the
|
|
11
|
+
// We need to be able to crawl the filesystem, regardless of Vike's `$ git ls-files` command call, because we need to fallback if the user didn't setup Git (e.g. we cannot remove the tinyglobby fallback).
|
|
12
12
|
function findFile(arg, cwd) {
|
|
13
13
|
(0, path_js_1.assertPosixPath)(cwd);
|
|
14
14
|
const filenames = (0, isArray_js_1.isArray)(arg) ? arg : [arg];
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.findPackageJson = findPackageJson;
|
|
4
4
|
const findFile_js_1 = require("./findFile.js");
|
|
5
5
|
const module_1 = require("module");
|
|
6
|
-
// @ts-ignore
|
|
6
|
+
// @ts-ignore `file://${__filename}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
7
7
|
const importMetaUrl = `file://${__filename}`;
|
|
8
8
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
9
9
|
function findPackageJson(cwd) {
|
|
@@ -5,9 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.assertFilePathAbsoluteFilesystem = assertFilePathAbsoluteFilesystem;
|
|
7
7
|
exports.isFilePathAbsolute = isFilePathAbsolute;
|
|
8
|
-
const
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const assert_js_1 = require("./assert.js");
|
|
10
10
|
const path_js_1 = require("./path.js");
|
|
11
|
+
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
12
|
+
const assertSetup_js_1 = require("./assertSetup.js");
|
|
13
|
+
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
14
|
+
// Server runtime shouldn't depend on node:path
|
|
15
|
+
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
11
16
|
/**
|
|
12
17
|
* Asserts that `filePath` is an absolute file path starting from the filesystem root.
|
|
13
18
|
*
|
|
@@ -18,6 +23,7 @@ function assertFilePathAbsoluteFilesystem(filePath) {
|
|
|
18
23
|
// - For Windows users, the assert is correct.
|
|
19
24
|
// - For Linux users assertFilePathAbsoluteFilesystem() will erroneously succeed if `p` is a path absolute from the user root dir.
|
|
20
25
|
// - But that's okay because the assertion will eventually fail for Windows users.
|
|
26
|
+
// - On Linux there doesn't seem to be a way to distinguish between an absolute path starting from the filesystem root or starting from the user root directory, see comment at isFilePathAbsoluteFilesystem()
|
|
21
27
|
(0, assert_js_1.assert)(isFilePathAbsoluteFilesystem(filePath));
|
|
22
28
|
(0, path_js_1.assertPosixPath)(filePath);
|
|
23
29
|
}
|
|
@@ -33,11 +39,11 @@ function isFilePathAbsoluteFilesystem(filePath) {
|
|
|
33
39
|
// - File path absolute starting from filesystem root, e.g. /home/rom/code/my-app/pages/about/+Page.js
|
|
34
40
|
// - File path absolute starting from user root dir (Vite's `config.root`), e.g. /pages/about/+Page.js
|
|
35
41
|
// - Checking whether `p` starts with the first directory of process.cwd() (or `userRootDir`) can be erroneous, most notably when using docker: https://github.com/vikejs/vike/issues/703
|
|
36
|
-
// - Using require.resolve() would be a solution but
|
|
42
|
+
// - Using require.resolve() or node:fs to check wehther the file/dir exsits would be a solution, but maybe too slow?
|
|
37
43
|
return filePath.startsWith('/');
|
|
38
44
|
}
|
|
39
45
|
else {
|
|
40
|
-
const yes =
|
|
46
|
+
const yes = node_path_1.default.win32.isAbsolute(filePath);
|
|
41
47
|
// Ensure isFilePathAbsoluteFilesystem() returns `false` if path is absolute starting from the user root dir (see comments above).
|
|
42
48
|
if (yes)
|
|
43
49
|
(0, assert_js_1.assert)(!filePath.startsWith('/'));
|
|
@@ -55,5 +61,5 @@ function isFilePathAbsolute(filePath) {
|
|
|
55
61
|
if (filePath.startsWith('/'))
|
|
56
62
|
return true;
|
|
57
63
|
// Seems to be reliable: https://nodejs.org/api/path.html#pathisabsolutepath
|
|
58
|
-
return
|
|
64
|
+
return node_path_1.default.isAbsolute(filePath);
|
|
59
65
|
}
|
package/dist/cjs/utils/path.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.assertPosixPath = assertPosixPath;
|
|
|
9
9
|
// - Robust shim reference: https://github.com/unjs/pathe
|
|
10
10
|
const assert_js_1 = require("./assert.js");
|
|
11
11
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
12
|
+
// While this path shim also works on the client-side, let's try to not use it on the client-side in order to minimize KBs sent to the browser.
|
|
12
13
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
13
14
|
/**********************/
|
|
14
15
|
/****** SHIMS *********/
|