1

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?

  • 1
    `mkdir package && cp -R source package/ && tar --exclude='./node_modules/' -cvf - . | gzip > archive.tar.gz ` Somthing like that? – infamoustrey May 15 '18 at 17:48
  • that would work, but I don't want to write to the filesystem, I have read-only access –  May 15 '18 at 18:46
  • 1
    because I have readonly access to the filesystem (it's in a docker container) I have to do it this way, instead of creating some temp dir. –  May 15 '18 at 18:46
  • Maybe I'm crazy but how can you make a zip in a read only env? – infamoustrey May 15 '18 at 19:36
  • 1
    easy - tar to stdout with `tar -c * | write_anywhere_but_local_filesystem` –  May 15 '18 at 22:52

1 Answers1

1

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:

tar --exclude='node_modules' -c . > archive.tar

then install it somewhere else with

  npm install /path/to/archive.tar

you can't install in the same project though, NPM will complain about circular deps, so install it in another project.