vike 0.4.159 → 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.
Files changed (125) hide show
  1. package/dist/cjs/node/plugin/index.js +20 -1
  2. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +2 -2
  3. package/dist/cjs/node/plugin/plugins/buildConfig.js +9 -0
  4. package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
  5. package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
  6. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -1
  7. package/dist/cjs/node/plugin/plugins/importBuild/index.js +1 -1
  8. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +18 -0
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
  10. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +129 -0
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +139 -0
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.js → getVikeConfig/transformFileImports.js} +44 -13
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +105 -78
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +201 -382
  17. package/dist/cjs/node/plugin/plugins/previewConfig.js +1 -1
  18. package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
  19. package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +3 -3
  20. package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
  21. package/dist/cjs/node/plugin/utils.js +1 -2
  22. package/dist/cjs/node/prerender/runPrerender.js +12 -5
  23. package/dist/cjs/node/runtime/globalContext.js +7 -3
  24. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
  25. package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
  26. package/dist/cjs/node/runtime/html/stream.js +2 -2
  27. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
  28. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
  29. package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
  30. package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
  31. package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
  32. package/dist/cjs/node/runtime/utils.js +1 -1
  33. package/dist/cjs/shared/page-configs/assertPlusFileExport.js +44 -0
  34. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +54 -27
  35. package/dist/cjs/shared/route/abort.js +1 -1
  36. package/dist/cjs/shared/route/executeGuardHook.js +3 -2
  37. package/dist/cjs/shared/utils.js +0 -1
  38. package/dist/cjs/utils/assert.js +5 -6
  39. package/dist/cjs/utils/assertIsNotProductionRuntime.js +35 -17
  40. package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
  41. package/dist/cjs/utils/nodeEnv.js +33 -1
  42. package/dist/cjs/utils/objectKeys.js +19 -3
  43. package/dist/cjs/utils/projectInfo.js +2 -4
  44. package/dist/cjs/utils/sorter.js +62 -1
  45. package/dist/esm/node/plugin/index.js +21 -2
  46. package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
  47. package/dist/esm/node/plugin/plugins/buildConfig.js +10 -1
  48. package/dist/esm/node/plugin/plugins/commonConfig.js +2 -2
  49. package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -2
  50. package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -2
  51. package/dist/esm/node/plugin/plugins/importBuild/index.js +2 -2
  52. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.d.ts +2 -0
  53. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +12 -0
  54. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +8 -1
  55. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
  56. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
  57. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
  58. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
  59. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +21 -0
  60. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +123 -0
  61. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
  62. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
  63. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +12 -0
  64. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +133 -0
  65. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.d.ts → getVikeConfig/transformFileImports.d.ts} +5 -5
  66. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.js → getVikeConfig/transformFileImports.js} +43 -12
  67. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.d.ts → getVikeConfig/transpileAndExecuteFile.d.ts} +3 -3
  68. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +105 -78
  69. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +16 -1
  70. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +199 -380
  71. package/dist/esm/node/plugin/plugins/previewConfig.js +2 -2
  72. package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
  73. package/dist/esm/node/plugin/shared/loggerNotProd/log.js +3 -3
  74. package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
  75. package/dist/esm/node/plugin/utils.d.ts +1 -2
  76. package/dist/esm/node/plugin/utils.js +1 -2
  77. package/dist/esm/node/prerender/runPrerender.js +13 -6
  78. package/dist/esm/node/runtime/globalContext.js +8 -4
  79. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
  80. package/dist/esm/node/runtime/html/renderHtml.js +1 -1
  81. package/dist/esm/node/runtime/html/stream.js +2 -2
  82. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
  83. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +1 -1
  84. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
  85. package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
  86. package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
  87. package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
  88. package/dist/esm/node/runtime/utils.d.ts +1 -1
  89. package/dist/esm/node/runtime/utils.js +1 -1
  90. package/dist/esm/shared/page-configs/Config.d.ts +1 -1
  91. package/dist/esm/shared/page-configs/PageConfig.d.ts +6 -0
  92. package/dist/esm/shared/page-configs/assertPlusFileExport.d.ts +2 -0
  93. package/dist/esm/shared/page-configs/assertPlusFileExport.js +38 -0
  94. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +54 -27
  95. package/dist/esm/shared/route/abort.js +2 -2
  96. package/dist/esm/shared/route/executeGuardHook.js +3 -2
  97. package/dist/esm/shared/utils.d.ts +0 -1
  98. package/dist/esm/shared/utils.js +0 -1
  99. package/dist/esm/utils/assert.js +5 -6
  100. package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +8 -6
  101. package/dist/esm/utils/assertIsNotProductionRuntime.js +35 -17
  102. package/dist/esm/utils/debug.d.ts +1 -1
  103. package/dist/esm/utils/findFile.d.ts +3 -0
  104. package/dist/esm/utils/findFile.js +21 -0
  105. package/dist/esm/utils/nodeEnv.d.ts +6 -0
  106. package/dist/esm/utils/nodeEnv.js +29 -0
  107. package/dist/esm/utils/objectKeys.d.ts +10 -1
  108. package/dist/esm/utils/objectKeys.js +20 -3
  109. package/dist/esm/utils/projectInfo.d.ts +2 -8
  110. package/dist/esm/utils/projectInfo.js +2 -4
  111. package/dist/esm/utils/sorter.d.ts +59 -0
  112. package/dist/esm/utils/sorter.js +61 -0
  113. package/package.json +1 -1
  114. package/dist/cjs/shared/page-configs/assertExports.js +0 -67
  115. package/dist/cjs/utils/objectEntries.js +0 -8
  116. package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
  117. package/dist/esm/shared/page-configs/assertExports.d.ts +0 -6
  118. package/dist/esm/shared/page-configs/assertExports.js +0 -61
  119. package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
  120. package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
  121. package/dist/esm/utils/objectEntries.d.ts +0 -4
  122. package/dist/esm/utils/objectEntries.js +0 -5
  123. /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
  124. /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
  125. /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
@@ -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);
@@ -22,8 +22,8 @@ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assert.ts'
22
22
  },
23
23
  showStackTraceList: new WeakSet()
24
24
  });
25
- const projectTag = `[${projectInfo_js_1.projectInfo.npmPackageName}]`;
26
- const projectTagWithVersion = `[${projectInfo_js_1.projectInfo.npmPackageName}@${projectInfo_js_1.projectInfo.projectVersion}]`;
25
+ const projectTag = `[vike]`;
26
+ const projectTagWithVersion = `[vike@${projectInfo_js_1.projectInfo.projectVersion}]`;
27
27
  const numberOfStackTraceLinesToRemove = 2;
28
28
  function assert(condition, debugInfo) {
29
29
  if (condition)
@@ -33,12 +33,11 @@ function assert(condition, debugInfo) {
33
33
  return null;
34
34
  }
35
35
  const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
36
- return picocolors_1.default.dim(`Debug info (for ${projectInfo_js_1.projectInfo.projectName} maintainers; you can ignore this): ${debugInfoSerialized}`);
36
+ return picocolors_1.default.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
37
37
  })();
38
- const link = `${projectInfo_js_1.projectInfo.githubRepository}/issues/new`;
39
38
  let errMsg = [
40
- `You stumbled upon a bug in ${projectInfo_js_1.projectInfo.projectName}'s source code.`,
41
- `Go to ${picocolors_1.default.blue(link)} and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).`,
39
+ `You stumbled upon a Vike bug.`,
40
+ `Go to ${picocolors_1.default.blue('https://github.com/vikejs/vike/issues/new')} and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).`,
42
41
  debugStr
43
42
  ]
44
43
  .filter(Boolean)
@@ -1,44 +1,62 @@
1
1
  "use strict";
