vike 0.4.191 → 0.4.193-commit-38002cb

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 (68) hide show
  1. package/dist/cjs/__internal/index.js +14 -6
  2. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +9 -5
  3. package/dist/cjs/node/plugin/plugins/buildConfig.js +2 -2
  4. package/dist/cjs/node/plugin/plugins/config/assertVikeConfig.js +4 -2
  5. package/dist/cjs/node/plugin/plugins/importBuild/index.js +24 -14
  6. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +12 -6
  7. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
  8. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -2
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +0 -3
  10. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +5 -0
  11. package/dist/cjs/node/prerender/runPrerender.js +4 -5
  12. package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +2 -2
  13. package/dist/cjs/node/runtime/globalContext.js +83 -26
  14. package/dist/cjs/node/runtime/html/stream.js +37 -24
  15. package/dist/cjs/node/runtime/page-files/getPageFilesExports.js +23 -0
  16. package/dist/cjs/node/runtime/page-files/setup.js +2 -20
  17. package/dist/cjs/node/runtime/renderPage/inferMediaType.js +3 -0
  18. package/dist/cjs/node/runtime/renderPage.js +3 -3
  19. package/dist/cjs/node/runtime/utils.js +1 -0
  20. package/dist/cjs/shared/hooks/getHook.js +4 -6
  21. package/dist/cjs/shared/page-configs/assertPlusFileExport.js +1 -2
  22. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +3 -1
  23. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  24. package/dist/cjs/utils/genPromise.js +9 -0
  25. package/dist/cjs/utils/isArray.js +1 -1
  26. package/dist/esm/__internal/index.d.ts +7 -0
  27. package/dist/esm/__internal/index.js +15 -6
  28. package/dist/esm/node/plugin/plugins/autoFullBuild.js +9 -5
  29. package/dist/esm/node/plugin/plugins/buildConfig.js +3 -3
  30. package/dist/esm/node/plugin/plugins/config/assertVikeConfig.js +4 -2
  31. package/dist/esm/node/plugin/plugins/importBuild/index.d.ts +2 -2
  32. package/dist/esm/node/plugin/plugins/importBuild/index.js +22 -12
  33. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +8 -0
  34. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +12 -6
  35. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
  36. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -2
  37. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +0 -1
  38. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +0 -3
  39. package/dist/esm/node/plugin/plugins/setGlobalContext.js +7 -2
  40. package/dist/esm/node/prerender/runPrerender.js +7 -8
  41. package/dist/esm/node/runtime/globalContext/loadImportBuild.js +1 -1
  42. package/dist/esm/node/runtime/globalContext.d.ts +12 -6
  43. package/dist/esm/node/runtime/globalContext.js +83 -26
  44. package/dist/esm/node/runtime/html/stream.js +37 -24
  45. package/dist/esm/node/runtime/page-files/getPageFilesExports.d.ts +2 -0
  46. package/dist/esm/node/runtime/page-files/getPageFilesExports.js +20 -0
  47. package/dist/esm/node/runtime/page-files/setup.js +1 -19
  48. package/dist/esm/node/runtime/renderPage/inferMediaType.d.ts +1 -1
  49. package/dist/esm/node/runtime/renderPage/inferMediaType.js +3 -0
  50. package/dist/esm/node/runtime/renderPage.js +4 -4
  51. package/dist/esm/node/runtime/utils.d.ts +1 -0
  52. package/dist/esm/node/runtime/utils.js +1 -0
  53. package/dist/esm/shared/ConfigVike.d.ts +3 -3
  54. package/dist/esm/shared/hooks/executeHook.d.ts +1 -1
  55. package/dist/esm/shared/hooks/getHook.d.ts +2 -2
  56. package/dist/esm/shared/hooks/getHook.js +3 -5
  57. package/dist/esm/shared/page-configs/PageConfig.d.ts +0 -2
  58. package/dist/esm/shared/page-configs/assertPlusFileExport.js +1 -2
  59. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -1
  60. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +3 -1
  61. package/dist/esm/types/index.d.ts +1 -0
  62. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  63. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  64. package/dist/esm/utils/genPromise.d.ts +4 -0
  65. package/dist/esm/utils/genPromise.js +5 -0
  66. package/dist/esm/utils/isArray.js +1 -1
  67. package/dist/esm/utils/projectInfo.d.ts +1 -1
  68. package/package.json +67 -67
@@ -2,25 +2,32 @@
2
2
  export { getGlobalContextSync };
3
3
  export { getGlobalContextAsync };
4
4
  // Internal use
5
- export { initGlobalContext };
6
5
  export { getGlobalContext };
7
6
  export { getViteDevServer };
8
7
  export { getViteConfig };
8
+ export { getRuntimeManifest };
9
+ export { initGlobalContext_renderPage };
10
+ export { initGlobalContext_runPrerender };
11
+ export { initGlobalContext_getGlobalContextAsync };
9
12
  export { setGlobalContext_viteDevServer };
13
+ export { setGlobalContext_viteConfig };
10
14
  export { setGlobalContext_isDev };
11
- export { setGlobalContext_prerender };
12
- export { getRuntimeManifest };
13
- import { assert, assertNodeEnv_runtime, assertUsage, assertWarning, getGlobalObject, isPlainObject, objectAssign, objectKeys } from './utils.js';
15
+ export { setGlobalContext_isPrerendering };
16
+ import { assert, assertNodeEnv_runtime, assertUsage, assertWarning, getGlobalObject, isPlainObject, objectAssign, objectKeys, genPromise } from './utils.js';
14
17
  import { loadImportBuild } from './globalContext/loadImportBuild.js';
15
18
  import { setPageFiles } from '../../shared/getPageFiles.js';
16
19
  import { assertPluginManifest } from '../shared/assertPluginManifest.js';
17
20
  import { getConfigVike } from '../shared/getConfigVike.js';
18
21
  import { assertRuntimeManifest } from '../shared/assertRuntimeManifest.js';
19
22
  import pc from '@brillout/picocolors';
