vike 0.4.256-commit-85a5a9e → 0.4.257-commit-c6e29ea

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 (39) hide show
  1. package/dist/node/api/preview.js +14 -6
  2. package/dist/node/vite/plugins/pluginDev/optimizeDeps.js +3 -2
  3. package/dist/node/vite/plugins/pluginUniversalDeploy/common.d.ts +2 -1
  4. package/dist/node/vite/plugins/pluginUniversalDeploy/common.js +2 -1
  5. package/dist/node/vite/plugins/pluginUniversalDeploy/detectDeprecated.d.ts +2 -1
  6. package/dist/node/vite/plugins/pluginUniversalDeploy/detectDeprecated.js +12 -6
  7. package/dist/node/vite/plugins/pluginUniversalDeploy/getDeployConfig.d.ts +10 -0
  8. package/dist/node/vite/plugins/pluginUniversalDeploy/{getDeployConfigs.js → getDeployConfig.js} +8 -6
  9. package/dist/node/vite/plugins/pluginUniversalDeploy/getServerConfig.d.ts +11 -0
  10. package/dist/node/vite/plugins/pluginUniversalDeploy/{getServerInfo.js → getServerConfig.js} +13 -2
  11. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginResolvePlusServer.d.ts +2 -1
  12. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginResolvePlusServer.js +2 -1
  13. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginServerEntryAlias.d.ts +2 -1
  14. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginServerEntryAlias.js +28 -6
  15. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginServerEntryInject.d.ts +2 -1
  16. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginServerEntryInject.js +2 -1
  17. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginUnwrapProdOptions.d.ts +2 -1
  18. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginUnwrapProdOptions.js +4 -1
  19. package/dist/node/vite/plugins/pluginUniversalDeploy.js +15 -18
  20. package/dist/node/vite/plugins/pluginWorkaroundVite6HmrRegression.js +2 -1
  21. package/dist/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.d.ts +5 -1
  22. package/dist/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +1 -3
  23. package/dist/node/vite/shared/resolveVikeConfigInternal/pointerImports.d.ts +5 -2
  24. package/dist/node/vite/shared/resolveVikeConfigInternal/resolvePointerImport.js +9 -1
  25. package/dist/server/runtime/globalContext.js +11 -5
  26. package/dist/server/runtime/renderPageServer/createPageContextServer.d.ts +2 -2
  27. package/dist/server/runtime/renderPageServer.d.ts +4 -4
  28. package/dist/shared-server-client/page-configs/assertPlusFileExport.js +8 -4
  29. package/dist/types/Config.d.ts +19 -13
  30. package/dist/types/FilePath.d.ts +6 -6
  31. package/dist/types/PageContext.d.ts +11 -6
  32. package/dist/types/VikeNamespace.d.ts +7 -0
  33. package/dist/utils/PROJECT_VERSION.d.ts +1 -1
  34. package/dist/utils/PROJECT_VERSION.js +1 -1
  35. package/dist/utils/isCloudflareWorkers.d.ts +1 -0
  36. package/dist/utils/isCloudflareWorkers.js +4 -0
  37. package/package.json +3 -3
  38. package/dist/node/vite/plugins/pluginUniversalDeploy/getDeployConfigs.d.ts +0 -27
  39. package/dist/node/vite/plugins/pluginUniversalDeploy/getServerInfo.d.ts +0 -7
@@ -9,6 +9,7 @@ import { isCallable } from '../../utils/isCallable.js';
9
9
  import pc from '@brillout/picocolors';
10
10
  import path from 'node:path';
11
11
  import { getVikeConfigInternal } from '../vite/shared/resolveVikeConfigInternal.js';
12
+ import { isUniversalDeployVitePreview } from '../vite/plugins/pluginUniversalDeploy/getServerConfig.js';
12
13
  import './assertEnvApiDev.js';
13
14
  /**
14
15
  * Programmatically trigger `$ vike preview`
@@ -18,14 +19,22 @@ import './assertEnvApiDev.js';
18
19
  async function preview(options = {}) {
19
20
  onSetupPreview();
20
21
  const { viteConfigFromUserResolved, viteConfigResolved } = await prepareViteApiCall(options, 'preview');
21
- const cliPreview = await resolveCliPreviewConfig();
22
- assertUsage(cliPreview !== false, `${pc.cyan('$ vike preview')} isn't supported`);
23
- const useVite = cliPreview === 'vite' || (cliPreview === undefined && !viteConfigResolved.vitePluginServerEntry?.inject);
24
- if (!useVite) {
22
+ const vikeConfig = await getVikeConfigInternal();
23
+ const cliPreviewConfig = await resolveCliPreviewConfig(vikeConfig);
24
+ assertUsage(cliPreviewConfig !== false, `${pc.cyan('$ vike preview')} isn't supported`);
25
+ const isUDVitePreview = isUniversalDeployVitePreview(vikeConfig, viteConfigResolved);
26
+ const useVitePreviewServer = cliPreviewConfig === 'vite' ||
27
+ (cliPreviewConfig === undefined &&
28
+ // dist/server/index.mjs exists when using @brillout/vite-plugin-server-entry inject mode; otherwise it's missing -> we must use Vite's preview server
29
+ (!viteConfigResolved.vitePluginServerEntry?.inject ||
30
+ // dist/server/index.mjs doesn't exist with some deployment plugins such as vite-plugin-vercel -> we must use Vite's preview server
31
+ isUDVitePreview));
32
+ if (!useVitePreviewServer) {
25
33
  // Dynamically import() server production entry dist/server/index.js
26
34
  const outDir = getOutDirs(viteConfigResolved, undefined).outDirRoot;
27
35
  const { outServerIndex } = await importServerProductionIndex({ outDir });
28
36
  const outServerIndexRelative = path.relative(viteConfigResolved.root, outServerIndex);
37
+ // TODO/after-PR-merge: always show a warning
29
38
  assertWarning(false, `Never run ${pc.cyan('$ vike preview')} in production, run ${pc.cyan(`$ node ${outServerIndexRelative}`)} instead (or Bun/Deno).`, { onlyOnce: true });
30
39
  return {
31
40
  viteConfig: viteConfigResolved,
@@ -40,8 +49,7 @@ async function preview(options = {}) {
40
49
  };
41
50
  }
42
51
  }
43
- async function resolveCliPreviewConfig() {
44
- const vikeConfig = await getVikeConfigInternal();
52
+ async function resolveCliPreviewConfig(vikeConfig) {
45
53
  const val = vikeConfig.config.cli?.preview;
46
54
  if (!isCallable(val)) {
47
55
  return val;
@@ -55,8 +55,9 @@ const optimizeDeps = {
55
55
  exclude: [
56
56
  '@brillout/import',
57
57
  '@brillout/json-serializer',
58
- // FIXME Breaks @cloudflare/vite-plugin. Remove me if CI passes
59
- // '@brillout/picocolors',
58
+ /* Adding @brillout/picocolors breaks the UD + Cloudflare test, we don't know why. TO-DO/eventually: re-add it and see if Vike's CI is green.
59
+ '@brillout/picocolors',
60
+ */
60
61
  '@brillout/vite-plugin-server-entry',
61
62
  'vike',
62
63
  ],
@@ -1,6 +1,7 @@
1
+ export { pluginCommon };
1
2
  import type { Plugin } from 'vite';
2
3
  import '../../assertEnvVite.js';
3
- export declare const pluginCommon: {
4
+ declare const pluginCommon: {
4
5
  applyToEnvironment(env: {
5
6
  name: string;
6
7
  getTopLevelConfig(): import("vite").ResolvedConfig;
@@ -1,5 +1,6 @@
1
+ export { pluginCommon };
1
2
  import '../../assertEnvVite.js';
2
- export const pluginCommon = {
3
+ const pluginCommon = {
3
4
  applyToEnvironment(env) {
4
5
  return env.config.consumer === 'server';
5
6
  },
@@ -1,3 +1,4 @@
1
+ export { hasVikeServerOrVikePhoton };
1
2
  import type { VikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
2
3
  import '../../assertEnvVite.js';
3
- export declare function hasVikeServerOrVikePhoton(vikeConfig: VikeConfigInternal): true | undefined;
4
+ declare function hasVikeServerOrVikePhoton(vikeConfig: VikeConfigInternal): true | undefined;
@@ -1,15 +1,21 @@
1
- import { assertWarning } from '../../../../utils/assert.js';
1
+ export { hasVikeServerOrVikePhoton };
2
+ import { assert, assertWarning } from '../../../../utils/assert.js';
2
3
  import pc from '@brillout/picocolors';
3
4
  import '../../assertEnvVite.js';
4
- export function hasVikeServerOrVikePhoton(vikeConfig) {
5
- const vikeExtendsNames = new Set(vikeConfig._extensions.map((plusFile) => ('fileExportsByConfigName' in plusFile ? plusFile.fileExportsByConfigName : {}).name));
6
- const vikeServerOrVikePhoton = vikeExtendsNames.has('vike-server')
5
+ function hasVikeServerOrVikePhoton(vikeConfig) {
6
+ const vikeExtensionNames = vikeConfig._extensions.map((plusFile) => {
7
+ assert(plusFile.isConfigFile);
8
+ const { name } = plusFile.fileExportsByConfigName;
9
+ assert(typeof name === 'string');
10
+ return name;
11
+ });
12
+ const vikeServerOrVikePhoton = vikeExtensionNames.includes('vike-server')
7
13
  ? 'vike-server'
8
- : vikeExtendsNames.has('vike-photon')
14
+ : vikeExtensionNames.includes('vike-photon')
9
15
  ? 'vike-photon'
10
16
  : null;
11
17
  if (vikeServerOrVikePhoton) {
12
- assertWarning(false, `${pc.cyan(vikeServerOrVikePhoton)} is deprecated, see ${pc.underline('https://vike.dev/migration/universal-deploy')}`, { onlyOnce: true });
18
+ assertWarning(false, `${pc.cyan(vikeServerOrVikePhoton)} is deprecated, see ${pc.underline('https://vike.dev/migration/server')}`, { onlyOnce: true });
13
19
  return true;
14
20
  }
15
21
  }
@@ -0,0 +1,10 @@
1
+ export { getDeployConfig };
2
+ import { fromVike } from 'convert-route/vike';
3
+ import type { PageConfigPublicWithRoute } from '../../../../shared-server-client/page-configs/resolveVikeConfigPublic.js';
4
+ import '../../assertEnvVite.js';
5
+ import type { Vercel } from '../../../../types/Config.js';
6
+ type RouteIr = ReturnType<typeof fromVike>;
7
+ declare function getDeployConfig(pageId: string, page: PageConfigPublicWithRoute): null | {
8
+ route: RouteIr[];
9
+ vercel: Vercel;
10
+ };
@@ -1,9 +1,11 @@
1
- export { getDeployConfigs };
1
+ export { getDeployConfig };
2
+ import { fromVike } from 'convert-route/vike';
2
3
  import { assert, assertUsage, assertWarning } from '../../../../utils/assert.js';
3
4
  import { isObject } from '../../../../utils/isObject.js';
4
5
  import '../../assertEnvVite.js';
5
6
  import { isCallable } from '../../../../utils/isCallable.js';
6
- function getDeployConfigs(pageId, page) {
7
+ import { pageContextJsonFileExtension } from '../../../../shared-server-client/getPageContextRequestUrl.js';
8
+ function getDeployConfig(pageId, page) {
7
9
  const { route } = page;
8
10
  if (!route)
9
11
  return null;
@@ -32,14 +34,14 @@ function getDeployConfigs(pageId, page) {
32
34
  assertWarning(!edge, errMsg('+edge'), { onlyOnce: true });
33
35
  return null;
34
36
  }
37
+ const routeIr = fromVike(route);
35
38
  return {
36
- route,
37
- // route: [...new Set([...toRou3(routeIr), ...getRoutePageContextJson(routeIr)])],
39
+ route: [routeIr, getRouteIrPageContextJson(routeIr)].filter((r) => r !== undefined),
38
40
  // Supported by vite-plugin-vercel@11
39
41
  vercel: { isr, edge },
40
42
  };
41
43
  }
42
- export function getRoutePageContextJson(routeIr) {
44
+ function getRouteIrPageContextJson(routeIr) {
43
45
  const lastSegment = routeIr.pathname.at(-1);
44
46
  assert(lastSegment);
45
47
  if (lastSegment.catchAll)
@@ -49,7 +51,7 @@ export function getRoutePageContextJson(routeIr) {
49
51
  ...routeIr.pathname.slice(0, -1),
50
52
  {
51
53
  ...lastSegment,
52
- value: `${lastSegment.value}.pageContext.json`,
54
+ value: lastSegment.value + pageContextJsonFileExtension,
53
55
  },
54
56
  ],
55
57
  };
@@ -0,0 +1,11 @@
1
+ export { getServerConfig };
2
+ export { isUniversalDeployVitePreview };
3
+ import type { ResolvedConfig } from 'vite';
4
+ import type { VikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
5
+ import '../../assertEnvVite.js';
6
+ declare function getServerConfig(vikeConfig: VikeConfigInternal): {
7
+ serverEntryId: string;
8
+ serverEntryVike: string;
9
+ serverFilePath: string | null;
10
+ } | undefined;
11
+ declare function isUniversalDeployVitePreview(vikeConfig: VikeConfigInternal, viteConfigResolved: ResolvedConfig): boolean;
@@ -1,7 +1,9 @@
1
- import { assert } from '../../../../utils/assert.js';
1
+ export { getServerConfig };
2
+ export { isUniversalDeployVitePreview };
2
3
  import { catchAllEntry } from '@universal-deploy/store';
4
+ import { assert } from '../../../../utils/assert.js';
3
5
  import '../../assertEnvVite.js';
4
- export function getServerInfo(vikeConfig) {
6
+ function getServerConfig(vikeConfig) {
5
7
  let serverEntryId;
6
8
  let serverFilePath = null;
7
9
  let serverEntryVike;
@@ -36,3 +38,12 @@ export function getServerInfo(vikeConfig) {
36
38
  serverFilePath,
37
39
  };
38
40
  }
41
+ function isUniversalDeployVitePreview(vikeConfig, viteConfigResolved) {
42
+ const isServerConfig = getServerConfig(vikeConfig);
43
+ if (!isServerConfig)
44
+ return false;
45
+ // @universal-deploy/node -> real preview
46
+ // else -> vite preview
47
+ const udNodePlugin = viteConfigResolved.plugins.find((p) => p.name.startsWith('ud:node:emit'));
48
+ return !udNodePlugin;
49
+ }
@@ -1,6 +1,7 @@
1
+ export { pluginResolvePlusServer };
1
2
  import type { Plugin } from 'vite';
2
3
  import '../../assertEnvVite.js';
3
4
  /**
4
5
  * If +server.js is defined, make virtual:ud:catch-all resolve to +server.js absolute path
5
6
  */
6
- export declare function pluginServerEntryInject(serverFilePath: string): Plugin;
7
+ declare function pluginResolvePlusServer(serverFilePath: string): Plugin;
@@ -1,10 +1,11 @@
1
+ export { pluginResolvePlusServer };
1
2
  import { pluginCommon } from './common.js';
2
3
  import { escapeRegex } from '../../../../utils/escapeRegex.js';
3
4
  import '../../assertEnvVite.js';
4
5
  /**
5
6
  * If +server.js is defined, make virtual:ud:catch-all resolve to +server.js absolute path
6
7
  */
7
- export function pluginServerEntryInject(serverFilePath) {
8
+ function pluginResolvePlusServer(serverFilePath) {
8
9
  return {
9
10
  name: 'vike:pluginUniversalDeploy:server',
10
11
  resolveId: {
@@ -1,4 +1,5 @@
1
1
  export { pluginServerEntryAlias };
2
2
  import type { Plugin } from 'vite';
3
3
  import '../../assertEnvVite.js';
4
- declare function pluginServerEntryAlias(): Plugin;
4
+ /** Alias for virtual:ud:catch if no userland server entry */
5
+ declare function pluginServerEntryAlias(serverFilePath?: string | null): Plugin;
@@ -1,18 +1,40 @@
1
1
  export { pluginServerEntryAlias };
2
+ import { catchAllEntry } from '@universal-deploy/store';
2
3
  import { pluginCommon } from './common.js';
3
4
  import { escapeRegex } from '../../../../utils/escapeRegex.js';
4
- import { catchAllEntry } from '@universal-deploy/store';
5
+ import { assert } from '../../../../utils/assert.js';
5
6
  import '../../assertEnvVite.js';
6
- function pluginServerEntryAlias() {
7
+ const serverEntryAlias = 'vike:server-entry';
8
+ const virtualFileId = '\0' + serverEntryAlias;
9
+ // === Rolldown filter
10
+ const filterRolldown = {
11
+ id: {
12
+ include: [new RegExp(escapeRegex(serverEntryAlias)), new RegExp(escapeRegex(virtualFileId))],
13
+ },
14
+ };
15
+ // ===
16
+ /** Alias for virtual:ud:catch if no userland server entry */
17
+ function pluginServerEntryAlias(serverFilePath) {
7
18
  return {
8
19
  name: 'vike:pluginUniversalDeploy:alias',
9
20
  resolveId: {
10
- filter: {
11
- // User facing alias for virtual:ud:catch-all
12
- id: new RegExp(escapeRegex('vike:server-entry')),
21
+ filter: filterRolldown,
22
+ handler() {
23
+ if (!serverFilePath)
24
+ return catchAllEntry;
25
+ return virtualFileId;
13
26
  },
27
+ },
28
+ load: {
29
+ filter: filterRolldown,
14
30
  handler() {
15
- return this.resolve(catchAllEntry);
31
+ assert(serverFilePath);
32
+ // Also re-export non-default exports, to support Durable Objects
33
+ return `import mod from ${JSON.stringify(catchAllEntry)};
34
+
35
+ export * from ${JSON.stringify(serverFilePath)};
36
+ export default mod;
37
+ `;
16
38
  },
17
39
  },
18
40
  ...pluginCommon,
@@ -1,3 +1,4 @@
1
+ export { pluginServerEntryInject };
1
2
  import type { Plugin } from 'vite';
2
3
  import '../../assertEnvVite.js';
3
- export declare function pluginServerEntryInject(serverEntryId: string): Plugin;
4
+ declare function pluginServerEntryInject(serverEntryId: string): Plugin;
@@ -1,9 +1,10 @@
1
+ export { pluginServerEntryInject };
1
2
  import { getMagicString } from '../../shared/getMagicString.js';
2
3
  import { serverEntryVirtualId } from '@brillout/vite-plugin-server-entry/plugin';
3
4
  import { pluginCommon } from './common.js';
4
5
  import '../../assertEnvVite.js';
5
6
  import { escapeRegex } from '../../../../utils/escapeRegex.js';
6
- export function pluginServerEntryInject(serverEntryId) {
7
+ function pluginServerEntryInject(serverEntryId) {
7
8
  return {
8
9
  name: 'vike:pluginUniversalDeploy:serverEntry',
9
10
  apply: 'build',
@@ -1,3 +1,4 @@
1
+ export { pluginUnwrapProdOptions };
1
2
  import type { Plugin } from 'vite';
2
3
  import '../../assertEnvVite.js';
3
- export declare function pluginUnwrapProdOptions(serverFilePath: string): Plugin;
4
+ declare function pluginUnwrapProdOptions(serverFilePath: string): Plugin;
@@ -1,7 +1,8 @@
1
+ export { pluginUnwrapProdOptions };
1
2
  import { wrapper } from 'vite-plugin-wrapper';
2
3
  import { escapeRegex } from '../../../../utils/escapeRegex.js';
3
4
  import '../../assertEnvVite.js';
4
- export function pluginUnwrapProdOptions(serverFilePath) {
5
+ function pluginUnwrapProdOptions(serverFilePath) {
5
6
  return wrapper({
6
7
  resolveId: {
7
8
  filter: {
@@ -12,6 +13,8 @@ export function pluginUnwrapProdOptions(serverFilePath) {
12
13
  load(id) {
13
14
  return `
14
15
  import mod from ${JSON.stringify(id)};
16
+
17
+ export * from ${JSON.stringify(id)};
15
18
  export default { ...mod, ...mod?.prod };
16
19
  `;
17
20
  },
@@ -2,12 +2,11 @@ export { pluginUniversalDeploy };
2
2
  import { toRou3 } from 'convert-route';
3
3
  import { addEntry } from '@universal-deploy/store';
4
4
  import universalDeploy, { resolveTargets } from '@universal-deploy/vite';
5
- import { fromVike } from 'convert-route/vike';
6
5
  import { pluginServerEntryInject } from './pluginUniversalDeploy/pluginServerEntryInject.js';
7
- import { getDeployConfigs, getRoutePageContextJson } from './pluginUniversalDeploy/getDeployConfigs.js';
6
+ import { getDeployConfig } from './pluginUniversalDeploy/getDeployConfig.js';
8
7
  import { pluginCommon } from './pluginUniversalDeploy/common.js';
9
8
  import { hasVikeServerOrVikePhoton } from './pluginUniversalDeploy/detectDeprecated.js';
10
- import { getServerInfo } from './pluginUniversalDeploy/getServerInfo.js';
9
+ import { getServerConfig } from './pluginUniversalDeploy/getServerConfig.js';
11
10
  import { pluginServerEntryAlias } from './pluginUniversalDeploy/pluginServerEntryAlias.js';
12
11
  import { pluginUnwrapProdOptions } from './pluginUniversalDeploy/pluginUnwrapProdOptions.js';
13
12
  import { unique } from '../../../utils/unique.js';
@@ -16,16 +15,16 @@ import '../assertEnvVite.js';
16
15
  function pluginUniversalDeploy(vikeConfig) {
17
16
  if (hasVikeServerOrVikePhoton(vikeConfig))
18
17
  return [];
19
- const serverInfo = getServerInfo(vikeConfig);
20
- if (!serverInfo)
18
+ const serverConfig = getServerConfig(vikeConfig);
19
+ if (!serverConfig)
21
20
  return [
22
- resolveTargets(({ vercel, node, netlify }) => {
21
+ resolveTargets((targets) => {
23
22
  // Cloudflare is supported even without universal-deploy
24
- const target = vercel ? 'Vercel' : node ? 'Node.js' : netlify ? 'Netlify' : null;
25
- assertUsage(target === null, `Cannot target ${target} without a server entry. Either set \`server: true\` in +config.js or create a \`+server.js\` file.`);
23
+ const target = targets.filter((t) => t !== '@cloudflare/vite-plugin')[0];
24
+ assertUsage(target === undefined, `${target} requires +server see https://vike.dev/server`);
26
25
  }),
27
26
  ];
28
- const { serverEntryVike, serverEntryId, serverFilePath } = serverInfo;
27
+ const { serverEntryVike, serverEntryId, serverFilePath } = serverConfig;
29
28
  return [
30
29
  ...universalDeploy(),
31
30
  {
@@ -33,17 +32,15 @@ function pluginUniversalDeploy(vikeConfig) {
33
32
  config() {
34
33
  // Map each Vike route to universal-deploy
35
34
  for (const [pageId, page] of Object.entries(vikeConfig.pages)) {
36
- const deployConfigs = getDeployConfigs(pageId, page);
37
- // Skip pages without deploy configs, as they will be handled by the catch-all route
38
- if (deployConfigs !== null) {
39
- const { route, ...additionalConfigs } = deployConfigs;
40
- const routeIr = fromVike(route);
41
- const routeIrPageContextJson = getRoutePageContextJson(routeIr);
35
+ const deployConfig = getDeployConfig(pageId, page);
36
+ // Skip pages without a deploy configuration, as they will be handled by the catch-all route
37
+ if (deployConfig) {
38
+ const { route, ...config } = deployConfig;
42
39
  addEntry({
43
- ...additionalConfigs,
40
+ ...config,
44
41
  id: serverEntryVike,
45
42
  // Map Vike routes to rou3 format
46
- route: unique([...toRou3(routeIr), ...(routeIrPageContextJson ? toRou3(routeIrPageContextJson) : [])]),
43
+ route: unique(route.map(toRou3).flat()),
47
44
  });
48
45
  }
49
46
  }
@@ -56,7 +53,7 @@ function pluginUniversalDeploy(vikeConfig) {
56
53
  ...pluginCommon,
57
54
  },
58
55
  pluginServerEntryInject(serverFilePath ?? serverEntryId),
59
- pluginServerEntryAlias(),
56
+ pluginServerEntryAlias(serverFilePath),
60
57
  !serverFilePath ? null : pluginUnwrapProdOptions(serverFilePath),
61
58
  ].filter((p) => p !== null);
62
59
  }
@@ -11,7 +11,8 @@ function pluginWorkaroundVite6HmrRegression() {
11
11
  enforce: 'post',
12
12
  hotUpdate: {
13
13
  order: 'post',
14
- handler({ modules, server, timestamp }) {
14
+ async handler(ctx) {
15
+ const { modules, server, timestamp } = ctx;
15
16
  if (this.environment.name !== 'ssr')
16
17
  return;
17
18
  let hasSsrOnlyModules = false;
@@ -34,7 +34,11 @@ type ConfigDefinition_ = {
34
34
  */
35
35
  effect?: ConfigEffect;
36
36
  /**
37
- * Always load the configuration value, and as soon as possible.
37
+ * Load the configuration of *all* pages (regardless of what page is being rendered).
38
+ *
39
+ * WARNING: this might bloat server- and client-side KBs.
40
+ *
41
+ * By default, to save server- and client-side KBs, the configuration of a page is only loaded when rendering that page.
38
42
  *
39
43
  * @default false
40
44
  *
@@ -310,10 +310,8 @@ const configDefinitionsBuiltIn = {
310
310
  env: { config: true },
311
311
  global: true,
312
312
  },
313
- // -- Vercel --
314
313
  vercel: {
315
- env: { server: true, config: true },
316
- eager: true,
314
+ env: { config: true },
317
315
  },
318
316
  };
319
317
  function getConfigEnv(pageConfig, configName) {
@@ -17,10 +17,13 @@ declare function transformPointerImports(code: string, filePathToShowToUser2: st
17
17
  * We discard the import name `someImport` because we don't need it.
18
18
  */
19
19
  type PointerImportData = {
20
+ importStringWasGenerated: boolean;
21
+ /** For example: `import:./some-file:someExport` */
22
+ importString: string;
23
+ /** For example: `./some-file` */
20
24
  importPath: string;
25
+ /** For example: `someExport` */
21
26
  exportName: string;
22
- importString: string;
23
- importStringWasGenerated: boolean;
24
27
  };
25
28
  declare function parsePointerImportData(importString: string): null | PointerImportData;
26
29
  declare function assertPointerImportPath(importPath: string): boolean;
@@ -78,7 +78,15 @@ function resolveImportPathWithNode(pointerImportData, importerFilePath, userRoot
78
78
  userRootDir,
79
79
  });
80
80
  if (!filePathAbsoluteFilesystem) {
81
- assert(!isImportPathRelative(pointerImportData.importPath));
81
+ if (isImportPathRelative(pointerImportData.importPath)) {
82
+ const { importPath, importStringWasGenerated, importString } = pointerImportData;
83
+ const { filePathToShowToUserResolved } = importerFilePath;
84
+ assert(filePathToShowToUserResolved);
85
+ const errIntro = importStringWasGenerated
86
+ ? `The import path ${pc.cyan(importPath)} in ${filePathToShowToUserResolved}`
87
+ : `The import ${pc.cyan(importString)} defined by ${filePathToShowToUserResolved}`;
88
+ assertUsage(false, `${errIntro} couldn't be resolved: does ${pc.cyan(importPath)} point to an existing file?`);
89
+ }
82
90
  /* This assertion fails if the npm package has a wrongly defined package.json#exports
83
91
  // Libraries don't use path aliases => filePathAbsoluteFilesystem should be defined
84
92
  assert(!importerFilePathAbsolute.includes('node_modules'))
@@ -43,6 +43,7 @@ import { getGlobalObject } from '../../utils/getGlobalObject.js';
43
43
  import { hasProp } from '../../utils/hasProp.js';
44
44
  import { isObject } from '../../utils/isObject.js';
45
45
  import { objectAssign } from '../../utils/objectAssign.js';
46
+ import { isCloudflareWorkers } from '../../utils/isCloudflareWorkers.js';
46
47
  import { importServerProductionEntry } from '@brillout/vite-plugin-server-entry/runtime';
47
48
  import { virtualFileIdGlobalEntryServer } from '../../shared-server-node/virtualFileId.js';
48
49
  import pc from '@brillout/picocolors';
@@ -229,7 +230,7 @@ async function initGlobalContext() {
229
230
  await globalObject.waitForUserFilesUpdate;
230
231
  }
231
232
  else {
232
- await loadProdBuildEntry(globalObject.viteConfigRuntime?.build.outDir);
233
+ await loadProdBuildEntry(false, globalObject.viteConfigRuntime?.build.outDir);
233
234
  }
234
235
  assertGlobalContextIsDefined();
235
236
  globalObject.isInitialized = true;
@@ -247,7 +248,9 @@ function assertViteManifest(manifest) {
247
248
  })
248
249
  */
249
250
  }
250
- async function loadProdBuildEntry(outDir) {
251
+ async function loadProdBuildEntry(
252
+ // Whether loadProdBuildEntry() is called at module initialization (when JavaScript modules are loaded), e.g. it's `false` when loadProdBuildEntry() was triggered by renderPage()
253
+ isModuleInit, outDir) {
251
254
  debug('loadProdBuildEntry()');
252
255
  if (globalObject.globalContext) {
253
256
  debug('loadProdBuildEntry() - already done');
@@ -274,7 +277,11 @@ async function loadProdBuildEntry(outDir) {
274
277
  assertProdBuildEntry(prodBuildEntry);
275
278
  globalObject.assetsManifest = prodBuildEntry.assetsManifest;
276
279
  globalObject.buildInfo = prodBuildEntry.buildInfo;
277
- await createGlobalContext(prodBuildEntry.virtualFileExportsGlobalEntry);
280
+ // Don't call +onCreateGlobalContext() during module initialization in Cloudflare Workers, to avoid the error "Disallowed operation called within global scope", see https://github.com/vikejs/vike/pull/3106#issuecomment-4209583465
281
+ const skipGlobalContextInit = isCloudflareWorkers() && isModuleInit;
282
+ if (!skipGlobalContextInit) {
283
+ await createGlobalContext(prodBuildEntry.virtualFileExportsGlobalEntry);
284
+ }
278
285
  }
279
286
  // This is the production entry, see:
280
287
  // https://github.com/vikejs/vike/blob/8c350e8105a626469e87594d983090919e82099b/packages/vike/node/vite/plugins/pluginBuild/pluginProdBuildEntry.ts#L47
@@ -286,8 +293,7 @@ async function setGlobalContext_prodBuildEntry(prodBuildEntry) {
286
293
  globalObject.prodBuildEntry = prodBuildEntry;
287
294
  globalObject.prodBuildEntryPrevious = prodBuildEntry;
288
295
  assert(globalObject.prodBuildEntry); // ensure no infinite loop
289
- await loadProdBuildEntry();
290
- assertGlobalContextIsDefined();
296
+ await loadProdBuildEntry(true);
291
297
  debug('setGlobalContext_prodBuildEntry() - done');
292
298
  }
293
299
  function assertProdBuildEntry(prodBuildEntry) {
@@ -3,10 +3,10 @@ export { createPageContextServerWithoutGlobalContext };
3
3
  export type { PageContextCreatedServer };
4
4
  export type { PageContextCreatedServerWithoutGlobalContext };
5
5
  import type { GlobalContextServerInternal } from '../globalContext.js';
6
- import type { PageContextInit, PageContextInternalInit } from '../renderPageServer.js';
6
+ import type { PageContextInit, PageContextInitInternal } from '../renderPageServer.js';
7
7
  import '../../assertEnvServer.js';
8
8
  type PageContextCreatedServer = Awaited<ReturnType<typeof createPageContextServer>>;
9
- declare function createPageContextServer(pageContextInit: PageContextInternalInit & {
9
+ declare function createPageContextServer(pageContextInit: PageContextInitInternal & {
10
10
  headers?: Record<string, unknown>;
11
11
  }, globalContext: GlobalContextServerInternal, args: {
12
12
  requestId: number;
@@ -1,21 +1,21 @@
1
1
  export { renderPageServer };
2
2
  export { getRequestTag };
3
3
  export type { PageContextInit };
4
- export type { PageContextInternalInit };
4
+ export type { PageContextInitInternal };
5
5
  export type { PageContextBegin };
6
6
  export type { RequestTag };
7
7
  import { type PageContextAborted } from '../../shared-server-client/route/abort.js';
8
8
  import { type GlobalContextServerInternal } from './globalContext.js';
9
9
  import { type HttpResponse } from './renderPageServer/createHttpResponse.js';
10
10
  import type { PageContextServer } from '../../types/index.js';
11
- import type { PageContextInit, PageContextInternalInit } from '../../types/PageContext.js';
11
+ import type { PageContextInit, PageContextInitInternal } from '../../types/PageContext.js';
12
12
  import { type AsyncStore } from './asyncHook.js';
13
13
  import '../assertEnvServer.js';
14
14
  type PageContextBegin = ReturnType<typeof getPageContextBegin>;
15
- declare function renderPageServer<PageContextUserAdded extends {}, PageContextInitUser extends PageContextInternalInit>(pageContextInit: PageContextInitUser): Promise<PageContextInitUser & {
15
+ declare function renderPageServer<PageContextUserAdded extends {}, PageContextInitUser extends PageContextInitInternal>(pageContextInit: PageContextInitUser): Promise<PageContextInitUser & {
16
16
  httpResponse: HttpResponse;
17
17
  } & Partial<PageContextServer & PageContextUserAdded>>;
18
- declare function getPageContextBegin(pageContextInit: PageContextInternalInit, globalContext: GlobalContextServerInternal, requestId: number, asyncStore: AsyncStore): {
18
+ declare function getPageContextBegin(pageContextInit: PageContextInitInternal, globalContext: GlobalContextServerInternal, requestId: number, asyncStore: AsyncStore): {
19
19
  _isOriginalObject: true;
20
20
  isPageContext: true;
21
21
  } & {
@@ -8,7 +8,9 @@ const SIDE_EXPORTS_TOLERATE = [
8
8
  '_rerender_only',
9
9
  ];
10
10
  // Tolerate `export { frontmatter }` in .mdx files
11
+ // Tolerate any exports from `+server.ts` for Cloudflare Durable Object
11
12
  const SIDE_EXPORTS_DO_NOT_CHECK = ['.md', '.mdx'];
13
+ const SIDE_EXPORTS_DO_NOT_CHECK_CONFIG = ['server'];
12
14
  function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
13
15
  const exportNames = Object.keys(fileExports);
14
16
  const isValid = (exportName) => exportName === 'default' || exportName === configName;
@@ -24,10 +26,12 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
24
26
  }
25
27
  assert(exportNamesValid.length === 1);
26
28
  // Warn upon side exports
27
- const exportNamesInvalid = exportNames
28
- .filter((e) => !isValid(e))
29
- .filter((exportName) => !SIDE_EXPORTS_TOLERATE.includes(exportName));
30
- if (!SIDE_EXPORTS_DO_NOT_CHECK.some((ext) => filePathToShowToUser.endsWith(ext))) {
29
+ const skip = SIDE_EXPORTS_DO_NOT_CHECK_CONFIG.includes(configName) ||
30
+ SIDE_EXPORTS_DO_NOT_CHECK.some((ext) => filePathToShowToUser.endsWith(ext));
31
+ if (!skip) {
32
+ const exportNamesInvalid = exportNames
33
+ .filter((e) => !isValid(e))
34
+ .filter((exportName) => !SIDE_EXPORTS_TOLERATE.includes(exportName));
31
35
  exportNamesInvalid.forEach((exportInvalid) => {
32
36
  assertWarning(false, `${filePathToShowToUser} unexpected ${pc.cyan(`export { ${exportInvalid} }`)}, see https://vike.dev/no-side-exports`, {
33
37
  onlyOnce: true,
@@ -10,6 +10,7 @@ export type { HookNamePage };
10
10
  export type { HookNameGlobal };
11
11
  export type { Route };
12
12
  export type { KeepScrollPosition };
13
+ export type { Vercel };
13
14
  export type { DataAsync };
14
15
  export type { DataSync };
15
16
  export type { GuardAsync };
@@ -557,21 +558,26 @@ type ConfigBuiltIn = {
557
558
  license?: string;
558
559
  /**
559
560
  * Vercel options
561
+ *
562
+ * https://vike.dev/vercel
560
563
  */
561
- vercel?: {
562
- /** Incremental Static Regeneration (ISR).
563
- *
564
- * https://vike.dev/vercel#isr
565
- */
566
- isr?: {
567
- expiration: number;
568
- };
569
- /** Deploy on Vercel Edge.
570
- *
571
- * https://vike.dev/vercel
572
- */
573
- edge?: boolean;
564
+ vercel?: Vercel;
565
+ };
566
+ type Vercel = {
567
+ /**
568
+ * Incremental Static Regeneration (ISR).
569
+ *
570
+ * https://vike.dev/vercel#isr
571
+ */
572
+ isr?: {
573
+ expiration: number;
574
574
  };
575
+ /**
576
+ * Deploy on Vercel Edge.
577
+ *
578
+ * https://vike.dev/vercel#edge
579
+ */
580
+ edge?: boolean;
575
581
  };
576
582
  type PrerenderSetting = boolean | {
577
583
  /**
@@ -15,11 +15,11 @@ type FilePathResolved = FilePathCommon & {
15
15
  */
16
16
  filePathAbsoluteFilesystem: string;
17
17
  /**
18
- * The file's path, shown to the user in logs.
18
+ * The file path shown to the user in logs.
19
19
  *
20
- * Resolved: it always shows a file path. (It never shows an import path such as `vike-react/config`.)
20
+ * Its value is: `filePath.filePathAbsoluteUserRootDir ?? filePath.filePathAbsoluteFilesystem`.
21
21
  *
22
- * Its value is equivalent to `filePath.filePathAbsoluteUserRootDir ?? filePath.filePathAbsoluteFilesystem`.
22
+ * Note that it always shows a file path. (It never shows an import path such as `vike-react/config`.)
23
23
  */
24
24
  filePathToShowToUserResolved: string;
25
25
  /**
@@ -52,11 +52,11 @@ type FilePathAbsoluteUserRootDir = {
52
52
  };
53
53
  type FilePathCommon = {
54
54
  /**
55
- * The file's path, shown to the user in logs.
55
+ * The file or import path shown to the user in logs.
56
56
  *
57
- * Unresolved: it may show an import path instead of a file path such as `vike-react/config`.
57
+ * Its value is: `filePath.filePathAbsoluteUserRootDir ?? filePath.importPathAbsolute`.
58
58
  *
59
- * Its value is equivalent to `filePath.filePathAbsoluteUserRootDir ?? filePath.importPathAbsolute`.
59
+ * Note that if `filePath.filePathAbsoluteUserRootDir` isn't defined then it shows the import path (e.g. `vike-react/config`) instead of a file path.
60
60
  */
61
61
  filePathToShowToUser: string;
62
62
  /**
@@ -8,11 +8,12 @@ export type { PageContextInternalServer };
8
8
  export type { PageContextInternalClient };
9
9
  export type { PageContextInternalClient_ServerRouting };
10
10
  export type { PageContextInternalClient_ClientRouting };
11
- export type { PageContextInternalInit };
11
+ export type { PageContextInitInternal };
12
12
  export type { PageContextInit };
13
13
  export type { PageContextBuiltInServer_deprecated as PageContextBuiltInServer };
14
14
  export type { PageContextBuiltInClientWithClientRouting_deprecated as PageContextBuiltInClientWithClientRouting };
15
15
  export type { PageContextBuiltInClientWithServerRouting_deprecated as PageContextBuiltInClientWithServerRouting };
16
+ import type { RuntimeAdapterTarget } from '@universal-middleware/core';
16
17
  import type { PageContextUrlInternal, PageContextUrlClient, PageContextUrlServer } from '../shared-server-client/getPageContextUrlComputed.js';
17
18
  import type { From, PageContextConfig, Source, Sources } from '../shared-server-client/page-configs/resolveVikeConfigPublic.js';
18
19
  import type { Config } from './Config.js';
@@ -26,7 +27,11 @@ import type { PageContextPublicProxyClient } from '../client/runtime-client-rout
26
27
  type PageContextServer<Data = unknown> = PageContextBuiltInServer<Data> & {
27
28
  /** https://vike.dev/warning/internals */
28
29
  dangerouslyUseInternals: DangerouslyUseInternals<PageContextInternalServer & PageContextAfterRender & PageContextPublicServer>;
29
- } & Vike.PageContext & Vike.PageContextServer;
30
+ } & Vike.PageContext & Vike.PageContextServer & (Vike.Server extends {
31
+ server: string;
32
+ } ? {
33
+ runtime: RuntimeAdapterTarget<Vike.Server['server']>;
34
+ } : {});
30
35
  type PageContext<Data = unknown> = PageContextClient<Data> | PageContextServer<Data>;
31
36
  type PageContextClient<Data = unknown> = PageContextBuiltInClientWithClientRouting<Data> & {
32
37
  /** https://vike.dev/warning/internals */
@@ -134,7 +139,7 @@ type PageContextInit = {
134
139
  headersOriginal?: unknown;
135
140
  /** @deprecated Set `pageContextInit.urlOriginal` instead */ url?: string;
136
141
  };
137
- type PageContextInternalInit = PageContextInit & {
142
+ type PageContextInitInternal = PageContextInit & {
138
143
  _reqDev?: IncomingMessage;
139
144
  _reqWeb?: Request;
140
145
  };
@@ -294,7 +299,7 @@ type PageContextInternalClient_ServerRouting = Omit<PageContextBuiltInClientWith
294
299
  * ```
295
300
  * With:
296
301
  * ```
297
- * import { PageContextServer } from 'vike/types'
302
+ * import type { PageContextServer } from 'vike/types'
298
303
  * ```
299
304
  *
300
305
  * See https://vike.dev/pageContext#typescript
@@ -307,7 +312,7 @@ type PageContextBuiltInServer_deprecated<_Page = never> = PageContextBuiltInServ
307
312
  * ```
308
313
  * With:
309
314
  * ```
310
- * import { PageContextClient } from 'vike/types'
315
+ * import type { PageContextClient } from 'vike/types'
311
316
  * ```
312
317
  *
313
318
  * See https://vike.dev/pageContext#typescript
@@ -320,7 +325,7 @@ type PageContextBuiltInClientWithClientRouting_deprecated<_Page = never> = PageC
320
325
  * ```
321
326
  * With:
322
327
  * ```
323
- * import { PageContextClientWithServerRouting as PageContextClient } from 'vike/types'
328
+ * import type { PageContextClientWithServerRouting as PageContextClient } from 'vike/types'
324
329
  * ```
325
330
  *
326
331
  * See https://vike.dev/pageContext#typescript
@@ -60,5 +60,12 @@ declare global {
60
60
  interface GlobalContextServer {
61
61
  _interfaceIsNotAny?: never;
62
62
  }
63
+ /** Defines the type of `pageContext.runtime`.
64
+ *
65
+ * https://vike.dev/server#pagecontext-runtime
66
+ */
67
+ interface Server {
68
+ _interfaceIsNotAny?: never;
69
+ }
63
70
  }
64
71
  }
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.256-commit-85a5a9e";
1
+ export declare const PROJECT_VERSION: "0.4.257-commit-c6e29ea";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.256-commit-85a5a9e';
2
+ export const PROJECT_VERSION = '0.4.257-commit-c6e29ea';
@@ -0,0 +1 @@
1
+ export declare function isCloudflareWorkers(): boolean;
@@ -0,0 +1,4 @@
1
+ // https://github.com/cloudflare/workers-sdk/issues/1481#issuecomment-2550929035
2
+ export function isCloudflareWorkers() {
3
+ return typeof navigator !== 'undefined' && navigator?.userAgent === 'Cloudflare-Workers';
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.256-commit-85a5a9e",
3
+ "version": "0.4.257-commit-c6e29ea",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -133,7 +133,7 @@
133
133
  "@brillout/picocolors": "^1.0.30",
134
134
  "@brillout/vite-plugin-server-entry": "0.7.18",
135
135
  "@universal-deploy/store": "^0.2.1",
136
- "@universal-deploy/vite": "^0.1.3",
136
+ "@universal-deploy/vite": "^0.1.6",
137
137
  "@universal-middleware/core": "^0.4.17",
138
138
  "@universal-middleware/node": "^0.1.0",
139
139
  "cac": "^6.0.0",
@@ -146,7 +146,7 @@
146
146
  "semver": "^7.7.4",
147
147
  "sirv": "^3.0.2",
148
148
  "source-map-support": "^0.5.0",
149
- "tinyglobby": "^0.2.10",
149
+ "tinyglobby": "^0.2.16",
150
150
  "vite": ">=6.3.0",
151
151
  "vite-plugin-wrapper": "^0.1.0"
152
152
  },
@@ -1,27 +0,0 @@
1
- export { getDeployConfigs };
2
- import type { fromVike } from 'convert-route';
3
- import type { PageConfigPublicWithRoute } from '../../../../shared-server-client/page-configs/resolveVikeConfigPublic.js';
4
- import '../../assertEnvVite.js';
5
- declare function getDeployConfigs(pageId: string, page: PageConfigPublicWithRoute): {
6
- route: string;
7
- vercel: {
8
- isr: {
9
- expiration: number;
10
- } | undefined;
11
- edge: boolean | undefined;
12
- };
13
- } | null;
14
- export declare function getRoutePageContextJson(routeIr: ReturnType<typeof fromVike>): {
15
- pathname: ({
16
- optional: boolean;
17
- } & ({
18
- value: string;
19
- catchAll?: never;
20
- } | {
21
- value?: never;
22
- catchAll: {
23
- name?: string;
24
- greedy: boolean;
25
- };
26
- }))[];
27
- } | undefined;
@@ -1,7 +0,0 @@
1
- import type { VikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
2
- import '../../assertEnvVite.js';
3
- export declare function getServerInfo(vikeConfig: VikeConfigInternal): {
4
- serverEntryId: string;
5
- serverEntryVike: string;
6
- serverFilePath: string | null;
7
- } | undefined;