From 33e09a08c38d6d39847ab68e308a3ba4e554b57d Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Mon, 26 Oct 2015 08:29:56 +0200 Subject: [PATCH 1/2] Do not call npm install if everything is installed In case there's node_modules dir and there's directory for each dependency defined in package.json of the project, we should not call `npm install`. In case `node_modules` dir does not exist and the project has dependencies or any of the dependencies is not installed, we'll call `npm install`. Another case when we'll call `npm install` is when `--force` option is used. This change is in order to allow modifications of modules inside `node_modules` directory. --- lib/services/plugins-service.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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()(); } From aa1ab495a7446b9a3f47e4afe1b5acb0de9ceb38 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Mon, 26 Oct 2015 09:14:56 +0200 Subject: [PATCH 2/2] Install latest available version if no matching version is found In case CLI is version 1.4.x, on platform add we are trying to install latest available 1.4.x runtime. In case there's no 1.4.x version, the code fails. Instead we should install latest availabe version in this case. --- lib/npm-installation-manager.ts | 2 +- test/npm-installation-manager.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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/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); + }); });