feat: auto-discover .pkgrc / pkg.config.{js,cjs,mjs}#254
Merged
robertsLando merged 3 commits intomainfrom Apr 20, 2026
Merged
Conversation
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.
There was a problem hiding this comment.
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--configas highest priority. - Add dynamic loading support for JS/CJS/MJS config files (including ESM via genuine
import()), and make discovered config overridepackage.json#pkgwith 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. |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--configevery time or pollutepackage.json. Discovery order:.pkgrc→.pkgrc.json→pkg.config.js→pkg.config.cjs→pkg.config.mjs.package.jsonnow co-exist:package.jsonsuppliesname/bin; pkgrc supplies thepkgconfig. If both definepkgconfig, pkgrc wins and a warning is logged..mjsis loaded via a genuine dynamicimport()(wrapped innew Functionto survive the CommonJS downlevel), enabling function-valued options down the road.--configstill wins over auto-discovery.Closes #238.
Test plan
test-46-pkgrc—.pkgrcwith a plain JS inputtest-46-pkgrc-js—pkg.config.jswith a plain JS inputtest-46-pkgrc-mjs—pkg.config.mjs(ESM) with a plain JS inputtest-46-pkgrc-overrides-pkg-field— both.pkgrcandpackage.json#pkgpresent; pkgrc winstest-46-input-package-json*regression checks still passtsc,prettier -c, andeslint lib testall clean🤖 Generated with Claude Code