vike 0.4.190 → 0.4.191-commit-7e0cd43

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 (35) hide show
  1. package/dist/cjs/__internal/index.js +11 -1
  2. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +12 -6
  3. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -2
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +0 -3
  6. package/dist/cjs/node/runtime/globalContext.js +7 -0
  7. package/dist/cjs/node/runtime/page-files/getPageFilesExports.js +23 -0
  8. package/dist/cjs/node/runtime/page-files/setup.js +2 -20
  9. package/dist/cjs/shared/getPageContext.js +2 -1
  10. package/dist/cjs/shared/hooks/executeHook.js +7 -1
  11. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +3 -1
  12. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  13. package/dist/esm/__internal/index.d.ts +7 -0
  14. package/dist/esm/__internal/index.js +12 -1
  15. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +8 -0
  16. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +12 -6
  17. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
  18. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -2
  19. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +0 -1
  20. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +0 -3
  21. package/dist/esm/node/runtime/globalContext.js +7 -0
  22. package/dist/esm/node/runtime/page-files/getPageFilesExports.d.ts +2 -0
  23. package/dist/esm/node/runtime/page-files/getPageFilesExports.js +20 -0
  24. package/dist/esm/node/runtime/page-files/setup.js +1 -19
  25. package/dist/esm/shared/getPageContext.d.ts +1 -1
  26. package/dist/esm/shared/getPageContext.js +1 -1
  27. package/dist/esm/shared/hooks/executeHook.d.ts +8 -1
  28. package/dist/esm/shared/hooks/executeHook.js +6 -0
  29. package/dist/esm/shared/page-configs/PageConfig.d.ts +0 -2
  30. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -1
  31. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +3 -1
  32. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  33. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  34. package/dist/esm/utils/projectInfo.d.ts +1 -1
  35. package/package.json +1 -1
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPagesAndRoutes = exports.route = void 0;
3
+ exports.getPageFilesAllSafe = exports.getPagesAndRoutes = exports.route = void 0;
4
4
  const index_js_1 = require("../shared/route/index.js");
5
+ const getPageFiles_js_1 = require("../shared/getPageFiles.js");
5
6
  const globalContext_js_1 = require("../node/runtime/globalContext.js");
6
7
  const assertNodeEnv_js_1 = require("../utils/assertNodeEnv.js");
7
8
  const assert_js_1 = require("../utils/assert.js");
@@ -27,6 +28,15 @@ async function getPagesAndRoutes() {
27
28
  };
28
29
  }
29
30
  exports.getPagesAndRoutes = getPagesAndRoutes;
