Skip to content

Commit 4b56f38

Browse files
Merge pull request #1186 from NativeScript/vladimirov/fix-tsc-no-modules
Install ALL dependencies and devDependencies before prepare
2 parents d575480 + 8c726cf commit 4b56f38

File tree

4 files changed

+10
-29
lines changed

4 files changed

+10
-29
lines changed

lib/definitions/plugins.d.ts

-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ interface IPluginsService {
55
getAllInstalledPlugins(): IFuture<IPluginData[]>;
66
ensureAllDependenciesAreInstalled(): IFuture<void>;
77
afterPrepareAllPlugins(): IFuture<void>;
8-
/**
9-
* Installs all devDependencies of the project.
10-
* In case all of them are already installed, no operation will be executed.
11-
* In case any of them is missing, all of them will be installed.
12-
* @return {IFuture<void>}
13-
*/
14-
installDevDependencies(): IFuture<void>;
158
}
169

1710
interface IPluginData extends INodeModuleData {

lib/services/platform-service.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,13 @@ export class PlatformService implements IPlatformService {
158158
return (() => {
159159
this.validatePlatform(platform);
160160

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

164169
this.preparePlatformCore(platform).wait();
165170
}).future<void>()();
@@ -223,7 +228,6 @@ export class PlatformService implements IPlatformService {
223228
// Process node_modules folder
224229
let appDir = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
225230
try {
226-
this.$pluginsService.ensureAllDependenciesAreInstalled().wait();
227231
let tnsModulesDestinationPath = path.join(appDir, PlatformService.TNS_MODULES_FOLDER_NAME);
228232
this.$broccoliBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime).wait();
229233
} catch(error) {

lib/services/plugins-service.ts

+2-17
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ export class PluginsService implements IPluginsService {
160160
return (() => {
161161
let installedDependencies = this.$fs.exists(this.nodeModulesPath).wait() ? this.$fs.readDirectory(this.nodeModulesPath).wait() : [];
162162
let packageJsonContent = this.$fs.readJson(this.getPackageJsonFilePath()).wait();
163-
if(this.$options.force || (packageJsonContent.dependencies && _.difference(_.keys(packageJsonContent.dependencies), installedDependencies).length)) {
163+
let allDependencies = _.keys(packageJsonContent.dependencies).concat(_.keys(packageJsonContent.devDependencies));
164+
if(this.$options.force || _.difference(allDependencies, installedDependencies).length) {
164165
let command = "npm install ";
165166
if(this.$options.ignoreScripts) {
166167
command += "--ignore-scripts";
@@ -185,22 +186,6 @@ export class PluginsService implements IPluginsService {
185186
return this.executeForAllInstalledPlatforms(action);
186187
}
187188

188-
public installDevDependencies(): IFuture<void> {
189-
return (() => {
190-
let installedDependencies = this.$fs.exists(this.nodeModulesPath).wait() ? this.$fs.readDirectory(this.nodeModulesPath).wait() : [];
191-
let packageJsonContent = this.$fs.readJson(this.getPackageJsonFilePath()).wait();
192-
let devDependencies = _.keys(packageJsonContent.devDependencies);
193-
if(devDependencies.length && (this.$options.force || _.difference(devDependencies, installedDependencies).length)) {
194-
let command = `npm install ${devDependencies.join(" ")}`;
195-
if(this.$options.ignoreScripts) {
196-
command += "--ignore-scripts";
197-
}
198-
this.$logger.trace(`Command for installing devDependencies is: '${command}'.`);
199-
this.$childProcess.exec(command, { cwd: this.$projectData.projectDir }).wait();
200-
}
201-
}).future<void>()();
202-
}
203-
204189
private get nodeModulesPath(): string {
205190
return path.join(this.$projectData.projectDir, "node_modules");
206191
}

test/platform-service.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ function createTestInjector() {
4949
},
5050
ensureAllDependenciesAreInstalled: () => {
5151
return Future.fromResult();
52-
},
53-
installDevDependencies: () => Future.fromResult()
52+
}
5453
});
5554
testInjector.register("projectFilesManager", ProjectFilesManagerLib.ProjectFilesManager);
5655
testInjector.register("hooksService", stubs.HooksServiceStub);

0 commit comments

Comments
 (0)