From e24e7dff07b8b49949d102efaa6a6708c1c70f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= Date: Tue, 7 Dec 2021 16:22:49 +0100 Subject: [PATCH] nodejs.prov: find namespaced bundled dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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//node_modules/ ^ ^ With namespaced bundled packages, this is no longer necessary the truth: npm/node_modules/@nmcli//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 --- nodejs.prov | 6 +++--- .../node_modules/@nmcli/test201/package.json | 4 ++++ .../node_modules/test200/package.json | 4 ++++ test/bundled_namespace/nodejs.prov.err.exp | 0 test/bundled_namespace/nodejs.prov.out.exp | 3 +++ test/bundled_namespace/nodejs.req.err.exp | 0 test/bundled_namespace/nodejs.req.out.exp | 1 + test/bundled_namespace/package.json.in | 11 +++++++++++ test/run | 2 +- 9 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 test/bundled_namespace/node_modules/@nmcli/test201/package.json create mode 100644 test/bundled_namespace/node_modules/test200/package.json create mode 100644 test/bundled_namespace/nodejs.prov.err.exp create mode 100644 test/bundled_namespace/nodejs.prov.out.exp create mode 100644 test/bundled_namespace/nodejs.req.err.exp create mode 100644 test/bundled_namespace/nodejs.req.out.exp create mode 100644 test/bundled_namespace/package.json.in diff --git a/nodejs.prov b/nodejs.prov index 663d3d9..56a9bf1 100755 --- a/nodejs.prov +++ b/nodejs.prov @@ -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 diff --git a/test/bundled_namespace/node_modules/@nmcli/test201/package.json b/test/bundled_namespace/node_modules/@nmcli/test201/package.json new file mode 100644 index 0000000..4618046 --- /dev/null +++ b/test/bundled_namespace/node_modules/@nmcli/test201/package.json @@ -0,0 +1,4 @@ +{ + "name": "@nmcli/test201", + "version": "2.1.4" +} diff --git a/test/bundled_namespace/node_modules/test200/package.json b/test/bundled_namespace/node_modules/test200/package.json new file mode 100644 index 0000000..92ab4ba --- /dev/null +++ b/test/bundled_namespace/node_modules/test200/package.json @@ -0,0 +1,4 @@ +{ + "name": "test200", + "version": "1.3.5" +} diff --git a/test/bundled_namespace/nodejs.prov.err.exp b/test/bundled_namespace/nodejs.prov.err.exp new file mode 100644 index 0000000..e69de29 diff --git a/test/bundled_namespace/nodejs.prov.out.exp b/test/bundled_namespace/nodejs.prov.out.exp new file mode 100644 index 0000000..cf9c17f --- /dev/null +++ b/test/bundled_namespace/nodejs.prov.out.exp @@ -0,0 +1,3 @@ +bundled(nodejs-@nmcli/test201) = 2.1.4 +bundled(nodejs-test200) = 1.3.5 +npm(test) = 4.5.6 diff --git a/test/bundled_namespace/nodejs.req.err.exp b/test/bundled_namespace/nodejs.req.err.exp new file mode 100644 index 0000000..e69de29 diff --git a/test/bundled_namespace/nodejs.req.out.exp b/test/bundled_namespace/nodejs.req.out.exp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/bundled_namespace/nodejs.req.out.exp @@ -0,0 +1 @@ + diff --git a/test/bundled_namespace/package.json.in b/test/bundled_namespace/package.json.in new file mode 100644 index 0000000..e41f38b --- /dev/null +++ b/test/bundled_namespace/package.json.in @@ -0,0 +1,11 @@ +{ + "name": "test", + "version": "4.5.6", + "engines": { + "node": ">=6 <10" + }, + "dependencies": { + "test100": "^1.2.3", + "test101": ">=2.1" + } +} diff --git a/test/run b/test/run index 6afb356..7897b24 100755 --- a/test/run +++ b/test/run @@ -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