diff --git a/network.py b/network.py index 1c6b2d8..dfb1659 100644 --- a/network.py +++ b/network.py @@ -8,6 +8,8 @@ interface: get(package_name) ''' +# index 0 is the package_name; index 1 is the version +default_url = 'https://registry.npmjs.org/{0}/-/{0}-{1}.tgz' def get(package_name): @@ -17,4 +19,12 @@ def get(package_name): print(Fore.RED + 'package `{0}ยด not found.'.format(package_name)) raise Exception() else: - return response.json() \ No newline at end of file + return response.json() + +def exists(package_name, resolved_version): + url_package = default_url.format(package_name, resolved_version) + response = requests.head(url_package) + if response.status_code == 404: + return False + else: + return True \ No newline at end of file diff --git a/worker.py b/worker.py index d636dc0..38dcd27 100644 --- a/worker.py +++ b/worker.py @@ -39,15 +39,17 @@ def get_times(time, date): # get the resolved version and verify if exists -def get_version(versions, svr): +def get_version(dependency, versions, svr): + if not len(versions): + return None + resolved_version = svr.best_satisfies(versions) # verify if resolved_version exists - # if ntw.exists(resolved_version): - # return resolved_versions - # else: - # versions.remove(resolved_version) - # return get_version(versions, svr) - return resolved_version + if ntw.exists(dependency, resolved_version): + return resolved_version + else: + versions.remove(str(resolved_version)) + return get_version(dependency, versions, svr) # get only the versions that is major @@ -60,7 +62,7 @@ def resolve_version(dependency, version, date): nvrp = NodeVersionRangeParser() svr = nvrp.parse(version) # get the best satisfies range - new_version = get_version(versions, svr) + new_version = get_version(dependency, versions, svr) # if one version satisfies if new_version: