Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/packagedcode/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,14 @@ def update_dependencies_by_purl(
if '_' in metadata:
requirement, _extra = metadata.split('_')

if ':' in requirement and '@' in requirement:
if (
':' in requirement
and '@' in requirement
and not requirement.startswith(
('git+', 'git:', 'git@', 'http://', 'https://', 'ssh://')
)
):

# dependencies with requirements like this are aliases and should be reported
aliased_package, _, constraint = requirement.rpartition('@')
_, _, aliased_package_name = aliased_package.rpartition(':')
Expand Down Expand Up @@ -1848,7 +1855,15 @@ def deps_mapper(deps, package, field_name, is_direct=True):
if not name:
continue

if ':' in requirement and '@' in requirement:
if (
':' in requirement
and '@' in requirement
and not requirement.startswith(
('git+', 'git:', 'git@', 'http://', 'https://', 'ssh://')
)
):


# dependencies with requirements like this are aliases and should be reported
aliased_package, _, requirement = requirement.rpartition('@')
_, _, aliased_package_name = aliased_package.rpartition(':')
Expand Down
16 changes: 16 additions & 0 deletions tests/packagedcode/test_npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,24 @@
from scancode_config import REGEN_TEST_FIXTURES
from scancode.cli_test_utils import run_scan_click
from scancode.cli_test_utils import check_json_scan
from packagedcode.npm import NpmPackageJsonHandler


def test_git_authenticated_dependency_keeps_declared_name():
package_json = {
"name": "example",
"version": "1.0.0",
"dependencies": {
"private-lib": "git+ssh://git@github.com:org/repo.git#v1.0.0"
}
}

package = NpmPackageJsonHandler._parse(package_json)

deps = package.dependencies
assert len(deps) == 1
assert deps[0].purl == "pkg:npm/private-lib"

class TestNpm(PackageTester):
test_data_dir = os.path.join(os.path.dirname(__file__), 'data')

Expand Down