vike 0.4.255-commit-05a7b95 → 0.4.256-commit-414bdc0

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 (33) hide show
  1. package/dist/node/prerender/runPrerender.js +17 -11
  2. package/dist/node/vite/plugins/pluginExtractAssets.js +2 -0
  3. package/dist/node/vite/plugins/pluginUniversalDeploy/common.d.ts +20 -0
  4. package/dist/node/vite/plugins/pluginUniversalDeploy/common.js +7 -0
  5. package/dist/node/vite/plugins/pluginUniversalDeploy/detectDeprecated.d.ts +3 -0
  6. package/dist/node/vite/plugins/pluginUniversalDeploy/detectDeprecated.js +15 -0
  7. package/dist/node/vite/plugins/pluginUniversalDeploy/getDeployConfigs.d.ts +16 -1
  8. package/dist/node/vite/plugins/pluginUniversalDeploy/getDeployConfigs.js +22 -25
  9. package/dist/node/vite/plugins/pluginUniversalDeploy/getServerInfo.d.ts +7 -0
  10. package/dist/node/vite/plugins/pluginUniversalDeploy/getServerInfo.js +33 -0
  11. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginResolveAlias.d.ts +3 -0
  12. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginResolveAlias.js +19 -0
  13. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginResolvePlusServer.d.ts +6 -0
  14. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginResolvePlusServer.js +22 -0
  15. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginUnwrapProdOptions.d.ts +3 -0
  16. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginUnwrapProdOptions.js +19 -0
  17. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginVikeVirtualEntry.d.ts +3 -0
  18. package/dist/node/vite/plugins/pluginUniversalDeploy/pluginVikeVirtualEntry.js +25 -0
  19. package/dist/node/vite/plugins/pluginUniversalDeploy.js +29 -126
  20. package/dist/types/Config.d.ts +1 -1
  21. package/dist/types/Server.d.ts +8 -0
  22. package/dist/types/Server.js +1 -0
  23. package/dist/types/index.d.ts +1 -0
  24. package/dist/utils/PROJECT_VERSION.d.ts +1 -1
  25. package/dist/utils/PROJECT_VERSION.js +1 -1
  26. package/dist/utils/assertKeys.js +2 -2
  27. package/dist/utils/assertNodeVersion.js +1 -1
  28. package/dist/utils/assertVersion.js +1 -1
  29. package/dist/utils/joinEnglish.d.ts +4 -1
  30. package/dist/utils/joinEnglish.js +4 -4
  31. package/package.json +12 -11
  32. package/dist/utils/asyncFlatten.d.ts +0 -4
  33. package/dist/utils/asyncFlatten.js +0 -7
@@ -239,17 +239,6 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, globalContext,
239
239
  const result = normalizeOnPrerenderHookResult(prerenderResult, hookFilePath, hookName);
240
240
  // Handle result
241
241
  await Promise.all(result.map(async ({ url, pageContext }) => {
242
- // Assert no duplication
243
- {
244
- const pageContextFound = prerenderContext.pageContexts.find((pageContext) => isSameUrl(pageContext.urlOriginal, url));
245
- if (pageContextFound) {
246
- assert(pageContextFound._providedByHook);
247
- const providedTwice = hookFilePath === pageContextFound._providedByHook.hookFilePath
248
- ? `twice by the ${hookName}() hook (${hookFilePath})`
249
- : `twice: by the ${hookName}() hook (${hookFilePath}) as well as by the hook ${pageContextFound._providedByHook.hookFilePath}() (${pageContextFound._providedByHook.hookName})`;
250
- assertUsage(false, `URL ${pc.cyan(url)} provided ${providedTwice}. Make sure to provide the URL only once instead.`);
251
- }
252
- }
253
242
  // Add result
254
243
  const providedByHook = { hookFilePath, hookName };
255
244
  const pageContextNew = await createPageContextPrerendering(url, prerenderContext, globalContext, false, undefined, providedByHook);
@@ -260,6 +249,23 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, globalContext,
260
249
  }
261
250
  }));
262
251
  })));
