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
This commit is contained in:
Dmitrii Sorin 2019-10-03 07:26:44 +10:00 committed by Ryan Cavanaugh
parent f00069b980
commit 4a5cd9c56a
2 changed files with 16 additions and 9 deletions

18
types/npm/index.d.ts vendored
View File

@ -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;
}

View File

@ -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);
})