vike 0.4.256 → 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 (66) hide show
  1. package/dist/client/runtime-client-routing/createPageContextClient.d.ts +2 -24
  2. package/dist/client/runtime-client-routing/getGlobalContextClientInternal.d.ts +2 -24
  3. package/dist/client/runtime-client-routing/getPageContextFromHooks.d.ts +8 -96
  4. package/dist/client/runtime-client-routing/renderPageClient.d.ts +8 -96
  5. package/dist/client/runtime-server-routing/createPageContextClient.d.ts +2 -24
  6. package/dist/client/runtime-server-routing/getGlobalContextClientInternal.d.ts +2 -24
  7. package/dist/client/shared/getGlobalContextClientInternalShared.d.ts +2 -24
  8. package/dist/node/api/preview.js +14 -6
  9. package/dist/node/prerender/runPrerender.d.ts +9 -36
  10. package/dist/node/vite/index.js +2 -0
  11. package/dist/node/vite/plugins/pluginDev/optimizeDeps.d.ts +1 -1
  12. package/dist/node/vite/plugins/pluginDev/optimizeDeps.js +2 -0
  13. package/dist/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +2 -0
  14. package/dist/node/vite/plugins/pluginUniversalDeploy/common.d.ts +21 -0
  15. package/dist/node/vite/plugins/pluginUniversalDeploy/common.js +8 -0
  16. package/dist/node/vite/plugins/pluginUniversalDeploy/detectDeprecated.d.ts +4 -0
  17. package/dist/node/vite/plugins/pluginUniversalDeploy/detectDeprecated.js +21 -0
  18. package/dist/node/vite/plugins/pluginUniversalDeploy/getDeployConfig.d.ts +10 -0
  19. package/dist/node/vite/plugins/pluginUniversalDeploy/getDeployConfig.js +58 -0
  20. package/dist/node/vite/plugins/pluginUniversalDeploy/getServerConfig.d.ts +11 -0
  21. package/dist/node/vite/plugins/pluginUniversalDeploy/getServerConfig.js +49 -0
  22. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginResolvePlusServer.d.ts +7 -0
  23. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginResolvePlusServer.js +23 -0
  24. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginServerEntryAlias.d.ts +5 -0
  25. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginServerEntryAlias.js +42 -0
  26. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginServerEntryInject.d.ts +4 -0
  27. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginServerEntryInject.js +25 -0
  28. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginUnwrapProdOptions.d.ts +4 -0
  29. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginUnwrapProdOptions.js +22 -0
  30. package/dist/node/vite/plugins/pluginUniversalDeploy.d.ts +5 -0
  31. package/dist/node/vite/plugins/pluginUniversalDeploy.js +59 -0
  32. package/dist/node/vite/plugins/pluginWorkaroundVite6HmrRegression.js +2 -1
  33. package/dist/node/vite/shared/addSsrMiddleware.js +1 -0
  34. package/dist/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.d.ts +5 -1
  35. package/dist/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +8 -0
  36. package/dist/node/vite/shared/resolveVikeConfigInternal/pointerImports.d.ts +5 -2
  37. package/dist/node/vite/shared/resolveVikeConfigInternal/resolvePointerImport.js +9 -1
  38. package/dist/server/runtime/fetch.d.ts +10 -0
  39. package/dist/server/runtime/fetch.js +5 -0
  40. package/dist/server/runtime/globalContext.d.ts +10 -120
  41. package/dist/server/runtime/globalContext.js +11 -5
  42. package/dist/server/runtime/renderPageServer/createHttpResponse.d.ts +5 -3
  43. package/dist/server/runtime/renderPageServer/createHttpResponse.js +13 -1
  44. package/dist/server/runtime/renderPageServer/createPageContextServer.d.ts +15 -39
  45. package/dist/server/runtime/renderPageServer/loadPageConfigsLazyServerSide.d.ts +9 -36
  46. package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.d.ts +36 -144
  47. package/dist/server/runtime/renderPageServer.d.ts +13 -39
  48. package/dist/server/runtime/renderPageServer.js +51 -3
  49. package/dist/server/runtime/universal-middleware.d.ts +9 -2
  50. package/dist/server/runtime/universal-middleware.js +9 -1
  51. package/dist/shared-server-client/createGlobalContextShared.d.ts +4 -48
  52. package/dist/shared-server-client/page-configs/assertPlusFileExport.js +8 -4
  53. package/dist/shared-server-client/page-configs/resolveVikeConfigPublic.d.ts +1 -0
  54. package/dist/types/Config.d.ts +32 -1
  55. package/dist/types/FilePath.d.ts +6 -6
  56. package/dist/types/PageContext.d.ts +15 -4
  57. package/dist/types/Server.d.ts +12 -0
  58. package/dist/types/Server.js +1 -0
  59. package/dist/types/VikeNamespace.d.ts +7 -0
  60. package/dist/types/index.d.ts +1 -0
  61. package/dist/utils/PROJECT_VERSION.d.ts +1 -1
  62. package/dist/utils/PROJECT_VERSION.js +1 -1
  63. package/dist/utils/isCloudflareWorkers.d.ts +1 -0
  64. package/dist/utils/isCloudflareWorkers.js +4 -0
  65. package/fetch.js +3 -0
  66. package/package.json +22 -4
@@ -40,6 +40,7 @@ import { pluginStripPointerImportAttribute } from './plugins/pluginStripPointerI
40
40
  import { getVikeConfigInternalEarly, isOnlyResolvingUserConfig } from '../api/resolveViteConfigFromUser.js';
41
41
  import './assertEnvVite.js';
42
42
  import { isStorybook } from '../../utils/isStorybook.js';
43
+ import { pluginUniversalDeploy } from './plugins/pluginUniversalDeploy.js';
43
44
  // We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
44
45
  setGetClientEntrySrcDev(getClientEntrySrcDev);
45
46
  assertIsNotProductionRuntime();
@@ -70,6 +71,7 @@ function plugin(vikeVitePluginOptions = {}) {
70
71
  ...pluginStaticReplace(vikeConfig),
71
72
  ...pluginNonRunnabeDev(),
72
73
  ...pluginStripPointerImportAttribute(),
74
+ ...pluginUniversalDeploy(vikeConfig),
73
75
  ...(await pluginViteConfigVikeExtensions(vikeConfig)),
74
76
  ];
75
77
  Object.assign(plugin, pluginAddendum);
@@ -9,7 +9,7 @@ declare const optimizeDeps: {
9
9
  };
10
10
  readonly ssr: {
11
11
  readonly optimizeDeps: {
12
- readonly exclude: ["@brillout/import", "@brillout/json-serializer", "@brillout/picocolors", "@brillout/vite-plugin-server-entry", "vike"];
12
+ readonly exclude: ["@brillout/import", "@brillout/json-serializer", "@brillout/vite-plugin-server-entry", "vike"];
13
13
  };
14
14
  };
15
15
  };
@@ -55,7 +55,9 @@ const optimizeDeps = {
55
55
  exclude: [
56
56
  '@brillout/import',
57
57
  '@brillout/json-serializer',
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.
58
59
  '@brillout/picocolors',
60
+ */
59
61
  '@brillout/vite-plugin-server-entry',
60
62
  'vike',
61
63
  ],
@@ -39,9 +39,11 @@ function pluginReplaceConstantsGlobalThis() {
39
39
  },
40
40
  },
41
41
  configEnvironment: {
42
+ order: 'pre',
42
43
  handler(name, config) {
43
44
  const isClientSide = !isViteServerSide_configEnvironment(name, config);
44
45
  return {
46
+ consumer: isClientSide ? 'client' : 'server',
45
47
  define: {
46
48
  'globalThis.__VIKE__IS_CLIENT': JSON.stringify(isClientSide),
47
49
  },
@@ -0,0 +1,21 @@
1
+ export { pluginCommon };
2
+ import type { Plugin } from 'vite';
3
+ import '../../assertEnvVite.js';
4
+ declare const pluginCommon: {
5
+ applyToEnvironment(env: {
6
+ name: string;
7
+ getTopLevelConfig(): import("vite").ResolvedConfig;
8
+ config: import("vite").ResolvedConfig & {
9
+ define?: Record<string, any>;
10
+ resolve: Required<import("vite").ResolveOptions>;
11
+ consumer: "client" | "server";
12
+ keepProcessEnv?: boolean;
13
+ optimizeDeps: import("vite").DepOptimizationOptions;
14
+ dev: import("vite").ResolvedDevEnvironmentOptions;
15
+ build: import("vite").ResolvedBuildEnvironmentOptions;
16
+ plugins: readonly Plugin[];
17
+ };
18
+ logger: import("vite").Logger;
19
+ }): boolean;
20
+ sharedDuringBuild: true;
21
+ };
@@ -0,0 +1,8 @@
1
+ export { pluginCommon };
2
+ import '../../assertEnvVite.js';
3
+ const pluginCommon = {
4
+ applyToEnvironment(env) {
5
+ return env.config.consumer === 'server';
6
+ },
7
+ sharedDuringBuild: true,
8
+ };
@@ -0,0 +1,4 @@
1
+ export { hasVikeServerOrVikePhoton };
2
+ import type { VikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
3
+ import '../../assertEnvVite.js';
4
+ declare function hasVikeServerOrVikePhoton(vikeConfig: VikeConfigInternal): true | undefined;
@@ -0,0 +1,21 @@
1
+ export { hasVikeServerOrVikePhoton };
2
+ import { assert, assertWarning } from '../../../../utils/assert.js';
3
+ import pc from '@brillout/picocolors';
4
+ import '../../assertEnvVite.js';
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')
13
+ ? 'vike-server'
14
+ : vikeExtensionNames.includes('vike-photon')
15
+ ? 'vike-photon'
16
+ : null;
17
+ if (vikeServerOrVikePhoton) {
18
+ assertWarning(false, `${pc.cyan(vikeServerOrVikePhoton)} is deprecated, see ${pc.underline('https://vike.dev/migration/server')}`, { onlyOnce: true });
19
+ return true;
20
+ }
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
+ };
@@ -0,0 +1,58 @@
1
+ export { getDeployConfig };
2
+ import { fromVike } from 'convert-route/vike';
3
+ import { assert, assertUsage, assertWarning } from '../../../../utils/assert.js';
4
+ import { isObject } from '../../../../utils/isObject.js';
5
+ import '../../assertEnvVite.js';
6
+ import { isCallable } from '../../../../utils/isCallable.js';
7
+ import { pageContextJsonFileExtension } from '../../../../shared-server-client/getPageContextRequestUrl.js';
8
+ function getDeployConfig(pageId, page) {
9
+ const { route } = page;
10
+ if (!route)
11
+ return null;
12
+ // Vercel setting: +edge
13
+ const { edge } = page.config?.vercel ?? {};
14
+ if (edge) {
15
+ assertUsage(typeof edge === 'boolean', '+edge must be a boolean');
16
+ }
17
+ // Vercel setting: +isr
18
+ let { isr } = page.config?.vercel ?? {};
19
+ if (isr) {
20
+ assertUsage(isObject(isr), '+isr must be an object');
21
+ assertUsage(typeof isr.expiration === 'number' && isr.expiration > 0, '+isr.expiration must be a positive number');
22
+ }
23
+ if (edge) {
24
+ assertWarning(!isr, `Page ${pageId} — ISR isn't supported for edge functions — remove +isr or +edge`, {
25
+ onlyOnce: true,
26
+ });
27
+ isr = undefined;
28
+ }
29
+ if (!edge && !isr)
30
+ return null;
31
+ if (isCallable(route)) {
32
+ const errMsg = (configName) => `The route of the page ${pageId} is defined via a Route Function — ${configName} isn't supported. Remove ${configName} or define the page's route using a Route String (or Filesystem Routing) instead of a Route Function.`;
33
+ assertWarning(!isr, errMsg('+isr'), { onlyOnce: true });
34
+ assertWarning(!edge, errMsg('+edge'), { onlyOnce: true });
35
+ return null;
36
+ }
37
+ const routeIr = fromVike(route);
38
+ return {
39
+ route: [routeIr, getRouteIrPageContextJson(routeIr)].filter((r) => r !== undefined),
40
+ // Supported by vite-plugin-vercel@11
41
+ vercel: { isr, edge },
42
+ };
43
+ }
44
+ function getRouteIrPageContextJson(routeIr) {
45
+ const lastSegment = routeIr.pathname.at(-1);
46
+ assert(lastSegment);
47
+ if (lastSegment.catchAll)
48
+ return;
49
+ return {
50
+ pathname: [
51
+ ...routeIr.pathname.slice(0, -1),
52
+ {
53
+ ...lastSegment,
54
+ value: lastSegment.value + pageContextJsonFileExtension,
55
+ },
56
+ ],
57
+ };
58
+ }
@@ -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;
@@ -0,0 +1,49 @@
1
+ export { getServerConfig };
2
+ export { isUniversalDeployVitePreview };
3
+ import { catchAllEntry } from '@universal-deploy/store';
4
+ import { assert } from '../../../../utils/assert.js';
5
+ import '../../assertEnvVite.js';
6
+ function getServerConfig(vikeConfig) {
7
+ let serverEntryId;
8
+ let serverFilePath = null;
9
+ let serverEntryVike;
10
+ // universal-deploy support must be manually enabled
11
+ const serverConfig =
12
+ // +config.js > `export default { server: true }`
13
+ vikeConfig.config.server ||
14
+ // +server.js exists
15
+ !!vikeConfig._pageConfigGlobal.configValueSources.server ||
16
+ false;
17
+ if (serverConfig === false)
18
+ return;
19
+ const serverPlusFile = vikeConfig._pageConfigGlobal.configValueSources.server?.[0];
20
+ if (serverPlusFile?.valueIsDefinedByPlusValueFile) {
21
+ assert('filePathAbsoluteFilesystem' in serverPlusFile.definedAt);
22
+ serverFilePath = serverPlusFile.definedAt.filePathAbsoluteFilesystem;
23
+ assert(serverFilePath);
24
+ serverEntryId = serverFilePath;
25
+ serverEntryVike = serverFilePath;
26
+ }
27
+ else {
28
+ serverEntryId = catchAllEntry;
29
+ serverEntryVike = 'vike/fetch';
30
+ }
31
+ return {
32
+ // Used to filter which module ID to transform.
33
+ // It points to a fully resolved server entry or the virtual universal-deploy catchAll entry.
34
+ serverEntryId,
35
+ // This entry will be pushed to universal-deploy via `addEntry`.
36
+ // It either points to the default fetchable endpoint (vike/fetch), or one defined by the user through +server.
37
+ serverEntryVike,
38
+ serverFilePath,
39
+ };
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
+ }
@@ -0,0 +1,7 @@
1
+ export { pluginResolvePlusServer };
2
+ import type { Plugin } from 'vite';
3
+ import '../../assertEnvVite.js';
4
+ /**
5
+ * If +server.js is defined, make virtual:ud:catch-all resolve to +server.js absolute path
6
+ */
7
+ declare function pluginResolvePlusServer(serverFilePath: string): Plugin;
@@ -0,0 +1,23 @@
1
+ export { pluginResolvePlusServer };
2
+ import { pluginCommon } from './common.js';
3
+ import { escapeRegex } from '../../../../utils/escapeRegex.js';
4
+ import '../../assertEnvVite.js';
5
+ /**
6
+ * If +server.js is defined, make virtual:ud:catch-all resolve to +server.js absolute path
7
+ */
8
+ function pluginResolvePlusServer(serverFilePath) {
9
+ return {
10
+ name: 'vike:pluginUniversalDeploy:server',
11
+ resolveId: {
12
+ order: 'pre',
13
+ filter: {
14
+ id: new RegExp(escapeRegex(serverFilePath)),
15
+ },
16
+ handler() {
17
+ // Will resolve the entry from the users project root
18
+ return this.resolve(serverFilePath);
19
+ },
20
+ },
21
+ ...pluginCommon,
22
+ };
23
+ }
@@ -0,0 +1,5 @@
1
+ export { pluginServerEntryAlias };
2
+ import type { Plugin } from 'vite';
3
+ import '../../assertEnvVite.js';
4
+ /** Alias for virtual:ud:catch if no userland server entry */
5
+ declare function pluginServerEntryAlias(serverFilePath?: string | null): Plugin;
@@ -0,0 +1,42 @@
1
+ export { pluginServerEntryAlias };
2
+ import { catchAllEntry } from '@universal-deploy/store';
3
+ import { pluginCommon } from './common.js';
4
+ import { escapeRegex } from '../../../../utils/escapeRegex.js';
5
+ import { assert } from '../../../../utils/assert.js';
6
+ import '../../assertEnvVite.js';
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) {
18
+ return {
19
+ name: 'vike:pluginUniversalDeploy:alias',
20
+ resolveId: {
21
+ filter: filterRolldown,
22
+ handler() {
23
+ if (!serverFilePath)
24
+ return catchAllEntry;
25
+ return virtualFileId;
26
+ },
27
+ },
28
+ load: {
29
+ filter: filterRolldown,
30
+ handler() {
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
+ `;
38
+ },
39
+ },
40
+ ...pluginCommon,
41
+ };
42
+ }
@@ -0,0 +1,4 @@
1
+ export { pluginServerEntryInject };
2
+ import type { Plugin } from 'vite';
3
+ import '../../assertEnvVite.js';
4
+ declare function pluginServerEntryInject(serverEntryId: string): Plugin;
@@ -0,0 +1,25 @@
1
+ export { pluginServerEntryInject };
2
+ import { getMagicString } from '../../shared/getMagicString.js';
3
+ import { serverEntryVirtualId } from '@brillout/vite-plugin-server-entry/plugin';
4
+ import { pluginCommon } from './common.js';
5
+ import '../../assertEnvVite.js';
6
+ import { escapeRegex } from '../../../../utils/escapeRegex.js';
7
+ function pluginServerEntryInject(serverEntryId) {
8
+ return {
9
+ name: 'vike:pluginUniversalDeploy:serverEntry',
10
+ apply: 'build',
11
+ transform: {
12
+ order: 'post',
13
+ filter: {
14
+ id: new RegExp(escapeRegex(serverEntryId)),
15
+ },
16
+ handler(code, id) {
17
+ const { magicString, getMagicStringResult } = getMagicString(code, id);
18
+ // Inject Vike virtual server entry
19
+ magicString.prepend(`import "${serverEntryVirtualId}";\n`);
20
+ return getMagicStringResult();
21
+ },
22
+ },
23
+ ...pluginCommon,
24
+ };
25
+ }
@@ -0,0 +1,4 @@
1
+ export { pluginUnwrapProdOptions };
2
+ import type { Plugin } from 'vite';
3
+ import '../../assertEnvVite.js';
4
+ declare function pluginUnwrapProdOptions(serverFilePath: string): Plugin;
@@ -0,0 +1,22 @@
1
+ export { pluginUnwrapProdOptions };
2
+ import { wrapper } from 'vite-plugin-wrapper';
3
+ import { escapeRegex } from '../../../../utils/escapeRegex.js';
4
+ import '../../assertEnvVite.js';
5
+ function pluginUnwrapProdOptions(serverFilePath) {
6
+ return wrapper({
7
+ resolveId: {
8
+ filter: {
9
+ id: new RegExp(escapeRegex(serverFilePath)),
10
+ },
11
+ },
12
+ // Unwrap all prod.* options
13
+ load(id) {
14
+ return `
15
+ import mod from ${JSON.stringify(id)};
16
+
17
+ export * from ${JSON.stringify(id)};
18
+ export default { ...mod, ...mod?.prod };
19
+ `;
20
+ },
21
+ });
22
+ }
@@ -0,0 +1,5 @@
1
+ export { pluginUniversalDeploy };
2
+ import type { Plugin } from 'vite';
3
+ import type { VikeConfigInternal } from '../shared/resolveVikeConfigInternal.js';
4
+ import '../assertEnvVite.js';
5
+ declare function pluginUniversalDeploy(vikeConfig: VikeConfigInternal): Plugin[];
@@ -0,0 +1,59 @@
1
+ export { pluginUniversalDeploy };
2
+ import { toRou3 } from 'convert-route';
3
+ import { addEntry } from '@universal-deploy/store';
4
+ import universalDeploy, { resolveTargets } from '@universal-deploy/vite';
5
+ import { pluginServerEntryInject } from './pluginUniversalDeploy/pluginServerEntryInject.js';
6
+ import { getDeployConfig } from './pluginUniversalDeploy/getDeployConfig.js';
7
+ import { pluginCommon } from './pluginUniversalDeploy/common.js';
8
+ import { hasVikeServerOrVikePhoton } from './pluginUniversalDeploy/detectDeprecated.js';
9
+ import { getServerConfig } from './pluginUniversalDeploy/getServerConfig.js';
10
+ import { pluginServerEntryAlias } from './pluginUniversalDeploy/pluginServerEntryAlias.js';
11
+ import { pluginUnwrapProdOptions } from './pluginUniversalDeploy/pluginUnwrapProdOptions.js';
12
+ import { unique } from '../../../utils/unique.js';
13
+ import { assertUsage } from '../../../utils/assert.js';
14
+ import '../assertEnvVite.js';
15
+ function pluginUniversalDeploy(vikeConfig) {
16
+ if (hasVikeServerOrVikePhoton(vikeConfig))
17
+ return [];
18
+ const serverConfig = getServerConfig(vikeConfig);
19
+ if (!serverConfig)
20
+ return [
21
+ resolveTargets((targets) => {
22
+ // Cloudflare is supported even without universal-deploy
23
+ const target = targets.filter((t) => t !== '@cloudflare/vite-plugin')[0];
24
+ assertUsage(target === undefined, `${target} requires +server — see https://vike.dev/server`);
25
+ }),
26
+ ];
27
+ const { serverEntryVike, serverEntryId, serverFilePath } = serverConfig;
28
+ return [
29
+ ...universalDeploy(),
30
+ {
31
+ name: 'vike:pluginUniversalDeploy:entries',
32
+ config() {
33
+ // Map each Vike route to universal-deploy
34
+ for (const [pageId, page] of Object.entries(vikeConfig.pages)) {
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;
39
+ addEntry({
40
+ ...config,
41
+ id: serverEntryVike,
42
+ // Map Vike routes to rou3 format
43
+ route: unique(route.map(toRou3).flat()),
44
+ });
45
+ }
46
+ }
47
+ // Default catch-all route
48
+ addEntry({
49
+ id: serverEntryVike,
50
+ route: '/**',
51
+ });
52
+ },
53
+ ...pluginCommon,
54
+ },
55
+ pluginServerEntryInject(serverFilePath ?? serverEntryId),
56
+ pluginServerEntryAlias(serverFilePath),
57
+ !serverFilePath ? null : pluginUnwrapProdOptions(serverFilePath),
58
+ ].filter((p) => p !== null);
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;
@@ -14,6 +14,7 @@ function addSsrMiddleware(middlewares, config, isPreview, isPrerenderingEnabled)
14
14
  const pageContextInit = {
15
15
  urlOriginal: url,
16
16
  headersOriginal: headers,
17
+ _reqDev: req,
17
18
  };
18
19
  Object.defineProperty(pageContextInit, 'userAgent', {
19
20
  get() {
@@ -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
  *
@@ -4,6 +4,7 @@ import { getConfigDefinedAt, } from '../../../../shared-server-client/page-confi
4
4
  import { getConfigValueSourceRelevantAnyEnv, getConfigValueSourcesRelevant, isConfigSourceValueNull, } from '../../plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js';
5
5
  import { getFileSuffixes } from '../../../../shared-server-node/getFileSuffixes.js';
6
6
  import '../../assertEnvVite.js';
7
+ // TODO/after-PR-merge: rename_full configDefinitionsBuiltIn metaBuiltIn
7
8
  const configDefinitionsBuiltIn = {
8
9
  onRenderHtml: {
9
10
  env: { server: true },
@@ -225,6 +226,10 @@ const configDefinitionsBuiltIn = {
225
226
  eager: true,
226
227
  global: true,
227
228
  },
229
+ server: {
230
+ env: { server: true },
231
+ global: true,
232
+ },
228
233
  cli: {
229
234
  env: { config: true },
230
235
  global: true,
@@ -305,6 +310,9 @@ const configDefinitionsBuiltIn = {
305
310
  env: { config: true },
306
311
  global: true,
307
312
  },
313
+ vercel: {
314
+ env: { config: true },
315
+ },
308
316
  };
309
317
  function getConfigEnv(pageConfig, configName) {
310
318
  const source = getConfigValueSourceRelevantAnyEnv(configName, pageConfig);
@@ -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'))
@@ -0,0 +1,10 @@
1
+ import '../assertEnvServer.js';
2
+ declare const _default: {
3
+ fetch: (<T extends string>(request: Request, context: Universal.Context, runtime: import("@universal-middleware/core").RuntimeAdapterTarget<T>) => Promise<Response>) & import("@universal-middleware/core").WithUniversalSymbols<{
4
+ name: string;
5
+ method: ("GET" | "HEAD" | "POST" | "PUT" | "OPTIONS" | "PATCH")[];
6
+ path: string;
7
+ immutable: true;
8
+ }>;
9
+ };
10
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import '../assertEnvServer.js';
2
+ import vikeHandler from './universal-middleware.js';
3
+ export default {
4
+ fetch: vikeHandler,
5
+ };