-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Mod File Generation #27451
Comments
So it just takes all your files and re-exports them in a mod.ts file? How does this save significant time? Why would you need to regenerate them and not update it whenever you create or delete a file? Since you've essentially switched it from manually including to manually excluding, I don't see how it saves any time. |
It's easy to forget to add/remove/update reexports. Consider projects that have dozens of files and many contributors. Also: auto-import updates come to mind: they often result in mod files that contain undesirable reexports. For instance, let's say we have a
export * from "./c.ts If we move export * from "../c.ts" Moderate ensures that this reexport is no longer in "moderating" is a way to simplify managing exports in large projects. The Deno team already somewhat "moderates" denoland/std. Although it's manual, there is an agreed upon convention for organizing and excluding files from different subpackages/mods. I'm not suggesting a specific |
This sounds like a useful features for certain projects, but I'm not sure if putting that into Deno itself is the ideal place. Personally, I haven't encountered projects where everything of the sibling files should be exported. There is always an exception here or there which makes automating it more tricky. That said it's a perfect feature to put into a tool on |
I would agree if not for the possibility that a proper solution may utilize the Deno module graph (to prevent issues such as used-before-initialization, misc). |
Index/mod/barrel modules are a serious anti pattern and should not be encouraged. Projects and packages should take steps to delete them from their codebase and move to optimal deep imports. To learn why, here is a detailed explanation: https://jaydenseric.com/blog/optimal-javascript-module-design |
Hi @jaydenseric, thanks for your thoughts. I too disagree with dependency barrel files. However, I'm suggesting something different. This issue is about conventions and workflows for exposing exports from subdirectories. We JS devs don't have visibility modifiers beyond I just read your article and I disagree with your arguments, especially in the context of Deno.
I haven't benched it myself, but my understanding––at least when using Deno––is that this performance overhead is negligible (caching included).
I think this point is the same as the first, yes?
When you create a reexport file such as an
This overhead is negligible.
I'd recommend ensuring there are no parse errors before running your code. You can run
This is an interesting thought. But a bit of a reach, no? In summary: files that reexport are not fundamentally an anti-pattern. @jaydenseric I think you may be coming to this issue with some faulty assumptions. I think @dsherret addresses your faulty assumptions quite well in denoland/std#2321
The question remains: is there a general-enough mod file convention and/or workflow that could satisfy the needs of large projects like deno_std |
I think this is better left for a separate tool and too specific to have a command in Deno. For example, something could do this on the fly in the editor. IIRC, I think someone proposed a general purpose code generator sub-command and that might be a better option, though it's something that can be easily achived with |
That's completely reasonable. Thank you @dsherret. |
This statement is indicative of the very strong paradigm that you both may be constrained by. Please give deeper consideration and thought to environments where bundling is not (or no longer) required. There are no strong arguments on the side of barrel files. The majority of the counter arguments to @jaydenseric's article are weak or require some other solution to solving a problem created by barrel modules that simply doesn't need to exist. |
Apologies I really don't know what you mean by this. By "paradigm", do you mean the decision to occasionally use re-exports to organize code / improve legibility? On another note, calling counterarguments "weak" without technical explanation is dismissive (as is suggesting a lack of "deeper consideration"). Not sure why this convo devolved... perhaps because of (what appears to be) baggage in denoland/std#2321. Anyways, the issue's closed. Be well guys! |
This may be out of scope, but I believe it's enough of a productivity boon that I'd like to propose it just incase.
I frequently utilize a tool called moderate to regenerate
mod.ts
files. The workflow is very simple:mod.ts
that I'd like to "moderate", I add a// moderate
comment at the very top.deno task mod
, which writes re-export statements for all files andmod.ts
-containing subdirectories.One can even specify excludes in the directive + add leading statements to be left untouched before the
// moderate
directive. Ie.This utility saves me significant time.
I was wondering if anyone thought a workflow such as this could make it into Deno toolchain, where it could be standardized and made to benefit the broader ecosystem. Dealing with mod/barrel files / and reexport statements is just such a pain for so many developers. I think we can do better by making this or a similar workflow a first class citizen.
The text was updated successfully, but these errors were encountered: