vike 0.4.160-commit-a1101c1 → 0.4.160-commit-30d535e
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/autoFullBuild.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +9 -0
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +7 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +21 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +150 -110
- package/dist/cjs/node/plugin/utils.js +1 -2
- package/dist/cjs/node/prerender/runPrerender.js +12 -5
- package/dist/cjs/node/runtime/globalContext.js +7 -4
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/cjs/shared/route/executeGuardHook.js +3 -2
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
- package/dist/cjs/utils/nodeEnv.js +23 -1
- package/dist/cjs/utils/objectKeys.js +19 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/sorter.js +62 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +10 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.d.ts → transformFileImports.d.ts} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +6 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +20 -26
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +149 -109
- package/dist/esm/node/plugin/utils.d.ts +1 -2
- package/dist/esm/node/plugin/utils.js +1 -2
- package/dist/esm/node/prerender/runPrerender.js +13 -6
- package/dist/esm/node/runtime/globalContext.js +8 -5
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
- package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/esm/shared/route/executeGuardHook.js +3 -2
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/utils/findFile.d.ts +3 -0
- package/dist/esm/utils/findFile.js +21 -0
- package/dist/esm/utils/nodeEnv.d.ts +4 -0
- package/dist/esm/utils/nodeEnv.js +19 -0
- package/dist/esm/utils/objectKeys.d.ts +10 -1
- package/dist/esm/utils/objectKeys.js +20 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/sorter.d.ts +59 -0
- package/dist/esm/utils/sorter.js +61 -0
- package/package.json +1 -1
- package/dist/cjs/utils/objectEntries.js +0 -8
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
- package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
- package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
- package/dist/esm/utils/objectEntries.d.ts +0 -4
- package/dist/esm/utils/objectEntries.js +0 -5
- /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.d.ts → loadFileAtConfigTime.d.ts} +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
export {
|
|
2
|
-
// For ./
|
|
1
|
+
export { logErrorHint };
|
|
2
|
+
// For ./logErrorHint/*.spec.ts
|
|
3
3
|
export { isCjsEsmError };
|
|
4
|
-
export {
|
|
4
|
+
export { isKnownError };
|
|
5
5
|
export { getHint };
|
|
6
6
|
import pc from '@brillout/picocolors';
|
|
7
7
|
import { assert, formatHintLog, isNotNullish, isObject, unique, joinEnglish } from '../utils.js';
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const knownErrors = [
|
|
9
|
+
{
|
|
10
|
+
errMsg: 'jsxDEV is not a function',
|
|
11
|
+
link: 'https://github.com/vikejs/vike/issues/1469#issuecomment-1919518096'
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
errMsg: 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)',
|
|
15
|
+
link: 'https://vike.dev/broken-npm-package#react-invalid-component'
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
function logErrorHint(error) {
|
|
19
|
+
/* Collect errors for ./logErrorHint.spec.ts
|
|
10
20
|
collectError(error)
|
|
11
21
|
//*/
|
|
12
22
|
const hint = getHint(error);
|
|
@@ -14,9 +24,10 @@ function logHintForCjsEsmError(error) {
|
|
|
14
24
|
logHint(hint);
|
|
15
25
|
}
|
|
16
26
|
function getHint(error) {
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
27
|
+
{
|
|
28
|
+
const link = isKnownError(error);
|
|
29
|
+
if (link)
|
|
30
|
+
return `To fix this error, see ${link}`;
|
|
20
31
|
}
|
|
21
32
|
const res = isCjsEsmError(error);
|
|
22
33
|
if (res) {
|
|
@@ -37,43 +48,71 @@ function logHint(hint) {
|
|
|
37
48
|
hint = formatHintLog(hint);
|
|
38
49
|
console.error(hint);
|
|
39
50
|
}
|
|
40
|
-
function
|
|
51
|
+
function isKnownError(error) {
|
|
41
52
|
const anywhere = getAnywhere(error);
|
|
42
|
-
|
|
53
|
+
const knownErr = knownErrors.find((knownErorr) => {
|
|
54
|
+
return includes(anywhere, knownErorr.errMsg);
|
|
55
|
+
});
|
|
56
|
+
if (!knownErr)
|
|
57
|
+
return false;
|
|
58
|
+
return knownErr.link;
|
|
43
59
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* `'some-npm-package'` -> add some-npm-package to `ssr.noExternal`
|
|
48
|
-
*/
|
|
60
|
+
// `false` -> noop
|
|
61
|
+
// `true` -> generic message
|
|
62
|
+
// `'some-npm-package'` -> add some-npm-package to `ssr.noExternal`
|
|
49
63
|
function isCjsEsmError(error) {
|
|
64
|
+
const res = check(error);
|
|
65
|
+
if (res === true || res === false)
|
|
66
|
+
return res;
|
|
67
|
+
const packageNames = normalizeRes(res);
|
|
68
|
+
if (packageNames === false)
|
|
69
|
+
return packageNames;
|
|
70
|
+
packageNames.forEach((packageName) => {
|
|
71
|
+
assert(!['vite', 'vike'].includes(packageName));
|
|
72
|
+
});
|
|
73
|
+
return packageNames;
|
|
74
|
+
}
|
|
75
|
+
function normalizeRes(res) {
|
|
76
|
+
let packageNames = Array.isArray(res) ? res : [res];
|
|
77
|
+
packageNames = unique(packageNames.filter(isNotNullish).filter((packageName) => packageName !== '@brillout/import'));
|
|
78
|
+
if (packageNames.length === 0)
|
|
79
|
+
return false;
|
|
80
|
+
return packageNames;
|
|
81
|
+
}
|
|
82
|
+
function check(error) {
|
|
50
83
|
const message = getErrMessage(error);
|
|
51
84
|
const anywhere = getAnywhere(error);
|
|
52
85
|
const packageName_stack1 = getPackageName_stack1(error);
|
|
53
86
|
const packageName_stack2 = getPackageName_stack2(error);
|
|
54
87
|
const isRelatedToNodeModules = !!packageName_stack1 || !!packageName_stack2 || includesNodeModules(message);
|
|
55
|
-
|
|
88
|
+
/*
|
|
89
|
+
const relatedNpmPackages = normalizeArray([
|
|
90
|
+
packageName_stack1 || null,
|
|
91
|
+
packageName_stack2 || null,
|
|
92
|
+
(message && extractFromNodeModulesPath(message)) || null
|
|
93
|
+
])
|
|
94
|
+
*/
|
|
56
95
|
// ERR_UNSUPPORTED_DIR_IMPORT
|
|
57
96
|
{
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
return
|
|
97
|
+
const packageName = parseNodeModulesPathMessage('ERR_UNSUPPORTED_DIR_IMPORT', anywhere);
|
|
98
|
+
if (packageName)
|
|
99
|
+
return packageName;
|
|
61
100
|
}
|
|
62
101
|
// ERR_UNKNOWN_FILE_EXTENSION
|
|
63
102
|
{
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
return
|
|
103
|
+
const packageName = parseUnkownFileExtensionMessage(anywhere);
|
|
104
|
+
if (packageName)
|
|
105
|
+
return packageName;
|
|
67
106
|
}
|
|
68
107
|
{
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
return
|
|
108
|
+
const packageName = parseNodeModulesPathMessage('ERR_UNKNOWN_FILE_EXTENSION', anywhere);
|
|
109
|
+
if (packageName)
|
|
110
|
+
return packageName;
|
|
72
111
|
}
|
|
73
112
|
{
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
return
|
|
113
|
+
const packageName = parseNodeModulesPathMessage('is not exported', anywhere);
|
|
114
|
+
if (packageName)
|
|
115
|
+
return packageName;
|
|
77
116
|
}
|
|
78
117
|
// Using CJS inside ESM modules.
|
|
79
118
|
if (includes(anywhere, 'require is not a function') ||
|
|
@@ -94,7 +133,7 @@ function isCjsEsmError(error) {
|
|
|
94
133
|
if (includes(anywhere, 'ERR_REQUIRE_ESM')) {
|
|
95
134
|
/* The issue is the importer, not the importee.
|
|
96
135
|
if (relatedNpmPackages) return relatedNpmPackages
|
|
97
|
-
|
|
136
|
+
*/
|
|
98
137
|
{
|
|
99
138
|
if (packageName_stack1)
|
|
100
139
|
return packageName_stack1;
|
|
@@ -114,9 +153,9 @@ function isCjsEsmError(error) {
|
|
|
114
153
|
*/
|
|
115
154
|
// `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
|
|
116
155
|
{
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
119
|
-
return
|
|
156
|
+
const packageName = parseImportFrom(anywhere);
|
|
157
|
+
if (packageName)
|
|
158
|
+
return packageName;
|
|
120
159
|
}
|
|
121
160
|
if (includes(anywhere, 'Cannot read properties of undefined')) {
|
|
122
161
|
if (isRelatedToNodeModules) {
|
|
@@ -152,7 +191,7 @@ function parseCannotFindMessage(str) {
|
|
|
152
191
|
return false;
|
|
153
192
|
// const packageNameCannotFind = extractFromPath(match[1]!)
|
|
154
193
|
const packageNameFrom = extractFromPath(match[2]);
|
|
155
|
-
return
|
|
194
|
+
return normalizeArray([
|
|
156
195
|
// packageNameCannotFind,
|
|
157
196
|
packageNameFrom
|
|
158
197
|
]);
|
|
@@ -163,7 +202,7 @@ function parseUnkownFileExtensionMessage(str) {
|
|
|
163
202
|
return false;
|
|
164
203
|
const filePath = match[1];
|
|
165
204
|
const packageName = extractFromPath(filePath);
|
|
166
|
-
return
|
|
205
|
+
return packageName;
|
|
167
206
|
}
|
|
168
207
|
function parseImportFrom(str) {
|
|
169
208
|
const match = /\bimport\b.*?\bfrom\b\s*?"(.+?)"/.exec(str);
|
|
@@ -171,7 +210,7 @@ function parseImportFrom(str) {
|
|
|
171
210
|
return false;
|
|
172
211
|
const importPath = match[1];
|
|
173
212
|
const packageName = extractFromPath(importPath);
|
|
174
|
-
return
|
|
213
|
+
return packageName;
|
|
175
214
|
}
|
|
176
215
|
function parseNodeModulesPathMessage(begin, str) {
|
|
177
216
|
str = str.replaceAll('\\', '/');
|
|
@@ -225,7 +264,6 @@ function extractFromPath(filePath) {
|
|
|
225
264
|
packageName = packageName.split('/')[0];
|
|
226
265
|
}
|
|
227
266
|
packageName = clean(packageName);
|
|
228
|
-
assert(!['vite', 'vike'].includes(packageName));
|
|
229
267
|
return packageName;
|
|
230
268
|
}
|
|
231
269
|
function clean(packageName) {
|
|
@@ -243,7 +281,7 @@ function extractFromNodeModulesPath(str) {
|
|
|
243
281
|
return false;
|
|
244
282
|
const packageName = extractFromPath(str);
|
|
245
283
|
assert(packageName);
|
|
246
|
-
return
|
|
284
|
+
return packageName;
|
|
247
285
|
}
|
|
248
286
|
function includes(str1, str2) {
|
|
249
287
|
return !!str1 && str1.toLowerCase().includes(str2.toLowerCase());
|
|
@@ -258,11 +296,11 @@ function includesNodeModules(str) {
|
|
|
258
296
|
return false;
|
|
259
297
|
return true;
|
|
260
298
|
}
|
|
261
|
-
function
|
|
262
|
-
const
|
|
263
|
-
if (
|
|
264
|
-
return
|
|
265
|
-
return
|
|
299
|
+
function normalizeArray(arr) {
|
|
300
|
+
const arrNormalized = arr.filter(isNotNullish);
|
|
301
|
+
if (arrNormalized.length === 0)
|
|
302
|
+
return null;
|
|
303
|
+
return arrNormalized;
|
|
266
304
|
}
|
|
267
305
|
function getErrMessage(err) {
|
|
268
306
|
if (!isObject(err))
|
|
@@ -6,7 +6,7 @@ import { isAbortError } from '../../../shared/route/abort.js';
|
|
|
6
6
|
import { setAlreadyLogged } from './isNewError.js';
|
|
7
7
|
import { isObject, warnIfErrorIsNotObject } from '../utils.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
|
-
import {
|
|
9
|
+
import { logErrorHint } from './logErrorHint.js';
|
|
10
10
|
function logErrorProd(err, _httpRquestId) {
|
|
11
11
|
warnIfErrorIsNotObject(err);
|
|
12
12
|
setAlreadyLogged(err);
|
|
@@ -20,6 +20,6 @@ function logErrorProd(err, _httpRquestId) {
|
|
|
20
20
|
}
|
|
21
21
|
// 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.)
|
|
22
22
|
function onRuntimeError(err) {
|
|
23
|
-
// The more runtime errors we pass to
|
|
24
|
-
|
|
23
|
+
// The more runtime errors we pass to logErrorHint() the better.
|
|
24
|
+
logErrorHint(err);
|
|
25
25
|
}
|
|
@@ -36,7 +36,7 @@ export * from '../../utils/isNpmPackage.js';
|
|
|
36
36
|
export * from '../../utils/isNotNullish.js';
|
|
37
37
|
export * from '../../utils/isScriptFile.js';
|
|
38
38
|
export * from '../../utils/removeFileExtention.js';
|
|
39
|
-
export * from '../../utils/
|
|
39
|
+
export * from '../../utils/objectKeys.js';
|
|
40
40
|
export * from '../../utils/isStringRecord.js';
|
|
41
41
|
export * from '../../utils/getFileExtension.js';
|
|
42
42
|
export * from '../../utils/assertIsNotProductionRuntime.js';
|
|
@@ -39,7 +39,7 @@ export * from '../../utils/isNpmPackage.js';
|
|
|
39
39
|
export * from '../../utils/isNotNullish.js';
|
|
40
40
|
export * from '../../utils/isScriptFile.js';
|
|
41
41
|
export * from '../../utils/removeFileExtention.js';
|
|
42
|
-
export * from '../../utils/
|
|
42
|
+
export * from '../../utils/objectKeys.js';
|
|
43
43
|
export * from '../../utils/isStringRecord.js';
|
|
44
44
|
export * from '../../utils/getFileExtension.js';
|
|
45
45
|
export * from '../../utils/assertIsNotProductionRuntime.js';
|
|
@@ -17,6 +17,7 @@ export type { DefinedAtFileFullInfo };
|
|
|
17
17
|
export type { FilePathResolved };
|
|
18
18
|
export type { FilePath };
|
|
19
19
|
import type { ConfigValueImported, ConfigValueSerialized } from './serialize/PageConfigSerialized.js';
|
|
20
|
+
import type { LocationId } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js';
|
|
20
21
|
type PageConfigBase = {
|
|
21
22
|
pageId: string;
|
|
22
23
|
isErrorPage?: true;
|
|
@@ -71,6 +72,7 @@ type ConfigValueSource = {
|
|
|
71
72
|
value?: unknown;
|
|
72
73
|
configEnv: ConfigEnvInternal;
|
|
73
74
|
definedAt: DefinedAtFileFullInfo;
|
|
75
|
+
locationId: LocationId;
|
|
74
76
|
/** Wether the config value is loaded at runtime, for example config.Page or config.onBeforeRender */
|
|
75
77
|
valueIsImportedAtRuntime: boolean;
|
|
76
78
|
/** Whether the config value is a file path, for example config.client */
|
|
@@ -2,41 +2,68 @@ export { parseConfigValuesImported };
|
|
|
2
2
|
import { assert } from '../../utils.js';
|
|
3
3
|
import { assertPlusFileExport } from '../assertPlusFileExport.js';
|
|
4
4
|
function parseConfigValuesImported(configValuesImported) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
definedAt: {
|
|
10
|
-
// importPath cannot be relative to the current file, since the current file is a virtual file
|
|
11
|
-
filePathToShowToUser: importPath,
|
|
12
|
-
fileExportPathToShowToUser: [configName, 'default'].includes(exportName)
|
|
13
|
-
? []
|
|
14
|
-
: // Side-effect config
|
|
15
|
-
[exportName]
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
assertIsNotNull(value, configName, importPath);
|
|
19
|
-
};
|
|
20
|
-
configValuesImported.forEach((configValueLoaded) => {
|
|
5
|
+
const configValuesUnmerged = {};
|
|
6
|
+
configValuesImported
|
|
7
|
+
.filter((c) => c.configName !== 'client')
|
|
8
|
+
.forEach((configValueLoaded) => {
|
|
21
9
|
if (configValueLoaded.isValueFile) {
|
|
22
10
|
const { exportValues, importPath, configName } = configValueLoaded;
|
|
23
|
-
|
|
24
|
-
assertPlusFileExport(exportValues, importPath, configName);
|
|
25
|
-
}
|
|
11
|
+
assertPlusFileExport(exportValues, importPath, configName);
|
|
26
12
|
Object.entries(exportValues).forEach(([exportName, exportValue]) => {
|
|
27
13
|
const isSideExport = exportName !== 'default'; // .md files may have "side-exports" such as `export { frontmatter }`
|
|
28
14
|
const configName = isSideExport ? exportName : configValueLoaded.configName;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
configValuesUnmerged[configName] ?? (configValuesUnmerged[configName] = []);
|
|
16
|
+
configValuesUnmerged[configName].push({
|
|
17
|
+
value: exportValue,
|
|
18
|
+
importPath,
|
|
19
|
+
exportName,
|
|
20
|
+
isSideExport
|
|
21
|
+
});
|
|
35
22
|
});
|
|
36
23
|
}
|
|
37
24
|
else {
|
|
38
25
|
const { configName, importPath, exportValue, exportName } = configValueLoaded;
|
|
39
|
-
|
|
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
|
+
value,
|
|
55
|
+
definedAt: {
|
|
56
|
+
// importPath cannot be relative to the current file, since the current file is a virtual file
|
|
57
|
+
filePathToShowToUser: importPath,
|
|
58
|
+
fileExportPathToShowToUser: [configName, 'default'].includes(exportName)
|
|
59
|
+
? []
|
|
60
|
+
: [
|
|
61
|
+
// Side-export
|
|
62
|
+
exportName
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
assertIsNotNull(value, configName, importPath);
|
|
40
67
|
}
|
|
41
68
|
});
|
|
42
69
|
return configValues;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { executeGuardHook };
|
|
2
2
|
import { getHook, getHookTimeoutDefault } from '../hooks/getHook.js';
|
|
3
3
|
import { assert, assertUsage, executeHook, isCallable } from './utils.js';
|
|
4
|
+
const errIntro = 'The guard() hook defined by';
|
|
4
5
|
async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
5
6
|
let hook;
|
|
6
7
|
if (pageContext._pageFilesAll.length > 0) {
|
|
@@ -20,7 +21,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
|
20
21
|
if (res)
|
|
21
22
|
pageContextForUserConsumption = res;
|
|
22
23
|
const hookResult = await executeHook(() => guard(pageContextForUserConsumption), hook);
|
|
23
|
-
assertUsage(hookResult === undefined,
|
|
24
|
+
assertUsage(hookResult === undefined, `${errIntro} ${hook.hookFilePath} returns a value, but guard() shouldn't return any value`);
|
|
24
25
|
}
|
|
25
26
|
function findPageGuard(pageId, pageFilesAll) {
|
|
26
27
|
const pageRouteFile = pageFilesAll.find((p) => p.pageId === pageId && p.fileType === '.page.route');
|
|
@@ -33,6 +34,6 @@ function findPageGuard(pageId, pageFilesAll) {
|
|
|
33
34
|
return null;
|
|
34
35
|
const hookFilePath = filePath;
|
|
35
36
|
const hookTimeout = getHookTimeoutDefault('guard');
|
|
36
|
-
assertUsage(isCallable(hookFn),
|
|
37
|
+
assertUsage(isCallable(hookFn), `${errIntro} ${hookFilePath} should be a function`);
|
|
37
38
|
return { hookFn, hookName: 'guard', hookFilePath, hookTimeout };
|
|
38
39
|
}
|
|
@@ -18,6 +18,5 @@ export * from '../utils/projectInfo.js';
|
|
|
18
18
|
export * from '../utils/isPropertyGetter.js';
|
|
19
19
|
export * from '../utils/isPromise.js';
|
|
20
20
|
export * from '../utils/checkType.js';
|
|
21
|
-
export * from '../utils/objectEntries.js';
|
|
22
21
|
export * from '../utils/getValuePrintable.js';
|
|
23
22
|
export * from '../utils/escapeRegex.js';
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -22,6 +22,5 @@ export * from '../utils/projectInfo.js';
|
|
|
22
22
|
export * from '../utils/isPropertyGetter.js';
|
|
23
23
|
export * from '../utils/isPromise.js';
|
|
24
24
|
export * from '../utils/checkType.js';
|
|
25
|
-
export * from '../utils/objectEntries.js';
|
|
26
25
|
export * from '../utils/getValuePrintable.js';
|
|
27
26
|
export * from '../utils/escapeRegex.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { findFile };
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
function findFile(arg, cwd) {
|
|
5
|
+
const filenames = Array.isArray(arg) ? arg : [arg];
|
|
6
|
+
let dir = cwd;
|
|
7
|
+
while (true) {
|
|
8
|
+
for (const filename of filenames) {
|
|
9
|
+
const configFilePath = path.join(dir, `./${filename}`);
|
|
10
|
+
if (fs.existsSync(configFilePath)) {
|
|
11
|
+
// return toPosixPath(configFilePath)
|
|
12
|
+
return configFilePath;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const dirPrevious = dir;
|
|
16
|
+
dir = path.dirname(dir);
|
|
17
|
+
if (dir === dirPrevious) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export { getNodeEnv };
|
|
2
2
|
export { setNodeEnvToProduction };
|
|
3
3
|
export { isNodeEnvDev };
|
|
4
|
+
export { getNodeEnvDesc };
|
|
5
|
+
export { assertNodeEnvIsNotDev };
|
|
4
6
|
declare function getNodeEnv(): null | undefined | string;
|
|
5
7
|
declare function setNodeEnvToProduction(): void | undefined;
|
|
6
8
|
declare function isNodeEnvDev(): boolean;
|
|
9
|
+
declare function getNodeEnvDesc(): `environment is set to be a ${string} environment by process.env.NODE_ENV === ${string}`;
|
|
10
|
+
declare function assertNodeEnvIsNotDev(operation: 'building' | 'pre-rendering'): void;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export { getNodeEnv };
|
|
2
2
|
export { setNodeEnvToProduction };
|
|
3
3
|
export { isNodeEnvDev };
|
|
4
|
+
export { getNodeEnvDesc };
|
|
5
|
+
export { assertNodeEnvIsNotDev };
|
|
6
|
+
import pc from '@brillout/picocolors';
|
|
7
|
+
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
8
|
+
import { assertUsage } from './assert.js';
|
|
9
|
+
assertIsNotBrowser();
|
|
4
10
|
function getNodeEnv() {
|
|
5
11
|
if (typeof process === 'undefined')
|
|
6
12
|
return null;
|
|
@@ -21,3 +27,16 @@ function isNodeEnvDev() {
|
|
|
21
27
|
// That's quite aggressive, let's see if some user complains
|
|
22
28
|
return false;
|
|
23
29
|
}
|
|
30
|
+
function getNodeEnvDesc() {
|
|
31
|
+
const nodeEnv = getNodeEnv();
|
|
32
|
+
const isDev = isNodeEnvDev();
|
|
33
|
+
const nodeEnvDesc = `environment is set to be a ${(isDev ? 'development' : 'production')} environment by ${pc.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`)}`;
|
|
34
|
+
return nodeEnvDesc;
|
|
35
|
+
}
|
|
36
|
+
function assertNodeEnvIsNotDev(operation) {
|
|
37
|
+
const isDev = isNodeEnvDev();
|
|
38
|
+
if (!isDev)
|
|
39
|
+
return;
|
|
40
|
+
const nodeEnvDesc = getNodeEnvDesc();
|
|
41
|
+
assertUsage(false, `The ${nodeEnvDesc} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`);
|
|
42
|
+
}
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
+
export { objectEntries };
|
|
2
|
+
export { objectFromEntries };
|
|
3
|
+
export { objectKeys };
|
|
4
|
+
type ValueOf<T> = T[keyof T];
|
|
5
|
+
type Entries<T> = [keyof T, ValueOf<T>][];
|
|
6
|
+
/** Same as Object.entries() but with type inference */
|
|
7
|
+
declare function objectEntries<T extends object>(obj: T): Entries<T>;
|
|
8
|
+
/** Same as Object.fromEntries() but with type inference */
|
|
9
|
+
declare function objectFromEntries<T extends [PropertyKey, unknown][]>(arr: T): Record<T[number][0], T[number][1]>;
|
|
1
10
|
/** Same as Object.keys() but with type inference */
|
|
2
|
-
|
|
11
|
+
declare function objectKeys<T extends object>(obj: T): (keyof T)[];
|
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
1
|
+
export { objectEntries };
|
|
2
|
+
export { objectFromEntries };
|
|
3
|
+
export { objectKeys };
|
|
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
|
+
/** Same as Object.fromEntries() but with type inference */
|
|
10
|
+
function objectFromEntries(arr) {
|
|
11
|
+
return Object.fromEntries(arr);
|
|
4
12
|
}
|
|
5
13
|
// https://stackoverflow.com/questions/52856496/typescript-object-keys-return-string
|
|
6
14
|
// https://github.com/sindresorhus/ts-extras/blob/main/source/object-keys.ts
|
|
15
|
+
/** Same as Object.keys() but with type inference */
|
|
16
|
+
function objectKeys(obj) {
|
|
17
|
+
return Object.keys(obj);
|
|
18
|
+
}
|
|
19
|
+
/*
|
|
20
|
+
function objectKeys2<T extends Record<string, unknown>>(obj: T): Array<keyof T> {
|
|
21
|
+
return Object.keys(obj)
|
|
22
|
+
}
|
|
23
|
+
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.160-commit-
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.160-commit-30d535e";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.160-commit-
|
|
6
|
+
projectVersion: "0.4.160-commit-30d535e";
|
|
7
7
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
3
|
import { onProjectInfo } from './assertSingleInstance.js';
|
|
4
|
-
const PROJECT_VERSION = '0.4.160-commit-
|
|
4
|
+
const PROJECT_VERSION = '0.4.160-commit-30d535e';
|
|
5
5
|
const projectInfo = {
|
|
6
6
|
projectName: 'Vike',
|
|
7
7
|
projectVersion: PROJECT_VERSION
|
|
@@ -2,7 +2,66 @@ export { higherFirst };
|
|
|
2
2
|
export { lowerFirst };
|
|
3
3
|
export { makeFirst };
|
|
4
4
|
export { makeLast };
|
|
5
|
+
export { reverse };
|
|
6
|
+
/**
|
|
7
|
+
* ```js
|
|
8
|
+
* let arr = [
|
|
9
|
+
* { price: 10 },
|
|
10
|
+
* { price: 1000 },
|
|
11
|
+
* { price: 100 }
|
|
12
|
+
* ]
|
|
13
|
+
* arr = arr.sort(higherFirst(el => el.price))
|
|
14
|
+
* isEqual(arr, [
|
|
15
|
+
* { price: 1000 },
|
|
16
|
+
* { price: 100 },
|
|
17
|
+
* { price: 10 }
|
|
18
|
+
* ])
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
5
21
|
declare function higherFirst<T>(getValue: (element: T) => number): (element1: T, element2: T) => 0 | 1 | -1;
|
|
22
|
+
/**
|
|
23
|
+
* ```js
|
|
24
|
+
* let arr = [
|
|
25
|
+
* { price: 10 },
|
|
26
|
+
* { price: 1000 },
|
|
27
|
+
* { price: 100 }
|
|
28
|
+
* ]
|
|
29
|
+
* arr = arr.sort(lowerFirst(el => el.price))
|
|
30
|
+
* isEqual(arr, [
|
|
31
|
+
* { price: 10 },
|
|
32
|
+
* { price: 100 },
|
|
33
|
+
* { price: 1000 }
|
|
34
|
+
* ])
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
6
37
|
declare function lowerFirst<T>(getValue: (element: T) => number): (element1: T, element2: T) => 0 | 1 | -1;
|
|
38
|
+
/**
|
|
39
|
+
* ```js
|
|
40
|
+
* let arr = [
|
|
41
|
+
* { name: 'iphone', isRocket: false },
|
|
42
|
+
* { name: 'starship', isRocket: true }
|
|
43
|
+
* ]
|
|
44
|
+
* arr = arr.sort(makeFirst(el => el.isRocket))
|
|
45
|
+
* isEqual(arr, [
|
|
46
|
+
* { name: 'starship', isRocket: true },
|
|
47
|
+
* { name: 'iphone', isRocket: false }
|
|
48
|
+
* ])
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
7
51
|
declare function makeFirst<T>(getValue: (element: T) => boolean | null): (element1: T, element2: T) => 0 | 1 | -1;
|
|
52
|
+
/**
|
|
53
|
+
* ```js
|
|
54
|
+
* let arr = [
|
|
55
|
+
* { name: 'starship', isRocket: true },
|
|
56
|
+
* { name: 'iphone', isRocket: false }
|
|
57
|
+
* ]
|
|
58
|
+
* arr = arr.sort(makeLast(el => el.isRocket))
|
|
59
|
+
* isEqual(arr, [
|
|
60
|
+
* { name: 'iphone', isRocket: false },
|
|
61
|
+
* { name: 'starship', isRocket: true }
|
|
62
|
+
* ])
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
8
65
|
declare function makeLast<T>(getValue: (element: T) => boolean | null): (element1: T, element2: T) => 0 | 1 | -1;
|
|
66
|
+
/** Reverse order result. */
|
|
67
|
+
declare function reverse(sortKey: 0 | 1 | -1): 0 | 1 | -1;
|