debug-path-calculation.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const path = require('path');
  2. // Simulate the test's path calculation
  3. const reExportFile = "/tmp/test/src/models/index.ts";
  4. const targetFile = "/tmp/test/src/target/moved.ts";
  5. console.log("=== Test's Path Calculation ===");
  6. const relativePath = path.relative(path.dirname(reExportFile), targetFile).replace(/\\/g, "/");
  7. console.log("Raw relative path:", relativePath);
  8. const pathWithoutExtension = relativePath.replace(/\.ts$/, "");
  9. console.log("Path without extension:", pathWithoutExtension);
  10. const expectedPath = pathWithoutExtension.startsWith(".") ? pathWithoutExtension : "./" + pathWithoutExtension;
  11. console.log("Expected path:", expectedPath);
  12. console.log("\n=== Our ImportManager's Calculation ===");
  13. // Simulate our calculateRelativePath method
  14. const fromPath = reExportFile;
  15. const toPath = targetFile;
  16. const normalizedFromPath = fromPath.replace(/\\/g, "/");
  17. const normalizedToPath = toPath.replace(/\\/g, "/");
  18. const fromDir = path.dirname(normalizedFromPath);
  19. let ourRelativePath = path.relative(fromDir, normalizedToPath);
  20. // Normalize the resulting path
  21. ourRelativePath = ourRelativePath.replace(/\\/g, "/");
  22. // Remove file extension
  23. ourRelativePath = ourRelativePath.replace(/\.(ts|tsx|js|jsx)$/, "");
  24. // Ensure it starts with ./ or ../
  25. if (!ourRelativePath.startsWith(".")) {
  26. ourRelativePath = "./" + ourRelativePath;
  27. }
  28. console.log("Our relative path:", ourRelativePath);
  29. console.log("\n=== Comparison ===");
  30. console.log("Test expects:", `export { AppSettings } from "${expectedPath}"`);
  31. console.log("We generate:", `export { AppSettings } from "${ourRelativePath}"`);
  32. console.log("Match:", expectedPath === ourRelativePath);