vike 0.4.206 → 0.4.208-commit-8d0a7ba

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 (27) hide show
  1. package/dist/cjs/__internal/index.js +13 -2
  2. package/dist/cjs/node/plugin/index.js +6 -7
  3. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +7 -3
  4. package/dist/cjs/node/plugin/plugins/buildConfig.js +1 -0
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -1
  6. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +12 -14
  7. package/dist/cjs/shared/page-configs/assertPlusFileExport.js +11 -10
  8. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  9. package/dist/cjs/utils/assert.js +1 -1
  10. package/dist/cjs/utils/path-shim.js +5 -0
  11. package/dist/esm/__internal/index.d.ts +2 -7
  12. package/dist/esm/__internal/index.js +14 -3
  13. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -0
  14. package/dist/esm/node/plugin/index.js +6 -7
  15. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +2 -0
  16. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +7 -3
  17. package/dist/esm/node/plugin/plugins/buildConfig.js +2 -1
  18. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -1
  19. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +12 -14
  20. package/dist/esm/shared/page-configs/Config.d.ts +1 -1
  21. package/dist/esm/shared/page-configs/assertPlusFileExport.js +11 -10
  22. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  23. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  24. package/dist/esm/utils/assert.js +1 -1
  25. package/dist/esm/utils/path-shim.js +5 -0
  26. package/dist/esm/utils/projectInfo.d.ts +1 -1
  27. package/package.json +4 -4
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.route = route;
4
4
  exports.getPagesAndRoutes = getPagesAndRoutes;
5
- exports.getPageFilesAllSafe = getPageFilesAllSafe;
5
+ exports.getMiddlewares = getMiddlewares;
6
6
  const index_js_1 = require("../shared/route/index.js");
7
7
  const getPageFiles_js_1 = require("../shared/getPageFiles.js");
8
8
  const globalContext_js_1 = require("../node/runtime/globalContext.js");
@@ -27,7 +27,18 @@ async function getPagesAndRoutes() {
27
27
  allPageIds
28
28
  };
29
29
  }
30
- // TODO: make it cleaner once the internal refactoring about global configs is done.
30
+ // TODO/eventually:
31
+ // - Remove the need for `isProduction` after Vike's CLI is implemented
32
+ // - Remove it in favor of https://vike.dev/getGlobalContext
33
+ async function getMiddlewares() {
34
+ const isProduction = process.env.NODE_ENV === 'production';
35
+ const { pageConfigs } = await getPageFilesAllSafe(isProduction);
36
+ const middlewares = pageConfigs[0].configValues.middleware.value.flat(Infinity);
37
+ return middlewares;
38
+ }
39
+ // TODO/eventually:
40
+ // - Make it cleaner once the internal refactoring about global configs is done.
41
+ // - Remove it in favor of https://vike.dev/getGlobalContext
31
42
  // Demo usage: https://github.com/vikejs/vike/pull/1823
32
43
  async function getPageFilesAllSafe(isProduction) {
33
44
  await (0, globalContext_js_1.initGlobalContext_getGlobalContextAsync)(isProduction);
@@ -62,13 +62,6 @@ function plugin(vikeConfig) {
62
62
  ];
63
63
  return plugins;
64
64
  }
65
- // Enable `const vike = require('vike/plugin')`.
66
- // - This lives at the end of the file to ensure it happens after all assignments to `exports`.
67
- // - This is only used for the CJS build; we wrap it in a try-catch for the ESM build.
68
- try {
69
- module.exports = Object.assign(exports.default, exports);
70
- }
71
- catch { }
72
65
  // Error upon wrong usage
73
66
  Object.defineProperty(plugin, 'apply', {
74
67
  enumerable: true,
@@ -80,3 +73,9 @@ Object.defineProperty(plugin, 'apply', {
80
73
  function assertViteVersion() {
81
74
  (0, utils_js_2.assertVersion)('Vite', vite_1.version, '5.1.0');
82
75
  }
76
+ // Ensures following works: `const vike = require('vike/plugin')` / `import vike from 'vike/plugin'`
77
+ // - It needs to live at the end of this file, in order to ensure we do it after all assignments to `exports`.
78
+ try {
79
+ module.exports = Object.assign(exports.default, exports);
80
+ }
81
+ catch { }
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.fixServerAssets = fixServerAssets;
7
7
  exports.fixServerAssets_isEnabled = fixServerAssets_isEnabled;
8
+ exports.fixServerAssets_assertCssCodeSplit = fixServerAssets_assertCssCodeSplit;
8
9
  exports.fixServerAssets_assertCssTarget = fixServerAssets_assertCssTarget;
9
10
  exports.fixServerAssets_assertCssTarget_populate = fixServerAssets_assertCssTarget_populate;
10
11
  const promises_1 = __importDefault(require("fs/promises"));
@@ -157,6 +158,10 @@ function getHash(src) {
157
158
  (0, utils_js_1.assert)(hash);
158
159
  return hash;
159
160
  }
161
+ // https://github.com/vikejs/vike/issues/1993
162
+ function fixServerAssets_assertCssCodeSplit(config) {
163
+ (0, utils_js_1.assertWarning)(config.build.cssCodeSplit, `${picocolors_1.default.cyan('build.cssCodeSplit')} shouldn't be set to ${picocolors_1.default.cyan('false')} (https://github.com/vikejs/vike/issues/1993)`, { onlyOnce: true });
164
+ }
160
165
  const targets = [];
161
166
  function fixServerAssets_assertCssTarget_populate(config) {
162
167
  const isServerSide = (0, utils_js_1.viteIsSSR)(config);
@@ -176,10 +181,9 @@ async function fixServerAssets_assertCssTarget(config) {
176
181
  targetsServer.forEach((targetServer) => {
177
182
  const targetCssResolvedServer = resolveCssTarget(targetServer);
178
183
  (0, utils_js_1.assertWarning)((0, utils_js_1.isEqualStringList)(targetCssResolvedClient, targetCssResolvedServer), [
179
- 'The CSS browser target must be the same for both client-side and server-side, but we got:',
184
+ 'The CSS browser target should be the same for both client-side and server-side (https://github.com/vikejs/vike/issues/1815#issuecomment-2507002979) but we got:',
180
185
  `Client-side: ${picocolors_1.default.cyan(JSON.stringify(targetCssResolvedClient))}`,
181
- `Server-side: ${picocolors_1.default.cyan(JSON.stringify(targetCssResolvedServer))}`,
182
- 'See https://github.com/vikejs/vike/issues/1815#issuecomment-2507002979 if you want to know why.'
186
+ `Server-side: ${picocolors_1.default.cyan(JSON.stringify(targetCssResolvedServer))}`
183
187
  ].join('\n'), {
184
188
  showStackTrace: true,
185
189
  onlyOnce: 'different-css-target'
@@ -55,6 +55,7 @@ function buildConfig() {
55
55
  // Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
56
56
  config.build.cssMinify = 'esbuild';
57
57
  (0, fixServerAssets_js_1.fixServerAssets_assertCssTarget_populate)(config);
58
+ (0, fixServerAssets_js_1.fixServerAssets_assertCssCodeSplit)(config);
58
59
  }
59
60
  }
60
61
  }
@@ -131,7 +131,9 @@ const configDefinitionsBuiltIn = {
131
131
  },
132
132
  keepScrollPosition: {
133
133
  env: { client: true }
134
- }
134
+ },
135
+ // TODO/eventually: define it as a global config.
136
+ middleware: { env: { server: true }, cumulative: true, eager: true }
135
137
  };
136
138
  exports.configDefinitionsBuiltIn = configDefinitionsBuiltIn;
137
139
  const configDefinitionsBuiltInGlobal = {
@@ -81,37 +81,35 @@ function processHookReturnValue(hookReturnValue, renderHook) {
81
81
  let pageContextPromise = null;
82
82
  let pageContextProvidedByRenderHook = null;
83
83
  let injectFilter = null;
84
- const ret = () => ({ documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter });
85
- if (hookReturnValue === null)
86
- return ret();
87
84
  if ((0, renderHtml_js_1.isDocumentHtml)(hookReturnValue)) {
88
85
  documentHtml = hookReturnValue;
89
- return ret();
86
+ return { documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter };
90
87
  }
91
88
  const errPrefix = `The ${renderHook.hookName}() hook defined at ${renderHook.hookFilePath}`;
92
- const errSuffix = `a string generated with the ${picocolors_1.default.cyan('escapeInject`<html>...</html>`')} template tag or a string returned by ${picocolors_1.default.cyan('dangerouslySkipEscape()')}, see https://vike.dev/escapeInject`;
89
+ const errSuffix = `a string generated with ${picocolors_1.default.cyan('escapeInject`<html>...</html>`')} or the value returned by ${picocolors_1.default.cyan('dangerouslySkipEscape()')}, see https://vike.dev/escapeInject`;
93
90
  if (typeof hookReturnValue === 'string') {
94
- (0, utils_js_1.assertWarning)(false, [errPrefix, 'returned a plain JavaScript string which is dangerous: it should instead return', errSuffix].join(' '), { onlyOnce: true });
91
+ (0, utils_js_1.assertWarning)(false, [
92
+ errPrefix,
93
+ `returned a plain JavaScript string which is ${picocolors_1.default.red(picocolors_1.default.bold('dangerous'))}: it should instead return`,
94
+ errSuffix
95
+ ].join(' '), { onlyOnce: true });
95
96
  hookReturnValue = (0, renderHtml_js_1.dangerouslySkipEscape)(hookReturnValue);
96
97
  }
97
- (0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(hookReturnValue), [
98
- errPrefix,
99
- `should return ${picocolors_1.default.cyan('null')}, the value ${picocolors_1.default.cyan('documentHtml')}, or an object ${picocolors_1.default.cyan('{ documentHtml, pageContext }')} where ${picocolors_1.default.cyan('pageContext')} is ${picocolors_1.default.cyan('undefined')} or an object holding additional pageContext values, and where ${picocolors_1.default.cyan('documentHtml')} is`,
100
- errSuffix
101
- ].join(' '));
98
+ const wrongReturnValue = `should return the value ${picocolors_1.default.cyan('documentHtml')} or an object ${picocolors_1.default.cyan('{ documentHtml }')} where ${picocolors_1.default.cyan('documentHtml')} is ${errSuffix}`;
99
+ (0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(hookReturnValue), `${errPrefix} ${wrongReturnValue}`);
102
100
  (0, assertHookReturnedObject_js_1.assertHookReturnedObject)(hookReturnValue, ['documentHtml', 'pageContext', 'injectFilter'], errPrefix);
101
+ (0, utils_js_1.assertUsage)(hookReturnValue.documentHtml, `${errPrefix} returned an object that is missing the ${picocolors_1.default.code('documentHtml')} property: it ${wrongReturnValue}`);
103
102
  if (hookReturnValue.injectFilter) {
104
103
  (0, utils_js_1.assertUsage)((0, utils_js_1.isCallable)(hookReturnValue.injectFilter), 'injectFilter should be a function');
105
104
  injectFilter = hookReturnValue.injectFilter;
106
105
  }
107
- (0, utils_js_1.assertUsage)(hookReturnValue.documentHtml, `${errPrefix} returned an object that is missing the ${picocolors_1.default.code('documentHtml')} property.`);
108
106
  {
109
107
  let val = hookReturnValue.documentHtml;
110
108
  const errBegin = `${errPrefix} returned ${picocolors_1.default.cyan('{ documentHtml }')}, but ${picocolors_1.default.cyan('documentHtml')}`;
111
109
  if (typeof val === 'string') {
112
110
  (0, utils_js_1.assertWarning)(false, [
113
111
  errBegin,
114
- `is a plain JavaScript string which is dangerous: ${picocolors_1.default.cyan('documentHtml')} should be`,
112
+ `is a plain JavaScript string which is ${picocolors_1.default.bold(picocolors_1.default.red('dangerous'))}: ${picocolors_1.default.cyan('documentHtml')} should be`,
115
113
  errSuffix
116
114
  ].join(' '), { onlyOnce: true });
117
115
  val = (0, renderHtml_js_1.dangerouslySkipEscape)(val);
@@ -132,5 +130,5 @@ function processHookReturnValue(hookReturnValue, renderHook) {
132
130
  pageContextProvidedByRenderHook = val;
133
131
  }
134
132
  }
135
- return ret();
133
+ return { documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter };
136
134
  }
@@ -6,34 +6,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.assertPlusFileExport = assertPlusFileExport;
7
7
  const utils_js_1 = require("../utils.js");
8
8
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
9
- const EXPORTS_IGNORE = [
9
+ const SIDE_EXPORTS_TOLERATE = [
10
10
  // vite-plugin-solid adds `export { $$registrations }`
11
11
  '$$registrations',
12
12
  // @vitejs/plugin-vue adds `export { _rerender_only }`
13
13
  '_rerender_only'
14
14
  ];
15
15
  // Tolerate `export { frontmatter }` in .mdx files
16
- const TOLERATE_SIDE_EXPORTS = ['.md', '.mdx'];
16
+ const SIDE_EXPORTS_DO_NOT_CHECK = ['.md', '.mdx'];
17
17
  function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
18
- const exportNames = Object.keys(fileExports).filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
18
+ const exportNames = Object.keys(fileExports);
19
19
  const isValid = (exportName) => exportName === 'default' || exportName === configName;
20
+ // Error upon missing/ambiguous export
20
21
  const exportNamesValid = exportNames.filter(isValid);
21
- const exportNamesInvalid = exportNames.filter((e) => !isValid(e));
22
- if (exportNamesValid.length === 1 && exportNamesInvalid.length === 0) {
23
- return;
24
- }
25
22
  const exportDefault = picocolors_1.default.code('export default');
26
23
  const exportNamed = picocolors_1.default.code(`export { ${configName} }`);
27
- (0, utils_js_1.assert)(exportNamesValid.length <= 2);
28
24
  if (exportNamesValid.length === 0) {
29
25
  (0, utils_js_1.assertUsage)(false, `${filePathToShowToUser} should have ${exportNamed} or ${exportDefault}`);
30
26
  }
31
27
  if (exportNamesValid.length === 2) {
32
28
  (0, utils_js_1.assertUsage)(false, `${filePathToShowToUser} is ambiguous: remove ${exportDefault} or ${exportNamed}`);
33
29
  }
34
- if (!TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext))) {
30
+ (0, utils_js_1.assert)(exportNamesValid.length === 1);
31
+ // Warn upon side exports
32
+ const exportNamesInvalid = exportNames
33
+ .filter((e) => !isValid(e))
34
+ .filter((exportName) => !SIDE_EXPORTS_TOLERATE.includes(exportName));
35
+ if (!SIDE_EXPORTS_DO_NOT_CHECK.some((ext) => filePathToShowToUser.endsWith(ext))) {
35
36
  exportNamesInvalid.forEach((exportInvalid) => {
36
- (0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} unexpected ${picocolors_1.default.cyan(`export { ${exportInvalid} }`)}`, {
37
+ (0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} unexpected ${picocolors_1.default.cyan(`export { ${exportInvalid} }`)}, see https://vike.dev/no-side-exports`, {
37
38
  onlyOnce: true
38
39
  });
39
40
  });
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.206';
5
+ exports.PROJECT_VERSION = '0.4.208-commit-8d0a7ba';
@@ -48,7 +48,7 @@ function assert(condition, debugInfo) {
48
48
  })();
49
49
  const link = picocolors_1.default.blue('https://github.com/vikejs/vike/issues/new');
50
50
  let errMsg = [
51
- `You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).`,
51
+ `You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually within 24 hours).`,
52
52
  debugStr
53
53
  ]
54
54
  .filter(Boolean)
@@ -12,3 +12,8 @@ function pathJoin(path1, path2) {
12
12
  joined = '/' + joined;
13
13
  return joined;
14
14
  }
15
+ /* https://github.com/brillout/telefunc/blob/0fd44322acbd07857ae29361ba7c998607f17dd5/telefunc/utils/path-shim.ts#L17-L21
16
+ function isAbsolute(filePath: string) {
17
+ // ...
18
+ }
19
+ */
@@ -1,6 +1,6 @@
1
1
  export { route, getPagesAndRoutes };
2
2
  export type { PageRoutes, PageFile, PageConfigRuntime as PageConfig };
3
- export { getPageFilesAllSafe };
3
+ export { getMiddlewares };
4
4
  import { route as routeInternal, type PageRoutes } from '../shared/route/index.js';
5
5
  import { type PageFile } from '../shared/getPageFiles.js';
6
6
  import { PageConfigRuntime } from '../shared/page-configs/PageConfig.js';
@@ -16,12 +16,7 @@ declare function getPagesAndRoutes(): Promise<{
16
16
  pageConfigs: PageConfigRuntime[];
17
17
  allPageIds: string[];
18
18
  }>;
19
- declare function getPageFilesAllSafe(isProduction: boolean): Promise<{
20
- pageFilesAll: PageFile[];
21
- allPageIds: string[];
22
- pageConfigs: PageConfigRuntime[];
23
- pageConfigGlobal: import("../shared/page-configs/PageConfig.js").PageConfigGlobalRuntime;
24
- }>;
19
+ declare function getMiddlewares(): Promise<unknown[]>;
25
20
  declare function route(pageContext: Parameters<typeof routeInternal>[0]): Promise<{
26
21
  pageContextAddendum: import("../shared/route/index.js").PageContextFromRoute;
27
22
  }>;
@@ -1,7 +1,7 @@
1
1
  // Internals needed by vite-plugin-vercel
2
2
  export { route, getPagesAndRoutes };
3
- // Internals needed by nitedani's experimental implementation of vike-telefunc
4
- export { getPageFilesAllSafe };
3
+ // Internals needed by experimental implementation of vike-telefunc
4
+ export { getMiddlewares };
5
5
  import { route as routeInternal } from '../shared/route/index.js';
6
6
  import { getPageFilesAll } from '../shared/getPageFiles.js';
7
7
  import { getGlobalContext, initGlobalContext_getGlobalContextAsync } from '../node/runtime/globalContext.js';
@@ -26,7 +26,18 @@ async function getPagesAndRoutes() {
26
26
  allPageIds
27
27
  };
28
28
  }
29
- // TODO: make it cleaner once the internal refactoring about global configs is done.
29
+ // TODO/eventually:
30
+ // - Remove the need for `isProduction` after Vike's CLI is implemented
31
+ // - Remove it in favor of https://vike.dev/getGlobalContext
32
+ async function getMiddlewares() {
33
+ const isProduction = process.env.NODE_ENV === 'production';
34
+ const { pageConfigs } = await getPageFilesAllSafe(isProduction);
35
+ const middlewares = pageConfigs[0].configValues.middleware.value.flat(Infinity);
36
+ return middlewares;
37
+ }
38
+ // TODO/eventually:
39
+ // - Make it cleaner once the internal refactoring about global configs is done.
40
+ // - Remove it in favor of https://vike.dev/getGlobalContext
30
41
  // Demo usage: https://github.com/vikejs/vike/pull/1823
31
42
  async function getPageFilesAllSafe(isProduction) {
32
43
  await initGlobalContext_getGlobalContextAsync(isProduction);
@@ -218,6 +218,7 @@ async function renderPageClientSide(renderArgs) {
218
218
  isBackwardNavigation,
219
219
  isClientSideNavigation,
220
220
  isHydration: isFirstRender && !isForErrorPage,
221
+ // Make it public as `pageContext.previous`? Maybe after https://github.com/vikejs/vike/issues/1268
221
222
  _previousPageContext: previousPageContext,
222
223
  ...pageContextInitClient
223
224
  });
@@ -56,13 +56,6 @@ function plugin(vikeConfig) {
56
56
  ];
57
57
  return plugins;
58
58
  }
59
- // Enable `const vike = require('vike/plugin')`.
60
- // - This lives at the end of the file to ensure it happens after all assignments to `exports`.
61
- // - This is only used for the CJS build; we wrap it in a try-catch for the ESM build.
62
- try {
63
- module.exports = Object.assign(exports.default, exports);
64
- }
65
- catch { }
66
59
  // Error upon wrong usage
67
60
  Object.defineProperty(plugin, 'apply', {
68
61
  enumerable: true,
@@ -74,3 +67,9 @@ Object.defineProperty(plugin, 'apply', {
74
67
  function assertViteVersion() {
75
68
  assertVersion('Vite', version, '5.1.0');
76
69
  }
70
+ // Ensures following works: `const vike = require('vike/plugin')` / `import vike from 'vike/plugin'`
71
+ // - It needs to live at the end of this file, in order to ensure we do it after all assignments to `exports`.
72
+ try {
73
+ module.exports = Object.assign(exports.default, exports);
74
+ }
75
+ catch { }
@@ -1,5 +1,6 @@
1
1
  export { fixServerAssets };
2
2
  export { fixServerAssets_isEnabled };
3
+ export { fixServerAssets_assertCssCodeSplit };
3
4
  export { fixServerAssets_assertCssTarget };
4
5
  export { fixServerAssets_assertCssTarget_populate };
5
6
  import { ViteManifest } from '../../../shared/ViteManifest.js';
@@ -13,5 +14,6 @@ import { ResolvedConfig } from 'vite';
13
14
  declare function fixServerAssets_isEnabled(): boolean;
14
15
  /** https://github.com/vikejs/vike/issues/1339 */
15
16
  declare function fixServerAssets(config: ResolvedConfig): Promise<ViteManifest>;
17
+ declare function fixServerAssets_assertCssCodeSplit(config: ResolvedConfig): void;
16
18
  declare function fixServerAssets_assertCssTarget_populate(config: ResolvedConfig): void;
17
19
  declare function fixServerAssets_assertCssTarget(config: ResolvedConfig): Promise<void>;
@@ -1,5 +1,6 @@
1
1
  export { fixServerAssets };
2
2
  export { fixServerAssets_isEnabled };
3
+ export { fixServerAssets_assertCssCodeSplit };
3
4
  export { fixServerAssets_assertCssTarget };
4
5
  export { fixServerAssets_assertCssTarget_populate };
5
6
  import fs from 'fs/promises';
@@ -152,6 +153,10 @@ function getHash(src) {
152
153
  assert(hash);
153
154
  return hash;
154
155
  }
156
+ // https://github.com/vikejs/vike/issues/1993
157
+ function fixServerAssets_assertCssCodeSplit(config) {
158
+ assertWarning(config.build.cssCodeSplit, `${pc.cyan('build.cssCodeSplit')} shouldn't be set to ${pc.cyan('false')} (https://github.com/vikejs/vike/issues/1993)`, { onlyOnce: true });
159
+ }
155
160
  const targets = [];
156
161
  function fixServerAssets_assertCssTarget_populate(config) {
157
162
  const isServerSide = viteIsSSR(config);
@@ -171,10 +176,9 @@ async function fixServerAssets_assertCssTarget(config) {
171
176
  targetsServer.forEach((targetServer) => {
172
177
  const targetCssResolvedServer = resolveCssTarget(targetServer);
173
178
  assertWarning(isEqualStringList(targetCssResolvedClient, targetCssResolvedServer), [
174
- 'The CSS browser target must be the same for both client-side and server-side, but we got:',
179
+ 'The CSS browser target should be the same for both client-side and server-side (https://github.com/vikejs/vike/issues/1815#issuecomment-2507002979) but we got:',
175
180
  `Client-side: ${pc.cyan(JSON.stringify(targetCssResolvedClient))}`,
176
- `Server-side: ${pc.cyan(JSON.stringify(targetCssResolvedServer))}`,
177
- 'See https://github.com/vikejs/vike/issues/1815#issuecomment-2507002979 if you want to know why.'
181
+ `Server-side: ${pc.cyan(JSON.stringify(targetCssResolvedServer))}`
178
182
  ].join('\n'), {
179
183
  showStackTrace: true,
180
184
  onlyOnce: 'different-css-target'
@@ -11,7 +11,7 @@ import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
11
11
  import { createRequire } from 'module';
12
12
  import fs from 'fs/promises';
13
13
  import path from 'path';
14
- import { fixServerAssets, fixServerAssets_assertCssTarget, fixServerAssets_assertCssTarget_populate, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
14
+ import { fixServerAssets, fixServerAssets_assertCssCodeSplit, fixServerAssets_assertCssTarget, fixServerAssets_assertCssTarget_populate, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
15
15
  import { set_ASSETS_MAP } from './importBuild/index.js';
16
16
  import { prependEntriesDir } from '../../shared/prependEntriesDir.js';
17
17
  import { getFilePathResolved } from '../shared/getFilePath.js';
@@ -49,6 +49,7 @@ function buildConfig() {
49
49
  // Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
50
50
  config.build.cssMinify = 'esbuild';
51
51
  fixServerAssets_assertCssTarget_populate(config);
52
+ fixServerAssets_assertCssCodeSplit(config);
52
53
  }
53
54
  }
54
55
  }
@@ -130,7 +130,9 @@ const configDefinitionsBuiltIn = {
130
130
  },
131
131
  keepScrollPosition: {
132
132
  env: { client: true }
133
- }
133
+ },
134
+ // TODO/eventually: define it as a global config.
135
+ middleware: { env: { server: true }, cumulative: true, eager: true }
134
136
  };
135
137
  const configDefinitionsBuiltInGlobal = {
136
138
  onPrerenderStart: {
@@ -76,37 +76,35 @@ function processHookReturnValue(hookReturnValue, renderHook) {
76
76
  let pageContextPromise = null;
77
77
  let pageContextProvidedByRenderHook = null;
78
78
  let injectFilter = null;
79
- const ret = () => ({ documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter });
80
- if (hookReturnValue === null)
81
- return ret();
82
79
  if (isDocumentHtml(hookReturnValue)) {
83
80
  documentHtml = hookReturnValue;
84
- return ret();
81
+ return { documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter };
85
82
  }
86
83
  const errPrefix = `The ${renderHook.hookName}() hook defined at ${renderHook.hookFilePath}`;
87
- const errSuffix = `a string generated with the ${pc.cyan('escapeInject`<html>...</html>`')} template tag or a string returned by ${pc.cyan('dangerouslySkipEscape()')}, see https://vike.dev/escapeInject`;
84
+ const errSuffix = `a string generated with ${pc.cyan('escapeInject`<html>...</html>`')} or the value returned by ${pc.cyan('dangerouslySkipEscape()')}, see https://vike.dev/escapeInject`;
88
85
  if (typeof hookReturnValue === 'string') {
89
- assertWarning(false, [errPrefix, 'returned a plain JavaScript string which is dangerous: it should instead return', errSuffix].join(' '), { onlyOnce: true });
86
+ assertWarning(false, [
87
+ errPrefix,
88
+ `returned a plain JavaScript string which is ${pc.red(pc.bold('dangerous'))}: it should instead return`,
89
+ errSuffix
90
+ ].join(' '), { onlyOnce: true });
90
91
  hookReturnValue = dangerouslySkipEscape(hookReturnValue);
91
92
  }
92
- assertUsage(isObject(hookReturnValue), [
93
- errPrefix,
94
- `should return ${pc.cyan('null')}, the value ${pc.cyan('documentHtml')}, or an object ${pc.cyan('{ documentHtml, pageContext }')} where ${pc.cyan('pageContext')} is ${pc.cyan('undefined')} or an object holding additional pageContext values, and where ${pc.cyan('documentHtml')} is`,
95
- errSuffix
96
- ].join(' '));
93
+ const wrongReturnValue = `should return the value ${pc.cyan('documentHtml')} or an object ${pc.cyan('{ documentHtml }')} where ${pc.cyan('documentHtml')} is ${errSuffix}`;
94
+ assertUsage(isObject(hookReturnValue), `${errPrefix} ${wrongReturnValue}`);
97
95
  assertHookReturnedObject(hookReturnValue, ['documentHtml', 'pageContext', 'injectFilter'], errPrefix);
96
+ assertUsage(hookReturnValue.documentHtml, `${errPrefix} returned an object that is missing the ${pc.code('documentHtml')} property: it ${wrongReturnValue}`);
98
97
  if (hookReturnValue.injectFilter) {
99
98
  assertUsage(isCallable(hookReturnValue.injectFilter), 'injectFilter should be a function');
100
99
  injectFilter = hookReturnValue.injectFilter;
101
100
  }
102
- assertUsage(hookReturnValue.documentHtml, `${errPrefix} returned an object that is missing the ${pc.code('documentHtml')} property.`);
103
101
  {
104
102
  let val = hookReturnValue.documentHtml;
105
103
  const errBegin = `${errPrefix} returned ${pc.cyan('{ documentHtml }')}, but ${pc.cyan('documentHtml')}`;
106
104
  if (typeof val === 'string') {
107
105
  assertWarning(false, [
108
106
  errBegin,
109
- `is a plain JavaScript string which is dangerous: ${pc.cyan('documentHtml')} should be`,
107
+ `is a plain JavaScript string which is ${pc.bold(pc.red('dangerous'))}: ${pc.cyan('documentHtml')} should be`,
110
108
  errSuffix
111
109
  ].join(' '), { onlyOnce: true });
112
110
  val = dangerouslySkipEscape(val);
@@ -127,5 +125,5 @@ function processHookReturnValue(hookReturnValue, renderHook) {
127
125
  pageContextProvidedByRenderHook = val;
128
126
  }
129
127
  }
130
- return ret();
128
+ return { documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter };
131
129
  }
@@ -43,7 +43,7 @@ type HookName = HookNamePage | HookNameGlobal | HookNameOldDesign;
43
43
  type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data';
44
44
  type HookNameGlobal = 'onBeforePrerender' | 'onBeforeRoute' | 'onPrerenderStart';
45
45
  type HookNameOldDesign = 'render' | 'prerender';
46
- type ConfigNameBuiltIn = Exclude<keyof Config, keyof ConfigVikeUserProvided | 'onBeforeRoute' | 'onPrerenderStart'> | 'prerender' | 'isClientRuntimeLoaded' | 'onBeforeRenderEnv' | 'dataEnv' | 'hooksTimeout' | 'clientHooks';
46
+ type ConfigNameBuiltIn = Exclude<keyof Config, keyof ConfigVikeUserProvided | 'onBeforeRoute' | 'onPrerenderStart'> | 'prerender' | 'isClientRuntimeLoaded' | 'onBeforeRenderEnv' | 'dataEnv' | 'hooksTimeout' | 'clientHooks' | 'middleware';
47
47
  type Config = ConfigBuiltIn & Vike.Config & (VikePackages.ConfigVikeReact | VikePackages.ConfigVikeVue | VikePackages.ConfigVikeSolid | VikePackages.ConfigVikeSvelte | VikePackages.ConfigVikeAngular);
48
48
  /** Hook for fetching data.
49
49
  *
@@ -1,34 +1,35 @@
1
1
  export { assertPlusFileExport };
2
2
  import { assert, assertUsage, assertWarning } from '../utils.js';
3
3
  import pc from '@brillout/picocolors';
4
- const EXPORTS_IGNORE = [
4
+ const SIDE_EXPORTS_TOLERATE = [
5
5
  // vite-plugin-solid adds `export { $$registrations }`
6
6
  '$$registrations',
7
7
  // @vitejs/plugin-vue adds `export { _rerender_only }`
8
8
  '_rerender_only'
9
9
  ];
10
10
  // Tolerate `export { frontmatter }` in .mdx files
11
- const TOLERATE_SIDE_EXPORTS = ['.md', '.mdx'];
11
+ const SIDE_EXPORTS_DO_NOT_CHECK = ['.md', '.mdx'];
12
12
  function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
13
- const exportNames = Object.keys(fileExports).filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
13
+ const exportNames = Object.keys(fileExports);
14
14
  const isValid = (exportName) => exportName === 'default' || exportName === configName;
15
+ // Error upon missing/ambiguous export
15
16
  const exportNamesValid = exportNames.filter(isValid);
16
- const exportNamesInvalid = exportNames.filter((e) => !isValid(e));
17
- if (exportNamesValid.length === 1 && exportNamesInvalid.length === 0) {
18
- return;
19
- }
20
17
  const exportDefault = pc.code('export default');
21
18
  const exportNamed = pc.code(`export { ${configName} }`);
22
- assert(exportNamesValid.length <= 2);
23
19
  if (exportNamesValid.length === 0) {
24
20
  assertUsage(false, `${filePathToShowToUser} should have ${exportNamed} or ${exportDefault}`);
25
21
  }
26
22
  if (exportNamesValid.length === 2) {
27
23
  assertUsage(false, `${filePathToShowToUser} is ambiguous: remove ${exportDefault} or ${exportNamed}`);
28
24
  }
29
- if (!TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext))) {
25
+ assert(exportNamesValid.length === 1);
26
+ // 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))) {
30
31
  exportNamesInvalid.forEach((exportInvalid) => {
31
- assertWarning(false, `${filePathToShowToUser} unexpected ${pc.cyan(`export { ${exportInvalid} }`)}`, {
32
+ assertWarning(false, `${filePathToShowToUser} unexpected ${pc.cyan(`export { ${exportInvalid} }`)}, see https://vike.dev/no-side-exports`, {
32
33
  onlyOnce: true
33
34
  });
34
35
  });
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.206";
1
+ export declare const PROJECT_VERSION: "0.4.208-commit-8d0a7ba";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.206';
2
+ export const PROJECT_VERSION = '0.4.208-commit-8d0a7ba';
@@ -43,7 +43,7 @@ function assert(condition, debugInfo) {
43
43
  })();
44
44
  const link = pc.blue('https://github.com/vikejs/vike/issues/new');
45
45
  let errMsg = [
46
- `You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).`,
46
+ `You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually within 24 hours).`,
47
47
  debugStr
48
48
  ]
49
49
  .filter(Boolean)
@@ -10,3 +10,8 @@ function pathJoin(path1, path2) {
10
10
  joined = '/' + joined;
11
11
  return joined;
12
12
  }
13
+ /* https://github.com/brillout/telefunc/blob/0fd44322acbd07857ae29361ba7c998607f17dd5/telefunc/utils/path-shim.ts#L17-L21
14
+ function isAbsolute(filePath: string) {
15
+ // ...
16
+ }
17
+ */
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.206";
3
+ projectVersion: "0.4.208-commit-8d0a7ba";
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.206",
3
+ "version": "0.4.208-commit-8d0a7ba",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -122,10 +122,10 @@
122
122
  },
123
123
  "dependencies": {
124
124
  "@brillout/import": "^0.2.3",
125
- "@brillout/json-serializer": "^0.5.13",
125
+ "@brillout/json-serializer": "^0.5.15",
126
126
  "@brillout/picocolors": "^1.0.15",
127
127
  "@brillout/require-shim": "^0.1.2",
128
- "@brillout/vite-plugin-server-entry": "^0.5.0",
128
+ "@brillout/vite-plugin-server-entry": "^0.5.5",
129
129
  "acorn": "^8.0.0",
130
130
  "cac": "^6.0.0",
131
131
  "es-module-lexer": "^1.0.0",
@@ -231,7 +231,7 @@
231
231
  "@types/resolve": "^1.20.6",
232
232
  "@types/semver": "^7.5.8",
233
233
  "@types/source-map-support": "^0.5.10",
234
- "react-streaming": "^0.3.43",
234
+ "react-streaming": "^0.3.44",
235
235
  "rimraf": "^5.0.5",
236
236
  "typescript": "^5.6.2",
237
237
  "vite": "^5.4.0"