vike 0.4.172-commit-ea2b76c → 0.4.172-commit-605b4a5

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 (36) hide show
  1. package/dist/cjs/node/plugin/index.js +3 -0
  2. package/dist/cjs/node/plugin/plugins/config/index.js +9 -5
  3. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -1
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +4 -3
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +12 -10
  6. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
  7. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
  8. package/dist/cjs/node/plugin/plugins/previewConfig.js +2 -2
  9. package/dist/cjs/node/plugin/resolveClientEntriesDev.js +59 -0
  10. package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +7 -1
  11. package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +1 -1
  12. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +9 -59
  13. package/dist/cjs/utils/assert.js +2 -2
  14. package/dist/cjs/utils/projectInfo.js +1 -1
  15. package/dist/esm/node/plugin/index.js +3 -0
  16. package/dist/esm/node/plugin/plugins/config/index.js +9 -5
  17. package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -1
  18. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  19. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +4 -3
  20. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +4 -1
  21. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +12 -10
  22. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
  23. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
  24. package/dist/esm/node/plugin/plugins/previewConfig.js +2 -2
  25. package/dist/esm/node/plugin/resolveClientEntriesDev.d.ts +4 -0
  26. package/dist/esm/node/plugin/resolveClientEntriesDev.js +56 -0
  27. package/dist/esm/node/plugin/shared/addSsrMiddleware.d.ts +2 -2
  28. package/dist/esm/node/plugin/shared/addSsrMiddleware.js +7 -1
  29. package/dist/esm/node/runtime/html/serializePageContextClientSide.js +1 -1
  30. package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +3 -0
  31. package/dist/esm/node/runtime/renderPage/getPageAssets.js +9 -59
  32. package/dist/esm/shared/ConfigVike.d.ts +7 -0
  33. package/dist/esm/utils/assert.js +2 -2
  34. package/dist/esm/utils/projectInfo.d.ts +2 -2
  35. package/dist/esm/utils/projectInfo.js +1 -1
  36. package/package.json +3 -3
@@ -28,9 +28,12 @@ const baseUrls_js_1 = require("./plugins/baseUrls.js");
28
28
  const envVars_js_1 = require("./plugins/envVars.js");
29
29
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
30
30
  const fileEnv_js_1 = require("./plugins/fileEnv.js");
31
+ const getPageAssets_js_1 = require("../runtime/renderPage/getPageAssets.js");
32
+ const resolveClientEntriesDev_js_1 = require("./resolveClientEntriesDev.js");
31
33
  (0, utils_js_2.assertNodeEnv_onVikePluginLoad)();
32
34
  (0, utils_js_2.markEnvAsVikePluginLoaded)();
33
35
  assertViteVersion();
36
+ (0, getPageAssets_js_1.setResolveClientEntriesDev)(resolveClientEntriesDev_js_1.resolveClientEntriesDev);
34
37
  // Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
35
38
  function plugin(vikeConfig) {
36
39
  const plugins = [
@@ -26,15 +26,16 @@ async function getConfigVikPromise(vikeConfig, config) {
26
26
  const fromPluginOptions = (vikeConfig ?? {});
27
27
  const fromViteConfig = (config.vike ?? {});
28
28
  const configs = [fromPluginOptions, fromViteConfig];
29
- const { globalVikeConfig: fromPlusConfigFile } = await (0, getVikeConfig_js_1.getVikeConfig)(config, (0, utils_js_1.isDev2)(config));
29
+ (0, assertVikeConfig_js_1.assertVikeConfig)(fromViteConfig, ({ prop, errMsg }) => `vite.config.js#vike.${prop} ${errMsg}`);
30
+ // TODO/v1-release: deprecate this
31
+ (0, assertVikeConfig_js_1.assertVikeConfig)(fromPluginOptions, ({ prop, errMsg }) => `vite.config.js > vike option ${prop} ${errMsg}`);
32
+ const crawlWithGit = fromPluginOptions.crawl?.git ?? null;
33
+ const { globalVikeConfig: fromPlusConfigFile } = await (0, getVikeConfig_js_1.getVikeConfig)(config, (0, utils_js_1.isDev2)(config), { crawlWithGit });
30
34
  configs.push(fromPlusConfigFile);
31
35
  (0, assertVikeConfig_js_1.assertVikeConfig)(fromPlusConfigFile, ({ prop, errMsg }) => {
32
36
  // TODO: add config file path ?
33
37
  return `config ${picocolors_1.default.cyan(prop)} ${errMsg}`;
34
38
  });
35
- (0, assertVikeConfig_js_1.assertVikeConfig)(fromViteConfig, ({ prop, errMsg }) => `vite.config.js#vike.${prop} ${errMsg}`);
36
- // TODO/v1-release: deprecate this
37
- (0, assertVikeConfig_js_1.assertVikeConfig)(fromPluginOptions, ({ prop, errMsg }) => `vite.config.js > vike option ${prop} ${errMsg}`);
38
39
  const { baseServer, baseAssets } = (0, resolveBase_js_1.resolveBase)(configs, config);
39
40
  const configVike = {
40
41
  disableAutoFullBuild: (0, pickFirst_js_1.pickFirst)(configs.map((c) => c.disableAutoFullBuild)) ?? null,
@@ -44,7 +45,10 @@ async function getConfigVikPromise(vikeConfig, config) {
44
45
  baseAssets,
45
46
  redirects: merge(configs.map((c) => c.redirects)) ?? {},
46
47
  disableUrlNormalization: (0, pickFirst_js_1.pickFirst)(configs.map((c) => c.disableUrlNormalization)) ?? false,
47
- trailingSlash: (0, pickFirst_js_1.pickFirst)(configs.map((c) => c.trailingSlash)) ?? false
48
+ trailingSlash: (0, pickFirst_js_1.pickFirst)(configs.map((c) => c.trailingSlash)) ?? false,
49
+ crawl: {
50
+ git: crawlWithGit
51
+ }
48
52
  };
49
53
  return configVike;
50
54
  }
@@ -79,7 +79,7 @@ function devConfig() {
79
79
  if (config.server.middlewareMode || hasHonoViteDevServer)
80
80
  return;
81
81
  return () => {
82
- (0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares);
82
+ (0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares, config, false);
83
83
  };
84
84
  }
85
85
  },
@@ -15,7 +15,7 @@ const execA = (0, util_1.promisify)(child_process_1.exec);
15
15
  (0, utils_js_1.assertIsNotProductionRuntime)();
16
16
  (0, utils_js_1.assertIsSingleModuleInstance)('crawlPlusFiles.ts');
17
17
  let gitIsNotUsable = false;
18
- async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
18
+ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, crawlWithGit) {
19
19
  (0, utils_js_1.assertPosixPath)(userRootDir);
20
20
  (0, utils_js_1.assertPosixPath)(outDirAbsoluteFilesystem);
21
21
  let outDirRelativeFromUserRootDir = path_1.default.posix.relative(userRootDir, outDirAbsoluteFilesystem);
@@ -33,7 +33,7 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
33
33
  const timeBefore = new Date().getTime();
34
34
  // Crawl
35
35
  let files = [];
36
- const res = await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir);
36
+ const res = crawlWithGit !== false && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
37
37
  if (res &&
38
38
  // Fallback to fast-glob for users that dynamically generate plus files. (Assuming all (generetad) plus files to be skipped because users usually included them in `.gitignore`.)
39
39
  res.length > 0) {
@@ -42,6 +42,8 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
42
42
  else {
43
43
  files = await fastGlob(userRootDir, outDirRelativeFromUserRootDir);
44
44
  }
45
+ // Filter build files
46
+ files = files.filter((file) => !(0, transpileAndExecuteFile_js_1.isTemporaryBuildFile)(file));
45
47
  // Check performance
46
48
  {
47
49
  const timeAfter = new Date().getTime();
@@ -59,7 +61,6 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
59
61
  // Both `$ git-ls files` and fast-glob return posix paths
60
62
  (0, utils_js_1.assertPosixPath)(filePath);
61
63
  (0, utils_js_1.assert)(!filePath.startsWith(userRootDir));
62
- (0, utils_js_1.assert)(!(0, transpileAndExecuteFile_js_1.isTemporaryBuildFile)(filePath));
63
64
  const filePathAbsoluteUserRootDir = path_1.default.posix.join('/', filePath);
64
65
  return { filePathAbsoluteUserRootDir };
65
66
  });
@@ -21,6 +21,7 @@ const loadFileAtConfigTime_js_1 = require("./getVikeConfig/loadFileAtConfigTime.
21
21
  const resolvePointerImport_js_1 = require("./getVikeConfig/resolvePointerImport.js");
22
22
  const getFilePath_js_1 = require("../../../shared/getFilePath.js");
23
23
  const getConfigValueBuildTime_js_1 = require("../../../../../shared/page-configs/getConfigValueBuildTime.js");
24
+ const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
24
25
  (0, utils_js_1.assertIsNotProductionRuntime)();
25
26
  let devServerIsCorrupt = false;
26
27
  let wasConfigInvalid = null;
@@ -65,11 +66,12 @@ async function handleReloadSideEffects() {
65
66
  }
66
67
  }
67
68
  }
68
- async function getVikeConfig(config, isDev, tolerateInvalidConfig) {
69
+ async function getVikeConfig(config, isDev, { crawlWithGit, tolerateInvalidConfig } = {}) {
69
70
  const { outDirRoot } = (0, utils_js_1.getOutDirs)(config);
70
71
  const userRootDir = config.root;
71
72
  if (!vikeConfigPromise) {
72
- vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, tolerateInvalidConfig);
73
+ const crawlWithGit_ = crawlWithGit !== undefined ? crawlWithGit : (await (0, getConfigVike_js_1.getConfigVike)(config)).crawl.git;
74
+ vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, crawlWithGit_, tolerateInvalidConfig);
73
75
  }
74
76
  return await vikeConfigPromise;
75
77
  }
@@ -81,8 +83,8 @@ async function isV1Design(config, isDev) {
81
83
  return isV1Design;
82
84
  }
83
85
  exports.isV1Design = isV1Design;
84
- async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
85
- const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev);
86
+ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit) {
87
+ const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
86
88
  const configFiles = [];
87
89
  const valueFiles = [];
88
90
  plusFiles.forEach((f) => {
@@ -213,12 +215,12 @@ function assertAllConfigsAreKnown(interfaceFilesByLocationId) {
213
215
  });
214
216
  });
215
217
  }
216
- async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, tolerateInvalidConfig) {
218
+ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, crawlWithGit, tolerateInvalidConfig) {
217
219
  let hasError = false;
218
220
  let ret;
219
221
  let err;
220
222
  try {
221
- ret = await loadVikeConfig(userRootDir, outDirRoot, isDev);
223
+ ret = await loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit);
222
224
  }
223
225
  catch (err_) {
224
226
  hasError = true;
@@ -255,8 +257,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
255
257
  }
256
258
  }
257
259
  }
258
- async function loadVikeConfig(userRootDir, outDirRoot, isDev) {
259
- const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev);
260
+ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
261
+ const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
260
262
  const importedFilesLoaded = {};
261
263
  const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
262
264
  const pageConfigs = await Promise.all((0, utils_js_1.objectEntries)(interfaceFilesByLocationId)
@@ -770,8 +772,8 @@ function getComputed(configValueSources, configDefinitions) {
770
772
  });
771
773
  return configValuesComputed;
772
774
  }
773
- async function findPlusFiles(userRootDir, outDirRoot, isDev) {
774
- const files = await (0, crawlPlusFiles_js_1.crawlPlusFiles)(userRootDir, outDirRoot, isDev);
775
+ async function findPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit) {
776
+ const files = await (0, crawlPlusFiles_js_1.crawlPlusFiles)(userRootDir, outDirRoot, isDev, crawlWithGit);
775
777
  const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir }));
776
778
  return plusFiles;
777
779
  }
@@ -21,7 +21,7 @@ async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
21
21
  }
22
22
  */
23
23
  const { pageId, isForClientSide } = result;
24
- const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config, isDev, true);
24
+ const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config, isDev, { tolerateInvalidConfig: true });
25
25
  const pageConfig = pageConfigs.find((pageConfig) => pageConfig.pageId === pageId);
26
26
  (0, utils_js_1.assert)(pageConfig);
27
27
  const configVike = await (0, getConfigVike_js_1.getConfigVike)(config);
@@ -7,7 +7,7 @@ const getVikeConfig_js_1 = require("./getVikeConfig.js");
7
7
  const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
8
8
  const serializeConfigValues_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValues.js");
9
9
  async function getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, config) {
10
- const { pageConfigs, pageConfigGlobal } = await (0, getVikeConfig_js_1.getVikeConfig)(config, isDev, true);
10
+ const { pageConfigs, pageConfigGlobal } = await (0, getVikeConfig_js_1.getVikeConfig)(config, isDev, { tolerateInvalidConfig: true });
11
11
  return getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
12
12
  }
13
13
  exports.getVirtualFilePageConfigs = getVirtualFilePageConfigs;
@@ -38,10 +38,10 @@ function previewConfig() {
38
38
  assertDist();
39
39
  /* 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'`.
40
40
  if (!configVike.prerender || configVike.prerender.partial) {
41
- addSsrMiddleware(server.middlewares)
41
+ addSsrMiddleware(server.middlewares, config, true)
42
42
  }
43
43
  /*/
44
- (0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares);
44
+ (0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares, config, true);
45
45
  //*/
46
46
  addStatic404Middleware(server.middlewares);
47
47
  };
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveClientEntriesDev = void 0;
4
+ const utils_js_1 = require("./utils.js");
5
+ const module_1 = require("module");
6
+ const path_1 = require("path");
7
+ const url_1 = require("url");
8
+ // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
9
+ const importMetaUrl = `file://${__filename}`;
10
+ const require_ = (0, module_1.createRequire)(importMetaUrl);
11
+ const __dirname_ = (0, path_1.dirname)((0, url_1.fileURLToPath)(importMetaUrl));
12
+ (0, utils_js_1.assertIsNotProductionRuntime)();
13
+ async function resolveClientEntriesDev(clientEntry, viteDevServer) {
14
+ let root = viteDevServer.config.root;
15
+ (0, utils_js_1.assert)(root);
16
+ root = (0, utils_js_1.toPosixPath)(root);
17
+ // The `?import` suffix is needed for MDX to be transpiled:
18
+ // - Not transpiled: `/pages/markdown.page.mdx`
19
+ // - Transpiled: `/pages/markdown.page.mdx?import`
20
+ // But `?import` doesn't work with `/@fs/`:
21
+ // - Not transpiled: /@fs/home/runner/work/vike/vike/examples/react-full/pages/markdown.page.mdx
22
+ // - Not transpiled: /@fs/home/runner/work/vike/vike/examples/react-full/pages/markdown.page.mdx?import
23
+ if (clientEntry.endsWith('?import')) {
24
+ (0, utils_js_1.assert)(clientEntry.startsWith('/'));
25
+ return clientEntry;
26
+ }
27
+ (0, utils_js_1.assertPosixPath)(clientEntry);
28
+ let filePath;
29
+ if (clientEntry.startsWith('/')) {
30
+ filePath = (0, utils_js_1.pathJoin)(root, clientEntry);
31
+ }
32
+ else {
33
+ if (clientEntry.startsWith('@@vike/')) {
34
+ (0, utils_js_1.assert)(clientEntry.endsWith('.js'));
35
+ try {
36
+ // For Vitest (which doesn't resolve vike to its dist but to its source files)
37
+ // [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/node/plugin/resolveClientEntriesDev.js
38
+ filePath = (0, utils_js_1.toPosixPath)(require_.resolve(clientEntry.replace('@@vike/dist/esm/client/', '../../client/').replace('.js', '.ts')));
39
+ }
40
+ catch {
41
+ // For users
42
+ // [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/resolveClientEntriesDev.js
43
+ filePath = (0, utils_js_1.toPosixPath)(require_.resolve(clientEntry.replace('@@vike/dist/esm/client/', '../../../../dist/esm/client/')));
44
+ }
45
+ }
46
+ else {
47
+ (0, utils_js_1.assertIsNpmPackageImport)(clientEntry);
48
+ filePath = require_.resolve(clientEntry);
49
+ }
50
+ }
51
+ if (!filePath.startsWith('/')) {
52
+ (0, utils_js_1.assert)(process.platform === 'win32');
53
+ filePath = '/' + filePath;
54
+ }
55
+ filePath = '/@fs' + filePath;
56
+ (0, utils_js_1.assertPosixPath)(filePath);
57
+ return filePath;
58
+ }
59
+ exports.resolveClientEntriesDev = resolveClientEntriesDev;
@@ -7,7 +7,7 @@ exports.addSsrMiddleware = void 0;
7
7
  const renderPage_js_1 = require("../../runtime/renderPage.js");
8
8
  const utils_js_1 = require("../utils.js");
9
9
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
- function addSsrMiddleware(middlewares) {
10
+ function addSsrMiddleware(middlewares, config, isPreview) {
11
11
  middlewares.use(async (req, res, next) => {
12
12
  if (res.headersSent)
13
13
  return next();
@@ -42,6 +42,12 @@ function addSsrMiddleware(middlewares) {
42
42
  // - We purposely don't use next(err) to align behavior: we use our own/copied implementation of buildErrorMessage() regardless of whether the user uses Vite's dev middleware or Vite's standalone dev server
43
43
  return next();
44
44
  }
45
+ const configHeaders = (isPreview && config?.preview?.headers) || config?.server?.headers;
46
+ if (configHeaders) {
47
+ for (const [name, value] of Object.entries(configHeaders))
48
+ if (value)
49
+ res.setHeader(name, value);
50
+ }
45
51
  if (!pageContext.httpResponse) {
46
52
  return next();
47
53
  }
@@ -35,7 +35,7 @@ function serializePageContextClientSide(pageContext) {
35
35
  pageContextClient[prop] = pageContext[prop];
36
36
  });
37
37
  if (Object.keys(pageContext._pageContextInit).some((p) => passToClient.includes(p))) {
38
- pageContextClient._pageContextInitIsPassedToClient = true;
38
+ pageContextClient[pageContextInitIsPassedToClient_js_1.pageContextInitIsPassedToClient] = true;
39
39
  }
40
40
  let pageContextSerialized;
41
41
  try {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPageAssets = void 0;
3
+ exports.setResolveClientEntriesDev = exports.getPageAssets = void 0;
4
4
  const utils_js_1 = require("../utils.js");
5
5
  const retrieveAssetsDev_js_1 = require("./getPageAssets/retrieveAssetsDev.js");
6
6
  const retrieveAssetsProd_js_1 = require("./getPageAssets/retrieveAssetsProd.js");
@@ -8,7 +8,9 @@ const inferMediaType_js_1 = require("./inferMediaType.js");
8
8
  const getManifestEntry_js_1 = require("./getPageAssets/getManifestEntry.js");
9
9
  const sortPageAssetsForEarlyHintsHeader_js_1 = require("./getPageAssets/sortPageAssetsForEarlyHintsHeader.js");
10
10
  const globalContext_js_1 = require("../globalContext.js");
11
- const import_1 = require("@brillout/import");
11
+ const globalObject = (0, utils_js_1.getGlobalObject)('getPageAssets.ts', {
12
+ resolveClientEntriesDev: null
13
+ });
12
14
  async function getPageAssets(pageContext, clientDependencies, clientEntries) {
13
15
  const globalContext = (0, globalContext_js_1.getGlobalContext)();
14
16
  const isDev = !globalContext.isProduction;
@@ -16,7 +18,7 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
16
18
  let clientEntriesSrc;
17
19
  if (isDev) {
18
20
  const { viteDevServer } = globalContext;
19
- clientEntriesSrc = await Promise.all(clientEntries.map((clientEntry) => resolveClientEntriesDev(clientEntry, viteDevServer)));
21
+ clientEntriesSrc = await Promise.all(clientEntries.map((clientEntry) => globalObject.resolveClientEntriesDev(clientEntry, viteDevServer)));
20
22
  assetUrls = await (0, retrieveAssetsDev_js_1.retrieveAssetsDev)(clientDependencies, viteDevServer);
21
23
  }
22
24
  else {
@@ -57,62 +59,6 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
57
59
  return pageAssets;
58
60
  }
59
61
  exports.getPageAssets = getPageAssets;
60
- async function resolveClientEntriesDev(clientEntry, viteDevServer) {
61
- let root = viteDevServer.config.root;
62
- (0, utils_js_1.assert)(root);
63
- root = (0, utils_js_1.toPosixPath)(root);
64
- // The `?import` suffix is needed for MDX to be transpiled:
65
- // - Not transpiled: `/pages/markdown.page.mdx`
66
- // - Transpiled: `/pages/markdown.page.mdx?import`
67
- // But `?import` doesn't work with `/@fs/`:
68
- // - Not transpiled: /@fs/home/runner/work/vike/vike/examples/react-full/pages/markdown.page.mdx
69
- // - Not transpiled: /@fs/home/runner/work/vike/vike/examples/react-full/pages/markdown.page.mdx?import
70
- if (clientEntry.endsWith('?import')) {
71
- (0, utils_js_1.assert)(clientEntry.startsWith('/'));
72
- return clientEntry;
73
- }
74
- (0, utils_js_1.assertPosixPath)(clientEntry);
75
- let filePath;
76
- if (clientEntry.startsWith('/')) {
77
- filePath = (0, utils_js_1.pathJoin)(root, clientEntry);
78
- }
79
- else {
80
- const { createRequire } = (await (0, import_1.import_)('module')).default;
81
- const { dirname } = (await (0, import_1.import_)('path')).default;
82
- const { fileURLToPath } = (await (0, import_1.import_)('url')).default;
83
- // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
84
- const importMetaUrl = `file://${__filename}`;
85
- const require_ = createRequire(importMetaUrl);
86
- const __dirname_ = dirname(fileURLToPath(importMetaUrl));
87
- // @ts-expect-error
88
- // Bun workaround https://github.com/vikejs/vike/pull/1048
89
- const res = typeof Bun !== 'undefined' ? (toPath) => Bun.resolveSync(toPath, __dirname_) : require_.resolve;
90
- if (clientEntry.startsWith('@@vike/')) {
91
- (0, utils_js_1.assert)(clientEntry.endsWith('.js'));
92
- try {
93
- // For Vitest (which doesn't resolve vike to its dist but to its source files)
94
- // [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/node/runtime/renderPage/getPageAssets.js
95
- filePath = (0, utils_js_1.toPosixPath)(res(clientEntry.replace('@@vike/dist/esm/client/', '../../../client/').replace('.js', '.ts')));
96
- }
97
- catch {
98
- // For users
99
- // [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/runtime/renderPage/getPageAssets.js
100
- filePath = (0, utils_js_1.toPosixPath)(res(clientEntry.replace('@@vike/dist/esm/client/', '../../../../../dist/esm/client/')));
101
- }
102
- }
103
- else {
104
- (0, utils_js_1.assertIsNpmPackageImport)(clientEntry);
105
- filePath = res(clientEntry);
106
- }
107
- }
108
- if (!filePath.startsWith('/')) {
109
- (0, utils_js_1.assert)(process.platform === 'win32');
110
- filePath = '/' + filePath;
111
- }
112
- filePath = '/@fs' + filePath;
113
- (0, utils_js_1.assertPosixPath)(filePath);
114
- return filePath;
115
- }
116
62
  function resolveClientEntriesProd(clientEntry, assetsManifest) {
117
63
  const { manifestEntry } = (0, getManifestEntry_js_1.getManifestEntry)(clientEntry, assetsManifest);
118
64
  (0, utils_js_1.assert)(manifestEntry.isEntry || manifestEntry.isDynamicEntry || clientEntry.endsWith('.css'), { clientEntry });
@@ -120,3 +66,7 @@ function resolveClientEntriesProd(clientEntry, assetsManifest) {
120
66
  (0, utils_js_1.assert)(!file.startsWith('/'));
121
67
  return '/' + file;
122
68
  }
69
+ function setResolveClientEntriesDev(resolveClientEntriesDev) {
70
+ globalObject.resolveClientEntriesDev = resolveClientEntriesDev;
71
+ }
72
+ exports.setResolveClientEntriesDev = setResolveClientEntriesDev;
@@ -37,9 +37,9 @@ function assert(condition, debugInfo) {
37
37
  const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
38
38
  return picocolors_1.default.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
39
39
  })();
40
+ const link = picocolors_1.default.blue('https://github.com/vikejs/vike/issues/new');
40
41
  let errMsg = [
41
- `You stumbled upon a Vike bug.`,
42
- `Go to ${picocolors_1.default.blue('https://github.com/vikejs/vike/issues/new')} and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).`,
42
+ `You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).`,
43
43
  debugStr
44
44
  ]
45
45
  .filter(Boolean)
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = exports.projectInfo = void 0;
4
- const PROJECT_VERSION = '0.4.172-commit-ea2b76c';
4
+ const PROJECT_VERSION = '0.4.172-commit-605b4a5';
5
5
  exports.PROJECT_VERSION = PROJECT_VERSION;
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
@@ -24,9 +24,12 @@ import { baseUrls } from './plugins/baseUrls.js';
24
24
  import { envVarsPlugin } from './plugins/envVars.js';
25
25
  import pc from '@brillout/picocolors';
26
26
  import { fileEnv } from './plugins/fileEnv.js';
27
+ import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.js';
28
+ import { resolveClientEntriesDev } from './resolveClientEntriesDev.js';
27
29
  assertNodeEnv_onVikePluginLoad();
28
30
  markEnvAsVikePluginLoaded();
29
31
  assertViteVersion();
32
+ setResolveClientEntriesDev(resolveClientEntriesDev);
30
33
  // Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
31
34
  function plugin(vikeConfig) {
32
35
  const plugins = [
@@ -20,15 +20,16 @@ async function getConfigVikPromise(vikeConfig, config) {
20
20
  const fromPluginOptions = (vikeConfig ?? {});
21
21
  const fromViteConfig = (config.vike ?? {});
22
22
  const configs = [fromPluginOptions, fromViteConfig];
23
- const { globalVikeConfig: fromPlusConfigFile } = await getVikeConfig(config, isDev2(config));
23
+ assertVikeConfig(fromViteConfig, ({ prop, errMsg }) => `vite.config.js#vike.${prop} ${errMsg}`);
24
+ // TODO/v1-release: deprecate this
25
+ assertVikeConfig(fromPluginOptions, ({ prop, errMsg }) => `vite.config.js > vike option ${prop} ${errMsg}`);
26
+ const crawlWithGit = fromPluginOptions.crawl?.git ?? null;
27
+ const { globalVikeConfig: fromPlusConfigFile } = await getVikeConfig(config, isDev2(config), { crawlWithGit });
24
28
  configs.push(fromPlusConfigFile);
25
29
  assertVikeConfig(fromPlusConfigFile, ({ prop, errMsg }) => {
26
30
  // TODO: add config file path ?
27
31
  return `config ${pc.cyan(prop)} ${errMsg}`;
28
32
  });
29
- assertVikeConfig(fromViteConfig, ({ prop, errMsg }) => `vite.config.js#vike.${prop} ${errMsg}`);
30
- // TODO/v1-release: deprecate this
31
- assertVikeConfig(fromPluginOptions, ({ prop, errMsg }) => `vite.config.js > vike option ${prop} ${errMsg}`);
32
33
  const { baseServer, baseAssets } = resolveBase(configs, config);
33
34
  const configVike = {
34
35
  disableAutoFullBuild: pickFirst(configs.map((c) => c.disableAutoFullBuild)) ?? null,
@@ -38,7 +39,10 @@ async function getConfigVikPromise(vikeConfig, config) {
38
39
  baseAssets,
39
40
  redirects: merge(configs.map((c) => c.redirects)) ?? {},
40
41
  disableUrlNormalization: pickFirst(configs.map((c) => c.disableUrlNormalization)) ?? false,
41
- trailingSlash: pickFirst(configs.map((c) => c.trailingSlash)) ?? false
42
+ trailingSlash: pickFirst(configs.map((c) => c.trailingSlash)) ?? false,
43
+ crawl: {
44
+ git: crawlWithGit
45
+ }
42
46
  };
43
47
  return configVike;
44
48
  }
@@ -77,7 +77,7 @@ function devConfig() {
77
77
  if (config.server.middlewareMode || hasHonoViteDevServer)
78
78
  return;
79
79
  return () => {
80
- addSsrMiddleware(server.middlewares);
80
+ addSsrMiddleware(server.middlewares, config, false);
81
81
  };
82
82
  }
83
83
  },
@@ -1,4 +1,4 @@
1
1
  export { crawlPlusFiles };
2
- declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: string, isDev: boolean): Promise<{
2
+ declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: string, isDev: boolean, crawlWithGit: null | boolean): Promise<{
3
3
  filePathAbsoluteUserRootDir: string;
4
4
  }[]>;
@@ -10,7 +10,7 @@ const execA = promisify(exec);
10
10
  assertIsNotProductionRuntime();
11
11
  assertIsSingleModuleInstance('crawlPlusFiles.ts');
12
12
  let gitIsNotUsable = false;
13
- async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
13
+ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, crawlWithGit) {
14
14
  assertPosixPath(userRootDir);
15
15
  assertPosixPath(outDirAbsoluteFilesystem);
16
16
  let outDirRelativeFromUserRootDir = path.posix.relative(userRootDir, outDirAbsoluteFilesystem);
@@ -28,7 +28,7 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
28
28
  const timeBefore = new Date().getTime();
29
29
  // Crawl
30
30
  let files = [];
31
- const res = await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir);
31
+ const res = crawlWithGit !== false && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
32
32
  if (res &&
33
33
  // Fallback to fast-glob for users that dynamically generate plus files. (Assuming all (generetad) plus files to be skipped because users usually included them in `.gitignore`.)
34
34
  res.length > 0) {
@@ -37,6 +37,8 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
37
37
  else {
38
38
  files = await fastGlob(userRootDir, outDirRelativeFromUserRootDir);
39
39
  }
40
+ // Filter build files
41
+ files = files.filter((file) => !isTemporaryBuildFile(file));
40
42
  // Check performance
41
43
  {
42
44
  const timeAfter = new Date().getTime();
@@ -54,7 +56,6 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
54
56
  // Both `$ git-ls files` and fast-glob return posix paths
55
57
  assertPosixPath(filePath);
56
58
  assert(!filePath.startsWith(userRootDir));
57
- assert(!isTemporaryBuildFile(filePath));
58
59
  const filePathAbsoluteUserRootDir = path.posix.join('/', filePath);
59
60
  return { filePathAbsoluteUserRootDir };
60
61
  });
@@ -29,6 +29,9 @@ type VikeConfigObject = {
29
29
  };
30
30
  declare const vikeConfigDependencies: Set<string>;
31
31
  declare function reloadVikeConfig(userRootDir: string, outDirRoot: string): void;
32
- declare function getVikeConfig(config: ResolvedConfig, isDev: boolean, tolerateInvalidConfig?: true): Promise<VikeConfigObject>;
32
+ declare function getVikeConfig(config: ResolvedConfig, isDev: boolean, { crawlWithGit, tolerateInvalidConfig }?: {
33
+ crawlWithGit?: null | boolean;
34
+ tolerateInvalidConfig?: true;
35
+ }): Promise<VikeConfigObject>;
33
36
  declare function isV1Design(config: ResolvedConfig, isDev: boolean): Promise<boolean>;
34
37
  declare function isVikeConfigFile(filePath: string): boolean;
@@ -20,6 +20,7 @@ import { loadConfigFile, loadImportedFile, loadValueFile } from './getVikeConfig
20
20
  import { clearFilesEnvMap, resolvePointerImportOfConfig } from './getVikeConfig/resolvePointerImport.js';
21
21
  import { getFilePathResolved } from '../../../shared/getFilePath.js';
22
22
  import { getConfigValueBuildTime } from '../../../../../shared/page-configs/getConfigValueBuildTime.js';
23
+ import { getConfigVike } from '../../../../shared/getConfigVike.js';
23
24
  assertIsNotProductionRuntime();
24
25
  let devServerIsCorrupt = false;
25
26
  let wasConfigInvalid = null;
@@ -62,11 +63,12 @@ async function handleReloadSideEffects() {
62
63
  }
63
64
  }
64
65
  }
65
- async function getVikeConfig(config, isDev, tolerateInvalidConfig) {
66
+ async function getVikeConfig(config, isDev, { crawlWithGit, tolerateInvalidConfig } = {}) {
66
67
  const { outDirRoot } = getOutDirs(config);
67
68
  const userRootDir = config.root;
68
69
  if (!vikeConfigPromise) {
69
- vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, tolerateInvalidConfig);
70
+ const crawlWithGit_ = crawlWithGit !== undefined ? crawlWithGit : (await getConfigVike(config)).crawl.git;
71
+ vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, crawlWithGit_, tolerateInvalidConfig);
70
72
  }
71
73
  return await vikeConfigPromise;
72
74
  }
@@ -76,8 +78,8 @@ async function isV1Design(config, isDev) {
76
78
  const isV1Design = pageConfigs.length > 0;
77
79
  return isV1Design;
78
80
  }
79
- async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
80
- const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev);
81
+ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit) {
82
+ const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
81
83
  const configFiles = [];
82
84
  const valueFiles = [];
83
85
  plusFiles.forEach((f) => {
@@ -208,12 +210,12 @@ function assertAllConfigsAreKnown(interfaceFilesByLocationId) {
208
210
  });
209
211
  });
210
212
  }
211
- async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, tolerateInvalidConfig) {
213
+ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, crawlWithGit, tolerateInvalidConfig) {
212
214
  let hasError = false;
213
215
  let ret;
214
216
  let err;
215
217
  try {
216
- ret = await loadVikeConfig(userRootDir, outDirRoot, isDev);
218
+ ret = await loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit);
217
219
  }
218
220
  catch (err_) {
219
221
  hasError = true;
@@ -250,8 +252,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
250
252
  }
251
253
  }
252
254
  }
253
- async function loadVikeConfig(userRootDir, outDirRoot, isDev) {
254
- const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev);
255
+ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
256
+ const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
255
257
  const importedFilesLoaded = {};
256
258
  const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
257
259
  const pageConfigs = await Promise.all(objectEntries(interfaceFilesByLocationId)
@@ -765,8 +767,8 @@ function getComputed(configValueSources, configDefinitions) {
765
767
  });
766
768
  return configValuesComputed;
767
769
  }
768
- async function findPlusFiles(userRootDir, outDirRoot, isDev) {
769
- const files = await crawlPlusFiles(userRootDir, outDirRoot, isDev);
770
+ async function findPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit) {
771
+ const files = await crawlPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
770
772
  const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir }));
771
773
  return plusFiles;
