Skip to content

Commit 73ce471

Browse files
committed
fix: resolve winget background spinner parsing bug
1 parent 69b9efa commit 73ce471

5 files changed

Lines changed: 40 additions & 32 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "winup-cli",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Minimalistic winget upgrade manager",
55
"main": "dist/cli/index.js",
66
"type": "module",

src/core/fetcher.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { getUpgradeList } from './runner.js'
77
export function fetchUpgrades(includeUnknown: boolean): PackageEntry[] {
88
try {
99
const rawText = getUpgradeList(includeUnknown)
10+
1011
const rawObjects = parseWingetOutput(rawText)
12+
1113
return normalizePackages(rawObjects)
1214
} catch (error: any) {
1315
Logger.error(`Failed to fetch updates: ${error.message}`)

src/core/normalizer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ export function normalizePackages(
66
const packageMap = new Map<string, PackageEntry>()
77

88
for (const raw of rawPackages) {
9-
const id = raw['id']
10-
const availableVersion = raw['available']
9+
const id = raw.id
10+
const availableVersion = raw.available
1111

1212
if (!id || !availableVersion) continue
1313

14-
const installedVersion = raw['version'] || ''
15-
const source = raw['source'] || ''
16-
const name = raw['name'] || id
14+
const installedVersion = raw.version || ''
15+
const source = raw.source || 'winget'
16+
const name = raw.name || id
1717

1818
const isUnknownVersion =
1919
installedVersion.toLowerCase().includes('unknown') ||

src/core/parser.ts

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
11
export function parseWingetOutput(rawOutput: string): Record<string, string>[] {
2-
const lines = rawOutput.split('\n').map(l => l.trimEnd())
3-
const separatorIndex = lines.findIndex(line => line.startsWith('---'))
4-
if (separatorIndex === -1 || separatorIndex === 0) {
2+
const lines = rawOutput.split('\n').map(l => l.replace(/\r/g, '').trim())
3+
4+
const separatorIndex = lines.findIndex(line => /^-{10,}$/.test(line))
5+
if (separatorIndex === -1) {
56
return []
67
}
7-
const headerLine = lines[separatorIndex - 1]
8+
89
const dataLines = lines.slice(separatorIndex + 1)
9-
const columns: { name: string; start: number; end?: number }[] = []
10-
const wordRegex = /\S+/g
11-
let match: RegExpExecArray | null = wordRegex.exec(headerLine)
12-
while (match !== null) {
13-
columns.push({
14-
name: match[0].toLowerCase(),
15-
start: match.index,
16-
})
17-
match = wordRegex.exec(headerLine)
18-
}
19-
for (let i = 0; i < columns.length - 1; i++) {
20-
columns[i].end = columns[i + 1].start
21-
}
2210
const results: Record<string, string>[] = []
11+
2312
for (const line of dataLines) {
24-
if (!line.trim()) continue
25-
const entry: Record<string, string> = {}
26-
for (const col of columns) {
27-
const text = col.end
28-
? line.substring(col.start, col.end)
29-
: line.substring(col.start)
30-
entry[col.name] = text.trim()
13+
const cleanLine = line.replace(/^[^a-zA-Z0-9(]+/, '').trim()
14+
if (!cleanLine) continue
15+
16+
if (
17+
/^\d+\s+upgrades/i.test(cleanLine) ||
18+
cleanLine.includes('upgrades available')
19+
)
20+
continue
21+
if (
22+
cleanLine.startsWith('1 package') ||
23+
cleanLine.includes('cannot be determined')
24+
)
25+
continue
26+
27+
const parts = cleanLine.split(/\s{2,}/)
28+
29+
if (parts.length >= 4) {
30+
results.push({
31+
name: parts[0],
32+
id: parts[1],
33+
version: parts[2],
34+
available: parts[3],
35+
source: parts[4] || 'winget',
36+
})
3137
}
32-
results.push(entry)
3338
}
39+
3440
return results
3541
}

src/core/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface ExecError {
88

99
export function getUpgradeList(includeUnknown: boolean): string {
1010
let command =
11-
'winget upgrade --accept-source-agreements --accept-package-agreements'
11+
'winget upgrade'
1212
if (includeUnknown) {
1313
command += ' --include-unknown'
1414
}

0 commit comments

Comments
 (0)