Skip to content

fix(deps): strip trailing slash from single-segment package paths in resolvePackageNameByPath#10366

Merged
zkochan merged 3 commits into
teambit:masterfrom
zkochan:fix-resolve-pkg-name-trailing-slash
May 12, 2026
Merged

fix(deps): strip trailing slash from single-segment package paths in resolvePackageNameByPath#10366
zkochan merged 3 commits into
teambit:masterfrom
zkochan:fix-resolve-pkg-name-trailing-slash

Conversation

@zkochan
Copy link
Copy Markdown
Member

@zkochan zkochan commented May 12, 2026

Summary

pathNormalizeToLinux (via normalize-path) already strips trailing slashes, but the single-segment branch in resolvePackageNameByPath returned the original (un-normalized) packagePath. So inputs like events/ leaked through unchanged.

That broke downstream matching: MissingPackagesDependenciesOnFs reported the package as events/, while every other consumer — workspace policy lookups, resolvedPackageData.name from resolvePackageData, and the component model's packageDependencies — uses the canonical name events. 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 npm events polyfill 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 import symptom where a webpack-bundler-style component reports config/webpack-fallbacks.ts -> events/ as a missing package: this PR makes the missing package surface as events instead of events/. Together with #10365 (which lets processMissing fall back to the component model when the model already records the dep), the issue clears cleanly on import.

Test plan

  • New e2e test e2e/harmony/missing-package-strips-trailing-slash.e2e.ts asserts the MissingPackagesDependenciesOnFs data records events, not events/, for require('events/').
  • Verified the test fails on the prior code (expected [ 'events/' ] to include 'events') and passes with the fix.

…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.
Copilot AI review requested due to automatic review settings May 12, 2026 12:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 original packagePath) from resolvePackageNameByPath.
  • Add an e2e regression test covering require('events/') and asserting the missing package is recorded as events (not events/).

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.

Comment thread e2e/harmony/missing-package-strips-trailing-slash.e2e.ts
zkochan added 2 commits May 12, 2026 14:33
…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.
@zkochan zkochan merged commit 7a9a133 into teambit:master May 12, 2026
12 checks passed
@zkochan zkochan deleted the fix-resolve-pkg-name-trailing-slash branch May 12, 2026 14:18
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.

3 participants