Skip to content

fix: skip empty dependency names to prevent lockfile corruption#33243

Open
hijingsong wants to merge 1 commit intodenoland:mainfrom
hijingsong:fix/empty-dep-lockfile-corruption
Open

fix: skip empty dependency names to prevent lockfile corruption#33243
hijingsong wants to merge 1 commit intodenoland:mainfrom
hijingsong:fix/empty-dep-lockfile-corruption

Conversation

@hijingsong
Copy link
Copy Markdown

Problem

When package.json contains an empty-string dependency key (e.g., "": "."), Deno works on the first run but corrupts the lockfile. On the second run, deserialization fails with:

Invalid workspace section: Invalid package requirement '@.'

Fixes #32113

Root Cause

An empty dependency name passes through PackageJsonDepValue::parse("", ".") and gets serialized into the lockfile as an invalid package requirement. When the lockfile is read back, the deserializer cannot parse it.

Fix

Skip empty-string dependency names at two locations:

  1. libs/package_json/lib.rs (resolve_local_package_json_deps): Filter out empty keys when building the dependency map. This prevents the invalid entry from entering the system at the parsing level.

  2. libs/resolver/lockfile.rs (collect_deps): Filter out empty keys when collecting link package deps for the lockfile. Belt-and-suspenders defense for the lockfile path specifically.

Empty-string dependency names are not valid npm package identifiers and serve no purpose, so silently ignoring them is the correct behavior.

Testing

Manually verified with the reproduction case from #32113:

{
    "dependencies": {
        "": "."
    }
}

Before: lockfile corruption on second run. After: empty entry is silently skipped.

…rruption

When package.json has an empty string dependency key (e.g., "": "."),
the empty name propagates through to the lockfile as an invalid package
requirement. On the first run, Deno serializes it to the lockfile, but
on the second run, deserialization fails with "Invalid package requirement
'@.'".

Skip empty dependency names at both the parsing level
(resolve_local_package_json_deps) and the lockfile collection level
(collect_deps) so the invalid entry never reaches the lockfile.

Fixes denoland#32113
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

Lockfile gets corrupted on empty package.json dependency

2 participants