Skip to content

refactor(update-links): divided into features instead of layers#9

Merged
mzwing merged 10 commits into
MZWNET:masterfrom
HyacinthHaru:master
Jun 22, 2026
Merged

refactor(update-links): divided into features instead of layers#9
mzwing merged 10 commits into
MZWNET:masterfrom
HyacinthHaru:master

Conversation

@HyacinthHaru

Copy link
Copy Markdown

结构(by-layer → by-feature)

  • 三个自包含的功能文件:
    • archive.ts — 版本清单发现
    • releases.ts — 现代下载页解析(React props)
    • legacy.ts — 旧版下载页解析 + 失败诊断
  • 新增 utils/:http.ts(fetchText)、version.ts(版本号提取)、
    regex-match.ts(pickFirstMatch/pickAllMatches)、concurrency.ts(mapWithConcurrency)
  • 删除 regex.ts / matching.ts / html.ts / types.ts(内容按「谁在用」归位)

顺带修复与改进

  • 修复 mapWithConcurrency 并发 bug:原 Array.from({length:N}).fill(runWorker())
    复用了同一个 promise,实际只起 1 个 worker → 脚本退化成串行抓取。改为工厂回调
    Array.from({length:N}, () => runWorker()),并发上限 limit 才真正生效。
  • 抽取 fetchText:消除 archive.ts / releases.ts 中重复的 fetch + 状态检查
  • 删除死代码 fallback 正则:LEGACY_LINUX_RUNFILE_FALLBACK_REGEX 与主正则逐字符
    相同,?? fallback 永不生效。实测 69 个 CUDA 版本(其中 16 个走 legacy 路径)全部
    被主正则覆盖,0 个需要 fallback
    ,故删除而非放宽。
  • 解耦:releases.ts 不再直接依赖 legacy 正则做失败诊断,改为调用
    legacy.describeLegacyFailure()
  • 简化:archive 的 label→version 清理逻辑下放到 archive.ts,index.ts 直接用 entry.version

…ency

Fix concurrency bug: replace .fill(runWorker()) with Array.from factory callback so each worker slot starts its own independent promise.
…agnostics

Inline all LEGACY regexes, WIN10_REGEX, normalizeLegacyUrl, pickWin10Preferred, and LegacyDownloadLinks into legacy.ts; add describeLegacyFailure. Remove matching.ts and clean up regex.ts/types.ts.
Inline PRIMARY/FALLBACK/REACT_PROPS regexes, ReleaseEntry/PageData/DownloadLinks types, and private extractReactProps/decodeHtmlEntities into releases.ts; delete now-empty html.ts, regex.ts, and types.ts.
@mzwing

mzwing commented Jun 21, 2026

Copy link
Copy Markdown

thx Haru🥰

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the scripts/update-links scraper from a by-layer layout into a by-feature structure, introduces shared utilities, and adds targeted Vitest coverage for key parsing/conmsumption helpers.

Changes:

  • Introduces new utilities (fetchText, regex match helpers, version extraction, and concurrency-limited mapping) and adds dedicated tests.
  • Refactors archive/version discovery and releases/legacy parsing to use the new utilities and removes now-obsolete shared modules (types.ts, regex.ts, matching.ts).
  • Fixes the concurrency worker startup bug by ensuring each worker loop is started with a distinct promise.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/update-links/version.test.ts Adds unit tests for version extraction from headers and URLs.
tests/update-links/regex-match.test.ts Adds tests for regex match helpers and patch-link filtering.
tests/update-links/legacy.test.ts Adds tests for legacy URL normalization and win10 preference selection.
tests/update-links/http.test.ts Adds tests for fetchText success/failure behavior.
tests/update-links/concurrency.test.ts Adds tests for result ordering and concurrency limiting.
scripts/update-links/utils/version.ts Extracts version parsing logic into a focused utility module.
scripts/update-links/utils/regex-match.ts Adds reusable regex match helpers and patch filtering.
scripts/update-links/utils/http.ts Centralizes fetch + status checking into fetchText.
scripts/update-links/utils/concurrency.ts Adds concurrency-limited async mapping helper (fixing prior worker startup issue).
scripts/update-links/archive.ts Refactors archive scraping to use fetchText and emits normalized entry.version.
scripts/update-links/releases.ts Refactors modern download page parsing; improves legacy failure diagnostics integration.
scripts/update-links/legacy.ts Refactors legacy parsing to use new utilities and adds failure description helper.
scripts/update-links/index.ts Switches to new archive entry shape and shared concurrency utility.
scripts/update-links/constants.ts Removes CUDA_ARCHIVE_URL export (now localized to archive feature).
scripts/update-links/types.ts Removes centralized types (moved/embedded where used).
scripts/update-links/regex.ts Removes centralized regex constants (moved/embedded where used).
scripts/update-links/matching.ts Removes centralized matching helpers (moved into feature/utils modules).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/update-links/utils/concurrency.ts
Comment thread tests/update-links/http.test.ts Outdated
Comment thread tests/update-links/regex-match.test.ts Outdated
@mzwing mzwing changed the title refactor(update-links): 按功能重构 refactor(update-links): devided into features instead of layers Jun 21, 2026
@mzwing mzwing requested a review from Copilot June 22, 2026 03:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@mzwing mzwing merged commit 823d177 into MZWNET:master Jun 22, 2026
21 checks passed
@mzwing mzwing changed the title refactor(update-links): devided into features instead of layers refactor(update-links): divided into features instead of layers Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants