-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Remove all relative requires #2383
Comments
What does |
|
Looking forward this, since keystone broke on 5.7.x |
This isn't what |
I think my initial comment was misleading. I did not mean to mandate the use of npm link for the app that depends on keystone, I meant it should be required to run npm link for development and publishing. The behavior of npm link that keystone should exploit is (from docs):
In this way, when an application installs keystone via npm, the absolute paths in keystone's requires will be resolved without any extra step for the user. If a user wants to run two different apps that use two different versions of Keystone, they simply have to specify a different version in each package.json (as they normally would). |
To cite npm help link:
I highly doubt that this is what you want to do. Other than that, I support removal of all parent directory requires within keystone. Instead, keystone development and testing should be done in a subdirectory "keystone" of a directory named "node_modules" (as it is always the case, when keystone is used within a server application). Then, requires within keystone can have the form require('keystone/some/component'), and especially, you get rid of ugly and unmaintainable require('../../../') by replacing them with require('keystone'). |
As @geloescht mentioned, |
@geloescht Creating a global symbolic link is, in fact, what you want to do during development. This is the mechanism that allows you to reference the package by name. When you publish the package, the links are resolved. I don't think that mandating development within a node_modules/ folder is an appropriate solution, you are simply taking advantage of the fact that npm blindly resolves everything inside of that folder. @ericelliott I believe we have two different definitions of "developer" in this discussion. We have a "keystonejs developer" who works on core keystone features. We also have a "client developer" who uses keystone as a dependency in their project. In the case of the "keystonejs developer", it is not an issue to work with multiple versions of keystone on one machine. Since keystone is in version control, you just need to switch to a different branch. The symbolic link created by In the case of the "client developer", it is also not an issue to work with multiple versions of keystone on one machine. The client developer will specify the version of keystone that they want in each app's package.json file. The client developer does not need to run npm link. To be clear, I am only talking about mandating |
I agree with @erg0dic Though |
Obviously this needs to be tested thoroughly from both developer's view points to make sure we're not missing something important here. |
And come to think of it, maybe this warrants a feature request for node (or npm? I never know what |
@erg0dic : To cite the paragraph you linked:
This is about developing a app using a development branch. Anyway, it's dangerous. Imagine keystone developer Maurice has two versions of keystone checked out at the same time. One in /home/maurice/development/keystone-master/ and one in /home/maurice/development/keystone-maurices-new-feature/. The problem exists, because require has one serious gap: It does not consider the current package it is in. Unless: You develop inside a directory named node_modules. Or you link to '..' inside the sub-directory node_modules. npm link does the second thing, but poorly, by going through a global, machine-dependent location. If there is a way of invocation npm link, that does not link to a global location, fine. Otherwise, better stay away from it and use good old ln -s, when you want to have links. |
Yeah, that's the one use case which is potentially dangerous. But TBH, once you start messing with npm link for whatever reason - i.e. Maurice would be npm linking anyway, regardless of this discussion - you have to make sure that whatever you're linking to is the correct thing. A long-winded way to say: Maurice would be in trouble in the current situation anyway. |
Well, if by current situation you are referring to the one with relative requires: No trouble at all. |
@geloescht You are correct. In the situation you described, you would have to run I don't mean to try to tell you how to work, but it would be much more efficient to leverage git to manage multiple versions of keystone in a single directory. I believe that this is how most people work with git. If you manage multiple versions of keystone in this way, |
Having multiple versions of a repository is quite handy if you do not want to stash all your uncommited changes in a feature branch before working on a different branch. IMO, npm link is a hack and has no advantage over ln -s except that it is a little more convenient in usage. The good thing for both of us is: The behaviour of npm publish relating to symbolic links is identical in both cases. Most this discussion is academic and more about personal preference. Just, please don't make npm link mandatory for keystone development. |
@geloescht Probably you have a different workflow, but I meant that in the situation you describe:
Most people will be npm link juggling anyway, regardless of what we're discussing here. At least I do, since for both What you propose is far more invasive and - again IMO - equally hacky, which is why I definitely prefer @erg0dic 's solution. |
I do link juggling using ln -s and not npm link, because ln -s does not modify my global environment. |
There are a number of ways to deal with relative requires in development. Here is a good list. I suggested using
I am not here to prove the relative superiority of my method over any other. I would, however, like us to agree to do something to address the issue of relative requires. |
@JedWatson any thoughts on this? It sure would be nice to get rid of the relative requires |
By the way, I submitted a pull request #2390 that depends on switching to module paths instead of relative paths. So I would love to hear a decision on this matter 🐵 |
Works on Windows is unfortunately a non-negotiable requirement for Keystone development, as at least one of our core contributors uses it and I don't want to cause problems for him (hi @webteckie 👋) or alienate other potential contributors on Windows. I don't see any issues using I'm all for resolving the relative requires if we can, but not as the cost of introducing hacks into the core codebase, especially if they have stability issues across platforms or may run into breaking changes with newer versions of node. They're a PITA when coding, but stability and predictability need to be our priorities as Keystone matures. |
Alright then I admit @JedWatson :-) fyi, while on windows I do spend 100% of the time in git bash and use all linux commands :-) Not sure if symbolic links work there...will check. But it's just one of those cases where I haven't had the need to buy a mac! But I've been thinking hard about buying one :-) |
As long as it works, do you really need to switch? 👍 I agree with Jed, we should definitely keep this as OS friendly as humanly possible. |
@mxstbr gonna start doing some iOS mobile app dev. But I realized I can also rent a mac in the cloud :-) |
Alright then, I give in :) Whereas the title says, remove all relative requires, I think it should only be most relative requires. I believe where tight coupling is already in place, such as where methods of a prototype (don't call it class ;) ) are divided up into separate files, relative queries between those files can stay (lib/list comes to mind). If they get moved around or referred to from the outside, then probably as one big chunk. Actually, this whole discussion has got me thinking of developing a non-evil version of npm link 😎 |
💯 that would be great |
Seconded. |
I'll close this issue for now, since #2390 is not directly related to this! |
Consider mandating use of
npm link
& remove all relative requires. Prevents issues like #2325 as a result of nondeterminism in path.relative(). Also much easier to reason about :)Maybe not in scope for v4 but definitely for future.
The text was updated successfully, but these errors were encountered: