vike 0.4.165 → 0.4.166-commit-a5e2596

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 (130) 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 +78 -63
  5. package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +14 -1
  6. package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
  7. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -23
  8. package/dist/cjs/node/plugin/plugins/envVars.js +3 -2
  9. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +9 -9
  10. package/dist/cjs/node/plugin/plugins/fileEnv.js +6 -3
  11. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +6 -2
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +53 -24
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +10 -25
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +32 -35
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +18 -26
  18. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +26 -21
  19. package/dist/cjs/node/plugin/shared/getFilePath.js +142 -0
  20. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +3 -8
  21. package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -1
  22. package/dist/cjs/node/plugin/utils.js +1 -1
  23. package/dist/cjs/node/prerender/runPrerender.js +6 -7
  24. package/dist/cjs/node/prerender/utils.js +2 -1
  25. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
  26. package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
  27. package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +3 -3
  28. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -1
  29. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +31 -33
  30. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +9 -8
  31. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +6 -12
  32. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +5 -0
  33. package/dist/cjs/node/runtime/renderPage.js +34 -21
  34. package/dist/cjs/node/runtime/utils.js +0 -1
  35. package/dist/cjs/shared/page-configs/FilePath.js +2 -0
  36. package/dist/cjs/shared/route/abort.js +2 -1
  37. package/dist/cjs/shared/route/executeGuardHook.js +2 -1
  38. package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +2 -1
  39. package/dist/cjs/shared/route/index.js +2 -3
  40. package/dist/cjs/shared/route/utils.js +0 -1
  41. package/dist/cjs/utils/assert.js +2 -0
  42. package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +1 -0
  43. package/dist/cjs/utils/assertSingleInstance.js +6 -5
  44. package/dist/cjs/utils/assertVersion.js +4 -1
  45. package/dist/cjs/utils/getGlobalObject.js +21 -6
  46. package/dist/cjs/utils/isNpmPackage.js +11 -5
  47. package/dist/cjs/utils/parseUrl.js +8 -1
  48. package/dist/cjs/utils/projectInfo.js +1 -4
  49. package/dist/esm/client/client-routing-runtime/history.d.ts +1 -1
  50. package/dist/esm/client/client-routing-runtime/history.js +5 -5
  51. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +1 -1
  52. package/dist/esm/node/plugin/index.js +1 -1
  53. package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
  54. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
  55. package/dist/esm/node/plugin/plugins/buildConfig.d.ts +1 -1
  56. package/dist/esm/node/plugin/plugins/buildConfig.js +79 -64
  57. package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +14 -1
  58. package/dist/esm/node/plugin/plugins/config/index.js +1 -1
  59. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +19 -24
  60. package/dist/esm/node/plugin/plugins/envVars.js +4 -3
  61. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +9 -9
  62. package/dist/esm/node/plugin/plugins/fileEnv.js +7 -4
  63. package/dist/esm/node/plugin/plugins/importUserCode/index.js +7 -3
  64. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +1 -1
  65. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
  66. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  67. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +54 -25
  68. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
  69. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
  70. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +1 -1
  71. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +11 -26
  72. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +2 -1
  73. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +32 -35
  74. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
  75. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +18 -26
  76. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
  77. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +26 -21
  78. package/dist/esm/node/plugin/shared/getFilePath.d.ts +21 -0
  79. package/dist/esm/node/plugin/shared/getFilePath.js +136 -0
  80. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +4 -9
  81. package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -1
  82. package/dist/esm/node/plugin/utils.d.ts +1 -1
  83. package/dist/esm/node/plugin/utils.js +1 -1
  84. package/dist/esm/node/prerender/runPrerender.js +2 -3
  85. package/dist/esm/node/prerender/utils.d.ts +2 -1
  86. package/dist/esm/node/prerender/utils.js +2 -1
  87. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
  88. package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
  89. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +1 -1
  90. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -1
  91. package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +32 -34
  92. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +9 -8
  93. package/dist/esm/node/runtime/renderPage/getPageAssets.js +7 -13
  94. package/dist/esm/node/runtime/renderPage/logErrorHint.js +2 -0
  95. package/dist/esm/node/runtime/renderPage.js +34 -21
  96. package/dist/esm/node/runtime/utils.d.ts +0 -1
  97. package/dist/esm/node/runtime/utils.js +0 -1
  98. package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +1 -1
  99. package/dist/esm/shared/page-configs/FilePath.d.ts +64 -0
  100. package/dist/esm/shared/page-configs/FilePath.js +1 -0
  101. package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -42
  102. package/dist/esm/shared/route/abort.js +2 -1
  103. package/dist/esm/shared/route/executeGuardHook.js +2 -1
  104. package/dist/esm/shared/route/executeOnBeforeRouteHook.js +2 -1
  105. package/dist/esm/shared/route/index.js +2 -3
  106. package/dist/esm/shared/route/utils.d.ts +0 -1
  107. package/dist/esm/shared/route/utils.js +0 -1
  108. package/dist/esm/utils/assert.js +2 -0
  109. package/dist/esm/utils/assertPathIsFilesystemAbsolute.js +1 -0
  110. package/dist/esm/utils/assertSingleInstance.d.ts +2 -2
  111. package/dist/esm/utils/assertSingleInstance.js +5 -4
  112. package/dist/esm/utils/assertVersion.js +4 -1
  113. package/dist/esm/utils/debug.d.ts +1 -1
  114. package/dist/esm/utils/getGlobalObject.d.ts +6 -1
  115. package/dist/esm/utils/getGlobalObject.js +22 -6
  116. package/dist/esm/utils/isNpmPackage.d.ts +5 -7
  117. package/dist/esm/utils/isNpmPackage.js +15 -4
  118. package/dist/esm/utils/parseUrl.js +8 -1
  119. package/dist/esm/utils/projectInfo.d.ts +2 -2
  120. package/dist/esm/utils/projectInfo.js +1 -4
  121. package/package.json +26 -14
  122. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -33
  123. package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -19
  124. package/dist/cjs/utils/getFilePathAbsolute.js +0 -70
  125. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +0 -5
  126. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -27
  127. package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.d.ts +0 -2
  128. package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -16
  129. package/dist/esm/utils/getFilePathAbsolute.d.ts +0 -5
  130. package/dist/esm/utils/getFilePathAbsolute.js +0 -64
@@ -0,0 +1,64 @@
1
+ export type { FilePath };
2
+ export type { FilePathResolved };
3
+ type FilePathResolved = FilePath & {
4
+ filePathAbsoluteFilesystem: string;
5
+ /**
6
+ * The file's path, shown to the user in logs.
7
+ *
8
+ * Resolved: it always shows a file path. (It nevers shows an import path such as `vike-react/config`.)
9
+ *
10
+ * Its value is equivalent to `filePath.filePathAbsoluteUserRootDir ?? filePath.filePathAbsoluteFilesystem`.
11
+ */
12
+ filePathToShowToUserResolved: string;
13
+ };
14
+ type IsReferencedByUserLandFile = {
15
+ filePathAbsoluteUserRootDir: string;
16
+ } | {
17
+ importPathAbsolute: string;
18
+ };
19
+ type FilePath = FilePathProps & IsReferencedByUserLandFile;
20
+ type FilePathProps = {
21
+ /**
22
+ * The file's path, absolute starting from the filesystem root.
23
+ *
24
+ * Example: `/home/rom/code/my-app/pages/some-page/+Page.js`
25
+ *
26
+ * The value is `null` for imports using path aliases. (Because Vike cannot resolve path aliases, otherwise Vike would need to re-implement https://www.npmjs.com/package/@rollup/plugin-alias.)
27
+ */
28
+ filePathAbsoluteFilesystem: string | null;
29
+ /**
30
+ * The file's path, absolute starting from the user root directory (i.e. Vite's `config.root`).
31
+ *
32
+ * Example: `/pages/some-page/+Page.js`.
33
+ *
34
+ * Its value is `null` if the file is outside of the user root directory (i.e. Vite's `config.root`).
35
+ *
36
+ */
37
+ filePathAbsoluteUserRootDir: string | null;
38
+ /**
39
+ * The file's path, shown to the user in logs.
40
+ *
41
+ * Unresolved: it may show an import path instead of a file path such as `vike-react/config`.
42
+ *
43
+ * Its value is equivalent to `filePath.filePathAbsoluteUserRootDir ?? filePath.importPathAbsolute`.
44
+ */
45
+ filePathToShowToUser: string;
46
+ /**
47
+ * The file's non-relative path, from Vite's perspective.
48
+ *
49
+ * Examples:
50
+ * - `/pages/+config.js`
51
+ * - `vike-react/config`
52
+ *
53
+ * We use it to generate import paths in virtual modules. (Since import paths in virtual modules cannot be relative.)
54
+ *
55
+ * Its value is equivalent to `filePath.filePathAbsoluteUserRootDir ?? filePath.importPathAbsolute`.
56
+ */
57
+ filePathAbsoluteVite: string;
58
+ /**
59
+ * The file's non-relative import path. It's either:
60
+ * - an npm package import (e.g. `vike-react/config`), or
61
+ * - a path alias import (e.g. `#components/Counter').
62
+ */
63
+ importPathAbsolute: string | null;
64
+ };
@@ -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,7 +7,8 @@ export { logAbortErrorHandled };
7
7
  export { getPageContextFromAllRewrites };
