Skip to content

Fix installation of runtime with next tag #1568

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

Merged
merged 1 commit into from
Mar 7, 2016
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
3 changes: 1 addition & 2 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ interface INodePackageManager {

interface INpmInstallationManager {
getCacheRootPath(): string;
addToCache(packageName: string, version: string): IFuture<void>;
addToCache(packageName: string, version: string): IFuture<any>;
cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void>;
install(packageName: string, options?: INpmInstallOptions): IFuture<string>;
getLatestVersion(packageName: string): IFuture<string>;
getLatestCompatibleVersion(packageName: string): IFuture<string>;
getCachedPackagePath(packageName: string, version: string): string;
addCleanCopyToCache(packageName: string, version: string): IFuture<void>;
}

interface INpmInstallOptions {
Expand Down
46 changes: 28 additions & 18 deletions lib/npm-installation-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,26 @@ export class NpmInstallationManager implements INpmInstallationManager {
return path.join(this.getCacheRootPath(), packageName, version, "package");
}

public addToCache(packageName: string, version: string): IFuture<void> {
public addToCache(packageName: string, version: string): IFuture<any> {
return (() => {
let cachedPackagePath = this.getCachedPackagePath(packageName, version);
let cachedPackageData: any;
if(!this.$fs.exists(cachedPackagePath).wait() || !this.$fs.exists(path.join(cachedPackagePath, "framework")).wait()) {
this.addToCacheCore(packageName, version).wait();
cachedPackageData = this.addToCacheCore(packageName, version).wait();
}

if(!this.isShasumOfPackageCorrect(packageName, version).wait()) {
// In case the version is tag (for example `next`), we need the real version number from the cache.
// In these cases the cachePackageData is populated when data is added to the cache.
// Also whenever the version is tag, we always get inside the above `if` and the cachedPackageData is populated.
let realVersion = (cachedPackageData && cachedPackageData.version) || version;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can preferably add a comment here explaining why the cachedPackageData's version prevails over version if both are present

if(!this.isShasumOfPackageCorrect(packageName, realVersion).wait()) {
// In some cases the package is not fully downloaded and there are missing directories
// Try removing the old package and add the real one to cache again
this.addCleanCopyToCache(packageName, version).wait();
cachedPackageData = this.addCleanCopyToCache(packageName, version).wait();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the interface, addCleanCopyToCache(packageName: string, version: string): IFuture<void>;, so this reassignment of cachedPackageData is pointless.
I'm guessing the interface is a bit off.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :)

}
}).future<void>()();

return cachedPackageData;
}).future<any>()();
}

public cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void> {
Expand Down Expand Up @@ -125,26 +132,29 @@ export class NpmInstallationManager implements INpmInstallationManager {
}).future<string>()();
}

public addCleanCopyToCache(packageName: string, version: string): IFuture<void> {
private addCleanCopyToCache(packageName: string, version: string): IFuture<any> {
return (() => {
let packagePath = path.join(this.getCacheRootPath(), packageName, version);
this.$logger.trace(`Deleting: ${packagePath}.`);
this.$fs.deleteDirectory(packagePath).wait();
this.addToCacheCore(packageName, version).wait();
if(!this.isShasumOfPackageCorrect(packageName, version).wait()) {
this.$errors.failWithoutHelp(`Unable to add package ${packageName} with version ${version} to npm cache. Try cleaning your cache and execute the command again.`);
let cachedPackageData = this.addToCacheCore(packageName, version).wait();
if(!this.isShasumOfPackageCorrect(packageName, cachedPackageData.version).wait()) {
this.$errors.failWithoutHelp(`Unable to add package ${packageName} with version ${cachedPackageData.version} to npm cache. Try cleaning your cache and execute the command again.`);
}
}).future<void>()();

return cachedPackageData;
}).future<any>()();
}

private addToCacheCore(packageName: string, version: string): IFuture<void> {
private addToCacheCore(packageName: string, version: string): IFuture<any> {
return (() => {
this.$npm.cache(packageName, version).wait();
let packagePath = path.join(this.getCacheRootPath(), packageName, version, "package");
let cachedPackageData = this.$npm.cache(packageName, version).wait();
let packagePath = path.join(this.getCacheRootPath(), packageName, cachedPackageData.version, "package");
if(!this.isPackageUnpacked(packagePath, packageName).wait()) {
this.cacheUnpack(packageName, version).wait();
this.cacheUnpack(packageName, cachedPackageData.version).wait();
}
}).future<void>()();
return cachedPackageData;
}).future<any>()();
}

private isShasumOfPackageCorrect(packageName: string, version: string): IFuture<boolean> {
Expand Down Expand Up @@ -185,9 +195,9 @@ export class NpmInstallationManager implements INpmInstallationManager {
return path.join(pathToNodeModules, folders[0]);
} else {
version = version || this.getLatestCompatibleVersion(packageName).wait();
let packagePath = this.getCachedPackagePath(packageName, version);
this.addToCache(packageName, version).wait();
return packagePath;
let cachedData = this.addToCache(packageName, version).wait();
let packageVersion = (cachedData && cachedData.version) || version;
return this.getCachedPackagePath(packageName, packageVersion);
}
}).future<string>()();
}
Expand Down
15 changes: 2 additions & 13 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ export class PlatformService implements IPlatformService {
let currentVersion = data && data.version ? data.version : "0.2.0";
let newVersion = version || this.$npmInstallationManager.getLatestVersion(platformData.frameworkPackageName).wait();

this.ensurePackageIsCached(platformData.frameworkPackageName, newVersion).wait();
let cachedPackageData = this.$npmInstallationManager.addToCache(platformData.frameworkPackageName, newVersion).wait();
newVersion = (cachedPackageData && cachedPackageData.version) || newVersion;

let canUpdate = platformData.platformProjectService.canUpdatePlatform(currentVersion, newVersion).wait();
if(canUpdate) {
Expand Down Expand Up @@ -638,18 +639,6 @@ export class PlatformService implements IPlatformService {
}).future<any>()();
}

private ensurePackageIsCached(packageName: string, version: string): IFuture<void> {
return (() => {
this.$npmInstallationManager.addToCache(packageName, version).wait();
let cachedPackagePath = this.$npmInstallationManager.getCachedPackagePath(packageName, version);
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>()();
}

private mapFrameworkFiles(npmCacheDirectoryPath: string, files: string[]): string[] {
return _.map(files, file => file.substr(npmCacheDirectoryPath.length + constants.PROJECT_FRAMEWORK_FOLDER_NAME.length + 1));
}
Expand Down
4 changes: 0 additions & 4 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ 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