Pārlūkot izejas kodu

fix: resolve relative paths in --index flag to prevent malformed config paths

When using --index with relative paths like './index/my-project', the path was
stored directly as the config filename, resulting in paths like:
/home/user/.config/qmd/./index/my-project.yml

This caused 'no such file or directory' errors. Now relative paths are resolved
and normalized by replacing path separators with underscores.
Tobi Lütke 3 mēneši atpakaļ
vecāks
revīzija
00bcfbbd34
1 mainītis faili ar 10 papildinājumiem un 1 dzēšanām
  1. 10 1
      src/collections.ts

+ 10 - 1
src/collections.ts

@@ -58,7 +58,16 @@ let currentIndexName: string = "index";
  * Config file will be ~/.config/qmd/{indexName}.yml
  */
 export function setConfigIndexName(name: string): void {
-  currentIndexName = name;
+  // Resolve relative paths to absolute paths and sanitize for use as filename
+  if (name.includes('/')) {
+    const { resolve } = require('path');
+    const { cwd } = require('process');
+    const absolutePath = resolve(cwd(), name);
+    // Replace path separators with underscores to create a valid filename
+    currentIndexName = absolutePath.replace(/\//g, '_').replace(/^_/, '');
+  } else {
+    currentIndexName = name;
+  }
 }
 
 function getConfigDir(): string {