vike 0.4.165-commit-8eba585 → 0.4.166-commit-6a8acaa

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 (84) 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/fileEnv.js +6 -3
  6. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +6 -2
  7. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +6 -2
  8. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +22 -18
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +7 -6
  10. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -3
  11. package/dist/cjs/node/plugin/shared/getFilePath.js +142 -0
  12. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +3 -8
  13. package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -1
  14. package/dist/cjs/node/plugin/utils.js +1 -1
  15. package/dist/cjs/node/prerender/runPrerender.js +6 -7
  16. package/dist/cjs/node/prerender/utils.js +2 -1
  17. package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +3 -3
  18. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -1
  19. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +5 -9
  20. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +9 -8
  21. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +6 -12
  22. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +5 -0
  23. package/dist/cjs/node/runtime/utils.js +0 -1
  24. package/dist/cjs/shared/route/abort.js +2 -1
  25. package/dist/cjs/shared/route/executeGuardHook.js +2 -1
  26. package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +2 -1
  27. package/dist/cjs/shared/route/utils.js +0 -1
  28. package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +1 -0
  29. package/dist/cjs/utils/isNpmPackage.js +11 -2
  30. package/dist/cjs/utils/parseUrl.js +8 -1
  31. package/dist/cjs/utils/projectInfo.js +1 -1
  32. package/dist/esm/client/client-routing-runtime/history.d.ts +1 -1
  33. package/dist/esm/client/client-routing-runtime/history.js +5 -5
  34. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +1 -1
  35. package/dist/esm/node/plugin/plugins/buildConfig.js +12 -7
  36. package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +2 -1
  37. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -23
  38. package/dist/esm/node/plugin/plugins/envVars.js +4 -3
  39. package/dist/esm/node/plugin/plugins/fileEnv.js +7 -4
  40. package/dist/esm/node/plugin/plugins/importUserCode/index.js +7 -3
  41. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +6 -2
  42. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +22 -18
  43. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +7 -6
  44. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -3
  45. package/dist/esm/node/plugin/shared/getFilePath.d.ts +21 -0
  46. package/dist/esm/node/plugin/shared/getFilePath.js +136 -0
  47. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +4 -9
  48. package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -1
  49. package/dist/esm/node/plugin/utils.d.ts +1 -1
  50. package/dist/esm/node/plugin/utils.js +1 -1
  51. package/dist/esm/node/prerender/runPrerender.js +2 -3
  52. package/dist/esm/node/prerender/utils.d.ts +2 -1
  53. package/dist/esm/node/prerender/utils.js +2 -1
  54. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +1 -1
  55. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -1
  56. package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -10
  57. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +9 -8
  58. package/dist/esm/node/runtime/renderPage/getPageAssets.js +7 -13
  59. package/dist/esm/node/runtime/renderPage/logErrorHint.js +2 -0
  60. package/dist/esm/node/runtime/utils.d.ts +0 -1
  61. package/dist/esm/node/runtime/utils.js +0 -1
  62. package/dist/esm/shared/page-configs/FilePath.d.ts +41 -29
  63. package/dist/esm/shared/route/abort.js +2 -1
  64. package/dist/esm/shared/route/executeGuardHook.js +2 -1
  65. package/dist/esm/shared/route/executeOnBeforeRouteHook.js +2 -1
  66. package/dist/esm/shared/route/utils.d.ts +0 -1
  67. package/dist/esm/shared/route/utils.js +0 -1
  68. package/dist/esm/utils/assertPathIsFilesystemAbsolute.js +1 -0
  69. package/dist/esm/utils/debug.d.ts +1 -1
  70. package/dist/esm/utils/isNpmPackage.d.ts +5 -1
  71. package/dist/esm/utils/isNpmPackage.js +10 -1
  72. package/dist/esm/utils/parseUrl.js +8 -1
  73. package/dist/esm/utils/projectInfo.d.ts +2 -2
  74. package/dist/esm/utils/projectInfo.js +1 -1
  75. package/package.json +25 -13
  76. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getFilePath.js +0 -90
  77. package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -19
  78. package/dist/cjs/utils/getFilePathAbsolute.js +0 -70
  79. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getFilePath.d.ts +0 -20
  80. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getFilePath.js +0 -84
  81. package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.d.ts +0 -2
  82. package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -16
  83. package/dist/esm/utils/getFilePathAbsolute.d.ts +0 -5
  84. package/dist/esm/utils/getFilePathAbsolute.js +0 -64
@@ -1,8 +1,9 @@
1
1
  export { fileEnv };
2
- import { assert, assertUsage, assertWarning, capitalizeFirstLetter, getFilePathAbsoluteUserRootDir } from '../utils.js';
2
+ import { assert, assertUsage, assertWarning, capitalizeFirstLetter } from '../utils.js';
3
3
  import { extractAssetsRE } from './extractAssetsPlugin.js';
4
4
  import { extractExportNamesRE } from './extractExportNamesPlugin.js';
5
5
  import pc from '@brillout/picocolors';
6
+ import { getModuleFilePath } from '../shared/getFilePath.js';
6
7
  function fileEnv() {
7
8
  let config;
8
9
  let isDev = false;
@@ -39,11 +40,13 @@ function fileEnv() {
39
40
  // resolved is null when import path is erroneous and doesn't actually point to a file
40
41
  if (!resolved)
41
42
  return;
42
- const modulePath = resolved.id.split('?')[0];
43
+ const moduleId = resolved.id;
44
+ const modulePath = moduleId.split('?')[0];
43
45
  // `.server.js` and `.client.js` should only apply to user files
44
46
  if (modulePath.includes('/node_modules/'))
45
47
  return;
46
48
  // TODO/v1-release: remove
49
+ // - I don't remember exactly, but I think I've added `TODO/v1-release: remove` because I vaguely remember that we can remove this after we remove the 0.4 design.
47
50
  if (modulePath.endsWith('.css'))
48
51
  return;
49
52
  const isServerSide = options?.ssr;
@@ -55,7 +58,7 @@ function fileEnv() {
55
58
  return;
56
59
  // Show error message
57
60
  let errMsg;
58
- let modulePathPretty = getFilePathAbsoluteUserRootDir(modulePath, config.root);
61
+ let modulePathPretty = getModuleFilePath(moduleId, config);
59
62
  modulePathPretty = modulePathPretty.replaceAll(suffix, pc.bold(suffix));
60
63
  errMsg = `${capitalizeFirstLetter(envExpect)}-only module ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
61
64
  if (importer &&
@@ -63,7 +66,7 @@ function fileEnv() {
63
66
  !importer.includes('virtual:vike:') &&
64
67
  // I don't know why and who sets importer to '<stdin>' (I guess Vite?)
65
68
  importer !== '<stdin>') {
66
- const importerPath = getFilePathAbsoluteUserRootDir(importer.split('?')[0], config.root);
69
+ const importerPath = getModuleFilePath(importer, config);
67
70
  errMsg += ` by ${importerPath}`;
68
71
  }
69
72
  if (isDev) {
@@ -3,12 +3,13 @@ import { normalizePath } from 'vite';
3
3
  import { getConfigVike } from '../../../shared/getConfigVike.js';
4
4
  import { getVirtualFilePageConfigValuesAll } from './v1-design/getVirtualFilePageConfigValuesAll.js';
5
5
  import { getVirtualFileImportUserCode } from './getVirtualFileImportUserCode.js';
6
- import { assert, assertPosixPath, getFilePathAbsoluteUserRootDir, getOutDirs, getVirtualFileId, isDev1, isDev1_onConfigureServer, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
6
+ import { assert, assertPosixPath, getOutDirs, getVirtualFileId, isDev1, isDev1_onConfigureServer, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
7
7
  import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
8
8
  import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
9
9
  import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile } from './v1-design/getVikeConfig.js';
10
10
  import pc from '@brillout/picocolors';
11
11
  import { logConfigInfo, clearLogs } from '../../shared/loggerNotProd.js';
12
+ import { getFilePathResolved } from '../../shared/getFilePath.js';
12
13
  function importUserCode() {
13
14
  let config;
14
15
  let configVike;
@@ -118,8 +119,11 @@ function isVikeConfigModule(filePathAbsoluteFilesystem) {
118
119
  }
119
120
  function reloadConfig(filePath, config, op) {
120
121
  {
121
- const filePathToShowToUser = pc.dim(getFilePathAbsoluteUserRootDir(filePath, config.root, true));
122
- const msg = `${op} ${filePathToShowToUser}`;
122
+ const { filePathToShowToUserResolved } = getFilePathResolved({
123
+ filePathAbsoluteFilesystem: filePath,
124
+ userRootDir: config.root
125
+ });
126
+ const msg = `${op} ${pc.dim(filePathToShowToUserResolved)}`;
123
127
  logConfigInfo(msg, 'info');
124
128
  }
125
129
  reloadVikeConfig(config.root, getOutDirs(config).outDirRoot);
@@ -9,7 +9,7 @@ import pc from '@brillout/picocolors';
9
9
  import { parseImportData } from './transformFileImports.js';
10
10
  import { getConfigFileExport } from '../getConfigFileExport.js';
11
11
  import { assertImportPath, resolveImportPath } from './resolveImportPath.js';
12
- import { getFilePathResolved } from './getFilePath.js';
12
+ import { getFilePathResolved } from '../../../../shared/getFilePath.js';
13
13
  assertIsNotProductionRuntime();
14
14
  // Load fake import
15
15
  async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
@@ -76,7 +76,11 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
76
76
  return { extendsConfigs, extendsFilePaths };
77
77
  }
78
78
  function warnUserLandExtension(importPath, configFilePath) {
79
- assertWarning(isNpmPackageImport(importPath), `${configFilePath.filePathToShowToUser} uses ${pc.cyan('extends')} to inherit from ${pc.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this.`, { onlyOnce: true });
79
+ // We preserve this feature because we may need it for eject
80
+ assertWarning(isNpmPackageImport(importPath, {
81
+ // Vike config files don't support path aliases. (If they do one day, then Vike will/should be able to resolve path aliases.)
82
+ cannotBePathAlias: true
83
+ }) || importPath.includes('/node_modules/'), `${configFilePath.filePathToShowToUser} uses ${pc.cyan('extends')} to inherit from ${pc.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this.`, { onlyOnce: true });
80
84
  }
81
85
  function getExtendsImportData(configFileExports, configFilePath) {
82
86
  const { filePathToShowToUser } = configFilePath;
@@ -6,7 +6,7 @@ import pc from '@brillout/picocolors';
6
6
  import { assert, assertPosixPath, assertUsage, deepEqual, requireResolve } from '../../../../utils.js';
7
7
  import { parseImportData } from './transformFileImports.js';
8
8
  import path from 'path';
9
- import { getFilePathResolved, getFilePathUnresolved } from './getFilePath.js';
9
+ import { getFilePathResolved, getFilePathUnresolved } from '../../../../shared/getFilePath.js';
10
10
  const filesEnvMap = new Map();
11
11
  function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
12
12
  if (typeof configValue !== 'string')
@@ -18,6 +18,7 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
18
18
  const filePathAbsoluteFilesystem = resolveImportPath(importData, importerFilePath);
19
19
  assertFileEnv(filePathAbsoluteFilesystem ?? importPath, configEnv, configName);
20
20
  const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
21
+ let filePath;
21
22
  if (importPath.startsWith('.')) {
22
23
  // We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
23
24
  // ```
@@ -25,28 +26,30 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
25
26
  // ```
26
27
  assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
27
28
  const filePathAbsoluteUserRootDir = resolveImportPath_absoluteUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
28
- const filePath = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir, importPathAbsolute: null });
29
- return {
30
- ...filePath,
31
- fileExportName: exportName,
32
- fileExportPathToShowToUser
33
- };
29
+ filePath = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
34
30
  }
35
31
  else {
36
32
  // importPath can be:
37
33
  // - an npm package import
38
34
  // - a path alias
39
- const filePath = getFilePathUnresolved({
40
- filePathAbsoluteFilesystem,
41
- filePathAbsoluteUserRootDir: null,
42
- importPathAbsolute: importPath
43
- });
44
- return {
45
- ...filePath,
46
- fileExportName: exportName,
47
- fileExportPathToShowToUser
48
- };
35
+ if (filePathAbsoluteFilesystem) {
36
+ filePath = getFilePathResolved({
37
+ userRootDir,
38
+ filePathAbsoluteFilesystem,
39
+ importPathAbsolute: importPath
40
+ });
41
+ }
42
+ else {
43
+ filePath = getFilePathUnresolved({
44
+ importPathAbsolute: importPath
45
+ });
46
+ }
49
47
  }
48
+ return {
49
+ ...filePath,
50
+ fileExportName: exportName,
51
+ fileExportPathToShowToUser
52
+ };
50
53
  }
51
54
  function resolveImportPath_absoluteUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
52
55
  assertPosixPath(userRootDir);
@@ -74,7 +77,8 @@ function resolveImportPath(importData, importerFilePath) {
74
77
  const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
75
78
  assertPosixPath(importerFilePathAbsolute);
76
79
  const cwd = path.posix.dirname(importerFilePathAbsolute);
77
- // We can't use import.meta.resolve() as of Junary 2023 (and probably for a lot longer): 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
80
+ // We can't use import.meta.resolve() as of Junary 2023 (and probably for a lot longer)
81
+ // 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
78
82
  // filePathAbsoluteFilesystem is expected to be null when importData.importPath is a Vite path alias
79
83
  const filePathAbsoluteFilesystem = requireResolve(importData.importPath, cwd);
80
84
  return filePathAbsoluteFilesystem;
@@ -70,7 +70,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
70
70
  outfile: path.posix.join(
71
71
  // Needed for correct inline source map
72
72
  entryFileDir,
73
- // `write: false` => no file is actually be emitted
73
+ // `write: false` => no file is actually emitted
74
74
  'NEVER_EMITTED.js'),
75
75
  logLevel: 'silent',
76
76
  format: 'esm',
@@ -102,10 +102,10 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
102
102
  return;
103
103
  if (args.pluginData?.[useEsbuildResolver])
104
104
  return;
105
- const isImportAbsolute = !args.path.startsWith('.');
106
105
  const { path, ...opts } = args;
107
106
  opts.pluginData = { [useEsbuildResolver]: true };
108
107
  const resolved = await build.resolve(path, opts);
108
+ resolved.path = toPosixPath(resolved.path);
109
109
  // vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
110
110
  // - This is temporary, see comment below.
111
111
  const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
@@ -120,14 +120,15 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
120
120
  // - For example if esbuild cannot resolve a path alias while Vite can.
121
121
  // - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
122
122
  resolved.errors.length > 0;
123
- pointerImports_[args.path] = isPointerImport;
123
+ pointerImports_[resolved.path] = isPointerImport;
124
+ assertPosixPath(resolved.path);
124
125
  const isExternal = isPointerImport ||
125
- // npm package imports that aren't pointer imports (e.g. Vite plugin import)
126
- isImportAbsolute;
126
+ // npm package imports that aren't pointer imports (e.g. importing a Vite plugin)
127
+ resolved.path.includes('/node_modules/');
127
128
  if (debug.isEnabled)
128
129
  debug('onResolved()', { args, resolved, isPointerImport, isExternal });
129
130
  if (isExternal) {
130
- return { external: true, path: args.path };
131
+ return { external: true, path: resolved.path };
131
132
  }
132
133
  else {
133
134
  return resolved;
@@ -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 { getFilePathResolved } from './getVikeConfig/getFilePath.js';
22
+ import { getFilePathResolved } from '../../../shared/getFilePath.js';
23
23
  assertIsNotProductionRuntime();
24
24
  let devServerIsCorrupt = false;
25
25
  let wasConfigInvalid = null;
@@ -740,7 +740,7 @@ function getComputed(configValueSources, configDefinitions) {
740
740
  }
741
741
  async function findPlusFiles(userRootDir, outDirRoot, isDev) {
742
742
  const files = await crawlPlusFiles(userRootDir, outDirRoot, isDev);
743
- const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir, importPathAbsolute: null }));
743
+ const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir }));
744
744
  return plusFiles;
745
745
  }
746
746
  function getConfigName(filePath) {
@@ -1007,7 +1007,11 @@ function sortConfigValueSources(configValueSources, locationIdPage) {
1007
1007
  // Sort after whether the config value was defined by an npm package
1008
1008
  .sort(makeFirst(([, [source]]) => {
1009
1009
  const { importPathAbsolute } = source.definedAt;
1010
- return !!importPathAbsolute && isNpmPackageImport(importPathAbsolute);
1010
+ return (!!importPathAbsolute &&
1011
+ isNpmPackageImport(importPathAbsolute, {
1012
+ // Vike config files don't support path aliases. (If they do one day, then Vike will/should be able to resolve path aliases.)
1013
+ cannotBePathAlias: true
1014
+ }));
1011
1015
  }))
1012
1016
  // Sort after the filesystem inheritance of the config value
1013
1017
  .sort(([, [source1]], [, [source2]]) => reverse(sortAfterInheritanceOrder(source1.locationId, source2.locationId, locationIdPage))));
@@ -0,0 +1,21 @@
1
+ export { getFilePathResolved };
2
+ export { getFilePathUnresolved };
3
+ export { getModuleFilePath };
4
+ export { getFilePathToShowToUserFromUnkown };
5
+ export { cleanFilePathUnkown };
6
+ import type { FilePath, FilePathResolved } from '../../../shared/page-configs/FilePath.js';
7
+ import type { ResolvedConfig } from 'vite';
8
+ declare function getFilePathUnresolved({ importPathAbsolute }: {
9
+ importPathAbsolute: string;
10
+ }): FilePath;
11
+ declare function getFilePathResolved(args: {
12
+ userRootDir: string;
13
+ importPathAbsolute?: string;
14
+ } & ({
15
+ filePathAbsoluteFilesystem: string;
16
+ } | {
17
+ filePathAbsoluteUserRootDir: string;
18
+ })): FilePathResolved;
19
+ declare function getModuleFilePath(moduleId: string, config: ResolvedConfig): string;
20
+ declare function getFilePathToShowToUserFromUnkown(filePathUnkown: string, userRootDir: string): string;
21
+ declare function cleanFilePathUnkown(filePathUnknown: string): string;
@@ -0,0 +1,136 @@
1
+ export { getFilePathResolved };
2
+ export { getFilePathUnresolved };
3
+ export { getModuleFilePath };
4
+ export { getFilePathToShowToUserFromUnkown };
5
+ export { cleanFilePathUnkown };
6
+ import path from 'path';
7
+ import { assert, assertPathIsFilesystemAbsolute, assertPosixPath, toPosixPath } from '../utils.js';
8
+ function getFilePathUnresolved({ importPathAbsolute }) {
9
+ return getFilePath({ importPathAbsolute, filePathAbsoluteUserRootDir: null });
10
+ }
11
+ function getFilePathResolved(args) {
12
+ const { userRootDir } = args;
13
+ const importPathAbsolute = args.importPathAbsolute ?? null;
14
+ let filePathAbsoluteFilesystem;
15
+ let filePathAbsoluteUserRootDir;
16
+ if ('filePathAbsoluteFilesystem' in args) {
17
+ filePathAbsoluteFilesystem = args.filePathAbsoluteFilesystem;
18
+ filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir });
19
+ }
20
+ else {
21
+ filePathAbsoluteUserRootDir = args.filePathAbsoluteUserRootDir;
22
+ filePathAbsoluteFilesystem = getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir });
23
+ }
24
+ let filePath;
25
+ const common = {
26
+ filePathAbsoluteUserRootDir,
27
+ importPathAbsolute,
28
+ userRootDir
29
+ };
30
+ if (importPathAbsolute) {
31
+ filePath = getFilePath({
32
+ ...common,
33
+ importPathAbsolute
34
+ });
35
+ }
36
+ else {
37
+ assert(filePathAbsoluteUserRootDir);
38
+ filePath = getFilePath({
39
+ ...common,
40
+ filePathAbsoluteUserRootDir
41
+ });
42
+ }
43
+ assert(filePathAbsoluteFilesystem);
44
+ assertPathIsFilesystemAbsolute(filePathAbsoluteFilesystem);
45
+ const filePathToShowToUserResolved = filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
46
+ assert(filePathToShowToUserResolved);
47
+ const filePathResolved = {
48
+ ...filePath,
49
+ filePathAbsoluteFilesystem,
50
+ filePathToShowToUserResolved
51
+ };
52
+ return filePathResolved;
53
+ }
54
+ function getFilePath(args) {
55
+ let filePathAbsoluteVite;
56
+ if (args.filePathAbsoluteUserRootDir !== null) {
57
+ filePathAbsoluteVite = args.filePathAbsoluteUserRootDir;
58
+ }
59
+ else {
60
+ assert(args.importPathAbsolute !== null); // Help TS
61
+ filePathAbsoluteVite = args.importPathAbsolute;
62
+ }
63
+ const filePathToShowToUser = filePathAbsoluteVite;
64
+ assert(filePathToShowToUser);
65
+ return {
66
+ ...args,
67
+ filePathAbsoluteFilesystem: null,
68
+ filePathAbsoluteVite,
69
+ filePathToShowToUser
70
+ };
71
+ }
72
+ function getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir }) {
73
+ assertPosixPath(filePathAbsoluteUserRootDir);
74
+ assertPosixPath(userRootDir);
75
+ assertPathIsFilesystemAbsolute(userRootDir);
76
+ const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathAbsoluteUserRootDir);
77
+ assertPathIsFilesystemAbsolute(userRootDir);
78
+ return filePathAbsoluteFilesystem;
79
+ }
80
+ function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir }) {
81
+ assertPosixPath(filePathAbsoluteFilesystem);
82
+ assertPosixPath(userRootDir);
83
+ assertPathIsFilesystemAbsolute(filePathAbsoluteFilesystem);
84
+ assertPathIsFilesystemAbsolute(userRootDir);
85
+ const filePathRelative = path.posix.relative(userRootDir, filePathAbsoluteFilesystem);
86
+ if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
87
+ assert(filePathRelative.startsWith('../'));
88
+ return null;
89
+ }
90
+ assert(!filePathRelative.startsWith('.') && !filePathRelative.startsWith('/'));
91
+ const filePathAbsoluteUserRootDir = `/${filePathRelative}`;
92
+ assert(filePathAbsoluteUserRootDir === getFilePathAbsoluteUserRootDir2(filePathAbsoluteFilesystem, userRootDir));
93
+ return filePathAbsoluteUserRootDir;
94
+ }
95
+ function getModuleFilePath(moduleId, config) {
96
+ const userRootDir = config.root;
97
+ assertPosixPath(moduleId);
98
+ assertPosixPath(userRootDir);
99
+ const filePathAbsoluteFilesystem = cleanModuleId(moduleId);
100
+ assertPathIsFilesystemAbsolute(filePathAbsoluteFilesystem);
101
+ const filePath = getFilePathResolved({ filePathAbsoluteFilesystem, userRootDir });
102
+ return filePath.filePathToShowToUserResolved;
103
+ }
104
+ function getFilePathToShowToUserFromUnkown(
105
+ // We don't have any guarentee about filePath, e.g. about whether is filePathAbsoluteFilesystem or filePathAbsoluteUserRootDir
106
+ filePathUnkown, userRootDir) {
107
+ assertPosixPath(userRootDir);
108
+ assertPathIsFilesystemAbsolute(userRootDir);
109
+ filePathUnkown = cleanFilePathUnkown(filePathUnkown);
110
+ if (!filePathUnkown.startsWith(userRootDir)) {
111
+ return filePathUnkown;
112
+ }
113
+ else {
114
+ return getFilePathAbsoluteUserRootDir2(filePathUnkown, userRootDir);
115
+ }
116
+ }
117
+ function getFilePathAbsoluteUserRootDir2(filePathAbsoluteFilesystem, userRootDir) {
118
+ assert(filePathAbsoluteFilesystem.startsWith(userRootDir));
119
+ let filePathAbsoluteUserRootDir = filePathAbsoluteFilesystem.slice(userRootDir.length);
120
+ if (!filePathAbsoluteUserRootDir.startsWith('/'))
121
+ filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir;
122
+ return filePathAbsoluteUserRootDir;
123
+ }
124
+ function cleanFilePathUnkown(filePathUnknown) {
125
+ filePathUnknown = toPosixPath(filePathUnknown);
126
+ filePathUnknown = cleanModuleId(filePathUnknown);
127
+ return filePathUnknown;
128
+ }
129
+ function cleanModuleId(moduleId) {
130
+ // remove query
131
+ const parts = moduleId.split('?');
132
+ if (parts.length > 1)
133
+ parts.pop();
134
+ assert(parts.length >= 1);
135
+ return parts.join('?');
136
+ }
@@ -7,7 +7,8 @@ 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, getFilePathAbsoluteUserRootDir, isObject, removeEmptyLines, stripAnsi, toPosixPath } from '../../utils.js';
10
+ import { assert, escapeRegex, isObject, removeEmptyLines, stripAnsi } from '../../utils.js';
11
+ import { cleanFilePathUnkown, getFilePathToShowToUserFromUnkown } from '../getFilePath.js';
11
12
  function isErrorWithCodeSnippet(err) {
12
13
  if (!isObject(err)) {
13
14
  return false;
@@ -46,7 +47,7 @@ function getPrettyErrorWithCodeSnippet(err, userRootDir) {
46
47
  let { id, frame } = err;
47
48
  const msgFirstLine = [
48
49
  pc.red('Failed to transpile'),
49
- pc.bold(pc.red(getFilePathAbsoluteUserRootDir(normalizeId(id), userRootDir))),
50
+ pc.bold(pc.red(getFilePathToShowToUserFromUnkown(id, userRootDir))),
50
51
  pc.red('because:')
51
52
  ].join(' ');
52
53
  const errMsg = getPrettyErrMessage(err);
@@ -85,7 +86,7 @@ function getPrettyErrMessage(err) {
85
86
  // Remove "/home/rom/code/vike/examples/react-full/components/Counter.tsx:1:8:" (redundant since we already print the filename)
86
87
  const pos = /(?:\:\d+|)/;
87
88
  errMsg = errMsg.split(reg([id, pos, pos, trail], 'gi')).join('');
88
- errMsg = errMsg.split(reg([normalizeId(id), pos, pos, trail], 'gi')).join('');
89
+ errMsg = errMsg.split(reg([cleanFilePathUnkown(id), pos, pos, trail], 'gi')).join('');
89
90
  // Remove "ERROR:" (useless)
90
91
  errMsg = errMsg.split(reg(['ERROR:', trail])).join('');
91
92
  // Remove "Internal server error:" (useless)
@@ -155,9 +156,3 @@ function isEquivalentErrorWithCodeSnippet(err1, err2) {
155
156
  function isDefinedAndSame(val1, val2) {
156
157
  return val1 && val1 === val2;
157
158
  }
158
- function normalizeId(id) {
159
- id = toPosixPath(id);
160
- // remove query
161
- id = id.split('?')[0];
162
- return id;
163
- }
@@ -14,7 +14,7 @@ export { clearLogs };
14
14
  import { isAbortError } from '../../../shared/route/abort.js';
15
15
  import { getViteConfig } from '../../runtime/globalContext.js';
16
16
  import { overwriteRuntimeProductionLogger } from '../../runtime/renderPage/loggerRuntime.js';
17
- import { assert, assertIsNotProductionRuntime, formatHintLog, getAssertErrMsg, isUserHookError, overwriteAssertProductionLogger, stripAnsi, warnIfErrorIsNotObject } from '../utils.js';
17
+ import { assert, assertIsNotProductionRuntime, formatHintLog, getAssertErrMsg, overwriteAssertProductionLogger, stripAnsi, warnIfErrorIsNotObject } from '../utils.js';
18
18
  import { getHttpRequestAsyncStore } from './getHttpRequestAsyncStore.js';
19
19
  import { isErrorDebug } from './isErrorDebug.js';
20
20
  import { isErrorWithCodeSnippet, getPrettyErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js';
@@ -24,6 +24,7 @@ import pc from '@brillout/picocolors';
24
24
  import { setAlreadyLogged } from '../../runtime/renderPage/isNewError.js';
25
25
  import { isConfigInvalid } from '../../runtime/renderPage/isConfigInvalid.js';
26
26
  import { onRuntimeError } from '../../runtime/renderPage/loggerProd.js';
27
+ import { isUserHookError } from '../../../shared/hooks/executeHook.js';
27
28
  assertIsNotProductionRuntime();
28
29
  overwriteRuntimeProductionLogger(logRuntimeError, logRuntimeInfo);
29
30
  overwriteAssertProductionLogger(assertLogger);
@@ -1,6 +1,5 @@
1
1
  export * from '../runtime/utils.js';
2
2
  export * from '../../utils/viteIsSSR.js';
3
- export * from '../../utils/getFilePathAbsolute.js';
4
3
  export * from '../../utils/requireResolve.js';
5
4
  export * from '../../utils/arrayIncludes.js';
6
5
  export * from '../../utils/isDev.js';
@@ -20,3 +19,4 @@ export * from '../../utils/injectRollupInputs.js';
20
19
  export * from '../../utils/humanizeTime.js';
21
20
  export * from '../../utils/pLimit.js';
22
21
  export * from '../../utils/assertVersion.js';
22
+ export * from '../../utils/assertPathIsFilesystemAbsolute.js';
@@ -6,7 +6,6 @@ onLoad();
6
6
  export * from '../runtime/utils.js';
7
7
  // Utils only needed by `plugin/*`
8
8
  export * from '../../utils/viteIsSSR.js';
9
- export * from '../../utils/getFilePathAbsolute.js';
10
9
  export * from '../../utils/requireResolve.js';
11
10
  export * from '../../utils/arrayIncludes.js';
12
11
  export * from '../../utils/isDev.js';
@@ -26,3 +25,4 @@ export * from '../../utils/injectRollupInputs.js';
26
25
  export * from '../../utils/humanizeTime.js';
27
26
  export * from '../../utils/pLimit.js';
28
27
  export * from '../../utils/assertVersion.js';
28
+ export * from '../../utils/assertPathIsFilesystemAbsolute.js';
@@ -5,8 +5,7 @@ export { runPrerender_forceExit };
5
5
  import '../runtime/page-files/setup.js';
6
6
  import path from 'path';
7
7
  import { route } from '../../shared/route/index.js';
8
- import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, executeHook, isPlainObject, isUserHookError, handleNodeEnv_prerender } from './utils.js';
9
- import { pLimit } from '../../utils/pLimit.js';
8
+ import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject, handleNodeEnv_prerender, pLimit, assertPathIsFilesystemAbsolute } from './utils.js';
10
9
  import { prerenderPage, prerender404Page, getRenderContext, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
11
10
  import pc from '@brillout/picocolors';
12
11
  import { cpus } from 'os';
@@ -20,13 +19,13 @@ import { getConfigValue, getConfigValueFilePathToShowToUser } from '../../shared
20
19
  import { loadConfigValues } from '../../shared/page-configs/loadConfigValues.js';
21
20
  import { isErrorPage } from '../../shared/error-page.js';
22
21
  import { addUrlComputedProps } from '../../shared/addUrlComputedProps.js';
23
- import { assertPathIsFilesystemAbsolute } from '../../utils/assertPathIsFilesystemAbsolute.js';
24
22
  import { isAbortError } from '../../shared/route/abort.js';
25
23
  import { loadUserFilesServerSide } from '../runtime/renderPage/loadUserFilesServerSide.js';
26
24
  import { getHookFromPageConfig, getHookFromPageConfigGlobal, getHookTimeoutDefault, setIsPrerenderering } from '../../shared/hooks/getHook.js';
27
25
  import { noRouteMatch } from '../../shared/route/noRouteMatch.js';
28
26
  import { getVikeConfig } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
29
27
  import { logErrorHint } from '../runtime/renderPage/logErrorHint.js';
28
+ import { executeHook, isUserHookError } from '../../shared/hooks/executeHook.js';
30
29
  async function runPrerenderFromAPI(options = {}) {
31
30
  await runPrerender(options, 'prerender()');
32
31
  // - We purposely propagate the error to the user land, so that the error interrupts the user land. It's also, I guess, a nice-to-have that the user has control over the error.
@@ -8,6 +8,7 @@ export * from '../../utils/getOutDirs.js';
8
8
  export * from '../../utils/isPropertyGetter.js';
9
9
  export * from '../../utils/filesystemPathHandling.js';
10
10
  export * from '../../utils/urlToFile.js';
11
- export * from '../../shared/hooks/executeHook.js';
12
11
  export * from '../../utils/isPlainObject.js';
13
12
  export * from '../../utils/assertNodeEnv.js';
13
+ export * from '../../utils/pLimit.js';
14
+ export * from '../../utils/assertPathIsFilesystemAbsolute.js';
@@ -10,6 +10,7 @@ export * from '../../utils/getOutDirs.js';
10
10
  export * from '../../utils/isPropertyGetter.js';
11
11
  export * from '../../utils/filesystemPathHandling.js';
12
12
  export * from '../../utils/urlToFile.js';
13
- export * from '../../shared/hooks/executeHook.js';
14
13
  export * from '../../utils/isPlainObject.js';
15
14
  export * from '../../utils/assertNodeEnv.js';
15
+ export * from '../../utils/pLimit.js';
16
+ export * from '../../utils/assertPathIsFilesystemAbsolute.js';
@@ -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);