31
+ // TODO: make it cleaner once the internal refactoring about global configs is done
32
+ async function getPageFilesAllSafe() {
33
+ await (0, globalContext_js_1.initGlobalContext)(false);
34
+ await (0, globalContext_js_1.getGlobalContextAsync)();
35
+ const globalContext = (0, globalContext_js_1.getGlobalContext)();
36
+ const pageFilesAll = await (0, getPageFiles_js_1.getPageFilesAll)(false, globalContext.isProduction);
37
+ return pageFilesAll;
38
+ }
39
+ exports.getPageFilesAllSafe = getPageFilesAllSafe;
30
40
  async function route(pageContext) {
31
41
  const pageContextFromRoute = await (0, index_js_1.route)(pageContext);
32
42
  // Old interface
@@ -33,7 +33,8 @@ const configDefinitionsBuiltIn = {
33
33
  cumulative: true
34
34
  },
35
35
  route: {
36
- env: { server: true, client: 'if-client-routing', eager: true }
36
+ env: { server: true, client: 'if-client-routing' },
37
+ eager: true
37
38
  },
38
39
  guard: {
39
40
  env: { server: true, client: 'if-client-routing' }
@@ -42,7 +43,8 @@ const configDefinitionsBuiltIn = {
42
43
  env: { server: true }
43
44
  },
44
45
  iKnowThePerformanceRisksOfAsyncRouteFunctions: {
45
- env: { server: true, client: 'if-client-routing', eager: true }
46
+ env: { server: true, client: 'if-client-routing' },
47
+ eager: true
46
48
  },
47
49
  filesystemRoutingRoot: {
48
50
  env: { config: true }
@@ -54,7 +56,8 @@ const configDefinitionsBuiltIn = {
54
56
  },
55
57
  clientRouting: {
56
58
  // We could make it { client: false } but we don't yet because of some legacy V0.4 design code
57
- env: { server: true, client: true, config: true, eager: true }
59
+ env: { server: true, client: true, config: true },
60
+ eager: true
58
61
  },
59
62
  clientHooks: {
60
63
  env: { config: true }
@@ -75,7 +78,8 @@ const configDefinitionsBuiltIn = {
75
78
  env: { config: true }
76
79
  },
77
80
  clientEntryLoaded: {
78
- env: { server: true, client: true, eager: true },
81
+ env: { server: true, client: true },
82
+ eager: true,
79
83
  _computed: (configValueSources) => {
80
84
  {
81
85
  const source = getConfigValueSource(configValueSources, 'clientHooks');
@@ -118,10 +122,12 @@ const configDefinitionsBuiltIn = {
118
122
  exports.configDefinitionsBuiltIn = configDefinitionsBuiltIn;
119
123
  const configDefinitionsBuiltInGlobal = {
120
124
  onPrerenderStart: {
121
- env: { server: true, production: true, eager: true }
125
+ env: { server: true, production: true },
126
+ eager: true
122
127
  },
123
128
  onBeforeRoute: {
124
- env: { server: true, client: 'if-client-routing', eager: true }
129
+ env: { server: true, client: 'if-client-routing' },
130
+ eager: true
125
131
  },
126
132
  prerender: {
127
133
  env: { config: true }
@@ -35,7 +35,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
35
35
  const importStatements = [];
36
36
  const isClientRouting = (0, getConfigValueBuildTime_js_1.getConfigValueBuildTime)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
37
37
  lines.push('export const configValuesSerialized = {');
38
- lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: false, isDev }), ''));
38
+ lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isDev }), { isEager: false }, ''));
39
39
  lines.push('};');
40
40
  if (!(0, fixServerAssets_js_1.fixServerAssets_isEnabled)() && includeAssetsImportedByServer && isForClientSide && !isDev) {
41
41
  importStatements.push(`import '${(0, extractAssetsQuery_js_1.extractAssetsAddQuery)((0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageId, false))}'`);
@@ -35,7 +35,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
35
35
  lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
36
36
  lines.push(` loadConfigValuesAll: () => import(${JSON.stringify(virtualFileIdPageConfigValuesAll)}),`);
37
37
  lines.push(` configValuesSerialized: {`);
38
- lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true, isDev }), ' '));
38
+ lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isDev }), { isEager: true }, ' '));
39
39
  lines.push(` },`);
40
40
  lines.push(` },`);
41
41
  });
@@ -45,7 +45,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
45
45
  function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements) {
46
46
  const lines = [];
47
47
  lines.push(` configValuesSerialized: {`);
48
- lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfigGlobal, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true, isDev }), ' '));
48
+ lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfigGlobal, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isDev }), { isEager: true }, ' '));
49
49
  lines.push(` },`);
50
50
  const code = lines.join('\n');
51
51
  return code;
@@ -13,9 +13,6 @@ function isRuntimeEnvMatch(configEnv, runtime) {
13
13
  if (configEnv.client === 'if-client-routing' && !runtime.isClientRouting)
14
14
  return false;
15
15
  }
16
- // Eager
17
- if (runtime.isEager !== !!configEnv.eager)
18
- return false;
19
16
  // Production/development
20
17
  if (
21
18
  //
@@ -11,6 +11,7 @@ const assertPluginManifest_js_1 = require("../shared/assertPluginManifest.js");
11
11
  const getConfigVike_js_1 = require("../shared/getConfigVike.js");
12
12
  const assertRuntimeManifest_js_1 = require("../shared/assertRuntimeManifest.js");
13
13
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
14
+ const getPageFilesExports_js_1 = require("./page-files/getPageFilesExports.js");
14
15
  let resolveGlobalContext;
15
16
  const globalObject = (0, utils_js_1.getGlobalObject)('globalContext.ts', {
16
17
  globalContextPromise: new Promise((r) => (resolveGlobalContext = r))
@@ -63,6 +64,7 @@ function setGlobalContext_viteDevServer(viteDevServer) {
63
64
  (0, utils_js_1.assert)(!globalObject.globalContext);
64
65
  globalObject.viteConfig = viteDevServer.config;
65
66
  globalObject.viteDevServer = viteDevServer;
67
+ eagerlyLoadUserFiles();
66
68
  }
67
69
  exports.setGlobalContext_viteDevServer = setGlobalContext_viteDevServer;
68
70
  function setGlobalContext_isDev(isDev) {
@@ -186,3 +188,8 @@ function assertViteManifest(manifest) {
186
188
  })
187
189
  */
188
190
  }
191
+ function eagerlyLoadUserFiles() {
192
+ // Other than here, the getPageFilesExports() function is only called only upon calling the renderPage() function.
193
+ // We call it as early as possible here for better performance.
194
+ (0, getPageFilesExports_js_1.getPageFilesExports)();
195
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPageFilesExports = void 0;
4
+ const utils_js_1 = require("../utils.js");
5
+ const globalContext_js_1 = require("../globalContext.js");
6
+ const virtualFileImportUserCode_js_1 = require("../../shared/virtual-files/virtualFileImportUserCode.js");
7
+ async function getPageFilesExports() {
8
+ const viteDevServer = (0, globalContext_js_1.getViteDevServer)();
9
+ (0, utils_js_1.assert)(viteDevServer);
10
+ let moduleExports;
11
+ try {
12
+ moduleExports = await viteDevServer.ssrLoadModule(virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer);
13
+ }
14
+ catch (err) {
15
+ (0, utils_js_1.debugGlob)(`Glob error: ${virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer} transpile error: `, err);
16
+ throw err;
17
+ }
18
+ moduleExports = moduleExports.default || moduleExports;
19
+ (0, utils_js_1.debugGlob)('Glob result: ', moduleExports);
20
+ (0, utils_js_1.assert)((0, utils_js_1.isObject)(moduleExports));
21
+ return moduleExports;
22
+ }
23
+ exports.getPageFilesExports = getPageFilesExports;
@@ -1,23 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const getPageFiles_js_1 = require("../../../shared/getPageFiles.js");
4
- const utils_js_1 = require("../utils.js");
5
- const globalContext_js_1 = require("../globalContext.js");
6
- const virtualFileImportUserCode_js_1 = require("../../shared/virtual-files/virtualFileImportUserCode.js");
7
- (0, getPageFiles_js_1.setPageFilesAsync)(getPageFilesExports);
8
- async function getPageFilesExports() {
9
- const viteDevServer = (0, globalContext_js_1.getViteDevServer)();
10
- (0, utils_js_1.assert)(viteDevServer);
11
- let moduleExports;
12
- try {
13
- moduleExports = await viteDevServer.ssrLoadModule(virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer);
14
- }
15
- catch (err) {
16
- (0, utils_js_1.debugGlob)(`Glob error: ${virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer} transpile error: `, err);
17
- throw err;
18
- }
19
- moduleExports = moduleExports.default || moduleExports;
20
- (0, utils_js_1.debugGlob)('Glob result: ', moduleExports);
21
- (0, utils_js_1.assert)((0, utils_js_1.isObject)(moduleExports));
22
- return moduleExports;
23
- }
4
+ const getPageFilesExports_js_1 = require("./getPageFilesExports.js");
5
+ (0, getPageFiles_js_1.setPageFilesAsync)(getPageFilesExports_js_1.getPageFilesExports);
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPageContext = void 0;
3
+ exports.providePageContext = exports.getPageContext = void 0;
4
4
  var executeHook_js_1 = require("./hooks/executeHook.js");
5
5
  Object.defineProperty(exports, "getPageContext", { enumerable: true, get: function () { return executeHook_js_1.getPageContext; } });
6
+ Object.defineProperty(exports, "providePageContext", { enumerable: true, get: function () { return executeHook_js_1.providePageContext; } });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUserHookError = exports.getPageContext = exports.executeHook = void 0;
3
+ exports.isUserHookError = exports.providePageContext = exports.getPageContext = exports.executeHook = void 0;
4
4
  const assert_js_1 = require("../../utils/assert.js");
5
5
  const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
6
6
  const humanizeTime_js_1 = require("../../utils/humanizeTime.js");
@@ -72,6 +72,11 @@ function getPageContext() {
72
72
  return globalObject.pageContext;
73
73
  }
74
74
  exports.getPageContext = getPageContext;
75
+ /**
76
+ * Provide `pageContext` for universal hooks.
77
+ *
78
+ * https://vike.dev/getPageContext
79
+ */
75
80
  function providePageContext(pageContext) {
76
81
  globalObject.pageContext = pageContext;
77
82
  // Promise.resolve() is quicker than process.nextTick() and setImmediate()
@@ -80,3 +85,4 @@ function providePageContext(pageContext) {
80
85
  globalObject.pageContext = null;
81
86
  });
82
87
  }
88
+ exports.providePageContext = providePageContext;
@@ -17,7 +17,7 @@ const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
17
17
  // - vike/shared/page-configs/serialize/parsePageConfigs.ts
18
18
  // - parsePageConfigs() is loaded on both the client- and server-side.
19
19
  (0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
20
- function serializeConfigValues(pageConfig, importStatements, isEnvMatch, tabspace) {
20
+ function serializeConfigValues(pageConfig, importStatements, isEnvMatch, { isEager }, tabspace) {
21
21
  const lines = [];
22
22
  tabspace += ' ';
23
23
  Object.entries(pageConfig.configValuesComputed ?? {}).forEach(([configName, configValuesComputed]) => {
@@ -36,6 +36,8 @@ function serializeConfigValues(pageConfig, importStatements, isEnvMatch, tabspac
36
36
  Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
37
37
  const configDef = pageConfig.configDefinitions[configName];
38
38
  (0, utils_js_1.assert)(configDef);
39
+ if (isEager !== !!configDef.eager)
40
+ return;
39
41
  if (!configDef.cumulative) {
40
42
  const configValueSource = sources[0];
41
43
  (0, utils_js_1.assert)(configValueSource);
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.190';
5
+ exports.PROJECT_VERSION = '0.4.191-commit-7e0cd43';
@@ -1,5 +1,6 @@
1
1
  export { route, getPagesAndRoutes };
2
2
  export type { PageRoutes, PageFile, PageConfigRuntime as PageConfig };
3
+ export { getPageFilesAllSafe };
3
4
  import { route as routeInternal, type PageRoutes } from '../shared/route/index.js';
4
5
  import { type PageFile } from '../shared/getPageFiles.js';
5
6
  import { PageConfigRuntime } from '../shared/page-configs/PageConfig.js';
@@ -15,6 +16,12 @@ declare function getPagesAndRoutes(): Promise<{
15
16
  pageConfigs: PageConfigRuntime[];
16
17
  allPageIds: string[];
17
18
  }>;
19
+ declare function getPageFilesAllSafe(): Promise<{
20
+ pageFilesAll: PageFile[];
21
+ allPageIds: string[];
22
+ pageConfigs: PageConfigRuntime[];
23
+ pageConfigGlobal: import("../shared/page-configs/PageConfig.js").PageConfigGlobalRuntime;
24
+ }>;
18
25
  declare function route(pageContext: Parameters<typeof routeInternal>[0]): Promise<{
19
26
  pageContextAddendum: import("../shared/route/index.js").PageContextFromRoute;
20
27
  }>;
@@ -1,7 +1,10 @@
1
1
  // Internals needed by vite-plugin-vercel
2
2
  export { route, getPagesAndRoutes };
3
+ // Internals needed by nitedani's experimental implementation of vike-telefunc
4
+ export { getPageFilesAllSafe };
3
5
  import { route as routeInternal } from '../shared/route/index.js';
4
- import { getGlobalContext, initGlobalContext } from '../node/runtime/globalContext.js';
6
+ import { getPageFilesAll } from '../shared/getPageFiles.js';
7
+ import { getGlobalContext, getGlobalContextAsync, initGlobalContext } from '../node/runtime/globalContext.js';
5
8
  import { handleNodeEnv_vitePluginVercel } from '../utils/assertNodeEnv.js';
6
9
  import { assert } from '../utils/assert.js';
7
10
  import { getRenderContext } from '../node/runtime/renderPage/renderPageAlreadyRouted.js';
@@ -25,6 +28,14 @@ async function getPagesAndRoutes() {
25
28
  allPageIds
26
29
  };
27
30
  }
31
+ // TODO: make it cleaner once the internal refactoring about global configs is done
32
+ async function getPageFilesAllSafe() {
33
+ await initGlobalContext(false);
34
+ await getGlobalContextAsync();
35
+ const globalContext = getGlobalContext();
36
+ const pageFilesAll = await getPageFilesAll(false, globalContext.isProduction);
37
+ return pageFilesAll;
38
+ }
28
39
  async function route(pageContext) {
29
40
  const pageContextFromRoute = await routeInternal(pageContext);
30
41
  // Old interface
@@ -31,6 +31,14 @@ type ConfigDefinition = {
31
31
  * https://vike.dev/meta
32
32
  */
33
33
  effect?: ConfigEffect;
34
+ /**
35
+ * Always load the configuration value, and as soon as possible.
36
+ *
37
+ * @default false
38
+ *
39
+ * https://vike.dev/meta
40
+ */
41
+ eager?: boolean;
34
42
  /**
35
43
  * Whether the configuration always applies to all pages (no config inheritance).
36
44
  *
@@ -32,7 +32,8 @@ const configDefinitionsBuiltIn = {
32
32
  cumulative: true
33
33
  },
34
34
  route: {
35
- env: { server: true, client: 'if-client-routing', eager: true }
35
+ env: { server: true, client: 'if-client-routing' },
36
+ eager: true
36
37
  },
37
38
  guard: {
38
39
  env: { server: true, client: 'if-client-routing' }
@@ -41,7 +42,8 @@ const configDefinitionsBuiltIn = {
41
42
  env: { server: true }
42
43
  },
43
44
  iKnowThePerformanceRisksOfAsyncRouteFunctions: {
44
- env: { server: true, client: 'if-client-routing', eager: true }
45
+ env: { server: true, client: 'if-client-routing' },
46
+ eager: true
45
47
  },
46
48
  filesystemRoutingRoot: {
47
49
  env: { config: true }
@@ -53,7 +55,8 @@ const configDefinitionsBuiltIn = {
53
55
  },
54
56
  clientRouting: {
55
57
  // We could make it { client: false } but we don't yet because of some legacy V0.4 design code
56
- env: { server: true, client: true, config: true, eager: true }
58
+ env: { server: true, client: true, config: true },
59
+ eager: true
57
60
  },
58
61
  clientHooks: {
59
62
  env: { config: true }
@@ -74,7 +77,8 @@ const configDefinitionsBuiltIn = {
74
77
  env: { config: true }
75
78
  },
76
79
  clientEntryLoaded: {
77
- env: { server: true, client: true, eager: true },
80
+ env: { server: true, client: true },
81
+ eager: true,
78
82
  _computed: (configValueSources) => {
79
83
  {
80
84
  const source = getConfigValueSource(configValueSources, 'clientHooks');
@@ -116,10 +120,12 @@ const configDefinitionsBuiltIn = {
116
120
  };
117
121
  const configDefinitionsBuiltInGlobal = {
118
122
  onPrerenderStart: {
119
- env: { server: true, production: true, eager: true }
123
+ env: { server: true, production: true },
124
+ eager: true
120
125
  },
121
126
  onBeforeRoute: {
122
- env: { server: true, client: 'if-client-routing', eager: true }
127
+ env: { server: true, client: 'if-client-routing' },
128
+ eager: true
123
129
  },
124
130
  prerender: {
125
131
  env: { config: true }
@@ -32,7 +32,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
32
32
  const importStatements = [];
33
33
  const isClientRouting = getConfigValueBuildTime(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
34
34
  lines.push('export const configValuesSerialized = {');
35
- lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: false, isDev }), ''));
35
+ lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), { isEager: false }, ''));
36
36
  lines.push('};');
37
37
  if (!fixServerAssets_isEnabled() && includeAssetsImportedByServer && isForClientSide && !isDev) {
38
38
  importStatements.push(`import '${extractAssetsAddQuery(getVirtualFileIdPageConfigValuesAll(pageId, false))}'`);
@@ -32,7 +32,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
32
32
  lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
33
33
  lines.push(` loadConfigValuesAll: () => import(${JSON.stringify(virtualFileIdPageConfigValuesAll)}),`);
34
34
  lines.push(` configValuesSerialized: {`);
35
- lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true, isDev }), ' '));
35
+ lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), { isEager: true }, ' '));
36
36
  lines.push(` },`);
37
37
  lines.push(` },`);
38
38
  });
@@ -42,7 +42,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
42
42
  function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements) {
43
43
  const lines = [];
44
44
  lines.push(` configValuesSerialized: {`);
45
- lines.push(...serializeConfigValues(pageConfigGlobal, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true, isDev }), ' '));
45
+ lines.push(...serializeConfigValues(pageConfigGlobal, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), { isEager: true }, ' '));
46
46
  lines.push(` },`);
47
47
  const code = lines.join('\n');
48
48
  return code;
@@ -3,6 +3,5 @@ import type { ConfigEnvInternal } from '../../../../../shared/page-configs/PageC
3
3
  declare function isRuntimeEnvMatch(configEnv: ConfigEnvInternal, runtime: {
4
4
  isForClientSide: boolean;
5
5
  isClientRouting: boolean;
6
- isEager: boolean;
7
6
  isDev: boolean;
8
7
  }): boolean;
@@ -11,9 +11,6 @@ function isRuntimeEnvMatch(configEnv, runtime) {
11
11
  if (configEnv.client === 'if-client-routing' && !runtime.isClientRouting)
12
12
  return false;
13
13
  }
14
- // Eager
15
- if (runtime.isEager !== !!configEnv.eager)
16
- return false;
17
14
  // Production/development
18
15
  if (
19
16
  //
@@ -17,6 +17,7 @@ import { assertPluginManifest } from '../shared/assertPluginManifest.js';
17
17
  import { getConfigVike } from '../shared/getConfigVike.js';
18
18
  import { assertRuntimeManifest } from '../shared/assertRuntimeManifest.js';
19
19
  import pc from '@brillout/picocolors';
20
+ import { getPageFilesExports } from './page-files/getPageFilesExports.js';
20
21
  let resolveGlobalContext;
21
22
  const globalObject = getGlobalObject('globalContext.ts', {
22
23
  globalContextPromise: new Promise((r) => (resolveGlobalContext = r))
@@ -66,6 +67,7 @@ function setGlobalContext_viteDevServer(viteDevServer) {
66
67
  assert(!globalObject.globalContext);
67
68
  globalObject.viteConfig = viteDevServer.config;
68
69
  globalObject.viteDevServer = viteDevServer;
70
+ eagerlyLoadUserFiles();
69
71
  }
70
72
  function setGlobalContext_isDev(isDev) {
71
73
  globalObject.isDev = isDev;
@@ -182,3 +184,8 @@ function assertViteManifest(manifest) {
182
184
  })
183
185
  */
184
186
  }
187
+ function eagerlyLoadUserFiles() {
188
+ // Other than here, the getPageFilesExports() function is only called only upon calling the renderPage() function.
189
+ // We call it as early as possible here for better performance.
190
+ getPageFilesExports();
191
+ }
@@ -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
- }
@@ -1 +1 @@
1
- export { getPageContext } from './hooks/executeHook.js';
1
+ export { getPageContext, providePageContext } from './hooks/executeHook.js';
@@ -1 +1 @@
1
- export { getPageContext } from './hooks/executeHook.js';
1
+ export { getPageContext, providePageContext } from './hooks/executeHook.js';
@@ -1,9 +1,10 @@
1
1
  export { executeHook };
2
2
  export { getPageContext };
3
+ export { providePageContext };
3
4
  export { isUserHookError };
4
5
  import type { PageContextClient, PageContextServer } from '../types.js';
5
6
  import type { Hook, HookLoc } from './getHook.js';
6
- type PageContextUnknown = null | Record<string, unknown>;
7
+ type PageContextUnknown = null | Record<string, any>;
7
8
  declare function isUserHookError(err: unknown): false | HookLoc;
8
9
  declare function executeHook<T = unknown>(hookFnCaller: () => T, hook: Omit<Hook, 'hookFn'>, pageContext: PageContextUnknown): Promise<T>;
9
10
  /**
@@ -12,3 +13,9 @@ declare function executeHook<T = unknown>(hookFnCaller: () => T, hook: Omit<Hook
12
13
  * https://vike.dev/getPageContext
13
14
  */
14
15
  declare function getPageContext<PageContext = PageContextClient | PageContextServer>(): null | PageContext;
16
+ /**
17
+ * Provide `pageContext` for universal hooks.
18
+ *
19
+ * https://vike.dev/getPageContext
20
+ */
21
+ declare function providePageContext(pageContext: PageContextUnknown): void;
@@ -1,5 +1,6 @@
1
1
  export { executeHook };
2
2
  export { getPageContext };
3
+ export { providePageContext };
3
4
  export { isUserHookError };
4
5
  import { getProjectError, assertWarning } from '../../utils/assert.js';
5
6
  import { getGlobalObject } from '../../utils/getGlobalObject.js';
@@ -69,6 +70,11 @@ function isNotDisabled(timeout) {
69
70
  function getPageContext() {
70
71
  return globalObject.pageContext;
71
72
  }
73
+ /**
74
+ * Provide `pageContext` for universal hooks.
75
+ *
76
+ * https://vike.dev/getPageContext
77
+ */
72
78
  function providePageContext(pageContext) {
73
79
  globalObject.pageContext = pageContext;
74
80
  // Promise.resolve() is quicker than process.nextTick() and setImmediate()
@@ -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
  };
@@ -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);
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.190";
1
+ export declare const PROJECT_VERSION: "0.4.191-commit-7e0cd43";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.190';
2
+ export const PROJECT_VERSION = '0.4.191-commit-7e0cd43';
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.190";
3
+ projectVersion: "0.4.191-commit-7e0cd43";
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.190",
3
+ "version": "0.4.191-commit-7e0cd43",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",