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.
Pull Request
📋 变更概述
fix: 使用流式处理优化 npm registry 响应,避免 1102 错误,并支持 @scope/package 名称
变更类型
🔍 详细说明
变更内容
response.text()替换改为 流式替换,避免大 JSON(如prisma包)导致 Worker CPU 超时 (1102)。@scope/package格式的 npm 包名。实现方法
TransformStream+TextDecoderStream+TextEncoderStream组合,实现边读边替换。tail缓冲,解决跨 chunk 边界匹配不完整问题。([^/]+)改为(@?[^/]+),确保带@scope的包路径也能正确重写。影响范围
🧪 测试
验证步骤
curl请求 metadata:curl -s https://<workers>.dev/npm/react | jq '.versions["18.2.0"].dist.tarball'👉 tarball 链接应替换为镜像域名。
curl -I请求 tarball:curl -I https://<workers>.dev/npm/react/-/react-18.2.0.tgz👉 应返回 200 OK。
npm install react --registry=https://<workers>.dev/npm👉 能正常安装。
npm install prisma --registry=https://<workers>.dev/npm👉 大包测试通过,无 1102 错误。
测试结果
📊 性能影响
prisma) 容易触发 Cloudflare Worker 1102 CPU 超时。🔒 安全考虑