vike 0.4.222-commit-6647d1e → 0.4.222-commit-5513d32

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 (32) hide show
  1. package/dist/cjs/node/plugin/plugins/buildApp.js +9 -5
  2. package/dist/cjs/node/plugin/plugins/buildConfig.js +3 -0
  3. package/dist/cjs/node/plugin/plugins/envVars.js +0 -1
  4. package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
  5. package/dist/cjs/node/runtime/globalContext.js +1 -1
  6. package/dist/cjs/node/runtime/renderPage.js +17 -13
  7. package/dist/cjs/node/runtime/universal-middleware.js +14 -0
  8. package/dist/cjs/shared/getPageContextUrlComputed.js +2 -2
  9. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  10. package/dist/cjs/utils/assert.js +1 -1
  11. package/dist/cjs/utils/parseUrl-extras.js +2 -2
  12. package/dist/cjs/utils/parseUrl.js +5 -5
  13. package/dist/esm/client/client-routing-runtime/skipLink.js +2 -2
  14. package/dist/esm/node/plugin/plugins/buildApp.js +9 -5
  15. package/dist/esm/node/plugin/plugins/buildConfig.js +3 -0
  16. package/dist/esm/node/plugin/plugins/envVars.js +0 -1
  17. package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +2 -2
  18. package/dist/esm/node/runtime/globalContext.js +1 -1
  19. package/dist/esm/node/runtime/renderPage.d.ts +5 -5
  20. package/dist/esm/node/runtime/renderPage.js +17 -12
  21. package/dist/esm/node/runtime/universal-middleware.d.ts +1 -0
  22. package/dist/esm/node/runtime/universal-middleware.js +11 -0
  23. package/dist/esm/shared/getPageContextUrlComputed.js +2 -2
  24. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  25. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  26. package/dist/esm/utils/assert.js +1 -1
  27. package/dist/esm/utils/parseUrl-extras.js +2 -2
  28. package/dist/esm/utils/parseUrl.d.ts +3 -4
  29. package/dist/esm/utils/parseUrl.js +5 -5
  30. package/dist/esm/utils/projectInfo.d.ts +1 -1
  31. package/package.json +15 -2
  32. package/universal-middleware.js +3 -0
@@ -9,6 +9,9 @@ const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js"
9
9
  const getFullBuildInlineConfig_js_1 = require("../shared/getFullBuildInlineConfig.js");
10
10
  function buildApp() {
11
11
  let config;
12
+ // `builder.buildApp` can be overriden by another plugin e.g vike-vercel https://github.com/vikejs/vike/pull/2184#issuecomment-2659425195
13
+ // In that case, we should'nt `forceExit`.
14
+ let forceExit = false;
12
15
  return [
13
16
  {
14
17
  name: 'vike:buildApp',
@@ -23,6 +26,10 @@ function buildApp() {
23
26
  (0, utils_js_1.assert)(builder.environments.ssr);
24
27
  await builder.build(builder.environments.client);
25
28
  await builder.build(builder.environments.ssr);
29
+ if (forceExit) {
30
+ (0, runPrerender_js_1.runPrerender_forceExit)();
31
+ (0, utils_js_1.assert)(false);
32
+ }
26
33
  }
27
34
  },
28
35
  environments: {
@@ -61,11 +68,8 @@ function buildApp() {
61
68
  if (!(0, context_js_1.isPrerenderAutoRunEnabled)(vikeConfig))
62
69
  return;
63
70
  const configInline = (0, getFullBuildInlineConfig_js_1.getFullBuildInlineConfig)(config);
64
- const { forceExit } = await (0, runPrerender_js_1.runPrerenderFromAutoRun)(configInline, config);
65
- if (forceExit) {
66
- (0, runPrerender_js_1.runPrerender_forceExit)();
67
- (0, utils_js_1.assert)(false);
68
- }
71
+ const res = await (0, runPrerender_js_1.runPrerenderFromAutoRun)(configInline, config);
72
+ forceExit = res.forceExit;
69
73
  }
70
74
  }
71
75
  ];
@@ -86,6 +86,9 @@ function buildConfig() {
86
86
  {
87
87
  name: 'vike:buildConfig:pre',
88
88
  apply: 'build',
89
+ applyToEnvironment(env) {
90
+ return env.name === 'ssr';
91
+ },
89
92
  // Make sure other writeBundle() hooks are called after this writeBundle() hook.
90
93
  // - set_ASSETS_MANIFEST() needs to be called before dist/server/ code is executed.
91
94
  // - For example, the writeBundle() hook of vite-plugin-vercel needs to be called after this writeBundle() hook, otherwise: https://github.com/vikejs/vike/issues/1527
@@ -95,7 +95,6 @@ function getIsClientSide(config, options) {
95
95
  return !isServerSide;
96
96
  }
97
97
  else {
98
- (0, utils_js_1.assert)(config.build.ssr === false);
99
98
  (0, utils_js_1.assert)(typeof options?.ssr === 'boolean');
100
99
  const isServerSide = options.ssr;
101
100
  return !isServerSide;
@@ -55,7 +55,7 @@ async function installHttpRequestAsyncStore() {
55
55
  return;
56
56
  }
57
57
  asyncLocalStorage = new mod.AsyncLocalStorage();
58
- (0, renderPage_js_1.renderPage_addWrapper)(async (httpRequestId, renderPage) => {
58
+ (0, renderPage_js_1.renderPage_addAsyncHookwrapper)(async (httpRequestId, renderPage) => {
59
59
  (0, utils_js_1.assert)(asyncLocalStorage);
60
60
  const loggedErrors = new Set();
61
61
  const markErrorAsLogged = (err) => {
@@ -127,7 +127,7 @@ function getViteConfig() {
127
127
  }
128
128
  async function initGlobalContext_renderPage() {
129
129
  debug('initGlobalContext_renderPage()');
130
- // globalObject.isProduction isn't set upon production server without vike-server (there isn't any signal we can use)
130
+ // `globalObject.isProduction === undefined` when using production server without `vike-server`. (There isn't any reliable signal we can use to determine early whether the environement is production or development.)
131
131
  if (globalObject.isProduction === undefined)
132
132
  setIsProduction(true);
133
133
  await initGlobalContext();
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.renderPage_addWrapper = void 0;
7
6
  exports.renderPage = renderPage;
7
+ exports.renderPage_addAsyncHookwrapper = renderPage_addAsyncHookwrapper;
8
8
  const renderPageAlreadyRouted_js_1 = require("./renderPage/renderPageAlreadyRouted.js");
9
9
  const index_js_1 = require("../../shared/route/index.js");
10
10
  const utils_js_1 = require("./utils.js");
@@ -26,13 +26,6 @@ const resolveRedirects_js_1 = require("./renderPage/resolveRedirects.js");
26
26
  const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage.ts', {
27
27
  httpRequestsCount: 0
28
28
  });
29
- let renderPage_wrapper = async (_httpRequestId, ret) => ({
30
- pageContextReturn: await ret()
31
- });
32
- const renderPage_addWrapper = (wrapper) => {
33
- renderPage_wrapper = wrapper;
34
- };
35
- exports.renderPage_addWrapper = renderPage_addWrapper;
36
29
  // `renderPage()` calls `renderPageNominal()` while ensuring that errors are `console.error(err)` instead of `throw err`, so that Vike never triggers a server shut down. (Throwing an error in an Express.js middleware shuts down the whole Express.js server.)
37
30
  async function renderPage(pageContextInit) {
38
31
  (0, assertArguments_js_1.assertArguments)(...arguments);
@@ -46,12 +39,20 @@ async function renderPage(pageContextInit) {
46
39
  const httpRequestId = getRequestId();
47
40
  const urlOriginalPretty = (0, utils_js_1.getUrlPretty)(pageContextInit.urlOriginal);
48
41
  logHttpRequest(urlOriginalPretty, httpRequestId);
49
- const { pageContextReturn } = await renderPage_wrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
42
+ const { pageContextReturn } = await asyncHookWrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
50
43
  logHttpResponse(urlOriginalPretty, httpRequestId, pageContextReturn);
51
44
  (0, utils_js_1.checkType)(pageContextReturn);
52
45
  (0, utils_js_1.assert)(pageContextReturn.httpResponse);
53
46
  return pageContextReturn;
54
47
  }
48
+ // Fallback wrapper if node:async_hooks isn't available
49
+ let asyncHookWrapper = async (_httpRequestId, ret) => ({
50
+ pageContextReturn: await ret()
51
+ });
52
+ // Add node:async_hooks wrapper
53
+ function renderPage_addAsyncHookwrapper(wrapper) {
54
+ asyncHookWrapper = wrapper;
55
+ }
55
56
  async function renderPageAndPrepare(pageContextInit, httpRequestId) {
56
57
  // Invalid config
57
58
  const handleInvalidConfig = (err) => {
@@ -70,8 +71,11 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
70
71
  await (0, globalContext_js_1.initGlobalContext_renderPage)();
71
72
  }
72
73
  catch (err) {
73
- // Errors are expected since assertUsage() is used in both initGlobalContext_renderPage() and getRenderContext().
74
- // initGlobalContext_renderPage() and getRenderContext() don't call any user hooks => err isn't thrown from user code.
74
+ // Errors are expected since assertUsage() is used in initGlobalContext_renderPage() such as:
75
+ // ```bash
76
+ // Re-build your app (you're using 1.2.3 but your app was built with 1.2.2)
77
+ // ```
78
+ // initGlobalContext_renderPage() doens't call any user hook => err isn't thrown from user code.
75
79
  (0, utils_js_1.assert)(!(0, abort_js_1.isAbortError)(err));
76
80
  (0, loggerRuntime_js_1.logRuntimeError)(err, httpRequestId);
77
81
  const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
@@ -458,6 +462,6 @@ async function assertBaseUrl(pageContextInit, globalContext) {
458
462
  const { baseServer } = globalContext;
459
463
  const { urlOriginal } = pageContextInit;
460
464
  const { urlWithoutPageContextRequestSuffix } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
461
- const { hasBaseServer } = (0, utils_js_1.parseUrl)(urlWithoutPageContextRequestSuffix, baseServer);
462
- (0, utils_js_1.assertUsage)(hasBaseServer, `${picocolors_1.default.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${picocolors_1.default.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which doesn't start with Base URL ${picocolors_1.default.code(baseServer)} (https://vike.dev/base-url)`);
465
+ const { isBaseMissing } = (0, utils_js_1.parseUrl)(urlWithoutPageContextRequestSuffix, baseServer);
466
+ (0, utils_js_1.assertUsage)(!isBaseMissing, `${picocolors_1.default.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${picocolors_1.default.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which doesn't start with Base URL ${picocolors_1.default.code(baseServer)} (https://vike.dev/base-url)`);
463
467
  }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = universalVikeHandler;
4
+ const index_js_1 = require("./index.js");
5
+ async function universalVikeHandler(request, context, runtime) {
6
+ const pageContextInit = { ...context, ...runtime, urlOriginal: request.url, headersOriginal: request.headers };
7
+ const pageContext = await (0, index_js_1.renderPage)(pageContextInit);
8
+ const response = pageContext.httpResponse;
9
+ const readable = response.getReadableWebStream();
10
+ return new Response(readable, {
11
+ status: response.statusCode,
12
+ headers: response.headers
13
+ });
14
+ }
@@ -88,8 +88,8 @@ function urlGetter() {
88
88
  }
89
89
  function urlParsedGetter() {
90
90
  const {
91
- // remove hasBaseServer as it isn't part of UrlPublic
92
- hasBaseServer: _, ...urlParsed } = getUrlParsed(this);
91
+ // remove isBaseMissing as it isn't part of UrlPublic
92
+ isBaseMissing: _, ...urlParsed } = getUrlParsed(this);
93
93
  const hashIsAvailable = (0, utils_js_1.isBrowser)();
94
94
  const warnHashNotAvailable = (prop) => {
95
95
  (0, utils_js_1.assertWarning)(hashIsAvailable, `pageContext.urlParsed.${prop} isn't available on the server-side (HTTP requests don't include the URL hash)`, { onlyOnce: true, showStackTrace: true });
@@ -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.222-commit-6647d1e';
5
+ exports.PROJECT_VERSION = '0.4.222-commit-5513d32';
@@ -47,7 +47,7 @@ function assert(condition, debugInfo) {
47
47
  const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
48
48
  return picocolors_1.default.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
49
49
  })();
50
- const link = picocolors_1.default.blue('https://github.com/vikejs/vike/issues/new');
50
+ const link = picocolors_1.default.blue('https://github.com/vikejs/vike/issues/new?template=bug.yml');
51
51
  let errMsg = [
52
52
  `You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually within 24 hours).`,
53
53
  debugStr
@@ -30,8 +30,8 @@ function prependBase(url, baseServer) {
30
30
  return `${baseServerNormalized}${url}`;
31
31
  }
32
32
  function removeBaseServer(url, baseServer) {
33
- const { hasBaseServer, origin, pathname, pathnameOriginal, searchOriginal, hashOriginal } = (0, parseUrl_js_1.parseUrl)(url, baseServer);
34
- (0, assert_js_1.assert)(hasBaseServer);
33
+ const { isBaseMissing, origin, pathname, pathnameOriginal, searchOriginal, hashOriginal } = (0, parseUrl_js_1.parseUrl)(url, baseServer);
34
+ (0, assert_js_1.assert)(!isBaseMissing);
35
35
  (0, parseUrl_js_1.assertUrlComponents)(url, origin, pathnameOriginal, searchOriginal, hashOriginal);
36
36
  const urlWithoutBase = (0, parseUrl_js_1.createUrlFromComponents)(origin, pathname, searchOriginal, hashOriginal);
37
37
  return urlWithoutBase;
@@ -49,7 +49,7 @@ function parseUrl(url, baseServer) {
49
49
  const pathnameOriginal = urlWithoutHashNorSearch.slice((origin || '').length);
50
50
  assertUrlComponents(url, origin, pathnameOriginal, searchOriginal, hashOriginal);
51
51
  // Base URL
52
- let { pathname, hasBaseServer } = removeBaseServer(pathnameAbsoluteWithBase, baseServer);
52
+ let { pathname, isBaseMissing } = removeBaseServer(pathnameAbsoluteWithBase, baseServer);
53
53
  // pageContext.urlParsed.href
54
54
  const href = createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal);
55
55
  // pageContext.urlParsed.{hostname, port}
@@ -66,7 +66,7 @@ function parseUrl(url, baseServer) {
66
66
  origin,
67
67
  pathname,
68
68
  pathnameOriginal: pathnameOriginal,
69
- hasBaseServer,
69
+ isBaseMissing,
70
70
  search,
71
71
  searchAll,
72
72
  searchOriginal,
@@ -235,7 +235,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
235
235
  (0, assert_js_1.assert)(baseServer.startsWith('/'));
236
236
  if (baseServer === '/') {
237
237
  const pathname = pathnameAbsoluteWithBase;
238
- return { pathname, hasBaseServer: true };
238
+ return { pathname, isBaseMissing: false };
239
239
  }
240
240
  // Support `url === '/some-base-url' && baseServer === '/some-base-url/'`
241
241
  let baseServerNormalized = baseServer;
@@ -245,7 +245,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
245
245
  }
246
246
  if (!urlPathname.startsWith(baseServerNormalized)) {
247
247
  const pathname = pathnameAbsoluteWithBase;
248
- return { pathname, hasBaseServer: false };
248
+ return { pathname, isBaseMissing: true };
249
249
  }
250
250
  (0, assert_js_1.assert)(urlPathname.startsWith('/') || urlPathname.startsWith('http'));
251
251
  (0, assert_js_1.assert)(urlPathname.startsWith(baseServerNormalized));
@@ -253,7 +253,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
253
253
  if (!urlPathname.startsWith('/'))
254
254
  urlPathname = '/' + urlPathname;
255
255
  (0, assert_js_1.assert)(urlPathname.startsWith('/'));
256
- return { pathname: urlPathname, hasBaseServer: true };
256
+ return { pathname: urlPathname, isBaseMissing: false };
257
257
  }
258
258
  function isBaseServer(baseServer) {
259
259
  return baseServer.startsWith('/');
@@ -49,8 +49,8 @@ function isSameAsCurrentUrl(href) {
49
49
  function hasBaseServer(href) {
50
50
  const baseServer = getBaseServer();
51
51
  assert(isBaseServer(baseServer));
52
- const { hasBaseServer } = parseUrl(href, baseServer);
53
- return hasBaseServer;
52
+ const { isBaseMissing } = parseUrl(href, baseServer);
53
+ return !isBaseMissing;
54
54
  }
55
55
  function isDisableAutomaticLinkInterception() {
56
56
  // @ts-ignore
@@ -7,6 +7,9 @@ import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
7
7
  import { getFullBuildInlineConfig } from '../shared/getFullBuildInlineConfig.js';
8
8
  function buildApp() {
9
9
  let config;
10
+ // `builder.buildApp` can be overriden by another plugin e.g vike-vercel https://github.com/vikejs/vike/pull/2184#issuecomment-2659425195
11
+ // In that case, we should'nt `forceExit`.
12
+ let forceExit = false;
10
13
  return [
11
14
  {
12
15
  name: 'vike:buildApp',
@@ -21,6 +24,10 @@ function buildApp() {
21
24
  assert(builder.environments.ssr);
22
25
  await builder.build(builder.environments.client);
23
26
  await builder.build(builder.environments.ssr);
27
+ if (forceExit) {
28
+ runPrerender_forceExit();
29
+ assert(false);
30
+ }
24
31
  }
25
32
  },
26
33
  environments: {
@@ -59,11 +66,8 @@ function buildApp() {
59
66
  if (!isPrerenderAutoRunEnabled(vikeConfig))
60
67
  return;
61
68
  const configInline = getFullBuildInlineConfig(config);
62
- const { forceExit } = await runPrerenderFromAutoRun(configInline, config);
63
- if (forceExit) {
64
- runPrerender_forceExit();
65
- assert(false);
66
- }
69
+ const res = await runPrerenderFromAutoRun(configInline, config);
70
+ forceExit = res.forceExit;
67
71
  }
68
72
  }
69
73
  ];
@@ -80,6 +80,9 @@ function buildConfig() {
80
80
  {
81
81
  name: 'vike:buildConfig:pre',
82
82
  apply: 'build',
83
+ applyToEnvironment(env) {
84
+ return env.name === 'ssr';
85
+ },
83
86
  // Make sure other writeBundle() hooks are called after this writeBundle() hook.
84
87
  // - set_ASSETS_MANIFEST() needs to be called before dist/server/ code is executed.
85
88
  // - For example, the writeBundle() hook of vite-plugin-vercel needs to be called after this writeBundle() hook, otherwise: https://github.com/vikejs/vike/issues/1527
@@ -93,7 +93,6 @@ function getIsClientSide(config, options) {
93
93
  return !isServerSide;
94
94
  }
95
95
  else {
96
- assert(config.build.ssr === false);
97
96
  assert(typeof options?.ssr === 'boolean');
98
97
  const isServerSide = options.ssr;
99
98
  return !isServerSide;
@@ -10,7 +10,7 @@
10
10
  // - We dedupe errors ourself with getHttpRequestAsyncStore().shouldErrorBeSwallowed()
11
11
  export { getHttpRequestAsyncStore };
12
12
  export { installHttpRequestAsyncStore };
13
- import { renderPage_addWrapper } from '../../runtime/renderPage.js';
13
+ import { renderPage_addAsyncHookwrapper } from '../../runtime/renderPage.js';
14
14
  import { assert, assertIsNotProductionRuntime, isObject, unique } from '../utils.js';
15
15
  import { getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js';
16
16
  import { logErrorDebugNote } from './loggerNotProd.js';
@@ -27,7 +27,7 @@ async function installHttpRequestAsyncStore() {
27
27
  return;
28
28
  }
29
29
  asyncLocalStorage = new mod.AsyncLocalStorage();
30
- renderPage_addWrapper(async (httpRequestId, renderPage) => {
30
+ renderPage_addAsyncHookwrapper(async (httpRequestId, renderPage) => {
31
31
  assert(asyncLocalStorage);
32
32
  const loggedErrors = new Set();
33
33
  const markErrorAsLogged = (err) => {
@@ -124,7 +124,7 @@ function getViteConfig() {
124
124
  }
125
125
  async function initGlobalContext_renderPage() {
126
126
  debug('initGlobalContext_renderPage()');
127
- // globalObject.isProduction isn't set upon production server without vike-server (there isn't any signal we can use)
127
+ // `globalObject.isProduction === undefined` when using production server without `vike-server`. (There isn't any reliable signal we can use to determine early whether the environement is production or development.)
128
128
  if (globalObject.isProduction === undefined)
129
129
  setIsProduction(true);
130
130
  await initGlobalContext();
@@ -1,11 +1,7 @@
1
1
  export { renderPage };
2
- export { renderPage_addWrapper };
2
+ export { renderPage_addAsyncHookwrapper };
3
3
  import { HttpResponse } from './renderPage/createHttpResponse.js';
4
4
  import type { PageContextServer } from '../../types/index.js';
5
- declare let renderPage_wrapper: <PageContext>(_httpRequestId: number, ret: () => Promise<PageContext>) => Promise<{
6
- pageContextReturn: Awaited<PageContext>;
7
- }>;
8
- declare const renderPage_addWrapper: (wrapper: typeof renderPage_wrapper) => void;
9
5
  declare function renderPage<PageContextUserAdded extends {}, PageContextInit extends {
10
6
  /** @deprecated */
11
7
  url?: string;
@@ -14,3 +10,7 @@ declare function renderPage<PageContextUserAdded extends {}, PageContextInit ext
14
10
  }>(pageContextInit: PageContextInit): Promise<PageContextInit & {
15
11
  httpResponse: HttpResponse;
16
12
  } & Partial<PageContextServer & PageContextUserAdded>>;
13
+ declare let asyncHookWrapper: <PageContext>(_httpRequestId: number, ret: () => Promise<PageContext>) => Promise<{
14
+ pageContextReturn: Awaited<PageContext>;
15
+ }>;
16
+ declare function renderPage_addAsyncHookwrapper(wrapper: typeof asyncHookWrapper): void;
@@ -1,5 +1,5 @@
1
1
  export { renderPage };
2
- export { renderPage_addWrapper };
2
+ export { renderPage_addAsyncHookwrapper };
3
3
  import { getPageContextInitEnhanced, renderPageAlreadyRouted } from './renderPage/renderPageAlreadyRouted.js';
4
4
  import { route } from '../../shared/route/index.js';
5
5
  import { assert, hasProp, objectAssign, isUrl, parseUrl, onSetupRuntime, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, setUrlOrigin, createUrlFromComponents, isUri, getUrlPretty } from './utils.js';
@@ -21,12 +21,6 @@ import { resolveRedirects } from './renderPage/resolveRedirects.js';
21
21
  const globalObject = getGlobalObject('runtime/renderPage.ts', {
22
22
  httpRequestsCount: 0
23
23
  });
24
- let renderPage_wrapper = async (_httpRequestId, ret) => ({
25
- pageContextReturn: await ret()
26
- });
27
- const renderPage_addWrapper = (wrapper) => {
28
- renderPage_wrapper = wrapper;
29
- };
30
24
  // `renderPage()` calls `renderPageNominal()` while ensuring that errors are `console.error(err)` instead of `throw err`, so that Vike never triggers a server shut down. (Throwing an error in an Express.js middleware shuts down the whole Express.js server.)
31
25
  async function renderPage(pageContextInit) {
32
26
  assertArguments(...arguments);
@@ -40,12 +34,20 @@ async function renderPage(pageContextInit) {
40
34
  const httpRequestId = getRequestId();
41
35
  const urlOriginalPretty = getUrlPretty(pageContextInit.urlOriginal);
42
36
  logHttpRequest(urlOriginalPretty, httpRequestId);
43
- const { pageContextReturn } = await renderPage_wrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
37
+ const { pageContextReturn } = await asyncHookWrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
44
38
  logHttpResponse(urlOriginalPretty, httpRequestId, pageContextReturn);
45
39
  checkType(pageContextReturn);
46
40
  assert(pageContextReturn.httpResponse);
47
41
  return pageContextReturn;
48
42
  }
43
+ // Fallback wrapper if node:async_hooks isn't available
44
+ let asyncHookWrapper = async (_httpRequestId, ret) => ({
45
+ pageContextReturn: await ret()
46
+ });
47
+ // Add node:async_hooks wrapper
48
+ function renderPage_addAsyncHookwrapper(wrapper) {
49
+ asyncHookWrapper = wrapper;
50
+ }
49
51
  async function renderPageAndPrepare(pageContextInit, httpRequestId) {
50
52
  // Invalid config
51
53
  const handleInvalidConfig = (err) => {
@@ -64,8 +66,11 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
64
66
  await initGlobalContext_renderPage();
65
67
  }
66
68
  catch (err) {
67
- // Errors are expected since assertUsage() is used in both initGlobalContext_renderPage() and getRenderContext().
68
- // initGlobalContext_renderPage() and getRenderContext() don't call any user hooks => err isn't thrown from user code.
69
+ // Errors are expected since assertUsage() is used in initGlobalContext_renderPage() such as:
70
+ // ```bash
71
+ // Re-build your app (you're using 1.2.3 but your app was built with 1.2.2)
72
+ // ```
73
+ // initGlobalContext_renderPage() doens't call any user hook => err isn't thrown from user code.
69
74
  assert(!isAbortError(err));
70
75
  logRuntimeError(err, httpRequestId);
71
76
  const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
@@ -452,6 +457,6 @@ async function assertBaseUrl(pageContextInit, globalContext) {
452
457
  const { baseServer } = globalContext;
453
458
  const { urlOriginal } = pageContextInit;
454
459
  const { urlWithoutPageContextRequestSuffix } = handlePageContextRequestUrl(urlOriginal);
455
- const { hasBaseServer } = parseUrl(urlWithoutPageContextRequestSuffix, baseServer);
456
- assertUsage(hasBaseServer, `${pc.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${pc.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which doesn't start with Base URL ${pc.code(baseServer)} (https://vike.dev/base-url)`);
460
+ const { isBaseMissing } = parseUrl(urlWithoutPageContextRequestSuffix, baseServer);
461
+ assertUsage(!isBaseMissing, `${pc.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${pc.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which doesn't start with Base URL ${pc.code(baseServer)} (https://vike.dev/base-url)`);
457
462
  }
@@ -0,0 +1 @@
1
+ export default function universalVikeHandler(request: Request, context: Record<string, unknown>, runtime: Record<string, unknown>): Promise<Response>;
@@ -0,0 +1,11 @@
1
+ import { renderPage } from './index.js';
2
+ export default async function universalVikeHandler(request, context, runtime) {
3
+ const pageContextInit = { ...context, ...runtime, urlOriginal: request.url, headersOriginal: request.headers };
4
+ const pageContext = await renderPage(pageContextInit);
5
+ const response = pageContext.httpResponse;
6
+ const readable = response.getReadableWebStream();
7
+ return new Response(readable, {
8
+ status: response.statusCode,
9
+ headers: response.headers
10
+ });
11
+ }
@@ -86,8 +86,8 @@ function urlGetter() {
86
86
  }
87
87
  function urlParsedGetter() {
88
88
  const {
89
- // remove hasBaseServer as it isn't part of UrlPublic
90
- hasBaseServer: _, ...urlParsed } = getUrlParsed(this);
89
+ // remove isBaseMissing as it isn't part of UrlPublic
90
+ isBaseMissing: _, ...urlParsed } = getUrlParsed(this);
91
91
  const hashIsAvailable = isBrowser();
92
92
  const warnHashNotAvailable = (prop) => {
93
93
  assertWarning(hashIsAvailable, `pageContext.urlParsed.${prop} isn't available on the server-side (HTTP requests don't include the URL hash)`, { onlyOnce: true, showStackTrace: true });
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.222-commit-6647d1e";
1
+ export declare const PROJECT_VERSION: "0.4.222-commit-5513d32";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.222-commit-6647d1e';
2
+ export const PROJECT_VERSION = '0.4.222-commit-5513d32';
@@ -42,7 +42,7 @@ function assert(condition, debugInfo) {
42
42
  const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
43
43
  return pc.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
44
44
  })();
45
- const link = pc.blue('https://github.com/vikejs/vike/issues/new');
45
+ const link = pc.blue('https://github.com/vikejs/vike/issues/new?template=bug.yml');
46
46
  let errMsg = [
47
47
  `You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually within 24 hours).`,
48
48
  debugStr
@@ -28,8 +28,8 @@ function prependBase(url, baseServer) {
28
28
  return `${baseServerNormalized}${url}`;
29
29
  }
30
30
  function removeBaseServer(url, baseServer) {
31
- const { hasBaseServer, origin, pathname, pathnameOriginal, searchOriginal, hashOriginal } = parseUrl(url, baseServer);
32
- assert(hasBaseServer);
31
+ const { isBaseMissing, origin, pathname, pathnameOriginal, searchOriginal, hashOriginal } = parseUrl(url, baseServer);
32
+ assert(!isBaseMissing);
33
33
  assertUrlComponents(url, origin, pathnameOriginal, searchOriginal, hashOriginal);
34
34
  const urlWithoutBase = createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal);
35
35
  return urlWithoutBase;
@@ -10,7 +10,6 @@ export { isBaseServer };
10
10
  export { assertUrlComponents };
11
11
  export { createUrlFromComponents };
12
12
  export type { UrlPublic };
13
- export type { UrlPrivate };
14
13
  type UrlPublic = {
15
14
  /** The full URL. */
16
15
  href: string;
@@ -41,10 +40,10 @@ type UrlPublic = {
41
40
  /** @deprecated */
42
41
  searchString: null | string;
43
42
  };
44
- type UrlPrivate = Omit<UrlPublic, 'hashString' | 'searchString'> & {
45
- hasBaseServer: boolean;
43
+ type UrlInternal = Omit<UrlPublic, 'hashString' | 'searchString'> & {
44
+ isBaseMissing: boolean;
46
45
  };
47
- declare function parseUrl(url: string, baseServer: string): UrlPrivate;
46
+ declare function parseUrl(url: string, baseServer: string): UrlInternal;
48
47
  declare function isBaseServer(baseServer: string): boolean;
49
48
  declare function assertUrlComponents(url: string, origin: string | null, pathnameOriginal: string, searchOriginal: string | null, hashOriginal: string | null): void;
50
49
  declare function createUrlFromComponents(origin: string | null, pathname: string, search: string | null, hash: string | null): string;
@@ -45,7 +45,7 @@ function parseUrl(url, baseServer) {
45
45
  const pathnameOriginal = urlWithoutHashNorSearch.slice((origin || '').length);
46
46
  assertUrlComponents(url, origin, pathnameOriginal, searchOriginal, hashOriginal);
47
47
  // Base URL
48
- let { pathname, hasBaseServer } = removeBaseServer(pathnameAbsoluteWithBase, baseServer);
48
+ let { pathname, isBaseMissing } = removeBaseServer(pathnameAbsoluteWithBase, baseServer);
49
49
  // pageContext.urlParsed.href
50
50
  const href = createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal);
51
51
  // pageContext.urlParsed.{hostname, port}
@@ -62,7 +62,7 @@ function parseUrl(url, baseServer) {
62
62
  origin,
63
63
  pathname,
64
64
  pathnameOriginal: pathnameOriginal,
65
- hasBaseServer,
65
+ isBaseMissing,
66
66
  search,
67
67
  searchAll,
68
68
  searchOriginal,
@@ -231,7 +231,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
231
231
  assert(baseServer.startsWith('/'));
232
232
  if (baseServer === '/') {
233
233
  const pathname = pathnameAbsoluteWithBase;
234
- return { pathname, hasBaseServer: true };
234
+ return { pathname, isBaseMissing: false };
235
235
  }
236
236
  // Support `url === '/some-base-url' && baseServer === '/some-base-url/'`
237
237
  let baseServerNormalized = baseServer;
@@ -241,7 +241,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
241
241
  }
242
242
  if (!urlPathname.startsWith(baseServerNormalized)) {
243
243
  const pathname = pathnameAbsoluteWithBase;
244
- return { pathname, hasBaseServer: false };
244
+ return { pathname, isBaseMissing: true };
245
245
  }
246
246
  assert(urlPathname.startsWith('/') || urlPathname.startsWith('http'));
247
247
  assert(urlPathname.startsWith(baseServerNormalized));
@@ -249,7 +249,7 @@ function removeBaseServer(pathnameAbsoluteWithBase, baseServer) {
249
249
  if (!urlPathname.startsWith('/'))
250
250
  urlPathname = '/' + urlPathname;
251
251
  assert(urlPathname.startsWith('/'));
252
- return { pathname: urlPathname, hasBaseServer: true };
252
+ return { pathname: urlPathname, isBaseMissing: false };
253
253
  }
254
254
  function isBaseServer(baseServer) {
255
255
  return baseServer.startsWith('/');
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.222-commit-6647d1e";
3
+ projectVersion: "0.4.222-commit-5513d32";
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.222-commit-6647d1e",
3
+ "version": "0.4.222-commit-5513d32",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -96,6 +96,15 @@
96
96
  "types": "./dist/esm/shared/modifyUrl.d.ts",
97
97
  "default": "./dist/esm/shared/modifyUrl.js"
98
98
  },
99
+ "./universal-middleware": {
100
+ "worker": "./dist/esm/node/runtime/universal-middleware.js",
101
+ "edge-light": "./dist/esm/node/runtime/universal-middleware.js",
102
+ "require": "./dist/cjs/node/runtime/universal-middleware.js",
103
+ "node": "./dist/esm/node/runtime/universal-middleware.js",
104
+ "browser": "./dist/esm/client/node.js",
105
+ "types": "./dist/esm/node/runtime/universal-middleware.d.ts",
106
+ "default": "./dist/esm/node/runtime/universal-middleware.js"
107
+ },
99
108
  "./__internal": {
100
109
  "require": "./dist/cjs/__internal/index.js",
101
110
  "node": "./dist/esm/__internal/index.js",
@@ -203,6 +212,9 @@
203
212
  "modifyUrl": [
204
213
  "./dist/esm/shared/modifyUrl.d.ts"
205
214
  ],
215
+ "universal-middleware": [
216
+ "./dist/esm/node/runtime/universal-middleware.d.ts"
217
+ ],
206
218
  "__internal": [
207
219
  "./dist/esm/__internal/index.d.ts"
208
220
  ],
@@ -235,7 +247,8 @@
235
247
  "./RenderErrorPage.js",
236
248
  "./routing.js",
237
249
  "./server.js",
238
- "./types.js"
250
+ "./types.js",
251
+ "./universal-middleware.js"
239
252
  ],
240
253
  "devDependencies": {
241
254
  "@biomejs/biome": "^1.5.3",
@@ -0,0 +1,3 @@
1
+ // Some tools still need this as of January 2025
2
+ export * from './dist/esm/node/runtime/universal-middleware.js'
3
+ export { default } from './dist/esm/node/runtime/universal-middleware.js'