Skip to content

Commit 1c03901

Browse files
fix: execute npm install before all hooks
CLI must install all project dependencies before running any hook as the hooks are commonly created during the installation of packages. In the current codebase we install the depenencies only during `run` operation, however we actually need this to be executed before each project preparation. To fix the behavior move the installation of dependencies in the prepareController and remove it from webpack-compiler-service. Also remove hook which is no longer supported - prepareJS.
1 parent 0001e76 commit 1c03901

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

lib/controllers/prepare-controller.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,39 @@ export class PrepareController extends EventEmitter {
2222
private $logger: ILogger,
2323
private $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder,
2424
private $platformsDataService: IPlatformsDataService,
25+
private $pluginsService: IPluginsService,
2526
private $prepareNativePlatformService: IPrepareNativePlatformService,
2627
private $projectChangesService: IProjectChangesService,
2728
private $projectDataService: IProjectDataService,
2829
private $webpackCompilerService: IWebpackCompilerService,
2930
private $watchIgnoreListService: IWatchIgnoreListService
3031
) { super(); }
3132

32-
@performanceLog()
33-
@hook("prepare")
3433
public async prepare(prepareData: IPrepareData): Promise<IPrepareResultData> {
3534
const projectData = this.$projectDataService.getProjectData(prepareData.projectDir);
35+
36+
await this.$pluginsService.ensureAllDependenciesAreInstalled(projectData);
37+
38+
return this.prepareCore(prepareData, projectData);
39+
}
40+
41+
public async stopWatchers(projectDir: string, platform: string): Promise<void> {
42+
const platformLowerCase = platform.toLowerCase();
43+
44+
if (this.watchersData && this.watchersData[projectDir] && this.watchersData[projectDir][platformLowerCase] && this.watchersData[projectDir][platformLowerCase].nativeFilesWatcher) {
45+
this.watchersData[projectDir][platformLowerCase].nativeFilesWatcher.close();
46+
this.watchersData[projectDir][platformLowerCase].nativeFilesWatcher = null;
47+
}
48+
49+
if (this.watchersData && this.watchersData[projectDir] && this.watchersData[projectDir][platformLowerCase] && this.watchersData[projectDir][platformLowerCase].hasWebpackCompilerProcess) {
50+
await this.$webpackCompilerService.stopWebpackCompiler(platform);
51+
this.watchersData[projectDir][platformLowerCase].hasWebpackCompilerProcess = false;
52+
}
53+
}
54+
55+
@performanceLog()
56+
@hook("prepare")
57+
private async prepareCore(prepareData: IPrepareData, projectData: IProjectData): Promise<IPrepareResultData> {
3658
this.$bundleValidatorHelper.validate(projectData, "1.0.0");
3759

3860
await this.$platformController.addPlatformIfNeeded(prepareData);
@@ -57,20 +79,6 @@ export class PrepareController extends EventEmitter {
5779
return result;
5880
}
5981

60-
public async stopWatchers(projectDir: string, platform: string): Promise<void> {
61-
const platformLowerCase = platform.toLowerCase();
62-
63-
if (this.watchersData && this.watchersData[projectDir] && this.watchersData[projectDir][platformLowerCase] && this.watchersData[projectDir][platformLowerCase].nativeFilesWatcher) {
64-
this.watchersData[projectDir][platformLowerCase].nativeFilesWatcher.close();
65-
this.watchersData[projectDir][platformLowerCase].nativeFilesWatcher = null;
66-
}
67-
68-
if (this.watchersData && this.watchersData[projectDir] && this.watchersData[projectDir][platformLowerCase] && this.watchersData[projectDir][platformLowerCase].hasWebpackCompilerProcess) {
69-
await this.$webpackCompilerService.stopWebpackCompiler(platform);
70-
this.watchersData[projectDir][platformLowerCase].hasWebpackCompilerProcess = false;
71-
}
72-
}
73-
7482
@hook("watch")
7583
private async startWatchersWithPrepare(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<IPrepareResultData> {
7684
if (!this.watchersData[projectData.projectDir]) {

lib/services/webpack/webpack-compiler-service.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as path from "path";
22
import * as child_process from "child_process";
33
import { EventEmitter } from "events";
44
import { performanceLog } from "../../common/decorators";
5-
import { hook } from "../../common/helpers";
65
import { WEBPACK_COMPILATION_COMPLETE } from "../../constants";
76

87
export class WebpackCompilerService extends EventEmitter implements IWebpackCompilerService {
@@ -13,7 +12,6 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
1312
public $hooksService: IHooksService,
1413
public $hostInfo: IHostInfo,
1514
private $logger: ILogger,
16-
private $pluginsService: IPluginsService,
1715
private $mobileHelper: Mobile.IMobileHelper,
1816
private $cleanupService: ICleanupService
1917
) { super(); }
@@ -129,13 +127,10 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
129127
}
130128

131129
@performanceLog()
132-
@hook('prepareJSApp')
133130
private async startWebpackProcess(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<child_process.ChildProcess> {
134131
const envData = this.buildEnvData(platformData.platformNameLowerCase, projectData, prepareData);
135132
const envParams = this.buildEnvCommandLineParams(envData, platformData, prepareData);
136133

137-
await this.$pluginsService.ensureAllDependenciesAreInstalled(projectData);
138-
139134
const args = [
140135
path.join(projectData.projectDir, "node_modules", "webpack", "bin", "webpack.js"),
141136
"--preserve-symlinks",

0 commit comments

Comments
 (0)