vike 0.4.165 → 0.4.166-commit-a5e2596

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/dist/cjs/node/plugin/index.js +1 -1
  2. package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
  3. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
  4. package/dist/cjs/node/plugin/plugins/buildConfig.js +78 -63
  5. package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +14 -1
  6. package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
  7. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -23
  8. package/dist/cjs/node/plugin/plugins/envVars.js +3 -2
  9. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +9 -9
  10. package/dist/cjs/node/plugin/plugins/fileEnv.js +6 -3
  11. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +6 -2
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +53 -24
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +10 -25
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +32 -35
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +18 -26
  18. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +26 -21
  19. package/dist/cjs/node/plugin/shared/getFilePath.js +142 -0
  20. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +3 -8
  21. package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -1
  22. package/dist/cjs/node/plugin/utils.js +1 -1
  23. package/dist/cjs/node/prerender/runPrerender.js +6 -7
  24. package/dist/cjs/node/prerender/utils.js +2 -1
  25. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
  26. package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
  27. package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +3 -3
  28. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -1
  29. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +31 -33
  30. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +9 -8
  31. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +6 -12
  32. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +5 -0
  33. package/dist/cjs/node/runtime/renderPage.js +34 -21
  34. package/dist/cjs/node/runtime/utils.js +0 -1
  35. package/dist/cjs/shared/page-configs/FilePath.js +2 -0
  36. package/dist/cjs/shared/route/abort.js +2 -1
  37. package/dist/cjs/shared/route/executeGuardHook.js +2 -1
  38. package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +2 -1
  39. package/dist/cjs/shared/route/index.js +2 -3
  40. package/dist/cjs/shared/route/utils.js +0 -1
  41. package/dist/cjs/utils/assert.js +2 -0
  42. package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +1 -0
  43. package/dist/cjs/utils/assertSingleInstance.js +6 -5
  44. package/dist/cjs/utils/assertVersion.js +4 -1
  45. package/dist/cjs/utils/getGlobalObject.js +21 -6
  46. package/dist/cjs/utils/isNpmPackage.js +11 -5
  47. package/dist/cjs/utils/parseUrl.js +8 -1
  48. package/dist/cjs/utils/projectInfo.js +1 -4
  49. package/dist/esm/client/client-routing-runtime/history.d.ts +1 -1
  50. package/dist/esm/client/client-routing-runtime/history.js +5 -5
  51. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +1 -1
  52. package/dist/esm/node/plugin/index.js +1 -1
  53. package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
  54. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
  55. package/dist/esm/node/plugin/plugins/buildConfig.d.ts +1 -1
  56. package/dist/esm/node/plugin/plugins/buildConfig.js +79 -64
  57. package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +14 -1
  58. package/dist/esm/node/plugin/plugins/config/index.js +1 -1
  59. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +19 -24
  60. package/dist/esm/node/plugin/plugins/envVars.js +4 -3
  61. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +9 -9
  62. package/dist/esm/node/plugin/plugins/fileEnv.js +7 -4
  63. package/dist/esm/node/plugin/plugins/importUserCode/index.js +7 -3
  64. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +1 -1
  65. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
  66. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  67. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +54 -25
  68. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
  69. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
  70. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +1 -1
  71. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +11 -26
  72. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +2 -1
  73. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +32 -35
  74. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
  75. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +18 -26
  76. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
  77. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +26 -21
  78. package/dist/esm/node/plugin/shared/getFilePath.d.ts +21 -0
  79. package/dist/esm/node/plugin/shared/getFilePath.js +136 -0
  80. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +4 -9
  81. package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -1
  82. package/dist/esm/node/plugin/utils.d.ts +1 -1
  83. package/dist/esm/node/plugin/utils.js +1 -1
  84. package/dist/esm/node/prerender/runPrerender.js +2 -3
  85. package/dist/esm/node/prerender/utils.d.ts +2 -1
  86. package/dist/esm/node/prerender/utils.js +2 -1
  87. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
  88. package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
  89. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +1 -1
  90. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -1
  91. package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +32 -34
  92. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +9 -8
  93. package/dist/esm/node/runtime/renderPage/getPageAssets.js +7 -13
  94. package/dist/esm/node/runtime/renderPage/logErrorHint.js +2 -0
  95. package/dist/esm/node/runtime/renderPage.js +34 -21
  96. package/dist/esm/node/runtime/utils.d.ts +0 -1
  97. package/dist/esm/node/runtime/utils.js +0 -1
  98. package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +1 -1
  99. package/dist/esm/shared/page-configs/FilePath.d.ts +64 -0
  100. package/dist/esm/shared/page-configs/FilePath.js +1 -0
  101. package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -42
  102. package/dist/esm/shared/route/abort.js +2 -1
  103. package/dist/esm/shared/route/executeGuardHook.js +2 -1
  104. package/dist/esm/shared/route/executeOnBeforeRouteHook.js +2 -1
  105. package/dist/esm/shared/route/index.js +2 -3
  106. package/dist/esm/shared/route/utils.d.ts +0 -1
  107. package/dist/esm/shared/route/utils.js +0 -1
  108. package/dist/esm/utils/assert.js +2 -0
  109. package/dist/esm/utils/assertPathIsFilesystemAbsolute.js +1 -0
  110. package/dist/esm/utils/assertSingleInstance.d.ts +2 -2
  111. package/dist/esm/utils/assertSingleInstance.js +5 -4
  112. package/dist/esm/utils/assertVersion.js +4 -1
  113. package/dist/esm/utils/debug.d.ts +1 -1
  114. package/dist/esm/utils/getGlobalObject.d.ts +6 -1
  115. package/dist/esm/utils/getGlobalObject.js +22 -6
  116. package/dist/esm/utils/isNpmPackage.d.ts +5 -7
  117. package/dist/esm/utils/isNpmPackage.js +15 -4
  118. package/dist/esm/utils/parseUrl.js +8 -1
  119. package/dist/esm/utils/projectInfo.d.ts +2 -2
  120. package/dist/esm/utils/projectInfo.js +1 -4
  121. package/package.json +26 -14
  122. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -33
  123. package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -19
  124. package/dist/cjs/utils/getFilePathAbsolute.js +0 -70
  125. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +0 -5
  126. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -27
  127. package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.d.ts +0 -2
  128. package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -16
  129. package/dist/esm/utils/getFilePathAbsolute.d.ts +0 -5
  130. package/dist/esm/utils/getFilePathAbsolute.js +0 -64
