-
-
Notifications
You must be signed in to change notification settings - Fork 120
Match v6 lockfile behaviour in v9 around injected deps #1924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Silic0nS0ldier
wants to merge
3
commits into
aspect-build:main
Choose a base branch
from
Silic0nS0ldier:injected-deps-v9-match-v6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,11 +28,33 @@ def _new_import_info(dependencies, dev_dependencies, optional_dependencies): | |
"optional_dependencies": optional_dependencies, | ||
} | ||
|
||
# Metadata about a package. | ||
# | ||
# Metadata may come from different locations depending on the lockfile, this struct should | ||
# have data normalized across lockfiles. | ||
def _new_package_info(id, name, dependencies, optional_dependencies, dev, has_bin, optional, requires_build, version, friendly_version, resolution): | ||
""" | ||
Metadata about a package. | ||
|
||
Metadata may come from different locations depending on the lockfile, this struct should | ||
have data normalized across lockfiles. | ||
|
||
Args: | ||
id: The package id, if present. | ||
TODO Remove. Used for to resolve path of local packages, however `resolution` is a better source of truth. | ||
name: The package name. | ||
dependencies: A map of package dependencies. | ||
optional_dependencies: A map of optional package dependencies. | ||
dev: True if the package is a dev dependency, None otherwise. | ||
has_bin: True if the package has a bin field. | ||
optional: True if the package is an optional dependency. | ||
Determines if package should be omitted `no_optional = True` specified. | ||
requires_build: True if the package requires a build. | ||
NOTE: With pnpm v9, this cannot be known ahead of time. | ||
version: The resolved package version. | ||
e.g. `file:packages/a`, `1.2.3`, `1.2.3_at_scope_peer_2.0.2`. | ||
friendly_version: The package version, normalized for users. Used to target patches, etc. | ||
e.g. `file:packages/a`, `1.2.3`. | ||
resolution: The package resolution. | ||
e.g. { integrity: "..." } | ||
e.g. { type: "directory", directory: "packages/a" } | ||
""" | ||
return { | ||
"id": id, | ||
"name": name, | ||
|
@@ -218,20 +240,21 @@ def _convert_pnpm_v6_v9_version_peer_dep(version): | |
# with rules_js. | ||
# | ||
# Examples: | ||
# 1.2.3 | ||
# 1.2.3(@scope/peer@2.0.2)(@scope/peer@4.5.6) | ||
# 4.5.6(patch_hash=o3deharooos255qt5xdujc3cuq) | ||
# 1.2.3 -> 1.2.3 | ||
# 1.2.3(@scope/peer@2.0.2) -> 1.2.3_at_scope_peer_2.0.2 | ||
# 1.2.3(@scope/peer@2.0.2)(@scope/peer@4.5.6) -> 1.2.3_2001974805 | ||
# 4.5.6(patch_hash=o3deharooos255qt5xdujc3cuq) -> 4.5.6_o3deharooos255qt5xdujc3cuq | ||
if version[-1] == ")": | ||
# Drop the patch_hash= not present in v5 so (patch_hash=123) -> (123) like v5 | ||
version = version.replace("(patch_hash=", "(") | ||
|
||
# There is a peer dep if the string ends with ")" | ||
# There is a peer dep (or patch) if the string ends with ")" | ||
peer_dep_index = version.find("(") | ||
peer_dep = version[peer_dep_index:] | ||
if len(peer_dep) > 32: | ||
# Prevent long paths. The pnpm lockfile v6 no longer hashes long sequences of | ||
# peer deps so we must hash here to prevent extremely long file paths that lead to | ||
# "File name too long) build failures. | ||
# "File name too long" build failures. | ||
peer_dep = utils.hash(peer_dep) | ||
else: | ||
peer_dep = peer_dep.replace("(@", "(_at_").replace(")(", "_").replace("@", "_").replace("/", "_") | ||
|
@@ -485,8 +508,20 @@ def _convert_v9_packages(packages, snapshots): | |
# package_data can have the resolved "version" for things like https:// deps | ||
friendly_version = package_data["version"] if "version" in package_data else static_key[version_index + 1:] | ||
|
||
package_id = package_snapshot.get("id", None) | ||
|
||
# match v6 lockfile behaviour with id | ||
if package_id != None and "file:" in package_id: | ||
# Remove package name from id | ||
package_id = package_id[len(name) + 1:] | ||
|
||
# ensure local packages always have an id, so that peer dependencies don't cause issues | ||
if package_id == None and "file:" in package_key: | ||
resolution = package_data.get("resolution") | ||
package_id = "file:" + resolution["directory"] | ||
|
||
package_info = _new_package_info( | ||
id = package_data.get("id", None), # TODO: does v9 have "id"? | ||
id = package_id, | ||
name = name, | ||
version = version, | ||
friendly_version = friendly_version, | ||
|
@@ -499,6 +534,11 @@ def _convert_v9_packages(packages, snapshots): | |
resolution = package_data.get("resolution"), | ||
) | ||
|
||
# Match v6 lockfile behaviour with local dependency keys | ||
if "file:" in package_key: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This as well. I'd like to see this change along with a test demonstrating the side-effects... |
||
# Remove package name from key | ||
package_key = package_key[len(name) + 1:] | ||
|
||
if package_key in result: | ||
msg = "ERROR: duplicate package: {}\n\t{}\n\t{}".format(package_key, result[package_key], package_info) | ||
fail(msg) | ||
|
@@ -540,10 +580,8 @@ def _parse_lockfile(parsed, err): | |
|
||
# Lockfile version may be a float such as 5.4 or a string such as '6.0' | ||
lockfile_version = str(parsed["lockfileVersion"]) | ||
lockfile_version = lockfile_version.lstrip("'") | ||
lockfile_version = lockfile_version.rstrip("'") | ||
lockfile_version = lockfile_version.lstrip("\"") | ||
lockfile_version = lockfile_version.rstrip("\"") | ||
lockfile_version = lockfile_version.strip("'") | ||
lockfile_version = lockfile_version.strip("\"") | ||
lockfile_version = float(lockfile_version) | ||
_assert_lockfile_version(lockfile_version) | ||
|
||
|
@@ -603,4 +641,5 @@ pnpm = struct( | |
# Exported only to be tested | ||
pnpm_test = struct( | ||
strip_v5_peer_dep_or_patched_version = _strip_v5_peer_dep_or_patched_version, | ||
convert_pnpm_v6_v9_version_peer_dep = _convert_pnpm_v6_v9_version_peer_dep, | ||
) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any tests that show the side-effects of this change? Can we see that in a diff?