vike 0.4.171-commit-2e4e1ce → 0.4.171-commit-14f2e5d

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.
Files changed (28) hide show
  1. package/dist/cjs/node/plugin/plugins/importUserCode/{generateEagerImport.js → addImportStatement.js} +8 -10
  2. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +46 -21
  3. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -3
  6. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +7 -8
  7. package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +2 -8
  8. package/dist/cjs/node/runtime/html/renderHtml.js +18 -9
  9. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +3 -2
  10. package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +3 -4
  11. package/dist/cjs/utils/projectInfo.js +1 -1
  12. package/dist/esm/node/plugin/plugins/importUserCode/addImportStatement.d.ts +14 -0
  13. package/dist/esm/node/plugin/plugins/importUserCode/{generateEagerImport.js → addImportStatement.js} +7 -9
  14. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +1 -1
  15. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +46 -21
  16. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
  17. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
  18. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -3
  19. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +7 -8
  20. package/dist/esm/node/plugin/shared/addSsrMiddleware.js +2 -8
  21. package/dist/esm/node/runtime/html/renderHtml.js +18 -9
  22. package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +3 -2
  23. package/dist/esm/shared/page-configs/serialize/serializeConfigValue.d.ts +1 -3
  24. package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +3 -4
  25. package/dist/esm/utils/projectInfo.d.ts +2 -2
  26. package/dist/esm/utils/projectInfo.js +1 -1
  27. package/package.json +10 -10
  28. package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +0 -16
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateEagerImport = void 0;
4
- let varCounterGlobal = 0;
3
+ exports.addImportStatement = void 0;
5
4
  /**
6
5
  * Naming:
7
6
  * `import { someExport as someImport } from './some-file'`
@@ -11,14 +10,12 @@ let varCounterGlobal = 0;
11
10
  * `exportName: 'someExport',`
12
11
  * `importName: 'someImport',`
13
12
  * `}`
14
- * We discard the information that the import variable is called `someImport` because we don't need it.
15
13
  */
16
- function generateEagerImport(importPath, varCounter, exportName) {
17
- if (varCounter === undefined)
18
- varCounter = varCounterGlobal++;
19
- const importName = `import_${varCounter}`;
14
+ function addImportStatement(importStatements, importPath, exportName) {
15
+ const importCounter = importStatements.length + 1;
16
+ const importName = `import${importCounter}`;
20
17
  const importLiteral = (() => {
21
- if (!exportName || exportName === '*') {
18
+ if (exportName === '*') {
22
19
  return `* as ${importName}`;
23
20
  }
24
21
  if (exportName === 'default') {
@@ -27,6 +24,7 @@ function generateEagerImport(importPath, varCounter, exportName) {
27
24
  return `{ ${exportName} as ${importName} }`;
28
25
  })();
29
26
  const importStatement = `import ${importLiteral} from '${importPath}';`;
30
- return { importName, importStatement };
27
+ importStatements.push(importStatement);
28
+ return { importName };
31
29
  }
32
- exports.generateEagerImport = generateEagerImport;
30
+ exports.addImportStatement = addImportStatement;
@@ -10,7 +10,11 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
10
  const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
11
11
  const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
12
12
  const getConfigValueSourcesNotOverriden_js_1 = require("../../../shared/getConfigValueSourcesNotOverriden.js");
13
- function getConfigValuesSerialized(pageConfig, isEnvMatch) {
13
+ const transformFileImports_js_1 = require("./getVikeConfig/transformFileImports.js");
14
+ const addImportStatement_js_1 = require("../addImportStatement.js");
15
+ const REPLACE_ME_BEFORE = '__VIKE__REPLACE_ME_BEFORE__';
16
+ const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
17
+ function getConfigValuesSerialized(pageConfig, importStatements, isEnvMatch) {
14
18
  const lines = [];
15
19
  Object.entries(pageConfig.configValuesComputed).forEach(([configName, configValuesComputed]) => {
16
20
  const { configEnv } = configValuesComputed;
@@ -23,7 +27,7 @@ function getConfigValuesSerialized(pageConfig, isEnvMatch) {
23
27
  (0, utils_js_1.assert)(configValue);
24
28
  const { value, ...common } = configValue;
25
29
  (0, utils_js_1.assert)(value === configValuesComputed.value);
26
- const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData);
30
+ const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData, importStatements);
27
31
  const configValueSerialized = { valueSerialized, ...common };
28
32
  (0, serializeConfigValue_js_1.serializeConfigValue)(lines, configName, configValueSerialized);
29
33
  });
@@ -36,7 +40,7 @@ function getConfigValuesSerialized(pageConfig, isEnvMatch) {
36
40
  return;
37
41
  }
38
42
  const { value, ...common } = configValue;
39
- const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData);
43
+ const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData, importStatements);
40
44
  const configValueSerialized = { valueSerialized, ...common };
41
45
  (0, serializeConfigValue_js_1.serializeConfigValue)(lines, configName, configValueSerialized);
42
46
  });
@@ -46,31 +50,52 @@ function getConfigValuesSerialized(pageConfig, isEnvMatch) {
46
50
  exports.getConfigValuesSerialized = getConfigValuesSerialized;
47
51
  function assertConfigValueIsSerializable(value, configName, definedAtData) {
48
52
  // Contains asserts
49
- getConfigValueSerialized(value, configName, definedAtData);
53
+ getConfigValueSerialized(value, configName, definedAtData, []);
50
54
  }
51
55
  exports.assertConfigValueIsSerializable = assertConfigValueIsSerializable;
52
- function getConfigValueSerialized(value, configName, definedAtData) {
56
+ function getConfigValueSerialized(value, configName, definedAtData, importStatements) {
53
57
  const valueName = `config${(0, utils_js_1.getPropAccessNotation)(configName)}`;
54
58
  let configValueSerialized;
55
59
  try {
56
- configValueSerialized = (0, stringify_1.stringify)(value, { valueName, forbidReactElements: true });
60
+ configValueSerialized = (0, stringify_1.stringify)(value, {
61
+ valueName,
62
+ forbidReactElements: true,
63
+ replacer(_, value) {
64
+ if (typeof value === 'string') {
65
+ const importData = (0, transformFileImports_js_1.parsePointerImportData)(value);
66
+ if (importData) {
67
+ const { importName } = (0, addImportStatement_js_1.addImportStatement)(importStatements, importData.importPath, importData.exportName);
68
+ const replacement = [REPLACE_ME_BEFORE, importName, REPLACE_ME_AFTER].join('');
69
+ return { replacement };
70
+ }
71
+ }
72
+ }
73
+ });
57
74
  }
58
75
  catch (err) {
59
- /*
60
- let serializationErrMsg = ''
61
- if (isJsonSerializerError(err)) {
62
- serializationErrMsg = err.messageCore
63
- } else {
64
- // When a property getter throws an error
65
- console.error('Serialization error:')
66
- console.error(err)
67
- serializationErrMsg = 'see serialization error printed above'
68
- }
69
- */
70
- const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)(definedAtData);
71
- (0, utils_js_1.assert)(configValueFilePathToShowToUser);
72
- (0, utils_js_1.assertUsage)(false, `${picocolors_1.default.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined over a so-called "pointer import", see https://vike.dev/config#pointer-imports`);
76
+ logJsonSerializeError(err, configName, definedAtData);
77
+ (0, utils_js_1.assert)(false);
73
78
  }
74
- configValueSerialized = JSON.stringify(configValueSerialized);
79
+ configValueSerialized = configValueSerialized.replaceAll(`"${REPLACE_ME_BEFORE}`, '');
80
+ configValueSerialized = configValueSerialized.replaceAll(`${REPLACE_ME_AFTER}"`, '');
81
+ (0, utils_js_1.assert)(!configValueSerialized.includes(REPLACE_ME_BEFORE));
82
+ (0, utils_js_1.assert)(!configValueSerialized.includes(REPLACE_ME_AFTER));
75
83
  return configValueSerialized;
76
84
  }
85
+ function logJsonSerializeError(err, configName, definedAtData) {
86
+ /*
87
+ // import { isJsonSerializerError } from '@brillout/json-serializer/stringify'
88
+ let serializationErrMsg = ''
89
+ if (isJsonSerializerError(err)) {
90
+ serializationErrMsg = err.messageCore
91
+ } else {
92
+ // When a property getter throws an error
93
+ console.error('Serialization error:')
94
+ console.error(err)
95
+ serializationErrMsg = 'see serialization error printed above'
96
+ }
97
+ //*/
98
+ const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)(definedAtData);
99
+ (0, utils_js_1.assert)(configValueFilePathToShowToUser);
100
+ (0, utils_js_1.assertUsage)(false, `${picocolors_1.default.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined over a so-called "pointer import", see https://vike.dev/config#pointer-imports`);
101
+ }
@@ -13,7 +13,7 @@ const transformFileImports_js_1 = require("./transformFileImports.js");
13
13
  const getConfigFileExport_js_1 = require("../getConfigFileExport.js");
14
14
  const resolvePointerImport_js_1 = require("./resolvePointerImport.js");
15
15
  (0, utils_js_1.assertIsNotProductionRuntime)();
16
- // Load fake import
16
+ // Load pointer import
17
17
  async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
18
18
  const f = import_.filePathAbsoluteFilesystem;
19
19
  if (!importedFilesLoaded[f]) {
@@ -35,7 +35,7 @@ async function loadValueFile(interfaceValueFile, configName, userRootDir) {
35
35
  });
36
36
  }
37
37
  exports.loadValueFile = loadValueFile;
38
- // Load +config.js, including all its extends fake imports
38
+ // Load +config.js, including all its extends pointer imports
39
39
  async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig) {
40
40
  const { filePathAbsoluteFilesystem } = configFilePath;
41
41
  assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
@@ -552,7 +552,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
552
552
  valueIsDefinedByValueFile: false,
553
553
  definedAtFilePath: pointerImport
554
554
  };
555
- // Load fake import
555
+ // Load pointer import
556
556
  if (isConfigEnv(configDef, configName) &&
557
557
  // The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
558
558
  configName !== 'extends') {
@@ -40,7 +40,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
40
40
  lines.push(getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements));
41
41
  lines.push('];');
42
42
  lines.push('export const configValuesSerialized = {');
43
- lines.push((0, getConfigValuesSerialized_js_1.getConfigValuesSerialized)(pageConfig, (configEnv, configValueSource) => isEnvMatch(configEnv, !configValueSource ? false : checkWhetherIsImport(configValueSource), {
43
+ lines.push((0, getConfigValuesSerialized_js_1.getConfigValuesSerialized)(pageConfig, importStatements, (configEnv, configValueSource) => isEnvMatch(configEnv, !configValueSource ? false : checkWhetherIsImport(configValueSource), {
44
44
  isImport: false,
45
45
  isForClientSide,
46
46
  isClientRouting
@@ -54,7 +54,6 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
54
54
  }
55
55
  function getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements) {
56
56
  const lines = [];
57
- const varCounterContainer = { varCounter: 0 };
58
57
  (0, getConfigValueSourcesNotOverriden_js_1.getConfigValueSourcesNotOverriden)(pageConfig).forEach((configValueSource) => {
59
58
  if (!isEnvMatch(configValueSource.configEnv, checkWhetherIsImport(configValueSource), {
60
59
  isImport: true,
@@ -63,7 +62,7 @@ function getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, i
63
62
  }))
64
63
  return;
65
64
  const whitespace = ' ';
66
- lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configValueSource.configName, whitespace, varCounterContainer, importStatements));
65
+ lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configValueSource.configName, whitespace, importStatements));
67
66
  });
68
67
  const code = lines.join('\n');
69
68
  return code;
@@ -16,18 +16,17 @@ exports.getVirtualFilePageConfigs = getVirtualFilePageConfigs;
16
16
  function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting) {
17
17
  const lines = [];
18
18
  const importStatements = [];
19
- const varCounterContainer = { varCounter: 0 };
20
19
  lines.push('export const pageConfigsSerialized = [');
21
- lines.push(getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements, varCounterContainer));
20
+ lines.push(getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements));
22
21
  lines.push('];');
23
22
  lines.push('export const pageConfigGlobalSerialized = {');
24
- lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements, varCounterContainer));
23
+ lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements));
25
24
  lines.push('};');
26
25
  const code = [...importStatements, ...lines].join('\n');
27
26
  (0, debug_js_1.debug)(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
28
27
  return code;
29
28
  }
30
- function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements, varCounterContainer) {
29
+ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements) {
31
30
  const lines = [];
32
31
  pageConfigs.forEach((pageConfig) => {
33
32
  const { pageId, routeFilesystem, isErrorPage } = pageConfig;
@@ -39,7 +38,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
39
38
  lines.push(` loadConfigValuesAll: () => import(${JSON.stringify(virtualFileIdPageConfigValuesAll)}),`);
40
39
  // Serialized config values
41
40
  lines.push(` configValuesSerialized: {`);
42
- lines.push((0, getConfigValuesSerialized_js_1.getConfigValuesSerialized)(pageConfig, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true })));
41
+ lines.push((0, getConfigValuesSerialized_js_1.getConfigValuesSerialized)(pageConfig, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true })));
43
42
  lines.push(` },`);
44
43
  // Imported config values
45
44
  const whitespace = ' ';
@@ -54,7 +53,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
54
53
  return;
55
54
  if (!(0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configValueSource.configEnv, { isForClientSide, isClientRouting, isEager: true }))
56
55
  return;
57
- lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, varCounterContainer, importStatements));
56
+ lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, importStatements));
58
57
  });
59
58
  lines.push(`${whitespace}],`);
60
59
  lines.push(` },`);
@@ -62,7 +61,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
62
61
  const code = lines.join('\n');
63
62
  return code;
64
63
  }
65
- function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements, varCounterContainer) {
64
+ function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements) {
66
65
  const lines = [];
67
66
  /* Nothing (yet)
68
67
  lines.push(` configValuesSerialized: {`)
@@ -85,7 +84,7 @@ function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, is
85
84
  const configValueSource = sources[0];
86
85
  (0, utils_js_1.assert)(configValueSource);
87
86
  const whitespace = ' ';
88
- lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, varCounterContainer, importStatements));
87
+ lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, importStatements));
89
88
  });
90
89
  lines.push(` ],`);
91
90
  const code = lines.join('\n');
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addSsrMiddleware = void 0;
4
4
  const renderPage_js_1 = require("../../runtime/renderPage.js");
5
- const utils_js_1 = require("../utils.js");
6
5
  function addSsrMiddleware(middlewares) {
7
6
  middlewares.use(async (req, res, next) => {
8
7
  if (res.headersSent)
@@ -11,15 +10,10 @@ function addSsrMiddleware(middlewares) {
11
10
  if (!url)
12
11
  return next();
13
12
  const { headers } = req;
13
+ const userAgent = headers['user-agent'];
14
14
  const pageContextInit = {
15
15
  urlOriginal: url,
16
- get userAgent() {
17
- (0, utils_js_1.assertWarning)(false, "pageContext.userAgent is deprecated in favor of pageContext.headers['user-agent']", {
18
- showStackTrace: true,
19
- onlyOnce: true
20
- });
21
- return headers['user-agent'];
22
- },
16
+ userAgent,
23
17
  headers
24
18
  };
25
19
  let pageContext;
@@ -170,31 +170,40 @@ async function renderTemplate(templateContent, pageContext) {
170
170
  setStream(templateVar);
171
171
  continue;
172
172
  }
173
- const getErrMsg = (typeText, end) => {
173
+ const getErrMsg = (msg) => {
174
174
  const { hookName, hookFilePath } = pageContext._renderHook;
175
175
  const nth = (i === 0 && '1st') || (i === 1 && '2nd') || (i === 2 && '3rd') || `${i}-th`;
176
- return [`The ${nth} HTML variable is ${typeText}, see ${hookName}() hook defined by ${hookFilePath}.`, end]
176
+ return [
177
+ `The ${nth} HTML variable is ${msg}`,
178
+ `The HTML was provided by the ${hookName}() hook at ${hookFilePath}.`
179
+ ]
177
180
  .filter(Boolean)
178
181
  .join(' ');
179
182
  };
180
- (0, utils_js_1.assertUsage)(!(0, utils_js_1.isPromise)(templateVar), getErrMsg('a promise', `Did you forget to ${picocolors_1.default.cyan('await')} the promise?`));
183
+ (0, utils_js_1.assertUsage)(!(0, utils_js_1.isPromise)(templateVar), getErrMsg(`a promise, did you forget to ${picocolors_1.default.cyan('await')} the promise?`));
181
184
  if (templateVar === undefined || templateVar === null) {
182
- (0, utils_js_1.assertWarning)(false, getErrMsg(`${picocolors_1.default.cyan(String(templateVar))} which will be converted to an empty string`, `Pass the empty string ${picocolors_1.default.cyan("''")} instead of ${picocolors_1.default.cyan(String(templateVar))} to remove this warning.`), { onlyOnce: false });
185
+ const msgVal = picocolors_1.default.cyan(String(templateVar));
186
+ const msgEmptyString = picocolors_1.default.cyan("''");
187
+ const msg = `${msgVal} which will be converted to an empty string. Pass the empty string ${msgEmptyString} instead of ${msgVal} to remove this warning.`;
188
+ (0, utils_js_1.assertWarning)(false, getErrMsg(msg), { onlyOnce: false });
183
189
  templateVar = '';
184
190
  }
185
191
  {
186
192
  const varType = typeof templateVar;
187
- const streamNote = ['boolean', 'number', 'bigint', 'symbol'].includes(varType)
188
- ? null
189
- : '(See https://vike.dev/streaming for HTML streaming.)';
190
- (0, utils_js_1.assertUsage)(varType === 'string', getErrMsg(picocolors_1.default.cyan(`typeof htmlVar === "${varType}"`), streamNote));
193
+ if (varType !== 'string') {
194
+ const msgType = picocolors_1.default.cyan(`typeof htmlVariable === "${varType}"`);
195
+ const msg = `${msgType} but a string or stream (https://vike.dev/streaming) is expected instead.`;
196
+ (0, utils_js_1.assertUsage)(false, getErrMsg(msg));
197
+ }
191
198
  }
192
199
  {
193
200
  const { isProduction } = (0, globalContext_js_1.getGlobalContext)();
194
201
  if ((0, utils_js_1.isHtml)(templateVar) &&
195
202
  // We don't show this warning in production because it's expected that some users may (un)willingly do some XSS injection: we avoid flooding the production logs.
196
203
  !isProduction) {
197
- (0, utils_js_1.assertWarning)(false, getErrMsg(`${picocolors_1.default.cyan(templateVar)} which seems to be HTML code`, 'Did you forget to wrap the value with dangerouslySkipEscape()?'), { onlyOnce: false });
204
+ const msgVal = picocolors_1.default.cyan(String(templateVar));
205
+ const msg = `${msgVal} which seems to be HTML code. Did you forget to wrap the value with dangerouslySkipEscape()?`;
206
+ (0, utils_js_1.assertWarning)(false, getErrMsg(msg), { onlyOnce: false });
198
207
  }
199
208
  }
200
209
  // Escape untrusted template variable
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseConfigValuesSerialized = void 0;
4
4
  const utils_js_1 = require("../../utils.js");
5
- const parse_1 = require("@brillout/json-serializer/parse");
6
5
  function parseConfigValuesSerialized(configValuesSerialized) {
7
6
  const configValues = {};
8
7
  Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
9
8
  (0, utils_js_1.assert)(!configValues[configName]);
10
9
  const { valueSerialized, ...common } = configValueSeriliazed;
11
- const value = (0, parse_1.parse)(valueSerialized);
10
+ console.log('valueSerialized', valueSerialized);
11
+ // const value = parse(valueSerialized)
12
+ const value = valueSerialized;
12
13
  let configValue;
13
14
  if (common.type === 'cumulative') {
14
15
  (0, utils_js_1.assert)((0, utils_js_1.isArray)(value));
@@ -8,7 +8,7 @@ exports.serializeConfigValueImported = exports.serializeConfigValue = void 0;
8
8
  const assertIsNotProductionRuntime_js_1 = require("../../../utils/assertIsNotProductionRuntime.js");
9
9
  (0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
10
10
  const utils_js_1 = require("../../utils.js");
11
- const generateEagerImport_js_1 = require("../../../node/plugin/plugins/importUserCode/generateEagerImport.js");
11
+ const addImportStatement_js_1 = require("../../../node/plugin/plugins/importUserCode/addImportStatement.js");
12
12
  function serializeConfigValue(lines, configName, configValueSerialized) {
13
13
  let whitespace = ' ';
14
14
  lines.push(`${whitespace}['${configName}']: {`);
@@ -21,7 +21,7 @@ function serializeConfigValue(lines, configName, configValueSerialized) {
21
21
  lines.push(`${whitespace}},`);
22
22
  }
23
23
  exports.serializeConfigValue = serializeConfigValue;
24
- function serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements) {
24
+ function serializeConfigValueImported(configValueSource, configName, whitespace, importStatements) {
25
25
  (0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
26
26
  (0, utils_js_1.assert)(whitespace.replaceAll(' ', '').length === 0);
27
27
  const { valueIsImportedAtRuntime, valueIsDefinedByValueFile, definedAtFilePath } = configValueSource;
@@ -29,8 +29,7 @@ function serializeConfigValueImported(configValueSource, configName, whitespace,
29
29
  const { filePathAbsoluteVite, fileExportName } = definedAtFilePath;
30
30
  if (valueIsDefinedByValueFile)
31
31
  (0, utils_js_1.assert)(fileExportName === undefined);
32
- const { importName, importStatement } = (0, generateEagerImport_js_1.generateEagerImport)(filePathAbsoluteVite, varCounterContainer.varCounter++, fileExportName);
33
- importStatements.push(importStatement);
32
+ const { importName } = (0, addImportStatement_js_1.addImportStatement)(importStatements, filePathAbsoluteVite, fileExportName || '*');
34
33
  const lines = [];
35
34
  lines.push(` {`);
36
35
  lines.push(` configName: '${configName}',`);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = exports.projectInfo = void 0;
4
- const PROJECT_VERSION = '0.4.171-commit-2e4e1ce';
4
+ const PROJECT_VERSION = '0.4.171-commit-14f2e5d';
5
5
  exports.PROJECT_VERSION = PROJECT_VERSION;
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
@@ -0,0 +1,14 @@
1
+ export { addImportStatement };
2
+ /**
3
+ * Naming:
4
+ * `import { someExport as someImport } from './some-file'`
5
+ * <=>
6
+ * `{`
7
+ * `importPath: './some-file',`
8
+ * `exportName: 'someExport',`
9
+ * `importName: 'someImport',`
10
+ * `}`
11
+ */
12
+ declare function addImportStatement(importStatements: string[], importPath: string, exportName: string): {
13
+ importName: string;
14
+ };
@@ -1,5 +1,4 @@
1
- export { generateEagerImport };
2
- let varCounterGlobal = 0;
1
+ export { addImportStatement };
3
2
  /**
4
3
  * Naming:
5
4
  * `import { someExport as someImport } from './some-file'`
@@ -9,14 +8,12 @@ let varCounterGlobal = 0;
9
8
  * `exportName: 'someExport',`
10
9
  * `importName: 'someImport',`
11
10
  * `}`
12
- * We discard the information that the import variable is called `someImport` because we don't need it.
13
11
  */
14
- function generateEagerImport(importPath, varCounter, exportName) {
15
- if (varCounter === undefined)
16
- varCounter = varCounterGlobal++;
17
- const importName = `import_${varCounter}`;
12
+ function addImportStatement(importStatements, importPath, exportName) {
13
+ const importCounter = importStatements.length + 1;
14
+ const importName = `import${importCounter}`;
18
15
  const importLiteral = (() => {
19
- if (!exportName || exportName === '*') {
16
+ if (exportName === '*') {
20
17
  return `* as ${importName}`;
21
18
  }
22
19
  if (exportName === 'default') {
@@ -25,5 +22,6 @@ function generateEagerImport(importPath, varCounter, exportName) {
25
22
  return `{ ${exportName} as ${importName} }`;
26
23
  })();
27
24
  const importStatement = `import ${importLiteral} from '${importPath}';`;
28
- return { importName, importStatement };
25
+ importStatements.push(importStatement);
26
+ return { importName };
29
27
  }
@@ -1,5 +1,5 @@
1
1
  export { getConfigValuesSerialized };
2
2
  export { assertConfigValueIsSerializable };
3
3
  import type { ConfigEnvInternal, ConfigValueSource, DefinedAtData, PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
4
- declare function getConfigValuesSerialized(pageConfig: PageConfigBuildTime, isEnvMatch: (configEnv: ConfigEnvInternal, configValueSource?: ConfigValueSource) => boolean): string;
4
+ declare function getConfigValuesSerialized(pageConfig: PageConfigBuildTime, importStatements: string[], isEnvMatch: (configEnv: ConfigEnvInternal, configValueSource?: ConfigValueSource) => boolean): string;
5
5
  declare function assertConfigValueIsSerializable(value: unknown, configName: string, definedAtData: DefinedAtData): void;
@@ -6,7 +6,11 @@ import pc from '@brillout/picocolors';
6
6
  import { getConfigValueFilePathToShowToUser } from '../../../../../shared/page-configs/helpers.js';
7
7
  import { serializeConfigValue } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
8
8
  import { getConfigValueSourcesNotOverriden } from '../../../shared/getConfigValueSourcesNotOverriden.js';
9
- function getConfigValuesSerialized(pageConfig, isEnvMatch) {
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) {
10
14
  const lines = [];
11
15
  Object.entries(pageConfig.configValuesComputed).forEach(([configName, configValuesComputed]) => {
12
16
  const { configEnv } = configValuesComputed;
@@ -19,7 +23,7 @@ function getConfigValuesSerialized(pageConfig, isEnvMatch) {
19
23
  assert(configValue);
20
24
  const { value, ...common } = configValue;
21
25
  assert(value === configValuesComputed.value);
22
- const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData);
26
+ const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData, importStatements);
23
27
  const configValueSerialized = { valueSerialized, ...common };
24
28
  serializeConfigValue(lines, configName, configValueSerialized);
25
29
  });
@@ -32,7 +36,7 @@ function getConfigValuesSerialized(pageConfig, isEnvMatch) {
32
36
  return;
33
37
  }
34
38
  const { value, ...common } = configValue;
35
- const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData);
39
+ const valueSerialized = getConfigValueSerialized(value, configName, configValue.definedAtData, importStatements);
36
40
  const configValueSerialized = { valueSerialized, ...common };
37
41
  serializeConfigValue(lines, configName, configValueSerialized);
38
42
  });
@@ -41,30 +45,51 @@ function getConfigValuesSerialized(pageConfig, isEnvMatch) {
41
45
  }
42
46
  function assertConfigValueIsSerializable(value, configName, definedAtData) {
43
47
  // Contains asserts
44
- getConfigValueSerialized(value, configName, definedAtData);
48
+ getConfigValueSerialized(value, configName, definedAtData, []);
45
49
  }
46
- function getConfigValueSerialized(value, configName, definedAtData) {
50
+ function getConfigValueSerialized(value, configName, definedAtData, importStatements) {
47
51
  const valueName = `config${getPropAccessNotation(configName)}`;
48
52
  let configValueSerialized;
49
53
  try {
50
- configValueSerialized = stringify(value, { valueName, forbidReactElements: true });
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
+ });
51
68
  }
52
69
  catch (err) {
53
- /*
54
- let serializationErrMsg = ''
55
- if (isJsonSerializerError(err)) {
56
- serializationErrMsg = err.messageCore
57
- } else {
58
- // When a property getter throws an error
59
- console.error('Serialization error:')
60
- console.error(err)
61
- serializationErrMsg = 'see serialization error printed above'
62
- }
63
- */
64
- const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser(definedAtData);
65
- assert(configValueFilePathToShowToUser);
66
- assertUsage(false, `${pc.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined over a so-called "pointer import", see https://vike.dev/config#pointer-imports`);
70
+ logJsonSerializeError(err, configName, definedAtData);
71
+ assert(false);
67
72
  }
68
- configValueSerialized = JSON.stringify(configValueSerialized);
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));
69
77
  return configValueSerialized;
70
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
+ }
@@ -10,7 +10,7 @@ import { parsePointerImportData } from './transformFileImports.js';
10
10
  import { getConfigFileExport } from '../getConfigFileExport.js';
11
11
  import { resolvePointerImport } from './resolvePointerImport.js';
12
12
  assertIsNotProductionRuntime();
13
- // Load fake import
13
+ // Load pointer import
14
14
  async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
15
15
  const f = import_.filePathAbsoluteFilesystem;
16
16
  if (!importedFilesLoaded[f]) {
@@ -30,7 +30,7 @@ async function loadValueFile(interfaceValueFile, configName, userRootDir) {
30
30
  interfaceValueFile.fileExportsByConfigName[configName_] = { configValue };
31
31
  });
32
32
  }
33
- // Load +config.js, including all its extends fake imports
33
+ // Load +config.js, including all its extends pointer imports
34
34
  async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig) {
35
35
  const { filePathAbsoluteFilesystem } = configFilePath;
36
36
  assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
@@ -547,7 +547,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
547
547
  valueIsDefinedByValueFile: false,
548
548
  definedAtFilePath: pointerImport
549
549
  };
550
- // Load fake import
550
+ // Load pointer import
551
551
  if (isConfigEnv(configDef, configName) &&
552
552
  // The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
553
553
  configName !== 'extends') {
@@ -37,7 +37,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
37
37
  lines.push(getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements));
38
38
  lines.push('];');
39
39
  lines.push('export const configValuesSerialized = {');
40
- lines.push(getConfigValuesSerialized(pageConfig, (configEnv, configValueSource) => isEnvMatch(configEnv, !configValueSource ? false : checkWhetherIsImport(configValueSource), {
40
+ lines.push(getConfigValuesSerialized(pageConfig, importStatements, (configEnv, configValueSource) => isEnvMatch(configEnv, !configValueSource ? false : checkWhetherIsImport(configValueSource), {
41
41
  isImport: false,
42
42
  isForClientSide,
43
43
  isClientRouting
@@ -51,7 +51,6 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
51
51
  }
52
52
  function getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements) {
53
53
  const lines = [];
54
- const varCounterContainer = { varCounter: 0 };
55
54
  getConfigValueSourcesNotOverriden(pageConfig).forEach((configValueSource) => {
56
55
  if (!isEnvMatch(configValueSource.configEnv, checkWhetherIsImport(configValueSource), {
57
56
  isImport: true,
@@ -60,7 +59,7 @@ function getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, i
60
59
  }))
61
60
  return;
62
61
  const whitespace = ' ';
63
- lines.push(...serializeConfigValueImported(configValueSource, configValueSource.configName, whitespace, varCounterContainer, importStatements));
62
+ lines.push(...serializeConfigValueImported(configValueSource, configValueSource.configName, whitespace, importStatements));
64
63
  });
65
64
  const code = lines.join('\n');
66
65
  return code;
@@ -13,18 +13,17 @@ async function getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRou
13
13
  function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting) {
14
14
  const lines = [];
15
15
  const importStatements = [];
16
- const varCounterContainer = { varCounter: 0 };
17
16
  lines.push('export const pageConfigsSerialized = [');
18
- lines.push(getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements, varCounterContainer));
17
+ lines.push(getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements));
19
18
  lines.push('];');
20
19
  lines.push('export const pageConfigGlobalSerialized = {');
21
- lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements, varCounterContainer));
20
+ lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements));
22
21
  lines.push('};');
23
22
  const code = [...importStatements, ...lines].join('\n');
24
23
  debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
25
24
  return code;
26
25
  }
27
- function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements, varCounterContainer) {
26
+ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements) {
28
27
  const lines = [];
29
28
  pageConfigs.forEach((pageConfig) => {
30
29
  const { pageId, routeFilesystem, isErrorPage } = pageConfig;
@@ -36,7 +35,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
36
35
  lines.push(` loadConfigValuesAll: () => import(${JSON.stringify(virtualFileIdPageConfigValuesAll)}),`);
37
36
  // Serialized config values
38
37
  lines.push(` configValuesSerialized: {`);
39
- lines.push(getConfigValuesSerialized(pageConfig, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true })));
38
+ lines.push(getConfigValuesSerialized(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true })));
40
39
  lines.push(` },`);
41
40
  // Imported config values
42
41
  const whitespace = ' ';
@@ -51,7 +50,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
51
50
  return;
52
51
  if (!isRuntimeEnvMatch(configValueSource.configEnv, { isForClientSide, isClientRouting, isEager: true }))
53
52
  return;
54
- lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
53
+ lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, importStatements));
55
54
  });
56
55
  lines.push(`${whitespace}],`);
57
56
  lines.push(` },`);
@@ -59,7 +58,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
59
58
  const code = lines.join('\n');
60
59
  return code;
61
60
  }
