Skip to content

feat: auto-discover .pkgrc / pkg.config.{js,cjs,mjs}#254

Merged
robertsLando merged 3 commits intomainfrom
feat/pkgrc-config-discovery
Apr 20, 2026
Merged

feat: auto-discover .pkgrc / pkg.config.{js,cjs,mjs}#254
robertsLando merged 3 commits intomainfrom
feat/pkgrc-config-discovery

Conversation

@robertsLando
Copy link
Copy Markdown
Member

Summary

  • Auto-discover a dedicated pkg config next to the input file so users no longer need to pass --config every time or pollute package.json. Discovery order: .pkgrc.pkgrc.jsonpkg.config.jspkg.config.cjspkg.config.mjs.
  • Pkgrc and package.json now co-exist: package.json supplies name / bin; pkgrc supplies the pkg config. If both define pkg config, pkgrc wins and a warning is logged.
  • .mjs is loaded via a genuine dynamic import() (wrapped in new Function to survive the CommonJS downlevel), enabling function-valued options down the road.
  • Explicit --config still wins over auto-discovery.

Closes #238.

Test plan

  • test-46-pkgrc.pkgrc with a plain JS input
  • test-46-pkgrc-jspkg.config.js with a plain JS input
  • test-46-pkgrc-mjspkg.config.mjs (ESM) with a plain JS input
  • test-46-pkgrc-overrides-pkg-field — both .pkgrc and package.json#pkg present; pkgrc wins
  • Existing test-46-input-package-json* regression checks still pass
  • tsc, prettier -c, and eslint lib test all clean

🤖 Generated with Claude Code

Look up a dedicated pkg config next to the input file so users don't
have to pass --config every time or clutter package.json. Discovery
order: .pkgrc, .pkgrc.json, pkg.config.js, pkg.config.cjs, pkg.config.mjs.
When a pkgrc and package.json both define pkg config, pkgrc wins and a
warning is logged; package.json still supplies name/bin. .mjs is loaded
via a genuine dynamic import() (wrapped in new Function to survive the
CommonJS downlevel), enabling function-valued options down the road.
@robertsLando robertsLando requested a review from Copilot April 20, 2026 08:43
@robertsLando robertsLando changed the title feat: auto-discover .pkgrc / pkg.config.{js,cjs,mjs} (closes #238) feat: auto-discover .pkgrc / pkg.config.{js,cjs,mjs} Apr 20, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds automatic discovery and loading of dedicated pkg configuration files located next to the input (entry file or resolved package.json), reducing the need for --config and avoiding package.json pollution.

Changes:

  • Implement auto-discovery of .pkgrc / .pkgrc.json / pkg.config.{js,cjs,mjs} with defined precedence, while keeping --config as highest priority.
  • Add dynamic loading support for JS/CJS/MJS config files (including ESM via genuine import()), and make discovered config override package.json#pkg with a warning.
  • Add test coverage for .pkgrc, pkg.config.js, pkg.config.mjs, and pkgrc-overrides-package.json#pkg, plus documentation updates.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/index.ts Adds config auto-discovery, loading logic for JSON/JS/CJS/MJS, and precedence behavior vs package.json#pkg.
lib/help.ts Updates CLI help text to mention auto-discovered config files.
docs-site/guide/configuration.md Documents standalone config files, supported filenames, and precedence rules.
test/test-46-pkgrc/main.js New test verifying .pkgrc auto-discovery next to a JS input.
test/test-46-pkgrc/test-x-index.js JS input fixture for pkgrc test.
test/test-46-pkgrc/.pkgrc .pkgrc fixture defining targets.
test/test-46-pkgrc-js/main.js New test verifying pkg.config.js auto-discovery.
test/test-46-pkgrc-js/test-x-index.js JS input fixture for pkg.config.js test.
test/test-46-pkgrc-js/pkg.config.js pkg.config.js fixture defining targets.
test/test-46-pkgrc-mjs/main.js New test verifying pkg.config.mjs auto-discovery via dynamic import.
test/test-46-pkgrc-mjs/test-x-index.js JS input fixture for pkg.config.mjs test.
test/test-46-pkgrc-mjs/pkg.config.mjs ESM config fixture defining targets.
test/test-46-pkgrc-overrides-pkg-field/main.js New regression test ensuring pkgrc overrides package.json#pkg targets.
test/test-46-pkgrc-overrides-pkg-field/test-x-index.js JS entry fixture referenced by package.json bin.
test/test-46-pkgrc-overrides-pkg-field/package.json Fixture with name, bin, and a conflicting pkg.targets (win).
test/test-46-pkgrc-overrides-pkg-field/.pkgrc Fixture pkgrc defining targets that should override package.json.

Comment thread lib/index.ts Outdated
Comment thread lib/help.ts Outdated
Comment thread docs-site/guide/configuration.md Outdated
List pkg.config.mjs consistently in the inline comment, CLI help, and
configuration guide precedence bullet — all three enumerated the first
four filenames but omitted the fifth.
@robertsLando robertsLando merged commit 53ce68b into main Apr 20, 2026
27 checks passed
@robertsLando robertsLando deleted the feat/pkgrc-config-discovery branch April 20, 2026 09:21
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.

feat: support a .pkgrc configuration file

2 participants