cherfia / chromiumly

A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.
MIT License
54 stars 7 forks source link

Make 'config' and 'dotenv' Peer Dependencies Optional #398

Closed OsoianMarcel closed 2 weeks ago

OsoianMarcel commented 1 month ago

Hello,

I would like to propose an enhancement for the 'chromiumly' library regarding its peer dependencies. Currently, 'chromiumly' requires 'config' and 'dotenv' as peer dependencies. However, in some cases, it would be beneficial if these dependencies were optional. This would allow clients to configure the library directly from the code without needing to include 'config' and 'dotenv' in their projects unless absolutely necessary.

Solution

Conditional Loading

Implement a mechanism to conditionally load 'config' and 'dotenv' libraries only when a specific function is called. Use dynamic imports to load these libraries.

Error Handling

If the function is called and the libraries are not available, throw a clear and descriptive error message indicating that 'config' or 'dotenv' needs to be installed.

Code Example:

async function loadConfig() {
    try {
        const config = await import('config');
        // Use the config library
    } catch (error) {
        throw new Error("The 'config' library is not installed. Please install it to use this feature.");
    }
}

async function loadDotenv() {
    try {
        const dotenv = await import('dotenv');
        dotenv.config();
        // Use the dotenv library
    } catch (error) {
        throw new Error("The 'dotenv' library is not installed. Please install it to use this feature.");
    }
}

Benefits:

Flexibility: Users can configure the library from the code without needing to include 'config' and 'dotenv' unless they are actually using them.

Reduced Dependencies: Projects that do not need these libraries won't be forced to include unnecessary dependencies.

Improved Usability: Simplifies the configuration process for users who prefer code-based configuration over using additional libraries.

Impact: This change will make the 'chromiumly' library more flexible and user-friendly, catering to a broader range of use cases and reducing unnecessary dependencies in client projects.

Thank you for considering this enhancement. Looking forward to your feedback.

cherfia commented 1 month ago

@OsoianMarcel Thank you for the suggestion. It's a good proposal, and I will work on including it into the next version 👍

cherfia commented 2 weeks ago

@OsoianMarcel It's now available in version 3.4.0 🚀