252
+ // Assert no duplicate URLs
253
+ // If duplicate URL is found an error will be issued
254
+ const pageContextsByUrl = {};
255
+ for (const pageContext of prerenderContext.pageContexts) {
256
+ assert(pageContext._providedByHook);
257
+ const urlNormalized = normalizeUrl(pageContext.urlOriginal);
258
+ const pageContextSameUrl = pageContextsByUrl[urlNormalized];
259
+ if (pageContextSameUrl) {
260
+ assert(pageContextSameUrl._providedByHook);
261
+ const { hookName, hookFilePath } = pageContext._providedByHook;
262
+ const providedTwice = hookFilePath === pageContextSameUrl._providedByHook.hookFilePath
263
+ ? `twice by the ${hookName}() hook (${hookFilePath})`
264
+ : `twice: by the ${hookName}() hook (${hookFilePath}) as well as by the hook ${pageContextSameUrl._providedByHook.hookFilePath}() (${pageContextSameUrl._providedByHook.hookName})`;
265
+ assertUsage(false, `URL ${pc.cyan(urlNormalized)} provided ${providedTwice}. Make sure to provide the URL only once instead.`);
266
+ }
267
+ pageContextsByUrl[urlNormalized] = pageContext;
268
+ }
263
269
  }
264
270
  function getUrlListFromPagesWithStaticRoute(globalContext, doNotPrerenderList) {
265
271
  const urlList = [];
@@ -41,6 +41,8 @@ const filterFunction = (id) => extractAssetsRE.test(id);
41
41
  function pluginExtractAssets() {
42
42
  let config;
43
43
  let vikeConfig;
44
+ if (handleAssetsManifest_isFixEnabled())
45
+ return [];
44
46
  let isFixEnabled;
45
47
  return [
46
48
  // This plugin removes all JavaScript from server-side only code, so that only CSS imports remains. (And also static files imports e.g. `import logoURL from './logo.svg.js'`).
@@ -0,0 +1,20 @@
1
+ import type { Plugin } from 'vite';
2
+ import '../../assertEnvVite.js';
3
+ export declare const pluginCommon: {
4
+ applyToEnvironment(env: {
5
+ name: string;
6
+ getTopLevelConfig(): import("vite").ResolvedConfig;
7
+ config: import("vite").ResolvedConfig & {
8
+ define?: Record<string, any>;
9
+ resolve: Required<import("vite").ResolveOptions>;
10
+ consumer: "client" | "server";
11
+ keepProcessEnv?: boolean;
12
+ optimizeDeps: import("vite").DepOptimizationOptions;
13
+ dev: import("vite").ResolvedDevEnvironmentOptions;
14
+ build: import("vite").ResolvedBuildEnvironmentOptions;
15
+ plugins: readonly Plugin[];
16
+ };
17
+ logger: import("vite").Logger;
18
+ }): boolean;
19
+ sharedDuringBuild: true;
20
+ };
@@ -0,0 +1,7 @@
1
+ import '../../assertEnvVite.js';
2
+ export const pluginCommon = {
3
+ applyToEnvironment(env) {
4
+ return env.config.consumer === 'server';
5
+ },
6
+ sharedDuringBuild: true,
7
+ };
@@ -0,0 +1,3 @@
1
+ import type { VikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
2
+ import '../../assertEnvVite.js';
3
+ export declare function hasVikeServerOrVikePhoton(vikeConfig: VikeConfigInternal): true | undefined;
@@ -0,0 +1,15 @@
1
+ import { assertWarning } from '../../../../utils/assert.js';
2
+ import pc from '@brillout/picocolors';
3
+ 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')
7
+ ? 'vike-server'
8
+ : vikeExtendsNames.has('vike-photon')
9
+ ? 'vike-photon'
10
+ : null;
11
+ if (vikeServerOrVikePhoton) {
12
+ assertWarning(false, `${pc.cyan(vikeServerOrVikePhoton)} is deprecated, see ${pc.underline('https://vike.dev/migration/universal-deploy')}`, { onlyOnce: true });
13
+ return true;
14
+ }
15
+ }
@@ -1,8 +1,9 @@
1
1
  export { getDeployConfigs };
2
+ import type { fromVike } from 'convert-route';
2
3
  import type { PageConfigPublicWithRoute } from '../../../../shared-server-client/page-configs/resolveVikeConfigPublic.js';
3
4
  import '../../assertEnvVite.js';
4
5
  declare function getDeployConfigs(pageId: string, page: PageConfigPublicWithRoute): {
5
- route: string[];
6
+ route: string;
6
7
  vercel: {
7
8
  isr: {
8
9
  expiration: number;
@@ -10,3 +11,17 @@ declare function getDeployConfigs(pageId: string, page: PageConfigPublicWithRout
10
11
  edge: boolean;
11
12
  };
12
13
  } | null;
14
+ export declare function getPageContextRoute(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,11 +1,10 @@
1
1
  import pc from '@brillout/picocolors';
2
2
  export { getDeployConfigs };
3
- import { fromVike, toRou3 } from 'convert-route';
4
3
  import { assert, assertUsage, assertWarning } from '../../../../utils/assert.js';
4
+ import { isObject } from '../../../../utils/isObject.js';
5
5
  import '../../assertEnvVite.js';
6
6
  function getDeployConfigs(pageId, page) {
7
- // Convert Vike's routes to rou3 format
8
- const routeIr = typeof page.route === 'string' ? fromVike(page.route) : null;
7
+ const route = typeof page.route === 'string' ? page.route : null;
9
8
  // Vercel specific configs
10
9
  const rawIsr = extractIsr(page.config);
11
10
  let isr = assertIsr(rawIsr);
@@ -18,9 +17,11 @@ function getDeployConfigs(pageId, page) {
18
17
  if (edge && rawIsr !== null && typeof rawIsr === 'object') {
19
18
  assertUsage(false, `Page ${pageId}: ISR cannot be enabled for edge functions. Remove ${pc.cyan('isr')} config or set \`{ edge: false }\`.`);
20
19
  }
21
- if (isrOrEdge && routeIr) {
20
+ if (isrOrEdge && route) {
22
21
  return {
23
- route: [...new Set([...toRou3(routeIr), ...getPageContextRoute(routeIr)])],
22
+ route,
23
+ // route: [...new Set([...toRou3(routeIr), ...getPageContextRoute(routeIr)])],
24
+ // Supported by vite-plugin-vercel@11
24
25
  vercel: {
25
26
  isr: isr ? { expiration: isr } : undefined,
26
27
  edge: Boolean(edge),
@@ -29,13 +30,11 @@ function getDeployConfigs(pageId, page) {
29
30
  }
30
31
  return null;
31
32
  }
32
- function extractIsr(exports) {
33
- if (exports === null || typeof exports !== 'object')
34
- return null;
35
- if (!('isr' in exports))
33
+ function extractIsr(pageConfig) {
34
+ if (!pageConfig.isr)
36
35
  return null;
37
- const isr = exports.isr;
38
- assertUsage(typeof isr === 'object' &&
36
+ const isr = pageConfig.isr;
37
+ assertUsage(isObject(isr) &&
39
38
  typeof isr.expiration === 'number' &&
40
39
  isr.expiration > 0, ' `{ expiration }` must be a positive number');
41
40
  return isr;
@@ -54,20 +53,18 @@ function extractEdge(exports) {
54
53
  assertUsage(typeof edge === 'boolean', ' `{ edge }` must be a boolean');
55
54
  return edge;
56
55
  }
57
- function getPageContextRoute(routeIr) {
56
+ export function getPageContextRoute(routeIr) {
58
57
  const lastSegment = routeIr.pathname.at(-1);
59
58
  assert(lastSegment);
60
- if (!lastSegment.catchAll) {
61
- const pageContextIr = {
62
- pathname: [
63
- ...routeIr.pathname.slice(0, -1),
64
- {
65
- ...lastSegment,
66
- value: `${lastSegment.value}.pageContext.json`,
67
- },
68
- ],
69
- };
70
- return toRou3(pageContextIr);
71
- }
72
- return [];
59
+ if (lastSegment.catchAll)
60
+ return;
61
+ return {
62
+ pathname: [
63
+ ...routeIr.pathname.slice(0, -1),
64
+ {
65
+ ...lastSegment,
66
+ value: `${lastSegment.value}.pageContext.json`,
67
+ },
68
+ ],
69
+ };
73
70
  }
@@ -0,0 +1,7 @@
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;
@@ -0,0 +1,33 @@
1
+ import { assert } from '../../../../utils/assert.js';
2
+ import { catchAllEntry } from '@universal-deploy/store';
3
+ import '../../assertEnvVite.js';
4
+ export function getServerInfo(vikeConfig) {
5
+ let serverEntryId;
6
+ let serverFilePath = null;
7
+ const serverConfig = vikeConfig.config.server;
8
+ // universal-deploy support manually disabled by user
9
+ if (serverConfig === false)
10
+ return;
11
+ const serverPlusFile = vikeConfig._pageConfigGlobal.configValueSources.server?.[0];
12
+ if (serverPlusFile) {
13
+ assert('filePathAbsoluteFilesystem' in serverPlusFile.definedAt);
14
+ serverFilePath = serverPlusFile.definedAt.filePathAbsoluteFilesystem;
15
+ assert(serverFilePath);
16
+ serverEntryId = serverFilePath;
17
+ }
18
+ else {
19
+ serverEntryId = catchAllEntry;
20
+ }
21
+ if (serverConfig !== true && !serverFilePath)
22
+ return;
23
+ const serverEntryVike = serverFilePath ?? 'vike/fetch';
24
+ return {
25
+ // Used to filter which module ID to transform.
26
+ // It points to a fully resolved server entry or the virtual universal-deploy catchAll entry.
27
+ serverEntryId,
28
+ // This entry will be pushed to universal-deploy via `addEntry`.
29
+ // It either points to the default fetchable endpoint (vike/fetch), or one defined by the user through +server.
30
+ serverEntryVike,
31
+ serverFilePath,
32
+ };
33
+ }
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ import '../../assertEnvVite.js';
3
+ export declare function pluginResolveAlias(): Plugin;
@@ -0,0 +1,19 @@
1
+ import { pluginCommon } from './common.js';
2
+ import { escapeRegex } from '../../../../utils/escapeRegex.js';
3
+ import { catchAllEntry } from '@universal-deploy/store';
4
+ import '../../assertEnvVite.js';
5
+ export function pluginResolveAlias() {
6
+ return {
7
+ name: 'vike:pluginUniversalDeploy:alias',
8
+ resolveId: {
9
+ filter: {
10
+ // User facing alias for virtual:ud:catch-all
11
+ id: new RegExp(escapeRegex('vike:server-entry')),
12
+ },
13
+ handler() {
14
+ return this.resolve(catchAllEntry);
15
+ },
16
+ },
17
+ ...pluginCommon,
18
+ };
19
+ }
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from 'vite';
2
+ import '../../assertEnvVite.js';
3
+ /**
4
+ * If +server.js is defined, make virtual:ud:catch-all resolve to +server.js absolute path
5
+ */
6
+ export declare function pluginVikeVirtualEntry(serverFilePath: string): Plugin;
@@ -0,0 +1,22 @@
1
+ import { pluginCommon } from './common.js';
2
+ import { escapeRegex } from '../../../../utils/escapeRegex.js';
3
+ import '../../assertEnvVite.js';
4
+ /**
5
+ * If +server.js is defined, make virtual:ud:catch-all resolve to +server.js absolute path
6
+ */
7
+ export function pluginVikeVirtualEntry(serverFilePath) {
8
+ return {
9
+ name: 'vike:pluginUniversalDeploy:server',
10
+ resolveId: {
11
+ order: 'pre',
12
+ filter: {
13
+ id: new RegExp(escapeRegex(serverFilePath)),
14
+ },
15
+ handler() {
16
+ // Will resolve the entry from the users project root
17
+ return this.resolve(serverFilePath);
18
+ },
19
+ },
20
+ ...pluginCommon,
21
+ };
22
+ }
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ import '../../assertEnvVite.js';
3
+ export declare function pluginUnwrapProdOptions(serverFilePath: string): Plugin;
@@ -0,0 +1,19 @@
1
+ import { wrapper } from 'vite-plugin-wrapper';
2
+ import { escapeRegex } from '../../../../utils/escapeRegex.js';
3
+ import '../../assertEnvVite.js';
4
+ export function pluginUnwrapProdOptions(serverFilePath) {
5
+ return wrapper({
6
+ resolveId: {
7
+ filter: {
8
+ id: new RegExp(escapeRegex(serverFilePath)),
9
+ },
10
+ },
11
+ // Unwrap all prod.* options
12
+ load(id) {
13
+ return `
14
+ import mod from ${JSON.stringify(id)};
15
+ export default { ...mod, ...mod?.prod };
16
+ `;
17
+ },
18
+ });
19
+ }
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ import '../../assertEnvVite.js';
3
+ export declare function pluginVikeVirtualEntry(serverEntryId: string): Plugin;
@@ -0,0 +1,25 @@
1
+ import { getMagicString } from '../../shared/getMagicString.js';
2
+ import { serverEntryVirtualId as vikeVirtualEntry } from '@brillout/vite-plugin-server-entry/plugin';
3
+ import { pluginCommon } from './common.js';
4
+ import '../../assertEnvVite.js';
5
+ export function pluginVikeVirtualEntry(serverEntryId) {
6
+ return {
7
+ name: 'vike:pluginUniversalDeploy:serverEntry',
8
+ apply: 'build',
9
+ transform: {
10
+ order: 'post',
11
+ filter: {
12
+ id: {
13
+ include: [serverEntryId],
14
+ },
15
+ },
16
+ handler(code, id) {
17
+ const { magicString, getMagicStringResult } = getMagicString(code, id);
18
+ // Inject Vike virtual server entry
19
+ magicString.prepend(`import "${vikeVirtualEntry}";\n`);
20
+ return getMagicStringResult();
21
+ },
22
+ },
23
+ ...pluginCommon,
24
+ };
25
+ }
@@ -1,155 +1,58 @@
1
+ import { toRou3 } from 'convert-route';
1
2
  export { pluginUniversalDeploy };
2
3
  import { addEntry } from '@universal-deploy/store';
3
- import { node } from '@universal-deploy/node/vite';
4
- import { catchAll, devServer } from '@universal-deploy/store/vite';
5
- import { serverEntryVirtualId as vikeEntryId } from '@brillout/vite-plugin-server-entry/plugin';
6
- import { getMagicString } from '../shared/getMagicString.js';
7
- import { escapeRegex } from '../../../utils/escapeRegex.js';
8
- import { getDeployConfigs } from './pluginUniversalDeploy/getDeployConfigs.js';
9
- import { assert, assertUsage, assertWarning } from '../../../utils/assert.js';
10
- import { asyncFlatten } from '../../../utils/asyncFlatten.js';
4
+ import universalDeploy from '@universal-deploy/vite';
5
+ import { fromVike } from 'convert-route/vike';
6
+ import { pluginVikeVirtualEntry } from './pluginUniversalDeploy/pluginVikeVirtualEntry.js';
7
+ import { getDeployConfigs, getPageContextRoute } from './pluginUniversalDeploy/getDeployConfigs.js';
8
+ import { pluginCommon } from './pluginUniversalDeploy/common.js';
9
+ import { hasVikeServerOrVikePhoton } from './pluginUniversalDeploy/detectDeprecated.js';
10
+ import { getServerInfo } from './pluginUniversalDeploy/getServerInfo.js';
11
+ import { pluginResolveAlias } from './pluginUniversalDeploy/pluginResolveAlias.js';
12
+ import { pluginUnwrapProdOptions } from './pluginUniversalDeploy/pluginUnwrapProdOptions.js';
11
13
  import '../assertEnvVite.js';
12
- import pc from '@brillout/picocolors';
13
- const virtualFileIdCatchAll = /^virtual:ud:catch-all$/;
14
+ import { unique } from '../../../utils/unique.js';
14
15
  function pluginUniversalDeploy(vikeConfig) {
15
16
  if (hasVikeServerOrVikePhoton(vikeConfig))
16
17
  return [];
17
- let serverEntryId = virtualFileIdCatchAll;
18
- let serverFilePath = null;
19
- const serverConfig = vikeConfig.config.server;
20
- if (serverConfig === false)
21
- return [];
22
- const serverPlusFile = vikeConfig._pageConfigGlobal.configValueSources.server?.[0];
23
- if (serverPlusFile) {
24
- assert('filePathAbsoluteFilesystem' in serverPlusFile.definedAt);
25
- serverFilePath = serverPlusFile.definedAt.filePathAbsoluteFilesystem;
26
- assert(serverFilePath);
27
- serverEntryId = new RegExp(escapeRegex(serverFilePath));
28
- }
29
- if (serverConfig !== true && !serverFilePath)
18
+ const serverInfo = getServerInfo(vikeConfig);
19
+ if (!serverInfo)
30
20
  return [];
21
+ const { serverEntryVike, serverEntryId, serverFilePath } = serverInfo;
31
22
  const plugins = [
32
- catchAll(),
33
- devServer(),
34
- // Enable node adapter only if +server is defined and no other deployment target has been found
35
- ...node({ importer: 'vike' }).map((p) =>
36
- // Disable node() plugin later when Vite's config() hook runs, because noDeploymentTargetFound() requires `config`
37
- enablePluginIf((config) => noDeploymentTargetFound(config), p)),
23
+ ...universalDeploy(),
38
24
  {
39
25
  name: 'vike:pluginUniversalDeploy:entries',
40
26
  config() {
27
+ // Map each Vike route to universal-deploy
41
28
  for (const [pageId, page] of Object.entries(vikeConfig.pages)) {
42
29
  const deployConfigs = getDeployConfigs(pageId, page);
30
+ // Skip pages without deploy configs, as they will be handled by the catch-all route
43
31
  if (deployConfigs !== null) {
32
+ const { route, ...additionalConfigs } = deployConfigs;
33
+ const routeIr = fromVike(route);
34
+ const pageContextRouteIr = getPageContextRoute(routeIr);
44
35
  addEntry({
45
- id: serverFilePath ?? 'vike/fetch',
46
- ...deployConfigs,
36
+ ...additionalConfigs,
37
+ id: serverEntryVike,
38
+ // Map Vike routes to rou3 format
39
+ route: unique([...toRou3(routeIr), ...(pageContextRouteIr ? toRou3(pageContextRouteIr) : [])]),
47
40
  });
48
41
  }
49
42
  }
50
43
  // Default catch-all route
51
44
  addEntry({
52
- id: serverFilePath ?? 'vike/fetch',
45
+ id: serverEntryVike,
53
46
  route: '/**',
54
47
  });
55
48
  },
56
- ...pluginOptions,
57
- },
58
- {
59
- name: 'vike:pluginUniversalDeploy:serverEntry',
60
- apply: 'build',
61
- transform: {
62
- order: 'post',
63
- filter: {
64
- id: {
65
- include: [serverEntryId],
66
- },
67
- },
68
- handler(code, id) {
69
- const { magicString, getMagicStringResult } = getMagicString(code, id);
70
- // Inject Vike virtual server entry
71
- magicString.prepend(`import "${vikeEntryId}";\n`);
72
- return getMagicStringResult();
73
- },
74
- },
75
- ...pluginOptions,
49
+ ...pluginCommon,
76
50
  },
51
+ pluginVikeVirtualEntry(serverFilePath ?? serverEntryId),
52
+ pluginResolveAlias(),
77
53
  ];
78
54
  if (serverFilePath) {
79
- plugins.push(
80
- // If +server.js is defined, make virtual:ud:catch-all resolve to +server.js absolute path
81
- {
82
- name: 'vike:pluginUniversalDeploy:server',
83
- resolveId: {
84
- order: 'pre',
85
- filter: {
86
- id: virtualFileIdCatchAll,
87
- },
88
- handler() {
89
- // Will resolve the entry from the users project root
90
- return this.resolve(serverFilePath);
91
- },
92
- },
93
- ...pluginOptions,
94
- });
55
+ plugins.push(pluginUnwrapProdOptions(serverFilePath));
95
56
  }
96
57
  return plugins;
97
58
  }
98
- const pluginOptions = {
99
- applyToEnvironment(env) {
100
- return env.config.consumer === 'server';
101
- },
102
- sharedDuringBuild: true,
103
- };
104
- /**
105
- * Enables a plugin based on a specified condition callback which will be executed in the `config` hook.
106
- */
107
- function enablePluginIf(condition, originalPlugin) {
108
- const originalConfig = originalPlugin.config;
109
- originalPlugin.config = {
110
- order: originalConfig && 'order' in originalConfig ? originalConfig.order : 'pre',
111
- async handler(c, e) {
112
- const enabled = await condition.call(this, c, e);
113
- if (!enabled) {
114
- const keysToDelete = Object.keys(originalPlugin).filter((k) => k !== 'name');
115
- originalPlugin.name += ':disabled';
116
- for (const key of keysToDelete) {
117
- // @ts-expect-error
118
- delete originalPlugin[key];
119
- }
120
- }
121
- else if (originalConfig) {
122
- if (typeof originalConfig === 'function') {
123
- return originalConfig.call(this, c, e);
124
- }
125
- return originalConfig.handler.call(this, c, e);
126
- }
127
- },
128
- };
129
- return originalPlugin;
130
- }
131
- // Disable a plugin if one of the following plugin is present
132
- // - vite-plugin-vercel
133
- // - @cloudflare/vite-plugin
134
- async function noDeploymentTargetFound(c) {
135
- const plugins = (await asyncFlatten((c.plugins ?? []))).filter((p) => Boolean(p));
136
- assertUsage(!plugins.some((p) => p.name.startsWith('photon:target-loader:vercel')), 'Replace `@photonjs/vercel` by `vite-plugin-vercel@11`, see https://vike.dev/migration/universal-deploy');
137
- assertUsage(!plugins.some((p) => p.name.startsWith('photon:target-loader:cloudflare')), 'Replace `@photonjs/cloudflare` by `@cloudflare/vite-plugin`, see https://vike.dev/migration/universal-deploy');
138
- // vite-plugin-vercel
139
- const vitePluginVercel = plugins.some((p) => p.name.match(/^vite-plugin-vercel:(?!.*:disabled$)/));
140
- // @cloudflare/vite-plugin
141
- const cloudflareVitePlugin = plugins.some((p) => p.name.match(/^vite-plugin-cloudflare:(?!.*:disabled$)/));
142
- return !vitePluginVercel && !cloudflareVitePlugin;
143
- }
144
- function hasVikeServerOrVikePhoton(vikeConfig) {
145
- const vikeExtendsNames = new Set(vikeConfig._extensions.map((plusFile) => ('fileExportsByConfigName' in plusFile ? plusFile.fileExportsByConfigName : {}).name));
146
- const vikeServerOrVikePhoton = vikeExtendsNames.has('vike-server')
147
- ? 'vike-server'
148
- : vikeExtendsNames.has('vike-photon')
149
- ? 'vike-photon'
150
- : null;
151
- if (vikeServerOrVikePhoton) {
152
- assertWarning(false, `${pc.cyan(vikeServerOrVikePhoton)} is deprecated, see ${pc.underline('https://vike.dev/migration/universal-deploy')}`, { onlyOnce: true });
153
- return true;
154
- }
155
- }
@@ -528,7 +528,7 @@ type ConfigBuiltIn = {
528
528
  *
529
529
  * https://vike.dev/server
530
530
  */
531
- server?: boolean;
531
+ server?: boolean | ImportStringList;
532
532
  cli?: {
533
533
  /** @experimental
534
534
  *
@@ -0,0 +1,8 @@
1
+ import type { Fetchable, ServerOptions } from '@universal-deploy/store';
2
+ /** Server options.
3
+ *
4
+ * https://vike.dev/server
5
+ */
6
+ export interface Server extends Fetchable {
7
+ prod?: Omit<ServerOptions, 'fetch'>;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -51,3 +51,4 @@ import { PageContextBuiltInServer } from './PageContext.js';
51
51
  */
52
52
  type PageContextBuiltIn<Page = any> = PageContextBuiltInServer<Page>;
53
53
  export type { PageContextBuiltIn };
54
+ export type { Server } from './Server.js';
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.255-commit-05a7b95";
1
+ export declare const PROJECT_VERSION: "0.4.256-commit-414bdc0";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.255-commit-05a7b95';
2
+ export const PROJECT_VERSION = '0.4.256-commit-414bdc0';
@@ -14,9 +14,9 @@ function assertKeys(obj, keysExpected, errPrefix) {
14
14
  assertUsage(false, [
15
15
  errPrefix,
16
16
  `unknown key${keysUnknown.length === 1 ? '' : 's'}`,
17
- joinEnglish(keysUnknown, 'and', pc.cyan) + '.',
17
+ joinEnglish(keysUnknown, 'and', { color: pc.cyan }) + '.',
18
18
  'Only following keys are allowed:',
19
- joinEnglish(keysExpected, 'and', pc.cyan) + '.',
19
+ joinEnglish(keysExpected, 'and', { color: pc.cyan }) + '.',
20
20
  ].join(' '));
21
21
  }
22
22
  }
@@ -8,5 +8,5 @@ function assertNodeVersion() {
8
8
  const version = process.versions.node;
9
9
  assertVersion('Node.js', version,
10
10
  // https://gist.github.com/brillout/8e0133716e169b981b6c4e8a938b0134
11
- ['20.19.0', '22.12.0', '23.0.0']);
11
+ ['20.19.0', '22.12.0']);
12
12
  }
@@ -6,7 +6,7 @@ import { assertIsNotBrowser } from './assertIsNotBrowser.js';
6
6
  import { joinEnglish } from './joinEnglish.js';
7
7
  assertIsNotBrowser();
8
8
  function assertVersion(dependencyName, versionActual, versionExpectedList) {
9
- assertUsage(isVersionMatch(versionActual, versionExpectedList), `${pc.bold(dependencyName)} ${pc.red(pc.bold(versionActual))} isn't supported, use ${pc.bold(dependencyName)} ${joinEnglish([...versionExpectedList, 'above'].map((v) => pc.green(pc.bold(v))), 'or')}.`);
9
+ assertUsage(isVersionMatch(versionActual, versionExpectedList), `${pc.bold(dependencyName)} ${pc.red(pc.bold(versionActual))} isn't supported, use ${pc.bold(dependencyName)} ${joinEnglish([...versionExpectedList, 'above'].map((v) => pc.green(pc.bold(v))), 'or', { trailingComma: false })}.`);
10
10
  }
11
11
  function isVersionMatch(versionActual, versionExpectedList) {
12
12
  assert(versionActual);
@@ -1,2 +1,5 @@
1
1
  export { joinEnglish };
2
- declare function joinEnglish(arr: string[] | readonly string[], conjunction: 'or' | 'and', colorizer?: (s: string) => string): string;
2
+ declare function joinEnglish(arr: string[] | readonly string[], conjunction: 'or' | 'and', { color, trailingComma }?: {
3
+ color?: (s: string) => string;
4
+ trailingComma?: boolean;
5
+ }): string;
@@ -1,12 +1,12 @@
1
1
  export { joinEnglish };
2
2
  import { assert } from './assert.js';
3
3
  // https://stackoverflow.com/questions/53879088/join-an-array-by-commas-and-and/53879103#53879103
4
- function joinEnglish(arr, conjunction, colorizer = (s) => s) {
4
+ function joinEnglish(arr, conjunction, { color = (s) => s, trailingComma = true } = {}) {
5
5
  assert(arr.length > 0);
6
6
  if (arr.length === 1)
7
- return colorizer(arr[0]);
7
+ return color(arr[0]);
8
8
  const firsts = arr.slice(0, arr.length - 1);
9
9
  const last = arr[arr.length - 1];
10
- const lastComma = arr.length > 2 ? ',' : '';
11
- return firsts.map(colorizer).join(', ') + `${lastComma} ${conjunction} ` + colorizer(last);
10
+ const lastComma = trailingComma && arr.length > 2 ? ',' : '';
11
+ return firsts.map(color).join(', ') + `${lastComma} ${conjunction} ` + color(last);
12
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.255-commit-05a7b95",
3
+ "version": "0.4.256-commit-414bdc0",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -132,8 +132,8 @@
132
132
  "@brillout/json-serializer": "^0.5.22",
133
133
  "@brillout/picocolors": "^1.0.30",
134
134
  "@brillout/vite-plugin-server-entry": "0.7.18",
135
- "@universal-deploy/node": "^0.1.2",
136
- "@universal-deploy/store": "^0.1.4",
135
+ "@universal-deploy/store": "^0.2.1",
136
+ "@universal-deploy/vite": "^0.1.1",
137
137
  "@universal-middleware/core": "^0.4.17",
138
138
  "@universal-middleware/node": "^0.1.0",
139
139
  "cac": "^6.0.0",
@@ -142,12 +142,13 @@
142
142
  "esbuild": ">=0.19.0",
143
143
  "json5": "^2.0.0",
144
144
  "magic-string": "^0.30.17",
145
- "picomatch": "^4.0.2",
146
- "semver": "^7.0.0",
147
- "sirv": "^3.0.1",
145
+ "picomatch": "^4.0.4",
146
+ "semver": "^7.7.4",
147
+ "sirv": "^3.0.2",
148
148
  "source-map-support": "^0.5.0",
149
149
  "tinyglobby": "^0.2.10",
150
- "vite": ">=6.3.0"
150
+ "vite": ">=6.3.0",
151
+ "vite-plugin-wrapper": "^0.1.0"
151
152
  },
152
153
  "peerDependencies": {
153
154
  "react-streaming": ">=0.3.42",
@@ -265,11 +266,11 @@
265
266
  "@types/babel__core": "^7.20.5",
266
267
  "@types/estree": "^1.0.5",
267
268
  "@types/node": "^20.10.5",
268
- "@types/picomatch": "^3.0.2",
269
- "@types/semver": "^7.5.8",
269
+ "@types/picomatch": "^4.0.2",
270
+ "@types/semver": "^7.7.1",
270
271
  "@types/source-map-support": "^0.5.10",
271
- "react-streaming": "^0.4.16",
272
- "rimraf": "^5.0.5",
272
+ "react-streaming": "^0.4.17",
273
+ "rimraf": "^6.1.3",
273
274
  "typescript": "^5.9.3",
274
275
  "vite": "^7.2.6"
275
276
  },
@@ -1,4 +0,0 @@
1
- export { asyncFlatten };
2
- export type { AsyncFlatten };
3
- type AsyncFlatten<T extends unknown[]> = T extends (infer U)[] ? Exclude<Awaited<U>, U[]>[] : never;
4
- declare function asyncFlatten<T extends unknown[]>(arr: T): Promise<AsyncFlatten<T>>;
@@ -1,7 +0,0 @@
1
- export { asyncFlatten };
2
- async function asyncFlatten(arr) {
3
- do {
4
- arr = (await Promise.all(arr)).flat(Infinity);
5
- } while (arr.some((v) => v?.then));
6
- return arr;
7
- }