20
- let resolveGlobalContext;
21
- const globalObject = getGlobalObject('globalContext.ts', {
22
- globalContextPromise: new Promise((r) => (resolveGlobalContext = r))
23
- });
23
+ import { getPageFilesExports } from './page-files/getPageFilesExports.js';
24
+ const globalObject = getGlobalObject('globalContext.ts', (() => {
25
+ const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = genPromise();
26
+ return {
27
+ viteDevServerPromise,
28
+ viteDevServerPromiseResolve
29
+ };
30
+ })());
24
31
  function getGlobalContext() {
25
32
  assert(globalObject.globalContext);
26
33
  return globalObject.globalContext;
@@ -31,10 +38,12 @@ function getGlobalContextSync() {
31
38
  return makePublic(globalObject.globalContext);
32
39
  }
33
40
  /** @experimental https://vike.dev/getGlobalContext */
34
- async function getGlobalContextAsync() {
35
- await globalObject.globalContextPromise;
36
- assert(globalObject.globalContext);
37
- return makePublic(globalObject.globalContext);
41
+ async function getGlobalContextAsync(isProduction) {
42
+ assertUsage(typeof isProduction === 'boolean', `[getGlobalContextAsync(isProduction)] Argument ${pc.cyan('isProduction')} ${isProduction === undefined ? 'is missing' : `should be ${pc.cyan('true')} or ${pc.cyan('false')}`}`);
43
+ await initGlobalContext_getGlobalContextAsync(isProduction);
44
+ const { globalContext } = globalObject;
45
+ assert(globalContext);
46
+ return makePublic(globalContext);
38
47
  }
39
48
  function makePublic(globalContext) {
40
49
  const globalContextPublic = {
@@ -63,34 +72,78 @@ function makePublic(globalContext) {
63
72
  function setGlobalContext_viteDevServer(viteDevServer) {
64
73
  if (globalObject.viteDevServer)
65
74
  return;
66
- assert(!globalObject.globalContext);
67
- globalObject.viteConfig = viteDevServer.config;
75
+ assertIsNotInitilizedYet();
76
+ assert(globalObject.viteConfig);
68
77
  globalObject.viteDevServer = viteDevServer;
78
+ globalObject.viteDevServerPromiseResolve(viteDevServer);
79
+ eagerlyLoadUserFiles();
80
+ }
81
+ function setGlobalContext_viteConfig(viteConfig, outDirRoot) {
82
+ if (globalObject.viteConfig)
83
+ return;
84
+ assertIsNotInitilizedYet();
85
+ globalObject.viteConfig = viteConfig;
86
+ globalObject.outDirRoot = outDirRoot;
87
+ }
88
+ function assertIsNotInitilizedYet() {
89
+ // In develpoment, globalObject.viteDevServer always needs to be awaited for before initializing globalObject.globalContext
90
+ assert(!globalObject.globalContext);
69
91
  }
70
92
  function setGlobalContext_isDev(isDev) {
71
93
  globalObject.isDev = isDev;
72
94
  }
95
+ function setGlobalContext_isPrerendering() {
96
+ globalObject.isPrerendering = true;
97
+ }
73
98
  function getViteDevServer() {
74
99
  return globalObject.viteDevServer ?? null;
75
100
  }
76
- function setGlobalContext_prerender(viteConfig) {
77
- if (globalObject.viteConfig)
101
+ function getViteConfig() {
102
+ return globalObject.viteConfig ?? null;
103
+ }
104
+ async function initGlobalContext_renderPage() {
105
+ await initGlobalContext(!globalObject.isDev);
106
+ }
107
+ async function initGlobalContext_runPrerender() {
108
+ if (globalObject.initGlobalContext_runPrerender_alreadyCalled)
78
109
  return;
110
+ globalObject.initGlobalContext_runPrerender_alreadyCalled = true;
111
+ assert(globalObject.isPrerendering);
112
+ assert(globalObject.viteConfig);
113
+ assert(globalObject.outDirRoot);
114
+ // We assume initGlobalContext_runPrerender() to be called before:
115
+ // - initGlobalContext_renderPage()
116
+ // - initGlobalContext_getGlobalContextAsync()
79
117
  assert(!globalObject.globalContext);
80
- globalObject.viteConfig = viteConfig;
118
+ await initGlobalContext(true);
81
119
  }
82
- function getViteConfig() {
83
- return globalObject.viteConfig ?? null;
120
+ async function initGlobalContext_getGlobalContextAsync(isProduction) {
121
+ if (!isProduction) {
122
+ const waitFor = 20;
123
+ const timeout = setTimeout(() => {
124
+ assertWarning(false, `Vite's development server still not created after ${waitFor} seconds.`, {
125
+ onlyOnce: false,
126
+ showStackTrace: true
127
+ });
128
+ }, waitFor * 1000);
129
+ await globalObject.viteDevServerPromise;
130
+ clearTimeout(timeout);
131
+ }
132
+ await initGlobalContext(isProduction);
84
133
  }
85
- async function initGlobalContext(isPrerendering = false, outDir) {
86
- if (globalObject.globalContext)
134
+ async function initGlobalContext(isProduction) {
135
+ if (globalObject.globalContext) {
136
+ assert(globalObject.globalContext.isProduction === isProduction);
137
+ // We assume setGlobalContext_isPrerendering() is called before initGlobalContext()
138
+ assert(globalObject.globalContext.isPrerendering === (globalObject.isPrerendering ?? false));
87
139
  return;
88
- const { viteDevServer, viteConfig, isDev } = globalObject;
140
+ }
141
+ const { viteDevServer, viteConfig, isDev, isPrerendering } = globalObject;
89
142
  assertNodeEnv_runtime(isDev ?? false);
90
- if (isDev) {
143
+ if (!isProduction) {
91
144
  assert(viteConfig);
92
- assert(!isPrerendering);
93
145
  assert(viteDevServer);
146
+ assert(!isPrerendering);
94
147
  const configVike = await getConfigVike(viteConfig);
95
148
  const pluginManifest = getRuntimeManifest(configVike);
96
149
  globalObject.globalContext = {
@@ -109,7 +162,7 @@ async function initGlobalContext(isPrerendering = false, outDir) {
109
162
  };
110
163
  }
111
164
  else {
112
- const buildEntries = await loadImportBuild(outDir);
165
+ const buildEntries = await loadImportBuild(globalObject.outDirRoot);
113
166
  assertBuildEntries(buildEntries, isPrerendering ?? false);
114
167
  const { pageFiles, assetsManifest, pluginManifest } = buildEntries;
115
168
  setPageFiles(pageFiles);
@@ -145,7 +198,6 @@ async function initGlobalContext(isPrerendering = false, outDir) {
145
198
  globalObject.globalContext = globalContext;
146
199
  }
147
200
  }
148
- resolveGlobalContext(globalObject.globalContext);
149
201
  }
150
202
  function getRuntimeManifest(configVike) {
151
203
  const { includeAssetsImportedByServer, baseServer, baseAssets, redirects, trailingSlash, disableUrlNormalization } = configVike;
@@ -182,3 +234,8 @@ function assertViteManifest(manifest) {
182
234
  })
183
235
  */
184
236
  }
237
+ function eagerlyLoadUserFiles() {
238
+ // Other than here, the getPageFilesExports() function is only called only upon calling the renderPage() function.
239
+ // We call it as early as possible here for better performance.
240
+ getPageFilesExports();
241
+ }
@@ -55,16 +55,15 @@ async function streamReadableNodeToString(readableNode) {
55
55
  }
56
56
  async function streamReadableWebToString(readableWeb) {
57
57
  const reader = readableWeb.getReader();
58
- const decoder = new TextDecoder();
58
+ const { decode, getClosingChunk } = decodeChunks();
59
59
  let str = '';
60
60
  while (true) {
61
61
  const { done, value } = await reader.read();
62
62
  if (done)
63
63
  break;
64
- str += decoder.decode(value, { stream: true });
64
+ str += decode(value);
65
65
  }
66
- // https://github.com/vikejs/vike/pull/1799#discussion_r1713554096
67
- str += decoder.decode();
66
+ str += getClosingChunk();
68
67
  return str;
69
68
  }
70
69
  async function stringToStreamReadableNode(str) {
@@ -128,15 +127,16 @@ async function streamPipeNodeToString(streamPipeNode) {
128
127
  return promise;
129
128
  }
130
129
  function streamPipeWebToString(streamPipeWeb) {
130
+ const { decode, getClosingChunk } = decodeChunks();
131
131
  let str = '';
132
132
  let resolve;
133
133
  const promise = new Promise((r) => (resolve = r));
134
134
  const writable = new WritableStream({
135
135
  write(chunk) {
136
- assert(typeof chunk === 'string');
137
- str += chunk;
136
+ str += decode(chunk);
138
137
  },
139
138
  close() {
139
+ str += getClosingChunk();
140
140
  resolve(str);
141
141
  }
142
142
  });
@@ -388,9 +388,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
388
388
  const writeChunk = (chunk) => {
389
389
  assert(writableOriginal);
390
390
  writableOriginal.write(chunk);
391
- if (debug.isActivated) {
392
- debug('data written (Node.js Writable)', getChunkAsString(chunk));
393
- }
391
+ debugWithChunk('data written (Node.js Writable)', chunk);
394
392
  };
395
393
  // For libraries such as https://www.npmjs.com/package/compression
396
394
  // - React calls writable.flush() when available
@@ -461,9 +459,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
461
459
  const writeChunk = (chunk) => {
462
460
  assert(writerOriginal);
463
461
  writerOriginal.write(encodeForWebStream(chunk));
464
- if (debug.isActivated) {
465
- debug('data written (Web Writable)', getChunkAsString(chunk));
466
- }
462
+ debugWithChunk('data written (Web Writable)', chunk);
467
463
  };
468
464
  // Web Streams have compression built-in
469
465
  // - https://developer.mozilla.org/en-US/docs/Web/API/Compression_Streams_API
@@ -554,14 +550,10 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
554
550
  // If readableOriginal doesn't implement readableOriginal.cancel() then it may still emit data after we close the stream. We therefore need to check whether we closed `controllerProxy`.
555
551
  !controllerProxyIsClosed) {
556
552
  controllerProxy.enqueue(encodeForWebStream(chunk));
557
- if (debug.isActivated) {
558
- debug('data written (Web Readable)', getChunkAsString(chunk));
559
- }
553
+ debugWithChunk('data written (Web Readable)', chunk);
560
554
  }
561
555
  else {
562
- if (debug.isActivated) {
563
- debug('data emitted but not written (Web Readable)', getChunkAsString(chunk));
564
- }
556
+ debugWithChunk('data emitted but not written (Web Readable)', chunk);
565
557
  }
566
558
  };
567
559
  // Readables don't have the notion of flushing
@@ -581,9 +573,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
581
573
  }
582
574
  const writeChunk = (chunk) => {
583
575
  readableProxy.push(chunk);
584
- if (debug.isActivated) {
585
- debug('data written (Node.js Readable)', getChunkAsString(chunk));
586
- }
576
+ debugWithChunk('data written (Node.js Readable)', chunk);
587
577
  };
588
578
  // Readables don't have the notion of flushing
589
579
  const flushStream = null;
@@ -796,11 +786,34 @@ function inferStreamName(stream) {
796
786
  }
797
787
  assert(false);
798
788
  }
799
- function getChunkAsString(chunk) {
789
+ function decodeChunks() {
790
+ const decoder = new TextDecoder();
791
+ const decode = (chunk) => {
792
+ if (typeof chunk === 'string') {
793
+ return chunk;
794
+ }
795
+ else if (chunk instanceof Uint8Array) {
796
+ return decoder.decode(chunk, { stream: true });
797
+ }
798
+ else {
799
+ assert(false);
800
+ }
801
+ };
802
+ // https://github.com/vikejs/vike/pull/1799#discussion_r1713554096
803
+ const getClosingChunk = () => {
804
+ return decoder.decode();
805
+ };
806
+ return { decode, getClosingChunk };
807
+ }
808
+ function debugWithChunk(msg, chunk) {
809
+ if (!debug.isActivated)
810
+ return;
811
+ let chunkStr;
800
812
  try {
801
- return new TextDecoder().decode(chunk);
813
+ chunkStr = new TextDecoder().decode(chunk);
802
814
  }
803
815
  catch (err) {
804
- return String(chunk);
816
+ chunkStr = String(chunk);
805
817
  }
818
+ debug(msg, chunkStr);
806
819
  }
@@ -0,0 +1,2 @@
1
+ export { getPageFilesExports };
2
+ declare function getPageFilesExports(): Promise<Record<string, unknown>>;
@@ -0,0 +1,20 @@
1
+ export { getPageFilesExports };
2
+ import { assert, debugGlob, isObject } from '../utils.js';
3
+ import { getViteDevServer } from '../globalContext.js';
4
+ import { virtualFileIdImportUserCodeServer } from '../../shared/virtual-files/virtualFileImportUserCode.js';
5
+ async function getPageFilesExports() {
6
+ const viteDevServer = getViteDevServer();
7
+ assert(viteDevServer);
8
+ let moduleExports;
9
+ try {
10
+ moduleExports = await viteDevServer.ssrLoadModule(virtualFileIdImportUserCodeServer);
11
+ }
12
+ catch (err) {
13
+ debugGlob(`Glob error: ${virtualFileIdImportUserCodeServer} transpile error: `, err);
14
+ throw err;
15
+ }
16
+ moduleExports = moduleExports.default || moduleExports;
17
+ debugGlob('Glob result: ', moduleExports);
18
+ assert(isObject(moduleExports));
19
+ return moduleExports;
20
+ }
@@ -1,21 +1,3 @@
1
1
  import { setPageFilesAsync } from '../../../shared/getPageFiles.js';
2
- import { assert, debugGlob, isObject } from '../utils.js';
3
- import { getViteDevServer } from '../globalContext.js';
4
- import { virtualFileIdImportUserCodeServer } from '../../shared/virtual-files/virtualFileImportUserCode.js';
2
+ import { getPageFilesExports } from './getPageFilesExports.js';
5
3
  setPageFilesAsync(getPageFilesExports);
6
- async function getPageFilesExports() {
7
- const viteDevServer = getViteDevServer();
8
- assert(viteDevServer);
9
- let moduleExports;
10
- try {
11
- moduleExports = await viteDevServer.ssrLoadModule(virtualFileIdImportUserCodeServer);
12
- }
13
- catch (err) {
14
- debugGlob(`Glob error: ${virtualFileIdImportUserCodeServer} transpile error: `, err);
15
- throw err;
16
- }
17
- moduleExports = moduleExports.default || moduleExports;
18
- debugGlob('Glob result: ', moduleExports);
19
- assert(isObject(moduleExports));
20
- return moduleExports;
21
- }
@@ -2,6 +2,6 @@ export { inferMediaType };
2
2
  export type { MediaType };
3
3
  type MediaType = null | {
4
4
  assetType: 'image' | 'script' | 'font' | 'style' | 'audio' | 'video' | 'document' | 'fetch' | 'track' | 'worker' | 'embed' | 'object';
5
- mediaType: 'text/javascript' | 'text/css' | 'image/jpeg' | 'image/png' | 'image/webp' | 'image/gif' | 'image/svg+xml' | 'font/ttf' | 'font/woff' | 'font/woff2' | 'video/mp4' | 'video/webm' | 'video/ogg' | 'video/mpeg' | 'video/x-msvideo' | 'video/quicktime' | 'audio/mpeg' | 'audio/wav' | 'audio/ogg' | 'audio/aac' | 'audio/midi' | 'audio/flac';
5
+ mediaType: 'text/javascript' | 'text/css' | 'image/avif' | 'image/jpeg' | 'image/png' | 'image/webp' | 'image/gif' | 'image/svg+xml' | 'font/ttf' | 'font/woff' | 'font/woff2' | 'video/mp4' | 'video/webm' | 'video/ogg' | 'video/mpeg' | 'video/x-msvideo' | 'video/quicktime' | 'audio/mpeg' | 'audio/wav' | 'audio/ogg' | 'audio/aac' | 'audio/midi' | 'audio/flac';
6
6
  };
7
7
  declare function inferMediaType(href: string): MediaType;
@@ -24,6 +24,9 @@ function inferMediaType(href) {
24
24
  if (href.endsWith('.svg')) {
25
25
  return { assetType: 'image', mediaType: 'image/svg+xml' };
26
26
  }
27
+ if (href.endsWith('.avif')) {
28
+ return { assetType: 'image', mediaType: 'image/avif' };
29
+ }
27
30
  // Fonts
28
31
  if (href.endsWith('.ttf')) {
29
32
  return { assetType: 'font', mediaType: 'font/ttf' };
@@ -4,7 +4,7 @@ import { getRenderContext, getPageContextInitEnhanced, renderPageAlreadyRouted }
4
4
  import { route } from '../../shared/route/index.js';
5
5
  import { assert, hasProp, objectAssign, isUrl, parseUrl, assertEnv, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, addUrlOrigin, createUrlFromComponents, isUri } from './utils.js';
6
6
  import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError, logAbortErrorHandled } from '../../shared/route/abort.js';
7
- import { getGlobalContext, initGlobalContext } from './globalContext.js';
7
+ import { getGlobalContext, initGlobalContext_renderPage } from './globalContext.js';
8
8
  import { handlePageContextRequestUrl } from './renderPage/handlePageContextRequestUrl.js';
9
9
  import { createHttpResponseObjectRedirect, createHttpResponsePageContextJson } from './renderPage/createHttpResponseObject.js';
10
10
  import { logRuntimeError, logRuntimeInfo } from './renderPage/loggerRuntime.js';
@@ -61,12 +61,12 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
61
61
  // Prepare context
62
62
  let renderContext;
63
63
  try {
64
- await initGlobalContext();
64
+ await initGlobalContext_renderPage();
65
65
  renderContext = await getRenderContext();
66
66
  }
67
67
  catch (err) {
68
- // Errors are expected since assertUsage() is used in both initGlobalContext() and getRenderContext().
69
- // initGlobalContext() and getRenderContext() don't call any user hooks => err isn't thrown from user code
68
+ // Errors are expected since assertUsage() is used in both initGlobalContext_renderPage() and getRenderContext().
69
+ // initGlobalContext_renderPage() and getRenderContext() don't call any user hooks => err isn't thrown from user code.
70
70
  assert(!isAbortError(err));
71
71
  logRuntimeError(err, httpRequestId);
72
72
  const pageContextHttpResponseNull = getPageContextHttpResponseNullWithError(err, pageContextInit);
@@ -56,3 +56,4 @@ export * from '../../utils/normalizeHeaders.js';
56
56
  export * from '../../utils/isVikeReactApp.js';
57
57
  export * from '../../utils/getPropAccessNotation.js';
58
58
  export * from '../../utils/PROJECT_VERSION.js';
59
+ export * from '../../utils/genPromise.js';
@@ -59,3 +59,4 @@ export * from '../../utils/normalizeHeaders.js';
59
59
  export * from '../../utils/isVikeReactApp.js';
60
60
  export * from '../../utils/getPropAccessNotation.js';
61
61
  export * from '../../utils/PROJECT_VERSION.js';
62
+ export * from '../../utils/genPromise.js';
@@ -7,7 +7,7 @@ type ConfigVikeResolved = {
7
7
  partial: boolean;
8
8
  disableAutoRun: boolean;
9
9
  };
10
- disableAutoFullBuild: boolean | null;
10
+ disableAutoFullBuild: boolean | 'prerender' | null;
11
11
  includeAssetsImportedByServer: boolean;
12
12
  baseAssets: string;
13
13
  baseServer: string;
@@ -63,13 +63,13 @@ type ConfigVikeUserProvided = {
63
63
  disableAutoRun?: boolean;
64
64
  };
65
65
  /**
66
- * Set to `true` to disable the automatic chaining of all the build steps.
66
+ * Disable the automatic chaining of build steps.
67
67
  *
68
68
  * https://vike.dev/disableAutoFullBuild
69
69
  *
70
70
  * @default false
71
71
  */
72
- disableAutoFullBuild?: boolean;
72
+ disableAutoFullBuild?: boolean | 'prerender';
73
73
  /** The Base URL of your server.
74
74
  *
75
75
  * https://vike.dev/base-url
@@ -4,7 +4,7 @@ export { providePageContext };
4
4
  export { isUserHookError };
5
5
  import type { PageContextClient, PageContextServer } from '../types.js';
6
6
  import type { Hook, HookLoc } from './getHook.js';
7
- type PageContextUnknown = null | Record<string, unknown>;
7
+ type PageContextUnknown = null | Record<string, any>;
8
8
  declare function isUserHookError(err: unknown): false | HookLoc;
9
9
  declare function executeHook<T = unknown>(hookFnCaller: () => T, hook: Omit<Hook, 'hookFn'>, pageContext: PageContextUnknown): Promise<T>;
10
10
  /**
@@ -2,7 +2,7 @@ export { getHook };
2
2
  export { getHookFromPageConfig };
3
3
  export { getHookFromPageConfigGlobal };
4
4
  export { assertHook };
5
- export { setIsPrerenderering };
5
+ export { getHook_setIsPrerenderering };
6
6
  export type { Hook };
7
7
  export type { HookName };
8
8
  export type { HookLoc };
@@ -33,4 +33,4 @@ declare function assertHook<TPageContext extends PageContextExports, THookName e
33
33
  exports: Record<THookName, Function | undefined>;
34
34
  };
35
35
  declare function getHookTimeoutDefault(hookName: HookName): HookTimeout;
36
- declare function setIsPrerenderering(): void;
36
+ declare function getHook_setIsPrerenderering(): void;
@@ -2,7 +2,7 @@ export { getHook };
2
2
  export { getHookFromPageConfig };
3
3
  export { getHookFromPageConfigGlobal };
4
4
  export { assertHook };
5
- export { setIsPrerenderering };
5
+ export { getHook_setIsPrerenderering };
6
6
  // TODO/v1-release: remove
7
7
  // We export for old V0.4 design which doesn't support configooksTimeout
8
8
  export { getHookTimeoutDefault };
@@ -11,9 +11,7 @@ import { getHookFilePathToShowToUser } from '../page-configs/helpers.js';
11
11
  import { getConfigValueRuntime } from '../page-configs/getConfigValue.js';
12
12
  import { assert, assertUsage, checkType, isCallable, isObject } from '../utils.js';
13
13
  import pc from '@brillout/picocolors';
14
- const globalObject = getGlobalObject('getHook.ts', {
15
- isPrerendering: false
16
- });
14
+ const globalObject = getGlobalObject('getHook.ts', {});
17
15
  function getHook(pageContext, hookName) {
18
16
  if (!(hookName in pageContext.exports)) {
19
17
  return null;
@@ -130,6 +128,6 @@ function getHookTimeoutDefault(hookName) {
130
128
  warning: 4 * 1000
131
129
  };
132
130
  }
133
- function setIsPrerenderering() {
131
+ function getHook_setIsPrerenderering() {
134
132
  globalObject.isPrerendering = true;
135
133
  }
@@ -67,8 +67,6 @@ type ConfigEnv = {
67
67
  /** For Vike internal use */
68
68
  type ConfigEnvInternal = Omit<ConfigEnv, 'client'> & {
69
69
  client?: boolean | 'if-client-routing';
70
- /** Always load value, no matter which page is loaded. */
71
- eager?: true;
72
70
  /** Load value only in production, or only in development. */
73
71
  production?: boolean;
74
72
  };
@@ -19,6 +19,7 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
19
19
  }
20
20
  const exportDefault = pc.code('export default');
21
21
  const exportNamed = pc.code(`export { ${configName} }`);
22
+ assert(exportNamesValid.length <= 2);
22
23
  if (exportNamesValid.length === 0) {
23
24
  assertUsage(false, `${filePathToShowToUser} should have a ${exportNamed} or ${exportDefault}`);
24
25
  }
@@ -27,8 +28,6 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
27
28
  onlyOnce: true
28
29
  });
29
30
  }
30
- assert(exportNamesValid.length === 1);
31
- assert(exportNamesInvalid.length > 0);
32
31
  if (!TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext))) {
33
32
  exportNamesInvalid.forEach((exportInvalid) => {
34
33
  assertWarning(false, `${filePathToShowToUser} unexpected ${pc.cyan(`export { ${exportInvalid} }`)}`, {
@@ -2,4 +2,6 @@ export { serializeConfigValues };
2
2
  import type { ConfigEnvInternal, PageConfigBuildTime, PageConfigGlobalBuildTime } from '../PageConfig.js';
3
3
  declare function serializeConfigValues(pageConfig: PageConfigBuildTime | (PageConfigGlobalBuildTime & {
4
4
  configValuesComputed?: undefined;
5
- }), importStatements: string[], isEnvMatch: (configEnv: ConfigEnvInternal) => boolean, tabspace: string): string[];
5
+ }), importStatements: string[], isEnvMatch: (configEnv: ConfigEnvInternal) => boolean, { isEager }: {
6
+ isEager: boolean;
7
+ }, tabspace: string): string[];
@@ -12,7 +12,7 @@ const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
12
12
  // - vike/shared/page-configs/serialize/parsePageConfigs.ts
13
13
  // - parsePageConfigs() is loaded on both the client- and server-side.
14
14
  assertIsNotProductionRuntime();
15
- function serializeConfigValues(pageConfig, importStatements, isEnvMatch, tabspace) {
15
+ function serializeConfigValues(pageConfig, importStatements, isEnvMatch, { isEager }, tabspace) {
16
16
  const lines = [];
17
17
  tabspace += ' ';
18
18
  Object.entries(pageConfig.configValuesComputed ?? {}).forEach(([configName, configValuesComputed]) => {
@@ -31,6 +31,8 @@ function serializeConfigValues(pageConfig, importStatements, isEnvMatch, tabspac
31
31
  Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
32
32
  const configDef = pageConfig.configDefinitions[configName];
33
33
  assert(configDef);
34
+ if (isEager !== !!configDef.eager)
35
+ return;
34
36
  if (!configDef.cumulative) {
35
37
  const configValueSource = sources[0];
36
38
  assert(configValueSource);
@@ -3,6 +3,7 @@ export type { PageContextServer } from '../shared/types.js';
3
3
  export type { PageContextClient } from '../shared/types.js';
4
4
  export type { PageContextWithServerRouting } from '../shared/types.js';
5
5
  export type { PageContextClientWithServerRouting } from '../shared/types.js';
6
+ export type { ConfigVitePluginServerEntry } from '@brillout/vite-plugin-server-entry/plugin';
6
7
  export type { PageContextBuiltInServer } from '../shared/types.js';
7
8
  export type { PageContextBuiltInClientWithClientRouting } from '../shared/types.js';
8
9
  export type { PageContextBuiltInClientWithServerRouting } from '../shared/types.js';
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.191";
1
+ export declare const PROJECT_VERSION: "0.4.193-commit-38002cb";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.191';
2
+ export const PROJECT_VERSION = '0.4.193-commit-38002cb';
@@ -0,0 +1,4 @@
1
+ export declare function genPromise<T>(): {
2
+ promise: Promise<T>;
3
+ resolve: (val: T) => void;
4
+ };
@@ -0,0 +1,5 @@
1
+ export function genPromise() {
2
+ let resolve;
3
+ const promise = new Promise((r) => (resolve = r));
4
+ return { promise, resolve };
5
+ }
@@ -1,4 +1,4 @@
1
- // Typesafe Array.isArray() asserting unknown[] instead of any[]
1
+ // Same as Array.isArray() but typesafe: asserts unknown[] instead of any[]
2
2
  export function isArray(value) {
3
3
  return Array.isArray(value);
4
4
  }
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.191";
3
+ projectVersion: "0.4.193-commit-38002cb";
4
4
  };