Skip to content

fix: issues when yarn is set as package manager #4233

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 2 commits into from
Dec 14, 2018
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
16 changes: 9 additions & 7 deletions lib/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class UpdateCommand extends ValidatePlatformCommandBase implements IComma
private $projectDataService: IProjectDataService,
private $fs: IFileSystem,
private $logger: ILogger) {
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
}

static readonly folders: string[] = [
Expand Down Expand Up @@ -83,8 +83,10 @@ export class UpdateCommand extends ValidatePlatformCommandBase implements IComma
}

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

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

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

await this.$pluginsService.ensureAllDependenciesAreInstalled(this.$projectData);
}

private getPlatforms(): {installed: string[], packagePlatforms: string[]} {
private getPlatforms(): { installed: string[], packagePlatforms: string[] } {
const installedPlatforms = this.$platformService.getInstalledPlatforms(this.$projectData);
const availablePlatforms = this.$platformService.getAvailablePlatforms(this.$projectData);
const packagePlatforms: string[] = [];
Expand Down
1 change: 1 addition & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const NATIVESCRIPT_KEY_NAME = "nativescript";
export const NODE_MODULES_FOLDER_NAME = "node_modules";
export const TNS_MODULES_FOLDER_NAME = "tns_modules";
export const TNS_CORE_MODULES_NAME = "tns-core-modules";
export const TNS_CORE_MODULES_WIDGETS_NAME = "tns-core-modules-widgets";
export const TNS_ANDROID_RUNTIME_NAME = "tns-android";
export const TNS_IOS_RUNTIME_NAME = "tns-ios";
export const PACKAGE_JSON_FILE_NAME = "package.json";
Expand Down
2 changes: 1 addition & 1 deletion lib/yarn-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class YarnPackageManager extends BasePackageManager {
@exported("yarn")
public async getCachePath(): Promise<string> {
const result = await this.$childProcess.exec(`yarn cache dir`);
return result;
return result.toString().trim();
}
}

Expand Down
14 changes: 12 additions & 2 deletions test/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ function createTestInjector(
testInjector.register("staticConfig", StaticConfig);
testInjector.register("androidProjectService", AndroidProjectService);
testInjector.register("androidToolsInfo", stubs.AndroidToolsInfoStub);
testInjector.register("projectData", { projectDir, initializeProjectData: () => { /* empty */ } });
testInjector.register("projectData", {
projectDir,
initializeProjectData: () => { /* empty */ },
dependencies: {}
});
testInjector.register("projectDataService", {
getNSValue: () => {
return "1.0.0";
Expand Down Expand Up @@ -134,7 +138,7 @@ describe("update command method tests", () => {
sandbox.restore();
});

it("if backup fails, pltforms not deleted and added, temp removed", async () => {
it("if backup fails, platforms not deleted and added, temp removed", async () => {
const installedPlatforms: string[] = ["android"];
const testInjector = createTestInjector(installedPlatforms);
const fs = testInjector.resolve("fs");
Expand Down Expand Up @@ -229,6 +233,12 @@ describe("update command method tests", () => {
sandbox.spy(pluginsService, "remove");
sandbox.spy(pluginsService, "add");
sandbox.spy(pluginsService, "ensureAllDependenciesAreInstalled");
const $projectData = testInjector.resolve("projectData");
$projectData.dependencies = {
"tns-core-modules": "1.0.0",
"tns-core-modules-widgets": "1.0.0"
};

const updateCommand = testInjector.resolve<UpdateCommand>(UpdateCommand);
return updateCommand.execute([]).then(() => {
assert(pluginsService.add.calledWith("tns-core-modules"));
Expand Down