diff --git a/lib/declarations.ts b/lib/declarations.ts index 0dac38feca..98fd4c5ab0 100644 --- a/lib/declarations.ts +++ b/lib/declarations.ts @@ -15,6 +15,7 @@ interface INpmInstallationManager { install(packageName: string, options?: INpmInstallOptions): IFuture; getLatestVersion(packageName: string): IFuture; getCachedPackagePath(packageName: string, version: string): string; + addCleanCopyToCache(packageName: string, version: string): IFuture; } interface INpmInstallOptions { diff --git a/lib/npm-installation-manager.ts b/lib/npm-installation-manager.ts index 5dad1eaa30..a8cf78cdc8 100644 --- a/lib/npm-installation-manager.ts +++ b/lib/npm-installation-manager.ts @@ -6,7 +6,7 @@ import semver = require("semver"); import npm = require("npm"); import constants = require("./constants"); -export class NpmInstallationManager { +export class NpmInstallationManager implements INpmInstallationManager { private static NPM_LOAD_FAILED = "Failed to retrieve data from npm. Please try again a little bit later."; private versionsCache: IDictionary; @@ -38,6 +38,15 @@ export class NpmInstallationManager { }).future()(); } + public addCleanCopyToCache(packageName: string, version: string): IFuture { + return (() => { + let packagePath = path.join(this.getCacheRootPath(), packageName, version); + this.$logger.trace(`Deleting: ${packagePath}.`); + this.$fs.deleteDirectory(packagePath).wait(); + this.addToCache(packageName, version).wait(); + }).future()(); + } + public cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture { unpackTarget = unpackTarget || path.join(npm.cache, packageName, version, "package"); return this.$npm.cacheUnpack(packageName, version, unpackTarget); diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index f248539124..17ddce5391 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -501,6 +501,12 @@ export class PlatformService implements IPlatformService { if(!this.$fs.exists(cachedPackagePath).wait()) { this.$npmInstallationManager.addToCache(packageName, version).wait(); } + + if(!this.$fs.exists(path.join(cachedPackagePath, constants.PROJECT_FRAMEWORK_FOLDER_NAME)).wait()) { + // In some cases the package is not fully downloaded and the framework directory is missing + // Try removing the old package and add the real one to cache again + this.$npmInstallationManager.addCleanCopyToCache(packageName, version).wait(); + } }).future()(); } diff --git a/test/stubs.ts b/test/stubs.ts index e718909776..62e1263462 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -195,6 +195,10 @@ export class NpmInstallationManagerStub implements INpmInstallationManager { return undefined; } + addCleanCopyToCache(packageName: string, version: string): IFuture { + return undefined; + } + cacheUnpack(packageName: string, version: string): IFuture { return undefined; }