|
2 | 2 | import type { FileInfo, VersionBumpOptions } from './types'
|
3 | 3 | import { readFileSync, writeFileSync } from 'node:fs'
|
4 | 4 | import { dirname, join, relative, resolve } from 'node:path'
|
5 |
| -import process from 'node:process' |
| 5 | +import * as process from 'node:process' |
6 | 6 | import { checkInterruption, userInterrupted } from './interrupt'
|
7 | 7 | import { ProgressEvent } from './types'
|
8 | 8 | import {
|
@@ -1099,16 +1099,17 @@ function showGeneratedChangelog(newContent: string, existingContent: string): vo
|
1099 | 1099 | for (const line of lines) {
|
1100 | 1100 | // Look for version headers like "## [1.0.1]" or "### v1.0.1"
|
1101 | 1101 | if (line.match(/^#+\s*(\[?v?\d+\.\d+\.\d+.*?\]?|Release)/i)) {
|
| 1102 | + // If we already found a changelog entry and now hit another header, stop processing |
| 1103 | + // This ensures we only get the first/latest entry |
| 1104 | + if (inChangelog) { |
| 1105 | + break |
| 1106 | + } |
1102 | 1107 | inChangelog = true
|
1103 | 1108 | relevantLines.push(line)
|
1104 | 1109 | }
|
1105 | 1110 | else if (inChangelog) {
|
1106 |
| - // Stop at the next version header or empty sections |
1107 |
| - if (line.match(/^#+\s*(\[?v?\d+\.\d+\.\d+.*?\]?|Release)/i)) { |
1108 |
| - break |
1109 |
| - } |
1110 | 1111 | // Add content lines but limit output
|
1111 |
| - if (relevantLines.length < 15) { // Limit to ~15 lines |
| 1112 | + if (relevantLines.length < 30) { // Allow for a bit more content |
1112 | 1113 | relevantLines.push(line)
|
1113 | 1114 | }
|
1114 | 1115 | }
|
@@ -1201,6 +1202,9 @@ async function generateChangelog(cwd: string, fromVersion?: string, toVersion?:
|
1201 | 1202 |
|
1202 | 1203 | // Write the combined content back to the file
|
1203 | 1204 | fs.writeFileSync(changelogPath, newContent, 'utf-8')
|
| 1205 | + |
| 1206 | + // Show the newly generated changelog section |
| 1207 | + showGeneratedChangelog(newContent, existingContent) |
1204 | 1208 | }
|
1205 | 1209 | else {
|
1206 | 1210 | // Use CLI approach in test mode
|
@@ -1297,15 +1301,20 @@ async function rollbackChanges(fileBackups: Map<string, { content: string, versi
|
1297 | 1301 | }
|
1298 | 1302 |
|
1299 | 1303 | // Then restore file contents to their original state
|
1300 |
| - for (const [filePath, backup] of fileBackups) { |
| 1304 | + // Use Array.from to convert Map entries to an array for compatibility |
| 1305 | + Array.from(fileBackups.entries()).forEach(([filePath, backup]) => { |
1301 | 1306 | try {
|
1302 |
| - const fs = await import('node:fs') |
1303 |
| - fs.writeFileSync(filePath, backup.content, 'utf-8') |
| 1307 | + // Use a dynamic import for fs |
| 1308 | + import('node:fs').then(fs => { |
| 1309 | + fs.writeFileSync(filePath, backup.content, 'utf-8') |
| 1310 | + }).catch(importError => { |
| 1311 | + console.warn(`Warning: Failed to import fs module: ${importError}`) |
| 1312 | + }) |
1304 | 1313 | }
|
1305 | 1314 | catch (rollbackError) {
|
1306 | 1315 | console.warn(`Warning: Failed to rollback ${filePath}: ${rollbackError}`)
|
1307 | 1316 | }
|
1308 |
| - } |
| 1317 | + }) |
1309 | 1318 | }
|
1310 | 1319 |
|
1311 | 1320 | /**
|
|
0 commit comments