vike 0.4.217 → 0.4.218-commit-ed9b3d4

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 (173) hide show
  1. package/dist/cjs/__internal/index.js +9 -8
  2. package/dist/cjs/node/api/build.js +21 -12
  3. package/dist/cjs/node/api/context.js +5 -1
  4. package/dist/cjs/node/api/index.js +17 -7
  5. package/dist/cjs/node/api/prepareViteApiCall.js +128 -26
  6. package/dist/cjs/node/api/utils.js +2 -0
  7. package/dist/cjs/node/cli/entry.js +19 -7
  8. package/dist/cjs/node/plugin/index.js +6 -5
  9. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +3 -4
  10. package/dist/cjs/node/plugin/plugins/baseUrls.js +20 -18
  11. package/dist/cjs/node/plugin/plugins/buildConfig.js +2 -2
  12. package/dist/cjs/node/plugin/plugins/{importBuild → buildEntry}/index.js +16 -17
  13. package/dist/cjs/node/plugin/plugins/commonConfig.js +6 -6
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +2 -3
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +22 -111
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +189 -16
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -1
  18. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +1 -1
  19. package/dist/cjs/node/plugin/plugins/{vite6HmrRegressionWorkaround.js → workaroundVite6HmrRegression.js} +3 -3
  20. package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +17 -7
  21. package/dist/cjs/node/prerender/isPrerenderEnabled.js +8 -0
  22. package/dist/cjs/node/prerender/runPrerender.js +22 -35
  23. package/dist/cjs/node/runtime/globalContext.js +76 -29
  24. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
  25. package/dist/cjs/node/runtime/index-common.js +0 -15
  26. package/dist/cjs/node/runtime/onLoad.js +17 -3
  27. package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
  28. package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +2 -2
  29. package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
  30. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
  31. package/dist/cjs/node/runtime/utils.js +1 -0
  32. package/dist/cjs/node/runtime-dev/index.js +17 -7
  33. package/dist/cjs/node/shared/resolveBase.js +2 -2
  34. package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +3 -3
  35. package/dist/cjs/shared/getPageFiles/{setPageFiles.js → getPageFiles.js} +2 -3
  36. package/dist/cjs/shared/getPageFiles.js +3 -9
  37. package/dist/cjs/shared/hooks/getHook.js +3 -3
  38. package/dist/cjs/shared/{getPageFiles/getExports.js → page-configs/getPageConfigUserFriendly.js} +113 -81
  39. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +79 -54
  40. package/dist/cjs/shared/route/loadPageRoutes.js +3 -3
  41. package/dist/cjs/shared/utils.js +1 -0
  42. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  43. package/dist/cjs/utils/assert.js +4 -3
  44. package/dist/cjs/utils/debug.js +11 -6
  45. package/dist/cjs/utils/objectReplace.js +9 -0
  46. package/dist/esm/__internal/index.d.ts +3 -5
  47. package/dist/esm/__internal/index.js +4 -5
  48. package/dist/esm/client/client-routing-runtime/createPageContext.js +7 -1
  49. package/dist/esm/client/client-routing-runtime/entry.d.ts +1 -1
  50. package/dist/esm/client/client-routing-runtime/entry.js +0 -1
  51. package/dist/esm/client/client-routing-runtime/getPageContextCurrent.d.ts +2 -2
  52. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +4 -4
  53. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +1 -1
  54. package/dist/esm/client/client-routing-runtime/prefetch/getPrefetchSettings.d.ts +2 -2
  55. package/dist/esm/client/client-routing-runtime/prefetch.d.ts +2 -2
  56. package/dist/esm/client/client-routing-runtime/prefetch.js +2 -2
  57. package/dist/esm/client/server-routing-runtime/entry.d.ts +1 -1
  58. package/dist/esm/client/server-routing-runtime/entry.js +0 -1
  59. package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
  60. package/dist/esm/client/server-routing-runtime/getPageContext.js +8 -2
  61. package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
  62. package/dist/esm/client/shared/loadUserFilesClientSide.d.ts +2 -2
  63. package/dist/esm/client/shared/loadUserFilesClientSide.js +2 -2
  64. package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
  65. package/dist/esm/node/api/build.js +4 -5
  66. package/dist/esm/node/api/context.d.ts +3 -1
  67. package/dist/esm/node/api/context.js +6 -2
  68. package/dist/esm/node/api/prepareViteApiCall.d.ts +9 -3
  69. package/dist/esm/node/api/prepareViteApiCall.js +111 -22
  70. package/dist/esm/node/api/utils.d.ts +2 -0
  71. package/dist/esm/node/api/utils.js +2 -0
  72. package/dist/esm/node/cli/entry.js +2 -0
  73. package/dist/esm/node/cli/parseCli.d.ts +1 -1
  74. package/dist/esm/node/plugin/index.d.ts +1 -1
  75. package/dist/esm/node/plugin/index.js +6 -5
  76. package/dist/esm/node/plugin/plugins/autoFullBuild.js +3 -4
  77. package/dist/esm/node/plugin/plugins/baseUrls.d.ts +1 -2
  78. package/dist/esm/node/plugin/plugins/baseUrls.js +21 -19
  79. package/dist/esm/node/plugin/plugins/buildConfig.js +2 -2
  80. package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.d.ts +1 -1
  81. package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/index.d.ts +2 -2
  82. package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/index.js +16 -17
  83. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +7 -1
  84. package/dist/esm/node/plugin/plugins/commonConfig.js +2 -2
  85. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +1 -1
  86. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +1 -1
  87. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +2 -3
  88. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  89. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +23 -112
  90. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +99 -1
  91. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +189 -16
  92. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -1
  93. package/dist/esm/node/plugin/plugins/setGlobalContext.js +1 -1
  94. package/dist/esm/node/plugin/plugins/workaroundVite6HmrRegression.d.ts +3 -0
  95. package/dist/esm/node/plugin/plugins/{vite6HmrRegressionWorkaround.js → workaroundVite6HmrRegression.js} +3 -3
  96. package/dist/esm/node/plugin/shared/getEnvVarObject.d.ts +1 -1
  97. package/dist/esm/node/prerender/isPrerenderEnabled.d.ts +3 -0
  98. package/dist/esm/node/prerender/isPrerenderEnabled.js +6 -0
  99. package/dist/esm/node/prerender/runPrerender.d.ts +1 -2
  100. package/dist/esm/node/prerender/runPrerender.js +4 -27
  101. package/dist/esm/node/runtime/globalContext.d.ts +6 -4
  102. package/dist/esm/node/runtime/globalContext.js +76 -29
  103. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  104. package/dist/esm/node/runtime/index-common.d.ts +0 -1
  105. package/dist/esm/node/runtime/index-common.js +0 -15
  106. package/dist/esm/node/runtime/index-deprecated.d.ts +1 -0
  107. package/dist/esm/node/runtime/onLoad.js +16 -2
  108. package/dist/esm/node/runtime/renderPage/analyzePage.js +1 -1
  109. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +1 -1
  110. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +2 -2
  111. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -1
  112. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +2 -2
  113. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
  114. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +5 -5
  115. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
  116. package/dist/esm/node/runtime/utils.d.ts +1 -0
  117. package/dist/esm/node/runtime/utils.js +1 -0
  118. package/dist/esm/node/shared/resolveBase.js +2 -2
  119. package/dist/esm/shared/getPageFiles/analyzeClientSide.js +1 -1
  120. package/dist/esm/shared/getPageFiles/{setPageFiles.js → getPageFiles.js} +2 -3
  121. package/dist/esm/shared/getPageFiles.d.ts +2 -5
  122. package/dist/esm/shared/getPageFiles.js +1 -4
  123. package/dist/esm/shared/hooks/getHook.d.ts +3 -3
  124. package/dist/esm/shared/hooks/getHook.js +1 -1
  125. package/dist/esm/shared/page-configs/Config.d.ts +8 -2
  126. package/dist/esm/shared/page-configs/PageConfig.d.ts +7 -3
  127. package/dist/esm/shared/{getPageFiles/getExports.d.ts → page-configs/getPageConfigUserFriendly.d.ts} +23 -12
  128. package/dist/esm/shared/{getPageFiles/getExports.js → page-configs/getPageConfigUserFriendly.js} +112 -80
  129. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +28 -4
  130. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +79 -54
  131. package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
  132. package/dist/esm/shared/route/loadPageRoutes.js +1 -1
  133. package/dist/esm/shared/types.d.ts +1 -1
  134. package/dist/esm/shared/utils.d.ts +1 -0
  135. package/dist/esm/shared/utils.js +1 -0
  136. package/dist/esm/types/index.d.ts +1 -1
  137. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  138. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  139. package/dist/esm/utils/assert.js +4 -3
  140. package/dist/esm/utils/debug.d.ts +1 -1
  141. package/dist/esm/utils/debug.js +11 -6
  142. package/dist/esm/utils/objectReplace.d.ts +1 -0
  143. package/dist/esm/utils/objectReplace.js +6 -0
  144. package/dist/esm/utils/projectInfo.d.ts +1 -1
  145. package/package.json +3 -22
  146. package/__internal/loadImportBuild.js +0 -3
  147. package/__internal/setup.js +0 -3
  148. package/dist/cjs/node/plugin/plugins/commonConfig/pluginName.js +0 -4
  149. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +0 -128
  150. package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +0 -25
  151. package/dist/cjs/node/runtime/page-files/getPageFilesExports.js +0 -22
  152. package/dist/cjs/node/runtime/page-files/setup.js +0 -5
  153. package/dist/esm/client/client-routing-runtime/pageFiles.d.ts +0 -1
  154. package/dist/esm/client/client-routing-runtime/pageFiles.js +0 -4
  155. package/dist/esm/client/server-routing-runtime/pageFiles.d.ts +0 -1
  156. package/dist/esm/client/server-routing-runtime/pageFiles.js +0 -4
  157. package/dist/esm/node/plugin/plugins/commonConfig/pluginName.d.ts +0 -1
  158. package/dist/esm/node/plugin/plugins/commonConfig/pluginName.js +0 -1
  159. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.d.ts +0 -104
  160. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +0 -123
  161. package/dist/esm/node/plugin/plugins/vite6HmrRegressionWorkaround.d.ts +0 -3
  162. package/dist/esm/node/runtime/globalContext/loadImportBuild.d.ts +0 -18
  163. package/dist/esm/node/runtime/globalContext/loadImportBuild.js +0 -23
  164. package/dist/esm/node/runtime/page-files/getPageFilesExports.d.ts +0 -2
  165. package/dist/esm/node/runtime/page-files/getPageFilesExports.js +0 -20
  166. package/dist/esm/node/runtime/page-files/setup.d.ts +0 -1
  167. package/dist/esm/node/runtime/page-files/setup.js +0 -3
  168. package/dist/cjs/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.js +0 -0
  169. package/dist/cjs/shared/page-configs/{getConfigValue.js → getConfigValueRuntime.js} +0 -0
  170. package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.js +0 -0
  171. package/dist/esm/shared/getPageFiles/{setPageFiles.d.ts → getPageFiles.d.ts} +1 -1
  172. /package/dist/esm/shared/page-configs/{getConfigValue.d.ts → getConfigValueRuntime.d.ts} +0 -0
  173. /package/dist/esm/shared/page-configs/{getConfigValue.js → getConfigValueRuntime.js} +0 -0
