Skip to content

Commit d18c984

Browse files
Fix installation of runtime with next tag
Our npmInstallationManager is using the passed `next` string as a version and searches for directory called `next` in the npm cache. Instead it should use the real version. Fix this by getting the result of npm call addToCache, which returns object with information about cached package.
1 parent 8dfd459 commit d18c984

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

lib/declarations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface INodePackageManager {
1111

1212
interface INpmInstallationManager {
1313
getCacheRootPath(): string;
14-
addToCache(packageName: string, version: string): IFuture<void>;
14+
addToCache(packageName: string, version: string): IFuture<any>;
1515
cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void>;
1616
install(packageName: string, options?: INpmInstallOptions): IFuture<string>;
1717
getLatestVersion(packageName: string): IFuture<string>;

lib/npm-installation-manager.ts

+23-17
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,22 @@ export class NpmInstallationManager implements INpmInstallationManager {
4242
return path.join(this.getCacheRootPath(), packageName, version, "package");
4343
}
4444

45-
public addToCache(packageName: string, version: string): IFuture<void> {
45+
public addToCache(packageName: string, version: string): IFuture<any> {
4646
return (() => {
4747
let cachedPackagePath = this.getCachedPackagePath(packageName, version);
48+
let cachedPackageData: any;
4849
if(!this.$fs.exists(cachedPackagePath).wait() || !this.$fs.exists(path.join(cachedPackagePath, "framework")).wait()) {
49-
this.addToCacheCore(packageName, version).wait();
50+
cachedPackageData = this.addToCacheCore(packageName, version).wait();
5051
}
51-
52-
if(!this.isShasumOfPackageCorrect(packageName, version).wait()) {
52+
let realVersion = (cachedPackageData && cachedPackageData.version) || version;
53+
if(!this.isShasumOfPackageCorrect(packageName, realVersion).wait()) {
5354
// In some cases the package is not fully downloaded and there are missing directories
5455
// Try removing the old package and add the real one to cache again
55-
this.addCleanCopyToCache(packageName, version).wait();
56+
cachedPackageData = this.addCleanCopyToCache(packageName, version).wait();
5657
}
57-
}).future<void>()();
58+
59+
return cachedPackageData;
60+
}).future<any>()();
5861
}
5962

6063
public cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void> {
@@ -130,21 +133,24 @@ export class NpmInstallationManager implements INpmInstallationManager {
130133
let packagePath = path.join(this.getCacheRootPath(), packageName, version);
131134
this.$logger.trace(`Deleting: ${packagePath}.`);
132135
this.$fs.deleteDirectory(packagePath).wait();
133-
this.addToCacheCore(packageName, version).wait();
134-
if(!this.isShasumOfPackageCorrect(packageName, version).wait()) {
135-
this.$errors.failWithoutHelp(`Unable to add package ${packageName} with version ${version} to npm cache. Try cleaning your cache and execute the command again.`);
136+
let cachedPackageData = this.addToCacheCore(packageName, version).wait();
137+
if(!this.isShasumOfPackageCorrect(packageName, cachedPackageData.version).wait()) {
138+
this.$errors.failWithoutHelp(`Unable to add package ${packageName} with version ${cachedPackageData.version} to npm cache. Try cleaning your cache and execute the command again.`);
136139
}
140+
141+
return cachedPackageData;
137142
}).future<void>()();
138143
}
139144

140-
private addToCacheCore(packageName: string, version: string): IFuture<void> {
145+
private addToCacheCore(packageName: string, version: string): IFuture<any> {
141146
return (() => {
142-
this.$npm.cache(packageName, version).wait();
143-
let packagePath = path.join(this.getCacheRootPath(), packageName, version, "package");
147+
let cachedPackageData = this.$npm.cache(packageName, version).wait();
148+
let packagePath = path.join(this.getCacheRootPath(), packageName, cachedPackageData.version, "package");
144149
if(!this.isPackageUnpacked(packagePath, packageName).wait()) {
145-
this.cacheUnpack(packageName, version).wait();
150+
this.cacheUnpack(packageName, cachedPackageData.version).wait();
146151
}
147-
}).future<void>()();
152+
return cachedPackageData;
153+
}).future<any>()();
148154
}
149155

150156
private isShasumOfPackageCorrect(packageName: string, version: string): IFuture<boolean> {
@@ -185,9 +191,9 @@ export class NpmInstallationManager implements INpmInstallationManager {
185191
return path.join(pathToNodeModules, folders[0]);
186192
} else {
187193
version = version || this.getLatestCompatibleVersion(packageName).wait();
188-
let packagePath = this.getCachedPackagePath(packageName, version);
189-
this.addToCache(packageName, version).wait();
190-
return packagePath;
194+
let cachedData = this.addToCache(packageName, version).wait();
195+
let packageVersion = (cachedData && cachedData.version) || version;
196+
return this.getCachedPackagePath(packageName, packageVersion);
191197
}
192198
}).future<string>()();
193199
}

lib/services/platform-service.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@ export class PlatformService implements IPlatformService {
549549
let currentVersion = data && data.version ? data.version : "0.2.0";
550550
let newVersion = version || this.$npmInstallationManager.getLatestVersion(platformData.frameworkPackageName).wait();
551551

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

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

641-
private ensurePackageIsCached(packageName: string, version: string): IFuture<void> {
642-
return (() => {
643-
this.$npmInstallationManager.addToCache(packageName, version).wait();
644-
let cachedPackagePath = this.$npmInstallationManager.getCachedPackagePath(packageName, version);
645-
if(!this.$fs.exists(path.join(cachedPackagePath, constants.PROJECT_FRAMEWORK_FOLDER_NAME)).wait()) {
646-
// In some cases the package is not fully downloaded and the framework directory is missing
647-
// Try removing the old package and add the real one to cache again
648-
this.$npmInstallationManager.addCleanCopyToCache(packageName, version).wait();
649-
}
650-
}).future<void>()();
651-
}
652-
653642
private mapFrameworkFiles(npmCacheDirectoryPath: string, files: string[]): string[] {
654643
return _.map(files, file => file.substr(npmCacheDirectoryPath.length + constants.PROJECT_FRAMEWORK_FOLDER_NAME.length + 1));
655644
}

0 commit comments

Comments
 (0)