Skip to content
Snippets Groups Projects

npm package.json parsing and license requesting

Merged Daniel Eggert requested to merge npm-license-check into dev
6 unresolved threads

I wrote some lines to parse a package.json and retrieve the license info from the NPM registry.

Unfortunately npm project files are not yet passed to the script, guess I missed some config property somewhere, @mdolling hope you can point me in the right direction.

Merge request reports

Checking pipeline status.

Approval is optional

Merged by Maximilian DollingMaximilian Dolling 4 years ago (Apr 15, 2021 3:14pm UTC)

Merge details

  • Changes merged into dev with cfb07dbd (commits were squashed).
  • Deleted the source branch.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
58 60 self.parent.dependencies_per_language["Python"] = deps
59 61 self.parent.errors["Python"] = errors
62 elif "Node" in self.parent.files_per_language:
63 deps, errors = self._get_node_libs()
64 self.parent.dependencies_per_language["Node"] = deps
65 self.parent.errors["Node"] = errors
66
67 def _get_node_libs(self) -> (list, list):
68 """
69 Parses package.json to get all imports and their versions.
70
71 :return: a list of dictionaries; dictionaries {key, value} represents {import name, import version}
72 """
73 deps = {}
74 errors = {}
75 std_lib_list = stdlib_list()
  • 75 std_lib_list = stdlib_list()
    76
    77 for file_path in self.parent.files_per_language["Node"]:
    78 # parse package.json
    79 package: Optional[dict] = None
    80
    81 if file_path.endswith('package.json'):
    82 with open(file_path) as file:
    83 package = json.load(file)
    84
    85 # invalid package dict
    86 if package is None:
    87 errors['package.json'] = {'unable to load package.json'}
    88 continue
    89
    90 # missing dependencies key
  • 87 errors['package.json'] = {'unable to load package.json'}
    88 continue
    89
    90 # missing dependencies key
    91 if 'dependencies' not in package:
    92 errors['package.json'] = {"missing 'dependencies' entry"}
    93 continue
    94
    95 # check dependency version for local file and url references
    96 for dep, value in package['dependencies'].items():
    97 version: str = value.trim()
    98
    99 if version.startswith('file') or 'https://' in version or 'http://' in version:
    100 # local file or url dependency
    101 errors[dep] = {'url/path not supported'}
    102 # elif version.startswith('^') or version.startswith('~'):
  • 57 59 deps, errors = self._get_python_libs()
    58 60 self.parent.dependencies_per_language["Python"] = deps
    59 61 self.parent.errors["Python"] = errors
    62 elif "Node" in self.parent.files_per_language:
  • @eggi you can also bumb the version to 0.7.0 =)

  • Maximilian Dolling changed target branch from master to dev

    changed target branch from master to dev

  • added 14 commits

    Compare with previous version

  • added 15 commits

    Compare with previous version

  • added 2 commits

    • c7fbc545 - fixed node handling in language check; bumped version; bumped required python version
    • f0075e43 - Merge branch 'npm-license-check-addition' into 'npm-license-check'

    Compare with previous version

  • added 2 commits

    • 9be98340 - separated handlers into subclasses for easier extendability
    • 8b28dafc - Merge branch 'separate-language-handlers' into 'npm-license-check'

    Compare with previous version

  • added 1 commit

    • b96382ff - adopted the docs to new parser

    Compare with previous version

  • mentioned in commit cfb07dbd

  • Please register or sign in to reply
    Loading