Skip to content

Feature proposal: add notation to treat parent as the "package" (for "non-encapsulating" directories) #126

@honey32

Description

@honey32

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"
    • 🗎 page.tsx ... import { ItemType } from "./_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

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"
    • 🗎 page.tsx ... import { ItemType } from "./_internal/item-type

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions