@frsource/release-it-config 1.0.1 → 1.0.2
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/CHANGELOG.md +2 -0
- package/monorepoIndependent.cjs +15 -10
- package/package.json +1 -1
- package/version-plugin.mjs +94 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [1.0.2](https://github.com/FRSOURCE/toolkit/compare/@frsource/release-it-config-v1.0.1...${npm.name}-v1.0.2) (2024-04-19)
|
|
4
|
+
|
|
3
5
|
## [1.0.1](https://github.com/FRSOURCE/toolkit/compare/@frsource/release-it-config-v1.0.0...${npm.name}-v1.0.1) (2024-04-18)
|
|
4
6
|
|
|
5
7
|
# 1.0.0 (2024-04-18)
|
package/monorepoIndependent.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const path = require("path");
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Configuration for independent package in monorepo workspace
|
|
@@ -9,21 +9,25 @@ const nodePath = require("path");
|
|
|
9
9
|
*/
|
|
10
10
|
module.exports = ({
|
|
11
11
|
pkgName,
|
|
12
|
-
path = `packages/${pkgName.substring(pkgName.lastIndexOf("/") + 1)}`,
|
|
12
|
+
path: pkgPath = `packages/${pkgName.substring(pkgName.lastIndexOf("/") + 1)}`,
|
|
13
13
|
buildCmd = "pnpm build",
|
|
14
|
+
/**
|
|
15
|
+
* @private (for internal usage)
|
|
16
|
+
*/
|
|
17
|
+
pluginsPath = "@frsource/release-it-config",
|
|
14
18
|
}) => {
|
|
15
|
-
if (
|
|
16
|
-
const nestingLevel =
|
|
17
|
-
if (
|
|
19
|
+
if (pkgPath.startsWith("/")) pkgPath = pkgPath.substring(1);
|
|
20
|
+
const nestingLevel = pkgPath.split("/").length;
|
|
21
|
+
if (path.sep !== "/") pkgPath = pkgPath.replaceAll("/", path.sep);
|
|
18
22
|
|
|
19
23
|
return {
|
|
20
24
|
npm: {
|
|
21
|
-
publishPath: "
|
|
25
|
+
publishPath: "*.tgz",
|
|
22
26
|
publish: true,
|
|
23
27
|
},
|
|
24
28
|
git: {
|
|
25
29
|
requireBranch: "main",
|
|
26
|
-
requireCommits:
|
|
30
|
+
requireCommits: false,
|
|
27
31
|
requireCommitsFail: false, // if there are no new commits release-it will stop the release process, but without throwing and error
|
|
28
32
|
requireCleanWorkingDir: true,
|
|
29
33
|
commitsPath: ".",
|
|
@@ -46,11 +50,12 @@ module.exports = ({
|
|
|
46
50
|
plugins: {
|
|
47
51
|
"@release-it/conventional-changelog": {
|
|
48
52
|
gitRawCommitsOpts: {
|
|
49
|
-
path,
|
|
53
|
+
path: pkgPath,
|
|
50
54
|
},
|
|
51
55
|
preset: "angular",
|
|
52
56
|
infile: "CHANGELOG.md",
|
|
53
57
|
},
|
|
58
|
+
[`${pluginsPath}/version-plugin.mjs`]: {},
|
|
54
59
|
},
|
|
55
60
|
hooks: {
|
|
56
61
|
"before:bump": buildCmd,
|
|
@@ -58,8 +63,8 @@ module.exports = ({
|
|
|
58
63
|
"pnpm install",
|
|
59
64
|
`git add ${"../".repeat(nestingLevel)}pnpm-lock.yaml`,
|
|
60
65
|
],
|
|
61
|
-
"before:npm:release": "
|
|
62
|
-
"after:npm:release": "rm
|
|
66
|
+
"before:npm:release": "pnpm pack",
|
|
67
|
+
"after:npm:release": "rm *.tgz",
|
|
63
68
|
},
|
|
64
69
|
};
|
|
65
70
|
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Plugin } from "release-it";
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { tmpdir, EOL } from "node:os";
|
|
5
|
+
|
|
6
|
+
const VERSION_BUMP_INFO_PATH = join(tmpdir(), "FRSOURCE_VERSION_BUMP");
|
|
7
|
+
const docs = "https://git.io/release-it-git";
|
|
8
|
+
|
|
9
|
+
const toUnique = (array) => [...new Set(array)];
|
|
10
|
+
const flattenDependencies = (infoObj, result = []) => {
|
|
11
|
+
if (infoObj?.dependencies) {
|
|
12
|
+
for (const [key, internalInfoObj] of Object.entries(infoObj.dependencies)) {
|
|
13
|
+
result.push(key);
|
|
14
|
+
flattenDependencies(internalInfoObj, result);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
const e = (message, docs, fail = true) => {
|
|
20
|
+
const error = new Error(
|
|
21
|
+
docs ? `${message}${EOL}Documentation: ${docs}${EOL}` : message
|
|
22
|
+
);
|
|
23
|
+
error.code = fail ? 1 : 0;
|
|
24
|
+
return error;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default class FRSVersionPlugin extends Plugin {
|
|
28
|
+
async getLatestVersion() {
|
|
29
|
+
this.log.log("Reading version file from:", VERSION_BUMP_INFO_PATH);
|
|
30
|
+
const gitOptions = this.config.getContext()?.git ?? {};
|
|
31
|
+
|
|
32
|
+
const shouldBeIncremented = await this.shouldBeIncremented();
|
|
33
|
+
const commitsSinceLatestTag = await this.getCommitsSinceLatestTag(
|
|
34
|
+
gitOptions.commitsPath
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// check commit requirement only when package doesn't need to be bumped because of workspace cross-dependencies
|
|
38
|
+
if (!shouldBeIncremented && commitsSinceLatestTag === 0) {
|
|
39
|
+
throw e(
|
|
40
|
+
`There are no commits since the latest tag.`,
|
|
41
|
+
docs,
|
|
42
|
+
gitOptions.requireCommitsFail
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
afterRelease() {
|
|
48
|
+
writeFileSync(
|
|
49
|
+
VERSION_BUMP_INFO_PATH,
|
|
50
|
+
`${this.config.getContext("name")}\n`,
|
|
51
|
+
{
|
|
52
|
+
flag: "as",
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async shouldBeIncremented() {
|
|
58
|
+
const recentlyBumpedPackages = this.getRecentlyBumpedPackages();
|
|
59
|
+
const workspaceDependencies = await this.getWorkspaceDependencies();
|
|
60
|
+
|
|
61
|
+
this.debug({ recentlyBumpedPackages, workspaceDependencies });
|
|
62
|
+
|
|
63
|
+
return workspaceDependencies.some((depName) =>
|
|
64
|
+
recentlyBumpedPackages.includes(depName)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async getWorkspaceDependencies() {
|
|
69
|
+
const packageInfoRaw = await this.exec(
|
|
70
|
+
"pnpm list --only-projects --depth Infinity --json -P",
|
|
71
|
+
{ options: { write: false } }
|
|
72
|
+
);
|
|
73
|
+
const packageInfo = toUnique(JSON.parse(packageInfoRaw));
|
|
74
|
+
return flattenDependencies(packageInfo?.[0]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getRecentlyBumpedPackages() {
|
|
78
|
+
if (!existsSync(VERSION_BUMP_INFO_PATH)) return [];
|
|
79
|
+
return toUnique(
|
|
80
|
+
readFileSync(VERSION_BUMP_INFO_PATH, "utf-8")
|
|
81
|
+
.split("\n")
|
|
82
|
+
.slice(1)
|
|
83
|
+
.filter(Boolean)
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async getCommitsSinceLatestTag(commitsPath = "") {
|
|
88
|
+
const { latestTag } = this.config.getContext();
|
|
89
|
+
const ref = latestTag ? `${latestTag}..HEAD` : "HEAD";
|
|
90
|
+
return this.exec(`git rev-list ${ref} --count ${commitsPath}`, {
|
|
91
|
+
options: { write: false },
|
|
92
|
+
}).then(Number);
|
|
93
|
+
}
|
|
94
|
+
}
|