You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current implementation breaks node's module system by mutating the global instance of moment. i.e. if two packages depend on different versions of moment-precise-range, which version is used? It will depend on the order they're loaded, which could change at runtime.
Secondly, users should have precise control over which version of moment they want/need to use.
Ideally, user passes moment into this plugin like so:
This removes need for moment-precise-range to even list moment as a dependency (I'd set it as a devDependency though so it's available during testing).
The plugin should not mutate the original moment instance. This means not using the official, yet destructive moment.fn method. Rather, the plugin would do something like this:
module.exports=function(moment){moment=Object.create(moment)// protect original moment from modificationmoment.preciseDiff=preciseDiffreturnmoment}
Alternatively you could export the preciseDiff function in isolation so users can attach it to moment however they wish.
The text was updated successfully, but these errors were encountered:
Oh, my bad the Object.create suggestion won't work with moment because it's default export is a function. You can set the prototype directly on the function though, something like this:
module.exports=function(moment){// protect original moment from modificationvarwrappedMoment=function(){returnmoment.apply(this,arguments)}wrappedMoment.__proto__=momentwrappedMoment.preciseDiff=preciseDiffreturnwrappedMoment}
Current implementation breaks node's module system by mutating the global instance of moment. i.e. if two packages depend on different versions of moment-precise-range, which version is used? It will depend on the order they're loaded, which could change at runtime.
Secondly, users should have precise control over which version of moment they want/need to use.
Ideally, user passes
moment
into this plugin like so:This removes need for
moment-precise-range
to even list moment as a dependency (I'd set it as a devDependency though so it's available during testing).The plugin should not mutate the original moment instance. This means not using the official, yet destructive
moment.fn
method. Rather, the plugin would do something like this:Alternatively you could export the
preciseDiff
function in isolation so users can attach it tomoment
however they wish.The text was updated successfully, but these errors were encountered: