From af87d90a8d9a3c6b77529947b2f451aa935d9def Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Fri, 27 Jun 2025 13:03:00 +0200 Subject: [PATCH] Correctly determine if a package has bundled dependencies I have a package that's as follows: # tree /usr/lib/node_modules/history /usr/lib/node_modules/history |-- DOMUtils.js |-- LocationUtils.js |-- PathUtils.js |-- createBrowserHistory.js |-- createHashHistory.js |-- createMemoryHistory.js |-- createTransitionManager.js |-- es | |-- DOMUtils.js | |-- LocationUtils.js | |-- PathUtils.js | |-- createBrowserHistory.js | |-- createHashHistory.js | |-- createMemoryHistory.js | |-- createTransitionManager.js | `-- index.js |-- index.js |-- node_modules | |-- invariant -> /usr/lib/node_modules/invariant | |-- loose-envify -> /usr/lib/node_modules/loose-envify | |-- resolve-pathname -> /usr/lib/node_modules/resolve-pathname | |-- value-equal -> /usr/lib/node_modules/value-equal | `-- warning -> /usr/lib/node_modules/warning |-- package.json `-- umd |-- history.js `-- history.min.js The node_modules directory was created by the %nodejs_symlink_deps macro. Then when using nodejs.req I don't get any dependencies: # echo /usr/lib/node_modules/history/package.json | /usr/lib/rpm/nodejs.req It looks like has_only_bundled_dependencies returns true, while it shouldn't. Critically, it runs this code: 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) ) Here dependency_path_iter is: [ '/usr/lib/node_modules/history/node_modules/invariant', '/usr/lib/node_modules/history/node_modules/loose-envify', '/usr/lib/node_modules/history/node_modules/resolve-pathname', '/usr/lib/node_modules/history/node_modules/value-equal', '/usr/lib/node_modules/history/node_modules/warning' ] And module_root_path is /usr/lib/node_modules/history. We can conclude that path.startswith(module_root_path) will always be true, because we started with iterating over files under module_root_path. The code suggests it should have looked up the real path instead. If we make that change, it correctly generates the dependencies. --- nodejs.req | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nodejs.req b/nodejs.req index 129606b..c89a3f7 100755 --- a/nodejs.req +++ b/nodejs.req @@ -633,9 +633,9 @@ def has_only_bundled_dependencies(module_dir_path): for basename in os.listdir(dependency_root_path) ) bundled_dependency_iter = ( - os.path.realpath(path) + path for path in dependency_path_iter - if not os.path.islink(path) or path.startswith(module_root_path) + if not os.path.islink(path) or os.path.realpath(path).startswith(module_root_path) ) return any(bundled_dependency_iter)