vike 0.4.256-commit-414bdc0 → 0.4.256-commit-70e9a80

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.
@@ -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,8 @@ const optimizeDeps = {
55
55
  exclude: [
56
56
  '@brillout/import',
57
57
  '@brillout/json-serializer',
58
- '@brillout/picocolors',
58
+ // FIXME Breaks @cloudflare/vite-plugin. Remove me if CI passes
59
+ // '@brillout/picocolors',
59
60
  '@brillout/vite-plugin-server-entry',
60
61
  'vike',
61
62
  ],
@@ -8,10 +8,10 @@ declare function getDeployConfigs(pageId: string, page: PageConfigPublicWithRout
8
8
  isr: {
9
9
  expiration: number;
10
10
  } | undefined;
11
- edge: boolean;
11
+ edge: boolean | undefined;
12
12
  };
13
13
  } | null;
14
- export declare function getPageContextRoute(routeIr: ReturnType<typeof fromVike>): {
14
+ export declare function getRoutePageContextJson(routeIr: ReturnType<typeof fromVike>): {
15
15
  pathname: ({
16
16
  optional: boolean;
17
17
  } & ({
@@ -1,59 +1,45 @@
1
- import pc from '@brillout/picocolors';
2
1
  export { getDeployConfigs };
3
2
  import { assert, assertUsage, assertWarning } from '../../../../utils/assert.js';
4
3
  import { isObject } from '../../../../utils/isObject.js';
5
4
  import '../../assertEnvVite.js';
5
+ import { isCallable } from '../../../../utils/isCallable.js';
6
6
  function getDeployConfigs(pageId, page) {
7
- const route = typeof page.route === 'string' ? page.route : null;
8
- // Vercel specific configs
9
- const rawIsr = extractIsr(page.config);
10
- let isr = assertIsr(rawIsr);
11
- const edge = extractEdge(page.config);
12
- const isrOrEdge = isr ? 'isr' : edge ? 'edge' : null;
13
- if (typeof page.route === 'function' && isrOrEdge) {
14
- assertWarning(false, `Page ${pageId}: ${pc.cyan(isrOrEdge)} is not supported when using route function. Remove ${pc.cyan(isrOrEdge)} config or use a route string if possible.`, { onlyOnce: true });
15
- isr = null;
7
+ const { route } = page;
8
+ if (!route)
9
+ return null;
10
+ // Vercel setting: +edge
11
+ const { edge } = page.config;
12
+ if (edge) {
13
+ assertUsage(typeof edge === 'boolean', '+edge must be a boolean');
16
14
  }
17
- if (edge && rawIsr !== null && typeof rawIsr === 'object') {
18
- assertUsage(false, `Page ${pageId}: ISR cannot be enabled for edge functions. Remove ${pc.cyan('isr')} config or set \`{ edge: false }\`.`);
15
+ // Vercel setting: +isr
16
+ let { isr } = page.config;
17
+ if (isr) {
18
+ assertUsage(isObject(isr), '+isr must be an object');
19
+ assertUsage(typeof isr.expiration === 'number' && isr.expiration > 0, '+isr.expiration must be a positive number');
19
20
  }
20
- if (isrOrEdge && route) {
21
- return {
22
- route,
23
- // route: [...new Set([...toRou3(routeIr), ...getPageContextRoute(routeIr)])],
24
- // Supported by vite-plugin-vercel@11
25
- vercel: {
26
- isr: isr ? { expiration: isr } : undefined,
27
- edge: Boolean(edge),
28
- },
29
- };
21
+ if (edge) {
22
+ assertWarning(!isr, `Page ${pageId} — ISR isn't supported for edge functions — remove +isr or +edge`, {
23
+ onlyOnce: true,
24
+ });
25
+ isr = undefined;
30
26
  }
31
- return null;
32
- }
33
- function extractIsr(pageConfig) {
34
- if (!pageConfig.isr)
35
- return null;
36
- const isr = pageConfig.isr;
37
- assertUsage(isObject(isr) &&
38
- typeof isr.expiration === 'number' &&
39
- isr.expiration > 0, ' `{ expiration }` must be a positive number');
40
- return isr;
41
- }
42
- function assertIsr(isr) {
43
- if (isr === null || isr === undefined)
27
+ if (!edge && !isr)
44
28
  return null;
45
- return isr.expiration;
46
- }
47
- function extractEdge(exports) {
48
- if (exports === null || typeof exports !== 'object')
49
- return null;
50
- if (!('edge' in exports))
29
+ if (isCallable(route)) {
30
+ 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 Filesytem Routing) instead of a Route Function.`;
31
+ assertWarning(!isr, errMsg('+isr'), { onlyOnce: true });
32
+ assertWarning(!edge, errMsg('+edge'), { onlyOnce: true });
51
33
  return null;
52
- const edge = exports.edge;
53
- assertUsage(typeof edge === 'boolean', ' `{ edge }` must be a boolean');
54
- return edge;
34
+ }
35
+ return {
36
+ route,
37
+ // route: [...new Set([...toRou3(routeIr), ...getRoutePageContextJson(routeIr)])],
38
+ // Supported by vite-plugin-vercel@11
39
+ vercel: { isr, edge },
40
+ };
55
41
  }
56
- export function getPageContextRoute(routeIr) {
42
+ export function getRoutePageContextJson(routeIr) {
57
43
  const lastSegment = routeIr.pathname.at(-1);
58
44
  assert(lastSegment);
59
45
  if (lastSegment.catchAll)
@@ -4,23 +4,23 @@ import '../../assertEnvVite.js';
4
4
  export function getServerInfo(vikeConfig) {
5
5
  let serverEntryId;
6
6
  let serverFilePath = null;
7
- const serverConfig = vikeConfig.config.server;
7
+ let serverEntryVike;
8
+ const serverConfig = vikeConfig.config.server ?? true;
8
9
  // universal-deploy support manually disabled by user
9
10
  if (serverConfig === false)
10
11
  return;
11
12
  const serverPlusFile = vikeConfig._pageConfigGlobal.configValueSources.server?.[0];
12
- if (serverPlusFile) {
13
+ if (serverPlusFile?.valueIsDefinedByPlusValueFile) {
13
14
  assert('filePathAbsoluteFilesystem' in serverPlusFile.definedAt);
14
15
  serverFilePath = serverPlusFile.definedAt.filePathAbsoluteFilesystem;
15
16
  assert(serverFilePath);
16
17
  serverEntryId = serverFilePath;
18
+ serverEntryVike = serverFilePath;
17
19
  }
18
20
  else {
19
21
  serverEntryId = catchAllEntry;
22
+ serverEntryVike = 'vike/fetch';
20
23
  }
21
- if (serverConfig !== true && !serverFilePath)
22
- return;
23
- const serverEntryVike = serverFilePath ?? 'vike/fetch';
24
24
  return {
25
25
  // Used to filter which module ID to transform.
26
26
  // It points to a fully resolved server entry or the virtual universal-deploy catchAll entry.
@@ -3,4 +3,4 @@ import '../../assertEnvVite.js';
3
3
  /**
4
4
  * If +server.js is defined, make virtual:ud:catch-all resolve to +server.js absolute path
5
5
  */
6
- export declare function pluginVikeVirtualEntry(serverFilePath: string): Plugin;
6
+ export declare function pluginServerEntryInject(serverFilePath: string): Plugin;
@@ -4,7 +4,7 @@ import '../../assertEnvVite.js';
4
4
  /**
5
5
  * If +server.js is defined, make virtual:ud:catch-all resolve to +server.js absolute path
6
6
  */
7
- export function pluginVikeVirtualEntry(serverFilePath) {
7
+ export function pluginServerEntryInject(serverFilePath) {
8
8
  return {
9
9
  name: 'vike:pluginUniversalDeploy:server',
10
10
  resolveId: {
@@ -0,0 +1,4 @@
1
+ export { pluginServerEntryAlias };
2
+ import type { Plugin } from 'vite';
3
+ import '../../assertEnvVite.js';
4
+ declare function pluginServerEntryAlias(): Plugin;
@@ -1,8 +1,9 @@
1
+ export { pluginServerEntryAlias };
1
2
  import { pluginCommon } from './common.js';
2
3
  import { escapeRegex } from '../../../../utils/escapeRegex.js';
3
4
  import { catchAllEntry } from '@universal-deploy/store';
4
5
  import '../../assertEnvVite.js';
5
- export function pluginResolveAlias() {
6
+ function pluginServerEntryAlias() {
6
7
  return {
7
8
  name: 'vike:pluginUniversalDeploy:alias',
8
9
  resolveId: {
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ import '../../assertEnvVite.js';
3
+ export declare function pluginServerEntryInject(serverEntryId: string): Plugin;
@@ -1,8 +1,8 @@
1
1
  import { getMagicString } from '../../shared/getMagicString.js';
2
- import { serverEntryVirtualId as vikeVirtualEntry } from '@brillout/vite-plugin-server-entry/plugin';
2
+ import { serverEntryVirtualId } from '@brillout/vite-plugin-server-entry/plugin';
3
3
  import { pluginCommon } from './common.js';
4
4
  import '../../assertEnvVite.js';
5
- export function pluginVikeVirtualEntry(serverEntryId) {
5
+ export function pluginServerEntryInject(serverEntryId) {
6
6
  return {
7
7
  name: 'vike:pluginUniversalDeploy:serverEntry',
8
8
  apply: 'build',
@@ -16,7 +16,7 @@ export function pluginVikeVirtualEntry(serverEntryId) {
16
16
  handler(code, id) {
17
17
  const { magicString, getMagicStringResult } = getMagicString(code, id);
18
18
  // Inject Vike virtual server entry
19
- magicString.prepend(`import "${vikeVirtualEntry}";\n`);
19
+ magicString.prepend(`import "${serverEntryVirtualId}";\n`);
20
20
  return getMagicStringResult();
21
21
  },
22
22
  },
@@ -1,14 +1,14 @@
1
- import { toRou3 } from 'convert-route';
2
1
  export { pluginUniversalDeploy };
2
+ import { toRou3 } from 'convert-route';
3
3
  import { addEntry } from '@universal-deploy/store';
4
4
  import universalDeploy from '@universal-deploy/vite';
5
5
  import { fromVike } from 'convert-route/vike';
6
- import { pluginVikeVirtualEntry } from './pluginUniversalDeploy/pluginVikeVirtualEntry.js';
7
- import { getDeployConfigs, getPageContextRoute } from './pluginUniversalDeploy/getDeployConfigs.js';
6
+ import { pluginServerEntryInject } from './pluginUniversalDeploy/pluginServerEntryInject.js';
7
+ import { getDeployConfigs, getRoutePageContextJson } from './pluginUniversalDeploy/getDeployConfigs.js';
8
8
  import { pluginCommon } from './pluginUniversalDeploy/common.js';
9
9
  import { hasVikeServerOrVikePhoton } from './pluginUniversalDeploy/detectDeprecated.js';
10
10
  import { getServerInfo } from './pluginUniversalDeploy/getServerInfo.js';
11
- import { pluginResolveAlias } from './pluginUniversalDeploy/pluginResolveAlias.js';
11
+ import { pluginServerEntryAlias } from './pluginUniversalDeploy/pluginServerEntryAlias.js';
12
12
  import { pluginUnwrapProdOptions } from './pluginUniversalDeploy/pluginUnwrapProdOptions.js';
13
13
  import '../assertEnvVite.js';
14
14
  import { unique } from '../../../utils/unique.js';
@@ -19,7 +19,7 @@ function pluginUniversalDeploy(vikeConfig) {
19
19
  if (!serverInfo)
20
20
  return [];
21
21
  const { serverEntryVike, serverEntryId, serverFilePath } = serverInfo;
22
- const plugins = [
22
+ return [
23
23
  ...universalDeploy(),
24
24
  {
25
25
  name: 'vike:pluginUniversalDeploy:entries',
@@ -31,12 +31,12 @@ function pluginUniversalDeploy(vikeConfig) {
31
31
  if (deployConfigs !== null) {
32
32
  const { route, ...additionalConfigs } = deployConfigs;
33
33
  const routeIr = fromVike(route);
34
- const pageContextRouteIr = getPageContextRoute(routeIr);
34
+ const routeIrPageContextJson = getRoutePageContextJson(routeIr);
35
35
  addEntry({
36
36
  ...additionalConfigs,
37
37
  id: serverEntryVike,
38
38
  // Map Vike routes to rou3 format
39
- route: unique([...toRou3(routeIr), ...(pageContextRouteIr ? toRou3(pageContextRouteIr) : [])]),
39
+ route: unique([...toRou3(routeIr), ...(routeIrPageContextJson ? toRou3(routeIrPageContextJson) : [])]),
40
40
  });
41
41
  }
42
42
  }
@@ -48,11 +48,8 @@ function pluginUniversalDeploy(vikeConfig) {
48
48
  },
49
49
  ...pluginCommon,
50
50
  },
51
- pluginVikeVirtualEntry(serverFilePath ?? serverEntryId),
52
- pluginResolveAlias(),
53
- ];
54
- if (serverFilePath) {
55
- plugins.push(pluginUnwrapProdOptions(serverFilePath));
56
- }
57
- return plugins;
51
+ pluginServerEntryInject(serverFilePath ?? serverEntryId),
52
+ pluginServerEntryAlias(),
53
+ !serverFilePath ? null : pluginUnwrapProdOptions(serverFilePath),
54
+ ].filter((p) => p !== null);
58
55
  }
@@ -227,7 +227,7 @@ const configDefinitionsBuiltIn = {
227
227
  global: true,
228
228
  },
229
229
  server: {
230
- env: { server: true },
230
+ env: { server: true, config: true },
231
231
  global: true,
232
232
  },
233
233
  cli: {
@@ -1,8 +1,12 @@
1
+ export type { Server };
1
2
  import type { Fetchable, ServerOptions } from '@universal-deploy/store';
2
- /** Server options.
3
+ /**
4
+ * Server settings.
3
5
  *
4
6
  * https://vike.dev/server
5
7
  */
6
- export interface Server extends Fetchable {
7
- prod?: Omit<ServerOptions, 'fetch'>;
8
+ interface Server extends Fetchable {
9
+ prod?: Omit<ServerOptions, 'fetch'> & {
10
+ static?: boolean | string;
11
+ };
8
12
  }
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.256-commit-414bdc0";
1
+ export declare const PROJECT_VERSION: "0.4.256-commit-70e9a80";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.256-commit-414bdc0';
2
+ export const PROJECT_VERSION = '0.4.256-commit-70e9a80';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.256-commit-414bdc0",
3
+ "version": "0.4.256-commit-70e9a80",
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.1",
136
+ "@universal-deploy/vite": "^0.1.2",
137
137
  "@universal-middleware/core": "^0.4.17",
138
138
  "@universal-middleware/node": "^0.1.0",
139
139
  "cac": "^6.0.0",
@@ -1,3 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- import '../../assertEnvVite.js';
3
- export declare function pluginResolveAlias(): Plugin;
@@ -1,3 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- import '../../assertEnvVite.js';
3
- export declare function pluginVikeVirtualEntry(serverEntryId: string): Plugin;