-
Notifications
You must be signed in to change notification settings - Fork 2.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
Add import command #2580
Add import command #2580
Conversation
That looks cool from the first sight, I would probably use it for migrating old projects that used to check in node_modules. My concern is that we want to keep Yarn lean enough to keep it maintainable and outsource maintenance of niche features to the community. |
This isn't a niche feature, this imo is a primary use case - starting to use yarn on an existing project. |
It did not, and I'm sorry about that - I completely forgot that was a thing! Happy to get the ball rolling there if you'd like.
Totally understandable, and yes - this represents my 4th or 5th attempt at a reliable migration tool, and all previous attempts were standalone. I'll spare you the gory details, but I determined a built-in was the only reasonable option. In general, existing support packages for this kind of thing seem to all have their own insane pitfalls, so you have to reinvent the wheel, a lot. Then you inevitably need some yarn apis in order to be accurate, but they're all private and very hard to get at from an external package (lib vs lib-legacy, roadrunner, etc). Also, verify tree check got added, which was the last big chunk of work yarn wasn't already doing. Since a standalone is such a large/annoying undertaking, and the nature of the tool is such that most people only need to run it once and then never use it again, I honestly don't expect to see a standalone any time soon. In fact, a major motivation for this PR is that I've already used it for all my projects and wanted to get the code out there before I forgot about it forever. =) |
@xdissent, I really appreciate your effort, thanks for getting this out for the community. |
SummaryImport command to generate a yarn lock file from an existing npm-installed MotivationMany projects currently use A Detailed designThe import command is implemented as a subclass of the install command. The significant differences are that it uses a The The resolver creates The The only functional code change outside of the import command is that How We Teach ThisThe DrawbacksThere are many different npm versions in the wild, and all with potential edge cases, so maintenance may become a problem. Changes to yarn internals could also require updates or additions to the command's implementation. AlternativesI've tried a handful of approaches to the problem but was ultimately convinced a built-in command was the only reasonable path forward. I also think this is such a common scenario that if an external migration tool did exist, many first time users could have a negative impression of yarn if the tool didn't perform well. Unresolved questions
|
Great job all around, @xdissent. FYI, we are working on a JS API for plugins and wrappers, RFC should be coming soon. |
Thanks! And sure thing re: plugin. I'll watch for the RFC and chime in if I foresee any potential implementation problems given the proposed API. |
Great work! |
A million times thank you for this. I cannot explain how helpful this feature has been. I was in an npm dependency nightmare and Thank you again. |
I am migrating checked-in node_modules to yarn. This is an awesome tool! Are there tips anywhere for how best to resolve errors of the nature of |
@rattrayalex-stripe I've encountered this problem when my |
Summary
Adds an
import
command to generate a lockfile from an existing node_modules folder, using the installed versions when it can, and warning when it can't (#682).It does the following:
_resolved
,_shasum
,gitHead
).The goal is to make migration to yarn as easy as possible for folks who currently shrinkwrap, minimizing the differences between the lockfile and their existing tree, and informing them of any changes.
Test plan
I've added tests for some basic scenarios, but I wanted to get some feedback about the approach I took. It requires storing the installed
node_modules
in the fixtures, and I thought someone might have a better idea. I'm sure there are lots of edge cases in the wild, so an easy way to add import tests seems important.