Skip to content

Commit

Permalink
Different npm install result from npm 5.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomaNikolov committed Jun 27, 2017
1 parent fb869c0 commit f6ac5bf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
39 changes: 38 additions & 1 deletion lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,37 @@ interface INpmPeerDependencyInfo {
peerMissing: boolean;
}

/**
* Describes information about dependency update packages.
*/
interface INpmDependencyUpdateInfo {
/**
* 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.
*/
Expand All @@ -168,7 +199,13 @@ 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;

/**
* Updated dependencies. Note that whenever update a particular dependency with npm 5 it is listed inside of array with key "updated".
* @type {INpmDependencyUpdateInfo[]}
*/
updated?: INpmDependencyUpdateInfo[];
/**
* Describes problems that might have occurred during installation. For example missing peer dependencies.
*/
Expand Down
12 changes: 12 additions & 0 deletions lib/node-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ export class NodePackageManager implements INodePackageManager {
try {
const originalOutput: INpmInstallCLIResult = JSON.parse(npmDryRunInstallOutput);
const name = _.head(_.keys(originalOutput.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 && originalOutput.updated) {
const updatedDependency = originalOutput.updated[0];
return {
name: updatedDependency.name,
originalOutput,
version: updatedDependency.version
};
}
const dependency = _.pick<INpmDependencyInfo, INpmDependencyInfo | INpmPeerDependencyInfo>(originalOutput.dependencies, name);
return {
name,
Expand Down

0 comments on commit f6ac5bf

Please sign in to comment.