@pob/version 1.0.1

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.
Files changed (69) hide show
  1. package/.editorconfig +13 -0
  2. package/.yo-rc.json +13 -0
  3. package/CHANGELOG.md +35 -0
  4. package/LICENSE +21 -0
  5. package/README.md +163 -0
  6. package/dist/index-node.mjs +1419 -0
  7. package/dist/index-node.mjs.map +1 -0
  8. package/package.json +81 -0
  9. package/rollup.config.mjs +12 -0
  10. package/src/__fixtures__/bun-basic/package.json +4 -0
  11. package/src/__fixtures__/bun-no-version/package.json +3 -0
  12. package/src/__fixtures__/yarn-basic/package.json +4 -0
  13. package/src/__fixtures__/yarn-basic/yarn.lock +12 -0
  14. package/src/__fixtures__/yarn-monorepo/package.json +7 -0
  15. package/src/__fixtures__/yarn-monorepo/packages/package-1/package.json +4 -0
  16. package/src/__fixtures__/yarn-monorepo/packages/package-2/package.json +7 -0
  17. package/src/__fixtures__/yarn-monorepo/packages/package-3/package.json +7 -0
  18. package/src/__fixtures__/yarn-monorepo/packages/package-4/package.json +7 -0
  19. package/src/__fixtures__/yarn-monorepo/packages/package-5/package.json +8 -0
  20. package/src/__fixtures__/yarn-monorepo/yarn.lock +0 -0
  21. package/src/__fixtures__/yarn-monorepo-duplicate-names/package.json +7 -0
  22. package/src/__fixtures__/yarn-monorepo-duplicate-names/packages/pkg-a/package.json +4 -0
  23. package/src/__fixtures__/yarn-monorepo-duplicate-names/packages/pkg-b/package.json +4 -0
  24. package/src/__fixtures__/yarn-monorepo-invalid-package-json/package.json +7 -0
  25. package/src/__fixtures__/yarn-monorepo-invalid-package-json/packages/pkg-with-invalid-json/package.json +5 -0
  26. package/src/__fixtures__/yarn-monorepo-nested/package.json +9 -0
  27. package/src/__fixtures__/yarn-monorepo-nested/packages/deep-nested/package.json +4 -0
  28. package/src/__fixtures__/yarn-monorepo-nested/packages/nested-1/packages/package-nested.json +4 -0
  29. package/src/__fixtures__/yarn-monorepo-nested/packages/nested-1/packages/package.json +4 -0
  30. package/src/__fixtures__/yarn-monorepo-nested/packages/package-1/package.json +4 -0
  31. package/src/__fixtures__/yarn-monorepo-no-name/package.json +7 -0
  32. package/src/__fixtures__/yarn-monorepo-no-name/packages/no-name-package/package.json +3 -0
  33. package/src/__fixtures__/yarn-monorepo-object-form/package.json +9 -0
  34. package/src/__fixtures__/yarn-monorepo-object-form/packages/package-1/package.json +4 -0
  35. package/src/__fixtures__/yarn-monorepo-object-form/packages/package-2/package.json +4 -0
  36. package/src/__fixtures__/yarn-monorepo-object-form/packages/package-3/package.json +4 -0
  37. package/src/__fixtures__/yarn-monorepo-object-form/packages/package-4/package.json +4 -0
  38. package/src/__fixtures__/yarn-monorepo-object-form/packages/package-5/package.json +4 -0
  39. package/src/__fixtures__/yarn-no-version/package.json +3 -0
  40. package/src/__fixtures__/yarn-no-version/yarn.lock +0 -0
  41. package/src/__fixtures__/yarn-with-lifecycle/.yarn/install-state.gz +0 -0
  42. package/src/__fixtures__/yarn-with-lifecycle/package.json +7 -0
  43. package/src/__fixtures__/yarn-with-lifecycle/yarn.lock +11 -0
  44. package/src/commands/version.test.ts +114 -0
  45. package/src/commands/version.ts +936 -0
  46. package/src/index.ts +13 -0
  47. package/src/missing-types.d.ts +10 -0
  48. package/src/pm/BunPackageManager.ts +12 -0
  49. package/src/pm/PackageManager.ts +66 -0
  50. package/src/pm/YarnPackageManager.ts +34 -0
  51. package/src/utils/UsageError.ts +6 -0
  52. package/src/utils/bumpTypeUtils.ts +113 -0
  53. package/src/utils/conventionalChangelogUtils.test.ts +762 -0
  54. package/src/utils/conventionalChangelogUtils.ts +104 -0
  55. package/src/utils/conventionalCommitConfigUtils.ts +20 -0
  56. package/src/utils/execCommand.ts +214 -0
  57. package/src/utils/generatorUtils.ts +11 -0
  58. package/src/utils/gitUtils.ts +193 -0
  59. package/src/utils/githubUtils.ts +114 -0
  60. package/src/utils/mapUtils.ts +7 -0
  61. package/src/utils/mapWorkspaces.test.ts +89 -0
  62. package/src/utils/packageDependenciesUtils.test.ts +25 -0
  63. package/src/utils/packageDependenciesUtils.ts +80 -0
  64. package/src/utils/packageUtils.test.ts +32 -0
  65. package/src/utils/packageUtils.ts +127 -0
  66. package/src/utils/updateChangelog.ts +39 -0
  67. package/src/utils/workspaceUtils.ts +142 -0
  68. package/tsconfig.json +21 -0
  69. package/vitest.config.js +9 -0
