@reliverse/dler 1.4.2 → 1.4.4

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/bin/app.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const FILL_ISSUE = "If you believe this is an error, please fill in the issue on https://github.com/reliverse/dler/issues";
package/bin/app.js ADDED
@@ -0,0 +1 @@
1
+ export const FILL_ISSUE = "If you believe this is an error, please fill in the issue on https://github.com/reliverse/dler/issues";
package/bin/impl.js CHANGED
@@ -1,19 +1,19 @@
1
+ import { bumpHandler, setBumpDisabled } from "@reliverse/bleump";
1
2
  import path from "@reliverse/pathkit";
2
3
  import fs from "@reliverse/relifso";
3
4
  import { processLibraryFlow } from "./libs/sdk/sdk-impl/library-flow.js";
4
5
  import { processRegularFlow } from "./libs/sdk/sdk-impl/regular-flow.js";
5
- import { bumpHandler } from "./libs/sdk/sdk-impl/utils/utils-bump.js";
6
6
  import { removeDistFolders } from "./libs/sdk/sdk-impl/utils/utils-clean.js";
7
7
  import { PROJECT_ROOT } from "./libs/sdk/sdk-impl/utils/utils-consts.js";
8
8
  import { handleDlerError } from "./libs/sdk/sdk-impl/utils/utils-error.js";
9
9
  import { finalizeBuild } from "./libs/sdk/sdk-impl/utils/utils-info.js";
10
10
  import { createPerfTimer } from "./libs/sdk/sdk-impl/utils/utils-perf.js";
11
11
  import { loadConfig } from "./load.js";
12
+ import { FILL_ISSUE } from "./app.js";
12
13
  export async function dlerBuild(isDev) {
13
14
  const timer = createPerfTimer();
14
15
  try {
15
16
  const config = await loadConfig();
16
- const pausePublishing = config.commonPubPause;
17
17
  if (config.logsFreshFile) {
18
18
  await fs.remove(path.join(PROJECT_ROOT, config.logsFileName));
19
19
  }
@@ -23,13 +23,19 @@ export async function dlerBuild(isDev) {
23
23
  config.libsDirDist,
24
24
  config.libsList
25
25
  );
26
- if (!config.bumpDisable) {
27
- await bumpHandler(
28
- config.bumpMode,
29
- config.bumpDisable,
30
- config.bumpFilter,
31
- config.bumpSet
32
- );
26
+ const disableBump = true;
27
+ if (!config.commonPubPause) {
28
+ try {
29
+ await bumpHandler(
30
+ config.bumpMode,
31
+ !disableBump,
32
+ config.bumpFilter,
33
+ config.bumpSet
34
+ );
35
+ await setBumpDisabled(disableBump, config.commonPubPause);
36
+ } catch {
37
+ throw new Error(`Failed to set bump disabled. ${FILL_ISSUE}`);
38
+ }
33
39
  }
34
40
  await processRegularFlow(
35
41
  timer,
@@ -43,7 +49,7 @@ export async function dlerBuild(isDev) {
43
49
  config.coreEntryFile,
44
50
  config.distJsrDryRun,
45
51
  config.distJsrFailOnWarn,
46
- pausePublishing,
52
+ config.commonPubPause,
47
53
  config.distJsrDirName,
48
54
  config.distJsrBuilder,
49
55
  config.transpileTarget,
@@ -74,7 +80,7 @@ export async function dlerBuild(isDev) {
74
80
  config.distJsrFailOnWarn,
75
81
  config.libsDirDist,
76
82
  config.libsDirSrc,
77
- pausePublishing,
83
+ config.commonPubPause,
78
84
  config.commonPubRegistry,
79
85
  config.distNpmOutFilesExt,
80
86
  config.distNpmBuilder,
@@ -96,7 +102,7 @@ export async function dlerBuild(isDev) {
96
102
  );
97
103
  await finalizeBuild(
98
104
  timer,
99
- pausePublishing,
105
+ config.commonPubPause,
100
106
  config.libsList,
101
107
  config.distNpmDirName,
102
108
  config.distJsrDirName,
@@ -119,13 +125,19 @@ export async function dlerPub(isDev) {
119
125
  config.libsDirDist,
120
126
  config.libsList
121
127
  );
122
- if (!config.bumpDisable) {
123
- await bumpHandler(
124
- config.bumpMode,
125
- config.bumpDisable,
126
- config.bumpFilter,
127
- config.bumpSet
128
- );
128
+ const disableBump = true;
129
+ if (!config.commonPubPause) {
130
+ try {
131
+ await bumpHandler(
132
+ config.bumpMode,
133
+ !disableBump,
134
+ config.bumpFilter,
135
+ config.bumpSet
136
+ );
137
+ await setBumpDisabled(disableBump, config.commonPubPause);
138
+ } catch {
139
+ throw new Error(`Failed to set bump disabled. ${FILL_ISSUE}`);
140
+ }
129
141
  }
130
142
  await processRegularFlow(
131
143
  timer,
@@ -1,6 +1,7 @@
1
+ import { setBumpDisabled } from "@reliverse/bleump";
1
2
  import { relinka } from "@reliverse/relinka";
2
3
  import prettyMilliseconds from "pretty-ms";
3
- import { setBumpDisabled } from "./utils-bump.js";
4
+ import { FILL_ISSUE } from "../../../../app.js";
4
5
  import { removeDistFolders } from "./utils-clean.js";
5
6
  import { getElapsedPerfTime } from "./utils-perf.js";
6
7
  export async function finalizeBuild(timer, commonPubPause, libsList, distNpmDirName, distJsrDirName, libsDirDist) {
@@ -11,7 +12,11 @@ export async function finalizeBuild(timer, commonPubPause, libsList, distNpmDirN
11
12
  libsDirDist,
12
13
  libsList
13
14
  );
14
- await setBumpDisabled(false, commonPubPause);
15
+ try {
16
+ await setBumpDisabled(false, commonPubPause);
17
+ } catch {
18
+ throw new Error(`Failed to set bump enabled. ${FILL_ISSUE}`);
19
+ }
15
20
  }
16
21
  const elapsedTime = getElapsedPerfTime(timer);
17
22
  const transpileFormattedTime = prettyMilliseconds(elapsedTime, {
@@ -503,6 +503,7 @@ export type MkdistHooks = {
503
503
  "mkdist:entry:options": (ctx: BuildContext, entry: MkdistBuildEntry, options: MkdistOptions) => Promise<void> | void;
504
504
  };
505
505
  type _BaseAndMkdist = BaseBuildEntry & MkdistOptions;
506
+ import type { BumpMode } from "@reliverse/bleump";
506
507
  import type { RollupAliasOptions } from "@rollup/plugin-alias";
507
508
  import type { RollupCommonJSOptions } from "@rollup/plugin-commonjs";
508
509
  import type { RollupJsonOptions } from "@rollup/plugin-json";
@@ -510,7 +511,6 @@ import type { RollupNodeResolveOptions } from "@rollup/plugin-node-resolve";
510
511
  import type { RollupReplaceOptions } from "@rollup/plugin-replace";
511
512
  import type { RollupOptions as _RollupOptions, OutputOptions, Plugin, RollupBuild } from "rollup";
512
513
  import type { Options as RollupDtsOptions } from "rollup-plugin-dts";
513
- import type { BumpMode } from "./sdk-impl/utils/utils-bump.js";
514
514
  export type RollupBuildEntry = BaseBuildEntry & {
515
515
  builder: "rollup";
516
516
  };
package/package.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
+ "@reliverse/bleump": "^1.1.1",
3
4
  "@reliverse/pathkit": "^1.1.4",
4
5
  "@reliverse/reglob": "^1.0.0",
5
6
  "@reliverse/relico": "^1.1.2",
@@ -12,7 +13,6 @@
12
13
  "@rollup/plugin-node-resolve": "^16.0.1",
13
14
  "@rollup/plugin-replace": "^6.0.2",
14
15
  "@rollup/pluginutils": "^5.1.4",
15
- "@types/semver": "^7.7.0",
16
16
  "bun": "^1.2.14",
17
17
  "chalk": "^5.4.1",
18
18
  "defu": "^6.1.4",
@@ -33,7 +33,6 @@
33
33
  "rollup": "^4.41.0",
34
34
  "rollup-plugin-dts": "^6.2.1",
35
35
  "scule": "^1.3.0",
36
- "semver": "^7.7.2",
37
36
  "tinyglobby": "^0.2.13",
38
37
  "ts-morph": "^26.0.0",
39
38
  "untyped": "^2.0.0"
@@ -43,7 +42,7 @@
43
42
  "license": "MIT",
44
43
  "name": "@reliverse/dler",
45
44
  "type": "module",
46
- "version": "1.4.2",
45
+ "version": "1.4.4",
47
46
  "keywords": [
48
47
  "reliverse",
49
48
  "cli",
@@ -1,89 +0,0 @@
1
- /**
2
- * Supported bump modes for versioning:
3
- * - patch: 1.2.3 → 1.2.4 (backwards-compatible bug fixes)
4
- * - minor: 1.2.3 → 1.3.0 (new backwards-compatible features)
5
- * - major: 1.2.3 → 2.0.0 (breaking changes)
6
- * - auto: Automatically determine bump type
7
- * - manual: Set a specific version (requires bumpSet to be set)
8
- */
9
- export type BumpMode = "patch" | "minor" | "major" | "auto" | "manual";
10
- export type FileType = "package.json" | "typescript" | "unknown";
11
- export type BumpOptions = {
12
- dryRun?: boolean;
13
- verbose?: boolean;
14
- customVersion?: string;
15
- };
16
- export type FileAnalysis = {
17
- file: string;
18
- supported: boolean;
19
- detectedVersion: string | null;
20
- versionMismatch: boolean;
21
- reason: string;
22
- fileType: FileType;
23
- };
24
- export type VersionInfo = {
25
- version: string;
26
- name?: string;
27
- author?: string;
28
- };
29
- export declare const isValidSemver: (version: string) => boolean;
30
- export declare const parseSemver: (version: string) => [number, number, number];
31
- export declare const calculateNewVersion: (current: string, bumpType: BumpMode, customVersion?: string, bumpSet?: string) => string;
32
- export declare const readFileInfo: (filePath: string) => Promise<VersionInfo | null>;
33
- export declare const getCurrentVersion: (filePath?: string, field?: string) => Promise<string>;
34
- export declare const getPackageName: (filePath?: string, field?: string) => Promise<string>;
35
- export declare const getPackageAuthor: (filePath?: string, field?: string) => Promise<string>;
36
- export declare const analyzeFiles: (files: string[], referenceVersion: string) => Promise<FileAnalysis[]>;
37
- export type DlerConfig = {
38
- bumpDisable?: boolean;
39
- bumpFilter?: string[];
40
- bumpMode?: BumpMode;
41
- bumpSet?: string;
42
- };
43
- export declare const getConfigFromDler: () => Promise<{
44
- files: string[];
45
- bumpDisable?: boolean;
46
- bumpMode?: BumpMode;
47
- bumpSet?: string;
48
- }>;
49
- export declare const getFilesFromConfigOrDefault: () => Promise<string[]>;
50
- export declare const bumpVersion: (bumpType: BumpMode, files?: string[], options?: BumpOptions, globs?: string[], bumpSet?: string) => Promise<void>;
51
- export declare const bumpVersionWithAnalysis: (bumpType: BumpMode, files?: string[], options?: BumpOptions, bumpSet?: string) => Promise<void>;
52
- export declare const compareVersions: (version1: string, version2: string) => number;
53
- export declare const getLatestVersion: (versions: string[]) => string | null;
54
- export declare const isPrerelease: (version: string) => boolean;
55
- export declare const satisfiesRange: (version: string, range: string) => boolean;
56
- export type BumpConfig = {
57
- bumpType: BumpMode;
58
- customVersion?: string;
59
- dryRun?: boolean;
60
- verbose?: boolean;
61
- };
62
- export type SessionConfig = {
63
- isCI: boolean;
64
- isNonInteractive: boolean;
65
- mainFile: string;
66
- filesToBump: string[];
67
- options: {
68
- dryRun: boolean;
69
- verbose: boolean;
70
- customVersion?: string;
71
- };
72
- bumpType: BumpMode;
73
- };
74
- export declare function validateBumpConfig(bumpType: BumpMode, customVersion?: string): void;
75
- export declare function getDefaultBumpMode(isCI: boolean, isNonInteractive: boolean): BumpMode;
76
- export declare function handleNonInteractiveSession(config: SessionConfig): Promise<void>;
77
- export declare function handleInteractiveSession(config: SessionConfig, projectVersion: string): Promise<{
78
- supportedFiles: FileAnalysis[];
79
- mismatchedFiles: FileAnalysis[];
80
- fileAnalysis: FileAnalysis[];
81
- }>;
82
- /**
83
- * Updates the "bumpDisable" flag in the build configuration file.
84
- */
85
- export declare function setBumpDisabled(value: boolean, commonPubPause: boolean): Promise<void>;
86
- /**
87
- * Handles version bumping using @reliverse/bleump
88
- */
89
- export declare function bumpHandler(bumpMode: BumpMode, bumpDisable: boolean, bumpFilter: string[], bumpSet?: string): Promise<void>;
@@ -1,416 +0,0 @@
1
- import { relinka } from "@reliverse/relinka";
2
- import { readFile, writeFile, access } from "node:fs/promises";
3
- import { join } from "node:path";
4
- import semver from "semver";
5
- const PROJECT_ROOT = process.cwd();
6
- const versionPatterns = {
7
- packageJson: /"version"\s*:\s*"([^"]+)"/,
8
- typescript: /version\s*[=:]\s*["']([^"']+)["']|version\s*:\s*["']([^"']+)["']\s*,/
9
- };
10
- const globToRegex = (pattern) => {
11
- const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "DOUBLESTAR").replace(/\*/g, "[^/]*").replace(/DOUBLESTAR/g, ".*").replace(/\?/g, "[^/]");
12
- return new RegExp(`^${escaped}$`);
13
- };
14
- const matchesGlobs = (filePath, globs) => {
15
- if (globs.length === 0) return true;
16
- return globs.some((glob) => globToRegex(glob).test(filePath));
17
- };
18
- export const isValidSemver = (version) => {
19
- return semver.valid(version) !== null;
20
- };
21
- export const parseSemver = (version) => {
22
- const parsed = semver.parse(version);
23
- if (!parsed) throw new Error(`invalid semver: ${version}`);
24
- return [parsed.major, parsed.minor, parsed.patch];
25
- };
26
- export const calculateNewVersion = (current, bumpType, customVersion, bumpSet) => {
27
- if (bumpType === "manual") {
28
- if (bumpSet) {
29
- if (!isValidSemver(bumpSet)) {
30
- throw new Error(`invalid bumpSet version: ${bumpSet}`);
31
- }
32
- return bumpSet;
33
- }
34
- if (!customVersion) {
35
- throw new Error(
36
- "either bumpSet (in .config/dler.ts) or --customVersion required when bumpType is 'manual'"
37
- );
38
- }
39
- if (!isValidSemver(customVersion)) {
40
- throw new Error(`invalid custom version: ${customVersion}`);
41
- }
42
- return customVersion;
43
- }
44
- let releaseType;
45
- switch (bumpType) {
46
- case "major":
47
- releaseType = "major";
48
- break;
49
- case "minor":
50
- releaseType = "minor";
51
- break;
52
- case "patch":
53
- case "auto":
54
- releaseType = "patch";
55
- break;
56
- default:
57
- throw new Error(`unknown bump type: ${bumpType}`);
58
- }
59
- const newVersion = semver.inc(current, releaseType);
60
- if (!newVersion) {
61
- throw new Error(`failed to bump version ${current} with type ${bumpType}`);
62
- }
63
- return newVersion;
64
- };
65
- const detectFileType = (filePath, content) => {
66
- if (filePath.endsWith("package.json")) return "package.json";
67
- if (filePath.endsWith(".ts") || filePath.endsWith(".js")) {
68
- if (versionPatterns.typescript.test(content)) return "typescript";
69
- }
70
- return "unknown";
71
- };
72
- const extractVersion = (content, fileType) => {
73
- switch (fileType) {
74
- case "package.json": {
75
- const pkgMatch = versionPatterns.packageJson.exec(content);
76
- return pkgMatch?.[1] ?? null;
77
- }
78
- case "typescript": {
79
- const tsMatch = versionPatterns.typescript.exec(content);
80
- return tsMatch?.[1] ?? tsMatch?.[2] ?? null;
81
- }
82
- default:
83
- return null;
84
- }
85
- };
86
- export const readFileInfo = async (filePath) => {
87
- try {
88
- const content = await readFile(filePath, "utf-8");
89
- if (filePath.endsWith("package.json")) {
90
- const pkg = JSON.parse(content);
91
- return {
92
- version: pkg.version ?? "",
93
- name: pkg.name ?? "",
94
- author: pkg.author ?? ""
95
- };
96
- }
97
- const fileType = detectFileType(filePath, content);
98
- const version = extractVersion(content, fileType);
99
- return version ? { version } : null;
100
- } catch {
101
- return null;
102
- }
103
- };
104
- export const getCurrentVersion = async (filePath = "package.json", field = "version") => {
105
- try {
106
- const content = await readFile(filePath, "utf-8");
107
- if (filePath.endsWith("package.json")) {
108
- const pkg = JSON.parse(content);
109
- const value = pkg[field];
110
- if (!value || typeof value !== "string") {
111
- throw new Error(`field '${field}' not found in ${filePath}`);
112
- }
113
- return value;
114
- }
115
- const pattern = new RegExp(`${field}\\s*[=:]\\s*["']([^"']+)["']`);
116
- const match = content.match(pattern);
117
- if (!match?.[1]) {
118
- throw new Error(`field '${field}' not found in ${filePath}`);
119
- }
120
- return match[1];
121
- } catch (error) {
122
- if (error instanceof Error) throw error;
123
- throw new Error(`failed to read ${filePath}: ${error}`);
124
- }
125
- };
126
- export const getPackageName = async (filePath = "package.json", field = "name") => {
127
- return getCurrentVersion(filePath, field);
128
- };
129
- export const getPackageAuthor = async (filePath = "package.json", field = "author") => {
130
- return getCurrentVersion(filePath, field);
131
- };
132
- const updateVersionInContent = (content, newVersion, fileType) => {
133
- switch (fileType) {
134
- case "package.json":
135
- return content.replace(
136
- versionPatterns.packageJson,
137
- `"version": "${newVersion}"`
138
- );
139
- case "typescript": {
140
- return content.replace(versionPatterns.typescript, (match) => {
141
- const delimiter = match.includes('"') ? '"' : "'";
142
- const operator = match.includes("=") ? "=" : ":";
143
- const hasComma = match.includes(",");
144
- return `version${operator} ${delimiter}${newVersion}${delimiter}${hasComma ? "," : ""}`;
145
- });
146
- }
147
- default:
148
- throw new Error("unsupported file type for version update");
149
- }
150
- };
151
- export const analyzeFiles = async (files, referenceVersion) => {
152
- const results = [];
153
- for (const file of files) {
154
- try {
155
- const content = await readFile(file, "utf-8");
156
- const fileType = detectFileType(file, content);
157
- const detectedVersion = extractVersion(content, fileType);
158
- let supported = fileType !== "unknown";
159
- let versionMismatch = false;
160
- let reason = "";
161
- if (!supported) {
162
- reason = "unsupported file type";
163
- } else if (!detectedVersion) {
164
- reason = "no version field found";
165
- supported = false;
166
- } else if (!semver.eq(detectedVersion, referenceVersion)) {
167
- versionMismatch = true;
168
- reason = `version mismatch: found ${detectedVersion}, expected ${referenceVersion}`;
169
- } else {
170
- reason = "ok";
171
- }
172
- results.push({
173
- file,
174
- supported,
175
- detectedVersion,
176
- versionMismatch,
177
- reason,
178
- fileType
179
- });
180
- } catch (error) {
181
- results.push({
182
- file,
183
- supported: false,
184
- detectedVersion: null,
185
- versionMismatch: false,
186
- reason: `read error: ${error}`,
187
- fileType: "unknown"
188
- });
189
- }
190
- }
191
- return results;
192
- };
193
- export const getConfigFromDler = async () => {
194
- try {
195
- await access(".config/dler.ts");
196
- const content = await readFile(".config/dler.ts", "utf-8");
197
- const filesMatch = /bumpFilter\s*[:=]\s*\[([\s\S]*?)\]/.exec(content);
198
- const bumpDisableMatch = /bumpDisable\s*[:=]\s*(true|false)/.exec(content);
199
- const bumpModeMatch = /bumpMode\s*[:=]\s*["']([^"']+)["']/.exec(content);
200
- const bumpSetMatch = /bumpSet\s*[:=]\s*["']([^"']+)["']/.exec(content);
201
- const files = filesMatch?.[1] ? filesMatch[1].split(",").map((f) => f.trim().replace(/["']/g, "")).filter(Boolean) : ["package.json", ".config/rse.ts"];
202
- const bumpDisable = bumpDisableMatch ? bumpDisableMatch[1] === "true" : void 0;
203
- const bumpMode = bumpModeMatch?.[1];
204
- const bumpSet = bumpSetMatch?.[1];
205
- return {
206
- files,
207
- bumpDisable,
208
- bumpMode,
209
- bumpSet
210
- };
211
- } catch {
212
- return {
213
- files: ["package.json", ".config/rse.ts"]
214
- };
215
- }
216
- };
217
- export const getFilesFromConfigOrDefault = async () => {
218
- const config = await getConfigFromDler();
219
- return config.files;
220
- };
221
- export const bumpVersion = async (bumpType, files = [], options = {}, globs = [], bumpSet) => {
222
- const { dryRun = false, verbose = false, customVersion } = options;
223
- const currentVersion = await getCurrentVersion();
224
- const newVersion = calculateNewVersion(
225
- currentVersion,
226
- bumpType,
227
- customVersion,
228
- bumpSet
229
- );
230
- if (verbose) {
231
- relinka("info", `bumping version: ${currentVersion} \u2192 ${newVersion}`);
232
- }
233
- const filteredFiles = files.filter((file) => matchesGlobs(file, globs));
234
- const updateResults = [];
235
- for (const file of filteredFiles) {
236
- try {
237
- const content = await readFile(file, "utf-8");
238
- const fileType = detectFileType(file, content);
239
- if (fileType === "unknown") {
240
- if (verbose) relinka("log", `skipping unsupported file: ${file}`);
241
- continue;
242
- }
243
- const currentFileVersion = extractVersion(content, fileType);
244
- if (!currentFileVersion) {
245
- if (verbose) relinka("log", `no version found in: ${file}`);
246
- continue;
247
- }
248
- const updatedContent = updateVersionInContent(
249
- content,
250
- newVersion,
251
- fileType
252
- );
253
- if (dryRun) {
254
- relinka("log", `- [dry-run] would update ${file}`);
255
- updateResults.push({ file, success: true });
256
- } else {
257
- await writeFile(file, updatedContent, "utf-8");
258
- if (verbose) {
259
- relinka("log", `- updated ${file}`);
260
- }
261
- updateResults.push({ file, success: true });
262
- }
263
- } catch (error) {
264
- const errorMsg = error instanceof Error ? error.message : String(error);
265
- updateResults.push({ file, success: false, error: errorMsg });
266
- if (verbose) {
267
- relinka("error", `failed to update ${file}: ${errorMsg}`);
268
- }
269
- }
270
- }
271
- const failures = updateResults.filter((r) => !r.success);
272
- if (failures.length > 0) {
273
- const failedFiles = failures.map((f) => `${f.file}: ${f.error}`).join(", ");
274
- throw new Error(`failed to update version in files: ${failedFiles}`);
275
- }
276
- if (verbose && !dryRun) {
277
- relinka(
278
- "verbose",
279
- `successfully bumped ${updateResults.length} files to version ${newVersion}`
280
- );
281
- }
282
- };
283
- export const bumpVersionWithAnalysis = async (bumpType, files = [], options = {}, bumpSet) => {
284
- const currentVersion = await getCurrentVersion();
285
- const analysis = await analyzeFiles(files, currentVersion);
286
- const supportedFiles = analysis.filter((a) => a.supported).map((a) => a.file);
287
- await bumpVersion(bumpType, supportedFiles, options, [], bumpSet);
288
- };
289
- export const compareVersions = (version1, version2) => {
290
- return semver.compare(version1, version2);
291
- };
292
- export const getLatestVersion = (versions) => {
293
- const validVersions = versions.filter(isValidSemver);
294
- if (validVersions.length === 0) return null;
295
- return semver.maxSatisfying(validVersions, "*");
296
- };
297
- export const isPrerelease = (version) => {
298
- return semver.prerelease(version) !== null;
299
- };
300
- export const satisfiesRange = (version, range) => {
301
- return semver.satisfies(version, range);
302
- };
303
- export function validateBumpConfig(bumpType, customVersion) {
304
- if (!["patch", "minor", "major", "auto", "manual"].includes(bumpType)) {
305
- throw new Error(`Invalid bump type: ${bumpType}`);
306
- }
307
- if (bumpType === "manual" && !customVersion) {
308
- throw new Error("customVersion is required when using manual bump type");
309
- }
310
- if (customVersion && !isValidSemver(customVersion)) {
311
- throw new Error(`Invalid custom version: ${customVersion}`);
312
- }
313
- }
314
- export function getDefaultBumpMode(isCI, isNonInteractive) {
315
- if (isCI || isNonInteractive) {
316
- return "patch";
317
- }
318
- return "auto";
319
- }
320
- export async function handleNonInteractiveSession(config) {
321
- const { bumpType, options, filesToBump } = config;
322
- validateBumpConfig(bumpType, options.customVersion);
323
- try {
324
- await bumpVersionWithAnalysis(bumpType, filesToBump, options);
325
- } catch (error) {
326
- throw new Error(`Failed to bump version: ${error}`);
327
- }
328
- }
329
- export async function handleInteractiveSession(config, projectVersion) {
330
- const { filesToBump } = config;
331
- const fileAnalysis = await analyzeFiles(filesToBump, projectVersion);
332
- const supportedFiles = fileAnalysis.filter((r) => r.supported);
333
- const unsupportedFiles = fileAnalysis.filter((r) => !r.supported);
334
- const mismatchedFiles = fileAnalysis.filter((r) => r.versionMismatch);
335
- if (supportedFiles.length === 0) {
336
- const reasons = unsupportedFiles.map((f) => `${f.file}: ${f.reason}`).join("\n");
337
- throw new Error(`No files can be bumped. Analysis results:
338
- ${reasons}`);
339
- }
340
- if (mismatchedFiles.length > 0) {
341
- const mismatches = mismatchedFiles.map(
342
- (f) => `${f.file}: found version ${f.detectedVersion} (expected ${projectVersion})`
343
- ).join("\n");
344
- relinka("warn", "Some files have mismatched versions:");
345
- relinka("info", mismatches);
346
- throw new Error("Please fix the version mismatches before continuing");
347
- }
348
- return {
349
- supportedFiles,
350
- mismatchedFiles,
351
- fileAnalysis
352
- };
353
- }
354
- async function fileExists(filePath) {
355
- try {
356
- await access(filePath);
357
- return true;
358
- } catch {
359
- return false;
360
- }
361
- }
362
- async function updateDlerConfig(key, value) {
363
- const dlerCfgPath = join(PROJECT_ROOT, ".config/dler.ts");
364
- if (!await fileExists(dlerCfgPath)) {
365
- relinka(
366
- "warn",
367
- `No .config/dler.ts found to update ${key}. This is not an error, but the ${key} flag will not be updated.`
368
- );
369
- return;
370
- }
371
- try {
372
- const content = await readFile(dlerCfgPath, "utf-8");
373
- const formattedValue = Array.isArray(value) ? `[${value.map((v) => `"${v}"`).join(", ")}]` : typeof value === "string" ? `"${value}"` : value;
374
- const pattern = new RegExp(`${key}\\s*[:=]\\s*([^,}\\]]+)`);
375
- const updatedContent = content.replace(
376
- pattern,
377
- `${key}: ${formattedValue}`
378
- );
379
- await writeFile(dlerCfgPath, updatedContent, "utf-8");
380
- relinka(
381
- "info",
382
- `Successfully updated ${key} to ${formattedValue} in .config/dler.ts`
383
- );
384
- } catch (error) {
385
- relinka(
386
- "warn",
387
- `Failed to update ${key} in ${dlerCfgPath}. This is not an error, but the ${key} flag will not be updated.`,
388
- error
389
- );
390
- }
391
- }
392
- export async function setBumpDisabled(value, commonPubPause) {
393
- if (commonPubPause && !value) {
394
- return;
395
- }
396
- await getConfigFromDler();
397
- await updateDlerConfig("bumpDisable", value);
398
- }
399
- export async function bumpHandler(bumpMode, bumpDisable, bumpFilter, bumpSet) {
400
- if (bumpDisable) {
401
- relinka("info", "Version bumping is paused");
402
- return;
403
- }
404
- try {
405
- const files = bumpFilter.length > 0 ? bumpFilter : ["package.json"];
406
- await bumpVersionWithAnalysis(bumpMode, files, {
407
- dryRun: false,
408
- verbose: true,
409
- customVersion: bumpMode === "manual" ? bumpSet : void 0
410
- });
411
- relinka("success", "Version bump completed successfully");
412
- } catch (error) {
413
- relinka("error", "Failed to bump version", error);
414
- throw error;
415
- }
416
- }