vike 0.4.168-commit-ce94f5c → 0.4.168-commit-42406a9

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 (173) hide show
  1. package/dist/cjs/node/plugin/plugins/buildConfig.js +10 -2
  2. package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +1 -1
  3. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +19 -16
  4. package/dist/cjs/node/plugin/plugins/distFileNames.js +7 -1
  5. package/dist/cjs/node/plugin/plugins/envVars.js +1 -5
  6. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +7 -7
  7. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +14 -11
  8. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +11 -14
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{resolveImportPath.js → resolvePointerImport.js} +58 -44
  10. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +8 -8
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +52 -12
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +81 -106
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -2
  14. package/dist/cjs/node/plugin/shared/getFilePath.js +44 -48
  15. package/dist/cjs/node/plugin/utils.js +2 -2
  16. package/dist/cjs/node/prerender/runPrerender.js +6 -5
  17. package/dist/cjs/node/prerender/utils.js +2 -1
  18. package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +1 -0
  19. package/dist/cjs/node/runtime/index-common.js +14 -3
  20. package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +2 -1
  21. package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +25 -14
  22. package/dist/cjs/node/runtime/renderPage/log404/index.js +2 -2
  23. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +1 -1
  24. package/dist/cjs/node/runtime/utils.js +2 -1
  25. package/dist/cjs/node/shared/assertV1Design.js +1 -1
  26. package/dist/cjs/node/shared/getClientEntry.js +2 -2
  27. package/dist/cjs/node/shared/prependEntriesDir.js +1 -0
  28. package/dist/cjs/node/shared/utils.js +0 -1
  29. package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +3 -3
  30. package/dist/cjs/shared/getPageFiles/getExports.js +8 -15
  31. package/dist/cjs/shared/getPageFiles.js +3 -6
  32. package/dist/cjs/shared/hooks/getHook.js +7 -6
  33. package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +48 -0
  34. package/dist/cjs/shared/page-configs/{helpers/getConfigValue.js → getConfigValue.js} +6 -8
  35. package/dist/cjs/shared/page-configs/helpers.js +6 -11
  36. package/dist/cjs/shared/page-configs/serialize/assertPageConfigsSerialized.js +1 -1
  37. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +2 -1
  38. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +11 -6
  39. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +4 -3
  40. package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +3 -3
  41. package/dist/cjs/shared/route/index.js +2 -2
  42. package/dist/cjs/shared/route/loadPageRoutes.js +12 -10
  43. package/dist/cjs/shared/route/resolveRouteFunction.js +8 -9
  44. package/dist/cjs/shared/route/resolveRouteString.js +5 -16
  45. package/dist/cjs/shared/route/utils.js +0 -1
  46. package/dist/cjs/shared/utils.js +1 -0
  47. package/dist/cjs/utils/assertPathFilesystemAbsolute.js +39 -0
  48. package/dist/cjs/utils/createErrorWithCleanStackTrace.js +1 -7
  49. package/dist/cjs/utils/debug.js +2 -1
  50. package/dist/cjs/utils/findFile.js +2 -1
  51. package/dist/cjs/utils/hasProp.js +9 -5
  52. package/dist/cjs/utils/injectRollupInputs.js +2 -1
  53. package/dist/cjs/utils/isArray.js +8 -0
  54. package/dist/cjs/utils/isArrayOfStrings.js +8 -0
  55. package/dist/cjs/utils/isDev.js +12 -4
  56. package/dist/cjs/utils/isNpmPackage.js +1 -1
  57. package/dist/cjs/utils/isObjectOfStrings.js +8 -0
  58. package/dist/cjs/utils/projectInfo.js +1 -1
  59. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +3 -1
  60. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +2 -1
  61. package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -0
  62. package/dist/esm/client/shared/getPageContextSerializedInHtml.d.ts +1 -0
  63. package/dist/esm/client/shared/getPageContextSerializedInHtml.js +1 -0
  64. package/dist/esm/client/shared/loadUserFilesClientSide.js +3 -7
  65. package/dist/esm/node/plugin/plugins/buildConfig.js +9 -1
  66. package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +2 -2
  67. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +20 -17
  68. package/dist/esm/node/plugin/plugins/distFileNames.js +8 -2
  69. package/dist/esm/node/plugin/plugins/envVars.js +2 -6
  70. package/dist/esm/node/plugin/plugins/importUserCode/index.js +9 -9
  71. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +2 -2
  72. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +14 -11
  73. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +4 -3
  74. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +2 -2
  75. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +12 -15
  76. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +12 -0
  77. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +123 -0
  78. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.d.ts +8 -8
  79. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +7 -7
  80. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +53 -13
  81. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +81 -106
  82. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
  83. package/dist/esm/node/plugin/shared/getFilePath.d.ts +11 -5
  84. package/dist/esm/node/plugin/shared/getFilePath.js +43 -47
  85. package/dist/esm/node/plugin/utils.d.ts +2 -2
  86. package/dist/esm/node/plugin/utils.js +2 -2
  87. package/dist/esm/node/prerender/runPrerender.js +6 -5
  88. package/dist/esm/node/prerender/utils.d.ts +2 -1
  89. package/dist/esm/node/prerender/utils.js +2 -1
  90. package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +1 -0
  91. package/dist/esm/node/runtime/html/serializePageContextClientSide.js +1 -0
  92. package/dist/esm/node/runtime/index-common.d.ts +0 -4
  93. package/dist/esm/node/runtime/index-common.js +14 -3
  94. package/dist/esm/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +2 -1
  95. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +4 -4
  96. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +27 -16
  97. package/dist/esm/node/runtime/renderPage/log404/index.js +2 -2
  98. package/dist/esm/node/runtime/renderPage/logErrorHint.js +2 -2
  99. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -7
  100. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +16 -16
  101. package/dist/esm/node/runtime/utils.d.ts +2 -1
  102. package/dist/esm/node/runtime/utils.js +2 -1
  103. package/dist/esm/node/shared/assertV1Design.js +1 -1
  104. package/dist/esm/node/shared/getClientEntry.js +1 -1
  105. package/dist/esm/node/shared/prependEntriesDir.js +1 -0
  106. package/dist/esm/node/shared/utils.d.ts +0 -1
  107. package/dist/esm/node/shared/utils.js +0 -1
  108. package/dist/esm/shared/getPageFiles/analyzeClientSide.js +1 -1
  109. package/dist/esm/shared/getPageFiles/getExports.d.ts +4 -5
  110. package/dist/esm/shared/getPageFiles/getExports.js +9 -16
  111. package/dist/esm/shared/getPageFiles.d.ts +1 -2
  112. package/dist/esm/shared/getPageFiles.js +1 -3
  113. package/dist/esm/shared/hooks/getHook.js +6 -5
  114. package/dist/esm/shared/page-configs/Config.d.ts +2 -2
  115. package/dist/esm/shared/page-configs/FilePath.d.ts +32 -22
  116. package/dist/esm/shared/page-configs/PageConfig.d.ts +27 -15
  117. package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +11 -0
  118. package/dist/esm/shared/page-configs/getConfigDefinedAt.js +42 -0
  119. package/dist/esm/shared/page-configs/{helpers/getConfigValue.d.ts → getConfigValue.d.ts} +2 -2
  120. package/dist/esm/shared/page-configs/{helpers/getConfigValue.js → getConfigValue.js} +6 -8
  121. package/dist/esm/shared/page-configs/helpers.d.ts +3 -9
  122. package/dist/esm/shared/page-configs/helpers.js +6 -8
  123. package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +7 -4
  124. package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.js +2 -2
  125. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +2 -1
  126. package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +12 -7
  127. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +5 -4
  128. package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +3 -3
  129. package/dist/esm/shared/route/index.js +2 -2
  130. package/dist/esm/shared/route/loadPageRoutes.d.ts +3 -3
  131. package/dist/esm/shared/route/loadPageRoutes.js +10 -8
  132. package/dist/esm/shared/route/resolveRouteFunction.d.ts +1 -1
  133. package/dist/esm/shared/route/resolveRouteFunction.js +9 -10
  134. package/dist/esm/shared/route/resolveRouteString.d.ts +0 -2
  135. package/dist/esm/shared/route/resolveRouteString.js +5 -16
  136. package/dist/esm/shared/route/utils.d.ts +0 -1
  137. package/dist/esm/shared/route/utils.js +0 -1
  138. package/dist/esm/shared/utils.d.ts +1 -0
  139. package/dist/esm/shared/utils.js +1 -0
  140. package/dist/esm/utils/assertPathFilesystemAbsolute.d.ts +6 -0
  141. package/dist/esm/utils/assertPathFilesystemAbsolute.js +33 -0
  142. package/dist/esm/utils/createErrorWithCleanStackTrace.js +1 -7
  143. package/dist/esm/utils/debug.js +2 -1
  144. package/dist/esm/utils/findFile.js +2 -1
  145. package/dist/esm/utils/hasProp.d.ts +1 -0
  146. package/dist/esm/utils/hasProp.js +9 -5
  147. package/dist/esm/utils/injectRollupInputs.js +2 -1
  148. package/dist/esm/utils/isArray.d.ts +1 -0
  149. package/dist/esm/utils/isArray.js +4 -0
  150. package/dist/esm/utils/isArrayOfStrings.d.ts +2 -0
  151. package/dist/esm/utils/isArrayOfStrings.js +5 -0
  152. package/dist/esm/utils/isDev.d.ts +3 -0
  153. package/dist/esm/utils/isDev.js +11 -3
  154. package/dist/esm/utils/isNpmPackage.js +1 -1
  155. package/dist/esm/utils/isObjectOfStrings.d.ts +2 -0
  156. package/dist/esm/utils/isObjectOfStrings.js +5 -0
  157. package/dist/esm/utils/projectInfo.d.ts +2 -2
  158. package/dist/esm/utils/projectInfo.js +1 -1
  159. package/package.json +1 -1
  160. package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +0 -43
  161. package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +0 -21
  162. package/dist/cjs/utils/isStringRecord.js +0 -7
  163. package/dist/cjs/utils/mergeCumulativeValues.js +0 -21
  164. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +0 -13
  165. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +0 -109
  166. package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +0 -7
  167. package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +0 -37
  168. package/dist/esm/utils/assertPathIsFilesystemAbsolute.d.ts +0 -3
  169. package/dist/esm/utils/assertPathIsFilesystemAbsolute.js +0 -15
  170. package/dist/esm/utils/isStringRecord.d.ts +0 -1
  171. package/dist/esm/utils/isStringRecord.js +0 -3
  172. package/dist/esm/utils/mergeCumulativeValues.d.ts +0 -2
  173. package/dist/esm/utils/mergeCumulativeValues.js +0 -18
@@ -25,12 +25,7 @@ function resolveRouteString(routeString, urlPathname) {
25
25
  return '[^/]+';
26
26
  }
27
27
  if (segment.glob) {
28
- if (segment.isLastDir) {
29
- return '|/.*';
30
- }
31
- else {
32
- return '.*';
33
- }
28
+ return '.*';
34
29
  }
35
30
  // segment.static
36
31
  return escapeRegex(segment.static);
@@ -60,8 +55,6 @@ function resolveRouteString(routeString, urlPathname) {
60
55
  }
61
56
  if (segment.glob) {
62
57
  const param = `*${hasMultipleGlobs ? ++globIdx : ''}`;
63
- if (segment.isLastDir)
64
- val = val.slice(1);
65
58
  routeParams[param] = val;
66
59
  }
67
60
  });
@@ -80,21 +73,17 @@ function parseRouteString(routeString) {
80
73
  };
81
74
  const parts = routeString.split('/');
82
75
  parts.forEach((s, i) => {
83
- const isFirst = i === 0;
84
- const isLast = i === parts.length - 1;
76
+ if (i !== 0)
77
+ pushStatic('/');
85
78
  if (isParam(s)) {
86
79
  assertWarning(!s.startsWith(PARAM_TOKEN_OLD), `Outdated Route String ${highlight(routeString)}, use ${highlight(routeString.split(PARAM_TOKEN_OLD).join(PARAM_TOKEN_NEW))} instead`, { onlyOnce: true });
87
- if (!isFirst)
88
- pushStatic('/');
89
80
  segments.push({ param: s.slice(1) });
90
81
  }
91
82
  else {
92
- if (s === '*' && isLast && routeString !== '*' && routeString !== '/*') {
93
- segments.push({ glob: true, isLastDir: true });
83
+ if (s === '*' && i === parts.length - 1 && routeString !== '*' && routeString !== '/*') {
84
+ segments.push({ glob: true });
94
85
  }
95
86
  else {
96
- if (!isFirst)
97
- pushStatic('/');
98
87
  s.split('*').forEach((s, i) => {
99
88
  if (i !== 0)
100
89
  segments.push({ glob: true });
@@ -6,7 +6,6 @@ export * from '../../utils/isPromise.js';
6
6
  export * from '../../utils/isPlainObject.js';
7
7
  export * from '../../utils/objectAssign.js';
8
8
  export * from '../../utils/slice.js';
9
- export * from '../../utils/isStringRecord.js';
10
9
  export * from '../../utils/unique.js';
11
10
  export * from '../../utils/isBrowser.js';
12
11
  export * from '../../utils/parseUrl.js';
@@ -15,7 +15,6 @@ export * from '../../utils/isPromise.js';
15
15
  export * from '../../utils/isPlainObject.js';
16
16
  export * from '../../utils/objectAssign.js';
17
17
  export * from '../../utils/slice.js';
18
- export * from '../../utils/isStringRecord.js';
19
18
  export * from '../../utils/unique.js';
20
19
  export * from '../../utils/isBrowser.js';
21
20
  export * from '../../utils/parseUrl.js';
@@ -20,3 +20,4 @@ export * from '../utils/isPromise.js';
20
20
  export * from '../utils/checkType.js';
21
21
  export * from '../utils/getValuePrintable.js';
22
22
  export * from '../utils/escapeRegex.js';
23
+ export * from '../utils/isArray.js';
@@ -24,3 +24,4 @@ export * from '../utils/isPromise.js';
24
24
  export * from '../utils/checkType.js';
25
25
  export * from '../utils/getValuePrintable.js';
26
26
  export * from '../utils/escapeRegex.js';
27
+ export * from '../utils/isArray.js';
@@ -0,0 +1,6 @@
1
+ export { assertPathFilesystemAbsolute };
2
+ export { isPathFilesystemAbsolute };
3
+ /** Assert path is absolute starting from the filesystem root. */
4
+ declare function assertPathFilesystemAbsolute(p: string): void;
5
+ /** Whether path is absolute starting from the filesystem root. Isn't reliable for Linux users: isPathFilesystemAbsolute() returns `true` for paths absolute from the user root dir. */
6
+ declare function isPathFilesystemAbsolute(p: string): boolean;
@@ -0,0 +1,33 @@
1
+ export { assertPathFilesystemAbsolute };
2
+ export { isPathFilesystemAbsolute };
3
+ import path from 'path';
4
+ import { assert } from './assert.js';
5
+ import { assertPosixPath } from './filesystemPathHandling.js';
6
+ /** Assert path is absolute starting from the filesystem root. */
7
+ function assertPathFilesystemAbsolute(p) {
8
+ // The assert is "eventually reliable":
9
+ // - For Windows users, the assert is correct.
10
+ // - For Linux users assertPathFilesystemAbsolute() will erroneously succeed if `p` is a path absolute from the user root dir.
11
+ // - But that's okay because the assertion will eventually fail for Windows users.
12
+ assert(isPathFilesystemAbsolute(p));
13
+ }
14
+ /** Whether path is absolute starting from the filesystem root. Isn't reliable for Linux users: isPathFilesystemAbsolute() returns `true` for paths absolute from the user root dir. */
15
+ function isPathFilesystemAbsolute(p) {
16
+ assertPosixPath(p);
17
+ assert(!p.startsWith('/@fs/'));
18
+ if (process.platform !== 'win32') {
19
+ // - For linux users, there doesn't seem to be a reliable way to distinguish between:
20
+ // - File path absolute starting from filesystem root, e.g. /home/rom/code/my-app/pages/about/+Page.js
21
+ // - File path absolute starting from user root dir (Vite's `config.root`), e.g. /pages/about/+Page.js
22
+ // - Checking whether `p` starts with the first directory of process.cwd() (or `userRootDir`) can be erroneous, most notably when using docker: https://github.com/vikejs/vike/issues/703
23
+ // - Using require.resolve() would be a solution but probably too slow?
24
+ return p.startsWith('/');
25
+ }
26
+ else {
27
+ const yes = path.win32.isAbsolute(p);
28
+ // Ensure isPathFilesystemAbsolute() returns `false` if path is absolute starting from the user root dir (see comments above).
29
+ if (yes)
30
+ assert(!p.startsWith('/'));
31
+ return yes;
32
+ }
33
+ }
@@ -1,13 +1,7 @@
1
1
  export { createErrorWithCleanStackTrace };
2
2
  import { isNodeJS } from './isNodeJS.js';
3
3
  function createErrorWithCleanStackTrace(errorMessage, numberOfStackTraceLinesToRemove) {
4
- let err;
5
- {
6
- var stackTraceLimit__original = Error.stackTraceLimit;
7
- Error.stackTraceLimit = Infinity;
8
- err = new Error(errorMessage);
9
- Error.stackTraceLimit = stackTraceLimit__original;
10
- }
4
+ const err = new Error(errorMessage);
11
5
  if (isNodeJS()) {
12
6
  err.stack = clean(err.stack, numberOfStackTraceLinesToRemove);
13
7
  }
@@ -7,6 +7,7 @@ import { assert, assertUsage } from './assert.js';
7
7
  import { checkType } from './checkType.js';
8
8
  import { getTerminalWidth } from './getTerminWidth.js';
9
9
  import pc from '@brillout/picocolors';
10
+ import { isArray } from './isArray.js';
10
11
  // Avoid this to be loaded in the browser. For isomorphic code: instead of `import { createDebugger } from './utils.js'`, use `globalThis.createDebugger()`.
11
12
  assert(!isBrowser());
12
13
  globalThis.__brillout_debug_createDebugger = createDebugger;
@@ -81,7 +82,7 @@ function formatMsg(info, options, padding, position) {
81
82
  if (typeof info === 'string') {
82
83
  str += info;
83
84
  }
84
- else if (Array.isArray(info)) {
85
+ else if (isArray(info)) {
85
86
  if (info.length === 0) {
86
87
  str += options.serialization?.emptyArray ?? '[]';
87
88
  }
@@ -1,8 +1,9 @@
1
1
  export { findFile };
2
2
  import path from 'path';
3
3
  import fs from 'fs';
4
+ import { isArray } from './isArray.js';
4
5
  function findFile(arg, cwd) {
5
- const filenames = Array.isArray(arg) ? arg : [arg];
6
+ const filenames = isArray(arg) ? arg : [arg];
6
7
  let dir = cwd;
7
8
  while (true) {
8
9
  for (const filename of filenames) {
@@ -5,6 +5,7 @@ declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectTy
5
5
  declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'object'): obj is ObjectType & Record<PropName, Record<string, unknown>>;
6
6
  declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'array'): obj is ObjectType & Record<PropName, unknown[]>;
7
7
  declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'string[]'): obj is ObjectType & Record<PropName, string[]>;
8
+ declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'string{}'): obj is ObjectType & Record<PropName, Record<string, string>>;
8
9
  declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'function'): obj is ObjectType & Record<PropName, (...args: any[]) => unknown>;
9
10
  declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'undefined'): obj is ObjectType & Record<PropName, undefined>;
10
11
  declare function hasProp<ObjectType, PropName extends PropertyKey>(obj: ObjectType, prop: PropName, type: 'null'): obj is ObjectType & Record<PropName, null>;
@@ -3,8 +3,9 @@ export { hasProp };
3
3
  // - https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABDAzgFQJ4AcCmdgAUAbgIYA2IOAXIiWBgDSJTbWIDkARnHGTnewCUNUhRzIUibr35gA3AFgAUKEiwEEzLnzFylGnUbNWNdmBABbTjgBOQkXvGpE5q7cUrw0eElRa8hKL6tPRMLLimKFA2MGAA5vaIQU6SUTHxHqreGn6sOskGocYRHOAA1mBwAO5gickSiOWVNZle6r7oeYGOhUbhbGmxcYgAvKVgFdW1wlI8fHSIAN7KiMiExeIjW+OTNeyIgksrq4g2OFAgNkjRlMcAvsdnF1cb+EmOo9v9Hg9KyhAIKK0GhNKajRAAFgATMplCQUChbFACLltIQSEwzJZrHZBIJ-oCZAA6MhwOIEEj4v6eNQ+WgIpEEAFgAAmMHaIImzTAM3hiJsUEkzLZ7SOShOa0QTIQIp8hyelzAx1WUAAFjZqi4cFVEABRGwamwEdgAQQZArpADESDAyEJlHcgA
4
4
  import { isCallable } from './isCallable.js';
5
5
  import { isObject } from './isObject.js';
6
- // prettier-ignore
7
- // biome-ignore format:
6
+ import { isArrayOfStrings } from './isArrayOfStrings.js';
7
+ import { isObjectOfStrings } from './isObjectOfStrings.js';
8
+ import { isArray } from './isArray.js';
8
9
  function hasProp(obj, prop, type = 'unknown') {
9
10
  if (!isObject(obj))
10
11
  return false;
@@ -16,18 +17,21 @@ function hasProp(obj, prop, type = 'unknown') {
16
17
  }
17
18
  const propValue = obj[prop];
18
19
  if (type === 'array') {
19
- return Array.isArray(propValue);
20
+ return isArray(propValue);
20
21
  }
21
22
  if (type === 'object') {
22
23
  return isObject(propValue);
23
24
  }
24
25
  if (type === 'string[]') {
25
- return Array.isArray(propValue) && propValue.every(el => typeof el === 'string');
26
+ return isArrayOfStrings(propValue);
27
+ }
28
+ if (type === 'string{}') {
29
+ return isObjectOfStrings(propValue);
26
30
  }
27
31
  if (type === 'function') {
28
32
  return isCallable(propValue);
29
33
  }
30
- if (Array.isArray(type)) {
34
+ if (isArray(type)) {
31
35
  return typeof propValue === 'string' && type.includes(propValue);
32
36
  }
33
37
  if (type === 'null') {
@@ -2,6 +2,7 @@ export { injectRollupInputs };
2
2
  export { normalizeRollupInput };
3
3
  import { assert } from './assert.js';
4
4
  import { isObject } from './isObject.js';
5
+ import { isArray } from './isArray.js';
5
6
  function injectRollupInputs(inputsNew, config) {
6
7
  const inputsCurrent = normalizeRollupInput(config.build.rollupOptions.input);
7
8
  const input = {
@@ -18,7 +19,7 @@ function normalizeRollupInput(input) {
18
19
  if (typeof input === 'string') {
19
20
  input = [input];
20
21
  }
21
- if (Array.isArray(input)) {
22
+ if (isArray(input)) {
22
23
  return Object.fromEntries(input.map((input) => [input, input]));
23
24
  }
24
25
  assert(isObject(input));
@@ -0,0 +1 @@
1
+ export declare function isArray(value: unknown): value is unknown[];
@@ -0,0 +1,4 @@
1
+ // Typesafe Array.isArray() — asserting unknown[] instead of any[]
2
+ export function isArray(value) {
3
+ return Array.isArray(value);
4
+ }
@@ -0,0 +1,2 @@
1
+ export { isArrayOfStrings };
2
+ declare function isArrayOfStrings(val: unknown): val is string[];
@@ -0,0 +1,5 @@
1
+ export { isArrayOfStrings };
2
+ import { isArray } from './isArray.js';
3
+ function isArrayOfStrings(val) {
4
+ return isArray(val) && val.every((v) => typeof v === 'string');
5
+ }
@@ -1,6 +1,9 @@
1
1
  export { isDev1 };
2
2
  export { isDev1_onConfigureServer };
3
3
  export { isDev2 };
4
+ export { isDev3 };
5
+ import type { ConfigEnv } from 'vite';
6
+ declare function isDev3(configEnv: ConfigEnv): null | boolean;
4
7
  declare function isDev1(): boolean;
5
8
  declare function isDev1_onConfigureServer(): void | undefined;
6
9
  import type { ResolvedConfig } from 'vite';
@@ -1,10 +1,18 @@
1
1
  export { isDev1 };
2
2
  export { isDev1_onConfigureServer };
3
3
  export { isDev2 };
4
- // There isn't any reliable way to test whether Vite is ran as dev/build/preview/optimizeDep
5
- // - Failed attempt to make a PR: https://github.com/brillout/vite/tree/fix/config-operation
4
+ export { isDev3 };
5
+ function isDev3(configEnv) {
6
+ const { isPreview, command } = configEnv;
7
+ if (command !== 'serve')
8
+ return false;
9
+ if (typeof isPreview === 'boolean')
10
+ return !isPreview;
11
+ // isPreview is undefined in older Vite versions, see https://github.com/vitejs/vite/commit/93fce55
12
+ return null;
13
+ }
6
14
  // ********
7
- // Method 1 - most reliable
15
+ // Method 1 - reliable
8
16
  // ********
9
17
  import { assert } from './assert.js';
10
18
  import { getGlobalObject } from './getGlobalObject.js';
@@ -22,7 +22,7 @@ function assertIsNpmPackageImport(str) {
22
22
  assert(isNpmPackageImport(str, {
23
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
24
  cannotBePathAlias: true
25
- }));
25
+ }), str);
26
26
  }
27
27
  function isNpmPackageName(str) {
28
28
  const res = parse(str);
@@ -0,0 +1,2 @@
1
+ export { isObjectOfStrings };
2
+ declare function isObjectOfStrings(val: unknown): val is Record<string, string>;
@@ -0,0 +1,5 @@
1
+ export { isObjectOfStrings };
2
+ import { isObject } from './isObject.js';
3
+ function isObjectOfStrings(val) {
4
+ return isObject(val) && Object.values(val).every((v) => typeof v === 'string');
5
+ }
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- declare const PROJECT_VERSION: "0.4.168-commit-ce94f5c";
3
+ declare const PROJECT_VERSION: "0.4.168-commit-42406a9";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.168-commit-ce94f5c";
6
+ projectVersion: "0.4.168-commit-42406a9";
7
7
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- const PROJECT_VERSION = '0.4.168-commit-ce94f5c';
3
+ const PROJECT_VERSION = '0.4.168-commit-42406a9';
4
4
  const projectInfo = {
5
5
  projectName: 'Vike',
6
6
  projectVersion: PROJECT_VERSION
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.168-commit-ce94f5c",
3
+ "version": "0.4.168-commit-42406a9",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
@@ -1,43 +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.getDefinedAtString = exports.getConfigDefinedAtString = void 0;
7
- const utils_js_1 = require("../../utils.js");
8
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
9
- const getExportPath_js_1 = require("../getExportPath.js");
10
- function getConfigDefinedAtString(sentenceBegin, configName, { definedAt }) {
11
- const definedAtString = getDefinedAtString(definedAt, configName);
12
- const definedAtStr = definedAtString === 'internally' ? definedAtString : `at ${definedAtString}`;
13
- let configNameStr = `${configName}${ /*sentenceBegin === 'Hook' ? '()' :*/''}`;
14
- const configDefinedAt = `${sentenceBegin} ${picocolors_1.default.cyan(configNameStr)} defined ${definedAtStr}`;
15
- return configDefinedAt;
16
- }
17
- exports.getConfigDefinedAtString = getConfigDefinedAtString;
18
- function getDefinedAtString(definedAt, configName) {
19
- if ('isComputed' in definedAt) {
20
- return 'internally';
21
- }
22
- let files;
23
- if ('files' in definedAt) {
24
- files = definedAt.files;
25
- }
26
- else {
27
- files = [definedAt];
28
- }
29
- (0, utils_js_1.assert)(files.length >= 1);
30
- const definedAtString = files
31
- .map((source) => {
32
- const { filePathToShowToUser, fileExportPathToShowToUser } = source;
33
- let s = filePathToShowToUser;
34
- const exportPath = (0, getExportPath_js_1.getExportPath)(fileExportPathToShowToUser, configName);
35
- if (exportPath) {
36
- s = `${s} > ${picocolors_1.default.cyan(exportPath)}`;
37
- }
38
- return s;
39
- })
40
- .join(' / ');
41
- return definedAtString;
42
- }
43
- exports.getDefinedAtString = getDefinedAtString;
@@ -1,21 +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.assertPathIsFilesystemAbsolute = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const assert_js_1 = require("./assert.js");
9
- const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
10
- /** Assert path is absolute from the filesystem root */
11
- function assertPathIsFilesystemAbsolute(p) {
12
- (0, filesystemPathHandling_js_1.assertPosixPath)(p);
13
- (0, assert_js_1.assert)(!p.startsWith('/@fs/'));
14
- if (process.platform !== 'win32') {
15
- (0, assert_js_1.assert)(p.startsWith('/'));
16
- }
17
- else {
18
- (0, assert_js_1.assert)(path_1.default.win32.isAbsolute(p));
19
- }
20
- }
21
- exports.assertPathIsFilesystemAbsolute = assertPathIsFilesystemAbsolute;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isStringRecord = void 0;
4
- function isStringRecord(thing) {
5
- return typeof thing === 'object' && thing !== null && Object.values(thing).every((val) => typeof val === 'string');
6
- }
7
- exports.isStringRecord = isStringRecord;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeCumulativeValues = void 0;
4
- const assert_js_1 = require("./assert.js");
5
- function mergeCumulativeValues(values) {
6
- if (values.length === 0)
7
- return null;
8
- if (values.every((v) => v instanceof Set)) {
9
- return new Set(values
10
- .map((v) => {
11
- (0, assert_js_1.assert)(v instanceof Set);
12
- return [...v];
13
- })
14
- .flat());
15
- }
16
- if (values.every((v) => Array.isArray(v))) {
17
- return values.flat();
18
- }
19
- return null;
20
- }
21
- exports.mergeCumulativeValues = mergeCumulativeValues;
@@ -1,13 +0,0 @@
1
- export { resolveImport };
2
- export { resolveImportPath };
3
- export { assertImportPath };
4
- export { clearFilesEnvMap };
5
- import type { ConfigEnvInternal, DefinedAtFileFullInfo } from '../../../../../../shared/page-configs/PageConfig.js';
6
- import { type ImportData } from './transformFileImports.js';
7
- import type { FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
8
- declare function resolveImport(configValue: unknown, importerFilePath: FilePathResolved, userRootDir: string, configEnv: ConfigEnvInternal, configName: string): null | (DefinedAtFileFullInfo & {
9
- fileExportName: string;
10
- });
11
- declare function resolveImportPath(importData: ImportData, importerFilePath: FilePathResolved): string | null;
12
- declare function assertImportPath(filePathAbsoluteFilesystem: string | null, importData: ImportData, importerFilePath: FilePathResolved): asserts filePathAbsoluteFilesystem is string;
13
- declare function clearFilesEnvMap(): void;
@@ -1,109 +0,0 @@
1
- export { resolveImport };
2
- export { resolveImportPath };
3
- export { assertImportPath };
4
- export { clearFilesEnvMap };
5
- import pc from '@brillout/picocolors';
6
- import { assert, assertPosixPath, assertUsage, deepEqual, requireResolve } from '../../../../utils.js';
7
- import { parseImportData } from './transformFileImports.js';
8
- import path from 'path';
9
- import { getFilePathResolved, getFilePathUnresolved } from '../../../../shared/getFilePath.js';
10
- const filesEnvMap = new Map();
11
- function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
12
- if (typeof configValue !== 'string')
13
- return null;
14
- const importData = parseImportData(configValue);
15
- if (!importData)
16
- return null;
17
- const { importPath, exportName } = importData;
18
- const filePathAbsoluteFilesystem = resolveImportPath(importData, importerFilePath);
19
- assertFileEnv(filePathAbsoluteFilesystem ?? importPath, configEnv, configName);
20
- const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
21
- let filePath;
22
- if (importPath.startsWith('.')) {
23
- assert(importPath.startsWith('./') || importPath.startsWith('../'));
24
- assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
25
- filePath = getFilePathResolved({ filePathAbsoluteFilesystem, userRootDir });
26
- // Imports are included in virtual files, thus the relative path of imports need to resolved.
27
- // ```
28
- // [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
29
- // ```
30
- assertUsage(filePath.filePathAbsoluteUserRootDir, `${importerFilePath.filePathToShowToUser} imports a relative path ${pc.cyan(importPath)} resolving outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
31
- // Alternativey, we can try one of the following but last time we tried none of the following worked.
32
- // /*
33
- // assert(filePathAbsoluteFilesystem.startsWith('/'))
34
- // filePath = `/@fs${filePathAbsoluteFilesystem}`
35
- // /*/
36
- // assert(filePathAbsoluteUserRootDir.startsWith('../'))
37
- // filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
38
- // //*/
39
- }
40
- else {
41
- // importPath can be:
42
- // - an npm package import
43
- // - a path alias
44
- if (filePathAbsoluteFilesystem) {
45
- filePath = getFilePathResolved({
46
- userRootDir,
47
- filePathAbsoluteFilesystem,
48
- importPathAbsolute: importPath
49
- });
50
- }
51
- else {
52
- filePath = getFilePathUnresolved({
53
- importPathAbsolute: importPath
54
- });
55
- }
56
- }
57
- return {
58
- ...filePath,
59
- fileExportName: exportName,
60
- fileExportPathToShowToUser
61
- };
62
- }
63
- function resolveImportPath(importData, importerFilePath) {
64
- const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
65
- assertPosixPath(importerFilePathAbsolute);
66
- const cwd = path.posix.dirname(importerFilePathAbsolute);
67
- // We can't use import.meta.resolve() as of Junary 2023 (and probably for a lot longer)
68
- // https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment137174954_62272600:~:text=But%20the%20argument%20parent%20(aka%20cwd)%20still%20requires%20a%20flag
69
- // filePathAbsoluteFilesystem is expected to be null when importData.importPath is a Vite path alias
70
- const filePathAbsoluteFilesystem = requireResolve(importData.importPath, cwd);
71
- return filePathAbsoluteFilesystem;
72
- }
73
- function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath) {
74
- const { importPath: importPath, importStringWasGenerated, importString } = importData;
75
- const { filePathToShowToUser } = importerFilePath;
76
- if (!filePathAbsoluteFilesystem) {
77
- const importPathString = pc.cyan(`'${importPath}'`);
78
- const errIntro = importStringWasGenerated
79
- ? `The import path ${importPathString} in ${filePathToShowToUser}`
80
- : `The import ${pc.cyan(importString)} defined in ${filePathToShowToUser}`;
81
- const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
82
- if (importPath.startsWith('.')) {
83
- assert(importPath.startsWith('./') || importPath.startsWith('../'));
84
- assertUsage(false, `${errIntro2} point to an existing file?`);
85
- }
86
- else {
87
- assertUsage(false, `${errIntro2} exist?`);
88
- }
89
- }
90
- }
91
- function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
92
- assertPosixPath(filePathForEnvCheck);
93
- if (!filesEnvMap.has(filePathForEnvCheck)) {
94
- filesEnvMap.set(filePathForEnvCheck, []);
95
- }
96
- const fileEnv = filesEnvMap.get(filePathForEnvCheck);
97
- fileEnv.push({ configEnv, configName });
98
- const configDifferentEnv = fileEnv.filter((c) => !deepEqual(c.configEnv, configEnv))[0];
99
- if (configDifferentEnv) {
100
- assertUsage(false, [
101
- `${filePathForEnvCheck} defines the value of configs living in different environments:`,
102
- ...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.cyan(c.configName)} which value lives in environment ${pc.cyan(JSON.stringify(c.configEnv))}`),
103
- 'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
104
- ].join('\n'));
105
- }
106
- }
107
- function clearFilesEnvMap() {
108
- filesEnvMap.clear();
109
- }
@@ -1,7 +0,0 @@
1
- export { getConfigDefinedAtString };
2
- export { getDefinedAtString };
3
- import type { DefinedAt } from '../PageConfig.js';
4
- declare function getConfigDefinedAtString<ConfigName extends string, SentenceBegin extends 'Config' | 'config'>(sentenceBegin: SentenceBegin, configName: ConfigName, { definedAt }: {
5
- definedAt: DefinedAt;
6
- }): `${SentenceBegin} ${ConfigName}${string} defined ${'internally' | `at ${string}`}`;
7
- declare function getDefinedAtString(definedAt: DefinedAt, configName: string): string;
@@ -1,37 +0,0 @@
1
- export { getConfigDefinedAtString };
2
- export { getDefinedAtString };
3
- import { assert } from '../../utils.js';
4
- import pc from '@brillout/picocolors';
5
- import { getExportPath } from '../getExportPath.js';
6
- function getConfigDefinedAtString(sentenceBegin, configName, { definedAt }) {
7
- const definedAtString = getDefinedAtString(definedAt, configName);
8
- const definedAtStr = definedAtString === 'internally' ? definedAtString : `at ${definedAtString}`;
9
- let configNameStr = `${configName}${ /*sentenceBegin === 'Hook' ? '()' :*/''}`;
10
- const configDefinedAt = `${sentenceBegin} ${pc.cyan(configNameStr)} defined ${definedAtStr}`;
11
- return configDefinedAt;
12
- }
13
- function getDefinedAtString(definedAt, configName) {
14
- if ('isComputed' in definedAt) {
15
- return 'internally';
16
- }
17
- let files;
18
- if ('files' in definedAt) {
19
- files = definedAt.files;
20
- }
21
- else {
22
- files = [definedAt];
23
- }
24
- assert(files.length >= 1);
25
- const definedAtString = files
26
- .map((source) => {
27
- const { filePathToShowToUser, fileExportPathToShowToUser } = source;
28
- let s = filePathToShowToUser;
29
- const exportPath = getExportPath(fileExportPathToShowToUser, configName);
30
- if (exportPath) {
31
- s = `${s} > ${pc.cyan(exportPath)}`;
32
- }
33
- return s;
34
- })
35
- .join(' / ');
36
- return definedAtString;
37
- }
@@ -1,3 +0,0 @@
1
- export { assertPathIsFilesystemAbsolute };
2
- /** Assert path is absolute from the filesystem root */
3
- declare function assertPathIsFilesystemAbsolute(p: string): void;
@@ -1,15 +0,0 @@
1
- export { assertPathIsFilesystemAbsolute };
2
- import path from 'path';
3
- import { assert } from './assert.js';
4
- import { assertPosixPath } from './filesystemPathHandling.js';
5
- /** Assert path is absolute from the filesystem root */
6
- function assertPathIsFilesystemAbsolute(p) {
7
- assertPosixPath(p);
8
- assert(!p.startsWith('/@fs/'));
9
- if (process.platform !== 'win32') {
10
- assert(p.startsWith('/'));
11
- }
12
- else {
13
- assert(path.win32.isAbsolute(p));
14
- }
15
- }
@@ -1 +0,0 @@
1
- export declare function isStringRecord(thing: unknown): thing is Record<string, string>;
@@ -1,3 +0,0 @@
1
- export function isStringRecord(thing) {
2
- return typeof thing === 'object' && thing !== null && Object.values(thing).every((val) => typeof val === 'string');
3
- }