vike 0.4.204 → 0.4.205

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 (24) hide show
  1. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +5 -1
  2. package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +3 -1
  3. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +1 -1
  4. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  5. package/dist/cjs/utils/parseUrl.js +33 -16
  6. package/dist/esm/client/client-routing-runtime/history.js +1 -1
  7. package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +2 -0
  8. package/dist/esm/client/client-routing-runtime/navigate.d.ts +2 -1
  9. package/dist/esm/client/client-routing-runtime/navigate.js +3 -2
  10. package/dist/esm/client/client-routing-runtime/normalizeUrlArgument.js +2 -2
  11. package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +1 -0
  12. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +3 -2
  13. package/dist/esm/client/client-routing-runtime/skipLink.js +4 -1
  14. package/dist/esm/client/shared/normalizeClientSideUrl.js +4 -0
  15. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +5 -1
  16. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.d.ts +3 -1
  17. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +3 -1
  18. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +1 -1
  19. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  20. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  21. package/dist/esm/utils/parseUrl.d.ts +2 -2
  22. package/dist/esm/utils/parseUrl.js +33 -16
  23. package/dist/esm/utils/projectInfo.d.ts +1 -1
  24. package/package.json +2 -2
@@ -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
  */
@@ -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
  }
@@ -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.205';
@@ -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)
@@ -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
  */
@@ -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
  }
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.204";
1
+ export declare const PROJECT_VERSION: "0.4.205";
@@ -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.205';
@@ -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.205";
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.205",
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"