-
Notifications
You must be signed in to change notification settings - Fork 137
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
Packager Refactoring #765
Packager Refactoring #765
Conversation
I think it's OK to have the shared code in core, but I would prefer utility functions over a base class. Not every packager implementation will want these utilities. Some packagers can natively speak HTML. |
Is there a cost to a packager implementation having access to these utility as methods and just not using them? If we want to go the utility-function route (which I think is totally fine) then I think it would be useful to have a separate package that contains the interface and utilities that a Packager-creator would likely need. That makes it more clear how to discover all those helpful bits, which I fear might get sort of "lost" if they're part of |
This isn't primarily about performance cost. This is about inheritance-as-framework-API being a pretty fraught area of API design.
In practice, people are going to write packagers by looking at what the existing packagers do. So I don't find this argument about discoverability compelling. Also consider that if we make a separate package, then we'll need to manage API versioning between it and core. |
That makes sense to me! I wasn't even thinking about performance when I asked, but more about other types of costs that might guide the design choice here. What you've described here sounds like a cost to avoid to me! The bit about keeping it in core makes sense to me too -- I'll take another stab at these changes while keeping they interface design and utility functions. Do you have a preference on the |
I like |
bb4ffba
to
e051440
Compare
I started this over again and simplified the changes
I decided not to bring over the file-copying behavior yet and instead just copy that manually into the Vite packager (at least, for now). |
53d3988
to
e4627b4
Compare
"Stat" is a webpack-specific concept, so I'd prefer to deemphasize it in the naming and organization and keep this as an implementation detail of HTMLEntrypoint.
This is a distillation of some of the refactoring from #759 that I thought would be easier to review and talk about outside of the Vite packager I am working on there.
The gist is that rather than being an interface that packagers need to adhere to, it can instead be an abstract base class that packagers extend from. This keeps the build-time requirement of implementing an async
build()
method but gives us a way to move some common tasks into the base class for sharing.I went ahead and kept the functionality that I moved to that base class in this PR. I found that while implementing the Vite packager, things like parsing the
ember-app
data out of the host app'spackage.json
and copying files from the input to the output were things both packagers need to do, and I imagine other packages would likely need that as well!The naming in this PR changes the semantics of some of the types a little, in a way that I think is a little more clear
Before
Packager
refers to a constructor for a PackagerPackagerInstance
refers to an instance of a PackagerAfter
PackagerConstructor
refers to a constructor for a PackagerPackager
refers to an instance of a PackagerI would have assumed that TypeScript has some kind of utility type for creating a type for a constructor of another class, but it surprisingly does not; the recommended approach is to use an
interface
in the way that this PR does.Other Options
We could also create two "tiers" of Packager base classes, if we wanted to; one that has the utilities and one that does not. I'm not sure that's really necessary, but it's definitely an option!
Separate
@embroider/packager
packager -- this could take the Packager base class and move it to a separate package rather than having it be part ofcore
. This really just comes down what should be part ofcore
and what should not. I could see this going either way, personally, but left it incore
for now (which is where the interface was originally defined).This would create a place for the
html-entrypoint
andstat-summary
files, which have now been moved tocore
but are really just there so that both Packagers can use them.HTMLEntrypoint
and the parsing it does is useful for both packagers, so moving it to a shared location would be really useful!