Skip to content

Commit 6d1f733

Browse files
authored
Merge pull request #200 from ysk8hori/fix-abstraction-file
fix(abstraction): abstraction でファイルを指定した際の出力でファイルがdirの見た目になるバグを修正
2 parents 48da3fe + b51e0f3 commit 6d1f733

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/graph/abstraction.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,50 @@ it('指定したディレクトリを抽象化できる', () => {
4747
}
4848
`);
4949
});
50+
51+
it('ファイル名を指定した場合、その対象はディレクトリ扱いにならない', () => {
52+
expect(
53+
abstraction(['src/a/b', 'src/a/b/c', 'src/a/a.ts'], {
54+
nodes: [
55+
{
56+
path: 'src/a/a.ts',
57+
name: 'a.ts',
58+
changeStatus: 'not_modified',
59+
},
60+
{
61+
path: 'src/a/b/b.ts',
62+
name: 'b.ts',
63+
changeStatus: 'not_modified',
64+
},
65+
{
66+
path: 'src/a/b/c/c.ts',
67+
name: 'c.ts',
68+
changeStatus: 'not_modified',
69+
},
70+
{
71+
path: 'src/a/b/c/d/d.ts',
72+
name: 'd.ts',
73+
changeStatus: 'not_modified',
74+
},
75+
],
76+
relations: [],
77+
}),
78+
).toMatchInlineSnapshot(`
79+
{
80+
"nodes": [
81+
{
82+
"changeStatus": "not_modified",
83+
"name": "a.ts",
84+
"path": "src/a/a.ts",
85+
},
86+
{
87+
"changeStatus": "not_modified",
88+
"isDirectory": true,
89+
"name": "/b",
90+
"path": "src/a/b",
91+
},
92+
],
93+
"relations": [],
94+
}
95+
`);
96+
});

src/graph/abstraction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function abstraction(
6464

6565
function abstractionNode(node: Node, absDirArrArr: string[][]): Node {
6666
const absDirArr = getAbstractionDirArr(absDirArrArr, node);
67-
if (!absDirArr) return node;
67+
if (!absDirArr || absDirArr.at(-1) === node.name) return node;
6868
return {
6969
name: `/${absDirArr.at(-1)!}`,
7070
path: abstractionPath(node.path, absDirArr),

0 commit comments

Comments
 (0)