Skip to content

Commit 61fcd40

Browse files
Fail when shasum is not correct
Fail when the shasum of the package is not correct.
1 parent 506fe60 commit 61fcd40

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/npm-installation-manager.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,14 @@ export class NpmInstallationManager implements INpmInstallationManager {
2828
return path.join(this.getCacheRootPath(), packageName, version, "package");
2929
}
3030

31-
public addToCache( packageName: string, version: string): IFuture<void> {
31+
public addToCache(packageName: string, version: string): IFuture<void> {
3232
return (() => {
33-
let shasumProperty = "dist.shasum";
3433
let cachedPackagePath = this.getCachedPackagePath(packageName, version);
3534
if(!this.$fs.exists(cachedPackagePath).wait()) {
3635
this.addToCacheCore(packageName, version).wait();
3736
}
3837

39-
let realShasum = this.$npm.view(`${packageName}@${version}`, shasumProperty).wait()[version][shasumProperty];
40-
let ourShasum = this.$fs.getFileShasum(cachedPackagePath + ".tgz").wait();
41-
this.$logger.trace(`Checking shasum of package: ${packageName}@${version}: expected ${realShasum}, actual ${ourShasum}.`);
42-
if(realShasum !== ourShasum) {
38+
if(!this.isShasumOfPackageCorrect(packageName, version).wait()) {
4339
// In some cases the package is not fully downloaded and the framework directory is missing
4440
// Try removing the old package and add the real one to cache again
4541
this.addCleanCopyToCache(packageName, version).wait();
@@ -88,6 +84,9 @@ export class NpmInstallationManager implements INpmInstallationManager {
8884
this.$logger.trace(`Deleting: ${packagePath}.`);
8985
this.$fs.deleteDirectory(packagePath).wait();
9086
this.addToCacheCore(packageName, version).wait();
87+
if(!this.isShasumOfPackageCorrect(packageName, version).wait()) {
88+
this.$errors.failWithoutHelp(`Unable to add package ${packageName} with version ${version} to npm cache. Try cleaning your cache and execute the command again.`)
89+
}
9190
}).future<void>()();
9291
}
9392

@@ -101,6 +100,17 @@ export class NpmInstallationManager implements INpmInstallationManager {
101100
}).future<void>()();
102101
}
103102

103+
private isShasumOfPackageCorrect(packageName: string, version: string): IFuture<boolean> {
104+
return ((): boolean => {
105+
let shasumProperty = "dist.shasum";
106+
let cachedPackagePath = this.getCachedPackagePath(packageName, version);
107+
let realShasum = this.$npm.view(`${packageName}@${version}`, shasumProperty).wait()[version][shasumProperty];
108+
let ourShasum = this.$fs.getFileShasum(cachedPackagePath + ".tgz").wait();
109+
this.$logger.trace(`Checking shasum of package: ${packageName}@${version}: expected ${realShasum}, actual ${ourShasum}.`);
110+
return realShasum === ourShasum;
111+
}).future<boolean>()();
112+
}
113+
104114
private installCore(packageName: string, pathToSave: string, version: string): IFuture<string> {
105115
return (() => {
106116
if (this.$options.frameworkPath) {

0 commit comments

Comments
 (0)