Skip to content

Commit b75a4e4

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 b75a4e4

File tree

4 files changed

+31
-37
lines changed

4 files changed

+31
-37
lines changed

lib/declarations.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ 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>;
1818
getLatestCompatibleVersion(packageName: string): IFuture<string>;
1919
getCachedPackagePath(packageName: string, version: string): string;
20-
addCleanCopyToCache(packageName: string, version: string): IFuture<void>;
2120
}
2221

2322
interface INpmInstallOptions {

lib/npm-installation-manager.ts

+28-18
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,26 @@ 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
}
5152

52-
if(!this.isShasumOfPackageCorrect(packageName, version).wait()) {
53+
// In case the version is tag (for example `next`), we need the real version number from the cache.
54+
// In these cases the cachePackageData is populated when data is added to the cache.
55+
// Also whenever the version is tag, we always get inside the above `if` and the cachedPackageData is populated.
56+
let realVersion = (cachedPackageData && cachedPackageData.version) || version;
57+
if(!this.isShasumOfPackageCorrect(packageName, realVersion).wait()) {
5358
// In some cases the package is not fully downloaded and there are missing directories
5459
// Try removing the old package and add the real one to cache again
55-
this.addCleanCopyToCache(packageName, version).wait();
60+
cachedPackageData = this.addCleanCopyToCache(packageName, version).wait();
5661
}
57-
}).future<void>()();
62+
63+
return cachedPackageData;
64+
}).future<any>()();
5865
}
5966

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

128-
public addCleanCopyToCache(packageName: string, version: string): IFuture<void> {
135+
private addCleanCopyToCache(packageName: string, version: string): IFuture<any> {
129136
return (() => {
130137
let packagePath = path.join(this.getCacheRootPath(), packageName, version);
131138
this.$logger.trace(`Deleting: ${packagePath}.`);
132139
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.`);
140+
let cachedPackageData = this.addToCacheCore(packageName, version).wait();
141+
if(!this.isShasumOfPackageCorrect(packageName, cachedPackageData.version).wait()) {
142+
this.$errors.failWithoutHelp(`Unable to add package ${packageName} with version ${cachedPackageData.version} to npm cache. Try cleaning your cache and execute the command again.`);
136143
}
137-
}).future<void>()();
144+
145+
return cachedPackageData;
146+
}).future<any>()();
138147
}
139148

140-
private addToCacheCore(packageName: string, version: string): IFuture<void> {
149+
private addToCacheCore(packageName: string, version: string): IFuture<any> {
141150
return (() => {
142-
this.$npm.cache(packageName, version).wait();
143-
let packagePath = path.join(this.getCacheRootPath(), packageName, version, "package");
151+
let cachedPackageData = this.$npm.cache(packageName, version).wait();
152+
let packagePath = path.join(this.getCacheRootPath(), packageName, cachedPackageData.version, "package");
144153
if(!this.isPackageUnpacked(packagePath, packageName).wait()) {
145-
this.cacheUnpack(packageName, version).wait();
154+
this.cacheUnpack(packageName, cachedPackageData.version).wait();
146155
}
147-
}).future<void>()();
156+
return cachedPackageData;
157+
}).future<any>()();
148158
}
149159

150160
private isShasumOfPackageCorrect(packageName: string, version: string): IFuture<boolean> {
@@ -185,9 +195,9 @@ export class NpmInstallationManager implements INpmInstallationManager {
185195
return path.join(pathToNodeModules, folders[0]);
186196
} else {
187197
version = version || this.getLatestCompatibleVersion(packageName).wait();
188-
let packagePath = this.getCachedPackagePath(packageName, version);
189-
this.addToCache(packageName, version).wait();
190-
return packagePath;
198+
let cachedData = this.addToCache(packageName, version).wait();
199+
let packageVersion = (cachedData && cachedData.version) || version;
200+
return this.getCachedPackagePath(packageName, packageVersion);
191201
}
192202
}).future<string>()();
193203
}

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
}

test/stubs.ts

-4
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,6 @@ export class NpmInstallationManagerStub implements INpmInstallationManager {
212212
return undefined;
213213
}
214214

215-
addCleanCopyToCache(packageName: string, version: string): IFuture<void> {
216-
return undefined;
217-
}
218-
219215
cacheUnpack(packageName: string, version: string): IFuture<void> {
220216
return undefined;
221217
}

0 commit comments

Comments
 (0)