@@ -1,8 +1,8 @@
1
- export { importBuild };
1
+ export { buildEntry };
2
2
  export { set_ASSETS_MAP };
3
3
  import type { Plugin, Rollup } from 'vite';
4
4
  type Bundle = Rollup.OutputBundle;
5
5
  type Options = Rollup.NormalizedOutputOptions;
6
- declare function importBuild(): Plugin[];
6
+ declare function buildEntry(): Plugin[];
7
7
  /** Set the value of the ASSETS_MAP constant inside dist/server/entry.js (or dist/server/index.js) */
8
8
  declare function set_ASSETS_MAP(options: Options, bundle: Bundle): Promise<void>;
@@ -1,23 +1,23 @@
1
- export { importBuild };
1
+ export { buildEntry };
2
2
  export { set_ASSETS_MAP };
3
3
  import { serverProductionEntryPlugin } from '@brillout/vite-plugin-server-entry/plugin';
4
+ import { virtualFileIdImportUserCodeServer } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
5
+ import { getVikeManifest } from './getVikeManifest.js';
6
+ import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
4
7
  import { assert, getOutDirs, toPosixPath } from '../../utils.js';
8
+ import fs from 'fs/promises';
5
9
  import path from 'path';
6
10
  import { createRequire } from 'module';
7
- import { getVikeManifest } from './getVikeManifest.js';
8
- import fs from 'fs/promises';
9
- import { virtualFileIdImportUserCodeServer } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
10
- import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
11
11
  // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
12
12
  const importMetaUrl = import.meta.url;
13
13
  const require_ = createRequire(importMetaUrl);
14
14
  const ASSETS_MAP = '__VITE_ASSETS_MAP__';
15
- function importBuild() {
15
+ function buildEntry() {
16
16
  let config;
17
17
  let vikeConfigGlobal;
18
18
  return [
19
19
  {
20
- name: 'vike:importBuild:config',
20
+ name: 'vike:buildEntry',
21
21
  enforce: 'post',
22
22
  async configResolved(config_) {
23
23
  config = config_;
@@ -38,17 +38,16 @@ function getServerProductionEntryCode(config, vikeConfigGlobal) {
38
38
  const vikeManifest = getVikeManifest(vikeConfigGlobal, config);
39
39
  // Let's eventually simplify and move everything to a single virtual module
40
40
  const importerCode = [
41
- ` import { setImportBuildGetters } from '${importPath}';`,
41
+ ` import { setGlobalContext_buildEntry } from '${importPath}';`,
42
42
  ` import * as pageFiles from '${virtualFileIdImportUserCodeServer}';`,
43
43
  ` {`,
44
44
  // We first set the values to a variable because of a Rollup bug, and this workaround doesn't work: https://github.com/vikejs/vike/commit/d5f3a4f7aae5a8bc44192e6cbb2bcb9007be188d
45
45
  ` const assetsManifest = ${ASSETS_MAP};`,
46
46
  ` const pluginManifest = ${JSON.stringify(vikeManifest, null, 2)};`,
47
- ' setImportBuildGetters({',
48
- ` pageFiles: () => pageFiles,`,
49
- ` getAssetsManifest: () => assetsManifest,`,
50
- // TODO: rename pluginManifest -> vikeManifest
51
- ` pluginManifest: () => pluginManifest,`,
47
+ ' setGlobalContext_buildEntry({',
48
+ ` pageFiles,`,
49
+ ` assetsManifest,`,
50
+ ` pluginManifest,`,
52
51
  ' });',
53
52
  ` }`,
54
53
  ''
@@ -85,12 +84,12 @@ function find_ASSETS_MAP(bundle) {
85
84
  function getImportPath(config) {
86
85
  // We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
87
86
  const filePathAbsolute = toPosixPath(
88
- // [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/importBuild/index.js
89
- require_.resolve(`../../../../../../dist/esm/node/runtime/globalContext/loadImportBuild.js`));
87
+ // [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/buildEntry/index.js
88
+ require_.resolve(`../../../../../../dist/esm/__internal/index.js`));
90
89
  if (
91
- // Let's implement a new config if a user needs the import to be a relative path instead of 'vike/__internal/loadImportBuild' (AFAIK a relative path is needed only if a framework has npm package 'vike' as direct dependency instead of a peer dependency and if the user of that framework uses pnpm)
90
+ // Let's implement a new config if a user needs the import to be a relative path instead of 'vike/__internal' (AFAIK a relative path is needed only if a framework has npm package 'vike' as direct dependency instead of a peer dependency and if the user of that framework uses pnpm)
92
91
  true) {
93
- return 'vike/__internal/loadImportBuild';
92
+ return 'vike/__internal';
94
93
  }
95
94
  else {
96
95
  const { outDirServer } = getOutDirs(config);
@@ -1,3 +1,9 @@
1
1
  export { commonConfig };
2
2
  import { type Plugin } from 'vite';
3
- declare function commonConfig(vikeVitePluginOptions?: unknown): Plugin[];
3
+ declare module 'vite' {
4
+ interface UserConfig {
5
+ _isDev?: boolean;
6
+ _vikeVitePluginOptions?: unknown;
7
+ }
8
+ }
9
+ declare function commonConfig(vikeVitePluginOptions: unknown): Plugin[];
@@ -6,11 +6,11 @@ import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
6
6
  import pc from '@brillout/picocolors';
7
7
  import path from 'path';
8
8
  import { assertResolveAlias } from './commonConfig/assertResolveAlias.js';
9
- import { pluginName } from './commonConfig/pluginName.js';
10
9
  import { getEnvVarObject } from '../shared/getEnvVarObject.js';
11
10
  import { isViteCliCall } from '../shared/isViteCliCall.js';
12
11
  import { isVikeCliOrApi } from '../../api/context.js';
13
- function commonConfig(vikeVitePluginOptions = {}) {
12
+ const pluginName = 'vike:commonConfig';
13
+ function commonConfig(vikeVitePluginOptions) {
14
14
  return [
15
15
  {
16
16
  name: `${pluginName}:pre`,
@@ -1,6 +1,6 @@
1
1
  export { getVirtualFileImportUserCode };
2
2
  import type { ResolvedConfig } from 'vite';
3
- import type { VikeConfigGlobal } from './v1-design/getVikeConfig/resolveVikeConfigGlobal.js';
3
+ import type { VikeConfigGlobal } from './v1-design/getVikeConfig.js';
4
4
  declare function getVirtualFileImportUserCode(id: string, options: {
5
5
  ssr?: boolean;
6
6
  } | undefined, vikeConfigGlobal: VikeConfigGlobal, config: ResolvedConfig, isDev: boolean): Promise<string>;
@@ -76,5 +76,5 @@ type ConfigDefinitions = Record<string, // configName
76
76
  ConfigDefinitionInternal>;
77
77
  type ConfigDefinitionsBuiltIn = Record<ConfigNameBuiltIn, ConfigDefinitionInternal>;
78
78
  declare const configDefinitionsBuiltIn: ConfigDefinitionsBuiltIn;
79
- type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization';
79
+ type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization' | 'vite';
80
80
  declare const configDefinitionsBuiltInGlobal: Record<ConfigNameGlobal, ConfigDefinitionInternal>;
@@ -143,9 +143,8 @@ const configDefinitionsBuiltInGlobal = {
143
143
  env: { server: true, client: 'if-client-routing' },
144
144
  eager: true
145
145
  },
146
- prerender: {
147
- env: { config: true }
148
- },
146
+ prerender: { env: { config: true } },
147
+ vite: { env: { config: true }, cumulative: true },
149
148
  disableAutoFullBuild: { env: { config: true } },
150
149
  includeAssetsImportedByServer: { env: { config: true } },
151
150
  baseAssets: { env: { config: true } },
@@ -1,4 +1,4 @@
1
1
  export { crawlPlusFiles };
2
- declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: null | string, crawlWithGit: null | boolean): Promise<{
2
+ declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: null | string): Promise<{
3
3
  filePathAbsoluteUserRootDir: string;
4
4
  }[]>;
@@ -1,17 +1,16 @@
1
1
  export { crawlPlusFiles };
2
- import { assertPosixPath, assert, scriptFileExtensions, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile } from '../../../../utils.js';
2
+ import { assertPosixPath, assert, scriptFileExtensions, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile, scriptFileExtensionList } from '../../../../utils.js';
3
3
  import path from 'path';
4
- import fs from 'fs/promises';
5
4
  import glob from 'fast-glob';
6
5
  import { exec } from 'child_process';
7
6
  import { promisify } from 'util';
8
7
  import { isTemporaryBuildFile } from './transpileAndExecuteFile.js';
8
+ import { getEnvVarObject } from '../../../../shared/getEnvVarObject.js';
9
9
  const execA = promisify(exec);
10
- const TOO_MANY_UNTRACKED_FILES = 5;
11
10
  assertIsNotProductionRuntime();
12
11
  assertIsSingleModuleInstance('crawlPlusFiles.ts');
13
12
  let gitIsNotUsable = false;
14
- async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, crawlWithGit) {
13
+ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
15
14
  assertPosixPath(userRootDir);
16
15
  //*/
17
16
  const outDirRelativeFromUserRootDir = null;
@@ -31,14 +30,13 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, crawlWithGi
31
30
  //
32
31
  !outDirRelativeFromUserRootDir.startsWith('../')));
33
32
  // Crawl
34
- let files = [];
35
- const res = crawlWithGit !== false && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
33
+ let files;
34
+ const res = !isGitCrawlDisabled() && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
36
35
  if (res &&
37
36
  // Fallback to fast-glob for users that dynamically generate plus files. (Assuming that no plus file is found because of the user's .gitignore list.)
38
- res.files.length > 0) {
39
- files = res.files;
37
+ res.length > 0) {
38
+ files = res;
40
39
  // We cannot find files inside symlink directories with `$ git ls-files` => we use fast-glob
41
- files.push(...(await crawlSymlinkDirs(res.symlinkDirs, userRootDir, outDirRelativeFromUserRootDir)));
42
40
  }
43
41
  else {
44
42
  files = await fastGlob(userRootDir, outDirRelativeFromUserRootDir);
@@ -70,24 +68,21 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
70
68
  'git',
71
69
  preserveUTF8,
72
70
  'ls-files',
73
- // We don't filter because:
74
- // - It would skip symlink directories
75
- // - Performance gain seems negligible: https://github.com/vikejs/vike/pull/1688#issuecomment-2166206648
76
- // ...scriptFileExtensionList.map((ext) => `"**/+*.${ext}"`),
71
+ // Performance gain seems negligible: https://github.com/vikejs/vike/pull/1688#issuecomment-2166206648
72
+ ...scriptFileExtensionList.map((ext) => `"**/+*.${ext}"`),
77
73
  // Performance gain is non-negligible.
78
74
  // - https://github.com/vikejs/vike/pull/1688#issuecomment-2166206648
79
75
  // - When node_modules/ is untracked the performance gain could be significant?
80
76
  ...ignoreAsPatterns.map((pattern) => `--exclude="${pattern}"`),
81
77
  // --others --exclude-standard => list untracked files (--others) while using .gitignore (--exclude-standard)
82
78
  // --cached => list tracked files
83
- // --stage => get file modes which we use to find symlink directories
84
- '--others --exclude-standard --cached --stage'
79
+ '--others --exclude-standard --cached'
85
80
  ].join(' ');
86
- let resultLines;
81
+ let filesAll;
87
82
  let filesDeleted;
88
83
  try {
89
84
  ;
90
- [resultLines, filesDeleted] = await Promise.all([
85
+ [filesAll, filesDeleted] = await Promise.all([
91
86
  // Main command
92
87
  runCmd1(cmd, userRootDir),
93
88
  // Get tracked but deleted files
@@ -101,40 +96,23 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
101
96
  }
102
97
  throw err;
103
98
  }
104
- const filePaths = resultLines.map(parseGitLsResultLine);
105
- // If there are too many files without mode we fallback to fast-glob
106
- if (filePaths.filter((f) => !f.mode).length > TOO_MANY_UNTRACKED_FILES)
107
- return null;
108
- const symlinkDirs = [];
109
99
  const files = [];
110
- for (const { filePath, mode } of filePaths) {
111
- // Deleted?
112
- if (filesDeleted.includes(filePath))
100
+ for (const filePath of filesAll) {
101
+ // + file?
102
+ if (!path.posix.basename(filePath).startsWith('+'))
113
103
  continue;
114
104
  // We have to repeat the same exclusion logic here because the option --exclude of `$ git ls-files` only applies to untracked files. (We use --exclude only to speed up the `$ git ls-files` command.)
115
105
  if (!ignoreAsFilterFn(filePath))
116
106
  continue;
117
- // Symlink directory?
118
- {
119
- const isSymlinkDir = await isSymlinkDirectory(mode, filePath, userRootDir);
120
- if (isSymlinkDir) {
121
- symlinkDirs.push(filePath);
122
- continue;
123
- }
124
- // Skip deleted files and non-symlink directories
125
- if (isSymlinkDir === null) {
126
- continue;
127
- }
128
- }
129
- // + file?
130
- if (!path.posix.basename(filePath).startsWith('+'))
131
- continue;
132
107
  // JavaScript file?
133
108
  if (!isScriptFile(filePath))
134
109
  continue;
110
+ // Deleted?
111
+ if (filesDeleted.includes(filePath))
112
+ continue;
135
113
  files.push(filePath);
136
114
  }
137
- return { files, symlinkDirs };
115
+ return files;
138
116
  }
139
117
  // Same as gitLsFiles() but using fast-glob
140
118
  async function fastGlob(userRootDir, outDirRelativeFromUserRootDir) {
@@ -204,77 +182,6 @@ async function isGitNotUsable(userRootDir) {
204
182
  return false;
205
183
  }
206
184
  }
207
- async function crawlSymlinkDirs(symlinkDirs, userRootDir, outDirRelativeFromUserRootDir) {
208
- const filesInSymlinkDirs = (await Promise.all(symlinkDirs.map(async (symlinkDir) => (await fastGlob(path.posix.join(userRootDir, symlinkDir), outDirRelativeFromUserRootDir)).map((filePath) => path.posix.join(symlinkDir, filePath))))).flat();
209
- return filesInSymlinkDirs;
210
- }
211
- // Parse:
212
- // ```
213
- // some/not/tracked/path
214
- // 100644 f6928073402b241b468b199893ff6f4aed0b7195 0\tpages/index/+Page.tsx
215
- // ```
216
- function parseGitLsResultLine(resultLine) {
217
- const [part1, part2, ...rest] = resultLine.split('\t');
218
- assert(part1);
219
- assert(rest.length === 0);
220
- // Git doesn't provide the mode for untracked paths.
221
- // `resultLine` is:
222
- // ```
223
- // some/not/tracked/path
224
- // ```
225
- if (part2 === undefined) {
226
- return { filePath: part1, mode: null };
227
- }
228
- assert(part2);
229
- // `resultLine` is:
230
- // ```
231
- // 100644 f6928073402b241b468b199893ff6f4aed0b7195 0\tpages/index/+Page.tsx
232
- // ```
233
- const [mode, _, __, ...rest2] = part1.split(' ');
234
- assert(mode && _ && __ && rest2.length === 0);
235
- return { filePath: part2, mode };
236
- }
237
- async function isSymlinkDirectory(mode, filePath, userRootDir) {
238
- const filePathAbsolute = path.posix.join(userRootDir, filePath);
239
- let stats = null;
240
- let isSymlink = false;
241
- if (mode === '120000') {
242
- isSymlink = true;
243
- }
244
- else if (mode === null) {
245
- // `$ git ls-files` doesn't provide the mode when Git doesn't track the path
246
- stats = await getFileStats(filePathAbsolute);
247
- if (stats === null)
248
- return null;
249
- isSymlink = stats.isSymbolicLink();
250
- if (!isSymlink && stats.isDirectory())
251
- return null;
252
- }
253
- else {
254
- assert(mode);
255
- }
256
- if (!isSymlink)
257
- return false;
258
- if (!stats)
259
- stats = await getFileStats(filePathAbsolute);
260
- if (stats === null)
261
- return null;
262
- const isDirectory = stats.isDirectory();
263
- return isDirectory;
264
- }
265
- async function getFileStats(filePathAbsolute) {
266
- let stats;
267
- try {
268
- stats = await fs.lstat(filePathAbsolute);
269
- }
270
- catch (err) {
271
- // File was deleted, usually a temporary file such as +config.js.build-j95xb988fpln.mjs
272
- // ENOENT: no such file or directory
273
- assert(err.code === 'ENOENT');
274
- return null;
275
- }
276
- return stats;
277
- }
278
185
  async function runCmd1(cmd, cwd) {
279
186
  const { stdout } = await execA(cmd, {
280
187
  cwd,
@@ -299,3 +206,7 @@ async function runCmd2(cmd, cwd) {
299
206
  stderr = stderr.toString().trim();
300
207
  return { stdout, stderr };
301
208
  }
209
+ function isGitCrawlDisabled() {
210
+ const crawSettings = getEnvVarObject('VIKE_CRAWL');
211
+ return crawSettings?.git === false;
212
+ }
@@ -8,11 +8,13 @@ export { getConfigValueInterfaceFile };
8
8
  export type { VikeConfigObject };
9
9
  export type { InterfaceValueFile };
10
10
  export type { InterfaceFile };
11
+ export type { VikeConfigGlobal };
12
+ export type { VikeVitePluginOptions };
11
13
  import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
12
14
  import { type LocationId } from './getVikeConfig/filesystemRouting.js';
13
15
  import type { ResolvedConfig } from 'vite';
14
16
  import type { FilePathResolved } from '../../../../../shared/page-configs/FilePath.js';
15
- import type { VikeConfigGlobal } from './getVikeConfig/resolveVikeConfigGlobal.js';
17
+ import { getPageConfigUserFriendlyNew } from '../../../../../shared/page-configs/getPageConfigUserFriendly.js';
16
18
  type InterfaceFile = InterfaceConfigFile | InterfaceValueFile;
17
19
  type InterfaceFileCommons = {
18
20
  locationId: LocationId;
@@ -37,6 +39,9 @@ type VikeConfigObject = {
37
39
  pageConfigs: PageConfigBuildTime[];
38
40
  pageConfigGlobal: PageConfigGlobalBuildTime;
39
41
  vikeConfigGlobal: VikeConfigGlobal;
42
+ vikeConfigNew: {
43
+ global: ReturnType<typeof getPageConfigUserFriendlyNew>;
44
+ };
40
45
  };
41
46
  declare const vikeConfigDependencies: Set<string>;
42
47
  declare function reloadVikeConfig(config: ResolvedConfig): void;
@@ -47,3 +52,96 @@ declare function getVikeConfig2(userRootDir: string, isDev: boolean, vikeVitePlu
47
52
  declare function isV1Design(config: ResolvedConfig): Promise<boolean>;
48
53
  declare function isVikeConfigFile(filePath: string): boolean;
49
54
  declare function getConfigValueInterfaceFile(interfaceFile: InterfaceFile, configName: string): unknown;
55
+ type VikeConfigGlobal = {
56
+ prerender: false | {
57
+ noExtraDir: boolean;
58
+ parallel: boolean | number;
59
+ partial: boolean;
60
+ disableAutoRun: boolean;
61
+ };
62
+ disableAutoFullBuild: boolean | 'prerender' | null;
63
+ includeAssetsImportedByServer: boolean;
64
+ baseAssets: string | null;
65
+ baseServer: string | null;
66
+ redirects: Record<string, string>;
67
+ trailingSlash: boolean;
68
+ disableUrlNormalization: boolean;
69
+ };
70
+ type VikeVitePluginOptions = {
71
+ /**
72
+ * Enable pre-rendering.
73
+ *
74
+ * https://vike.dev/pre-rendering
75
+ *
76
+ * @default false
77
+ */
78
+ prerender?: boolean | {
79
+ /**
80
+ * Don't create a new directory for each HTML file.
81
+ *
82
+ * For example, generate `dist/client/about.html` instead of `dist/client/about/index.html`.
83
+ *
84
+ * @default false
85
+ */
86
+ noExtraDir?: boolean;
87
+ /**
88
+ * Number of concurrent pre-render jobs.
89
+ *
90
+ * Set to `false` to disable concurrency.
91
+ *
92
+ * @default os.cpus().length
93
+ */
94
+ parallel?: boolean | number;
95
+ /**
96
+ * Allow only some of your pages to be pre-rendered.
97
+ *
98
+ * This setting doesn't affect the pre-rendering process: it merely suppresses the warnings when some of your pages cannot be pre-rendered.
99
+
100
+ * @default false
101
+ */
102
+ partial?: boolean;
103
+ /**
104
+ * Disable the automatic initiation of the pre-rendering process when running `$ vike build`.
105
+ *
106
+ * Use this if you want to programmatically initiate the pre-rendering process instead.
107
+ *
108
+ * https://vike.dev/api#prerender
109
+ *
110
+ * @default false
111
+ */
112
+ disableAutoRun?: boolean;
113
+ };
114
+ /** @deprecated See https://vike.dev/disableAutoFullBuild */
115
+ disableAutoFullBuild?: boolean | 'prerender';
116
+ /** The Base URL of your server.
117
+ *
118
+ * https://vike.dev/base-url
119
+ */
120
+ baseServer?: string;
121
+ /** The Base URL of your static assets.
122
+ *
123
+ * https://vike.dev/base-url
124
+ */
125
+ baseAssets?: string;
126
+ /** @deprecated It's now `true` by default. You can remove this option. */
127
+ includeAssetsImportedByServer?: boolean;
128
+ /** Permanent redirections (HTTP status code 301)
129
+ *
130
+ * https://vike.dev/redirects
131
+ */
132
+ redirects?: Record<string, string>;
133
+ /** Whether URLs should end with a trailing slash.
134
+ *
135
+ * https://vike.dev/url-normalization
136
+ *
137
+ * @default false
138
+ */
139
+ trailingSlash?: boolean;
140
+ /** Disable automatic URL normalization.
141
+ *
142
+ * https://vike.dev/url-normalization
143
+ *
144
+ * @default false
145
+ */
146
+ disableUrlNormalization?: boolean;
147
+ };