vike 0.4.243 → 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.
Files changed (36) hide show
  1. package/dist/esm/client/runtime-client-routing/getGlobalContextClientInternal.d.ts +0 -3
  2. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +4 -4
  3. package/dist/esm/client/runtime-client-routing/initOnLinkClick.js +3 -3
  4. package/dist/esm/client/runtime-client-routing/initOnPopState.js +1 -1
  5. package/dist/esm/client/runtime-client-routing/isLinkSkipped.d.ts +6 -0
  6. package/dist/esm/client/runtime-client-routing/{skipLink.js → isLinkSkipped.js} +10 -15
  7. package/dist/esm/client/runtime-client-routing/prefetch.js +3 -3
  8. package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +149 -2
  9. package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +4 -4
  10. package/dist/esm/client/runtime-server-routing/getGlobalContextClientInternal.d.ts +0 -3
  11. package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +4 -1
  12. package/dist/esm/node/api/preview.d.ts +3 -0
  13. package/dist/esm/node/api/preview.js +18 -2
  14. package/dist/esm/node/api/utils.d.ts +1 -0
  15. package/dist/esm/node/api/utils.js +1 -0
  16. package/dist/esm/node/runtime/globalContext.d.ts +2 -4
  17. package/dist/esm/node/runtime/renderPage.d.ts +283 -0
  18. package/dist/esm/node/vite/plugins/build/handleAssetsManifest.js +4 -3
  19. package/dist/esm/node/vite/plugins/build/pluginBuildApp.js +1 -1
  20. package/dist/esm/node/vite/plugins/pluginViteConfigVikeExtensions.js +8 -5
  21. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +4 -0
  22. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +8 -4
  23. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +10 -9
  24. package/dist/esm/shared/getProxyForPublicUsage.d.ts +8 -1
  25. package/dist/esm/shared/getProxyForPublicUsage.js +24 -24
  26. package/dist/esm/shared/prepareGlobalContextForPublicUsage.d.ts +4 -1
  27. package/dist/esm/shared/preparePageContextForPublicUsage.d.ts +4 -1
  28. package/dist/esm/types/Config.d.ts +8 -2
  29. package/dist/esm/types/GlobalContext.d.ts +18 -0
  30. package/dist/esm/types/GlobalContext.js +1 -0
  31. package/dist/esm/types/PageContext.d.ts +12 -10
  32. package/dist/esm/types/index.d.ts +2 -1
  33. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  34. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  35. package/package.json +1 -1
  36. package/dist/esm/client/runtime-client-routing/skipLink.d.ts +0 -6
@@ -1,8 +1,5 @@
1
1
  export { getGlobalContextClientInternal };
2
- export type { GlobalContextClient };
3
2
  export type { GlobalContextClientInternal };
4
- import type { GlobalContextBasePublic } from '../../shared/createGlobalContextShared.js';
5
- type GlobalContextClient = GlobalContextBasePublic & Pick<GlobalContextClientInternal, 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextClient & {};
6
3
  type GlobalContextClientInternal = Awaited<ReturnType<typeof getGlobalContextClientInternal>>;
7
4
  declare function getGlobalContextClientInternal(): Promise<{
8
5
  _globalConfigPublic: {
@@ -145,7 +145,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
145
145
  isHydration: boolean;
146
146
  isBackwardNavigation: boolean | null;
147
147
  previousPageContext: import("../../types/PageContext.js").PageContextClient<unknown> | null;
148
- globalContext: import("./getGlobalContextClientInternal.js").GlobalContextClient;
148
+ globalContext: import("../../types/GlobalContext.js").GlobalContextClient;
149
149
  } & {
150
150
  urlOriginal: string;
151
151
  } & {
@@ -210,7 +210,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
210
210
  isHydration: boolean;
211
211
  isBackwardNavigation: boolean | null;
212
212
  previousPageContext: import("../../types/PageContext.js").PageContextClient<unknown> | null;
213
- globalContext: import("./getGlobalContextClientInternal.js").GlobalContextClient;
213
+ globalContext: import("../../types/GlobalContext.js").GlobalContextClient;
214
214
  } & {
215
215
  urlOriginal: string;
216
216
  } & {
@@ -366,7 +366,7 @@ declare function getPageContextFromClientHooks(pageContext: {
366
366
  isHydration: boolean;
367
367
  isBackwardNavigation: boolean | null;
368
368
  previousPageContext: import("../../types/PageContext.js").PageContextClient<unknown> | null;
369
- globalContext: import("./getGlobalContextClientInternal.js").GlobalContextClient;
369
+ globalContext: import("../../types/GlobalContext.js").GlobalContextClient;
370
370
  } & {
371
371
  urlOriginal: string;
372
372
  } & {
@@ -429,7 +429,7 @@ declare function getPageContextFromClientHooks(pageContext: {
429
429
  isHydration: boolean;
430
430
  isBackwardNavigation: boolean | null;
431
431
  previousPageContext: import("../../types/PageContext.js").PageContextClient<unknown> | null;
432
- globalContext: import("./getGlobalContextClientInternal.js").GlobalContextClient;
432
+ globalContext: import("../../types/GlobalContext.js").GlobalContextClient;
433
433
  } & {
434
434
  urlOriginal: string;
435
435
  } & {
@@ -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);
@@ -4,11 +4,13 @@ export { disableClientRouting };
4
4
  export { firstRenderStartPromise };
5
5
  export { getPageContextClient };
6
6
  export type { PageContextBegin };
7
+ export type { PageContextInternalClientAfterRender };
7
8
  import { type PageContextFromRewrite } from '../../shared/route/abort.js';
8
9
  import { type ScrollTarget } from './setScrollPosition.js';
9
10
  import type { PageContextConfig } from '../../shared/getPageFiles.js';
10
11
  import type { PageContextClient, PageContextInternalClient } from '../../types/PageContext.js';
11
12
  import type { VikeGlobalInternal } from '../../types/VikeGlobalInternal.js';
13
+ type PageContextInternalClientAfterRender = NonNullable<Awaited<ReturnType<typeof renderPageClientSide>>>;
12
14
  declare const firstRenderStartPromise: Promise<void>;
13
15
  type PageContextRouted = {
14
16
  pageId: string;
@@ -26,7 +28,152 @@ type RenderArgs = {
26
28
  isClientSideNavigation?: boolean;
27
29
  pageContextInitClient?: Record<string, unknown>;
28
30
  };
29
- declare function renderPageClientSide(renderArgs: RenderArgs): Promise<void>;
31
+ declare function renderPageClientSide(renderArgs: RenderArgs): Promise<({
32
+ _pageFilesLoaded: import("../../shared/getPageFiles.js").PageFile[];
33
+ urlOriginal?: string;
34
+ urlPathname?: string;
35
+ pageId: string;
36
+ _globalContext: import("../shared/getGlobalContextClientInternalShared.js").GlobalContextClientInternalShared;
37
+ } & PageContextConfig & import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum & PageContextInternalClient & {
38
+ _isOriginalObject: true;
39
+ isPageContext: true;
40
+ } & {
41
+ isClientSide: true;
42
+ isPrerendering: false;
43
+ urlOriginal: string;
44
+ _globalContext: {
45
+ _globalConfigPublic: {
46
+ pages: {
47
+ [k: string]: {
48
+ config: import("../../types/index.js").ConfigResolved;
49
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
50
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
51
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
52
+ } & ({
53
+ route: import("../../types/Config.js").Route;
54
+ isErrorPage?: undefined;
55
+ } | {
56
+ route?: undefined;
57
+ isErrorPage: true;
58
+ });
59
+ };
60
+ config: import("../../types/index.js").ConfigResolved;
61
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
62
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
63
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
64
+ };
65
+ pages: {
66
+ [k: string]: {
67
+ config: import("../../types/index.js").ConfigResolved;
68
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
69
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
70
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
71
+ } & ({
72
+ route: import("../../types/Config.js").Route;
73
+ isErrorPage?: undefined;
74
+ } | {
75
+ route?: undefined;
76
+ isErrorPage: true;
77
+ });
78
+ };
79
+ config: import("../../types/index.js").ConfigResolved;
80
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
81
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
82
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
83
+ isGlobalContext: true;
84
+ _isOriginalObject: true;
85
+ _virtualFileExportsGlobalEntry: unknown;
86
+ _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
87
+ _pageConfigs: import("../../types/PageConfig.js").PageConfigRuntime[];
88
+ _pageConfigGlobal: import("../../types/PageConfig.js").PageConfigGlobalRuntime;
89
+ _allPageIds: string[];
90
+ } & {
91
+ isClientSide: true;
92
+ } & {
93
+ _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
94
+ _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
95
+ };
96
+ _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
97
+ _urlHandler: null;
98
+ _urlRewrite: null | string;
99
+ _baseServer: string;
100
+ } & {
101
+ urlParsed: import("./utils.js").UrlPublic;
102
+ urlPathname: string;
103
+ url: string;
104
+ } & import("../../shared/page-configs/resolveVikeConfigPublic.js").GlobalConfigPublic & {
105
+ isBackwardNavigation: boolean | null;
106
+ isClientSideNavigation: boolean;
107
+ isHydration: boolean;
108
+ previousPageContext: ({
109
+ pageId: string;
110
+ } & PageContextConfig & PageContextRouted & import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum & PageContextInternalClient & Omit<Partial<PageContextConfig & {
111
+ isPageContext: true;
112
+ Page: import("../../types/Config.js").Config["Page"];
113
+ routeParams: Record<string, string>;
114
+ data: unknown;
115
+ urlOriginal: string;
116
+ headers: Record<string, string> | null;
117
+ headersOriginal?: unknown;
118
+ headersResponse: Headers;
119
+ is404: boolean | null;
120
+ isClientSideNavigation: boolean;
121
+ abortReason?: unknown;
122
+ abortStatusCode?: import("../../shared/route/abort.js").AbortStatusCode;
123
+ errorWhileRendering?: unknown;
124
+ pageId: string | null;
125
+ from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
126
+ source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
127
+ sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
128
+ url: string;
129
+ pageExports: Record<string, unknown>;
130
+ isBaseMissing?: true;
131
+ }> & Pick<PageContextConfig & {
132
+ isPageContext: true;
133
+ Page: import("../../types/Config.js").Config["Page"];
134
+ routeParams: Record<string, string>;
135
+ data: unknown;
136
+ urlOriginal: string;
137
+ headers: Record<string, string> | null;
138
+ headersOriginal?: unknown;
139
+ headersResponse: Headers;
140
+ is404: boolean | null;
141
+ isClientSideNavigation: boolean;
142
+ abortReason?: unknown;
143
+ abortStatusCode?: import("../../shared/route/abort.js").AbortStatusCode;
144
+ errorWhileRendering?: unknown;
145
+ pageId: string | null;
146
+ from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
147
+ source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
148
+ sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
149
+ url: string;
150
+ pageExports: Record<string, unknown>;
151
+ isBaseMissing?: true;
152
+ }, "exports" | "pageId" | "pageExports" | "config" | "Page" | "data" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "routeParams" | "abortReason"> & {
153
+ isClientSide: true;
154
+ isPrerendering: false;
155
+ } & {
156
+ isHydration: boolean;
157
+ isBackwardNavigation: boolean | null;
158
+ previousPageContext: PageContextClient<unknown> | null;
159
+ globalContext: import("../../types/GlobalContext.js").GlobalContextClient;
160
+ } & {
161
+ urlOriginal: string;
162
+ } & {
163
+ urlParsed: import("./utils.js").UrlPublic;
164
+ urlPathname: string;
165
+ url: string;
166
+ }, ("globalContext" | "Page" | "data") | "previousPageContext"> & {
167
+ previousPageContext: {
168
+ pageId: string;
169
+ } | null;
170
+ } & {
171
+ urlOriginal: string;
172
+ }) | null;
173
+ } & {
174
+ urlPathname: string;
175
+ _hasPageContextFromServer: boolean;
176
+ } & PageContextRouted) | undefined>;
30
177
  declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isBackwardNavigation, pageContextsFromRewrite, isClientSideNavigation, pageContextInitClient, isFirstRender, }: {
31
178
  urlOriginal: string;
32
179
  isBackwardNavigation: boolean | null;
@@ -156,7 +303,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
156
303
  isHydration: boolean;
157
304
  isBackwardNavigation: boolean | null;
158
305
  previousPageContext: PageContextClient<unknown> | null;
159
- globalContext: import("./getGlobalContextClientInternal.js").GlobalContextClient;
306
+ globalContext: import("../../types/GlobalContext.js").GlobalContextClient;
160
307
  } & {
161
308
  urlOriginal: string;
162
309
  } & {
@@ -57,8 +57,7 @@ async function renderPageClientSide(renderArgs) {
57
57
  globalObject.firstRenderStartPromiseResolve();
58
58
  if (isRenderOutdated())
59
59
  return;
60
- await renderPageNominal();
61
- return;
60
+ return await renderPageNominal();
62
61
  async function renderPageNominal() {
63
62
  const onError = async (err) => {
64
63
  await handleError({ err });
@@ -187,7 +186,7 @@ async function renderPageClientSide(renderArgs) {
187
186
  return;
188
187
  updateType(pageContext, pageContextAugmented);
189
188
  // Render page view
190
- await renderPageView(pageContext);
189
+ return await renderPageView(pageContext);
191
190
  }
192
191
  else {
193
192
  // Fetch pageContext from server-side hooks
@@ -227,7 +226,7 @@ async function renderPageClientSide(renderArgs) {
227
226
  if (isRenderOutdated())
228
227
  return;
229
228
  updateType(pageContext, pageContextFromClientHooks);
230
- await renderPageView(pageContext);
229
+ return await renderPageView(pageContext);
231
230
  }
232
231
  }
233
232
  // When the normal page threw an error:
@@ -474,6 +473,7 @@ async function renderPageClientSide(renderArgs) {
474
473
  addLinkPrefetchHandlers();
475
474
  globalObject.renderedPageContext = pageContext;
476
475
  stampFinished(urlOriginal);
476
+ return pageContext;
477
477
  }
478
478
  }
479
479
  async function getPageContextBegin(isForErrorPage, { urlOriginal, isBackwardNavigation, pageContextsFromRewrite, isClientSideNavigation, pageContextInitClient, isFirstRender, }) {
@@ -1,8 +1,5 @@
1
1
  export { getGlobalContextClientInternal };
2
- export type { GlobalContextClientWithServerRouting };
3
2
  export type { GlobalContextClientInternalWithServerRouting };
4
- import type { GlobalContextBasePublic } from '../../shared/createGlobalContextShared.js';
5
- type GlobalContextClientWithServerRouting = GlobalContextBasePublic & Pick<GlobalContextClientInternalWithServerRouting, 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextClient & {};
6
3
  type GlobalContextClientInternalWithServerRouting = Awaited<ReturnType<typeof getGlobalContextClientInternal>>;
7
4
  declare function getGlobalContextClientInternal(): Promise<{
8
5
  _globalConfigPublic: {
@@ -8,4 +8,7 @@ type PageContextForPublicUsageClientShared = PageContextPrepareMinimum & PageCon
8
8
  declare function preparePageContextForPublicUsageClientShared<PageContext extends PageContextForPublicUsageClientShared>(pageContext: PageContext): PageContext & {
9
9
  Page: unknown;
10
10
  };
11
- declare function preparePageContextForPublicUsageClientMinimal<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext;
11
+ declare function preparePageContextForPublicUsageClientMinimal<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext & {
12
+ _isProxyObject: true;
13
+ dangerouslyUseInternals: PageContext;
14
+ };
@@ -1,4 +1,5 @@
1
1
  export { preview };
2
+ export type { CliPreviewConfig };
2
3
  import { type ResolvedConfig, type PreviewServer } from 'vite';
3
4
  import type { ApiOptions } from './types.js';
4
5
  /**
@@ -10,3 +11,5 @@ declare function preview(options?: ApiOptions): Promise<{
10
11
  viteServer?: PreviewServer;
11
12
  viteConfig: ResolvedConfig;
12
13
  }>;
14
+ type CliPreviewValue = boolean | 'vite' | undefined;
15
+ type CliPreviewConfig = CliPreviewValue | (() => CliPreviewValue | Promise<CliPreviewValue>);
@@ -3,9 +3,10 @@ import { prepareViteApiCall } from './prepareViteApiCall.js';
3
3
  import { preview as previewVite } from 'vite';
4
4
  import { importServerProductionIndex } from '@brillout/vite-plugin-server-entry/runtime';
5
5
  import { getOutDirs } from '../vite/shared/getOutDirs.js';
6
- import { assertWarning, onSetupPreview } from './utils.js';
6
+ import { assertUsage, assertWarning, onSetupPreview, isCallable } from './utils.js';
7
7
  import pc from '@brillout/picocolors';
8
8
  import path from 'node:path';
9
+ import { getVikeConfigInternal } from '../vite/shared/resolveVikeConfigInternal.js';
9
10
  /**
10
11
  * Programmatically trigger `$ vike preview`
11
12
  *
@@ -14,7 +15,11 @@ import path from 'node:path';
14
15
  async function preview(options = {}) {
15
16
  onSetupPreview();
16
17
  const { viteConfigFromUserResolved, viteConfigResolved } = await prepareViteApiCall(options, 'preview');
17
- if (viteConfigResolved.vitePluginServerEntry?.inject) {
18
+ const cliPreview = await resolveCliPreviewConfig();
19
+ assertUsage(cliPreview !== false, `${pc.cyan('$ vike preview')} isn't supported`);
20
+ const useVite = cliPreview === 'vite' || (cliPreview === undefined && !viteConfigResolved.vitePluginServerEntry?.inject);
21
+ if (!useVite) {
22
+ // Dynamically import() server production entry dist/server/index.js
18
23
  const outDir = getOutDirs(viteConfigResolved, undefined).outDirRoot;
19
24
  const { outServerIndex } = await importServerProductionIndex({ outDir });
20
25
  const outServerIndexRelative = path.relative(viteConfigResolved.root, outServerIndex);
@@ -24,6 +29,7 @@ async function preview(options = {}) {
24
29
  };
25
30
  }
26
31
  else {
32
+ // Use Vite's preview server
27
33
  const server = await previewVite(viteConfigFromUserResolved);
28
34
  return {
29
35
  viteServer: server,
@@ -31,3 +37,13 @@ async function preview(options = {}) {
31
37
  };
32
38
  }
33
39
  }
40
+ async function resolveCliPreviewConfig() {
41
+ const vikeConfig = await getVikeConfigInternal();
42
+ const val = vikeConfig.config.cli?.preview;
43
+ if (!isCallable(val)) {
44
+ return val;
45
+ }
46
+ else {
47
+ return await val();
48
+ }
49
+ }
@@ -5,3 +5,4 @@ export * from '../../utils/isObject.js';
5
5
  export * from '../../utils/assertVersion.js';
6
6
  export * from '../../utils/pick.js';
7
7
  export * from '../../utils/assertSetup.js';
8
+ export * from '../../utils/isCallable.js';
@@ -9,3 +9,4 @@ export * from '../../utils/isObject.js';
9
9
  export * from '../../utils/assertVersion.js';
10
10
  export * from '../../utils/pick.js';
11
11
  export * from '../../utils/assertSetup.js';
12
+ export * from '../../utils/isCallable.js';
@@ -20,17 +20,15 @@ export { updateUserFiles };
20
20
  export { isRunnable };
21
21
  export { vikeConfigErrorRecoverMsg };
22
22
  export type { BuildInfo };
23
- export type { GlobalContextServerInternal as GlobalContextServerInternal };
24
- export type { GlobalContextServer };
23
+ export type { GlobalContextServerInternal };
25
24
  import type { ViteManifest } from '../../types/ViteManifest.js';
26
25
  import type { ResolvedConfig, ViteDevServer } from 'vite';
27
26
  import { type PageRoutes } from '../../shared/route/loadPageRoutes.js';
28
27
  import type { ViteConfigRuntime } from '../vite/shared/getViteConfigRuntime.js';
29
- import type { GlobalContext } from '../../types/PageContext.js';
28
+ import type { GlobalContext } from '../../types/GlobalContext.js';
30
29
  import type { Hook } from '../../shared/hooks/getHook.js';
31
30
  import type { PrerenderContext } from '../../types/index.js';
32
31
  declare const vikeConfigErrorRecoverMsg: "Vike config loaded";
33
- type GlobalContextServer = Pick<GlobalContextServerInternal, 'assetsManifest' | 'config' | 'viteConfig' | 'viteConfigRuntime' | 'pages' | 'baseServer' | 'baseAssets' | 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextServer;
34
32
  type GlobalContextServerInternal = Awaited<ReturnType<typeof createGlobalContext>>;
35
33
  declare function getGlobalContextServerInternal(): Promise<{
36
34
  globalContext: (Record<string, unknown> & {
@@ -2,6 +2,7 @@ export { renderPage };
2
2
  export { renderPage_addAsyncHookwrapper };
3
3
  export type { PageContextInit };
4
4
  export type { PageContextBegin };
5
+ export type { PageContextInternalServerAfterRender };
5
6
  import { type GlobalContextServerInternal } from './globalContext.js';
6
7
  import { type HttpResponse } from './renderPage/createHttpResponse.js';
7
8
  import type { PageContextServer } from '../../types/index.js';
@@ -21,6 +22,288 @@ declare function renderPage<PageContextUserAdded extends {}, PageContextInitUser
21
22
  httpResponse: HttpResponse;
22
23
  } & Partial<PageContextServer & PageContextUserAdded>>;
23
24
  declare function renderPage_addAsyncHookwrapper(wrapper: typeof globalObject.asyncHookWrapper): void;
25
+ type PageContextInternalServerAfterRender = Awaited<ReturnType<typeof renderPageNominal>>;
26
+ declare function renderPageNominal(pageContext: PageContextBegin): Promise<({
27
+ _isOriginalObject: true;
28
+ isPageContext: true;
29
+ } & {
30
+ isClientSide: false;
31
+ isPrerendering: boolean;
32
+ } & Pick<PageContextInternalServer, "urlOriginal" | "headersOriginal"> & {
33
+ /** @deprecated Set `pageContextInit.urlOriginal` instead */ url?: string;
34
+ /** @deprecated Set pageContextInit.headersOriginal instead */ headers?: Record<string, string>;
35
+ } & {
36
+ _globalContext: ({
37
+ _globalConfigPublic: {
38
+ pages: {
39
+ [k: string]: {
40
+ config: import("../../types/index.js").ConfigResolved;
41
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
42
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
43
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
44
+ } & ({
45
+ route: import("../../types/Config.js").Route;
46
+ isErrorPage?: undefined;
47
+ } | {
48
+ route?: undefined;
49
+ isErrorPage: true;
50
+ });
51
+ };
52
+ config: import("../../types/index.js").ConfigResolved;
53
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
54
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
55
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
56
+ };
57
+ pages: {
58
+ [k: string]: {
59
+ config: import("../../types/index.js").ConfigResolved;
60
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
61
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
62
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
63
+ } & ({
64
+ route: import("../../types/Config.js").Route;
65
+ isErrorPage?: undefined;
66
+ } | {
67
+ route?: undefined;
68
+ isErrorPage: true;
69
+ });
70
+ };
71
+ config: import("../../types/index.js").ConfigResolved;
72
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
73
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
74
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
75
+ isGlobalContext: true;
76
+ _isOriginalObject: true;
77
+ _virtualFileExportsGlobalEntry: unknown;
78
+ _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
79
+ _pageConfigs: import("../../types/PageConfig.js").PageConfigRuntime[];
80
+ _pageConfigGlobal: import("../../types/PageConfig.js").PageConfigGlobalRuntime;
81
+ _allPageIds: string[];
82
+ } & (({
83
+ _isProduction: false;
84
+ _isPrerendering: false;
85
+ assetsManifest: null;
86
+ _viteDevServer: import("vite").ViteDevServer | undefined;
87
+ viteConfig: import("vite").ResolvedConfig | undefined;
88
+ isClientSide: false;
89
+ _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
90
+ _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
91
+ } | {
92
+ _isPrerendering: true;
93
+ viteConfig: import("vite").ResolvedConfig;
94
+ _isProduction: true;
95
+ assetsManifest: import("../../types/ViteManifest.js").ViteManifest;
96
+ _viteDevServer: null;
97
+ _usesClientRouter: boolean;
98
+ isClientSide: false;
99
+ _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
100
+ _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
101
+ } | {
102
+ _isPrerendering: false;
103
+ viteConfig: null;
104
+ _isProduction: true;
105
+ assetsManifest: import("../../types/ViteManifest.js").ViteManifest;
106
+ _viteDevServer: null;
107
+ _usesClientRouter: boolean;
108
+ isClientSide: false;
109
+ _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
110
+ _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
111
+ }) & {
112
+ baseServer: string;
113
+ baseAssets: string;
114
+ viteConfigRuntime: {
115
+ root: string;
116
+ build: {
117
+ outDir: string;
118
+ };
119
+ _baseViteOriginal: string;
120
+ vitePluginServerEntry: {
121
+ inject: boolean | undefined;
122
+ };
123
+ };
124
+ })) & {
125
+ prerenderContext: import("../prerender/runPrerender.js").PrerenderContextPublic | undefined;
126
+ };
127
+ _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
128
+ _baseServer: string;
129
+ _baseAssets: string;
130
+ _pageContextInit: PageContextInit;
131
+ _urlRewrite: null;
132
+ _urlHandler: ((url: string) => string) | null;
133
+ isClientSideNavigation: boolean;
134
+ } & {
135
+ pages: {
136
+ [k: string]: {
137
+ config: import("../../types/index.js").ConfigResolved;
138
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
139
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
140
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
141
+ } & ({
142
+ route: import("../../types/Config.js").Route;
143
+ isErrorPage?: undefined;
144
+ } | {
145
+ route?: undefined;
146
+ isErrorPage: true;
147
+ });
148
+ };
149
+ config: import("../../types/index.js").ConfigResolved;
150
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
151
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
152
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
153
+ } & {
154
+ urlParsed: import("./utils.js").UrlPublic;
155
+ urlPathname: string;
156
+ url: string;
157
+ } & {
158
+ headers: Record<string, string> | null;
159
+ } & {
160
+ _httpRequestId: number;
161
+ _isPageContextJsonRequest: boolean;
162
+ } & {
163
+ errorWhileRendering: null;
164
+ } & import("../../shared/route/index.js").PageContextAfterRoute & {
165
+ is404: boolean | null;
166
+ } & Record<"pageId", null> & import("./renderPage/renderPageAfterRoute.js").PageContextAfterRender) | ({
167
+ _isOriginalObject: true;
168
+ isPageContext: true;
169
+ } & {
170
+ isClientSide: false;
171
+ isPrerendering: boolean;
172
+ } & Pick<PageContextInternalServer, "urlOriginal" | "headersOriginal"> & {
173
+ /** @deprecated Set `pageContextInit.urlOriginal` instead */ url?: string;
174
+ /** @deprecated Set pageContextInit.headersOriginal instead */ headers?: Record<string, string>;
175
+ } & {
176
+ _globalContext: ({
177
+ _globalConfigPublic: {
178
+ pages: {
179
+ [k: string]: {
180
+ config: import("../../types/index.js").ConfigResolved;
181
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
182
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
183
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
184
+ } & ({
185
+ route: import("../../types/Config.js").Route;
186
+ isErrorPage?: undefined;
187
+ } | {
188
+ route?: undefined;
189
+ isErrorPage: true;
190
+ });
191
+ };
192
+ config: import("../../types/index.js").ConfigResolved;
193
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
194
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
195
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
196
+ };
197
+ pages: {
198
+ [k: string]: {
199
+ config: import("../../types/index.js").ConfigResolved;
200
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
201
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
202
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
203
+ } & ({
204
+ route: import("../../types/Config.js").Route;
205
+ isErrorPage?: undefined;
206
+ } | {
207
+ route?: undefined;
208
+ isErrorPage: true;
209
+ });
210
+ };
211
+ config: import("../../types/index.js").ConfigResolved;
212
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
213
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
214
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
215
+ isGlobalContext: true;
216
+ _isOriginalObject: true;
217
+ _virtualFileExportsGlobalEntry: unknown;
218
+ _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
219
+ _pageConfigs: import("../../types/PageConfig.js").PageConfigRuntime[];
220
+ _pageConfigGlobal: import("../../types/PageConfig.js").PageConfigGlobalRuntime;
221
+ _allPageIds: string[];
222
+ } & (({
223
+ _isProduction: false;
224
+ _isPrerendering: false;
225
+ assetsManifest: null;
226
+ _viteDevServer: import("vite").ViteDevServer | undefined;
227
+ viteConfig: import("vite").ResolvedConfig | undefined;
228
+ isClientSide: false;
229
+ _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
230
+ _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
231
+ } | {
232
+ _isPrerendering: true;
233
+ viteConfig: import("vite").ResolvedConfig;
234
+ _isProduction: true;
235
+ assetsManifest: import("../../types/ViteManifest.js").ViteManifest;
236
+ _viteDevServer: null;
237
+ _usesClientRouter: boolean;
238
+ isClientSide: false;
239
+ _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
240
+ _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
241
+ } | {
242
+ _isPrerendering: false;
243
+ viteConfig: null;
244
+ _isProduction: true;
245
+ assetsManifest: import("../../types/ViteManifest.js").ViteManifest;
246
+ _viteDevServer: null;
247
+ _usesClientRouter: boolean;
248
+ isClientSide: false;
249
+ _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
250
+ _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
251
+ }) & {
252
+ baseServer: string;
253
+ baseAssets: string;
254
+ viteConfigRuntime: {
255
+ root: string;
256
+ build: {
257
+ outDir: string;
258
+ };
259
+ _baseViteOriginal: string;
260
+ vitePluginServerEntry: {
261
+ inject: boolean | undefined;
262
+ };
263
+ };
264
+ })) & {
265
+ prerenderContext: import("../prerender/runPrerender.js").PrerenderContextPublic | undefined;
266
+ };
267
+ _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
268
+ _baseServer: string;
269
+ _baseAssets: string;
270
+ _pageContextInit: PageContextInit;
271
+ _urlRewrite: null;
272
+ _urlHandler: ((url: string) => string) | null;
273
+ isClientSideNavigation: boolean;
274
+ } & {
275
+ pages: {
276
+ [k: string]: {
277
+ config: import("../../types/index.js").ConfigResolved;
278
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
279
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
280
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
281
+ } & ({
282
+ route: import("../../types/Config.js").Route;
283
+ isErrorPage?: undefined;
284
+ } | {
285
+ route?: undefined;
286
+ isErrorPage: true;
287
+ });
288
+ };
289
+ config: import("../../types/index.js").ConfigResolved;
290
+ _source: import("../../shared/page-configs/resolveVikeConfigPublic.js").Source;
291
+ _sources: import("../../shared/page-configs/resolveVikeConfigPublic.js").Sources;
292
+ _from: import("../../shared/page-configs/resolveVikeConfigPublic.js").From;
293
+ } & {
294
+ urlParsed: import("./utils.js").UrlPublic;
295
+ urlPathname: string;
296
+ url: string;
297
+ } & {
298
+ headers: Record<string, string> | null;
299
+ } & {
300
+ _httpRequestId: number;
301
+ _isPageContextJsonRequest: boolean;
302
+ } & {
303
+ errorWhileRendering: null;
304
+ } & import("../../shared/route/index.js").PageContextAfterRoute & {
305
+ is404: boolean | null;
306
+ } & Record<"pageId", string> & import("./renderPage/renderPageAfterRoute.js").PageContextAfterRender)>;
24
307
  declare function getPageContextBegin(pageContextInit: PageContextInit, globalContext: GlobalContextServerInternal, httpRequestId: number): {
25
308
  _isOriginalObject: true;
26
309
  isPageContext: true;
@@ -221,9 +221,10 @@ function handleAssetsManifest_assertUsageCssCodeSplit(config) {
221
221
  }
222
222
  function handleAssetsManifest_alignCssTarget(config) {
223
223
  globalObject.configsAll.push(config);
224
- const { cssTarget } = globalObject.configsAll
225
- .filter((c) => !isViteServerSide_viteEnvOptional(c, undefined))
226
- .at(-1).build;
224
+ const clientSideConfigs = globalObject.configsAll.filter((c) => !isViteServerSide_viteEnvOptional(c, undefined));
225
+ if (clientSideConfigs.length === 0)
226
+ return;
227
+ const { cssTarget } = clientSideConfigs.at(-1).build;
227
228
  assert(cssTarget);
228
229
  globalObject.configsAll.forEach((c) => (c.build.cssTarget = cssTarget));
229
230
  }
@@ -89,6 +89,7 @@ function pluginBuildApp() {
89
89
  */
90
90
  async handler(options, bundle) {
91
91
  try {
92
+ handleAssetsManifest_assertUsageCssTarget(config, this.environment);
92
93
  await handleAssetsManifest(config, this.environment, options, bundle);
93
94
  await triggerPrerendering(config, this.environment, bundle);
94
95
  }
@@ -112,7 +113,6 @@ function pluginBuildApp() {
112
113
  order: 'post',
113
114
  handler() {
114
115
  onSetupBuild();
115
- handleAssetsManifest_assertUsageCssTarget(config, this.environment);
116
116
  },
117
117
  },
118
118
  },
@@ -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 [
@@ -196,6 +196,10 @@ const configDefinitionsBuiltIn = {
196
196
  env: { client: true },
197
197
  },
198
198
  middleware: { env: { server: true }, cumulative: true, eager: true, global: true },
199
+ cli: {
200
+ env: { config: true },
201
+ global: true,
202
+ },
199
203
  onPrerenderStart: {
200
204
  env: { server: true, production: true },
201
205
  eager: true,
@@ -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 };
@@ -18,6 +17,7 @@ import { type GlobalConfigPublic } from '../../../shared/page-configs/resolveVik
18
17
  import { type PlusFile } from './resolveVikeConfigInternal/getPlusFilesAll.js';
19
18
  import type { PrerenderContextPublic } from '../../prerender/runPrerender.js';
20
19
  import type { ResolvedConfig, UserConfig } from 'vite';
20
+ import { type DangerouslyUseInternals } from '../../../shared/getProxyForPublicUsage.js';
21
21
  type VikeConfigContext = {
22
22
  userRootDir: string;
23
23
  isDev: boolean;
@@ -37,14 +37,18 @@ type VikeConfigInternal = GlobalConfigPublic & {
37
37
  };
38
38
  declare function reloadVikeConfig(): void;
39
39
  declare function getVikeConfigInternal(doNotRestartViteOnError?: boolean): Promise<VikeConfigInternal>;
40
- declare function getVikeConfigInternalSync(): VikeConfigInternal;
41
40
  /**
42
41
  * Get all the information Vike knows about the app in your Vite plugin.
43
42
  *
44
43
  * https://vike.dev/getVikeConfig
45
44
  */
46
- declare function getVikeConfig(config: ResolvedConfig | UserConfig): VikeConfig;
47
- type VikeConfig = Pick<VikeConfigInternal, 'config' | 'pages' | 'prerenderContext'>;
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
+ type VikeConfig = Pick<VikeConfigInternal, 'config' | 'pages' | 'prerenderContext'> & {
49
+ /** https://vike.dev/warning/internals */
50
+ dangerouslyUseInternals: DangerouslyUseInternals<VikeConfigInternal>;
51
+ };
48
52
  declare function setVikeConfigContext(vikeConfigCtx_: VikeConfigContext): void;
49
53
  declare function isVikeConfigContextSet(): boolean;
50
54
  declare function getVikeConfigInternalOptional(): Promise<null | 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;
@@ -1,4 +1,11 @@
1
1
  export { getProxyForPublicUsage };
2
+ export type { DangerouslyUseInternals };
2
3
  type Target = Record<string, unknown>;
3
4
  type Fallback = (prop: string | symbol) => unknown;
4
- declare function getProxyForPublicUsage<Obj extends Target>(obj: Obj, objName: 'pageContext' | 'globalContext' | 'prerenderContext' | 'vikeConfig', skipOnInternalProp?: true, fallback?: Fallback): Obj;
5
+ declare function getProxyForPublicUsage<Obj extends Target>(obj: Obj, objName: 'pageContext' | 'globalContext' | 'prerenderContext' | 'vikeConfig', skipOnInternalProp?: true, fallback?: Fallback): Obj & {
6
+ _isProxyObject: true;
7
+ /** https://vike.dev/warning/internals */
8
+ dangerouslyUseInternals: DangerouslyUseInternals<Obj>;
9
+ };
10
+ /** https://vike.dev/warning/internals */
11
+ type DangerouslyUseInternals<Obj> = Obj;
@@ -10,25 +10,27 @@ import { NOT_SERIALIZABLE } from './NOT_SERIALIZABLE.js';
10
10
  import { assert, assertUsage, assertWarning, getPropAccessNotation, isBrowser } from './utils.js';
11
11
  function getProxyForPublicUsage(obj, objName, skipOnInternalProp, fallback) {
12
12
  return new Proxy(obj, {
13
- get: getTrapGet(obj, objName, skipOnInternalProp, fallback),
13
+ get: (_, prop) => getProp(prop, obj, objName, skipOnInternalProp, fallback),
14
14
  });
15
15
  }
16
- function getTrapGet(obj, objName, skipOnInternalProp, fallback) {
17
- return function (_, prop) {
18
- const propStr = String(prop);
19
- if (prop === '_isProxyObject')
20
- return true;
21
- if (!skipOnInternalProp)
16
+ function getProp(prop, obj, objName, skipOnInternalProp, fallback) {
17
+ const propStr = String(prop);
18
+ if (prop === '_isProxyObject')
19
+ return true;
20
+ if (prop === 'dangerouslyUseInternals')
21
+ return obj;
22
+ if (!skipOnInternalProp) {
23
+ if (!globalThis.__VIKE__IS_CLIENT)
22
24
  onInternalProp(propStr, objName);
23
- if (fallback && !(prop in obj)) {
24
- // Rudimentary flat pageContext implementation https://github.com/vikejs/vike/issues/1268
25
- // Failed full-fledged implementation: https://github.com/vikejs/vike/pull/2458
26
- return fallback(prop);
27
- }
28
- const val = obj[prop];
29
- onNotSerializable(propStr, val, objName);
30
- return val;
31
- };
25
+ }
26
+ if (fallback && !(prop in obj)) {
27
+ // Rudimentary flat pageContext implementation https://github.com/vikejs/vike/issues/1268
28
+ // Failed full-fledged implementation: https://github.com/vikejs/vike/pull/2458
29
+ return fallback(prop);
30
+ }
31
+ const val = obj[prop];
32
+ onNotSerializable(propStr, val, objName);
33
+ return val;
32
34
  }
33
35
  function onNotSerializable(propStr, val, objName) {
34
36
  if (val !== NOT_SERIALIZABLE)
@@ -38,17 +40,15 @@ function onNotSerializable(propStr, val, objName) {
38
40
  assertUsage(false, `Can't access ${objName}${propName} on the client side. Because it can't be serialized, see server logs.`);
39
41
  }
40
42
  function onInternalProp(propStr, objName) {
41
- // - We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
42
- // - TO-DO/eventually: use import.meta.CLIENT instead of isBrowser()
43
- // - Where import.meta.CLIENT is defined by Vike
44
- // - Using import.meta.env.CLIENT (note `.env.`) doesn't seem possible: https://github.com/brillout/playground_node_import.meta.env
45
- // - If Rolldown Vite + Rolldowns always transpiles node_modules/ then we can simply use import.meta.env.SSR
46
- if (isBrowser())
47
- return;
43
+ // We must skip it on the client-side because of the reactivity mechanism of UI frameworks like Solid.
44
+ assert(!isBrowser());
48
45
  // TO-DO/soon/proxy: remove this and only warn on built-in access instead
49
46
  if (propStr === '_configFromHook')
50
47
  return;
51
48
  if (propStr.startsWith('_')) {
52
- assertWarning(false, `Using internal ${objName}.${propStr} which may break in any minor version update. Reach out on GitHub to request official support for your use case.`, { onlyOnce: true, showStackTrace: true });
49
+ assertWarning(false, `Using internal ${objName}.${propStr} https://vike.dev/warning/internals`, {
50
+ onlyOnce: true,
51
+ showStackTrace: true,
52
+ });
53
53
  }
54
54
  }
@@ -4,4 +4,7 @@ type GlobalContextPrepareMinimum = {
4
4
  _isOriginalObject: true;
5
5
  isGlobalContext: true;
6
6
  };
7
- declare function prepareGlobalContextForPublicUsage<GlobalContext extends GlobalContextPrepareMinimum>(globalContext: GlobalContext): GlobalContext;
7
+ declare function prepareGlobalContextForPublicUsage<GlobalContext extends GlobalContextPrepareMinimum>(globalContext: GlobalContext): GlobalContext & {
8
+ _isProxyObject: true;
9
+ dangerouslyUseInternals: GlobalContext;
10
+ };
@@ -7,5 +7,8 @@ type PageContextPrepareMinimum = {
7
7
  isPageContext: true;
8
8
  _globalContext: GlobalContextPrepareMinimum;
9
9
  };
10
- declare function preparePageContextForPublicUsage<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext;
10
+ declare function preparePageContextForPublicUsage<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext & {
11
+ _isProxyObject: true;
12
+ dangerouslyUseInternals: PageContext;
13
+ };
11
14
  declare function assertPropertyGetters(pageContext: Record<string, unknown>): void;
@@ -42,9 +42,11 @@ import type { InjectFilterEntry } from './index.js';
42
42
  import type { VikeVitePluginOptions } from '../node/vite/index.js';
43
43
  import type { Vike } from './VikeNamespace.js';
44
44
  import type { HooksTimeoutProvidedByUser } from '../shared/hooks/getHook.js';
45
- import type { GlobalContext, PageContextClient, PageContextServer } from './PageContext.js';
45
+ import type { PageContextClient, PageContextServer } from './PageContext.js';
46
+ import type { GlobalContext } from './GlobalContext.js';
46
47
  import type { InlineConfig } from 'vite';
47
48
  import type { PassToClientPublic } from '../node/runtime/renderPage/html/serializeContext.js';
49
+ import type { CliPreviewConfig } from '../node/api/preview.js';
48
50
  type HookNameOld = HookName | HookNameOldDesign;
49
51
  type HookName = HookNamePage | HookNameGlobal;
50
52
  type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data' | 'onData' | 'route';
@@ -384,7 +386,7 @@ type ConfigBuiltIn = {
384
386
  *
385
387
  * https://vite.dev/config/
386
388
  */
387
- vite?: InlineConfig;
389
+ vite?: InlineConfig | (() => InlineConfig | Promise<InlineConfig>);
388
390
  /** Permanent redirections (HTTP status code 301)
389
391
  *
390
392
  * https://vike.dev/redirects
@@ -512,6 +514,10 @@ type ConfigBuiltIn = {
512
514
  keepScrollPosition?: KeepScrollPosition;
513
515
  /** @experimental */
514
516
  middleware?: Function;
517
+ /** @experimental */
518
+ cli?: {
519
+ preview?: CliPreviewConfig;
520
+ };
515
521
  };
516
522
  type ConfigBuiltInResolved = {
517
523
  passToClient?: string[][];
@@ -0,0 +1,18 @@
1
+ export type { GlobalContext };
2
+ export type { GlobalContextServer };
3
+ export type { GlobalContextClient };
4
+ export type { GlobalContextClientWithServerRouting };
5
+ import type { GlobalContextServerInternal } from '../node/runtime/globalContext.js';
6
+ import type { GlobalContextClientInternalWithServerRouting } from '../client/runtime-server-routing/getGlobalContextClientInternal.js';
7
+ import type { GlobalContextBasePublic } from '../shared/createGlobalContextShared.js';
8
+ import type { GlobalContextClientInternal } from '../client/runtime-client-routing/getGlobalContextClientInternal.js';
9
+ type GlobalContext = GlobalContextServer | GlobalContextClient;
10
+ type GlobalContextServer = Pick<GlobalContextServerInternal, 'assetsManifest' | 'config' | 'viteConfig' | 'viteConfigRuntime' | 'pages' | 'baseServer' | 'baseAssets' | 'isClientSide'> & {
11
+ /** https://vike.dev/warning/internals */
12
+ dangerouslyUseInternals: GlobalContextServerInternal;
13
+ } & Vike.GlobalContext & Vike.GlobalContextServer;
14
+ type GlobalContextClient = GlobalContextBasePublic & {
15
+ /** https://vike.dev/warning/internals */
16
+ dangerouslyUseInternals: GlobalContextClientInternal;
17
+ } & Pick<GlobalContextClientInternal, 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextClient & {};
18
+ type GlobalContextClientWithServerRouting = GlobalContextBasePublic & Pick<GlobalContextClientInternalWithServerRouting, 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextClient & {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,12 +1,8 @@
1
1
  export type { PageContext };
2
2
  export type { PageContextServer };
3
3
  export type { PageContextClient };
4
- export type { GlobalContext };
5
- export type { GlobalContextServer };
6
- export type { GlobalContextClient };
7
4
  export type { PageContextWithServerRouting };
8
5
  export type { PageContextClientWithServerRouting };
9
- export type { GlobalContextClientWithServerRouting };
10
6
  export type { PageContextInternalServer };
11
7
  export type { PageContextInternalClient };
12
8
  export type { PageContextInternalClient_ServerRouting };
@@ -18,13 +14,19 @@ import type { PageContextUrlInternal, PageContextUrlClient, PageContextUrlServer
18
14
  import type { From, PageContextConfig, Source, Sources } from '../shared/page-configs/resolveVikeConfigPublic.js';
19
15
  import type { Config } from './Config.js';
20
16
  import type { AbortStatusCode } from '../shared/route/abort.js';
21
- import type { GlobalContextServer } from '../node/runtime/globalContext.js';
22
- import type { GlobalContextClient } from '../client/runtime-client-routing/getGlobalContextClientInternal.js';
23
- import type { GlobalContextClientWithServerRouting } from '../client/runtime-server-routing/getGlobalContextClientInternal.js';
24
- type PageContextServer<Data = unknown> = PageContextBuiltInServer<Data> & Vike.PageContext & Vike.PageContextServer;
17
+ import type { GlobalContextClient, GlobalContextServer, GlobalContextClientWithServerRouting } from './GlobalContext.js';
18
+ import type { DangerouslyUseInternals } from '../shared/getProxyForPublicUsage.js';
19
+ import type { PageContextInternalServerAfterRender } from '../node/runtime/renderPage.js';
20
+ import type { PageContextInternalClientAfterRender } from '../client/runtime-client-routing/renderPageClientSide.js';
21
+ type PageContextServer<Data = unknown> = PageContextBuiltInServer<Data> & {
22
+ /** https://vike.dev/warning/internals */
23
+ dangerouslyUseInternals: DangerouslyUseInternals<PageContextInternalServer & PageContextInternalServerAfterRender>;
24
+ } & Vike.PageContext & Vike.PageContextServer;
25
25
  type PageContext<Data = unknown> = PageContextClient<Data> | PageContextServer<Data>;
26
- type PageContextClient<Data = unknown> = PageContextBuiltInClientWithClientRouting<Data> & Vike.PageContext & Vike.PageContextClient;
27
- type GlobalContext = GlobalContextServer | GlobalContextClient;
26
+ type PageContextClient<Data = unknown> = PageContextBuiltInClientWithClientRouting<Data> & {
27
+ /** https://vike.dev/warning/internals */
28
+ dangerouslyUseInternals: DangerouslyUseInternals<PageContextInternalClient_ClientRouting & PageContextInternalClientAfterRender>;
29
+ } & Vike.PageContext & Vike.PageContextClient;
28
30
  type PageContextWithServerRouting<Data = unknown> = PageContextClientWithServerRouting<Data> | PageContextServer<Data>;
29
31
  type PageContextClientWithServerRouting<Data = unknown> = PageContextBuiltInClientWithServerRouting<Data> & Vike.PageContext & Vike.PageContextClient;
30
32
  type PageContextBuiltInCommon<Data> = PageContextConfig & {
@@ -1,4 +1,5 @@
1
- export type { PageContext, PageContextServer, PageContextClient, GlobalContext, GlobalContextServer, GlobalContextClient, PageContextWithServerRouting, PageContextClientWithServerRouting, GlobalContextClientWithServerRouting, } from './PageContext.js';
1
+ export type { PageContext, PageContextServer, PageContextClient, PageContextWithServerRouting, PageContextClientWithServerRouting, } from './PageContext.js';
2
+ export type { GlobalContext, GlobalContextServer, GlobalContextClient, GlobalContextClientWithServerRouting, } from './GlobalContext.js';
2
3
  export type { PrerenderContextPublic as PrerenderContext } from '../node/prerender/runPrerender.js';
3
4
  export type { PageContextBuiltInServer } from './PageContext.js';
4
5
  export type { PageContextBuiltInClientWithClientRouting } from './PageContext.js';
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.243";
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.243';
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.243",
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;