Skip to content

Commit 6ab0cfe

Browse files
Fix installation of tns-core-modules during project creation (#2790)
CLI tries to install `tns-core-modules` during project creation. In case the template does not have `tns-core-modules` in it, CLI will install latest version of `tns-core-modules` which may (and most probably is) be incompatible with the runtime and other dependencies of the project. In such cases ensure the CLI installs version of tns-core-modules that matches its own version, i.e. when CLI is 2.5.2, it should install latest 2.5.x core modules. Also ensure exact versions are installed and persisted by `npmInstallationManager`.
1 parent e133380 commit 6ab0cfe

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

lib/npm-installation-manager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class NpmInstallationManager implements INpmInstallationManager {
108108

109109
packageName = packageName + (version ? `@${version}` : "");
110110

111-
let npmOptions: any = { silent: true };
111+
let npmOptions: any = { silent: true, "save-exact": true };
112112

113113
if (dependencyType) {
114114
npmOptions[dependencyType] = true;

lib/services/project-service.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export class ProjectService implements IProjectService {
1414
private $projectHelper: IProjectHelper,
1515
private $projectNameService: IProjectNameService,
1616
private $projectTemplatesService: IProjectTemplatesService,
17-
private $staticConfig: IStaticConfig) { }
17+
private $staticConfig: IStaticConfig,
18+
private $npmInstallationManager: INpmInstallationManager) { }
1819

1920
@exported("projectService")
2021
public async createProject(projectOptions: IProjectSettings): Promise<void> {
@@ -50,10 +51,12 @@ export class ProjectService implements IProjectService {
5051

5152
await this.ensureAppResourcesExist(projectDir);
5253

53-
let packageName = constants.TNS_CORE_MODULES_NAME;
54-
await this.$npm.install(packageName, projectDir, { save: true, "save-exact": true });
55-
5654
let templatePackageJsonData = this.getDataFromJson(templatePath);
55+
56+
if (!(templatePackageJsonData && templatePackageJsonData.dependencies && templatePackageJsonData.dependencies[constants.TNS_CORE_MODULES_NAME])) {
57+
await this.$npmInstallationManager.install(constants.TNS_CORE_MODULES_NAME, projectDir, { dependencyType: "save" });
58+
}
59+
5760
this.mergeProjectAndTemplateProperties(projectDir, templatePackageJsonData); //merging dependencies from template (dev && prod)
5861
this.removeMergedDependencies(projectDir, templatePackageJsonData);
5962

test/project-service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ProjectIntegrationTest {
114114
this.testInjector.register("fs", FileSystem);
115115
this.testInjector.register("projectDataService", ProjectDataServiceLib.ProjectDataService);
116116
this.testInjector.register("staticConfig", StaticConfig);
117-
this.testInjector.register("analyticsService", { track: async () => undefined });
117+
this.testInjector.register("analyticsService", { track: async (): Promise<any> => undefined });
118118

119119
this.testInjector.register("npmInstallationManager", NpmInstallationManager);
120120
this.testInjector.register("npm", NpmLib.NodePackageManager);
@@ -130,6 +130,7 @@ class ProjectIntegrationTest {
130130
return dummyString;
131131
}
132132
});
133+
this.testInjector.register("npmInstallationManager", NpmInstallationManager);
133134
}
134135
}
135136

@@ -471,6 +472,7 @@ describe("Project Service Tests", () => {
471472
testInjector.register("projectTemplatesService", {});
472473
testInjector.register("staticConfig", {});
473474
testInjector.register("projectHelper", {});
475+
testInjector.register("npmInstallationManager", {});
474476

475477
return testInjector;
476478
};

0 commit comments

Comments
 (0)