vike 0.4.165-commit-b3cc3cb → 0.4.165-commit-8eba585

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 (79) hide show
  1. package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
  2. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
  3. package/dist/cjs/node/plugin/plugins/buildConfig.js +1 -1
  4. package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +12 -0
  5. package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
  6. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
  7. package/dist/cjs/node/plugin/plugins/envVars.js +1 -1
  8. package/dist/cjs/node/plugin/plugins/fileEnv.js +2 -2
  9. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
  10. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +53 -24
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getFilePath.js +90 -0
  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/loggerNotProd/errorWithCodeSnippet.js +1 -1
  19. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
  20. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +26 -24
  21. package/dist/cjs/node/runtime/renderPage.js +34 -21
  22. package/dist/cjs/shared/page-configs/FilePath.js +2 -0
  23. package/dist/cjs/utils/assert.js +2 -0
  24. package/dist/cjs/utils/assertSingleInstance.js +6 -5
  25. package/dist/cjs/utils/assertVersion.js +4 -1
  26. package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
  27. package/dist/cjs/utils/getGlobalObject.js +21 -6
  28. package/dist/cjs/utils/isNpmPackage.js +1 -4
  29. package/dist/cjs/utils/parseUrl.js +1 -1
  30. package/dist/cjs/utils/projectInfo.js +1 -4
  31. package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
  32. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
  33. package/dist/esm/node/plugin/plugins/buildConfig.js +2 -2
  34. package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +12 -0
  35. package/dist/esm/node/plugin/plugins/config/index.js +1 -1
  36. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -3
  37. package/dist/esm/node/plugin/plugins/envVars.js +2 -2
  38. package/dist/esm/node/plugin/plugins/fileEnv.js +3 -3
  39. package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
  40. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +1 -1
  41. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
  42. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  43. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +54 -25
  44. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
  45. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
  46. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getFilePath.d.ts +20 -0
  47. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getFilePath.js +84 -0
  48. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +1 -1
  49. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +6 -25
  50. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +2 -1
  51. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +15 -22
  52. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
  53. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -20
  54. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
  55. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -20
  56. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
  57. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
  58. package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +26 -24
  59. package/dist/esm/node/runtime/renderPage.js +34 -21
  60. package/dist/esm/shared/page-configs/FilePath.d.ts +52 -0
  61. package/dist/esm/shared/page-configs/FilePath.js +1 -0
  62. package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -42
  63. package/dist/esm/utils/assert.js +2 -0
  64. package/dist/esm/utils/assertSingleInstance.d.ts +2 -2
  65. package/dist/esm/utils/assertSingleInstance.js +5 -4
  66. package/dist/esm/utils/assertVersion.js +4 -1
  67. package/dist/esm/utils/getFilePathAbsolute.d.ts +4 -4
  68. package/dist/esm/utils/getFilePathAbsolute.js +10 -10
  69. package/dist/esm/utils/getGlobalObject.d.ts +6 -1
  70. package/dist/esm/utils/getGlobalObject.js +22 -6
  71. package/dist/esm/utils/isNpmPackage.d.ts +0 -6
  72. package/dist/esm/utils/isNpmPackage.js +5 -3
  73. package/dist/esm/utils/parseUrl.js +1 -1
  74. package/dist/esm/utils/projectInfo.d.ts +2 -2
  75. package/dist/esm/utils/projectInfo.js +1 -4
  76. package/package.json +2 -2
  77. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -33
  78. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +0 -5
  79. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -27
@@ -19,7 +19,7 @@ import { crawlPlusFiles } from './getVikeConfig/crawlPlusFiles.js';
19
19
  import { getConfigFileExport } from './getConfigFileExport.js';
20
20
  import { loadConfigFile, loadImportedFile, loadValueFile } from './getVikeConfig/loadFileAtConfigTime.js';
21
21
  import { clearFilesEnvMap, resolveImport } from './getVikeConfig/resolveImportPath.js';
22
- import { resolveFilePathRelativeToUserRootDir } from './getVikeConfig/resolveFilePath.js';
22
+ import { getFilePathResolved } from './getVikeConfig/getFilePath.js';
23
23
  assertIsNotProductionRuntime();
24
24
  let devServerIsCorrupt = false;
25
25
  let wasConfigInvalid = null;
@@ -62,7 +62,7 @@ async function handleReloadSideEffects() {
62
62
  }
63
63
  }
64
64
  }
65
- async function getVikeConfig(config, isDev, tolerateInvalidConfig = false) {
65
+ async function getVikeConfig(config, isDev, tolerateInvalidConfig) {
66
66
  const { outDirRoot } = getOutDirs(config);
67
67
  const userRootDir = config.root;
68
68
  if (!vikeConfigPromise) {
@@ -92,11 +92,11 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
92
92
  await Promise.all([
93
93
  // Config files
94
94
  ...configFiles.map(async (filePath) => {
95
- const { filePathRelativeToUserRootDir } = filePath;
96
- assert(filePathRelativeToUserRootDir);
95
+ const { filePathAbsoluteUserRootDir } = filePath;
96
+ assert(filePathAbsoluteUserRootDir);
97
97
  const { configFile, extendsConfigs } = await loadConfigFile(filePath, userRootDir, [], false);
98
- assert(filePath.filePathRelativeToUserRootDir);
99
- const locationId = getLocationId(filePathRelativeToUserRootDir);
98
+ assert(filePath.filePathAbsoluteUserRootDir);
99
+ const locationId = getLocationId(filePathAbsoluteUserRootDir);
100
100
  const interfaceFile = getInterfaceFileFromConfigFile(configFile, false, locationId);
101
101
  interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
102
102
  interfaceFilesByLocationId[locationId].push(interfaceFile);
@@ -145,11 +145,11 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
145
145
  }),
146
146
  // Value files
147
147
  ...valueFiles.map(async (filePath) => {
148
- const { filePathRelativeToUserRootDir } = filePath;
149
- assert(filePathRelativeToUserRootDir);
150
- const configName = getConfigName(filePathRelativeToUserRootDir);
148
+ const { filePathAbsoluteUserRootDir } = filePath;
149
+ assert(filePathAbsoluteUserRootDir);
150
+ const configName = getConfigName(filePathAbsoluteUserRootDir);
151
151
  assert(configName);
152
- const locationId = getLocationId(filePathRelativeToUserRootDir);
152
+ const locationId = getLocationId(filePathAbsoluteUserRootDir);
153
153
  const interfaceFile = {
154
154
  locationId,
155
155
  filePath,
@@ -348,9 +348,9 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
348
348
  const interfaceFilesGlobalPaths = [];
349
349
  objectEntries(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
350
350
  assert(isGlobalLocation(locationId, locationIds));
351
- interfaceFiles.forEach(({ filePath: { filePathRelativeToUserRootDir } }) => {
352
- if (filePathRelativeToUserRootDir) {
353
- interfaceFilesGlobalPaths.push(filePathRelativeToUserRootDir);
351
+ interfaceFiles.forEach(({ filePath: { filePathAbsoluteUserRootDir } }) => {
352
+ if (filePathAbsoluteUserRootDir) {
353
+ interfaceFilesGlobalPaths.push(filePathAbsoluteUserRootDir);
354
354
  }
355
355
  });
356
356
  });
@@ -459,10 +459,10 @@ async function resolveConfigValueSources(configName, configDef, interfaceFilesRe
459
459
  }
460
460
  function makeOrderDeterministic(interfaceFile1, interfaceFile2) {
461
461
  return lowerFirst((interfaceFile) => {
462
- const { filePathRelativeToUserRootDir } = interfaceFile.filePath;
462
+ const { filePathAbsoluteUserRootDir } = interfaceFile.filePath;
463
463
  assert(isInterfaceFileUserLand(interfaceFile));
464
- assert(filePathRelativeToUserRootDir);
465
- return filePathRelativeToUserRootDir.length;
464
+ assert(filePathAbsoluteUserRootDir);
465
+ return filePathAbsoluteUserRootDir.length;
466
466
  })(interfaceFile1, interfaceFile2);
467
467
  }
468
468
  function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName) {
@@ -536,6 +536,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
536
536
  configName !== 'extends') {
537
537
  if (import_.filePathAbsoluteFilesystem) {
538
538
  assert(hasProp(import_, 'filePathAbsoluteFilesystem', 'string')); // Help TS
539
+ assert(hasProp(import_, 'filePathToShowToUserResolved', 'string')); // Help TS
539
540
  const fileExport = await loadImportedFile(import_, userRootDir, importedFilesLoaded);
540
541
  configValueSource.value = fileExport;
541
542
  }
@@ -739,7 +740,7 @@ function getComputed(configValueSources, configDefinitions) {
739
740
  }
740
741
  async function findPlusFiles(userRootDir, outDirRoot, isDev) {
741
742
  const files = await crawlPlusFiles(userRootDir, outDirRoot, isDev);
742
- const plusFiles = files.map(({ filePathRelativeToUserRootDir }) => resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir, userRootDir));
743
+ const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir, importPathAbsolute: null }));
743
744
  return plusFiles;
744
745
  }
745
746
  function getConfigName(filePath) {
@@ -829,9 +830,9 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
829
830
  const configDefinedAt = getConfigDefinedAtString('Config', configName, configFilesystemRoutingRoot);
830
831
  assertUsage(typeof value === 'string', `${configDefinedAt} should be a string`);
831
832
  assertUsage(value.startsWith('/'), `${configDefinedAt} is ${pc.cyan(value)} but it should start with a leading slash ${pc.cyan('/')}`);
832
- const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.definedAt;
833
- assert(filePathRelativeToUserRootDir);
834
- const before = getFilesystemRouteString(getLocationId(filePathRelativeToUserRootDir));
833
+ const { filePathAbsoluteUserRootDir } = configFilesystemRoutingRoot.definedAt;
834
+ assert(filePathAbsoluteUserRootDir);
835
+ const before = getFilesystemRouteString(getLocationId(filePathAbsoluteUserRootDir));
835
836
  const after = value;
836
837
  const filesystemRoutingRootEffect = { before, after };
837
838
  return { filesystemRoutingRootEffect, filesystemRoutingRootDefinedAt: configDefinedAt };
@@ -7,7 +7,7 @@ export { isEquivalentErrorWithCodeSnippet };
7
7
  export { getPrettyErrMessage };
8
8
  // Copied & adapted from https://github.com/vitejs/vite/blob/9c114c5c72a6af87e3330d5573362554b4511265/packages/vite/src/node/server/middlewares/error.ts
9
9
  import pc from '@brillout/picocolors';
10
- import { assert, escapeRegex, getFilePathRelativeToUserRootDir, isObject, removeEmptyLines, stripAnsi, toPosixPath } from '../../utils.js';
10
+ import { assert, escapeRegex, getFilePathAbsoluteUserRootDir, isObject, removeEmptyLines, stripAnsi, toPosixPath } from '../../utils.js';
11
11
  function isErrorWithCodeSnippet(err) {
12
12
  if (!isObject(err)) {
13
13
  return false;
@@ -46,7 +46,7 @@ function getPrettyErrorWithCodeSnippet(err, userRootDir) {
46
46
  let { id, frame } = err;
47
47
  const msgFirstLine = [
48
48
  pc.red('Failed to transpile'),
49
- pc.bold(pc.red(getFilePathRelativeToUserRootDir(normalizeId(id), userRootDir))),
49
+ pc.bold(pc.red(getFilePathAbsoluteUserRootDir(normalizeId(id), userRootDir))),
50
50
  pc.red('because:')
51
51
  ].join(' ');
52
52
  const errMsg = getPrettyErrMessage(err);
@@ -138,6 +138,7 @@ async function mergeScriptEntries(pageAssets, isProduction) {
138
138
  function getPageContextJsonScriptTag(pageContext) {
139
139
  const pageContextSerialized = sanitizeJson(serializePageContextClientSide(pageContext));
140
140
  const htmlTag = `<script id="vike_pageContext" type="application/json">${pageContextSerialized}</script>`;
141
+ // Used by contra.com https://github.com/gajus
141
142
  // @ts-expect-error
142
143
  pageContext._pageContextHtmlTag = htmlTag;
143
144
  return htmlTag;
@@ -48,35 +48,37 @@ function getManifestEntry(id, assetsManifest) {
48
48
  const [manifestKey, manifestEntry] = found;
49
49
  return { manifestEntry, manifestKey };
50
50
  }
51
+ /* Can we remove this?
51
52
  // extensions[number].pageConfigsSrcDir
52
53
  if (id.startsWith('/node_modules/') || id.startsWith('/../')) {
53
- let manifestKeyEnd = id.split('/node_modules/').slice(-1)[0];
54
- assert(manifestKeyEnd, debugInfo);
55
- assert(!manifestKeyEnd.startsWith('/'), debugInfo);
56
- manifestKeyEnd = '/' + manifestKeyEnd;
57
- {
58
- const { manifestEntry, manifestKey } = findEntryWithKeyEnd(manifestKeyEnd, assetsManifest, id);
59
- if (manifestEntry) {
60
- assert(manifestKey, debugInfo);
61
- return { manifestEntry, manifestKey };
62
- }
63
- }
64
- {
65
- assert(manifestKeyEnd.startsWith('/'), debugInfo);
66
- const dirS = manifestKeyEnd.split('/');
67
- assert(dirS[0] === '', debugInfo);
68
- manifestKeyEnd = '/' + dirS.slice(2).join('/');
69
- assert(manifestKeyEnd.startsWith('/'), debugInfo);
54
+ let manifestKeyEnd = id.split('/node_modules/').slice(-1)[0]
55
+ assert(manifestKeyEnd, debugInfo)
56
+ assert(!manifestKeyEnd.startsWith('/'), debugInfo)
57
+ manifestKeyEnd = '/' + manifestKeyEnd
58
+ {
59
+ const { manifestEntry, manifestKey } = findEntryWithKeyEnd(manifestKeyEnd, assetsManifest, id)
60
+ if (manifestEntry) {
61
+ assert(manifestKey, debugInfo)
62
+ return { manifestEntry, manifestKey }
70
63
  }
71
- {
72
- const { manifestEntry, manifestKey } = findEntryWithKeyEnd(manifestKeyEnd, assetsManifest, id);
73
- if (manifestEntry) {
74
- assert(manifestKey, debugInfo);
75
- return { manifestEntry, manifestKey };
76
- }
64
+ }
65
+ {
66
+ assert(manifestKeyEnd.startsWith('/'), debugInfo)
67
+ const dirS = manifestKeyEnd.split('/')
68
+ assert(dirS[0] === '', debugInfo)
69
+ manifestKeyEnd = '/' + dirS.slice(2).join('/')
70
+ assert(manifestKeyEnd.startsWith('/'), debugInfo)
71
+ }
72
+ {
73
+ const { manifestEntry, manifestKey } = findEntryWithKeyEnd(manifestKeyEnd, assetsManifest, id)
74
+ if (manifestEntry) {
75
+ assert(manifestKey, debugInfo)
76
+ return { manifestEntry, manifestKey }
77
77
  }
78
- assert(false, debugInfo);
78
+ }
79
+ assert(false, debugInfo)
79
80
  }
81
+ */
80
82
  assert(false, debugInfo);
81
83
  }
82
84
  function findEntryWithKeyEnd(manifestKeyEnd, assetsManifest, id) {
@@ -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 = {};
@@ -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,7 @@ 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 = ['http://', 'https://', 'tauri://', 'file://'];
16
16
  function isParsable(url) {
17
17
  // `parseUrl()` works with these URLs
18
18
  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-commit-b3cc3cb";
3
+ declare const PROJECT_VERSION: "0.4.165-commit-8eba585";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.165-commit-b3cc3cb";
6
+ projectVersion: "0.4.165-commit-8eba585";
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-commit-b3cc3cb';
3
+ const PROJECT_VERSION = '0.4.165-commit-8eba585';
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-commit-b3cc3cb",
3
+ "version": "0.4.165-commit-8eba585",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
@@ -188,7 +188,7 @@
188
188
  "@types/node": "^20.10.5",
189
189
  "@types/resolve": "^1.20.6",
190
190
  "@types/source-map-support": "^0.5.10",
191
- "react-streaming": "^0.3.22",
191
+ "react-streaming": "^0.3.24",
192
192
  "rimraf": "^5.0.5",
193
193
  "typescript": "^5.3.3",
194
194
  "vite": "npm:@brillout/vite@5.1.0-commit-3dc7abd"