Skip to content

Commit

Permalink
fix: #119
Browse files Browse the repository at this point in the history
  • Loading branch information
benawad committed Apr 27, 2020
1 parent bd49e1d commit 366f8cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/index/formatFileStructure/fixImports/makeImportPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ export const makeImportPath = (

const relativeDirectory = path.dirname(relativePath);
const ext = getExtensionFromImport(relativePath);
const fileName = path.basename(relativePath, ext);
let fileName = path.basename(relativePath, ext);

// this will cleanup index imports
// path.join("../add", ".") => "../add"
// instead of: path.join("../add", "index") => "../add/index"
if (fileName === "index") {
fileName = ".";
}

let newImport = path.join(relativeDirectory, fileName);

Expand Down
9 changes: 9 additions & 0 deletions tests/make-import-path.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { makeImportPath } from "../src/index/formatFileStructure/fixImports/makeImportPath";

describe("makeImportPath", () => {
it("../add/index => ../add", () => {
expect(makeImportPath("src/app.js", "src/add/index.js", true)).toBe(
"./add"
);
});
});

0 comments on commit 366f8cf

Please sign in to comment.