Skip to content
This repository has been archived by the owner on Apr 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #173 from apiaryio/opichals/add-support-for-bb-dep…
Browse files Browse the repository at this point in the history
…-check-dot

feat(dep): add support for `bb dep check .`
  • Loading branch information
honzajavorek committed Aug 16, 2018
2 parents 3d5156f + 1f2d1e7 commit 8057d11
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions blackbelt/commands/dep.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def cli():

def validate_dep(ctx, param, dep):
try:
if dep == '.': # check the current project_dir
return (dep, '*')
dep_name, dep_version = parse_dep(dep)
except Exception:
raise click.BadParameter('The dependency format should be e.g. react@16.2')
Expand Down
27 changes: 19 additions & 8 deletions blackbelt/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,25 @@ def check(dep, list_path, licenses_path, dev=False, debug=False):
click.echo('Analyzing the package...')
dep_name, dep_version = dep

with tempfile.TemporaryDirectory() as tmp_dir:
try:
install(dep_name, dep_version, tmp_dir, dev=dev)
except Exception as e:
if debug:
raise
raise click.BadParameter('The npm package could not be installed')
licenses = license_checker(tmp_dir)
if dep_name == '.': # check the `pwd` project deps
click.echo('The dependency is a local directory, using whatever is currently in node_modules')
project_dir = '.'
if not os.path.isdir(os.path.join(project_dir, 'node_modules')):
raise click.BadParameter('There are no node_modules to analyze in the project directory')
package_json = os.path.join(project_dir, 'package.json')
with open(package_json) as f:
package_data = json.load(f)
dep_name = package_data['name'];
licenses = license_checker(project_dir)
else:
with tempfile.TemporaryDirectory() as tmp_dir:
try:
install(dep_name, dep_version, tmp_dir, dev=dev)
except Exception as e:
if debug:
raise
raise click.BadParameter('The npm package could not be installed')
licenses = license_checker(tmp_dir)

pre_approval_verdict = get_pre_approval_verdict(licenses)
details, fourth_party_licenses = separate_top_level_details(licenses, dep_name)
Expand Down

0 comments on commit 8057d11

Please sign in to comment.