docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

[Proposal] Change design of package @docusaurus/core.

Open BogdanDor opened this issue 5 years ago • 3 comments

Change design of package @docusaurus/core. This code has implicit dependencies and is hard for newbs. Logic this package interwined with infrastructure code. Modules interact with file system, network and third-party libraries. Tests also have problems. By tests hard understand what does package. Tests is written for individuals files and they probably check implementation, not interface, that user interact with one.

💥 Proposal

To fix this problems, propose remove external dependencies from modules from folder commands. And later move features to custom webpack loaders and plugins. Steps necessary to perform for that.

  1. Write integration tests. Tests should checks commands corecteness interact with external environment.

  2. Replace code that interact with fs, network and 3rd-party libraries to wrappers.

  3. Change requirements for commands. That modules shouldn't interact with infrastructure now, only call explicit injected functions. Move wrappers to individual files. Pass every dependency explicit to constructor. In tests instead of external dependencies use mocks.

  4. Source tests could be removed because module tests from commands and integration tests should cover all possible cases.

  5. Features from commands step-by-step move to webpack loaders and plugins. Requirements and сonsequently tests should change also step-by-step. Finally, instead of methods createConfig and modules commands should be files with webpack config.

Have you read the Contributing Guidelines on issues?

Yes

BogdanDor avatar Mar 08 '21 16:03 BogdanDor

Sorry but I have a hard time understanding this proposal.

If you have a concrete thing you can improve PRs are welcome, but please don't refactor everything at once because it's really hard to review for me.

slorber avatar Mar 08 '21 18:03 slorber

The idea is solid although the language is hardly understandable.

By my understanding, the OP is asking for:

  • Tests to be fully E2E instead of testing internal impl; (which I partially agree, E2E tests should be improved, but unit tests are also necessary)
  • Separate side-effects (fs, web request...) from pure core logic (I don't know how that's possible but the idea is sound, like how functional programmers do things);
  • The CLI should only call Node.js / Webpack handles (also requested in #4841).

Josh-Cena avatar Oct 29 '21 02:10 Josh-Cena

Actually, closing in favor of #3056 and #4841

Josh-Cena avatar Nov 08 '21 14:11 Josh-Cena