772
774
  }
@@ -19,7 +19,7 @@ async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
19
19
  }
20
20
  */
21
21
  const { pageId, isForClientSide } = result;
22
- const { pageConfigs } = await getVikeConfig(config, isDev, true);
22
+ const { pageConfigs } = await getVikeConfig(config, isDev, { tolerateInvalidConfig: true });
23
23
  const pageConfig = pageConfigs.find((pageConfig) => pageConfig.pageId === pageId);
24
24
  assert(pageConfig);
25
25
  const configVike = await getConfigVike(config);
@@ -5,7 +5,7 @@ import { getVikeConfig } from './getVikeConfig.js';
5
5
  import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
6
6
  import { serializeConfigValues } from '../../../../../shared/page-configs/serialize/serializeConfigValues.js';
7
7
  async function getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, config) {
8
- const { pageConfigs, pageConfigGlobal } = await getVikeConfig(config, isDev, true);
8
+ const { pageConfigs, pageConfigGlobal } = await getVikeConfig(config, isDev, { tolerateInvalidConfig: true });
9
9
  return getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
10
10
  }
11
11
  function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting) {
@@ -33,10 +33,10 @@ function previewConfig() {
33
33
  assertDist();
34
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'`.
35
35
  if (!configVike.prerender || configVike.prerender.partial) {
36
- addSsrMiddleware(server.middlewares)
36
+ addSsrMiddleware(server.middlewares, config, true)
37
37
  }
38
38
  /*/
39
- addSsrMiddleware(server.middlewares);
39
+ addSsrMiddleware(server.middlewares, config, true);
40
40
  //*/
41
41
  addStatic404Middleware(server.middlewares);
42
42
  };
@@ -0,0 +1,4 @@
1
+ export { resolveClientEntriesDev };
2
+ export type ResolveClientEntriesDev = typeof resolveClientEntriesDev;
3
+ import type { ViteDevServer } from 'vite';
4
+ declare function resolveClientEntriesDev(clientEntry: string, viteDevServer: ViteDevServer): Promise<string>;
@@ -0,0 +1,56 @@
1
+ export { resolveClientEntriesDev };
2
+ import { assert, assertPosixPath, toPosixPath, pathJoin, assertIsNpmPackageImport, assertIsNotProductionRuntime } from './utils.js';
3
+ import { createRequire } from 'module';
4
+ import { dirname } from 'path';
5
+ import { fileURLToPath } from 'url';
6
+ // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
7
+ const importMetaUrl = import.meta.url;
8
+ const require_ = createRequire(importMetaUrl);
9
+ const __dirname_ = dirname(fileURLToPath(importMetaUrl));
10
+ assertIsNotProductionRuntime();
11
+ async function resolveClientEntriesDev(clientEntry, viteDevServer) {
12
+ let root = viteDevServer.config.root;
13
+ assert(root);
14
+ root = toPosixPath(root);
15
+ // The `?import` suffix is needed for MDX to be transpiled:
16
+ // - Not transpiled: `/pages/markdown.page.mdx`
17
+ // - Transpiled: `/pages/markdown.page.mdx?import`
18
+ // But `?import` doesn't work with `/@fs/`:
19
+ // - Not transpiled: /@fs/home/runner/work/vike/vike/examples/react-full/pages/markdown.page.mdx
20
+ // - Not transpiled: /@fs/home/runner/work/vike/vike/examples/react-full/pages/markdown.page.mdx?import
21
+ if (clientEntry.endsWith('?import')) {
22
+ assert(clientEntry.startsWith('/'));
23
+ return clientEntry;
24
+ }
25
+ assertPosixPath(clientEntry);
26
+ let filePath;
27
+ if (clientEntry.startsWith('/')) {
28
+ filePath = pathJoin(root, clientEntry);
29
+ }
30
+ else {
31
+ if (clientEntry.startsWith('@@vike/')) {
32
+ assert(clientEntry.endsWith('.js'));
33
+ try {
34
+ // For Vitest (which doesn't resolve vike to its dist but to its source files)
35
+ // [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/node/plugin/resolveClientEntriesDev.js
36
+ filePath = toPosixPath(require_.resolve(clientEntry.replace('@@vike/dist/esm/client/', '../../client/').replace('.js', '.ts')));
37
+ }
38
+ catch {
39
+ // For users
40
+ // [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/resolveClientEntriesDev.js
41
+ filePath = toPosixPath(require_.resolve(clientEntry.replace('@@vike/dist/esm/client/', '../../../../dist/esm/client/')));
42
+ }
43
+ }
44
+ else {
45
+ assertIsNpmPackageImport(clientEntry);
46
+ filePath = require_.resolve(clientEntry);
47
+ }
48
+ }
49
+ if (!filePath.startsWith('/')) {
50
+ assert(process.platform === 'win32');
51
+ filePath = '/' + filePath;
52
+ }
53
+ filePath = '/@fs' + filePath;
54
+ assertPosixPath(filePath);
55
+ return filePath;
56
+ }
@@ -1,4 +1,4 @@
1
1
  export { addSsrMiddleware };
2
- import type { ViteDevServer } from 'vite';
2
+ import type { ResolvedConfig, ViteDevServer } from 'vite';
3
3
  type ConnectServer = ViteDevServer['middlewares'];
4
- declare function addSsrMiddleware(middlewares: ConnectServer): void;
4
+ declare function addSsrMiddleware(middlewares: ConnectServer, config: ResolvedConfig, isPreview: boolean): void;
@@ -2,7 +2,7 @@ export { addSsrMiddleware };
2
2
  import { renderPage } from '../../runtime/renderPage.js';
3
3
  import { assertWarning } from '../utils.js';
4
4
  import pc from '@brillout/picocolors';
5
- function addSsrMiddleware(middlewares) {
5
+ function addSsrMiddleware(middlewares, config, isPreview) {
6
6
  middlewares.use(async (req, res, next) => {
7
7
  if (res.headersSent)
8
8
  return next();
@@ -37,6 +37,12 @@ function addSsrMiddleware(middlewares) {
37
37
  // - We purposely don't use next(err) to align behavior: we use our own/copied implementation of buildErrorMessage() regardless of whether the user uses Vite's dev middleware or Vite's standalone dev server
38
38
  return next();
39
39
  }
40
+ const configHeaders = (isPreview && config?.preview?.headers) || config?.server?.headers;
41
+ if (configHeaders) {
42
+ for (const [name, value] of Object.entries(configHeaders))
43
+ if (value)
44
+ res.setHeader(name, value);
45
+ }
40
46
  if (!pageContext.httpResponse) {
41
47
  return next();
42
48
  }
@@ -31,7 +31,7 @@ function serializePageContextClientSide(pageContext) {
31
31
  pageContextClient[prop] = pageContext[prop];
32
32
  });
33
33
  if (Object.keys(pageContext._pageContextInit).some((p) => passToClient.includes(p))) {
34
- pageContextClient._pageContextInitIsPassedToClient = true;
34
+ pageContextClient[pageContextInitIsPassedToClient] = true;
35
35
  }
36
36
  let pageContextSerialized;
37
37
  try {
@@ -1,9 +1,11 @@
1
1
  export { getPageAssets };
2
+ export { setResolveClientEntriesDev };
2
3
  export type { PageAsset };
3
4
  export type { GetPageAssets };
4
5
  export type { PageContextGetPageAssets };
5
6
  import { type MediaType } from './inferMediaType.js';
6
7
  import type { ClientDependency } from '../../../shared/getPageFiles/analyzePageClientSide/ClientDependency.js';
8
+ import type { ResolveClientEntriesDev } from '../../plugin/resolveClientEntriesDev.js';
7
9
  type PageAsset = {
8
10
  src: string;
9
11
  assetType: null | NonNullable<MediaType>['assetType'];
@@ -17,3 +19,4 @@ type PageContextGetPageAssets = {
17
19
  _includeAssetsImportedByServer: boolean;
18
20
  };
19
21
  declare function getPageAssets(pageContext: PageContextGetPageAssets, clientDependencies: ClientDependency[], clientEntries: string[]): Promise<PageAsset[]>;
22
+ declare function setResolveClientEntriesDev(resolveClientEntriesDev: ResolveClientEntriesDev): void;
@@ -1,12 +1,15 @@
1
1
  export { getPageAssets };
2
- import { assert, prependBase, assertPosixPath, toPosixPath, unique, pathJoin, assertIsNpmPackageImport } from '../utils.js';
2
+ export { setResolveClientEntriesDev };
3
+ import { assert, prependBase, toPosixPath, unique, getGlobalObject } from '../utils.js';
3
4
  import { retrieveAssetsDev } from './getPageAssets/retrieveAssetsDev.js';
4
5
  import { retrieveAssetsProd } from './getPageAssets/retrieveAssetsProd.js';
5
6
  import { inferMediaType } from './inferMediaType.js';
6
7
  import { getManifestEntry } from './getPageAssets/getManifestEntry.js';
7
8
  import { sortPageAssetsForEarlyHintsHeader } from './getPageAssets/sortPageAssetsForEarlyHintsHeader.js';
8
9
  import { getGlobalContext } from '../globalContext.js';
9
- import { import_ } from '@brillout/import';
10
+ const globalObject = getGlobalObject('getPageAssets.ts', {
11
+ resolveClientEntriesDev: null
12
+ });
10
13
  async function getPageAssets(pageContext, clientDependencies, clientEntries) {
11
14
  const globalContext = getGlobalContext();
12
15
  const isDev = !globalContext.isProduction;
@@ -14,7 +17,7 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
14
17
  let clientEntriesSrc;
15
18
  if (isDev) {
16
19
  const { viteDevServer } = globalContext;
17
- clientEntriesSrc = await Promise.all(clientEntries.map((clientEntry) => resolveClientEntriesDev(clientEntry, viteDevServer)));
20
+ clientEntriesSrc = await Promise.all(clientEntries.map((clientEntry) => globalObject.resolveClientEntriesDev(clientEntry, viteDevServer)));
18
21
  assetUrls = await retrieveAssetsDev(clientDependencies, viteDevServer);
19
22
  }
20
23
  else {
@@ -54,62 +57,6 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
54
57
  sortPageAssetsForEarlyHintsHeader(pageAssets);
55
58
  return pageAssets;
56
59
  }
57
- async function resolveClientEntriesDev(clientEntry, viteDevServer) {
58
- let root = viteDevServer.config.root;
59
- assert(root);
60
- root = toPosixPath(root);
61
- // The `?import` suffix is needed for MDX to be transpiled:
62
- // - Not transpiled: `/pages/markdown.page.mdx`
63
- // - Transpiled: `/pages/markdown.page.mdx?import`
64
- // But `?import` doesn't work with `/@fs/`:
65
- // - Not transpiled: /@fs/home/runner/work/vike/vike/examples/react-full/pages/markdown.page.mdx
66
- // - Not transpiled: /@fs/home/runner/work/vike/vike/examples/react-full/pages/markdown.page.mdx?import
67
- if (clientEntry.endsWith('?import')) {
68
- assert(clientEntry.startsWith('/'));
69
- return clientEntry;
70
- }
71
- assertPosixPath(clientEntry);
72
- let filePath;
73
- if (clientEntry.startsWith('/')) {
74
- filePath = pathJoin(root, clientEntry);
75
- }
76
- else {
77
- const { createRequire } = (await import_('module')).default;
78
- const { dirname } = (await import_('path')).default;
79
- const { fileURLToPath } = (await import_('url')).default;
80
- // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
81
- const importMetaUrl = import.meta.url;
82
- const require_ = createRequire(importMetaUrl);
83
- const __dirname_ = dirname(fileURLToPath(importMetaUrl));
84
- // @ts-expect-error
85
- // Bun workaround https://github.com/vikejs/vike/pull/1048
86
- const res = typeof Bun !== 'undefined' ? (toPath) => Bun.resolveSync(toPath, __dirname_) : require_.resolve;
87
- if (clientEntry.startsWith('@@vike/')) {
88
- assert(clientEntry.endsWith('.js'));
89
- try {
90
- // For Vitest (which doesn't resolve vike to its dist but to its source files)
91
- // [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/node/runtime/renderPage/getPageAssets.js
92
- filePath = toPosixPath(res(clientEntry.replace('@@vike/dist/esm/client/', '../../../client/').replace('.js', '.ts')));
93
- }
94
- catch {
95
- // For users
96
- // [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/runtime/renderPage/getPageAssets.js
97
- filePath = toPosixPath(res(clientEntry.replace('@@vike/dist/esm/client/', '../../../../../dist/esm/client/')));
98
- }
99
- }
100
- else {
101
- assertIsNpmPackageImport(clientEntry);
102
- filePath = res(clientEntry);
103
- }
104
- }
105
- if (!filePath.startsWith('/')) {
106
- assert(process.platform === 'win32');
107
- filePath = '/' + filePath;
108
- }
109
- filePath = '/@fs' + filePath;
110
- assertPosixPath(filePath);
111
- return filePath;
112
- }
113
60
  function resolveClientEntriesProd(clientEntry, assetsManifest) {
114
61
  const { manifestEntry } = getManifestEntry(clientEntry, assetsManifest);
115
62
  assert(manifestEntry.isEntry || manifestEntry.isDynamicEntry || clientEntry.endsWith('.css'), { clientEntry });
@@ -117,3 +64,6 @@ function resolveClientEntriesProd(clientEntry, assetsManifest) {
117
64
  assert(!file.startsWith('/'));
118
65
  return '/' + file;
119
66
  }
67
+ function setResolveClientEntriesDev(resolveClientEntriesDev) {
68
+ globalObject.resolveClientEntriesDev = resolveClientEntriesDev;
69
+ }
@@ -14,6 +14,9 @@ type ConfigVikeResolved = {
14
14
  redirects: Record<string, string>;
15
15
  trailingSlash: boolean;
16
16
  disableUrlNormalization: boolean;
17
+ crawl: {
18
+ git: null | boolean;
19
+ };
17
20
  };
18
21
  type ConfigVikeUserProvided = {
19
22
  /**
@@ -98,4 +101,8 @@ type ConfigVikeUserProvided = {
98
101
  * @default false
99
102
  */
100
103
  disableUrlNormalization?: boolean;
104
+ /** @experimental https://github.com/vikejs/vike/issues/1655 */
105
+ crawl?: {
106
+ git?: boolean;
107
+ };
101
108
  };
@@ -40,9 +40,9 @@ function assert(condition, debugInfo) {
40
40
  const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
41
41
  return pc.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
42
42
  })();
43
+ const link = pc.blue('https://github.com/vikejs/vike/issues/new');
43
44
  let errMsg = [
44
- `You stumbled upon a Vike bug.`,
45
- `Go to ${pc.blue('https://github.com/vikejs/vike/issues/new')} and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).`,
45
+ `You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).`,
46
46
  debugStr
47
47
  ]
48
48
  .filter(Boolean)
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- declare const PROJECT_VERSION: "0.4.172-commit-ea2b76c";
3
+ declare const PROJECT_VERSION: "0.4.172-commit-605b4a5";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.172-commit-ea2b76c";
6
+ projectVersion: "0.4.172-commit-605b4a5";
7
7
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- const PROJECT_VERSION = '0.4.172-commit-ea2b76c';
3
+ const PROJECT_VERSION = '0.4.172-commit-605b4a5';
4
4
  const projectInfo = {
5
5
  projectName: 'Vike',
6
6
  projectVersion: PROJECT_VERSION
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.172-commit-ea2b76c",
3
+ "version": "0.4.172-commit-605b4a5",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "@brillout/import": "^0.2.3",
17
17
  "@brillout/json-serializer": "^0.5.10",
18
- "@brillout/picocolors": "^1.0.10",
18
+ "@brillout/picocolors": "^1.0.13",
19
19
  "@brillout/require-shim": "^0.1.2",
20
20
  "@brillout/vite-plugin-server-entry": "^0.4.5",
21
21
  "acorn": "^8.0.0",
@@ -194,7 +194,7 @@
194
194
  "@biomejs/biome": "^1.5.3",
195
195
  "@brillout/import": "^0.2.3",
196
196
  "@brillout/json-serializer": "^0.5.8",
197
- "@brillout/picocolors": "^1.0.10",
197
+ "@brillout/picocolors": "^1.0.13",
198
198
  "@brillout/release-me": "^0.3.8",
199
199
  "@brillout/require-shim": "^0.1.2",
200
200
  "@brillout/vite-plugin-server-entry": "^0.4.0",