• Bug#1063862: npm2deb fails when self.json['bin'] is not a list -- [patc

    From Georges Khaznadar@21:1/5 to All on Tue Feb 13 19:30:01 2024
    This is a multi-part MIME message sent by reportbug.


    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)
    util