Skip to content

Commit 33e09a0

Browse files
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.
1 parent 10d8321 commit 33e09a0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/services/plugins-service.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,15 @@ export class PluginsService implements IPluginsService {
161161

162162
public ensureAllDependenciesAreInstalled(): IFuture<void> {
163163
return (() => {
164-
let command = "npm install ";
165-
if(this.$options.ignoreScripts) {
166-
command += "--ignore-scripts";
164+
let installedDependencies = this.$fs.exists(this.nodeModulesPath).wait() ? this.$fs.readDirectory(this.nodeModulesPath).wait() : [];
165+
let packageJsonContent = this.$fs.readJson(this.getPackageJsonFilePath()).wait();
166+
if(this.$options.force || (packageJsonContent.dependencies && _.difference(_.keys(packageJsonContent.dependencies), installedDependencies).length)) {
167+
let command = "npm install ";
168+
if(this.$options.ignoreScripts) {
169+
command += "--ignore-scripts";
170+
}
171+
this.$childProcess.exec(command, { cwd: this.$projectData.projectDir }).wait();
167172
}
168-
this.$childProcess.exec(command, { cwd: this.$projectData.projectDir }).wait();
169173
}).future<void>()();
170174
}
171175

0 commit comments

Comments
 (0)