Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different npm install result from npm 5. #2926

Merged
merged 1 commit into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 73 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 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.
*/
Expand All @@ -175,6 +206,47 @@ interface INpmInstallCLIResult {
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.
*/
Expand All @@ -193,7 +265,7 @@ interface INpmInstallResultInfo {
* The original output that npm CLI produced upon installation.
* @type {INpmInstallCLIResult}
*/
originalOutput?: INpmInstallCLIResult;
originalOutput?: INpmInstallCLIResult | INpm5InstallCliResult;
}

interface INpmInstallOptions {
Expand Down
20 changes: 17 additions & 3 deletions lib/node-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<INpmDependencyInfo, INpmDependencyInfo | INpmPeerDependencyInfo>(originalOutput.dependencies, name);
const originalOutput: INpmInstallCLIResult | INpm5InstallCliResult = JSON.parse(npmDryRunInstallOutput);
const npm5Output = <INpm5InstallCliResult> originalOutput;
const npmOutput = <INpmInstallCLIResult> 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<INpmDependencyInfo, INpmDependencyInfo | INpmPeerDependencyInfo>(npmOutput.dependencies, name);
return {
name,
originalOutput,
Expand Down