Skip to content

Watcher should construct the bundler within itself instead of take it from outside #6931

@hyf0

Description

@hyf0

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
  • BindingWatcher convert BindingOptions to BundlerOptions + Plugins and pass them to Wacher
  • Watcher receive BundlerOptions + Plugins and perform validation inside of Watcher itself
  • If something wrong, Watcher::new will return BuildErrors, and binding watcher will be responsible to convert binding errors to napi errors.

Misc

  • binding_dev_engine has this problem too.
  • NormalizedWatcherOptions doesn't exist, but you should get the gist of what I said.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions