-
-
Notifications
You must be signed in to change notification settings - Fork 741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: xz compression option #571
Conversation
I personally prefer downloading xz to save on network bandwidth, so that's why I made this PR. In case it's useful for other people as well. I haven't squashed this yet, but if this will be merged, I wanted some feedback on whether the new error messages are needed, or if any of the changes to the script should be re-formatted/cleaned up somehow. Happy to squash and force-push when it's ready to merge. Also, I put together an alternate implementation of the error messages here: https://github.com/DeeDeeG/n/blob/5ca0a2a8ffa57b5bc06e1c82988dbd129d2feec5/bin/n#L564-L567 That branch has two distinct errors: One if the extension is totally invalid (not present in the "latest" directory) or just invalid for the version you asked for (0.8 and 0.9 didn't ship with xz-compressed tarballs, only gzip-compressed ones). Let me know if you prefer that, and I can force-push that to the branch for this PR. Thanks for any feedback on this. |
Reference: https://en.wikipedia.org/wiki/Xz No mention of xz in issues prior to now, but it is smaller. I looked at Still thinking about preferred behaviour... Automatic is nice so everyone gets benefit but means we need to get it right! |
FWIW xz is known as a slower algorithm vs. gzip. But I don't think these tarballs are big enough to make it noticeable. I think (for a machine that comfortably runs node, npm, etc.) we can expect that decompressing these tarballs takes less than a second, regardless of whether we use xz or gzip. Theoretically there is a trade-off, but practically I think xz is an improvement for little to no cost. The other thing to think about, IMO, is if all platforms that have a gzip decompressor also have an xz decompressor. On debian/Ubuntu this is xz-utils. It's installed by default even on some slim/minimal debian images I have used (from Docker). I have no idea about Alpine, Arch, etc. or macOS. Seems like a good idea to try to deduce xz support. Perhaps run a |
We already have EDIT: But if a better way can be learned from nvm, nvs, etc then I don't object to that. |
Eventually, I would like to make the use of xz automatic. And I didn't have it on my wish list until you raised it, thanks. But that is a riskier change and there other things I want to do first (especially improve error handling, and switch to using So what about opt-in xz now, like this Pull Request? Well, maybe!
So if you want to rework your Pull Request to test for (say) |
sounds good. I did think |
8423228
to
e7c4cdb
Compare
To download an xz-compressed tarball, set the environment variable "N_USE_XZ" to be non-empty before running n.
e7c4cdb
to
41400d6
Compare
A quick note: Without more-sophisticated error mechanisms, this will simply give
for everything below (earlier than) node 0.10.42 when using xz. (Whereas n still supports all the way back to 0.8.6 if using the default gzip-compressed tarballs.) |
I made two versions of this feature to respond to feedback. Both have restored the error messages to be the same as before this PR. And both versions use the environment variable
It uses two if-then-else constructions to preserve the exact lines that would be run from before this PR if I am open to feedback on either approach. |
I suppose the tar flag could be reduced to simply Pros:
Cons:
Neutral:
|
I prefer first implementation (in this Pull Request). Thanks for preparing two implementations. :-) I wondered about plain |
(I laughed when I saw you added 👀 to my comment. I have been doing that as a quiet way of indicating I saw someones comment, and you are the first person to do it back. 👍) |
Shipped in v5.0.0 Thank you for your contributions. |
Pull Request Template:
Describe what you did
Add the option to download a
.tar.xz
tarball instead of a.tar.gz
tarballHow you did it
in bin/n, check for an environment variable
EXTENSION
.If
EXTENSION
is set, use this intarball_url()
to set the URL to end in (effectively).tar."$EXTENSION"
rather than.tar.gz
...AND also use this in
install()
to set the tar extraction flags to-Jx
(for extracting an xz-compressed archive) if$EXTENSION
evaluates toxz
Also changed an error message to now alert the user if they have given an invalid extension.
By default, if the environment variable
EXTENSION
is unset, the script will set it to "gz" to use gzip compression.How to verify it doesn't effect the functionality of n
n 10 (or similar)...
(with and without
EXTENSION
environment variable set toxz
)If this solves an issue, please put issue in PR notes.
Nope, I went directly to a PR with this.
If this solves an issue, please include the output of issue that had problems and then the fixed output from the same command.
N/A
Squash any unnecessary commits to keep history clean as possible
Place description for the changelog in PR so we can tally all changes for any future release