vike 0.4.219 → 0.4.220-commit-9a798ce

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 (157) hide show
  1. package/dist/cjs/node/api/build.js +23 -58
  2. package/dist/cjs/node/api/context.js +6 -8
  3. package/dist/cjs/node/api/prepareViteApiCall.js +6 -7
  4. package/dist/cjs/node/api/utils.js +1 -1
  5. package/dist/cjs/node/cli/context.js +16 -0
  6. package/dist/cjs/node/cli/entry.js +2 -0
  7. package/dist/cjs/node/cli/utils.js +1 -0
  8. package/dist/cjs/{utils → node/plugin}/getOutDirs.js +11 -11
  9. package/dist/cjs/node/plugin/index.js +1 -7
  10. package/dist/cjs/node/plugin/onLoad.js +6 -1
  11. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +43 -31
  12. package/dist/cjs/node/plugin/plugins/baseUrls.js +2 -2
  13. package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -3
  14. package/dist/cjs/node/plugin/plugins/buildEntry/index.js +24 -21
  15. package/dist/cjs/node/plugin/plugins/commonConfig.js +11 -8
  16. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +4 -2
  17. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -7
  18. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +3 -4
  19. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +10 -9
  20. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +8 -3
  21. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +158 -176
  22. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -1
  23. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +3 -2
  24. package/dist/cjs/node/plugin/plugins/previewConfig.js +3 -4
  25. package/dist/cjs/node/plugin/utils.js +1 -1
  26. package/dist/cjs/node/prerender/context.js +26 -0
  27. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +25 -0
  28. package/dist/cjs/node/prerender/runPrerender.js +64 -37
  29. package/dist/cjs/node/prerender/utils.js +3 -2
  30. package/dist/cjs/node/runtime/globalContext.js +44 -58
  31. package/dist/cjs/node/runtime/page-files/setup.js +1 -1
  32. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -3
  33. package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +6 -5
  34. package/dist/cjs/node/runtime/renderPage.js +10 -5
  35. package/dist/cjs/node/runtime/utils.js +3 -2
  36. package/dist/cjs/node/shared/resolveBase.js +9 -0
  37. package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +2 -2
  38. package/dist/cjs/shared/page-configs/loadConfigValues.js +5 -1
  39. package/dist/cjs/shared/utils.js +1 -1
  40. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  41. package/dist/cjs/utils/assertSetup.js +15 -1
  42. package/dist/cjs/utils/catchInfiniteLoop.js +34 -0
  43. package/dist/cjs/utils/findFile.js +3 -3
  44. package/dist/cjs/utils/isDev.js +4 -1
  45. package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +2 -2
  46. package/dist/cjs/utils/makePublicCopy.js +32 -0
  47. package/dist/cjs/utils/requireResolve.js +3 -3
  48. package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
  49. package/dist/esm/client/client-routing-runtime/history.js +23 -18
  50. package/dist/esm/client/client-routing-runtime/index.d.ts +0 -1
  51. package/dist/esm/client/client-routing-runtime/index.js +0 -1
  52. package/dist/esm/client/client-routing-runtime/initClientRouter.js +2 -2
  53. package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +3 -4
  54. package/dist/esm/client/client-routing-runtime/initOnPopState.d.ts +0 -10
  55. package/dist/esm/client/client-routing-runtime/initOnPopState.js +50 -62
  56. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +15 -15
  57. package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +4 -6
  58. package/dist/esm/client/client-routing-runtime/scrollRestoration.js +17 -12
  59. package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +1 -1
  60. package/dist/esm/client/client-routing-runtime/setScrollPosition.js +29 -5
  61. package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -0
  62. package/dist/esm/client/client-routing-runtime/utils.js +1 -0
  63. package/dist/esm/client/shared/normalizeClientSideUrl.js +2 -3
  64. package/dist/esm/node/api/build.d.ts +1 -6
  65. package/dist/esm/node/api/build.js +20 -25
  66. package/dist/esm/node/api/context.d.ts +4 -4
  67. package/dist/esm/node/api/context.js +6 -9
  68. package/dist/esm/node/api/prepareViteApiCall.d.ts +0 -1
  69. package/dist/esm/node/api/prepareViteApiCall.js +7 -8
  70. package/dist/esm/node/api/utils.d.ts +1 -1
  71. package/dist/esm/node/api/utils.js +1 -1
  72. package/dist/esm/node/cli/context.d.ts +5 -0
  73. package/dist/esm/node/cli/context.js +14 -0
  74. package/dist/esm/node/cli/entry.js +2 -0
  75. package/dist/esm/node/cli/parseCli.d.ts +3 -1
  76. package/dist/esm/node/cli/utils.d.ts +1 -0
  77. package/dist/esm/node/cli/utils.js +1 -0
  78. package/dist/esm/{utils → node/plugin}/getOutDirs.js +5 -5
  79. package/dist/esm/node/plugin/index.d.ts +29 -1
  80. package/dist/esm/node/plugin/index.js +2 -8
  81. package/dist/esm/node/plugin/onLoad.js +7 -2
  82. package/dist/esm/node/plugin/plugins/autoFullBuild.js +43 -31
  83. package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
  84. package/dist/esm/node/plugin/plugins/buildConfig.js +7 -4
  85. package/dist/esm/node/plugin/plugins/buildEntry/index.d.ts +3 -3
  86. package/dist/esm/node/plugin/plugins/buildEntry/index.js +25 -22
  87. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +8 -2
  88. package/dist/esm/node/plugin/plugins/commonConfig.js +9 -6
  89. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +4 -2
  90. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
  91. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -7
  92. package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -4
  93. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.d.ts +3 -2
  94. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +10 -9
  95. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +8 -3
  96. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -95
  97. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +159 -177
  98. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -1
  99. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +3 -2
  100. package/dist/esm/node/plugin/plugins/previewConfig.js +3 -4
  101. package/dist/esm/node/plugin/utils.js +1 -1
  102. package/dist/esm/node/prerender/context.d.ts +9 -0
  103. package/dist/esm/node/prerender/context.js +24 -0
  104. package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +5 -0
  105. package/dist/esm/node/prerender/resolvePrerenderConfig.js +23 -0
  106. package/dist/esm/node/prerender/runPrerender.d.ts +42 -1
  107. package/dist/esm/node/prerender/runPrerender.js +65 -38
  108. package/dist/esm/node/prerender/utils.d.ts +3 -2
  109. package/dist/esm/node/prerender/utils.js +3 -2
  110. package/dist/esm/node/runtime/globalContext.d.ts +15 -9
  111. package/dist/esm/node/runtime/globalContext.js +45 -59
  112. package/dist/esm/node/runtime/page-files/setup.js +1 -1
  113. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +5 -5
  114. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -3
  115. package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +2 -0
  116. package/dist/esm/node/runtime/renderPage/resolveRedirects.js +5 -5
  117. package/dist/esm/node/runtime/renderPage.js +10 -5
  118. package/dist/esm/node/runtime/utils.d.ts +3 -2
  119. package/dist/esm/node/runtime/utils.js +3 -2
  120. package/dist/esm/node/shared/resolveBase.d.ts +4 -1
  121. package/dist/esm/node/shared/resolveBase.js +9 -0
  122. package/dist/esm/shared/page-configs/Config.d.ts +76 -3
  123. package/dist/esm/shared/page-configs/PageConfig.d.ts +25 -16
  124. package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +1 -1
  125. package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +2 -2
  126. package/dist/esm/shared/page-configs/loadConfigValues.js +6 -2
  127. package/dist/esm/shared/utils.d.ts +1 -1
  128. package/dist/esm/shared/utils.js +1 -1
  129. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  130. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  131. package/dist/esm/utils/assertSetup.js +15 -1
  132. package/dist/esm/utils/catchInfiniteLoop.d.ts +2 -0
  133. package/dist/esm/utils/catchInfiniteLoop.js +32 -0
  134. package/dist/esm/utils/findFile.js +1 -1
  135. package/dist/esm/utils/isDev.js +4 -1
  136. package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -1
  137. package/dist/esm/utils/makePublicCopy.d.ts +3 -0
  138. package/dist/esm/utils/makePublicCopy.js +30 -0
  139. package/dist/esm/utils/projectInfo.d.ts +1 -1
  140. package/dist/esm/utils/requireResolve.js +1 -1
  141. package/package.json +1 -1
  142. package/dist/cjs/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -17
  143. package/dist/cjs/node/prerender/isPrerenderAutoRunEnabled.js +0 -16
  144. package/dist/cjs/node/shared/assertPluginManifest.js +0 -20
  145. package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -16
  146. package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.d.ts +0 -5
  147. package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -15
  148. package/dist/esm/node/prerender/isPrerenderAutoRunEnabled.d.ts +0 -5
  149. package/dist/esm/node/prerender/isPrerenderAutoRunEnabled.js +0 -14
  150. package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -12
  151. package/dist/esm/node/shared/assertPluginManifest.js +0 -18
  152. package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -10
  153. package/dist/esm/node/shared/assertRuntimeManifest.js +0 -14
  154. /package/dist/cjs/utils/{filesystemPathHandling.js → toPosixPath.js} +0 -0
  155. /package/dist/esm/{utils → node/plugin}/getOutDirs.d.ts +0 -0
  156. /package/dist/esm/utils/{filesystemPathHandling.d.ts → toPosixPath.d.ts} +0 -0
  157. /package/dist/esm/utils/{filesystemPathHandling.js → toPosixPath.js} +0 -0
