Skip to content

Commit

Permalink
fix(pnpm): npm: aliases to self (#1846)
Browse files Browse the repository at this point in the history
Close #1843
  • Loading branch information
jbedard authored Jul 11, 2024
1 parent 9af6a39 commit 508d967
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion e2e/pnpm_lockfiles/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"tslib": "^2.6.3",
"typescript": "^5.4.5",
"meaning-of-life": "1.0.0",
"is-odd": "3.0.1",
"is-odd": "npm:is-odd@3.0.1",
"is-odd-alt-version": "npm:is-odd@^2.0.0",
"uvu": "0.5.6",
"@scoped/a": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion e2e/pnpm_lockfiles/v54/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/pnpm_lockfiles/v60/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/pnpm_lockfiles/v61/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/pnpm_lockfiles/v90/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions npm/private/pnpm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _convert_v5_importer_dependency_map(specifiers, deps):
for name, version in deps.items():
specifier = specifiers.get(name)

if specifier.startswith("npm:"):
if specifier.startswith("npm:") and not specifier.startswith("npm:{}@".format(name)):
# Keep the npm: specifier for aliased dependencies
# convert v5 style aliases ([default_registry]/aliased/version) to npm:aliased@version
alias, version = _strip_v5_v6_default_registry(version).lstrip("/").rsplit("/", 1)
Expand Down Expand Up @@ -238,7 +238,7 @@ def _convert_pnpm_v6_importer_dependency_map(deps):
specifier = attributes.get("specifier")
version = attributes.get("version")

if specifier.startswith("npm:"):
if specifier.startswith("npm:") and not specifier.startswith("npm:{}@".format(name)):
# Keep the npm: specifier for aliased dependencies
# convert v6 style aliases ([registry]/aliased@version) to npm:aliased@version
alias, version = _split_name_at_version(_strip_v5_v6_default_registry(version).lstrip("/"))
Expand Down Expand Up @@ -391,10 +391,9 @@ def _convert_pnpm_v9_importer_dependency_map(deps):
# Transition version[(patch)(peer)(data)] to a rules_js version format
version = _convert_pnpm_v6_v9_version_peer_dep(version)

if specifier.startswith("npm:"):
if specifier.startswith("npm:") and not specifier.startswith("npm:{}@".format(name)):
# Keep the npm: specifier for aliased dependencies
alias, version = version.rsplit("@", 1)
version = "npm:{}@{}".format(alias, version)
version = "npm:{}".format(version)

result[name] = version
return result
Expand Down

0 comments on commit 508d967

Please sign in to comment.