Skip to content

Commit f6ac5bf

Browse files
committed
Different npm install result from npm 5.
1 parent fb869c0 commit f6ac5bf

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

lib/declarations.d.ts

+38-1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,37 @@ interface INpmPeerDependencyInfo {
149149
peerMissing: boolean;
150150
}
151151

152+
/**
153+
* Describes information about dependency update packages.
154+
*/
155+
interface INpmDependencyUpdateInfo {
156+
/**
157+
* Npm action type.
158+
* @type {string}
159+
*/
160+
action: string;
161+
/**
162+
* Dependency name.
163+
* @type {string}
164+
*/
165+
name: string;
166+
/**
167+
* Dependency version.
168+
* @type {string}
169+
*/
170+
version: string;
171+
/**
172+
* Destination of the installation.
173+
* @type {string}
174+
*/
175+
path: string;
176+
/**
177+
* Dependency previous version.
178+
* @type {string}
179+
*/
180+
previousVersion: string;
181+
}
182+
152183
/**
153184
* Describes information returned by the npm CLI upon calling install with --json flag.
154185
*/
@@ -168,7 +199,13 @@ interface INpmInstallCLIResult {
168199
* Whenever installing npm prints the information by reversing the tree of operations and because the initial dependency was installed last it is listed first.
169200
* @type {INpmDependencyInfo | INpmPeerDependencyInfo}
170201
*/
171-
dependencies: INpmDependencyInfo | INpmPeerDependencyInfo;
202+
dependencies?: INpmDependencyInfo | INpmPeerDependencyInfo;
203+
204+
/**
205+
* Updated dependencies. Note that whenever update a particular dependency with npm 5 it is listed inside of array with key "updated".
206+
* @type {INpmDependencyUpdateInfo[]}
207+
*/
208+
updated?: INpmDependencyUpdateInfo[];
172209
/**
173210
* Describes problems that might have occurred during installation. For example missing peer dependencies.
174211
*/

lib/node-package-manager.ts

+12
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@ export class NodePackageManager implements INodePackageManager {
145145
try {
146146
const originalOutput: INpmInstallCLIResult = JSON.parse(npmDryRunInstallOutput);
147147
const name = _.head(_.keys(originalOutput.dependencies));
148+
149+
// Npm 5 return different object after performing `npm install --dry-run`.
150+
// Considering that the dependency is already installed we should
151+
// find it in the `updated` key as a first element of the array.
152+
if (!name && originalOutput.updated) {
153+
const updatedDependency = originalOutput.updated[0];
154+
return {
155+
name: updatedDependency.name,
156+
originalOutput,
157+
version: updatedDependency.version
158+
};
159+
}
148160
const dependency = _.pick<INpmDependencyInfo, INpmDependencyInfo | INpmPeerDependencyInfo>(originalOutput.dependencies, name);
149161
return {
150162
name,

0 commit comments

Comments
 (0)