fix: improve pack performance by not reading into memory
The current implementation is very slow due to having to load all into memory before writing the file. Pacote itself has a command that does that right away as a stream. This improves the performance significantly.
Fixing the test case seemed more tricky than the fix, so I hope you could suggest what to do about the test.
The reason the test fails is because the code is failing. The file is created but it's empty. npm crashes when lib/commands/pack.js tries to run getContents on the returned object, which is no longer a stream.
pacote.tarball.file eventually returns from #toFile:
{
integrity: 'sha512-...',
resolved: '/path',
from: 'file:/path'
}
via
writer.on('close', () => res({
integrity: this.integrity && String(this.integrity),
resolved: this.resolved,
from: this.from,
}))
Instead of the tarballStream.
I believe the issue is around the return of the pack call. I do not think it should return the tarball in memory, which is a breaking change for this module. Right now, the PR is definitely incomplete. I think it would just be good to have a closer look and see if we could prevent the in memory read.