vike 0.4.214 → 0.4.216

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 (112) hide show
  1. package/dist/cjs/__internal/index.js +2 -2
  2. package/dist/cjs/node/api/build.js +14 -3
  3. package/dist/cjs/node/api/context.js +20 -0
  4. package/dist/cjs/node/api/dev.js +11 -3
  5. package/dist/cjs/node/api/onLoad.js +9 -0
  6. package/dist/cjs/node/api/{enhanceViteConfig.js → prepareViteApiCall.js} +11 -6
  7. package/dist/cjs/node/api/prerender.js +11 -3
  8. package/dist/cjs/node/api/preview.js +11 -3
  9. package/dist/cjs/node/api/utils.js +22 -0
  10. package/dist/cjs/node/cli/entry.js +8 -8
  11. package/dist/cjs/node/cli/onLoad.js +2 -0
  12. package/dist/cjs/node/plugin/index.js +2 -3
  13. package/dist/cjs/node/plugin/onLoad.js +2 -2
  14. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +0 -3
  15. package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -5
  16. package/dist/cjs/node/plugin/plugins/commonConfig/pluginName.js +1 -1
  17. package/dist/cjs/node/plugin/plugins/commonConfig.js +23 -1
  18. package/dist/cjs/node/plugin/plugins/devConfig/index.js +0 -3
  19. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +9 -19
  20. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -7
  21. package/dist/cjs/node/plugin/plugins/previewConfig.js +0 -1
  22. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +32 -17
  23. package/dist/cjs/node/prerender/runPrerender.js +5 -4
  24. package/dist/cjs/node/prerender/utils.js +1 -1
  25. package/dist/cjs/node/runtime/globalContext.js +6 -6
  26. package/dist/cjs/node/runtime/index-common.js +3 -1
  27. package/dist/cjs/node/runtime/renderPage.js +4 -2
  28. package/dist/cjs/node/runtime/utils.js +1 -2
  29. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +25 -0
  30. package/dist/cjs/node/runtime-dev/index.js +32 -0
  31. package/dist/cjs/shared/page-configs/getConfigValue.js +2 -31
  32. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +4 -4
  33. package/dist/cjs/shared/page-configs/getConfigValueTyped.js +32 -0
  34. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +2 -2
  35. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  36. package/dist/cjs/utils/assertSetup.js +135 -0
  37. package/dist/cjs/utils/isDocker.js +2 -2
  38. package/dist/cjs/utils/requireResolve.js +2 -2
  39. package/dist/esm/__internal/index.js +2 -2
  40. package/dist/esm/node/api/build.d.ts +10 -3
  41. package/dist/esm/node/api/build.js +14 -3
  42. package/dist/esm/node/api/context.d.ts +5 -0
  43. package/dist/esm/node/api/context.js +19 -0
  44. package/dist/esm/node/api/dev.d.ts +11 -2
  45. package/dist/esm/node/api/dev.js +11 -3
  46. package/dist/esm/node/api/onLoad.d.ts +2 -0
  47. package/dist/esm/node/api/onLoad.js +7 -0
  48. package/dist/esm/node/api/prepareViteApiCall.d.ts +7 -0
  49. package/dist/esm/node/api/{enhanceViteConfig.js → prepareViteApiCall.js} +11 -6
  50. package/dist/esm/node/api/prerender.d.ts +9 -1
  51. package/dist/esm/node/api/prerender.js +11 -3
  52. package/dist/esm/node/api/preview.d.ts +11 -2
  53. package/dist/esm/node/api/preview.js +11 -3
  54. package/dist/esm/node/api/{APIOptions.d.ts → types.d.ts} +3 -1
  55. package/dist/esm/node/api/utils.d.ts +2 -0
  56. package/dist/esm/node/api/utils.js +6 -0
  57. package/dist/esm/node/cli/entry.js +8 -8
  58. package/dist/esm/node/cli/onLoad.js +2 -0
  59. package/dist/esm/node/cli/parseCli.d.ts +1 -1
  60. package/dist/esm/node/plugin/index.js +3 -4
  61. package/dist/esm/node/plugin/onLoad.js +1 -1
  62. package/dist/esm/node/plugin/plugins/autoFullBuild.js +0 -3
  63. package/dist/esm/node/plugin/plugins/buildConfig.js +7 -6
  64. package/dist/esm/node/plugin/plugins/commonConfig/pluginName.d.ts +1 -1
  65. package/dist/esm/node/plugin/plugins/commonConfig/pluginName.js +1 -1
  66. package/dist/esm/node/plugin/plugins/commonConfig.js +23 -1
  67. package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -4
  68. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  69. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +10 -20
  70. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -7
  71. package/dist/esm/node/plugin/plugins/previewConfig.js +1 -2
  72. package/dist/esm/node/plugin/plugins/setGlobalContext.d.ts +1 -1
  73. package/dist/esm/node/plugin/plugins/setGlobalContext.js +34 -19
  74. package/dist/esm/node/prerender/runPrerender.d.ts +5 -3
  75. package/dist/esm/node/prerender/runPrerender.js +6 -5
  76. package/dist/esm/node/prerender/utils.d.ts +1 -1
  77. package/dist/esm/node/prerender/utils.js +1 -1
  78. package/dist/esm/node/runtime/globalContext.d.ts +2 -2
  79. package/dist/esm/node/runtime/globalContext.js +7 -7
  80. package/dist/esm/node/runtime/index-common.d.ts +1 -0
  81. package/dist/esm/node/runtime/index-common.js +1 -0
  82. package/dist/esm/node/runtime/renderPage.js +5 -3
  83. package/dist/esm/node/runtime/utils.d.ts +1 -2
  84. package/dist/esm/node/runtime/utils.js +1 -2
  85. package/dist/esm/node/runtime-dev/createDevMiddleware.d.ts +10 -0
  86. package/dist/esm/node/runtime-dev/createDevMiddleware.js +23 -0
  87. package/dist/esm/node/runtime-dev/index.d.ts +3 -0
  88. package/dist/esm/node/runtime-dev/index.js +6 -0
  89. package/dist/esm/shared/page-configs/getConfigValue.d.ts +2 -8
  90. package/dist/esm/shared/page-configs/getConfigValue.js +1 -27
  91. package/dist/esm/shared/page-configs/getConfigValueBuildTime.d.ts +2 -3
  92. package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +2 -2
  93. package/dist/esm/shared/page-configs/getConfigValueTyped.d.ts +9 -0
  94. package/dist/esm/shared/page-configs/getConfigValueTyped.js +27 -0
  95. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
  96. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  97. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  98. package/dist/esm/utils/assertSetup.d.ts +20 -0
  99. package/dist/esm/utils/assertSetup.js +130 -0
  100. package/dist/esm/utils/isDocker.js +1 -1
  101. package/dist/esm/utils/projectInfo.d.ts +1 -1
  102. package/dist/esm/utils/requireResolve.js +1 -1
  103. package/package.json +1 -1
  104. package/dist/cjs/utils/assertIsNotProductionRuntime.js +0 -62
  105. package/dist/cjs/utils/assertNodeEnv.js +0 -106
  106. package/dist/esm/node/api/enhanceViteConfig.d.ts +0 -6
  107. package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +0 -12
  108. package/dist/esm/utils/assertIsNotProductionRuntime.js +0 -59
  109. package/dist/esm/utils/assertNodeEnv.d.ts +0 -10
  110. package/dist/esm/utils/assertNodeEnv.js +0 -103
  111. /package/dist/cjs/node/api/{APIOptions.js → types.js} +0 -0
  112. /package/dist/esm/node/api/{APIOptions.js → types.js} +0 -0
@@ -1,3 +1,11 @@
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
+ /**
5
+ * Programmatically trigger `$ vike prerender`
6
+ *
7
+ * https://vike.dev/api#prerender
8
+ */
9
+ declare function prerender(options?: PrerenderOptions): Promise<{
10
+ viteConfig: ResolvedConfig;
11
+ }>;
@@ -1,8 +1,16 @@
1
1
  export { prerender };
2
2
  import { runPrerenderFromAPI } from '../prerender/runPrerender.js';
3
- import { enhanceViteConfig } from './enhanceViteConfig.js';
3
+ import { prepareViteApiCall } from './prepareViteApiCall.js';
4
+ /**
5
+ * Programmatically trigger `$ vike prerender`
6
+ *
7
+ * https://vike.dev/api#prerender
8
+ */
4
9
  async function prerender(options = {}) {
5
- const { viteConfigEnhanced } = await enhanceViteConfig(options.viteConfig, 'prerender');
10
+ const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'prerender');
6
11
  options.viteConfig = viteConfigEnhanced;
7
- await runPrerenderFromAPI(options);
12
+ const { viteConfig } = await runPrerenderFromAPI(options);
13
+ return {
14
+ viteConfig
15
+ };
8
16
  }
@@ -1,3 +1,12 @@
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
+ /**
5
+ * Programmatically trigger `$ vike preview`
6
+ *
7
+ * https://vike.dev/api#preview
8
+ */
9
+ declare function preview(options?: APIOptions): Promise<{
10
+ viteServer: PreviewServer;
11
+ viteConfig: ResolvedConfig;
12
+ }>;
@@ -1,8 +1,16 @@
1
1
  export { preview };
