vike 0.4.146-commit-701e2e5 → 0.4.147
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 +6 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +76 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +61 -40
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +57 -40
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +43 -17
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +12 -70
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +11 -8
- package/dist/cjs/node/plugin/shared/{getConfigValueSourcesRelevant.js → getConfigValueSourcesNotOverriden.js} +3 -3
- package/dist/cjs/node/plugin/utils.js +2 -0
- package/dist/cjs/node/prerender/runPrerender.js +20 -15
- package/dist/cjs/node/runtime/index-common.js +3 -1
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -2
- package/dist/cjs/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +12 -3
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +19 -0
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +3 -12
- package/dist/cjs/utils/assertKeys.js +28 -0
- package/dist/cjs/utils/joinEnglish.js +3 -3
- package/dist/cjs/utils/projectInfo.js +3 -2
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +6 -2
- 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/node/plugin/index.d.ts +1 -0
- package/dist/esm/node/plugin/index.js +1 -0
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +70 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +58 -37
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +58 -41
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +43 -17
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +13 -68
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +11 -8
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.d.ts +5 -0
- package/dist/esm/node/plugin/shared/{getConfigValueSourcesRelevant.js → getConfigValueSourcesNotOverriden.js} +2 -2
- package/dist/esm/node/plugin/utils.d.ts +2 -0
- package/dist/esm/node/plugin/utils.js +2 -0
- package/dist/esm/node/prerender/runPrerender.js +20 -15
- package/dist/esm/node/runtime/index-common.d.ts +1 -0
- package/dist/esm/node/runtime/index-common.js +1 -0
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -2
- package/dist/esm/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +14 -4
- package/dist/esm/shared/page-configs/loadConfigValues.js +12 -3
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.d.ts +4 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +16 -0
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +4 -13
- package/dist/esm/utils/assertKeys.d.ts +4 -0
- package/dist/esm/utils/assertKeys.js +22 -0
- package/dist/esm/utils/joinEnglish.d.ts +1 -1
- package/dist/esm/utils/joinEnglish.js +3 -3
- package/dist/esm/utils/projectInfo.d.ts +3 -1
- package/dist/esm/utils/projectInfo.js +2 -1
- package/package.json +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +0 -28
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +0 -25
- package/dist/esm/node/plugin/shared/getConfigValueSourcesRelevant.d.ts +0 -5
|
@@ -3,9 +3,11 @@ 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.ssr = exports.plugin = void 0;
|
|
6
|
+
exports.version = exports.ssr = exports.plugin = void 0;
|
|
7
7
|
exports.default = plugin;
|
|
8
|
-
|
|
8
|
+
var utils_js_1 = require("./utils.js");
|
|
9
|
+
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return utils_js_1.PROJECT_VERSION; } });
|
|
10
|
+
const utils_js_2 = require("./utils.js");
|
|
9
11
|
const buildConfig_js_1 = require("./plugins/buildConfig.js");
|
|
10
12
|
const previewConfig_js_1 = require("./plugins/previewConfig.js");
|
|
11
13
|
const autoFullBuild_js_1 = require("./plugins/autoFullBuild.js");
|
|
@@ -26,7 +28,7 @@ const extensionsAssets_js_1 = require("./plugins/extensionsAssets.js");
|
|
|
26
28
|
const baseUrls_js_1 = require("./plugins/baseUrls.js");
|
|
27
29
|
const envVars_js_1 = require("./plugins/envVars.js");
|
|
28
30
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
29
|
-
(0,
|
|
31
|
+
(0, utils_js_2.markEnvAsVite)();
|
|
30
32
|
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
31
33
|
function plugin(vikeConfig) {
|
|
32
34
|
const plugins = [
|
|
@@ -65,6 +67,6 @@ catch { }
|
|
|
65
67
|
Object.defineProperty(plugin, 'apply', {
|
|
66
68
|
enumerable: true,
|
|
67
69
|
get: () => {
|
|
68
|
-
(0,
|
|
70
|
+
(0, utils_js_2.assertUsage)(false, `Add ${picocolors_1.default.cyan('vike()')} instead of ${picocolors_1.default.cyan('vike')} to vite.config.js#plugins (i.e. call the function and add the return value instead of adding the function itself)`, { showStackTrace: true });
|
|
69
71
|
}
|
|
70
72
|
});
|
|
@@ -4,7 +4,7 @@ exports.determineOptimizeDeps = void 0;
|
|
|
4
4
|
const findPageFiles_js_1 = require("../../shared/findPageFiles.js");
|
|
5
5
|
const utils_js_1 = require("../../utils.js");
|
|
6
6
|
const getVikeConfig_js_1 = require("../importUserCode/v1-design/getVikeConfig.js");
|
|
7
|
-
const
|
|
7
|
+
const getConfigValueSourcesNotOverriden_js_1 = require("../../shared/getConfigValueSourcesNotOverriden.js");
|
|
8
8
|
const buildConfig_js_1 = require("../buildConfig.js");
|
|
9
9
|
const virtualFileImportUserCode_js_1 = require("../../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
10
10
|
async function determineOptimizeDeps(config, configVike, isDev) {
|
|
@@ -33,12 +33,11 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
33
33
|
// V1 design
|
|
34
34
|
{
|
|
35
35
|
pageConfigs.forEach((pageConfig) => {
|
|
36
|
-
|
|
37
|
-
configValueSourcesRelevant.forEach((configValueSource) => {
|
|
36
|
+
(0, getConfigValueSourcesNotOverriden_js_1.getConfigValueSourcesNotOverriden)(pageConfig).forEach((configValueSource) => {
|
|
38
37
|
if (!configValueSource.valueIsImportedAtRuntime)
|
|
39
38
|
return;
|
|
40
39
|
const { definedAt, configEnv } = configValueSource;
|
|
41
|
-
if (configEnv
|
|
40
|
+
if (!configEnv.client)
|
|
42
41
|
return;
|
|
43
42
|
if (definedAt.filePathRelativeToUserRootDir !== null) {
|
|
44
43
|
const { filePathAbsoluteFilesystem } = definedAt;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.assertConfigValueIsSerializable = exports.getConfigValuesSerialized = void 0;
|
|
7
|
+
const utils_js_1 = require("../../../utils.js");
|
|
8
|
+
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
9
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
|
+
const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
|
|
11
|
+
const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
|
|
12
|
+
const getConfigValueSourcesNotOverriden_js_1 = require("../../../shared/getConfigValueSourcesNotOverriden.js");
|
|
13
|
+
function getConfigValuesSerialized(pageConfig, isEnvMatch) {
|
|
14
|
+
const lines = [];
|
|
15
|
+
Object.entries(pageConfig.configValuesComputed).forEach(([configName, configValuesComputed]) => {
|
|
16
|
+
const { value, configEnv } = configValuesComputed;
|
|
17
|
+
if (!isEnvMatch(configEnv))
|
|
18
|
+
return;
|
|
19
|
+
// configValeSources has higher precedence
|
|
20
|
+
if (pageConfig.configValueSources[configName])
|
|
21
|
+
return;
|
|
22
|
+
const configValue = pageConfig.configValues[configName];
|
|
23
|
+
(0, utils_js_1.assert)(configValue);
|
|
24
|
+
const { definedAt } = configValue;
|
|
25
|
+
const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
|
|
26
|
+
(0, serializeConfigValue_js_1.serializeConfigValue)(lines, configName, { definedAt, valueSerialized });
|
|
27
|
+
});
|
|
28
|
+
(0, getConfigValueSourcesNotOverriden_js_1.getConfigValueSourcesNotOverriden)(pageConfig).forEach((configValueSource) => {
|
|
29
|
+
const { configName, configEnv } = configValueSource;
|
|
30
|
+
const configValue = pageConfig.configValues[configName];
|
|
31
|
+
if (!configValue)
|
|
32
|
+
return;
|
|
33
|
+
if (!isEnvMatch(configEnv, configValueSource)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const { value, definedAt } = configValue;
|
|
37
|
+
const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
|
|
38
|
+
(0, serializeConfigValue_js_1.serializeConfigValue)(lines, configName, { definedAt, valueSerialized });
|
|
39
|
+
});
|
|
40
|
+
const code = lines.join('\n');
|
|
41
|
+
return code;
|
|
42
|
+
}
|
|
43
|
+
exports.getConfigValuesSerialized = getConfigValuesSerialized;
|
|
44
|
+
function assertConfigValueIsSerializable(value, configName, definedAt) {
|
|
45
|
+
// Contains asserts
|
|
46
|
+
getConfigValueSerialized(value, configName, definedAt);
|
|
47
|
+
}
|
|
48
|
+
exports.assertConfigValueIsSerializable = assertConfigValueIsSerializable;
|
|
49
|
+
function getConfigValueSerialized(value, configName, definedAt) {
|
|
50
|
+
const valueName = `config${(0, utils_js_1.getPropAccessNotation)(configName)}`;
|
|
51
|
+
let configValueSerialized;
|
|
52
|
+
try {
|
|
53
|
+
configValueSerialized = (0, stringify_1.stringify)(value, { valueName, forbidReactElements: true });
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
let serializationErrMsg = '';
|
|
57
|
+
if ((0, stringify_1.isJsonSerializerError)(err)) {
|
|
58
|
+
serializationErrMsg = err.messageCore;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// When a property getter throws an error
|
|
62
|
+
console.error('Serialization error:');
|
|
63
|
+
console.error(err);
|
|
64
|
+
serializationErrMsg = 'see serialization error printed above';
|
|
65
|
+
}
|
|
66
|
+
const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)({ definedAt });
|
|
67
|
+
(0, utils_js_1.assert)(configValueFilePathToShowToUser);
|
|
68
|
+
(0, utils_js_1.assertUsage)(false, [
|
|
69
|
+
`The value of the config ${picocolors_1.default.cyan(configName)} cannot be defined inside the file ${configValueFilePathToShowToUser}:`,
|
|
70
|
+
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because its value isn't serializable: ${serializationErrMsg}.)`,
|
|
71
|
+
`Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
|
|
72
|
+
].join(' '));
|
|
73
|
+
}
|
|
74
|
+
configValueSerialized = JSON.stringify(configValueSerialized);
|
|
75
|
+
return configValueSerialized;
|
|
76
|
+
}
|
|
@@ -1,101 +1,122 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.configDefinitionsBuiltInGlobal = exports.configDefinitionsBuiltIn = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_js_1 = require("../../../../utils.js");
|
|
5
5
|
const configDefinitionsBuiltIn = {
|
|
6
6
|
onRenderHtml: {
|
|
7
|
-
env:
|
|
7
|
+
env: { server: true }
|
|
8
8
|
},
|
|
9
9
|
onRenderClient: {
|
|
10
|
-
env:
|
|
10
|
+
env: { client: true }
|
|
11
11
|
},
|
|
12
12
|
onHydrationEnd: {
|
|
13
|
-
env:
|
|
13
|
+
env: { client: true }
|
|
14
14
|
},
|
|
15
15
|
onPageTransitionStart: {
|
|
16
|
-
env:
|
|
16
|
+
env: { client: true }
|
|
17
17
|
},
|
|
18
18
|
onPageTransitionEnd: {
|
|
19
|
-
env:
|
|
19
|
+
env: { client: true }
|
|
20
20
|
},
|
|
21
21
|
onBeforeRender: {
|
|
22
|
-
env:
|
|
22
|
+
env: { server: true }
|
|
23
23
|
},
|
|
24
24
|
onBeforePrerenderStart: {
|
|
25
|
-
env:
|
|
25
|
+
env: { server: true }
|
|
26
26
|
},
|
|
27
27
|
Page: {
|
|
28
|
-
env:
|
|
28
|
+
env: { server: true, client: true }
|
|
29
29
|
},
|
|
30
30
|
passToClient: {
|
|
31
|
-
env:
|
|
31
|
+
env: { server: true, config: true },
|
|
32
32
|
cumulative: true
|
|
33
33
|
},
|
|
34
34
|
route: {
|
|
35
|
-
env: '
|
|
35
|
+
env: { server: true, client: 'if-client-routing', eager: true }
|
|
36
36
|
},
|
|
37
37
|
guard: {
|
|
38
|
-
env: '
|
|
38
|
+
env: { server: true, client: 'if-client-routing' }
|
|
39
39
|
},
|
|
40
40
|
iKnowThePerformanceRisksOfAsyncRouteFunctions: {
|
|
41
|
-
env: '
|
|
41
|
+
env: { server: true, client: 'if-client-routing', eager: true }
|
|
42
42
|
},
|
|
43
43
|
filesystemRoutingRoot: {
|
|
44
|
-
env:
|
|
44
|
+
env: { config: true }
|
|
45
45
|
},
|
|
46
46
|
client: {
|
|
47
47
|
// The value of the client config is merely the file path to the client entry file, which is only needed on the sever-side
|
|
48
|
-
env:
|
|
48
|
+
env: { server: true },
|
|
49
49
|
_valueIsFilePath: true
|
|
50
50
|
},
|
|
51
51
|
clientRouting: {
|
|
52
|
-
// We could make it
|
|
53
|
-
env:
|
|
52
|
+
// We could make it { client: false } but we don't yet because of some legacy V0.4 design code
|
|
53
|
+
env: { server: true, client: true, config: true, eager: true }
|
|
54
54
|
},
|
|
55
55
|
prerender: {
|
|
56
|
-
env:
|
|
56
|
+
env: { config: true }
|
|
57
57
|
},
|
|
58
58
|
hydrationCanBeAborted: {
|
|
59
|
-
env:
|
|
59
|
+
env: { client: true }
|
|
60
60
|
},
|
|
61
61
|
prefetchStaticAssets: {
|
|
62
|
-
env:
|
|
62
|
+
env: { client: true }
|
|
63
63
|
},
|
|
64
64
|
extends: {
|
|
65
|
-
env:
|
|
65
|
+
env: { config: true }
|
|
66
66
|
},
|
|
67
67
|
meta: {
|
|
68
|
-
env:
|
|
68
|
+
env: { config: true }
|
|
69
69
|
},
|
|
70
70
|
isClientSideRenderable: {
|
|
71
|
-
env:
|
|
72
|
-
_computed: (configValueSources) =>
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
env: { server: true, client: true, eager: true },
|
|
72
|
+
_computed: (configValueSources) => isConfigSet(configValueSources, 'onRenderClient') &&
|
|
73
|
+
isConfigSet(configValueSources, 'Page') &&
|
|
74
|
+
!!getConfigEnv(configValueSources, 'Page')?.client
|
|
75
75
|
},
|
|
76
76
|
onBeforeRenderEnv: {
|
|
77
|
-
env:
|
|
78
|
-
_computed: (configValueSources) => !
|
|
77
|
+
env: { client: true },
|
|
78
|
+
_computed: (configValueSources) => !isConfigSet(configValueSources, 'onBeforeRender') ? null : getConfigEnv(configValueSources, 'onBeforeRender')
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
exports.configDefinitionsBuiltIn = configDefinitionsBuiltIn;
|
|
82
82
|
const configDefinitionsBuiltInGlobal = {
|
|
83
83
|
onPrerenderStart: {
|
|
84
|
-
env:
|
|
84
|
+
env: { server: true }
|
|
85
85
|
},
|
|
86
86
|
onBeforeRoute: {
|
|
87
|
-
env: '
|
|
87
|
+
env: { server: true, client: 'if-client-routing', eager: true }
|
|
88
88
|
},
|
|
89
89
|
prerender: {
|
|
90
|
-
env:
|
|
91
|
-
},
|
|
92
|
-
extensions: { env:
|
|
93
|
-
disableAutoFullBuild: { env:
|
|
94
|
-
includeAssetsImportedByServer: { env:
|
|
95
|
-
baseAssets: { env:
|
|
96
|
-
baseServer: { env:
|
|
97
|
-
redirects: { env:
|
|
98
|
-
trailingSlash: { env:
|
|
99
|
-
disableUrlNormalization: { env:
|
|
90
|
+
env: { config: true }
|
|
91
|
+
},
|
|
92
|
+
extensions: { env: { config: true } },
|
|
93
|
+
disableAutoFullBuild: { env: { config: true } },
|
|
94
|
+
includeAssetsImportedByServer: { env: { config: true } },
|
|
95
|
+
baseAssets: { env: { config: true } },
|
|
96
|
+
baseServer: { env: { config: true } },
|
|
97
|
+
redirects: { env: { server: true } },
|
|
98
|
+
trailingSlash: { env: { server: true } },
|
|
99
|
+
disableUrlNormalization: { env: { server: true } }
|
|
100
100
|
};
|
|
101
101
|
exports.configDefinitionsBuiltInGlobal = configDefinitionsBuiltInGlobal;
|
|
102
|
+
function getConfigEnv(configValueSources, configName) {
|
|
103
|
+
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
104
|
+
if (!configValueSource)
|
|
105
|
+
return null;
|
|
106
|
+
return configValueSource.configEnv;
|
|
107
|
+
}
|
|
108
|
+
function isConfigSet(configValueSources, configName) {
|
|
109
|
+
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
110
|
+
// Enable users to suppress global config values by overriding the config's value to null
|
|
111
|
+
if (configValueSource?.value === null)
|
|
112
|
+
return false;
|
|
113
|
+
return !!configValueSource;
|
|
114
|
+
}
|
|
115
|
+
function getConfigValueSource(configValueSources, configName) {
|
|
116
|
+
const sources = configValueSources[configName];
|
|
117
|
+
if (!sources)
|
|
118
|
+
return null;
|
|
119
|
+
const configValueSource = sources[0];
|
|
120
|
+
(0, utils_js_1.assert)(configValueSource);
|
|
121
|
+
return configValueSource;
|
|
122
|
+
}
|
|
@@ -18,8 +18,8 @@ const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/remove
|
|
|
18
18
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
19
19
|
const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
|
|
20
20
|
const assertExports_js_1 = require("../../../../../shared/page-configs/assertExports.js");
|
|
21
|
-
const getVirtualFilePageConfigs_js_1 = require("./getVirtualFilePageConfigs.js");
|
|
22
21
|
const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
|
|
22
|
+
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
23
23
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
24
24
|
let devServerIsCorrupt = false;
|
|
25
25
|
let wasConfigInvalid = null;
|
|
@@ -156,12 +156,12 @@ async function loadImportedFile(filePath, userRootDir, importedFilesLoaded) {
|
|
|
156
156
|
return fileExports;
|
|
157
157
|
}
|
|
158
158
|
function isConfigEnv(configDef, configName) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return
|
|
159
|
+
const configEnv = configDef.env;
|
|
160
|
+
if (configDef.cumulative) {
|
|
161
|
+
// In principle we could lift that requirement (but it requires non-trivial modifications)
|
|
162
|
+
(0, utils_js_1.assertUsage)(configEnv.config, `Config ${picocolors_1.default.cyan(configName)} needs its ${picocolors_1.default.cyan('env')} to have ${picocolors_1.default.cyan('{ config: true }')} (because ${picocolors_1.default.cyan(configName)} is a ${picocolors_1.default.cyan('cumulative')} config)`);
|
|
163
|
+
}
|
|
164
|
+
return !!configEnv.config;
|
|
165
165
|
}
|
|
166
166
|
function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
167
167
|
const { fileExports, filePath, extendsFilePaths } = configFile;
|
|
@@ -514,6 +514,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
514
514
|
}
|
|
515
515
|
else if (interfaceFile.isValueFile) {
|
|
516
516
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
517
|
+
(0, utils_js_1.assert)(valueAlreadyLoaded === !!configEnv.config);
|
|
517
518
|
const configValueSource = {
|
|
518
519
|
configEnv,
|
|
519
520
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
@@ -528,9 +529,6 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
528
529
|
if (valueAlreadyLoaded) {
|
|
529
530
|
configValueSource.value = conf.configValue;
|
|
530
531
|
}
|
|
531
|
-
else {
|
|
532
|
-
(0, utils_js_1.assert)(configEnv !== 'config-only');
|
|
533
|
-
}
|
|
534
532
|
return configValueSource;
|
|
535
533
|
}
|
|
536
534
|
(0, utils_js_1.assert)(false);
|
|
@@ -542,12 +540,12 @@ function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
|
542
540
|
}
|
|
543
541
|
const fileEnv = filesEnv.get(filePathForEnvCheck);
|
|
544
542
|
fileEnv.push({ configEnv, configName });
|
|
545
|
-
const configDifferentEnv = fileEnv.filter((c) => c.configEnv
|
|
543
|
+
const configDifferentEnv = fileEnv.filter((c) => !(0, utils_js_1.deepEqual)(c.configEnv, configEnv))[0];
|
|
546
544
|
if (configDifferentEnv) {
|
|
547
545
|
(0, utils_js_1.assertUsage)(false, [
|
|
548
546
|
`${filePathForEnvCheck} defines the value of configs living in different environments:`,
|
|
549
|
-
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.cyan(c.configName)} which value lives in environment ${picocolors_1.default.cyan(c.configEnv)}`),
|
|
550
|
-
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file
|
|
547
|
+
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.cyan(c.configName)} which value lives in environment ${picocolors_1.default.cyan(JSON.stringify(c.configEnv))}`),
|
|
548
|
+
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file'
|
|
551
549
|
].join('\n'));
|
|
552
550
|
}
|
|
553
551
|
}
|
|
@@ -683,30 +681,17 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
683
681
|
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}`)} to a value with an invalid type ${picocolors_1.default.cyan(typeof def)}: it should be an object instead.`);
|
|
684
682
|
}
|
|
685
683
|
// env
|
|
684
|
+
let configEnv;
|
|
686
685
|
{
|
|
687
|
-
|
|
688
|
-
'client-only',
|
|
689
|
-
'server-only',
|
|
690
|
-
'server-and-client',
|
|
691
|
-
'config-only'
|
|
692
|
-
];
|
|
693
|
-
const fix = [
|
|
694
|
-
`Set the value of ${picocolors_1.default.cyan(`meta.${configName}.env`)} to `,
|
|
695
|
-
(0, utils_js_1.joinEnglish)(envValues.map((s) => picocolors_1.default.cyan(`'${s}'`)), 'or'),
|
|
696
|
-
'.'
|
|
697
|
-
].join('');
|
|
686
|
+
(0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
698
687
|
if (!('env' in def)) {
|
|
699
|
-
(0, utils_js_1.
|
|
700
|
-
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} doesn't set ${picocolors_1.default.cyan(`meta.${configName}.env`)} but it's required. ${fix}`);
|
|
701
|
-
}
|
|
702
|
-
if (!(0, utils_js_1.hasProp)(def, 'env', 'string')) {
|
|
703
|
-
(0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
704
|
-
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to an invalid type ${picocolors_1.default.cyan(typeof def.env)}. ${fix}`);
|
|
705
|
-
}
|
|
706
|
-
if (!envValues.includes(def.env)) {
|
|
707
|
-
(0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
708
|
-
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to an unknown value ${picocolors_1.default.cyan(`'${def.env}'`)}. ${fix}`);
|
|
688
|
+
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} doesn't set ${picocolors_1.default.cyan(`meta.${configName}.env`)} but it's required.`);
|
|
709
689
|
}
|
|
690
|
+
configEnv = getConfigEnvValue(def.env, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to`);
|
|
691
|
+
// Overwrite deprecated value with valid value
|
|
692
|
+
// TODO/v1-release: remove once support for the deprecated values is removed
|
|
693
|
+
if (typeof def.env === 'string')
|
|
694
|
+
def.env = configEnv;
|
|
710
695
|
}
|
|
711
696
|
// effect
|
|
712
697
|
if ('effect' in def) {
|
|
@@ -714,9 +699,9 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
714
699
|
(0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
715
700
|
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} to an invalid type ${picocolors_1.default.cyan(typeof def.effect)}: it should be a function instead`);
|
|
716
701
|
}
|
|
717
|
-
if (
|
|
702
|
+
if (!configEnv.config) {
|
|
718
703
|
(0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
719
|
-
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env
|
|
704
|
+
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env has ${picocolors_1.default.cyan('{ config: true }')} (but it's ${picocolors_1.default.cyan(JSON.stringify(configEnv))} instead)`);
|
|
720
705
|
}
|
|
721
706
|
}
|
|
722
707
|
});
|
|
@@ -727,8 +712,8 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
|
|
|
727
712
|
return;
|
|
728
713
|
// The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
|
|
729
714
|
// (We could support effect for non config-only by always loading its value at config time, regardless of the config's `env` value.)
|
|
730
|
-
(0, utils_js_1.assertUsage)(configDef.env
|
|
731
|
-
`Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(configDef.env)}: effects can only be added to configs with an ${picocolors_1.default.cyan('env')}
|
|
715
|
+
(0, utils_js_1.assertUsage)(configDef.env.config, [
|
|
716
|
+
`Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(JSON.stringify(configDef.env))}: effects can only be added to configs with an ${picocolors_1.default.cyan('env')} with ${picocolors_1.default.cyan('{ config: true }')}.`
|
|
732
717
|
].join(' '));
|
|
733
718
|
const source = configValueSources[configName]?.[0];
|
|
734
719
|
if (!source)
|
|
@@ -1046,7 +1031,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
1046
1031
|
return { routeFilesystem, isErrorPage: undefined };
|
|
1047
1032
|
}
|
|
1048
1033
|
function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName) {
|
|
1049
|
-
(0, utils_js_1.assert)(configFilesystemRoutingRoot.configEnv
|
|
1034
|
+
(0, utils_js_1.assert)(configFilesystemRoutingRoot.configEnv.config);
|
|
1050
1035
|
// Eagerly loaded since it's config-only
|
|
1051
1036
|
(0, utils_js_1.assert)('value' in configFilesystemRoutingRoot);
|
|
1052
1037
|
const { value } = configFilesystemRoutingRoot;
|
|
@@ -1143,7 +1128,7 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1143
1128
|
// We could, in principle, also support cumulative for values that aren't loaded at config-time but it isn't completely trivial to implement.
|
|
1144
1129
|
(0, utils_js_1.assert)('value' in configValueSource);
|
|
1145
1130
|
// Make sure configValueSource.value is serializable
|
|
1146
|
-
(0,
|
|
1131
|
+
(0, getConfigValuesSerialized_js_1.assertConfigValueIsSerializable)(configValueSource.value, configName, getDefinedAt(configValueSource));
|
|
1147
1132
|
const assertNoMixing = (isSet) => {
|
|
1148
1133
|
const vals1 = isSet ? valuesSet : valuesArr;
|
|
1149
1134
|
const t1 = isSet ? 'a Set' : 'an array';
|
|
@@ -1184,3 +1169,35 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1184
1169
|
}
|
|
1185
1170
|
(0, utils_js_1.assert)(false);
|
|
1186
1171
|
}
|
|
1172
|
+
function getConfigEnvValue(val, errMsgIntro) {
|
|
1173
|
+
const errInvalidValue = `${errMsgIntro} an invalid value ${picocolors_1.default.cyan(JSON.stringify(val))}`;
|
|
1174
|
+
// Legacy outdated values
|
|
1175
|
+
if (typeof val === 'string') {
|
|
1176
|
+
const valConverted = (() => {
|
|
1177
|
+
if (val === 'client-only')
|
|
1178
|
+
return { client: true };
|
|
1179
|
+
if (val === 'server-only')
|
|
1180
|
+
return { server: true };
|
|
1181
|
+
if (val === 'server-and-client')
|
|
1182
|
+
return { server: true, client: true };
|
|
1183
|
+
if (val === 'config-only')
|
|
1184
|
+
return { config: true };
|
|
1185
|
+
if (val === '_routing-lazy')
|
|
1186
|
+
return { server: true, client: 'if-client-routing' };
|
|
1187
|
+
if (val === '_routing-eager')
|
|
1188
|
+
return { server: true, client: 'if-client-routing', eager: true };
|
|
1189
|
+
(0, utils_js_1.assertUsage)(false, errInvalidValue);
|
|
1190
|
+
})();
|
|
1191
|
+
(0, utils_js_1.assertWarning)(false, `${errMsgIntro} ${picocolors_1.default.cyan(val)} which is deprecated and will be removed in the next major release`, { onlyOnce: true });
|
|
1192
|
+
return valConverted;
|
|
1193
|
+
}
|
|
1194
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(val), `${errMsgIntro} an invalid type ${picocolors_1.default.cyan(typeof val)}`);
|
|
1195
|
+
(0, utils_js_1.assertKeys)(val, ['config', 'server', 'client'], `${errInvalidValue}:`);
|
|
1196
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(val, 'config', 'undefined') || (0, utils_js_1.hasProp)(val, 'config', 'boolean'), errInvalidValue);
|
|
1197
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(val, 'server', 'undefined') || (0, utils_js_1.hasProp)(val, 'server', 'boolean'), errInvalidValue);
|
|
1198
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(val, 'client', 'undefined') || (0, utils_js_1.hasProp)(val, 'client', 'boolean'), errInvalidValue);
|
|
1199
|
+
/* Uncomment to allow users to set an eager config. Same for `{ client: 'if-client-routing' }`.
|
|
1200
|
+
assertUsage(hasProp(val, 'eager', 'undefined') || hasProp(val, 'eager', 'boolean'), errInvalidValue)
|
|
1201
|
+
*/
|
|
1202
|
+
return val;
|
|
1203
|
+
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -7,10 +7,11 @@ const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
|
7
7
|
const extractAssetsQuery_js_1 = require("../../../../shared/extractAssetsQuery.js");
|
|
8
8
|
const debug_js_1 = require("./debug.js");
|
|
9
9
|
const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
|
|
10
|
-
const
|
|
10
|
+
const getConfigValueSourcesNotOverriden_js_1 = require("../../../shared/getConfigValueSourcesNotOverriden.js");
|
|
11
11
|
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
12
12
|
const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
|
|
13
13
|
const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
|
|
14
|
+
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
14
15
|
async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
15
16
|
const result = (0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id);
|
|
16
17
|
(0, utils_js_1.assert)(result);
|
|
@@ -31,27 +32,52 @@ async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
|
31
32
|
}
|
|
32
33
|
exports.getVirtualFilePageConfigValuesAll = getVirtualFilePageConfigValuesAll;
|
|
33
34
|
function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer, isDev) {
|
|
34
|
-
const configValue = (0, helpers_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean');
|
|
35
|
-
const isClientRouting = configValue?.value ?? false;
|
|
36
35
|
const lines = [];
|
|
37
36
|
const importStatements = [];
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
(
|
|
41
|
-
const { valueIsImportedAtRuntime, configEnv, configName } = configValueSource;
|
|
42
|
-
if (!valueIsImportedAtRuntime)
|
|
43
|
-
return;
|
|
44
|
-
if (configValueSource.valueIsFilePath)
|
|
45
|
-
return;
|
|
46
|
-
if (!(0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: false }))
|
|
47
|
-
return;
|
|
48
|
-
const whitespace = ' ';
|
|
49
|
-
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
50
|
-
});
|
|
37
|
+
const isClientRouting = (0, helpers_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
38
|
+
lines.push('export const configValuesImported = [');
|
|
39
|
+
lines.push(getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements));
|
|
51
40
|
lines.push('];');
|
|
41
|
+
lines.push('export const configValuesSerialized = {');
|
|
42
|
+
lines.push((0, getConfigValuesSerialized_js_1.getConfigValuesSerialized)(pageConfig, (configEnv, configValueSource) => isEnvMatch(configEnv, !configValueSource ? false : checkWhetherIsImport(configValueSource), {
|
|
43
|
+
isImport: false,
|
|
44
|
+
isForClientSide,
|
|
45
|
+
isClientRouting
|
|
46
|
+
})));
|
|
47
|
+
lines.push('};');
|
|
52
48
|
if (includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
53
|
-
|
|
49
|
+
importStatements.push(`import '${(0, extractAssetsQuery_js_1.extractAssetsAddQuery)((0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageId, false))}'`);
|
|
54
50
|
}
|
|
55
51
|
const code = [...importStatements, ...lines].join('\n');
|
|
56
52
|
return code;
|
|
57
53
|
}
|
|
54
|
+
function getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements) {
|
|
55
|
+
const lines = [];
|
|
56
|
+
const varCounterContainer = { varCounter: 0 };
|
|
57
|
+
(0, getConfigValueSourcesNotOverriden_js_1.getConfigValueSourcesNotOverriden)(pageConfig).forEach((configValueSource) => {
|
|
58
|
+
if (!isEnvMatch(configValueSource.configEnv, checkWhetherIsImport(configValueSource), {
|
|
59
|
+
isImport: true,
|
|
60
|
+
isForClientSide,
|
|
61
|
+
isClientRouting
|
|
62
|
+
}))
|
|
63
|
+
return;
|
|
64
|
+
const whitespace = ' ';
|
|
65
|
+
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configValueSource.configName, whitespace, varCounterContainer, importStatements));
|
|
66
|
+
});
|
|
67
|
+
const code = lines.join('\n');
|
|
68
|
+
return code;
|
|
69
|
+
}
|
|
70
|
+
function checkWhetherIsImport(configValueSource) {
|
|
71
|
+
const { valueIsImportedAtRuntime, valueIsFilePath } = configValueSource;
|
|
72
|
+
return valueIsImportedAtRuntime && !valueIsFilePath;
|
|
73
|
+
}
|
|
74
|
+
function isEnvMatch(configEnv, isImport, runtime) {
|
|
75
|
+
// Whether config value is imported or serialized
|
|
76
|
+
if (isImport !== runtime.isImport)
|
|
77
|
+
return false;
|
|
78
|
+
// Runtime match
|
|
79
|
+
const { isForClientSide, isClientRouting } = runtime;
|
|
80
|
+
if (!(0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: false }))
|
|
81
|
+
return false;
|
|
82
|
+
return true;
|
|
83
|
+
}
|