42_npmjs: fix json error handling for outdated

git-svn-id: https://svn.fhem.de/fhem/trunk@18688 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2019-02-22 13:50:56 +00:00
parent a3dd7dfa67
commit 37a9c7c9c3

View File

@ -368,46 +368,46 @@ sub Set($$@) {
else { else {
$list = "outdated:noArg"; $list = "outdated:noArg";
if ( defined( $hash->{".fhem"}{npm}{listedpackages} ) my $install;
&& defined( foreach ( keys %fhem_npm_modules ) {
$hash->{".fhem"}{npm}{listedpackages}{dependencies} ) ) next
{ if (
my $install; defined( $hash->{".fhem"}{npm}{listedpackages} )
foreach ( keys %fhem_npm_modules ) { and defined(
next $hash->{".fhem"}{npm}{listedpackages}{dependencies}
if ( )
defined( and defined(
$hash->{".fhem"}{npm}{listedpackages}{dependencies} $hash->{".fhem"}{npm}{listedpackages}{dependencies}{$_}
{$_} )
) );
); $install .= "," if ($install);
$install .= "," if ($install); $install = "install:fhem-all," unless ($install);
$install = "install:fhem-all," unless ($install); $install .= $_;
$install .= $_; }
} $install = "install" unless ($install);
$install = "install" unless ($install); $list .= " $install";
$list .= " $install";
if ( if ( defined( $hash->{".fhem"}{npm}{listedpackages} )
scalar and
defined( $hash->{".fhem"}{npm}{listedpackages}{dependencies} )
and scalar
keys %{ $hash->{".fhem"}{npm}{listedpackages}{dependencies} } >
1 )
{
my $uninstall;
foreach (
sort
keys %{ $hash->{".fhem"}{npm}{listedpackages}{dependencies} keys %{ $hash->{".fhem"}{npm}{listedpackages}{dependencies}
} > 1 )
{
my $uninstall;
foreach (
sort
keys
%{ $hash->{".fhem"}{npm}{listedpackages}{dependencies} }
)
{
next if ( $_ eq "npm" or $_ eq "undefined" );
$uninstall .= "," if ($uninstall);
$uninstall = "uninstall:all,fhem-all,"
unless ($uninstall);
$uninstall .= $_;
} }
$list .= " $uninstall"; )
{
next if ( $_ eq "npm" or $_ eq "undefined" );
$uninstall .= "," if ($uninstall);
$uninstall = "uninstall:all,fhem-all,"
unless ($uninstall);
$uninstall .= $_;
} }
$list .= " $uninstall";
} }
if ( defined( $hash->{".fhem"}{npm}{outdatedpackages} ) if ( defined( $hash->{".fhem"}{npm}{outdatedpackages} )
@ -734,7 +734,7 @@ sub ExecuteNpmCommand($) {
# One-time action to add remote hosts key. # One-time action to add remote hosts key.
# If key changes, user will need to intervene # If key changes, user will need to intervene
# and cleanup known_hosts file manually for security reasons # and cleanup known_hosts file manually for security reasons
$cmdPrefix = $cmdPrefix =
'KEY=$(ssh-keyscan -t ed25519 ' 'KEY=$(ssh-keyscan -t ed25519 '
. $2 . $2
@ -752,63 +752,58 @@ sub ExecuteNpmCommand($) {
$cmdSuffix = '\' 2>&1'; $cmdSuffix = '\' 2>&1';
} }
my $global = '-g ';
my $sudo = 'sudo -n -E ';
if ( $cmd->{npmglobal} eq '0' ) {
$global = '';
$sudo = '';
}
$npm->{nodejsversions} = $npm->{nodejsversions} =
$cmdPrefix $cmdPrefix
. 'echo n | node -e "console.log(JSON.stringify(process.versions));" 2>&1' . 'echo n | node -e "console.log(JSON.stringify(process.versions));" 2>&1'
. $cmdSuffix; . $cmdSuffix;
if ( $cmd->{npmglobal} == 0 ) { $npm->{npminstall} =
$npm->{npminstall} = $cmdPrefix
$cmdPrefix . 'echo n | sh -c "'
. 'echo n | npm install --json --silent --unsafe-perm %PACKAGES% 2>/dev/null' . $sudo
. $cmdSuffix; . 'npm install '
$npm->{npmuninstall} = . $global
$cmdPrefix . '--json --silent --unsafe-perm %PACKAGES%" 2>&1'
. 'echo n | npm uninstall --json --silent %PACKAGES% 2>/dev/null' . $cmdSuffix;
. $cmdSuffix; $npm->{npmuninstall} =
$npm->{npmupdate} = $cmdPrefix
$cmdPrefix . 'echo n | sh -c "'
. 'echo n | npm update --json --silent --unsafe-perm %PACKAGES% 2>/dev/null' . $sudo
. $cmdSuffix; . 'npm uninstall '
$npm->{npmoutdated} = . $global
$cmdPrefix . '--json --silent %PACKAGES%" 2>&1'
. 'echo n | ' . $cmdSuffix;
. 'echo "{' . "\n" $npm->{npmupdate} =
. '\"versions\": "; ' $cmdPrefix
. 'node -e "console.log(JSON.stringify(process.versions));"; ' . 'echo n | sh -c "'
. 'L1=$(npm list --json --silent --depth=0 2>/dev/null); ' . $sudo
. '[ "$L1" != "" ] && [ "$L1" != "\n" ] && echo ", \"listed\": $L1"; ' . 'npm update '
. 'L2=$(npm outdated --json 2>&1); ' . $global
. '[ "$L2" != "" ] && [ "$L2" != "\n" ] && echo ", \"outdated\": $L2"; ' . '--json --silent --unsafe-perm %PACKAGES%" 2>&1'
. 'echo "}"' . $cmdSuffix;
. $cmdSuffix; $npm->{npmoutdated} =
} $cmdPrefix
else { . 'echo n | '
$npm->{npminstall} = . 'echo "{' . "\n"
$cmdPrefix . '\"versions\": "; '
. 'echo n | sh -c "sudo -n npm install -g --json --silent --unsafe-perm %PACKAGES%" 2>&1' . 'node -e "console.log(JSON.stringify(process.versions));"; '
. $cmdSuffix; . 'L1=$(npm list '
$npm->{npmuninstall} = . $global
$cmdPrefix . '--json --silent --depth=0 2>/dev/null); '
. 'echo n | sh -c "sudo -n npm uninstall -g --json --silent %PACKAGES%" 2>&1' . '[ "$L1" != "" ] && [ "$L1" != "\n" ] && echo ", \"listed\": $L1"; '
. $cmdSuffix; . 'L2=$(npm outdated '
$npm->{npmupdate} = $cmdPrefix . $global
. '--json --silent 2>&1); '
# . 'echo n | sudo -n -E sh -c "npm update -g --json --silent --unsafe-perm %PACKAGES% 2>/dev/null" 2>&1' . '[ "$L2" != "" ] && [ "$L2" != "\n" ] && echo ", \"outdated\": $L2"; '
. 'echo n | sh -c "sudo -n npm update -g --json --silent --unsafe-perm %PACKAGES%" 2>&1' . 'echo "}"'
. $cmdSuffix; . $cmdSuffix;
$npm->{npmoutdated} =
$cmdPrefix
. 'echo n | '
. 'echo "{' . "\n"
. '\"versions\": "; '
. 'node -e "console.log(JSON.stringify(process.versions));"; '
. 'L1=$(npm list -g --json --silent --depth=0 2>/dev/null); '
. '[ "$L1" != "" ] && [ "$L1" != "\n" ] && echo ", \"listed\": $L1"; '
. 'L2=$(npm outdated -g --json 2>&1); '
. '[ "$L2" != "" ] && [ "$L2" != "\n" ] && echo ", \"outdated\": $L2"; '
. 'echo "}"'
. $cmdSuffix;
}
my $response; my $response;
@ -822,9 +817,9 @@ sub ExecuteNpmCommand($) {
elsif ( $1 =~ /^nodejs-v(\d+)/ ) { elsif ( $1 =~ /^nodejs-v(\d+)/ ) {
$npm->{npminstall} = $npm->{npminstall} =
$cmdPrefix $cmdPrefix
. "echo n | if [ -z \"\$(node --version 2>/dev/null)\" ]; then" . 'echo n | if [ -z "$(node --version 2>/dev/null)" ]; then'
. " curl -sSL https://deb.nodesource.com/setup_$1.x | DEBIAN_FRONTEND=noninteractive sudo -n -E sh -c \"bash - >/dev/null 2>&1\" 2>&1 &&" . ' sh -c "curl -sSL https://deb.nodesource.com/setup_'.$1.'.x | DEBIAN_FRONTEND=noninteractive sudo -n -E bash - >/dev/null 2>&1" 2>&1 &&'
. ' DEBIAN_FRONTEND=noninteractive sudo -n -E sh -c "apt-get install -qqy nodejs >/dev/null 2>&1" 2>&1; ' . ' sh -c "DEBIAN_FRONTEND=noninteractive sudo -n -E apt-get install -qqy nodejs >/dev/null 2>&1" 2>&1; '
. 'fi; ' . 'fi; '
. 'node -e "console.log(JSON.stringify(process.versions));" 2>&1' . 'node -e "console.log(JSON.stringify(process.versions));" 2>&1'
. $cmdSuffix; . $cmdSuffix;
@ -1638,7 +1633,7 @@ sub ToDay() {
"node", "node",
"npm" "npm"
], ],
"version": "v0.10.5", "version": "v0.10.6",
"release_status": "stable", "release_status": "stable",
"author": [ "author": [
"Julian Pawlowski <julian.pawlowski@gmail.com>" "Julian Pawlowski <julian.pawlowski@gmail.com>"