@@ -12,6 +12,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
12
12
  const transformFileImports_js_1 = require("./transformFileImports.js");
13
13
  const getConfigFileExport_js_1 = require("../getConfigFileExport.js");
14
14
  const resolveImportPath_js_1 = require("./resolveImportPath.js");
15
+ const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
15
16
  (0, utils_js_1.assertIsNotProductionRuntime)();
16
17
  // Load fake import
17
18
  async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
@@ -64,21 +65,12 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
64
65
  const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
65
66
  const extendsConfigFiles = [];
66
67
  extendsImportData.map((importData) => {
67
- const { importPath: importPath } = importData;
68
+ const { importPath: importPathAbsolute } = importData;
68
69
  const filePathAbsoluteFilesystem = (0, resolveImportPath_js_1.resolveImportPath)(importData, configFilePath);
69
70
  (0, resolveImportPath_js_1.assertImportPath)(filePathAbsoluteFilesystem, importData, configFilePath);
70
- warnUserLandExtension(importPath, configFilePath);
71
- // - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
72
- // - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsoluteFilesystem for added clarity
73
- const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir);
74
- const filePathAbsoluteVite = filePathRelativeToUserRootDir ?? importPath;
75
- extendsConfigFiles.push({
76
- filePathAbsoluteFilesystem,
77
- filePathAbsoluteVite,
78
- filePathRelativeToUserRootDir,
79
- filePathToShowToUser: filePathAbsoluteVite,
80
- importPathAbsolute: importPath
81
- });
71
+ warnUserLandExtension(importPathAbsolute, configFilePath);
72
+ const filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteFilesystem, userRootDir, importPathAbsolute });
73
+ extendsConfigFiles.push(filePath);
82
74
  });
83
75
  const extendsConfigs = [];
84
76
  await Promise.all(extendsConfigFiles.map(async (configFilePath) => {
@@ -89,19 +81,12 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
89
81
  const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
90
82
  return { extendsConfigs, extendsFilePaths };
91
83
  }
92
- function determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir) {
93
- (0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
94
- (0, utils_js_1.assertPosixPath)(userRootDir);
95
- if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
96
- return null;
97
- }
98
- let filePathRelativeToUserRootDir = filePathAbsoluteFilesystem.slice(userRootDir.length);
99
- if (!filePathRelativeToUserRootDir.startsWith('/'))
100
- filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
101
- return filePathRelativeToUserRootDir;
102
- }
103
84
  function warnUserLandExtension(importPath, configFilePath) {
104
- (0, utils_js_1.assertWarning)((0, utils_js_1.isNpmPackageImport)(importPath), `${configFilePath.filePathToShowToUser} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.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 });
85
+ // We preserve this feature because we may need it for eject
86
+ (0, utils_js_1.assertWarning)((0, utils_js_1.isNpmPackageImport)(importPath, {
87
+ // Vike config files don't support path aliases. (If they do one day, then Vike will/should be able to resolve path aliases.)
88
+ cannotBePathAlias: true
89
+ }) || importPath.includes('/node_modules/'), `${configFilePath.filePathToShowToUser} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.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 });
105
90
  }
106
91
  function getExtendsImportData(configFileExports, configFilePath) {
107
92
  const { filePathToShowToUser } = configFilePath;
@@ -8,6 +8,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
8
8
  const utils_js_1 = require("../../../../utils.js");
9
9
  const transformFileImports_js_1 = require("./transformFileImports.js");
10
10
  const path_1 = __importDefault(require("path"));
11
+ const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
11
12
  const filesEnvMap = new Map();
12
13
  function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
13
14
  if (typeof configValue !== 'string')
@@ -19,50 +20,45 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
19
20
  const filePathAbsoluteFilesystem = resolveImportPath(importData, importerFilePath);
20
21
  assertFileEnv(filePathAbsoluteFilesystem ?? importPath, configEnv, configName);
21
22
  const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
23
+ let filePath;
22
24
  if (importPath.startsWith('.')) {
23
25
  // We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
24
26
  // ```
25
27
  // [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
26
28
  // ```
27
29
  assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
28
- const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
29
- const filePath = {
30
- filePathAbsoluteFilesystem,
31
- filePathRelativeToUserRootDir,
32
- filePathAbsoluteVite: filePathRelativeToUserRootDir,
33
- filePathToShowToUser: filePathRelativeToUserRootDir,
34
- importPathAbsolute: null
35
- };
36
- return {
37
- ...filePath,
38
- fileExportName: exportName,
39
- fileExportPathToShowToUser
40
- };
30
+ const filePathAbsoluteUserRootDir = resolveImportPath_absoluteUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
31
+ filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir });
41
32
  }
42
33
  else {
43
34
  // importPath can be:
44
35
  // - an npm package import
45
36
  // - a path alias
46
- const filePath = {
47
- filePathAbsoluteFilesystem,
48
- filePathRelativeToUserRootDir: null,
49
- filePathAbsoluteVite: importPath,
50
- filePathToShowToUser: importPath,
51
- importPathAbsolute: importPath
52
- };
53
- return {
54
- ...filePath,
55
- fileExportName: exportName,
56
- fileExportPathToShowToUser
57
- };
37
+ if (filePathAbsoluteFilesystem) {
38
+ filePath = (0, getFilePath_js_1.getFilePathResolved)({
39
+ userRootDir,
40
+ filePathAbsoluteFilesystem,
41
+ importPathAbsolute: importPath
42
+ });
43
+ }
44
+ else {
45
+ filePath = (0, getFilePath_js_1.getFilePathUnresolved)({
46
+ importPathAbsolute: importPath
47
+ });
48
+ }
58
49
  }
50
+ return {
51
+ ...filePath,
52
+ fileExportName: exportName,
53
+ fileExportPathToShowToUser
54
+ };
59
55
  }
60
56
  exports.resolveImport = resolveImport;
61
- function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
57
+ function resolveImportPath_absoluteUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
62
58
  (0, utils_js_1.assertPosixPath)(userRootDir);
63
- let filePathRelativeToUserRootDir;
59
+ let filePathAbsoluteUserRootDir;
64
60
  if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
65
- filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
61
+ filePathAbsoluteUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
66
62
  }
67
63
  else {
68
64
  (0, utils_js_1.assertUsage)(false, `${configFilePath.filePathToShowToUser} imports from a relative path ${picocolors_1.default.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
@@ -71,20 +67,21 @@ function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, imp
71
67
  // assert(filePathAbsoluteFilesystem.startsWith('/'))
72
68
  // filePath = `/@fs${filePathAbsoluteFilesystem}`
73
69
  // /*/
74
- // filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem)
75
- // assert(filePathRelativeToUserRootDir.startsWith('../'))
76
- // filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir
70
+ // filePathAbsoluteUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem)
71
+ // assert(filePathAbsoluteUserRootDir.startsWith('../'))
72
+ // filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir
77
73
  // //*/
78
74
  }
79
- (0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
80
- (0, utils_js_1.assert)(filePathRelativeToUserRootDir.startsWith('/'));
81
- return filePathRelativeToUserRootDir;
75
+ (0, utils_js_1.assertPosixPath)(filePathAbsoluteUserRootDir);
76
+ (0, utils_js_1.assert)(filePathAbsoluteUserRootDir.startsWith('/'));
77
+ return filePathAbsoluteUserRootDir;
82
78
  }
83
79
  function resolveImportPath(importData, importerFilePath) {
84
80
  const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
85
81
  (0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
86
82
  const cwd = path_1.default.posix.dirname(importerFilePathAbsolute);
87
- // 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
83
+ // We can't use import.meta.resolve() as of Junary 2023 (and probably for a lot longer)
84
+ // 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
88
85
  // filePathAbsoluteFilesystem is expected to be null when importData.importPath is a Vite path alias
89
86
  const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolve)(importData.importPath, cwd);
90
87
  return filePathAbsoluteFilesystem;
@@ -16,13 +16,12 @@ require("source-map-support/register.js");
16
16
  (0, utils_js_1.assertIsNotProductionRuntime)();
17
17
  const debug = (0, utils_js_1.createDebugger)('vike:pointer-imports');
18
18
  async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
19
- const { filePathAbsoluteFilesystem } = filePath;
19
+ const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
20
20
  const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
21
- const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
22
- (0, utils_js_1.assertUsage)((0, utils_js_1.isJavaScriptFile)(filePathAbsoluteFilesystem), `${filePathToShowToUser2} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
21
+ (0, utils_js_1.assertUsage)((0, utils_js_1.isJavaScriptFile)(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
23
22
  const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
24
23
  if (isHeader) {
25
- (0, utils_js_1.assertWarning)(false, `${picocolors_1.default.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUser2} to ${removeHeaderFileExtension(filePathToShowToUser2)} is usually enough, although you may occasionally need to use ${picocolors_1.default.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
24
+ (0, utils_js_1.assertWarning)(false, `${picocolors_1.default.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${picocolors_1.default.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
26
25
  }
27
26
  if (isConfigFile === 'is-extension-config' && !isHeader && fileExtension.endsWith('js')) {
28
27
  // This doesn't track dependencies => we should never use this for user land configs
@@ -38,28 +37,27 @@ async function transpileAndExecuteFile(filePath, userRootDir, isConfigFile) {
38
37
  }
39
38
  exports.transpileAndExecuteFile = transpileAndExecuteFile;
40
39
  async function transpileFile(filePath, transformImports, userRootDir) {
41
- const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
42
- const { filePathAbsoluteFilesystem } = filePath;
40
+ const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
43
41
  (0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
44
42
  getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
45
43
  if (debug.isEnabled)
46
- debug('transpile', filePathToShowToUser2);
44
+ debug('transpile', filePathToShowToUserResolved);
47
45
  let { code, pointerImports } = await transpileWithEsbuild(filePath, userRootDir, transformImports);
48
46
  if (debug.isEnabled)
49
- debug(`code, post esbuild (${filePathToShowToUser2})`, code);
47
+ debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
50
48
  let isImportTransformed = false;
51
49
  if (transformImports) {
52
- const codeMod = (0, transformFileImports_js_1.transformFileImports)(code, filePathToShowToUser2, pointerImports);
50
+ const codeMod = (0, transformFileImports_js_1.transformFileImports)(code, filePathToShowToUserResolved, pointerImports);
53
51
  if (codeMod) {
54
52
  code = codeMod;
55
53
  isImportTransformed = true;
56
54
  if (debug.isEnabled)
57
- debug(`code, post transformImports() (${filePathToShowToUser2})`, code);
55
+ debug(`code, post transformImports() (${filePathToShowToUserResolved})`, code);
58
56
  }
59
57
  }
60
58
  if (!isImportTransformed) {
61
59
  if (debug.isEnabled)
62
- debug(`code, no transformImports() (${filePathToShowToUser2})`);
60
+ debug(`code, no transformImports() (${filePathToShowToUserResolved})`);
63
61
  }
64
62
  return code;
65
63
  }
@@ -75,7 +73,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
75
73
  outfile: path_1.default.posix.join(
76
74
  // Needed for correct inline source map
77
75
  entryFileDir,
78
- // `write: false` => no file is actually be emitted
76
+ // `write: false` => no file is actually emitted
79
77
  'NEVER_EMITTED.js'),
80
78
  logLevel: 'silent',
81
79
  format: 'esm',
@@ -107,10 +105,10 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
107
105
  return;
108
106
  if (args.pluginData?.[useEsbuildResolver])
109
107
  return;
110
- const isImportAbsolute = !args.path.startsWith('.');
111
108
  const { path, ...opts } = args;
112
109
  opts.pluginData = { [useEsbuildResolver]: true };
113
110
  const resolved = await build.resolve(path, opts);
111
+ resolved.path = (0, utils_js_1.toPosixPath)(resolved.path);
114
112
  // vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
115
113
  // - This is temporary, see comment below.
116
114
  const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
@@ -125,14 +123,15 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
125
123
  // - For example if esbuild cannot resolve a path alias while Vite can.
126
124
  // - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
127
125
  resolved.errors.length > 0;
128
- pointerImports_[args.path] = isPointerImport;
126
+ pointerImports_[resolved.path] = isPointerImport;
127
+ (0, utils_js_1.assertPosixPath)(resolved.path);
129
128
  const isExternal = isPointerImport ||
130
- // npm package imports that aren't pointer imports (e.g. Vite plugin import)
131
- isImportAbsolute;
129
+ // npm package imports that aren't pointer imports (e.g. importing a Vite plugin)
130
+ resolved.path.includes('/node_modules/');
132
131
  if (debug.isEnabled)
133
132
  debug('onResolved()', { args, resolved, isPointerImport, isExternal });
134
133
  if (isExternal) {
135
- return { external: true, path: args.path };
134
+ return { external: true, path: resolved.path };
136
135
  }
137
136
  else {
138
137
  return resolved;
@@ -298,19 +297,12 @@ function triggerPrepareStackTrace(err) {
298
297
  }
299
298
  }
300
299
  function getErrIntroMsg(operation, filePath) {
301
- const filePathToShowToUser2 = getFilePathToShowToUser2(filePath);
300
+ const { filePathToShowToUserResolved } = filePath;
302
301
  const msg = [
303
302
  // prettier ignore
304
303
  picocolors_1.default.red(`Failed to ${operation}`),
305
- picocolors_1.default.bold(picocolors_1.default.red(filePathToShowToUser2)),
304
+ picocolors_1.default.bold(picocolors_1.default.red(filePathToShowToUserResolved)),
306
305
  picocolors_1.default.red(`because:`)
307
306
  ].join(' ');
308
307
  return msg;
309
308
  }
310
- /** `filePath.filePathToShowToUser` may show the import path of a package, use `filePathToShowToUser2` instead always show a file path instead. */
311
- function getFilePathToShowToUser2(filePath) {
312
- const { filePathAbsoluteFilesystem, filePathRelativeToUserRootDir } = filePath;
313
- const filePathToShowToUser2 = filePathRelativeToUserRootDir || filePathAbsoluteFilesystem;
314
- (0, utils_js_1.assert)(filePathToShowToUser2);
315
- return filePathToShowToUser2;
316
- }
@@ -20,7 +20,7 @@ const crawlPlusFiles_js_1 = require("./getVikeConfig/crawlPlusFiles.js");
20
20
  const getConfigFileExport_js_1 = require("./getConfigFileExport.js");
21
21
  const loadFileAtConfigTime_js_1 = require("./getVikeConfig/loadFileAtConfigTime.js");
22
22
  const resolveImportPath_js_1 = require("./getVikeConfig/resolveImportPath.js");
23
- const resolveFilePath_js_1 = require("./getVikeConfig/resolveFilePath.js");
23
+ const getFilePath_js_1 = require("../../../shared/getFilePath.js");
24
24
  (0, utils_js_1.assertIsNotProductionRuntime)();
25
25
  let devServerIsCorrupt = false;
26
26
  let wasConfigInvalid = null;
@@ -65,7 +65,7 @@ async function handleReloadSideEffects() {
65
65
  }
66
66
  }
67
67
  }
68
- async function getVikeConfig(config, isDev, tolerateInvalidConfig = false) {
68
+ async function getVikeConfig(config, isDev, tolerateInvalidConfig) {
69
69
  const { outDirRoot } = (0, utils_js_1.getOutDirs)(config);
70
70
  const userRootDir = config.root;
71
71
  if (!vikeConfigPromise) {
@@ -97,11 +97,11 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
97
97
  await Promise.all([
98
98
  // Config files
99
99
  ...configFiles.map(async (filePath) => {
100
- const { filePathRelativeToUserRootDir } = filePath;
101
- (0, utils_js_1.assert)(filePathRelativeToUserRootDir);
100
+ const { filePathAbsoluteUserRootDir } = filePath;
101
+ (0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
102
102
  const { configFile, extendsConfigs } = await (0, loadFileAtConfigTime_js_1.loadConfigFile)(filePath, userRootDir, [], false);
103
- (0, utils_js_1.assert)(filePath.filePathRelativeToUserRootDir);
104
- const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir);
103
+ (0, utils_js_1.assert)(filePath.filePathAbsoluteUserRootDir);
104
+ const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathAbsoluteUserRootDir);
105
105
  const interfaceFile = getInterfaceFileFromConfigFile(configFile, false, locationId);
106
106
  interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
107
107
  interfaceFilesByLocationId[locationId].push(interfaceFile);
@@ -150,11 +150,11 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
150
150
  }),
151
151
  // Value files
152
152
  ...valueFiles.map(async (filePath) => {
153
- const { filePathRelativeToUserRootDir } = filePath;
154
- (0, utils_js_1.assert)(filePathRelativeToUserRootDir);
155
- const configName = getConfigName(filePathRelativeToUserRootDir);
153
+ const { filePathAbsoluteUserRootDir } = filePath;
154
+ (0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
155
+ const configName = getConfigName(filePathAbsoluteUserRootDir);
156
156
  (0, utils_js_1.assert)(configName);
157
- const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir);
157
+ const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathAbsoluteUserRootDir);
158
158
  const interfaceFile = {
159
159
  locationId,
160
160
  filePath,
@@ -353,9 +353,9 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
353
353
  const interfaceFilesGlobalPaths = [];
354
354
  (0, utils_js_1.objectEntries)(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
355
355
  (0, utils_js_1.assert)((0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds));
356
- interfaceFiles.forEach(({ filePath: { filePathRelativeToUserRootDir } }) => {
357
- if (filePathRelativeToUserRootDir) {
358
- interfaceFilesGlobalPaths.push(filePathRelativeToUserRootDir);
356
+ interfaceFiles.forEach(({ filePath: { filePathAbsoluteUserRootDir } }) => {
357
+ if (filePathAbsoluteUserRootDir) {
358
+ interfaceFilesGlobalPaths.push(filePathAbsoluteUserRootDir);
359
359
  }
360
360
  });
361
361
  });
@@ -464,10 +464,10 @@ async function resolveConfigValueSources(configName, configDef, interfaceFilesRe
464
464
  }
465
465
  function makeOrderDeterministic(interfaceFile1, interfaceFile2) {
466
466
  return (0, utils_js_1.lowerFirst)((interfaceFile) => {
467
- const { filePathRelativeToUserRootDir } = interfaceFile.filePath;
467
+ const { filePathAbsoluteUserRootDir } = interfaceFile.filePath;
468
468
  (0, utils_js_1.assert)(isInterfaceFileUserLand(interfaceFile));
469
- (0, utils_js_1.assert)(filePathRelativeToUserRootDir);
470
- return filePathRelativeToUserRootDir.length;
469
+ (0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
470
+ return filePathAbsoluteUserRootDir.length;
471
471
  })(interfaceFile1, interfaceFile2);
472
472
  }
473
473
  function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName) {
@@ -541,6 +541,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
541
541
  configName !== 'extends') {
542
542
  if (import_.filePathAbsoluteFilesystem) {
543
543
  (0, utils_js_1.assert)((0, utils_js_1.hasProp)(import_, 'filePathAbsoluteFilesystem', 'string')); // Help TS
544
+ (0, utils_js_1.assert)((0, utils_js_1.hasProp)(import_, 'filePathToShowToUserResolved', 'string')); // Help TS
544
545
  const fileExport = await (0, loadFileAtConfigTime_js_1.loadImportedFile)(import_, userRootDir, importedFilesLoaded);
545
546
  configValueSource.value = fileExport;
546
547
  }
@@ -744,7 +745,7 @@ function getComputed(configValueSources, configDefinitions) {
744
745
  }
745
746
  async function findPlusFiles(userRootDir, outDirRoot, isDev) {
746
747
  const files = await (0, crawlPlusFiles_js_1.crawlPlusFiles)(userRootDir, outDirRoot, isDev);
747
- const plusFiles = files.map(({ filePathRelativeToUserRootDir }) => (0, resolveFilePath_js_1.resolveFilePathRelativeToUserRootDir)(filePathRelativeToUserRootDir, userRootDir));
748
+ const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir }));
748
749
  return plusFiles;
749
750
  }
750
751
  function getConfigName(filePath) {
@@ -834,9 +835,9 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
834
835
  const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configFilesystemRoutingRoot);
835
836
  (0, utils_js_1.assertUsage)(typeof value === 'string', `${configDefinedAt} should be a string`);
836
837
  (0, utils_js_1.assertUsage)(value.startsWith('/'), `${configDefinedAt} is ${picocolors_1.default.cyan(value)} but it should start with a leading slash ${picocolors_1.default.cyan('/')}`);
837
- const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.definedAt;
838
- (0, utils_js_1.assert)(filePathRelativeToUserRootDir);
839
- const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir));
838
+ const { filePathAbsoluteUserRootDir } = configFilesystemRoutingRoot.definedAt;
839
+ (0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
840
+ const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(filePathAbsoluteUserRootDir));
840
841
  const after = value;
841
842
  const filesystemRoutingRootEffect = { before, after };
842
843
  return { filesystemRoutingRootEffect, filesystemRoutingRootDefinedAt: configDefinedAt };
@@ -1012,7 +1013,11 @@ function sortConfigValueSources(configValueSources, locationIdPage) {
1012
1013
  // Sort after whether the config value was defined by an npm package
1013
1014
  .sort((0, utils_js_1.makeFirst)(([, [source]]) => {
1014
1015
  const { importPathAbsolute } = source.definedAt;
1015
- return !!importPathAbsolute && (0, utils_js_1.isNpmPackageImport)(importPathAbsolute);
1016
+ return (!!importPathAbsolute &&
1017
+ (0, utils_js_1.isNpmPackageImport)(importPathAbsolute, {
1018
+ // Vike config files don't support path aliases. (If they do one day, then Vike will/should be able to resolve path aliases.)
1019
+ cannotBePathAlias: true
1020
+ }));
1016
1021
  }))
1017
1022
  // Sort after the filesystem inheritance of the config value
1018
1023
  .sort(([, [source1]], [, [source2]]) => (0, utils_js_1.reverse)((0, filesystemRouting_js_1.sortAfterInheritanceOrder)(source1.locationId, source2.locationId, locationIdPage))));
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.cleanFilePathUnkown = exports.getFilePathToShowToUserFromUnkown = exports.getModuleFilePath = exports.getFilePathUnresolved = exports.getFilePathResolved = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const utils_js_1 = require("../utils.js");
9
+ function getFilePathUnresolved({ importPathAbsolute }) {
10
+ return getFilePath({ importPathAbsolute, filePathAbsoluteUserRootDir: null });
11
+ }
12
+ exports.getFilePathUnresolved = getFilePathUnresolved;
13
+ function getFilePathResolved(args) {
14
+ const { userRootDir } = args;
15
+ const importPathAbsolute = args.importPathAbsolute ?? null;
16
+ let filePathAbsoluteFilesystem;
17
+ let filePathAbsoluteUserRootDir;
18
+ if ('filePathAbsoluteFilesystem' in args) {
19
+ filePathAbsoluteFilesystem = args.filePathAbsoluteFilesystem;
20
+ filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir });
21
+ }
22
+ else {
23
+ filePathAbsoluteUserRootDir = args.filePathAbsoluteUserRootDir;
24
+ filePathAbsoluteFilesystem = getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir });
25
+ }
26
+ let filePath;
27
+ const common = {
28
+ filePathAbsoluteUserRootDir,
29
+ importPathAbsolute,
30
+ userRootDir
31
+ };
32
+ if (importPathAbsolute) {
33
+ filePath = getFilePath({
34
+ ...common,
35
+ importPathAbsolute
36
+ });
37
+ }
38
+ else {
39
+ (0, utils_js_1.assert)(filePathAbsoluteUserRootDir);
40
+ filePath = getFilePath({
41
+ ...common,
42
+ filePathAbsoluteUserRootDir
43
+ });
44
+ }
45
+ (0, utils_js_1.assert)(filePathAbsoluteFilesystem);
46
+ (0, utils_js_1.assertPathIsFilesystemAbsolute)(filePathAbsoluteFilesystem);
47
+ const filePathToShowToUserResolved = filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
48
+ (0, utils_js_1.assert)(filePathToShowToUserResolved);
49
+ const filePathResolved = {
50
+ ...filePath,
51
+ filePathAbsoluteFilesystem,
52
+ filePathToShowToUserResolved
53
+ };
54
+ return filePathResolved;
55
+ }
56
+ exports.getFilePathResolved = getFilePathResolved;
57
+ function getFilePath(args) {
58
+ let filePathAbsoluteVite;
59
+ if (args.filePathAbsoluteUserRootDir !== null) {
60
+ filePathAbsoluteVite = args.filePathAbsoluteUserRootDir;
61
+ }
62
+ else {
63
+ (0, utils_js_1.assert)(args.importPathAbsolute !== null); // Help TS
64
+ filePathAbsoluteVite = args.importPathAbsolute;
65
+ }
66
+ const filePathToShowToUser = filePathAbsoluteVite;
67
+ (0, utils_js_1.assert)(filePathToShowToUser);
68
+ return {
69
+ ...args,
70
+ filePathAbsoluteFilesystem: null,
71
+ filePathAbsoluteVite,
72
+ filePathToShowToUser
73
+ };
74
+ }
75
+ function getFilePathAbsoluteUserFilesystem({ filePathAbsoluteUserRootDir, userRootDir }) {
76
+ (0, utils_js_1.assertPosixPath)(filePathAbsoluteUserRootDir);
77
+ (0, utils_js_1.assertPosixPath)(userRootDir);
78
+ (0, utils_js_1.assertPathIsFilesystemAbsolute)(userRootDir);
79
+ const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathAbsoluteUserRootDir);
80
+ (0, utils_js_1.assertPathIsFilesystemAbsolute)(userRootDir);
81
+ return filePathAbsoluteFilesystem;
82
+ }
83
+ function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir }) {
84
+ (0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
85
+ (0, utils_js_1.assertPosixPath)(userRootDir);
86
+ (0, utils_js_1.assertPathIsFilesystemAbsolute)(filePathAbsoluteFilesystem);
87
+ (0, utils_js_1.assertPathIsFilesystemAbsolute)(userRootDir);
88
+ const filePathRelative = path_1.default.posix.relative(userRootDir, filePathAbsoluteFilesystem);
89
+ if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
90
+ (0, utils_js_1.assert)(filePathRelative.startsWith('../'));
91
+ return null;
92
+ }
93
+ (0, utils_js_1.assert)(!filePathRelative.startsWith('.') && !filePathRelative.startsWith('/'));
94
+ const filePathAbsoluteUserRootDir = `/${filePathRelative}`;
95
+ (0, utils_js_1.assert)(filePathAbsoluteUserRootDir === getFilePathAbsoluteUserRootDir2(filePathAbsoluteFilesystem, userRootDir));
96
+ return filePathAbsoluteUserRootDir;
97
+ }
98
+ function getModuleFilePath(moduleId, config) {
99
+ const userRootDir = config.root;
100
+ (0, utils_js_1.assertPosixPath)(moduleId);
101
+ (0, utils_js_1.assertPosixPath)(userRootDir);
102
+ const filePathAbsoluteFilesystem = cleanModuleId(moduleId);
103
+ (0, utils_js_1.assertPathIsFilesystemAbsolute)(filePathAbsoluteFilesystem);
104
+ const filePath = getFilePathResolved({ filePathAbsoluteFilesystem, userRootDir });
105
+ return filePath.filePathToShowToUserResolved;
106
+ }
107
+ exports.getModuleFilePath = getModuleFilePath;
108
+ function getFilePathToShowToUserFromUnkown(
109
+ // We don't have any guarentee about filePath, e.g. about whether is filePathAbsoluteFilesystem or filePathAbsoluteUserRootDir
110
+ filePathUnkown, userRootDir) {
111
+ (0, utils_js_1.assertPosixPath)(userRootDir);
112
+ (0, utils_js_1.assertPathIsFilesystemAbsolute)(userRootDir);
113
+ filePathUnkown = cleanFilePathUnkown(filePathUnkown);
114
+ if (!filePathUnkown.startsWith(userRootDir)) {
115
+ return filePathUnkown;
116
+ }
117
+ else {
118
+ return getFilePathAbsoluteUserRootDir2(filePathUnkown, userRootDir);
119
+ }
120
+ }
121
+ exports.getFilePathToShowToUserFromUnkown = getFilePathToShowToUserFromUnkown;
122
+ function getFilePathAbsoluteUserRootDir2(filePathAbsoluteFilesystem, userRootDir) {
123
+ (0, utils_js_1.assert)(filePathAbsoluteFilesystem.startsWith(userRootDir));
124
+ let filePathAbsoluteUserRootDir = filePathAbsoluteFilesystem.slice(userRootDir.length);
125
+ if (!filePathAbsoluteUserRootDir.startsWith('/'))
126
+ filePathAbsoluteUserRootDir = '/' + filePathAbsoluteUserRootDir;
127
+ return filePathAbsoluteUserRootDir;
128
+ }
129
+ function cleanFilePathUnkown(filePathUnknown) {
130
+ filePathUnknown = (0, utils_js_1.toPosixPath)(filePathUnknown);
131
+ filePathUnknown = cleanModuleId(filePathUnknown);
132
+ return filePathUnknown;
133
+ }
134
+ exports.cleanFilePathUnkown = cleanFilePathUnkown;
135
+ function cleanModuleId(moduleId) {
136
+ // remove query
137
+ const parts = moduleId.split('?');
138
+ if (parts.length > 1)
139
+ parts.pop();
140
+ (0, utils_js_1.assert)(parts.length >= 1);
141
+ return parts.join('?');
142
+ }
@@ -9,6 +9,7 @@ exports.getPrettyErrMessage = exports.isEquivalentErrorWithCodeSnippet = exports
9
9
  // Copied & adapted from https://github.com/vitejs/vite/blob/9c114c5c72a6af87e3330d5573362554b4511265/packages/vite/src/node/server/middlewares/error.ts
10
10
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
11
11
  const utils_js_1 = require("../../utils.js");
12
+ const getFilePath_js_1 = require("../getFilePath.js");
12
13
  function isErrorWithCodeSnippet(err) {
13
14
  if (!(0, utils_js_1.isObject)(err)) {
14
15
  return false;
@@ -48,7 +49,7 @@ function getPrettyErrorWithCodeSnippet(err, userRootDir) {
48
49
  let { id, frame } = err;
49
50
  const msgFirstLine = [
50
51
  picocolors_1.default.red('Failed to transpile'),
51
- picocolors_1.default.bold(picocolors_1.default.red((0, utils_js_1.getFilePathRelativeToUserRootDir)(normalizeId(id), userRootDir))),
52
+ picocolors_1.default.bold(picocolors_1.default.red((0, getFilePath_js_1.getFilePathToShowToUserFromUnkown)(id, userRootDir))),
52
53
  picocolors_1.default.red('because:')
53
54
  ].join(' ');
54
55
  const errMsg = getPrettyErrMessage(err);
@@ -88,7 +89,7 @@ function getPrettyErrMessage(err) {
88
89
  // Remove "/home/rom/code/vike/examples/react-full/components/Counter.tsx:1:8:" (redundant since we already print the filename)
89
90
  const pos = /(?:\:\d+|)/;
90
91
  errMsg = errMsg.split(reg([id, pos, pos, trail], 'gi')).join('');
91
- errMsg = errMsg.split(reg([normalizeId(id), pos, pos, trail], 'gi')).join('');
92
+ errMsg = errMsg.split(reg([(0, getFilePath_js_1.cleanFilePathUnkown)(id), pos, pos, trail], 'gi')).join('');
92
93
  // Remove "ERROR:" (useless)
93
94
  errMsg = errMsg.split(reg(['ERROR:', trail])).join('');
94
95
  // Remove "Internal server error:" (useless)
@@ -160,9 +161,3 @@ exports.isEquivalentErrorWithCodeSnippet = isEquivalentErrorWithCodeSnippet;
160
161
  function isDefinedAndSame(val1, val2) {
161
162
  return val1 && val1 === val2;
162
163
  }
163
- function normalizeId(id) {
164
- id = (0, utils_js_1.toPosixPath)(id);
165
- // remove query
166
- id = id.split('?')[0];
167
- return id;
168
- }
@@ -23,6 +23,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
23
23
  const isNewError_js_1 = require("../../runtime/renderPage/isNewError.js");
24
24
  const isConfigInvalid_js_1 = require("../../runtime/renderPage/isConfigInvalid.js");
25
25
  const loggerProd_js_1 = require("../../runtime/renderPage/loggerProd.js");
26
+ const executeHook_js_1 = require("../../../shared/hooks/executeHook.js");
26
27
  (0, utils_js_1.assertIsNotProductionRuntime)();
27
28
  (0, loggerRuntime_js_1.overwriteRuntimeProductionLogger)(logRuntimeError, logRuntimeInfo);
28
29
  (0, utils_js_1.overwriteAssertProductionLogger)(assertLogger);
@@ -99,7 +100,7 @@ function logErr(err, httpRequestId = null, errorComesFromVite) {
99
100
  }
100
101
  }
101
102
  // Needs to be after assertion messages handling, because user hooks may throw an assertion error
102
- const hook = (0, utils_js_1.isUserHookError)(err);
103
+ const hook = (0, executeHook_js_1.isUserHookError)(err);
103
104
  if (hook) {
104
105
  const { hookName, hookFilePath } = hook;
105
106
  (0, log_js_1.logWithVikeTag)(picocolors_1.default.red(`Following error was thrown by the ${hookName}() hook defined at ${hookFilePath}`), 'error', category);
@@ -22,7 +22,6 @@ const onLoad_js_1 = require("./onLoad.js");
22
22
  __exportStar(require("../runtime/utils.js"), exports);
23
23
  // Utils only needed by `plugin/*`
24
24
  __exportStar(require("../../utils/viteIsSSR.js"), exports);
25
- __exportStar(require("../../utils/getFilePathAbsolute.js"), exports);
26
25
  __exportStar(require("../../utils/requireResolve.js"), exports);
27
26
  __exportStar(require("../../utils/arrayIncludes.js"), exports);
28
27
  __exportStar(require("../../utils/isDev.js"), exports);
@@ -42,3 +41,4 @@ __exportStar(require("../../utils/injectRollupInputs.js"), exports);
42
41
  __exportStar(require("../../utils/humanizeTime.js"), exports);
43
42
  __exportStar(require("../../utils/pLimit.js"), exports);
44
43
  __exportStar(require("../../utils/assertVersion.js"), exports);
44
+ __exportStar(require("../../utils/assertPathIsFilesystemAbsolute.js"), exports);