fix(web): replace fs.cpSync to avoid Windows crash in extract step - #574
Open
chx7776-afk wants to merge 1 commit into
Open
chx7776-afk wants to merge 1 commit into
chx7776-afk wants to merge 1 commit into
Conversation
`fs.cpSync` in `copyChapterAssets` terminates the Node process on Windows with Node 22. Running `npm run extract` (the `predev` hook of `npm run dev`) prints "Source: root chapter folders (17)" and then exits with STATUS_STACK_BUFFER_OVERRUN (exit code 0xC0000409) without any JS-level error, so the course data is never written and the dev server never starts. Replace it with a small recursive copy helper built on `fs.readdirSync` + `fs.copyFileSync`, which is what `fs.cpSync` does internally minus the native path that crashes here. Verified on Windows 11 / Node v22.20.0: - before: exit 0xC0000409, extraction aborted, no course-assets output - after: exit 0, "17 versions / 16 diffs / 51 docs", 74 asset files written
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the single
fs.cpSynccall inweb/scripts/extract-content.tswith a small recursive copy helper.Closes #573.
Why
On Windows with Node 22,
fs.cpSynckills the process at the native layer withSTATUS_STACK_BUFFER_OVERRUN(exit code0xC0000409) and no JS-level error:...then the process is gone. Because this script backs the
predevhook,npm run devnever starts either.The crash is not specific to this repo — copying a directory holding a single one-line text file is enough to trigger it, so there is no project-side workaround other than not calling
fs.cpSync.Change
fs.cpSyncis used in exactly one place,copyChapterAssets(). The newcopyDirRecursive()helper does the same thing viafs.readdirSyncwithwithFileTypes+fs.mkdirSync+fs.copyFileSync, and recurses into subdirectories.pathis already imported in this file.No behaviour change on other platforms: same files land in the same destination layout.
Verification
Windows 11, Node v22.20.0, run against a clean tree (removed
web/public/course-assets/first):3221226505(0xC0000409)0Source: root chapter folders (17)17 versions / 16 diffs / 51 docsweb/public/course-assets/Also confirmed
npm run buildproceeds past the previously blockingpredevstep.Notes
web/scripts/extract-content.ts: +21 / -1.中文说明(Chinese summary)
摘要
把
web/scripts/extract-content.ts中唯一一处fs.cpSync调用替换为一个小型递归复制函数。关联 Issue:#573。
背景
在 Windows + Node 22 下,
fs.cpSync会在原生层直接终止进程,报STATUS_STACK_BUFFER_OVERRUN(退出码0xC0000409),且没有任何 JS 层报错:然后就没了下文。由于该脚本是
predev钩子的实现,npm run dev也随之无法启动。这个崩溃与仓库本身无关 —— 即使只复制一个含单行文本文件的目录也照样触发,因此项目侧除了「不要调用
fs.cpSync」之外没有别的绕法。改动
fs.cpSync全仓库只用在一处,即copyChapterAssets()。新增的copyDirRecursive()用fs.readdirSync(带withFileTypes)+fs.mkdirSync+fs.copyFileSync实现相同效果,并递归处理子目录。path在该文件中已有引入。其他平台行为不变:同样的文件落到同样的目标目录结构下。
验证
环境 Windows 11 + Node v22.20.0,在干净的工作区上运行(先删掉
web/public/course-assets/):3221226505(0xC0000409)0Source: root chapter folders (17)17 versions / 16 diffs / 51 docsweb/public/course-assets/同时确认
npm run build能够越过此前阻塞它的predev步骤继续执行。说明
web/scripts/extract-content.ts:+21 / -1。