vike 0.4.204 → 0.4.206

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 (56) hide show
  1. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +37 -0
  2. package/dist/cjs/node/plugin/plugins/buildConfig.js +4 -0
  3. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +4 -3
  4. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +5 -4
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +5 -1
  6. package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
  7. package/dist/cjs/node/plugin/utils.js +1 -0
  8. package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +3 -1
  9. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +1 -1
  10. package/dist/cjs/node/runtime/utils.js +0 -1
  11. package/dist/cjs/node/shared/utils.js +0 -1
  12. package/dist/cjs/node/shared/virtual-files/virtualFileImportUserCode.js +2 -1
  13. package/dist/cjs/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +2 -1
  14. package/dist/cjs/{utils → node/shared}/virtual-files.js +10 -5
  15. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  16. package/dist/cjs/utils/assert.js +18 -27
  17. package/dist/cjs/utils/isEqualStringList.js +13 -0
  18. package/dist/cjs/utils/parseUrl.js +33 -16
  19. package/dist/esm/client/client-routing-runtime/history.js +1 -1
  20. package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +2 -0
  21. package/dist/esm/client/client-routing-runtime/navigate.d.ts +2 -1
  22. package/dist/esm/client/client-routing-runtime/navigate.js +3 -2
  23. package/dist/esm/client/client-routing-runtime/normalizeUrlArgument.js +2 -2
  24. package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +1 -0
  25. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +3 -2
  26. package/dist/esm/client/client-routing-runtime/skipLink.js +4 -1
  27. package/dist/esm/client/shared/normalizeClientSideUrl.js +4 -0
  28. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +4 -0
  29. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +38 -1
  30. package/dist/esm/node/plugin/plugins/buildConfig.js +5 -1
  31. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +2 -1
  32. package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -1
  33. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +5 -1
  34. package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
  35. package/dist/esm/node/plugin/utils.d.ts +1 -0
  36. package/dist/esm/node/plugin/utils.js +1 -0
  37. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.d.ts +3 -1
  38. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +3 -1
  39. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +1 -1
  40. package/dist/esm/node/runtime/utils.d.ts +0 -1
  41. package/dist/esm/node/runtime/utils.js +0 -1
  42. package/dist/esm/node/shared/utils.d.ts +0 -1
  43. package/dist/esm/node/shared/utils.js +0 -1
  44. package/dist/esm/node/shared/virtual-files/virtualFileImportUserCode.js +2 -1
  45. package/dist/esm/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +2 -1
  46. package/dist/esm/{utils → node/shared}/virtual-files.js +4 -2
  47. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  48. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  49. package/dist/esm/utils/assert.js +18 -27
  50. package/dist/esm/utils/isEqualStringList.d.ts +3 -0
  51. package/dist/esm/utils/isEqualStringList.js +11 -0
  52. package/dist/esm/utils/parseUrl.d.ts +2 -2
  53. package/dist/esm/utils/parseUrl.js +33 -16
  54. package/dist/esm/utils/projectInfo.d.ts +1 -1
  55. package/package.json +2 -2
  56. /package/dist/esm/{utils → node/shared}/virtual-files.d.ts +0 -0
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.fixServerAssets = fixServerAssets;
7
7
  exports.fixServerAssets_isEnabled = fixServerAssets_isEnabled;
8
+ exports.fixServerAssets_assertCssTarget = fixServerAssets_assertCssTarget;
9
+ exports.fixServerAssets_assertCssTarget_populate = fixServerAssets_assertCssTarget_populate;
8
10
  const promises_1 = __importDefault(require("fs/promises"));
9
11
  const path_1 = __importDefault(require("path"));
10
12
  const fs_1 = require("fs");
