Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Public API in shared layer #45

Closed
EliseyMartynov opened this issue Jun 25, 2024 · 8 comments
Closed

Question: Public API in shared layer #45

EliseyMartynov opened this issue Jun 25, 2024 · 8 comments

Comments

@EliseyMartynov
Copy link
Member

EliseyMartynov commented Jun 25, 2024

Как мы знаем shared слой состоит не из слайсов, а из сегментов. Требование Public API для сегментов shared слоя не кажется избыточным? Может вы не учли исключение shared слоя при написании этого правила?

image

Sandbox: https://codesandbox.io/p/devbox/steiger-test-g4f4wp

==================================================

Из этого вытекает вторая проблема: если в shared слое т.к. он состоит из сегментов убирать Public API - в линтере нужна настройка разрешенной глубины импортов для конкретного слоя, чтобы это не выглядело нарушением Public API, e.g.:

import from 'shared/ui/card'

Воспроизвести в сэндбоксе быстро не получилось.

@EliseyMartynov EliseyMartynov changed the title Questing: Public API in shared layer Question: Public API in shared layer Jun 25, 2024
@illright
Copy link
Member

That's currently how the public API rule is formulated:

Every slice (and segment on layers that don't have slices) must contain a public API definition.

The case with shared/ui is something to discuss, because some people don't want a single index file to keep bundles lightweight. So to me, this is more the case of support several indexes if needed

@EliseyMartynov
Copy link
Member Author

shared/ui can be a really large dir. Several indexes will degrade DX in that case.

@illright
Copy link
Member

How would they degrade DX? And also what solution would you prefer?

@EliseyMartynov
Copy link
Member Author

How it would degrade - I would have to go and configure every folder in shared/ui as my multi-index entries, isnt it?

As I said in my Russian comment - configure depth may be could solve it?

@illright
Copy link
Member

I would have to go and configure every folder in shared/ui as my multi-index entries

Yes, if you want every folder in shared/ui to be an index, which I don't think is a great idea, because it kind of defeats the purpose of Public API

configure depth may be could solve it?

This rule is concerned with the presence of public API, so I would want any modifications to this rule to be modifications to the rules of public API. Currently, the public API is required on every slice and on every segment in Shared. If this requirement doesn't work well for your project, then we can discuss how we can change the definition of what a public API is

@vdanchenkov
Copy link

vdanchenkov commented Jun 28, 2024

I have another issue, but it's closely related to this discussion.

✘ Forbidden sidestep of public API when importing "shared/ui/form/index.tsx" from "features/my-feature/ui/Component.tsx". // no-public-api-sidestep

As you can see I have segment shared/ui with public API and shared/ui/form with public API. I see that nested segments looks strange, but looks like some people use it that way.

shared/ui/form contains several controls specific to usage inside forms.

So, is it a bug, should we allow usage of deep index.ts?

Or I have to flatten segments to have shared/ui and shared/form?

@illright
Copy link
Member

With Steiger 0.5.0, the public API rule was relaxed in shared/ui and shared/lib — you can now also import from shared/ui/card, for example, in addition to the regular import from shared/ui

@illright
Copy link
Member

@vdanchenkov your case should now be possible as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants