Skip to content

fix: resolve component-id from package-name when full metadata lacks componentId - #10558

Merged
davidfirst merged 4 commits into
masterfrom
fix-resolve-component-id-from-pkg-name
Aug 3, 2026
Merged

davidfirst merged 4 commits into
masterfrom
fix-resolve-component-id-from-pkg-name

Conversation

@davidfirst

Copy link
Copy Markdown
Member

Proposed Changes

bit import <package-name> fails with: "the package.json of version X has no componentId field".

The pnpm v12 engine filters the full package document. The filter keeps only standard fields. It removes the componentId field. The engine returns the abbreviated document without a filter. Registries such as bit.cloud include componentId in the abbreviated document.

This fix adds a fallback to fetchFullPackageManifest. When the full manifest has no componentId, it gets the abbreviated manifest. It then merges the two manifests. The root cause stays in the pnpm engine and must get a fix there.

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Fallback version drift ✓ Resolved 🐞 Bug ☼ Reliability
Description
fetchFullPackageManifest() re-resolves the abbreviated manifest using the original (possibly
versionless/tag/range) package spec, so it may resolve a different version than the already-resolved
full manifest and then skip the merge. In that case, the function returns the filtered full manifest
without componentId, making component-id resolution intermittently fail even though the abbreviated
manifest might contain it for the originally resolved version.
Code

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[R1680-1682]

+        const { manifest: abbreviated } = await pm.resolveRemoteVersion(packageName, resolveOpts);
+        if (abbreviated && 'componentId' in abbreviated && abbreviated.version === manifest.version) {
+          // the componentId (and any other non-standard field) of the abbreviated manifest survives the merge,
Evidence
The fallback currently re-resolves using the original packageName spec, and the pnpm resolver in
this repo resolves versionless specs as "latest" (bareSpecifier becomes undefined), so the
resolved version can change between the two calls; the merge is explicitly skipped when versions
differ.

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1667-1692]
scopes/dependencies/pnpm/lynx.ts[710-764]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`fetchFullPackageManifest()` does a second `resolveRemoteVersion(packageName, ...)` call for the abbreviated manifest. If `packageName` is not an exact version (e.g. `@scope/pkg`, dist-tag, or a range), the second call may resolve a different version than the first call; when that happens, the code skips merging and returns the full manifest without `componentId`.
## Issue Context
`resolveRemoteVersion()` treats missing version as "latest" by passing `bareSpecifier: undefined`, so two sequential resolves of the same versionless spec are not guaranteed to be consistent if registry state changes between calls.
## Fix Focus Areas
- scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1674-1685]
### Suggested fix
Use the *already resolved* version from the full manifest to build an exact spec for the fallback lookup, e.g.:
- `const exactSpec = `${manifest.name}@${manifest.version}`;`
- `await pm.resolveRemoteVersion(exactSpec, resolveOpts)`
Then you can either remove the `abbreviated.version === manifest.version` check (it should always match) or keep it as a defensive assertion.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Fallback resolve error leaks ✓ Resolved 🐞 Bug ☼ Reliability
Description
fetchFullPackageManifest() now performs an additional resolveRemoteVersion() call to fetch the
abbreviated manifest, but any error from that fallback call will bubble up. This reduces resilience
because a transient failure in the fallback can abort component-id resolution even though the full
manifest was already fetched successfully.
Code

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1679]

+      const { manifest: abbreviated } = await pm.resolveRemoteVersion(packageName, resolveOpts);
Evidence
The PR adds an unguarded fallback resolveRemoteVersion() call when componentId is missing;
resolveRemoteVersion() can throw; and downstream code expects to receive a manifest and then
throws a specific missing-componentId error. With the new code, a fallback error can escape
earlier and change behavior.

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1667-1686]
scopes/dependencies/pnpm/lynx.ts[741-768]
scopes/workspace/workspace/workspace.ts[2207-2222]
components/modules/component-package-name/package-name-to-component-id.ts[34-57]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`fetchFullPackageManifest()` performs a second `pm.resolveRemoteVersion()` call to fetch the abbreviated manifest when `componentId` is missing in the full manifest. If that second call throws (network/resolver/cache error), the exception propagates and prevents downstream callers from applying their existing “missing componentId” handling.
### Issue Context
Callers such as `Workspace.resolveComponentIdFromRegistryManifest()` fetch the manifest and then explicitly throw a deterministic error when `componentId` is missing. The new unguarded fallback introduces a new failure mode that can override that behavior.
### Fix Focus Areas
- scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1669-1685]
### Suggested fix
- Wrap the abbreviated-manifest lookup in `try/catch`.
- On fallback failure, return the original `manifest` (full metadata) unchanged so callers can continue with their existing missing-`componentId` logic.
- (Optional) add a `logger.debug()` line when the fallback is attempted/used to aid debugging.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Fallback resolve error leaks ✓ Resolved 🐞 Bug ☼ Reliability
Description
fetchFullPackageManifest() now performs an additional resolveRemoteVersion() call to fetch the
abbreviated manifest, but any error from that fallback call will bubble up. This reduces resilience
because a transient failure in the fallback can abort component-id resolution even though the full
manifest was already fetched successfully.
Code

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1679]

+      const { manifest: abbreviated } = await pm.resolveRemoteVersion(packageName, resolveOpts);
Evidence
The PR adds an unguarded fallback resolveRemoteVersion() call when componentId is missing;
resolveRemoteVersion() can throw; and downstream code expects to receive a manifest and then
throws a specific missing-componentId error. With the new code, a fallback error can escape
earlier and change behavior.

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1667-1686]
scopes/dependencies/pnpm/lynx.ts[741-768]
scopes/workspace/workspace/workspace.ts[2207-2222]
components/modules/component-package-name/package-name-to-component-id.ts[34-57]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`fetchFullPackageManifest()` performs a second `pm.resolveRemoteVersion()` call to fetch the abbreviated manifest when `componentId` is missing in the full manifest. If that second call throws (network/resolver/cache error), the exception propagates and prevents downstream callers from applying their existing “missing componentId” handling.
### Issue Context
Callers such as `Workspace.resolveComponentIdFromRegistryManifest()` fetch the manifest and then explicitly throw a deterministic error when `componentId` is missing. The new unguarded fallback introduces a new failure mode that can override that behavior.
### Fix Focus Areas
- scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1669-1685]
### Suggested fix
- Wrap the abbreviated-manifest lookup in `try/catch`.
- On fallback failure, return the original `manifest` (full metadata) unchanged so callers can continue with their existing missing-`componentId` logic.
- (Optional) add a `logger.debug()` line when the fallback is attempted/used to aid debugging.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

4. Extra resolve on misses 🐞 Bug ➹ Performance
Description
The new fallback is triggered solely by the absence of componentId in the full manifest, which
includes the normal case where a package is simply not a Bit component. This adds an extra
resolution attempt (and potential remote work) on the negative path before callers report “probably
not a component”.
Code

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1675]

+    if (manifest && !('componentId' in manifest)) {
Evidence
The fallback condition is based only on missing componentId, and downstream callers already treat
missing componentId as a normal “not a component” case; therefore the fallback will also run on
that negative path and incur an extra resolve before the caller throws.

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1674-1684]
scopes/workspace/workspace/workspace.ts[2216-2219]
components/modules/component-package-name/package-name-to-component-id.ts[44-48]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The fallback always performs a second `resolveRemoteVersion()` call when `componentId` is missing in the full manifest. For non-component packages (which callers already treat as a valid/expected negative case), this adds avoidable extra resolution work.
### Issue Context
Callers explicitly interpret missing `componentId` as “probably not a component”. The fallback is necessary to work around pnpm’s filtered full-metadata manifest for component packages, but it also runs for non-component packages.
### Fix Focus Areas
- scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1669-1685]
### Suggested fix
- Gate the fallback to the relevant package-manager(s) (e.g. `if (pm.name === 'pnpm')`) and/or add a small in-memory cache keyed by `packageName@version` to avoid repeating the extra resolve when the same lookup happens multiple times in a process.
- Keep existing behavior for component packages by still merging when the abbreviated manifest has `componentId` for the same version.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Extra resolve on misses 🐞 Bug ➹ Performance
Description
The new fallback is triggered solely by the absence of componentId in the full manifest, which
includes the normal case where a package is simply not a Bit component. This adds an extra
resolution attempt (and potential remote work) on the negative path before callers report “probably
not a component”.
Code

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1675]

+    if (manifest && !('componentId' in manifest)) {
Evidence
The fallback condition is based only on missing componentId, and downstream callers already treat
missing componentId as a normal “not a component” case; therefore the fallback will also run on
that negative path and incur an extra resolve before the caller throws.

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1674-1684]
scopes/workspace/workspace/workspace.ts[2216-2219]
components/modules/component-package-name/package-name-to-component-id.ts[44-48]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The fallback always performs a second `resolveRemoteVersion()` call when `componentId` is missing in the full manifest. For non-component packages (which callers already treat as a valid/expected negative case), this adds avoidable extra resolution work.
### Issue Context
Callers explicitly interpret missing `componentId` as “probably not a component”. The fallback is necessary to work around pnpm’s filtered full-metadata manifest for component packages, but it also runs for non-component packages.
### Fix Focus Areas
- scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1669-1685]
### Suggested fix
- Gate the fallback to the relevant package-manager(s) (e.g. `if (pm.name === 'pnpm')`) and/or add a small in-memory cache keyed by `packageName@version` to avoid repeating the extra resolve when the same lookup happens multiple times in a process.
- Keep existing behavior for component packages by still merging when the abbreviated manifest has `componentId` for the same version.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Fix componentId resolution by merging abbreviated manifest when full metadata is filtered

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Add a fallback when full package metadata is missing non-standard fields like componentId
• Fetch and merge the abbreviated manifest to restore componentId for registries such as bit.cloud
• Guard the merge by matching manifest versions to avoid mixing mismatched metadata
Diagram

graph TD
  A["DependencyResolver"] --> B["fetchFullPackageManifest()"] --> C["PM.resolveRemoteVersion(fullMetadata=true)"] --> D{"componentId missing?"}
  D -->|"No"| E["Return full manifest"]
  D -->|"Yes"| F["PM.resolveRemoteVersion(abbrev)"] --> G{"abbrev has componentId & same version?"}
  G -->|"Yes"| H["Merge abbrev + full"]
  G -->|"No"| E
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Fix filtering in pnpm v12 engine (@pnpm/napi)
  • ➕ Addresses root cause so all consumers get correct full metadata
  • ➕ Avoids extra network call for fallback
  • ➕ Prevents similar issues for other non-standard fields
  • ➖ Requires upstream coordination/release; not immediately available
  • ➖ Still leaves current users broken until pnpm update is adopted
2. Always fetch abbreviated manifest (avoid fullMetadata)
  • ➕ Simpler logic; avoids pnpm full-metadata filtering behavior entirely
  • ➕ Single request in the common path
  • ➖ Loses full manifest fields that are only present in the full document
  • ➖ Regresses behavior for consumers relying on fullMetadata-only fields
3. Direct registry fetch for componentId (custom endpoint/HTTP)
  • ➕ Independent of pnpm metadata shaping/caching
  • ➕ Can be tailored to registry-specific behavior
  • ➖ Adds custom networking/auth/caching logic duplicating package manager responsibilities
  • ➖ Increases maintenance and compatibility risk across registries

Recommendation: Keep this PR’s approach: it provides an immediate, low-risk workaround while preserving the benefits of full metadata. The version equality guard helps prevent accidental merges across different resolutions. Still pursue an upstream pnpm fix as the long-term solution to remove the need for the fallback.

Files changed (1) +14 / -3

Bug fix (1) +14 / -3
dependency-resolver.main.runtime.tsFallback to abbreviated manifest when full metadata lacks componentId +14/-3

Fallback to abbreviated manifest when full metadata lacks componentId

