vike 0.4.143 → 0.4.144-commit-e40e9b1
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/plugin/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +31 -30
- package/dist/cjs/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +19 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +228 -186
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -35
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +60 -95
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +14 -13
- package/dist/cjs/node/plugin/shared/findPageFiles.js +2 -1
- package/dist/cjs/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +1 -12
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/cjs/node/plugin/utils.js +2 -3
- package/dist/cjs/node/prerender/runPrerender.js +18 -20
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
- package/dist/cjs/node/runtime/renderPage/log404/index.js +10 -5
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
- package/dist/cjs/node/runtime/renderPage.js +1 -1
- package/dist/cjs/node/shared/getClientEntryFilePath.js +1 -7
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/cjs/shared/error-page.js +1 -1
- package/dist/cjs/shared/getPageFiles/getExports.js +8 -11
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +10 -44
- package/dist/cjs/shared/hooks/getHook.js +3 -1
- package/dist/cjs/shared/page-configs/assertExports.js +60 -0
- package/dist/cjs/shared/page-configs/getExportPath.js +9 -10
- package/dist/cjs/shared/page-configs/loadConfigValues.js +18 -0
- package/dist/cjs/shared/page-configs/serialize/PageConfigSerialized.js +2 -0
- package/dist/cjs/shared/page-configs/serialize/assertPageConfigs.js +19 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +56 -0
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +65 -0
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +58 -0
- package/dist/cjs/shared/page-configs/utils.js +65 -42
- package/dist/cjs/shared/route/loadPageRoutes.js +12 -15
- package/dist/cjs/shared/route/resolveRedirects.js +1 -1
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -0
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/getOutDirs.js +25 -18
- package/dist/cjs/utils/getValuePrintable.js +1 -1
- package/dist/cjs/utils/objectAssign.js +3 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/{resolve.js → requireResolve.js} +3 -3
- package/dist/cjs/utils/warnIfErrorIsNotObject.js +1 -1
- package/dist/esm/__internal/index.d.ts +3 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageId.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/useClientRouter.js +3 -3
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
- package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +2 -2
- package/dist/esm/client/shared/loadPageFilesClientSide.js +2 -2
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/plugin/index.js +3 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/config/index.js +2 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +31 -30
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +13 -2
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +20 -11
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +19 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +5 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +229 -187
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -32
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +60 -95
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +7 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +15 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.d.ts +18 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +14 -13
- package/dist/esm/node/plugin/shared/findPageFiles.js +3 -2
- package/dist/esm/node/plugin/shared/{getConfigValueSource.d.ts → getConfigValueSourcesRelevant.d.ts} +0 -2
- package/dist/esm/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +0 -11
- package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -2
- package/dist/esm/node/plugin/utils.d.ts +1 -2
- package/dist/esm/node/plugin/utils.js +2 -3
- package/dist/esm/node/prerender/runPrerender.js +20 -22
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.js +10 -5
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +13 -13
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
- package/dist/esm/node/runtime/renderPage.js +1 -1
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +2 -2
- package/dist/esm/node/shared/getClientEntryFilePath.js +2 -8
- package/dist/esm/shared/addIs404ToPageProps.d.ts +2 -2
- package/dist/esm/shared/addUrlComputedProps.d.ts +4 -2
- package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/esm/shared/error-page.d.ts +3 -3
- package/dist/esm/shared/error-page.js +1 -1
- package/dist/esm/shared/getPageFiles/analyzeClientSide.d.ts +2 -2
- package/dist/esm/shared/getPageFiles/getExports.d.ts +3 -4
- package/dist/esm/shared/getPageFiles/getExports.js +7 -10
- package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +3 -3
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +9 -43
- package/dist/esm/shared/getPageFiles/setPageFiles.d.ts +3 -3
- package/dist/esm/shared/hooks/getHook.js +3 -1
- package/dist/esm/shared/page-configs/Config.d.ts +201 -14
- package/dist/esm/shared/page-configs/PageConfig.d.ts +80 -73
- package/dist/esm/shared/page-configs/assertExports.d.ts +6 -0
- package/dist/esm/shared/page-configs/assertExports.js +54 -0
- package/dist/esm/shared/page-configs/findPageConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
- package/dist/esm/shared/page-configs/getExportPath.js +9 -10
- package/dist/esm/shared/page-configs/loadConfigValues.d.ts +3 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +15 -0
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +32 -0
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.js +1 -0
- package/dist/esm/shared/page-configs/serialize/assertPageConfigs.d.ts +5 -0
- package/dist/esm/shared/page-configs/serialize/assertPageConfigs.js +16 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.d.ts +4 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +50 -0
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +7 -0
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +62 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.d.ts +8 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +52 -0
- package/dist/esm/shared/page-configs/utils.d.ts +21 -14
- package/dist/esm/shared/page-configs/utils.js +64 -41
- package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/shared/route/index.d.ts +3 -3
- package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +13 -16
- package/dist/esm/shared/route/resolveRedirects.js +1 -1
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -0
- package/dist/esm/shared/types.d.ts +8 -6
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/utils/getOutDirs.d.ts +0 -2
- package/dist/esm/utils/getOutDirs.js +24 -17
- package/dist/esm/utils/getValuePrintable.js +1 -1
- package/dist/esm/utils/objectAssign.js +3 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/requireResolve.d.ts +2 -0
- package/dist/esm/utils/{resolve.js → requireResolve.js} +2 -2
- package/dist/esm/utils/warnIfErrorIsNotObject.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
- package/dist/cjs/shared/getPageFiles/assertPageConfigs.js +0 -19
- package/dist/cjs/shared/page-configs/loadPageCode.js +0 -63
- package/dist/cjs/utils/assertDefaultExport.js +0 -53
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -10
- package/dist/esm/shared/getPageFiles/assertPageConfigs.d.ts +0 -5
- package/dist/esm/shared/getPageFiles/assertPageConfigs.js +0 -16
- package/dist/esm/shared/page-configs/loadPageCode.d.ts +0 -3
- package/dist/esm/shared/page-configs/loadPageCode.js +0 -57
- package/dist/esm/utils/assertDefaultExport.d.ts +0 -8
- package/dist/esm/utils/assertDefaultExport.js +0 -47
- package/dist/esm/utils/resolve.d.ts +0 -2
- /package/dist/cjs/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
- /package/dist/esm/shared/getPageFiles/{assertExports.d.ts → assert_exports_old_design.d.ts} +0 -0
- /package/dist/esm/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getVirtualFilePageConfigValuesAll = void 0;
|
|
7
4
|
const utils_js_1 = require("../../../utils.js");
|
|
8
|
-
const generateEagerImport_js_1 = require("../generateEagerImport.js");
|
|
9
5
|
const virtualFilePageConfigValuesAll_js_1 = require("../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
10
6
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
11
7
|
const extractAssetsQuery_js_1 = require("../../../../shared/extractAssetsQuery.js");
|
|
12
8
|
const debug_js_1 = require("./debug.js");
|
|
13
|
-
const path_1 = __importDefault(require("path"));
|
|
14
9
|
const utils_js_2 = require("../../../../../shared/page-configs/utils.js");
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
10
|
+
const getConfigValueSourcesRelevant_js_1 = require("../../../shared/getConfigValueSourcesRelevant.js");
|
|
11
|
+
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
12
|
+
const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
|
|
13
|
+
async function getVirtualFilePageConfigValuesAll(id, userRootDir, outDirRoot, isDev, configVike) {
|
|
18
14
|
const result = (0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id);
|
|
19
15
|
(0, utils_js_1.assert)(result);
|
|
20
16
|
/* This assertion fails when using includeAssetsImportedByServer
|
|
@@ -24,7 +20,7 @@ async function getVirtualFilePageConfigValuesAll(id, userRootDir, isDev, configV
|
|
|
24
20
|
}
|
|
25
21
|
*/
|
|
26
22
|
const { pageId, isForClientSide } = result;
|
|
27
|
-
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(userRootDir, isDev, configVike.extensions, true);
|
|
23
|
+
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(userRootDir, outDirRoot, isDev, configVike.extensions, true);
|
|
28
24
|
const pageConfig = pageConfigs.find((pageConfig) => pageConfig.pageId === pageId);
|
|
29
25
|
(0, utils_js_1.assert)(pageConfig);
|
|
30
26
|
const code = getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, configVike.includeAssetsImportedByServer, isDev);
|
|
@@ -38,37 +34,17 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
38
34
|
const lines = [];
|
|
39
35
|
const importStatements = [];
|
|
40
36
|
lines.push('export default [');
|
|
41
|
-
|
|
42
|
-
(0,
|
|
43
|
-
const { valueIsImportedAtRuntime,
|
|
37
|
+
const varCounterContainer = { varCounter: 0 };
|
|
38
|
+
(0, getConfigValueSourcesRelevant_js_1.getConfigValueSourcesRelevant)(pageConfig).forEach((configValueSource) => {
|
|
39
|
+
const { valueIsImportedAtRuntime, configEnv, configName } = configValueSource;
|
|
44
40
|
if (!valueIsImportedAtRuntime)
|
|
45
41
|
return;
|
|
46
42
|
if (configValueSource.valueIsFilePath)
|
|
47
43
|
return;
|
|
48
|
-
if (!(0,
|
|
44
|
+
if (!(0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: false }))
|
|
49
45
|
return;
|
|
50
|
-
const
|
|
51
|
-
(0,
|
|
52
|
-
const fileName = path_1.default.posix.basename(filePath);
|
|
53
|
-
const isPlusFile = fileName.startsWith('+');
|
|
54
|
-
const fileExportName = fileExportPath[0];
|
|
55
|
-
(0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
|
|
56
|
-
(0, utils_js_1.assert)(fileExportName);
|
|
57
|
-
const { importVar, importStatement } = (0, generateEagerImport_js_1.generateEagerImport)(filePath, varCounter++, isPlusFile ? undefined : fileExportName);
|
|
58
|
-
importStatements.push(importStatement);
|
|
59
|
-
lines.push(` {`);
|
|
60
|
-
lines.push(` configName: '${configName}',`);
|
|
61
|
-
lines.push(` importFilePath: '${filePath}',`);
|
|
62
|
-
lines.push(` isPlusFile: ${JSON.stringify(isPlusFile)},`);
|
|
63
|
-
if (isPlusFile) {
|
|
64
|
-
lines.push(` importFileExports: ${importVar},`);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
lines.push(` importFileExportValue: ${importVar},`);
|
|
68
|
-
(0, utils_js_1.assert)(fileExportName);
|
|
69
|
-
lines.push(` importFileExportName: ${JSON.stringify(fileExportName)},`);
|
|
70
|
-
}
|
|
71
|
-
lines.push(` },`);
|
|
46
|
+
const whitespace = ' ';
|
|
47
|
+
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
72
48
|
});
|
|
73
49
|
lines.push('];');
|
|
74
50
|
if (includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
@@ -5,23 +5,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getConfigValueSerialized = exports.getVirtualFilePageConfigs = void 0;
|
|
7
7
|
const utils_js_1 = require("../../../utils.js");
|
|
8
|
-
const generateEagerImport_js_1 = require("../generateEagerImport.js");
|
|
9
8
|
const virtualFilePageConfigValuesAll_js_1 = require("../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
10
9
|
const debug_js_1 = require("./debug.js");
|
|
11
10
|
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
12
11
|
const helpers_js_1 = require("./helpers.js");
|
|
13
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
13
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
15
|
+
const utils_js_2 = require("../../../../../shared/page-configs/utils.js");
|
|
16
|
+
const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
|
|
17
|
+
async function getVirtualFilePageConfigs(userRootDir, outDirRoot, isForClientSide, isDev, id, configVike, isClientRouting) {
|
|
18
|
+
const { pageConfigs, pageConfigGlobal } = await (0, getVikeConfig_js_1.getVikeConfig)(userRootDir, outDirRoot, isDev, configVike.extensions, true);
|
|
18
19
|
return getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
|
|
19
20
|
}
|
|
20
21
|
exports.getVirtualFilePageConfigs = getVirtualFilePageConfigs;
|
|
21
22
|
function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting) {
|
|
22
23
|
const lines = [];
|
|
23
24
|
const importStatements = [];
|
|
24
|
-
|
|
25
|
+
const varCounterContainer = { varCounter: 0 };
|
|
26
|
+
lines.push('export const pageConfigsSerialized = [');
|
|
25
27
|
pageConfigs.forEach((pageConfig) => {
|
|
26
28
|
const { pageId, routeFilesystem, isErrorPage } = pageConfig;
|
|
27
29
|
const virtualFileIdPageConfigValuesAll = (0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageId, isForClientSide);
|
|
@@ -30,122 +32,93 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
|
|
|
30
32
|
lines.push(` isErrorPage: ${JSON.stringify(isErrorPage)},`);
|
|
31
33
|
lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
|
|
32
34
|
lines.push(` loadConfigValuesAll: async () => (await import(${JSON.stringify(virtualFileIdPageConfigValuesAll)})).default,`);
|
|
33
|
-
lines.push(`
|
|
34
|
-
Object.entries(pageConfig.
|
|
35
|
+
lines.push(` configValuesSerialized: {`);
|
|
36
|
+
Object.entries(pageConfig.configValuesComputed).forEach(([configName, configValuesComputed]) => {
|
|
37
|
+
const { value, configEnv } = configValuesComputed;
|
|
38
|
+
if (!(0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true }))
|
|
39
|
+
return;
|
|
40
|
+
if (pageConfig.configValueSources[configName])
|
|
41
|
+
return;
|
|
42
|
+
const configValue = pageConfig.configValues[configName];
|
|
43
|
+
(0, utils_js_1.assert)(configValue);
|
|
44
|
+
const { definedAt } = configValue;
|
|
45
|
+
const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
|
|
46
|
+
(0, serializeConfigValue_js_1.serializeConfigValue)(lines, configName, { definedAt, valueSerialized });
|
|
47
|
+
});
|
|
48
|
+
Object.entries(pageConfig.configValueSources).forEach(([configName]) => {
|
|
35
49
|
const configValue = pageConfig.configValues[configName];
|
|
36
50
|
if (configValue) {
|
|
37
|
-
const configEnv = (0, helpers_js_1.getConfigEnv)(pageConfig, configName);
|
|
51
|
+
const configEnv = (0, helpers_js_1.getConfigEnv)(pageConfig.configValueSources, configName);
|
|
38
52
|
(0, utils_js_1.assert)(configEnv, configName);
|
|
39
|
-
|
|
53
|
+
const isEnvMatch = (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true });
|
|
54
|
+
if (!isEnvMatch)
|
|
40
55
|
return;
|
|
41
|
-
const { value,
|
|
42
|
-
const valueSerialized = getConfigValueSerialized(value, configName,
|
|
43
|
-
|
|
44
|
-
serializeConfigValue(lines, configName, configValue2);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
const configValueSource = sources[0];
|
|
48
|
-
(0, utils_js_1.assert)(configValueSource);
|
|
49
|
-
if (configValueSource.configEnv === '_routing-eager') {
|
|
50
|
-
const { definedAtInfo } = configValueSource;
|
|
51
|
-
(0, utils_js_1.assert)(!configValueSource.isComputed);
|
|
52
|
-
const { filePath, fileExportPath } = configValueSource.definedAtInfo;
|
|
53
|
-
const [exportName] = fileExportPath;
|
|
54
|
-
(0, utils_js_1.assert)(exportName);
|
|
55
|
-
const configValueEagerImport = getConfigValueEagerImport(filePath, exportName, importStatements);
|
|
56
|
-
const configValue = { definedAtInfo, value: configValueEagerImport };
|
|
57
|
-
serializeConfigValue(lines, configName, configValue);
|
|
58
|
-
}
|
|
56
|
+
const { value, definedAt } = configValue;
|
|
57
|
+
const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
|
|
58
|
+
(0, serializeConfigValue_js_1.serializeConfigValue)(lines, configName, { definedAt, valueSerialized });
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
lines.push(` },`);
|
|
62
|
+
let whitespace = ' ';
|
|
63
|
+
lines.push(`${whitespace}configValuesImported: [`);
|
|
64
|
+
Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
|
|
65
|
+
const configValue = pageConfig.configValues[configName];
|
|
66
|
+
if (configValue)
|
|
67
|
+
return;
|
|
68
|
+
const configValueSource = sources[0];
|
|
69
|
+
(0, utils_js_1.assert)(configValueSource);
|
|
70
|
+
if (configValueSource.configEnv !== '_routing-eager')
|
|
71
|
+
return;
|
|
72
|
+
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
73
|
+
});
|
|
74
|
+
lines.push(`${whitespace}],`);
|
|
75
|
+
// pageConfig end
|
|
62
76
|
lines.push(` },`);
|
|
63
77
|
});
|
|
64
78
|
lines.push('];');
|
|
65
|
-
lines.push('export const
|
|
66
|
-
|
|
79
|
+
lines.push('export const pageConfigGlobalSerialized = {');
|
|
80
|
+
/* Nothing (yet)
|
|
81
|
+
lines.push(` configValuesSerialized: {`)
|
|
82
|
+
lines.push(` },`)
|
|
83
|
+
*/
|
|
84
|
+
lines.push(` configValuesImported: [`);
|
|
85
|
+
(0, utils_js_1.objectEntries)(pageConfigGlobal.configValueSources).forEach(([configName, sources]) => {
|
|
67
86
|
if (configName === 'onBeforeRoute') {
|
|
68
87
|
// if( isForClientSide && !isClientRouting ) return
|
|
69
88
|
}
|
|
70
89
|
else if (configName === 'onPrerenderStart') {
|
|
71
90
|
if (isDev || isForClientSide) {
|
|
72
91
|
// Only load onPrerenderStart() in server production runtime
|
|
73
|
-
|
|
92
|
+
return;
|
|
74
93
|
}
|
|
75
94
|
}
|
|
76
95
|
else {
|
|
77
96
|
(0, utils_js_1.assert)(false);
|
|
78
97
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
content = serializeConfigValueSource(configValueSource, configName, whitespace, isForClientSide, isClientRouting, importStatements, true);
|
|
86
|
-
(0, utils_js_1.assert)(content.startsWith('{') && content.endsWith('},') && content.includes('\n'));
|
|
87
|
-
}
|
|
88
|
-
content = `${whitespace}[${JSON.stringify(configName)}]: ${content}`;
|
|
89
|
-
lines.push(content);
|
|
98
|
+
const configValueSource = sources[0];
|
|
99
|
+
(0, utils_js_1.assert)(configValueSource);
|
|
100
|
+
const whitespace = ' ';
|
|
101
|
+
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
90
102
|
});
|
|
103
|
+
lines.push(` ],`);
|
|
91
104
|
lines.push('};');
|
|
92
105
|
const code = [...importStatements, ...lines].join('\n');
|
|
93
106
|
(0, debug_js_1.debug)(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
94
107
|
return code;
|
|
95
108
|
}
|
|
96
|
-
function
|
|
97
|
-
let whitespace = ' ';
|
|
98
|
-
lines.push(`${whitespace}['${configName}']: {`);
|
|
99
|
-
whitespace += ' ';
|
|
100
|
-
Object.entries(configValue).forEach(([key, val]) => {
|
|
101
|
-
const valSerialized = key === 'value' || key === 'valueSerialized' ? val : JSON.stringify(val);
|
|
102
|
-
lines.push(`${whitespace} ${key}: ${valSerialized},`);
|
|
103
|
-
});
|
|
104
|
-
whitespace = whitespace.slice(2);
|
|
105
|
-
lines.push(`${whitespace}},`);
|
|
106
|
-
}
|
|
107
|
-
function serializeConfigValueSource(configValueSource, configName, whitespace, isForClientSide, isClientRouting, importStatements, isGlobalConfig) {
|
|
108
|
-
(0, utils_js_1.assert)(!configValueSource.isComputed);
|
|
109
|
-
const { definedAtInfo, configEnv } = configValueSource;
|
|
110
|
-
const lines = [];
|
|
111
|
-
lines.push(`{`);
|
|
112
|
-
lines.push(`${whitespace} definedAtInfo: ${JSON.stringify(definedAtInfo)},`);
|
|
113
|
-
lines.push(`${whitespace} configEnv: ${JSON.stringify(configEnv)},`);
|
|
114
|
-
const eager = configValueSource.configEnv === '_routing-eager' || isGlobalConfig;
|
|
115
|
-
if ((0, isConfigEnvMatch_js_1.isConfigEnvMatch)(configEnv, isForClientSide, isClientRouting) || eager) {
|
|
116
|
-
if ('value' in configValueSource) {
|
|
117
|
-
const { value } = configValueSource;
|
|
118
|
-
const valueSerialized = getConfigValueSerialized(value, configName, definedAtInfo);
|
|
119
|
-
lines.push(`${whitespace} valueSerialized: ${valueSerialized}`);
|
|
120
|
-
}
|
|
121
|
-
else if (eager) {
|
|
122
|
-
const { filePath, fileExportPath } = configValueSource.definedAtInfo;
|
|
123
|
-
const [exportName] = fileExportPath;
|
|
124
|
-
(0, utils_js_1.assert)(exportName);
|
|
125
|
-
const configValueEagerImport = getConfigValueEagerImport(filePath, exportName, importStatements);
|
|
126
|
-
lines.push(`${whitespace} value: ${configValueEagerImport},`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
lines.push(`${whitespace}},`);
|
|
130
|
-
return lines.join('\n');
|
|
131
|
-
}
|
|
132
|
-
function getConfigValueSerialized(value, configName, definedAtInfo) {
|
|
133
|
-
let configValueSerialized;
|
|
109
|
+
function getConfigValueSerialized(value, configName, definedAt) {
|
|
134
110
|
const valueName = `config${(0, utils_js_1.getPropAccessNotation)(configName)}`;
|
|
111
|
+
let configValueSerialized;
|
|
135
112
|
try {
|
|
136
113
|
configValueSerialized = (0, stringify_1.stringify)(value, { valueName });
|
|
137
114
|
}
|
|
138
115
|
catch (err) {
|
|
139
116
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(err, 'messageCore', 'string'));
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
// - cumulative => the values are already ensured to be serializable
|
|
143
|
-
(0, utils_js_1.assert)(definedAtInfo);
|
|
144
|
-
const configDefinedByFile = definedAtInfo.filePath;
|
|
145
|
-
(0, utils_js_1.assert)(configDefinedByFile);
|
|
117
|
+
const configValueFilePathToShowToUser = (0, utils_js_2.getConfigValueFilePathToShowToUser)({ definedAt });
|
|
118
|
+
(0, utils_js_1.assert)(configValueFilePathToShowToUser);
|
|
146
119
|
(0, utils_js_1.assertUsage)(false, [
|
|
147
|
-
`The value of the config ${picocolors_1.default.cyan(configName)} cannot be defined inside the file ${
|
|
148
|
-
`its value must be defined in an another file and then imported by ${
|
|
120
|
+
`The value of the config ${picocolors_1.default.cyan(configName)} cannot be defined inside the file ${configValueFilePathToShowToUser}:`,
|
|
121
|
+
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because the value isn't serializable: ${err.messageCore}.)`,
|
|
149
122
|
`Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
|
|
150
123
|
].join(' '));
|
|
151
124
|
}
|
|
@@ -153,11 +126,3 @@ function getConfigValueSerialized(value, configName, definedAtInfo) {
|
|
|
153
126
|
return configValueSerialized;
|
|
154
127
|
}
|
|
155
128
|
exports.getConfigValueSerialized = getConfigValueSerialized;
|
|
156
|
-
function getConfigValueEagerImport(importFilePath, exportName, importStatements) {
|
|
157
|
-
let configValueEagerImport;
|
|
158
|
-
const { importVar, importStatement } = (0, generateEagerImport_js_1.generateEagerImport)(importFilePath);
|
|
159
|
-
importStatements.push(importStatement);
|
|
160
|
-
// TODO: expose all exports so that assertDefaultExport can be applied
|
|
161
|
-
configValueEagerImport = `${importVar}[${JSON.stringify(exportName)}]`;
|
|
162
|
-
return configValueEagerImport;
|
|
163
|
-
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isConfigSet = exports.getConfigEnv = void 0;
|
|
4
|
-
const getConfigValueSource_js_1 = require("../../../shared/getConfigValueSource.js");
|
|
5
4
|
const utils_js_1 = require("../../../utils.js");
|
|
6
5
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
7
|
-
function getConfigEnv(
|
|
8
|
-
const configValueSource =
|
|
6
|
+
function getConfigEnv(configValueSources, configName) {
|
|
7
|
+
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
9
8
|
if (!configValueSource)
|
|
10
9
|
return null;
|
|
11
10
|
if (configValueSource) {
|
|
@@ -24,11 +23,19 @@ function getConfigEnv(pageConfig, configName) {
|
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
exports.getConfigEnv = getConfigEnv;
|
|
27
|
-
function isConfigSet(
|
|
28
|
-
const configValueSource =
|
|
26
|
+
function isConfigSet(configValueSources, configName) {
|
|
27
|
+
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
29
28
|
// Enable users to suppress global config values by overriding the config's value to null
|
|
30
29
|
if (configValueSource?.value === null)
|
|
31
30
|
return false;
|
|
32
31
|
return !!configValueSource;
|
|
33
32
|
}
|
|
34
33
|
exports.isConfigSet = isConfigSet;
|
|
34
|
+
function getConfigValueSource(configValueSources, configName) {
|
|
35
|
+
const sources = configValueSources[configName];
|
|
36
|
+
if (!sources)
|
|
37
|
+
return null;
|
|
38
|
+
const configValueSource = sources[0];
|
|
39
|
+
(0, utils_js_1.assert)(configValueSource);
|
|
40
|
+
return configValueSource;
|
|
41
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRuntimeEnvMatch = void 0;
|
|
4
|
+
function isRuntimeEnvMatch(configEnv, runtime) {
|
|
5
|
+
const { isForClientSide, isClientRouting, isEager } = runtime;
|
|
6
|
+
if (configEnv === 'config-only')
|
|
7
|
+
return false;
|
|
8
|
+
if (configEnv === (isForClientSide ? 'server-only' : 'client-only'))
|
|
9
|
+
return false;
|
|
10
|
+
if (configEnv === '_routing-eager' || configEnv === '_routing-lazy') {
|
|
11
|
+
if (isForClientSide && !isClientRouting)
|
|
12
|
+
return false;
|
|
13
|
+
if (isEager !== (configEnv === '_routing-eager'))
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
exports.isRuntimeEnvMatch = isRuntimeEnvMatch;
|
|
@@ -17,13 +17,13 @@ function replaceImportStatements(code, filePathToShowToUser) {
|
|
|
17
17
|
imports.forEach((node) => {
|
|
18
18
|
if (node.type !== 'ImportDeclaration')
|
|
19
19
|
return;
|
|
20
|
-
const
|
|
21
|
-
(0, utils_js_1.assert)(typeof
|
|
20
|
+
const importPath = node.source.value;
|
|
21
|
+
(0, utils_js_1.assert)(typeof importPath === 'string');
|
|
22
22
|
const { start, end } = node;
|
|
23
23
|
const importStatementCode = code.slice(start, end);
|
|
24
24
|
// No variable imported
|
|
25
25
|
if (node.specifiers.length === 0) {
|
|
26
|
-
const isWarning = !utils_js_1.styleFileRE.test(
|
|
26
|
+
const isWarning = !utils_js_1.styleFileRE.test(importPath);
|
|
27
27
|
let quote = indent(importStatementCode);
|
|
28
28
|
if (isWarning) {
|
|
29
29
|
quote = picocolors_1.default.cyan(quote);
|
|
@@ -46,7 +46,7 @@ function replaceImportStatements(code, filePathToShowToUser) {
|
|
|
46
46
|
specifier.type === 'ImportDefaultSpecifier' ||
|
|
47
47
|
specifier.type === 'ImportNamespaceSpecifier');
|
|
48
48
|
const importLocalName = specifier.local.name;
|
|
49
|
-
const
|
|
49
|
+
const exportName = (() => {
|
|
50
50
|
if (specifier.type === 'ImportDefaultSpecifier')
|
|
51
51
|
return 'default';
|
|
52
52
|
if (specifier.type === 'ImportNamespaceSpecifier')
|
|
@@ -58,11 +58,11 @@ function replaceImportStatements(code, filePathToShowToUser) {
|
|
|
58
58
|
}
|
|
59
59
|
return importLocalName;
|
|
60
60
|
})();
|
|
61
|
-
const
|
|
62
|
-
replacement += `const ${importLocalName} = '${
|
|
61
|
+
const importString = serializeImportData({ importPath, exportName, importStringWasGenerated: true });
|
|
62
|
+
replacement += `const ${importLocalName} = '${importString}';`;
|
|
63
63
|
fileImports.push({
|
|
64
64
|
importStatementCode,
|
|
65
|
-
|
|
65
|
+
importString,
|
|
66
66
|
importLocalName
|
|
67
67
|
});
|
|
68
68
|
});
|
|
@@ -92,35 +92,35 @@ function getImports(code) {
|
|
|
92
92
|
const import_ = 'import';
|
|
93
93
|
const SEP = ':';
|
|
94
94
|
const zeroWidthSpace = '\u200b';
|
|
95
|
-
function serializeImportData({
|
|
96
|
-
const tag =
|
|
97
|
-
// `import:${
|
|
98
|
-
return `${tag}${import_}${SEP}${
|
|
95
|
+
function serializeImportData({ importPath, exportName, importStringWasGenerated }) {
|
|
96
|
+
const tag = importStringWasGenerated ? zeroWidthSpace : '';
|
|
97
|
+
// `import:${importPath}:${importPath}`
|
|
98
|
+
return `${tag}${import_}${SEP}${importPath}${SEP}${exportName}`;
|
|
99
99
|
}
|
|
100
100
|
function isImportData(str) {
|
|
101
101
|
return str.startsWith(import_ + SEP) || str.startsWith(zeroWidthSpace + import_ + SEP);
|
|
102
102
|
}
|
|
103
103
|
exports.isImportData = isImportData;
|
|
104
|
-
function parseImportData(
|
|
105
|
-
if (!isImportData(
|
|
104
|
+
function parseImportData(importString) {
|
|
105
|
+
if (!isImportData(importString)) {
|
|
106
106
|
return null;
|
|
107
107
|
}
|
|
108
|
-
let
|
|
109
|
-
if (
|
|
110
|
-
|
|
108
|
+
let importStringWasGenerated = false;
|
|
109
|
+
if (importString.startsWith(zeroWidthSpace)) {
|
|
110
|
+
importStringWasGenerated = true;
|
|
111
111
|
(0, utils_js_1.assert)(zeroWidthSpace.length === 1);
|
|
112
|
-
|
|
112
|
+
importString = importString.slice(1);
|
|
113
113
|
}
|
|
114
|
-
const parts =
|
|
115
|
-
if (!
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
return {
|
|
114
|
+
const parts = importString.split(SEP).slice(1);
|
|
115
|
+
if (!importStringWasGenerated && parts.length === 1) {
|
|
116
|
+
const exportName = 'default';
|
|
117
|
+
const importPath = parts[0];
|
|
118
|
+
return { importPath, exportName, importStringWasGenerated, importString };
|
|
119
119
|
}
|
|
120
120
|
(0, utils_js_1.assert)(parts.length >= 2);
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
return {
|
|
121
|
+
const exportName = parts[parts.length - 1];
|
|
122
|
+
const importPath = parts.slice(0, -1).join(SEP);
|
|
123
|
+
return { importPath, exportName, importStringWasGenerated, importString };
|
|
124
124
|
}
|
|
125
125
|
exports.parseImportData = parseImportData;
|
|
126
126
|
function spliceMany(str, operations) {
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isTmpFile = exports.
|
|
6
|
+
exports.isTmpFile = exports.getConfigExecutionErrorIntroMsg = exports.getConfigBuildErrorFormatted = exports.transpileAndExecuteFile = void 0;
|
|
7
7
|
const esbuild_1 = require("esbuild");
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -14,10 +14,11 @@ const replaceImportStatements_js_1 = require("./replaceImportStatements.js");
|
|
|
14
14
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
15
15
|
require("source-map-support/register.js");
|
|
16
16
|
const getFilePathToShowToUser_js_1 = require("./getFilePathToShowToUser.js");
|
|
17
|
+
const assertExports_js_1 = require("../../../../../shared/page-configs/assertExports.js");
|
|
17
18
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
18
19
|
async function transpileAndExecuteFile(filePath, isValueFile, userRootDir) {
|
|
19
20
|
const { code, fileImports } = await transpileFile(filePath, isValueFile, userRootDir);
|
|
20
|
-
const { fileExports } = await executeFile(filePath, code, fileImports);
|
|
21
|
+
const { fileExports } = await executeFile(filePath, code, fileImports, isValueFile);
|
|
21
22
|
return { fileExports };
|
|
22
23
|
}
|
|
23
24
|
exports.transpileAndExecuteFile = transpileAndExecuteFile;
|
|
@@ -135,7 +136,7 @@ async function transpileWithEsbuild(filePath, bundle, userRootDir) {
|
|
|
135
136
|
(0, utils_js_1.assert)(typeof code === 'string');
|
|
136
137
|
return code;
|
|
137
138
|
}
|
|
138
|
-
async function executeFile(filePath, code, fileImports) {
|
|
139
|
+
async function executeFile(filePath, code, fileImports, isValueFile) {
|
|
139
140
|
const { filePathAbsolute, filePathRelativeToUserRootDir } = filePath;
|
|
140
141
|
// Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
|
|
141
142
|
// - But seems to break source maps, so I don't think it's worth it
|
|
@@ -160,10 +161,10 @@ async function executeFile(filePath, code, fileImports) {
|
|
|
160
161
|
// - import() returns `[Module: null prototype] { default: { onRenderClient: '...' }}`
|
|
161
162
|
// - We don't need this special object
|
|
162
163
|
fileExports = { ...fileExports };
|
|
163
|
-
if (fileImports) {
|
|
164
|
+
if (fileImports && !isValueFile) {
|
|
164
165
|
(0, utils_js_1.assert)(filePathRelativeToUserRootDir !== undefined);
|
|
165
|
-
const
|
|
166
|
-
|
|
166
|
+
const filePathToShowToUser = filePathRelativeToUserRootDir ?? filePathAbsolute;
|
|
167
|
+
assertImportsAreReExported(fileImports, fileExports, filePathToShowToUser);
|
|
167
168
|
}
|
|
168
169
|
return { fileExports };
|
|
169
170
|
}
|
|
@@ -189,13 +190,13 @@ async function formatBuildErr(err, filePath) {
|
|
|
189
190
|
err[formatted] = `${msgIntro}\n${msgEsbuild}`;
|
|
190
191
|
}
|
|
191
192
|
const execErrIntroMsg = new WeakMap();
|
|
192
|
-
function
|
|
193
|
+
function getConfigExecutionErrorIntroMsg(err) {
|
|
193
194
|
if (!(0, utils_js_1.isObject)(err))
|
|
194
195
|
return null;
|
|
195
196
|
const errIntroMsg = execErrIntroMsg.get(err);
|
|
196
197
|
return errIntroMsg ?? null;
|
|
197
198
|
}
|
|
198
|
-
exports.
|
|
199
|
+
exports.getConfigExecutionErrorIntroMsg = getConfigExecutionErrorIntroMsg;
|
|
199
200
|
const tmpPrefix = `[build-`;
|
|
200
201
|
function getFilePathTmp(filePath) {
|
|
201
202
|
(0, utils_js_1.assertPosixPath)(filePath);
|
|
@@ -212,17 +213,17 @@ function isTmpFile(filePath) {
|
|
|
212
213
|
return fileName.startsWith(tmpPrefix);
|
|
213
214
|
}
|
|
214
215
|
exports.isTmpFile = isTmpFile;
|
|
215
|
-
function
|
|
216
|
-
(0,
|
|
216
|
+
function assertImportsAreReExported(fileImports, fileExports, filePathToShowToUser) {
|
|
217
|
+
(0, assertExports_js_1.assertExportsOfConfigFile)(fileExports, filePathToShowToUser);
|
|
217
218
|
const exportedStrings = getExportedStrings(fileExports.default);
|
|
218
219
|
Object.values(exportedStrings).forEach((exportVal) => {
|
|
219
220
|
if (typeof exportVal !== 'string')
|
|
220
221
|
return;
|
|
221
222
|
if (!(0, replaceImportStatements_js_1.isImportData)(exportVal))
|
|
222
223
|
return;
|
|
223
|
-
const
|
|
224
|
+
const importString = exportVal;
|
|
224
225
|
fileImports.forEach((fileImport) => {
|
|
225
|
-
if (fileImport.
|
|
226
|
+
if (fileImport.importString === importString) {
|
|
226
227
|
fileImport.isReExported = true;
|
|
227
228
|
}
|
|
228
229
|
});
|
|
@@ -234,7 +235,7 @@ function assertFileImports(fileImports, fileExports, filePath) {
|
|
|
234
235
|
const importNamesUnused = fileImportsUnused.map((fi) => picocolors_1.default.cyan(fi.importLocalName)).join(', ');
|
|
235
236
|
const singular = fileImportsUnused.length === 1;
|
|
236
237
|
(0, utils_js_1.assertUsage)(fileImportsUnused.length === 0, [
|
|
237
|
-
`${
|
|
238
|
+
`${filePathToShowToUser} imports the following:`,
|
|
238
239
|
...importStatements.map((s) => picocolors_1.default.cyan(` ${s}`)),
|
|
239
240
|
`But the import${singular ? '' : 's'} ${importNamesUnused} ${singular ? "isn't" : "aren't"} re-exported at ${picocolors_1.default.cyan('export default { ... }')} and therefore ${singular ? 'has' : 'have'} no effect, see explanation at https://vike.dev/header-file`
|
|
240
241
|
].join('\n'));
|
|
@@ -9,8 +9,9 @@ const utils_js_1 = require("../utils.js");
|
|
|
9
9
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
10
|
async function findPageFiles(config, fileTypes, isDev) {
|
|
11
11
|
const cwd = config.root;
|
|
12
|
+
const { outDirRoot } = (0, utils_js_1.getOutDirs)(config);
|
|
12
13
|
const timeBase = new Date().getTime();
|
|
13
|
-
let pageFiles = await (0, fast_glob_1.default)(fileTypes.map((fileType) => `**/*${fileType}.${utils_js_1.scriptFileExtensions}`), { ignore: ['**/node_modules/**'], cwd, dot: false });
|
|
14
|
+
let pageFiles = await (0, fast_glob_1.default)(fileTypes.map((fileType) => `**/*${fileType}.${utils_js_1.scriptFileExtensions}`), { ignore: ['**/node_modules/**', `${outDirRoot}/**`], cwd, dot: false });
|
|
14
15
|
pageFiles = pageFiles.map((p) => '/' + (0, utils_js_1.toPosixPath)(p));
|
|
15
16
|
const time = new Date().getTime() - timeBase;
|
|
16
17
|
if (isDev) {
|
package/dist/cjs/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js}
RENAMED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConfigValueSourcesRelevant =
|
|
3
|
+
exports.getConfigValueSourcesRelevant = void 0;
|
|
4
4
|
const utils_js_1 = require("../../shared/utils.js");
|
|
5
5
|
(0, utils_js_1.assertIsNotBrowser)();
|
|
6
|
-
function getConfigValueSource(pageConfig, configName) {
|
|
7
|
-
// Doesn't exist on the client-side, but we are on the server-side as attested by assertIsNotBrowser()
|
|
8
|
-
(0, utils_js_1.assert)(pageConfig.configValueSources);
|
|
9
|
-
const sources = pageConfig.configValueSources[configName];
|
|
10
|
-
if (!sources)
|
|
11
|
-
return null;
|
|
12
|
-
const configValueSource = sources[0];
|
|
13
|
-
(0, utils_js_1.assert)(configValueSource);
|
|
14
|
-
return configValueSource;
|
|
15
|
-
}
|
|
16
|
-
exports.getConfigValueSource = getConfigValueSource;
|
|
17
6
|
function getConfigValueSourcesRelevant(pageConfig) {
|
|
18
7
|
const configValueSourcesRelevant = Object.entries(pageConfig.configValueSources).map(([configName, sources]) => {
|
|
19
8
|
const configValueSource = sources[0];
|
|
@@ -111,7 +111,7 @@ function logConfigError(err) {
|
|
|
111
111
|
(0, utils_js_1.warnIfErrorIsNotObject)(err);
|
|
112
112
|
const category = getConfigCategory();
|
|
113
113
|
{
|
|
114
|
-
const errIntroMsg = (0, transpileAndExecuteFile_js_1.
|
|
114
|
+
const errIntroMsg = (0, transpileAndExecuteFile_js_1.getConfigExecutionErrorIntroMsg)(err);
|
|
115
115
|
if (errIntroMsg) {
|
|
116
116
|
(0, utils_js_1.assert)((0, utils_js_1.stripAnsi)(errIntroMsg).startsWith('Failed to execute'));
|
|
117
117
|
(0, log_js_1.logWithVikeTag)(errIntroMsg, 'error', category);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Utils needed by
|
|
2
|
+
// Utils needed by Vike's Vite plugin.
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -24,8 +24,7 @@ __exportStar(require("../runtime/utils.js"), exports);
|
|
|
24
24
|
__exportStar(require("../../utils/viteIsSSR.js"), exports);
|
|
25
25
|
__exportStar(require("../../utils/getFilePathAbsolute.js"), exports);
|
|
26
26
|
__exportStar(require("../../utils/getDependencyPackageJson.js"), exports);
|
|
27
|
-
__exportStar(require("../../utils/
|
|
28
|
-
__exportStar(require("../../utils/assertDefaultExport.js"), exports);
|
|
27
|
+
__exportStar(require("../../utils/requireResolve.js"), exports);
|
|
29
28
|
__exportStar(require("../../utils/arrayIncludes.js"), exports);
|
|
30
29
|
__exportStar(require("../../utils/isDev.js"), exports);
|
|
31
30
|
__exportStar(require("../../utils/objectKeys.js"), exports);
|