@cmflow/cli 2.0.7 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmflow/cli",
3
- "version": "2.0.7",
3
+ "version": "2.1.0",
4
4
  "description": "An awesome Git Flow",
5
5
  "author": "camfou",
6
6
  "license": "MIT",
@@ -84,9 +84,10 @@ Au menu de cette livraison :
84
84
  ${context.releases
85
85
  .reverse()
86
86
  .map((release) => {
87
- const issues = release.issues.map((issue) => {
88
- return ` - ${TYPES[issue.fields.issuetype.name] || issue.fields.issuetype.name}(${issue.key}): ${getSummary(issue)}`;
89
- });
87
+ const issues =
88
+ release.issues?.map((issue) => {
89
+ return ` - ${TYPES[issue.fields.issuetype.name] || issue.fields.issuetype.name}(${issue.key}): ${getSummary(issue)}`;
90
+ }) || [];
90
91
 
91
92
  return issues.length ? (context.releases.length > 1 ? "- v" + release.version + ":\n" : "") + issues.join(",\n") : false;
92
93
  })
@@ -11,7 +11,6 @@ export class Rebase extends Fetch {
11
11
  mapContext(commander, context) {
12
12
  return {
13
13
  ...context,
14
- useYarn: context.HAS_YARN,
15
14
  origin: context.ORIGIN,
16
15
  featureBranch: git.getBranchName(),
17
16
  fromBranch: context.PRODUCTION_BRANCH,
@@ -32,7 +32,6 @@ export class Start extends Fetch {
32
32
 
33
33
  return {
34
34
  ...context,
35
- useYarn: context.HAS_YARN,
36
35
  origin: context.ORIGIN,
37
36
  jiraId: options.jiraId,
38
37
  branchName: options.branchName,
@@ -1,18 +1,16 @@
1
- import { git, npm, yarn } from "../../common/index.js";
2
-
3
- export const runTest = ({ E2E_CMD, useYarn, skipTest, skipUnit, skipE2E }) => {
4
- const manager = useYarn ? yarn : npm;
1
+ import { getPackageManager, git } from "../../common/index.js";
5
2
 
3
+ export const runTest = ({ E2E_CMD, PACKAGE_MANAGER, skipTest, skipUnit, skipE2E }) => {
6
4
  return [
7
5
  {
8
6
  title: "Unit test",
9
7
  skip: () => skipTest || skipUnit,
10
- task: () => manager.run("test")
8
+ task: () => getPackageManager(PACKAGE_MANAGER).run("test")
11
9
  },
12
10
  {
13
11
  title: "E2E test",
14
12
  skip: () => skipTest || skipE2E,
15
- task: () => manager.run(E2E_CMD || "test_e2e")
13
+ task: () => getPackageManager(PACKAGE_MANAGER).run(E2E_CMD || "test_e2e")
16
14
  },
17
15
  {
18
16
  title: "Reset changes",
@@ -1,11 +1,10 @@
1
1
  import Listr from "listr";
2
2
  import { catchError } from "rxjs";
3
3
 
4
- import { npm, yarn } from "../../common/index.js";
4
+ import { getPackageManager } from "../../common/index.js";
5
5
  import { refreshMetadata, shouldReinstall } from "../utils/check-install.js";
6
6
 
7
- export const updateDependencies = ({ useYarn }) => {
8
- const manager = useYarn ? yarn : npm;
7
+ export const updateDependencies = ({ PACKAGE_MANAGER }) => {
9
8
  const reinstall = shouldReinstall();
10
9
 
11
10
  return {
@@ -15,14 +14,14 @@ export const updateDependencies = ({ useYarn }) => {
15
14
  new Listr(
16
15
  [
17
16
  {
18
- title: `Restore dependencies using ${useYarn ? "Yarn" : "Npm"}`,
17
+ title: `Restore dependencies using ${PACKAGE_MANAGER.toUpperCase()}`,
19
18
  task: () =>
20
- manager
19
+ getPackageManager(PACKAGE_MANAGER)
21
20
  .restore()
22
21
  .toObservable()
23
22
  .pipe(
24
23
  catchError((error) => {
25
- if (useYarn) {
24
+ if (PACKAGE_MANAGER === "yarn") {
26
25
  if (error.stderr.startsWith("error Your lockfile needs to be updated")) {
27
26
  throw new Error("yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again.");
28
27
  }
@@ -0,0 +1,34 @@
1
+ import { Cli } from "./cli.js";
2
+
3
+ class PnpmCli extends Cli {
4
+ constructor() {
5
+ super("pnpm");
6
+ }
7
+
8
+ newVersion(version) {
9
+ // pnpm follows npm's version CLI semantics
10
+ return this.version("--no-git-tag-version", version);
11
+ }
12
+
13
+ version(...args) {
14
+ return this.sync("version", ...args);
15
+ }
16
+
17
+ run(...args) {
18
+ return super.run("run", ...args);
19
+ }
20
+
21
+ install(...args) {
22
+ return super.run("install", ...args);
23
+ }
24
+
25
+ /**
26
+ * Reinstall dependencies without pnpm-lock.yaml mutation
27
+ * @returns {Promise<unknown>}
28
+ */
29
+ restore() {
30
+ return super.run("install", "--frozen-lockfile");
31
+ }
32
+ }
33
+
34
+ export const pnpm = new PnpmCli();
@@ -0,0 +1,51 @@
1
+ vi.mock("execa", () => {
2
+ const execaMock = vi.fn();
3
+ execaMock.sync = vi.fn();
4
+ return { default: execaMock };
5
+ });
6
+
7
+ const { default: execa } = await import("execa");
8
+ const { pnpm } = await import("./pnpm.js");
9
+ const { Cli } = await import("./cli.js");
10
+
11
+ execa.sync.mockImplementation((...args) => {
12
+ return {
13
+ stdout: `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
14
+ };
15
+ });
16
+ execa.mockReturnValue({});
17
+
18
+ describe("PnpmCli", () => {
19
+ beforeEach(() => {
20
+ vi.spyOn(Cli, "getRaw").mockImplementation((...args) => {
21
+ return `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
22
+ });
23
+ });
24
+ describe("newVersion", () => {
25
+ it("should run newVersion cmd", () => {
26
+ const result = pnpm.newVersion("1.0.0");
27
+
28
+ expect(result.stdout).toEqual("CMD: pnpm version --no-git-tag-version 1.0.0");
29
+ });
30
+ });
31
+ describe("run", () => {
32
+ it('should run "run" cmd', async () => {
33
+ await pnpm.run("run-arg");
34
+
35
+ expect(execa).toHaveBeenCalledWith("pnpm", ["run", "run-arg"], {
36
+ cwd: process.cwd(),
37
+ stdio: "inherit"
38
+ });
39
+ });
40
+ });
41
+ describe("install", () => {
42
+ it('should run "install" cmd', async () => {
43
+ await pnpm.install("install-arg");
44
+
45
+ expect(execa).toHaveBeenCalledWith("pnpm", ["install", "install-arg"], {
46
+ cwd: process.cwd(),
47
+ stdio: "inherit"
48
+ });
49
+ });
50
+ });
51
+ });
@@ -94,17 +94,20 @@ export function getConfig() {
94
94
  } = process.env;
95
95
 
96
96
  const HAS_YARN = hasYarn();
97
+ const HAS_PNPM = fs.existsSync(join(process.cwd(), "pnpm-lock.yaml"));
97
98
  const IS_YARN_BERRY = HAS_YARN ? fs.existsSync(join(process.cwd(), ".yamlrc.yml")) : false;
98
99
  let BUMP_METHOD = get(pkg, "flow.bumpMethod", "default");
99
100
 
100
- if (IS_YARN_BERRY && ["native", "default"].includes(BUMP_METHOD)) {
101
+ if ((IS_YARN_BERRY || HAS_PNPM) && ["native", "default"].includes(BUMP_METHOD)) {
101
102
  BUMP_METHOD = "cmflow";
102
103
  }
103
104
 
104
105
  return {
105
106
  pkg,
107
+ PACKAGE_MANAGER: HAS_PNPM ? "pnpm" : HAS_YARN ? "yarn" : "npm",
106
108
  PROJECT_NAME: PROJECT_NAME || projectName,
107
- HAS_YARN: hasYarn(),
109
+ HAS_YARN,
110
+ HAS_PNPM,
108
111
  IS_YARN_BERRY,
109
112
  HAS_LERNA: (pkg.dependencies && pkg.dependencies.lerna) || (pkg.devDependencies && pkg.devDependencies.lerna),
110
113
  CI_SKIP: "[ci skip]",
@@ -0,0 +1,7 @@
1
+ import { npm } from "./cli/npm.js";
2
+ import { pnpm } from "./cli/pnpm.js";
3
+ import { yarn } from "./cli/yarn.js";
4
+
5
+ export function getPackageManager(pkgManager) {
6
+ return pkgManager === "yarn" ? yarn : pkgManager === "pnpm" ? pnpm : npm;
7
+ }
@@ -3,8 +3,10 @@ export * from "./cli/docker.js";
3
3
  export * from "./cli/git.js";
4
4
  export * from "./cli/lerna.js";
5
5
  export * from "./cli/npm.js";
6
+ export * from "./cli/pnpm.js";
6
7
  export * from "./cli/yarn.js";
7
8
  export * from "./configure-git-workspace.js";
8
9
  export * from "./get-config.js";
9
10
  export * from "./get-package-json.js";
11
+ export * from "./get-package-manager.js";
10
12
  export * from "./run-command.js";
@@ -1,20 +1,19 @@
1
- import { getConfig, lerna, npm, yarn } from "../../../common/index.js";
1
+ import { getConfig, getPackageManager, lerna } from "../../../common/index.js";
2
2
  import { bumpPackagesVersion } from "../../utils/bump-packages-version.js";
3
3
 
4
- export async function prepare(pluginConfig, context) {
4
+ export async function prepare(_, context) {
5
5
  context.config = getConfig();
6
6
  const {
7
- config: { HAS_YARN, HAS_LERNA, BUMP_METHOD, WORKSPACES },
7
+ config: { PACKAGE_MANAGER, HAS_LERNA, BUMP_METHOD, WORKSPACES },
8
8
  logger
9
9
  } = context;
10
- const pkgManager = HAS_YARN ? yarn : npm;
11
10
 
12
11
  logger.info(`Start bump version for all packages using method: ${BUMP_METHOD}`);
13
12
 
14
13
  switch (BUMP_METHOD) {
15
14
  case "native":
16
15
  logger.info("Using package manager");
17
- npm.newVersion(context.nextRelease.version);
16
+ getPackageManager(PACKAGE_MANAGER).newVersion(context.nextRelease.version);
18
17
  break;
19
18
  case "lerna":
20
19
  if (HAS_LERNA) {
@@ -23,11 +22,11 @@ export async function prepare(pluginConfig, context) {
23
22
  break;
24
23
  case "cmflow":
25
24
  await bumpPackagesVersion(context.nextRelease.version, WORKSPACES);
26
- await pkgManager.install();
25
+ await getPackageManager(PACKAGE_MANAGER).install();
27
26
  break;
28
27
  case "native:lerna":
29
28
  default:
30
- npm.newVersion(context.nextRelease.version);
29
+ getPackageManager("npm").newVersion(context.nextRelease.version);
31
30
 
32
31
  if (HAS_LERNA) {
33
32
  await lerna.newVersion(context.nextRelease.version);
@@ -1,4 +1,4 @@
1
- import { getConfig, npm, yarn } from "../../common/index.js";
1
+ import { getConfig, getPackageManager } from "../../common/index.js";
2
2
 
3
3
  /**
4
4
  * @param pluginConfig {{command: string}}
@@ -8,11 +8,11 @@ import { getConfig, npm, yarn } from "../../common/index.js";
8
8
  export default async function runCommand(pluginConfig, context) {
9
9
  context.config = getConfig();
10
10
  const {
11
- config: { HAS_YARN },
11
+ config: { PACKAGE_MANAGER },
12
12
  logger
13
13
  } = context;
14
14
 
15
- const pkgManager = HAS_YARN ? yarn : npm;
15
+ const pkgManager = getPackageManager(PACKAGE_MANAGER);
16
16
 
17
17
  logger.info(`Start ${pluginConfig.command} task`);
18
18