yarn.lock v1 with a scoped alias of an unscoped package yields no packages and no error

未关闭 适合新手
#5,466 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@Shubham-dev-stack 已经在做这个了。

开始于 2026年11月12日。

  • #5470 来自 @Shubham-dev-stack —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

阅读 src/packagedcode/npm.py 中 YarnLockV1Handler.parse 里统计 @ 字符的断言附近部分。使用提供的、无 scope 包的有 scope 别名重现故障,然后检查附近的 Yarn v1 解析测试,以确定应在哪里添加覆盖。完成标准是 lockfile 能够提供包和依赖数据,且没有解析错误。

由索引模型根据 Issue 内容生成。

描述

Description

In a Yarn v1 yarn.lock, an alias whose own name is scoped and whose target is not scoped has three @:

"@jest/react-is-18@npm:react-is@^18.3.1":
  version "18.3.1"
  resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#..."

YarnLockV1Handler.parse asserts that a requirement starting with @ has two @ (a scoped package) or four (a scoped alias of a scoped package):

if req.startswith('@'):
    # 2 = package, 4 = alias
    assert req.count('@') in [2, 4]

With three, the parsing fails with an AssertionError at src/packagedcode/npm.py line 1063 and the whole lockfile is lost. Through the CLI the scan completes with no package data, no dependencies and no scan error for the file.

In a sample of 6 Yarn v1 lockfiles from well-known projects, 2 fail this way (webpack/webpack and GoogleChrome/lighthouse), both on @jest/react-is-18@npm:react-is@^18.3.1 and @jest/react-is-19@npm:react-is@^19.2.5.

How To Reproduce
  1. Download yarn.lock from https://github.com/webpack/webpack at commit 71338e24bc.
  2. Run scancode --package --json-pp out.json yarn.lock
  3. In out.json, package_data is empty for the file, dependencies is empty and scan_errors is empty.

Calling packagedcode.npm.YarnLockV1Handler.parse() on the file directly shows the AssertionError.

System configuration
  • macOS (Apple Silicon)
  • scancode-toolkit 32.5.0; the same code is on develop at e423b48a1
  • installed with pip, Python 3.12
主要语言
Python
星标
2.7k
派生
871
平均合并
1 天 10 小时
30 天内合并 PR
3

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

aboutcode-org/scancode-toolkit 的其他 Issue

查看 aboutcode-org/scancode-toolkit 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。