2
2
  // Mechanism to ensure code isn't loaded by production runtime
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.assertEnv = exports.markEnvAsVite = exports.markEnvAsPreview = exports.markEnvAsDev = exports.assertIsNotProductionRuntime = void 0;
4
+ exports.vikeVitePluginLoadedInProductionError = exports.assertEnv = exports.markEnvAsVikePluginLoaded = exports.markEnvAsVitePreview = exports.markEnvAsViteDev = exports.assertIsNotProductionRuntime = void 0;
5
5
  const assert_js_1 = require("./assert.js");
6
6
  const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
7
+ const debug_js_1 = require("./debug.js");
7
8
  const getGlobalObject_js_1 = require("./getGlobalObject.js");
8
9
  const isVitest_js_1 = require("./isVitest.js");
9
10
  (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
11
+ const debug = (0, debug_js_1.createDebugger)('vike:setup');
12
+ const vikeVitePluginLoadedInProductionError = `Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.`;
13
+ exports.vikeVitePluginLoadedInProductionError = vikeVitePluginLoadedInProductionError;
10
14
  const env = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertIsNotProductionRuntime.ts', {});
11
- // Called by *.ts that want to ensure that they aren't loaded by the server runtime in production
15
+ // Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
12
16
  function assertIsNotProductionRuntime() {
13
- env.shouldBeVite = true;
17
+ if (debug.isEnabled)
18
+ debug('assertIsNotProductionRuntime()', new Error().stack);
19
+ env.shouldNotBeProduction = true;
14
20
  }
15
21
  exports.assertIsNotProductionRuntime = assertIsNotProductionRuntime;
16
22
  // Called by Vite hook configureServer()
17
- function markEnvAsDev() {
18
- env.isDev = true;
23
+ function markEnvAsViteDev() {
24
+ if (debug.isEnabled)
25
+ debug('markEnvAsViteDev()', new Error().stack);
26
+ env.isViteDev = true;
19
27
  }
20
- exports.markEnvAsDev = markEnvAsDev;
28
+ exports.markEnvAsViteDev = markEnvAsViteDev;
21
29
  // Called by Vite hook configurePreviewServer()
22
- function markEnvAsPreview() {
23
- env.isPreview = true;
30
+ function markEnvAsVitePreview() {
31
+ if (debug.isEnabled)
32
+ debug('markEnvAsVitePreview()', new Error().stack);
33
+ env.isVitePreview = true;
24
34
  }
25
- exports.markEnvAsPreview = markEnvAsPreview;
35
+ exports.markEnvAsVitePreview = markEnvAsVitePreview;
26
36
  // Called by ../node/plugin/index.ts
27
- function markEnvAsVite() {
28
- env.isVite = true;
37
+ function markEnvAsVikePluginLoaded() {
38
+ if (debug.isEnabled)
39
+ debug('markEnvAsVikePluginLoaded()', new Error().stack);
40
+ env.isVikePluginLoaded = true;
29
41
  }
30
- exports.markEnvAsVite = markEnvAsVite;
42
+ exports.markEnvAsVikePluginLoaded = markEnvAsVikePluginLoaded;
31
43
  // Called by ../node/runtime/index.ts
32
44
  function assertEnv() {
45
+ if (debug.isEnabled)
46
+ debug('assertEnv()', new Error().stack);
33
47
  if ((0, isVitest_js_1.isVitest)())
34
48
  return;
35
- if (env.isDev || env.isPreview) {
36
- (0, assert_js_1.assert)(env.isVite);
37
- (0, assert_js_1.assert)(env.shouldBeVite);
49
+ const isProduction = !env.isViteDev && !env.isVitePreview;
50
+ if (isProduction) {
51
+ // Seems to be the only reliable way to assert that the user doesn't load Vike's Vite plugin in production. (The other assert() that uses process.env.NODE_ENV doesn't work if the user sets the process.env.NODE_ENV value later.)
52
+ (0, assert_js_1.assertUsage)(!env.isVikePluginLoaded, vikeVitePluginLoadedInProductionError);
53
+ // This assert() is the main goal of this file: it ensures assertIsNotProductionRuntime()
54
+ (0, assert_js_1.assert)(!env.shouldNotBeProduction);
38
55
  }
39
56
  else {
40
- (0, assert_js_1.assert)(!env.isVite);
41
- (0, assert_js_1.assert)(!env.shouldBeVite);
57
+ // This assert() is obious and boring
58
+ (0, assert_js_1.assert)(env.shouldNotBeProduction);
59
+ (0, assert_js_1.assert)(env.isVikePluginLoaded);
42
60
  }
43
61
  }
44
62
  exports.assertEnv = assertEnv;
@@ -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.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;
@@ -14,3 +21,28 @@ function setNodeEnvToProduction() {
14
21
  env.NODE_ENV = 'production';
15
22
  }
16
23
  exports.setNodeEnvToProduction = setNodeEnvToProduction;
24
+ function isNodeEnvDev() {
25
+ const nodeEnv = getNodeEnv();
26
+ if (!nodeEnv)
27
+ return true;
28
+ if (['development', 'dev'].includes(nodeEnv))
29
+ return true;
30
+ // That's quite aggressive, let's see if some user complains
31
+ return false;
32
+ }
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,13 +2,11 @@
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.159';
5
+ const PROJECT_VERSION = '0.4.160-commit-30d535e';
6
6
  exports.PROJECT_VERSION = PROJECT_VERSION;
7
7
  const projectInfo = {
8
8
  projectName: 'Vike',
9
- projectVersion: PROJECT_VERSION,
10
- npmPackageName: 'vike',
11
- githubRepository: 'https://github.com/vikejs/vike'
9
+ projectVersion: PROJECT_VERSION
12
10
  };
13
11
  exports.projectInfo = projectInfo;
14
12
  // Trick: since `utils/asserts.ts` depends on this file (`utils/projectInfo.ts`), we can have confidence that this file is always instantiated. So that we don't have to initialize this code snippet at every possible entry. (There are a *lot* of entries: `client/router/`, `client/`, `node/`, `node/plugin/`, `node/cli`, etc.)
@@ -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;
@@ -3,7 +3,7 @@ export { plugin };
3
3
  // TODO/v1-release: remove
4
4
  export { plugin as ssr };
5
5
  export { PROJECT_VERSION as version } from './utils.js';
6
- import { assertUsage, markEnvAsVite } from './utils.js';
6
+ import { assertUsage, getNodeEnv, isNodeEnvDev, markEnvAsVikePluginLoaded, vikeVitePluginLoadedInProductionError } from './utils.js';
7
7
  import { buildConfig } from './plugins/buildConfig.js';
8
8
  import { previewConfig } from './plugins/previewConfig.js';
9
9
  import { autoFullBuild } from './plugins/autoFullBuild.js';
@@ -24,7 +24,8 @@ import { baseUrls } from './plugins/baseUrls.js';
24
24
  import { envVarsPlugin } from './plugins/envVars.js';
25
25
  import pc from '@brillout/picocolors';
26
26
  import { fileEnv } from './plugins/fileEnv.js';
27
- markEnvAsVite();
27
+ assertNodeEnv();
28
+ markEnvAsVikePluginLoaded();
28
29
  // Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
29
30
  function plugin(vikeConfig) {
30
31
  const plugins = [
@@ -64,3 +65,21 @@ Object.defineProperty(plugin, 'apply', {
64
65
  assertUsage(false, `Add ${pc.cyan('vike()')} instead of ${pc.cyan('vike')} to vite.config.js#plugins (i.e. call the function and add the return value instead of adding the function itself)`, { showStackTrace: true });
65
66
  }
66
67
  });
68
+ function assertNodeEnv() {
69
+ const nodeEnv = getNodeEnv();
70
+ if (nodeEnv === 'test')
71
+ return;
72
+ // We should change this to be a warning if it blocks users (e.g. if a bad-citizen tool sets a wrong process.env.NODE_ENV value).
73
+ assertUsage(
74
+ /* We can enable this assertion after Vike's CLI is implemented and using Vite's CLI is deprecated (we can then check whether the context is a `$ vike build`).
75
+ isNodeEnvDev() || isVikeCliBuild(),
76
+ /*/
77
+ isNodeEnvDev() || true,
78
+ ///*/
79
+ [
80
+ pc.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`),
81
+ '(which Vike interprets as a non-development environment https://vike.dev/NODE_ENV)',
82
+ 'while the vike/plugin module is loaded.',
83
+ vikeVitePluginLoadedInProductionError
84
+ ].join(' '));
85
+ }
@@ -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
+ }
@@ -1,5 +1,5 @@
1
1
  export { commonConfig };
2
- import { assert, assertWarning, findUserPackageJsonPath } from '../utils.js';
2
+ import { assert, assertWarning, findFile } from '../utils.js';
3
3
  import { assertRollupInput } from './buildConfig.js';
4
4
  import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
5
5
  import pc from '@brillout/picocolors';
@@ -70,7 +70,7 @@ function workaroundCI(config) {
70
70
  }
71
71
  }
72
72
  function assertEsm(userViteRoot) {
73
- const packageJsonPath = findUserPackageJsonPath(userViteRoot);
73
+ const packageJsonPath = findFile('package.json', userViteRoot);
74
74
  if (!packageJsonPath)
75
75
  return;
76
76
  const packageJson = require_(packageJsonPath);
@@ -1,7 +1,7 @@
1
1
  // Move to standalone package? E.g. https://www.npmjs.com/package/stem
2
2
  export { getStemPackages };
3
3
  import path from 'path';
4
- import { assert, assertUsage, assertWarning, toPosixPath, assertPosixPath, getDependencyRootDir, findUserPackageJsonPath } from '../../utils.js';
4
+ import { assert, assertUsage, assertWarning, toPosixPath, assertPosixPath, getDependencyRootDir, findFile } from '../../utils.js';
5
5
  import { import_ } from '@brillout/import';
6
6
  import { createRequire } from 'module';
7
7
  // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
@@ -48,7 +48,7 @@ async function getStemPackages(userAppRootDir) {
48
48
  return stemPackages;
49
49
  }
50
50
  function findUserRootDir(userAppRootDir) {
51
- const userPkgJsonPath = findUserPackageJsonPath(userAppRootDir);
51
+ const userPkgJsonPath = findFile('package.json', userAppRootDir);
52
52
  assertUsage(userPkgJsonPath, `Couldn't find package.json in any parent directory starting from ${userAppRootDir}`);
53
53
  return toPosixPath(path.dirname(userPkgJsonPath));
54
54
  }
@@ -3,7 +3,7 @@ import { determineOptimizeDeps } from './determineOptimizeDeps.js';
3
3
  import { determineFsAllowList } from './determineFsAllowList.js';
4
4
  import { getConfigVike } from '../../../shared/getConfigVike.js';
5
5
  import { addSsrMiddleware } from '../../shared/addSsrMiddleware.js';
6
- import { markEnvAsDev } from '../../utils.js';
6
+ import { markEnvAsViteDev } from '../../utils.js';
7
7
  import { improveViteLogs } from '../../shared/loggerVite.js';
8
8
  import { isErrorDebug } from '../../shared/isErrorDebug.js';
9
9
  import { installHttpRequestAsyncStore } from '../../shared/getHttpRequestAsyncStore.js';
@@ -64,7 +64,7 @@ function devConfig() {
64
64
  }
65
65
  },
66
66
  configureServer() {
67
- markEnvAsDev();
67
+ markEnvAsViteDev();
68
68
  }
69
69
  },
70
70
  {
@@ -1,6 +1,6 @@
1
1
  export { importBuild };
2
2
  import { serverEntryPlugin, findServerEntry } from '@brillout/vite-plugin-server-entry/plugin.js';
3
- import { assert, getOutDirs, projectInfo, toPosixPath, viteIsSSR } from '../../utils.js';
3
+ import { assert, getOutDirs, toPosixPath, viteIsSSR } from '../../utils.js';
4
4
  import path from 'path';
5
5
  import { createRequire } from 'module';
6
6
  import { getConfigVike } from '../../../shared/getConfigVike.js';
@@ -32,7 +32,7 @@ function importBuild() {
32
32
  getImporterCode: () => {
33
33
  return getEntryCode(config, configVike);
34
34
  },
35
- libraryName: projectInfo.projectName
35
+ libraryName: 'Vike'
36
36
  })
37
37
  ];
38
38
  }
@@ -0,0 +1,2 @@
1
+ export { getConfigFileExport };
2
+ declare function getConfigFileExport(fileExports: Record<string, unknown>, filePathToShowToUser: string): Record<string, unknown>;
@@ -0,0 +1,12 @@
1
+ export { getConfigFileExport };
2
+ import pc from '@brillout/picocolors';
3
+ import { assertPlusFileExport } from '../../../../../shared/page-configs/assertPlusFileExport.js';
4
+ import { assert, assertUsage, isObject } from '../../../utils.js';
5
+ function getConfigFileExport(fileExports, filePathToShowToUser) {
6
+ assertPlusFileExport(fileExports, filePathToShowToUser, 'config');
7
+ const fileExport = fileExports.default || fileExports.config;
8
+ assert('default' in fileExports !== 'config' in fileExports);
9
+ const exportName = pc.cyan('default' in fileExports ? 'export default' : 'export { config }');
10
+ assertUsage(isObject(fileExport), `The ${exportName} of ${filePathToShowToUser} should be an object (but it's ${pc.cyan(`typeof exportedValue === ${JSON.stringify(typeof fileExport)}`)} instead)`);
11
+ return fileExport;
12
+ }
@@ -1,6 +1,7 @@
1
1
  export { configDefinitionsBuiltIn };
2
2
  export { configDefinitionsBuiltInGlobal };
3
3
  export type { ConfigDefinition };
4
+ export type { ConfigDefinitions };
4
5
  export type { ConfigDefinitionInternal };
5
6
  export type { ConfigNameGlobal };
6
7
  export type { ConfigEffect };
@@ -24,12 +25,17 @@ type ConfigDefinition = {
24
25
  */
25
26
  cumulative?: boolean;
26
27
  /**
27
- * Define a so-called "Shortcut Config".
28
+ * Function called when the config value is defined.
28
29
  *
29
30
  * https://vike.dev/meta
30
31
  */
31
32
  effect?: ConfigEffect;
32
33
  };
34
+ /**
35
+ * Function called when the config value is defined.
36
+ *
37
+ * https://vike.dev/meta
38
+ */
33
39
  type ConfigEffect = (config: {
34
40
  /** The config value.
35
41
  *
@@ -49,6 +55,7 @@ type ConfigDefinitionInternal = Omit<ConfigDefinition, 'env'> & {
49
55
  _userEffectDefinedAt?: DefinedAtFileFullInfo;
50
56
  env: ConfigEnvInternal;
51
57
  };
58
+ type ConfigDefinitions = Record<string, ConfigDefinitionInternal>;
52
59
  type ConfigDefinitionsBuiltIn = Record<ConfigNameBuiltIn, ConfigDefinitionInternal>;
53
60
  declare const configDefinitionsBuiltIn: ConfigDefinitionsBuiltIn;
54
61
  type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'extensions' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization';
@@ -1,5 +1,4 @@
1
1
  export { crawlPlusFiles };
2
2
  declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: string, isDev: boolean): Promise<{
3
3
  filePathRelativeToUserRootDir: string;
4
- filePathAbsoluteFilesystem: string;
5
4
  }[]>;
@@ -44,11 +44,7 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
44
44
  p = toPosixPath(p);
45
45
  assert(!p.startsWith(userRootDir));
46
46
  const filePathRelativeToUserRootDir = path.posix.join('/', p);
47
- const filePathAbsoluteFilesystem = path.posix.join(userRootDir, p);
48
- return {
49
- filePathRelativeToUserRootDir,
50
- filePathAbsoluteFilesystem
51
- };
47
+ return { filePathRelativeToUserRootDir };
52
48
  });
53
49
  return plusFiles;
54
50
  }