diff --git a/src/getRelativePath.js b/src/getRelativePath.js index a6466e9..5b6ee72 100644 --- a/src/getRelativePath.js +++ b/src/getRelativePath.js @@ -6,7 +6,10 @@ import { posix } from "https://deno.land/std@0.121.0/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(".")) { diff --git a/test/integration/circular.test.js b/test/integration/circular.test.js index 0320e45..65917e1 100644 --- a/test/integration/circular.test.js +++ b/test/integration/circular.test.js @@ -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 <-+ // | | @@ -377,7 +377,7 @@ Deno.test({ `, }); - const basePath = tmpDirBasePath + "A/"; + const basePath = tmpDirBasePath + "A/foo.js"; try { const importer = new Importer(basePath);