vike 0.4.246 → 0.4.247-commit-a642bde

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.
@@ -89,7 +89,7 @@ async function getViteInfo(viteConfigFromUserVikeApiOptions, viteContext) {
89
89
  // Show a warning because Vike supports Vite's CLI (as well as third-party CLIs).
90
90
  // - Encourage users to define a vite.config.js file that also works with Vite's CLI (and potentially other third-party CLIs).
91
91
  // - Vike-based frameworks, such as DocPress, allow their users to omit defining a vite.config.js file.
92
- assertWarning(viteConfigFromUserViteConfigFile, // Only show the warning if the user defined a vite.config.js file
92
+ assertWarning(!viteConfigFromUserViteConfigFile, // Only show the warning if the user defined a vite.config.js file
93
93
  "Omitting Vike's Vite plugin (inside your vite.config.js) is deprecated — make sure to always add Vike's Vite plugin https://vike.dev/vite-plugin", { onlyOnce: true });
94
94
  // Add Vike to plugins if not present.
95
95
  // Using a dynamic import because the script calling the Vike API may not live in the same place as vite.config.js, thus vike/plugin may resolved to two different node_modules/vike directories.
@@ -30,24 +30,12 @@ const virtualFileIdPageEntryPrefix =
30
30
  const virtualFileIdGlobalEntryPrefix =
31
31
  //
32
32
  'virtual:vike:global-entry:';
33
- const virtualFileIdGlobalEntries = [
34
- virtualFileIdGlobalEntryServer,
35
- virtualFileIdGlobalEntryClientCR,
36
- virtualFileIdGlobalEntryClientSR,
37
- ];
38
- assert(virtualFileIdGlobalEntries.every((v) =>
39
- //
40
- v.startsWith(virtualFileIdGlobalEntryPrefix)));
41
- assert([virtualFileIdPageEntryClient, virtualFileIdPageEntryServer].every((v) =>
42
- //
43
- v.startsWith(virtualFileIdPageEntryPrefix)));
44
33
  function parseVirtualFileId(id) {
45
34
  id = removeVirtualFileIdPrefix(id);
46
35
  if (!id.startsWith(virtualFileIdGlobalEntryPrefix) && !id.startsWith(virtualFileIdPageEntryPrefix))
47
36
  return false;
48
37
  // Global entry
49
38
  if (id.includes(virtualFileIdGlobalEntryPrefix)) {
50
- assert(virtualFileIdGlobalEntries.includes(id));
51
39
  const isForClientSide = id !== virtualFileIdGlobalEntryServer;
52
40
  const isClientRouting = id === virtualFileIdGlobalEntryClientCR;
53
41
  return {
@@ -58,23 +46,26 @@ function parseVirtualFileId(id) {
58
46
  }
59
47
  // Page entry
60
48
  if (id.includes(virtualFileIdPageEntryPrefix)) {
61
- assert(id.startsWith(virtualFileIdPageEntryPrefix));
62
49
  const idOriginal = id;
63
50
  id = extractAssetsRemoveQuery(id);
64
51
  const isExtractAssets = idOriginal !== id;
65
52
  if (id.startsWith(virtualFileIdPageEntryClient)) {
66
53
  assert(isExtractAssets === false);
54
+ const pageIdSerialized = id.slice(virtualFileIdPageEntryClient.length);
55
+ const pageId = deserializePageId(pageIdSerialized);
67
56
  return {
68
57
  type: 'page-entry',
69
- pageId: id.slice(virtualFileIdPageEntryClient.length),
58
+ pageId,
70
59
  isForClientSide: true,
71
60
  isExtractAssets,
72
61
  };
73
62
  }
74
63
  if (id.startsWith(virtualFileIdPageEntryServer)) {
64
+ const pageIdSerialized = id.slice(virtualFileIdPageEntryServer.length);
65
+ const pageId = deserializePageId(pageIdSerialized);
75
66
  return {
76
67
  type: 'page-entry',
77
- pageId: id.slice(virtualFileIdPageEntryServer.length),
68
+ pageId,
78
69
  isForClientSide: false,
79
70
  isExtractAssets,
80
71
  };
@@ -86,7 +77,6 @@ function parseVirtualFileId(id) {
86
77
  function generateVirtualFileId(args) {
87
78
  if (args.type === 'global-entry') {
88
79
  const { isForClientSide, isClientRouting } = args;
89
- assert(typeof isClientRouting === 'boolean');
90
80
  if (!isForClientSide) {
91
81
  return virtualFileIdGlobalEntryServer;
92
82
  }
@@ -99,9 +89,20 @@ function generateVirtualFileId(args) {
99
89
  }
100
90
  if (args.type === 'page-entry') {
101
91
  const { pageId, isForClientSide } = args;
102
- assert(typeof pageId === 'string');
103
- const id = `${isForClientSide ? virtualFileIdPageEntryClient : virtualFileIdPageEntryServer}${pageId}`;
92
+ const pageIdSerialized = serializePageId(pageId);
93
+ const id = `${isForClientSide ? virtualFileIdPageEntryClient : virtualFileIdPageEntryServer}${pageIdSerialized}`;
104
94
  return id;
105
95
  }
106
96
  assert(false);
107
97
  }
98
+ // Workaround:
99
+ // - We replace virtual:vike:page-entry:client:/ with virtual:vike:page-entry:client:ROOT
100
+ // - In order to avoid Vite to replace `virtual:vike:page-entry:client:/` with `virtual:vike:page-entry:client:`
101
+ // - I guess Vite/Rollup mistakenly treat the virtual ID as a path and tries to normalize id
102
+ const ROOT = 'ROOT';
103
+ function serializePageId(pageId) {
104
+ return pageId === '/' ? ROOT : pageId;
105
+ }
106
+ function deserializePageId(pageId) {
107
+ return pageId === ROOT ? '/' : pageId;
108
+ }
@@ -1,22 +1,46 @@
1
1
  export { determineOptimizeDeps };
2
2
  import { findPageFiles } from '../../shared/findPageFiles.js';
3
- import { assert, assertIsImportPathNpmPackage, createDebugger, getNpmPackageName, isArray, isFilePathAbsoluteFilesystem, isVirtualFileId, } from '../../utils.js';
3
+ import { assert, assertIsImportPathNpmPackage, createDebugger, getNpmPackageName, isArray, isFilePathAbsoluteFilesystem, isVirtualFileId, requireResolveOptional, } from '../../utils.js';
4
4
  import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
5
5
  import { analyzeClientEntries } from '../build/pluginBuildConfig.js';
6
6
  import { virtualFileIdGlobalEntryClientCR, virtualFileIdGlobalEntryClientSR } from '../../../shared/virtualFileId.js';
7
7
  import { getFilePathResolved } from '../../shared/getFilePath.js';
8
8
  import { getConfigValueSourcesRelevant } from '../pluginVirtualFiles/getConfigValueSourcesRelevant.js';
9
9
  const debug = createDebugger('vike:optimizeDeps');
10
+ const WORKAROUND_LATE_DISCOVERY = [
11
+ // Workaround for https://github.com/vitejs/vite-plugin-react/issues/650
12
+ // - The issue was closed as completed with https://github.com/vitejs/vite/pull/20495 but it doesn't fix the issue and the workaround is still needed.
13
+ // - TO-DO/eventually: try removing the workaround and see if the CI fails (at test/@cloudflare_vite-plugin/) — maybe the issue will get fixed at some point.
14
+ 'react/jsx-dev-runtime',
15
+ // Workaround for https://github.com/vikejs/vike/issues/2823#issuecomment-3514325487
16
+ '@compiled/react/runtime',
17
+ ];
10
18
  async function determineOptimizeDeps(config) {
11
19
  const vikeConfig = await getVikeConfigInternal();
12
20
  const { _pageConfigs: pageConfigs } = vikeConfig;
13
21
  const { entriesClient, entriesServer, includeClient, includeServer } = await getPageDeps(config, pageConfigs);
22
+ WORKAROUND_LATE_DISCOVERY.forEach((dep) => {
23
+ const userRootDir = config.root;
24
+ const resolved = requireResolveOptional({ importPath: dep, userRootDir, importerFilePath: null });
25
+ const resolvedInsideRepo = resolved && resolved.startsWith(userRootDir);
26
+ if (resolvedInsideRepo) {
27
+ // We add `dep` only if `resolvedInsideRepo === true` otherwise Vite logs a warning like the following.
28
+ // - ```console
29
+ // [11:22:42.464][/examples/vue-full][npm run dev][stderr] Failed to resolve dependency: react/jsx-dev-runtime, present in client 'optimizeDeps.include'
30
+ // ```
31
+ // - ```console
32
+ // [12:24:53.225][/test/@cloudflare_vite-plugin/test-dev.test.ts][npm run dev][stderr] Failed to resolve dependency: @compiled/react/runtime, present in ssr 'optimizeDeps.include'
33
+ // ```
34
+ includeClient.push(dep);
35
+ includeServer.push(dep);
36
+ }
37
+ else if (config.optimizeDeps.include?.includes(dep)) {
38
+ // Monorepo => always `resolvedInsideRepo === false` — we use this other approach to workaround missing 'react/jsx-dev-runtime'
39
+ includeServer.push(dep);
40
+ }
41
+ });
14
42
  config.optimizeDeps.include = add(config.optimizeDeps.include, includeClient);
15
43
  config.optimizeDeps.entries = add(config.optimizeDeps.entries, entriesClient);
16
- // Workaround for https://github.com/vitejs/vite-plugin-react/issues/650
17
- // - The issue was closed as completed with https://github.com/vitejs/vite/pull/20495 but it doesn't fix the issue and the workaround is still needed.
18
- // - TO-DO/eventually: try removing the workaround and see if the CI fails (at test/@cloudflare_vite-plugin/) — maybe the issue will get fixed at some point.
19
- includeServer.push('react/jsx-dev-runtime');
20
44
  for (const envName in config.environments) {
21
45
  const env = config.environments[envName];
22
46
  if (env.consumer === 'server' && env.optimizeDeps.noDiscovery === false) {
@@ -21,38 +21,21 @@ function pluginDev() {
21
21
  handler() {
22
22
  return {
23
23
  appType: 'custom',
24
- // TO-DO/next-major-release: remove (AFAICT we only need to use config.optimizeDeps for the old design)
25
24
  optimizeDeps: {
26
25
  exclude: [
27
- // We exclude Vike's client runtime to be able to use Vite's import.meta.glob()
26
+ // We must exclude Vike's client runtime so it can import virtual modules
28
27
  'vike/client',
29
28
  'vike/client/router',
30
- // It seems like client-side/isomorphic imports also need to be excluded, in order to avoid the following:
31
- // ```
32
- // Client runtime loaded twice https://vike.dev/client-runtime-duplicated
33
- // ```
34
- 'vike/routing',
35
- 'vike/getPageContext',
36
- // We exclude @brillout/json-serializer and @brillout/picocolors to avoid:
29
+ ],
30
+ include: [
31
+ // Avoid:
37
32
  // ```
38
33
  // 9:28:58 AM [vite] ✨ new dependencies optimized: @brillout/json-serializer/parse
39
34
  // 9:28:58 AM [vite] ✨ optimized dependencies changed. reloading
40
35
  // ```
41
- '@brillout/json-serializer/parse',
42
- '@brillout/json-serializer/stringify',
43
- '@brillout/picocolors',
44
- // We exclude all packages that depend on any optimizeDeps.exclude entry because, otherwise, the entry cannot be resolved when using pnpm. For example:
45
- // ```
46
- // Failed to resolve import "@brillout/json-serializer/parse" from "../../packages/vike-react-query/dist/renderer/VikeReactQueryWrapper.js". Does the file exist?
47
- // 343| // ../../node_modules/.pnpm/react-streaming@0.3.16_react-dom@18.2.0_react@18.2.0/node_modules/react-streaming/dist/esm/client/useAsync.js
48
- // 344| import { parse as parse2 } from "@brillout/json-serializer/parse";
49
- // ```
50
- // The source map is confusing, the import actually lives at node_modules/.vite/deps/vike-react-query_renderer_VikeReactQueryWrapper.js which contains:
51
- // ```js
52
- // // ../../node_modules/.pnpm/react-streaming@0.3.16_react-dom@18.2.0_react@18.2.0/node_modules/react-streaming/dist/esm/client/useAsync.js
53
- // import { parse as parse2 } from "@brillout/json-serializer/parse";
54
- // ```
55
- 'react-streaming',
36
+ 'vike > @brillout/json-serializer/parse',
37
+ 'vike > @brillout/json-serializer/stringify',
38
+ 'vike > @brillout/picocolors',
56
39
  ],
57
40
  },
58
41
  };
@@ -21,6 +21,8 @@ async function pluginViteConfigVikeExtensions() {
21
21
  }));
22
22
  const pluginsFromExtensions = (viteConfigFromExtensions.plugins ?? []);
23
23
  delete viteConfigFromExtensions.plugins;
24
+ // Avoid infinite loop
25
+ assertUsage(!pluginsFromExtensions.some((p) => p.name?.startsWith('vike:')), "Adding Vike's Vite plugin using +vite is forbidden");
24
26
  return [
25
27
  ...pluginsFromExtensions,
26
28
  {
@@ -73,8 +73,10 @@ function resolveImportPathWithNode(pointerImportData, importerFilePath, userRoot
73
73
  });
74
74
  if (!filePathAbsoluteFilesystem) {
75
75
  assert(!isImportPathRelative(pointerImportData.importPath));
76
+ /* This assertion fails if the npm package has a wrongly defined package.json#exports
76
77
  // Libraries don't use path aliases => filePathAbsoluteFilesystem should be defined
77
- assert(!importerFilePathAbsolute.includes('node_modules'));
78
+ assert(!importerFilePathAbsolute.includes('node_modules'))
79
+ */
78
80
  }
79
81
  return filePathAbsoluteFilesystem;
80
82
  }
@@ -1,3 +1,3 @@
1
1
  export { defineConfig };
2
2
  import type { Config } from './Config.js';
3
- declare function defineConfig(config: Config): Config;
3
+ declare function defineConfig<T extends Config>(config: T): T;
@@ -1,4 +1,6 @@
1
1
  export { defineConfig };
2
+ // For JavaScript users. AFAICT there isn't another practical reason to use defineConfig() instead of `Config`.
3
+ // https://github.com/vikejs/vike/issues/1156
2
4
  function defineConfig(config) {
3
5
  return config;
4
6
  }
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.246";
1
+ export declare const PROJECT_VERSION: "0.4.247-commit-a642bde";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.246';
2
+ export const PROJECT_VERSION = '0.4.247-commit-a642bde';
@@ -41,7 +41,7 @@ function assert(condition, debugInfo) {
41
41
  return null;
42
42
  }
43
43
  const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
44
- return pc.dim(`Debug info for Vike maintainers (you can ignore this): ${debugInfoSerialized}`);
44
+ return pc.dim(`Debug for maintainers (you can ignore this): ${debugInfoSerialized}`);
45
45
  })();
46
46
  const link = pc.underline('https://github.com/vikejs/vike/issues/new?template=bug.yml');
47
47
  let errMsg = [
@@ -5,7 +5,7 @@ export { requireResolveDistFile };
5
5
  export { getPackageNodeModulesDirectory };
6
6
  declare function requireResolveOptional({ importPath, importerFilePath, userRootDir, }: {
7
7
  importPath: string;
8
- importerFilePath: string;
8
+ importerFilePath: string | null;
9
9
  userRootDir: string;
10
10
  }): string | null;
11
11
  declare function requireResolveOptionalDir({ importPath, importerDir, userRootDir, }: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.246",
3
+ "version": "0.4.247-commit-a642bde",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -15,7 +15,8 @@
15
15
  "types": "./dist/esm/client/runtime-server-routing/index.d.ts"
16
16
  },
17
17
  "./types": {
18
- "types": "./dist/esm/types/index.d.ts"
18
+ "types": "./dist/esm/types/index.d.ts",
19
+ "default": "./dist/esm/types/index.js"
19
20
  },
20
21
  "./client/router": {
21
22
  "worker": "./dist/esm/node/client/router.js",