Skip to content

Do not call npm install if everything is installed #1102

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 2 commits into from
Oct 26, 2015
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
2 changes: 1 addition & 1 deletion lib/npm-installation-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions lib/services/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,15 @@ export class PluginsService implements IPluginsService {

public ensureAllDependenciesAreInstalled(): IFuture<void> {
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<void>()();
}

Expand Down
20 changes: 20 additions & 0 deletions test/npm-installation-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
});
});