vike 0.4.214 → 0.4.215

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 (61) hide show
  1. package/dist/cjs/node/api/build.js +9 -3
  2. package/dist/cjs/node/api/context.js +18 -0
  3. package/dist/cjs/node/api/dev.js +6 -3
  4. package/dist/cjs/node/api/onLoad.js +9 -0
  5. package/dist/cjs/node/api/{enhanceViteConfig.js → prepareApiCall.js} +11 -6
  6. package/dist/cjs/node/api/prerender.js +6 -3
  7. package/dist/cjs/node/api/preview.js +6 -3
  8. package/dist/cjs/node/api/utils.js +21 -0
  9. package/dist/cjs/node/cli/entry.js +8 -8
  10. package/dist/cjs/node/cli/onLoad.js +2 -0
  11. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +0 -3
  12. package/dist/cjs/node/plugin/plugins/commonConfig/pluginName.js +1 -1
  13. package/dist/cjs/node/plugin/plugins/commonConfig.js +5 -1
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -15
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -7
  16. package/dist/cjs/node/prerender/runPrerender.js +4 -3
  17. package/dist/cjs/shared/page-configs/getConfigValue.js +2 -31
  18. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +2 -2
  19. package/dist/cjs/shared/page-configs/getConfigValueTyped.js +32 -0
  20. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  21. package/dist/esm/node/api/build.d.ts +5 -3
  22. package/dist/esm/node/api/build.js +9 -3
  23. package/dist/esm/node/api/context.d.ts +5 -0
  24. package/dist/esm/node/api/context.js +17 -0
  25. package/dist/esm/node/api/dev.d.ts +6 -2
  26. package/dist/esm/node/api/dev.js +6 -3
  27. package/dist/esm/node/api/onLoad.d.ts +2 -0
  28. package/dist/esm/node/api/onLoad.js +7 -0
  29. package/dist/esm/node/api/prepareApiCall.d.ts +7 -0
  30. package/dist/esm/node/api/{enhanceViteConfig.js → prepareApiCall.js} +11 -6
  31. package/dist/esm/node/api/prerender.d.ts +4 -1
  32. package/dist/esm/node/api/prerender.js +6 -3
  33. package/dist/esm/node/api/preview.d.ts +6 -2
  34. package/dist/esm/node/api/preview.js +6 -3
  35. package/dist/esm/node/api/{APIOptions.d.ts → types.d.ts} +3 -1
  36. package/dist/esm/node/api/utils.d.ts +1 -0
  37. package/dist/esm/node/api/utils.js +5 -0
  38. package/dist/esm/node/cli/entry.js +8 -8
  39. package/dist/esm/node/cli/onLoad.js +2 -0
  40. package/dist/esm/node/plugin/plugins/autoFullBuild.js +0 -3
  41. package/dist/esm/node/plugin/plugins/commonConfig/pluginName.d.ts +1 -1
  42. package/dist/esm/node/plugin/plugins/commonConfig/pluginName.js +1 -1
  43. package/dist/esm/node/plugin/plugins/commonConfig.js +5 -1
  44. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  45. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -16
  46. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -7
  47. package/dist/esm/node/prerender/runPrerender.d.ts +5 -3
  48. package/dist/esm/node/prerender/runPrerender.js +4 -3
  49. package/dist/esm/shared/page-configs/getConfigValue.d.ts +2 -8
  50. package/dist/esm/shared/page-configs/getConfigValue.js +1 -27
  51. package/dist/esm/shared/page-configs/getConfigValueBuildTime.d.ts +2 -3
  52. package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +1 -1
  53. package/dist/esm/shared/page-configs/getConfigValueTyped.d.ts +9 -0
  54. package/dist/esm/shared/page-configs/getConfigValueTyped.js +27 -0
  55. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  56. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  57. package/dist/esm/utils/projectInfo.d.ts +1 -1
  58. package/package.json +1 -1
  59. package/dist/esm/node/api/enhanceViteConfig.d.ts +0 -6
  60. /package/dist/cjs/node/api/{APIOptions.js → types.js} +0 -0
  61. /package/dist/esm/node/api/{APIOptions.js → types.js} +0 -0
@@ -24,10 +24,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.build = build;
27
- const enhanceViteConfig_js_1 = require("./enhanceViteConfig.js");
27
+ const prepareApiCall_js_1 = require("./prepareApiCall.js");
28
28
  const vite_1 = require("vite");
29
29
  async function build(options = {}) {
30
- const { viteConfigEnhanced, configVike } = await (0, enhanceViteConfig_js_1.enhanceViteConfig)(options.viteConfig, 'build');
30
+ const { viteConfigEnhanced, configVike } = await (0, prepareApiCall_js_1.prepareApiCall)(options.viteConfig, 'build');
31
31
  // Build client-side
32
32
  const outputClient = await (0, vite_1.build)(viteConfigEnhanced);
33
33
  // Build server-side
@@ -37,7 +37,13 @@ async function build(options = {}) {
37
37
  const { runPrerenderFromAutoRun } = await Promise.resolve().then(() => __importStar(require('../prerender/runPrerender.js')));
38
38
  await runPrerenderFromAutoRun(viteConfigEnhanced, true);
39
39
  }
40
- return { outputClient, outputServer };
40
+ return {
41
+ /* We don't return `viteConfig` because `viteConfigEnhanced` is `InlineConfig` not `ResolvedConfig`
42
+ viteConfig: viteConfigEnhanced,
43
+ */
44
+ rollupOutputClient: outputClient,
45
+ rollupOutputServer: outputServer
46
+ };
41
47
  }
42
48
  function setSSR(viteConfig) {
43
49
  return {
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isVikeCliOrApi = isVikeCliOrApi;
4
+ exports.setOperation = setOperation;
5
+ const utils_js_1 = require("./utils.js");
6
+ let apiOperation;
7
+ function getOperation() {
8
+ (0, utils_js_1.assert)(apiOperation);
9
+ return apiOperation;
10
+ }
11
+ function isVikeCliOrApi() {
12
+ // The CLI uses the API
13
+ return !!apiOperation;
14
+ }
15
+ function setOperation(operation) {
16
+ (0, utils_js_1.assert)(!apiOperation);
17
+ apiOperation = operation;
18
+ }
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dev = dev;
4
- const enhanceViteConfig_js_1 = require("./enhanceViteConfig.js");
4
+ const prepareApiCall_js_1 = require("./prepareApiCall.js");
5
5
  const vite_1 = require("vite");
6
6
  async function dev(options = {}) {
7
- const { viteConfigEnhanced } = await (0, enhanceViteConfig_js_1.enhanceViteConfig)(options.viteConfig, 'dev');
7
+ const { viteConfigEnhanced } = await (0, prepareApiCall_js_1.prepareApiCall)(options.viteConfig, 'dev');
8
8
  const server = await (0, vite_1.createServer)(viteConfigEnhanced);
9
- return server;
9
+ return {
10
+ viteServer: server,
11
+ viteConfig: server.config
12
+ };
10
13
  }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onLoad = onLoad;
4
+ const assertIsNotBrowser_js_1 = require("../../utils/assertIsNotBrowser.js");
5
+ const utils_js_1 = require("../runtime/utils.js");
6
+ function onLoad() {
7
+ (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
8
+ (0, utils_js_1.assertIsNotProductionRuntime)();
9
+ }
@@ -23,12 +23,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.enhanceViteConfig = enhanceViteConfig;
26
+ exports.prepareApiCall = prepareApiCall;
27
27
  const vite_1 = require("vite");
28
28
  const getConfigVike_js_1 = require("../shared/getConfigVike.js");
29
29
  const pluginName_js_1 = require("../plugin/plugins/commonConfig/pluginName.js");
30
- async function enhanceViteConfig(viteConfig = {}, command) {
31
- let viteConfigResolved = await resolveViteConfig(viteConfig, command);
30
+ const context_js_1 = require("./context.js");
31
+ async function prepareApiCall(viteConfig = {}, operation) {
32
+ (0, context_js_1.setOperation)(operation);
33
+ return enhanceViteConfig(viteConfig, operation);
34
+ }
35
+ async function enhanceViteConfig(viteConfig = {}, operation) {
36
+ let viteConfigResolved = await resolveViteConfig(viteConfig, operation);
32
37
  let viteConfigEnhanced = viteConfig;
33
38
  // Add vike to plugins if not present
34
39
  if (!viteConfigResolved.plugins.some((p) => p.name === pluginName_js_1.pluginName)) {
@@ -38,7 +43,7 @@ async function enhanceViteConfig(viteConfig = {}, command) {
38
43
  ...viteConfig,
39
44
  plugins: [...(viteConfig.plugins ?? []), vikePlugin()]
40
45
  };
41
- viteConfigResolved = await resolveViteConfig(viteConfigEnhanced, command);
46
+ viteConfigResolved = await resolveViteConfig(viteConfigEnhanced, operation);
42
47
  }
43
48
  const configVike = await (0, getConfigVike_js_1.getConfigVike)(viteConfigResolved);
44
49
  // TODO: enable Vike extensions to add Vite plugins
@@ -47,6 +52,6 @@ async function enhanceViteConfig(viteConfig = {}, command) {
47
52
  configVike
48
53
  };
49
54
  }
50
- async function resolveViteConfig(viteConfig, command) {
51
- return await (0, vite_1.resolveConfig)(viteConfig, command === 'build' || command === 'prerender' ? 'build' : 'serve', 'custom', command === 'dev' ? 'development' : 'production', command === 'preview');
55
+ async function resolveViteConfig(viteConfig, operation) {
56
+ return await (0, vite_1.resolveConfig)(viteConfig, operation === 'build' || operation === 'prerender' ? 'build' : 'serve', 'custom', operation === 'dev' ? 'development' : 'production', operation === 'preview');
52
57
  }
@@ -2,9 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.prerender = prerender;
4
4
  const runPrerender_js_1 = require("../prerender/runPrerender.js");
5
- const enhanceViteConfig_js_1 = require("./enhanceViteConfig.js");
5
+ const prepareApiCall_js_1 = require("./prepareApiCall.js");
6
6
  async function prerender(options = {}) {
7
- const { viteConfigEnhanced } = await (0, enhanceViteConfig_js_1.enhanceViteConfig)(options.viteConfig, 'prerender');
7
+ const { viteConfigEnhanced } = await (0, prepareApiCall_js_1.prepareApiCall)(options.viteConfig, 'prerender');
8
8
  options.viteConfig = viteConfigEnhanced;
9
- await (0, runPrerender_js_1.runPrerenderFromAPI)(options);
9
+ const { viteConfig } = await (0, runPrerender_js_1.runPrerenderFromAPI)(options);
10
+ return {
11
+ viteConfig
12
+ };
10
13
  }
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.preview = preview;
4
- const enhanceViteConfig_js_1 = require("./enhanceViteConfig.js");
4
+ const prepareApiCall_js_1 = require("./prepareApiCall.js");
5
5
  const vite_1 = require("vite");
6
6
  async function preview(options = {}) {
7
- const { viteConfigEnhanced } = await (0, enhanceViteConfig_js_1.enhanceViteConfig)(options.viteConfig, 'preview');
7
+ const { viteConfigEnhanced } = await (0, prepareApiCall_js_1.prepareApiCall)(options.viteConfig, 'preview');
8
8
  const server = await (0, vite_1.preview)(viteConfigEnhanced);
9
- return server;
9
+ return {
10
+ viteServer: server,
11
+ viteConfig: server.config
12
+ };
10
13
  }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ // Utils needed by Vike's API
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ // We call onLoad() here so that it's called even when only a subset of the API is loaded. (Making the assert() calls inside onLoad() a lot stronger.)
19
+ const onLoad_js_1 = require("./onLoad.js");
20
+ (0, onLoad_js_1.onLoad)();
21
+ __exportStar(require("../../utils/assert.js"), exports);
@@ -49,16 +49,16 @@ async function cli() {
49
49
  async function cmdDev() {
50
50
  const startTime = performance.now();
51
51
  try {
52
- const server = await (0, index_js_1.dev)();
53
- await server.listen();
54
- const info = server.config.logger.info;
52
+ const { viteServer } = await (0, index_js_1.dev)();
53
+ await viteServer.listen();
54
+ const info = viteServer.config.logger.info;
55
55
  const startupDurationString = picocolors_1.default.dim(`ready in ${picocolors_1.default.reset(picocolors_1.default.bold(String(Math.ceil(performance.now() - startTime))))} ms`);
56
56
  const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
57
57
  info(` ${picocolors_1.default.yellow(`${picocolors_1.default.bold(utils_js_1.projectInfo.projectName)} v${utils_js_1.projectInfo.projectVersion}`)} ${startupDurationString}\n`, {
58
58
  clear: !hasExistingLogs
59
59
  });
60
- server.printUrls();
61
- server.bindCLIShortcuts({ print: true });
60
+ viteServer.printUrls();
61
+ viteServer.bindCLIShortcuts({ print: true });
62
62
  }
63
63
  catch (err) {
64
64
  console.error(picocolors_1.default.red(`Error while starting dev server:`));
@@ -80,9 +80,9 @@ async function cmdBuild() {
80
80
  }
81
81
  async function cmdPreview() {
82
82
  try {
83
- const server = await (0, index_js_1.preview)();
84
- server.printUrls();
85
- server.bindCLIShortcuts({ print: true });
83
+ const { viteServer } = await (0, index_js_1.preview)();
84
+ viteServer.printUrls();
85
+ viteServer.bindCLIShortcuts({ print: true });
86
86
  }
87
87
  catch (err) {
88
88
  console.error(picocolors_1.default.red(`Error while starting preview server:`));
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.onLoad = onLoad;
4
4
  const assertIsNotBrowser_js_1 = require("../../utils/assertIsNotBrowser.js");
5
+ const utils_js_1 = require("../runtime/utils.js");
5
6
  function onLoad() {
6
7
  (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
8
+ (0, utils_js_1.assertIsNotProductionRuntime)();
7
9
  }
@@ -14,9 +14,6 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
14
14
  const logErrorHint_js_1 = require("../../runtime/renderPage/logErrorHint.js");
15
15
  const buildConfig_js_1 = require("./buildConfig.js");
16
16
  let forceExit = false;
17
- (0, utils_js_1.assertWarning)(!(0, isViteCliCall_js_1.isViteCliCall)(), `Vite's CLI is deprecated ${picocolors_1.default.underline('https://vike.dev/migration/cli')}`, {
18
- onlyOnce: true
19
- });
20
17
  function autoFullBuild() {
21
18
  let config;
22
19
  let configVike;
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pluginName = void 0;
4
- exports.pluginName = 'vike:commonConfig-1';
4
+ exports.pluginName = 'vike:commonConfig';
@@ -13,6 +13,10 @@ const path_1 = __importDefault(require("path"));
13
13
  const assertResolveAlias_js_1 = require("./commonConfig/assertResolveAlias.js");
14
14
  const pluginName_js_1 = require("./commonConfig/pluginName.js");
15
15
  const getEnvVarObject_js_1 = require("../shared/getEnvVarObject.js");
16
+ const isViteCliCall_js_1 = require("../shared/isViteCliCall.js");
17
+ (0, utils_js_1.assertWarning)(!(0, isViteCliCall_js_1.isViteCliCall)(), `Vite's CLI is deprecated ${picocolors_1.default.underline('https://vike.dev/migration/cli')}`, {
18
+ onlyOnce: true
19
+ });
16
20
  function commonConfig() {
17
21
  return [
18
22
  {
@@ -23,7 +27,7 @@ function commonConfig() {
23
27
  }
24
28
  },
25
29
  {
26
- name: 'vike:commonConfig-2',
30
+ name: `${pluginName_js_1.pluginName}:post`,
27
31
  enforce: 'post',
28
32
  configResolved: {
29
33
  order: 'post',
@@ -10,14 +10,13 @@ const promises_1 = __importDefault(require("fs/promises"));
10
10
  const fast_glob_1 = __importDefault(require("fast-glob"));
11
11
  const child_process_1 = require("child_process");
12
12
  const util_1 = require("util");
13
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
14
13
  const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
15
14
  const execA = (0, util_1.promisify)(child_process_1.exec);
16
15
  const TOO_MANY_UNTRACKED_FILES = 5;
17
16
  (0, utils_js_1.assertIsNotProductionRuntime)();
18
17
  (0, utils_js_1.assertIsSingleModuleInstance)('crawlPlusFiles.ts');
19
18
  let gitIsNotUsable = false;
20
- async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, crawlWithGit) {
19
+ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, crawlWithGit) {
21
20
  (0, utils_js_1.assertPosixPath)(userRootDir);
22
21
  (0, utils_js_1.assertPosixPath)(outDirAbsoluteFilesystem);
23
22
  let outDirRelativeFromUserRootDir = path_1.default.posix.relative(userRootDir, outDirAbsoluteFilesystem);
@@ -32,7 +31,6 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, craw
32
31
  (!outDirRelativeFromUserRootDir.startsWith('./') &&
33
32
  //
34
33
  !outDirRelativeFromUserRootDir.startsWith('../')));
35
- const timeBefore = new Date().getTime();
36
34
  // Crawl
37
35
  let files = [];
38
36
  const res = crawlWithGit !== false && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
@@ -48,18 +46,6 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, craw
48
46
  }
49
47
  // Filter build files
50
48
  files = files.filter((filePath) => !(0, transpileAndExecuteFile_js_1.isTemporaryBuildFile)(filePath));
51
- // Check performance
52
- {
53
- const timeAfter = new Date().getTime();
54
- const timeSpent = timeAfter - timeBefore;
55
- if (isDev) {
56
- // We only warn in dev, because while building it's expected to take a long time as crawling is competing for resources with other tasks.
57
- // Although, in dev, it's also competing for resources e.g. with Vite's `optimizeDeps`.
58
- (0, utils_js_1.assertWarning)(timeSpent < 3 * 1000, `Crawling your ${picocolors_1.default.cyan('+')} files took an unexpected long time (${(0, utils_js_1.humanizeTime)(timeSpent)}). If you consistently get this warning, then consider reaching out on GitHub.`, {
59
- onlyOnce: 'slow-crawling'
60
- });
61
- }
62
- }
63
49
  // Normalize
64
50
  const plusFiles = files.map((filePath) => {
65
51
  // Both `$ git-ls files` and fast-glob return posix paths
@@ -86,8 +86,8 @@ async function isV1Design(config, isDev) {
86
86
  const isV1Design = pageConfigs.length > 0;
87
87
  return isV1Design;
88
88
  }
89
- async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit) {
90
- const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
89
+ async function loadInterfaceFiles(userRootDir, outDirRoot, crawlWithGit) {
90
+ const plusFiles = await findPlusFiles(userRootDir, outDirRoot, crawlWithGit);
91
91
  const configFiles = [];
92
92
  const valueFiles = [];
93
93
  plusFiles.forEach((f) => {
@@ -201,7 +201,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
201
201
  let ret;
202
202
  let err;
203
203
  try {
204
- ret = await loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit);
204
+ ret = await loadVikeConfig(userRootDir, outDirRoot, crawlWithGit);
205
205
  }
206
206
  catch (err_) {
207
207
  hasError = true;
@@ -238,8 +238,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
238
238
  }
239
239
  }
240
240
  }
241
- async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
242
- const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
241
+ async function loadVikeConfig(userRootDir, outDirRoot, crawlWithGit) {
242
+ const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, crawlWithGit);
243
243
  const importedFilesLoaded = {};
244
244
  const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
245
245
  const pageConfigs = await Promise.all((0, utils_js_1.objectEntries)(interfaceFilesByLocationId)
@@ -785,8 +785,8 @@ function getComputed(configValueSources, configDefinitions) {
785
785
  });
786
786
  return configValuesComputed;
787
787
  }
788
- async function findPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit) {
789
- const files = await (0, crawlPlusFiles_js_1.crawlPlusFiles)(userRootDir, outDirRoot, isDev, crawlWithGit);
788
+ async function findPlusFiles(userRootDir, outDirRoot, crawlWithGit) {
789
+ const files = await (0, crawlPlusFiles_js_1.crawlPlusFiles)(userRootDir, outDirRoot, crawlWithGit);
790
790
  const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir }));
791
791
  return plusFiles;
792
792
  }
@@ -56,15 +56,15 @@ const getVikeConfig_js_1 = require("../plugin/plugins/importUserCode/v1-design/g
56
56
  const logErrorHint_js_1 = require("../runtime/renderPage/logErrorHint.js");
57
57
  const executeHook_js_1 = require("../../shared/hooks/executeHook.js");
58
58
  const getConfigValueBuildTime_js_1 = require("../../shared/page-configs/getConfigValueBuildTime.js");
59
- const enhanceViteConfig_js_1 = require("../api/enhanceViteConfig.js");
59
+ const prepareApiCall_js_1 = require("../api/prepareApiCall.js");
60
60
  async function runPrerenderFromAPI(options = {}) {
61
- await runPrerender(options, 'prerender()');
61
+ return await runPrerender(options, 'prerender()');
62
62
  // - We purposely propagate the error to the user land, so that the error interrupts the user land. It's also, I guess, a nice-to-have that the user has control over the error.
63
63
  // - We don't use logErrorHint() because we don't have control over what happens with the error. For example, if the user land purposely swallows the error then the hint shouldn't be logged. Also, it's best if the hint is shown to the user *after* the error, but we cannot do/guarentee that.
64
64
  }
65
65
  async function runPrerenderFromCLIPrerenderCommand() {
66
66
  try {
67
- const { viteConfigEnhanced } = await (0, enhanceViteConfig_js_1.enhanceViteConfig)(undefined, 'prerender');
67
+ const { viteConfigEnhanced } = await (0, prepareApiCall_js_1.prepareApiCall)(undefined, 'prerender');
68
68
  await runPrerender({ viteConfig: viteConfigEnhanced }, '$ vike prerender');
69
69
  }
70
70
  catch (err) {
@@ -143,6 +143,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
143
143
  console.log(`${picocolors_1.default.green(`✓`)} ${prerenderedCount} HTML documents pre-rendered.`);
144
144
  }
145
145
  warnMissingPages(prerenderedPageContexts, doNotPrerenderList, renderContext, partial);
146
+ return { viteConfig };
146
147
  }
147
148
  async function collectDoNoPrerenderList(renderContext, pageConfigs, doNotPrerenderList, concurrencyLimit) {
148
149
  // V1 design
@@ -1,39 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getConfigValueRuntime = getConfigValueRuntime;
7
- exports.getConfigValueTyped = getConfigValueTyped;
8
- const utils_js_1 = require("../utils.js");
9
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
- const getConfigDefinedAt_js_1 = require("./getConfigDefinedAt.js");
11
- function getConfigValueTyped(configValue, configName, type) {
12
- /* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
13
- // Enable users to suppress global config values by setting the local config value to null
14
- if (configValue.value === null) return null
15
- */
16
- const { value, definedAtData } = configValue;
17
- if (type)
18
- assertConfigValueType(value, type, configName, definedAtData);
19
- return configValue;
20
- }
4
+ const getConfigValueTyped_js_1 = require("./getConfigValueTyped.js");
21
5
  function getConfigValueRuntime(pageConfig, configName, type) {
22
6
  const configValue = pageConfig.configValues[configName];
23
7
  if (!configValue)
24
8
  return null;
25
- return getConfigValueTyped(configValue, configName, type);
26
- }
27
- function assertConfigValueType(value, type, configName, definedAtData) {
28
- (0, utils_js_1.assert)(value !== null);
29
- const typeActual = typeof value;
30
- if (typeActual === type)
31
- return;
32
- const valuePrintable = (0, utils_js_1.getValuePrintable)(value);
33
- const problem = valuePrintable !== null
34
- ? `value ${picocolors_1.default.cyan(valuePrintable)}`
35
- : `type ${picocolors_1.default.cyan(typeActual)}`;
36
- const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAtOptional)('Config', configName, definedAtData);
37
- const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${picocolors_1.default.cyan(type)} instead`;
38
- (0, utils_js_1.assertUsage)(false, errMsg);
9
+ return (0, getConfigValueTyped_js_1.getConfigValueTyped)(configValue, configName, type);
39
10
  }
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getConfigValueBuildTime = getConfigValueBuildTime;
4
4
  const utils_js_1 = require("../utils.js");
5
- const getConfigValue_js_1 = require("./getConfigValue.js");
6
5
  const assertIsNotProductionRuntime_js_1 = require("../../utils/assertIsNotProductionRuntime.js");
6
+ const getConfigValueTyped_js_1 = require("./getConfigValueTyped.js");
7
7
  (0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
8
8
  function getConfigValueBuildTime(pageConfig, configName, type) {
9
9
  const configValue = getConfigValue(pageConfig, configName);
10
10
  if (!configValue)
11
11
  return null;
12
- return (0, getConfigValue_js_1.getConfigValueTyped)(configValue, configName, type);
12
+ return (0, getConfigValueTyped_js_1.getConfigValueTyped)(configValue, configName, type);
13
13
  }
14
14
  function getConfigValue(pageConfig, configName) {
15
15
  const { configValueSources, configValuesComputed, configDefinitions } = pageConfig;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getConfigValueTyped = getConfigValueTyped;
7
+ const utils_js_1 = require("../utils.js");
8
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
9
+ const getConfigDefinedAt_js_1 = require("./getConfigDefinedAt.js");
10
+ function getConfigValueTyped(configValue, configName, type) {
11
+ /* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
12
+ // Enable users to suppress global config values by setting the local config value to null
13
+ if (configValue.value === null) return null
14
+ */
15
+ const { value, definedAtData } = configValue;
16
+ if (type)
17
+ assertConfigValueType(value, type, configName, definedAtData);
18
+ return configValue;
19
+ }
20
+ function assertConfigValueType(value, type, configName, definedAtData) {
21
+ (0, utils_js_1.assert)(value !== null);
22
+ const typeActual = typeof value;
23
+ if (typeActual === type)
24
+ return;
25
+ const valuePrintable = (0, utils_js_1.getValuePrintable)(value);
26
+ const problem = valuePrintable !== null
27
+ ? `value ${picocolors_1.default.cyan(valuePrintable)}`
28
+ : `type ${picocolors_1.default.cyan(typeActual)}`;
29
+ const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAtOptional)('Config', configName, definedAtData);
30
+ const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${picocolors_1.default.cyan(type)} instead`;
31
+ (0, utils_js_1.assertUsage)(false, errMsg);
32
+ }
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.214';
5
+ exports.PROJECT_VERSION = '0.4.215';
@@ -1,6 +1,8 @@
1
1
  export { build };
2
- import type { APIOptions } from './APIOptions.js';
2
+ import { type Rollup } from 'vite';
3
+ import type { APIOptions } from './types.js';
4
+ type RollupOutput = Rollup.RollupOutput | Rollup.RollupOutput[] | Rollup.RollupWatcher;
3
5
  declare function build(options?: APIOptions): Promise<{
4
- outputClient: import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher;
5
- outputServer: import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher;
6
+ rollupOutputClient: RollupOutput;
7
+ rollupOutputServer: RollupOutput;
6
8
  }>;
@@ -1,8 +1,8 @@
1
1
  export { build };
2
- import { enhanceViteConfig } from './enhanceViteConfig.js';
2
+ import { prepareApiCall } from './prepareApiCall.js';
3
3
  import { build as buildVite } from 'vite';
4
4
  async function build(options = {}) {
5
- const { viteConfigEnhanced, configVike } = await enhanceViteConfig(options.viteConfig, 'build');
5
+ const { viteConfigEnhanced, configVike } = await prepareApiCall(options.viteConfig, 'build');
6
6
  // Build client-side
7
7
  const outputClient = await buildVite(viteConfigEnhanced);
8
8
  // Build server-side
@@ -12,7 +12,13 @@ async function build(options = {}) {
12
12
  const { runPrerenderFromAutoRun } = await import('../prerender/runPrerender.js');
13
13
  await runPrerenderFromAutoRun(viteConfigEnhanced, true);
14
14
  }
15
- return { outputClient, outputServer };
15
+ return {
16
+ /* We don't return `viteConfig` because `viteConfigEnhanced` is `InlineConfig` not `ResolvedConfig`
17
+ viteConfig: viteConfigEnhanced,
18
+ */
19
+ rollupOutputClient: outputClient,
20
+ rollupOutputServer: outputServer
21
+ };
16
22
  }
17
23
  function setSSR(viteConfig) {
18
24
  return {
@@ -0,0 +1,5 @@
1
+ export { isVikeCliOrApi };
2
+ export { setOperation as setOperation };
3
+ import type { Operation } from './types.js';
4
+ declare function isVikeCliOrApi(): boolean;
5
+ declare function setOperation(operation: Operation): void;
@@ -0,0 +1,17 @@
1
+ export { isVikeCliOrApi };
2
+ // export { getOperation }
3
+ export { setOperation as setOperation };
4
+ import { assert } from './utils.js';
5
+ let apiOperation;
6
+ function getOperation() {
7
+ assert(apiOperation);
8
+ return apiOperation;
9
+ }
10
+ function isVikeCliOrApi() {
11
+ // The CLI uses the API
12
+ return !!apiOperation;
13
+ }
14
+ function setOperation(operation) {
15
+ assert(!apiOperation);
16
+ apiOperation = operation;
17
+ }
@@ -1,3 +1,7 @@
1
1
  export { dev };
2
- import type { APIOptions } from './APIOptions.js';
3
- declare function dev(options?: APIOptions): Promise<import("vite").ViteDevServer>;
2
+ import { type ResolvedConfig, type ViteDevServer } from 'vite';
3
+ import type { APIOptions } from './types.js';
4
+ declare function dev(options?: APIOptions): Promise<{
5
+ viteServer: ViteDevServer;
6
+ viteConfig: ResolvedConfig;
7
+ }>;
@@ -1,8 +1,11 @@
1
1
  export { dev };
2
- import { enhanceViteConfig } from './enhanceViteConfig.js';
2
+ import { prepareApiCall } from './prepareApiCall.js';
3
3
  import { createServer } from 'vite';
4
4
  async function dev(options = {}) {
5
- const { viteConfigEnhanced } = await enhanceViteConfig(options.viteConfig, 'dev');
5
+ const { viteConfigEnhanced } = await prepareApiCall(options.viteConfig, 'dev');
6
6
  const server = await createServer(viteConfigEnhanced);
7
- return server;
7
+ return {
8
+ viteServer: server,
9
+ viteConfig: server.config
10
+ };
8
11
  }
@@ -0,0 +1,2 @@
1
+ export { onLoad };
2
+ declare function onLoad(): void;
@@ -0,0 +1,7 @@
1
+ export { onLoad };
2
+ import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
3
+ import { assertIsNotProductionRuntime } from '../runtime/utils.js';
4
+ function onLoad() {
5
+ assertIsNotBrowser();
6
+ assertIsNotProductionRuntime();
7
+ }
@@ -0,0 +1,7 @@
1
+ export { prepareApiCall };
2
+ import type { InlineConfig } from 'vite';
3
+ import type { Operation } from './types.js';
4
+ declare function prepareApiCall(viteConfig: InlineConfig | undefined, operation: Operation): Promise<{
5
+ viteConfigEnhanced: InlineConfig;
6
+ configVike: import("../../shared/ConfigVike.js").ConfigVikeResolved;
7
+ }>;
@@ -1,9 +1,14 @@
1
- export { enhanceViteConfig };
1
+ export { prepareApiCall };
2
2
  import { resolveConfig } from 'vite';
3
3
  import { getConfigVike } from '../shared/getConfigVike.js';
4
4
  import { pluginName } from '../plugin/plugins/commonConfig/pluginName.js';
5
- async function enhanceViteConfig(viteConfig = {}, command) {
6
- let viteConfigResolved = await resolveViteConfig(viteConfig, command);
5
+ import { setOperation } from './context.js';
6
+ async function prepareApiCall(viteConfig = {}, operation) {
7
+ setOperation(operation);
8
+ return enhanceViteConfig(viteConfig, operation);
9
+ }
10
+ async function enhanceViteConfig(viteConfig = {}, operation) {
11
+ let viteConfigResolved = await resolveViteConfig(viteConfig, operation);
7
12
  let viteConfigEnhanced = viteConfig;
8
13
  // Add vike to plugins if not present
9
14
  if (!viteConfigResolved.plugins.some((p) => p.name === pluginName)) {
@@ -13,7 +18,7 @@ async function enhanceViteConfig(viteConfig = {}, command) {
13
18
  ...viteConfig,
14
19
  plugins: [...(viteConfig.plugins ?? []), vikePlugin()]
15
20
  };
16
- viteConfigResolved = await resolveViteConfig(viteConfigEnhanced, command);
21
+ viteConfigResolved = await resolveViteConfig(viteConfigEnhanced, operation);
17
22
  }
18
23
  const configVike = await getConfigVike(viteConfigResolved);
19
24
  // TODO: enable Vike extensions to add Vite plugins
@@ -22,6 +27,6 @@ async function enhanceViteConfig(viteConfig = {}, command) {
22
27
  configVike
23
28
  };
24
29
  }
25
- async function resolveViteConfig(viteConfig, command) {
26
- return await resolveConfig(viteConfig, command === 'build' || command === 'prerender' ? 'build' : 'serve', 'custom', command === 'dev' ? 'development' : 'production', command === 'preview');
30
+ async function resolveViteConfig(viteConfig, operation) {
31
+ return await resolveConfig(viteConfig, operation === 'build' || operation === 'prerender' ? 'build' : 'serve', 'custom', operation === 'dev' ? 'development' : 'production', operation === 'preview');
27
32
  }
@@ -1,3 +1,6 @@
1
1
  export { prerender };
2
2
  import { type PrerenderOptions } from '../prerender/runPrerender.js';
3
- declare function prerender(options?: PrerenderOptions): Promise<void>;
3
+ import type { ResolvedConfig } from 'vite';
4
+ declare function prerender(options?: PrerenderOptions): Promise<{
5
+ viteConfig: ResolvedConfig;
6
+ }>;
@@ -1,8 +1,11 @@
1
1
  export { prerender };
2
2
  import { runPrerenderFromAPI } from '../prerender/runPrerender.js';
3
- import { enhanceViteConfig } from './enhanceViteConfig.js';
3
+ import { prepareApiCall } from './prepareApiCall.js';
4
4
  async function prerender(options = {}) {
5
- const { viteConfigEnhanced } = await enhanceViteConfig(options.viteConfig, 'prerender');
5
+ const { viteConfigEnhanced } = await prepareApiCall(options.viteConfig, 'prerender');
6
6
  options.viteConfig = viteConfigEnhanced;
7
- await runPrerenderFromAPI(options);
7
+ const { viteConfig } = await runPrerenderFromAPI(options);
8
+ return {
9
+ viteConfig
10
+ };
8
11
  }
@@ -1,3 +1,7 @@
1
1
  export { preview };
2
- import type { APIOptions } from './APIOptions.js';
3
- declare function preview(options?: APIOptions): Promise<import("vite").PreviewServer>;
2
+ import { type ResolvedConfig, type PreviewServer } from 'vite';
3
+ import type { APIOptions } from './types.js';
4
+ declare function preview(options?: APIOptions): Promise<{
5
+ viteServer: PreviewServer;
6
+ viteConfig: ResolvedConfig;
7
+ }>;
@@ -1,8 +1,11 @@
1
1
  export { preview };
2
- import { enhanceViteConfig } from './enhanceViteConfig.js';
2
+ import { prepareApiCall } from './prepareApiCall.js';
3
3
  import { preview as previewVite } from 'vite';
4
4
  async function preview(options = {}) {
5
- const { viteConfigEnhanced } = await enhanceViteConfig(options.viteConfig, 'preview');
5
+ const { viteConfigEnhanced } = await prepareApiCall(options.viteConfig, 'preview');
6
6
  const server = await previewVite(viteConfigEnhanced);
7
- return server;
7
+ return {
8
+ viteServer: server,
9
+ viteConfig: server.config
10
+ };
8
11
  }
@@ -1,4 +1,5 @@
1
- export { APIOptions };
1
+ export type { APIOptions };
2
+ export type { Operation };
2
3
  import type { InlineConfig } from 'vite';
3
4
  type APIOptions = {
4
5
  /**
@@ -8,3 +9,4 @@ type APIOptions = {
8
9
  */
9
10
  viteConfig?: InlineConfig;
10
11
  };
12
+ type Operation = 'build' | 'dev' | 'preview' | 'prerender';
@@ -0,0 +1 @@
1
+ export * from '../../utils/assert.js';
@@ -0,0 +1,5 @@
1
+ // Utils needed by Vike's API
2
+ // We call onLoad() here so that it's called even when only a subset of the API is loaded. (Making the assert() calls inside onLoad() a lot stronger.)
3
+ import { onLoad } from './onLoad.js';
4
+ onLoad();
5
+ export * from '../../utils/assert.js';
@@ -21,16 +21,16 @@ async function cli() {
21
21
  async function cmdDev() {
22
22
  const startTime = performance.now();
23
23
  try {
24
- const server = await dev();
25
- await server.listen();
26
- const info = server.config.logger.info;
24
+ const { viteServer } = await dev();
25
+ await viteServer.listen();
26
+ const info = viteServer.config.logger.info;
27
27
  const startupDurationString = pc.dim(`ready in ${pc.reset(pc.bold(String(Math.ceil(performance.now() - startTime))))} ms`);
28
28
  const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
29
29
  info(` ${pc.yellow(`${pc.bold(projectInfo.projectName)} v${projectInfo.projectVersion}`)} ${startupDurationString}\n`, {
30
30
  clear: !hasExistingLogs
31
31
  });
32
- server.printUrls();
33
- server.bindCLIShortcuts({ print: true });
32
+ viteServer.printUrls();
33
+ viteServer.bindCLIShortcuts({ print: true });
34
34
  }
35
35
  catch (err) {
36
36
  console.error(pc.red(`Error while starting dev server:`));
@@ -52,9 +52,9 @@ async function cmdBuild() {
52
52
  }
53
53
  async function cmdPreview() {
54
54
  try {
55
- const server = await preview();
56
- server.printUrls();
57
- server.bindCLIShortcuts({ print: true });
55
+ const { viteServer } = await preview();
56
+ viteServer.printUrls();
57
+ viteServer.bindCLIShortcuts({ print: true });
58
58
  }
59
59
  catch (err) {
60
60
  console.error(pc.red(`Error while starting preview server:`));
@@ -1,5 +1,7 @@
1
1
  export { onLoad };
2
2
  import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
3
+ import { assertIsNotProductionRuntime } from '../runtime/utils.js';
3
4
  function onLoad() {
4
5
  assertIsNotBrowser();
6
+ assertIsNotProductionRuntime();
5
7
  }
@@ -9,9 +9,6 @@ import pc from '@brillout/picocolors';
9
9
  import { logErrorHint } from '../../runtime/renderPage/logErrorHint.js';
10
10
  import { manifestTempFile } from './buildConfig.js';
11
11
  let forceExit = false;
12
- assertWarning(!isViteCliCall(), `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
13
- onlyOnce: true
14
- });
15
12
  function autoFullBuild() {
16
13
  let config;
17
14
  let configVike;
@@ -1 +1 @@
1
- export declare const pluginName = "vike:commonConfig-1";
1
+ export declare const pluginName = "vike:commonConfig";
@@ -1 +1 @@
1
- export const pluginName = 'vike:commonConfig-1';
1
+ export const pluginName = 'vike:commonConfig';
@@ -8,6 +8,10 @@ import path from 'path';
8
8
  import { assertResolveAlias } from './commonConfig/assertResolveAlias.js';
9
9
  import { pluginName } from './commonConfig/pluginName.js';
10
10
  import { getEnvVarObject } from '../shared/getEnvVarObject.js';
11
+ import { isViteCliCall } from '../shared/isViteCliCall.js';
12
+ assertWarning(!isViteCliCall(), `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
13
+ onlyOnce: true
14
+ });
11
15
  function commonConfig() {
12
16
  return [
13
17
  {
@@ -18,7 +22,7 @@ function commonConfig() {
18
22
  }
19
23
  },
20
24
  {
21
- name: 'vike:commonConfig-2',
25
+ name: `${pluginName}:post`,
22
26
  enforce: 'post',
23
27
  configResolved: {
24
28
  order: 'post',
@@ -1,4 +1,4 @@
1
1
  export { crawlPlusFiles };
2
- declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: string, isDev: boolean, crawlWithGit: null | boolean): Promise<{
2
+ declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: string, crawlWithGit: null | boolean): Promise<{
3
3
  filePathAbsoluteUserRootDir: string;
4
4
  }[]>;
@@ -1,18 +1,17 @@
1
1
  export { crawlPlusFiles };
2
- import { assertPosixPath, assert, assertWarning, scriptFileExtensions, humanizeTime, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile } from '../../../../utils.js';
2
+ import { assertPosixPath, assert, scriptFileExtensions, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile } from '../../../../utils.js';
3
3
  import path from 'path';
4
4
  import fs from 'fs/promises';
5
5
  import glob from 'fast-glob';
6
6
  import { exec } from 'child_process';
7
7
  import { promisify } from 'util';
8
- import pc from '@brillout/picocolors';
9
8
  import { isTemporaryBuildFile } from './transpileAndExecuteFile.js';
10
9
  const execA = promisify(exec);
11
10
  const TOO_MANY_UNTRACKED_FILES = 5;
12
11
  assertIsNotProductionRuntime();
13
12
  assertIsSingleModuleInstance('crawlPlusFiles.ts');
14
13
  let gitIsNotUsable = false;
15
- async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, crawlWithGit) {
14
+ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, crawlWithGit) {
16
15
  assertPosixPath(userRootDir);
17
16
  assertPosixPath(outDirAbsoluteFilesystem);
18
17
  let outDirRelativeFromUserRootDir = path.posix.relative(userRootDir, outDirAbsoluteFilesystem);
@@ -27,7 +26,6 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, craw
27
26
  (!outDirRelativeFromUserRootDir.startsWith('./') &&
28
27
  //
29
28
  !outDirRelativeFromUserRootDir.startsWith('../')));
30
- const timeBefore = new Date().getTime();
31
29
  // Crawl
32
30
  let files = [];
33
31
  const res = crawlWithGit !== false && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
@@ -43,18 +41,6 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, craw
43
41
  }
44
42
  // Filter build files
45
43
  files = files.filter((filePath) => !isTemporaryBuildFile(filePath));
46
- // Check performance
47
- {
48
- const timeAfter = new Date().getTime();
49
- const timeSpent = timeAfter - timeBefore;
50
- if (isDev) {
51
- // We only warn in dev, because while building it's expected to take a long time as crawling is competing for resources with other tasks.
52
- // Although, in dev, it's also competing for resources e.g. with Vite's `optimizeDeps`.
53
- assertWarning(timeSpent < 3 * 1000, `Crawling your ${pc.cyan('+')} files took an unexpected long time (${humanizeTime(timeSpent)}). If you consistently get this warning, then consider reaching out on GitHub.`, {
54
- onlyOnce: 'slow-crawling'
55
- });
56
- }
57
- }
58
44
  // Normalize
59
45
  const plusFiles = files.map((filePath) => {
60
46
  // Both `$ git-ls files` and fast-glob return posix paths
@@ -80,8 +80,8 @@ async function isV1Design(config, isDev) {
80
80
  const isV1Design = pageConfigs.length > 0;
81
81
  return isV1Design;
82
82
  }
83
- async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit) {
84
- const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
83
+ async function loadInterfaceFiles(userRootDir, outDirRoot, crawlWithGit) {
84
+ const plusFiles = await findPlusFiles(userRootDir, outDirRoot, crawlWithGit);
85
85
  const configFiles = [];
86
86
  const valueFiles = [];
87
87
  plusFiles.forEach((f) => {
@@ -195,7 +195,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
195
195
  let ret;
196
196
  let err;
197
197
  try {
198
- ret = await loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit);
198
+ ret = await loadVikeConfig(userRootDir, outDirRoot, crawlWithGit);
199
199
  }
200
200
  catch (err_) {
201
201
  hasError = true;
@@ -232,8 +232,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
232
232
  }
233
233
  }
234
234
  }
235
- async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
236
- const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
235
+ async function loadVikeConfig(userRootDir, outDirRoot, crawlWithGit) {
236
+ const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, crawlWithGit);
237
237
  const importedFilesLoaded = {};
238
238
  const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
239
239
  const pageConfigs = await Promise.all(objectEntries(interfaceFilesByLocationId)
@@ -779,8 +779,8 @@ function getComputed(configValueSources, configDefinitions) {
779
779
  });
780
780
  return configValuesComputed;
781
781
  }
782
- async function findPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit) {
783
- const files = await crawlPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
782
+ async function findPlusFiles(userRootDir, outDirRoot, crawlWithGit) {
783
+ const files = await crawlPlusFiles(userRootDir, outDirRoot, crawlWithGit);
784
784
  const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir }));
785
785
  return plusFiles;
786
786
  }
@@ -4,8 +4,8 @@ export { runPrerenderFromAutoRun };
4
4
  export { runPrerender_forceExit };
5
5
  export type { PrerenderOptions };
6
6
  import '../runtime/page-files/setup.js';
7
- import type { InlineConfig } from 'vite';
8
- import type { APIOptions } from '../api/APIOptions.js';
7
+ import type { InlineConfig, ResolvedConfig } from 'vite';
8
+ import type { APIOptions } from '../api/types.js';
9
9
  type PrerenderOptions = APIOptions & {
10
10
  /** Initial `pageContext` values */
11
11
  pageContextInit?: Record<string, unknown>;
@@ -26,7 +26,9 @@ type PrerenderOptions = APIOptions & {
26
26
  /** @deprecated */
27
27
  base?: string;
28
28
  };
29
- declare function runPrerenderFromAPI(options?: PrerenderOptions): Promise<void>;
29
+ declare function runPrerenderFromAPI(options?: PrerenderOptions): Promise<{
30
+ viteConfig: ResolvedConfig;
31
+ }>;
30
32
  declare function runPrerenderFromCLIPrerenderCommand(): Promise<void>;
31
33
  declare function runPrerenderFromAutoRun(viteConfig: InlineConfig, forceExit: boolean): Promise<void>;
32
34
  declare function runPrerender_forceExit(): void;
@@ -28,15 +28,15 @@ import { getVikeConfig } from '../plugin/plugins/importUserCode/v1-design/getVik
28
28
  import { logErrorHint } from '../runtime/renderPage/logErrorHint.js';
29
29
  import { executeHook, isUserHookError } from '../../shared/hooks/executeHook.js';
30
30
  import { getConfigValueBuildTime } from '../../shared/page-configs/getConfigValueBuildTime.js';
31
- import { enhanceViteConfig } from '../api/enhanceViteConfig.js';
31
+ import { prepareApiCall } from '../api/prepareApiCall.js';
32
32
  async function runPrerenderFromAPI(options = {}) {
33
- await runPrerender(options, 'prerender()');
33
+ return await runPrerender(options, 'prerender()');
34
34
  // - We purposely propagate the error to the user land, so that the error interrupts the user land. It's also, I guess, a nice-to-have that the user has control over the error.
35
35
  // - We don't use logErrorHint() because we don't have control over what happens with the error. For example, if the user land purposely swallows the error then the hint shouldn't be logged. Also, it's best if the hint is shown to the user *after* the error, but we cannot do/guarentee that.
36
36
  }
37
37
  async function runPrerenderFromCLIPrerenderCommand() {
38
38
  try {
39
- const { viteConfigEnhanced } = await enhanceViteConfig(undefined, 'prerender');
39
+ const { viteConfigEnhanced } = await prepareApiCall(undefined, 'prerender');
40
40
  await runPrerender({ viteConfig: viteConfigEnhanced }, '$ vike prerender');
41
41
  }
42
42
  catch (err) {
@@ -115,6 +115,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
115
115
  console.log(`${pc.green(`✓`)} ${prerenderedCount} HTML documents pre-rendered.`);
116
116
  }
117
117
  warnMissingPages(prerenderedPageContexts, doNotPrerenderList, renderContext, partial);
118
+ return { viteConfig };
118
119
  }
119
120
  async function collectDoNoPrerenderList(renderContext, pageConfigs, doNotPrerenderList, concurrencyLimit) {
120
121
  // V1 design
@@ -1,14 +1,8 @@
1
1
  export { getConfigValueRuntime };
2
- export { getConfigValueTyped };
3
- export type { TypeAsString };
4
2
  import { type ResolveTypeAsString } from '../utils.js';
5
3
  import type { PageConfigRuntime, ConfigValue } from './PageConfig.js';
6
4
  import type { ConfigNameBuiltIn } from './Config.js';
7
- type ConfigName = ConfigNameBuiltIn;
8
- type TypeAsString = 'string' | 'boolean' | undefined;
9
- declare function getConfigValueTyped<Type extends TypeAsString = undefined>(configValue: ConfigValue, configName: ConfigName, type?: Type): null | (ConfigValue & {
10
- value: ResolveTypeAsString<Type>;
11
- });
12
- declare function getConfigValueRuntime<Type extends TypeAsString = undefined>(pageConfig: PageConfigRuntime, configName: ConfigName, type?: Type): null | (ConfigValue & {
5
+ import { type TypeAsString } from './getConfigValueTyped.js';
6
+ declare function getConfigValueRuntime<Type extends TypeAsString = undefined>(pageConfig: PageConfigRuntime, configName: ConfigNameBuiltIn, type?: Type): null | (ConfigValue & {
13
7
  value: ResolveTypeAsString<Type>;
14
8
  });
@@ -1,34 +1,8 @@
1
1
  export { getConfigValueRuntime };
2
- export { getConfigValueTyped };
3
- import { assert, assertUsage, getValuePrintable } from '../utils.js';
4
- import pc from '@brillout/picocolors';
5
- import { getConfigDefinedAtOptional } from './getConfigDefinedAt.js';
6
- function getConfigValueTyped(configValue, configName, type) {
7
- /* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
8
- // Enable users to suppress global config values by setting the local config value to null
9
- if (configValue.value === null) return null
10
- */
11
- const { value, definedAtData } = configValue;
12
- if (type)
13
- assertConfigValueType(value, type, configName, definedAtData);
14
- return configValue;
15
- }
2
+ import { getConfigValueTyped } from './getConfigValueTyped.js';
16
3
  function getConfigValueRuntime(pageConfig, configName, type) {
17
4
  const configValue = pageConfig.configValues[configName];
18
5
  if (!configValue)
19
6
  return null;
20
7
  return getConfigValueTyped(configValue, configName, type);
21
8
  }
22
- function assertConfigValueType(value, type, configName, definedAtData) {
23
- assert(value !== null);
24
- const typeActual = typeof value;
25
- if (typeActual === type)
26
- return;
27
- const valuePrintable = getValuePrintable(value);
28
- const problem = valuePrintable !== null
29
- ? `value ${pc.cyan(valuePrintable)}`
30
- : `type ${pc.cyan(typeActual)}`;
31
- const configDefinedAt = getConfigDefinedAtOptional('Config', configName, definedAtData);
32
- const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`;
33
- assertUsage(false, errMsg);
34
- }
@@ -2,8 +2,7 @@ export { getConfigValueBuildTime };
2
2
  import { type ResolveTypeAsString } from '../utils.js';
3
3
  import type { PageConfigBuildTime, ConfigValue } from './PageConfig.js';
4
4
  import type { ConfigNameBuiltIn } from './Config.js';
5
- import { type TypeAsString } from './getConfigValue.js';
6
- type ConfigName = ConfigNameBuiltIn;
7
- declare function getConfigValueBuildTime<Type extends TypeAsString = undefined>(pageConfig: PageConfigBuildTime, configName: ConfigName, type?: Type): null | (ConfigValue & {
5
+ import { type TypeAsString } from './getConfigValueTyped.js';
6
+ declare function getConfigValueBuildTime<Type extends TypeAsString = undefined>(pageConfig: PageConfigBuildTime, configName: ConfigNameBuiltIn, type?: Type): null | (ConfigValue & {
8
7
  value: ResolveTypeAsString<Type>;
9
8
  });
@@ -1,7 +1,7 @@
1
1
  export { getConfigValueBuildTime };
2
2
  import { assert } from '../utils.js';
3
- import { getConfigValueTyped } from './getConfigValue.js';
4
3
  import { assertIsNotProductionRuntime } from '../../utils/assertIsNotProductionRuntime.js';
4
+ import { getConfigValueTyped } from './getConfigValueTyped.js';
5
5
  assertIsNotProductionRuntime();
6
6
  function getConfigValueBuildTime(pageConfig, configName, type) {
7
7
  const configValue = getConfigValue(pageConfig, configName);
@@ -0,0 +1,9 @@
1
+ export { getConfigValueTyped };
2
+ export type { TypeAsString };
3
+ import { type ResolveTypeAsString } from '../utils.js';
4
+ import type { ConfigValue } from './PageConfig.js';
5
+ import type { ConfigNameBuiltIn } from './Config.js';
6
+ type TypeAsString = 'string' | 'boolean' | undefined;
7
+ declare function getConfigValueTyped<Type extends TypeAsString = undefined>(configValue: ConfigValue, configName: ConfigNameBuiltIn, type?: Type): null | (ConfigValue & {
8
+ value: ResolveTypeAsString<Type>;
9
+ });
@@ -0,0 +1,27 @@
1
+ export { getConfigValueTyped };
2
+ import { assert, assertUsage, getValuePrintable } from '../utils.js';
3
+ import pc from '@brillout/picocolors';
4
+ import { getConfigDefinedAtOptional } from './getConfigDefinedAt.js';
5
+ function getConfigValueTyped(configValue, configName, type) {
6
+ /* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
7
+ // Enable users to suppress global config values by setting the local config value to null
8
+ if (configValue.value === null) return null
9
+ */
10
+ const { value, definedAtData } = configValue;
11
+ if (type)
12
+ assertConfigValueType(value, type, configName, definedAtData);
13
+ return configValue;
14
+ }
15
+ function assertConfigValueType(value, type, configName, definedAtData) {
16
+ assert(value !== null);
17
+ const typeActual = typeof value;
18
+ if (typeActual === type)
19
+ return;
20
+ const valuePrintable = getValuePrintable(value);
21
+ const problem = valuePrintable !== null
22
+ ? `value ${pc.cyan(valuePrintable)}`
23
+ : `type ${pc.cyan(typeActual)}`;
24
+ const configDefinedAt = getConfigDefinedAtOptional('Config', configName, definedAtData);
25
+ const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`;
26
+ assertUsage(false, errMsg);
27
+ }
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.214";
1
+ export declare const PROJECT_VERSION: "0.4.215";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.214';
2
+ export const PROJECT_VERSION = '0.4.215';
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.214";
3
+ projectVersion: "0.4.215";
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.214",
3
+ "version": "0.4.215",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -1,6 +0,0 @@
1
- export { enhanceViteConfig };
2
- import type { InlineConfig } from 'vite';
3
- declare function enhanceViteConfig(viteConfig: InlineConfig | undefined, command: 'build' | 'dev' | 'preview' | 'prerender'): Promise<{
4
- viteConfigEnhanced: InlineConfig;
5
- configVike: import("../../shared/ConfigVike.js").ConfigVikeResolved;
6
- }>;
File without changes
File without changes