Skip to content

Commit ccf3bbc

Browse files
fix: tns update does not work when yarn is set
When yarn is set as package manager, `tns update` command fails. The problem is that during command's execution, we try to remove `tns-core-modules-widgets` from the project. When `tns-core-modules-widgets` pacakage is not a dependency of the project (this is the default case as this package is dependency of `tns-core-modules` not a direct dependency of the project), calling `yarn remove` fails. In the same case `npm` does not fail. To resolve the issue, check if `tns-core-modules-widgets` are dependency of the project and uninstall this package only in such case.
1 parent bad66ad commit ccf3bbc

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

lib/commands/update.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export class UpdateCommand extends ValidatePlatformCommandBase implements IComma
1313
private $projectDataService: IProjectDataService,
1414
private $fs: IFileSystem,
1515
private $logger: ILogger) {
16-
super($options, $platformsData, $platformService, $projectData);
17-
this.$projectData.initializeProjectData();
16+
super($options, $platformsData, $platformService, $projectData);
17+
this.$projectData.initializeProjectData();
1818
}
1919

2020
static readonly folders: string[] = [
@@ -83,8 +83,10 @@ export class UpdateCommand extends ValidatePlatformCommandBase implements IComma
8383
}
8484

8585
await this.$platformService.removePlatforms(platforms.installed, this.$projectData);
86-
await this.$pluginsService.remove("tns-core-modules", this.$projectData);
87-
await this.$pluginsService.remove("tns-core-modules-widgets", this.$projectData);
86+
await this.$pluginsService.remove(constants.TNS_CORE_MODULES_NAME, this.$projectData);
87+
if (!!this.$projectData.dependencies[constants.TNS_CORE_MODULES_WIDGETS_NAME]) {
88+
await this.$pluginsService.remove(constants.TNS_CORE_MODULES_WIDGETS_NAME, this.$projectData);
89+
}
8890

8991
for (const folder of UpdateCommand.folders) {
9092
this.$fs.deleteDirectory(path.join(this.$projectData.projectDir, folder));
@@ -95,16 +97,16 @@ export class UpdateCommand extends ValidatePlatformCommandBase implements IComma
9597
await this.$platformService.addPlatforms([platform + "@" + args[0]], this.$options.platformTemplate, this.$projectData, this.$options, this.$options.frameworkPath);
9698
}
9799

98-
await this.$pluginsService.add("tns-core-modules@" + args[0], this.$projectData);
100+
await this.$pluginsService.add(`${constants.TNS_CORE_MODULES_NAME}@${args[0]}`, this.$projectData);
99101
} else {
100102
await this.$platformService.addPlatforms(platforms.packagePlatforms, this.$options.platformTemplate, this.$projectData, this.$options, this.$options.frameworkPath);
101-
await this.$pluginsService.add("tns-core-modules", this.$projectData);
103+
await this.$pluginsService.add(constants.TNS_CORE_MODULES_NAME, this.$projectData);
102104
}
103105

104106
await this.$pluginsService.ensureAllDependenciesAreInstalled(this.$projectData);
105107
}
106108

107-
private getPlatforms(): {installed: string[], packagePlatforms: string[]} {
109+
private getPlatforms(): { installed: string[], packagePlatforms: string[] } {
108110
const installedPlatforms = this.$platformService.getInstalledPlatforms(this.$projectData);
109111
const availablePlatforms = this.$platformService.getAvailablePlatforms(this.$projectData);
110112
const packagePlatforms: string[] = [];

lib/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const NATIVESCRIPT_KEY_NAME = "nativescript";
77
export const NODE_MODULES_FOLDER_NAME = "node_modules";
88
export const TNS_MODULES_FOLDER_NAME = "tns_modules";
99
export const TNS_CORE_MODULES_NAME = "tns-core-modules";
10+
export const TNS_CORE_MODULES_WIDGETS_NAME = "tns-core-modules-widgets";
1011
export const TNS_ANDROID_RUNTIME_NAME = "tns-android";
1112
export const TNS_IOS_RUNTIME_NAME = "tns-ios";
1213
export const PACKAGE_JSON_FILE_NAME = "package.json";

test/update.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ function createTestInjector(
3737
testInjector.register("staticConfig", StaticConfig);
3838
testInjector.register("androidProjectService", AndroidProjectService);
3939
testInjector.register("androidToolsInfo", stubs.AndroidToolsInfoStub);
40-
testInjector.register("projectData", { projectDir, initializeProjectData: () => { /* empty */ } });
40+
testInjector.register("projectData", {
41+
projectDir,
42+
initializeProjectData: () => { /* empty */ },
43+
dependencies: {}
44+
});
4145
testInjector.register("projectDataService", {
4246
getNSValue: () => {
4347
return "1.0.0";
@@ -134,7 +138,7 @@ describe("update command method tests", () => {
134138
sandbox.restore();
135139
});
136140

137-
it("if backup fails, pltforms not deleted and added, temp removed", async () => {
141+
it("if backup fails, platforms not deleted and added, temp removed", async () => {
138142
const installedPlatforms: string[] = ["android"];
139143
const testInjector = createTestInjector(installedPlatforms);
140144
const fs = testInjector.resolve("fs");
@@ -229,6 +233,12 @@ describe("update command method tests", () => {
229233
sandbox.spy(pluginsService, "remove");
230234
sandbox.spy(pluginsService, "add");
231235
sandbox.spy(pluginsService, "ensureAllDependenciesAreInstalled");
236+
const $projectData = testInjector.resolve("projectData");
237+
$projectData.dependencies = {
238+
"tns-core-modules": "1.0.0",
239+
"tns-core-modules-widgets": "1.0.0"
240+
};
241+
232242
const updateCommand = testInjector.resolve<UpdateCommand>(UpdateCommand);
233243
return updateCommand.execute([]).then(() => {
234244
assert(pluginsService.add.calledWith("tns-core-modules"));

0 commit comments

Comments
 (0)