vike 0.4.236-commit-eab75f6 → 0.4.237

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 (69) hide show
  1. package/dist/cjs/client/shared/createGetGlobalContextClient.js +2 -4
  2. package/dist/cjs/node/runtime/html/serializeContext.js +8 -47
  3. package/dist/cjs/node/runtime/html/stream.js +1 -1
  4. package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +4 -7
  5. package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +50 -14
  6. package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +19 -6
  7. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -3
  8. package/dist/cjs/node/runtime/renderPage.js +7 -6
  9. package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +45 -43
  10. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +67 -0
  11. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +1 -2
  12. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +2 -3
  13. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
  14. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +7 -18
  15. package/dist/cjs/shared/createGlobalContextShared.js +13 -0
  16. package/dist/cjs/shared/modifyUrlSameOrigin.js +9 -4
  17. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +12 -13
  18. package/dist/cjs/shared/utils.js +2 -0
  19. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  20. package/dist/cjs/utils/cast.js +1 -1
  21. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +35 -48
  22. package/dist/esm/client/runtime-client-routing/history.d.ts +3 -5
  23. package/dist/esm/client/runtime-client-routing/history.js +39 -22
  24. package/dist/esm/client/runtime-client-routing/initClientRouter.js +2 -3
  25. package/dist/esm/client/runtime-client-routing/utils.d.ts +2 -0
  26. package/dist/esm/client/runtime-client-routing/utils.js +2 -0
  27. package/dist/esm/client/shared/createGetGlobalContextClient.js +2 -4
  28. package/dist/esm/node/runtime/html/serializeContext.d.ts +8 -3
  29. package/dist/esm/node/runtime/html/serializeContext.js +8 -47
  30. package/dist/esm/node/runtime/html/stream.js +1 -1
  31. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +1 -1
  32. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +4 -7
  33. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
  34. package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.d.ts +1 -1
  35. package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.js +51 -15
  36. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +20 -7
  37. package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
  38. package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +0 -1
  39. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +4 -5
  40. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -3
  41. package/dist/esm/node/runtime/renderPage.d.ts +1 -0
  42. package/dist/esm/node/runtime/renderPage.js +7 -6
  43. package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +46 -44
  44. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +14 -0
  45. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +65 -0
  46. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +1 -2
  47. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +2 -3
  48. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.d.ts +2 -2
  49. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
  50. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +1 -3
  51. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +8 -19
  52. package/dist/esm/shared/createGlobalContextShared.js +14 -1
  53. package/dist/esm/shared/modifyUrlSameOrigin.d.ts +1 -1
  54. package/dist/esm/shared/modifyUrlSameOrigin.js +9 -4
  55. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -2
  56. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +12 -13
  57. package/dist/esm/shared/utils.d.ts +2 -0
  58. package/dist/esm/shared/utils.js +2 -0
  59. package/dist/esm/types/Config.d.ts +33 -98
  60. package/dist/esm/types/index.d.ts +3 -1
  61. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  62. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  63. package/dist/esm/utils/cast.d.ts +2 -2
  64. package/dist/esm/utils/cast.js +1 -1
  65. package/dist/esm/utils/objectFilter.d.ts +1 -1
  66. package/package.json +1 -1
  67. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -23
  68. package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.d.ts +0 -7
  69. package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -21
