You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`npm` module provides a way to interact with npm specifically the use of install, uninstall, search and view commands.
224
+
225
+
### install
226
+
Installs specified package. Note that you can use the third argument in order to pass different options to the installation like `ignore-scripts`, `save` or `save-exact` which work exactly like they would if you would execute npm from the command line and pass them as `--` flags.
227
+
* Auxiliary interfaces:
228
+
```TypeScript
229
+
/**
230
+
* Describes information about installed package.
231
+
*/
232
+
interface INpmInstallResultInfo {
233
+
/**
234
+
* Installed package's name.
235
+
* @type{string}
236
+
*/
237
+
name: string;
238
+
/**
239
+
* Installed package's version.
240
+
* @type{string}
241
+
*/
242
+
version: string;
243
+
/**
244
+
* The original output that npm CLI produced upon installation.
245
+
* @type{INpmInstallCLIResult}
246
+
*/
247
+
originalOutput: INpmInstallCLIResult;
248
+
}
249
+
```
250
+
251
+
* Definition:
252
+
```TypeScript
253
+
/**
254
+
* Installs dependency
255
+
* @param{string}packageName The name of the dependency - can be a path, a url or a string.
256
+
* @param{string}pathToSave The destination of the installation.
257
+
* @param{IDictionary<string | boolean>}config Additional options that can be passed to manipulate installation.
258
+
* @return{Promise<INpmInstallResultInfo>} Information about installed package.
console.log(`${result.name}'s latest version is ${result["dist-tags"].latest}`);
337
+
}, err=> {
338
+
console.log("An error occurred during viewing", err);
339
+
});
340
+
```
341
+
222
342
## How to add a new method to Public API
223
343
CLI is designed as command line tool and when it is used as a library, it does not give you access to all of the methods. This is mainly implementation detail. Most of the CLI's code is created to work in command line, not as a library, so before adding method to public API, most probably it will require some modification.
224
344
For example the `$options` injected module contains information about all `--` options passed on the terminal. When the CLI is used as a library, the options are not populated. Before adding method to public API, make sure its implementation does not rely on `$options`.
0 commit comments