@@ -12,6 +14,8 @@ const utils_js_1 = require("../../utils.js");
12
14
  const virtualFilePageConfigValuesAll_js_1 = require("../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
13
15
  const buildConfig_js_1 = require("../buildConfig.js");
14
16
  const getAssetsDir_js_1 = require("../../shared/getAssetsDir.js");
17
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
18
+ const getVikeConfig_js_1 = require("../importUserCode/v1-design/getVikeConfig.js");
15
19
  /**
16
20
  * true => use workaround config.build.ssrEmitAssets
17
21
  * false => use workaround extractAssets plugin
@@ -153,3 +157,36 @@ function getHash(src) {
153
157
  (0, utils_js_1.assert)(hash);
154
158
  return hash;
155
159
  }
160
+ const targets = [];
161
+ function fixServerAssets_assertCssTarget_populate(config) {
162
+ const isServerSide = (0, utils_js_1.viteIsSSR)(config);
163
+ (0, utils_js_1.assert)(typeof isServerSide === 'boolean');
164
+ (0, utils_js_1.assert)(config.build.target !== undefined);
165
+ targets.push({ global: config.build.target, css: config.build.cssTarget, isServerSide });
166
+ }
167
+ async function fixServerAssets_assertCssTarget(config) {
168
+ if (!fixServerAssets_isEnabled())
169
+ return;
170
+ if (!(await (0, getVikeConfig_js_1.isV1Design)(config, false)))
171
+ return;
172
+ const targetsServer = targets.filter((t) => t.isServerSide);
173
+ const targetsClient = targets.filter((t) => !t.isServerSide);
174
+ targetsClient.forEach((targetClient) => {
175
+ const targetCssResolvedClient = resolveCssTarget(targetClient);
176
+ targetsServer.forEach((targetServer) => {
177
+ const targetCssResolvedServer = resolveCssTarget(targetServer);
178
+ (0, utils_js_1.assertWarning)((0, utils_js_1.isEqualStringList)(targetCssResolvedClient, targetCssResolvedServer), [
179
+ 'The CSS browser target must be the same for both client-side and server-side, but we got:',
180
+ `Client-side: ${picocolors_1.default.cyan(JSON.stringify(targetCssResolvedClient))}`,
181
+ `Server-side: ${picocolors_1.default.cyan(JSON.stringify(targetCssResolvedServer))}`,
182
+ 'See https://github.com/vikejs/vike/issues/1815#issuecomment-2507002979 if you want to know why.'
183
+ ].join('\n'), {
184
+ showStackTrace: true,
185
+ onlyOnce: 'different-css-target'
186
+ });
187
+ });
188
+ });
189
+ }
190
+ function resolveCssTarget(target) {
191
+ return target.css ?? target.global;
192
+ }
@@ -54,6 +54,7 @@ function buildConfig() {
54
54
  config.build.ssrEmitAssets = true;
55
55
  // Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
56
56
  config.build.cssMinify = 'esbuild';
57
+ (0, fixServerAssets_js_1.fixServerAssets_assertCssTarget_populate)(config);
57
58
  }
58
59
  }
59
60
  }
@@ -71,6 +72,9 @@ function buildConfig() {
71
72
  },
72
73
  buildStart() {
73
74
  (0, utils_js_1.assertNodeEnv_build)();
75
+ },
76
+ async closeBundle() {
77
+ await (0, fixServerAssets_js_1.fixServerAssets_assertCssTarget)(config);
74
78
  }
75
79
  },
76
80
  {
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.extractAssetsRE = void 0;
9
9
  exports.extractAssetsPlugin = extractAssetsPlugin;
10
10
  const utils_js_1 = require("../utils.js");
11
+ const virtual_files_js_1 = require("../../shared/virtual-files.js");
11
12
  const extractAssetsQuery_js_1 = require("../../shared/extractAssetsQuery.js");
12
13
  const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
13
14
  const isAsset_js_1 = require("../shared/isAsset.js");
@@ -122,9 +123,9 @@ function extractAssetsPlugin() {
122
123
  name: 'vike:extractAssets-3',
123
124
  apply: 'build',
124
125
  load(id) {
125
- if (!(0, utils_js_1.isVirtualFileId)(id))
126
+ if (!(0, virtual_files_js_1.isVirtualFileId)(id))
126
127
  return undefined;
127
- id = (0, utils_js_1.getVirtualFileId)(id);
128
+ id = (0, virtual_files_js_1.getVirtualFileId)(id);
128
129
  if (id === EMPTY_MODULE_ID) {
129
130
  return '// Erased by vike:extractAssets';
130
131
  }
@@ -152,7 +153,7 @@ function extractAssetsPlugin() {
152
153
  }
153
154
  function emptyModule(file, importer) {
154
155
  debugOperation('NUKED', file, importer);
155
- return (0, utils_js_1.resolveVirtualFileId)(EMPTY_MODULE_ID);
156
+ return (0, virtual_files_js_1.resolveVirtualFileId)(EMPTY_MODULE_ID);
156
157
  }
157
158
  function appendExtractAssetsQuery(file, importer) {
158
159
  debugOperation('TRANSFORMED', file, importer);
@@ -9,6 +9,7 @@ const getConfigVike_js_1 = require("../../../shared/getConfigVike.js");
9
9
  const getVirtualFilePageConfigValuesAll_js_1 = require("./v1-design/getVirtualFilePageConfigValuesAll.js");
10
10
  const getVirtualFileImportUserCode_js_1 = require("./getVirtualFileImportUserCode.js");
11
11
  const utils_js_1 = require("../../utils.js");
12
+ const virtual_files_js_1 = require("../../../shared/virtual-files.js");
12
13
  const virtualFilePageConfigValuesAll_js_1 = require("../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
13
14
  const virtualFileImportUserCode_js_1 = require("../../../shared/virtual-files/virtualFileImportUserCode.js");
14
15
  const getVikeConfig_js_1 = require("./v1-design/getVikeConfig.js");
@@ -36,8 +37,8 @@ function importUserCode() {
36
37
  }
37
38
  },
38
39
  resolveId(id) {
39
- if ((0, utils_js_1.isVirtualFileId)(id)) {
40
- return (0, utils_js_1.resolveVirtualFileId)(id);
40
+ if ((0, virtual_files_js_1.isVirtualFileId)(id)) {
41
+ return (0, virtual_files_js_1.resolveVirtualFileId)(id);
41
42
  }
42
43
  },
43
44
  handleHotUpdate(ctx) {
@@ -51,9 +52,9 @@ function importUserCode() {
51
52
  }
52
53
  },
53
54
  async load(id, options) {
54
- if (!(0, utils_js_1.isVirtualFileId)(id))
55
+ if (!(0, virtual_files_js_1.isVirtualFileId)(id))
55
56
  return undefined;
56
- id = (0, utils_js_1.getVirtualFileId)(id);
57
+ id = (0, virtual_files_js_1.getVirtualFileId)(id);
57
58
  (0, utils_js_1.assert)(typeof isDev === 'boolean');
58
59
  if ((0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id)) {
59
60
  const code = await (0, getVirtualFilePageConfigValuesAll_js_1.getVirtualFilePageConfigValuesAll)(id, isDev, config);
@@ -291,7 +291,11 @@ async function getFileStats(filePathAbsolute) {
291
291
  return stats;
292
292
  }
293
293
  async function runCmd1(cmd, cwd) {
294
- const { stdout } = await execA(cmd, { cwd });
294
+ const { stdout } = await execA(cmd, {
295
+ cwd,
296
+ // https://github.com/vikejs/vike/issues/1982
297
+ maxBuffer: Infinity
298
+ });
295
299
  /* Not always true: https://github.com/vikejs/vike/issues/1440#issuecomment-1892831303
296
300
  assert(res.stderr === '')
297
301
  */
@@ -168,7 +168,7 @@ function assertLogger(thing, logType) {
168
168
  assert(res)
169
169
  */
170
170
  if (!res)
171
- throw new Error('Internal error, reach out to a maintainer');
171
+ throw new Error('Internal Vike error, reach out to a maintainer');
172
172
  const { assertMsg, showVikeVersion } = res;
173
173
  (0, log_js_1.logWithVikeTag)(assertMsg, logType, category, showVikeVersion);
174
174
  }
@@ -43,3 +43,4 @@ __exportStar(require("../../utils/assertVersion.js"), exports);
43
43
  __exportStar(require("../../utils/isFilePathAbsoluteFilesystem.js"), exports);
44
44
  __exportStar(require("../../utils/isArray.js"), exports);
45
45
  __exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
46
+ __exportStar(require("../../utils/isEqualStringList.js"), exports);
@@ -4,10 +4,12 @@ exports.getCacheControl = getCacheControl;
4
4
  const helpers_js_1 = require("../../../../shared/page-configs/helpers.js");
5
5
  const getConfigValue_js_1 = require("../../../../shared/page-configs/getConfigValue.js");
6
6
  const defaultValue = 'no-store, max-age=0';
7
- function getCacheControl(pageId, pageConfigs) {
7
+ function getCacheControl(pageId, pageConfigs, statusCode) {
8
8
  // TODO/v1-release: remove
9
9
  if (pageConfigs.length === 0)
10
10
  return defaultValue;
11
+ if (statusCode > 499)
12
+ return defaultValue;
11
13
  const pageConfig = (0, helpers_js_1.getPageConfig)(pageId, pageConfigs);
12
14
  const configValue = (0, getConfigValue_js_1.getConfigValueRuntime)(pageConfig, 'cacheControl', 'string');
13
15
  const value = configValue?.value;
@@ -30,7 +30,7 @@ async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
30
30
  const earlyHints = (0, getEarlyHints_js_1.getEarlyHints)(await pageContext.__getPageAssets());
31
31
  const headers = [];
32
32
  (0, utils_js_1.assert)(pageContext.pageId);
33
- const cacheControl = (0, getCacheControl_js_1.getCacheControl)(pageContext.pageId, pageContext._pageConfigs);
33
+ const cacheControl = (0, getCacheControl_js_1.getCacheControl)(pageContext.pageId, pageContext._pageConfigs, statusCode);
34
34
  if (cacheControl) {
35
35
  headers.push(['Cache-Control', cacheControl]);
36
36
  }
@@ -59,7 +59,6 @@ __exportStar(require("../../utils/objectEntries.js"), exports);
59
59
  __exportStar(require("../../utils/objectFromEntries.js"), exports);
60
60
  __exportStar(require("../../utils/getFileExtension.js"), exports);
61
61
  __exportStar(require("../../utils/assertIsNotProductionRuntime.js"), exports);
62
- __exportStar(require("../../utils/virtual-files.js"), exports);
63
62
  __exportStar(require("../../utils/path-shim.js"), exports);
64
63
  __exportStar(require("../../utils/assertNodeEnv.js"), exports);
65
64
  __exportStar(require("../../utils/isHtml.js"), exports);
@@ -28,7 +28,6 @@ __exportStar(require("../../utils/hasProp.js"), exports);
28
28
  __exportStar(require("../../utils/parseUrl.js"), exports);
29
29
  __exportStar(require("../../utils/parseUrl-extras.js"), exports);
30
30
  __exportStar(require("../../utils/isObject.js"), exports);
31
- __exportStar(require("../../utils/virtual-files.js"), exports);
32
31
  __exportStar(require("../../utils/assertIsNotBrowser.js"), exports);
33
32
  __exportStar(require("../../utils/isNotNullish.js"), exports);
34
33
  __exportStar(require("../../utils/unique.js"), exports);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.virtualFileIdImportUserCodeClientCR = exports.virtualFileIdImportUserCodeClientSR = exports.virtualFileIdImportUserCodeServer = void 0;
4
4
  exports.isVirtualFileIdImportUserCode = isVirtualFileIdImportUserCode;
5
5
  const utils_js_1 = require("../utils.js");
6
+ const virtual_files_js_1 = require("../virtual-files.js");
6
7
  const idBase = 'virtual:vike:importUserCode';
7
8
  const virtualFileIdImportUserCodeServer = `${idBase}:server`;
8
9
  exports.virtualFileIdImportUserCodeServer = virtualFileIdImportUserCodeServer;
@@ -11,7 +12,7 @@ exports.virtualFileIdImportUserCodeClientSR = virtualFileIdImportUserCodeClientS
11
12
  const virtualFileIdImportUserCodeClientCR = `${idBase}:client:client-routing`;
12
13
  exports.virtualFileIdImportUserCodeClientCR = virtualFileIdImportUserCodeClientCR;
13
14
  function isVirtualFileIdImportUserCode(id) {
14
- id = (0, utils_js_1.getVirtualFileId)(id);
15
+ id = (0, virtual_files_js_1.getVirtualFileId)(id);
15
16
  if (!id.startsWith(idBase))
16
17
  return false;
17
18
  (0, utils_js_1.assert)(
@@ -4,6 +4,7 @@ exports.isVirtualFileIdPageConfigValuesAll = isVirtualFileIdPageConfigValuesAll;
4
4
  exports.getVirtualFileIdPageConfigValuesAll = getVirtualFileIdPageConfigValuesAll;
5
5
  const extractAssetsQuery_js_1 = require("../extractAssetsQuery.js");
6
6
  const utils_js_1 = require("../utils.js");
7
+ const virtual_files_js_1 = require("../virtual-files.js");
7
8
  const idBase = 'virtual:vike:pageConfigValuesAll:';
8
9
  const idBaseClient = `${idBase}client:`;
9
10
  const idBaseServer = `${idBase}server:`;
@@ -12,7 +13,7 @@ function getVirtualFileIdPageConfigValuesAll(pageId, isForClientSide) {
12
13
  return id;
13
14
  }
14
15
  function isVirtualFileIdPageConfigValuesAll(id) {
15
- id = (0, utils_js_1.getVirtualFileId)(id);
16
+ id = (0, virtual_files_js_1.getVirtualFileId)(id);
16
17
  if (!id.includes(idBase))
17
18
  return false;
18
19
  (0, utils_js_1.assert)(id.startsWith(idBase));
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.isVirtualFileId = isVirtualFileId;
4
7
  exports.getVirtualFileId = getVirtualFileId;
5
8
  exports.resolveVirtualFileId = resolveVirtualFileId;
6
- const assert_js_1 = require("./assert.js");
9
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
+ const utils_js_1 = require("./utils.js");
7
11
  const idBase = 'virtual:vike:';
8
12
  // https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
9
13
  const tag = '\0';
@@ -12,21 +16,22 @@ function isVirtualFileId(id) {
12
16
  return true;
13
17
  if (id.startsWith(tag + idBase))
14
18
  return true;
15
- (0, assert_js_1.assert)(!id.includes(idBase));
19
+ // https://github.com/vikejs/vike/issues/1985
20
+ (0, utils_js_1.assertUsage)(!id.includes(idBase), `Encountered a module ID ${picocolors_1.default.cyan(id)} that is unexpected. Are you using a tool that modifies the ID of modules? For example, the baseUrl setting in tsconfig.json cannot be used.`);
16
21
  return false;
17
22
  }
18
23
  function getVirtualFileId(id) {
19
24
  if (id.startsWith(tag)) {
20
25
  id = id.slice(tag.length);
21
26
  }
22
- (0, assert_js_1.assert)(!id.startsWith(tag));
27
+ (0, utils_js_1.assert)(!id.startsWith(tag));
23
28
  return id;
24
29
  }
25
30
  function resolveVirtualFileId(id) {
26
- (0, assert_js_1.assert)(isVirtualFileId(id));
31
+ (0, utils_js_1.assert)(isVirtualFileId(id));
27
32
  if (!id.startsWith(tag)) {
28
33
  id = tag + id;
29
34
  }
30
- (0, assert_js_1.assert)(id.startsWith(tag));
35
+ (0, utils_js_1.assert)(id.startsWith(tag));
31
36
  return id;
32
37
  }
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.204';
5
+ exports.PROJECT_VERSION = '0.4.206';
@@ -150,7 +150,7 @@ function addPrefixProjctName(msg, showProjectVersion = false) {
150
150
  }
151
151
  function getAssertErrMsg(thing) {
152
152
  let errMsg;
153
- let errStack = null;
153
+ let errStack;
154
154
  if (typeof thing === 'string') {
155
155
  errMsg = thing;
156
156
  }
@@ -161,33 +161,24 @@ function getAssertErrMsg(thing) {
161
161
  else {
162
162
  return null;
163
163
  }
164
- let assertMsg;
165
- let isBug;
166
- if (errMsg.startsWith(projectTag)) {
167
- assertMsg = errMsg.slice(projectTag.length);
168
- isBug = false;
169
- }
170
- else if (errMsg.startsWith(projectTagWithVersion)) {
171
- assertMsg = errMsg.slice(projectTagWithVersion.length);
172
- isBug = true;
173
- }
174
- else {
175
- return null;
176
- }
177
- // Append stack trace
178
- if (errStack && (isBug || globalObject.showStackTraceList.has(thing))) {
179
- assertMsg = `${assertMsg}\n${removeErrMsg(errStack)}`;
164
+ for (const tag of [projectTagWithVersion, projectTag]) {
165
+ const showVikeVersion = tag === projectTagWithVersion;
166
+ const errStackPrefix = `Error: ${tag}`;
167
+ if (errStack?.startsWith(errStackPrefix)) {
168
+ if (globalObject.showStackTraceList.has(thing)) {
169
+ const assertMsg = errStack.slice(errStackPrefix.length);
170
+ return { assertMsg, showVikeVersion };
171
+ }
172
+ }
173
+ else if (errStack?.includes(tag)) {
174
+ throw new Error('Internal Vike error');
175
+ }
176
+ if (errMsg?.startsWith(tag)) {
177
+ const assertMsg = errMsg.slice(tag.length);
178
+ return { assertMsg, showVikeVersion };
179
+ }
180
180
  }
181
- const showVikeVersion = isBug;
182
- return { assertMsg, showVikeVersion };
183
- }
184
- function removeErrMsg(stack) {
185
- if (typeof stack !== 'string')
186
- return String(stack);
187
- const [firstLine, ...stackLines] = stack.split('\n');
188
- if (!firstLine.startsWith('Error: '))
189
- return stack;
190
- return stackLines.join('\n');
181
+ return null;
191
182
  }
192
183
  function overwriteAssertProductionLogger(logger) {
193
184
  globalObject.logger = logger;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEqualStringList = isEqualStringList;
4
+ function isEqualStringList(a, b) {
5
+ if (a === b)
6
+ return true;
7
+ if (Array.isArray(a) && Array.isArray(b)) {
8
+ const sortedA = [...a].sort();
9
+ const sortedB = [...b].sort();
10
+ return sortedA.length === sortedB.length && sortedA.every((val, i) => val === sortedB[i]);
11
+ }
12
+ return false;
13
+ }
@@ -12,7 +12,7 @@ exports.assertUsageUrlRedirectTarget = assertUsageUrlRedirectTarget;
12
12
  exports.isUrl = isUrl;
13
13
  exports.isUri = isUri;
14
14
  exports.isUrlRedirectTarget = isUrlRedirectTarget;
15
- exports.isUrlPathnameRelative = isUrlPathnameRelative;
15
+ exports.isUrlRelative = isUrlRelative;
16
16
  exports.isUrlExternal = isUrlExternal;
17
17
  exports.isBaseServer = isBaseServer;
18
18
  exports.assertUrlComponents = assertUrlComponents;
@@ -24,19 +24,23 @@ function parseUrl(url, baseServer) {
24
24
  (0, assert_js_1.assert)(isUrl(url), url);
25
25
  (0, assert_js_1.assert)(baseServer.startsWith('/'));
26
26
  // Hash
27
- const [urlWithoutHash, ...h] = url.split('#');
28
- (0, assert_js_1.assert)(urlWithoutHash !== undefined);
29
- const hashOriginal = ['', ...h].join('#') || null;
27
+ const { hashString: hashOriginal, withoutHash: urlWithoutHash } = extractHash(url);
30
28
  (0, assert_js_1.assert)(hashOriginal === null || hashOriginal.startsWith('#'));
31
29
  const hash = hashOriginal === null ? '' : decodeSafe(hashOriginal.slice(1));
32
30
  // Search
33
- const [urlWithoutHashNorSearch, ...searchList] = urlWithoutHash.split('?');
34
- (0, assert_js_1.assert)(urlWithoutHashNorSearch !== undefined);
35
- const searchOriginal = ['', ...searchList].join('?') || null;
31
+ const { searchString: searchOriginal, withoutSearch: urlWithoutHashNorSearch } = extractSearch(urlWithoutHash);
36
32
  (0, assert_js_1.assert)(searchOriginal === null || searchOriginal.startsWith('?'));
33
+ let searchString = '';
34
+ if (searchOriginal !== null) {
35
+ searchString = searchOriginal;
36
+ }
37
+ else if (url.startsWith('#')) {
38
+ const baseURI = getBaseURI();
39
+ searchString = (baseURI && extractSearch(baseURI).searchString) || '';
40
+ }
37
41
  const search = {};
38
42
  const searchAll = {};
39
- Array.from(new URLSearchParams(searchOriginal || '')).forEach(([key, val]) => {
43
+ Array.from(new URLSearchParams(searchString)).forEach(([key, val]) => {
40
44
  search[key] = val;
41
45
  searchAll[key] = [...(searchAll.hasOwnProperty(key) ? searchAll[key] : []), val];
42
46
  });
@@ -70,6 +74,16 @@ function parseUrl(url, baseServer) {
70
74
  hashOriginal
71
75
  };
72
76
  }
77
+ function extractHash(url) {
78
+ const [withoutHash, ...parts] = url.split('#');
79
+ const hashString = ['', ...parts].join('#') || null;
80
+ return { hashString, withoutHash: withoutHash };
81
+ }
82
+ function extractSearch(url) {
83
+ const [withoutSearch, ...parts] = url.split('?');
84
+ const searchString = ['', ...parts].join('?') || null;
85
+ return { searchString, withoutSearch: withoutSearch };
86
+ }
73
87
  function decodeSafe(urlComponent) {
74
88
  try {
75
89
  return decodeURIComponent(urlComponent);
@@ -106,13 +120,10 @@ function getPathnameAbsoluteWithBase(url, baseServer) {
106
120
  }
107
121
  else {
108
122
  // url is a relative path
109
- // In the browser, this is the Base URL of the current URL.
110
- // Safe access `window?.document?.baseURI` for users who shim `window` in Node.js
111
- const baseURI = typeof window !== 'undefined' ? window?.document?.baseURI : undefined;
123
+ const baseURI = getBaseURI();
112
124
  let base;
113
125
  if (baseURI) {
114
- const baseURIPathaname = parseOrigin(baseURI.split('?')[0].split('#')[0]).pathname;
115
- base = baseURIPathaname;
126
+ base = parseOrigin(baseURI.split('?')[0].split('#')[0]).pathname;
116
127
  }
117
128
  else {
118
129
  base = baseServer;
@@ -121,6 +132,12 @@ function getPathnameAbsoluteWithBase(url, baseServer) {
121
132
  return { protocol: null, origin: null, pathnameAbsoluteWithBase };
122
133
  }
123
134
  }
135
+ function getBaseURI() {
136
+ // In the browser, this is the Base URL of the current URL.
137
+ // Safe access `window?.document?.baseURI` for users who shim `window` in Node.js
138
+ const baseURI = typeof window !== 'undefined' ? window?.document?.baseURI : undefined;
139
+ return baseURI;
140
+ }
124
141
  function parseOrigin(url) {
125
142
  if (!isUrlWithProtocol(url)) {
126
143
  return { pathname: url, origin: null, protocol: null };
@@ -251,16 +268,16 @@ function createUrlFromComponents(origin, pathname, search, hash) {
251
268
  }
252
269
  function isUrl(url) {
253
270
  // parseUrl() works with these URLs
254
- return isUrlWithProtocol(url) || url.startsWith('/') || isUrlPathnameRelative(url);
271
+ return isUrlWithProtocol(url) || url.startsWith('/') || isUrlRelative(url);
255
272
  }
256
273
  function isUrlRedirectTarget(url) {
257
274
  return url.startsWith('/') || isUri(url) || isUrlWithProtocol(url);
258
275
  }
259
- function isUrlPathnameRelative(url) {
276
+ function isUrlRelative(url) {
260
277
  return ['.', '?', '#'].some((c) => url.startsWith(c)) || url === '';
261
278
  }
262
279
  function isUrlExternal(url) {
263
- return !url.startsWith('/') && !isUrlPathnameRelative(url);
280
+ return !url.startsWith('/') && !isUrlRelative(url);
264
281
  }
265
282
  /*
266
283
  URL with protocol.
@@ -50,7 +50,7 @@ function getState() {
50
50
  // - Therefore, we have to monkey patch history.pushState() and history.replaceState()
51
51
  // - Therefore, we need the assert() below to ensure history.state has been enhanced by Vike
52
52
  // - If users stumble upon this assert() then let's make it a assertUsage()
53
- assert(isVikeEnhanced(state));
53
+ assert(isVikeEnhanced(state), { state });
54
54
  return state;
55
55
  }
56
56
  function getStateNotEnhanced() {
@@ -18,7 +18,9 @@ async function onClick(ev) {
18
18
  // - https://github.com/vikejs/vike/issues/1962
19
19
  // - https://github.com/sveltejs/kit/issues/8725
20
20
  if (href?.includes('#') && isSameAsCurrentUrl(href)) {
21
+ // Prevent Firefox from setting `window.history.state` to `null`
21
22
  ev.preventDefault();
23
+ // Replicate the browser's native behavior
22
24
  scrollToHashOrTop(href.split('#')[1]);
23
25
  return;
24
26
  }
@@ -8,8 +8,9 @@ export { reload };
8
8
  * @param keepScrollPosition - Don't scroll to the top of the page, instead keep the current scroll position.
9
9
  * @param overwriteLastHistoryEntry - Don't create a new entry in the browser's history, instead let the new URL replace the current URL. (This effectively removes the current URL from the browser history).
10
10
  */
11
- declare function navigate(url: string, { keepScrollPosition, overwriteLastHistoryEntry }?: {
11
+ declare function navigate(url: string, { keepScrollPosition, overwriteLastHistoryEntry, pageContext }?: {
12
12
  keepScrollPosition?: boolean;
13
13
  overwriteLastHistoryEntry?: boolean;
14
+ pageContext?: Record<string, unknown>;
14
15
  }): Promise<void>;
15
16
  declare function reload(): Promise<void>;
@@ -13,7 +13,7 @@ assertClientRouting();
13
13
  * @param keepScrollPosition - Don't scroll to the top of the page, instead keep the current scroll position.
14
14
  * @param overwriteLastHistoryEntry - Don't create a new entry in the browser's history, instead let the new URL replace the current URL. (This effectively removes the current URL from the browser history).
15
15
  */
16
- async function navigate(url, { keepScrollPosition = false, overwriteLastHistoryEntry = false } = {}) {
16
+ async function navigate(url, { keepScrollPosition = false, overwriteLastHistoryEntry = false, pageContext } = {}) {
17
17
  normalizeUrlArgument(url, 'navigate');
18
18
  // If `hydrationCanBeAborted === false` (e.g. Vue) then we can apply navigate() only after hydration is done
19
19
  await firstRenderStartPromise;
@@ -22,7 +22,8 @@ async function navigate(url, { keepScrollPosition = false, overwriteLastHistoryE
22
22
  scrollTarget,
23
23
  urlOriginal: url,
24
24
  overwriteLastHistoryEntry,
25
- isBackwardNavigation: false
25
+ isBackwardNavigation: false,
26
+ pageContextInitClient: pageContext
26
27
  });
27
28
  }
28
29
  async function reload() {
@@ -1,5 +1,5 @@
1
1
  export { normalizeUrlArgument };
2
- import { assertUsage, isUrl, isUrlPathnameRelative } from './utils.js';
2
+ import { assertUsage, isUrl, isUrlRelative } from './utils.js';
3
3
  function normalizeUrlArgument(url, fnName) {
4
4
  // Succinct error message to save client-side KBs
5
5
  const errMsg = `[${fnName}(url)] Invalid URL ${url}`;
@@ -8,7 +8,7 @@ function normalizeUrlArgument(url, fnName) {
8
8
  // Use normalizeClientSideUrl() instead?
9
9
  url = url.slice(location.origin.length);
10
10
  }
11
- assertUsage(url.startsWith('/') || isUrlPathnameRelative(url),
11
+ assertUsage(url.startsWith('/') || isUrlRelative(url),
12
12
  // `errMsg` used the original `url` value
13
13
  errMsg);
14
14
  return url;
@@ -14,6 +14,7 @@ type RenderArgs = {
14
14
  redirectCount?: number;
15
15
  doNotRenderIfSamePage?: boolean;
16
16
  isClientSideNavigation?: boolean;
17
+ pageContextInitClient?: Record<string, unknown>;
17
18
  };
18
19
  declare function renderPageClientSide(renderArgs: RenderArgs): Promise<void>;
19
20
  declare function disableClientRouting(err: unknown, log: boolean): void;
@@ -30,7 +30,7 @@ const globalObject = getGlobalObject('renderPageClientSide.ts', (() => {
30
30
  })());
31
31
  const { firstRenderStartPromise } = globalObject;
32
32
  async function renderPageClientSide(renderArgs) {
33
- const { urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, pageContextsFromRewrite = [], redirectCount = 0, doNotRenderIfSamePage, isClientSideNavigation = true } = renderArgs;
33
+ const { urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, pageContextsFromRewrite = [], redirectCount = 0, doNotRenderIfSamePage, isClientSideNavigation = true, pageContextInitClient } = renderArgs;
34
34
  let { scrollTarget } = renderArgs;
35
35
  const { previousPageContext } = globalObject;
36
36
  addLinkPrefetchHandlers_unwatch();
@@ -218,7 +218,8 @@ async function renderPageClientSide(renderArgs) {
218
218
  isBackwardNavigation,
219
219
  isClientSideNavigation,
220
220
  isHydration: isFirstRender && !isForErrorPage,
221
- _previousPageContext: previousPageContext
221
+ _previousPageContext: previousPageContext,
222
+ ...pageContextInitClient
222
223
  });
223
224
  {
224
225
  const pageContextFromAllRewrites = getPageContextFromAllRewrites(pageContextsFromRewrite);
@@ -32,15 +32,18 @@ function isNewTabLink(linkTag) {
32
32
  return target === '_blank' || target === '_external' || rel === 'external' || linkTag.hasAttribute('download');
33
33
  }
34
34
  function isSamePageHashLink(href) {
35
+ if (href.startsWith('#'))
36
+ return true;
35
37
  if (href.includes('#') &&
36
38
  normalizeClientSideUrl(href, { withoutHash: true }) ===
37
39
  normalizeClientSideUrl(window.location.href, { withoutHash: true })) {
38
40
  return true;
39
41
  }
40
- assert(!href.startsWith('#'));
41
42
  return false;
42
43
  }
43
44
  function isSameAsCurrentUrl(href) {
45
+ if (href.startsWith('#'))
46
+ return href === window.location.hash;
44
47
  return normalizeClientSideUrl(href) === normalizeClientSideUrl(window.location.href);
45
48
  }
46
49
  function hasBaseServer(href) {
@@ -2,6 +2,10 @@ 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`.
8
+ assert(!url.startsWith('#'));
5
9
  const { searchOriginal, hashOriginal, pathname } = parseUrl(url, '/');
6
10
  let urlCurrent = `${pathname}${searchOriginal || ''}`;
7
11
  if (!options?.withoutHash)
@@ -1,5 +1,7 @@
1
1
  export { fixServerAssets };
2
2
  export { fixServerAssets_isEnabled };
3
+ export { fixServerAssets_assertCssTarget };
4
+ export { fixServerAssets_assertCssTarget_populate };
3
5
  import { ViteManifest } from '../../../shared/ViteManifest.js';
4
6
  import { ResolvedConfig } from 'vite';
5
7
  /**
@@ -11,3 +13,5 @@ import { ResolvedConfig } from 'vite';
11
13
  declare function fixServerAssets_isEnabled(): boolean;
12
14
  /** https://github.com/vikejs/vike/issues/1339 */
13
15
  declare function fixServerAssets(config: ResolvedConfig): Promise<ViteManifest>;
16
+ declare function fixServerAssets_assertCssTarget_populate(config: ResolvedConfig): void;
17
+ declare function fixServerAssets_assertCssTarget(config: ResolvedConfig): Promise<void>;
@@ -1,12 +1,16 @@
1
1
  export { fixServerAssets };
2
2
  export { fixServerAssets_isEnabled };
3
+ export { fixServerAssets_assertCssTarget };
4
+ export { fixServerAssets_assertCssTarget_populate };
3
5
  import fs from 'fs/promises';
4
6
  import path from 'path';
5
7
  import { existsSync } from 'fs';
6
- import { assert, getOutDirs, pLimit, unique } from '../../utils.js';
8
+ import { assert, assertWarning, getOutDirs, isEqualStringList, pLimit, unique, viteIsSSR } from '../../utils.js';
7
9
  import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
8
10
  import { manifestTempFile } from '../buildConfig.js';
9
11
  import { getAssetsDir } from '../../shared/getAssetsDir.js';
12
+ import pc from '@brillout/picocolors';
13
+ import { isV1Design } from '../importUserCode/v1-design/getVikeConfig.js';
10
14
  /**
11
15
  * true => use workaround config.build.ssrEmitAssets
12
16
  * false => use workaround extractAssets plugin
@@ -148,3 +152,36 @@ function getHash(src) {
148
152
  assert(hash);
149
153
  return hash;
150
154
  }
155
+ const targets = [];
156
+ function fixServerAssets_assertCssTarget_populate(config) {
157
+ const isServerSide = viteIsSSR(config);
158
+ assert(typeof isServerSide === 'boolean');
159
+ assert(config.build.target !== undefined);
160
+ targets.push({ global: config.build.target, css: config.build.cssTarget, isServerSide });
161
+ }
162
+ async function fixServerAssets_assertCssTarget(config) {
163
+ if (!fixServerAssets_isEnabled())
164
+ return;
165
+ if (!(await isV1Design(config, false)))
166
+ return;
167
+ const targetsServer = targets.filter((t) => t.isServerSide);
168
+ const targetsClient = targets.filter((t) => !t.isServerSide);
169
+ targetsClient.forEach((targetClient) => {
170
+ const targetCssResolvedClient = resolveCssTarget(targetClient);
171
+ targetsServer.forEach((targetServer) => {
172
+ const targetCssResolvedServer = resolveCssTarget(targetServer);
173
+ assertWarning(isEqualStringList(targetCssResolvedClient, targetCssResolvedServer), [
174
+ 'The CSS browser target must be the same for both client-side and server-side, but we got:',
175
+ `Client-side: ${pc.cyan(JSON.stringify(targetCssResolvedClient))}`,
176
+ `Server-side: ${pc.cyan(JSON.stringify(targetCssResolvedServer))}`,
177
+ 'See https://github.com/vikejs/vike/issues/1815#issuecomment-2507002979 if you want to know why.'
178
+ ].join('\n'), {
179
+ showStackTrace: true,
180
+ onlyOnce: 'different-css-target'
181
+ });
182
+ });
183
+ });
184
+ }
185
+ function resolveCssTarget(target) {
186
+ return target.css ?? target.global;
187
+ }
@@ -11,7 +11,7 @@ import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
11
11
  import { createRequire } from 'module';
12
12
  import fs from 'fs/promises';
13
13
  import path from 'path';
14
- import { fixServerAssets, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
14
+ import { fixServerAssets, fixServerAssets_assertCssTarget, fixServerAssets_assertCssTarget_populate, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
15
15
  import { set_ASSETS_MAP } from './importBuild/index.js';
16
16
  import { prependEntriesDir } from '../../shared/prependEntriesDir.js';
17
17
  import { getFilePathResolved } from '../shared/getFilePath.js';
@@ -48,6 +48,7 @@ function buildConfig() {
48
48
  config.build.ssrEmitAssets = true;
49
49
  // Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
50
50
  config.build.cssMinify = 'esbuild';
51
+ fixServerAssets_assertCssTarget_populate(config);
51
52
  }
52
53
  }
53
54
  }
@@ -65,6 +66,9 @@ function buildConfig() {
65
66
  },
66
67
  buildStart() {
67
68
  assertNodeEnv_build();
69
+ },
70
+ async closeBundle() {
71
+ await fixServerAssets_assertCssTarget(config);
68
72
  }
69
73
  },
70
74
  {
@@ -6,7 +6,8 @@
6
6
  // - This appraoch supports import path aliases `vite.config.js#resolve.alias` https://vitejs.dev/config/#resolve-alias
7
7
  export { extractAssetsPlugin };
8
8
  export { extractAssetsRE };
9
- import { viteIsSSR_options, assert, assertPosixPath, styleFileRE, createDebugger, isScriptFile, resolveVirtualFileId, isVirtualFileId, getVirtualFileId, assertUsage } from '../utils.js';
9
+ import { viteIsSSR_options, assert, assertPosixPath, styleFileRE, createDebugger, isScriptFile, assertUsage } from '../utils.js';
10
+ import { resolveVirtualFileId, isVirtualFileId, getVirtualFileId } from '../../shared/virtual-files.js';
10
11
  import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
11
12
  import { getConfigVike } from '../../shared/getConfigVike.js';
12
13
  import { isAsset } from '../shared/isAsset.js';
@@ -3,7 +3,8 @@ import { normalizePath } from 'vite';
3
3
  import { getConfigVike } from '../../../shared/getConfigVike.js';
4
4
  import { getVirtualFilePageConfigValuesAll } from './v1-design/getVirtualFilePageConfigValuesAll.js';
5
5
  import { getVirtualFileImportUserCode } from './getVirtualFileImportUserCode.js';
6
- import { assert, assertPosixPath, getOutDirs, getVirtualFileId, isDev3, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
6
+ import { assert, assertPosixPath, getOutDirs, isDev3 } from '../../utils.js';
7
+ import { resolveVirtualFileId, isVirtualFileId, getVirtualFileId } from '../../../shared/virtual-files.js';
7
8
  import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
8
9
  import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
9
10
  import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile, isV1Design } from './v1-design/getVikeConfig.js';
@@ -286,7 +286,11 @@ async function getFileStats(filePathAbsolute) {
286
286
  return stats;
287
287
  }
288
288
  async function runCmd1(cmd, cwd) {
289
- const { stdout } = await execA(cmd, { cwd });
289
+ const { stdout } = await execA(cmd, {
290
+ cwd,
291
+ // https://github.com/vikejs/vike/issues/1982
292
+ maxBuffer: Infinity
293
+ });
290
294
  /* Not always true: https://github.com/vikejs/vike/issues/1440#issuecomment-1892831303
291
295
  assert(res.stderr === '')
292
296
  */
@@ -163,7 +163,7 @@ function assertLogger(thing, logType) {
163
163
  assert(res)
164
164
  */
165
165
  if (!res)
166
- throw new Error('Internal error, reach out to a maintainer');
166
+ throw new Error('Internal Vike error, reach out to a maintainer');
167
167
  const { assertMsg, showVikeVersion } = res;
168
168
  logWithVikeTag(assertMsg, logType, category, showVikeVersion);
169
169
  }
@@ -21,3 +21,4 @@ export * from '../../utils/assertVersion.js';
21
21
  export * from '../../utils/isFilePathAbsoluteFilesystem.js';
22
22
  export * from '../../utils/isArray.js';
23
23
  export * from '../../utils/PROJECT_VERSION.js';
24
+ export * from '../../utils/isEqualStringList.js';
@@ -27,3 +27,4 @@ export * from '../../utils/assertVersion.js';
27
27
  export * from '../../utils/isFilePathAbsoluteFilesystem.js';
28
28
  export * from '../../utils/isArray.js';
29
29
  export * from '../../utils/PROJECT_VERSION.js';
30
+ export * from '../../utils/isEqualStringList.js';
@@ -1,3 +1,5 @@
1
1
  export { getCacheControl };
2
2
  import type { PageConfigRuntime } from '../../../../shared/page-configs/PageConfig.js';
3
- declare function getCacheControl(pageId: string, pageConfigs: PageConfigRuntime[]): string;
3
+ import type { HttpResponse } from '../createHttpResponse.js';
4
+ type StatusCode = HttpResponse['statusCode'];
5
+ declare function getCacheControl(pageId: string, pageConfigs: PageConfigRuntime[], statusCode: StatusCode): string;
@@ -2,10 +2,12 @@ export { getCacheControl };
2
2
  import { getPageConfig } from '../../../../shared/page-configs/helpers.js';
3
3
  import { getConfigValueRuntime } from '../../../../shared/page-configs/getConfigValue.js';
4
4
  const defaultValue = 'no-store, max-age=0';
5
- function getCacheControl(pageId, pageConfigs) {
5
+ function getCacheControl(pageId, pageConfigs, statusCode) {
6
6
  // TODO/v1-release: remove
7
7
  if (pageConfigs.length === 0)
8
8
  return defaultValue;
9
+ if (statusCode > 499)
10
+ return defaultValue;
9
11
  const pageConfig = getPageConfig(pageId, pageConfigs);
10
12
  const configValue = getConfigValueRuntime(pageConfig, 'cacheControl', 'string');
11
13
  const value = configValue?.value;
@@ -28,7 +28,7 @@ async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
28
28
  const earlyHints = getEarlyHints(await pageContext.__getPageAssets());
29
29
  const headers = [];
30
30
  assert(pageContext.pageId);
31
- const cacheControl = getCacheControl(pageContext.pageId, pageContext._pageConfigs);
31
+ const cacheControl = getCacheControl(pageContext.pageId, pageContext._pageConfigs, statusCode);
32
32
  if (cacheControl) {
33
33
  headers.push(['Cache-Control', cacheControl]);
34
34
  }
@@ -40,7 +40,6 @@ export * from '../../utils/objectEntries.js';
40
40
  export * from '../../utils/objectFromEntries.js';
41
41
  export * from '../../utils/getFileExtension.js';
42
42
  export * from '../../utils/assertIsNotProductionRuntime.js';
43
- export * from '../../utils/virtual-files.js';
44
43
  export * from '../../utils/path-shim.js';
45
44
  export * from '../../utils/assertNodeEnv.js';
46
45
  export * from '../../utils/isHtml.js';
@@ -43,7 +43,6 @@ export * from '../../utils/objectEntries.js';
43
43
  export * from '../../utils/objectFromEntries.js';
44
44
  export * from '../../utils/getFileExtension.js';
45
45
  export * from '../../utils/assertIsNotProductionRuntime.js';
46
- export * from '../../utils/virtual-files.js';
47
46
  export * from '../../utils/path-shim.js';
48
47
  export * from '../../utils/assertNodeEnv.js';
49
48
  export * from '../../utils/isHtml.js';
@@ -10,7 +10,6 @@ export * from '../../utils/hasProp.js';
10
10
  export * from '../../utils/parseUrl.js';
11
11
  export * from '../../utils/parseUrl-extras.js';
12
12
  export * from '../../utils/isObject.js';
13
- export * from '../../utils/virtual-files.js';
14
13
  export * from '../../utils/assertIsNotBrowser.js';
15
14
  export * from '../../utils/isNotNullish.js';
16
15
  export * from '../../utils/unique.js';
@@ -12,7 +12,6 @@ export * from '../../utils/hasProp.js';
12
12
  export * from '../../utils/parseUrl.js';
13
13
  export * from '../../utils/parseUrl-extras.js';
14
14
  export * from '../../utils/isObject.js';
15
- export * from '../../utils/virtual-files.js';
16
15
  export * from '../../utils/assertIsNotBrowser.js';
17
16
  export * from '../../utils/isNotNullish.js';
18
17
  export * from '../../utils/unique.js';
@@ -2,7 +2,8 @@ export { virtualFileIdImportUserCodeServer };
2
2
  export { virtualFileIdImportUserCodeClientSR };
3
3
  export { virtualFileIdImportUserCodeClientCR };
4
4
  export { isVirtualFileIdImportUserCode };
5
- import { assert, getVirtualFileId } from '../utils.js';
5
+ import { assert } from '../utils.js';
6
+ import { getVirtualFileId } from '../virtual-files.js';
6
7
  const idBase = 'virtual:vike:importUserCode';
7
8
  const virtualFileIdImportUserCodeServer = `${idBase}:server`;
8
9
  const virtualFileIdImportUserCodeClientSR = `${idBase}:client:server-routing`;
@@ -1,7 +1,8 @@
1
1
  export { isVirtualFileIdPageConfigValuesAll };
2
2
  export { getVirtualFileIdPageConfigValuesAll };
3
3
  import { extractAssetsRemoveQuery } from '../extractAssetsQuery.js';
4
- import { assert, getVirtualFileId } from '../utils.js';
4
+ import { assert } from '../utils.js';
5
+ import { getVirtualFileId } from '../virtual-files.js';
5
6
  const idBase = 'virtual:vike:pageConfigValuesAll:';
6
7
  const idBaseClient = `${idBase}client:`;
7
8
  const idBaseServer = `${idBase}server:`;
@@ -1,7 +1,8 @@
1
1
  export { isVirtualFileId };
2
2
  export { getVirtualFileId };
3
3
  export { resolveVirtualFileId };
4
- import { assert } from './assert.js';
4
+ import pc from '@brillout/picocolors';
5
+ import { assert, assertUsage } from './utils.js';
5
6
  const idBase = 'virtual:vike:';
6
7
  // https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
7
8
  const tag = '\0';
@@ -10,7 +11,8 @@ function isVirtualFileId(id) {
10
11
  return true;
11
12
  if (id.startsWith(tag + idBase))
12
13
  return true;
13
- assert(!id.includes(idBase));
14
+ // https://github.com/vikejs/vike/issues/1985
15
+ assertUsage(!id.includes(idBase), `Encountered a module ID ${pc.cyan(id)} that is unexpected. Are you using a tool that modifies the ID of modules? For example, the baseUrl setting in tsconfig.json cannot be used.`);
14
16
  return false;
15
17
  }
16
18
  function getVirtualFileId(id) {
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.204";
1
+ export declare const PROJECT_VERSION: "0.4.206";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.204';
2
+ export const PROJECT_VERSION = '0.4.206';
@@ -145,7 +145,7 @@ function addPrefixProjctName(msg, showProjectVersion = false) {
145
145
  }
146
146
  function getAssertErrMsg(thing) {
147
147
  let errMsg;
148
- let errStack = null;
148
+ let errStack;
149
149
  if (typeof thing === 'string') {
150
150
  errMsg = thing;
151
151
  }
@@ -156,33 +156,24 @@ function getAssertErrMsg(thing) {
156
156
  else {
157
157
  return null;
158
158
  }
159
- let assertMsg;
160
- let isBug;
161
- if (errMsg.startsWith(projectTag)) {
162
- assertMsg = errMsg.slice(projectTag.length);
163
- isBug = false;
164
- }
165
- else if (errMsg.startsWith(projectTagWithVersion)) {
166
- assertMsg = errMsg.slice(projectTagWithVersion.length);
167
- isBug = true;
168
- }
169
- else {
170
- return null;
171
- }
172
- // Append stack trace
173
- if (errStack && (isBug || globalObject.showStackTraceList.has(thing))) {
174
- assertMsg = `${assertMsg}\n${removeErrMsg(errStack)}`;
159
+ for (const tag of [projectTagWithVersion, projectTag]) {
160
+ const showVikeVersion = tag === projectTagWithVersion;
161
+ const errStackPrefix = `Error: ${tag}`;
162
+ if (errStack?.startsWith(errStackPrefix)) {
163
+ if (globalObject.showStackTraceList.has(thing)) {
164
+ const assertMsg = errStack.slice(errStackPrefix.length);
165
+ return { assertMsg, showVikeVersion };
166
+ }
167
+ }
168
+ else if (errStack?.includes(tag)) {
169
+ throw new Error('Internal Vike error');
170
+ }
171
+ if (errMsg?.startsWith(tag)) {
172
+ const assertMsg = errMsg.slice(tag.length);
173
+ return { assertMsg, showVikeVersion };
174
+ }
175
175
  }
176
- const showVikeVersion = isBug;
177
- return { assertMsg, showVikeVersion };
178
- }
179
- function removeErrMsg(stack) {
180
- if (typeof stack !== 'string')
181
- return String(stack);
182
- const [firstLine, ...stackLines] = stack.split('\n');
183
- if (!firstLine.startsWith('Error: '))
184
- return stack;
185
- return stackLines.join('\n');
176
+ return null;
186
177
  }
187
178
  function overwriteAssertProductionLogger(logger) {
188
179
  globalObject.logger = logger;
@@ -0,0 +1,3 @@
1
+ export { isEqualStringList };
2
+ type StringList = false | string | string[];
3
+ declare function isEqualStringList(a: StringList, b: StringList): boolean;
@@ -0,0 +1,11 @@
1
+ export { isEqualStringList };
2
+ function isEqualStringList(a, b) {
3
+ if (a === b)
4
+ return true;
5
+ if (Array.isArray(a) && Array.isArray(b)) {
6
+ const sortedA = [...a].sort();
7
+ const sortedB = [...b].sort();
8
+ return sortedA.length === sortedB.length && sortedA.every((val, i) => val === sortedB[i]);
9
+ }
10
+ return false;
11
+ }
@@ -4,7 +4,7 @@ export { assertUsageUrlRedirectTarget };
4
4
  export { isUrl };
5
5
  export { isUri };
6
6
  export { isUrlRedirectTarget };
7
- export { isUrlPathnameRelative };
7
+ export { isUrlRelative };
8
8
  export { isUrlExternal };
9
9
  export { isBaseServer };
10
10
  export { assertUrlComponents };
@@ -50,7 +50,7 @@ declare function assertUrlComponents(url: string, origin: string | null, pathnam
50
50
  declare function createUrlFromComponents(origin: string | null, pathname: string, search: string | null, hash: string | null): string;
51
51
  declare function isUrl(url: string): boolean;
52
52
  declare function isUrlRedirectTarget(url: string): boolean;
53
- declare function isUrlPathnameRelative(url: string): boolean;
53
+ declare function isUrlRelative(url: string): boolean;
54
54
  declare function isUrlExternal(url: string): boolean;
55
55
  declare function isUri(uri: string): boolean;
56
56
  declare function assertUsageUrlPathnameAbsolute(url: string, errPrefix: string): void;
@@ -8,7 +8,7 @@ export { assertUsageUrlRedirectTarget };
8
8
  export { isUrl };
9
9
  export { isUri };
10
10
  export { isUrlRedirectTarget };
11
- export { isUrlPathnameRelative };
11
+ export { isUrlRelative };
12
12
  export { isUrlExternal };
13
13
  export { isBaseServer };
14
14
  export { assertUrlComponents };
@@ -20,19 +20,23 @@ function parseUrl(url, baseServer) {
20
20
  assert(isUrl(url), url);
21
21
  assert(baseServer.startsWith('/'));
22
22
  // Hash
23
- const [urlWithoutHash, ...h] = url.split('#');
24
- assert(urlWithoutHash !== undefined);
25
- const hashOriginal = ['', ...h].join('#') || null;
23
+ const { hashString: hashOriginal, withoutHash: urlWithoutHash } = extractHash(url);
26
24
  assert(hashOriginal === null || hashOriginal.startsWith('#'));
27
25
  const hash = hashOriginal === null ? '' : decodeSafe(hashOriginal.slice(1));
28
26
  // Search
29
- const [urlWithoutHashNorSearch, ...searchList] = urlWithoutHash.split('?');
30
- assert(urlWithoutHashNorSearch !== undefined);
31
- const searchOriginal = ['', ...searchList].join('?') || null;
27
+ const { searchString: searchOriginal, withoutSearch: urlWithoutHashNorSearch } = extractSearch(urlWithoutHash);
32
28
  assert(searchOriginal === null || searchOriginal.startsWith('?'));
29
+ let searchString = '';
30
+ if (searchOriginal !== null) {
31
+ searchString = searchOriginal;
32
+ }
33
+ else if (url.startsWith('#')) {
34
+ const baseURI = getBaseURI();
35
+ searchString = (baseURI && extractSearch(baseURI).searchString) || '';
36
+ }
33
37
  const search = {};
34
38
  const searchAll = {};
35
- Array.from(new URLSearchParams(searchOriginal || '')).forEach(([key, val]) => {
39
+ Array.from(new URLSearchParams(searchString)).forEach(([key, val]) => {
36
40
  search[key] = val;
37
41
  searchAll[key] = [...(searchAll.hasOwnProperty(key) ? searchAll[key] : []), val];
38
42
  });
@@ -66,6 +70,16 @@ function parseUrl(url, baseServer) {
66
70
  hashOriginal
67
71
  };
68
72
  }
73
+ function extractHash(url) {
74
+ const [withoutHash, ...parts] = url.split('#');
75
+ const hashString = ['', ...parts].join('#') || null;
76
+ return { hashString, withoutHash: withoutHash };
77
+ }
78
+ function extractSearch(url) {
79
+ const [withoutSearch, ...parts] = url.split('?');
80
+ const searchString = ['', ...parts].join('?') || null;
81
+ return { searchString, withoutSearch: withoutSearch };
82
+ }
69
83
  function decodeSafe(urlComponent) {
70
84
  try {
71
85
  return decodeURIComponent(urlComponent);
@@ -102,13 +116,10 @@ function getPathnameAbsoluteWithBase(url, baseServer) {
102
116
  }
103
117
  else {
104
118
  // url is a relative path
105
- // In the browser, this is the Base URL of the current URL.
106
- // Safe access `window?.document?.baseURI` for users who shim `window` in Node.js
107
- const baseURI = typeof window !== 'undefined' ? window?.document?.baseURI : undefined;
119
+ const baseURI = getBaseURI();
108
120
  let base;
109
121
  if (baseURI) {
110
- const baseURIPathaname = parseOrigin(baseURI.split('?')[0].split('#')[0]).pathname;
111
- base = baseURIPathaname;
122
+ base = parseOrigin(baseURI.split('?')[0].split('#')[0]).pathname;
112
123
  }
113
124
  else {
114
125
  base = baseServer;
@@ -117,6 +128,12 @@ function getPathnameAbsoluteWithBase(url, baseServer) {
117
128
  return { protocol: null, origin: null, pathnameAbsoluteWithBase };
118
129
  }
119
130
  }
131
+ function getBaseURI() {
132
+ // In the browser, this is the Base URL of the current URL.
133
+ // Safe access `window?.document?.baseURI` for users who shim `window` in Node.js
134
+ const baseURI = typeof window !== 'undefined' ? window?.document?.baseURI : undefined;
135
+ return baseURI;
136
+ }
120
137
  function parseOrigin(url) {
121
138
  if (!isUrlWithProtocol(url)) {
122
139
  return { pathname: url, origin: null, protocol: null };
@@ -247,16 +264,16 @@ function createUrlFromComponents(origin, pathname, search, hash) {
247
264
  }
248
265
  function isUrl(url) {
249
266
  // parseUrl() works with these URLs
250
- return isUrlWithProtocol(url) || url.startsWith('/') || isUrlPathnameRelative(url);
267
+ return isUrlWithProtocol(url) || url.startsWith('/') || isUrlRelative(url);
251
268
  }
252
269
  function isUrlRedirectTarget(url) {
253
270
  return url.startsWith('/') || isUri(url) || isUrlWithProtocol(url);
254
271
  }
255
- function isUrlPathnameRelative(url) {
272
+ function isUrlRelative(url) {
256
273
  return ['.', '?', '#'].some((c) => url.startsWith(c)) || url === '';
257
274
  }
258
275
  function isUrlExternal(url) {
259
- return !url.startsWith('/') && !isUrlPathnameRelative(url);
276
+ return !url.startsWith('/') && !isUrlRelative(url);
260
277
  }
261
278
  /*
262
279
  URL with protocol.
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.204";
3
+ projectVersion: "0.4.206";
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.204",
3
+ "version": "0.4.206",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -129,7 +129,7 @@
129
129
  "acorn": "^8.0.0",
130
130
  "cac": "^6.0.0",
131
131
  "es-module-lexer": "^1.0.0",
132
- "esbuild": "^0.19.0 || ^0.20.0 || ^0.21.0 || ^0.22.0 || ^0.23.0",
132
+ "esbuild": "^0.19.0 || ^0.20.0 || ^0.21.0 || ^0.22.0 || ^0.23.0 || ^0.24.0",
133
133
  "fast-glob": "^3.0.0",
134
134
  "semver": "^7.0.0",
135
135
  "source-map-support": "^0.5.0"