vike 0.4.222-commit-5513d32 → 0.4.222-commit-fab3841

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 (63) hide show
  1. package/dist/cjs/client/shared/getPageContextProxyForUser.js +1 -1
  2. package/dist/cjs/node/api/prepareViteApiCall.js +1 -1
  3. package/dist/cjs/node/plugin/plugins/envVars.js +2 -17
  4. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +2 -2
  5. package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +1 -1
  6. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -1
  7. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +5 -5
  8. package/dist/cjs/node/plugin/shared/viteIsSSR.js +19 -10
  9. package/dist/cjs/node/runtime/globalContext.js +1 -1
  10. package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +1 -1
  11. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +24 -0
  12. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -1
  13. package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +1 -1
  14. package/dist/cjs/node/runtime/renderPage/isNewError.js +1 -1
  15. package/dist/cjs/node/runtime/renderPage/isVikeConfigInvalid.js +10 -0
  16. package/dist/cjs/node/runtime/renderPage.js +44 -30
  17. package/dist/cjs/shared/getPageContextRequestUrl.js +1 -1
  18. package/dist/cjs/shared/getPageContextUrlComputed.js +10 -7
  19. package/dist/cjs/shared/hooks/getHook.js +1 -1
  20. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  21. package/dist/cjs/utils/assertSetup.js +1 -1
  22. package/dist/cjs/utils/assertSingleInstance.js +1 -1
  23. package/dist/cjs/utils/getGlobalObject.js +2 -6
  24. package/dist/esm/client/client-routing-runtime/getPageContextCurrent.js +1 -1
  25. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +1 -1
  26. package/dist/esm/client/client-routing-runtime/history.js +1 -1
  27. package/dist/esm/client/client-routing-runtime/prefetch.js +1 -1
  28. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
  29. package/dist/esm/client/client-routing-runtime/scrollRestoration.js +1 -1
  30. package/dist/esm/client/shared/getPageContextProxyForUser.js +1 -1
  31. package/dist/esm/node/api/prepareViteApiCall.js +1 -1
  32. package/dist/esm/node/plugin/plugins/envVars.js +2 -17
  33. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +3 -3
  34. package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +1 -1
  35. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -1
  36. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +5 -5
  37. package/dist/esm/node/plugin/shared/viteIsSSR.d.ts +7 -4
  38. package/dist/esm/node/plugin/shared/viteIsSSR.js +20 -11
  39. package/dist/esm/node/runtime/globalContext.js +1 -1
  40. package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +1 -1
  41. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +2 -0
  42. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +24 -0
  43. package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -1
  44. package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.js +1 -1
  45. package/dist/esm/node/runtime/renderPage/isNewError.js +1 -1
  46. package/dist/esm/node/runtime/renderPage/isVikeConfigInvalid.d.ts +6 -0
  47. package/dist/esm/node/runtime/renderPage/isVikeConfigInvalid.js +8 -0
  48. package/dist/esm/node/runtime/renderPage.js +45 -31
  49. package/dist/esm/shared/getPageContextRequestUrl.js +1 -1
  50. package/dist/esm/shared/getPageContextUrlComputed.js +10 -7
  51. package/dist/esm/shared/hooks/getHook.js +1 -1
  52. package/dist/esm/shared/types.d.ts +6 -0
  53. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  54. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  55. package/dist/esm/utils/assertSetup.js +1 -1
  56. package/dist/esm/utils/assertSingleInstance.js +1 -1
  57. package/dist/esm/utils/getGlobalObject.d.ts +3 -2
  58. package/dist/esm/utils/getGlobalObject.js +2 -6
  59. package/dist/esm/utils/projectInfo.d.ts +1 -1
  60. package/package.json +1 -1
  61. package/dist/cjs/node/runtime/renderPage/isConfigInvalid.js +0 -10
  62. package/dist/esm/node/runtime/renderPage/isConfigInvalid.d.ts +0 -6
  63. package/dist/esm/node/runtime/renderPage/isConfigInvalid.js +0 -8
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPageContextProxyForUser = getPageContextProxyForUser;
4
4
  const utils_js_1 = require("../server-routing-runtime/utils.js");
5
5
  const notSerializable_js_1 = require("../../shared/notSerializable.js");
6
- const globalObject = (0, utils_js_1.getGlobalObject)('getPageContextProxyForUser.ts', {});
6
+ const globalObject = (0, utils_js_1.getGlobalObject)('shared/getPageContextProxyForUser.ts', {});
7
7
  /**
8
8
  * Throw error when pageContext value isn't:
9
9
  * - serializable, or
@@ -48,7 +48,7 @@ const path_1 = __importDefault(require("path"));
48
48
  const utils_js_1 = require("./utils.js");
49
49
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
50
50
  const globalContext_js_1 = require("../runtime/globalContext.js");
51
- const globalObject = (0, utils_js_1.getGlobalObject)('prepareViteApiCall.ts', {});
51
+ const globalObject = (0, utils_js_1.getGlobalObject)('api/prepareViteApiCall.ts', {});
52
52
  async function prepareViteApiCall(viteConfigFromOptions, operation) {
53
53
  clear();
54
54
  (0, context_js_1.setContextApiOperation)(operation);
@@ -6,6 +6,7 @@ const utils_js_1 = require("../utils.js");
6
6
  const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
7
7
  const getFilePath_js_1 = require("../shared/getFilePath.js");
8
8
  const normalizeId_js_1 = require("../shared/normalizeId.js");
9
+ const viteIsSSR_js_1 = require("../shared/viteIsSSR.js");
9
10
  // TODO/enventually: (after we implemented vike.config.js)
10
11
  // - Make import.meta.env work inside +config.js
11
12
  // - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
@@ -38,7 +39,7 @@ function envVarsPlugin() {
38
39
  if (!code.includes('import.meta.env.'))
39
40
  return;
40
41
  const isBuild = config.command === 'build';
41
- const isClientSide = getIsClientSide(config, options);
42
+ const isClientSide = !(0, viteIsSSR_js_1.viteIsSSR_safe)(config, options);
42
43
  Object.entries(envsAll)
43
44
  .filter(([key]) => {
44
45
  // Already handled by Vite
@@ -84,19 +85,3 @@ function envVarsPlugin() {
84
85
  function applyEnvVar(envStatementRegEx, envVal, code) {
85
86
  return code.replace(envStatementRegEx, JSON.stringify(envVal));
86
87
  }
87
- function getIsClientSide(config, options) {
88
- const isBuild = config.command === 'build';
89
- if (isBuild) {
90
- (0, utils_js_1.assert)(typeof config.build.ssr === 'boolean');
91
- const isServerSide = config.build.ssr;
92
- if (options !== undefined) {
93
- (0, utils_js_1.assert)(options.ssr === isServerSide);
94
- }
95
- return !isServerSide;
96
- }
97
- else {
98
- (0, utils_js_1.assert)(typeof options?.ssr === 'boolean');
99
- const isServerSide = options.ssr;
100
- return !isServerSide;
101
- }
102
- }
@@ -48,7 +48,7 @@ function extractAssetsPlugin() {
48
48
  }
49
49
  // TODO/now: add meta.default
50
50
  (0, utils_js_1.assert)(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
51
- (0, utils_js_1.assert)(!(0, viteIsSSR_js_1.viteIsSSR_options)(options));
51
+ (0, utils_js_1.assert)(!(0, viteIsSSR_js_1.viteIsSSR_safe)(config, options));
52
52
  const importStatements = await (0, parseEsModule_js_1.getImportStatements)(src);
53
53
  const moduleNames = getImportedModules(importStatements);
54
54
  const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
@@ -65,7 +65,7 @@ function extractAssetsPlugin() {
65
65
  // - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
66
66
  enforce: 'pre',
67
67
  async resolveId(source, importer, options) {
68
- if ((0, viteIsSSR_js_1.viteIsSSR_options)(options)) {
68
+ if ((0, viteIsSSR_js_1.viteIsSSR_safe)(config, options)) {
69
69
  // When building for the server, there should never be a `?extractAssets` query
70
70
  (0, utils_js_1.assert)(!extractAssetsRE.test(source));
71
71
  (0, utils_js_1.assert)(importer === undefined || !extractAssetsRE.test(importer));
@@ -11,7 +11,7 @@ const viteIsSSR_js_1 = require("../shared/viteIsSSR.js");
11
11
  const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
12
12
  exports.extractExportNamesRE = extractExportNamesRE;
13
13
  const debug = (0, utils_js_1.createDebugger)('vike:extractExportNames');
14
- const globalObject = (0, utils_js_1.getGlobalObject)('extractExportNamesPlugin.ts', {});
14
+ const globalObject = (0, utils_js_1.getGlobalObject)('plugins/extractExportNamesPlugin.ts', {});
15
15
  function extractExportNamesPlugin() {
16
16
  let isDev = false;
17
17
  return {
@@ -16,7 +16,7 @@ const getEnvVarObject_js_1 = require("../../../../shared/getEnvVarObject.js");
16
16
  const execA = (0, util_1.promisify)(child_process_1.exec);
17
17
  const debug = (0, utils_js_1.createDebugger)('vike:crawl');
18
18
  (0, utils_js_1.assertIsNotProductionRuntime)();
19
- (0, utils_js_1.assertIsSingleModuleInstance)('crawlPlusFiles.ts');
19
+ (0, utils_js_1.assertIsSingleModuleInstance)('getVikeConfig/crawlPlusFiles.ts');
20
20
  let gitIsNotUsable = false;
21
21
  async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
22
22
  (0, utils_js_1.assertPosixPath)(userRootDir);
@@ -13,7 +13,7 @@ exports.getConfigDefinitionOptional = getConfigDefinitionOptional;
13
13
  const utils_js_1 = require("../../../utils.js");
14
14
  const configDefinitionsBuiltIn_js_1 = require("./getVikeConfig/configDefinitionsBuiltIn.js");
15
15
  const filesystemRouting_js_1 = require("./getVikeConfig/filesystemRouting.js");
16
- const isConfigInvalid_js_1 = require("../../../../runtime/renderPage/isConfigInvalid.js");
16
+ const isVikeConfigInvalid_js_1 = require("../../../../runtime/renderPage/isVikeConfigInvalid.js");
17
17
  const globalContext_js_1 = require("../../../../runtime/globalContext.js");
18
18
  const loggerNotProd_js_1 = require("../../../shared/loggerNotProd.js");
19
19
  const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/removeSuperfluousViteLog.js");
@@ -43,7 +43,7 @@ function reloadVikeConfig(config) {
43
43
  handleReloadSideEffects();
44
44
  }
45
45
  async function handleReloadSideEffects() {
46
- wasConfigInvalid = !!isConfigInvalid_js_1.isConfigInvalid;
46
+ wasConfigInvalid = !!isVikeConfigInvalid_js_1.isVikeConfigInvalid;
47
47
  const vikeConfigPromisePrevious = vikeConfigPromise;
48
48
  try {
49
49
  await vikeConfigPromise;
@@ -58,7 +58,7 @@ async function handleReloadSideEffects() {
58
58
  // Let the next handleReloadSideEffects() call handle side effects
59
59
  return;
60
60
  }
61
- if (!isConfigInvalid_js_1.isConfigInvalid) {
61
+ if (!isVikeConfigInvalid_js_1.isVikeConfigInvalid) {
62
62
  if (wasConfigInvalid) {
63
63
  wasConfigInvalid = false;
64
64
  (0, loggerNotProd_js_1.logConfigErrorRecover)();
@@ -111,13 +111,13 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
111
111
  if (!hasError) {
112
112
  (0, utils_js_1.assert)(ret);
113
113
  (0, utils_js_1.assert)(err === undefined);
114
- (0, isConfigInvalid_js_1.isConfigInvalid_set)(false);
114
+ (0, isVikeConfigInvalid_js_1.isVikeConfigInvalid_set)(false);
115
115
  return ret;
116
116
  }
117
117
  else {
118
118
  (0, utils_js_1.assert)(ret === undefined);
119
119
  (0, utils_js_1.assert)(err);
120
- (0, isConfigInvalid_js_1.isConfigInvalid_set)({ err });
120
+ (0, isVikeConfigInvalid_js_1.isVikeConfigInvalid_set)({ err });
121
121
  if (!isDev) {
122
122
  (0, utils_js_1.assert)((0, globalContext_js_1.getViteDevServer)() === null);
123
123
  throw err;
@@ -2,21 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.viteIsSSR = viteIsSSR;
4
4
  exports.viteIsSSR_options = viteIsSSR_options;
5
+ exports.viteIsSSR_safe = viteIsSSR_safe;
5
6
  const assert_js_1 = require("../../../utils/assert.js");
6
- const isObject_js_1 = require("../../../utils/isObject.js");
7
7
  function viteIsSSR(config) {
8
8
  return !!config?.build?.ssr;
9
9
  }
10
- // https://github.com/vitejs/vite/discussions/5109#discussioncomment-1450726
11
10
  function viteIsSSR_options(options) {
12
- if (options === undefined) {
13
- return false;
14
- }
15
- if (typeof options === 'boolean') {
16
- return options;
11
+ return !!options?.ssr;
12
+ }
13
+ // Vite is quite messy about setting `ssr: boolean`, thus we use an extra safe implemention for security purposes.
14
+ // It's used for .client.js and .server.js guarantee thus we use agressive assert() calls for added safety.
15
+ function viteIsSSR_safe(config, options) {
16
+ if (config.command === 'build') {
17
+ (0, assert_js_1.assert)(typeof config.build.ssr === 'boolean');
18
+ const val = config.build.ssr;
19
+ if (options?.ssr !== undefined)
20
+ (0, assert_js_1.assert)(val === options.ssr);
21
+ return val;
17
22
  }
18
- if ((0, isObject_js_1.isObject)(options)) {
19
- return !!options.ssr;
23
+ else {
24
+ (0, assert_js_1.assert)(typeof options?.ssr === 'boolean');
25
+ const val = options.ssr;
26
+ /* This assert() fails (which is very unexpected).
27
+ if (typeof config.build.ssr === 'boolean') assert(val === config.build.ssr)
28
+ //*/
29
+ return val;
20
30
  }
21
- (0, assert_js_1.assert)(false);
22
31
  }
@@ -37,7 +37,7 @@ const assertV1Design_js_1 = require("../shared/assertV1Design.js");
37
37
  const getPageConfigsRuntime_js_1 = require("../../shared/getPageConfigsRuntime.js");
38
38
  const resolveBase_js_1 = require("../shared/resolveBase.js");
39
39
  const debug = (0, utils_js_1.createDebugger)('vike:globalContext');
40
- const globalObject = (0, utils_js_1.getGlobalObject)('globalContext.ts', getInitialGlobalContext());
40
+ const globalObject = (0, utils_js_1.getGlobalObject)('runtime/globalContext.ts', getInitialGlobalContext());
41
41
  async function getGlobalContextInternal() {
42
42
  // getGlobalContextInternal() should always be called after initGlobalContext()
43
43
  (0, utils_js_1.assert)(globalObject.isInitialized);
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.assertNoInfiniteHttpRedirect = assertNoInfiniteHttpRedirect;
7
7
  const utils_js_1 = require("../../utils.js");
8
8
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
9
- const globalObject = (0, utils_js_1.getGlobalObject)('assertNoInfiniteHttpRedirect.ts', {
9
+ const globalObject = (0, utils_js_1.getGlobalObject)('createHttpResponse/assertNoInfiniteHttpRedirect.ts', {
10
10
  redirectGraph: {}
11
11
  });
12
12
  function assertNoInfiniteHttpRedirect(urlRedirectTarget, urlLogical) {
@@ -5,6 +5,7 @@ exports.createHttpResponsePageContextJson = createHttpResponsePageContextJson;
5
5
  exports.createHttpResponseError = createHttpResponseError;
6
6
  exports.createHttpResponseRedirect = createHttpResponseRedirect;
7
7
  exports.createHttpResponseFavicon404 = createHttpResponseFavicon404;
8
+ exports.createHttpResponseBaseIsMissing = createHttpResponseBaseIsMissing;
8
9
  const utils_js_1 = require("../utils.js");
9
10
  const error_page_js_1 = require("../../../shared/error-page.js");
10
11
  const getHttpResponseBody_js_1 = require("./getHttpResponseBody.js");
@@ -40,6 +41,29 @@ function createHttpResponseFavicon404() {
40
41
  const httpResponse = createHttpResponse(404, 'text/html;charset=utf-8', [], "<p>No favicon.ico found.</p><script>console.log('This HTTP response was generated by Vike.')</script>");
41
42
  return httpResponse;
42
43
  }
44
+ function createHttpResponseBaseIsMissing(urlOriginal, baseServer) {
45
+ const httpResponse = createHttpResponse(
46
+ // We use the error code `500` to signal a failing state because this HTTP response should never be used, see https://vike.dev/base-url#setup
47
+ // In other words: this HTTP response is expected to be generated but isn't expected to be actually used.
48
+ 500, 'text/html;charset=utf-8', [], `
49
+ <h1>Error: Base URL is missing</h1>
50
+ <p>
51
+ <a href="https://vike.dev/renderPage"><code>renderPage(pageContextInit)</code></a> called with <code>pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}</code> which doesn't start with the Base URL <code>${baseServer}</code>.
52
+ </p>
53
+ <p>
54
+ See <a href="https://vike.dev/base-url#setup">vike.dev/base-url#setup</a> for how to properly setup your server while using a Base URL.
55
+ </p>
56
+ <style>
57
+ code {
58
+ font-family: monospace;
59
+ background-color: #eaeaea;
60
+ padding: 3px 5px;
61
+ border-radius: 4px;
62
+ }
63
+ </style>
64
+ `);
65
+ return httpResponse;
66
+ }
43
67
  function createHttpResponseError(pageContext) {
44
68
  const reason = (() => {
45
69
  if (!pageContext) {
@@ -8,7 +8,7 @@ const retrieveAssetsProd_js_1 = require("./getPageAssets/retrieveAssetsProd.js")
8
8
  const inferMediaType_js_1 = require("./inferMediaType.js");
9
9
  const getManifestEntry_js_1 = require("./getPageAssets/getManifestEntry.js");
10
10
  const sortPageAssetsForEarlyHintsHeader_js_1 = require("./getPageAssets/sortPageAssetsForEarlyHintsHeader.js");
11
- const globalObject = (0, utils_js_1.getGlobalObject)('getPageAssets.ts', {
11
+ const globalObject = (0, utils_js_1.getGlobalObject)('renderPage/getPageAssets.ts', {
12
12
  resolveClientEntriesDev: null
13
13
  });
14
14
  async function getPageAssets(pageContext, clientDependencies, clientEntries) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handlePageContextRequestUrl = handlePageContextRequestUrl;
4
4
  const getPageContextRequestUrl_js_1 = require("../../../shared/getPageContextRequestUrl.js");
5
5
  const utils_js_1 = require("../utils.js");
6
- // See shared/getPageContextRequestUrl.ts
6
+ // See also shared/getPageContextRequestUrl.ts
7
7
  function handlePageContextRequestUrl(url) {
8
8
  if (!hasSuffix(url)) {
9
9
  return { urlWithoutPageContextRequestSuffix: url, isPageContextRequest: false };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNewError = isNewError;
4
4
  exports.setAlreadyLogged = setAlreadyLogged;
5
5
  const utils_js_1 = require("../utils.js");
6
- const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage/isNewError.ts', {
6
+ const globalObject = (0, utils_js_1.getGlobalObject)('renderPage/isNewError.ts', {
7
7
  wasAlreadyLogged: new WeakSet()
8
8
  });
9
9
  function isNewError(errErrorPage, errNominalPage) {
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isVikeConfigInvalid_set = exports.isVikeConfigInvalid = void 0;
4
+ const utils_js_1 = require("../utils.js");
5
+ let isVikeConfigInvalid;
6
+ const isVikeConfigInvalid_set = (val) => {
7
+ (0, utils_js_1.assert)(val === false || val.err);
8
+ exports.isVikeConfigInvalid = isVikeConfigInvalid = val;
9
+ };
10
+ exports.isVikeConfigInvalid_set = isVikeConfigInvalid_set;
@@ -16,7 +16,7 @@ const loggerRuntime_js_1 = require("./renderPage/loggerRuntime.js");
16
16
  const isNewError_js_1 = require("./renderPage/isNewError.js");
17
17
  const assertArguments_js_1 = require("./renderPage/assertArguments.js");
18
18
  const index_js_2 = require("./renderPage/log404/index.js");
19
- const isConfigInvalid_js_1 = require("./renderPage/isConfigInvalid.js");
19
+ const isVikeConfigInvalid_js_1 = require("./renderPage/isVikeConfigInvalid.js");
20
20
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
21
21
  const serializePageContextClientSide_js_1 = require("./html/serializePageContextClientSide.js");
22
22
  const error_page_js_1 = require("../../shared/error-page.js");
@@ -30,12 +30,11 @@ const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage.ts', {
30
30
  async function renderPage(pageContextInit) {
31
31
  (0, assertArguments_js_1.assertArguments)(...arguments);
32
32
  (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextInit, 'urlOriginal', 'string')); // assertUsage() already implemented at assertArguments()
33
- (0, utils_js_1.onSetupRuntime)();
34
33
  assertIsUrl(pageContextInit.urlOriginal);
35
- const urlPathnameWithBase = (0, utils_js_1.parseUrl)(pageContextInit.urlOriginal, '/').pathname;
36
- assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
37
- if (urlPathnameWithBase.endsWith('/favicon.ico'))
38
- return getPageContextHttpResponseFavicon404(pageContextInit);
34
+ (0, utils_js_1.onSetupRuntime)();
35
+ const pageContextInvalidRequest = renderInvalidRequest(pageContextInit);
36
+ if (pageContextInvalidRequest)
37
+ return pageContextInvalidRequest;
39
38
  const httpRequestId = getRequestId();
40
39
  const urlOriginalPretty = (0, utils_js_1.getUrlPretty)(pageContextInit.urlOriginal);
41
40
  logHttpRequest(urlOriginalPretty, httpRequestId);
@@ -55,15 +54,10 @@ function renderPage_addAsyncHookwrapper(wrapper) {
55
54
  }
56
55
  async function renderPageAndPrepare(pageContextInit, httpRequestId) {
57
56
  // Invalid config
58
- const handleInvalidConfig = (err) => {
59
- (0, loggerRuntime_js_1.logRuntimeInfo)?.(picocolors_1.default.bold(picocolors_1.default.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
60
- const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
61
- return pageContextWithError;
62
- };
63
- if (isConfigInvalid_js_1.isConfigInvalid) {
57
+ if (isVikeConfigInvalid_js_1.isVikeConfigInvalid) {
64
58
  if (1 < 2 // Make TS happy
65
59
  ) {
66
- return handleInvalidConfig(isConfigInvalid_js_1.isConfigInvalid.err);
60
+ return renderInvalidVikeConfig(isVikeConfigInvalid_js_1.isVikeConfigInvalid.err, pageContextInit, httpRequestId);
67
61
  }
68
62
  }
69
63
  // Prepare context
@@ -81,15 +75,19 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
81
75
  const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
82
76
  return pageContextWithError;
83
77
  }
84
- if (isConfigInvalid_js_1.isConfigInvalid) {
85
- return handleInvalidConfig(isConfigInvalid_js_1.isConfigInvalid.err);
78
+ if (isVikeConfigInvalid_js_1.isVikeConfigInvalid) {
79
+ return renderInvalidVikeConfig(isVikeConfigInvalid_js_1.isVikeConfigInvalid.err, pageContextInit, httpRequestId);
86
80
  }
87
81
  else {
88
- // From now on, globalContext contains all the configuration data; getVikeConfig() isn't called anymore for this request
82
+ // `globalContext` now contains the entire Vike config and getVikeConfig() isn't called anymore for this request.
89
83
  }
90
84
  const globalContext = await (0, globalContext_js_1.getGlobalContextInternal)();
91
85
  // Check Base URL
92
- await assertBaseUrl(pageContextInit, globalContext);
86
+ {
87
+ const pageContextHttpResponse = await checkBaseUrl(pageContextInit, globalContext);
88
+ if (pageContextHttpResponse)
89
+ return pageContextHttpResponse;
90
+ }
93
91
  // Normalize URL
94
92
  {
95
93
  const pageContextHttpResponse = await normalizeUrl(pageContextInit, globalContext, httpRequestId);
@@ -257,15 +255,6 @@ function getPageContextHttpResponseError(err, pageContextInit, pageContext) {
257
255
  });
258
256
  return pageContextWithError;
259
257
  }
260
- function getPageContextHttpResponseFavicon404(pageContextInit) {
261
- const pageContext = createPageContext(pageContextInit);
262
- const httpResponse = (0, createHttpResponse_js_1.createHttpResponseFavicon404)();
263
- (0, utils_js_1.objectAssign)(pageContext, {
264
- httpResponse
265
- });
266
- (0, utils_js_1.checkType)(pageContext);
267
- return pageContext;
268
- }
269
258
  function createPageContext(pageContextInit) {
270
259
  const pageContext = {
271
260
  _isPageContextObject: true
@@ -458,10 +447,35 @@ pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalConte
458
447
  (0, utils_js_1.assert)(pageContextAbort.abortStatusCode);
459
448
  return { pageContextAbort };
460
449
  }
461
- async function assertBaseUrl(pageContextInit, globalContext) {
450
+ async function checkBaseUrl(pageContextInit, globalContext) {
462
451
  const { baseServer } = globalContext;
463
452
  const { urlOriginal } = pageContextInit;
464
- const { urlWithoutPageContextRequestSuffix } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
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)`);
453
+ const { isBaseMissing } = (0, utils_js_1.parseUrl)(urlOriginal, baseServer);
454
+ if (!isBaseMissing)
455
+ return;
456
+ const pageContext = createPageContext(pageContextInit);
457
+ const httpResponse = (0, createHttpResponse_js_1.createHttpResponseBaseIsMissing)(urlOriginal, baseServer);
458
+ (0, utils_js_1.objectAssign)(pageContext, {
459
+ httpResponse,
460
+ isBaseMissing: true
461
+ });
462
+ (0, utils_js_1.checkType)(pageContext);
463
+ return pageContext;
464
+ }
465
+ function renderInvalidRequest(pageContextInit) {
466
+ const urlPathnameWithBase = (0, utils_js_1.parseUrl)(pageContextInit.urlOriginal, '/').pathname;
467
+ assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
468
+ if (urlPathnameWithBase.endsWith('/favicon.ico')) {
469
+ const pageContext = createPageContext(pageContextInit);
470
+ const httpResponse = (0, createHttpResponse_js_1.createHttpResponseFavicon404)();
471
+ (0, utils_js_1.objectAssign)(pageContext, { httpResponse });
472
+ (0, utils_js_1.checkType)(pageContext);
473
+ return pageContext;
474
+ }
475
+ return null;
476
+ }
477
+ function renderInvalidVikeConfig(err, pageContextInit, httpRequestId) {
478
+ (0, loggerRuntime_js_1.logRuntimeInfo)?.(picocolors_1.default.bold(picocolors_1.default.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
479
+ const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
480
+ return pageContextWithError;
467
481
  }
@@ -9,7 +9,7 @@ exports.pageContextJsonFileExtension = pageContextJsonFileExtension;
9
9
  // `/some-base-url/index.pageContext.json` instead of `/some-base-url.pageContext.json` in order to comply to common reverse proxy setups, see https://github.com/vikejs/vike/issues/443
10
10
  const doNotCreateExtraDirectory = false;
11
11
  exports.doNotCreateExtraDirectory = doNotCreateExtraDirectory;
12
- // See node/renderPage/handlePageContextRequestUrl.ts
12
+ // See also node/renderPage/handlePageContextRequestUrl.ts
13
13
  function getPageContextRequestUrl(url) {
14
14
  const pageContextRequestUrl = (0, urlToFile_js_1.urlToFile)(url, pageContextJsonFileExtension, doNotCreateExtraDirectory);
15
15
  return pageContextRequestUrl;
@@ -39,26 +39,29 @@ function getUrlParsed(pageContext) {
39
39
  // 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
40
40
  // Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
41
41
  // Determine logical URL
42
- // TODO/soon: revert https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
43
- const assertUrlResolved = (src) => (0, utils_js_1.assert)(urlResolved && typeof urlResolved === 'string', { src, urlResolved });
42
+ const assertUrlResolved = (src) => (0, utils_js_1.assert)(urlResolved && typeof urlResolved === 'string',
43
+ // TODO/eventually: remove debug logs, see:
44
+ // - https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
45
+ // - https://github.com/vikejs/vike/commit/5c7810f3080ab62536950f26e019bb2a3a517082
46
+ { src, urlResolved });
44
47
  let urlResolved;
45
- let baseToBeRemoved;
48
+ let isBaseToBeRemoved;
46
49
  if (pageContext.urlLogical) {
47
50
  // Set by onBeforeRoute()
48
51
  urlResolved = pageContext.urlLogical;
49
- baseToBeRemoved = false;
52
+ isBaseToBeRemoved = false;
50
53
  assertUrlResolved(1);
51
54
  }
52
55
  else if (pageContext._urlRewrite) {
53
56
  // Set by `throw render()`
54
57
  urlResolved = pageContext._urlRewrite;
55
- baseToBeRemoved = false;
58
+ isBaseToBeRemoved = false;
56
59
  assertUrlResolved(2);
57
60
  }
58
61
  else {
59
62
  // Set by renderPage()
60
63
  urlResolved = pageContext.urlOriginal;
61
- baseToBeRemoved = true;
64
+ isBaseToBeRemoved = true;
62
65
  assertUrlResolved(3);
63
66
  }
64
67
  assertUrlResolved(4);
@@ -71,7 +74,7 @@ function getUrlParsed(pageContext) {
71
74
  // - We assume there isn't any Base URL to the URLs set by the user at `throw render()` and onBeforeRoute()
72
75
  // - This makes sense because the Base URL is merely a setting: ideally the user should write code that doesn't know anything about it (so that the user can remove/add/change Base URL without having to modify any code).
73
76
  // - pageContext.urlOriginal is the URL of the HTTP request and thus contains the Base URL.
74
- const baseServer = !baseToBeRemoved ? '/' : pageContext._baseServer;
77
+ const baseServer = !isBaseToBeRemoved ? '/' : pageContext._baseServer;
75
78
  // Parse URL
76
79
  return (0, utils_js_1.parseUrl)(urlResolved, baseServer);
77
80
  }
@@ -14,7 +14,7 @@ const helpers_js_1 = require("../page-configs/helpers.js");
14
14
  const getConfigValueRuntime_js_1 = require("../page-configs/getConfigValueRuntime.js");
15
15
  const utils_js_1 = require("../utils.js");
16
16
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
17
- const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('getHook.ts', {});
17
+ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('hooks/getHook.ts', {});
18
18
  function getHook(pageContext, hookName) {
19
19
  if (!(hookName in pageContext.exports)) {
20
20
  return null;
@@ -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-5513d32';
5
+ exports.PROJECT_VERSION = '0.4.222-commit-fab3841';
@@ -21,7 +21,7 @@ const isVitest_js_1 = require("./isVitest.js");
21
21
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
22
22
  (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
23
23
  const debug = (0, debug_js_1.createDebugger)('vike:setup');
24
- const setup = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertIsNotProductionRuntime.ts', {});
24
+ const setup = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertSetup.ts', {});
25
25
  // Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
26
26
  function assertIsNotProductionRuntime() {
27
27
  if (debug.isActivated)
@@ -16,7 +16,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
16
16
  /* Use original assertUsage() & assertWarning() after all CJS is removed from node_modules/vike/dist/
17
17
  import { assertUsage, assertWarning } from './assert.js'
18
18
  */
19
- const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('assertSingleInstance.ts', {
19
+ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertSingleInstance.ts', {
20
20
  instances: [],
21
21
  alreadyLogged: new Set()
22
22
  });
@@ -4,17 +4,13 @@ exports.getGlobalObject = getGlobalObject;
4
4
  exports.assertIsSingleModuleInstance = assertIsSingleModuleInstance;
5
5
  const assert_js_1 = require("./assert.js");
6
6
  /** Share information across module instances. */
7
- function getGlobalObject(
8
- // We use the filename (or file path) as key. There should be only one getGlobalObject() usage per file. Thus the key should be unique, assuming the filename (or file path) is unique.
9
- key, defaultValue) {
7
+ function getGlobalObject(key, defaultValue) {
10
8
  const globalObjects = getGlobalObjects();
11
9
  const globalObject = (globalObjects[key] = globalObjects[key] || defaultValue);
12
10
  return globalObject;
13
11
  }
14
12
  /** Assert that the module is instantiated only once. */
15
- function assertIsSingleModuleInstance(
16
- // We use the filename (or file path) as key.
17
- key) {
13
+ function assertIsSingleModuleInstance(key) {
18
14
  const globalObjects = getGlobalObjects();
19
15
  (0, assert_js_1.assert)(!(key in globalObjects));
20
16
  }
@@ -1,7 +1,7 @@
1
1
  export { setPageContextCurrent };
2
2
  export { getPageContextCurrent };
3
3
  import { getGlobalObject } from './utils.js';
4
- const globalObject = getGlobalObject('getPageContextCurrent.ts', {
4
+ const globalObject = getGlobalObject('client-routing-runtime/getPageContextCurrent.ts', {
5
5
  pageContextCurrent: null
6
6
  });
7
7
  function getPageContextCurrent() {
@@ -18,7 +18,7 @@ import { executeGuardHook } from '../../shared/route/executeGuardHook.js';
18
18
  import { AbortRender, isAbortPageContext } from '../../shared/route/abort.js';
19
19
  import { pageContextInitIsPassedToClient } from '../../shared/misc/pageContextInitIsPassedToClient.js';
20
20
  import { isServerSideError } from '../../shared/misc/isServerSideError.js';
21
- const globalObject = getGlobalObject('router/getPageContext.ts', {});
21
+ const globalObject = getGlobalObject('client-routing-runtime/getPageContextFromHooks.ts', {});
22
22
  // TODO/eventually: rename
23
23
  function getPageContextFromHooks_serialized() {
24
24
  const pageContextSerialized = getPageContextSerializedInHtml();
@@ -7,7 +7,7 @@ export { monkeyPatchHistoryAPI };
7
7
  import { getCurrentUrl } from '../shared/getCurrentUrl.js';
8
8
  import { assert, assertUsage, getGlobalObject, isObject } from './utils.js';
9
9
  initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
10
- const globalObject = getGlobalObject('history.ts', { previous: getHistoryInfo() });
10
+ const globalObject = getGlobalObject('client-routing-runtime/history.ts', { previous: getHistoryInfo() });
11
11
  // `window.history.state === null` when:
12
12
  // - The very first render
13
13
  // - Click on `<a href="#some-hash" />`
@@ -19,7 +19,7 @@ import { PAGE_CONTEXT_MAX_AGE_DEFAULT, getPrefetchSettings } from './prefetch/ge
19
19
  import pc from '@brillout/picocolors';
20
20
  import { normalizeUrlArgument } from './normalizeUrlArgument.js';
21
21
  assertClientRouting();
22
- const globalObject = getGlobalObject('prefetch.ts', {
22
+ const globalObject = getGlobalObject('client-routing-runtime/prefetch.ts', {
23
23
  linkPrefetchHandlerAdded: new WeakSet(),
24
24
  addLinkPrefetchHandlers_debounce: null,
25
25
  mutationObserver: new MutationObserver(addLinkPrefetchHandlers),
@@ -20,7 +20,7 @@ import { getErrorPageId } from '../../shared/error-page.js';
20
20
  import { setPageContextCurrent } from './getPageContextCurrent.js';
21
21
  import { getRouteStringParameterList } from '../../shared/route/resolveRouteString.js';
22
22
  import { getCurrentUrl } from '../shared/getCurrentUrl.js';
23
- const globalObject = getGlobalObject('renderPageClientSide.ts', (() => {
23
+ const globalObject = getGlobalObject('client-routing-runtime/renderPageClientSide.ts', (() => {
24
24
  const { promise: firstRenderStartPromise, resolve: firstRenderStartPromiseResolve } = genPromise();
25
25
  return {
26
26
  previousPageContext: null,
@@ -6,7 +6,7 @@ export { scrollRestoration_initialRenderIsDone };
6
6
  // - Firefox doesn't restore the scroll position upon page reload but does upon Cmd-Shift-T
7
7
  // See also: https://github.com/cyco130/knave/blob/e9e1bc7687848504293197f1b314b7d12ad0d228/design.md#scroll-restoration
8
8
  import { getGlobalObject, onPageHide, onPageShow } from './utils.js';
9
- const globalObject = getGlobalObject('scrollRestoration.ts', {});
9
+ const globalObject = getGlobalObject('client-routing-runtime/scrollRestoration.ts', {});
10
10
  function scrollRestoration_init() {
11
11
  // Use the native scroll restoration mechanism only for the first render
12
12
  scrollRestoration_enable();
@@ -1,7 +1,7 @@
1
1
  export { getPageContextProxyForUser };
2
2
  import { assert, assertUsage, assertWarning, getGlobalObject, getPropAccessNotation } from '../server-routing-runtime/utils.js';
3
3
  import { notSerializable } from '../../shared/notSerializable.js';
4
- const globalObject = getGlobalObject('getPageContextProxyForUser.ts', {});
4
+ const globalObject = getGlobalObject('shared/getPageContextProxyForUser.ts', {});
5
5
  /**
6
6
  * Throw error when pageContext value isn't:
7
7
  * - serializable, or
@@ -10,7 +10,7 @@ import path from 'path';
10
10
  import { assert, assertUsage, getGlobalObject, isObject, toPosixPath } from './utils.js';
11
11
  import pc from '@brillout/picocolors';
12
12
  import { clearGlobalContext } from '../runtime/globalContext.js';
13
- const globalObject = getGlobalObject('prepareViteApiCall.ts', {});
13
+ const globalObject = getGlobalObject('api/prepareViteApiCall.ts', {});
14
14
  async function prepareViteApiCall(viteConfigFromOptions, operation) {
15
15
  clear();
16
16
  setContextApiOperation(operation);