public virtual async Task <bool> ExecuteAsync() { OnCommandStarted(); var redirector = new NpmCommandRedirector(this); try { GetPathToNpm(); } catch (NpmNotFoundException) { redirector.WriteErrorLine(Resources.CouldNotFindNpm); return(false); } redirector.WriteLine( string.Format(CultureInfo.InvariantCulture, "===={0}====\r\n\r\n", string.Format(CultureInfo.InvariantCulture, Resources.ExecutingCommand, Arguments))); var cancelled = false; try { await NpmHelpers.ExecuteNpmCommandAsync( redirector, GetPathToNpm(), _fullPathToRootPackageDirectory, new[] { Arguments }, _cancellation); } catch (OperationCanceledException) { cancelled = true; } OnCommandCompleted(Arguments, redirector.HasErrors, cancelled); return(!redirector.HasErrors); }
public async Task TestNpmCommandProcessExitSucceeds() { var npmPath = NpmHelpers.GetPathToNpm(); var redirector = new NpmCommand.NpmCommandRedirector(new NpmBinCommand(null, false)); for (int j = 0; j < 200; j++) { await NpmHelpers.ExecuteNpmCommandAsync( redirector, npmPath, null, new[] { "config", "get", "registry" }, null); } }
private async Task <Uri> GetRegistryUrl() { var output = await NpmHelpers.ExecuteNpmCommandAsync( null, GetPathToNpm(), FullPathToRootPackageDirectory, new[] { "config", "get", "registry" }, null); if (output != null) { _registryUrl = output .Select(s => { Uri u; return(Uri.TryCreate(s, UriKind.Absolute, out u) ? u : null); }) .FirstOrDefault(u => u != null); } _registryUrl = _registryUrl ?? new Uri("https://registry.npmjs.org/"); return(_registryUrl); }
public virtual async Task <bool> ExecuteAsync() { this.OnCommandStarted(); var redirector = this.showConsole ? null : new NpmCommandRedirector(this); var cancelled = false; try { // Call this method first to throw a NpmNotFoundException before writing anything to the output. var pathToNpm = this.GetPathToNpm(); redirector?.WriteLine( string.Format(CultureInfo.InvariantCulture, "===={0}====\r\n\r\n", string.Format(CultureInfo.InvariantCulture, Resources.ExecutingCommand, this.Arguments))); await NpmHelpers.ExecuteNpmCommandAsync( redirector, pathToNpm, this.FullPathToRootPackageDirectory, new[] { this.Arguments }, this.showConsole, cancellationResetEvent : this.cancellation); } catch (NpmNotFoundException) { redirector?.WriteErrorLine(Resources.CouldNotFindNpm); return(false); } catch (OperationCanceledException) { cancelled = true; } finally { this.OnCommandCompleted(this.Arguments, redirector?.HasErrors ?? false, cancelled); } return(redirector?.HasErrors != true); // return true when the command completed without errors, or redirector is null (which means we can't track) }