Skip to content

Commit e681aed

Browse files
Make sure framework dir is part of the cached framework
In some cases framework dir is missing in the npm cached package of the framework. Check if it exists and if not, remove the package from the cache and add it again. Fixes #699
1 parent c480c6b commit e681aed

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

lib/declarations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface INpmInstallationManager {
1515
install(packageName: string, options?: INpmInstallOptions): IFuture<string>;
1616
getLatestVersion(packageName: string): IFuture<string>;
1717
getCachedPackagePath(packageName: string, version: string): string;
18+
addCleanCopyToCache(packageName: string, version: string): IFuture<void>;
1819
}
1920

2021
interface INpmInstallOptions {

lib/npm-installation-manager.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import semver = require("semver");
66
import npm = require("npm");
77
import constants = require("./constants");
88

9-
export class NpmInstallationManager {
9+
export class NpmInstallationManager implements INpmInstallationManager {
1010
private static NPM_LOAD_FAILED = "Failed to retrieve data from npm. Please try again a little bit later.";
1111
private versionsCache: IDictionary<string[]>;
1212

@@ -38,6 +38,15 @@ export class NpmInstallationManager {
3838
}).future<void>()();
3939
}
4040

41+
public addCleanCopyToCache(packageName: string, version: string): IFuture<void> {
42+
return (() => {
43+
let packagePath = path.join(this.getCacheRootPath(), packageName, version);
44+
this.$logger.trace(`Deleting: ${packagePath}.`);
45+
this.$fs.deleteDirectory(path.join(this.getCacheRootPath(), packageName, version)).wait();
46+
this.addToCache(packageName, version).wait();
47+
}).future<void>()();
48+
}
49+
4150
public cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void> {
4251
unpackTarget = unpackTarget || path.join(npm.cache, packageName, version, "package");
4352
return this.$npm.cacheUnpack(packageName, version, unpackTarget);

lib/services/platform-service.ts

+15
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,26 @@ export class PlatformService implements IPlatformService {
496496
}).future<any>()();
497497
}
498498

499+
private checkNpmCache(pathToPackage: string): IFuture<void>{
500+
return (() => {
501+
let dirs = this.$fs.readDirectory(pathToPackage).wait();
502+
_.each(dirs, dir => {
503+
504+
})
505+
}).future<void>()();
506+
}
507+
499508
private ensurePackageIsCached(cachedPackagePath: string, packageName: string, version: string): IFuture<void> {
500509
return (() => {
501510
if(!this.$fs.exists(cachedPackagePath).wait()) {
502511
this.$npmInstallationManager.addToCache(packageName, version).wait();
503512
}
513+
514+
if(!this.$fs.exists(path.join(cachedPackagePath, constants.PROJECT_FRAMEWORK_FOLDER_NAME)).wait()) {
515+
// In some cases the package is not fully downloaded and the framework directory is missing
516+
// Try removing the old package and add it to the cache
517+
this.$npmInstallationManager.addCleanCopyToCache(packageName, version).wait();
518+
}
504519
}).future<void>()();
505520
}
506521

test/stubs.ts

+4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ export class NpmInstallationManagerStub implements INpmInstallationManager {
195195
return undefined;
196196
}
197197

198+
addCleanCopyToCache(packageName: string, version: string): IFuture<void> {
199+
return undefined;
200+
}
201+
198202
cacheUnpack(packageName: string, version: string): IFuture<void> {
199203
return undefined;
200204
}

0 commit comments

Comments
 (0)