cross-bump 0.1.0 → 0.2.0

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 (3) hide show
  1. package/dist/index.d.ts +65 -53
  2. package/dist/index.js +255 -210
  3. package/package.json +5 -5
package/dist/index.d.ts CHANGED
@@ -1,11 +1,18 @@
1
- import { PathLike } from 'node:fs';
2
- import semver from 'semver';
3
- export { parse as parseVersion } from 'semver';
1
+ import { PathLike } from "node:fs";
2
+ import semver, { parse as parseVersion } from "semver";
4
3
 
4
+ //#region src/ignore.d.ts
5
5
  declare const DEFAULT_IGNORED_GLOBS: string[];
6
6
  declare const G_GITIGNORE = "**/.gitignore";
7
- declare function getGitignores(cwd: string, ignoreGlobs?: string[]): Set<string>;
7
+ declare function getGitignores(cwd?: string, ignoreGlobs?: string[]): Set<string>;
8
+ /**
9
+ * parse gitignore to globs
10
+ * @param content gitignore file content
11
+ */
12
+ declare function parseGitingore(content: string): string[];
8
13
 
14
+ //#endregion
15
+ //#region src/project.d.ts
9
16
  declare const supportedProjectCategory: readonly ["java", "javascript", "rust"];
10
17
  declare const supportedProjectFiles: readonly ["package.json", "pom.xml", "Cargo.toml"];
11
18
  declare const supportedProjectGlobs: string[];
@@ -22,17 +29,21 @@ type ProjectFile = {
22
29
  path: string;
23
30
  };
24
31
  /**
25
- * Searches for all project files in the specified directory and its subdirectories.
26
- *
27
- * @param dir - The directory to search in.
28
- * @param ignore - The directories to exclude from the search.
29
- * @param recursive - Whether to recursively search. @default false
30
- * @return An array of file paths that match the search criteria.
31
- */
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
+ */
32
39
  declare function findProjectFiles(cwd?: string, ignore?: string[], recursive?: boolean): ProjectFile[];
33
40
 
41
+ //#endregion
42
+ //#region src/util.d.ts
34
43
  declare function isBlankPath(path?: PathLike): path is "" | undefined;
35
44
 
45
+ //#endregion
46
+ //#region src/version.d.ts
36
47
  type VersionNumbers = {
37
48
  nextMajor: string;
38
49
  nextMinor: string;
@@ -47,62 +58,63 @@ type UpgradeOptions = {
47
58
  finalNewline?: boolean;
48
59
  };
49
60
  /**
50
- * Generates the next versions based on the given version.
51
- *
52
- * @param version - Optional. The version to generate the next versions from.
53
- * @param coerce - Optional. Whether to coerce the version or not. Defaults to false.
54
- * @return An object containing the next major, minor, patch, release, pre-major, pre-minor, and pre-patch versions.
55
- */
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
+ */
56
67
  declare function getNextVersions(version?: semver.SemVer | string, coerce?: boolean): VersionNumbers;
57
68
  /**
58
- * Upgrades the version of the POM file.
59
- *
60
- * @param filePath - The path to the POM file.
61
- * @param version - The new version to set.
62
- * @param dry - Whether to perform a dry run or not. @default process.env.DRY
63
- * @return A promise that resolves when the version upgrade is complete.
64
- */
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
+ */
65
76
  declare function upgradePomVersion(filePath: PathLike, version: string, opts?: UpgradeOptions): void;
66
77
  /**
67
- * Retrieves the version of the Java project.
68
- *
69
- * @return The version of the Java project.
70
- */
78
+ * Retrieves the version of the Java project.
79
+ *
80
+ * @return The version of the Java project.
81
+ */
71
82
  declare function getJavaProjectVersion(filePath: PathLike): string | undefined;
72
83
  /**
73
- * Updates the version of a package in a specified file.
74
- *
75
- * @param filePath - The path to the file.
76
- * @param version - The new version to set.
77
- * @param dry - Whether to perform a dry run. @default process.env.DRY
78
- * @return A promise that resolves when the version is upgraded.
79
- */
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
+ */
80
91
  declare function upgradePackageVersion(filePath: PathLike, version: string, opts?: UpgradeOptions): void;
81
92
  /**
82
- * Reads the package.json file at the specified file path and returns the version number.
83
- *
84
- * @param filePath - The path to the package.json file.
85
- * @return The version number as a string, or undefined if the file cannot be read or parsed.
86
- */
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
+ */
87
98
  declare function getJSProjectVersion(filePath: PathLike): string | undefined;
88
99
  /**
89
- * Retrieves the version of a Rust project based on the contents of a specified file.
90
- *
91
- * @param filePath - The path to the file containing the Rust project details.
92
- * @return The version of the Rust project, or undefined if the version is not available.
93
- */
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
+ */
94
105
  declare function getRustProjectVersion(filePath: PathLike): Promise<string | undefined>;
95
106
  /**
96
- * Upgrade the cargo version in the specified file.
97
- *
98
- * @param filePath - The path to the file.
99
- * @param version - The version to upgrade to.
100
- * @param dry - Whether to perform a dry run. @default process.env.DRY
101
- * @return A promise that resolves when the upgrade is complete.
102
- */
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
+ */
103
114
  declare function upgradeCargoVersion(filePath: PathLike, version: string, opts?: UpgradeOptions): Promise<void>;
104
115
  declare function upgradeProjectVersion(nextVersion: string, projectFile?: ProjectFile, opts?: UpgradeOptions): Promise<void>;
105
116
  declare function getProjectVersion(projectFile: ProjectFile): Promise<string | undefined>;
106
117
  declare function isVersionValid(version?: string): boolean;
107
118
 
108
- export { DEFAULT_IGNORED_GLOBS, G_GITIGNORE, type ProjectCategory, type ProjectFile, type ProjectFileName, findProjectFiles, getGitignores, getJSProjectVersion, getJavaProjectVersion, getNextVersions, getProjectVersion, getRustProjectVersion, isBlankPath, isVersionValid, supportedProjectCategory, supportedProjectFiles, supportedProjectGlobs, upgradeCargoVersion, upgradePackageVersion, upgradePomVersion, upgradeProjectVersion };
119
+ //#endregion
120
+ export { DEFAULT_IGNORED_GLOBS, G_GITIGNORE, ProjectCategory, ProjectFile, ProjectFileName, findProjectFiles, getGitignores, getJSProjectVersion, getJavaProjectVersion, getNextVersions, getProjectVersion, getRustProjectVersion, isBlankPath, isVersionValid, parseGitingore, parseVersion, supportedProjectCategory, supportedProjectFiles, supportedProjectGlobs, upgradeCargoVersion, upgradePackageVersion, upgradePomVersion, upgradeProjectVersion };
package/dist/index.js CHANGED
@@ -1,242 +1,287 @@
1
- // src/ignore.ts
1
+ import * as fs$1 from "node:fs";
2
+ import fs, { readFileSync } from "node:fs";
2
3
  import fg from "fast-glob";
3
- import gitignore from "parse-gitignore";
4
- var DEFAULT_IGNORED_GLOBS = ["**/node_modules/**", "**/.git/**", "**/target/**", "**/build/**", "**/dist/**"];
5
- var G_GITIGNORE = "**/.gitignore";
4
+ import isGlob from "is-glob";
5
+ import path from "node:path";
6
+ import process from "node:process";
7
+ import initTomlEdit, { edit, parse } from "@rainbowatcher/toml-edit-js";
8
+ import * as cheerio from "cheerio";
9
+ import detectIndent from "detect-indent";
10
+ import semver, { parse as parseVersion } from "semver";
11
+
12
+ //#region src/ignore.ts
13
+ const DEFAULT_IGNORED_GLOBS = [
14
+ "**/node_modules/**",
15
+ "**/.git/**",
16
+ "**/target/**",
17
+ "**/build/**",
18
+ "**/dist/**"
19
+ ];
20
+ const G_GITIGNORE = "**/.gitignore";
6
21
  function getGitignores(cwd, ignoreGlobs = DEFAULT_IGNORED_GLOBS) {
7
- const gitignores = fg.sync(G_GITIGNORE, {
8
- absolute: true,
9
- cwd,
10
- ignore: ignoreGlobs,
11
- onlyFiles: true
12
- });
13
- const set = /* @__PURE__ */ new Set();
14
- for (const gi of gitignores) {
15
- const result = gitignore(gi);
16
- if (!result?.globs()?.length) continue;
17
- for (const item of result.globs()[0].patterns) {
18
- set.add(item);
19
- }
20
- }
21
- return set;
22
+ const gitignores = fg.sync(G_GITIGNORE, {
23
+ absolute: true,
24
+ cwd,
25
+ ignore: ignoreGlobs,
26
+ onlyFiles: true
27
+ });
28
+ const set = new Set();
29
+ for (const gi of gitignores) {
30
+ const rules = readFileSync(gi, { encoding: "utf8" });
31
+ const globs = parseGitingore(rules);
32
+ if (globs.length === 0) continue;
33
+ for (const item of globs) set.add(item);
34
+ }
35
+ return set;
36
+ }
37
+ /**
38
+ * parse gitignore to globs
39
+ * @param content gitignore file content
40
+ */
41
+ function parseGitingore(content) {
42
+ const globs = [];
43
+ const lines = content.split(/\r\n?|\n/);
44
+ for (const rawLine of lines) {
45
+ const line = rawLine.trim();
46
+ if (line.startsWith("#") || line.length === 0) continue;
47
+ let isNegative = false;
48
+ let pattern = line;
49
+ if (pattern.startsWith("!")) {
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}/**`);
64
+ }
65
+ return globs;
22
66
  }
23
67
 
24
- // src/project.ts
25
- import fs from "node:fs";
26
- import path from "node:path";
27
- import fg2 from "fast-glob";
28
-
29
- // src/util.ts
30
- function isBlankPath(path2) {
31
- return path2 === void 0 || path2.toString().trim().length === 0;
68
+ //#endregion
69
+ //#region src/util.ts
70
+ function isBlankPath(path$1) {
71
+ return path$1 === void 0 || path$1.toString().trim().length === 0;
32
72
  }
33
73
 
34
- // src/project.ts
35
- var supportedProjectCategory = [
36
- "java",
37
- "javascript",
38
- "rust"
39
- /* , "go" */
74
+ //#endregion
75
+ //#region src/project.ts
76
+ const supportedProjectCategory = [
77
+ "java",
78
+ "javascript",
79
+ "rust"
40
80
  ];
41
- var supportedProjectFiles = ["package.json", "pom.xml", "Cargo.toml"];
42
- var supportedProjectGlobs = supportedProjectFiles.map((f) => `**/${f}`);
43
- var projectCategoryMap = {
44
- "Cargo.toml": "rust",
45
- "package.json": "javascript",
46
- "pom.xml": "java"
47
- // go: "go.mod",
81
+ const supportedProjectFiles = [
82
+ "package.json",
83
+ "pom.xml",
84
+ "Cargo.toml"
85
+ ];
86
+ const supportedProjectGlobs = supportedProjectFiles.map((f) => `**/${f}`);
87
+ const projectCategoryMap = {
88
+ "Cargo.toml": "rust",
89
+ "package.json": "javascript",
90
+ "pom.xml": "java"
48
91
  };
92
+ /**
93
+ * Searches for all project files in the specified directory and its subdirectories.
94
+ *
95
+ * @param dir - The directory to search in.
96
+ * @param ignore - The directories to exclude from the search.
97
+ * @param recursive - Whether to recursively search. @default false
98
+ * @return An array of file paths that match the search criteria.
99
+ */
49
100
  function findProjectFiles(cwd, ignore = [], recursive = false) {
50
- const files = [];
51
- if (isBlankPath(cwd)) {
52
- return files;
53
- }
54
- const projectFiles = fg2.sync(supportedProjectGlobs, {
55
- absolute: true,
56
- cwd,
57
- deep: recursive ? Infinity : 1,
58
- fs,
59
- ignore
60
- });
61
- return projectFiles.map((f) => ({
62
- category: projectCategoryMap[path.basename(f)],
63
- path: f
64
- }));
101
+ const files = [];
102
+ if (isBlankPath(cwd)) return files;
103
+ const projectFiles = fg.sync(supportedProjectGlobs, {
104
+ absolute: true,
105
+ cwd,
106
+ deep: recursive ? Infinity : 1,
107
+ fs,
108
+ ignore
109
+ });
110
+ return projectFiles.map((f) => ({
111
+ category: projectCategoryMap[path.basename(f)],
112
+ path: f
113
+ }));
65
114
  }
66
115
 
67
- // src/version.ts
68
- import * as fs2 from "node:fs";
69
- import process from "node:process";
70
- import initTomlEdit, { edit, parse } from "@rainbowatcher/toml-edit-js";
71
- import * as cheerio from "cheerio";
72
- import detectIndent from "detect-indent";
73
- import semver from "semver";
74
- var FALLBACK_VERSION = "undefined";
116
+ //#endregion
117
+ //#region src/version.ts
118
+ const FALLBACK_VERSION = "undefined";
119
+ /**
120
+ * Generates the next versions based on the given version.
121
+ *
122
+ * @param version - Optional. The version to generate the next versions from.
123
+ * @param coerce - Optional. Whether to coerce the version or not. Defaults to false.
124
+ * @return An object containing the next major, minor, patch, release, pre-major, pre-minor, and pre-patch versions.
125
+ */
75
126
  function getNextVersions(version, coerce = false) {
76
- let versionNum;
77
- let id;
78
- const defaultId = "alpha";
79
- if (version instanceof semver.SemVer) {
80
- versionNum = version.version;
81
- id = `${version.prerelease[0] ?? ""}`;
82
- } else if (typeof version === "string") {
83
- versionNum = coerce ? semver.coerce(version)?.version ?? version : version;
84
- id = `${semver.prerelease(version)?.[0] ?? ""}`;
85
- } else {
86
- versionNum = "0.0.0";
87
- id = defaultId;
88
- }
89
- const nextMajor = semver.inc(versionNum, "major") ?? FALLBACK_VERSION;
90
- const nextMinor = semver.inc(versionNum, "minor") ?? FALLBACK_VERSION;
91
- const nextPatch = semver.inc(versionNum, "patch") ?? FALLBACK_VERSION;
92
- const nextRelease = (id ? semver.inc(versionNum, "prerelease", id, "1") : semver.inc(versionNum, "patch")) ?? FALLBACK_VERSION;
93
- const nextPreMajor = semver.inc(versionNum, "premajor", defaultId, "1") ?? FALLBACK_VERSION;
94
- const nextPreMinor = semver.inc(versionNum, "preminor", defaultId, "1") ?? FALLBACK_VERSION;
95
- const nextPrePatch = semver.inc(versionNum, "prepatch", defaultId, "1") ?? FALLBACK_VERSION;
96
- return {
97
- nextMajor,
98
- nextMinor,
99
- nextPatch,
100
- nextPreMajor,
101
- nextPreMinor,
102
- nextPrePatch,
103
- nextRelease
104
- };
127
+ let versionNum;
128
+ let id;
129
+ const defaultId = "alpha";
130
+ if (version instanceof semver.SemVer) {
131
+ versionNum = version.version;
132
+ id = `${version.prerelease[0] ?? ""}`;
133
+ } else if (typeof version === "string") {
134
+ versionNum = coerce ? semver.coerce(version)?.version ?? version : version;
135
+ id = `${semver.prerelease(version)?.[0] ?? ""}`;
136
+ } else {
137
+ versionNum = "0.0.0";
138
+ id = defaultId;
139
+ }
140
+ const nextMajor = semver.inc(versionNum, "major") ?? FALLBACK_VERSION;
141
+ const nextMinor = semver.inc(versionNum, "minor") ?? FALLBACK_VERSION;
142
+ const nextPatch = semver.inc(versionNum, "patch") ?? FALLBACK_VERSION;
143
+ const nextRelease = (id ? semver.inc(versionNum, "prerelease", id, "1") : semver.inc(versionNum, "patch")) ?? FALLBACK_VERSION;
144
+ const nextPreMajor = semver.inc(versionNum, "premajor", defaultId, "1") ?? FALLBACK_VERSION;
145
+ const nextPreMinor = semver.inc(versionNum, "preminor", defaultId, "1") ?? FALLBACK_VERSION;
146
+ const nextPrePatch = semver.inc(versionNum, "prepatch", defaultId, "1") ?? FALLBACK_VERSION;
147
+ return {
148
+ nextMajor,
149
+ nextMinor,
150
+ nextPatch,
151
+ nextPreMajor,
152
+ nextPreMinor,
153
+ nextPrePatch,
154
+ nextRelease
155
+ };
105
156
  }
157
+ /**
158
+ * Upgrades the version of the POM file.
159
+ *
160
+ * @param filePath - The path to the POM file.
161
+ * @param version - The new version to set.
162
+ * @param dry - Whether to perform a dry run or not. @default process.env.DRY
163
+ * @return A promise that resolves when the version upgrade is complete.
164
+ */
106
165
  function upgradePomVersion(filePath, version, opts = {}) {
107
- const {
108
- dry = process.env.DRY,
109
- finalNewline = true
110
- } = opts;
111
- const content = fs2.readFileSync(filePath, "utf8");
112
- const $ = cheerio.load(content, {
113
- xml: { decodeEntities: false }
114
- });
115
- const projectVersion = $("project>version");
116
- const parentVersion = $("project>parent>version");
117
- projectVersion?.text(version);
118
- parentVersion?.text(version);
119
- let newXml = $.xml().trimEnd();
120
- if (finalNewline) {
121
- newXml += "\n";
122
- }
123
- if (!dry) {
124
- fs2.writeFileSync(filePath, newXml);
125
- }
166
+ const { dry = process.env.DRY, finalNewline = true } = opts;
167
+ const content = fs$1.readFileSync(filePath, "utf8");
168
+ const $ = cheerio.load(content, { xml: { decodeEntities: false } });
169
+ const projectVersion = $("project>version");
170
+ const parentVersion = $("project>parent>version");
171
+ projectVersion?.text(version);
172
+ parentVersion?.text(version);
173
+ let newXml = $.xml().trimEnd();
174
+ if (finalNewline) newXml += "\n";
175
+ if (!dry) fs$1.writeFileSync(filePath, newXml);
126
176
  }
177
+ /**
178
+ * Retrieves the version of the Java project.
179
+ *
180
+ * @return The version of the Java project.
181
+ */
127
182
  function getJavaProjectVersion(filePath) {
128
- const pom = fs2.readFileSync(filePath, "utf8");
129
- const $ = cheerio.load(pom);
130
- const currVersion = $("project>version").text();
131
- return currVersion;
183
+ const pom = fs$1.readFileSync(filePath, "utf8");
184
+ const $ = cheerio.load(pom);
185
+ const currVersion = $("project>version").text();
186
+ return currVersion;
132
187
  }
188
+ /**
189
+ * Updates the version of a package in a specified file.
190
+ *
191
+ * @param filePath - The path to the file.
192
+ * @param version - The new version to set.
193
+ * @param dry - Whether to perform a dry run. @default process.env.DRY
194
+ * @return A promise that resolves when the version is upgraded.
195
+ */
133
196
  function upgradePackageVersion(filePath, version, opts = {}) {
134
- const {
135
- dry = process.env.DRY,
136
- finalNewline = true
137
- } = opts;
138
- const file = fs2.readFileSync(filePath, "utf8");
139
- const { amount } = detectIndent(file);
140
- const packageJson = JSON.parse(file);
141
- const indent = amount ?? 2;
142
- packageJson.version = version;
143
- let newPkgJson = JSON.stringify(packageJson, null, indent);
144
- if (finalNewline) {
145
- newPkgJson += "\n";
146
- }
147
- if (!dry) {
148
- fs2.writeFileSync(filePath, newPkgJson);
149
- }
197
+ const { dry = process.env.DRY, finalNewline = true } = opts;
198
+ const file = fs$1.readFileSync(filePath, "utf8");
199
+ const { amount } = detectIndent(file);
200
+ const packageJson = JSON.parse(file);
201
+ const indent = amount ?? 2;
202
+ packageJson.version = version;
203
+ let newPkgJson = JSON.stringify(packageJson, null, indent);
204
+ if (finalNewline) newPkgJson += "\n";
205
+ if (!dry) fs$1.writeFileSync(filePath, newPkgJson);
150
206
  }
207
+ /**
208
+ * Reads the package.json file at the specified file path and returns the version number.
209
+ *
210
+ * @param filePath - The path to the package.json file.
211
+ * @return The version number as a string, or undefined if the file cannot be read or parsed.
212
+ */
151
213
  function getJSProjectVersion(filePath) {
152
- const packageJson = fs2.readFileSync(filePath, "utf8");
153
- const { version } = JSON.parse(packageJson);
154
- return version;
214
+ const packageJson = fs$1.readFileSync(filePath, "utf8");
215
+ const { version } = JSON.parse(packageJson);
216
+ return version;
155
217
  }
218
+ /**
219
+ * Retrieves the version of a Rust project based on the contents of a specified file.
220
+ *
221
+ * @param filePath - The path to the file containing the Rust project details.
222
+ * @return The version of the Rust project, or undefined if the version is not available.
223
+ */
156
224
  async function getRustProjectVersion(filePath) {
157
- const file = fs2.readFileSync(filePath, "utf8");
158
- await initTomlEdit({});
159
- const { package: cargoPackage } = parse(file);
160
- if (cargoPackage?.version) {
161
- return cargoPackage.version;
162
- }
225
+ const file = fs$1.readFileSync(filePath, "utf8");
226
+ await initTomlEdit({});
227
+ const { package: cargoPackage } = parse(file);
228
+ if (cargoPackage?.version) return cargoPackage.version;
163
229
  }
230
+ /**
231
+ * Upgrade the cargo version in the specified file.
232
+ *
233
+ * @param filePath - The path to the file.
234
+ * @param version - The version to upgrade to.
235
+ * @param dry - Whether to perform a dry run. @default process.env.DRY
236
+ * @return A promise that resolves when the upgrade is complete.
237
+ */
164
238
  async function upgradeCargoVersion(filePath, version, opts = {}) {
165
- const {
166
- dry = process.env.DRY
167
- } = opts;
168
- await initTomlEdit({});
169
- const cargoFile = fs2.readFileSync(filePath, "utf8");
170
- const cargoToml = parse(cargoFile);
171
- let newCargoFile = cargoFile;
172
- const { package: cargoPackage, workspace } = cargoToml;
173
- if (!dry) {
174
- if (cargoPackage?.version && typeof cargoPackage.version === "string") {
175
- newCargoFile = edit(cargoFile, "package.version", version);
176
- }
177
- if (workspace?.package?.version && typeof workspace.package.version === "string") {
178
- newCargoFile = edit(newCargoFile, "workspace.package.version", version);
179
- }
180
- fs2.writeFileSync(filePath, newCargoFile);
181
- }
239
+ const { dry = process.env.DRY } = opts;
240
+ await initTomlEdit({});
241
+ const cargoFile = fs$1.readFileSync(filePath, "utf8");
242
+ const cargoToml = parse(cargoFile);
243
+ let newCargoFile = cargoFile;
244
+ const { package: cargoPackage, workspace } = cargoToml;
245
+ if (!dry) {
246
+ if (cargoPackage?.version && typeof cargoPackage.version === "string") newCargoFile = edit(cargoFile, "package.version", version);
247
+ if (workspace?.package?.version && typeof workspace.package.version === "string") newCargoFile = edit(newCargoFile, "workspace.package.version", version);
248
+ fs$1.writeFileSync(filePath, newCargoFile);
249
+ }
182
250
  }
183
251
  async function upgradeProjectVersion(nextVersion, projectFile, opts = {}) {
184
- switch (projectFile?.category) {
185
- case "java": {
186
- upgradePomVersion(projectFile.path, nextVersion, opts);
187
- break;
188
- }
189
- case "javascript": {
190
- upgradePackageVersion(projectFile.path, nextVersion, opts);
191
- break;
192
- }
193
- case "rust": {
194
- await upgradeCargoVersion(projectFile.path, nextVersion, opts);
195
- break;
196
- }
197
- }
252
+ switch (projectFile?.category) {
253
+ case "java": {
254
+ upgradePomVersion(projectFile.path, nextVersion, opts);
255
+ break;
256
+ }
257
+ case "javascript": {
258
+ upgradePackageVersion(projectFile.path, nextVersion, opts);
259
+ break;
260
+ }
261
+ case "rust": {
262
+ await upgradeCargoVersion(projectFile.path, nextVersion, opts);
263
+ break;
264
+ }
265
+ }
198
266
  }
199
267
  async function getProjectVersion(projectFile) {
200
- let projectVersion;
201
- switch (projectFile?.category) {
202
- case "java": {
203
- projectVersion = getJavaProjectVersion(projectFile.path);
204
- break;
205
- }
206
- case "javascript": {
207
- projectVersion = getJSProjectVersion(projectFile.path);
208
- break;
209
- }
210
- case "rust": {
211
- projectVersion = await getRustProjectVersion(projectFile.path);
212
- }
213
- }
214
- return projectVersion;
268
+ let projectVersion;
269
+ switch (projectFile?.category) {
270
+ case "java": {
271
+ projectVersion = getJavaProjectVersion(projectFile.path);
272
+ break;
273
+ }
274
+ case "javascript": {
275
+ projectVersion = getJSProjectVersion(projectFile.path);
276
+ break;
277
+ }
278
+ case "rust": projectVersion = await getRustProjectVersion(projectFile.path);
279
+ }
280
+ return projectVersion;
215
281
  }
216
282
  function isVersionValid(version) {
217
- return !!semver.valid(version);
283
+ return !!semver.valid(version);
218
284
  }
219
285
 
220
- // src/index.ts
221
- import { parse as parse2 } from "semver";
222
- export {
223
- DEFAULT_IGNORED_GLOBS,
224
- G_GITIGNORE,
225
- findProjectFiles,
226
- getGitignores,
227
- getJSProjectVersion,
228
- getJavaProjectVersion,
229
- getNextVersions,
230
- getProjectVersion,
231
- getRustProjectVersion,
232
- isBlankPath,
233
- isVersionValid,
234
- parse2 as parseVersion,
235
- supportedProjectCategory,
236
- supportedProjectFiles,
237
- supportedProjectGlobs,
238
- upgradeCargoVersion,
239
- upgradePackageVersion,
240
- upgradePomVersion,
241
- upgradeProjectVersion
242
- };
286
+ //#endregion
287
+ export { DEFAULT_IGNORED_GLOBS, G_GITIGNORE, findProjectFiles, getGitignores, getJSProjectVersion, getJavaProjectVersion, getNextVersions, getProjectVersion, getRustProjectVersion, isBlankPath, isVersionValid, parseGitingore, parseVersion, supportedProjectCategory, supportedProjectFiles, supportedProjectGlobs, upgradeCargoVersion, upgradePackageVersion, upgradePomVersion, upgradeProjectVersion };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cross-bump",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "description": "cross language bump utility",
6
6
  "author": {
7
7
  "name": "rainbowatcher",
@@ -37,12 +37,12 @@
37
37
  "@rainbowatcher/toml-edit-js": "^0.2.1",
38
38
  "cheerio": "1.0.0",
39
39
  "detect-indent": "^7.0.1",
40
- "fast-glob": "^3.3.2",
41
- "parse-gitignore": "^2.0.0",
42
- "semver": "^7.6.3"
40
+ "fast-glob": "^3.3.3",
41
+ "is-glob": "^4.0.3",
42
+ "semver": "^7.7.1"
43
43
  },
44
44
  "scripts": {
45
45
  "clean": "rimraf dist/*",
46
- "build": "tsup"
46
+ "build": "tsdown"
47
47
  }
48
48
  }