Skip to content

feat(barrel-policy): accept a package's declared entry files as barrels - #136

Merged
Mearman merged 2 commits into
mainfrom
feat/barrel-policy-entries
Oct 11, 2026
Merged

Mearman merged 2 commits into
mainfrom
feat/barrel-policy-entries

Conversation

@Mearman

@Mearman Mearman commented Oct 11, 2026

Copy link
Copy Markdown
Member

Adds an entries option to exadev/barrel-policy so a package that publishes several entry points can declare them, instead of turning the rule off for those files.

'exadev/barrel-policy': ['error', { mode: 'single', entries: ['src/layout.ts', 'src/store/*.ts', 'src/*/index.ts'] }]

The globs are relative to the nearest package.json, so one shared config works across a workspace. A matched file is a permitted barrel: it may contain only re-exports, from anywhere in single (as src/index.ts may) and from a package or a direct sibling in siblings. Files the list does not match behave exactly as before, and nothing changes for a config without entries. entries with mode: 'banned' throws when the rule is created; under auto resolved to banned the list selects nothing.

I chose an explicit list over deriving entries from exports: the targets there are built files (./dist/layout.js), and the source behind each depends on tsdown, tsc or bundler configuration the rule can't see. The README section on package entry points explains this.

With this, ExaDev/process-graph#41 can replace its "exadev/barrel-policy": "off" block with entries listing its subpath modules.

Also fixes the plugin.configs.react/nextjs typing from #134: they are now typed as the arrays the getters return, so defineConfig(...plugin.configs.react) typechecks. A compatibility check spreads both, and a test pins that recommended stays a single object.

Fixes #135
Fixes #134

A package that publishes subpath exports has a module behind each one, and
that module is an entry point just as src/index.ts is. 'single' treated only
src/index.ts as a barrel and 'siblings' only accepted re-exports from a direct
sibling, so the only way to lint such a package was to turn the rule off for
its entry files, which also stopped checking that they hold only re-exports.

The new entries option lists the entry files as globs relative to the nearest
package.json. A matched file is a permitted barrel: it may hold only
re-exports, from anywhere in 'single' and from a package or a direct sibling
in 'siblings'. Every other file keeps its mode's behaviour, and the default
is unchanged. entries beside mode 'banned' is rejected when the rule is
created, and under 'auto' resolved to 'banned' the list selects nothing.

The list is explicit rather than derived from package.json exports, because
an exports target names the built file and mapping it back to its source
depends on build configuration the rule cannot read.

Fixes #135
The react and nextjs getters return arrays built from several upstream
blocks, but PublicPlugin typed every config as a single object or an array,
so spreading them, as an array is used, failed with TS2488. recommended and
barrel are now typed as single config objects and react and nextjs as
arrays, matching the getters, whose own return types are narrowed the same
way. A consumer-compatibility check spreads both arrays into defineConfig,
and a test pins that recommended cannot be spread.

Fixes #134
@Mearman

Mearman commented Oct 11, 2026

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-10-11T05:51:16.113835Z 7dd9540 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 7dd954082c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@Mearman
Mearman marked this pull request as ready for review October 11, 2026 05:48
@Mearman
Mearman merged commit 9301eb6 into main Oct 11, 2026
18 of 20 checks passed
@Mearman
Mearman deleted the feat/barrel-policy-entries branch October 11, 2026 05:48
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 3.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

barrel-policy has no way to accept a package's subpath entry modules configs.react and configs.nextjs are typed as one config object but are arrays

1 participant