fix(deps): strip trailing slash from single-segment package paths in resolvePackageNameByPath#10366
Merged
zkochan merged 3 commits intoMay 12, 2026
Conversation
…resolvePackageNameByPath
`pathNormalizeToLinux` (via `normalize-path`) already strips trailing slashes, but the
single-segment branch returned the *original* (un-normalized) `packagePath`, leaking
inputs like `events/` through unchanged. That broke downstream matching: the missing
package was reported under `events/` in MissingPackagesDependenciesOnFs while everything
else — workspace policy lookups, package.json names from resolvePackageData, and the
model's packageDependencies — uses `events`. The trailing-slash form appears in
real-world code (e.g. webpack browser-fallback configs: `require.resolve('events/')`),
where it's used to bypass Node's builtin and force resolution to the npm package.
Returning the normalized path makes the function consistent and aligns all consumers on
the canonical package name.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a dependency-resolution edge case where resolvePackageNameByPath() returned the original (non-normalized) input for single-segment package paths, allowing trailing slashes (e.g. events/) to leak into downstream dependency/issue reporting. It also adds an e2e regression test to ensure missing packages are reported using the canonical package name (without the trailing slash).
Changes:
- Normalize single-segment package paths by returning
packagePathLinux(instead of the originalpackagePath) fromresolvePackageNameByPath. - Add an e2e regression test covering
require('events/')and asserting the missing package is recorded asevents(notevents/).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
components/legacy/utils/packages/resolve-pkg-name-by-path.ts |
Fixes single-segment path handling to consistently use the normalized (trailing-slash-stripped) form. |
e2e/harmony/missing-package-strips-trailing-slash.e2e.ts |
Adds an end-to-end regression test ensuring missing-package reporting uses canonical package names. |
…of string literal Addresses Copilot review on teambit#10366: match the existing convention used across the e2e suite (delete, deprecate, custom-env, dependencies-cmd, etc.) so the test stays in sync with the issue class if it's ever renamed.
davidfirst
approved these changes
May 12, 2026
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
pathNormalizeToLinux(vianormalize-path) already strips trailing slashes, but the single-segment branch inresolvePackageNameByPathreturned the original (un-normalized)packagePath. So inputs likeevents/leaked through unchanged.That broke downstream matching:
MissingPackagesDependenciesOnFsreported the package asevents/, while every other consumer — workspace policy lookups,resolvedPackageData.namefromresolvePackageData, and the component model'spackageDependencies— uses the canonical nameevents. The trailing-slash form appears in real-world code (most commonly webpack browser-fallback configs:require.resolve('events/')), where it's used to force resolution to the npmeventspolyfill rather than Node's builtin.Returning the normalized path fixes the leak and aligns all consumers on the canonical package name.
This is part of fixing the
bit lane importsymptom where a webpack-bundler-style component reportsconfig/webpack-fallbacks.ts -> events/as a missing package: this PR makes the missing package surface aseventsinstead ofevents/. Together with #10365 (which letsprocessMissingfall back to the component model when the model already records the dep), the issue clears cleanly on import.Test plan
e2e/harmony/missing-package-strips-trailing-slash.e2e.tsasserts theMissingPackagesDependenciesOnFsdata recordsevents, notevents/, forrequire('events/').expected [ 'events/' ] to include 'events') and passes with the fix.