I am trying to replicate the behavior of npm pack
because it has a limitation where it does not write to stdout, it can only write to a local file (see this issue: https://github.com/npm/npm/issues/12039)
Now, I can tar the current directory and write to stdout like so:
tar --exclude='./node_modules/' -cv . | gzip > archive.tar.gz
however, when you extract npm pack
tarballs, all the contents of a your package should be in a directory called 'package'
.
So my question is - how can I tarball the current directory, but put the current directory inside a directory called 'package'
before it gets archived?
Is there some tar -flag that lets you do that?
I did some legwork and as far as my testing goes, npm will accept a tarball with everything in the root, or everything in a subdirectory called 'package'.
To test the above theory, you can tar a NPM project directory with:
then install it somewhere else with
you can't install in the same project though, NPM will complain about circular deps, so install it in another project.