vike 0.4.172-commit-55d8662 → 0.4.172-commit-24e2d90

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 (30) hide show
  1. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -1
  2. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +74 -11
  3. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -51
  4. package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +1 -1
  5. package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
  6. package/dist/cjs/node/plugin/shared/loggerVite.js +1 -1
  7. package/dist/cjs/node/runtime/onLoad.js +4 -0
  8. package/dist/cjs/node/{plugin/shared → shared}/isErrorDebug.js +1 -1
  9. package/dist/cjs/node/shared/utils.js +1 -0
  10. package/dist/cjs/utils/assert.js +7 -1
  11. package/dist/cjs/utils/projectInfo.js +1 -1
  12. package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -1
  13. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.d.ts +2 -0
  14. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +74 -11
  15. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +2 -52
  16. package/dist/esm/node/plugin/shared/loggerNotProd/log.js +1 -1
  17. package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
  18. package/dist/esm/node/plugin/shared/loggerVite.js +1 -1
  19. package/dist/esm/node/runtime/onLoad.js +4 -0
  20. package/dist/esm/node/{plugin/shared → shared}/isErrorDebug.js +1 -1
  21. package/dist/esm/node/shared/utils.d.ts +1 -0
  22. package/dist/esm/node/shared/utils.js +1 -0
  23. package/dist/esm/shared/page-configs/Config.d.ts +2 -1
  24. package/dist/esm/types/index.d.ts +1 -1
  25. package/dist/esm/utils/assert.d.ts +2 -0
  26. package/dist/esm/utils/assert.js +6 -0
  27. package/dist/esm/utils/projectInfo.d.ts +2 -2
  28. package/dist/esm/utils/projectInfo.js +1 -1
  29. package/package.json +1 -1
  30. /package/dist/esm/node/{plugin/shared → shared}/isErrorDebug.d.ts +0 -0
@@ -6,7 +6,7 @@ const determineFsAllowList_js_1 = require("./determineFsAllowList.js");
6
6
  const addSsrMiddleware_js_1 = require("../../shared/addSsrMiddleware.js");
7
7
  const utils_js_1 = require("../../utils.js");
8
8
  const loggerVite_js_1 = require("../../shared/loggerVite.js");
9
- const isErrorDebug_js_1 = require("../../shared/isErrorDebug.js");
9
+ const isErrorDebug_js_1 = require("../../../shared/isErrorDebug.js");
10
10
  const getHttpRequestAsyncStore_js_1 = require("../../shared/getHttpRequestAsyncStore.js");
11
11
  if ((0, isErrorDebug_js_1.isErrorDebug)()) {
12
12
  Error.stackTraceLimit = Infinity;
@@ -3,21 +3,68 @@ 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.assertExtensionsPeerDependencies = void 0;
6
+ exports.assertExtensionsPeerDependencies = exports.assertExtensionsConventions = void 0;
7
7
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
8
8
  const isObjectOfStrings_js_1 = require("../../../../../utils/isObjectOfStrings.js");
9
9
  const utils_js_1 = require("../../../utils.js");
10
10
  const getVikeConfig_js_1 = require("./getVikeConfig.js");
11
11
  const path_1 = __importDefault(require("path"));
12
12
  const semver_1 = __importDefault(require("semver"));
13
+ function assertExtensionsConventions(interfaceFile) {
14
+ assertExtensionName(interfaceFile);
15
+ assertConfigExportPath(interfaceFile);
16
+ }
17
+ exports.assertExtensionsConventions = assertExtensionsConventions;
18
+ function assertConfigExportPath(interfaceFile) {
19
+ const { importPathAbsolute } = interfaceFile.filePath;
20
+ (0, utils_js_1.assert)(importPathAbsolute);
21
+ const name = getConfigNameValue(interfaceFile);
22
+ (0, utils_js_1.assert)(name); // already asserted in assertExtensionName()
23
+ const importPathAbsoluteExpected = `${name}/config`;
24
+ (0, utils_js_1.assertWarning)(importPathAbsolute === importPathAbsoluteExpected, `The Vike configuration of ${picocolors_1.default.bold(name)} is exported at ${picocolors_1.default.bold(importPathAbsolute)} but it should be exported at ${picocolors_1.default.bold(importPathAbsoluteExpected)} instead.`, { onlyOnce: true });
25
+ }
26
+ function assertExtensionName(interfaceFile) {
27
+ let nameDeduced;
28
+ {
29
+ const { importPathAbsolute } = interfaceFile.filePath;
30
+ (0, utils_js_1.assert)(importPathAbsolute);
31
+ nameDeduced = importPathAbsolute
32
+ .split('/')
33
+ .slice(0, importPathAbsolute.startsWith('@') ? 2 : 1)
34
+ .join('/');
35
+ }
36
+ const name = getConfigNameValue(interfaceFile);
37
+ const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
38
+ if (name) {
39
+ (0, utils_js_1.assertWarning)(name === nameDeduced, `The setting ${picocolors_1.default.bold('name')} defined at ${filePathToShowToUser} is ${picocolors_1.default.bold(name)} but it should be ${picocolors_1.default.bold(nameDeduced)} instead (the name of the npm package).`, { onlyOnce: true });
40
+ }
41
+ else {
42
+ if (
43
+ // Let's eventually remove this
44
+ [
45
+ 'vike-react',
46
+ 'vike-react-query',
47
+ 'vike-react-zustand',
48
+ 'vike-vue',
49
+ 'vike-vue-query',
50
+ 'vike-vue-pinia',
51
+ 'vike-pinia',
52
+ 'vike-solid'
53
+ ].includes(nameDeduced)) {
54
+ (0, utils_js_1.assertUsage)(false, `Update ${nameDeduced} to its latest version.`);
55
+ }
56
+ else {
57
+ (0, utils_js_1.assertUsage)(false, `The setting ${picocolors_1.default.bold('name')} is missing: it should be set by the config ${filePathToShowToUser} of ${picocolors_1.default.bold(nameDeduced)}.`);
58
+ }
59
+ }
60
+ }
13
61
  function assertExtensionsPeerDependencies(interfaceFilesRelevantList) {
14
62
  // Get installed extensions
15
63
  const extensions = {};
16
64
  interfaceFilesRelevantList.forEach((interfaceFile) => {
17
65
  const name = getConfigNameValue(interfaceFile);
18
66
  if (name) {
19
- const extensionConfigFilePath = interfaceFile.filePath.filePathAbsoluteFilesystem;
20
- const version = getExtensionVersion(extensionConfigFilePath, name);
67
+ const version = getExtensionVersion(name, interfaceFile);
21
68
  extensions[name] = version;
22
69
  }
23
70
  });
@@ -27,13 +74,16 @@ function assertExtensionsPeerDependencies(interfaceFilesRelevantList) {
27
74
  if (!require)
28
75
  return;
29
76
  const name = getConfigNameValue(interfaceFile);
30
- // TODO: unify assertUsage()?
31
- (0, utils_js_1.assertUsage)(name, `Setting ${picocolors_1.default.bold('name')} is required when using setting ${picocolors_1.default.bold('require')}.`);
77
+ const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
78
+ (0, utils_js_1.assertUsage)(name, `Setting ${picocolors_1.default.bold('name')} is required for being able to use setting ${picocolors_1.default.bold('require')} in ${filePathToShowToUser}.`);
32
79
  Object.entries(require).forEach(([reqName, reqVersion]) => {
80
+ const errBase = `${picocolors_1.default.bold(name)} requires ${picocolors_1.default.bold(reqName)}`;
81
+ if (reqName === 'vike') {
82
+ (0, utils_js_1.assertUsage)(isVersionRange(utils_js_1.PROJECT_VERSION, reqVersion), `${errBase} version ${picocolors_1.default.bold(reqVersion)} but ${picocolors_1.default.bold(utils_js_1.PROJECT_VERSION)} is installed.`);
83
+ }
33
84
  const extensionVersion = extensions[reqName];
34
- const errBase = `The Vike extension ${picocolors_1.default.bold(name)} requires ${picocolors_1.default.bold(reqName)}`;
35
85
  (0, utils_js_1.assertUsage)(extensionVersion, `${errBase}.`);
36
- (0, utils_js_1.assertUsage)(semver_1.default.satisfies(extensionVersion, reqVersion), `${errBase} version ${picocolors_1.default.bold(reqVersion)} but ${picocolors_1.default.bold(extensionVersion)} is installed.`);
86
+ (0, utils_js_1.assertUsage)(isVersionRange(extensionVersion, reqVersion), `${errBase} version ${picocolors_1.default.bold(reqVersion)} but ${picocolors_1.default.bold(extensionVersion)} is installed.`);
37
87
  });
38
88
  });
39
89
  }
@@ -51,21 +101,34 @@ function getConfigNameValue(interfaceFile) {
51
101
  const name = (0, getVikeConfig_js_1.getConfigValueInterfaceFile)(interfaceFile, 'name');
52
102
  if (!name)
53
103
  return null;
54
- // TODO: move assertUsage() here
55
- (0, utils_js_1.assert)(typeof name === 'string');
104
+ const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
105
+ (0, utils_js_1.assertUsage)(typeof name === 'string', `The setting ${picocolors_1.default.bold('name')} defined at ${filePathToShowToUser} should be a string.`);
56
106
  return name;
57
107
  }
58
108
  // We use a forever cache: users need to restart the dev server anyways when touching node_modules/**/* (I presume Vite doesn't pick up node_modules/**/* changes).
59
109
  const extensionsVersion = {};
60
- function getExtensionVersion(extensionConfigFilePath, name) {
110
+ function getExtensionVersion(name, interfaceFile) {
61
111
  if (!extensionsVersion[name]) {
112
+ const extensionConfigFilePath = interfaceFile.filePath.filePathAbsoluteFilesystem;
62
113
  const found = (0, utils_js_1.findPackageJson)(path_1.default.posix.dirname(extensionConfigFilePath));
63
114
  (0, utils_js_1.assert)(found);
64
115
  const { packageJson, packageJsonPath } = found;
65
- (0, utils_js_1.assertUsage)(packageJson.name === name, `The setting ${picocolors_1.default.bold('name')} set by ${extensionConfigFilePath} is ${picocolors_1.default.bold(JSON.stringify(name))} but it should be equal to ${packageJsonPath}${picocolors_1.default.dim('#')}${picocolors_1.default.bold('name')} which is ${picocolors_1.default.bold(JSON.stringify(packageJson.name))}`);
116
+ const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
117
+ const nameExpected = packageJson.name;
118
+ (0, utils_js_1.assertWarning)(name === nameExpected, `The setting ${picocolors_1.default.bold('name')} defined at ${filePathToShowToUser} is ${picocolors_1.default.bold(JSON.stringify(name))} but it should be equal to ${picocolors_1.default.bold(JSON.stringify(nameExpected))} (the value of ${packageJsonPath}${picocolors_1.default.dim('#')}${picocolors_1.default.bold('name')})`, { onlyOnce: true });
66
119
  const { version } = packageJson;
67
120
  (0, utils_js_1.assert)(typeof version === 'string');
68
121
  extensionsVersion[name] = version;
69
122
  }
70
123
  return extensionsVersion[name];
71
124
  }
125
+ function getFilePathToShowToUser(interfaceFile) {
126
+ const { filePathToShowToUserResolved } = interfaceFile.filePath;
127
+ (0, utils_js_1.assert)(filePathToShowToUserResolved);
128
+ return filePathToShowToUserResolved;
129
+ }
130
+ function isVersionRange(version, range) {
131
+ // Remove pre-release tag
132
+ version = version.split('-')[0];
133
+ return semver_1.default.satisfies(version, range);
134
+ }
@@ -126,7 +126,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit)
126
126
  ```
127
127
  */
128
128
  const interfaceFile = getInterfaceFileFromConfigFile(extendsConfig, true, locationId);
129
- assertVikeExtensionConventions(extendsConfig, interfaceFile);
129
+ (0, assertExtensions_js_1.assertExtensionsConventions)(interfaceFile);
130
130
  interfaceFilesByLocationId[locationId].push(interfaceFile);
131
131
  });
132
132
  }),
@@ -165,56 +165,6 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit)
165
165
  assertAllConfigsAreKnown(interfaceFilesByLocationId);
166
166
  return interfaceFilesByLocationId;
167
167
  }
168
- function assertVikeExtensionConventions(extendsConfig, interfaceFile) {
169
- const alreadyMigrated = [
170
- 'vike-react',
171
- 'vike-react-query',
172
- 'vike-react-zustand',
173
- 'vike-vue',
174
- 'vike-pinia',
175
- 'vike-solid'
176
- ];
177
- const { importPathAbsolute } = extendsConfig.filePath;
178
- (0, utils_js_1.assert)(importPathAbsolute);
179
- const extensionName = importPathAbsolute
180
- .split('/')
181
- .slice(0, importPathAbsolute.startsWith('@') ? 2 : 1)
182
- .join('/');
183
- const errMsg = alreadyMigrated.includes(extensionName)
184
- ? `You're using a deprecated version of the Vike extension ${extensionName}, update ${extensionName} to its latest version.`
185
- : `The config of the Vike extension ${extensionName} should define the ${picocolors_1.default.cyan('name')} setting.`;
186
- const extensionNameValue = getConfigValueInterfaceFile(interfaceFile, 'name');
187
- if (alreadyMigrated) {
188
- // Eventually remove (always use assertUsage())
189
- (0, utils_js_1.assertWarning)(extensionNameValue, errMsg, { onlyOnce: true });
190
- }
191
- else {
192
- (0, utils_js_1.assertUsage)(extensionNameValue, errMsg);
193
- }
194
- {
195
- const { filePathToShowToUserResolved } = interfaceFile.filePath;
196
- (0, utils_js_1.assert)(filePathToShowToUserResolved);
197
- const errPrefix = `The setting ${picocolors_1.default.bold('name')} defined at ${filePathToShowToUserResolved}`;
198
- (0, utils_js_1.assertUsage)(typeof extensionNameValue === 'string', `${errPrefix} should be a string.`);
199
- (0, utils_js_1.assertWarning)(extensionNameValue === extensionName, `${errPrefix} is ${picocolors_1.default.bold(extensionNameValue)} but it should be ${picocolors_1.default.bold(extensionName)} instead.`, { onlyOnce: true });
200
- }
201
- {
202
- const importPathAbsoluteExpected = `${extensionName}/config`;
203
- (0, utils_js_1.assertWarning)(importPathAbsolute === importPathAbsoluteExpected, `The Vike configuration of ${extensionName} is exported at ${picocolors_1.default.bold(importPathAbsolute)} but it should be exported at ${picocolors_1.default.bold(importPathAbsoluteExpected)} instead.`, { onlyOnce: true });
204
- }
205
- if (extensionName.startsWith('vike-')) {
206
- const prefix = [
207
- //
208
- 'vike-react',
209
- 'vike-vue',
210
- 'vike-solid',
211
- 'vike-svelte',
212
- 'vike-angular',
213
- 'vike-preact'
214
- ];
215
- (0, utils_js_1.assertWarning)(prefix.some((p) => extensionName === p || extensionName.startsWith(`${p}-`)), `The name of the Vike extension ${picocolors_1.default.bold(extensionName)} should be or start with ${(0, utils_js_1.joinEnglish)(prefix.map(picocolors_1.default.bold), 'or')}.`, { onlyOnce: true });
216
- }
217
- }
218
168
  function getInterfaceFileFromConfigFile(configFile, isConfigExtend, locationId) {
219
169
  const { fileExports, filePath, extendsFilePaths } = configFile;
220
170
  const interfaceFile = {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.applyViteSourceMapToStackTrace = exports.screenHasErrors = exports.clearScreen = exports.isFirstLog = exports.logDirectly = exports.logWithVikeTag = exports.logWithViteTag = void 0;
7
7
  const utils_js_1 = require("../../utils.js");
8
8
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
9
- const isErrorDebug_js_1 = require("../isErrorDebug.js");
9
+ const isErrorDebug_js_1 = require("../../../shared/isErrorDebug.js");
10
10
  const globalContext_js_1 = require("../../../runtime/globalContext.js");
11
11
  (0, utils_js_1.assertIsNotProductionRuntime)();
12
12
  let isFirstLog = true;
@@ -15,7 +15,7 @@ const globalContext_js_1 = require("../../runtime/globalContext.js");
15
15
  const loggerRuntime_js_1 = require("../../runtime/renderPage/loggerRuntime.js");
16
16
  const utils_js_1 = require("../utils.js");
17
17
  const getHttpRequestAsyncStore_js_1 = require("./getHttpRequestAsyncStore.js");
18
- const isErrorDebug_js_1 = require("./isErrorDebug.js");
18
+ const isErrorDebug_js_1 = require("../../shared/isErrorDebug.js");
19
19
  const errorWithCodeSnippet_js_1 = require("./loggerNotProd/errorWithCodeSnippet.js");
20
20
  const transpileAndExecuteFile_js_1 = require("../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js");
21
21
  const log_js_1 = require("./loggerNotProd/log.js");
@@ -5,7 +5,7 @@ const utils_js_1 = require("../utils.js");
5
5
  const loggerNotProd_js_1 = require("./loggerNotProd.js");
6
6
  const getHttpRequestAsyncStore_js_1 = require("./getHttpRequestAsyncStore.js");
7
7
  const removeSuperfluousViteLog_js_1 = require("./loggerVite/removeSuperfluousViteLog.js");
8
- const isErrorDebug_js_1 = require("./isErrorDebug.js");
8
+ const isErrorDebug_js_1 = require("../../shared/isErrorDebug.js");
9
9
  function improveViteLogs(config) {
10
10
  intercept('info', config);
11
11
  intercept('warn', config);
@@ -4,9 +4,13 @@ exports.onLoad = void 0;
4
4
  const assertIsNotBrowser_js_1 = require("../../utils/assertIsNotBrowser.js");
5
5
  const assertNodeVersion_js_1 = require("../../utils/assertNodeVersion.js");
6
6
  const require_shim_1 = require("@brillout/require-shim");
7
+ const utils_js_1 = require("./utils.js");
8
+ const isErrorDebug_js_1 = require("../shared/isErrorDebug.js");
7
9
  function onLoad() {
8
10
  (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
9
11
  (0, assertNodeVersion_js_1.assertNodeVersion)();
10
12
  (0, require_shim_1.installRequireShim)();
13
+ if ((0, isErrorDebug_js_1.isErrorDebug)())
14
+ (0, utils_js_1.setAlwaysShowStackTrace)();
11
15
  }
12
16
  exports.onLoad = onLoad;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isErrorDebug = void 0;
4
- const utils_js_1 = require("../utils.js");
4
+ const utils_js_1 = require("./utils.js");
5
5
  function isErrorDebug() {
6
6
  return (0, utils_js_1.isDebugActivated)('vike:error');
7
7
  }
@@ -32,3 +32,4 @@ __exportStar(require("../../utils/virtual-files.js"), exports);
32
32
  __exportStar(require("../../utils/assertIsNotBrowser.js"), exports);
33
33
  __exportStar(require("../../utils/isNotNullish.js"), exports);
34
34
  __exportStar(require("../../utils/unique.js"), exports);
35
+ __exportStar(require("../../utils/debug.js"), exports);
@@ -3,7 +3,7 @@ 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.isBug = exports.overwriteAssertProductionLogger = exports.getAssertErrMsg = exports.addOnBeforeLogHook = exports.getProjectError = exports.assertInfo = exports.assertWarning = exports.assertUsage = exports.assert = void 0;
6
+ exports.setAlwaysShowStackTrace = exports.isBug = exports.overwriteAssertProductionLogger = exports.getAssertErrMsg = exports.addOnBeforeLogHook = exports.getProjectError = exports.assertInfo = exports.assertWarning = exports.assertUsage = exports.assert = void 0;
7
7
  const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
8
8
  const createErrorWithCleanStackTrace_js_1 = require("./createErrorWithCleanStackTrace.js");
9
9
  const getGlobalObject_js_1 = require("./getGlobalObject.js");
@@ -55,6 +55,7 @@ exports.assert = assert;
55
55
  function assertUsage(condition, errMsg, { showStackTrace } = {}) {
56
56
  if (condition)
57
57
  return;
58
+ showStackTrace = showStackTrace || globalObject.alwaysShowStackTrace;
58
59
  errMsg = addWhitespace(errMsg);
59
60
  errMsg = addPrefixAssertType(errMsg, 'Wrong Usage');
60
61
  errMsg = addPrefixProjctName(errMsg);
@@ -77,6 +78,7 @@ exports.getProjectError = getProjectError;
77
78
  function assertWarning(condition, msg, { onlyOnce, showStackTrace }) {
78
79
  if (condition)
79
80
  return;
81
+ showStackTrace = showStackTrace || globalObject.alwaysShowStackTrace;
80
82
  msg = addWhitespace(msg);
81
83
  msg = addPrefixAssertType(msg, 'Warning');
82
84
  msg = addPrefixProjctName(msg);
@@ -193,3 +195,7 @@ function isBug(err) {
193
195
  return !String(err).includes('[Bug]');
194
196
  }
195
197
  exports.isBug = isBug;
198
+ function setAlwaysShowStackTrace() {
199
+ globalObject.alwaysShowStackTrace = true;
200
+ }
201
+ exports.setAlwaysShowStackTrace = setAlwaysShowStackTrace;
@@ -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.172-commit-55d8662';
4
+ const PROJECT_VERSION = '0.4.172-commit-24e2d90';
5
5
  exports.PROJECT_VERSION = PROJECT_VERSION;
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
@@ -4,7 +4,7 @@ import { determineFsAllowList } from './determineFsAllowList.js';
4
4
  import { addSsrMiddleware } from '../../shared/addSsrMiddleware.js';
5
5
  import { markEnvAsViteDev } from '../../utils.js';
6
6
  import { improveViteLogs } from '../../shared/loggerVite.js';
7
- import { isErrorDebug } from '../../shared/isErrorDebug.js';
7
+ import { isErrorDebug } from '../../../shared/isErrorDebug.js';
8
8
  import { installHttpRequestAsyncStore } from '../../shared/getHttpRequestAsyncStore.js';
9
9
  if (isErrorDebug()) {
10
10
  Error.stackTraceLimit = Infinity;
@@ -1,3 +1,5 @@
1
+ export { assertExtensionsConventions };
1
2
  export { assertExtensionsPeerDependencies };
2
3
  import { type InterfaceFile } from './getVikeConfig.js';
4
+ declare function assertExtensionsConventions(interfaceFile: InterfaceFile): void;
3
5
  declare function assertExtensionsPeerDependencies(interfaceFilesRelevantList: InterfaceFile[]): void;
@@ -1,18 +1,65 @@
1
+ export { assertExtensionsConventions };
1
2
  export { assertExtensionsPeerDependencies };
2
3
  import pc from '@brillout/picocolors';
3
4
  import { isObjectOfStrings } from '../../../../../utils/isObjectOfStrings.js';
4
- import { assert, assertUsage, findPackageJson } from '../../../utils.js';
5
+ import { PROJECT_VERSION, assert, assertUsage, assertWarning, findPackageJson } from '../../../utils.js';
5
6
  import { getConfigValueInterfaceFile } from './getVikeConfig.js';
6
7
  import path from 'path';
7
8
  import semver from 'semver';
9
+ function assertExtensionsConventions(interfaceFile) {
10
+ assertExtensionName(interfaceFile);
11
+ assertConfigExportPath(interfaceFile);
12
+ }
13
+ function assertConfigExportPath(interfaceFile) {
14
+ const { importPathAbsolute } = interfaceFile.filePath;
15
+ assert(importPathAbsolute);
16
+ const name = getConfigNameValue(interfaceFile);
17
+ assert(name); // already asserted in assertExtensionName()
18
+ const importPathAbsoluteExpected = `${name}/config`;
19
+ assertWarning(importPathAbsolute === importPathAbsoluteExpected, `The Vike configuration of ${pc.bold(name)} is exported at ${pc.bold(importPathAbsolute)} but it should be exported at ${pc.bold(importPathAbsoluteExpected)} instead.`, { onlyOnce: true });
20
+ }
21
+ function assertExtensionName(interfaceFile) {
22
+ let nameDeduced;
23
+ {
24
+ const { importPathAbsolute } = interfaceFile.filePath;
25
+ assert(importPathAbsolute);
26
+ nameDeduced = importPathAbsolute
27
+ .split('/')
28
+ .slice(0, importPathAbsolute.startsWith('@') ? 2 : 1)
29
+ .join('/');
30
+ }
31
+ const name = getConfigNameValue(interfaceFile);
32
+ const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
33
+ if (name) {
34
+ assertWarning(name === nameDeduced, `The setting ${pc.bold('name')} defined at ${filePathToShowToUser} is ${pc.bold(name)} but it should be ${pc.bold(nameDeduced)} instead (the name of the npm package).`, { onlyOnce: true });
35
+ }
36
+ else {
37
+ if (
38
+ // Let's eventually remove this
39
+ [
40
+ 'vike-react',
41
+ 'vike-react-query',
42
+ 'vike-react-zustand',
43
+ 'vike-vue',
44
+ 'vike-vue-query',
45
+ 'vike-vue-pinia',
46
+ 'vike-pinia',
47
+ 'vike-solid'
48
+ ].includes(nameDeduced)) {
49
+ assertUsage(false, `Update ${nameDeduced} to its latest version.`);
50
+ }
51
+ else {
52
+ assertUsage(false, `The setting ${pc.bold('name')} is missing: it should be set by the config ${filePathToShowToUser} of ${pc.bold(nameDeduced)}.`);
53
+ }
54
+ }
55
+ }
8
56
  function assertExtensionsPeerDependencies(interfaceFilesRelevantList) {
9
57
  // Get installed extensions
10
58
  const extensions = {};
11
59
  interfaceFilesRelevantList.forEach((interfaceFile) => {
12
60
  const name = getConfigNameValue(interfaceFile);
13
61
  if (name) {
14
- const extensionConfigFilePath = interfaceFile.filePath.filePathAbsoluteFilesystem;
15
- const version = getExtensionVersion(extensionConfigFilePath, name);
62
+ const version = getExtensionVersion(name, interfaceFile);
16
63
  extensions[name] = version;
17
64
  }
18
65
  });
@@ -22,13 +69,16 @@ function assertExtensionsPeerDependencies(interfaceFilesRelevantList) {
22
69
  if (!require)
23
70
  return;
24
71
  const name = getConfigNameValue(interfaceFile);
25
- // TODO: unify assertUsage()?
26
- assertUsage(name, `Setting ${pc.bold('name')} is required when using setting ${pc.bold('require')}.`);
72
+ const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
73
+ assertUsage(name, `Setting ${pc.bold('name')} is required for being able to use setting ${pc.bold('require')} in ${filePathToShowToUser}.`);
27
74
  Object.entries(require).forEach(([reqName, reqVersion]) => {
75
+ const errBase = `${pc.bold(name)} requires ${pc.bold(reqName)}`;
76
+ if (reqName === 'vike') {
77
+ assertUsage(isVersionRange(PROJECT_VERSION, reqVersion), `${errBase} version ${pc.bold(reqVersion)} but ${pc.bold(PROJECT_VERSION)} is installed.`);
78
+ }
28
79
  const extensionVersion = extensions[reqName];
29
- const errBase = `The Vike extension ${pc.bold(name)} requires ${pc.bold(reqName)}`;
30
80
  assertUsage(extensionVersion, `${errBase}.`);
31
- assertUsage(semver.satisfies(extensionVersion, reqVersion), `${errBase} version ${pc.bold(reqVersion)} but ${pc.bold(extensionVersion)} is installed.`);
81
+ assertUsage(isVersionRange(extensionVersion, reqVersion), `${errBase} version ${pc.bold(reqVersion)} but ${pc.bold(extensionVersion)} is installed.`);
32
82
  });
33
83
  });
34
84
  }
@@ -45,21 +95,34 @@ function getConfigNameValue(interfaceFile) {
45
95
  const name = getConfigValueInterfaceFile(interfaceFile, 'name');
46
96
  if (!name)
47
97
  return null;
48
- // TODO: move assertUsage() here
49
- assert(typeof name === 'string');
98
+ const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
99
+ assertUsage(typeof name === 'string', `The setting ${pc.bold('name')} defined at ${filePathToShowToUser} should be a string.`);
50
100
  return name;
51
101
  }
52
102
  // We use a forever cache: users need to restart the dev server anyways when touching node_modules/**/* (I presume Vite doesn't pick up node_modules/**/* changes).
53
103
  const extensionsVersion = {};
54
- function getExtensionVersion(extensionConfigFilePath, name) {
104
+ function getExtensionVersion(name, interfaceFile) {
55
105
  if (!extensionsVersion[name]) {
106
+ const extensionConfigFilePath = interfaceFile.filePath.filePathAbsoluteFilesystem;
56
107
  const found = findPackageJson(path.posix.dirname(extensionConfigFilePath));
57
108
  assert(found);
58
109
  const { packageJson, packageJsonPath } = found;
59
- assertUsage(packageJson.name === name, `The setting ${pc.bold('name')} set by ${extensionConfigFilePath} is ${pc.bold(JSON.stringify(name))} but it should be equal to ${packageJsonPath}${pc.dim('#')}${pc.bold('name')} which is ${pc.bold(JSON.stringify(packageJson.name))}`);
110
+ const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
111
+ const nameExpected = packageJson.name;
112
+ assertWarning(name === nameExpected, `The setting ${pc.bold('name')} defined at ${filePathToShowToUser} is ${pc.bold(JSON.stringify(name))} but it should be equal to ${pc.bold(JSON.stringify(nameExpected))} (the value of ${packageJsonPath}${pc.dim('#')}${pc.bold('name')})`, { onlyOnce: true });
60
113
  const { version } = packageJson;
61
114
  assert(typeof version === 'string');
62
115
  extensionsVersion[name] = version;
63
116
  }
64
117
  return extensionsVersion[name];
65
118
  }
119
+ function getFilePathToShowToUser(interfaceFile) {
120
+ const { filePathToShowToUserResolved } = interfaceFile.filePath;
121
+ assert(filePathToShowToUserResolved);
122
+ return filePathToShowToUserResolved;
123
+ }
124
+ function isVersionRange(version, range) {
125
+ // Remove pre-release tag
126
+ version = version.split('-')[0];
127
+ return semver.satisfies(version, range);
128
+ }
@@ -22,7 +22,7 @@ import { clearFilesEnvMap, resolvePointerImportOfConfig } from './getVikeConfig/
22
22
  import { getFilePathResolved } from '../../../shared/getFilePath.js';
23
23
  import { getConfigValueBuildTime } from '../../../../../shared/page-configs/getConfigValueBuildTime.js';
24
24
  import { getConfigVike } from '../../../../shared/getConfigVike.js';
25
- import { assertExtensionsPeerDependencies } from './assertExtensions.js';
25
+ import { assertExtensionsPeerDependencies, assertExtensionsConventions } from './assertExtensions.js';
26
26
  assertIsNotProductionRuntime();
27
27
  let devServerIsCorrupt = false;
28
28
  let wasConfigInvalid = null;
@@ -122,7 +122,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit)
122
122
  ```
123
123
  */
124
124
  const interfaceFile = getInterfaceFileFromConfigFile(extendsConfig, true, locationId);
125
- assertVikeExtensionConventions(extendsConfig, interfaceFile);
125
+ assertExtensionsConventions(interfaceFile);
126
126
  interfaceFilesByLocationId[locationId].push(interfaceFile);
127
127
  });
128
128
  }),
@@ -161,56 +161,6 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit)
161
161
  assertAllConfigsAreKnown(interfaceFilesByLocationId);
162
162
  return interfaceFilesByLocationId;
163
163
  }
164
- function assertVikeExtensionConventions(extendsConfig, interfaceFile) {
165
- const alreadyMigrated = [
166
- 'vike-react',
167
- 'vike-react-query',
168
- 'vike-react-zustand',
169
- 'vike-vue',
170
- 'vike-pinia',
171
- 'vike-solid'
172
- ];
173
- const { importPathAbsolute } = extendsConfig.filePath;
174
- assert(importPathAbsolute);
175
- const extensionName = importPathAbsolute
176
- .split('/')
177
- .slice(0, importPathAbsolute.startsWith('@') ? 2 : 1)
178
- .join('/');
179
- const errMsg = alreadyMigrated.includes(extensionName)
180
- ? `You're using a deprecated version of the Vike extension ${extensionName}, update ${extensionName} to its latest version.`
181
- : `The config of the Vike extension ${extensionName} should define the ${pc.cyan('name')} setting.`;
182
- const extensionNameValue = getConfigValueInterfaceFile(interfaceFile, 'name');
183
- if (alreadyMigrated) {
184
- // Eventually remove (always use assertUsage())
185
- assertWarning(extensionNameValue, errMsg, { onlyOnce: true });
186
- }
187
- else {
188
- assertUsage(extensionNameValue, errMsg);
189
- }
190
- {
191
- const { filePathToShowToUserResolved } = interfaceFile.filePath;
192
- assert(filePathToShowToUserResolved);
193
- const errPrefix = `The setting ${pc.bold('name')} defined at ${filePathToShowToUserResolved}`;
194
- assertUsage(typeof extensionNameValue === 'string', `${errPrefix} should be a string.`);
195
- assertWarning(extensionNameValue === extensionName, `${errPrefix} is ${pc.bold(extensionNameValue)} but it should be ${pc.bold(extensionName)} instead.`, { onlyOnce: true });
196
- }
197
- {
198
- const importPathAbsoluteExpected = `${extensionName}/config`;
199
- assertWarning(importPathAbsolute === importPathAbsoluteExpected, `The Vike configuration of ${extensionName} is exported at ${pc.bold(importPathAbsolute)} but it should be exported at ${pc.bold(importPathAbsoluteExpected)} instead.`, { onlyOnce: true });
200
- }
201
- if (extensionName.startsWith('vike-')) {
202
- const prefix = [
203
- //
204
- 'vike-react',
205
- 'vike-vue',
206
- 'vike-solid',
207
- 'vike-svelte',
208
- 'vike-angular',
209
- 'vike-preact'
210
- ];
211
- assertWarning(prefix.some((p) => extensionName === p || extensionName.startsWith(`${p}-`)), `The name of the Vike extension ${pc.bold(extensionName)} should be or start with ${joinEnglish(prefix.map(pc.bold), 'or')}.`, { onlyOnce: true });
212
- }
213
- }
214
164
  function getInterfaceFileFromConfigFile(configFile, isConfigExtend, locationId) {
215
165
  const { fileExports, filePath, extendsFilePaths } = configFile;
216
166
  const interfaceFile = {
@@ -7,7 +7,7 @@ export { screenHasErrors };
7
7
  export { applyViteSourceMapToStackTrace };
8
8
  import { assert, projectInfo, stripAnsi, hasProp, assertIsNotProductionRuntime } from '../../utils.js';
9
9
  import pc from '@brillout/picocolors';
10
- import { isErrorDebug } from '../isErrorDebug.js';
10
+ import { isErrorDebug } from '../../../shared/isErrorDebug.js';
11
11
  import { getViteDevServer } from '../../../runtime/globalContext.js';
12
12
  assertIsNotProductionRuntime();
13
13
  let isFirstLog = true;
@@ -16,7 +16,7 @@ import { getViteConfig } from '../../runtime/globalContext.js';
16
16
  import { overwriteRuntimeProductionLogger } from '../../runtime/renderPage/loggerRuntime.js';
17
17
  import { assert, assertIsNotProductionRuntime, formatHintLog, getAssertErrMsg, overwriteAssertProductionLogger, stripAnsi, warnIfErrorIsNotObject } from '../utils.js';
18
18
  import { getHttpRequestAsyncStore } from './getHttpRequestAsyncStore.js';
19
- import { isErrorDebug } from './isErrorDebug.js';
19
+ import { isErrorDebug } from '../../shared/isErrorDebug.js';
20
20
  import { isErrorWithCodeSnippet, getPrettyErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js';
21
21
  import { getConfigExecutionErrorIntroMsg, getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js';
22
22
  import { logWithVikeTag, logWithViteTag, logDirectly, isFirstLog, screenHasErrors, clearScreen, applyViteSourceMapToStackTrace } from './loggerNotProd/log.js';
@@ -3,7 +3,7 @@ import { assert, removeEmptyLines, trimWithAnsi, trimWithAnsiTrailOnly } from '.
3
3
  import { logViteError, logViteAny, clearLogs } from './loggerNotProd.js';
4
4
  import { getHttpRequestAsyncStore } from './getHttpRequestAsyncStore.js';
5
5
  import { removeSuperfluousViteLog } from './loggerVite/removeSuperfluousViteLog.js';
6
- import { isErrorDebug } from './isErrorDebug.js';
6
+ import { isErrorDebug } from '../../shared/isErrorDebug.js';
7
7
  function improveViteLogs(config) {
8
8
  intercept('info', config);
9
9
  intercept('warn', config);
@@ -2,8 +2,12 @@ export { onLoad };
2
2
  import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
3
3
  import { assertNodeVersion } from '../../utils/assertNodeVersion.js';
4
4
  import { installRequireShim } from '@brillout/require-shim';
5
+ import { setAlwaysShowStackTrace } from './utils.js';
6
+ import { isErrorDebug } from '../shared/isErrorDebug.js';
5
7
  function onLoad() {
6
8
  assertIsNotBrowser();
7
9
  assertNodeVersion();
8
10
  installRequireShim();
11
+ if (isErrorDebug())
12
+ setAlwaysShowStackTrace();
9
13
  }
@@ -1,5 +1,5 @@
1
1
  export { isErrorDebug };
2
- import { isDebugActivated } from '../utils.js';
2
+ import { isDebugActivated } from './utils.js';
3
3
  function isErrorDebug() {
4
4
  return isDebugActivated('vike:error');
5
5
  }
@@ -14,3 +14,4 @@ export * from '../../utils/virtual-files.js';
14
14
  export * from '../../utils/assertIsNotBrowser.js';
15
15
  export * from '../../utils/isNotNullish.js';
16
16
  export * from '../../utils/unique.js';
17
+ export * from '../../utils/debug.js';
@@ -16,3 +16,4 @@ export * from '../../utils/virtual-files.js';
16
16
  export * from '../../utils/assertIsNotBrowser.js';
17
17
  export * from '../../utils/isNotNullish.js';
18
18
  export * from '../../utils/unique.js';
19
+ export * from '../../utils/debug.js';
@@ -5,6 +5,7 @@ export type { ConfigMeta };
5
5
  export type { HookName };
6
6
  export type { HookNamePage };
7
7
  export type { HookNameGlobal };
8
+ export type { ImportString };
8
9
  export type { DataAsync };
9
10
  export type { DataSync };
10
11
  export type { GuardAsync };
@@ -362,7 +363,7 @@ type ConfigBuiltIn = {
362
363
  *
363
364
  * https://vike.dev/require
364
365
  */
365
- require?: string;
366
+ require?: Record<string, string>;
366
367
  };
367
368
  type ConfigMeta = Record<string, ConfigDefinition>;
368
369
  type ImportString = `import:${string}`;
@@ -6,7 +6,7 @@ export type { PageContextClientWithServerRouting } from '../shared/types.js';
6
6
  export type { PageContextBuiltInServer } from '../shared/types.js';
7
7
  export type { PageContextBuiltInClientWithClientRouting } from '../shared/types.js';
8
8
  export type { PageContextBuiltInClientWithServerRouting } from '../shared/types.js';
9
- export type { Config, ConfigMeta as Meta, DataAsync, DataSync, GuardAsync, GuardSync, OnBeforePrerenderStartAsync, OnBeforePrerenderStartSync, OnBeforeRenderAsync, OnBeforeRenderSync, OnBeforeRouteAsync, OnBeforeRouteSync, OnHydrationEndAsync, OnHydrationEndSync, OnPageTransitionEndAsync, OnPageTransitionEndSync, OnPageTransitionStartAsync, OnPageTransitionStartSync, OnPrerenderStartAsync, OnPrerenderStartSync, OnRenderClientAsync, OnRenderClientSync, OnRenderHtmlAsync, OnRenderHtmlSync, RouteAsync, RouteSync } from '../shared/page-configs/Config.js';
9
+ export type { Config, ConfigMeta as Meta, ImportString, DataAsync, DataSync, GuardAsync, GuardSync, OnBeforePrerenderStartAsync, OnBeforePrerenderStartSync, OnBeforeRenderAsync, OnBeforeRenderSync, OnBeforeRouteAsync, OnBeforeRouteSync, OnHydrationEndAsync, OnHydrationEndSync, OnPageTransitionEndAsync, OnPageTransitionEndSync, OnPageTransitionStartAsync, OnPageTransitionStartSync, OnPrerenderStartAsync, OnPrerenderStartSync, OnRenderClientAsync, OnRenderClientSync, OnRenderHtmlAsync, OnRenderHtmlSync, RouteAsync, RouteSync } from '../shared/page-configs/Config.js';
10
10
  export type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
11
11
  export type { ConfigDefinition, ConfigEffect } from '../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
12
12
  export type { ConfigEntries } from '../shared/getPageFiles/getExports.js';
@@ -7,6 +7,7 @@ export { addOnBeforeLogHook };
7
7
  export { getAssertErrMsg };
8
8
  export { overwriteAssertProductionLogger };
9
9
  export { isBug };
10
+ export { setAlwaysShowStackTrace };
10
11
  type Logger = (msg: string | Error, logType: 'warn' | 'info') => void;
11
12
  declare function assert(condition: unknown, debugInfo?: unknown): asserts condition;
12
13
  declare function assertUsage(condition: unknown, errMsg: string, { showStackTrace }?: {
@@ -27,3 +28,4 @@ declare function getAssertErrMsg(thing: unknown): {
27
28
  } | null;
28
29
  declare function overwriteAssertProductionLogger(logger: Logger): void;
29
30
  declare function isBug(err: unknown): boolean;
31
+ declare function setAlwaysShowStackTrace(): void;
@@ -7,6 +7,7 @@ export { addOnBeforeLogHook };
7
7
  export { getAssertErrMsg };
8
8
  export { overwriteAssertProductionLogger };
9
9
  export { isBug };
10
+ export { setAlwaysShowStackTrace };
10
11
  import { onAssertModuleLoad } from './assertSingleInstance.js';
11
12
  import { createErrorWithCleanStackTrace } from './createErrorWithCleanStackTrace.js';
12
13
  import { getGlobalObject } from './getGlobalObject.js';
@@ -57,6 +58,7 @@ function assert(condition, debugInfo) {
57
58
  function assertUsage(condition, errMsg, { showStackTrace } = {}) {
58
59
  if (condition)
59
60
  return;
61
+ showStackTrace = showStackTrace || globalObject.alwaysShowStackTrace;
60
62
  errMsg = addWhitespace(errMsg);
61
63
  errMsg = addPrefixAssertType(errMsg, 'Wrong Usage');
62
64
  errMsg = addPrefixProjctName(errMsg);
@@ -77,6 +79,7 @@ function getProjectError(errMsg) {
77
79
  function assertWarning(condition, msg, { onlyOnce, showStackTrace }) {
78
80
  if (condition)
79
81
  return;
82
+ showStackTrace = showStackTrace || globalObject.alwaysShowStackTrace;
80
83
  msg = addWhitespace(msg);
81
84
  msg = addPrefixAssertType(msg, 'Warning');
82
85
  msg = addPrefixProjctName(msg);
@@ -187,3 +190,6 @@ function overwriteAssertProductionLogger(logger) {
187
190
  function isBug(err) {
188
191
  return !String(err).includes('[Bug]');
189
192
  }
193
+ function setAlwaysShowStackTrace() {
194
+ globalObject.alwaysShowStackTrace = true;
195
+ }
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- declare const PROJECT_VERSION: "0.4.172-commit-55d8662";
3
+ declare const PROJECT_VERSION: "0.4.172-commit-24e2d90";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.172-commit-55d8662";
6
+ projectVersion: "0.4.172-commit-24e2d90";
7
7
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- const PROJECT_VERSION = '0.4.172-commit-55d8662';
3
+ const PROJECT_VERSION = '0.4.172-commit-24e2d90';
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.172-commit-55d8662",
3
+ "version": "0.4.172-commit-24e2d90",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",