jsmreese / moment-duration-format

Format function plugin for the Moment Duration object.
MIT License
968 stars 120 forks source link

Issue when require is available, but not used to load moment #63

Closed johannesjo closed 6 years ago

johannesjo commented 7 years ago

I've a setup using electron where require is available, but moment is included directly (as bower_component). This leads to issue because of the way moment is loaded:


    // define internal moment reference
    var moment;

    if (typeof require === "function") {
        try { moment = require('moment'); }
        catch (e) {}
    }

    if (!moment && root.moment) {
        moment = root.moment;
    } 

Personally I think it should be the other way round, e.g.:

    // define internal moment reference
    var moment;

    if (root.moment) {
        moment = root.moment;
    } else if (typeof require === "function") {
        try { moment = require('moment'); }
        catch (e) {}
    } 

If you agree, I happily provide a PR.

jsmreese commented 7 years ago

Check out the dev branch of the repository. the module setup was fixed there a long time ago and likely suits your needs. Sorry I've never gotten around to publishing the updated version (maybe someday soon...)

johannesjo commented 7 years ago

Thanks for your quick response! Is it complicated to publish a new version? Ideally this just should be a couple of commands :)

jsmreese commented 7 years ago

You're absolutely right... not hard to publish a new version, and I really should. I never got a chance to finish everything I'd hoped would make it into a new version, and then... life...

Quite frankly I expected that this feature would have made it into moment core by now (whether in the form of my plugin or otherwise). The fact that it hasn't speaks to just how difficult this problem is to handle in a generic and easily localizable way. So many different use cases...

johannesjo commented 7 years ago

I didn't mean to complain in any way, I know how hard it is, to keep your open source repositories up to date. I also really really appreciate what you did with this module. Dealing with dates and time always gives me headache and apart from this issue above I haven't encountered any other problems.

I just was curious what the reason is you don't simply make a release. But I understand that there is some bigger release waiting with some unfinished business in there. I personally prefer rolling updates for my smaller projects, so I don't need to think too hard when making the next release.

evanshortiss commented 7 years ago

@jsmreese would it be easier for you to publish this if someone were to create a branch of tag 1.3.0 and port just the UMD fix? I would be happy to try that.

We're currently using a fork and referencing the dev branch in our package so would be nice to use npm instead.