Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

New command "fake" or "mock" #10000

Closed
VanCoding opened this issue Oct 16, 2015 · 6 comments
Closed

New command "fake" or "mock" #10000

VanCoding opened this issue Oct 16, 2015 · 6 comments

Comments

@VanCoding
Copy link

Hi folks

I'd like to discuss adding a new command "npm fake" or "npm mock" or something else that describes its functionality even better.

What does it do?

Basically it tells npm to use a specific package from a local source instead of installing it from the web. If we then npm install this specific package, npm creates a symlink to the location of that module inside node_modules instead of installing the official version from the web. Everything else would work the same.

Npm would save this information in some local settings file like ".npmsources". So everytime I'd run "npm install" in the root directory of my app, npm would be aware of the replaced package and act accordingly.

It's important to note that this is a temporary setting usually for development purposes. So we don't change the "package.json" file. Basically we just want to replace a specific package with another one during development. So the developer would always add the ".npmsources" file to ".gitignore", because it's really a local setting and not something we want to provide to the users.

But why?
In NPMv3 a lot has changed. In version 3, it tries to build the most efficient package tree. And additionally, it does no longer allow GIT-repositories to be in the "node_modules" folder.

But sometimes, I'd like to develop on 2 packages at the same time, to see if they work together flawlessly. In the past, I just cloned the in-development dependency into the node_modules folder and everything worked great. But that's no longer possible, so we need an alternative. An even more elegant one, if possible.

And I think the suggested new command would be exactly this. It would developers allow to use GIT repositories as submodules during development without changing anything in the "package.json" files, and it would allow NPM to manage where to place the symlink in the package tree, so that it remains efficient and clean.

Why not use npm link?
I've tried to use it at first, but I noticed that it's unusable for this task for the following reasons:

  1. The npm linked package gets installed globally and then symlinked. That means when I run npm install, the packages inside the linked package don't get touched at all. Because of this, we don't have a nice dependency tree.
  2. The linked package also does not act like it would live direclty inside the host package. When it has peer dependencies and tries to require them, it cant find them because it acts like its outside of the package.

I've explained the situation a bit better in #5875. As you can see, there aren't any satisfactory solutions for this yet.

Please let me know what you think about it or if you don't understand something.

Thanks :)

@kenany
Copy link
Contributor

kenany commented Oct 16, 2015

Hey this is issue #10000 :)

@watilde
Copy link
Contributor

watilde commented Oct 16, 2015

Congrats #10000 🎉

@VanCoding
Copy link
Author

omg how can npm have 10'000 issue reports? :P

@aredridel
Copy link
Contributor

Part 2 is one that I noticed and I think is super interesting to try to solve. Perhaps is the crux of the matter.

@VanCoding
Copy link
Author

@aredridel as you can see I've already opened a feature request for node that tries to fix this.

@npm-robot
Copy link

We're closing this issue as it has gone thirty days without activity. In our experience if an issue has gone thirty days without any activity then it's unlikely to be addressed. In the case of bug reports, often the underlying issue will be addressed but finding related issues is quite difficult and often incomplete.

If this was a bug report and it is still relevant then we encourage you to open it again as a new issue. If this was a feature request then you should feel free to open it again, or even better open a PR.

For more information about our new issue aging policies and why we've instituted them please see our blog post.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants