vike 0.4.160-commit-a1101c1 → 0.4.160-commit-facd36e

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 (83) hide show
  1. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +2 -2
  2. package/dist/cjs/node/plugin/plugins/buildConfig.js +9 -0
  3. package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
  4. package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
  6. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
  7. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +5 -5
  8. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +2 -2
  10. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +7 -7
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +21 -27
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +149 -110
  13. package/dist/cjs/node/plugin/utils.js +1 -2
  14. package/dist/cjs/node/prerender/runPrerender.js +12 -5
  15. package/dist/cjs/node/runtime/globalContext.js +7 -4
  16. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  17. package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
  18. package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
  19. package/dist/cjs/node/runtime/utils.js +1 -1
  20. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
  21. package/dist/cjs/shared/route/executeGuardHook.js +3 -2
  22. package/dist/cjs/shared/utils.js +0 -1
  23. package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
  24. package/dist/cjs/utils/nodeEnv.js +23 -1
  25. package/dist/cjs/utils/objectKeys.js +19 -3
  26. package/dist/cjs/utils/projectInfo.js +1 -1
  27. package/dist/cjs/utils/sorter.js +62 -1
  28. package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
  29. package/dist/esm/node/plugin/plugins/buildConfig.js +10 -1
  30. package/dist/esm/node/plugin/plugins/commonConfig.js +2 -2
  31. package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -2
  32. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -0
  33. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
  34. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
  35. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
  36. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
  37. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +4 -4
  38. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
  39. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
  40. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +1 -1
  41. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
  42. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.d.ts → transformFileImports.d.ts} +2 -2
  43. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +6 -6
  44. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
  45. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +20 -26
  46. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -0
  47. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +148 -109
  48. package/dist/esm/node/plugin/utils.d.ts +1 -2
  49. package/dist/esm/node/plugin/utils.js +1 -2
  50. package/dist/esm/node/prerender/runPrerender.js +13 -6
  51. package/dist/esm/node/runtime/globalContext.js +8 -5
  52. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  53. package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
  54. package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
  55. package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
  56. package/dist/esm/node/runtime/utils.d.ts +1 -1
  57. package/dist/esm/node/runtime/utils.js +1 -1
  58. package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -0
  59. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
  60. package/dist/esm/shared/route/executeGuardHook.js +3 -2
  61. package/dist/esm/shared/utils.d.ts +0 -1
  62. package/dist/esm/shared/utils.js +0 -1
  63. package/dist/esm/utils/findFile.d.ts +3 -0
  64. package/dist/esm/utils/findFile.js +21 -0
  65. package/dist/esm/utils/nodeEnv.d.ts +4 -0
  66. package/dist/esm/utils/nodeEnv.js +19 -0
  67. package/dist/esm/utils/objectKeys.d.ts +10 -1
  68. package/dist/esm/utils/objectKeys.js +20 -3
  69. package/dist/esm/utils/projectInfo.d.ts +2 -2
  70. package/dist/esm/utils/projectInfo.js +1 -1
  71. package/dist/esm/utils/sorter.d.ts +59 -0
  72. package/dist/esm/utils/sorter.js +61 -0
  73. package/package.json +1 -1
  74. package/dist/cjs/utils/objectEntries.js +0 -8
  75. package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
  76. package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
  77. package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
  78. package/dist/esm/utils/objectEntries.d.ts +0 -4
  79. package/dist/esm/utils/objectEntries.js +0 -5
  80. /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
  81. /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.d.ts → loadFileAtConfigTime.d.ts} +0 -0
  82. /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
  83. /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
@@ -3,22 +3,33 @@ 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.getHint = exports.isReactInvalidComponentError = exports.isCjsEsmError = exports.logHintForCjsEsmError = void 0;
6
+ exports.getHint = exports.isKnownError = exports.isCjsEsmError = exports.logErrorHint = void 0;
7
7
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
8
8
  const utils_js_1 = require("../utils.js");
9
- function logHintForCjsEsmError(error) {
10
- /* Collect errors for ./logHintForCjsEsmError.spec.ts
9
+ const knownErrors = [
10
+ {
11
+ errMsg: 'jsxDEV is not a function',
12
+ link: 'https://github.com/vikejs/vike/issues/1469#issuecomment-1919518096'
13
+ },
14
+ {
15
+ errMsg: 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)',
16
+ link: 'https://vike.dev/broken-npm-package#react-invalid-component'
17
+ }
18
+ ];
19
+ function logErrorHint(error) {
20
+ /* Collect errors for ./logErrorHint.spec.ts
11
21
  collectError(error)
12
22
  //*/
13
23
  const hint = getHint(error);
14
24
  if (hint)
15
25
  logHint(hint);
16
26
  }
