isaacs / node-tar

tar for node
ISC License
837 stars 183 forks source link

Documentation: including multiple unrelated directories without leading directory elements in a single archive #415

Closed aral closed 3 months ago

aral commented 5 months ago

Not sure if this is the best way to do this but given it took me a moment to figure it out (as it does not seem to be a natively-supported use case), I thought I’d document it.

Please feel free to add to the documentation/examples or to close this and folks will still be able to find it if they search for it.

TL; DR: use symlinks.

How to include multiple directories from different places in the file system hierarchy in an archive without including the whole directory structure for any of them.

https://codeberg.org/aral/gists/src/branch/main/how-to-include-multiple-directories-from-different-places-in-the-file-system-hierarchy-in-an-archive-without-including-the-whole-directory-structure-for-any-of-them.md

isaacs commented 3 months ago

You could also append them to an archive.

Eg, to add /some/path/asdf and /other/path/foo to the same archive, do this:

const file = '/path/to/file.tar'
await tar.u({ file, cwd: '/some/path' }, ['asdf'])
await tar.u({ file, cwd: '/other/path' }, ['foo'])

Note the similarity:

#!/usr/bin/env bash
file='/path/to/file.tar'
tar u -f $file -C /some/path asdf
tar u -f $file -C /other/path foo