-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No relative require in locales #1989
No relative require in locales #1989
Conversation
I found another solution instead of using npm link, use the new feature of npm 2: local dependencies: in my branch: https://github.com/timaschew/moment/commits/moment-as-module |
I'm a bit confused now. Do we need this and why? What works better and what might (possibly) break. |
You should use it because moment and all locales files should obviously not bundled together in all cases. For instance if you want to load locale files via AMD or in some other dynamic way. So that involves that using IMO the version with define a locale module in the package.json is cleaner than using grunt shell + npm link commands. The only condition is: you need npm >= 2.x |
I haven't seen people complaining about the way we import moment inside language files. Also the way you propose to put it seems like the languages and core are in separate repositories. All node projects I've seen have relative dependencies between the files. If we put locale files in another repo, then it would make more sense, but it would also make it more complicated for users. If this is causing a problem for component, why not maintain a separate component repository that we push on every release. |
Yes, a separate repos would make sense, but also a little bit overkill. You talking about Node projects, but I'm talking about browser environment. AMD has it's own syntax and define a namespace, this is the reason why their implementations like Require.js is not affected with this issue. |
This and the problem of a dynamic require in the moment.js: Line 777 in 981647d
|
Well, the dynamic require is just a nice feature for node.js. Its not something that we want to support, it was just something that we could :) How is size a problem for browser in this setting (browserify / component). They fetch only the files needed. Also for those environments -- yes, you have to specify the language files you want (or just take all locales) -- I don't see any problem with that. Is there a way around? Requiring a locale used to also set it, but then there are other weird cases we have to handle. How is making the requires not relative fix any of those? |
The es6 locale is going to provide different builds for different environments, so then (hopefully) everybody will be happy, no matter the build / module system used. You still didn't say which tools have problems loading moment now, and under what circumstances. |
@timaschew the require logic was severely changed in 2.10.0, can you verify if it works for you now (2.10.3 is latest). I guess we still require relatively, but amd requires are absolute. I guess we can add a special browserify/component header that works well for it. |
I've opened PR #3082 since it is sometimes a pain to define the |
This PR rewrote all
require('../moment')
torequire('moment')
The reason is to decouple the locales from the moment.js file.
This could cause problems in browser environment, because locale files are not always bundled with moment.js, so there should be no relative relation anymore.
In Node.js envirnoment this works fine, because node will lookup moment in the node_modules directory. Also browserify still works.
This makes it easier for tools which use
require
in browser environment to load moment. To get it working the namespace/pathmoment
must be registered, instead of../moment