Comments (4)
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.
@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.
@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 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)
- npm run watch no longer runs tsc --watch
- StringUtils.isEmpty type guard types value as 'never' when false HOT 7
- Add type guard for RecordUtils.isRecord
- Add Lodash chunk and flatten to collection utils HOT 1
- Add 'Cache-Control' HttpHeader enum
- Add functionality to pull culture from route HOT 1
- Fix skipped LocalizationUtils.detectCultureCode test
- Allow consumer to control 'debug' option for LocalizationUtils/i18next
- Move + export LocalizationInitOptions interface from LocalizationUtils
- Implement network information utilities
- Update README with section on internationalization
- Lighten peer dependency version further
- ReferenceError exception when window is not defined HOT 1
- Add null to the collection type and type guard
- AuditableDefaultValues / Factory for requiring properties to be set
- Upgrade node requirement to v16 LTS HOT 1
- Add 'Content-Length' HttpHeader enum
- Slow workflow/npm install for cypress HOT 2
- Add AriaRole Enum to /src/enumerations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from andculturecode.javascript.core.