@@ -0,0 +1,65 @@
1
+ export { getConfigValueSourcesRelevant };
2
+ export { isRuntimeEnvMatch };
3
+ import { assert } from '../../utils.js';
4
+ function getConfigValueSourcesRelevant(configName, runtimeEnv, pageConfig) {
5
+ const configDef = pageConfig.configDefinitions[configName];
6
+ assert(configDef);
7
+ let sourcesRelevant = pageConfig.configValueSources[configName];
8
+ if (!sourcesRelevant)
9
+ return [];
10
+ if (!configDef.cumulative) {
11
+ const source = sourcesRelevant[0];
12
+ if (source) {
13
+ sourcesRelevant = [source];
14
+ }
15
+ else {
16
+ assert(sourcesRelevant.length === 0);
17
+ }
18
+ }
19
+ else {
20
+ // isOverridden() must be called before isRuntimeEnvMatch() is called (otherwise isOverridden() will return a wrong value)
21
+ sourcesRelevant = sourcesRelevant.filter((source) => !isOverridden(source, configName, pageConfig));
22
+ }
23
+ sourcesRelevant = sourcesRelevant.filter((source) => isRuntimeEnvMatch(source.configEnv, runtimeEnv));
24
+ return sourcesRelevant;
25
+ }
26
+ function isRuntimeEnvMatch(configEnv, runtimeEnv) {
27
+ if ('isForConfig' in runtimeEnv)
28
+ return !!configEnv.config;
29
+ // Runtime
30
+ if (!runtimeEnv.isForClientSide) {
31
+ if (!configEnv.server)
32
+ return false;
33
+ }
34
+ else {
35
+ if (!configEnv.client)
36
+ return false;
37
+ if (configEnv.client === 'if-client-routing' && !runtimeEnv.isClientRouting)
38
+ return false;
39
+ }
40
+ // Production/development
41
+ if (configEnv.production !== undefined) {
42
+ assert(typeof configEnv.production === 'boolean');
43
+ assert(typeof runtimeEnv.isDev === 'boolean');
44
+ if (configEnv.production) {
45
+ if (runtimeEnv.isDev)
46
+ return false;
47
+ }
48
+ else {
49
+ if (!runtimeEnv.isDev)
50
+ return false;
51
+ }
52
+ }
53
+ return true;
54
+ }
55
+ function isOverridden(source, configName, pageConfig) {
56
+ const configDef = pageConfig.configDefinitions[configName];
57
+ assert(configDef);
58
+ if (configDef.cumulative)
59
+ return false;
60
+ const sources = pageConfig.configValueSources[configName];
61
+ assert(sources);
62
+ const idx = sources.indexOf(source);
63
+ assert(idx >= 0);
64
+ return idx > 0;
65
+ }
@@ -5,7 +5,6 @@ import { getVirtualFileIdPageConfigLazy, isVirtualFileIdPageConfigLazy, } from '
5
5
  import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
6
6
  import { extractAssetsAddQuery } from '../../../shared/extractAssetsQuery.js';
7
7
  import { debug } from './debug.js';
8
- import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
9
8
  import { serializeConfigValues } from '../../../../shared/page-configs/serialize/serializeConfigValues.js';
10
9
  import { handleAssetsManifest_isFixEnabled } from '../pluginBuild/handleAssetsManifest.js';
11
10
  import { getConfigValueBuildTime } from '../../../../shared/page-configs/getConfigValueBuildTime.js';
@@ -44,7 +43,7 @@ function getLoadConfigLazy(pageConfig, isForClientSide, pageId, includeAssetsImp
44
43
  const filesEnv = new Map();
45
44
  const isClientRouting = getConfigValueBuildTime(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
46
45
  lines.push('export const configValuesSerialized = {');
47
- lines.push(...serializeConfigValues(pageConfig, importStatements, filesEnv, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), '', false));
46
+ lines.push(...serializeConfigValues(pageConfig, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, '', false));
48
47
  lines.push('};');
49
48
  if (!handleAssetsManifest_isFixEnabled(config) && includeAssetsImportedByServer && isForClientSide && !isDev) {
50
49
  importStatements.push(`import '${extractAssetsAddQuery(getVirtualFileIdPageConfigLazy(pageId, false))}'`);
@@ -2,7 +2,6 @@ export { getVirtualFilePageConfigsEager };
2
2
  import { getVirtualFileIdPageConfigLazy } from '../../../shared/virtualFiles/virtualFilePageConfigLazy.js';
3
3
  import { debug } from './debug.js';
4
4
  import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
5
- import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
6
5
  import { serializeConfigValues } from '../../../../shared/page-configs/serialize/serializeConfigValues.js';
7
6
  async function getVirtualFilePageConfigsEager(isForClientSide, isDev, id, isClientRouting) {
8
7
  const vikeConfig = await getVikeConfigInternal(true);
@@ -39,7 +38,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
39
38
  const load = `() => ({ moduleId: ${virtualFileId}, moduleExports: import(${virtualFileId}) })`;
40
39
  lines.push(` loadConfigLazy: ${load},`);
41
40
  lines.push(` configValuesSerialized: {`);
42
- lines.push(...serializeConfigValues(pageConfig, importStatements, filesEnv, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), ' ', true));
41
+ lines.push(...serializeConfigValues(pageConfig, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, ' ', true));
43
42
  lines.push(` },`);
44
43
  lines.push(` },`);
45
44
  });
@@ -49,7 +48,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
49
48
  function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements, filesEnv) {
50
49
  const lines = [];
51
50
  lines.push(` configValuesSerialized: {`);
52
- lines.push(...serializeConfigValues(pageConfigGlobal, importStatements, filesEnv, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), ' ', null));
51
+ lines.push(...serializeConfigValues(pageConfigGlobal, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, ' ', null));
53
52
  lines.push(` },`);
54
53
  const code = lines.join('\n');
55
54
  return code;
@@ -4,7 +4,7 @@ export type { ConfigDefinitions };
4
4
  export type { ConfigDefinitionsInternal };
5
5
  export type { ConfigDefinitionInternal };
6
6
  export type { ConfigEffect };
7
- import type { ConfigEnvInternal, ConfigEnv, ConfigValueSources, DefinedAtFilePath } from '../../../../types/PageConfig.js';
7
+ import type { ConfigEnvInternal, ConfigEnv, DefinedAtFilePath, PageConfigBuildTime } from '../../../../types/PageConfig.js';
8
8
  import type { Config, ConfigNameBuiltIn, ConfigNameGlobal } from '../../../../types/Config.js';
9
9
  import { type ConfigDefinedAt } from '../../../../shared/page-configs/getConfigDefinedAt.js';
10
10
  /** The meta definition of a config.
@@ -75,7 +75,7 @@ type ConfigEffect = (config: {
75
75
  }) => Config | undefined;
76
76
  /** For Vike internal use */
77
77
  type ConfigDefinitionInternal = Omit<ConfigDefinition_, 'env'> & {
78
- _computed?: (configValueSources: ConfigValueSources) => unknown;
78
+ _computed?: (pageConfig: Omit<PageConfigBuildTime, 'configValuesComputed'>) => unknown;
79
79
  _valueIsFilePath?: true;
80
80
  _userEffectDefinedAtFilePath?: DefinedAtFilePath;
81
81
  env: ConfigEnvInternal;
@@ -1,6 +1,7 @@
1
1
  export { configDefinitionsBuiltIn };
2
2
  import { assert, assertUsage } from '../../utils.js';
3
3
  import { getConfigDefinedAt } from '../../../../shared/page-configs/getConfigDefinedAt.js';
4
+ import { getConfigValueSourcesRelevant } from '../../plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js';
4
5
  const configDefinitionsBuiltIn = {
5
6
  onRenderHtml: {
6
7
  env: { server: true },
@@ -95,6 +96,22 @@ const configDefinitionsBuiltIn = {
95
96
  meta: {
96
97
  env: { config: true },
97
98
  },
99
+ serverOnlyHooks: {
100
+ env: { client: true },
101
+ eager: true,
102
+ _computed: (pageConfig) => {
103
+ const sources = ['data', 'onBeforeRender', 'onCreatePageContext']
104
+ .map((hookName) => getConfigValueSourcesRelevant(hookName, {
105
+ isForClientSide: false,
106
+ // TO-DO/eventually/remove-server-router: let's eventually remove support for Server Routing
107
+ isClientRouting: true,
108
+ }, pageConfig))
109
+ .flat(1)
110
+ // Server-only
111
+ .filter((source) => !source.configEnv.client);
112
+ return sources.length > 0;
113
+ },
114
+ },
98
115
  // Whether the page loads:
99
116
  // - Vike's client runtime
100
117
  // - User's client hooks
@@ -102,7 +119,8 @@ const configDefinitionsBuiltIn = {
102
119
  isClientRuntimeLoaded: {
103
120
  env: { server: true, client: true },
104
121
  eager: true,
105
- _computed: (configValueSources) => {
122
+ _computed: (pageConfig) => {
123
+ const { configValueSources } = pageConfig;
106
124
  {
107
125
  const source = getConfigValueSource(configValueSources, 'clientHooks');
108
126
  if (source) {
@@ -120,15 +138,25 @@ const configDefinitionsBuiltIn = {
120
138
  !!getConfigEnv(configValueSources, 'Page')?.client);
121
139
  },
122
140
  },
141
+ // TO-DO/soon/cumulative-hooks: remove and replace with new computed prop `clientOnlyHooks: string[]` (see other TO-DO/soon/cumulative-hooks entries)
123
142
  onBeforeRenderEnv: {
124
143
  env: { client: true },
125
144
  eager: true,
126
- _computed: (configValueSources) => !isConfigSet(configValueSources, 'onBeforeRender') ? null : getConfigEnv(configValueSources, 'onBeforeRender'),
145
+ _computed: (pageConfig) => {
146
+ const { configValueSources } = pageConfig;
147
+ return !isConfigSet(configValueSources, 'onBeforeRender')
148
+ ? null
149
+ : getConfigEnv(configValueSources, 'onBeforeRender');
150
+ },
127
151
  },
152
+ // TO-DO/soon/cumulative-hooks: remove and replace with new computed prop `clientOnlyHooks: string[]` (see other TO-DO/soon/cumulative-hooks entries)
128
153
  dataEnv: {
129
154
  env: { client: true },
130
155
  eager: true,
131
- _computed: (configValueSources) => !isConfigSet(configValueSources, 'data') ? null : getConfigEnv(configValueSources, 'data'),
156
+ _computed: (pageConfig) => {
157
+ const { configValueSources } = pageConfig;
158
+ return !isConfigSet(configValueSources, 'data') ? null : getConfigEnv(configValueSources, 'data');
159
+ },
132
160
  },
133
161
  hooksTimeout: {
134
162
  env: { server: true, client: true },
@@ -7,11 +7,10 @@ export { isV1Design };
7
7
  export { getConfVal };
8
8
  export { getConfigDefinitionOptional };
9
9
  export { getVikeConfigFromCliOrEnv };
10
- export { isOverridden };
11
10
  export type { VikeConfigInternal };
12
11
  export { getVikeConfig };
13
12
  export type { VikeConfig };
14
- import type { PageConfigGlobalBuildTime, ConfigValueSource, PageConfigBuildTime } from '../../../types/PageConfig.js';
13
+ import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../types/PageConfig.js';
15
14
  import { type ConfigDefinitionsInternal, type ConfigDefinitionInternal } from './resolveVikeConfigInternal/configDefinitionsBuiltIn.js';
16
15
  import { type VikeConfigPublicGlobal, type VikeConfigPublicPageEager } from '../../../shared/page-configs/resolveVikeConfigPublic.js';
17
16
  import { type PlusFile } from './resolveVikeConfigInternal/getPlusFilesAll.js';
@@ -65,4 +64,3 @@ declare function getConfVal(plusFile: PlusFile, configName: string): null | {
65
64
  } | {
66
65
  valueIsLoaded: false;
67
66
  };
68
- declare function isOverridden(source: ConfigValueSource, configName: string, pageConfig: PageConfigBuildTime | PageConfigGlobalBuildTime): boolean;
@@ -8,10 +8,9 @@ export { isV1Design };
8
8
  export { getConfVal };
9
9
  export { getConfigDefinitionOptional };
10
10
  export { getVikeConfigFromCliOrEnv };
11
- export { isOverridden };
12
11
  // Public usage
13
12
  export { getVikeConfig };
14
- import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, includes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, assertKeys, objectKeys, objectFromEntries, unique, isCallable, makeFirst, lowerFirst, makeLast, assertIsSingleModuleInstance, genPromise, } from '../utils.js';
13
+ import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, includes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, assertKeys, objectKeys, objectFromEntries, unique, isCallable, makeFirst, lowerFirst, makeLast, assertIsSingleModuleInstance, genPromise, checkType, objectAssign, } from '../utils.js';
15
14
  import { configDefinitionsBuiltIn, } from './resolveVikeConfigInternal/configDefinitionsBuiltIn.js';
16
15
  import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, applyFilesystemRoutingRootEffect, } from './resolveVikeConfigInternal/filesystemRouting.js';
17
16
  import { getViteDevServer } from '../../runtime/globalContext.js';
@@ -287,15 +286,16 @@ function getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRo
287
286
  applyEffectsMetaEnv(configValueSources, configDefinitionsLocal);
288
287
  applyEffectsConfVal(configValueSources, configDefinitionsLocal, plusFilesAll);
289
288
  sortConfigValueSources(configValueSources, locationId);
290
- const configValuesComputed = getComputed(configValueSources, configDefinitionsLocal);
291
289
  const pageConfig = {
292
290
  pageId: locationId,
293
291
  ...pageConfigRoute,
294
292
  configDefinitions: configDefinitionsLocal,
295
293
  plusFiles: plusFilesRelevant,
296
294
  configValueSources,
297
- configValuesComputed,
298
295
  };
296
+ const configValuesComputed = getComputed(pageConfig);
297
+ objectAssign(pageConfig, { configValuesComputed });
298
+ checkType(pageConfig);
299
299
  return pageConfig;
300
300
  });
301
301
  assertPageConfigs(pageConfigs);
@@ -362,7 +362,7 @@ function assertOnBeforeRenderEnv(pageConfig) {
362
362
  }
363
363
  function getConfigValues(pageConfig, tolerateMissingValue) {
364
364
  const configValues = {};
365
- getConfigValuesBase(pageConfig, (configEnv) => !!configEnv.config, null).forEach((entry) => {
365
+ getConfigValuesBase(pageConfig, { isForConfig: true }, null).forEach((entry) => {
366
366
  if (entry.configValueBase.type === 'computed') {
367
367
  assert('value' in entry); // Help TS
368
368
  const { configValueBase, value, configName } = entry;
@@ -896,12 +896,12 @@ function applyEffectMetaEnv(configModFromEffect, configValueSources, configDefEf
896
896
  });
897
897
  });
898
898
  }
899
- function getComputed(configValueSources, configDefinitions) {
899
+ function getComputed(pageConfig) {
900
900
  const configValuesComputed = {};
901
- objectEntries(configDefinitions).forEach(([configName, configDef]) => {
901
+ objectEntries(pageConfig.configDefinitions).forEach(([configName, configDef]) => {
902
902
  if (!configDef._computed)
903
903
  return;
904
- const value = configDef._computed(configValueSources);
904
+ const value = configDef._computed(pageConfig);
905
905
  if (value === undefined)
906
906
  return;
907
907
  configValuesComputed[configName] = {
@@ -1097,17 +1097,6 @@ function isGlobalLocation(locationId, plusFilesAll) {
1097
1097
  .map(([locationId]) => locationId);
1098
1098
  return locationIdsPage.every((locId) => isInherited(locationId, locId));
1099
1099
  }
1100
- function isOverridden(source, configName, pageConfig) {
1101
- const configDef = pageConfig.configDefinitions[configName];
1102
- assert(configDef);
1103
- if (configDef.cumulative)
1104
- return false;
1105
- const sources = pageConfig.configValueSources[configName];
1106
- assert(sources);
1107
- const idx = sources.indexOf(source);
1108
- assert(idx >= 0);
1109
- return idx > 0;
1110
- }
1111
1100
  function resolvePrerenderContext(vikeConfig) {
1112
1101
  const { isPrerenderingEnabled, isPrerenderingEnabledForAllPages } = resolvePrerenderConfigGlobal(vikeConfig);
1113
1102
  prerenderContext ?? (prerenderContext = {
@@ -1,15 +1,27 @@
1
1
  export { createGlobalContextShared };
2
2
  export { getGlobalContextSyncErrMsg };
3
- import { changeEnumerable, objectAssign, objectReplace, unique } from './utils.js';
3
+ import { changeEnumerable, genPromise, getGlobalObject, objectAssign, objectReplace, unique } from './utils.js';
4
4
  import { parseVirtualFileExports } from './getPageFiles/parseVirtualFileExports.js';
5
5
  import { resolveVikeConfigPublicGlobal, resolveVikeConfigPublicPageEager, } from './page-configs/resolveVikeConfigPublic.js';
6
6
  import { execHookGlobal } from './hooks/execHook.js';
7
7
  import { prepareGlobalContextForPublicUsage } from './prepareGlobalContextForPublicUsage.js';
8
8
  import { getHookFromPageConfigGlobalCumulative } from './hooks/getHook.js';
9
9
  const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
10
+ const globalObject_ = getGlobalObject('shared/createGlobalContextShared.ts', {});
11
+ // TO-DO/eventually use flat globalContext — like flat pageContext
10
12
  async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext,
11
13
  // TO-DO/next-major-release: we'll be able to remove addGlobalContextTmp after loadPageRoutes() is sync (it will be sync after we remove the old design)
12
14
  addGlobalContextTmp, addGlobalContextAsync) {
15
+ const { previousCallPromise } = globalObject_;
16
+ const { promise, resolve } = genPromise({
17
+ // Avoid this Cloudflare Worker error:
18
+ // ```console
19
+ // Error: Disallowed operation called within global scope. Asynchronous I/O (ex: fetch() or connect()), setting a timeout, and generating random values are not allowed within global scope. To fix this error, perform this operation within a handler.
20
+ // ```
21
+ timeout: null,
22
+ });
23
+ globalObject_.previousCallPromise = promise;
24
+ await previousCallPromise;
13
25
  const globalContext = createGlobalContextBase(virtualFileExports);
14
26
  let isNewGlobalContext;
15
27
  if (!globalObject.globalContext) {
@@ -52,6 +64,7 @@ addGlobalContextTmp, addGlobalContextAsync) {
52
64
  objectAssign(globalObject.globalContext, globalContext, true);
53
65
  }
54
66
  }
67
+ resolve();
55
68
  return globalObject.globalContext;
56
69
  }
57
70
  function createGlobalContextBase(virtualFileExports) {
@@ -5,5 +5,5 @@ type ModifyUrlSameOriginOptions = {
5
5
  search?: Search | null;
6
6
  pathname?: string;
7
7
  };
8
- type Search = Record<string, string | null> | URLSearchParams;
8
+ type Search = Record<string, string | null | undefined> | URLSearchParams;
9
9
  declare function modifyUrlSameOrigin(url: string, modify: ModifyUrlSameOriginOptions): string;
@@ -1,4 +1,6 @@
1
1
  export { modifyUrlSameOrigin };
2
+ // We don't move modifyUrlSameOrigin() to the modifyUrl.ts file because we plan to use modifyUrlSameOrigin() on the client-side:
3
+ // https://github.com/vikejs/vike/blob/c5a2de5e85262771f97851767c00ac35da69c64b/packages/vike/client/runtime-client-routing/navigate.ts#L4
2
4
  import { createUrlFromComponents, isNotNullish_keyVal, parseUrl, objectFilter, assertUsageUrlPathnameAbsolute, } from './utils.js';
3
5
  function modifyUrlSameOrigin(url, modify) {
4
6
  const urlParsed = parseUrl(url, '/');
@@ -25,16 +27,19 @@ function modifyUrlSameOrigin(url, modify) {
25
27
  const urlModified = createUrlFromComponents(urlParsed.origin, pathname, search, hash);
26
28
  return urlModified;
27
29
  }
28
- function resolveSearch(urlParsed, search) {
30
+ function resolveSearch(urlParsed, modifySearch) {
29
31
  let searchParams;
30
- if (search instanceof URLSearchParams) {
32
+ if (modifySearch instanceof URLSearchParams) {
31
33
  // Overwrite
32
- searchParams = search;
34
+ searchParams = modifySearch;
33
35
  }
34
36
  else {
35
37
  // Merge
36
- const searchMap = objectFilter({ ...urlParsed.search, ...search }, (isNotNullish_keyVal));
38
+ const searchMap = objectFilter({ ...urlParsed.search, ...objectFilter(modifySearch, isNotUndefined) }, (isNotNullish_keyVal));
37
39
  searchParams = new URLSearchParams(searchMap);
38
40
  }
39
41
  return '?' + searchParams.toString();
40
42
  }
43
+ function isNotUndefined(arg) {
44
+ return arg[1] !== undefined;
45
+ }
@@ -3,9 +3,10 @@ export { getConfigValuesBase };
3
3
  export { isJsonValue };
4
4
  export type { FilesEnv };
5
5
  import type { ConfigEnvInternal, ConfigValueSource, DefinedAt, PageConfigBuildTime, PageConfigGlobalBuildTime } from '../../../types/PageConfig.js';
6
- declare function serializeConfigValues(pageConfig: PageConfigBuildTime | PageConfigGlobalBuildTime, importStatements: string[], filesEnv: FilesEnv, isEnvMatch: (configEnv: ConfigEnvInternal) => boolean, tabspace: string, isEager: boolean | null): string[];
6
+ import { type RuntimeEnv } from '../../../node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js';
7
+ declare function serializeConfigValues(pageConfig: PageConfigBuildTime | PageConfigGlobalBuildTime, importStatements: string[], filesEnv: FilesEnv, runtimeEnv: RuntimeEnv, tabspace: string, isEager: boolean | null): string[];
7
8
  declare function isJsonValue(value: unknown): boolean;
8
- declare function getConfigValuesBase(pageConfig: PageConfigBuildTime | PageConfigGlobalBuildTime, isEnvMatch: (configEnv: ConfigEnvInternal) => boolean, isEager: boolean | null): ConfigValuesBase;
9
+ declare function getConfigValuesBase(pageConfig: PageConfigBuildTime | PageConfigGlobalBuildTime, runtimeEnv: RuntimeEnv, isEager: boolean | null): ConfigValuesBase;
9
10
  type ConfigValuesBase = ({
10
11
  configValueBase: {
11
12
  type: 'computed';
@@ -7,7 +7,7 @@ import { parsePointerImportData } from '../../../node/vite/shared/resolveVikeCon
7
7
  import { getConfigValueFilePathToShowToUser } from '../helpers.js';
8
8
  import { stringify } from '@brillout/json-serializer/stringify';
9
9
  import pc from '@brillout/picocolors';
10
- import { isOverridden } from '../../../node/vite/shared/resolveVikeConfigInternal.js';
10
+ import { getConfigValueSourcesRelevant, isRuntimeEnvMatch, } from '../../../node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js';
11
11
  const stringifyOptions = { forbidReactElements: true };
12
12
  const REPLACE_ME_BEFORE = '__VIKE__REPLACE_ME_BEFORE__';
13
13
  const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
@@ -16,10 +16,10 @@ const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
16
16
  // - parsePageConfigs() is loaded on both the client- and server-side.
17
17
  assertIsNotBrowser();
18
18
  assertIsNotProductionRuntime();
19
- function serializeConfigValues(pageConfig, importStatements, filesEnv, isEnvMatch, tabspace, isEager) {
19
+ function serializeConfigValues(pageConfig, importStatements, filesEnv, runtimeEnv, tabspace, isEager) {
20
20
  const lines = [];
21
21
  tabspace += ' ';
22
- getConfigValuesBase(pageConfig, isEnvMatch, isEager).forEach((entry) => {
22
+ getConfigValuesBase(pageConfig, runtimeEnv, isEager).forEach((entry) => {
23
23
  if (entry.configValueBase.type === 'computed') {
24
24
  assert('value' in entry); // Help TS
25
25
  const { configValueBase, value, configName, configEnv } = entry;
@@ -176,12 +176,12 @@ function logJsonSerializeError(err, configName, definedAtData) {
176
176
  assert(configValueFilePathToShowToUser);
177
177
  assertUsage(false, `${pc.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined using a separate file ${pc.bold(`+${configName}.js`)}, see https://vike.dev/error/runtime-in-config`);
178
178
  }
179
- function getConfigValuesBase(pageConfig, isEnvMatch, isEager) {
179
+ function getConfigValuesBase(pageConfig, runtimeEnv, isEager) {
180
180
  const fromComputed = Object.entries(pageConfig.configValuesComputed ?? {}).map(([configName, valueInfo]) => {
181
181
  const { configEnv, value } = valueInfo;
182
- if (!isEnvMatch(configEnv))
182
+ if (!isRuntimeEnvMatch(configEnv, runtimeEnv))
183
183
  return 'SKIP';
184
- // Is there a use case for overriding computed values? If yes, then configValeSources has higher precedence
184
+ // AFAICT this should never happen: I ain't aware of a use case for overriding computed values. If there is a use case, then configValueSources has higher precedence.
185
185
  if (pageConfig.configValueSources[configName])
186
186
  return 'SKIP';
187
187
  const configValueBase = {
@@ -190,16 +190,17 @@ function getConfigValuesBase(pageConfig, isEnvMatch, isEager) {
190
190
  };
191
191
  return { configValueBase, value, configName, configEnv };
192
192
  });
193
- const fromSources = Object.entries(pageConfig.configValueSources).map(([configName, sources]) => {
193
+ const fromSources = Object.entries(pageConfig.configValueSources).map(([configName]) => {
194
194
  const configDef = pageConfig.configDefinitions[configName];
195
195
  assert(configDef);
196
196
  if (isEager !== null && isEager !== !!configDef.eager)
197
197
  return 'SKIP';
198
198
  if (!configDef.cumulative) {
199
- const source = sources[0];
200
- assert(source);
201
- if (!isEnvMatch(source.configEnv))
199
+ const sourcesRelevant = getConfigValueSourcesRelevant(configName, runtimeEnv, pageConfig);
200
+ const source = sourcesRelevant[0];
201
+ if (!source)
202
202
  return 'SKIP';
203
+ assert(sourcesRelevant.length === 1);
203
204
  const definedAtFile = getDefinedAtFileSource(source);
204
205
  const configValueBase = {
205
206
  type: 'standard',
@@ -208,9 +209,7 @@ function getConfigValuesBase(pageConfig, isEnvMatch, isEager) {
208
209
  return { configValueBase, sourceRelevant: source, configName };
209
210
  }
210
211
  else {
211
- const sourcesRelevant = sources
212
- .filter((source) => !isOverridden(source, configName, pageConfig))
213
- .filter((source) => isEnvMatch(source.configEnv));
212
+ const sourcesRelevant = getConfigValueSourcesRelevant(configName, runtimeEnv, pageConfig);
214
213
  if (sourcesRelevant.length === 0)
215
214
  return 'SKIP';
216
215
  const definedAtData = [];
@@ -25,3 +25,5 @@ export * from '../utils/objectDefineProperty.js';
25
25
  export * from '../utils/isScriptFile.js';
26
26
  export * from '../utils/objectFilter.js';
27
27
  export * from '../utils/getPropAccessNotation.js';
28
+ export * from '../utils/getGlobalObject.js';
29
+ export * from '../utils/genPromise.js';
@@ -29,3 +29,5 @@ export * from '../utils/objectDefineProperty.js';
29
29
  export * from '../utils/isScriptFile.js';
30
30
  export * from '../utils/objectFilter.js';
31
31
  export * from '../utils/getPropAccessNotation.js';
32
+ export * from '../utils/getGlobalObject.js';
33
+ export * from '../utils/genPromise.js';