dts-critic icon indicating copy to clipboard operation
dts-critic copied to clipboard

Fails to unpack the source package with scoped package

Open jnv opened this issue 4 years ago • 2 comments

Node 16.9.1, npm 7.20.3

I am trying to run npm test for scoped package @atom/watcher I would like to add. However, I am getting the following error:

tar (child): @atom/watcher-1.3.5.tgz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

Upon further inspection, it looks like npm pack doesn't return a correct filename in the JSON:

$ npm pack @atom/watcher --json
[
  {
    "id": "@atom/[email protected]",
    "name": "@atom/watcher",
    "version": "1.3.5",
    "size": 109100,
    "unpackedSize": 449712,
    "shasum": "30efe6ecb8cf0985116f25765ce467b41bca3d6b",
    "integrity": "sha512-QP95EnVtpQmlNVL3ravmVBbTDFteRi99CGvlP925d0+WvjPHSPOKYLxDUP3WyT+fCKqW0sboKrpPSwnbMZvCJw==",
    "filename": "@atom/watcher-1.3.5.tgz",
    "files": [
    ... removed

Notice that filename property states "@atom/watcher-1.3.5.tgz", however, the fetched file has name atom-watcher-1.3.5.tgz.

I was able to fix this by modifying the filename extracted from JSON here:

https://github.com/DefinitelyTyped/dts-critic/blob/b079c11437c03a6b9d68a95ba2b2872b80201a9c/index.ts#L320

to

const tarballName = npmPack.endsWith(".tgz") ? npmPack : JSON.parse(npmPack)[0].filename.replace('/', '-').replace('@', '') as string;

Of course, this isn't pretty but does the job. Also I am not sure whether this works with older versions of npm, notably npm 6.

Alternatively perhaps this should be fixed in npm?

jnv avatar Oct 17 '21 18:10 jnv

Related issues

  • https://github.com/DefinitelyTyped/DefinitelyTyped/issues/56042
  • https://github.com/npm/cli/issues/3405

noahtallen avatar Nov 12 '21 00:11 noahtallen

A workaround is to use an older npm version, such as v6.14.15.

noahtallen avatar Nov 12 '21 00:11 noahtallen