Skip to content

Install ALL dependencies and devDependencies before prepare #1186

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 1 commit into from
Nov 13, 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
7 changes: 0 additions & 7 deletions lib/definitions/plugins.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ interface IPluginsService {
getAllInstalledPlugins(): IFuture<IPluginData[]>;
ensureAllDependenciesAreInstalled(): IFuture<void>;
afterPrepareAllPlugins(): IFuture<void>;
/**
* Installs all devDependencies of the project.
* In case all of them are already installed, no operation will be executed.
* In case any of them is missing, all of them will be installed.
* @return {IFuture<void>}
*/
installDevDependencies(): IFuture<void>;
}

interface IPluginData extends INodeModuleData {
Expand Down
10 changes: 7 additions & 3 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,13 @@ export class PlatformService implements IPlatformService {
return (() => {
this.validatePlatform(platform);

//Install dev-dependencies here, so before-prepare hooks will be executed correctly.
this.$pluginsService.installDevDependencies().wait();
//We need dev-dependencies here, so before-prepare hooks will be executed correctly.
try {
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();
} catch(err) {
this.$logger.trace(err);
this.$errors.failWithoutHelp(`Unable to install dependencies. Make sure your package.json is valid and all dependencies are correct. Error is: ${err.message}`);
}

this.preparePlatformCore(platform).wait();
}).future<void>()();
Expand Down Expand Up @@ -223,7 +228,6 @@ export class PlatformService implements IPlatformService {
// Process node_modules folder
let appDir = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
try {
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();
let tnsModulesDestinationPath = path.join(appDir, PlatformService.TNS_MODULES_FOLDER_NAME);
this.$broccoliBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime).wait();
} catch(error) {
Expand Down
19 changes: 2 additions & 17 deletions lib/services/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export class PluginsService implements IPluginsService {
return (() => {
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 allDependencies = _.keys(packageJsonContent.dependencies).concat(_.keys(packageJsonContent.devDependencies));
if(this.$options.force || _.difference(allDependencies, installedDependencies).length) {
let command = "npm install ";
if(this.$options.ignoreScripts) {
command += "--ignore-scripts";
Expand All @@ -185,22 +186,6 @@ export class PluginsService implements IPluginsService {
return this.executeForAllInstalledPlatforms(action);
}

public installDevDependencies(): IFuture<void> {
return (() => {
let installedDependencies = this.$fs.exists(this.nodeModulesPath).wait() ? this.$fs.readDirectory(this.nodeModulesPath).wait() : [];
let packageJsonContent = this.$fs.readJson(this.getPackageJsonFilePath()).wait();
let devDependencies = _.keys(packageJsonContent.devDependencies);
if(devDependencies.length && (this.$options.force || _.difference(devDependencies, installedDependencies).length)) {
let command = `npm install ${devDependencies.join(" ")}`;
if(this.$options.ignoreScripts) {
command += "--ignore-scripts";
}
this.$logger.trace(`Command for installing devDependencies is: '${command}'.`);
this.$childProcess.exec(command, { cwd: this.$projectData.projectDir }).wait();
}
}).future<void>()();
}

private get nodeModulesPath(): string {
return path.join(this.$projectData.projectDir, "node_modules");
}
Expand Down
3 changes: 1 addition & 2 deletions test/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ function createTestInjector() {
},
ensureAllDependenciesAreInstalled: () => {
return Future.fromResult();
},
installDevDependencies: () => Future.fromResult()
}
});
testInjector.register("projectFilesManager", ProjectFilesManagerLib.ProjectFilesManager);
testInjector.register("hooksService", stubs.HooksServiceStub);
Expand Down