-
Notifications
You must be signed in to change notification settings - Fork 699
Description
Nicely done. I still feel there're some bad code smells here. Let me illustrate in a separate issue without blocking this PR.
Originally posted by @hyf0 in #6860 (review)
Some design orientations
- All the rust crates (except
rolldown_binding) should be written as if they were gonna be used as a rust libaray.- This enforces us to deisgn clean and elegant API and well-organized code structures, which makes us easily to maintain the code.
- There are cases that rules don't apply, but you should try to follow them as much as possible.
Validation like #6860 should be done within the crate rolldown's scope instead of being in rolldown_binding.
And why the PR can't do that. That's becuase Watcher is designed to receive the bundler from outside, so you can't do a advance check with NormalizedBundlerOptions and NormalizedWatcherOptions.
And why the watcher tries to receive the bundler from outside? That's becuase, in the current code, we only provide abstriction about BindingOptions -> BindingBundler, so binding watcher would have use this abstraction and then take the Bundler out of BindingBundler. (This's a classic example of not considering about the overall code design but just to make it run)
The practic way should be:
- We provide abstraction for
BindingOptions->BundlerOptions + Plugins BindingWatcherconvertBindingOptionstoBundlerOptions + Pluginsand pass them toWacherWatcherreceiveBundlerOptions + Pluginsand perform validation inside ofWatcheritself- If something wrong,
Watcher::newwill returnBuildErrors, andbinding watcherwill be responsible to convert binding errors to napi errors.
Misc
binding_dev_enginehas this problem too.NormalizedWatcherOptionsdoesn't exist, but you should get the gist of what I said.