From ec3111235bd0d2fd232b6d1077236d4f1f240c8d Mon Sep 17 00:00:00 2001 From: Jan Staněk Date: Sep 03 2020 09:58:17 +0000 Subject: Make unbundled dependency detection more readable Since the logic in the `has_only_bundled_dependencies` function is a bit complicated (and was buried between iterator processing), I have extracted the main decision making to separate closure. This should hopefully ease groking what is going on and make future changes easier in case they are needed. --- diff --git a/nodejs.req b/nodejs.req index 129606b..a39b805 100755 --- a/nodejs.req +++ b/nodejs.req @@ -627,6 +627,11 @@ def has_only_bundled_dependencies(module_dir_path): module_root_path = os.path.abspath(module_dir_path) dependency_root_path = os.path.join(module_root_path, "node_modules") + def is_unbundled(path): + is_link = os.path.islink(path) + is_external = not path.startswith(module_root_path) + return is_link and is_external + try: dependency_path_iter = ( os.path.join(dependency_root_path, basename) @@ -635,10 +640,11 @@ def has_only_bundled_dependencies(module_dir_path): bundled_dependency_iter = ( os.path.realpath(path) for path in dependency_path_iter - if not os.path.islink(path) or path.startswith(module_root_path) + if not is_unbundled(path) ) return any(bundled_dependency_iter) + except OSError: # node_modules does not exist return False