vike 0.4.166 → 0.4.167-commit-14e4b5e

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 (105) hide show
  1. package/dist/cjs/node/plugin/plugins/buildConfig.js +11 -6
  2. package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +2 -1
  3. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +17 -22
  4. package/dist/cjs/node/plugin/plugins/envVars.js +3 -2
  5. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +11 -13
  6. package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -4
  7. package/dist/cjs/node/plugin/plugins/fileEnv.js +6 -3
  8. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +6 -2
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +3 -3
  10. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -0
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +5 -1
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +21 -17
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +34 -23
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -3
  15. package/dist/cjs/node/plugin/shared/getFilePath.js +83 -29
  16. package/dist/cjs/node/plugin/shared/isErrorDebug.js +1 -1
  17. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +3 -8
  18. package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -1
  19. package/dist/cjs/node/plugin/utils.js +1 -1
  20. package/dist/cjs/node/prerender/runPrerender.js +6 -7
  21. package/dist/cjs/node/prerender/utils.js +2 -1
  22. package/dist/cjs/node/runtime/html/stream.js +5 -5
  23. package/dist/cjs/node/runtime/renderPage/analyzePage.js +1 -1
  24. package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +3 -3
  25. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -1
  26. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +5 -9
  27. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +9 -8
  28. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +6 -12
  29. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +13 -1
  30. package/dist/cjs/node/runtime/utils.js +0 -1
  31. package/dist/cjs/shared/page-configs/assertPlusFileExport.js +1 -3
  32. package/dist/cjs/shared/route/abort.js +2 -1
  33. package/dist/cjs/shared/route/executeGuardHook.js +2 -1
  34. package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +2 -1
  35. package/dist/cjs/shared/route/index.js +2 -3
  36. package/dist/cjs/shared/route/utils.js +0 -1
  37. package/dist/cjs/utils/assertIsNotProductionRuntime.js +5 -5
  38. package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +1 -0
  39. package/dist/cjs/utils/debug.js +48 -14
  40. package/dist/cjs/utils/isNpmPackage.js +11 -2
  41. package/dist/cjs/utils/projectInfo.js +1 -1
  42. package/dist/cjs/utils/trackLogs.js +1 -1
  43. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +31 -24
  44. package/dist/esm/node/plugin/plugins/buildConfig.js +12 -7
  45. package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +2 -1
  46. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -23
  47. package/dist/esm/node/plugin/plugins/envVars.js +4 -3
  48. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +12 -14
  49. package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +3 -5
  50. package/dist/esm/node/plugin/plugins/fileEnv.js +7 -4
  51. package/dist/esm/node/plugin/plugins/importUserCode/index.js +7 -3
  52. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/debug.d.ts +1 -1
  53. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +4 -4
  54. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -0
  55. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +5 -1
  56. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +21 -17
  57. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +2 -2
  58. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +33 -22
  59. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +8 -4
  60. package/dist/esm/node/plugin/shared/getFilePath.d.ts +10 -9
  61. package/dist/esm/node/plugin/shared/getFilePath.js +83 -29
  62. package/dist/esm/node/plugin/shared/isErrorDebug.js +2 -2
  63. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +4 -9
  64. package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -1
  65. package/dist/esm/node/plugin/utils.d.ts +1 -1
  66. package/dist/esm/node/plugin/utils.js +1 -1
  67. package/dist/esm/node/prerender/runPrerender.js +2 -3
  68. package/dist/esm/node/prerender/utils.d.ts +2 -1
  69. package/dist/esm/node/prerender/utils.js +2 -1
  70. package/dist/esm/node/runtime/html/stream.js +5 -5
  71. package/dist/esm/node/runtime/renderPage/analyzePage.js +1 -1
  72. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +1 -1
  73. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -1
  74. package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -10
  75. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +9 -8
  76. package/dist/esm/node/runtime/renderPage/getPageAssets.js +7 -13
  77. package/dist/esm/node/runtime/renderPage/logErrorHint.js +13 -1
  78. package/dist/esm/node/runtime/utils.d.ts +0 -1
  79. package/dist/esm/node/runtime/utils.js +0 -1
  80. package/dist/esm/shared/addUrlComputedProps.d.ts +2 -2
  81. package/dist/esm/shared/page-configs/FilePath.d.ts +41 -29
  82. package/dist/esm/shared/page-configs/assertPlusFileExport.js +1 -3
  83. package/dist/esm/shared/route/abort.js +2 -1
  84. package/dist/esm/shared/route/executeGuardHook.js +2 -1
  85. package/dist/esm/shared/route/executeOnBeforeRouteHook.js +2 -1
  86. package/dist/esm/shared/route/index.js +2 -3
  87. package/dist/esm/shared/route/utils.d.ts +0 -1
  88. package/dist/esm/shared/route/utils.js +0 -1
  89. package/dist/esm/utils/assertIsNotProductionRuntime.js +5 -5
  90. package/dist/esm/utils/assertPathIsFilesystemAbsolute.js +1 -0
  91. package/dist/esm/utils/debug.d.ts +5 -4
  92. package/dist/esm/utils/debug.js +45 -14
  93. package/dist/esm/utils/debugGlob.d.ts +1 -1
  94. package/dist/esm/utils/isNpmPackage.d.ts +5 -1
  95. package/dist/esm/utils/isNpmPackage.js +10 -1
  96. package/dist/esm/utils/projectInfo.d.ts +2 -2
  97. package/dist/esm/utils/projectInfo.js +1 -1
  98. package/dist/esm/utils/trackLogs.js +2 -2
  99. package/package.json +1 -1
  100. package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -19
  101. package/dist/cjs/utils/getFilePathAbsolute.js +0 -70
  102. package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.d.ts +0 -2
  103. package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -16
  104. package/dist/esm/utils/getFilePathAbsolute.d.ts +0 -5
  105. package/dist/esm/utils/getFilePathAbsolute.js +0 -64
@@ -379,7 +379,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
379
379
  const writeChunk = (chunk) => {
380
380
  assert(writableOriginal);
381
381
  writableOriginal.write(chunk);
382
- if (debug.isEnabled) {
382
+ if (debug.isActivated) {
383
383
  debug('data written (Node.js Writable)', String(chunk));
384
384
  }
385
385
  };
@@ -452,7 +452,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
452
452
  const writeChunk = (chunk) => {
453
453
  assert(writerOriginal);
454
454
  writerOriginal.write(encodeForWebStream(chunk));
455
- if (debug.isEnabled) {
455
+ if (debug.isActivated) {
456
456
  debug('data written (Web Writable)', String(chunk));
457
457
  }
458
458
  };
@@ -545,12 +545,12 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
545
545
  // If readableOriginal doesn't implement readableOriginal.cancel() then it may still emit data after we close the stream. We therefore need to check whether we closed `controllerProxy`.
546
546
  !controllerProxyIsClosed) {
547
547
  controllerProxy.enqueue(encodeForWebStream(chunk));
548
- if (debug.isEnabled) {
548
+ if (debug.isActivated) {
549
549
  debug('data written (Web Readable)', String(chunk));
550
550
  }
551
551
  }
552
552
  else {
553
- if (debug.isEnabled) {
553
+ if (debug.isActivated) {
554
554
  debug('data emitted but not written (Web Readable)', String(chunk));
555
555
  }
556
556
  }
@@ -572,7 +572,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
572
572
  }
573
573
  const writeChunk = (chunk) => {
574
574
  readableProxy.push(chunk);
575
- if (debug.isEnabled) {
575
+ if (debug.isActivated) {
576
576
  debug('data written (Node.js Readable)', String(chunk));
577
577
  }
578
578
  };
@@ -13,7 +13,7 @@ function analyzePage(pageFilesAll, pageConfig, pageId) {
13
13
  const clientDependencies = [];
14
14
  clientDependencies.push({
15
15
  id: getVirtualFileIdPageConfigValuesAll(pageConfig.pageId, true),
16
- onlyAssets: false,
16
+ onlyAssets: isClientSideRenderable ? false : true,
17
17
  eagerlyImported: false
18
18
  });
19
19
  // In production we inject the import of the server virtual module with ?extractAssets inside the client virtual module
@@ -1,8 +1,8 @@
1
1
  export { executeOnBeforeRenderAndDataHooks };
2
2
  import { getHook } from '../../../shared/hooks/getHook.js';
3
3
  import { preparePageContextForUserConsumptionServerSide } from './preparePageContextForUserConsumptionServerSide.js';
4
- import { executeHook } from '../utils.js';
5
4
  import { assertOnBeforeRenderHookReturn } from '../../../shared/assertOnBeforeRenderHookReturn.js';
5
+ import { executeHook } from '../../../shared/hooks/executeHook.js';
6
6
  async function executeOnBeforeRenderAndDataHooks(pageContext) {
7
7
  if (pageContext._pageContextAlreadyProvidedByOnPrerenderHook) {
8
8
  return;
@@ -1,13 +1,14 @@
1
1
  export { executeOnRenderHtmlHook };
2
2
  import { isDocumentHtml, renderDocumentHtml, dangerouslySkipEscape } from '../html/renderHtml.js';
3
3
  import { getHook } from '../../../shared/hooks/getHook.js';
4
- import { assert, assertUsage, assertWarning, isObject, objectAssign, isPromise, executeHook, isCallable } from '../utils.js';
4
+ import { assert, assertUsage, assertWarning, isObject, objectAssign, isPromise, isCallable } from '../utils.js';
5
5
  import { isStream } from '../html/stream.js';
6
6
  import { assertPageContextProvidedByUser } from '../../../shared/assertPageContextProvidedByUser.js';
7
7
  import { preparePageContextForUserConsumptionServerSide } from './preparePageContextForUserConsumptionServerSide.js';
8
8
  import { assertHookReturnedObject } from '../../../shared/assertHookReturnedObject.js';
9
9
  import { logRuntimeError } from './loggerRuntime.js';
10
10
  import pc from '@brillout/picocolors';
11
+ import { executeHook } from '../../../shared/hooks/executeHook.js';
11
12
  async function executeOnRenderHtmlHook(pageContext) {
12
13
  const { renderHook, hookFn } = getRenderHook(pageContext);
13
14
  objectAssign(pageContext, { _renderHook: renderHook });
@@ -1,10 +1,8 @@
1
1
  export { getManifestEntry };
2
- import { assert, slice, isNpmPackageImport } from '../../utils.js';
3
- import { assertClientEntryId } from './assertClientEntryId.js';
2
+ import { assert, slice, assertIsNpmPackageImport } from '../../utils.js';
4
3
  import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
5
4
  import { prependEntriesDir } from '../../../shared/prependEntriesDir.js';
6
5
  function getManifestEntry(id, assetsManifest) {
7
- assertClientEntryId(id);
8
6
  const debugInfo = getDebugInfo(id, assetsManifest);
9
7
  // Vike client entry
10
8
  if (id.startsWith('@@vike/')) {
@@ -42,12 +40,11 @@ function getManifestEntry(id, assetsManifest) {
42
40
  return { manifestEntry, manifestKey };
43
41
  }
44
42
  // npm package import
45
- if (isNpmPackageImport(id)) {
46
- const found = Object.entries(assetsManifest).find(([, e]) => e.name === prependEntriesDir(id));
47
- assert(found);
48
- const [manifestKey, manifestEntry] = found;
49
- return { manifestEntry, manifestKey };
50
- }
43
+ assertIsNpmPackageImport(id);
44
+ const found = Object.entries(assetsManifest).find(([, e]) => e.name === prependEntriesDir(id));
45
+ assert(found);
46
+ const [manifestKey, manifestEntry] = found;
47
+ return { manifestEntry, manifestKey };
51
48
  /* Can we remove this?
52
49
  // extensions[number].pageConfigsSrcDir
53
50
  if (id.startsWith('/node_modules/') || id.startsWith('/../')) {
@@ -79,7 +76,6 @@ function getManifestEntry(id, assetsManifest) {
79
76
  assert(false, debugInfo)
80
77
  }
81
78
  */
82
- assert(false, debugInfo);
83
79
  }
84
80
  function findEntryWithKeyEnd(manifestKeyEnd, assetsManifest, id) {
85
81
  const debugInfo = getDebugInfo(id, assetsManifest, manifestKeyEnd);
@@ -9,15 +9,16 @@ function retrieveAssetsProd(clientDependencies, assetsManifest, includeAssetsImp
9
9
  clientDependencies.forEach(({ id, onlyAssets, eagerlyImported }) => {
10
10
  if (eagerlyImported)
11
11
  return; // Eagerly imported assets aren't imported with import() and therefore don't create a new Rollup entry and aren't listed in the manifest file
12
- if (onlyAssets) {
13
- if (!includeAssetsImportedByServer)
14
- return;
12
+ // TODO/v1-release: remove
13
+ if (includeAssetsImportedByServer &&
14
+ onlyAssets &&
15
+ id.includes('.page.server.') &&
15
16
  // We assume that all npm packages have already built their files: bundlers (Rollup, esbuild, tsup, ...) extract the CSS out of JavaScript => we can assume JavaScript to not import any CSS/assets.
16
- if (isNpmPackageImport(id))
17
- return;
18
- if (id.includes('.page.server.')) {
19
- id = extractAssetsAddQuery(id);
20
- }
17
+ !isNpmPackageImport(id, {
18
+ // I presume Vite already resolves path aliases when Vite sets the module's id
19
+ cannotBePathAlias: true
20
+ })) {
21
+ id = extractAssetsAddQuery(id);
21
22
  }
22
23
  const { manifestKey } = getManifestEntry(id, assetsManifest);
23
24
  collectAssets(manifestKey, assetUrls, visistedAssets, assetsManifest, onlyAssets);
@@ -1,12 +1,11 @@
1
1
  export { getPageAssets };
2
- import { assert, prependBase, assertPosixPath, toPosixPath, isNpmPackageImport, unique, pathJoin } from '../utils.js';
2
+ import { assert, prependBase, assertPosixPath, toPosixPath, unique, pathJoin, assertIsNpmPackageImport } from '../utils.js';
3
3
  import { retrieveAssetsDev } from './getPageAssets/retrieveAssetsDev.js';
4
4
  import { retrieveAssetsProd } from './getPageAssets/retrieveAssetsProd.js';
5
5
  import { inferMediaType } from './inferMediaType.js';
6
6
  import { getManifestEntry } from './getPageAssets/getManifestEntry.js';
7
7
  import { sortPageAssetsForEarlyHintsHeader } from './getPageAssets/sortPageAssetsForEarlyHintsHeader.js';
8
8
  import { getGlobalContext } from '../globalContext.js';
9
- import { assertClientEntryId } from './getPageAssets/assertClientEntryId.js';
10
9
  import { import_ } from '@brillout/import';
11
10
  async function getPageAssets(pageContext, clientDependencies, clientEntries) {
12
11
  const globalContext = getGlobalContext();
@@ -56,7 +55,6 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
56
55
  return pageAssets;
57
56
  }
58
57
  async function resolveClientEntriesDev(clientEntry, viteDevServer) {
59
- assertClientEntryId(clientEntry);
60
58
  let root = viteDevServer.config.root;
61
59
  assert(root);
62
60
  root = toPosixPath(root);
@@ -73,11 +71,9 @@ async function resolveClientEntriesDev(clientEntry, viteDevServer) {
73
71
  assertPosixPath(clientEntry);
74
72
  let filePath;
75
73
  if (clientEntry.startsWith('/')) {
76
- // User files
77
74
  filePath = pathJoin(root, clientEntry);
78
75
  }
79
- else if (clientEntry.startsWith('@@vike/') || isNpmPackageImport(clientEntry)) {
80
- // Vike client entry
76
+ else {
81
77
  const { createRequire } = (await import_('module')).default;
82
78
  const { dirname } = (await import_('path')).default;
83
79
  const { fileURLToPath } = (await import_('url')).default;
@@ -88,10 +84,7 @@ async function resolveClientEntriesDev(clientEntry, viteDevServer) {
88
84
  // @ts-expect-error
89
85
  // Bun workaround https://github.com/vikejs/vike/pull/1048
90
86
  const res = typeof Bun !== 'undefined' ? (toPath) => Bun.resolveSync(toPath, __dirname_) : require_.resolve;
91
- if (isNpmPackageImport(clientEntry)) {
92
- filePath = res(clientEntry);
93
- }
94
- else {
87
+ if (clientEntry.startsWith('@@vike/')) {
95
88
  assert(clientEntry.endsWith('.js'));
96
89
  try {
97
90
  // For Vitest (which doesn't resolve vike to its dist but to its source files)
@@ -104,9 +97,10 @@ async function resolveClientEntriesDev(clientEntry, viteDevServer) {
104
97
  filePath = toPosixPath(res(clientEntry.replace('@@vike/dist/esm/client/', '../../../../../dist/esm/client/')));
105
98
  }
106
99
  }
107
- }
108
- else {
109
- assert(false);
100
+ else {
101
+ assertIsNpmPackageImport(clientEntry);
102
+ filePath = res(clientEntry);
103
+ }
110
104
  }
111
105
  if (!filePath.startsWith('/')) {
112
106
  assert(process.platform === 'win32');
@@ -20,6 +20,10 @@ const knownErrors = [
20
20
  // ```
21
21
  errMsg: 'assets.json',
22
22
  link: 'https://vike.dev/getGlobalContext'
23
+ },
24
+ {
25
+ errMsg: /Named export.*not found/i,
26
+ link: 'https://vike.dev/broken-npm-package#named-export-not-found'
23
27
  }
24
28
  ];
25
29
  function logErrorHint(error) {
@@ -285,7 +289,15 @@ function extractFromNodeModulesPath(str) {
285
289
  return packageName;
286
290
  }
287
291
  function includes(str1, str2) {
288
- return !!str1 && str1.toLowerCase().includes(str2.toLowerCase());
292
+ if (!str1)
293
+ return false;
294
+ if (str2 instanceof RegExp) {
295
+ return str2.test(str1.toLowerCase());
296
+ }
297
+ if (typeof str2 === 'string') {
298
+ return str1.toLowerCase().includes(str2.toLowerCase());
299
+ }
300
+ return false;
289
301
  }
290
302
  function includesNodeModules(str) {
291
303
  if (!str)
@@ -29,7 +29,6 @@ export * from '../../utils/isPropertyGetter.js';
29
29
  export * from '../../utils/debug.js';
30
30
  export * from '../../utils/urlToFile.js';
31
31
  export * from '../../utils/getGlobalObject.js';
32
- export * from '../../shared/hooks/executeHook.js';
33
32
  export * from '../../utils/freezePartial.js';
34
33
  export * from '../../utils/isNpmPackage.js';
35
34
  export * from '../../utils/isNotNullish.js';
@@ -32,7 +32,6 @@ export * from '../../utils/isPropertyGetter.js';
32
32
  export * from '../../utils/debug.js';
33
33
  export * from '../../utils/urlToFile.js';
34
34
  export * from '../../utils/getGlobalObject.js';
35
- export * from '../../shared/hooks/executeHook.js';
36
35
  export * from '../../utils/freezePartial.js';
37
36
  export * from '../../utils/isNpmPackage.js';
38
37
  export * from '../../utils/isNotNullish.js';
@@ -18,14 +18,14 @@ type Url = {
18
18
  searchAll: Record<string, string[]>;
19
19
  /** The URL search parameterer string, e.g. `?details=yes` of `https://example.com/product/42?details=yes#reviews` */
20
20
  searchOriginal: null | string;
21
- /** @deprecated */
22
- searchString: null | string;
23
21
  /** The URL hash, e.g. `reviews` of `https://example.com/product/42?details=yes#reviews` */
24
22
  hash: string;
25
23
  /** The URL hash string, e.g. `#reviews` of `https://example.com/product/42?details=yes#reviews` */
26
24
  hashOriginal: null | string;
27
25
  /** @deprecated */
28
26
  hashString: null | string;
27
+ /** @deprecated */
28
+ searchString: null | string;
29
29
  };
30
30
  type PageContextUrlComputedPropsClient = {
31
31
  /** @deprecated */
@@ -2,51 +2,63 @@ export type { FilePath };
2
2
  export type { FilePathResolved };
3
3
  type FilePathResolved = FilePath & {
4
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
+ */
5
12
  filePathToShowToUserResolved: string;
6
13
  };
7
- type FilePath = {
8
- /** The file's path, non-relative from Vite's perspective.
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.
9
23
  *
10
- * Its value is equivalent to `filePath.filePathAbsoluteUserRootDir ?? filePath.importPathAbsolute`, for example:
11
- * - `vike-react/config`, or
12
- * - `/pages/+config.js`.
24
+ * Example: `/home/rom/code/my-app/pages/some-page/+Page.js`
13
25
  *
14
- * We use it to generate import paths in virtual modules. (Since virtual modules cannot have relative import paths.)
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.)
15
27
  */
16
- filePathAbsoluteVite: string;
17
- /** The file's path, absolute starting from the filesystem root.
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`.
18
33
  *
19
- * Example: `/home/rom/code/my-app/pages/some-page/Page.js`
34
+ * Its value is `null` if the file is outside of the user root directory (i.e. Vite's `config.root`).
20
35
  *
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
36
  */
23
- filePathAbsoluteFilesystem: string | null;
24
- /** The file's path, shown to user upon logging.
37
+ filePathAbsoluteUserRootDir: string | null;
38
+ /**
39
+ * The file's path, shown to the user in logs.
25
40
  *
26
- * Unresolved: it may show an import path of a package e.g. `vike-react/config`.
41
+ * Unresolved: it may show an import path instead of a file path such as `vike-react/config`.
27
42
  *
28
- * Currently, its value is equivalent to `FilePath['filePathAbsoluteVite']`.
43
+ * Its value is equivalent to `filePath.filePathAbsoluteUserRootDir ?? filePath.importPathAbsolute`.
29
44
  */
30
45
  filePathToShowToUser: string;
31
- /** The file's path, shown to user upon logging.
46
+ /**
47
+ * The file's non-relative path, from Vite's perspective.
32
48
  *
33
- * Resolved: it always shows an absolute file path.
49
+ * Examples:
50
+ * - `/pages/+config.js`
51
+ * - `vike-react/config`
34
52
  *
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`).
53
+ * We use it to generate import paths in virtual modules. (Since import paths in virtual modules cannot be relative.)
39
54
  *
40
- * Example: `/pages/some-page/Page.js`
55
+ * Its value is equivalent to `filePath.filePathAbsoluteUserRootDir ?? filePath.importPathAbsolute`.
41
56
  */
42
- filePathAbsoluteUserRootDir: string | null;
43
- /** The file's path, as absolute import path. It's either:
57
+ filePathAbsoluteVite: string;
58
+ /**
59
+ * The file's non-relative import path. It's either:
44
60
  * - an npm package import (e.g. `vike-react/config`), or
45
- * - an alias (`#components/Counter').
61
+ * - a path alias import (e.g. `#components/Counter').
46
62
  */
47
63
  importPathAbsolute: string | null;
48
- } & ({
49
- importPathAbsolute: string;
50
- } | {
51
- filePathAbsoluteUserRootDir: string;
52
- });
64
+ };
@@ -23,9 +23,7 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
23
23
  }
24
24
  else {
25
25
  assert(exportsAll.length === 2); // because `exportsInvalid.length === 0`
26
- assertWarning(false, `${filePathToShowToUser} remove ${exportNamed} or ${exportDefault}`, {
27
- onlyOnce: true
28
- });
26
+ assertWarning(false, `The exports of ${filePathToShowToUser} are ambiguous: remove ${exportDefault} or ${exportNamed}`, { onlyOnce: true });
29
27
  }
30
28
  }
31
29
  else {
@@ -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';
@@ -16,31 +16,31 @@ const vikeVitePluginLoadedInProductionError = `Loading Vike's Vite plugin (the v
16
16
  const env = getGlobalObject('utils/assertIsNotProductionRuntime.ts', {});
17
17
  // Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
18
18
  function assertIsNotProductionRuntime() {
19
- if (debug.isEnabled)
19
+ if (debug.isActivated)
20
20
  debug('assertIsNotProductionRuntime()', new Error().stack);
21
21
  env.shouldNotBeProduction = true;
22
22
  }
23
23
  // Called by Vite hook configureServer()
24
24
  function markEnvAsViteDev() {
25
- if (debug.isEnabled)
25
+ if (debug.isActivated)
26
26
  debug('markEnvAsViteDev()', new Error().stack);
27
27
  env.isViteDev = true;
28
28
  }
29
29
  // Called by Vite hook configurePreviewServer()
30
30
  function markEnvAsVitePreview() {
31
- if (debug.isEnabled)
31
+ if (debug.isActivated)
32
32
  debug('markEnvAsVitePreview()', new Error().stack);
33
33
  env.isVitePreview = true;
34
34
  }
35
35
  // Called by ../node/plugin/index.ts
36
36
  function markEnvAsVikePluginLoaded() {
37
- if (debug.isEnabled)
37
+ if (debug.isActivated)
38
38
  debug('markEnvAsVikePluginLoaded()', new Error().stack);
39
39
  env.isVikePluginLoaded = true;
40
40
  }
41
41
  // Called by ../node/runtime/index.ts
42
42
  function assertEnv() {
43
- if (debug.isEnabled)
43
+ if (debug.isActivated)
44
44
  debug('assertEnv()', new Error().stack);
45
45
  if (isVitest())
46
46
  return;
@@ -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,7 +1,8 @@
1
1
  export { createDebugger };
2
- export { isDebugEnabled };
2
+ export { isDebugActivated };
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
+ declare const flags: readonly ["vike:error", "vike:extractAssets", "vike:extractExportNames", "vike:glob", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:routing", "vike:setup", "vike:stream", "vike:virtual-files"];
5
+ type Flag = (typeof flags)[number];
5
6
  type Debug = ReturnType<typeof createDebugger>;
6
7
  type Options = {
7
8
  serialization?: {
@@ -10,6 +11,6 @@ type Options = {
10
11
  };
11
12
  declare function createDebugger(flag: Flag, optionsGlobal?: Options): ((...msgs: unknown[]) => void) & {
12
13
  options: (optionsLocal: Options) => (...msgs: unknown[]) => void;
13
- isEnabled: boolean;
14
+ isActivated: boolean;
14
15
  };
15
- declare function isDebugEnabled(flag: Flag): boolean;
16
+ declare function isDebugActivated(flag: Flag): boolean;
@@ -1,16 +1,35 @@
1
1
  export { createDebugger };
2
- export { isDebugEnabled };
2
+ export { isDebugActivated };
3
3
  import { isBrowser } from './isBrowser.js';
4
4
  import { isCallable } from './isCallable.js';
5
5
  import { objectAssign } from './objectAssign.js';
6
- import { assert } from './assert.js';
6
+ import { assert, assertUsage } from './assert.js';
7
7
  import { checkType } from './checkType.js';
8
8
  import { getTerminalWidth } from './getTerminWidth.js';
9
+ import pc from '@brillout/picocolors';
9
10
  // Avoid this to be loaded in the browser. For isomorphic code: instead of `import { createDebugger } from './utils.js'`, use `globalThis.createDebugger()`.
10
11
  assert(!isBrowser());
11
12
  globalThis.__brillout_debug_createDebugger = createDebugger;
13
+ const flags = [
14
+ 'vike:error',
15
+ 'vike:extractAssets',
16
+ 'vike:extractExportNames',
17
+ 'vike:glob',
18
+ 'vike:log',
19
+ 'vike:optimizeDeps',
20
+ 'vike:outDir',
21
+ 'vike:pageFiles',
22
+ 'vike:pointer-imports',
23
+ 'vike:routing',
24
+ 'vike:setup',
25
+ 'vike:stream',
26
+ 'vike:virtual-files'
27
+ ];
28
+ const flagRegex = /\bvike:[a-zA-Z-]+/g;
29
+ assertDEBUG();
12
30
  function createDebugger(flag, optionsGlobal) {
13
31
  checkType(flag);
32
+ assert(flags.includes(flag));
14
33
  const debugWithOptions = (optionsLocal) => {
15
34
  return (...msgs) => {
16
35
  const options = { ...optionsGlobal, ...optionsLocal };
@@ -18,11 +37,11 @@ function createDebugger(flag, optionsGlobal) {
18
37
  };
19
38
  };
20
39
  const debug = (...msgs) => debugWithOptions({})(...msgs);
21
- objectAssign(debug, { options: debugWithOptions, isEnabled: isDebugEnabled(flag) });
40
+ objectAssign(debug, { options: debugWithOptions, isActivated: isDebugActivated(flag) });
22
41
  return debug;
23
42
  }
24
43
  function debug_(flag, options, ...msgs) {
25
- if (!isDebugEnabled(flag))
44
+ if (!isDebugActivated(flag))
26
45
  return;
27
46
  let [msgFirst, ...msgsRest] = msgs;
28
47
  const padding = ' '.repeat(flag.length + 1);
@@ -47,17 +66,12 @@ function debug_(flag, options, ...msgs) {
47
66
  console.log(msg);
48
67
  });
49
68
  }
50
- function isDebugEnabled(flag) {
69
+ function isDebugActivated(flag) {
51
70
  checkType(flag);
52
- let DEBUG;
53
- // - `process` can be undefined in edge workers
54
- // - We want bundlers to be able to statically replace `process.env.*`
55
- try {
56
- DEBUG = process.env.DEBUG;
57
- }
58
- catch { }
59
- const isEnabled = DEBUG?.includes(flag) ?? false;
60
- return isEnabled;
71
+ assert(flags.includes(flag));
72
+ const DEBUG = getDEBUG();
73
+ const isActivated = DEBUG?.includes(flag) ?? false;
74
+ return isActivated;
61
75
  }
62
76
  function formatMsg(info, options, padding, position) {
63
77
  if (info === undefined) {
@@ -119,3 +133,20 @@ function replaceFunctionSerializer(_key, value) {
119
133
  }
120
134
  return value;
121
135
  }
136
+ function assertDEBUG() {
137
+ const DEBUG = getDEBUG() ?? '';
138
+ const flagsActivated = DEBUG.match(flagRegex) ?? [];
139
+ flagsActivated.forEach((flag) => {
140
+ assertUsage(flags.includes(flag), `Unknown DEBUG flag ${pc.cyan(flag)}. Valid flags:\n${flags.map((f) => ` ${pc.cyan(f)}`).join('\n')}`);
141
+ });
142
+ }
143
+ function getDEBUG() {
144
+ let DEBUG;
145
+ // - `process` can be undefined in edge workers
146
+ // - We want bundlers to be able to statically replace `process.env.*`
147
+ try {
148
+ DEBUG = process.env.DEBUG;
149
+ }
150
+ catch { }
151
+ return DEBUG;
152
+ }
@@ -4,5 +4,5 @@ export declare const debugGlob: ((...msgs: unknown[]) => void) & {
4
4
  emptyArray?: string | undefined;
5
5
  } | undefined;
6
6
  }) => (...msgs: unknown[]) => void;
7
- isEnabled: boolean;
7
+ isActivated: boolean;
8
8
  };
@@ -1,8 +1,12 @@
1
1
  export { isNpmPackageImport };
2
+ export { assertIsNpmPackageImport };
2
3
  export { isValidPathAlias };
3
4
  export { parse };
4
5
  export { isDistinguishable };
5
- declare function isNpmPackageImport(str: string): boolean;
6
+ declare function isNpmPackageImport(str: string, { cannotBePathAlias }: {
7
+ cannotBePathAlias: true;
8
+ }): boolean;
9
+ declare function assertIsNpmPackageImport(str: string): void;
6
10
  declare function isValidPathAlias(alias: string): boolean;
7
11
  declare function isDistinguishable(alias: string): boolean;
8
12
  declare function parse(str: string | undefined): null | {