From a18021b2872d81aa3bf0f930edbebf626f24bc8a Mon Sep 17 00:00:00 2001 From: Jan Staněk Date: Jul 02 2019 14:34:23 +0000 Subject: Treat only external dependency links as un-bundled When a previously un-bundled dependency becomes bundled, it is sometimes desirable to keep the actual path in node_modules as a symlink in order to keep RPM happy. In that case, the dependencies might be stored in i.e. `node_modules.bundled` directory, and the `node_modules` directory would contain symlinks to them. This change tweaks the detection of un-bundled dependencies, so that in the above case the symlinks are still treated as bundled. --- diff --git a/nodejs.req b/nodejs.req index 0a36187..7c27a8a 100755 --- a/nodejs.req +++ b/nodejs.req @@ -613,6 +613,9 @@ def rpm_format(requirement, version_spec="*"): def has_only_bundled_dependencies(module_dir_path): """Determines if the module contains only bundled dependencies. + Dependencies are considered un-bundled when they are symlinks + pointing outside the root module's tree. + Arguments: module_dir_path (str): Path to the module directory (directory with ``package.json``). @@ -629,8 +632,18 @@ def has_only_bundled_dependencies(module_dir_path): os.path.join(dependency_root_path, basename) for basename in os.listdir(dependency_root_path) ) + linked_dependency_iter = ( + os.path.realpath(path) + for path in dependency_path_iter + if os.path.islink(path) + ) + outside_dependency_iter = ( + path + for path in linked_dependency_iter + if not path.startswith(module_root_path) + ) - return not any(os.path.islink(path) for path in dependency_path_iter) + return not any(outside_dependency_iter) except OSError: # node_modules does not exist return False