Repository: webscopeio/license.sh

Issue:
Npm run fail
https://gitlab.com/license_test_group/satnogs-db
```
Traceback (most recent call last):
  File "/usr/local/bin/license-sh", line 2, in <module>
    from license_sh import __main__
  File "/usr/local/lib/python3.8/site-packages/license_sh/__main__.py", line 24, in <module>
    run_license_sh(arguments)
  File "/usr/local/lib/python3.8/site-packages/license_sh/commands/run_license_sh.py", line 58, in run_license_sh
    dep_tree, license_map = runner.check()
  File "/usr/local/lib/python3.8/site-packages/license_sh/runners/npm/__init__.py", line 142, in check
    license_map = fetch_npm_licenses(flat_dependencies)
  File "/usr/local/lib/python3.8/site-packages/license_sh/runners/runners_shared.py", line 40, in fetch_npm_licenses
    asyncio.run(fetch_concurrent(urls))
  File "/usr/local/lib/python3.8/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 612, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.8/site-packages/license_sh/runners/runners_shared.py", line 33, in fetch_concurrent
    license_map[f"{page['name']}@{version}"] = extract_npm_license(
KeyError: 'name'
```

Discussion:

Patch:
diff --git a/.gitignore b/.gitignore
index 770d014..7ac4476 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,6 @@ examples
 .vscode
 **/node_modules/**
 **/target/**
-**/dist/**
\ No newline at end of file
+**/dist/**
+**/build/**
+**/license_sh.egg-info/**
\ No newline at end of file
diff --git a/license_sh/helpers.py b/license_sh/helpers.py
index 56b2849..7358ff7 100644
--- a/license_sh/helpers.py
+++ b/license_sh/helpers.py
@@ -43,7 +43,11 @@ def get_npm_license_from_licenses_array(licenses_array):
 
     license_name = UNKNOWN
     for license_item in licenses_array:
-        license_item_type = license_item.get("type", UNKNOWN)
+        license_item_type = (
+            license_item.get("type", UNKNOWN)
+            if type(license_item) is dict
+            else f"{license_item}"
+        )
         if license_name != UNKNOWN:
             license_name = f"{license_name} AND {license_item_type}"
         else:
diff --git a/license_sh/runners/runners_shared.py b/license_sh/runners/runners_shared.py
index 8f013df..bcea6e3 100644
--- a/license_sh/runners/runners_shared.py
+++ b/license_sh/runners/runners_shared.py
@@ -30,9 +30,10 @@ def fetch_npm_licenses(all_dependencies):
                 try:
                     output, version = await result
                     page = json.loads(output)
-                    license_map[f"{page['name']}@{version}"] = extract_npm_license(
-                        page, version
-                    )
+                    if ("name") in page:
+                        license_map[f"{page['name']}@{version}"] = extract_npm_license(
+                            page, version
+                        )
 
                 except json.JSONDecodeError:
                     pass
diff --git a/license_sh/version.py b/license_sh/version.py
index f871089..13361d1 100644
--- a/license_sh/version.py
+++ b/license_sh/version.py
@@ -1,1 +1,1 @@
-__version__ = "1.0.15"
+__version__ = "1.0.16"


Test patch:
diff --git a/tests/runners/test_helpers.py b/tests/runners/test_helpers.py
index 1a0f966..9026a98 100644
--- a/tests/runners/test_helpers.py
+++ b/tests/runners/test_helpers.py
@@ -272,6 +272,16 @@ class NpmRunnerTestCase(unittest.TestCase):
         name = extract_npm_license(data, "Unknown")
         self.assertEqual(name, "MIT")
 
+    def test_extract_npm_licenses_global_single_string(self):
+        data = json.loads(
+            """{
+            "name": "name",
+            "licenses": ["MIT"]
+        }"""
+        )
+        name = extract_npm_license(data, "Unknown")
+        self.assertEqual(name, "MIT")
+
     def test_extract_npm_licenses_global_single(self):
         data = json.loads(
             """{