Skip to content

Commit 10b7a47

Browse files
committed
feat(yarn2): add default branch (master)
1 parent f581c77 commit 10b7a47

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/actions/CreateYarn2ConfigsAction.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { nonZeroInstalls, zeroInstalls } from "../configs";
1+
import { getChangesetBaseRefs, nonZeroInstalls, zeroInstalls } from "../configs";
22
import { removeFile, runCommand, withCurrentDir, writeContentToFile } from "../process";
33
import { InquirerConfigs } from "../types";
44
import { Action } from "./Action";
@@ -13,14 +13,18 @@ export class CreateYarn2ConfigsAction extends Action {
1313
await runCommand("yarn", ["set", "version", "berry"]);
1414

1515
// Set nodeLinker mode to "node-modules"
16-
await writeContentToFile(withCurrentDir("./.yarnrc.yml"), "nodeLinker: node-modules");
16+
await runCommand("yarn", ["config", "set", "nodeLinker", "node-modules"]);
1717

1818
// Add plugins
1919
this.userConfigs.typescript && (await runCommand("yarn", ["plugin", "import", "typescript"]));
2020
await runCommand("yarn", ["plugin", "import", "interactive-tools"]);
2121
await runCommand("yarn", ["plugin", "import", "stage"]);
2222
await runCommand("yarn", ["plugin", "import", "version"]);
2323

24+
// Set changesetBaseRefs to default branch (require version plugin)
25+
const changesetBaseRefs = getChangesetBaseRefs(this.userConfigs.defaultBranch);
26+
await runCommand("yarn", ["config", "set", "changesetBaseRefs", changesetBaseRefs]);
27+
2428
// Remove old .yarnrc
2529
await removeFile(withCurrentDir("./.yarnrc"));
2630

src/configs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ export const flowConfigs = {
6262
},
6363
strict: {},
6464
};
65+
66+
export const getChangesetBaseRefs = (branch = "master") =>
67+
[`${branch}`, `origin/${branch}`, `upstream/${branch}`].join(",");

src/inquirer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export async function collectAnswers(): Promise<InquirerConfigs> {
3636
when: (answers) => answers.configurations.includes("yarn2"),
3737
default: false,
3838
},
39+
{
40+
type: "input",
41+
name: "defaultBranch",
42+
message: "What is default branch (git) of this project?",
43+
when: (answers) => answers.configurations.includes("yarn2"),
44+
default: "master",
45+
},
3946
{
4047
type: "list",
4148
name: "framework",

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type Yarn2Configs = { zeroInstalls?: boolean };
1+
export type Yarn2Configs = { zeroInstalls?: boolean; defaultBranch?: string };
22

33
export type Framework = "react" | "none";
44

0 commit comments

Comments
 (0)