vike 0.4.204-commit-9a97c22 → 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.
@@ -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-commit-9a97c22';
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.
@@ -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;
@@ -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 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.204-commit-9a97c22";
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-commit-9a97c22';
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-commit-9a97c22";
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-commit-9a97c22",
3
+ "version": "0.4.205",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {