Skip to content

Commit

Permalink
fix(cli-core): fix yarn berry package manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Dec 9, 2024
1 parent 21d7071 commit 16bb927
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/cli-core/src/packageManagers/supports/YarnBerryManager.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import {Inject, Injectable} from "@tsed/di";
import {inject, Injectable} from "@tsed/di";
import {join} from "path";
import {Observable} from "rxjs";

import {CliYaml} from "../../services/CliYaml.js";
import {BaseManager, type ManagerCmdOpts, type ManagerCmdSyncOpts} from "./BaseManager.js";
import {CliFs} from "../../services/index.js";
import {BaseManager, type ManagerCmdOpts} from "./BaseManager.js";

@Injectable({
type: "package:manager"
})
export class YarnBerryManager extends BaseManager {
readonly name = "yarn_berry";
readonly cmd = "yarn";

@Inject()
protected cliYaml: CliYaml;
protected verboseOpt = "";
protected cliYaml = inject(CliYaml);
protected fs = inject(CliFs);

async init(options: ManagerCmdOpts) {
const lockFile = join(String(options.cwd!), "yarn.lock");

if (!this.fs.exists(lockFile)) {
this.fs.writeFileSync(lockFile, "");
}

// init yarn v1
this.install(options);
try {
await this.install(options).toPromise();
} catch (er) {}

// then switch write file
await this.cliYaml.write(join(String(options.cwd!), ".yarnrc.yml"), {
Expand All @@ -29,6 +38,7 @@ export class YarnBerryManager extends BaseManager {
}

add(deps: string[], options: ManagerCmdOpts) {
console.log(deps);
return this.run("add", [...deps], options);
}

Expand All @@ -37,6 +47,6 @@ export class YarnBerryManager extends BaseManager {
}

install(options: ManagerCmdOpts): Observable<any> {
return this.run("install", [options.verbose && "--verbose"], options);
return this.run("install", [], options);
}
}

0 comments on commit 16bb927

Please sign in to comment.