2
- import { enhanceViteConfig } from './enhanceViteConfig.js';
2
+ import { prepareViteApiCall } from './prepareViteApiCall.js';
3
3
  import { preview as previewVite } from 'vite';
4
+ /**
5
+ * Programmatically trigger `$ vike preview`
6
+ *
7
+ * https://vike.dev/api#preview
8
+ */
4
9
  async function preview(options = {}) {
5
- const { viteConfigEnhanced } = await enhanceViteConfig(options.viteConfig, 'preview');
10
+ const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'preview');
6
11
  const server = await previewVite(viteConfigEnhanced);
7
- return server;
12
+ return {
13
+ viteServer: server,
14
+ viteConfig: server.config
15
+ };
8
16
  }
@@ -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,2 @@
1
+ export * from '../../utils/assert.js';
2
+ export * from '../../utils/getGlobalObject.js';
@@ -0,0 +1,6 @@
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';
6
+ export * from '../../utils/getGlobalObject.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
  }
@@ -1,4 +1,4 @@
1
1
  export { parseCli };
2
2
  declare function parseCli(): {
3
- command: "build" | "dev" | "preview" | "prerender";
3
+ command: "dev" | "build" | "preview" | "prerender";
4
4
  };
@@ -4,7 +4,7 @@ export { plugin };
4
4
  export { plugin as ssr };
5
5
  export { PROJECT_VERSION as version } from './utils.js';
6
6
  import { version } from 'vite';
7
- import { assertNodeEnv_onVikePluginLoad, assertUsage, assertVersion, markEnvAsVikePluginLoaded } from './utils.js';
7
+ import { assertUsage, assertVersion, markSetup_vikeVitePlugin } from './utils.js';
8
8
  import { buildConfig } from './plugins/buildConfig.js';
9
9
  import { previewConfig } from './plugins/previewConfig.js';
10
10
  import { autoFullBuild } from './plugins/autoFullBuild.js';
@@ -28,8 +28,7 @@ import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.
28
28
  import { resolveClientEntriesDev } from './resolveClientEntriesDev.js';
29
29
  import { workaroundCssModuleHmr } from './plugins/workaroundCssModuleHmr.js';
30
30
  import { vite6HmrRegressionWorkaround } from './plugins/vite6HmrRegressionWorkaround.js';
31
- assertNodeEnv_onVikePluginLoad();
32
- markEnvAsVikePluginLoaded();
31
+ markSetup_vikeVitePlugin();
33
32
  assertViteVersion();
34
33
  setResolveClientEntriesDev(resolveClientEntriesDev);
35
34
  // Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
@@ -48,7 +47,7 @@ function plugin(vikeConfig) {
48
47
  ...extractAssetsPlugin(),
49
48
  extractExportNamesPlugin(),
50
49
  suppressRollupWarning(),
51
- setGlobalContext(),
50
+ ...setGlobalContext(),
52
51
  ...importBuild(),
53
52
  baseUrls(vikeConfig),
54
53
  envVarsPlugin(),
@@ -1,6 +1,6 @@
1
1
  export { onLoad };
2
2
  import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
3
- import { assertIsNotProductionRuntime } from '../../utils/assertIsNotProductionRuntime.js';
3
+ import { assertIsNotProductionRuntime } from '../../utils/assertSetup.js';
4
4
  import { assertNodeVersion } from '../../utils/assertNodeVersion.js';
5
5
  function onLoad() {
6
6
  assertIsNotBrowser();
@@ -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;
@@ -2,7 +2,7 @@ export { buildConfig };
2
2
  export { assertRollupInput };
3
3
  export { analyzeClientEntries };
4
4
  export { manifestTempFile };
5
- import { assert, resolveOutDir, viteIsSSR, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs, assertNodeEnv_build, assertIsNpmPackageImport } from '../utils.js';
5
+ import { assert, resolveOutDir, viteIsSSR, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs, onSetupBuild, assertIsNpmPackageImport } from '../utils.js';
6
6
  import { getVikeConfig, isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
7
7
  import { findPageFiles } from '../shared/findPageFiles.js';
8
8
  import { getConfigVike } from '../../shared/getConfigVike.js';
@@ -27,14 +27,14 @@ function buildConfig() {
27
27
  let config;
28
28
  return [
29
29
  {
30
- name: 'vike:buildConfig:configResolved',
30
+ name: 'vike:buildConfig:post',
31
31
  apply: 'build',
32
32
  enforce: 'post',
33
33
  configResolved: {
34
34
  order: 'post',
35
35
  async handler(config_) {
36
36
  config = config_;
37
- assertNodeEnv_build();
37
+ onSetupBuild();
38
38
  assertRollupInput(config);
39
39
  const entries = await getEntries(config);
40
40
  assert(Object.keys(entries).length > 0);
@@ -57,7 +57,7 @@ function buildConfig() {
57
57
  config: {
58
58
  order: 'post',
59
59
  handler(config) {
60
- assertNodeEnv_build();
60
+ onSetupBuild();
61
61
  isSsrBuild = viteIsSSR(config);
62
62
  return {
63
63
  build: {
@@ -69,14 +69,15 @@ function buildConfig() {
69
69
  }
70
70
  },
71
71
  buildStart() {
72
- assertNodeEnv_build();
72
+ onSetupBuild();
73
73
  },
74
74
  async closeBundle() {
75
+ onSetupBuild();
75
76
  await fixServerAssets_assertCssTarget(config);
76
77
  }
77
78
  },
78
79
  {
79
- name: 'vike:buildConfig:writeBundle',
80
+ name: 'vike:buildConfig:pre',
80
81
  apply: 'build',
81
82
  // Make sure other writeBundle() hooks are called after this writeBundle() hook.
82
83
  // - set_ASSETS_MAP() needs to be called before dist/server/ code is executed.
@@ -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,8 @@ 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
+ import { isVikeCliOrApi } from '../../api/context.js';
11
13
  function commonConfig() {
12
14
  return [
13
15
  {
@@ -18,7 +20,7 @@ function commonConfig() {
18
20
  }
19
21
  },
20
22
  {
21
- name: 'vike:commonConfig-2',
23
+ name: `${pluginName}:post`,
22
24
  enforce: 'post',
23
25
  configResolved: {
24
26
  order: 'post',
@@ -30,6 +32,7 @@ function commonConfig() {
30
32
  assertRollupInput(config);
31
33
  assertResolveAlias(config);
32
34
  assertEsm(config.root);
35
+ assertVikeCliOrApi(config);
33
36
  }
34
37
  },
35
38
  config: {
@@ -93,3 +96,22 @@ function assertSingleInstance(config) {
93
96
  const numberOfInstances = config.plugins.filter((o) => o.name === pluginName).length;
94
97
  assertUsage(numberOfInstances === 1, `Vike's Vite plugin (${pc.cyan("import vike from 'vike/plugin'")}) is being added ${numberOfInstances} times to the list of Vite plugins. Make sure to add it only once instead.`);
95
98
  }
99
+ function assertVikeCliOrApi(config) {
100
+ if (isVikeCliOrApi())
101
+ return;
102
+ if (isViteCliCall()) {
103
+ assertWarning(false, `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
104
+ onlyOnce: true
105
+ });
106
+ return;
107
+ }
108
+ if (config.server.middlewareMode) {
109
+ assertWarning(false, `${pc.cyan('vite.createServer()')} is deprecated ${pc.underline('https://vike.dev/migration/cli#api')}`, {
110
+ onlyOnce: true
111
+ });
112
+ return;
113
+ }
114
+ assertWarning(false, `Vite's JavaScript API is deprecated ${pc.underline('https://vike.dev/migration/cli#api')}`, {
115
+ onlyOnce: true
116
+ });
117
+ }
@@ -3,7 +3,7 @@ export { logDockerHint };
3
3
  import { determineOptimizeDeps } from './determineOptimizeDeps.js';
4
4
  import { determineFsAllowList } from './determineFsAllowList.js';
5
5
  import { addSsrMiddleware } from '../../shared/addSsrMiddleware.js';
6
- import { applyDev, assertWarning, isDocker, markEnvAsViteDev } from '../../utils.js';
6
+ import { applyDev, assertWarning, isDocker } 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';
@@ -65,9 +65,6 @@ function devConfig() {
65
65
  improveViteLogs(config);
66
66
  }
67
67
  logDockerHint(config.server.host);
68
- },
69
- configureServer() {
70
- markEnvAsViteDev();
71
68
  }
72
69
  },
73
70
  {
@@ -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,25 +1,28 @@
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
- assertPosixPath(outDirAbsoluteFilesystem);
18
- let outDirRelativeFromUserRootDir = path.posix.relative(userRootDir, outDirAbsoluteFilesystem);
16
+ //*/
17
+ const outDirRelativeFromUserRootDir = null;
18
+ /*/
19
+ assertPosixPath(outDirAbsoluteFilesystem)
20
+ let outDirRelativeFromUserRootDir: string | null = path.posix.relative(userRootDir, outDirAbsoluteFilesystem)
19
21
  if (outDirRelativeFromUserRootDir.startsWith('../')) {
20
- // config.outDir is outside of config.root => it's going to be ignored anyways
21
- outDirRelativeFromUserRootDir = null;
22
+ // config.outDir is outside of config.root => it's going to be ignored anyways
23
+ outDirRelativeFromUserRootDir = null
22
24
  }
25
+ //*/
23
26
  assert(outDirRelativeFromUserRootDir === null ||
24
27
  /* Not true if outDirRelativeFromUserRootDir starts with a hidden directory (i.e. a directory with a name that starts with `.`)
25
28
  !outDirRelativeFromUserRootDir.startsWith('.') &&
@@ -27,7 +30,6 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, craw
27
30
  (!outDirRelativeFromUserRootDir.startsWith('./') &&
28
31
  //
29
32
  !outDirRelativeFromUserRootDir.startsWith('../')));
30
- const timeBefore = new Date().getTime();
31
33
  // Crawl
32
34
  let files = [];
33
35
  const res = crawlWithGit !== false && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
@@ -43,18 +45,6 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, craw
43
45
  }
44
46
  // Filter build files
45
47
  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
48
  // Normalize
59
49
  const plusFiles = files.map((filePath) => {
60
50
  // 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
  }
@@ -1,5 +1,5 @@
1
1
  export { previewConfig };
2
- import { assertUsage, getOutDirs, resolveOutDir, markEnvAsVitePreview, applyPreview } from '../utils.js';
2
+ import { assertUsage, getOutDirs, resolveOutDir, applyPreview } from '../utils.js';
3
3
  import fs from 'fs';
4
4
  import path from 'path';
5
5
  import { addSsrMiddleware } from '../shared/addSsrMiddleware.js';
@@ -29,7 +29,6 @@ function previewConfig() {
29
29
  - This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
30
30
  config.appType = 'mpa'
31
31
  */
32
- markEnvAsVitePreview();
33
32
  return () => {
34
33
  assertDist();
35
34
  /* We don't use this condition (we wrongfully always use the SSR middleware) because of the regression introduced by https://github.com/vitejs/vite/pull/14756 which stops servering .html files when `appType: 'custom'`.
@@ -1,3 +1,3 @@
1
1
  export { setGlobalContext };
2
2
  import type { Plugin } from 'vite';
3
- declare function setGlobalContext(): Plugin;
3
+ declare function setGlobalContext(): Plugin[];
@@ -1,26 +1,41 @@
1
1
  export { setGlobalContext };
2
- import { setGlobalContext_isDev, setGlobalContext_viteDevServer, setGlobalContext_viteConfig } from '../../runtime/globalContext.js';
3
- import { assertFilePathAbsoluteFilesystem, getOutDirs, isDevCheck } from '../utils.js';
2
+ import { setGlobalContext_isViteDev, setGlobalContext_viteDevServer, setGlobalContext_viteConfig } from '../../runtime/globalContext.js';
3
+ import { assertFilePathAbsoluteFilesystem, getOutDirs, isDevCheck, markSetup_isViteDev, markSetup_viteDevServer, markSetup_vitePreviewServer } from '../utils.js';
4
4
  function setGlobalContext() {
5
- return {
6
- name: 'vike:setGlobalContext',
7
- enforce: 'pre',
8
- configureServer: {
9
- order: 'pre',
10
- handler(viteDevServer) {
11
- setGlobalContext_viteDevServer(viteDevServer);
5
+ return [
6
+ {
7
+ name: 'vike:setGlobalContext:pre',
8
+ enforce: 'pre',
9
+ configureServer: {
10
+ order: 'pre',
11
+ handler(viteDevServer) {
12
+ setGlobalContext_viteDevServer(viteDevServer);
13
+ markSetup_viteDevServer();
14
+ }
15
+ },
16
+ configurePreviewServer() {
17
+ markSetup_vitePreviewServer();
18
+ },
19
+ config: {
20
+ order: 'pre',
21
+ handler(_, env) {
22
+ const isViteDev = isDevCheck(env);
23
+ setGlobalContext_isViteDev(isViteDev);
24
+ markSetup_isViteDev(isViteDev);
25
+ }
12
26
  }
13
27
  },
14
- config: {
15
- handler(_, env) {
16
- const isDev = isDevCheck(env);
17
- setGlobalContext_isDev(isDev);
28
+ {
29
+ name: 'vike:setGlobalContext:post',
30
+ enforce: 'post',
31
+ configResolved: {
32
+ order: 'post',
33
+ handler(config) {
34
+ const { outDirRoot } = getOutDirs(config);
35
+ assertFilePathAbsoluteFilesystem(outDirRoot); // Needed for loadImportBuild(outDir) of @brillout/vite-plugin-server-entry
36
+ setGlobalContext_viteConfig(config, outDirRoot);
37
+ }
18
38
  }
19
- },
20
- configResolved(config) {
21
- const { outDirRoot } = getOutDirs(config);
22
- assertFilePathAbsoluteFilesystem(outDirRoot); // Needed for loadImportBuild(outDir) of @brillout/vite-plugin-server-entry
23
- setGlobalContext_viteConfig(config, outDirRoot);
24
39
  }
25
- };
40
+ ];
26
41
  }
@@ -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;
@@ -5,7 +5,7 @@ export { runPrerender_forceExit };
5
5
  import '../runtime/page-files/setup.js';
6
6
  import path from 'path';
7
7
  import { route } from '../../shared/route/index.js';
8
- import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject, handleNodeEnv_prerender, pLimit, isArray, changeEnumerable } from './utils.js';
8
+ import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject, pLimit, isArray, changeEnumerable, onSetupPrerender } from './utils.js';
9
9
  import { prerenderPage, prerender404Page, getRenderContext, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
10
10
  import pc from '@brillout/picocolors';
11
11
  import { cpus } from 'os';
@@ -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 { prepareViteApiCall } from '../api/prepareViteApiCall.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 prepareViteApiCall(undefined, 'prerender');
40
40
  await runPrerender({ viteConfig: viteConfigEnhanced }, '$ vike prerender');
41
41
  }
42
42
  catch (err) {
@@ -61,13 +61,13 @@ async function runPrerenderFromAutoRun(viteConfig, forceExit) {
61
61
  }
62
62
  async function runPrerender(options = {}, standaloneTrigger) {
63
63
  checkOutdatedOptions(options);
64
+ onSetupPrerender();
64
65
  setGlobalContext_isPrerendering();
65
66
  getHook_setIsPrerenderering();
66
67
  const logLevel = !!options.onPagePrerender ? 'warn' : 'info';
67
68
  if (logLevel === 'info') {
68
69
  console.log(`${pc.cyan(`vike v${projectInfo.projectVersion}`)} ${pc.green('pre-rendering HTML...')}`);
69
70
  }
70
- handleNodeEnv_prerender();
71
71
  await disableReactStreaming();
72
72
  const viteConfig = await resolveConfig(options.viteConfig || {}, 'vike pre-rendering', 'production');
73
73
  assertLoadedConfig(viteConfig, options);
@@ -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
@@ -9,7 +9,7 @@ export * from '../../utils/isPropertyGetter.js';
9
9
  export * from '../../utils/filesystemPathHandling.js';
10
10
  export * from '../../utils/urlToFile.js';
11
11
  export * from '../../utils/isPlainObject.js';
12
- export * from '../../utils/assertNodeEnv.js';
12
+ export * from '../../utils/assertSetup.js';
13
13
  export * from '../../utils/pLimit.js';
14
14
  export * from '../../utils/isFilePathAbsoluteFilesystem.js';
15
15
  export * from '../../utils/isArray.js';
@@ -11,7 +11,7 @@ export * from '../../utils/isPropertyGetter.js';
11
11
  export * from '../../utils/filesystemPathHandling.js';
12
12
  export * from '../../utils/urlToFile.js';
13
13
  export * from '../../utils/isPlainObject.js';
14
- export * from '../../utils/assertNodeEnv.js';
14
+ export * from '../../utils/assertSetup.js';
15
15
  export * from '../../utils/pLimit.js';
16
16
  export * from '../../utils/isFilePathAbsoluteFilesystem.js';
17
17
  export * from '../../utils/isArray.js';
@@ -9,7 +9,7 @@ export { initGlobalContext_runPrerender };
9
9
  export { initGlobalContext_getGlobalContextAsync };
10
10
  export { setGlobalContext_viteDevServer };
11
11
  export { setGlobalContext_viteConfig };
12
- export { setGlobalContext_isDev };
12
+ export { setGlobalContext_isViteDev };
13
13
  export { setGlobalContext_isPrerendering };
14
14
  import type { ViteManifest } from '../shared/ViteManifest.js';
15
15
  import type { ResolvedConfig, ViteDevServer } from 'vite';
@@ -52,7 +52,7 @@ declare function getGlobalContextSync(): GlobalContextPublic;
52
52
  declare function getGlobalContextAsync(isProduction: boolean): Promise<GlobalContextPublic>;
53
53
  declare function setGlobalContext_viteDevServer(viteDevServer: ViteDevServer): void;
54
54
  declare function setGlobalContext_viteConfig(viteConfig: ResolvedConfig, outDirRoot: string): void;
55
- declare function setGlobalContext_isDev(isDev: boolean): void;
55
+ declare function setGlobalContext_isViteDev(isViteDev: boolean): void;
56
56
  declare function setGlobalContext_isPrerendering(): void;
57
57
  declare function getViteDevServer(): ViteDevServer | null;
58
58
  declare function getViteConfig(): ResolvedConfig | null;