From 4a5cd9c56ac79c44516b6845de9b4b9d77c9261e Mon Sep 17 00:00:00 2001 From: Dmitrii Sorin Date: Thu, 3 Oct 2019 07:26:44 +1000 Subject: [PATCH] Support silent function calls (#38531) * Support silent function calls NPM API commands support a second parameter which is boolean: https://github.com/npm/cli/blob/latest/lib/view.js#L76 https://github.com/npm/cli/blob/latest/lib/ls.js#L33 * Update overload types for info command * Revert "Support silent function calls" This reverts commit 4d18bdc187ba836a6ecb37c5e530066c48066915. * Update tests --- types/npm/index.d.ts | 18 +++++++++++------- types/npm/npm-tests.ts | 7 +++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/types/npm/index.d.ts b/types/npm/index.d.ts index 066a932440..3051fba096 100644 --- a/types/npm/index.d.ts +++ b/types/npm/index.d.ts @@ -37,7 +37,6 @@ declare namespace NPM { //#region Commands Interfaces export interface Commands { - // Commands install: CommandFunction; uninstall: CommandFunction; cache: CommandFunction; @@ -68,7 +67,6 @@ declare namespace NPM { "help-search": CommandFunction; ls: CommandFunction; search: CommandFunction; - view: CommandFunction; init: CommandFunction; version: CommandFunction; edit: CommandFunction; @@ -82,6 +80,16 @@ declare namespace NPM { bin: CommandFunction; whoami: CommandFunction; + // view and its aliases + view(args: string[], callback: CommandCallback): void; + view(args: string[], silent: boolean, callback: CommandCallback): void; + info(args: string[], callback: CommandCallback): void; + info(args: string[], silent: boolean, callback: CommandCallback): void; + show(args: string[], callback: CommandCallback): void; + show(args: string[], silent: boolean, callback: CommandCallback): void; + v(args: string[], callback: CommandCallback): void; + v(args: string[], silent: boolean, callback: CommandCallback): void; + test: CommandFunction; stop: CommandFunction; start: CommandFunction; @@ -103,8 +111,6 @@ declare namespace NPM { isntall: CommandFunction; // install up: CommandFunction; // update c: CommandFunction; // config - info: CommandFunction; // view - show: CommandFunction; // view find: CommandFunction; // search s: CommandFunction; // search se: CommandFunction; // search @@ -119,7 +125,7 @@ declare namespace NPM { t: CommandFunction; // test "find-dupes": CommandFunction; // dedupe ddp: CommandFunction; // dedupe - v: CommandFunction; // view + // plumbing build: CommandFunction; @@ -129,11 +135,9 @@ declare namespace NPM { visnup: CommandFunction; } - export interface CommandFunction { (args: string[], callback: CommandCallback): void; } - export interface CommandCallback { (err?: Error, result?: any, result2?: any, result3?: any, result4?: any): void; } diff --git a/types/npm/npm-tests.ts b/types/npm/npm-tests.ts index 460e6f450a..b784ab7d4b 100644 --- a/types/npm/npm-tests.ts +++ b/types/npm/npm-tests.ts @@ -4,7 +4,7 @@ * Created by using code samples from https://github.com/npm/npm#using-npm-programmatically. */ -import npm = require("npm"); +import * as npm from 'npm'; npm.load({}, function (er) { if (er) { @@ -19,9 +19,12 @@ npm.load({}, function (er) { // command succeeded, and data might have some info }); + npm.commands.view(["some", "args"], true, function () {}); // silent: true + npm.commands.view(["some", "args"], function () {}); + npm.on("log", function (message: string) { console.log(message); }); - + npm.config.set('audit', false); })