pathpida icon indicating copy to clipboard operation
pathpida copied to clipboard

refactor parseAppDir.ts and fix issue 197

Open lp0ql opened this issue 6 months ago • 0 comments

Original (日本語)

変更の種類 (Types of changes)

  • [x] バグ修正
    • resolves #197

変更内容 (Changes)

  • parseAppDir.ts を文字列連結中心の実装から、状態を保持するクラス OutputObject に移行。
    • 目的: 離れたパスにあるルートグループを安全にマージしやすくするため。
  • テスト追加
    • Issue #197 を再現するテストケースを追加。

追加の背景・補足 (Additional context)

問題を解決しつつ、無理のない範囲で既存の出力と同じになるように心がけています。 (出力の並び順など)

背景

既存実装ではルートグループのマージが困難だったため、クラス化しました。 クラス内で objectKey を管理し、同一レベルに同じキーが重複出力される問題を解消しました。

副作用

  • 生成される型定義の末尾の , の有無が一部変わります。
-    }),
+    })

, が必須の箇所では正しく出力されていることを確認したため、追加修正は行っていません。

知識

parseAppDir.ts 以外のファイルについてあまり理解できていません。🙇‍♂️

テストのパス状況

  • テストは,の差分を除きパスしています。

コミュニティノート (Community note)

賛同される方は :+1: リアクションで Upvote をお願いします。


Types of changes

  • [x] Bug fix
    • resolves #197

Changes

  • Refactored parseAppDir.ts from a string-concatenation implementation to a stateful OutputObject class.
    • Purpose: To safely merge route groups that reside in different paths.
  • Tests
    • Added a test case that reproduces issue #197.

Additional context

The fix keeps the generated output identical to the previous version wherever reasonably possible—for example, it preserves the original ordering of entries in the output.

Background

Because the previous implementation made it difficult to merge route groups, the logic was converted to a class-based design.
objectKey is now managed inside the class to eliminate duplicate keys at the same level.

Side effects

  • The presence or absence of a trailing comma , in some generated type definitions has changed.
-    }),
+    })

Commas are still emitted where required, so no further adjustments have been made.

Known limitations

I am not very familiar with files other than parseAppDir.ts in pathpida. 🙇‍♂️

Test status

  • All tests pass except for the comma-related differences.

Community note

Please upvote with reacting as :+1: to express your agreement.

lp0ql avatar Jun 28 '25 10:06 lp0ql