@@ -2,8 +2,12 @@ export { setScrollPosition };
2
2
  export { autoSaveScrollPosition };
3
3
  export { scrollToHashOrTop };
4
4
  import { assert, onPageHide, sleep, throttle } from './utils.js';
5
- import { saveScrollPosition } from './history.js';
6
- function setScrollPosition(scrollTarget) {
5
+ import { replaceHistoryStateOriginal, saveScrollPosition } from './history.js';
6
+ function setScrollPosition(scrollTarget, url) {
7
+ if (!scrollTarget && url && hasTextFragment(url)) {
8
+ scrollToTextFragment(url);
9
+ return;
10
+ }
7
11
  if (scrollTarget && 'x' in scrollTarget) {
8
12
  setScroll(scrollTarget);
9
13
  return;
@@ -14,6 +18,21 @@ function setScrollPosition(scrollTarget) {
14
18
  const hash = getUrlHash();
15
19
  scrollToHashOrTop(hash);
16
20
  }
21
+ // https://github.com/vikejs/vike/issues/2114
22
+ // https://github.com/WICG/scroll-to-text-fragment/issues/261
23
+ function scrollToTextFragment(url) {
24
+ const stateOriginal = window.history.state;
25
+ replaceHistoryStateOriginal(null, url);
26
+ // We need `history.state===null` before location.replace() so that our 'popstate' handling is correct
27
+ assert(window.history.state === null);
28
+ // - Chrome's location.replace() keeps the current state (`history.state===stateOriginal`)
29
+ // - Firefox's location.replace() replaces the current state with `null` (`history.state===null`)
30
+ window.location.replace(url);
31
+ replaceHistoryStateOriginal(stateOriginal, url);
32
+ }
33
+ function hasTextFragment(url) {
34
+ return url.includes('#') && url.includes(':~:text');
35
+ }
17
36
  // Replicates the browser's native behavior
18
37
  function scrollToHashOrTop(hash) {
19
38
  if (!hash) {
@@ -45,9 +64,14 @@ function scrollToTop() {
45
64
  * - Let's remove it and see if users complain?
46
65
  */
47
66
  function setScroll(scrollPosition) {
48
- const scroll = () => window.scrollTo(scrollPosition.x, scrollPosition.y);
49
- const done = () => window.scrollX === scrollPosition.x && window.scrollY === scrollPosition.y;
50
- // In principle, this `done()` call should force the repaint to be finished. But that doesn't seem to be the case with `Firefox 97.0.1`.
67
+ const scroll = () => {
68
+ // `window.scrollTo()` respects the CSS `scroll-behavior: smooth` property
69
+ window.scrollTo(scrollPosition.x, scrollPosition.y);
70
+ };
71
+ const done = () => {
72
+ return window.scrollX === scrollPosition.x && window.scrollY === scrollPosition.y;
73
+ };
74
+ // In principle, this `done()` call should force the repaint to be finished, but that doesn't seem to be the case with `Firefox 97.0.1`.
51
75
  if (done())
52
76
  return;
53
77
  scroll();
@@ -21,3 +21,4 @@ export * from '../../utils/onPageVisibilityChange.js';
21
21
  export * from '../../utils/augmentType.js';
22
22
  export * from '../../utils/PROJECT_VERSION.js';
23
23
  export * from '../../utils/genPromise.js';
24
+ export * from '../../utils/catchInfiniteLoop.js';
@@ -25,3 +25,4 @@ export * from '../../utils/onPageVisibilityChange.js';
25
25
  export * from '../../utils/augmentType.js';
26
26
  export * from '../../utils/PROJECT_VERSION.js';
27
27
  export * from '../../utils/genPromise.js';
28
+ export * from '../../utils/catchInfiniteLoop.js';
@@ -2,9 +2,8 @@ export { normalizeClientSideUrl };
2
2
  import { assert, parseUrl } from './utils.js';
3
3
  /** Resolves relative URLs */
4
4
  function normalizeClientSideUrl(url, options) {
5
- // This function doesn't work for `url === '#some-hash'` because `searchOriginal` is `null` even if window.location.href has a search string.
6
- // - Thus the resolved absolute URL would be missing the search string.
7
- // - It makes sense that `parseUrl()` returns `searchOriginal === null` since there isn't any search string in `url`.
5
+ // This function doesn't work for `url === '#some-hash'` because `searchOriginal` will be missing: if window.location.href has a search string then it's going to be missing in the returned `urlCurrent` value because `parseUrl(url)` returns `searchOriginal: null` since there isn't any search string in `url`.
6
+ // - Maybe `const { searchOriginal } = parseUrl(window.location.href)` can be a fix. (Let's check how `normalizeClientSideUrl()` is being used.)
8
7
  assert(!url.startsWith('#'));
9
8
  const { searchOriginal, hashOriginal, pathname } = parseUrl(url, '/');
10
9
  let urlCurrent = `${pathname}${searchOriginal || ''}`;
@@ -1,13 +1,8 @@
1
1
  export { build };
2
- import { type Rollup } from 'vite';
3
2
  import type { APIOptions } from './types.js';
4
- type RollupOutput = Rollup.RollupOutput | Rollup.RollupOutput[] | Rollup.RollupWatcher;
5
3
  /**
6
4
  * Programmatically trigger `$ vike build`
7
5
  *
8
6
  * https://vike.dev/api#build
9
7
  */
10
- declare function build(options?: APIOptions): Promise<{
11
- rollupOutputClient: RollupOutput;
12
- rollupOutputServer: RollupOutput;
13
- }>;
8
+ declare function build(options?: APIOptions): Promise<{}>;
@@ -1,37 +1,32 @@
1
1
  export { build };
2
2
  import { prepareViteApiCall } from './prepareViteApiCall.js';
3
3
  import { build as buildVite } from 'vite';
4
- import { isPrerenderAutoRunEnabled } from '../prerender/isPrerenderAutoRunEnabled.js';
4
+ import assert from 'assert';
5
+ import { isVikeCli } from '../cli/context.js';
6
+ import { isPrerendering } from '../prerender/context.js';
5
7
  /**
6
8
  * Programmatically trigger `$ vike build`
7
9
  *
8
10
  * https://vike.dev/api#build
9
11
  */
10
12
  async function build(options = {}) {
11
- const { viteConfigEnhanced, vikeConfigGlobal } = await prepareViteApiCall(options.viteConfig, 'build');
12
- // Build client-side
13
- const outputClient = await buildVite(viteConfigEnhanced);
14
- // Build server-side
15
- const outputServer = await buildVite(setSSR(viteConfigEnhanced));
16
- // Pre-render
17
- if (isPrerenderAutoRunEnabled(vikeConfigGlobal)) {
18
- const { runPrerenderFromAutoRun } = await import('../prerender/runPrerender.js');
19
- await runPrerenderFromAutoRun(viteConfigEnhanced);
20
- }
13
+ const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'build');
14
+ // Pass it to autoFullBuild()
15
+ if (viteConfigEnhanced)
16
+ viteConfigEnhanced._viteConfigEnhanced = viteConfigEnhanced;
17
+ // 1. Build client-side
18
+ // 2. Build server-side
19
+ // > See: https://github.com/vikejs/vike/blob/c6c7533a56b3a16fc43ed644fc5c10c02d0ff375/vike/node/plugin/plugins/autoFullBuild.ts#L90
20
+ // 3. Pre-render (if enabled)
21
+ // > See: https://github.com/vikejs/vike/blob/c6c7533a56b3a16fc43ed644fc5c10c02d0ff375/vike/node/plugin/plugins/autoFullBuild.ts#L98
22
+ // > We purposely don't start the pre-rendering in this `build()` function but in a Rollup hook instead.
23
+ // > Rationale: https://github.com/vikejs/vike/issues/2123
24
+ await buildVite(viteConfigEnhanced);
25
+ // When using the Vike CLI with pre-rendering the process is forcefully exited at the end of the buildVite() call above
26
+ assert(!(isVikeCli() && isPrerendering()));
21
27
  return {
22
- /* We don't return `viteConfig` because `viteConfigEnhanced` is `InlineConfig` not `ResolvedConfig`
23
- viteConfig: viteConfigEnhanced,
24
- */
25
- rollupOutputClient: outputClient,
26
- rollupOutputServer: outputServer
27
- };
28
- }
29
- function setSSR(viteConfig) {
30
- return {
31
- ...viteConfig,
32
- build: {
33
- ...viteConfig?.build,
34
- ssr: true
35
- }
28
+ /* We don't return `viteConfig` because `viteConfigEnhanced` is `InlineConfig` not `ResolvedConfig`
29
+ viteConfig: viteConfigEnhanced,
30
+ */
36
31
  };
37
32
  }
@@ -1,7 +1,7 @@
1
- export { setOperation };
2
- export { clearOperation };
3
1
  export { isVikeCliOrApi };
2
+ export { setContextApiOperation };
3
+ export { clearContextApiOperation };
4
4
  import type { Operation } from './types.js';
5
5
  declare function isVikeCliOrApi(): boolean;
6
- declare function setOperation(operation: Operation): void;
7
- declare function clearOperation(): void;
6
+ declare function setContextApiOperation(operation: Operation): void;
7
+ declare function clearContextApiOperation(): void;
@@ -1,12 +1,9 @@
1
- // export { getOperation }
2
- export { setOperation };
3
- export { clearOperation };
4
1
  export { isVikeCliOrApi };
2
+ export { setContextApiOperation };
3
+ export { clearContextApiOperation };
5
4
  import { assert, getGlobalObject } from './utils.js';
6
- const globalObject = getGlobalObject('context.ts', {
7
- apiOperation: undefined
8
- });
9
- function getOperation() {
5
+ const globalObject = getGlobalObject('api/context.ts', {});
6
+ function getApiOperation() {
10
7
  assert(globalObject.apiOperation);
11
8
  return globalObject.apiOperation;
12
9
  }
@@ -14,10 +11,10 @@ function isVikeCliOrApi() {
14
11
  // The CLI uses the API
15
12
  return !!globalObject.apiOperation;
16
13
  }
17
- function setOperation(operation) {
14
+ function setContextApiOperation(operation) {
18
15
  assert(!globalObject.apiOperation);
19
16
  globalObject.apiOperation = operation;
20
17
  }
21
- function clearOperation() {
18
+ function clearContextApiOperation() {
22
19
  globalObject.apiOperation = undefined;
23
20
  }
@@ -6,7 +6,6 @@ import type { InlineConfig, ResolvedConfig } from 'vite';
6
6
  import type { Operation } from './types.js';
7
7
  declare function prepareViteApiCall(viteConfig: InlineConfig | undefined, operation: Operation): Promise<{
8
8
  viteConfigEnhanced: InlineConfig | undefined;
9
- vikeConfigGlobal: import("../plugin/plugins/importUserCode/v1-design/getVikeConfig.js").VikeConfigGlobal;
10
9
  }>;
11
10
  declare function getViteRoot(operation: 'build' | 'dev' | 'preview' | 'prerender'): Promise<string>;
12
11
  declare function normalizeViteRoot(root: string): string;
@@ -4,7 +4,7 @@ export { assertViteRoot };
4
4
  export { normalizeViteRoot };
5
5
  // TODO: enable Vike extensions to add Vite plugins
6
6
  import { loadConfigFromFile, mergeConfig, resolveConfig } from 'vite';
7
- import { clearOperation, setOperation } from './context.js';
7
+ import { clearContextApiOperation, setContextApiOperation } from './context.js';
8
8
  import { getVikeConfig2 } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
9
9
  import path from 'path';
10
10
  import { assert, assertUsage, getGlobalObject, isObject, toPosixPath } from './utils.js';
@@ -13,31 +13,30 @@ import { clearGlobalContext } from '../runtime/globalContext.js';
13
13
  const globalObject = getGlobalObject('prepareViteApiCall.ts', {});
14
14
  async function prepareViteApiCall(viteConfig, operation) {
15
15
  clear();
16
- setOperation(operation);
16
+ setContextApiOperation(operation);
17
17
  return enhanceViteConfig(viteConfig, operation);
18
18
  }
19
19
  // For subsequent API calls, e.g. calling prerender() after build()
20
20
  function clear() {
21
- clearOperation();
21
+ clearContextApiOperation();
22
22
  clearGlobalContext();
23
23
  }
24
24
  async function enhanceViteConfig(viteConfig, operation) {
25
25
  const viteInfo = await getInfoFromVite(viteConfig, operation);
26
26
  await assertViteRoot2(viteInfo.root, viteInfo.viteConfigEnhanced, operation);
27
27
  const vikeConfig = await getVikeConfig2(viteInfo.root, operation === 'dev', viteInfo.vikeVitePluginOptions);
28
- const viteConfigEnhanced = addViteSettingsSetByUser(viteInfo.viteConfigEnhanced, vikeConfig);
28
+ const viteConfigEnhanced = addViteSettingsSetByVikeConfig(viteInfo.viteConfigEnhanced, vikeConfig);
29
29
  return {
30
- viteConfigEnhanced,
31
- vikeConfigGlobal: vikeConfig.vikeConfigGlobal
30
+ viteConfigEnhanced
32
31
  };
33
32
  }
34
- function addViteSettingsSetByUser(viteConfigEnhanced, vikeConfig) {
33
+ function addViteSettingsSetByVikeConfig(viteConfigEnhanced, vikeConfig) {
35
34
  const viteConfigs = vikeConfig.global.from.configsCumulative.vite;
36
35
  if (!viteConfigs)
37
36
  return viteConfigEnhanced;
38
37
  viteConfigs.values.forEach((v) => {
39
38
  assertUsage(isObject(v.value), `${v.definedAt} should be an object`);
40
- viteConfigEnhanced = mergeConfig(v.value, viteConfigEnhanced ?? {});
39
+ viteConfigEnhanced = mergeConfig(viteConfigEnhanced ?? {}, v.value);
41
40
  });
42
41
  return viteConfigEnhanced;
43
42
  }
@@ -1,4 +1,4 @@
1
1
  export * from '../../utils/assert.js';
2
2
  export * from '../../utils/getGlobalObject.js';
3
- export * from '../../utils/filesystemPathHandling.js';
3
+ export * from '../../utils/toPosixPath.js';
4
4
  export * from '../../utils/isObject.js';
@@ -4,5 +4,5 @@ import { onLoad } from './onLoad.js';
4
4
  onLoad();
5
5
  export * from '../../utils/assert.js';
6
6
  export * from '../../utils/getGlobalObject.js';
7
- export * from '../../utils/filesystemPathHandling.js';
7
+ export * from '../../utils/toPosixPath.js';
8
8
  export * from '../../utils/isObject.js';
@@ -0,0 +1,5 @@
1
+ export { isVikeCli };
2
+ export { setContextCliCommand };
3
+ import type { Command } from './parseCli.js';
4
+ declare function isVikeCli(): boolean;
5
+ declare function setContextCliCommand(command: Command): void;
@@ -0,0 +1,14 @@
1
+ export { isVikeCli };
2
+ export { setContextCliCommand };
3
+ import { assert, getGlobalObject } from './utils.js';
4
+ const globalObject = getGlobalObject('cli/context.ts', {});
5
+ function getCliCommand() {
6
+ return globalObject.cliCommand;
7
+ }
8
+ function isVikeCli() {
9
+ return !!globalObject.cliCommand;
10
+ }
11
+ function setContextCliCommand(command) {
12
+ assert(!globalObject.cliCommand);
13
+ globalObject.cliCommand = command;
14
+ }
@@ -2,9 +2,11 @@ import { projectInfo } from './utils.js';
2
2
  import { dev, build, preview } from '../api/index.js';
3
3
  import pc from '@brillout/picocolors';
4
4
  import { parseCli } from './parseCli.js';
5
+ import { setContextCliCommand } from './context.js';
5
6
  cli();
6
7
  async function cli() {
7
8
  const { command } = parseCli();
9
+ setContextCliCommand(command);
8
10
  if (command === 'dev') {
9
11
  await cmdDev();
10
12
  }
@@ -1,4 +1,6 @@
1
1
  export { parseCli };
2
+ export type { Command };
3
+ type Command = 'dev' | 'build' | 'preview' | 'prerender';
2
4
  declare function parseCli(): {
3
- command: "build" | "dev" | "preview" | "prerender";
5
+ command: Command;
4
6
  };
@@ -1,3 +1,4 @@
1
1
  export * from '../../utils/assert.js';
2
2
  export * from '../../utils/projectInfo.js';
3
3
  export * from '../../utils/includes.js';
4
+ export * from '../../utils/getGlobalObject.js';
@@ -5,3 +5,4 @@ onLoad();
5
5
  export * from '../../utils/assert.js';
6
6
  export * from '../../utils/projectInfo.js';
7
7
  export * from '../../utils/includes.js';
8
+ export * from '../../utils/getGlobalObject.js';
@@ -1,11 +1,11 @@
1
1
  export { getOutDirs };
2
2
  export { resolveOutDir };
3
- import { viteIsSSR } from './viteIsSSR.js';
4
- import { assert, assertUsage } from './assert.js';
5
- import { pathJoin } from './path-shim.js';
6
- import { assertPosixPath, toPosixPath } from './filesystemPathHandling.js';
3
+ import { viteIsSSR } from '../../utils/viteIsSSR.js';
4
+ import { assert, assertUsage } from '../../utils/assert.js';
5
+ import { pathJoin } from '../../utils/path-shim.js';
6
+ import { assertPosixPath, toPosixPath } from '../../utils/toPosixPath.js';
7
7
  import pc from '@brillout/picocolors';
8
- import { createDebugger } from './debug.js';
8
+ import { createDebugger } from '../../utils/debug.js';
9
9
  const debug = createDebugger('vike:outDir');
10
10
  function getOutDirs(config) {
11
11
  debug('getOutDirs()', new Error().stack);
@@ -2,6 +2,34 @@ export default plugin;
2
2
  export { plugin };
3
3
  export { plugin as ssr };
4
4
  export type { VikeVitePluginOptions as UserConfig };
5
+ export type { VikeVitePluginOptions };
5
6
  export { PROJECT_VERSION as version } from './utils.js';
6
- import type { VikeVitePluginOptions } from './plugins/importUserCode/v1-design/getVikeConfig.js';
7
7
  declare function plugin(vikeVitePluginOptions?: VikeVitePluginOptions): any;
8
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
9
+ type VikeVitePluginOptions = {
10
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
11
+ prerender?: boolean | {
12
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
13
+ noExtraDir?: boolean;
14
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
15
+ parallel?: boolean | number;
16
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
17
+ partial?: boolean;
18
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
19
+ disableAutoRun?: boolean;
20
+ };
21
+ /** @deprecated See https://vike.dev/disableAutoFullBuild */
22
+ disableAutoFullBuild?: boolean | 'prerender';
23
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
24
+ baseServer?: string;
25
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
26
+ baseAssets?: string;
27
+ /** @deprecated It's now `true` by default. You can remove this option. */
28
+ includeAssetsImportedByServer?: boolean;
29
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
30
+ redirects?: Record<string, string>;
31
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
32
+ trailingSlash?: boolean;
33
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
34
+ disableUrlNormalization?: boolean;
35
+ };
@@ -3,8 +3,7 @@ export { plugin };
3
3
  // TODO/v1-release: remove
4
4
  export { plugin as ssr };
5
5
  export { PROJECT_VERSION as version } from './utils.js';
6
- import { version } from 'vite';
7
- import { assertUsage, assertVersion, markSetup_vikeVitePlugin } from './utils.js';
6
+ import { assertUsage } from './utils.js';
8
7
  import { buildConfig } from './plugins/buildConfig.js';
9
8
  import { previewConfig } from './plugins/previewConfig.js';
10
9
  import { autoFullBuild } from './plugins/autoFullBuild.js';
@@ -27,8 +26,7 @@ import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.
27
26
  import { resolveClientEntriesDev } from './resolveClientEntriesDev.js';
28
27
  import { workaroundCssModuleHmr } from './plugins/workaroundCssModuleHmr.js';
29
28
  import { workaroundVite6HmrRegression } from './plugins/workaroundVite6HmrRegression.js';
30
- markSetup_vikeVitePlugin();
31
- assertViteVersion();
29
+ // We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
32
30
  setResolveClientEntriesDev(resolveClientEntriesDev);
33
31
  // Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
34
32
  function plugin(vikeVitePluginOptions = {}) {
@@ -63,10 +61,6 @@ Object.defineProperty(plugin, 'apply', {
63
61
  assertUsage(false, `Add ${pc.cyan('vike()')} instead of ${pc.cyan('vike')} to vite.config.js#plugins (i.e. call the function and add the return value instead of adding the function itself)`, { showStackTrace: true });
64
62
  }
65
63
  });
66
- // package.json#peerDependencies isn't enough as users can ignore it
67
- function assertViteVersion() {
68
- assertVersion('Vite', version, '5.1.0');
69
- }
70
64
  // Ensures following works: `const vike = require('vike/plugin')` / `import vike from 'vike/plugin'`
71
65
  // - It needs to live at the end of this file, in order to ensure we do it after all assignments to `exports`.
72
66
  try {
@@ -1,10 +1,15 @@
1
1
  export { onLoad };
2
2
  import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
3
- import { assertIsNotProductionRuntime } from '../../utils/assertSetup.js';
3
+ import { assertIsNotProductionRuntime, markSetup_vikeVitePlugin } from '../../utils/assertSetup.js';
4
4
  import { assertNodeVersion } from '../../utils/assertNodeVersion.js';
5
+ import { assertVersion } from '../../utils/assertVersion.js';
6
+ import { version } from 'vite';
5
7
  function onLoad() {
8
+ markSetup_vikeVitePlugin();
6
9
  assertIsNotBrowser();
7
10
  assertNodeVersion();
8
- // Ensure we don't bloat the server runtime with heavy plugin dependencies such as esbuild
11
+ // package.json#peerDependencies isn't enough as users can ignore it
12
+ assertVersion('Vite', version, '5.1.0');
13
+ // Ensure we don't bloat the server runtime with heavy dependencies such Vite and esbuild
9
14
  assertIsNotProductionRuntime();
10
15
  }
@@ -3,26 +3,27 @@ export { autoFullBuild };
3
3
  import { build } from 'vite';
4
4
  import { assertWarning } from '../utils.js';
5
5
  import { runPrerenderFromAutoRun, runPrerender_forceExit } from '../../prerender/runPrerender.js';
6
- import { isPrerenderAutoRunEnabled } from '../../prerender/isPrerenderAutoRunEnabled.js';
6
+ import { isPrerenderAutoRunEnabled } from '../../prerender/context.js';
7
7
  import { isViteCliCall, getViteConfigFromCli } from '../shared/isViteCliCall.js';
8
8
  import pc from '@brillout/picocolors';
9
9
  import { logErrorHint } from '../../runtime/renderPage/logErrorHint.js';
10
10
  import { manifestTempFile } from './buildConfig.js';
11
11
  import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
12
+ import { isVikeCliOrApi } from '../../api/context.js';
13
+ import { isVikeCli } from '../../cli/context.js';
12
14
  let forceExit = false;
13
15
  function autoFullBuild() {
14
16
  let config;
15
- let vikeConfigGlobal;
17
+ let vikeConfig;
16
18
  return [
17
19
  {
18
20
  name: 'vike:autoFullBuild',
19
21
  apply: 'build',
20
22
  enforce: 'pre',
21
23
  async configResolved(config_) {
22
- const vikeConfig = await getVikeConfig(config_);
23
- vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
24
+ vikeConfig = await getVikeConfig(config_);
24
25
  config = config_;
25
- abortViteBuildSsr(vikeConfigGlobal);
26
+ abortViteBuildSsr(vikeConfig);
26
27
  },
27
28
  writeBundle: {
28
29
  /* We can't use this because it breaks Vite's logging. TODO: try again with latest Vite version.
@@ -31,7 +32,7 @@ function autoFullBuild() {
31
32
  */
32
33
  async handler(_options, bundle) {
33
34
  try {
34
- await triggerFullBuild(config, vikeConfigGlobal, bundle);
35
+ await triggerFullBuild(config, vikeConfig, bundle);
35
36
  }
36
37
  catch (err) {
37
38
  // Avoid Rollup prefixing the error with [vike:autoFullBuild], for example see https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
@@ -57,10 +58,10 @@ function autoFullBuild() {
57
58
  }
58
59
  ];
59
60
  }
60
- async function triggerFullBuild(config, vikeConfigGlobal, bundle) {
61
+ async function triggerFullBuild(config, vikeConfig, bundle) {
61
62
  if (config.build.ssr)
62
63
  return; // already triggered
63
- if (isDisabled(vikeConfigGlobal))
64
+ if (isDisabled(vikeConfig))
64
65
  return;
65
66
  // Workaround for @vitejs/plugin-legacy
66
67
  // - The legacy plugin triggers its own Rollup build for the client-side.
@@ -69,43 +70,54 @@ async function triggerFullBuild(config, vikeConfigGlobal, bundle) {
69
70
  if (!bundle[manifestTempFile])
70
71
  return;
71
72
  const configFromCli = !isViteCliCall() ? null : getViteConfigFromCli();
72
- const configInline = {
73
- ...configFromCli,
74
- configFile: configFromCli?.configFile || config.configFile,
75
- root: config.root,
76
- build: {
77
- ...configFromCli?.build
78
- }
79
- };
80
- try {
81
- await build({
82
- ...configInline,
73
+ let configInline;
74
+ if (config._viteConfigEnhanced) {
75
+ configInline = config._viteConfigEnhanced;
76
+ }
77
+ else {
78
+ configInline = {
79
+ ...configFromCli,
80
+ configFile: configFromCli?.configFile || config.configFile,
81
+ root: config.root,
83
82
  build: {
84
- ...configInline.build,
85
- ssr: true
83
+ ...configFromCli?.build
86
84
  }
87
- });
85
+ };
86
+ }
87
+ try {
88
+ await build(setSSR(configInline));
88
89
  }
89
90
  catch (err) {
90
91
  console.error(err);
91
92
  logErrorHint(err);
92
93
  process.exit(1);
93
94
  }
94
- if (isPrerenderAutoRunEnabled(vikeConfigGlobal)) {
95
- await runPrerenderFromAutoRun(configInline);
96
- forceExit = true;
95
+ if (isPrerenderAutoRunEnabled(vikeConfig)) {
96
+ const { prerenderContextPublic } = await runPrerenderFromAutoRun(configInline);
97
+ config.vike.prerenderContext = prerenderContextPublic;
98
+ forceExit = isVikeCli() || isViteCliCall();
97
99
  }
98
100
  }
99
- function abortViteBuildSsr(vikeConfigGlobal) {
100
- if (vikeConfigGlobal.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
101
+ function setSSR(configInline) {
102
+ return {
103
+ ...configInline,
104
+ build: {
105
+ ...configInline.build,
106
+ ssr: true
107
+ }
108
+ };
109
+ }
110
+ function abortViteBuildSsr(vikeConfig) {
111
+ if (vikeConfig.global.config.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
101
112
  assertWarning(false, `The CLI call ${pc.cyan('$ vite build --ssr')} is superfluous since ${pc.cyan('$ vite build')} also builds the server-side. If you want two separate build steps then use https://vike.dev/disableAutoFullBuild or use Vite's ${pc.cyan('build()')} API.`, { onlyOnce: true });
102
113
  process.exit(0);
103
114
  }
104
115
  }
105
- function isDisabled(vikeConfigGlobal) {
106
- const { disableAutoFullBuild } = vikeConfigGlobal;
107
- if (disableAutoFullBuild === null || disableAutoFullBuild === 'prerender') {
108
- return !isViteCliCall();
116
+ function isDisabled(vikeConfig) {
117
+ const { disableAutoFullBuild } = vikeConfig.global.config;
118
+ if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
119
+ const isViteApi = !isViteCliCall() && !isVikeCliOrApi();
120
+ return isViteApi;
109
121
  }
110
122
  else {
111
123
  return disableAutoFullBuild;
@@ -11,7 +11,7 @@ function baseUrls() {
11
11
  const isDev = config._isDev;
12
12
  assert(typeof isDev === 'boolean');
13
13
  const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
14
- basesResolved = resolveBase(baseViteOriginal, config.vike.vikeConfigGlobal.baseServer, config.vike.vikeConfigGlobal.baseAssets);
14
+ basesResolved = resolveBase(baseViteOriginal, config.vike.global.config.baseServer ?? null, config.vike.global.config.baseAssets ?? null);
15
15
  // We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
16
16
  process.env.BASE_SERVER = basesResolved.baseServer;
17
17
  process.env.BASE_ASSETS = basesResolved.baseAssets;
@@ -27,7 +27,7 @@ function baseUrls() {
27
27
  },
28
28
  async configResolved(config) {
29
29
  const vikeConfig = await getVikeConfig(config);
30
- const basesResolved2 = resolveBaseFromResolvedConfig(vikeConfig.vikeConfigGlobal.baseServer, vikeConfig.vikeConfigGlobal.baseAssets, config);
30
+ const basesResolved2 = resolveBaseFromResolvedConfig(vikeConfig.global.config.baseServer ?? null, vikeConfig.global.config.baseAssets ?? null, config);
31
31
  assert(basesResolved2.baseServer === basesResolved.baseServer);
32
32
  assert(basesResolved2.baseAssets === basesResolved.baseAssets);
33
33
  /* In dev, Vite seems buggy around setting vite.config.js#base to an absolute URL (e.g. http://localhost:8080/cdn/)
@@ -11,7 +11,7 @@ import { createRequire } from 'module';
11
11
  import fs from 'fs/promises';
12
12
  import path from 'path';
13
13
  import { fixServerAssets, fixServerAssets_assertCssCodeSplit, fixServerAssets_assertCssTarget, fixServerAssets_assertCssTarget_populate, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
14
- import { set_ASSETS_MAP } from './buildEntry/index.js';
14
+ import { set_ASSETS_MANIFEST } from './buildEntry/index.js';
15
15
  import { prependEntriesDir } from '../../shared/prependEntriesDir.js';
16
16
  import { getFilePathResolved } from '../shared/getFilePath.js';
17
17
  import { getConfigValueBuildTime } from '../../../shared/page-configs/getConfigValueBuildTime.js';
@@ -79,7 +79,7 @@ function buildConfig() {
79
79
  name: 'vike:buildConfig:pre',
80
80
  apply: 'build',
81
81
  // Make sure other writeBundle() hooks are called after this writeBundle() hook.
82
- // - set_ASSETS_MAP() needs to be called before dist/server/ code is executed.
82
+ // - set_ASSETS_MANIFEST() needs to be called before dist/server/ code is executed.
83
83
  // - For example, the writeBundle() hook of vite-plugin-vercel needs to be called after this writeBundle() hook, otherwise: https://github.com/vikejs/vike/issues/1527
84
84
  enforce: 'pre',
85
85
  writeBundle: {
@@ -102,7 +102,7 @@ function buildConfig() {
102
102
  }
103
103
  await fs.rm(clientManifestFilePath);
104
104
  await fs.rm(serverManifestFilePath);
105
- await set_ASSETS_MAP(options, bundle);
105
+ await set_ASSETS_MANIFEST(options, bundle);
106
106
  }
107
107
  }
108
108
  }
@@ -112,7 +112,10 @@ function buildConfig() {
112
112
  async function getEntries(config) {
113
113
  const vikeConfig = await getVikeConfig(config);
114
114
  const { pageConfigs } = vikeConfig;
115
- const pageFileEntries = await getPageFileEntries(config, vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer); // TODO/v1-release: remove
115
+ // TODO/v1-release: remove
116
+ const pageFileEntries = await getPageFileEntries(config,
117
+ // TODO/now: add meta.default
118
+ vikeConfig.global.config.includeAssetsImportedByServer ?? true);
116
119
  assertUsage(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
117
120
  if (viteIsSSR(config)) {
118
121
  const pageEntries = getPageEntries(pageConfigs);
@@ -1,8 +1,8 @@
1
1
  export { buildEntry };
2
- export { set_ASSETS_MAP };
2
+ export { set_ASSETS_MANIFEST };
3
3
  import type { Plugin, Rollup } from 'vite';
4
4
  type Bundle = Rollup.OutputBundle;
5
5
  type Options = Rollup.NormalizedOutputOptions;
6
6
  declare function buildEntry(): Plugin[];
7
- /** Set the value of the ASSETS_MAP constant inside dist/server/entry.js (or dist/server/index.js) */
8
- declare function set_ASSETS_MAP(options: Options, bundle: Bundle): Promise<void>;
7
+ /** Set the value of the ASSETS_MANIFEST constant inside dist/server/entry.js (or dist/server/index.js) */
8
+ declare function set_ASSETS_MANIFEST(options: Options, bundle: Bundle): Promise<void>;