vike 0.4.165 → 0.4.166

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 (90) hide show
  1. package/dist/cjs/node/plugin/index.js +1 -1
  2. package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
  3. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
  4. package/dist/cjs/node/plugin/plugins/buildConfig.js +68 -58
  5. package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +12 -0
  6. package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
  7. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
  8. package/dist/cjs/node/plugin/plugins/envVars.js +1 -1
  9. package/dist/cjs/node/plugin/plugins/fileEnv.js +2 -2
  10. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +53 -24
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +5 -24
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +15 -22
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -20
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -20
  18. package/dist/cjs/node/plugin/shared/getFilePath.js +88 -0
  19. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
  20. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
  21. package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
  22. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +26 -24
  23. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +5 -0
  24. package/dist/cjs/node/runtime/renderPage.js +34 -21
  25. package/dist/cjs/shared/page-configs/FilePath.js +2 -0
  26. package/dist/cjs/utils/assert.js +2 -0
  27. package/dist/cjs/utils/assertSingleInstance.js +6 -5
  28. package/dist/cjs/utils/assertVersion.js +4 -1
  29. package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
  30. package/dist/cjs/utils/getGlobalObject.js +21 -6
  31. package/dist/cjs/utils/isNpmPackage.js +1 -4
  32. package/dist/cjs/utils/parseUrl.js +8 -1
  33. package/dist/cjs/utils/projectInfo.js +1 -4
  34. package/dist/esm/client/client-routing-runtime/history.d.ts +1 -1
  35. package/dist/esm/client/client-routing-runtime/history.js +5 -5
  36. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +1 -1
  37. package/dist/esm/node/plugin/index.js +1 -1
  38. package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
  39. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
  40. package/dist/esm/node/plugin/plugins/buildConfig.d.ts +1 -1
  41. package/dist/esm/node/plugin/plugins/buildConfig.js +69 -59
  42. package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +12 -0
  43. package/dist/esm/node/plugin/plugins/config/index.js +1 -1
  44. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -3
  45. package/dist/esm/node/plugin/plugins/envVars.js +2 -2
  46. package/dist/esm/node/plugin/plugins/fileEnv.js +3 -3
  47. package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
  48. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +1 -1
  49. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
  50. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  51. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +54 -25
  52. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
  53. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
  54. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +1 -1
  55. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +6 -25
  56. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +2 -1
  57. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +15 -22
  58. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
  59. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -20
  60. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
  61. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -20
  62. package/dist/esm/node/plugin/shared/getFilePath.d.ts +20 -0
  63. package/dist/esm/node/plugin/shared/getFilePath.js +82 -0
  64. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
  65. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
  66. package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
  67. package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +26 -24
  68. package/dist/esm/node/runtime/renderPage/logErrorHint.js +2 -0
  69. package/dist/esm/node/runtime/renderPage.js +34 -21
  70. package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +1 -1
  71. package/dist/esm/shared/page-configs/FilePath.d.ts +52 -0
  72. package/dist/esm/shared/page-configs/FilePath.js +1 -0
  73. package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -42
  74. package/dist/esm/utils/assert.js +2 -0
  75. package/dist/esm/utils/assertSingleInstance.d.ts +2 -2
  76. package/dist/esm/utils/assertSingleInstance.js +5 -4
  77. package/dist/esm/utils/assertVersion.js +4 -1
  78. package/dist/esm/utils/getFilePathAbsolute.d.ts +4 -4
  79. package/dist/esm/utils/getFilePathAbsolute.js +10 -10
  80. package/dist/esm/utils/getGlobalObject.d.ts +6 -1
  81. package/dist/esm/utils/getGlobalObject.js +22 -6
  82. package/dist/esm/utils/isNpmPackage.d.ts +0 -6
  83. package/dist/esm/utils/isNpmPackage.js +5 -3
  84. package/dist/esm/utils/parseUrl.js +8 -1
  85. package/dist/esm/utils/projectInfo.d.ts +2 -2
  86. package/dist/esm/utils/projectInfo.js +1 -4
  87. package/package.json +26 -14
  88. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -33
  89. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +0 -5
  90. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -27
@@ -51,7 +51,7 @@ async function renderPage(pageContextInit) {
51
51
  async function renderPageAndPrepare(pageContextInit, httpRequestId) {
52
52
  // Invalid config
53
53
  const handleInvalidConfig = () => {
54
- logRuntimeInfo?.(pc.bold(pc.red("Couldn't load configuration: see error above.")), httpRequestId, 'error');
54
+ logRuntimeInfo?.(pc.bold(pc.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
55
55
  const pageContextHttpResponseNull = getPageContextHttpResponseNull(pageContextInit);
56
56
  return pageContextHttpResponseNull;
57
57
  };
@@ -203,29 +203,42 @@ function getRequestInfoMessage(urlOriginal) {
203
203
  }
204
204
  function logHttpResponse(urlOriginal, httpRequestId, pageContextReturn) {
205
205
  const statusCode = pageContextReturn.httpResponse?.statusCode ?? null;
206
+ let msg;
207
+ let isNominal;
206
208
  {
207
- // If URL doesn't include Base URL
208
209
  const { errorWhileRendering } = pageContextReturn;
209
- const isSkipped = statusCode === null && (errorWhileRendering === null || errorWhileRendering === undefined);
210
- if (isSkipped)
211
- return;
212
- }
213
- const isSuccess = statusCode !== null && statusCode >= 200 && statusCode <= 399;
214
- const isNominal = isSuccess || statusCode === 404;
215
- const color = (s) => pc.bold(isSuccess ? pc.green(String(s)) : pc.red(String(s)));
216
- const isRedirect = statusCode && 300 <= statusCode && statusCode <= 399;
217
- const type = isRedirect ? 'redirect' : 'response';
218
- if (isRedirect) {
219
- assert(pageContextReturn.httpResponse);
220
- const headerRedirect = pageContextReturn.httpResponse.headers
221
- .slice()
222
- .reverse()
223
- .find((header) => header[0] === 'Location');
224
- assert(headerRedirect);
225
- const urlRedirect = headerRedirect[1];
226
- urlOriginal = urlRedirect;
210
+ const isSkipped = statusCode === null && !errorWhileRendering;
211
+ if (isSkipped) {
212
+ // - URL doesn't include Base URL
213
+ // - Can we abort earlier so that `logHttpResponse()` and `logHttpRequest()` aren't even called?
214
+ // - Error loading a Vike config file
215
+ // - We should show `HTTP response ${urlOriginal} ERR` instead.
216
+ // - Maybe we can/should make the error available at pageContext.errorWhileRendering
217
+ assert(errorWhileRendering === null || errorWhileRendering === undefined);
218
+ msg = `HTTP response ${pc.bold(urlOriginal)} ${pc.dim('null')}`;
219
+ // Erroneous value (it shoud sometimes be `false`) but it's fine as it doesn't seem to have much of an impact.
220
+ isNominal = true;
221
+ }
222
+ else {
223
+ const isSuccess = statusCode !== null && statusCode >= 200 && statusCode <= 399;
224
+ isNominal = isSuccess || statusCode === 404;
225
+ const color = (s) => pc.bold(isSuccess ? pc.green(String(s)) : pc.red(String(s)));
226
+ const isRedirect = statusCode && 300 <= statusCode && statusCode <= 399;
227
+ const type = isRedirect ? 'redirect' : 'response';
228
+ if (isRedirect) {
229
+ assert(pageContextReturn.httpResponse);
230
+ const headerRedirect = pageContextReturn.httpResponse.headers
231
+ .slice()
232
+ .reverse()
233
+ .find((header) => header[0] === 'Location');
234
+ assert(headerRedirect);
235
+ const urlRedirect = headerRedirect[1];
236
+ urlOriginal = urlRedirect;
237
+ }
238
+ msg = `HTTP ${type} ${pc.bold(urlOriginal)} ${color(statusCode ?? 'ERR')}`;
239
+ }
227
240
  }
228
- logRuntimeInfo?.(`HTTP ${type} ${pc.bold(urlOriginal)} ${color(statusCode ?? 'ERR')}`, httpRequestId, isNominal ? 'info' : 'error');
241
+ logRuntimeInfo?.(msg, httpRequestId, isNominal ? 'info' : 'error');
229
242
  }
230
243
  function getPageContextHttpResponseNullWithError(err, pageContextInit) {
231
244
  const pageContextHttpResponseNull = {};
@@ -2,7 +2,7 @@ export type { PageContextConfig };
2
2
  import type { VikePackages } from '../../VikeNamespace.js';
3
3
  import type { ConfigBuiltIn } from '../Config.js';
4
4
  import type { Combine, IsNotEmpty, XOR5 } from './helpers.ts';
5
- type PageContextConfig = ConfigBuiltIn & (ConfigVikePackagesNotEmptyXor extends true ? ConfigVikePackagesIntersection : ConfigVikePackagesCombined);
5
+ type PageContextConfig = ConfigBuiltIn & Vike.Config & (ConfigVikePackagesNotEmptyXor extends true ? ConfigVikePackagesIntersection : ConfigVikePackagesCombined);
6
6
  type ConfigVikePackagesIntersection = VikePackages.ConfigVikeReact & VikePackages.ConfigVikeVue & VikePackages.ConfigVikeSolid & VikePackages.ConfigVikeSvelte & VikePackages.ConfigVikeAngular;
7
7
  type ConfigVikePackagesCombined = Combine<VikePackages.ConfigVikeReact, Combine<VikePackages.ConfigVikeVue, Combine<VikePackages.ConfigVikeSolid, Combine<VikePackages.ConfigVikeSvelte, VikePackages.ConfigVikeAngular>>>>;
8
8
  type ConfigVikePackagesNotEmptyXor = XOR5<IsNotEmpty<VikePackages.ConfigVikeReact>, IsNotEmpty<VikePackages.ConfigVikeVue>, IsNotEmpty<VikePackages.ConfigVikeSolid>, IsNotEmpty<VikePackages.ConfigVikeSvelte>, IsNotEmpty<VikePackages.ConfigVikeAngular>>;
@@ -0,0 +1,52 @@
1
+ export type { FilePath };
2
+ export type { FilePathResolved };
3
+ type FilePathResolved = FilePath & {
4
+ filePathAbsoluteFilesystem: string;
5
+ filePathToShowToUserResolved: string;
6
+ };
7
+ type FilePath = {
8
+ /** The file's path, non-relative from Vite's perspective.
9
+ *
10
+ * Its value is equivalent to `filePath.filePathAbsoluteUserRootDir ?? filePath.importPathAbsolute`, for example:
11
+ * - `vike-react/config`, or
12
+ * - `/pages/+config.js`.
13
+ *
14
+ * We use it to generate import paths in virtual modules. (Since virtual modules cannot have relative import paths.)
15
+ */
16
+ filePathAbsoluteVite: string;
17
+ /** The file's path, absolute starting from the filesystem root.
18
+ *
19
+ * Example: `/home/rom/code/my-app/pages/some-page/Page.js`
20
+ *
21
+ * The value is `null` upon aliased import paths which we cannot resolve (we'd need to re-implement https://www.npmjs.com/package/@rollup/plugin-alias).
22
+ */
23
+ filePathAbsoluteFilesystem: string | null;
24
+ /** The file's path, shown to user upon logging.
25
+ *
26
+ * Unresolved: it may show an import path of a package e.g. `vike-react/config`.
27
+ *
28
+ * Currently, its value is equivalent to `FilePath['filePathAbsoluteVite']`.
29
+ */
30
+ filePathToShowToUser: string;
31
+ /** The file's path, shown to user upon logging.
32
+ *
33
+ * Resolved: it always shows an absolute file path.
34
+ *
35
+ * Currently, its value is equivalent to `FilePath['filePathAbsoluteUserRootDir'] | FilePath['filePathAbsoluteFilesystem'] `.
36
+ */
37
+ filePathToShowToUserResolved: string | null;
38
+ /** The file's path, absolute starting from the user root directory (i.e. Vite's `config.root`).
39
+ *
40
+ * Example: `/pages/some-page/Page.js`
41
+ */
42
+ filePathAbsoluteUserRootDir: string | null;
43
+ /** The file's path, as absolute import path. It's either:
44
+ * - an npm package import (e.g. `vike-react/config`), or
45
+ * - an alias (`#components/Counter').
46
+ */
47
+ importPathAbsolute: string | null;
48
+ } & ({
49
+ importPathAbsolute: string;
50
+ } | {
51
+ filePathAbsoluteUserRootDir: string;
52
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -14,10 +14,9 @@ export type { ConfigValuesComputed };
14
14
  export type { DefinedAt };
15
15
  export type { DefinedAtFile };
16
16
  export type { DefinedAtFileFullInfo };
17
- export type { FilePathResolved };
18
- export type { FilePath };
19
17
  import type { ConfigValueImported, ConfigValueSerialized } from './serialize/PageConfigSerialized.js';
20
18
  import type { LocationId } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js';
19
+ import type { FilePath } from './FilePath.js';
21
20
  type PageConfigBase = {
22
21
  pageId: string;
23
22
  isErrorPage?: true;
@@ -100,43 +99,3 @@ type DefinedAtFile = {
100
99
  fileExportPathToShowToUser: null | string[];
101
100
  };
102
101
  type ConfigValues = Record<string, ConfigValue>;
103
- type FilePathResolved = FilePath & {
104
- filePathAbsoluteFilesystem: string;
105
- };
106
- type FilePath = {
107
- /** The file's path, absolute from Vite's perspective.
108
- *
109
- * We use this to generate import paths in virtual modules. (Virtual modules cannot have relative import paths.)
110
- *
111
- * Its value is equivalent to `filePath.filePathRelativeToUserRootDir ?? filePath.importPathAbsolute`, for example:
112
- * - `vike-react/config`, or
113
- * - `/pages/+config.js`.
114
- */
115
- filePathAbsoluteVite: string;
116
- /** The file's path, absolute from the filesystem root.
117
- *
118
- * Example: `/home/rom/code/my-app/pages/some-page/Page.js`
119
- *
120
- * The value is `null` upon aliased import paths which we cannot resolve (we'd need to re-implement https://www.npmjs.com/package/@rollup/plugin-alias).
121
- */
122
- filePathAbsoluteFilesystem: string | null;
123
- /** The file's path, shown to user upon logging.
124
- *
125
- * Currently, its value is equivalent to `FilePath['filePathAbsoluteVite']`.
126
- */
127
- filePathToShowToUser: string;
128
- } & ({
129
- filePathRelativeToUserRootDir: null;
130
- /** The file's path, as absolute import path. It's either:
131
- * - an npm package import (e.g. `vike-react/config`), or
132
- * - an alias (`#components/Counter').
133
- */
134
- importPathAbsolute: string;
135
- } | {
136
- /** The file's path, relative to Vite's root (i.e. the user project's root directory).
137
- *
138
- * Example: `/pages/some-page/Page.js`
139
- */
140
- filePathRelativeToUserRootDir: string;
141
- importPathAbsolute: null | string;
142
- });
@@ -7,6 +7,7 @@ export { addOnBeforeLogHook };
7
7
  export { getAssertErrMsg };
8
8
  export { overwriteAssertProductionLogger };
9
9
  export { isBug };
10
+ import { onAssertModuleLoad } from './assertSingleInstance.js';
10
11
  import { createErrorWithCleanStackTrace } from './createErrorWithCleanStackTrace.js';
11
12
  import { getGlobalObject } from './getGlobalObject.js';
12
13
  import { isObject } from './isObject.js';
@@ -25,6 +26,7 @@ const globalObject = getGlobalObject('utils/assert.ts', {
25
26
  },
26
27
  showStackTraceList: new WeakSet()
27
28
  });
29
+ onAssertModuleLoad();
28
30
  const projectTag = `[vike]`;
29
31
  const projectTagWithVersion = `[vike@${projectInfo.projectVersion}]`;
30
32
  const numberOfStackTraceLinesToRemove = 2;
@@ -1,6 +1,6 @@
1
1
  export { onClientEntry_ServerRouting };
2
2
  export { onClientEntry_ClientRouting };
3
- export { onProjectInfo };
3
+ export { onAssertModuleLoad };
4
4
  declare function onClientEntry_ServerRouting(isProduction: boolean): void;
5
5
  declare function onClientEntry_ClientRouting(isProduction: boolean): void;
6
- declare function onProjectInfo(projectVersion: string): void;
6
+ declare function onAssertModuleLoad(): void;
@@ -1,11 +1,12 @@
1
1
  export { onClientEntry_ServerRouting };
2
2
  export { onClientEntry_ClientRouting };
3
- export { onProjectInfo };
3
+ export { onAssertModuleLoad };
4
4
  // - Throw error if there are two different versions of vike loaded
5
5
  // - Show warning if entry of Client Routing and entry of Server Routing are both loaded
6
6
  // - Show warning if vike is loaded twice
7
7
  import { unique } from './unique.js';
8
8
  import { getGlobalObject } from './getGlobalObject.js';
9
+ import { projectInfo } from './projectInfo.js';
9
10
  /* Use original assertUsage() & assertWarning() after all CJS is removed from node_modules/vike/dist/
10
11
  import { assertUsage, assertWarning } from './assert.js'
11
12
  */
@@ -58,9 +59,9 @@ function onClientEntry_ClientRouting(isProduction) {
58
59
  globalObject.checkSingleInstance = true;
59
60
  assertSingleInstance();
60
61
  }
61
- // Called by utils/projectInfo.ts which is loaded by all entries (since utils/asserts.ts depends on utils/projectInfo.ts, we can have confidence that onProjectInfo() is called by each entry). That way we don't have to call a callback for every entry (there are a *lot* of entries: `client/router/`, `client/`, `node/runtime/`, `node/plugin/`, `node/cli`).
62
- function onProjectInfo(projectVersion) {
63
- globalObject.instances.push(projectVersion);
62
+ // Called by utils/assert.ts which is (most certainly) loaded by all entries. That way we don't have to call a callback for every entry. (There are a lot of entries: `client/router/`, `client/`, `node/runtime/`, `node/plugin/`, `node/cli`.)
63
+ function onAssertModuleLoad() {
64
+ globalObject.instances.push(projectInfo.projectVersion);
64
65
  assertSingleInstance();
65
66
  }
66
67
  function assertUsage(condition, errorMessage) {
@@ -22,9 +22,12 @@ function isVersionOrAbove(versionActual, versionExpected) {
22
22
  function parseVersion(version) {
23
23
  // Remove pre-release tag
24
24
  version = version.split('-')[0];
25
+ let partsStr = version.split('.');
26
+ // Git seems to be using a fourth number: https://github.com/git/git/tree/master/Documentation/RelNotes
27
+ partsStr = partsStr.slice(0, 3);
25
28
  // major.minor.patch
26
- const partsStr = version.split('.');
27
29
  assert(partsStr.length === 3);
30
+ assert(partsStr.every((s) => s.length > 0));
28
31
  const parts = partsStr.map((s) => parseInt(s, 10));
29
32
  return parts;
30
33
  }
@@ -1,5 +1,5 @@
1
- export { getFilePathAbsolute };
2
- export { getFilePathRelativeToUserRootDir };
1
+ export { getFilePathAbsoluteFilesystem };
2
+ export { getFilePathAbsoluteUserRootDir };
3
3
  import type { ResolvedConfig } from 'vite';
4
- declare function getFilePathAbsolute(filePath: string, config: ResolvedConfig): string;
5
- declare function getFilePathRelativeToUserRootDir(filePathAbsoluteFilesystem: string, userRootDir: string, alwaysRelative?: boolean): string;
4
+ declare function getFilePathAbsoluteFilesystem(filePath: string, config: ResolvedConfig): string;
5
+ declare function getFilePathAbsoluteUserRootDir(filePathAbsoluteFilesystem: string, userRootDir: string, alwaysRelative?: boolean): string;
@@ -1,5 +1,5 @@
1
- export { getFilePathAbsolute };
2
- export { getFilePathRelativeToUserRootDir };
1
+ export { getFilePathAbsoluteFilesystem };
2
+ export { getFilePathAbsoluteUserRootDir };
3
3
  import { assertPosixPath, toPosixPath } from './filesystemPathHandling.js';
4
4
  import { assert } from './assert.js';
5
5
  import path from 'path';
@@ -14,7 +14,7 @@ assertIsNotProductionRuntime();
14
14
  // Vite handles paths such as /pages/index.page.js which are relative to `config.root`.
15
15
  // Make them absolute starting from the filesystem root.
16
16
  // Also resolve plus files living in npm packages such as restack/renderer/+onRenderHtml.js
17
- function getFilePathAbsolute(filePath, config) {
17
+ function getFilePathAbsoluteFilesystem(filePath, config) {
18
18
  assertPosixPath(filePath);
19
19
  if (filePath.startsWith('/@fs/')) {
20
20
  return filePath;
@@ -42,20 +42,20 @@ function getFilePathAbsolute(filePath, config) {
42
42
  assertPathIsFilesystemAbsolute(filePathAbsoluteFilesystem);
43
43
  return filePathAbsoluteFilesystem;
44
44
  }
45
- function getFilePathRelativeToUserRootDir(filePathAbsoluteFilesystem, userRootDir, alwaysRelative = false) {
45
+ function getFilePathAbsoluteUserRootDir(filePathAbsoluteFilesystem, userRootDir, alwaysRelative = false) {
46
46
  assertPosixPath(filePathAbsoluteFilesystem);
47
47
  assertPosixPath(userRootDir);
48
- let filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem);
48
+ let filePathAbsoluteUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem);
49
49
  if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
50
- assert(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'),
50
+ assert(!filePathAbsoluteUserRootDir.startsWith('.') && !filePathAbsoluteUserRootDir.startsWith('/'),
51
51
  // Surprinsingly, this assertion seem to fail sometimes: https://github.com/vikejs/vike/issues/1139
52
- { filePathRelativeToUserRootDir, filePathAbsoluteFilesystem, userRootDir });
53
- filePathRelativeToUserRootDir = `/${filePathRelativeToUserRootDir}`;
54
- return filePathRelativeToUserRootDir;
52
+ { filePathAbsoluteUserRootDir, filePathAbsoluteFilesystem, userRootDir });
53
+ filePathAbsoluteUserRootDir = `/${filePathAbsoluteUserRootDir}`;
54
+ return filePathAbsoluteUserRootDir;
55
55
  }
56
56
  else {
57
57
  if (alwaysRelative) {
58
- return filePathRelativeToUserRootDir;
58
+ return filePathAbsoluteUserRootDir;
59
59
  }
60
60
  else {
61
61
  return filePathAbsoluteFilesystem;
@@ -1 +1,6 @@
1
- export declare function getGlobalObject<T extends Record<string, unknown> = never>(key: `${string}.ts`, defaultValue: T): T;
1
+ export { getGlobalObject };
2
+ export { assertIsSingleModuleInstance };
3
+ /** Share information across module instances. */
4
+ declare function getGlobalObject<T extends Record<string, unknown> = never>(key: `${string}.ts`, defaultValue: T): T;
5
+ /** Assert that the module is instantiated only once. */
6
+ declare function assertIsSingleModuleInstance(key: `${string}.ts`): void;
@@ -1,9 +1,25 @@
1
- export function getGlobalObject(
2
- // We use the filename as key; each `getGlobalObject()` call should live inside a file with a unique filename.
1
+ export { getGlobalObject };
2
+ export { assertIsSingleModuleInstance };
3
+ import { assert } from './assert.js';
4
+ import { projectInfo } from './projectInfo.js';
5
+ const projectKey = `_${projectInfo.projectName.toLowerCase()}`;
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.
3
9
  key, defaultValue) {
4
- // @ts-ignore
5
- const globalObjectsAll = (globalThis[projectKey] = globalThis[projectKey] || {});
6
- const globalObject = (globalObjectsAll[key] = globalObjectsAll[key] || defaultValue);
10
+ const globalObjects = getGlobalObjects();
11
+ const globalObject = (globalObjects[key] = globalObjects[key] || defaultValue);
7
12
  return globalObject;
8
13
  }
9
- const projectKey = '_vike';
14
+ /** Assert that the module is instantiated only once. */
15
+ function assertIsSingleModuleInstance(
16
+ // We use the filename (or file path) as key.
17
+ key) {
18
+ const globalObjects = getGlobalObjects();
19
+ assert(!(key in globalObjects));
20
+ }
21
+ function getGlobalObjects() {
22
+ // @ts-ignore
23
+ const globalObjects = (globalThis[projectKey] = globalThis[projectKey] || {});
24
+ return globalObjects;
25
+ }
@@ -1,14 +1,8 @@
1
1
  export { isNpmPackageImport };
2
- export { isNpmPackageName };
3
- export { getNpmPackageName };
4
- export { getNpmPackageImportPath };
5
2
  export { isValidPathAlias };
6
3
  export { parse };
7
4
  export { isDistinguishable };
8
5
  declare function isNpmPackageImport(str: string): boolean;
9
- declare function isNpmPackageName(str: string | undefined): boolean;
10
- declare function getNpmPackageName(str: string): null | string;
11
- declare function getNpmPackageImportPath(str: string): null | string;
12
6
  declare function isValidPathAlias(alias: string): boolean;
13
7
  declare function isDistinguishable(alias: string): boolean;
14
8
  declare function parse(str: string | undefined): null | {
@@ -1,8 +1,10 @@
1
1
  export { isNpmPackageImport };
2
- export { isNpmPackageName };
3
- export { getNpmPackageName };
4
- export { getNpmPackageImportPath };
5
2
  export { isValidPathAlias };
3
+ /* Currently not used
4
+ export { isNpmPackageName }
5
+ export { getNpmPackageName }
6
+ export { getNpmPackageImportPath }
7
+ */
6
8
  // For ./isNpmPackage.spec.ts
7
9
  export { parse };
8
10
  export { isDistinguishable };
@@ -12,7 +12,14 @@ export { isUriWithProtocol };
12
12
  import { slice } from './slice.js';
13
13
  import { assert, assertUsage } from './assert.js';
14
14
  import pc from '@brillout/picocolors';
15
- const PROTOCOLS = ['http://', 'https://', 'tauri://'];
15
+ const PROTOCOLS = [
16
+ 'http://',
17
+ 'https://',
18
+ // For [Tauri](https://tauri.app/)
19
+ 'tauri://',
20
+ // For Electron: https://github.com/vikejs/vike/issues/1557
21
+ 'file://'
22
+ ];
16
23
  function isParsable(url) {
17
24
  // `parseUrl()` works with these URLs
18
25
  return (PROTOCOLS.some((p) => url.startsWith(p)) ||
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- declare const PROJECT_VERSION: "0.4.165";
3
+ declare const PROJECT_VERSION: "0.4.166";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.165";
6
+ projectVersion: "0.4.166";
7
7
  };
@@ -1,10 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- import { onProjectInfo } from './assertSingleInstance.js';
4
- const PROJECT_VERSION = '0.4.165';
3
+ const PROJECT_VERSION = '0.4.166';
5
4
  const projectInfo = {
6
5
  projectName: 'Vike',
7
6
  projectVersion: PROJECT_VERSION
8
7
  };
9
- // Trick: since `utils/asserts.ts` depends on this file (`utils/projectInfo.ts`), we can have confidence that this file is always instantiated. So that we don't have to initialize this code snippet at every possible entry. (There are a *lot* of entries: `client/router/`, `client/`, `node/`, `node/plugin/`, `node/cli`, etc.)
10
- onProjectInfo(projectInfo.projectVersion);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.165",
3
+ "version": "0.4.166",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
@@ -33,7 +33,8 @@
33
33
  "require": "./dist/cjs/node/runtime/index-deprecated.js",
34
34
  "node": "./dist/esm/node/runtime/index-deprecated.js",
35
35
  "browser": "./dist/esm/client/node.js",
36
- "types": "./dist/esm/node/runtime/index-deprecated.d.ts"
36
+ "types": "./dist/esm/node/runtime/index-deprecated.d.ts",
37
+ "default": "./dist/esm/node/runtime/index-deprecated.js"
37
38
  },
38
39
  "./server": {
39
40
  "worker": "./dist/esm/node/runtime/index.js",
@@ -41,7 +42,8 @@
41
42
  "require": "./dist/cjs/node/runtime/index.js",
42
43
  "node": "./dist/esm/node/runtime/index.js",
43
44
  "browser": "./dist/esm/client/node.js",
44
- "types": "./dist/esm/node/runtime/index.d.ts"
45
+ "types": "./dist/esm/node/runtime/index.d.ts",
46
+ "default": "./dist/esm/node/runtime/index.js"
45
47
  },
46
48
  "./client": {
47
49
  "types": "./dist/esm/client/server-routing-runtime/index.d.ts"
@@ -55,7 +57,8 @@
55
57
  "require": "./dist/cjs/node/client/router.js",
56
58
  "node": "./dist/esm/node/client/router.js",
57
59
  "browser": "./dist/esm/client/client-routing-runtime/index.js",
58
- "types": "./dist/esm/client/client-routing-runtime/index.d.ts"
60
+ "types": "./dist/esm/client/client-routing-runtime/index.d.ts",
61
+ "default": "./dist/esm/client/client-routing-runtime/index.js"
59
62
  },
60
63
  "./routing": {
61
64
  "worker": "./dist/esm/shared/route/routing.js",
@@ -63,22 +66,26 @@
63
66
  "require": "./dist/cjs/shared/route/routing.js",
64
67
  "node": "./dist/esm/shared/route/routing.js",
65
68
  "browser": "./dist/esm/shared/route/routing.js",
66
- "types": "./dist/esm/shared/route/routing.d.ts"
69
+ "types": "./dist/esm/shared/route/routing.d.ts",
70
+ "default": "./dist/esm/shared/route/routing.js"
67
71
  },
68
72
  "./cli": {
69
73
  "require": "./dist/cjs/node/cli/index.js",
70
74
  "node": "./dist/esm/node/cli/index.js",
71
- "types": "./dist/esm/node/cli/index.d.ts"
75
+ "types": "./dist/esm/node/cli/index.d.ts",
76
+ "default": "./dist/esm/node/cli/index.js"
72
77
  },
73
78
  "./prerender": {
74
79
  "require": "./dist/cjs/node/prerender/index.js",
75
80
  "node": "./dist/esm/node/prerender/index.js",
76
- "types": "./dist/esm/node/prerender/index.d.ts"
81
+ "types": "./dist/esm/node/prerender/index.d.ts",
82
+ "default": "./dist/esm/node/prerender/index.js"
77
83
  },
78
84
  "./plugin": {
79
85
  "require": "./dist/cjs/node/plugin/index.js",
80
86
  "node": "./dist/esm/node/plugin/index.js",
81
- "types": "./dist/esm/node/plugin/index.d.ts"
87
+ "types": "./dist/esm/node/plugin/index.d.ts",
88
+ "default": "./dist/esm/node/plugin/index.js"
82
89
  },
83
90
  "./RenderErrorPage": {
84
91
  "worker": "./dist/esm/shared/RenderErrorPage.js",
@@ -86,7 +93,8 @@
86
93
  "require": "./dist/cjs/shared/RenderErrorPage.js",
87
94
  "node": "./dist/esm/shared/RenderErrorPage.js",
88
95
  "browser": "./dist/esm/shared/RenderErrorPage.js",
89
- "types": "./dist/esm/shared/RenderErrorPage.d.ts"
96
+ "types": "./dist/esm/shared/RenderErrorPage.d.ts",
97
+ "default": "./dist/esm/shared/RenderErrorPage.js"
90
98
  },
91
99
  "./abort": {
92
100
  "worker": "./dist/esm/shared/abort.js",
@@ -94,24 +102,28 @@
94
102
  "require": "./dist/cjs/shared/abort.js",
95
103
  "node": "./dist/esm/shared/abort.js",
96
104
  "browser": "./dist/esm/shared/abort.js",
97
- "types": "./dist/esm/shared/abort.d.ts"
105
+ "types": "./dist/esm/shared/abort.d.ts",
106
+ "default": "./dist/esm/shared/abort.js"
98
107
  },
99
108
  "./__internal": {
100
109
  "require": "./dist/cjs/__internal/index.js",
101
110
  "node": "./dist/esm/__internal/index.js",
102
- "types": "./dist/esm/__internal/index.d.ts"
111
+ "types": "./dist/esm/__internal/index.d.ts",
112
+ "default": "./dist/esm/__internal/index.js"
103
113
  },
104
114
  "./__internal/setup": {
105
115
  "require": "./dist/cjs/node/runtime/page-files/setup.js",
106
116
  "node": "./dist/esm/node/runtime/page-files/setup.js",
107
- "types": "./dist/esm/node/runtime/page-files/setup.d.ts"
117
+ "types": "./dist/esm/node/runtime/page-files/setup.d.ts",
118
+ "default": "./dist/esm/node/runtime/page-files/setup.js"
108
119
  },
109
120
  "./__internal/loadImportBuild": {
110
121
  "worker": "./dist/esm/node/runtime/globalContext/loadImportBuild.js",
111
122
  "edge-light": "./dist/esm/node/runtime/globalContext/loadImportBuild.js",
112
123
  "require": "./dist/cjs/node/runtime/globalContext/loadImportBuild.js",
113
124
  "node": "./dist/esm/node/runtime/globalContext/loadImportBuild.js",
114
- "types": "./dist/esm/node/runtime/globalContext/loadImportBuild.d.ts"
125
+ "types": "./dist/esm/node/runtime/globalContext/loadImportBuild.d.ts",
126
+ "default": "./dist/esm/node/runtime/globalContext/loadImportBuild.js"
115
127
  }
116
128
  },
117
129
  "peerDependencies": {
@@ -188,7 +200,7 @@
188
200
  "@types/node": "^20.10.5",
189
201
  "@types/resolve": "^1.20.6",
190
202
  "@types/source-map-support": "^0.5.10",
191
- "react-streaming": "^0.3.22",
203
+ "react-streaming": "^0.3.24",
192
204
  "rimraf": "^5.0.5",
193
205
  "typescript": "^5.3.3",
194
206
  "vite": "npm:@brillout/vite@5.1.0-commit-3dc7abd"
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveFilePathAbsoluteFilesystem = exports.resolveFilePathRelativeToUserRootDir = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const utils_js_1 = require("../../../../utils.js");
9
- function resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir, userRootDir) {
10
- (0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
11
- (0, utils_js_1.assertPosixPath)(userRootDir);
12
- const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathRelativeToUserRootDir);
13
- return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
14
- }
15
- exports.resolveFilePathRelativeToUserRootDir = resolveFilePathRelativeToUserRootDir;
16
- function resolveFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem, userRootDir) {
17
- (0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
18
- (0, utils_js_1.assertPosixPath)(userRootDir);
19
- let filePathRelativeToUserRootDir = path_1.default.posix.relative(userRootDir, filePathAbsoluteFilesystem);
20
- (0, utils_js_1.assert)(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'));
21
- filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
22
- return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
23
- }
24
- exports.resolveFilePathAbsoluteFilesystem = resolveFilePathAbsoluteFilesystem;
25
- function getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem) {
26
- return {
27
- filePathRelativeToUserRootDir,
28
- filePathAbsoluteVite: filePathRelativeToUserRootDir,
29
- filePathAbsoluteFilesystem,
30
- filePathToShowToUser: filePathRelativeToUserRootDir,
31
- importPathAbsolute: null
32
- };
33
- }
@@ -1,5 +0,0 @@
1
- export { resolveFilePathRelativeToUserRootDir };
2
- export { resolveFilePathAbsoluteFilesystem };
3
- import type { FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
4
- declare function resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir: string, userRootDir: string): FilePathResolved;
5
- declare function resolveFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem: string, userRootDir: string): FilePathResolved;
@@ -1,27 +0,0 @@
1
- export { resolveFilePathRelativeToUserRootDir };
2
- export { resolveFilePathAbsoluteFilesystem };
3
- import path from 'path';
4
- import { assert, assertPosixPath } from '../../../../utils.js';
5
- function resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir, userRootDir) {
6
- assertPosixPath(filePathRelativeToUserRootDir);
7
- assertPosixPath(userRootDir);
8
- const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelativeToUserRootDir);
9
- return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
10
- }
11
- function resolveFilePathAbsoluteFilesystem(filePathAbsoluteFilesystem, userRootDir) {
12
- assertPosixPath(filePathAbsoluteFilesystem);
13
- assertPosixPath(userRootDir);
14
- let filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem);
15
- assert(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'));
16
- filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
17
- return getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem);
18
- }
19
- function getFilePathResolved(filePathRelativeToUserRootDir, filePathAbsoluteFilesystem) {
20
- return {
21
- filePathRelativeToUserRootDir,
22
- filePathAbsoluteVite: filePathRelativeToUserRootDir,
23
- filePathAbsoluteFilesystem,
24
- filePathToShowToUser: filePathRelativeToUserRootDir,
25
- importPathAbsolute: null
26
- };
27
- }