9

I've previously used ng update --all, cause I want to update every package to the latest version, including those dependencies which do not have schematics attached to it.

The --all option is now deprecated and will not function any more. The only option is to specify each package to update and I find that tedious. Is there a way to grep the outdated package output from ng update into a single line space separated variable which can then be input to a new ng update ${packageList}?

The output from ng update is as follows:

The installed local Angular CLI version is older than the latest stable version. Installing a temporary version to perform the update. Installing packages for tooling via npm. Installed packages for tooling via npm. Using package manager: 'npm' Collecting installed dependencies... Found 67 dependencies. We analyzed your package.json, there are some packages to update: Name Version Command to update -------------------------------------------------------------------------------------- @angular/cdk 10.2.5 -> 11.0.0 ng update @angular/cdk @angular/cli 10.1.7 -> 11.0.0 ng update @angular/cli @angular/core 10.2.0 -> 11.0.0 ng update @angular/core @angular/material 10.2.5 -> 11.0.0 ng update @angular/material @nrwl/angular 10.3.1 -> 10.3.3 ng update @nrwl/angular @nrwl/cypress 10.3.1 -> 10.3.3 ng update @nrwl/cypress @nrwl/jest 10.3.1 -> 10.3.3 ng update @nrwl/jest @nrwl/storybook 10.3.1 -> 10.3.3 ng update @nrwl/storybook @nrwl/workspace 10.3.1 -> 10.3.3 ng update @nrwl/workspace There might be additional packages which don't provide 'ng update' capabilities that are outdated. You can update the addition packages by running the update command of your package manager. 

I want to run a bash script which collects only the package names from the first column of this output, and feeds it back into a variable. The end result being:

> ng update ${packageList} ng update @angular/cdk @angular/cli @angular/core @angular/material @nrwl/angular @nrwl/cypress @nrwl/jest @nrwl/storybook @nrwl/workspace --force=true 

Help? Is this possible?

4 Answers 4

6

Think I got it with this one-liner:

ng update | awk -v re='@[[:alnum:]]' '$0 ~ re {printf $1 " "}' | xargs ng update --force=true && npm update 

By piping the output of the first ng update run into awk, I can search for text which resembles package names and output a space-separated list of arguments which I then pipe as xargs into a second ng update command.

By running this first and npm update after, I get every single dependency with migration schematics updated firstly, then all the rest afterwards. Happy! 🙂

Sign up to request clarification or add additional context in comments.

2 Comments

The solution does not work after upgrading to version 13.
You are right @BhadreshPatel. You should use Mr sweat potato's answer below: stackoverflow.com/questions/64804114/…
2

DISCLAIMER: BACKUP YOUR ENTIRE PROJECT FIRST BEFORE RUNNING THIS COMMAND.

ng update @angular/cli @angular/core --force --allow-dirty 

5 Comments

This will NOT update every dependency in package.json. Only @angular/cli and @angular/core.
@ØysteinAmundsen, Thanks sweet potato, but I think the question was about "angular" packages, not all in package.json. :)
Still, this will only update two of them.
-No, this will update ALL the angular packages, like @angular/*
It will update most of them but not all. Two that I know of still need to be updated manually: @angular/cdk and @angular/material.
-1

try this command ng update --legacy-peer-deps

Comments

-2

Try this:

npm update --save-dev 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.