62
- function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements, varCounterContainer) {
61
+ function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements) {
63
62
  const lines = [];
64
63
  /* Nothing (yet)
65
64
  lines.push(` configValuesSerialized: {`)
@@ -82,7 +81,7 @@ function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, is
82
81
  const configValueSource = sources[0];
83
82
  assert(configValueSource);
84
83
  const whitespace = ' ';
85
- lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
84
+ lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, importStatements));
86
85
  });
87
86
  lines.push(` ],`);
88
87
  const code = lines.join('\n');
@@ -1,6 +1,5 @@
1
1
  export { addSsrMiddleware };
2
2
  import { renderPage } from '../../runtime/renderPage.js';
3
- import { assertWarning } from '../utils.js';
4
3
  function addSsrMiddleware(middlewares) {
5
4
  middlewares.use(async (req, res, next) => {
6
5
  if (res.headersSent)
@@ -9,15 +8,10 @@ function addSsrMiddleware(middlewares) {
9
8
  if (!url)
10
9
  return next();
11
10
  const { headers } = req;
11
+ const userAgent = headers['user-agent'];
12
12
  const pageContextInit = {
13
13
  urlOriginal: url,
14
- get userAgent() {
15
- assertWarning(false, "pageContext.userAgent is deprecated in favor of pageContext.headers['user-agent']", {
16
- showStackTrace: true,
17
- onlyOnce: true
18
- });
19
- return headers['user-agent'];
20
- },
14
+ userAgent,
21
15
  headers
22
16
  };
23
17
  let pageContext;
@@ -165,31 +165,40 @@ async function renderTemplate(templateContent, pageContext) {
165
165
  setStream(templateVar);
166
166
  continue;
167
167
  }
168
- const getErrMsg = (typeText, end) => {
168
+ const getErrMsg = (msg) => {
169
169
  const { hookName, hookFilePath } = pageContext._renderHook;
170
170
  const nth = (i === 0 && '1st') || (i === 1 && '2nd') || (i === 2 && '3rd') || `${i}-th`;
171
- return [`The ${nth} HTML variable is ${typeText}, see ${hookName}() hook defined by ${hookFilePath}.`, end]
171
+ return [
172
+ `The ${nth} HTML variable is ${msg}`,
173
+ `The HTML was provided by the ${hookName}() hook at ${hookFilePath}.`
174
+ ]
172
175
  .filter(Boolean)
173
176
  .join(' ');
174
177
  };
175
- assertUsage(!isPromise(templateVar), getErrMsg('a promise', `Did you forget to ${pc.cyan('await')} the promise?`));
178
+ assertUsage(!isPromise(templateVar), getErrMsg(`a promise, did you forget to ${pc.cyan('await')} the promise?`));
176
179
  if (templateVar === undefined || templateVar === null) {
177
- assertWarning(false, getErrMsg(`${pc.cyan(String(templateVar))} which will be converted to an empty string`, `Pass the empty string ${pc.cyan("''")} instead of ${pc.cyan(String(templateVar))} to remove this warning.`), { onlyOnce: false });
180
+ const msgVal = pc.cyan(String(templateVar));
181
+ const msgEmptyString = pc.cyan("''");
182
+ const msg = `${msgVal} which will be converted to an empty string. Pass the empty string ${msgEmptyString} instead of ${msgVal} to remove this warning.`;
183
+ assertWarning(false, getErrMsg(msg), { onlyOnce: false });
178
184
  templateVar = '';
179
185
  }
180
186
  {
181
187
  const varType = typeof templateVar;
182
- const streamNote = ['boolean', 'number', 'bigint', 'symbol'].includes(varType)
183
- ? null
184
- : '(See https://vike.dev/streaming for HTML streaming.)';
185
- assertUsage(varType === 'string', getErrMsg(pc.cyan(`typeof htmlVar === "${varType}"`), streamNote));
188
+ if (varType !== 'string') {
189
+ const msgType = pc.cyan(`typeof htmlVariable === "${varType}"`);
190
+ const msg = `${msgType} but a string or stream (https://vike.dev/streaming) is expected instead.`;
191
+ assertUsage(false, getErrMsg(msg));
192
+ }
186
193
  }
187
194
  {
188
195
  const { isProduction } = getGlobalContext();
189
196
  if (isHtml(templateVar) &&
190
197
  // We don't show this warning in production because it's expected that some users may (un)willingly do some XSS injection: we avoid flooding the production logs.
191
198
  !isProduction) {
192
- assertWarning(false, getErrMsg(`${pc.cyan(templateVar)} which seems to be HTML code`, 'Did you forget to wrap the value with dangerouslySkipEscape()?'), { onlyOnce: false });
199
+ const msgVal = pc.cyan(String(templateVar));
200
+ const msg = `${msgVal} which seems to be HTML code. Did you forget to wrap the value with dangerouslySkipEscape()?`;
201
+ assertWarning(false, getErrMsg(msg), { onlyOnce: false });
193
202
  }
194
203
  }
195
204
  // Escape untrusted template variable
@@ -1,12 +1,13 @@
1
1
  export { parseConfigValuesSerialized };
2
2
  import { assert, isArray } from '../../utils.js';
3
- import { parse } from '@brillout/json-serializer/parse';
4
3
  function parseConfigValuesSerialized(configValuesSerialized) {
5
4
  const configValues = {};
6
5
  Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
7
6
  assert(!configValues[configName]);
8
7
  const { valueSerialized, ...common } = configValueSeriliazed;
9
- const value = parse(valueSerialized);
8
+ console.log('valueSerialized', valueSerialized);
9
+ // const value = parse(valueSerialized)
10
+ const value = valueSerialized;
10
11
  let configValue;
11
12
  if (common.type === 'cumulative') {
12
13
  assert(isArray(value));
@@ -3,6 +3,4 @@ export { serializeConfigValueImported };
3
3
  import { ConfigValueSource } from '../PageConfig.js';
4
4
  import { ConfigValueSerialized } from './PageConfigSerialized.js';
5
5
  declare function serializeConfigValue(lines: string[], configName: string, configValueSerialized: ConfigValueSerialized): void;
6
- declare function serializeConfigValueImported(configValueSource: ConfigValueSource, configName: string, whitespace: string, varCounterContainer: {
7
- varCounter: number;
8
- }, importStatements: string[]): string[];
6
+ declare function serializeConfigValueImported(configValueSource: ConfigValueSource, configName: string, whitespace: string, importStatements: string[]): string[];
@@ -7,7 +7,7 @@ export { serializeConfigValueImported };
7
7
  import { assertIsNotProductionRuntime } from '../../../utils/assertIsNotProductionRuntime.js';
8
8
  assertIsNotProductionRuntime();
9
9
  import { assert } from '../../utils.js';
10
- import { generateEagerImport } from '../../../node/plugin/plugins/importUserCode/generateEagerImport.js';
10
+ import { addImportStatement } from '../../../node/plugin/plugins/importUserCode/addImportStatement.js';
11
11
  function serializeConfigValue(lines, configName, configValueSerialized) {
12
12
  let whitespace = ' ';
13
13
  lines.push(`${whitespace}['${configName}']: {`);
@@ -19,7 +19,7 @@ function serializeConfigValue(lines, configName, configValueSerialized) {
19
19
  whitespace = whitespace.slice(2);
20
20
  lines.push(`${whitespace}},`);
21
21
  }
22
- function serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements) {
22
+ function serializeConfigValueImported(configValueSource, configName, whitespace, importStatements) {
23
23
  assert(!configValueSource.valueIsFilePath);
24
24
  assert(whitespace.replaceAll(' ', '').length === 0);
25
25
  const { valueIsImportedAtRuntime, valueIsDefinedByValueFile, definedAtFilePath } = configValueSource;
@@ -27,8 +27,7 @@ function serializeConfigValueImported(configValueSource, configName, whitespace,
27
27
  const { filePathAbsoluteVite, fileExportName } = definedAtFilePath;
28
28
  if (valueIsDefinedByValueFile)
29
29
  assert(fileExportName === undefined);
30
- const { importName, importStatement } = generateEagerImport(filePathAbsoluteVite, varCounterContainer.varCounter++, fileExportName);
31
- importStatements.push(importStatement);
30
+ const { importName } = addImportStatement(importStatements, filePathAbsoluteVite, fileExportName || '*');
32
31
  const lines = [];
33
32
  lines.push(` {`);
34
33
  lines.push(` configName: '${configName}',`);
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- declare const PROJECT_VERSION: "0.4.171-commit-2e4e1ce";
3
+ declare const PROJECT_VERSION: "0.4.171-commit-14f2e5d";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.171-commit-2e4e1ce";
6
+ projectVersion: "0.4.171-commit-14f2e5d";
7
7
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- const PROJECT_VERSION = '0.4.171-commit-2e4e1ce';
3
+ const PROJECT_VERSION = '0.4.171-commit-14f2e5d';
4
4
  const projectInfo = {
5
5
  projectName: 'Vike',
6
6
  projectVersion: PROJECT_VERSION
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.171-commit-2e4e1ce",
3
+ "version": "0.4.171-commit-14f2e5d",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@brillout/import": "^0.2.3",
17
- "@brillout/json-serializer": "^0.5.8",
17
+ "@brillout/json-serializer": "^0.5.9",
18
18
  "@brillout/picocolors": "^1.0.10",
19
19
  "@brillout/require-shim": "^0.1.2",
20
20
  "@brillout/vite-plugin-server-entry": "^0.4.5",
@@ -195,23 +195,23 @@
195
195
  "@brillout/import": "^0.2.3",
196
196
  "@brillout/json-serializer": "^0.5.8",
197
197
  "@brillout/picocolors": "^1.0.10",
198
+ "@brillout/release-me": "^0.3.7",
198
199
  "@brillout/require-shim": "^0.1.2",
199
200
  "@brillout/vite-plugin-server-entry": "^0.4.0",
200
- "acorn": "^8.11.2",
201
- "cac": "^6.7.14",
202
- "es-module-lexer": "^1.4.1",
203
- "esbuild": "^0.19.10",
204
- "fast-glob": "^3.3.2",
205
- "sirv": "^2.0.4",
206
- "source-map-support": "^0.5.21",
207
- "@brillout/release-me": "^0.3.7",
208
201
  "@types/estree": "^1.0.5",
209
202
  "@types/jest": "^29.5.11",
210
203
  "@types/node": "^20.10.5",
211
204
  "@types/resolve": "^1.20.6",
212
205
  "@types/source-map-support": "^0.5.10",
206
+ "acorn": "^8.11.2",
207
+ "cac": "^6.7.14",
208
+ "es-module-lexer": "^1.4.1",
209
+ "esbuild": "^0.19.10",
210
+ "fast-glob": "^3.3.2",
213
211
  "react-streaming": "^0.3.24",
214
212
  "rimraf": "^5.0.5",
213
+ "sirv": "^2.0.4",
214
+ "source-map-support": "^0.5.21",
215
215
  "typescript": "^5.3.3",
216
216
  "vite": "npm:@brillout/vite@5.1.0-commit-3dc7abd"
217
217
  },
@@ -1,16 +0,0 @@
1
- export { generateEagerImport };
2
- /**
3
- * Naming:
4
- * `import { someExport as someImport } from './some-file'`
5
- * <=>
6
- * `{`
7
- * `importPath: './some-file',`
8
- * `exportName: 'someExport',`
9
- * `importName: 'someImport',`
10
- * `}`
11
- * We discard the information that the import variable is called `someImport` because we don't need it.
12
- */
13
- declare function generateEagerImport(importPath: string, varCounter?: number, exportName?: string): {
14
- importName: string;
15
- importStatement: string;
16
- };