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

Refactor package structures to "client" + "server" #5910

Open
2 tasks done
Josh-Cena opened this issue Nov 9, 2021 · 2 comments
Open
2 tasks done

Refactor package structures to "client" + "server" #5910

Josh-Cena opened this issue Nov 9, 2021 · 2 comments
Assignees
Labels
better engineering Not a bug or feature request proposal This issue is a proposal, usually non-trivial change

Comments

@Josh-Cena
Copy link
Collaborator

Have you read the Contributing Guidelines on issues?

Motivation

All packages should have a client and a server folder. Here's a good model: https://github.com/cmfcmf/docusaurus-search-local/tree/master/src

What's wrong with the current setup?

Currently, a plugin's server code is at the root of src/ while most client code is in src/theme/. It's hard to tell which file belongs to Node and which is Webpack, which sometimes leads to server code ending up in client. For most packages the only client folder is theme; but for plugin-content-docs, for example, it also includes client.

Moreover, this makes TS transpilation hard. Had we started with a clear client-server biclassification, a lot of the trouble in #5612 can be avoided. We can simply transpile the two folders with different TSConfigs without worrying about one's output overwriting another. As we go on to work on #5612, we can just watch changes in the client folder, because hot-reloading the server code isn't going to update the website anyways.

What does it take to separate the two folders?

Almost nothing—just move what's currently in src/ to src/server/ and what's in src/theme/ to src/client/theme/. We can also use two tsconfig files in src/server/ and src/client/ with different types (we shouldn't have @types/node in client, for example), and different .eslintconfig.

Self-service

  • I'd be willing to do some initial work on this proposal myself.
@Josh-Cena Josh-Cena added proposal This issue is a proposal, usually non-trivial change better engineering Not a bug or feature request labels Nov 9, 2021
@slorber
Copy link
Collaborator

slorber commented Nov 9, 2021

Agree we should do this, but probably not right now :)

We should also look into using exports because a plugin does not have a single entry point and in practice could also expose some client-side or server-side utils/APIs (the docs plugin does this, but in a quite messy way)

https://nodejs.org/api/packages.html#package-entry-points

@Josh-Cena
Copy link
Collaborator Author

We have different exports for reading-time: https://github.com/ngryman/reading-time/blob/dbe1d26d14892ee991a1799ca576df4de2824bf7/package.json#L5-L6

I think the general direction is we should try to eliminate all import xxx from x/lib/core/... kind of import. Since we have @theme/ aliases the client export is probably fine

@Josh-Cena Josh-Cena self-assigned this Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
better engineering Not a bug or feature request proposal This issue is a proposal, usually non-trivial change
Projects
None yet
Development

No branches or pull requests

2 participants