vike 0.4.244-commit-a8703f7 → 0.4.244-commit-aae383f

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.
@@ -1,5 +1,5 @@
1
1
  export { initOnLinkClick };
2
- import { isLinkIgnored, isSameAsCurrentUrl, skipLink } from './skipLink.js';
2
+ import { isLinkIgnored, isHrefCurrentUrl, isLinkSkipped } from './isLinkSkipped.js';
3
3
  import { renderPageClientSide } from './renderPageClientSide.js';
4
4
  import { scrollToHashOrTop } from './setScrollPosition.js';
5
5
  function initOnLinkClick() {
@@ -19,14 +19,14 @@ async function onLinkClick(ev) {
19
19
  // Workaround for Firefox bug: clicking on a hash link that doesn't change the current URL causes Firefox to erroneously set `window.history.state = null` without firing any signal that we can detect.
20
20
  // - https://github.com/vikejs/vike/issues/1962
21
21
  // - https://github.com/sveltejs/kit/issues/8725
22
- if (href.includes('#') && isSameAsCurrentUrl(href)) {
22
+ if (href.includes('#') && isHrefCurrentUrl(href)) {
23
23
  // Prevent Firefox from setting `window.history.state` to `null`
24
24
  ev.preventDefault();
25
25
  // Replicate the browser's native behavior
26
26
  scrollToHashOrTop(href.split('#')[1]);
27
27
  return;
28
28
  }
29
- if (skipLink(linkTag))
29
+ if (isLinkSkipped(linkTag))
30
30
  return;
31
31
  ev.preventDefault();
32
32
  let scrollTarget;
@@ -14,7 +14,7 @@ import { catchInfiniteLoop } from './utils.js';
14
14
  // 2. URL hash changes:
15
15
  // - By the user clicking on `<a href="#some-hash">`
16
16
  // - The popstate event is *only* triggered if `href` starts with '#' (even if `href==='/foo#bar'` and the current URL has the same pathname '/foo' then popstate isn't triggered)
17
- // - Vike doesn't intercept hash links (see `skipLink()`) and let's the browser handle them.
17
+ // - Vike doesn't intercept hash links (see `isLinkSkipped()`) and let's the browser handle them.
18
18
  // - By the app using a `location` API such as `location.hash = 'some-hash'`
19
19
  // - Only upon hash navigation: setting `location.href='/foo'` triggers a full page reload and no popstate event is fired.
20
20
  // - Also upon `location.href='/foo#bar'` while the current URL is '/foo' (unlike <a> clicks).
@@ -0,0 +1,6 @@
1
+ export { isLinkSkipped };
2
+ export { isLinkIgnored };
3
+ export { isHrefCurrentUrl };
4
+ declare function isLinkSkipped(linkTag: HTMLElement): boolean;
5
+ declare function isLinkIgnored(linkTag: HTMLElement): boolean;
6
+ declare function isHrefCurrentUrl(href: string): boolean;
@@ -1,18 +1,17 @@
1
- // TODO: rename_full skipLink isLinkSkipped
2
- export { skipLink };
1
+ export { isLinkSkipped };
3
2
  export { isLinkIgnored };
4
- export { isSameAsCurrentUrl };
3
+ export { isHrefCurrentUrl };
5
4
  import { normalizeClientSideUrl } from '../shared/normalizeClientSideUrl.js';
6
5
  import { getBaseServer } from './getBaseServer.js';
7
6
  import { assert, parseUrl, isBaseServer, isUrl, isUrlExternal } from './utils.js';
8
- function skipLink(linkTag) {
7
+ function isLinkSkipped(linkTag) {
9
8
  const href = linkTag.getAttribute('href');
10
9
  return (href === null ||
11
10
  !isUrl(href) ||
12
11
  href === '' ||
13
12
  isUrlExternal(href) ||
14
- isSamePageHashLink(href) ||
15
- isNewTabLink(linkTag) ||
13
+ isHrefSamePageHash(href) ||
14
+ isLinkExternal(linkTag) ||
16
15
  isLinkIgnored(linkTag) ||
17
16
  !hasBaseServer(href) ||
18
17
  // Purposely last because disableAutomaticLinkInterception will be removed in the next major release
@@ -25,13 +24,11 @@ function isVikeLink(linkTag) {
25
24
  return true;
26
25
  }
27
26
  else {
28
- // TODO: rename target attrVal
29
- const target = linkTag.getAttribute('data-vike-link');
30
- return target !== null && target !== 'false';
27
+ const attrVal = linkTag.getAttribute('data-vike-link');
28
+ return attrVal !== null && attrVal !== 'false';
31
29
  }
32
30
  }
33
- // TODO rename
34
- function isNewTabLink(linkTag) {
31
+ function isLinkExternal(linkTag) {
35
32
  const target = linkTag.getAttribute('target');
36
33
  const rel = linkTag.getAttribute('rel');
37
34
  return target === '_blank' || target === '_external' || rel === 'external' || linkTag.hasAttribute('download');
@@ -39,11 +36,9 @@ function isNewTabLink(linkTag) {
39
36
  function isLinkIgnored(linkTag) {
40
37
  return linkTag.getAttribute('data-vike') === 'false';
41
38
  }
42
- // TODO refactor both functions below?
43
- function isSamePageHashLink(href) {
39
+ function isHrefSamePageHash(href) {
44
40
  if (href.startsWith('#'))
45
41
  return true;
46
- // TODO: remove?
47
42
  if (href.includes('#') &&
48
43
  normalizeClientSideUrl(href, { withoutHash: true }) ===
49
44
  normalizeClientSideUrl(window.location.href, { withoutHash: true })) {
@@ -51,7 +46,7 @@ function isSamePageHashLink(href) {
51
46
  }
52
47
  return false;
53
48
  }
54
- function isSameAsCurrentUrl(href) {
49
+ function isHrefCurrentUrl(href) {
55
50
  if (href.startsWith('#'))
56
51
  return href === window.location.hash;
57
52
  return normalizeClientSideUrl(href) === normalizeClientSideUrl(window.location.href);
@@ -7,7 +7,7 @@ export { addLinkPrefetchHandlers_watch };
7
7
  export { addLinkPrefetchHandlers_unwatch };
8
8
  import { assert, assertClientRouting, assertUsage, assertWarning, checkIfClientRouting, getGlobalObject, hasProp, objectAssign, } from './utils.js';
9
9
  import { isErrorFetchingStaticAssets, loadPageConfigsLazyClientSide } from '../shared/loadPageConfigsLazyClientSide.js';
10
- import { skipLink } from './skipLink.js';
10
+ import { isLinkSkipped } from './isLinkSkipped.js';
11
11
  import { disableClientRouting } from './renderPageClientSide.js';
12
12
  import { isClientSideRoutable } from './isClientSideRoutable.js';
13
13
  import { createPageContextClientSide } from './createPageContextClientSide.js';
@@ -170,7 +170,7 @@ function addLinkPrefetchHandlers_apply() {
170
170
  if (globalObject.linkPrefetchHandlerAdded.has(linkTag))
171
171
  continue;
172
172
  globalObject.linkPrefetchHandlerAdded.add(linkTag);
173
- if (skipLink(linkTag))
173
+ if (isLinkSkipped(linkTag))
174
174
  continue;
175
175
  linkTag.addEventListener('mouseover', () => {
176
176
  prefetchOnEvent(linkTag, 'hover');
@@ -205,7 +205,7 @@ async function prefetchOnEvent(linkTag, event) {
205
205
  }
206
206
  }
207
207
  // Check again in case DOM was manipulated since last check
208
- if (skipLink(linkTag))
208
+ if (isLinkSkipped(linkTag))
209
209
  return;
210
210
  const urlOfLink = linkTag.getAttribute('href');
211
211
  const pageContextLink = await getPageContextLink(urlOfLink);
@@ -1,6 +1,6 @@
1
1
  export { pluginViteConfigVikeExtensions };
2
2
  import { mergeConfig } from 'vite';
3
- import { assertUsage, isObject } from '../utils.js';
3
+ import { assertUsage, isCallable, isObject } from '../utils.js';
4
4
  import { getVikeConfigInternalEarly } from '../../api/resolveViteConfigFromUser.js';
5
5
  // Apply +vite
6
6
  // - For example, Vike extensions adding Vite plugins
@@ -12,10 +12,13 @@ async function pluginViteConfigVikeExtensions() {
12
12
  const viteConfigsExtensions = vikeConfig._from.configsCumulative.vite;
13
13
  if (!viteConfigsExtensions)
14
14
  return [];
15
- viteConfigsExtensions.values.forEach((v) => {
16
- assertUsage(isObject(v.value), `${v.definedAt} should be an object`);
17
- viteConfigFromExtensions = mergeConfig(viteConfigFromExtensions, v.value);
18
- });
15
+ await Promise.all(viteConfigsExtensions.values.map(async (v) => {
16
+ let val = v.value;
17
+ if (isCallable(val))
18
+ val = await val();
19
+ assertUsage(isObject(val), `${v.definedAt} should be an object, or a function returning an object`);
20
+ viteConfigFromExtensions = mergeConfig(viteConfigFromExtensions, val);
21
+ }));
19
22
  const pluginsFromExtensions = (viteConfigFromExtensions.plugins ?? []);
20
23
  delete viteConfigFromExtensions.plugins;
21
24
  return [
@@ -2,7 +2,6 @@ export { getVikeConfig };
2
2
  export type { VikeConfig };
3
3
  export { getVikeConfigInternal };
4
4
  export { getVikeConfigInternalOptional };
5
- export { getVikeConfigInternalSync };
6
5
  export { setVikeConfigContext };
7
6
  export { isVikeConfigContextSet };
8
7
  export { reloadVikeConfig };
@@ -38,13 +37,14 @@ type VikeConfigInternal = GlobalConfigPublic & {
38
37
  };
39
38
  declare function reloadVikeConfig(): void;
40
39
  declare function getVikeConfigInternal(doNotRestartViteOnError?: boolean): Promise<VikeConfigInternal>;
41
- declare function getVikeConfigInternalSync(): VikeConfigInternal;
42
40
  /**
43
41
  * Get all the information Vike knows about the app in your Vite plugin.
44
42
  *
45
43
  * https://vike.dev/getVikeConfig
46
44
  */
47
- declare function getVikeConfig(config: ResolvedConfig | UserConfig): VikeConfig;
45
+ declare function getVikeConfig(
46
+ /** @deprecated the `config` argument isn't needed anymore — remove it (it doesn't have any effect) */
47
+ config?: ResolvedConfig | UserConfig): VikeConfig;
48
48
  type VikeConfig = Pick<VikeConfigInternal, 'config' | 'pages' | 'prerenderContext'> & {
49
49
  /** https://vike.dev/warning/internals */
50
50
  dangerouslyUseInternals: DangerouslyUseInternals<VikeConfigInternal>;
@@ -3,7 +3,6 @@ export { getVikeConfig };
3
3
  // Internal usage
4
4
  export { getVikeConfigInternal };
5
5
  export { getVikeConfigInternalOptional };
6
- export { getVikeConfigInternalSync };
7
6
  export { setVikeConfigContext };
8
7
  export { isVikeConfigContextSet };
9
8
  export { reloadVikeConfig };
@@ -58,11 +57,6 @@ doNotRestartViteOnError = false) {
58
57
  const vikeConfig = await getOrResolveVikeConfig(userRootDir, isDev, vikeVitePluginOptions, doNotRestartViteOnError);
59
58
  return vikeConfig;
60
59
  }
61
- // TO-DO/next-major-release: remove
62
- function getVikeConfigInternalSync() {
63
- assert(globalObject.vikeConfigSync);
64
- return globalObject.vikeConfigSync;
65
- }
66
60
  // TO-DO/eventually: this maybe(/probably?) isn't safe against race conditions upon file changes in development, thus:
67
61
  // - Like getGlobalContext() and getGlobalContextSync() — make getVikeConfig() async and provide a getVikeConfigSync() while discourage using it
68
62
  // Public usage
@@ -72,10 +66,17 @@ function getVikeConfigInternalSync() {
72
66
  * https://vike.dev/getVikeConfig
73
67
  */
74
68
  function getVikeConfig(
75
- // TO-DO/eventually: remove unused arguments (older versions used it and we didn't remove it yet to avoid a TypeScript breaking change)
76
- // - No rush: we can do it later since it's getVikeConfig() is a beta feature as documented at https://vike.dev/getVikeConfig
69
+ /** @deprecated the `config` argument isn't needed anymore remove it (it doesn't have any effect) */
77
70
  config) {
78
- const vikeConfig = getVikeConfigInternalSync();
71
+ /* TO-DO/eventualy: add deprecation warning. We don't do it yet because of vike-server and vike-cloudflare which are using getVikeConfig() with the argument.
72
+ assertWarning(
73
+ config === undefined,
74
+ `getVikeConfig() doesn't accept any argument anymore — remove the argument (it doesn't have any effect)`,
75
+ { onlyOnce: true, showStackTrace: true },
76
+ )
77
+ */
78
+ assert(globalObject.vikeConfigSync);
79
+ const vikeConfig = globalObject.vikeConfigSync;
79
80
  assertUsage(vikeConfig, 'getVikeConfig() can only be used when Vite is loaded (i.e. during development or build) — Vite is never loaded in production.');
80
81
  const vikeConfigPublic = getProxyForPublicUsage(vikeConfig, 'vikeConfig');
81
82
  return vikeConfigPublic;
@@ -386,7 +386,7 @@ type ConfigBuiltIn = {
386
386
  *
387
387
  * https://vite.dev/config/
388
388
  */
389
- vite?: InlineConfig;
389
+ vite?: InlineConfig | (() => InlineConfig | Promise<InlineConfig>);
390
390
  /** Permanent redirections (HTTP status code 301)
391
391
  *
392
392
  * https://vike.dev/redirects
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.244-commit-a8703f7";
1
+ export declare const PROJECT_VERSION: "0.4.244-commit-aae383f";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.244-commit-a8703f7';
2
+ export const PROJECT_VERSION = '0.4.244-commit-aae383f';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.244-commit-a8703f7",
3
+ "version": "0.4.244-commit-aae383f",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -1,6 +0,0 @@
1
- export { skipLink };
2
- export { isLinkIgnored };
3
- export { isSameAsCurrentUrl };
4
- declare function skipLink(linkTag: HTMLElement): boolean;
5
- declare function isLinkIgnored(linkTag: HTMLElement): boolean;
6
- declare function isSameAsCurrentUrl(href: string): boolean;