@frsource/release-it-config 1.0.0 → 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 +7 -0
- package/monorepoIndependent.cjs +31 -20
- package/package.json +1 -1
- package/version-plugin.mjs +94 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
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
|
+
|
|
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)
|
|
6
|
+
|
|
7
|
+
# 1.0.0 (2024-04-18)
|
package/monorepoIndependent.cjs
CHANGED
|
@@ -1,59 +1,70 @@
|
|
|
1
|
-
const
|
|
1
|
+
const path = require("path");
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Configuration for independent package in monorepo workspace
|
|
5
5
|
* @param {Object} options
|
|
6
|
-
* @param {string} options.
|
|
7
|
-
* @param {string} [options.path=`packages/${options.
|
|
6
|
+
* @param {string} options.pkgName name of the package in the monorepo, e.g. `@frsource/my-package`
|
|
7
|
+
* @param {string} [options.path=`packages/${options.pkgName}`] path of the package relative to the monorepo root, without starting slash. Always use "/" as delimiter. Will default to `packages/${options.pkgName}` (package scope in `options.pkgName` will be omitted)
|
|
8
8
|
* @param {string} [options.buildCmd="pnpm build"] command that should be used to build the package, defaults to `pnpm build`
|
|
9
9
|
*/
|
|
10
10
|
module.exports = ({
|
|
11
|
-
|
|
12
|
-
path = `packages/${
|
|
11
|
+
pkgName,
|
|
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",
|
|
26
|
+
publish: true,
|
|
22
27
|
},
|
|
23
28
|
git: {
|
|
24
29
|
requireBranch: "main",
|
|
25
|
-
requireCommits:
|
|
30
|
+
requireCommits: false,
|
|
26
31
|
requireCommitsFail: false, // if there are no new commits release-it will stop the release process, but without throwing and error
|
|
27
32
|
requireCleanWorkingDir: true,
|
|
28
33
|
commitsPath: ".",
|
|
29
|
-
commitMessage: "chore:
|
|
34
|
+
commitMessage: "chore(release): ${npm.name} v${version}",
|
|
30
35
|
tagName: "${npm.name}-v${version}",
|
|
31
36
|
tagMatch: "${npm.name}-v[0-9]*.[0-9]*.[0-9]*",
|
|
32
37
|
getLatestTagFromAllRefs: false, // https://github.com/release-it/release-it/blob/main/docs/git.md#use-all-refs-to-determine-latest-tag
|
|
33
38
|
},
|
|
34
39
|
github: {
|
|
35
40
|
release: true,
|
|
41
|
+
releaseName: `${pkgName}@\${version}`,
|
|
36
42
|
comments: {
|
|
37
|
-
submit:
|
|
43
|
+
submit: false, // hitting the secondary rate limit issues, see:
|
|
44
|
+
// https://github.com/FRSOURCE/toolkit/actions/runs/8730568392/job/23954615077#step:8:38
|
|
38
45
|
issue:
|
|
39
|
-
":rocket: _This issue has been resolved in ${
|
|
40
|
-
pr: ":rocket: _This pull request is included in ${
|
|
46
|
+
":rocket: _This issue has been resolved in [${releaseName} (click for release notes)](${releaseUrl})._",
|
|
47
|
+
pr: ":rocket: _This pull request is included in [${releaseName} (click for release notes)](${releaseUrl})._",
|
|
41
48
|
},
|
|
42
49
|
},
|
|
43
50
|
plugins: {
|
|
44
51
|
"@release-it/conventional-changelog": {
|
|
45
52
|
gitRawCommitsOpts: {
|
|
46
|
-
path,
|
|
53
|
+
path: pkgPath,
|
|
47
54
|
},
|
|
55
|
+
preset: "angular",
|
|
56
|
+
infile: "CHANGELOG.md",
|
|
48
57
|
},
|
|
58
|
+
[`${pluginsPath}/version-plugin.mjs`]: {},
|
|
49
59
|
},
|
|
50
60
|
hooks: {
|
|
51
61
|
"before:bump": buildCmd,
|
|
52
|
-
"after:bump":
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
62
|
+
"after:bump": [
|
|
63
|
+
"pnpm install",
|
|
64
|
+
`git add ${"../".repeat(nestingLevel)}pnpm-lock.yaml`,
|
|
65
|
+
],
|
|
66
|
+
"before:npm:release": "pnpm pack",
|
|
67
|
+
"after:npm:release": "rm *.tgz",
|
|
57
68
|
},
|
|
58
69
|
};
|
|
59
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
|
+
}
|