Git Product home page Git Product logo

Comments (4)

brandongregoryscott avatar brandongregoryscott commented on September 26, 2024

Just noting this here for future reference - I stumbled upon a package called codependency that offers a similar approach to what I was trying to accomplish with 'optional' peer dependencies. For packages that consumers may never need to use (thinking i18next or humanize-plus, for example), we could update the imports where they are currently located to be something along the lines of...

import HumanizeModule from "humanize-plus"; // Importing just the type, this does not emit a require(...)
import codependency from "codependency";
const requirePeer = codependency.get("andculturecode-javascript-core");
// Does not throw an error on import, but does return undefined if consumer does not have humanize-plus installed
const Humanize = requirePeer("humanize-plus", { optional: true }) as typeof HumanizeModule; 

...
const pluralize = (
    number: number,
    singular?: string,
    plural?: string
): string => Humanize.pluralize(number, singular, plural);

We could also move the requirePeer call to where the dep is actually called, and let it throw an error at runtime (by removing the { optional: true } object) - which might be more obvious to a consumer when they are attempting to use a function we provide that relies on an external, optional dependency.

It sounds like for now, we are OK with having consumers install the few external dependencies we have listed, even if they are not planning on using those features. If this becomes too much of a pain, we may want to consider moving in this direction ☝️

from andculturecode.javascript.core.

wintondeshong avatar wintondeshong commented on September 26, 2024

@brandongregoryscott thank you for all the work writing this up, investigations and finding the codependency package above. Being able to avoid declaring deps in consumers, despite not needing them, would be awesome! I also think it has minimal impact in terms of code (per examples above and in their repo). I wonder if we can find any other libraries fulfilling the same need? I ask because it appears there are some pretty long outstanding issues with this particular library. If not, we can give it a whirl and see if we are impacted by any of those issues and perhaps take a stab at resolving them.

from andculturecode.javascript.core.

brandongregoryscott avatar brandongregoryscott commented on September 26, 2024

@wintondeshong Of course! Glad to dig into it. I will keep digging for other solutions too. Noting here that while I stumbled upon this package separately (typing 'peer dependency' into Github, out of curiosity), I stumbled upon another StackExchange answer this morning that described the same approach and linked to that package. https://softwareengineering.stackexchange.com/a/273576

from andculturecode.javascript.core.

wintondeshong avatar wintondeshong commented on September 26, 2024

@wintondeshong Of course! Glad to dig into it. I will keep digging for other solutions too. Noting here that while I stumbled upon this package separately (typing 'peer dependency' into Github, out of curiosity), I stumbled upon another StackExchange answer this morning that described the same approach and linked to that package. https://softwareengineering.stackexchange.com/a/273576

I'm down if we try it out. Looks promising despite some of the outstanding issues. Can see how it goes

from andculturecode.javascript.core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.