vike 0.4.171-commit-f9548df → 0.4.171-commit-3b2cb88
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/plugins/buildConfig.js +3 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -15
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +2 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +30 -74
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -42
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -49
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +6 -0
- package/dist/cjs/node/prerender/runPrerender.js +3 -2
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +3 -3
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScripts.js +2 -1
- package/dist/cjs/node/runtime/html/injectAssets/mergeScriptTags.js +2 -8
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +9 -7
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/cjs/node/shared/assertV1Design.js +3 -4
- package/dist/cjs/shared/getPageContextUrlComputed.js +8 -6
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +2 -2
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +15 -8
- package/dist/cjs/shared/hooks/getHook.js +2 -2
- package/dist/cjs/shared/page-configs/getConfigValue.js +14 -17
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +70 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +3 -12
- package/dist/cjs/shared/page-configs/serialize/assertPageConfigsSerialized.js +0 -18
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +110 -16
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +198 -0
- package/dist/cjs/shared/route/loadPageRoutes.js +2 -2
- package/dist/cjs/utils/hasProp.js +5 -7
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +3 -3
- package/dist/esm/client/client-routing-runtime/installClientRouter.js +18 -10
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +4 -4
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -15
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +30 -74
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -42
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -49
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +1 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +6 -0
- package/dist/esm/node/prerender/runPrerender.js +4 -3
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +3 -3
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScripts.js +3 -2
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.d.ts +1 -1
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.js +2 -8
- package/dist/esm/node/runtime/renderPage/analyzePage.js +9 -7
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +4 -4
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/esm/node/shared/assertV1Design.d.ts +2 -2
- package/dist/esm/node/shared/assertV1Design.js +3 -4
- package/dist/esm/shared/getPageContextUrlComputed.js +8 -6
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +14 -7
- package/dist/esm/shared/hooks/getHook.d.ts +2 -2
- package/dist/esm/shared/hooks/getHook.js +3 -3
- package/dist/esm/shared/page-configs/PageConfig.d.ts +10 -4
- package/dist/esm/shared/page-configs/getConfigValue.d.ts +12 -12
- package/dist/esm/shared/page-configs/getConfigValue.js +13 -16
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.d.ts +9 -0
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +67 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +3 -12
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +15 -19
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.d.ts +1 -5
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.js +1 -16
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +4 -1
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +109 -15
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +5 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +192 -0
- package/dist/esm/shared/route/loadPageRoutes.js +3 -3
- package/dist/esm/utils/hasProp.d.ts +4 -13
- package/dist/esm/utils/hasProp.js +5 -7
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +0 -101
- package/dist/cjs/node/plugin/shared/getConfigValueSourcesNotOverriden.js +0 -14
- package/dist/cjs/node/shared/getClientEntry.js +0 -12
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +0 -85
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +0 -24
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +0 -49
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +0 -95
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.d.ts +0 -5
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.js +0 -11
- package/dist/esm/node/shared/getClientEntry.d.ts +0 -3
- package/dist/esm/node/shared/getClientEntry.js +0 -9
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.d.ts +0 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +0 -82
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.d.ts +0 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +0 -21
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.d.ts +0 -6
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +0 -46
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
export { getConfigValuesSerialized };
|
|
2
|
-
export { assertConfigValueIsSerializable };
|
|
3
|
-
import { assert, assertUsage, getPropAccessNotation } from '../../../utils.js';
|
|
4
|
-
import { stringify } from '@brillout/json-serializer/stringify';
|
|
5
|
-
import pc from '@brillout/picocolors';
|
|
6
|
-
import { getConfigValueFilePathToShowToUser } from '../../../../../shared/page-configs/helpers.js';
|
|
7
|
-
import { serializeConfigValue } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
|
|
8
|
-
import { getConfigValueSourcesNotOverriden } from '../../../shared/getConfigValueSourcesNotOverriden.js';
|
|
9
|
-
import { parsePointerImportData } from './getVikeConfig/transformFileImports.js';
|
|
10
|
-
import { addImportStatement } from '../addImportStatement.js';
|
|
11
|
-
const REPLACE_ME_BEFORE = '__VIKE__REPLACE_ME_BEFORE__';
|
|
12
|
-
const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
13
|
-
function getConfigValuesSerialized(pageConfig, importStatements, isEnvMatch) {
|
|
14
|
-
const lines = [];
|
|
15
|
-
Object.entries(pageConfig.configValuesComputed).forEach(([configName, configValuesComputed]) => {
|
|
16
|
-
const { 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
|
-
assert(configValue);
|
|
24
|
-
const { value, ...common } = configValue;
|
|
25
|
-
assert(value === configValuesComputed.value);
|
|
26
|
-
const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData, importStatements);
|
|
27
|
-
const configValueSerialized = { valueSerialized, ...common };
|
|
28
|
-
serializeConfigValue(lines, configName, configValueSerialized);
|
|
29
|
-
});
|
|
30
|
-
getConfigValueSourcesNotOverriden(pageConfig).forEach((configValueSource) => {
|
|
31
|
-
const { configName, configEnv } = configValueSource;
|
|
32
|
-
const configValue = pageConfig.configValues[configName];
|
|
33
|
-
if (!configValue)
|
|
34
|
-
return;
|
|
35
|
-
if (!isEnvMatch(configEnv, configValueSource)) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const { value, ...common } = configValue;
|
|
39
|
-
const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData, importStatements);
|
|
40
|
-
const configValueSerialized = { valueSerialized, ...common };
|
|
41
|
-
serializeConfigValue(lines, configName, configValueSerialized);
|
|
42
|
-
});
|
|
43
|
-
const code = lines.join('\n');
|
|
44
|
-
return code;
|
|
45
|
-
}
|
|
46
|
-
function assertConfigValueIsSerializable(value, configName, definedAtData) {
|
|
47
|
-
// Contains asserts
|
|
48
|
-
getConfigValueSerialized(value, configName, definedAtData, []);
|
|
49
|
-
}
|
|
50
|
-
function getConfigValueSerialized(value, configName, definedAtData, importStatements) {
|
|
51
|
-
const valueName = `config${getPropAccessNotation(configName)}`;
|
|
52
|
-
let configValueSerialized;
|
|
53
|
-
try {
|
|
54
|
-
configValueSerialized = stringify(value, {
|
|
55
|
-
valueName,
|
|
56
|
-
forbidReactElements: true,
|
|
57
|
-
replacer(_, value) {
|
|
58
|
-
if (typeof value === 'string') {
|
|
59
|
-
const importData = parsePointerImportData(value);
|
|
60
|
-
if (importData) {
|
|
61
|
-
const { importName } = addImportStatement(importStatements, importData.importPath, importData.exportName);
|
|
62
|
-
const replacement = [REPLACE_ME_BEFORE, importName, REPLACE_ME_AFTER].join('');
|
|
63
|
-
return { replacement };
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
logJsonSerializeError(err, configName, definedAtData);
|
|
71
|
-
assert(false);
|
|
72
|
-
}
|
|
73
|
-
configValueSerialized = configValueSerialized.replaceAll(`"${REPLACE_ME_BEFORE}`, '');
|
|
74
|
-
configValueSerialized = configValueSerialized.replaceAll(`${REPLACE_ME_AFTER}"`, '');
|
|
75
|
-
assert(!configValueSerialized.includes(REPLACE_ME_BEFORE));
|
|
76
|
-
assert(!configValueSerialized.includes(REPLACE_ME_AFTER));
|
|
77
|
-
return configValueSerialized;
|
|
78
|
-
}
|
|
79
|
-
function logJsonSerializeError(err, configName, definedAtData) {
|
|
80
|
-
/*
|
|
81
|
-
// import { isJsonSerializerError } from '@brillout/json-serializer/stringify'
|
|
82
|
-
let serializationErrMsg = ''
|
|
83
|
-
if (isJsonSerializerError(err)) {
|
|
84
|
-
serializationErrMsg = err.messageCore
|
|
85
|
-
} else {
|
|
86
|
-
// When a property getter throws an error
|
|
87
|
-
console.error('Serialization error:')
|
|
88
|
-
console.error(err)
|
|
89
|
-
serializationErrMsg = 'see serialization error printed above'
|
|
90
|
-
}
|
|
91
|
-
//*/
|
|
92
|
-
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser(definedAtData);
|
|
93
|
-
assert(configValueFilePathToShowToUser);
|
|
94
|
-
assertUsage(false, `${pc.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined over a so-called "pointer import", see https://vike.dev/config#pointer-imports`);
|
|
95
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { getConfigValueSourcesNotOverriden };
|
|
2
|
-
import type { ConfigValueSource, PageConfigBuildTime } from '../../../shared/page-configs/PageConfig.js';
|
|
3
|
-
declare function getConfigValueSourcesNotOverriden(pageConfig: PageConfigBuildTime): (ConfigValueSource & {
|
|
4
|
-
configName: string;
|
|
5
|
-
})[];
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export { getConfigValueSourcesNotOverriden };
|
|
2
|
-
import { assert, assertIsNotBrowser } from '../../shared/utils.js';
|
|
3
|
-
assertIsNotBrowser();
|
|
4
|
-
function getConfigValueSourcesNotOverriden(pageConfig) {
|
|
5
|
-
const configValueSourcesRelevant = Object.entries(pageConfig.configValueSources).map(([configName, sources]) => {
|
|
6
|
-
const configValueSource = sources[0];
|
|
7
|
-
assert(configValueSource);
|
|
8
|
-
return { configName, ...configValueSource };
|
|
9
|
-
});
|
|
10
|
-
return configValueSourcesRelevant;
|
|
11
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { getClientEntry };
|
|
2
|
-
import { getConfigValue } from '../../shared/page-configs/getConfigValue.js';
|
|
3
|
-
function getClientEntry(pageConfig) {
|
|
4
|
-
const configName = 'client';
|
|
5
|
-
const configValue = getConfigValue(pageConfig, configName, 'string');
|
|
6
|
-
if (!configValue)
|
|
7
|
-
return null;
|
|
8
|
-
return configValue.value;
|
|
9
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
export { parseConfigValuesImported };
|
|
2
|
-
import { assert } from '../../utils.js';
|
|
3
|
-
import { assertPlusFileExport } from '../assertPlusFileExport.js';
|
|
4
|
-
function parseConfigValuesImported(configValuesImported) {
|
|
5
|
-
const configValuesUnmerged = {};
|
|
6
|
-
configValuesImported
|
|
7
|
-
.filter((c) => c.configName !== 'client')
|
|
8
|
-
.forEach((configValueLoaded) => {
|
|
9
|
-
if (configValueLoaded.isValueFile) {
|
|
10
|
-
const { exportValues, importPath, configName } = configValueLoaded;
|
|
11
|
-
assertPlusFileExport(exportValues, importPath, configName);
|
|
12
|
-
Object.entries(exportValues).forEach(([exportName, exportValue]) => {
|
|
13
|
-
const isSideExport = exportName !== 'default'; // .md files may have "side-exports" such as `export { frontmatter }`
|
|
14
|
-
const configName = isSideExport ? exportName : configValueLoaded.configName;
|
|
15
|
-
configValuesUnmerged[configName] ?? (configValuesUnmerged[configName] = []);
|
|
16
|
-
configValuesUnmerged[configName].push({
|
|
17
|
-
value: exportValue,
|
|
18
|
-
importPath,
|
|
19
|
-
exportName,
|
|
20
|
-
isSideExport
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
const { configName, importPath, exportValue, exportName } = configValueLoaded;
|
|
26
|
-
configValuesUnmerged[configName] ?? (configValuesUnmerged[configName] = []);
|
|
27
|
-
configValuesUnmerged[configName].push({
|
|
28
|
-
value: exportValue,
|
|
29
|
-
importPath,
|
|
30
|
-
exportName,
|
|
31
|
-
isSideExport: false
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
const configValues = {};
|
|
36
|
-
Object.entries(configValuesUnmerged).forEach(([configName, values]) => {
|
|
37
|
-
const valuesWithoutSideExports = values.filter((v) => !v.isSideExport);
|
|
38
|
-
const isCumulative = valuesWithoutSideExports.length > 1;
|
|
39
|
-
const noSideExports = valuesWithoutSideExports.length === values.length;
|
|
40
|
-
if (isCumulative) {
|
|
41
|
-
// Vike currently doesn't support side exports for cumulative configs
|
|
42
|
-
assert(noSideExports);
|
|
43
|
-
// TODO: implement
|
|
44
|
-
assert(false);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
const val = valuesWithoutSideExports[0] ??
|
|
48
|
-
// We can't avoid side-export conflicts upstream. (We cannot know about side-exports at build-time.)
|
|
49
|
-
// Side-exports have lower precedence.
|
|
50
|
-
values[0];
|
|
51
|
-
assert(val);
|
|
52
|
-
const { value, importPath, exportName } = val;
|
|
53
|
-
configValues[configName] = {
|
|
54
|
-
type: 'standard',
|
|
55
|
-
value,
|
|
56
|
-
definedAtData: {
|
|
57
|
-
// importPath cannot be relative to the current file, since the current file is a virtual file
|
|
58
|
-
filePathToShowToUser: importPath,
|
|
59
|
-
fileExportPathToShowToUser: [configName, 'default'].includes(exportName)
|
|
60
|
-
? []
|
|
61
|
-
: [
|
|
62
|
-
// Side-export
|
|
63
|
-
exportName
|
|
64
|
-
]
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
assertIsNotNull(value, configName, importPath);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
return configValues;
|
|
71
|
-
}
|
|
72
|
-
function assertIsNotNull(configValue, configName, importPath) {
|
|
73
|
-
assert(!importPath.includes('+config.'));
|
|
74
|
-
/* Re-use this for:
|
|
75
|
-
* - upcoming config.requestPageContextOnNavigation
|
|
76
|
-
* - for cumulative values in the future: we don't need this for now because, currently, cumulative values are never imported.
|
|
77
|
-
assertUsage(
|
|
78
|
-
configValue !== null,
|
|
79
|
-
`Set ${pc.cyan(configName)} to ${pc.cyan('null')} in a +config.js file instead of ${importPath}`
|
|
80
|
-
)
|
|
81
|
-
*/
|
|
82
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { parseConfigValuesSerialized };
|
|
2
|
-
import type { ConfigValues } from '../PageConfig.js';
|
|
3
|
-
import type { ConfigValueSerialized } from './PageConfigSerialized.js';
|
|
4
|
-
declare function parseConfigValuesSerialized(configValuesSerialized: Record<string, ConfigValueSerialized>): ConfigValues;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export { parseConfigValuesSerialized };
|
|
2
|
-
import { assert, isArray } from '../../utils.js';
|
|
3
|
-
import { parseTransform } from '@brillout/json-serializer/parse';
|
|
4
|
-
function parseConfigValuesSerialized(configValuesSerialized) {
|
|
5
|
-
const configValues = {};
|
|
6
|
-
Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
|
|
7
|
-
assert(!configValues[configName]);
|
|
8
|
-
const { valueSerialized, ...common } = configValueSeriliazed;
|
|
9
|
-
const value = parseTransform(valueSerialized);
|
|
10
|
-
let configValue;
|
|
11
|
-
if (common.type === 'cumulative') {
|
|
12
|
-
assert(isArray(value));
|
|
13
|
-
configValue = { value, ...common };
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
configValue = { value, ...common };
|
|
17
|
-
}
|
|
18
|
-
configValues[configName] = configValue;
|
|
19
|
-
});
|
|
20
|
-
return configValues;
|
|
21
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { serializeConfigValue };
|
|
2
|
-
export { serializeConfigValueImported };
|
|
3
|
-
import { ConfigValueSource } from '../PageConfig.js';
|
|
4
|
-
import { ConfigValueSerialized } from './PageConfigSerialized.js';
|
|
5
|
-
declare function serializeConfigValue(lines: string[], configName: string, configValueSerialized: ConfigValueSerialized): void;
|
|
6
|
-
declare function serializeConfigValueImported(configValueSource: ConfigValueSource, configName: string, whitespace: string, importStatements: string[]): string[];
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export { serializeConfigValue };
|
|
2
|
-
export { serializeConfigValueImported };
|
|
3
|
-
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with:
|
|
4
|
-
// - vike/shared/page-configs/serialize/parsePageConfigs.ts
|
|
5
|
-
// - vike/shared/page-configs/serialize/parseConfigValuesImported.ts
|
|
6
|
-
// Both parsePageConfigs() parseConfigValuesImported() and are loaded on the client-side and server-side
|
|
7
|
-
import { assertIsNotProductionRuntime } from '../../../utils/assertIsNotProductionRuntime.js';
|
|
8
|
-
assertIsNotProductionRuntime();
|
|
9
|
-
import { assert } from '../../utils.js';
|
|
10
|
-
import { addImportStatement } from '../../../node/plugin/plugins/importUserCode/addImportStatement.js';
|
|
11
|
-
function serializeConfigValue(lines, configName, configValueSerialized) {
|
|
12
|
-
let whitespace = ' ';
|
|
13
|
-
lines.push(`${whitespace}['${configName}']: {`);
|
|
14
|
-
whitespace += ' ';
|
|
15
|
-
Object.entries(configValueSerialized).forEach(([key, val]) => {
|
|
16
|
-
const valSerialized = key === 'valueSerialized' ? val : JSON.stringify(val);
|
|
17
|
-
lines.push(`${whitespace} ${key}: ${valSerialized},`);
|
|
18
|
-
});
|
|
19
|
-
whitespace = whitespace.slice(2);
|
|
20
|
-
lines.push(`${whitespace}},`);
|
|
21
|
-
}
|
|
22
|
-
function serializeConfigValueImported(configValueSource, configName, whitespace, importStatements) {
|
|
23
|
-
assert(!configValueSource.valueIsFilePath);
|
|
24
|
-
assert(whitespace.replaceAll(' ', '').length === 0);
|
|
25
|
-
const { valueIsImportedAtRuntime, valueIsDefinedByValueFile, definedAtFilePath } = configValueSource;
|
|
26
|
-
assert(valueIsImportedAtRuntime);
|
|
27
|
-
const { filePathAbsoluteVite, fileExportName } = definedAtFilePath;
|
|
28
|
-
if (valueIsDefinedByValueFile)
|
|
29
|
-
assert(fileExportName === undefined);
|
|
30
|
-
const { importName } = addImportStatement(importStatements, filePathAbsoluteVite, fileExportName || '*');
|
|
31
|
-
const lines = [];
|
|
32
|
-
lines.push(` {`);
|
|
33
|
-
lines.push(` configName: '${configName}',`);
|
|
34
|
-
lines.push(` importPath: '${filePathAbsoluteVite}',`);
|
|
35
|
-
lines.push(` isValueFile: ${JSON.stringify(valueIsDefinedByValueFile)},`);
|
|
36
|
-
if (valueIsDefinedByValueFile) {
|
|
37
|
-
lines.push(` exportValues: ${importName},`);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
lines.push(` exportValue: ${importName},`);
|
|
41
|
-
assert(fileExportName);
|
|
42
|
-
lines.push(` exportName: ${JSON.stringify(fileExportName)},`);
|
|
43
|
-
}
|
|
44
|
-
lines.push(` },`);
|
|
45
|
-
return lines;
|
|
46
|
-
}
|