@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.
- package/.editorconfig +13 -0
- package/.yo-rc.json +13 -0
- package/CHANGELOG.md +35 -0
- package/LICENSE +21 -0
- package/README.md +163 -0
- package/dist/index-node.mjs +1419 -0
- package/dist/index-node.mjs.map +1 -0
- package/package.json +81 -0
- package/rollup.config.mjs +12 -0
- package/src/__fixtures__/bun-basic/package.json +4 -0
- package/src/__fixtures__/bun-no-version/package.json +3 -0
- package/src/__fixtures__/yarn-basic/package.json +4 -0
- package/src/__fixtures__/yarn-basic/yarn.lock +12 -0
- package/src/__fixtures__/yarn-monorepo/package.json +7 -0
- package/src/__fixtures__/yarn-monorepo/packages/package-1/package.json +4 -0
- package/src/__fixtures__/yarn-monorepo/packages/package-2/package.json +7 -0
- package/src/__fixtures__/yarn-monorepo/packages/package-3/package.json +7 -0
- package/src/__fixtures__/yarn-monorepo/packages/package-4/package.json +7 -0
- package/src/__fixtures__/yarn-monorepo/packages/package-5/package.json +8 -0
- package/src/__fixtures__/yarn-monorepo/yarn.lock +0 -0
- package/src/__fixtures__/yarn-monorepo-duplicate-names/package.json +7 -0
- package/src/__fixtures__/yarn-monorepo-duplicate-names/packages/pkg-a/package.json +4 -0
- package/src/__fixtures__/yarn-monorepo-duplicate-names/packages/pkg-b/package.json +4 -0
- package/src/__fixtures__/yarn-monorepo-invalid-package-json/package.json +7 -0
- package/src/__fixtures__/yarn-monorepo-invalid-package-json/packages/pkg-with-invalid-json/package.json +5 -0
- package/src/__fixtures__/yarn-monorepo-nested/package.json +9 -0
- package/src/__fixtures__/yarn-monorepo-nested/packages/deep-nested/package.json +4 -0
- package/src/__fixtures__/yarn-monorepo-nested/packages/nested-1/packages/package-nested.json +4 -0
- package/src/__fixtures__/yarn-monorepo-nested/packages/nested-1/packages/package.json +4 -0
- package/src/__fixtures__/yarn-monorepo-nested/packages/package-1/package.json +4 -0
- package/src/__fixtures__/yarn-monorepo-no-name/package.json +7 -0
- package/src/__fixtures__/yarn-monorepo-no-name/packages/no-name-package/package.json +3 -0
- package/src/__fixtures__/yarn-monorepo-object-form/package.json +9 -0
- package/src/__fixtures__/yarn-monorepo-object-form/packages/package-1/package.json +4 -0
- package/src/__fixtures__/yarn-monorepo-object-form/packages/package-2/package.json +4 -0
- package/src/__fixtures__/yarn-monorepo-object-form/packages/package-3/package.json +4 -0
- package/src/__fixtures__/yarn-monorepo-object-form/packages/package-4/package.json +4 -0
- package/src/__fixtures__/yarn-monorepo-object-form/packages/package-5/package.json +4 -0
- package/src/__fixtures__/yarn-no-version/package.json +3 -0
- package/src/__fixtures__/yarn-no-version/yarn.lock +0 -0
- package/src/__fixtures__/yarn-with-lifecycle/.yarn/install-state.gz +0 -0
- package/src/__fixtures__/yarn-with-lifecycle/package.json +7 -0
- package/src/__fixtures__/yarn-with-lifecycle/yarn.lock +11 -0
- package/src/commands/version.test.ts +114 -0
- package/src/commands/version.ts +936 -0
- package/src/index.ts +13 -0
- package/src/missing-types.d.ts +10 -0
- package/src/pm/BunPackageManager.ts +12 -0
- package/src/pm/PackageManager.ts +66 -0
- package/src/pm/YarnPackageManager.ts +34 -0
- package/src/utils/UsageError.ts +6 -0
- package/src/utils/bumpTypeUtils.ts +113 -0
- package/src/utils/conventionalChangelogUtils.test.ts +762 -0
- package/src/utils/conventionalChangelogUtils.ts +104 -0
- package/src/utils/conventionalCommitConfigUtils.ts +20 -0
- package/src/utils/execCommand.ts +214 -0
- package/src/utils/generatorUtils.ts +11 -0
- package/src/utils/gitUtils.ts +193 -0
- package/src/utils/githubUtils.ts +114 -0
- package/src/utils/mapUtils.ts +7 -0
- package/src/utils/mapWorkspaces.test.ts +89 -0
- package/src/utils/packageDependenciesUtils.test.ts +25 -0
- package/src/utils/packageDependenciesUtils.ts +80 -0
- package/src/utils/packageUtils.test.ts +32 -0
- package/src/utils/packageUtils.ts +127 -0
- package/src/utils/updateChangelog.ts +39 -0
- package/src/utils/workspaceUtils.ts +142 -0
- package/tsconfig.json +21 -0
- package/vitest.config.js +9 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { program } from "commander";
|
|
3
|
+
|
|
4
|
+
import "./commands/version.ts";
|
|
5
|
+
|
|
6
|
+
// relative to dist directory
|
|
7
|
+
const pkg = JSON.parse(
|
|
8
|
+
// eslint-disable-next-line unicorn/prefer-json-parse-buffer
|
|
9
|
+
fs.readFileSync(new URL("../package.json", import.meta.url), "utf8"),
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
program.name(pkg.name).description(pkg.description).version(pkg.version);
|
|
13
|
+
program.parse();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// declare module "conventional-changelog-core" {
|
|
2
|
+
// export default function conventionalChangelogCore(
|
|
3
|
+
// options: any,
|
|
4
|
+
// context?: any,
|
|
5
|
+
// gitRawCommitsOpts?: any,
|
|
6
|
+
// parserOpts?: any,
|
|
7
|
+
// writerOpts?: any,
|
|
8
|
+
// gitRawExecOpts?: any,
|
|
9
|
+
// ): Readable;
|
|
10
|
+
// }
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { execCommand } from "../utils/execCommand.ts";
|
|
2
|
+
import type { PackageManager } from "./PackageManager.ts";
|
|
3
|
+
|
|
4
|
+
export const BunPackageManager: PackageManager = {
|
|
5
|
+
async runScript(workspace, scriptName) {
|
|
6
|
+
await execCommand(workspace, ["bun", "run", scriptName], "inherit");
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
async publish(workspace) {
|
|
10
|
+
await execCommand(workspace, ["bun", "publish"], "inherit");
|
|
11
|
+
},
|
|
12
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import type { Workspace } from "../utils/packageUtils.ts";
|
|
3
|
+
import { BunPackageManager } from "./BunPackageManager.ts";
|
|
4
|
+
import { YarnPackageManager } from "./YarnPackageManager.ts";
|
|
5
|
+
|
|
6
|
+
export interface PackageManager {
|
|
7
|
+
installOnPackageContentChange?: (rootWorkspace: Workspace) => Promise<void>;
|
|
8
|
+
runScript: (workspace: Workspace, scriptName: string) => Promise<void>;
|
|
9
|
+
publish: (workspace: Workspace) => Promise<void>;
|
|
10
|
+
publishWorkspaces?: (rootWorkspace: Workspace) => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const autoDetectPackageManager = (
|
|
14
|
+
rootWorkspace: Workspace,
|
|
15
|
+
): PackageManager => {
|
|
16
|
+
const hasYarnLock = existsSync(`${rootWorkspace.cwd}/yarn.lock`);
|
|
17
|
+
const hasBunLockLegacy = existsSync(`${rootWorkspace.cwd}/bun.lockb`);
|
|
18
|
+
const hasBunLock = existsSync(`${rootWorkspace.cwd}/bun.lock`);
|
|
19
|
+
const hasNpmPackageLock = existsSync(
|
|
20
|
+
`${rootWorkspace.cwd}/package-lock.json`,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
if (
|
|
24
|
+
[hasYarnLock, hasBunLockLegacy, hasBunLock, hasNpmPackageLock].filter(
|
|
25
|
+
Boolean,
|
|
26
|
+
).length > 1
|
|
27
|
+
) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Multiple lock files detected in workspace at ${rootWorkspace.cwd}. Please ensure only one lock file is present, or pass --package-manager option to bypass auto-detection.`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (hasYarnLock) {
|
|
34
|
+
return YarnPackageManager;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (hasBunLockLegacy || hasBunLock) {
|
|
38
|
+
return BunPackageManager;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (hasNpmPackageLock) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
"NPM is not currently supported as a package manager. Please migrate to Yarn or Bun, or open an issue to request support.",
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
throw new Error(
|
|
48
|
+
`No lock file detected in workspace at ${rootWorkspace.cwd}. Please ensure a supported lock file is present, or pass --package-manager option to bypass auto-detection.`,
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const getPackageManager = (
|
|
53
|
+
rootWorkspace: Workspace,
|
|
54
|
+
specifiedPackageManager?: "bun" | "yarn",
|
|
55
|
+
): PackageManager => {
|
|
56
|
+
if (specifiedPackageManager === "bun") {
|
|
57
|
+
return BunPackageManager;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (specifiedPackageManager === "yarn") {
|
|
61
|
+
return YarnPackageManager;
|
|
62
|
+
}
|
|
63
|
+
throw new Error(
|
|
64
|
+
"Invalid package manager specified. Supported values are 'bun' and 'yarn'.",
|
|
65
|
+
);
|
|
66
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { execCommand } from "../utils/execCommand.ts";
|
|
2
|
+
import type { Workspace } from "../utils/packageUtils.ts";
|
|
3
|
+
import type { PackageManager } from "./PackageManager.ts";
|
|
4
|
+
|
|
5
|
+
export const YarnPackageManager: PackageManager = {
|
|
6
|
+
async installOnPackageContentChange(rootWorkspace: Workspace) {
|
|
7
|
+
await execCommand(rootWorkspace, ["yarn", "install"], "inherit");
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
async runScript(workspace: Workspace, scriptName: string) {
|
|
11
|
+
await execCommand(workspace, ["yarn", "run", scriptName], "inherit");
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
async publish(workspace: Workspace) {
|
|
15
|
+
await execCommand(workspace, ["yarn", "npm", "publish"], "inherit");
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
async publishWorkspaces(rootWorkspace: Workspace) {
|
|
19
|
+
await execCommand(
|
|
20
|
+
rootWorkspace,
|
|
21
|
+
[
|
|
22
|
+
"yarn",
|
|
23
|
+
"workspaces",
|
|
24
|
+
"foreach",
|
|
25
|
+
"--all",
|
|
26
|
+
"--parallel",
|
|
27
|
+
"--no-private",
|
|
28
|
+
"npm",
|
|
29
|
+
"publish",
|
|
30
|
+
],
|
|
31
|
+
"inherit",
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import semver from "semver";
|
|
2
|
+
import { UsageError } from "./UsageError.ts";
|
|
3
|
+
import type { Workspace } from "./packageUtils.ts";
|
|
4
|
+
import { getWorkspaceName } from "./workspaceUtils.ts";
|
|
5
|
+
|
|
6
|
+
export type BumpType = "major" | "minor" | "patch";
|
|
7
|
+
|
|
8
|
+
// https://github.com/yarnpkg/berry/blob/506ded5f5f5a89553435940c74f1d857fd685a42/packages/plugin-version/sources/versionUtils.ts#L10
|
|
9
|
+
// Basically we only support auto-upgrading the ranges that are very simple (^x.y.z, ~x.y.z, >=x.y.z, and of course x.y.z)
|
|
10
|
+
const SUPPORTED_UPGRADE_REGEXP =
|
|
11
|
+
// eslint-disable-next-line regexp/no-unused-capturing-group
|
|
12
|
+
/^((?:>=|[~^])?)(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-z-][0-9a-z-]*)(\.(0|[1-9]\d*|\d*[a-z-][0-9a-z-]*))*)?(\+[0-9a-z-]+(\.[0-9a-z-]+)*)?$/i;
|
|
13
|
+
|
|
14
|
+
const yarnWorkspaceProtocol = "workspace:";
|
|
15
|
+
|
|
16
|
+
export const calcBumpRange = (
|
|
17
|
+
workspace: Workspace,
|
|
18
|
+
range: string,
|
|
19
|
+
newVersion: string,
|
|
20
|
+
): string => {
|
|
21
|
+
if (range === "*") {
|
|
22
|
+
return range;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let useWorkspaceProtocol = false;
|
|
26
|
+
|
|
27
|
+
if (range.startsWith(yarnWorkspaceProtocol)) {
|
|
28
|
+
const slicedRange = range.slice(yarnWorkspaceProtocol.length);
|
|
29
|
+
|
|
30
|
+
// Workspaces referenced through their path never get upgraded ("workspace:packages/yarnpkg-core")
|
|
31
|
+
if (slicedRange === workspace.relativeCwd) {
|
|
32
|
+
return range;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (slicedRange === "*") {
|
|
36
|
+
return range;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
range = slicedRange;
|
|
40
|
+
useWorkspaceProtocol = true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const parsed = SUPPORTED_UPGRADE_REGEXP.exec(range);
|
|
44
|
+
if (!parsed) {
|
|
45
|
+
const workspaceName = getWorkspaceName(workspace);
|
|
46
|
+
throw new Error(`Couldn't bump range ${range} in ${workspaceName}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return `${useWorkspaceProtocol ? yarnWorkspaceProtocol : ""}${
|
|
50
|
+
parsed[1] ?? ""
|
|
51
|
+
}${newVersion}`;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const getHighestBumpType = (bumpTypes: BumpType[]): BumpType => {
|
|
55
|
+
if (bumpTypes.includes("major")) {
|
|
56
|
+
return "major";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (bumpTypes.includes("minor")) {
|
|
60
|
+
return "minor";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return "patch";
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const calcBumpType = (
|
|
67
|
+
bumpType: BumpType,
|
|
68
|
+
maxBumpType: BumpType,
|
|
69
|
+
): BumpType => {
|
|
70
|
+
if (maxBumpType === "major") {
|
|
71
|
+
return bumpType;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (maxBumpType === "minor") {
|
|
75
|
+
return bumpType === "major" || bumpType === "minor" ? "minor" : "patch";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return "patch";
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const incVersion = (version: string, bumpType: BumpType): string | null => {
|
|
82
|
+
// handle breaking of 0.x
|
|
83
|
+
if (bumpType === "major" && semver.major(version) === 0) {
|
|
84
|
+
bumpType = "minor";
|
|
85
|
+
}
|
|
86
|
+
return semver.inc(version, bumpType);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const incrementVersion = (
|
|
90
|
+
workspace: Workspace,
|
|
91
|
+
currentVersion: string,
|
|
92
|
+
bumpType: BumpType,
|
|
93
|
+
): string => {
|
|
94
|
+
const newVersion = incVersion(currentVersion, bumpType);
|
|
95
|
+
|
|
96
|
+
if (!newVersion) {
|
|
97
|
+
throw new UsageError(
|
|
98
|
+
`Could not determine next version for "${getWorkspaceName(
|
|
99
|
+
workspace,
|
|
100
|
+
)}" (currentVersion: ${currentVersion}, bumpType: ${bumpType}})`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return newVersion;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// const createPrerelease = (
|
|
108
|
+
// version: string,
|
|
109
|
+
// prereleaseType: ReleaseType,
|
|
110
|
+
// prereleaseId: string,
|
|
111
|
+
// ) => {
|
|
112
|
+
// return semver.inc(version, prereleaseType, prereleaseId);
|
|
113
|
+
// };
|