Skip to content
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

Use $nu.data-dir as last directory for vendor autoloads on all platforms #14879

Merged
merged 2 commits into from
Jan 21, 2025

Conversation

NotTheDr01ds
Copy link
Contributor

@NotTheDr01ds NotTheDr01ds commented Jan 21, 2025

Description

Should fix #14872.

Before

The vendor autoload code in #13382 has the same issue that I just fixed in user-autoloads via #14877. Specifically, it uses dirs::data_dir() (from the dirs crate), leading to a different behavior when XDG_DATA_HOME is set on each platform.

  • On Linux, the dirs crate automatically uses XDG_DATA_HOME for dirs::data_dir(), so everything worked as expected.
  • On macOS, dirs doesn't use the XDG spec, but the vendor autoload code from Use directories for autoloading #13382 specifically added XDG_DATA_HOME. However, even if XDG_DATA_HOME was set, vendor autoloads would still use the dirs version as well.
  • On Windows, XDG_DATA_HOME was ignored completely by vendor autoloads, even though $nu.data-dirs was respecting it.

After

This PR uses nu::data_dirs() on all platforms. nu::data_dirs() respects XDG_DATA_HOME (if set) on all platforms.

User-Facing Changes

Might be a breaking change if someone was depending on the old behavior, but the doc already specified the behavior in this PR.

Tests + Formatting

  • 🟢 toolkit fmt
  • 🟢 toolkit clippy
  • 🟢 toolkit test
  • 🟢 toolkit test stdlib

After Submitting

Documentation already reflects the behavior in this PR.

@fdncred
Copy link
Collaborator

fdncred commented Jan 21, 2025

If this comment still valid, about MacOS, after this PR?

// if on macOS, additionally check XDG_DATA_HOME, which `dirs` is only doing on Linux

@NotTheDr01ds
Copy link
Contributor Author

@fdncred Thanks - I did mean to clean those up, then forgot :-/ The comments also need a few other adjustments, I believe.

@NotTheDr01ds NotTheDr01ds merged commit 0666b37 into nushell:main Jan 21, 2025
15 checks passed
@github-actions github-actions bot added this to the v0.102.0 milestone Jan 21, 2025
@NotTheDr01ds NotTheDr01ds added pr:bugfix This PR fixes some bug pr:breaking-change This PR implies a change affecting users and has to be noted in the release notes configuration Issue related to nu's configuration labels Jan 21, 2025
@Bahex
Copy link
Contributor

Bahex commented Jan 22, 2025

@NotTheDr01ds This seems have changed my last vendor autoload dir incorrectly

from ~/.local/share/nushell/vendor/autoload
to ~/.local/share/vendor/autoload

@NotTheDr01ds
Copy link
Contributor Author

@Bahex What does $nu.data-dir show?

@Bahex
Copy link
Contributor

Bahex commented Jan 22, 2025

@NotTheDr01ds it's set correctly to ~/.local/share/nushell

@NotTheDr01ds
Copy link
Contributor Author

Thanks - I see the problem. Fixing now.

@NotTheDr01ds
Copy link
Contributor Author

@Bahex Fix is going through CI at the moment. Apologies for the bad testing on my part. At the moment, I have to rely on "eyeballing" the path. I really wish we had a way to test autoload code, but I can't find a way to place test files in a "sandboxed" data-dir. The files leak out of the test harness into the user's config :-/.

NotTheDr01ds added a commit that referenced this pull request Jan 22, 2025
Fix issue in #14879 with incorrect subdirectory.
Before: Appended `vendor/autoload`
After: Appends `nushell/vendor/autoload`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Issue related to nu's configuration pr:breaking-change This PR implies a change affecting users and has to be noted in the release notes pr:bugfix This PR fixes some bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

/vendor/autoload is not added as last path on Windows
3 participants