Skip to content

feat: read global rc from xdg config dir - #328

Merged
pi0 merged 5 commits into
unjs:mainfrom
danielroe:feat/xdg-global-rc
Sep 2, 2026
Merged

pi0 merged 5 commits into
unjs:mainfrom
danielroe:feat/xdg-global-rc

Conversation

@danielroe

@danielroe danielroe commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

spotted when reviewing nuxt/telemetry#465

we don't respect global rc from xdg config dir, even though this is where the non-deprecated helpers from rc9 write configuration...

Summary by CodeRabbit

  • Documentation

    • Updated configuration guidance to explain supported locations and precedence.
  • Bug Fixes

    • Global configuration is now discovered from both the user configuration directory and legacy home-directory location.
    • Workspace configuration takes precedence over global settings.
    • Custom configuration directory handling now follows the documented precedence rules.
  • Tests

    • Added coverage for configuration discovery, fallback behavior, precedence, and custom configuration directory handling.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: de1539a0-767a-443b-8367-86e4b2857137

📥 Commits

Reviewing files that changed from the base of the PR and between dfd43c7 and f9dd17b.

📒 Files selected for processing (1)
  • src/loader.ts

📝 Walkthrough

Walkthrough

Global RC discovery now reads the user configuration directory and the legacy home file. Tests cover lookup precedence, fallback behavior, project overrides, and XDG_CONFIG_HOME handling. The README documents the supported locations and precedence.

Changes

Global RC discovery

Layer / File(s) Summary
Update global RC loading
src/loader.ts, README.md
The loader reads the user configuration directory and legacy home file. The README documents the lookup order and precedence.
Validate RC locations and precedence
test/global-rc.test.ts
Tests cover legacy home files, user configuration files, empty-file fallback, project precedence, and XDG_CONFIG_HOME handling.

Estimated code review effort: 2 (Simple) | ~10 minutes

Mergeability Score: ⚪ Minimal · up to dfd43

The change is localized to loading the global configuration from the XDG config directory, with accompanying documentation and tests; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: mrlubos

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: loading the global rc file from the XDG configuration directory.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.92%. Comparing base (42d9697) to head (f9dd17b).
⚠️ Report is 230 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #328      +/-   ##
==========================================
+ Coverage   76.92%   77.92%   +1.00%     
==========================================
  Files           7        5       -2     
  Lines         806      367     -439     
  Branches       80      142      +62     
==========================================
- Hits          620      286     -334     
+ Misses        184       67     -117     
- Partials        2       14      +12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
test/global-rc.test.ts (2)

17-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Move internal helpers to the bottom of the file.

Move restoreEnv and load below the it blocks, before the closing describe block.

As per coding guidelines, **/*.{ts,tsx,js,jsx} requires internal helper functions at the bottom of files.

Also applies to: 43-43

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/global-rc.test.ts` around lines 17 - 25, Move the internal helper
functions restoreEnv and load below all it blocks in the describe block, placing
them immediately before the closing describe brace. Keep their implementations
and test behavior unchanged.

Source: Coding guidelines


45-88: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Use checked-in RC fixtures.

Move the RC file contents into test/fixture/ and use those files to construct each test case. Keep the temporary environment roots for HOME and XDG_CONFIG_HOME.

As per coding guidelines, test/**/*.test.{ts,tsx,js,jsx} must use fixture-based testing with real config files from test/fixture/.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/global-rc.test.ts` around lines 45 - 88, Move the inline RC contents in
the global configuration tests into checked-in files under test/fixture/, then
update each test in the relevant suite to copy or use those fixture files when
constructing HOME, XDG_CONFIG_HOME, and project configurations. Preserve the
temporary environment roots and all existing precedence and empty-file
scenarios, including the XDG_CONFIG_HOME isolation case; do not pass
configuration contents directly to writeFile.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 105-107: Update the RC configuration source documentation in
README.md to list the complete loading order: workspace directory first, then
the user config directory from $XDG_CONFIG_HOME or ~/.config, then the user home
directory. Keep the stated precedence aligned with this order and avoid
describing the home directory as the sole global source.

---

Nitpick comments:
In `@test/global-rc.test.ts`:
- Around line 17-25: Move the internal helper functions restoreEnv and load
below all it blocks in the describe block, placing them immediately before the
closing describe brace. Keep their implementations and test behavior unchanged.
- Around line 45-88: Move the inline RC contents in the global configuration
tests into checked-in files under test/fixture/, then update each test in the
relevant suite to copy or use those fixture files when constructing HOME,
XDG_CONFIG_HOME, and project configurations. Preserve the temporary environment
roots and all existing precedence and empty-file scenarios, including the
XDG_CONFIG_HOME isolation case; do not pass configuration contents directly to
writeFile.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fa31bda9-68ca-4c07-bbff-b44db8a7a67d

📥 Commits

Reviewing files that changed from the base of the PR and between a2704d2 and 1293ad1.

📒 Files selected for processing (3)
  • README.md
  • src/loader.ts
  • test/global-rc.test.ts

Comment thread README.md Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Around line 79-80: Update the README priority list and the globalRc
description to state that the XDG_CONFIG_HOME RC file is used instead of the
legacy home-directory RC file when XDG_CONFIG_HOME is set; otherwise, the
home-directory file remains the fallback.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bc111653-398b-44fd-b761-907a135e0776

📥 Commits

Reviewing files that changed from the base of the PR and between 1293ad1 and 29fcba9.

📒 Files selected for processing (1)
  • README.md

Comment thread README.md Resolved
@pi0
pi0 merged commit 3882060 into unjs:main Sep 2, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants