-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Sometimes my project has a structure like below:
- 📁 app/todo-list/
- 📁 _internal/
- 🗎 item-type.ts ... package private
export type ItemType = "routine" | "one-shot"
- 🗎 index.ts ... package private
export { ItemType } from "./item-type"
- 🗎 item-type.ts ... package private
- 🗎 page.tsx ...
import { ItemType } from "./_internal
- 📁 _internal/
If I want to keep item-type.ts
under _internal
and simultaneously can only be available in app/todo-list
directory, index.ts
barrel-file is necessary.
But, it's なんか嫌 for me. To deal with RSC's magic on bundling, barrel files seem confusing on illustrating in mind an import graph separated by server / client boundary. (actual case: https://qiita.com/kay-adamof/items/8d7324810dd1b051d373)
I know the best way is to prevent using _internal/
directory, which is far from encapsulation.
- 📁 app/todo-list/
- 🗎 _item-type.ts ... package private
export type ItemType = "routine" | "one-shot"
- 🗎 page.tsx ...
import { ItemType } from "./_item-type
- 🗎 _item-type.ts ... package private
But, there could be another way.
- 📁 app/todo-list/
- 📁 _internal/
- 🗎 item-type.ts ... package private (for
app/todo-list/
)export type ItemType = "routine" | "one-shot"
- 🗎 item-type.ts ... package private (for
- 🗎 page.tsx ...
import { ItemType } from "./_internal/item-type
- 📁 _internal/
0. @package ..
for each exports
by, for example, annotating ItemType
like:
// app/todo-list/_internal/item-type.ts
/**
* @package ..
*/
export type ItemType = "routine" | "one-shot"
where ..
indicates that the parent directory is the actual "package", the folder as a boundary of encapsulation.
ygkn and hayato-oshuhyo
Metadata
Metadata
Assignees
Labels
No labels