diff --git a/lib/npm-installation-manager.ts b/lib/npm-installation-manager.ts index f716159fa4..2498150338 100644 --- a/lib/npm-installation-manager.ts +++ b/lib/npm-installation-manager.ts @@ -84,7 +84,7 @@ export class NpmInstallationManager implements INpmInstallationManager { .sortBy(verData => verData.patch) .value(); - let result = _.last(compatibleVersions); + let result = _.last(compatibleVersions) || this.getVersionData(latestVersion); let latestCompatibleVersion = `${result.major}.${result.minor}.${result.patch}`; return latestCompatibleVersion; diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index 80999b75da..2d630e34d2 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -161,11 +161,15 @@ export class PluginsService implements IPluginsService { public ensureAllDependenciesAreInstalled(): IFuture { return (() => { - let command = "npm install "; - if(this.$options.ignoreScripts) { - command += "--ignore-scripts"; + let installedDependencies = this.$fs.exists(this.nodeModulesPath).wait() ? this.$fs.readDirectory(this.nodeModulesPath).wait() : []; + let packageJsonContent = this.$fs.readJson(this.getPackageJsonFilePath()).wait(); + if(this.$options.force || (packageJsonContent.dependencies && _.difference(_.keys(packageJsonContent.dependencies), installedDependencies).length)) { + let command = "npm install "; + if(this.$options.ignoreScripts) { + command += "--ignore-scripts"; + } + this.$childProcess.exec(command, { cwd: this.$projectData.projectDir }).wait(); } - this.$childProcess.exec(command, { cwd: this.$projectData.projectDir }).wait(); }).future()(); } diff --git a/test/npm-installation-manager.ts b/test/npm-installation-manager.ts index 13ef0e9e35..43bf7b55c1 100644 --- a/test/npm-installation-manager.ts +++ b/test/npm-installation-manager.ts @@ -72,6 +72,7 @@ describe("Npm installation manager tests", () => { let expectedLatestCompatibleVersion = "1.4.0"; assert.equal(actualLatestCompatibleVersion, expectedLatestCompatibleVersion); }); + it("returns correct latest compatible version", () => { let testInjector = createTestInjector(); @@ -92,4 +93,23 @@ describe("Npm installation manager tests", () => { let expectedLatestCompatibleVersion = "1.3.3"; assert.equal(actualLatestCompatibleVersion, expectedLatestCompatibleVersion); }); + + it("returns correct latest compatible version", () => { + let testInjector = createTestInjector(); + + let versions = ["1.2.0", "1.3.0", "1.3.1", "1.3.2", "1.3.3", "1.4.0"]; + let latestVersion = _.last(versions); + mockNpm(testInjector, versions, latestVersion); + + // Mock staticConfig.version + let staticConfig = testInjector.resolve("staticConfig"); + staticConfig.version = "1.5.0"; + + // Mock npmInstallationManager.getLatestVersion + let npmInstallationManager = testInjector.resolve("npmInstallationManager"); + npmInstallationManager.getLatestVersion = (packageName: string) => Future.fromResult(latestVersion); + + let actualLatestCompatibleVersion = npmInstallationManager.getLatestCompatibleVersion("").wait(); + assert.equal(actualLatestCompatibleVersion, latestVersion); + }); });