@@ -0,0 +1,114 @@
1
+ import { URL, fileURLToPath } from "node:url";
2
+ import { describe, expect, it } from "vitest";
3
+ import { Level, LoggerCLI, StringHandler } from "nightingale";
4
+ import type { VersionCommandOptions } from "./version.ts";
5
+ import { Defaults, versionCommandAction } from "./version.ts";
6
+
7
+ interface ExecuteCommandResult {
8
+ exitCode: number;
9
+ stdout: string;
10
+ stderr: string;
11
+ }
12
+ const presetOption = {
13
+ // preset: fileURLToPath(
14
+ // new URL(
15
+ // "../../node_modules/conventional-changelog-conventionalcommits",
16
+ // import.meta.url,
17
+ // ),
18
+ // ),
19
+ };
20
+
21
+ class TesteableLoggerCLI extends LoggerCLI {
22
+ stringHandler = new StringHandler(Level.ALL);
23
+
24
+ protected override getHandlersAndProcessors(recordLevel: number) {
25
+ return {
26
+ handlers: [this.stringHandler],
27
+ processors: [],
28
+ };
29
+ }
30
+ }
31
+
32
+ const executeAction = async (
33
+ options: Partial<VersionCommandOptions>,
34
+ ): Promise<ExecuteCommandResult> => {
35
+ const logger = new TesteableLoggerCLI("yarn-version", {});
36
+ const nightingaleHandler = logger.stringHandler;
37
+ try {
38
+ await versionCommandAction(
39
+ { ...Defaults, ...options, cwdIsRoot: true },
40
+ { logger },
41
+ );
42
+ } catch (error) {
43
+ return {
44
+ exitCode: 1,
45
+ stdout: "",
46
+ stderr: (error as any).toString(),
47
+ };
48
+ }
49
+ return {
50
+ exitCode: 0,
51
+ stdout: nightingaleHandler.string,
52
+ stderr: "",
53
+ };
54
+ };
55
+
56
+ describe("version", () => {
57
+ it.each(["yarn", "bun"] as const)(
58
+ "should fail for %s if package has no version",
59
+ async (packageManager) => {
60
+ const { exitCode, stdout, stderr } = await executeAction({
61
+ ...presetOption,
62
+ dryRun: true,
63
+ packageManager,
64
+ cwd: fileURLToPath(
65
+ new URL(
66
+ `../__fixtures__/${packageManager}-no-version`,
67
+ import.meta.url,
68
+ ),
69
+ ),
70
+ });
71
+ expect(exitCode).toBe(1);
72
+ expect(stderr).toContain(
73
+ 'UsageError: package.json has no version in its manifest. For the first release, set to "1.0.0-pre" or "0.1.0-pre".',
74
+ ); // replace with expected output
75
+ expect(stdout).toBeFalsy();
76
+ },
77
+ );
78
+
79
+ it.each(["yarn", "bun"] as const)(
80
+ "should fail for %s if --prerelease is passed",
81
+ async (packageManager) => {
82
+ const { exitCode, stdout, stderr } = await executeAction({
83
+ ...presetOption,
84
+ prerelease: "alpha",
85
+ dryRun: true,
86
+ packageManager,
87
+ cwd: fileURLToPath(
88
+ new URL(`../__fixtures__/${packageManager}-basic`, import.meta.url),
89
+ ),
90
+ });
91
+ expect(exitCode).toBe(1);
92
+ expect(stderr).toContain("prerelease is not supported yet."); // replace with expected output
93
+ expect(stdout).toBeFalsy();
94
+ },
95
+ );
96
+
97
+ it.each(["yarn", "bun"] as const)(
98
+ "should pass for %s with dry-run and force",
99
+ async (packageManager) => {
100
+ const { exitCode, stdout, stderr } = await executeAction({
101
+ ...presetOption,
102
+ force: "minor",
103
+ dryRun: true,
104
+ packageManager,
105
+ cwd: fileURLToPath(
106
+ new URL(`../__fixtures__/${packageManager}-basic`, import.meta.url),
107
+ ),
108
+ });
109
+ expect(stderr).toBeFalsy();
110
+ expect(exitCode).toBe(0);
111
+ expect(stdout).toContain("basic: 1.0.0 -> 1.1.0"); // replace with expected output
112
+ },
113
+ );
114
+ });