nodejs.prov: find namespaced bundled dependencies

The previous behaviour assumed that in a bundled package path,
there is always `node_modules` directory on each other spot – i.e.:

npm/node_modules/<dep1>/node_modules/<subdep>
    ^                   ^

With namespaced bundled packages, this is no longer necessary the truth:

npm/node_modules/@nmcli/<dep1>/node_modules/…
    ^                   ! – expected node_modules

---

The previous implementation considered any directory not named
`node_modules` as a package directory, and tried to process it as such.
Among other things, it pruned the list of subdirectories to be processed
to just another `node_modules` subdir, if that existed.
With namespaced packages, this pruning in essence happened too soon,
and so they were skipped altogether.

With this patch applied, only directories that directly contain
the `package.json` file are processed as package directories,
meaning that the walk should correctly descend into namespaces
(even nested ones, if they appear).

Resolves: rhbz#2029904
This commit is contained in:
Jan Staněk 2021-12-07 16:22:49 +01:00
parent b1c10eec41
commit e24e7dff07
No known key found for this signature in database
GPG Key ID: 2972F2037B243B6D
9 changed files with 27 additions and 4 deletions

View File

@ -93,9 +93,9 @@ def generate_dependencies(module_path, module_dir_set=NODE_MODULES):
else: # Invalid metadata path
raise ValueError("Invalid module path '%s'" % module_path)
for dir_path, subdir_list, __ in os.walk(root_dir):
# Currently in node_modules (or similar), continue to subdirs
if os.path.basename(dir_path) in module_dir_set:
for dir_path, subdir_list, file_list in os.walk(root_dir):
# We are only interested in directories that contain package.json
if "package.json" not in file_list:
continue
# Read and format metadata

View File

@ -0,0 +1,4 @@
{
"name": "@nmcli/test201",
"version": "2.1.4"
}

View File

@ -0,0 +1,4 @@
{
"name": "test200",
"version": "1.3.5"
}

View File

@ -0,0 +1,3 @@
bundled(nodejs-@nmcli/test201) = 2.1.4
bundled(nodejs-test200) = 1.3.5
npm(test) = 4.5.6

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,11 @@
{
"name": "test",
"version": "4.5.6",
"engines": {
"node": ">=6 <10"
},
"dependencies": {
"test100": "^1.2.3",
"test101": ">=2.1"
}
}

View File

@ -4,7 +4,7 @@ ln -sf nodejs.req nodejs_req.py
"$(command -v python2 || echo :)" -m doctest nodejs_req.py || exit 1
"$(command -v python3 || echo :)" -m doctest nodejs_req.py || exit 1
for test in unbundled bundled
for test in unbundled bundled bundled_namespace
do
sed -e "s|//.*$||" < test/$test/package.json.in > test/$test/package.json