Description: Fix npm pack tarball filename parsing with npm >= 7 npm >= 7 emits "npm notice" lines on stderr which subprocess.getstatusoutput merges into stdout, so the tarball filename is no longer the last output line. Blindly taking the last line made "npm2deb create " fail with "[Errno 2] No such file or directory: 'npm notice'". Select the ".tgz" line instead. Author: Yadd Forwarded: no Last-Update: 2026-07-13 --- a/npm2deb/__init__.py +++ b/npm2deb/__init__.py @@ -5,6 +5,8 @@ from urllib.request import urlopen as _urlopen from subprocess import getstatusoutput as _getstatusoutput from subprocess import call as _call +from subprocess import run as _run +from subprocess import PIPE as _PIPE import os as _os import re as _re import tarfile @@ -405,12 +407,21 @@ def download(self): utils.debug(1, "downloading %s@%s tarball from npm registry" % (self.name, self.version)) - info = _getstatusoutput('npm pack "%s@%s"' % (self.name, self.version)) - if info[0] != 0: - exception = "Error downloading package %s@%s\n" % (self.name, self.version) - exception += info[1] - raise ValueError(exception) - tarball_file = info[1].split('\n')[-1] + # npm >= 7 floods stderr with "npm notice" lines. Merging stdout and + # stderr (as subprocess.getstatusoutput does) interleaves, and even + # corrupts, the tarball filename npm prints on stdout. Keep the streams + # separate so stdout contains only the filename. + result = _run(['npm', 'pack', '%s@%s' % (self.name, self.version)], + stdout=_PIPE, stderr=_PIPE, universal_newlines=True) + if result.returncode != 0: + raise ValueError("Error downloading package %s@%s\n%s" + % (self.name, self.version, result.stderr)) + stdout_lines = [line.strip() for line in result.stdout.split('\n') + if line.strip()] + if not stdout_lines: + raise ValueError("Could not find packed tarball in npm pack " + "output for %s@%s" % (self.name, self.version)) + tarball_file = stdout_lines[-1] tarball = tarfile.open(tarball_file) # get the root directory name root_dir = tarball.getnames()[0]