0

I have am building a new NPM package to be published. In doing so am generating files that will be included via PHP. These are added to a tarball as in the following snippet.

$disk = 'local';
$path = '/';
$tarball = new \PharData('scope-package-1.2.3.tar', format: \Phar::TAR);

foreach(Storage::disk($disk)->allFiles($path) as $file) {
  $tarball->addFromString(basename($file), Storage::disk($disk)->get($file));
}

$tarball->compress(\Phar::GZ, '.tgz');

The resulting file, scope-package-1.2.3.tgz, looks valid. If I were to npm publish /path/to/scope-package-1.2.3.tgz I get the following error.

npm ERR! code ENOENT\n
npm ERR! syscall open\n
npm ERR! path ~/.npm/_cacache/tmp/rZtgL9/package.json\n
npm ERR! errno -2\n
npm ERR! enoent ENOENT: no such file or directory, open '~/.npm/_cacache/tmp/rZtgL9/package.json'\n
npm ERR! enoent This is related to npm not being able to find a file.\n
npm ERR! enoent \n

I can't tell where NPM decide the rZtgL9 portion of that cache.

If I remove the gzipped tarball and in the same directory run npm pack this creates a file named the same, and from what I can tell otherwise the same. Both extract correctly on OSX and both have the same contents. If I publish this tarball in the same way, however, it works!

What is it that npm pack may be doing that allows it to be fetched from the cache that my code does not? Running npm pack does not appear to affect the cache.

Marshall Davis
  • 3,337
  • 5
  • 39
  • 47

0 Answers0