Proposal: Introducing Template-Based Pattern Management#5
Open
Jeremy-F wants to merge 6 commits into
Open
Conversation
added 6 commits
December 19, 2024 20:46
Author
|
Hello, With some time and reflection, I believe the pull request is too impactful and changes the initial simplicity of the project. If you're okay with it, @xthezealot, I'll continue developing this idea further on my fork. I'll go ahead and close the pull request. Thank you! |
Owner
|
Hi @Jeremy-F, Your feature looks great. I'll pick this up in a few months. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
First, let me start by saying how much I admire this repository. I truly believe it's an excellent idea with great potential. The simplicity of
npmpruneand its "integrate and forget" philosophy is exactly what makes it such a valuable tool.In my previous pull request, I proposed adding support for additional patterns via CLI arguments. For example, I illustrated how one could exclude unnecessary image files (e.g.,
.png,.jpeg,.gif) fromnode_modules:While this approach provided much-needed flexibility, I quickly realized its limitations in real-world use cases. For instance, in my scenario, I deploy AWS Lambda functions with code written in CommonJS. This means I have no need for the
esmmodules included in certain libraries. However, crafting longRUNcommands in myDockerfileto handle these exclusions quickly became cumbersome:The more use cases I encountered, the more apparent it became that relying solely on manual CLI arguments is unsustainable. The core strength of
npmprune—its simplicity—was being undermined by these verbose configurations.Problem Statement
One of the key goals of this script, as stated in issue #1
I completely agree with this philosophy—it’s the reason I was drawn to this repository in the first place.
However, I believe that simplicity and extensibility are not mutually exclusive. In fact, enabling a standard, customizable way to clean
node_modulescan enhance the script's utility while preserving its core "integrate and forget" ethos. By makingnpmprunemore extensible, we also provide room for "extremely aggressive" use cases without compromising safety for standard use.Proposal
To address this, I propose the introduction of template-based pattern management through a new
-t(template) flag. This flag allows users to apply predefined templates of patterns for specific use cases. For example:To remove image files:
To remove
esm-related files:To combine templates:
This approach allows users to apply common cleaning patterns effortlessly, without relying on long CLI arguments or custom scripts. It also opens the door for the community to contribute and share templates for specific scenarios, fostering the development of a flexible and community-driven standard for cleaning
node_modules.Implementation Highlights
Template Management:
templates/directory and can be easily extended.images: Patterns for image files (*.png,*.jpeg,*.gif, etc.).esm: Patterns foresm-specific files (*.mjs,dist-es, etc.).default: The original hardcoded patterns for general cleanup.aws: Patterns specific to AWS SDK files (aws-sdk/dist,aws-sdk/dist-tools).Overridable Templates:
TEMPLATE_BASE_URL=`pwd`/templates ./npmprune.sh -t default,imagesCLI Integration:
-tflag enables one or more templates to be applied dynamically.Backward Compatibility:
-tflag does not interfere with the original functionality. Users can still provide patterns directly as CLI arguments../npmprune.sh ".husky" -t images,esmSafety Features:
logfunction suppresses unnecessary output in production environments (NODE_ENV=production).Potential Drawback
The main drawback introduced by this change is that the script now relies on either
wgetorcurlto fetch templates dynamically. This adds a slight dependency overhead. However, given thatwgetis commonly available in Docker environments (where this script is likely to be used), this should not pose a significant issue. In fact, the original idea of this script was to integrate it directly into Docker image creation usingwget, so this change aligns well with its intended use case. For environments wherewgetorcurlare unavailable, users can still provide their own local templates as files.Future Documentation
If this proposal is accepted, I will write the necessary documentation to explain how to use the
-tflag with existing templates (default,images,esm,aws).Closing Thoughts
This proposal does not aim to force any new behavior but rather to enhance the flexibility of
npmprunewhile staying true to its original philosophy. By introducing templates, we make the script more powerful and community-driven, allowing it to handle both simple and complex use cases with ease.Thank you for considering this proposal! I’m happy to make any adjustments based on your feedback.