8
8
  export { AbortRender };
9
9
  export { assertNoInfiniteAbortLoop };
10
- import { assert, assertInfo, assertUsage, assertWarning, checkType, hasProp, isUriWithProtocol, isUserHookError, joinEnglish, objectAssign, truncateString } from './utils.js';
10
+ import { isUserHookError } from '../hooks/executeHook.js';
11
+ import { assert, assertInfo, assertUsage, assertWarning, checkType, hasProp, isUriWithProtocol, joinEnglish, objectAssign, truncateString } from './utils.js';
11
12
  import pc from '@brillout/picocolors';
12
13
  /**
13
14
  * Abort the rendering of the current page, and redirect the user to another URL instead.
@@ -1,6 +1,7 @@
1
1
  export { executeGuardHook };
2
2
  import { getHook, getHookTimeoutDefault } from '../hooks/getHook.js';
3
- import { assert, assertUsage, executeHook, isCallable } from './utils.js';
3
+ import { assert, assertUsage, isCallable } from './utils.js';
4
+ import { executeHook } from '../hooks/executeHook.js';
4
5
  const errIntro = 'The guard() hook defined by';
5
6
  async function executeGuardHook(pageContext, prepareForUserConsumption) {
6
7
  let hook;
@@ -1,8 +1,9 @@
1
1
  export { executeOnBeforeRouteHook };
2
2
  import { assertPageContextProvidedByUser } from '../assertPageContextProvidedByUser.js';
3
- import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrl, joinEnglish, assert, executeHook } from './utils.js';
3
+ import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrl, joinEnglish, assert } from './utils.js';
4
4
  import { assertRouteParams, assertSyncRouting } from './resolveRouteFunction.js';
5
5
  import pc from '@brillout/picocolors';
6
+ import { executeHook } from '../hooks/executeHook.js';
6
7
  async function executeOnBeforeRouteHook(pageContext) {
7
8
  const pageContextFromOnBeforeRouteHook = {};
8
9
  if (!pageContext._onBeforeRouteHook)
@@ -34,9 +34,8 @@ async function route(pageContextForRoute) {
34
34
  objectAssign(pageContext, pageContextFromOnBeforeRouteHook);
35
35
  // Vike's routing
36
36
  const allPageIds = pageContext._allPageIds;
37
- assert(allPageIds.length >= 0);
38
- assertUsage(pageContext._pageFilesAll.length > 0 || pageContext._pageConfigs.length > 0, 'No *.page.js file found. You must create at least one *.page.js file.');
39
- assertUsage(allPageIds.length > 0, "You must create at least one *.page.js file that isn't _default.page.*");
37
+ assertUsage(allPageIds.length > 0, 'No page found. You must create at least one page.');
38
+ assert(pageContext._pageFilesAll.length > 0 || pageContext._pageConfigs.length > 0);
40
39
  const { urlPathname } = pageContext;
41
40
  assert(urlPathname.startsWith('/'));
42
41
  const routeMatches = [];
@@ -10,7 +10,6 @@ export * from '../../utils/isStringRecord.js';
10
10
  export * from '../../utils/unique.js';
11
11
  export * from '../../utils/isBrowser.js';
12
12
  export * from '../../utils/parseUrl.js';
13
- export * from '../hooks/executeHook.js';
14
13
  export * from '../../utils/checkType.js';
15
14
  export * from '../../utils/joinEnglish.js';
16
15
  export * from '../../utils/projectInfo.js';
@@ -19,7 +19,6 @@ export * from '../../utils/isStringRecord.js';
19
19
  export * from '../../utils/unique.js';
20
20
  export * from '../../utils/isBrowser.js';
21
21
  export * from '../../utils/parseUrl.js';
22
- export * from '../hooks/executeHook.js';
23
22
  export * from '../../utils/checkType.js';
24
23
  export * from '../../utils/joinEnglish.js';
25
24
  export * from '../../utils/projectInfo.js';
@@ -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;
@@ -5,6 +5,7 @@ import { assertPosixPath } from './filesystemPathHandling.js';
5
5
  /** Assert path is absolute from the filesystem root */
6
6
  function assertPathIsFilesystemAbsolute(p) {
7
7
  assertPosixPath(p);
8
+ assert(!p.startsWith('/@fs/'));
8
9
  if (process.platform === 'win32') {
9
10
  assert(path.win32.isAbsolute(p));
10
11
  }
@@ -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,7 +1,7 @@
1
1
  export { createDebugger };
2
2
  export { isDebugEnabled };
3
3
  export type { Debug };
4
- type Flag = 'vike:routing' | 'vike:error' | 'vike:stream' | 'vike:log' | 'vike:virtual-files' | 'vike:outDir' | 'vike:extractExportNames' | 'vike:extractAssets' | 'vike:glob' | 'vike:pageFiles' | 'vike:setup' | 'vike:pointer-imports';
4
+ type Flag = 'vike:routing' | 'vike:error' | 'vike:stream' | 'vike:log' | 'vike:virtual-files' | 'vike:outDir' | 'vike:extractExportNames' | 'vike:extractAssets' | 'vike:glob' | 'vike:pageFiles' | 'vike:setup' | 'vike:pointer-imports' | 'vike:optimizeDeps';
5
5
  type Debug = ReturnType<typeof createDebugger>;
6
6
  type Options = {
7
7
  serialization?: {
@@ -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,12 @@
1
1
  export { isNpmPackageImport };
2
- export { isNpmPackageName };
3
- export { getNpmPackageName };
4
- export { getNpmPackageImportPath };
2
+ export { assertIsNpmPackageImport };
5
3
  export { isValidPathAlias };
6
4
  export { parse };
7
5
  export { isDistinguishable };
8
- 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;
6
+ declare function isNpmPackageImport(str: string, { cannotBePathAlias }: {
7
+ cannotBePathAlias: true;
8
+ }): boolean;
9
+ declare function assertIsNpmPackageImport(str: string): void;
12
10
  declare function isValidPathAlias(alias: string): boolean;
13
11
  declare function isDistinguishable(alias: string): boolean;
14
12
  declare function parse(str: string | undefined): null | {
@@ -1,18 +1,29 @@
1
1
  export { isNpmPackageImport };
2
- export { isNpmPackageName };
3
- export { getNpmPackageName };
4
- export { getNpmPackageImportPath };
2
+ export { assertIsNpmPackageImport };
5
3
  export { isValidPathAlias };
4
+ /* Currently not used
5
+ export { isNpmPackageName }
6
+ export { getNpmPackageName }
7
+ export { getNpmPackageImportPath }
8
+ */
6
9
  // For ./isNpmPackage.spec.ts
7
10
  export { parse };
8
11
  export { isDistinguishable };
9
12
  import { assert } from './assert.js';
10
13
  import { assertIsNotBrowser } from './assertIsNotBrowser.js';
11
14
  assertIsNotBrowser();
12
- function isNpmPackageImport(str) {
15
+ function isNpmPackageImport(str, { cannotBePathAlias }) {
16
+ // We cannot distinguish path alises that look like npm package imports
17
+ assert(cannotBePathAlias);
13
18
  const res = parse(str);
14
19
  return res !== null;
15
20
  }
21
+ function assertIsNpmPackageImport(str) {
22
+ assert(isNpmPackageImport(str, {
23
+ // If `str` is a path alias that looks like an npm package => assertIsNpmPackageImport() is erroneous but that's okay because the assertion will eventually fail for some other user using a disambiguated path alias.
24
+ cannotBePathAlias: true
25
+ }));
26
+ }
16
27
  function isNpmPackageName(str) {
17
28
  const res = parse(str);
18
29
  return res !== null && res.importPath === null;
@@ -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-commit-a5e2596";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.165";
6
+ projectVersion: "0.4.166-commit-a5e2596";
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-commit-a5e2596';
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-commit-a5e2596",
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,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertClientEntryId = void 0;
4
- const utils_js_1 = require("../../utils.js");
5
- const virtualFilePageConfigValuesAll_js_1 = require("../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
6
- function assertClientEntryId(id) {
7
- (0, utils_js_1.assertPosixPath)(id);
8
- (0, utils_js_1.assert)(!id.startsWith('/@fs'), id);
9
- (0, utils_js_1.assert)(
10
- // Client entry
11
- id.startsWith('@@vike/') ||
12
- // User files
13
- id.startsWith('/') ||
14
- // Page code importer
15
- (0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id) ||
16
- // Import
17
- (0, utils_js_1.isNpmPackageImport)(id), id);
18
- }
19
- exports.assertClientEntryId = assertClientEntryId;