[Pkg-javascript-devel] Bug#1063862: npm2deb fails when self.json['bin'] is not a list -- [patch provided]

Georges Khaznadar georgesk at debian.org
Tue Feb 13 18:18:04 GMT 2024


Package: npm2deb
Version: 0.3.0-12
Severity: normal
Tags: patch

Dear Maintainer,

When I try to run:
   npm2deb create @babel/parser
the command fails:
   ...
   File "/usr/lib/python3/dist-packages/npm2deb/__init__.py", line 260, in
create_links
    orig = _os.path.normpath(self.json['bin'][script])
                             ~~~~~~~~~~~~~~~~^^^^^^^^
  TypeError: string indices must be integers, not 'str'

The reason of this error is that:
   self.json['bin'] == './bin/babel-parser.js'
in this particular case.

Here is a patch which restores the expected behavior:

-----------------8<-------------------------------------
diff --git a/npm2deb/__init__.py b/npm2deb/__init__.py
index ee3f29a..e2974da 100644
--- a/npm2deb/__init__.py
+++ b/npm2deb/__init__.py
@@ -255,9 +255,16 @@ and may not include tests.\n""")
         links = []
         dest = self.debian_dest
         if 'bin' in self.json:
-            for script in self.json['bin']:
-                orig = _os.path.normpath(self.json['bin'][script])
-                links.append("%s/%s usr/bin/%s" % (dest, orig, script))
+            if isinstance(self.json['bin'], list):
+                for script in self.json['bin']:
+                    orig = _os.path.normpath(self.json['bin'][script])
+                    links.append("%s/%s /usr/bin/%s" %
+                                 (self.name, orig, script))
+                else:
+                    script = self.json['bin']
+                    orig = _os.path.normpath(self.json['bin'])
+                    links.append("%s/%s /usr/bin/%s" %
+                                 (self.name, orig, script))
         if len(links) > 0:
             content = '\n'.join(links)
             utils.create_debian_file('links', content)
-----------------8<-------------------------------------

Best regards,                  Georges.


-- System Information:
Debian Release: trixie/sid
  APT prefers stable
  APT policy: (700, 'stable'), (650, 'testing'), (500, 'stable-updates'), (500, 'stable-security'), (500, 'oldstable-updates'), (500, 'oldstable-security'), (500, 'oldoldstable'), (500, 'unstable'), (500, 'oldstable')
Architecture: amd64 (x86_64)

Kernel: Linux 4.19.0-25-amd64 (SMP w/4 CPU threads)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages npm2deb depends on:
ii  devscripts                2.23.7
ii  node-github-url-from-git  1.5.0+~1.5.1-1
ii  npm                       9.2.0~ds1-2
ii  python3                   3.11.6-1
ii  python3-apt               2.7.5
ii  python3-dateutil          2.8.2-3

npm2deb recommends no packages.

npm2deb suggests no packages.

-- no debconf information
-------------- next part --------------
diff --git a/debian/changelog b/debian/changelog
index 75564f7..da54cd4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+npm2deb (0.3.0-12.1) unstable; urgency=medium
+
+  * NMU: fix an issue when self.json['bin'] is not a list.
+
+ -- Georges Khaznadar <georgesk at debian.org>  Tue, 13 Feb 2024 18:57:29 +0100
+
 npm2deb (0.3.0-12) unstable; urgency=medium
 
   * Update standards version to 4.6.1, no changes needed.
diff --git a/npm2deb/__init__.py b/npm2deb/__init__.py
index ee3f29a..e2974da 100644
--- a/npm2deb/__init__.py
+++ b/npm2deb/__init__.py
@@ -255,9 +255,16 @@ and may not include tests.\n""")
         links = []
         dest = self.debian_dest
         if 'bin' in self.json:
-            for script in self.json['bin']:
-                orig = _os.path.normpath(self.json['bin'][script])
-                links.append("%s/%s usr/bin/%s" % (dest, orig, script))
+            if isinstance(self.json['bin'], list):
+                for script in self.json['bin']:
+                    orig = _os.path.normpath(self.json['bin'][script])
+                    links.append("%s/%s /usr/bin/%s" %
+                                 (self.name, orig, script))
+                else:
+                    script = self.json['bin']
+                    orig = _os.path.normpath(self.json['bin'])
+                    links.append("%s/%s /usr/bin/%s" %
+                                 (self.name, orig, script))
         if len(links) > 0:
             content = '\n'.join(links)
             utils.create_debian_file('links', content)


More information about the Pkg-javascript-devel mailing list