Skip to content

Commit

Permalink
fix: Include the correct relative paths in circular import errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jespertheend committed Feb 2, 2023
1 parent 1fe5cd7 commit acb632f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/getRelativePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { posix } from "https://deno.land/[email protected]/path/mod.ts";
* @param {string} pathB
*/
export function getRelativePath(pathA, pathB) {
const a = posix.fromFileUrl(pathA);
let a = posix.fromFileUrl(pathA);
if (!a.endsWith("/")) {
a = posix.dirname(a)
}
const b = posix.fromFileUrl(pathB);
let rel = posix.relative(a, b);
if (!rel.startsWith("/") && !rel.startsWith(".")) {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/circular.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ Consider passing the following path to \`importer.makeReal()\`:
});

Deno.test({
name: "circular import with file above the base path",
name: "circular import with file above the base path, base path ends with a file name",
async fn() {
// A <-+
// | |
Expand All @@ -377,7 +377,7 @@ Deno.test({
`,
});

const basePath = tmpDirBasePath + "A/";
const basePath = tmpDirBasePath + "A/foo.js";

try {
const importer = new Importer(basePath);
Expand Down

0 comments on commit acb632f

Please sign in to comment.