17
- exports.logHintForCjsEsmError = logHintForCjsEsmError;
27
+ exports.logErrorHint = logErrorHint;
18
28
  function getHint(error) {
19
- if (isReactInvalidComponentError(error)) {
20
- const hint = 'To fix this error, see https://vike.dev/broken-npm-package#react-invalid-component';
21
- return hint;
29
+ {
30
+ const link = isKnownError(error);
31
+ if (link)
32
+ return `To fix this error, see ${link}`;
22
33
  }
23
34
  const res = isCjsEsmError(error);
24
35
  if (res) {
@@ -40,44 +51,73 @@ function logHint(hint) {
40
51
  hint = (0, utils_js_1.formatHintLog)(hint);
41
52
  console.error(hint);
42
53
  }
43
- function isReactInvalidComponentError(error) {
54
+ function isKnownError(error) {
44
55
  const anywhere = getAnywhere(error);
45
- return includes(anywhere, 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)');
56
+ const knownErr = knownErrors.find((knownErorr) => {
57
+ return includes(anywhere, knownErorr.errMsg);
58
+ });
59
+ if (!knownErr)
60
+ return false;
61
+ return knownErr.link;
46
62
  }
47
- exports.isReactInvalidComponentError = isReactInvalidComponentError;
48
- /**
49
- * `false` -> noop
50
- * `true` -> generic message
51
- * `'some-npm-package'` -> add some-npm-package to `ssr.noExternal`
52
- */
63
+ exports.isKnownError = isKnownError;
64
+ // `false` -> noop
65
+ // `true` -> generic message
66
+ // `'some-npm-package'` -> add some-npm-package to `ssr.noExternal`
53
67
  function isCjsEsmError(error) {
68
+ const res = check(error);
69
+ if (res === true || res === false)
70
+ return res;
71
+ const packageNames = normalizeRes(res);
72
+ if (packageNames === false)
73
+ return packageNames;
74
+ packageNames.forEach((packageName) => {
75
+ (0, utils_js_1.assert)(!['vite', 'vike'].includes(packageName));
76
+ });
77
+ return packageNames;
78
+ }
79
+ exports.isCjsEsmError = isCjsEsmError;
80
+ function normalizeRes(res) {
81
+ let packageNames = Array.isArray(res) ? res : [res];
82
+ packageNames = (0, utils_js_1.unique)(packageNames.filter(utils_js_1.isNotNullish).filter((packageName) => packageName !== '@brillout/import'));
83
+ if (packageNames.length === 0)
84
+ return false;
85
+ return packageNames;
86
+ }
87
+ function check(error) {
54
88
  const message = getErrMessage(error);
55
89
  const anywhere = getAnywhere(error);
56
90
  const packageName_stack1 = getPackageName_stack1(error);
57
91
  const packageName_stack2 = getPackageName_stack2(error);
58
92
  const isRelatedToNodeModules = !!packageName_stack1 || !!packageName_stack2 || includesNodeModules(message);
59
- // const relatedNpmPackages = normalize([packageName_stack1, packageName_stack2, extractFromNodeModulesPath(message)])
93
+ /*
94
+ const relatedNpmPackages = normalizeArray([
95
+ packageName_stack1 || null,
96
+ packageName_stack2 || null,
97
+ (message && extractFromNodeModulesPath(message)) || null
98
+ ])
99
+ */
60
100
  // ERR_UNSUPPORTED_DIR_IMPORT
61
101
  {
62
- const packageNames = parseNodeModulesPathMessage('ERR_UNSUPPORTED_DIR_IMPORT', anywhere);
63
- if (packageNames)
64
- return packageNames;
102
+ const packageName = parseNodeModulesPathMessage('ERR_UNSUPPORTED_DIR_IMPORT', anywhere);
103
+ if (packageName)
104
+ return packageName;
65
105
  }
66
106
  // ERR_UNKNOWN_FILE_EXTENSION
67
107
  {
68
- const packageNames = parseUnkownFileExtensionMessage(anywhere);
69
- if (packageNames)
70
- return packageNames;
108
+ const packageName = parseUnkownFileExtensionMessage(anywhere);
109
+ if (packageName)
110
+ return packageName;
71
111
  }
72
112
  {
73
- const packageNames = parseNodeModulesPathMessage('ERR_UNKNOWN_FILE_EXTENSION', anywhere);
74
- if (packageNames)
75
- return packageNames;
113
+ const packageName = parseNodeModulesPathMessage('ERR_UNKNOWN_FILE_EXTENSION', anywhere);
114
+ if (packageName)
115
+ return packageName;
76
116
  }
77
117
  {
78
- const packageNames = parseNodeModulesPathMessage('is not exported', anywhere);
79
- if (packageNames)
80
- return packageNames;
118
+ const packageName = parseNodeModulesPathMessage('is not exported', anywhere);
119
+ if (packageName)
120
+ return packageName;
81
121
  }
82
122
  // Using CJS inside ESM modules.
83
123
  if (includes(anywhere, 'require is not a function') ||
@@ -98,7 +138,7 @@ function isCjsEsmError(error) {
98
138
  if (includes(anywhere, 'ERR_REQUIRE_ESM')) {
99
139
  /* The issue is the importer, not the importee.
100
140
  if (relatedNpmPackages) return relatedNpmPackages
101
- */
141
+ */
102
142
  {
103
143
  if (packageName_stack1)
104
144
  return packageName_stack1;
@@ -118,9 +158,9 @@ function isCjsEsmError(error) {
118
158
  */
119
159
  // `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
120
160
  {
121
- const packageNames = parseImportFrom(anywhere);
122
- if (packageNames)
123
- return packageNames;
161
+ const packageName = parseImportFrom(anywhere);
162
+ if (packageName)
163
+ return packageName;
124
164
  }
125
165
  if (includes(anywhere, 'Cannot read properties of undefined')) {
126
166
  if (isRelatedToNodeModules) {
@@ -150,14 +190,13 @@ function isCjsEsmError(error) {
150
190
  }
151
191
  return false;
152
192
  }
153
- exports.isCjsEsmError = isCjsEsmError;
154
193
  function parseCannotFindMessage(str) {
155
194
  const match = /Cannot find \S+ '(\S+)' imported from (\S+)/.exec(str);
156
195
  if (!match)
157
196
  return false;
158
197
  // const packageNameCannotFind = extractFromPath(match[1]!)
159
198
  const packageNameFrom = extractFromPath(match[2]);
160
- return normalize([
199
+ return normalizeArray([
161
200
  // packageNameCannotFind,
162
201
  packageNameFrom
163
202
  ]);
@@ -168,7 +207,7 @@ function parseUnkownFileExtensionMessage(str) {
168
207
  return false;
169
208
  const filePath = match[1];
170
209
  const packageName = extractFromPath(filePath);
171
- return normalize([packageName]);
210
+ return packageName;
172
211
  }
173
212
  function parseImportFrom(str) {
174
213
  const match = /\bimport\b.*?\bfrom\b\s*?"(.+?)"/.exec(str);
@@ -176,7 +215,7 @@ function parseImportFrom(str) {
176
215
  return false;
177
216
  const importPath = match[1];
178
217
  const packageName = extractFromPath(importPath);
179
- return normalize([packageName]);
218
+ return packageName;
180
219
  }
181
220
  function parseNodeModulesPathMessage(begin, str) {
182
221
  str = str.replaceAll('\\', '/');
@@ -230,7 +269,6 @@ function extractFromPath(filePath) {
230
269
  packageName = packageName.split('/')[0];
231
270
  }
232
271
  packageName = clean(packageName);
233
- (0, utils_js_1.assert)(!['vite', 'vike'].includes(packageName));
234
272
  return packageName;
235
273
  }
236
274
  function clean(packageName) {
@@ -248,7 +286,7 @@ function extractFromNodeModulesPath(str) {
248
286
  return false;
249
287
  const packageName = extractFromPath(str);
250
288
  (0, utils_js_1.assert)(packageName);
251
- return normalize([packageName]);
289
+ return packageName;
252
290
  }
253
291
  function includes(str1, str2) {
254
292
  return !!str1 && str1.toLowerCase().includes(str2.toLowerCase());
@@ -263,11 +301,11 @@ function includesNodeModules(str) {
263
301
  return false;
264
302
  return true;
265
303
  }
266
- function normalize(packageNames) {
267
- const result = (0, utils_js_1.unique)(packageNames.filter(utils_js_1.isNotNullish).filter((packageName) => packageName !== '@brillout/import'));
268
- if (result.length === 0)
269
- return false;
270
- return result;
304
+ function normalizeArray(arr) {
305
+ const arrNormalized = arr.filter(utils_js_1.isNotNullish);
306
+ if (arrNormalized.length === 0)
307
+ return null;
308
+ return arrNormalized;
271
309
  }
272
310
  function getErrMessage(err) {
273
311
  if (!(0, utils_js_1.isObject)(err))
@@ -10,7 +10,7 @@ const abort_js_1 = require("../../../shared/route/abort.js");
10
10
  const isNewError_js_1 = require("./isNewError.js");
11
11
  const utils_js_1 = require("../utils.js");
12
12
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
13
- const logHintForCjsEsmError_js_1 = require("./logHintForCjsEsmError.js");
13
+ const logErrorHint_js_1 = require("./logErrorHint.js");
14
14
  function logErrorProd(err, _httpRquestId) {
15
15
  (0, utils_js_1.warnIfErrorIsNotObject)(err);
16
16
  (0, isNewError_js_1.setAlreadyLogged)(err);
@@ -25,7 +25,7 @@ function logErrorProd(err, _httpRquestId) {
25
25
  exports.logErrorProd = logErrorProd;
26
26
  // Every server-side runtime error is expected to go through onRuntimeError(). (In principle, any runtime error is (or at least should) be catched by Vike, otherwise Vike couldn't render the error page.)
27
27
  function onRuntimeError(err) {
28
- // The more runtime errors we pass to logHintForCjsEsmError() the better.
29
- (0, logHintForCjsEsmError_js_1.logHintForCjsEsmError)(err);
28
+ // The more runtime errors we pass to logErrorHint() the better.
29
+ (0, logErrorHint_js_1.logErrorHint)(err);
30
30
  }
31
31
  exports.onRuntimeError = onRuntimeError;
@@ -55,7 +55,7 @@ __exportStar(require("../../utils/isNpmPackage.js"), exports);
55
55
  __exportStar(require("../../utils/isNotNullish.js"), exports);
56
56
  __exportStar(require("../../utils/isScriptFile.js"), exports);
57
57
  __exportStar(require("../../utils/removeFileExtention.js"), exports);
58
- __exportStar(require("../../utils/objectEntries.js"), exports);
58
+ __exportStar(require("../../utils/objectKeys.js"), exports);
59
59
  __exportStar(require("../../utils/isStringRecord.js"), exports);
60
60
  __exportStar(require("../../utils/getFileExtension.js"), exports);
61
61
  __exportStar(require("../../utils/assertIsNotProductionRuntime.js"), exports);
@@ -4,41 +4,68 @@ exports.parseConfigValuesImported = void 0;
4
4
  const utils_js_1 = require("../../utils.js");
5
5
  const assertPlusFileExport_js_1 = require("../assertPlusFileExport.js");
6
6
  function parseConfigValuesImported(configValuesImported) {
7
- const configValues = {};
8
- const addConfigValue = (configName, value, importPath, exportName) => {
9
- configValues[configName] = {
10
- value,
11
- definedAt: {
12
- // importPath cannot be relative to the current file, since the current file is a virtual file
13
- filePathToShowToUser: importPath,
14
- fileExportPathToShowToUser: [configName, 'default'].includes(exportName)
15
- ? []
16
- : // Side-effect config
17
- [exportName]
18
- }
19
- };
20
- assertIsNotNull(value, configName, importPath);
21
- };
22
- configValuesImported.forEach((configValueLoaded) => {
7
+ const configValuesUnmerged = {};
8
+ configValuesImported
9
+ .filter((c) => c.configName !== 'client')
10
+ .forEach((configValueLoaded) => {
23
11
  if (configValueLoaded.isValueFile) {
24
12
  const { exportValues, importPath, configName } = configValueLoaded;
25
- if (configName !== 'client') {
26
- (0, assertPlusFileExport_js_1.assertPlusFileExport)(exportValues, importPath, configName);
27
- }
13
+ (0, assertPlusFileExport_js_1.assertPlusFileExport)(exportValues, importPath, configName);
28
14
  Object.entries(exportValues).forEach(([exportName, exportValue]) => {
29
15
  const isSideExport = exportName !== 'default'; // .md files may have "side-exports" such as `export { frontmatter }`
30
16
  const configName = isSideExport ? exportName : configValueLoaded.configName;
31
- if (isSideExport && configName in configValues) {
32
- // We can't avoid side-export conflicts upstream. (Because we cannot know about side-exports upstream at build-time.)
33
- // Side-exports have the lowest priority.
34
- return;
35
- }
36
- addConfigValue(configName, exportValue, importPath, exportName);
17
+ configValuesUnmerged[configName] ?? (configValuesUnmerged[configName] = []);
18
+ configValuesUnmerged[configName].push({
19
+ value: exportValue,
20
+ importPath,
21
+ exportName,
22
+ isSideExport
23
+ });
37
24
  });
38
25
  }
39
26
  else {
40
27
  const { configName, importPath, exportValue, exportName } = configValueLoaded;
41
- addConfigValue(configName, exportValue, importPath, exportName);
28
+ configValuesUnmerged[configName] ?? (configValuesUnmerged[configName] = []);
29
+ configValuesUnmerged[configName].push({
30
+ value: exportValue,
31
+ importPath,
32
+ exportName,
33
+ isSideExport: false
34
+ });
35
+ }
36
+ });
37
+ const configValues = {};
38
+ Object.entries(configValuesUnmerged).forEach(([configName, values]) => {
39
+ const valuesWithoutSideExports = values.filter((v) => !v.isSideExport);
40
+ const isCumulative = valuesWithoutSideExports.length > 1;
41
+ const noSideExports = valuesWithoutSideExports.length === values.length;
42
+ if (isCumulative) {
43
+ // Vike currently doesn't support side exports for cumulative configs
44
+ (0, utils_js_1.assert)(noSideExports);
45
+ // TODO: implement
46
+ (0, utils_js_1.assert)(false);
47
+ }
48
+ else {
49
+ const val = valuesWithoutSideExports[0] ??
50
+ // We can't avoid side-export conflicts upstream. (We cannot know about side-exports at build-time.)
51
+ // Side-exports have lower precedence.
52
+ values[0];
53
+ (0, utils_js_1.assert)(val);
54
+ const { value, importPath, exportName } = val;
55
+ configValues[configName] = {
56
+ value,
57
+ definedAt: {
58
+ // importPath cannot be relative to the current file, since the current file is a virtual file
59
+ filePathToShowToUser: importPath,
60
+ fileExportPathToShowToUser: [configName, 'default'].includes(exportName)
61
+ ? []
62
+ : [
63
+ // Side-export
64
+ exportName
65
+ ]
66
+ }
67
+ };
68
+ assertIsNotNull(value, configName, importPath);
42
69
  }
43
70
  });
44
71
  return configValues;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeGuardHook = void 0;
4
4
  const getHook_js_1 = require("../hooks/getHook.js");
5
5
  const utils_js_1 = require("./utils.js");
6
+ const errIntro = 'The guard() hook defined by';
6
7
  async function executeGuardHook(pageContext, prepareForUserConsumption) {
7
8
  let hook;
8
9
  if (pageContext._pageFilesAll.length > 0) {
@@ -22,7 +23,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
22
23
  if (res)
23
24
  pageContextForUserConsumption = res;
24
25
  const hookResult = await (0, utils_js_1.executeHook)(() => guard(pageContextForUserConsumption), hook);
25
- (0, utils_js_1.assertUsage)(hookResult === undefined, `The guard() hook of ${hook.hookFilePath} returns a value, but guard() doesn't accept any return value`);
26
+ (0, utils_js_1.assertUsage)(hookResult === undefined, `${errIntro} ${hook.hookFilePath} returns a value, but guard() shouldn't return any value`);
26
27
  }
27
28
  exports.executeGuardHook = executeGuardHook;
28
29
  function findPageGuard(pageId, pageFilesAll) {
@@ -36,6 +37,6 @@ function findPageGuard(pageId, pageFilesAll) {
36
37
  return null;
37
38
  const hookFilePath = filePath;
38
39
  const hookTimeout = (0, getHook_js_1.getHookTimeoutDefault)('guard');
39
- (0, utils_js_1.assertUsage)((0, utils_js_1.isCallable)(hookFn), `guard() defined by ${hookFilePath} should be a function`);
40
+ (0, utils_js_1.assertUsage)((0, utils_js_1.isCallable)(hookFn), `${errIntro} ${hookFilePath} should be a function`);
40
41
  return { hookFn, hookName: 'guard', hookFilePath, hookTimeout };
41
42
  }
@@ -38,6 +38,5 @@ __exportStar(require("../utils/projectInfo.js"), exports);
38
38
  __exportStar(require("../utils/isPropertyGetter.js"), exports);
39
39
  __exportStar(require("../utils/isPromise.js"), exports);
40
40
  __exportStar(require("../utils/checkType.js"), exports);
41
- __exportStar(require("../utils/objectEntries.js"), exports);
42
41
  __exportStar(require("../utils/getValuePrintable.js"), exports);
43
42
  __exportStar(require("../utils/escapeRegex.js"), exports);
@@ -3,16 +3,19 @@ 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.findUserPackageJsonPath = void 0;
6
+ exports.findFile = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
- function findUserPackageJsonPath(userDir) {
10
- let dir = userDir;
9
+ function findFile(arg, cwd) {
10
+ const filenames = Array.isArray(arg) ? arg : [arg];
11
+ let dir = cwd;
11
12
  while (true) {
12
- const configFilePath = path_1.default.join(dir, './package.json');
13
- if (fs_1.default.existsSync(configFilePath)) {
14
- // return toPosixPath(configFilePath)
15
- return configFilePath;
13
+ for (const filename of filenames) {
14
+ const configFilePath = path_1.default.join(dir, `./${filename}`);
15
+ if (fs_1.default.existsSync(configFilePath)) {
16
+ // return toPosixPath(configFilePath)
17
+ return configFilePath;
18
+ }
16
19
  }
17
20
  const dirPrevious = dir;
18
21
  dir = path_1.default.dirname(dir);
@@ -21,4 +24,4 @@ function findUserPackageJsonPath(userDir) {
21
24
  }
22
25
  }
23
26
  }
24
- exports.findUserPackageJsonPath = findUserPackageJsonPath;
27
+ exports.findFile = findFile;
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNodeEnvDev = exports.setNodeEnvToProduction = exports.getNodeEnv = void 0;
6
+ exports.assertNodeEnvIsNotDev = exports.getNodeEnvDesc = exports.isNodeEnvDev = exports.setNodeEnvToProduction = exports.getNodeEnv = void 0;
7
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
8
+ const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
9
+ const assert_js_1 = require("./assert.js");
10
+ (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
4
11
  function getNodeEnv() {
5
12
  if (typeof process === 'undefined')
6
13
  return null;
@@ -24,3 +31,18 @@ function isNodeEnvDev() {
24
31
  return false;
25
32
  }
26
33
  exports.isNodeEnvDev = isNodeEnvDev;
34
+ function getNodeEnvDesc() {
35
+ const nodeEnv = getNodeEnv();
36
+ const isDev = isNodeEnvDev();
37
+ const nodeEnvDesc = `environment is set to be a ${(isDev ? 'development' : 'production')} environment by ${picocolors_1.default.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`)}`;
38
+ return nodeEnvDesc;
39
+ }
40
+ exports.getNodeEnvDesc = getNodeEnvDesc;
41
+ function assertNodeEnvIsNotDev(operation) {
42
+ const isDev = isNodeEnvDev();
43
+ if (!isDev)
44
+ return;
45
+ const nodeEnvDesc = getNodeEnvDesc();
46
+ (0, assert_js_1.assertUsage)(false, `The ${nodeEnvDesc} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`);
47
+ }
48
+ exports.assertNodeEnvIsNotDev = assertNodeEnvIsNotDev;
@@ -1,10 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.objectKeys = void 0;
3
+ exports.objectKeys = exports.objectFromEntries = exports.objectEntries = void 0;
4
+ // https://stackoverflow.com/questions/60141960/typescript-key-value-relation-preserving-object-entries-type/75337277#75337277
5
+ /** Same as Object.entries() but with type inference */
6
+ function objectEntries(obj) {
7
+ return Object.entries(obj);
8
+ }
9
+ exports.objectEntries = objectEntries;
10
+ /** Same as Object.fromEntries() but with type inference */
11
+ function objectFromEntries(arr) {
12
+ return Object.fromEntries(arr);
13
+ }
14
+ exports.objectFromEntries = objectFromEntries;
15
+ // https://stackoverflow.com/questions/52856496/typescript-object-keys-return-string
16
+ // https://github.com/sindresorhus/ts-extras/blob/main/source/object-keys.ts
4
17
  /** Same as Object.keys() but with type inference */
5
18
  function objectKeys(obj) {
6
19
  return Object.keys(obj);
7
20
  }
8
21
  exports.objectKeys = objectKeys;
9
- // https://stackoverflow.com/questions/52856496/typescript-object-keys-return-string
10
- // https://github.com/sindresorhus/ts-extras/blob/main/source/object-keys.ts
22
+ /*
23
+ function objectKeys2<T extends Record<string, unknown>>(obj: T): Array<keyof T> {
24
+ return Object.keys(obj)
25
+ }
26
+ */
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = exports.projectInfo = void 0;
4
4
  const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
5
- const PROJECT_VERSION = '0.4.160-commit-a1101c1';
5
+ const PROJECT_VERSION = '0.4.160-commit-facd36e';
6
6
  exports.PROJECT_VERSION = PROJECT_VERSION;
7
7
  const projectInfo = {
8
8
  projectName: 'Vike',
@@ -1,10 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeLast = exports.makeFirst = exports.lowerFirst = exports.higherFirst = void 0;
3
+ exports.reverse = exports.makeLast = exports.makeFirst = exports.lowerFirst = exports.higherFirst = void 0;
4
4
  const assert_js_1 = require("./assert.js");
5
5
  // -1 => element1 first (i.e. `indexOf(element1) < indexOf(element2)`)
6
6
  // +1 => element2 first (i.e. `indexOf(element2) < indexOf(element1)`)
7
7
  // 0 => keep original order of element1 and element2
8
+ /**
9
+ * ```js
10
+ * let arr = [
11
+ * { price: 10 },
12
+ * { price: 1000 },
13
+ * { price: 100 }
14
+ * ]
15
+ * arr = arr.sort(higherFirst(el => el.price))
16
+ * isEqual(arr, [
17
+ * { price: 1000 },
18
+ * { price: 100 },
19
+ * { price: 10 }
20
+ * ])
21
+ * ```
22
+ */
8
23
  function higherFirst(getValue) {
9
24
  return (element1, element2) => {
10
25
  const val1 = getValue(element1);
@@ -16,6 +31,21 @@ function higherFirst(getValue) {
16
31
  };
17
32
  }
18
33
  exports.higherFirst = higherFirst;
34
+ /**
35
+ * ```js
36
+ * let arr = [
37
+ * { price: 10 },
38
+ * { price: 1000 },
39
+ * { price: 100 }
40
+ * ]
41
+ * arr = arr.sort(lowerFirst(el => el.price))
42
+ * isEqual(arr, [
43
+ * { price: 10 },
44
+ * { price: 100 },
45
+ * { price: 1000 }
46
+ * ])
47
+ * ```
48
+ */
19
49
  function lowerFirst(getValue) {
20
50
  return (element1, element2) => {
21
51
  const val1 = getValue(element1);
@@ -27,6 +57,19 @@ function lowerFirst(getValue) {
27
57
  };
28
58
  }
29
59
  exports.lowerFirst = lowerFirst;
60
+ /**
61
+ * ```js
62
+ * let arr = [
63
+ * { name: 'iphone', isRocket: false },
64
+ * { name: 'starship', isRocket: true }
65
+ * ]
66
+ * arr = arr.sort(makeFirst(el => el.isRocket))
67
+ * isEqual(arr, [
68
+ * { name: 'starship', isRocket: true },
69
+ * { name: 'iphone', isRocket: false }
70
+ * ])
71
+ * ```
72
+ */
30
73
  function makeFirst(getValue) {
31
74
  return (element1, element2) => {
32
75
  const val1 = getValue(element1);
@@ -46,6 +89,19 @@ function makeFirst(getValue) {
46
89
  };
47
90
  }
48
91
  exports.makeFirst = makeFirst;
92
+ /**
93
+ * ```js
94
+ * let arr = [
95
+ * { name: 'starship', isRocket: true },
96
+ * { name: 'iphone', isRocket: false }
97
+ * ]
98
+ * arr = arr.sort(makeLast(el => el.isRocket))
99
+ * isEqual(arr, [
100
+ * { name: 'iphone', isRocket: false },
101
+ * { name: 'starship', isRocket: true }
102
+ * ])
103
+ * ```
104
+ */
49
105
  function makeLast(getValue) {
50
106
  return makeFirst((element) => {
51
107
  const val = getValue(element);
@@ -58,3 +114,8 @@ function makeLast(getValue) {
58
114
  });
59
115
  }
60
116
  exports.makeLast = makeLast;
117
+ /** Reverse order result. */
118
+ function reverse(sortKey) {
119
+ return (-1 * sortKey);
120
+ }
121
+ exports.reverse = reverse;
@@ -5,7 +5,7 @@ import { runPrerenderFromAutoFullBuild, runPrerender_forceExit } from '../../pre
5
5
  import { getConfigVike } from '../../shared/getConfigVike.js';
6
6
  import { isViteCliCall, getViteConfigFromCli } from '../shared/isViteCliCall.js';
7
7
  import pc from '@brillout/picocolors';
8
- import { logHintForCjsEsmError } from '../../runtime/renderPage/logHintForCjsEsmError.js';
8
+ import { logErrorHint } from '../../runtime/renderPage/logErrorHint.js';
9
9
  let forceExit = false;
10
10
  function autoFullBuild() {
11
11
  let config;
@@ -82,7 +82,7 @@ async function triggerFullBuild(config, configVike, bundle) {
82
82
  }
83
83
  catch (err) {
84
84
  console.error(err);
85
- logHintForCjsEsmError(err);
85
+ logErrorHint(err);
86
86
  process.exit(1);
87
87
  }
88
88
  if (configVike.prerender && !configVike.prerender.disableAutoRun) {
@@ -1,7 +1,7 @@
1
1
  export { buildConfig };
2
2
  export { assertRollupInput };
3
3
  export { analyzeClientEntries };
4
- import { assert, resolveOutDir, viteIsSSR, getFilePathAbsolute, addOnBeforeLogHook, removeFileExtention, unique, assertPosixPath, assertUsage, injectRollupInputs, normalizeRollupInput } from '../utils.js';
4
+ import { assert, resolveOutDir, viteIsSSR, getFilePathAbsolute, addOnBeforeLogHook, removeFileExtention, unique, assertPosixPath, assertUsage, injectRollupInputs, normalizeRollupInput, assertNodeEnvIsNotDev } from '../utils.js';
5
5
  import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
6
6
  import { getConfigValue } from '../../../shared/page-configs/helpers.js';
7
7
  import { findPageFiles } from '../shared/findPageFiles.js';
@@ -25,6 +25,7 @@ function buildConfig() {
25
25
  configResolved: {
26
26
  order: 'post',
27
27
  async handler(config) {
28
+ assertNodeEnv();
28
29
  assertRollupInput(config);
29
30
  const entries = await getEntries(config);
30
31
  assert(Object.keys(entries).length > 0);
@@ -33,6 +34,7 @@ function buildConfig() {
33
34
  }
34
35
  },
35
36
  config(config) {
37
+ assertNodeEnv();
36
38
  generateManifest = !viteIsSSR(config);
37
39
  return {
38
40
  build: {
@@ -42,7 +44,11 @@ function buildConfig() {
42
44
  }
43
45
  };
44
46
  },
47
+ buildStart() {
48
+ assertNodeEnv();
49
+ },
45
50
  async writeBundle(options, bundle) {
51
+ assertNodeEnv();
46
52
  const manifestEntry = bundle[manifestTempFile];
47
53
  /* Fails with @vitejs/plugin-legacy because writeBundle() is called twice during the client build (once for normal client assets and a second time for legacy assets), see reproduction at https://github.com/vikejs/vike/issues/1154
48
54
  assert(generateManifest === !!manifestEntry)
@@ -224,3 +230,6 @@ function assertRollupInput(config) {
224
230
  const htmlInput = htmlInputs[0];
225
231
  assertUsage(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using Vike, instead follow https://vike.dev/add`);
226
232
  }
233
+ function assertNodeEnv() {
234
+ assertNodeEnvIsNotDev('building');
235
+ }