• Refactors resolve options into a shared object, then adds a fallback path when the full manifest is missing componentId. In that case it fetches the abbreviated manifest and merges it into the full manifest when versions match, preserving non-standard fields stripped by pnpm v12 full-metadata filtering.

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Fallback resolve error leaks 🐞 Bug ☼ Reliability
Description
fetchFullPackageManifest() now performs an additional resolveRemoteVersion() call to fetch the
abbreviated manifest, but any error from that fallback call will bubble up. This reduces resilience
because a transient failure in the fallback can abort component-id resolution even though the full
manifest was already fetched successfully.
Code

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1679]

+      const { manifest: abbreviated } = await pm.resolveRemoteVersion(packageName, resolveOpts);
Evidence
The PR adds an unguarded fallback resolveRemoteVersion() call when componentId is missing;
resolveRemoteVersion() can throw; and downstream code expects to receive a manifest and then
throws a specific missing-componentId error. With the new code, a fallback error can escape
earlier and change behavior.

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1667-1686]
scopes/dependencies/pnpm/lynx.ts[741-768]
scopes/workspace/workspace/workspace.ts[2207-2222]
components/modules/component-package-name/package-name-to-component-id.ts[34-57]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`fetchFullPackageManifest()` performs a second `pm.resolveRemoteVersion()` call to fetch the abbreviated manifest when `componentId` is missing in the full manifest. If that second call throws (network/resolver/cache error), the exception propagates and prevents downstream callers from applying their existing “missing componentId” handling.

### Issue Context
Callers such as `Workspace.resolveComponentIdFromRegistryManifest()` fetch the manifest and then explicitly throw a deterministic error when `componentId` is missing. The new unguarded fallback introduces a new failure mode that can override that behavior.

### Fix Focus Areas
- scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1669-1685]

### Suggested fix
- Wrap the abbreviated-manifest lookup in `try/catch`.
- On fallback failure, return the original `manifest` (full metadata) unchanged so callers can continue with their existing missing-`componentId` logic.
- (Optional) add a `logger.debug()` line when the fallback is attempted/used to aid debugging.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

2. Extra resolve on misses 🐞 Bug ➹ Performance
Description
The new fallback is triggered solely by the absence of componentId in the full manifest, which
includes the normal case where a package is simply not a Bit component. This adds an extra
resolution attempt (and potential remote work) on the negative path before callers report “probably
not a component”.
Code

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1675]

+    if (manifest && !('componentId' in manifest)) {
Evidence
The fallback condition is based only on missing componentId, and downstream callers already treat
missing componentId as a normal “not a component” case; therefore the fallback will also run on
that negative path and incur an extra resolve before the caller throws.

scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1674-1684]
scopes/workspace/workspace/workspace.ts[2216-2219]
components/modules/component-package-name/package-name-to-component-id.ts[44-48]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The fallback always performs a second `resolveRemoteVersion()` call when `componentId` is missing in the full manifest. For non-component packages (which callers already treat as a valid/expected negative case), this adds avoidable extra resolution work.

### Issue Context
Callers explicitly interpret missing `componentId` as “probably not a component”. The fallback is necessary to work around pnpm’s filtered full-metadata manifest for component packages, but it also runs for non-component packages.

### Fix Focus Areas
- scopes/dependencies/dependency-resolver/dependency-resolver.main.runtime.ts[1669-1685]

### Suggested fix
- Gate the fallback to the relevant package-manager(s) (e.g. `if (pm.name === 'pnpm')`) and/or add a small in-memory cache keyed by `packageName@version` to avoid repeating the extra resolve when the same lookup happens multiple times in a process.
- Keep existing behavior for component packages by still merging when the abbreviated manifest has `componentId` for the same version.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 04ed6ee

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit eb791cd

@davidfirst
davidfirst merged commit e191a3e into master Aug 3, 2026
13 checks passed
@davidfirst
davidfirst deleted the fix-resolve-component-id-from-pkg-name branch August 3, 2026 18:42
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.

2 participants