Accept optional mapFilename config for rollup-app-reexports#1202
Accept optional mapFilename config for rollup-app-reexports#1202ef4 merged 1 commit intoembroider-build:mainfrom
mapFilename config for rollup-app-reexports#1202Conversation
|
how close is this to "just authoring the app-js section of package.json yourself?" - why would we opt for this instead of that? I 100% understand the desire to re-map the input modules to the app-re-exports. Something I did a lot of in v1 addons, that I would like to see "a" solution for, is for having helpers, modifiers, components all in non-default exports (or in the same file), and still properly re-exported in app-js somehow. That said, I think the approach you have here is extensible enough for future extending, if need it |
Plugins like appReexports appear explicitly in rollup.config.js so you can replace or remove them. Nothing stops a v2 addon author from manually managing an That said, this change seems fine. The main nudge I want to give people with this plugin is away from putting arbitrary code in the app tree (limiting to only reexports). If people choose to drop the plugin, they lose that nudge. This option lets more people stick with the plugin. |
Doing that by hand is of course possible, but to Ed's point that's far more free-form and invites a lot more abuse. Having to manage the
Exactly. Thank you for merging! |
|
Can this be documented somewhere? Maybe in https://github.com/embroider-build/embroider/blob/main/ADDON-AUTHOR-GUIDE.md? |
I brought this up in Discord the other day and didn't get any immediate vehement "no way" responses, so I'm going ahead and proposing it here.
Tl;dr: in
@embroider/addon-dev's tooling for generating app reexports, I'd like to be able to define a mapping between the source and reexport paths for an entity instead of assuming they're exactly the same.Background
For addons that expose many resolvable entities (components, helpers, services, etc), it can be helpful to somehow namespace those entities to make it clear to consumers where they're coming from when they see a component invocation or service injection.
Short of no-longer-the-future Batman namespacing, a lighter-weight way to do that is by grouping those entities together under a directory so that everything your addon exposes is clearly prefixed with an indicator of where it's from. Concretely, rather than directly having
components/fooin mycool-addonpackage, I might havecomponents/cool-addon/foo, and consumers would write<CoolAddon::Foo />in their templates.It's a bit cumbersome to have that extra directory in the canonical path for the implementation, though: it's an additional layer of nesting to navigate through in editors and code browsers, and you end up writing somewhat redundant import paths like
cool-addon/components/cool-addon/foo. The latter point also becomes a bit more painful as first-class component templates pick up steam and consumers begin needing to care about the import paths of the components, helpers and modifiers they use.To mitigate this in a v1 addon, I can put my reexport in
app/components/cool-addon/foo.jswhile leaving my implementation inaddon/components/foo.hbs, but since reexports are managed as part of build tooling for v2 addons, I don't have that flexibility.This Change
This change adds an optional
appReexportsfunction that devs can pass toappReexportsto remap the names of files emitted as part of theirapp-jscontent.By configuring my v2
cool-addonlike the snippet above, I can provide a reasonably ergonomic form factor for consuming myFoocomponent unambiguously in a loose-mode template (<CoolAddon::Foo />) or a strict-mode one (import Foo from 'cool-addon/components/foo').