Skip to content

Make sure framework dir is part of the cached framework #708

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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface INpmInstallationManager {
install(packageName: string, options?: INpmInstallOptions): IFuture<string>;
getLatestVersion(packageName: string): IFuture<string>;
getCachedPackagePath(packageName: string, version: string): string;
addCleanCopyToCache(packageName: string, version: string): IFuture<void>;
}

interface INpmInstallOptions {
Expand Down
11 changes: 10 additions & 1 deletion lib/npm-installation-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>;

Expand Down Expand Up @@ -38,6 +38,15 @@ export class NpmInstallationManager {
}).future<void>()();
}

public addCleanCopyToCache(packageName: string, version: string): IFuture<void> {
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<void>()();
}

public cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void> {
unpackTarget = unpackTarget || path.join(npm.cache, packageName, version, "package");
return this.$npm.cacheUnpack(packageName, version, unpackTarget);
Expand Down
6 changes: 6 additions & 0 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>()();
}

Expand Down
4 changes: 4 additions & 0 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ export class NpmInstallationManagerStub implements INpmInstallationManager {
return undefined;
}

addCleanCopyToCache(packageName: string, version: string): IFuture<void> {
return undefined;
}

cacheUnpack(packageName: string, version: string): IFuture<void> {
return undefined;
}
Expand Down