diff --git a/lib/declarations.d.ts b/lib/declarations.d.ts index 2d9637d780..19cdc4e780 100644 --- a/lib/declarations.d.ts +++ b/lib/declarations.d.ts @@ -149,6 +149,37 @@ interface INpmPeerDependencyInfo { peerMissing: boolean; } +/** + * Describes information about dependency update packages. + */ +interface INpm5DependencyInfo { + /** + * Npm action type. + * @type {string} + */ + action: string; + /** + * Dependency name. + * @type {string} + */ + name: string; + /** + * Dependency version. + * @type {string} + */ + version: string; + /** + * Destination of the installation. + * @type {string} + */ + path: string; + /** + * Dependency previous version. + * @type {string} + */ + previousVersion: string; +} + /** * Describes information returned by the npm CLI upon calling install with --json flag. */ @@ -168,13 +199,54 @@ interface INpmInstallCLIResult { * Whenever installing npm prints the information by reversing the tree of operations and because the initial dependency was installed last it is listed first. * @type {INpmDependencyInfo | INpmPeerDependencyInfo} */ - dependencies: INpmDependencyInfo | INpmPeerDependencyInfo; + dependencies?: INpmDependencyInfo | INpmPeerDependencyInfo; /** * Describes problems that might have occurred during installation. For example missing peer dependencies. */ problems?: string[]; } +/** + * Describes information returned by the npm 5 CLI upon calling install with --json flag. + */ +interface INpm5InstallCliResult { + /** + * Added dependencies. Note that whenever add a particular dependency with npm 5 it is listed inside of array with key "Added". + * @type {INpmDependencyUpdateInfo[]} + */ + added: INpm5DependencyInfo[]; + /** + * Removed dependencies. Note that whenever remove a particular dependency with npm 5 it is listed inside of array with key "removed". + * @type {INpmDependencyUpdateInfo[]} + */ + removed: INpm5DependencyInfo[]; + /** + * Updated dependencies. Note that whenever update a particular dependency with npm 5 it is listed inside of array with key "updated". + * @type {INpmDependencyUpdateInfo[]} + */ + updated: INpm5DependencyInfo[]; + /** + * Moved dependencies. Note that whenever move a particular dependency with npm 5 it is listed inside of array with key "moved". + * @type {INpmDependencyUpdateInfo[]} + */ + moved: INpm5DependencyInfo[]; + /** + * Failed dependencies. Note that whenever use npm 5 and the operation over particular dependency fail it is listed inside of array with key "failed". + * @type {INpmDependencyUpdateInfo[]} + */ + failed: INpm5DependencyInfo[]; + /** + * Warnings. Note that whenever use npm 5 and the operation over particular dependency have warnings they are listed inside of array with key "warnings". + * @type {INpmDependencyUpdateInfo[]} + */ + warnings: INpm5DependencyInfo[]; + /** + *Time elapsed. + * @type {Number} + */ + elapsed: Number +} + /** * Describes information about installed package. */ @@ -193,7 +265,7 @@ interface INpmInstallResultInfo { * The original output that npm CLI produced upon installation. * @type {INpmInstallCLIResult} */ - originalOutput?: INpmInstallCLIResult; + originalOutput?: INpmInstallCLIResult | INpm5InstallCliResult; } interface INpmInstallOptions { diff --git a/lib/node-package-manager.ts b/lib/node-package-manager.ts index c64f2c8236..0538c9cef9 100644 --- a/lib/node-package-manager.ts +++ b/lib/node-package-manager.ts @@ -143,9 +143,23 @@ export class NodePackageManager implements INodePackageManager { private parseNpmInstallResult(npmDryRunInstallOutput: string, npmInstallOutput: string, userSpecifiedPackageName: string): INpmInstallResultInfo { // TODO: Add tests for this functionality try { - const originalOutput: INpmInstallCLIResult = JSON.parse(npmDryRunInstallOutput); - const name = _.head(_.keys(originalOutput.dependencies)); - const dependency = _.pick(originalOutput.dependencies, name); + const originalOutput: INpmInstallCLIResult | INpm5InstallCliResult = JSON.parse(npmDryRunInstallOutput); + const npm5Output = originalOutput; + const npmOutput = originalOutput; + const name = _.head(_.keys(npmOutput.dependencies)); + + // Npm 5 return different object after performing `npm install --dry-run`. + // Considering that the dependency is already installed we should + // find it in the `updated` key as a first element of the array. + if (!name && npm5Output.updated) { + const updatedDependency = npm5Output.updated[0]; + return { + name: updatedDependency.name, + originalOutput, + version: updatedDependency.version + }; + } + const dependency = _.pick(npmOutput.dependencies, name); return { name, originalOutput,