-
Notifications
You must be signed in to change notification settings - Fork 12k
Option for ng new to use yarn instead of npm install #2651
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
Comments
Just done a few tests locally with a new angular-cli project and the theory and results are staggering. yarn: 120s and then 45s after deleting node_modules folder After an install already to determine there's nothing to do: In my opinion yarn should outright be the default and only way to install, even based on things like lock files by default and deterministic results. |
I don't have the timings in front of me, but I saw a bigger timing difference than your first pair of numbers above. Of course it varies by hardware etc. It seems to me that yarn is a very helpful leap forward in the NPM world. Something we have been waiting for for a while, some fundamental improvements (determinism, so important) as well as the practical benefit of being faster. The most pleasing part is that it did not require replacing the repositories or metadata format, this is all benefit obtained by writing different code to run in the client. Of course it's also important to remember that it was just released, and has some ways to go to reach something close to feature parity. Of relevance to Angular-CLI specifically: CLI pushes NPM quite hard.
As a result of all these things, yarn is especially big win for CLI, more so than for projects that use fewer dependencies, or changing less often, or are typically used by very experienced NPM users, etc. |
For anyone that wants to use yarn right now, no code changes are necessary. |
@clydin that's not enough, any of the commands run by ng (such as test or e2e) are run using npm, just do a |
@victornoel actually it is. NPM is simply being used as a task runner in those cases. |
I was thinking about how it might be possible for CLI to provide the best experience by default. Whatever experience arrives by default is what most brand-new users will have, and it would be great if those new users could have the yarn experience. How about this?
The instructions to get started could then be:
(Or similar, I typed the above from memory from yesterday and it might not be exactly correct.) The above idea reflects a philosophy of "likely best results by default, other things optional". An alternative philosophy is "old behavior by default, new behavior optional". |
yarn :) sounds good to me to choose it automatically if it exists |
@clydin maybe we are not talking of the same thing :) I realise this issue is about ng new, not ng in general, that's why my comment is not relevant maybe. |
Of the commands that use npm, only This doesn't mean first-class support for yarn wouldn't be useful (at least in the long-term). Especially if yarn doesn't succumb to the package linking bug that renders |
Please checkout YarNPM :) |
There are only two real commands that use I recognize that the speed improvements are dramatic, which is awesome. Install speed is important because no one wants to wait long while starting a new project. So, hypothetically, Yarn usage would help solve the install problem. Wouldn't address the cause, which is the very large dependency tree, but would help minimize the symptoms. Now let's talk about the downsides. It's a new system dependency, of which we only have two at the moment: node4 and npm3. A lot of people don't even realize they need npm3, resulting in a fair number of issues filed. Expecting users to also have yarn is... not really something that's reasonable. It's another new tech, undoubtedly with its fair share of issues like anything else. This repo already gets a lot of npm issues, not sure I'm looking forward to also have yarn issues being filed against the CLI. Scope is also something to be considered. Either it's the default and affects the majority of users, or it's a niche optimization. If you're savvy enough to want yarn, you sure are savvy enough to do it manually. To be clear though, no one that's actually participating on this thread is part of the majority. If you've ever looked at the CLI issue tracker, you are not part of the majority. Lastly there's the issue of configuration. A lot of people have npm configured to their needs. Proxies, private repos, whatever. Stuff that they need on their environment, otherwise they cannot work. I don't think yarn offers parity on that front. For these reasons I am not a big fan of defaulting to yarn. Not opposed to having some kind of flag to facilitate yarn usage, but a PR implementing it has to find a way to test it in all CI envs: Linux, OSX and Windows. |
If there comes a point where this is implemented (when?), you can just add an environment variable to select yarn if you want that eg: export ngpm=yarn. Then those who want to use it can easily set that and forget it. The ng-cli developers can then choose the functions which they want to implement yarn support for based on which are consistent. |
@leonletto Aliasing a Nice Classic solution :) But what about not compatible features? (commands are not exactly the same) |
As previously mentioned, nothing needs to be implemented to use yarn right now. Just use --skip-npm on new/init. |
I just added this into my ngproj() {
ng new $1 --skip-npm && cd $1 && yarn
} Usage: ngproj proj_name |
Great idea @gelidus! I automated it even further by initializing a git repo, making an initial commit and opening my IDE, as I always tend to do those steps after creating a new project. ng-new() {
ng new $1 --skip-npm && cd $1 && yarn && git init && git add . && git commit -am "Initial commit" && wstorm .
} |
Personally I partially agree with @filipesilva. Yarn shouldn't be the default, for all it's strengths I am sure us Yarn users are in the minority. That said, I have seen the deterministic nature of how yarn operates break cli projects when you install with it. Perhaps a more reasonable path would be to simply validate that you can run the Travis validations on a matrix using yarn for the install. That would ensure it works properly for those of us that want to use it without adding a dependency for those that don't. |
We recently ran into a lot of problems using yarn :( our builds are sometimes failing on segfaults. There are open issues on yarn for this. Check twice if you want to use yarn within wercker/travis. Yarn may not be mature enough at this moment. |
We're going to move this discussion to the tracking issue #3886. Closing this but you can keep the discussion going. |
Just tried to use yarn, again, there are so much issues using yarn on windows(performance issues, bugs, etc). just jumped back to npm. |
You can define it as default using: |
I'm guessing the benchmarks between npm and yarn will be more similar now that npm5 is out. |
You can also get the latest version of yarn using: |
Below commands not work on [email protected] : ng new --skip-npm <project>
# or
ng set --global packageManager=yarn
# or
ng config --set packageManager=yarn
# or
ng config --set --global packageManager=yarn I found below command still work on [email protected] : ng new --skip-install <project> See: Angular CLI: Speed up installing dependencies with Yarn |
@imzhengfei in my blogpost you can read how to set YARN as default in Angular CLI v6: https://medium.com/@beeman/using-yarn-with-angular-cli-v6-7f53a7678b93
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Is it possible to have a ng new option that replaces the use of npm install with yarn ?
Thank you,
Adrian
The text was updated successfully, but these errors were encountered: