vike 0.4.146 → 0.4.147-commit-2fa53b2

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 (83) hide show
  1. package/dist/cjs/node/plugin/index.js +6 -4
  2. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -4
  3. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +76 -0
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +61 -40
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +104 -0
  6. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +62 -75
  7. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +43 -17
  8. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +12 -70
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +11 -8
  10. package/dist/cjs/node/plugin/shared/{getConfigValueSourcesRelevant.js → getConfigValueSourcesNotOverriden.js} +3 -3
  11. package/dist/cjs/node/plugin/utils.js +2 -0
  12. package/dist/cjs/node/prerender/runPrerender.js +75 -67
  13. package/dist/cjs/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
  14. package/dist/cjs/node/runtime/index-common.js +3 -1
  15. package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
  16. package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js +12 -12
  17. package/dist/cjs/node/runtime/renderPage/createHttpResponseObject.js +3 -3
  18. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -2
  19. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
  20. package/dist/cjs/node/runtime/renderPage.js +10 -7
  21. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -0
  22. package/dist/cjs/shared/page-configs/loadConfigValues.js +12 -3
  23. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +19 -0
  24. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +3 -12
  25. package/dist/cjs/utils/assertKeys.js +28 -0
  26. package/dist/cjs/utils/joinEnglish.js +3 -3
  27. package/dist/cjs/utils/parseUrl-extras.js +16 -7
  28. package/dist/cjs/utils/parseUrl.js +24 -16
  29. package/dist/cjs/utils/projectInfo.js +3 -2
  30. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +25 -11
  31. package/dist/esm/client/client-routing-runtime/index.d.ts +1 -0
  32. package/dist/esm/client/client-routing-runtime/index.js +1 -0
  33. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +2 -2
  34. package/dist/esm/client/shared/getPageContextSerializedInHtml.js +1 -1
  35. package/dist/esm/node/plugin/index.d.ts +1 -0
  36. package/dist/esm/node/plugin/index.js +1 -0
  37. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -4
  38. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +5 -0
  39. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +70 -0
  40. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +58 -37
  41. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +5 -0
  42. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +98 -0
  43. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +63 -76
  44. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +43 -17
  45. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +0 -3
  46. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +13 -68
  47. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +11 -8
  48. package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.d.ts +5 -0
  49. package/dist/esm/node/plugin/shared/{getConfigValueSourcesRelevant.js → getConfigValueSourcesNotOverriden.js} +2 -2
  50. package/dist/esm/node/plugin/utils.d.ts +2 -0
  51. package/dist/esm/node/plugin/utils.js +2 -0
  52. package/dist/esm/node/prerender/runPrerender.js +75 -67
  53. package/dist/esm/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
  54. package/dist/esm/node/runtime/index-common.d.ts +1 -0
  55. package/dist/esm/node/runtime/index-common.js +1 -0
  56. package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
  57. package/dist/esm/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.d.ts +1 -1
  58. package/dist/esm/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js +12 -12
  59. package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +1 -1
  60. package/dist/esm/node/runtime/renderPage/createHttpResponseObject.js +3 -3
  61. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -2
  62. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +1 -1
  63. package/dist/esm/node/runtime/renderPage.js +11 -8
  64. package/dist/esm/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -0
  65. package/dist/esm/shared/page-configs/PageConfig.d.ts +14 -4
  66. package/dist/esm/shared/page-configs/loadConfigValues.js +12 -3
  67. package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.d.ts +4 -0
  68. package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +16 -0
  69. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +4 -13
  70. package/dist/esm/utils/assertKeys.d.ts +4 -0
  71. package/dist/esm/utils/assertKeys.js +22 -0
  72. package/dist/esm/utils/joinEnglish.d.ts +1 -1
  73. package/dist/esm/utils/joinEnglish.js +3 -3
  74. package/dist/esm/utils/parseUrl-extras.d.ts +1 -1
  75. package/dist/esm/utils/parseUrl-extras.js +16 -7
  76. package/dist/esm/utils/parseUrl.js +24 -16
  77. package/dist/esm/utils/projectInfo.d.ts +3 -1
  78. package/dist/esm/utils/projectInfo.js +2 -1
  79. package/package.json +3 -3
  80. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +0 -28
  81. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.d.ts +0 -5
  82. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +0 -25
  83. package/dist/esm/node/plugin/shared/getConfigValueSourcesRelevant.d.ts +0 -5
@@ -2,7 +2,7 @@ export { renderPage };
2
2
  export { renderPage_addWrapper };
3
3
  import { getRenderContext, getPageContextInitEnhanced, renderPageAlreadyRouted } from './renderPage/renderPageAlreadyRouted.js';
4
4
  import { route } from '../../shared/route/index.js';
5
- import { assert, hasProp, objectAssign, isParsable, parseUrl, assertEnv, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, addUrlOrigin } from './utils.js';
5
+ import { assert, hasProp, objectAssign, isParsable, parseUrl, assertEnv, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, addUrlOrigin, createUrlFromComponents } from './utils.js';
6
6
  import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError, logAbortErrorHandled } from '../../shared/route/abort.js';
7
7
  import { getGlobalContext, initGlobalContext } from './globalContext.js';
8
8
  import { handlePageContextRequestUrl } from './renderPage/handlePageContextRequestUrl.js';
@@ -312,11 +312,11 @@ function skipRequest(urlOriginal) {
312
312
  isViteClientRequest);
313
313
  }
314
314
  function normalizeUrl(pageContextInit, httpRequestId) {
315
- const { trailingSlash, disableUrlNormalization } = getGlobalContext();
315
+ const { trailingSlash, disableUrlNormalization, baseServer } = getGlobalContext();
316
316
  if (disableUrlNormalization)
317
317
  return null;
318
318
  const { urlOriginal } = pageContextInit;
319
- const urlNormalized = normalizeUrlPathname(urlOriginal, trailingSlash);
319
+ const urlNormalized = normalizeUrlPathname(urlOriginal, trailingSlash, baseServer);
320
320
  if (!urlNormalized)
321
321
  return null;
322
322
  logRuntimeInfo?.(`URL normalized from ${pc.cyan(urlOriginal)} to ${pc.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
@@ -327,10 +327,8 @@ function normalizeUrl(pageContextInit, httpRequestId) {
327
327
  function getPermanentRedirect(pageContextInit, httpRequestId) {
328
328
  const { redirects, baseServer } = getGlobalContext();
329
329
  const urlWithoutBase = removeBaseServer(pageContextInit.urlOriginal, baseServer);
330
- let urlOriginalPathnameWithouBase;
331
330
  let origin = null;
332
331
  let urlTarget = modifyUrlPathname(urlWithoutBase, (urlPathname) => {
333
- urlOriginalPathnameWithouBase = urlPathname;
334
332
  const urlTargetWithOrigin = resolveRedirects(redirects, urlPathname);
335
333
  if (urlTargetWithOrigin === null)
336
334
  return null;
@@ -340,13 +338,12 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
340
338
  });
341
339
  if (origin)
342
340
  urlTarget = addUrlOrigin(urlTarget, origin);
343
- assert(urlOriginalPathnameWithouBase);
344
341
  if (urlTarget === urlWithoutBase)
345
342
  return null;
346
343
  logRuntimeInfo?.(`Permanent redirect defined by your config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
347
344
  urlTarget = prependBase(urlTarget, baseServer);
348
345
  assert(urlTarget !== pageContextInit.urlOriginal);
349
- const httpResponse = createHttpResponseObjectRedirect({ url: urlTarget, statusCode: 301 }, urlOriginalPathnameWithouBase);
346
+ const httpResponse = createHttpResponseObjectRedirect({ url: urlTarget, statusCode: 301 }, urlWithoutBase);
350
347
  const pageContextHttpResponse = { ...pageContextInit, httpResponse };
351
348
  return pageContextHttpResponse;
352
349
  }
@@ -390,7 +387,13 @@ async function handleAbortError(errAbort, pageContextsFromRewrite, pageContextIn
390
387
  ...pageContextInit,
391
388
  ...pageContextAbort
392
389
  };
393
- const httpResponse = createHttpResponseObjectRedirect(pageContextAbort._urlRedirect, pageContextNominalPageInit.urlPathname);
390
+ const httpResponse = createHttpResponseObjectRedirect(pageContextAbort._urlRedirect, (() => {
391
+ const { pathname, searchOriginal } = pageContextNominalPageInit.urlParsed;
392
+ const urlLogical = createUrlFromComponents(null, pathname, searchOriginal,
393
+ // The server-side doesn't have access to the hash
394
+ null);
395
+ return urlLogical;
396
+ })());
394
397
  objectAssign(pageContextReturn, { httpResponse });
395
398
  return { pageContextReturn };
396
399
  }
@@ -1,3 +1,4 @@
1
+ // TODO/v1-release: remove
1
2
  export { determineClientEntry };
2
3
  export { getVikeClientEntry };
3
4
  function determineClientEntry({ pageFilesClientSide, pageFilesServerSide, isHtmlOnly, isClientRouting }) {
@@ -16,7 +16,7 @@ export type { DefinedAtFile };
16
16
  export type { DefinedAtFileFullInfo };
17
17
  export type { FilePathResolved };
18
18
  export type { FilePath };
19
- import type { ConfigValueImported } from './serialize/PageConfigSerialized.js';
19
+ import type { ConfigValueImported, ConfigValueSerialized } from './serialize/PageConfigSerialized.js';
20
20
  type PageConfigBase = {
21
21
  pageId: string;
22
22
  isErrorPage?: true;
@@ -30,7 +30,10 @@ type PageConfigRuntime = PageConfigBase & {
30
30
  /** All loaded config values */
31
31
  configValues: ConfigValues;
32
32
  /** Load config values that are lazily loaded such as config.Page */
33
- loadConfigValuesAll: () => Promise<ConfigValueImported[]>;
33
+ loadConfigValuesAll: () => Promise<{
34
+ configValuesImported: ConfigValueImported[];
35
+ configValuesSerialized: Record<string, ConfigValueSerialized>;
36
+ }>;
34
37
  };
35
38
  /** Same as PageConfigRuntime but also contains all lazily loaded config values such as config.Page */
36
39
  type PageConfigRuntimeLoaded = PageConfigRuntime & {
@@ -50,9 +53,16 @@ type PageConfigGlobalRuntime = {
50
53
  type PageConfigGlobalBuildTime = {
51
54
  configValueSources: ConfigValueSources;
52
55
  };
53
- type ConfigEnv = 'client-only' | 'server-only' | 'server-and-client' | 'config-only';
56
+ type ConfigEnv = {
57
+ client?: boolean;
58
+ server?: boolean;
59
+ config?: boolean;
60
+ };
54
61
  /** For Vike internal use */
55
- type ConfigEnvInternal = ConfigEnv | '_routing-eager' | '_routing-lazy';
62
+ type ConfigEnvInternal = Omit<ConfigEnv, 'client'> & {
63
+ client?: boolean | 'if-client-routing';
64
+ eager?: boolean;
65
+ };
56
66
  type ConfigValueSource = {
57
67
  value?: unknown;
58
68
  configEnv: ConfigEnvInternal;
@@ -1,15 +1,24 @@
1
1
  export { loadConfigValues };
2
2
  import { objectAssign } from '../utils.js';
3
3
  import { parseConfigValuesImported } from './serialize/parseConfigValuesImported.js';
4
+ import { parseConfigValuesSerialized } from './serialize/parseConfigValuesSerialized.js';
4
5
  async function loadConfigValues(pageConfig, isDev) {
5
6
  if ('isAllLoaded' in pageConfig &&
6
7
  // We don't need to cache in dev, since Vite already caches the virtual module
7
8
  !isDev) {
8
9
  return pageConfig;
9
10
  }
10
- const configValuesImported = await pageConfig.loadConfigValuesAll();
11
- const configValuesAddendum = parseConfigValuesImported(configValuesImported);
12
- Object.assign(pageConfig.configValues, configValuesAddendum);
11
+ const configValuesLoaded = await pageConfig.loadConfigValuesAll();
12
+ {
13
+ const { configValuesImported } = configValuesLoaded;
14
+ const configValuesAddendum = parseConfigValuesImported(configValuesImported);
15
+ Object.assign(pageConfig.configValues, configValuesAddendum);
16
+ }
17
+ {
18
+ const { configValuesSerialized } = configValuesLoaded;
19
+ const configValuesAddendum = parseConfigValuesSerialized(configValuesSerialized);
20
+ Object.assign(pageConfig.configValues, configValuesAddendum);
21
+ }
13
22
  objectAssign(pageConfig, { isAllLoaded: true });
14
23
  return pageConfig;
15
24
  }
@@ -0,0 +1,4 @@
1
+ export { parseConfigValuesSerialized };
2
+ import type { ConfigValues } from '../PageConfig.js';
3
+ import type { ConfigValueSerialized } from './PageConfigSerialized.js';
4
+ declare function parseConfigValuesSerialized(configValuesSerialized: Record<string, ConfigValueSerialized>): ConfigValues;
@@ -0,0 +1,16 @@
1
+ export { parseConfigValuesSerialized };
2
+ import { assert } from '../../utils.js';
3
+ import { parse } from '@brillout/json-serializer/parse';
4
+ function parseConfigValuesSerialized(configValuesSerialized) {
5
+ const configValues = {};
6
+ Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
7
+ const { valueSerialized, definedAt } = configValueSeriliazed;
8
+ assert(valueSerialized);
9
+ assert(!configValues[configName]);
10
+ configValues[configName] = {
11
+ value: parse(valueSerialized),
12
+ definedAt
13
+ };
14
+ });
15
+ return configValues;
16
+ }
@@ -1,24 +1,15 @@
1
1
  export { parsePageConfigs };
2
- import { parse } from '@brillout/json-serializer/parse';
3
2
  import { parseConfigValuesImported } from './parseConfigValuesImported.js';
4
- import { assert, assertUsage, isCallable } from '../../utils.js';
3
+ import { assertUsage, isCallable } from '../../utils.js';
5
4
  import { getConfigDefinedAtString } from '../helpers.js';
5
+ import { parseConfigValuesSerialized } from './parseConfigValuesSerialized.js';
6
6
  function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
7
7
  const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
8
8
  const configValues = {};
9
9
  {
10
10
  const { configValuesSerialized } = pageConfigSerialized;
11
- Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
12
- {
13
- const { valueSerialized, definedAt } = configValueSeriliazed;
14
- assert(valueSerialized);
15
- assert(!configValues[configName]);
16
- configValues[configName] = {
17
- value: parse(valueSerialized),
18
- definedAt
19
- };
20
- }
21
- });
11
+ const configValuesAddendum = parseConfigValuesSerialized(configValuesSerialized);
12
+ Object.assign(configValues, configValuesAddendum);
22
13
  }
23
14
  {
24
15
  const { configValuesImported } = pageConfigSerialized;
@@ -0,0 +1,4 @@
1
+ export { assertKeys };
2
+ declare function assertKeys<Keys extends readonly string[]>(obj: Record<string, unknown>, keysExpected: Keys, errPrefix: string): asserts obj is {
3
+ [key in Keys[number]]?: unknown;
4
+ };
@@ -0,0 +1,22 @@
1
+ export { assertKeys };
2
+ import pc from '@brillout/picocolors';
3
+ import { assertUsage } from './assert.js';
4
+ import { joinEnglish } from './joinEnglish.js';
5
+ function assertKeys(obj, keysExpected, errPrefix) {
6
+ const keysUnknown = [];
7
+ const keys = Object.keys(obj);
8
+ for (const key of keys) {
9
+ if (!keysExpected.includes(key)) {
10
+ keysUnknown.push(key);
11
+ }
12
+ }
13
+ if (keysUnknown.length !== 0) {
14
+ assertUsage(false, [
15
+ errPrefix,
16
+ `unknown key${keysUnknown.length === 1 ? '' : 's'}`,
17
+ joinEnglish(keysUnknown, 'and', pc.cyan) + '.',
18
+ 'Only following keys are allowed:',
19
+ joinEnglish(keysExpected, 'and', pc.cyan) + '.'
20
+ ].join(' '));
21
+ }
22
+ }
@@ -1,2 +1,2 @@
1
1
  export { joinEnglish };
2
- declare function joinEnglish(arr: string[], conjunction: 'or' | 'and'): string;
2
+ declare function joinEnglish(arr: string[] | readonly string[], conjunction: 'or' | 'and', colorizer?: (s: string) => string): string;
@@ -1,11 +1,11 @@
1
1
  export { joinEnglish };
2
2
  import { assert } from './assert.js';
3
3
  // https://stackoverflow.com/questions/53879088/join-an-array-by-commas-and-and/53879103#53879103
4
- function joinEnglish(arr, conjunction) {
4
+ function joinEnglish(arr, conjunction, colorizer = (s) => s) {
5
5
  assert(arr.length > 0);
6
6
  if (arr.length === 1)
7
- return arr[0];
7
+ return colorizer(arr[0]);
8
8
  const firsts = arr.slice(0, arr.length - 1);
9
9
  const last = arr[arr.length - 1];
10
- return firsts.join(', ') + ` ${conjunction} ` + last;
10
+ return firsts.map(colorizer).join(', ') + ` ${conjunction} ` + colorizer(last);
11
11
  }
@@ -8,7 +8,7 @@ export { addUrlOrigin };
8
8
  declare function prependBase(url: string, baseServer: string): string;
9
9
  declare function removeBaseServer(url: string, baseServer: string): string;
10
10
  declare function isBaseAssets(base: string): boolean;
11
- declare function normalizeUrlPathname(urlOriginal: string, trailingSlash: boolean): string | null;
11
+ declare function normalizeUrlPathname(urlOriginal: string, trailingSlash: boolean, baseServer: string): string | null;
12
12
  declare function modifyUrlPathname(url: string, modifier: (urlPathname: string) => string | null): string;
13
13
  declare function removeUrlOrigin(url: string): {
14
14
  urlModified: string;
@@ -53,15 +53,20 @@ function normalizeBaseServer(baseServer) {
53
53
  function isBaseAssets(base) {
54
54
  return base.startsWith('/') || base.startsWith('http://') || base.startsWith('https://');
55
55
  }
56
- function normalizeUrlPathname(urlOriginal, trailingSlash) {
56
+ function normalizeUrlPathname(urlOriginal, trailingSlash, baseServer) {
57
57
  const urlNormalized = modifyUrlPathname(urlOriginal, (urlPathname) => {
58
58
  assert(urlPathname.startsWith('/'));
59
- let urlPathnameNormalized = '/' + urlPathname.split('/').filter(Boolean).join('/');
60
- if (urlPathnameNormalized !== '/') {
61
- assert(!urlPathnameNormalized.endsWith('/'));
62
- if (trailingSlash) {
63
- urlPathnameNormalized = urlPathnameNormalized + '/';
64
- }
59
+ let urlPathnameNormalized = normalize(urlPathname);
60
+ if (urlPathnameNormalized === '/') {
61
+ return urlPathnameNormalized;
62
+ }
63
+ // If the Base URL has a trailing slash, then Vite (as of vite@5.0.0-beta.19) expects the root URL to also have a trailing slash, see https://github.com/vikejs/vike/issues/1258#issuecomment-1812226260
64
+ if (baseServer.endsWith('/') && baseServer !== '/' && normalize(baseServer) === urlPathnameNormalized) {
65
+ trailingSlash = true;
66
+ }
67
+ assert(!urlPathnameNormalized.endsWith('/'));
68
+ if (trailingSlash) {
69
+ urlPathnameNormalized = urlPathnameNormalized + '/';
65
70
  }
66
71
  return urlPathnameNormalized;
67
72
  });
@@ -69,6 +74,10 @@ function normalizeUrlPathname(urlOriginal, trailingSlash) {
69
74
  return null;
70
75
  return urlNormalized;
71
76
  }
77
+ function normalize(urlPathname) {
78
+ assert(urlPathname.startsWith('/'));
79
+ return '/' + urlPathname.split('/').filter(Boolean).join('/');
80
+ }
72
81
  function modifyUrlPathname(url, modifier) {
73
82
  const { origin, pathnameOriginal, searchOriginal, hashOriginal } = parseUrl(url, '/');
74
83
  const pathnameModified = modifier(pathnameOriginal);
@@ -54,7 +54,7 @@ function parseUrl(url, baseServer) {
54
54
  searchAll[key] = [...(searchAll.hasOwnProperty(key) ? searchAll[key] : []), val];
55
55
  });
56
56
  // Origin + pathname
57
- const { origin, pathname: pathnameResolved } = parsePathname(urlWithoutHashNorSearch, baseServer);
57
+ const { origin, pathname: pathnameResolved } = getPathname(urlWithoutHashNorSearch, baseServer);
58
58
  assert(origin === null || origin === decodeSafe(origin)); // AFAICT decoding the origin is useless
59
59
  assert(pathnameResolved.startsWith('/'));
60
60
  assert(origin === null || url.startsWith(origin));
@@ -89,35 +89,43 @@ function decodeSafe(urlComponent) {
89
89
  return urlComponent;
90
90
  }
91
91
  function decodePathname(urlPathname) {
92
+ urlPathname = urlPathname.replace(/\s+$/, '');
92
93
  urlPathname = urlPathname
93
94
  .split('/')
94
95
  .map((dir) => decodeSafe(dir).split('/').join('%2F'))
95
96
  .join('/');
96
- urlPathname = urlPathname.replace(/\s/g, '');
97
97
  return urlPathname;
98
98
  }
99
- function parsePathname(urlWithoutHashNorSearch, baseServer) {
99
+ function getPathname(url, baseServer) {
100
+ // Search and hash already extracted
101
+ assert(!url.includes('?') && !url.includes('#'));
102
+ // url has origin
100
103
  {
101
- const { origin, pathname } = parseOrigin(urlWithoutHashNorSearch);
104
+ const { origin, pathname } = parseOrigin(url);
102
105
  if (origin) {
103
106
  return { origin, pathname };
104
107
  }
105
- assert(pathname === urlWithoutHashNorSearch);
108
+ assert(pathname === url);
106
109
  }
107
- if (urlWithoutHashNorSearch.startsWith('/')) {
108
- return { origin: null, pathname: urlWithoutHashNorSearch };
110
+ // url doesn't have origin
111
+ if (url.startsWith('/')) {
112
+ return { origin: null, pathname: url };
109
113
  }
110
114
  else {
111
- // In the browser, this is the Base URL of the current URL
115
+ // url is a relative path
116
+ // In the browser, this is the Base URL of the current URL.
112
117
  // Safe access `window?.document?.baseURI` for users who shim `window` in Node.js
113
- let baseURI = typeof window !== 'undefined' && window?.document?.baseURI;
114
- if (baseURI)
115
- baseURI = parseOrigin(baseURI).pathname;
116
- const base = baseURI || baseServer;
117
- const pathname = resolveUrlPathnameRelative(urlWithoutHashNorSearch, base);
118
- // We need to parse the origin in case `base === window.document.baseURI`
119
- const parsed = parseOrigin(pathname);
120
- return parsed;
118
+ const baseURI = typeof window !== 'undefined' ? window?.document?.baseURI : undefined;
119
+ let base;
120
+ if (baseURI) {
121
+ const baseURIPathaname = parseOrigin(baseURI.split('?')[0]).pathname;
122
+ base = baseURIPathaname;
123
+ }
124
+ else {
125
+ base = baseServer;
126
+ }
127
+ const pathname = resolveUrlPathnameRelative(url, base);
128
+ return { origin: null, pathname };
121
129
  }
122
130
  }
123
131
  function parseOrigin(url) {
@@ -1,11 +1,13 @@
1
1
  export { projectInfo };
2
2
  export type { ProjectTag };
3
+ export { PROJECT_VERSION };
4
+ declare const PROJECT_VERSION: "0.4.147-commit-2fa53b2";
3
5
  type PackageName = typeof projectInfo.npmPackageName;
4
6
  type ProjectVersion = typeof projectInfo.projectVersion;
5
7
  type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
6
8
  declare const projectInfo: {
7
9
  projectName: "Vike";
8
- projectVersion: "0.4.146";
10
+ projectVersion: "0.4.147-commit-2fa53b2";
9
11
  npmPackageName: "vike";
10
12
  githubRepository: "https://github.com/vikejs/vike";
11
13
  };
@@ -1,6 +1,7 @@
1
1
  export { projectInfo };
2
+ export { PROJECT_VERSION };
2
3
  import { onProjectInfo } from './assertSingleInstance.js';
3
- const PROJECT_VERSION = '0.4.146';
4
+ const PROJECT_VERSION = '0.4.147-commit-2fa53b2';
4
5
  const projectInfo = {
5
6
  projectName: 'Vike',
6
7
  projectVersion: PROJECT_VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.146",
3
+ "version": "0.4.147-commit-2fa53b2",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
@@ -14,7 +14,7 @@
14
14
  "dependencies": {
15
15
  "@brillout/import": "0.2.3",
16
16
  "@brillout/json-serializer": "^0.5.8",
17
- "@brillout/picocolors": "^1.0.9",
17
+ "@brillout/picocolors": "^1.0.10",
18
18
  "@brillout/require-shim": "^0.1.2",
19
19
  "@brillout/vite-plugin-import-build": "^0.2.20",
20
20
  "acorn": "^8.8.2",
@@ -162,7 +162,7 @@
162
162
  "vike": "./node/cli/bin-entry.js"
163
163
  },
164
164
  "devDependencies": {
165
- "@brillout/release-me": "^0.1.8",
165
+ "@brillout/release-me": "^0.1.9",
166
166
  "@types/estree": "^1.0.0",
167
167
  "@types/jest": "^27.4.1",
168
168
  "@types/node": "^20.1.0",
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isConfigSet = exports.getConfigEnv = void 0;
4
- const utils_js_1 = require("../../../utils.js");
5
- (0, utils_js_1.assertIsNotProductionRuntime)();
6
- function getConfigEnv(configValueSources, configName) {
7
- const configValueSource = getConfigValueSource(configValueSources, configName);
8
- if (!configValueSource)
9
- return null;
10
- return configValueSource.configEnv;
11
- }
12
- exports.getConfigEnv = getConfigEnv;
13
- function isConfigSet(configValueSources, configName) {
14
- const configValueSource = getConfigValueSource(configValueSources, configName);
15
- // Enable users to suppress global config values by overriding the config's value to null
16
- if (configValueSource?.value === null)
17
- return false;
18
- return !!configValueSource;
19
- }
20
- exports.isConfigSet = isConfigSet;
21
- function getConfigValueSource(configValueSources, configName) {
22
- const sources = configValueSources[configName];
23
- if (!sources)
24
- return null;
25
- const configValueSource = sources[0];
26
- (0, utils_js_1.assert)(configValueSource);
27
- return configValueSource;
28
- }
@@ -1,5 +0,0 @@
1
- export { getConfigEnv };
2
- export { isConfigSet };
3
- import type { ConfigEnvInternal, ConfigValueSources } from '../../../../../shared/page-configs/PageConfig.js';
4
- declare function getConfigEnv(configValueSources: ConfigValueSources, configName: string): null | ConfigEnvInternal;
5
- declare function isConfigSet(configValueSources: ConfigValueSources, configName: string): boolean;
@@ -1,25 +0,0 @@
1
- export { getConfigEnv };
2
- export { isConfigSet };
3
- import { assert, assertIsNotProductionRuntime } from '../../../utils.js';
4
- assertIsNotProductionRuntime();
5
- function getConfigEnv(configValueSources, configName) {
6
- const configValueSource = getConfigValueSource(configValueSources, configName);
7
- if (!configValueSource)
8
- return null;
9
- return configValueSource.configEnv;
10
- }
11
- function isConfigSet(configValueSources, configName) {
12
- const configValueSource = getConfigValueSource(configValueSources, configName);
13
- // Enable users to suppress global config values by overriding the config's value to null
14
- if (configValueSource?.value === null)
15
- return false;
16
- return !!configValueSource;
17
- }
18
- function getConfigValueSource(configValueSources, configName) {
19
- const sources = configValueSources[configName];
20
- if (!sources)
21
- return null;
22
- const configValueSource = sources[0];
23
- assert(configValueSource);
24
- return configValueSource;
25
- }
@@ -1,5 +0,0 @@
1
- export { getConfigValueSourcesRelevant };
2
- import type { ConfigValueSource, PageConfigBuildTime } from '../../../shared/page-configs/PageConfig.js';
3
- declare function getConfigValueSourcesRelevant(pageConfig: PageConfigBuildTime): (ConfigValueSource & {
4
- configName: string;
5
- })[];