cross-bump 0.2.0 → 0.2.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/dist/index.d.ts +75 -69
- package/dist/index.js +74 -30
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,16 @@ declare const DEFAULT_IGNORED_GLOBS: string[];
|
|
|
6
6
|
declare const G_GITIGNORE = "**/.gitignore";
|
|
7
7
|
declare function getGitignores(cwd?: string, ignoreGlobs?: string[]): Set<string>;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
* Parses gitignore content into an array of glob patterns.
|
|
10
|
+
*
|
|
11
|
+
* rules ref: https://git-scm.com/docs/gitignore#_pattern_format
|
|
12
|
+
*
|
|
13
|
+
* @param content The content of the .gitignore file.
|
|
14
|
+
* @param gitignoreFilePath Absolute path to the .gitignore file.
|
|
15
|
+
* @param projectRoot Absolute path to the project root (cwd for fast-glob).
|
|
16
|
+
* @returns An array of glob patterns.
|
|
17
|
+
*/
|
|
18
|
+
declare function parseGitingore(content: string, gitignoreFilePath: string, projectRoot: string): string[];
|
|
13
19
|
|
|
14
20
|
//#endregion
|
|
15
21
|
//#region src/project.d.ts
|
|
@@ -19,23 +25,23 @@ declare const supportedProjectGlobs: string[];
|
|
|
19
25
|
type ProjectCategory = typeof supportedProjectCategory[number];
|
|
20
26
|
type ProjectFileName = typeof supportedProjectFiles[number];
|
|
21
27
|
type ProjectFile = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
/**
|
|
29
|
+
* project category
|
|
30
|
+
*/
|
|
31
|
+
category: ProjectCategory;
|
|
32
|
+
/**
|
|
33
|
+
* project file path
|
|
34
|
+
*/
|
|
35
|
+
path: string;
|
|
30
36
|
};
|
|
31
37
|
/**
|
|
32
|
-
* Searches for all project files in the specified directory and its subdirectories.
|
|
33
|
-
*
|
|
34
|
-
* @param dir - The directory to search in.
|
|
35
|
-
* @param ignore - The directories to exclude from the search.
|
|
36
|
-
* @param recursive - Whether to recursively search. @default false
|
|
37
|
-
* @return An array of file paths that match the search criteria.
|
|
38
|
-
*/
|
|
38
|
+
* Searches for all project files in the specified directory and its subdirectories.
|
|
39
|
+
*
|
|
40
|
+
* @param dir - The directory to search in.
|
|
41
|
+
* @param ignore - The directories to exclude from the search.
|
|
42
|
+
* @param recursive - Whether to recursively search. @default false
|
|
43
|
+
* @return An array of file paths that match the search criteria.
|
|
44
|
+
*/
|
|
39
45
|
declare function findProjectFiles(cwd?: string, ignore?: string[], recursive?: boolean): ProjectFile[];
|
|
40
46
|
|
|
41
47
|
//#endregion
|
|
@@ -45,72 +51,72 @@ declare function isBlankPath(path?: PathLike): path is "" | undefined;
|
|
|
45
51
|
//#endregion
|
|
46
52
|
//#region src/version.d.ts
|
|
47
53
|
type VersionNumbers = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
nextMajor: string;
|
|
55
|
+
nextMinor: string;
|
|
56
|
+
nextPatch: string;
|
|
57
|
+
nextPreMajor: string;
|
|
58
|
+
nextPreMinor: string;
|
|
59
|
+
nextPrePatch: string;
|
|
60
|
+
nextRelease: string;
|
|
55
61
|
};
|
|
56
62
|
type UpgradeOptions = {
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
dry?: boolean;
|
|
64
|
+
finalNewline?: boolean;
|
|
59
65
|
};
|
|
60
66
|
/**
|
|
61
|
-
* Generates the next versions based on the given version.
|
|
62
|
-
*
|
|
63
|
-
* @param version - Optional. The version to generate the next versions from.
|
|
64
|
-
* @param coerce - Optional. Whether to coerce the version or not. Defaults to false.
|
|
65
|
-
* @return An object containing the next major, minor, patch, release, pre-major, pre-minor, and pre-patch versions.
|
|
66
|
-
*/
|
|
67
|
+
* Generates the next versions based on the given version.
|
|
68
|
+
*
|
|
69
|
+
* @param version - Optional. The version to generate the next versions from.
|
|
70
|
+
* @param coerce - Optional. Whether to coerce the version or not. Defaults to false.
|
|
71
|
+
* @return An object containing the next major, minor, patch, release, pre-major, pre-minor, and pre-patch versions.
|
|
72
|
+
*/
|
|
67
73
|
declare function getNextVersions(version?: semver.SemVer | string, coerce?: boolean): VersionNumbers;
|
|
68
74
|
/**
|
|
69
|
-
* Upgrades the version of the POM file.
|
|
70
|
-
*
|
|
71
|
-
* @param filePath - The path to the POM file.
|
|
72
|
-
* @param version - The new version to set.
|
|
73
|
-
* @param dry - Whether to perform a dry run or not. @default process.env.DRY
|
|
74
|
-
* @return A promise that resolves when the version upgrade is complete.
|
|
75
|
-
*/
|
|
75
|
+
* Upgrades the version of the POM file.
|
|
76
|
+
*
|
|
77
|
+
* @param filePath - The path to the POM file.
|
|
78
|
+
* @param version - The new version to set.
|
|
79
|
+
* @param dry - Whether to perform a dry run or not. @default process.env.DRY
|
|
80
|
+
* @return A promise that resolves when the version upgrade is complete.
|
|
81
|
+
*/
|
|
76
82
|
declare function upgradePomVersion(filePath: PathLike, version: string, opts?: UpgradeOptions): void;
|
|
77
83
|
/**
|
|
78
|
-
* Retrieves the version of the Java project.
|
|
79
|
-
*
|
|
80
|
-
* @return The version of the Java project.
|
|
81
|
-
*/
|
|
84
|
+
* Retrieves the version of the Java project.
|
|
85
|
+
*
|
|
86
|
+
* @return The version of the Java project.
|
|
87
|
+
*/
|
|
82
88
|
declare function getJavaProjectVersion(filePath: PathLike): string | undefined;
|
|
83
89
|
/**
|
|
84
|
-
* Updates the version of a package in a specified file.
|
|
85
|
-
*
|
|
86
|
-
* @param filePath - The path to the file.
|
|
87
|
-
* @param version - The new version to set.
|
|
88
|
-
* @param dry - Whether to perform a dry run. @default process.env.DRY
|
|
89
|
-
* @return A promise that resolves when the version is upgraded.
|
|
90
|
-
*/
|
|
90
|
+
* Updates the version of a package in a specified file.
|
|
91
|
+
*
|
|
92
|
+
* @param filePath - The path to the file.
|
|
93
|
+
* @param version - The new version to set.
|
|
94
|
+
* @param dry - Whether to perform a dry run. @default process.env.DRY
|
|
95
|
+
* @return A promise that resolves when the version is upgraded.
|
|
96
|
+
*/
|
|
91
97
|
declare function upgradePackageVersion(filePath: PathLike, version: string, opts?: UpgradeOptions): void;
|
|
92
98
|
/**
|
|
93
|
-
* Reads the package.json file at the specified file path and returns the version number.
|
|
94
|
-
*
|
|
95
|
-
* @param filePath - The path to the package.json file.
|
|
96
|
-
* @return The version number as a string, or undefined if the file cannot be read or parsed.
|
|
97
|
-
*/
|
|
99
|
+
* Reads the package.json file at the specified file path and returns the version number.
|
|
100
|
+
*
|
|
101
|
+
* @param filePath - The path to the package.json file.
|
|
102
|
+
* @return The version number as a string, or undefined if the file cannot be read or parsed.
|
|
103
|
+
*/
|
|
98
104
|
declare function getJSProjectVersion(filePath: PathLike): string | undefined;
|
|
99
105
|
/**
|
|
100
|
-
* Retrieves the version of a Rust project based on the contents of a specified file.
|
|
101
|
-
*
|
|
102
|
-
* @param filePath - The path to the file containing the Rust project details.
|
|
103
|
-
* @return The version of the Rust project, or undefined if the version is not available.
|
|
104
|
-
*/
|
|
106
|
+
* Retrieves the version of a Rust project based on the contents of a specified file.
|
|
107
|
+
*
|
|
108
|
+
* @param filePath - The path to the file containing the Rust project details.
|
|
109
|
+
* @return The version of the Rust project, or undefined if the version is not available.
|
|
110
|
+
*/
|
|
105
111
|
declare function getRustProjectVersion(filePath: PathLike): Promise<string | undefined>;
|
|
106
112
|
/**
|
|
107
|
-
* Upgrade the cargo version in the specified file.
|
|
108
|
-
*
|
|
109
|
-
* @param filePath - The path to the file.
|
|
110
|
-
* @param version - The version to upgrade to.
|
|
111
|
-
* @param dry - Whether to perform a dry run. @default process.env.DRY
|
|
112
|
-
* @return A promise that resolves when the upgrade is complete.
|
|
113
|
-
*/
|
|
113
|
+
* Upgrade the cargo version in the specified file.
|
|
114
|
+
*
|
|
115
|
+
* @param filePath - The path to the file.
|
|
116
|
+
* @param version - The version to upgrade to.
|
|
117
|
+
* @param dry - Whether to perform a dry run. @default process.env.DRY
|
|
118
|
+
* @return A promise that resolves when the upgrade is complete.
|
|
119
|
+
*/
|
|
114
120
|
declare function upgradeCargoVersion(filePath: PathLike, version: string, opts?: UpgradeOptions): Promise<void>;
|
|
115
121
|
declare function upgradeProjectVersion(nextVersion: string, projectFile?: ProjectFile, opts?: UpgradeOptions): Promise<void>;
|
|
116
122
|
declare function getProjectVersion(projectFile: ProjectFile): Promise<string | undefined>;
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as fs$1 from "node:fs";
|
|
2
2
|
import fs, { readFileSync } from "node:fs";
|
|
3
|
-
import fg from "fast-glob";
|
|
4
|
-
import isGlob from "is-glob";
|
|
5
3
|
import path from "node:path";
|
|
6
4
|
import process from "node:process";
|
|
5
|
+
import fg from "fast-glob";
|
|
7
6
|
import initTomlEdit, { edit, parse } from "@rainbowatcher/toml-edit-js";
|
|
8
7
|
import * as cheerio from "cheerio";
|
|
9
8
|
import detectIndent from "detect-indent";
|
|
@@ -19,50 +18,95 @@ const DEFAULT_IGNORED_GLOBS = [
|
|
|
19
18
|
];
|
|
20
19
|
const G_GITIGNORE = "**/.gitignore";
|
|
21
20
|
function getGitignores(cwd, ignoreGlobs = DEFAULT_IGNORED_GLOBS) {
|
|
22
|
-
const
|
|
21
|
+
const gitignoreFiles = fg.sync(G_GITIGNORE, {
|
|
23
22
|
absolute: true,
|
|
24
23
|
cwd,
|
|
25
24
|
ignore: ignoreGlobs,
|
|
26
25
|
onlyFiles: true
|
|
27
26
|
});
|
|
28
27
|
const set = new Set();
|
|
29
|
-
for (const
|
|
30
|
-
const rules = readFileSync(
|
|
31
|
-
const globs = parseGitingore(rules);
|
|
28
|
+
for (const gitignoreFilePath of gitignoreFiles) {
|
|
29
|
+
const rules = readFileSync(gitignoreFilePath, { encoding: "utf8" });
|
|
30
|
+
const globs = parseGitingore(rules, gitignoreFilePath, cwd = process.cwd());
|
|
32
31
|
if (globs.length === 0) continue;
|
|
33
32
|
for (const item of globs) set.add(item);
|
|
34
33
|
}
|
|
35
34
|
return set;
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* Processes a raw line from .gitignore content.
|
|
38
|
+
* Handles empty lines, comments, trailing whitespace
|
|
39
|
+
*/
|
|
40
|
+
function processRawGitignoreLine(rawLine) {
|
|
41
|
+
let line = rawLine.trimStart();
|
|
42
|
+
if (line.length === 0 || line.startsWith("#")) return {
|
|
43
|
+
cleanedLine: "",
|
|
44
|
+
shouldSkip: true
|
|
45
|
+
};
|
|
46
|
+
line = normalizeIgnoreRule(line);
|
|
47
|
+
let isNegative = false;
|
|
48
|
+
if (/\\\s*$/.test(line)) line = `${line.replace(/\\\s*$/, "")} `;
|
|
49
|
+
else line = line.trimEnd();
|
|
50
|
+
if (line.startsWith("!")) {
|
|
51
|
+
line = line.slice(1);
|
|
52
|
+
isNegative = true;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
cleanedLine: line,
|
|
56
|
+
isNegative
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Converts the gitignore pattern to a glob pattern relative to the project root.
|
|
61
|
+
* @param result The processed gitignore line result
|
|
62
|
+
* @param gitignoreFileDirAbs Absolute path to the directory containing the .gitignore file.
|
|
63
|
+
* @param projectRoot Absolute path to the project root.
|
|
40
64
|
*/
|
|
41
|
-
function
|
|
42
|
-
const
|
|
65
|
+
function toRelativeGlob(result, gitignoreFileDirAbs, projectRoot) {
|
|
66
|
+
const { cleanedLine, isNegative } = result;
|
|
67
|
+
const pattern = cleanedLine.replaceAll(/\\([# !])/g, "$1");
|
|
68
|
+
const relativeGitignoreDir = path.relative(projectRoot, gitignoreFileDirAbs);
|
|
69
|
+
let glob;
|
|
70
|
+
if (pattern.includes("/")) {
|
|
71
|
+
const _pattern = pattern.startsWith("/") ? pattern.slice(1) : pattern.startsWith("**/") ? pattern : `**/${pattern.endsWith("/") ? pattern.slice(0, -1) : pattern}`;
|
|
72
|
+
const targetPath = path.resolve(gitignoreFileDirAbs, _pattern);
|
|
73
|
+
glob = path.relative(projectRoot, targetPath) || ".";
|
|
74
|
+
} else glob = path.join(relativeGitignoreDir, "**", pattern);
|
|
75
|
+
if (glob === "*" || glob === ".") glob = path.join(relativeGitignoreDir, glob);
|
|
76
|
+
return isNegative ? `!${glob}` : glob;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Normalizes the gitignore rule
|
|
80
|
+
* Converts path separators to `/`, removes leading `./`, and handles empty globs.
|
|
81
|
+
*/
|
|
82
|
+
function normalizeIgnoreRule(glob) {
|
|
83
|
+
let normalized = glob.replaceAll("\\\\", "/");
|
|
84
|
+
if (normalized.startsWith("./")) normalized = normalized.slice(2);
|
|
85
|
+
if (normalized === "") normalized = ".";
|
|
86
|
+
return normalized;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Parses gitignore content into an array of glob patterns.
|
|
90
|
+
*
|
|
91
|
+
* rules ref: https://git-scm.com/docs/gitignore#_pattern_format
|
|
92
|
+
*
|
|
93
|
+
* @param content The content of the .gitignore file.
|
|
94
|
+
* @param gitignoreFilePath Absolute path to the .gitignore file.
|
|
95
|
+
* @param projectRoot Absolute path to the project root (cwd for fast-glob).
|
|
96
|
+
* @returns An array of glob patterns.
|
|
97
|
+
*/
|
|
98
|
+
function parseGitingore(content, gitignoreFilePath, projectRoot) {
|
|
99
|
+
const resultGlobs = [];
|
|
43
100
|
const lines = content.split(/\r\n?|\n/);
|
|
101
|
+
const gitignoreFileDirAbs = path.dirname(gitignoreFilePath);
|
|
44
102
|
for (const rawLine of lines) {
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
isNegative = true;
|
|
51
|
-
pattern = pattern.slice(1);
|
|
52
|
-
}
|
|
53
|
-
if (isGlob(pattern)) {
|
|
54
|
-
globs.push(isNegative ? `!${pattern}` : pattern);
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (pattern.endsWith("/")) {
|
|
58
|
-
const dirPattern = pattern.slice(0, -1);
|
|
59
|
-
globs.push(isNegative ? `!**/${dirPattern}/**` : `**/${dirPattern}/**`);
|
|
60
|
-
} else if (pattern.startsWith("/")) {
|
|
61
|
-
const rootPattern = pattern.slice(1);
|
|
62
|
-
globs.push(isNegative ? `!${rootPattern}` : rootPattern, isNegative ? `!${rootPattern}/**` : `${rootPattern}/**`);
|
|
63
|
-
} else globs.push(isNegative ? `!**/${pattern}` : `**/${pattern}`, isNegative ? `!**/${pattern}/**` : `**/${pattern}/**`);
|
|
103
|
+
const result = processRawGitignoreLine(rawLine);
|
|
104
|
+
if (result.shouldSkip) continue;
|
|
105
|
+
const relativeGlob = toRelativeGlob(result, gitignoreFileDirAbs, projectRoot);
|
|
106
|
+
resultGlobs.push(relativeGlob);
|
|
107
|
+
if (!relativeGlob.endsWith("*") && relativeGlob !== ".") resultGlobs.push(`${relativeGlob}/**`);
|
|
64
108
|
}
|
|
65
|
-
return
|
|
109
|
+
return [...new Set(resultGlobs)];
|
|
66
110
|
}
|
|
67
111
|
|
|
68
112
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cross-bump",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"description": "cross language bump utility",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "rainbowatcher",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"detect-indent": "^7.0.1",
|
|
40
40
|
"fast-glob": "^3.3.3",
|
|
41
41
|
"is-glob": "^4.0.3",
|
|
42
|
-
"semver": "^7.7.
|
|
42
|
+
"semver": "^7.7.2"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"clean": "rimraf dist/*",
|