Skip to content

Commit

Permalink
added support for package-lock.json Signed-off-by:VarshaUN <varshaun5…
Browse files Browse the repository at this point in the history
…8@gmail.com>
  • Loading branch information
VarshaUN committed Nov 16, 2024
1 parent 15b76ea commit 381909f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/packagedcode/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,17 @@ def _parse(cls, json_data, package_only=False):
('dist', dist_mapper),
]

hidden_lockfile = json_data.get('hiddenLockfile', False)
dependencies = json_data.get('dependencies', {})
for dep_name, dep_data in dependencies.items():
if 'version' not in dep_data:
if dep_data.get('bundled'): dep_data['type'] = 'bundled'
if 'registry' in dep_data: dep_data['type'] = 'registry'
if 'git' in dep_data: dep_data['type'] = 'git'
if 'http' in dep_data: dep_data['type'] = 'http'
if 'tarball' in dep_data: dep_data['type'] = 'tarball'
if 'link' in dep_data: dep_data['type'] = 'link'

extra_data = {}
extra_data_fields = ['workspaces', 'engines', 'packageManager']
for extra_data_field in extra_data_fields:
Expand Down Expand Up @@ -599,7 +610,7 @@ def _parse(cls, json_data, package_only=False):
logger_debug(f'NpmPackageJsonHandler: parse: package: {package.to_dict()}')

return package

@classmethod
def parse(cls, location, package_only=False):
with io.open(location, encoding='utf-8') as loc:
Expand Down
13 changes: 13 additions & 0 deletions tests/packagedcode/test_npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,19 @@ def test_npm_yarn_lock_v1_parse_alias(self):
packages = npm.YarnLockV1Handler.parse(test_file)
self.check_packages_data(packages, expected_loc, regen=REGEN_TEST_FIXTURES)

def test_parse_hidden_lockfile(self):
test_file = self.get_test_loc('npm/package-lock-latest/package-lock.json')
expected_loc = self.get_test_loc('npm/package-lock-latest/package-lock.json-expected')
packages = npm.NpmPackageLockJsonHandler.parse(test_file)
self.check_packages_data(packages, expected_loc, regen=REGEN_TEST_FIXTURES)

def test_parse_non_versions(self):
test_file = self.get_test_loc('npm/package-lock-latest/package-lock.json')
expected_loc = self.get_test_loc('npm/package-lock-latest/package-lock.json-expected')
packages = npm.NpmPackageLockJsonHandler.parse(test_file)
self.check_packages_data(packages, expected_loc, regen=REGEN_TEST_FIXTURES)


def test_is_datafile_pnpm_shrinkwrap_yaml(self):
test_file = self.get_test_loc('npm/pnpm/shrinkwrap/v3/vuepack/shrinkwrap.yaml')
assert npm.PnpmShrinkwrapYamlHandler.is_datafile(test_file)
Expand Down

0 comments on commit 381909f

Please # to comment.