Skip to content

Publish only a whitelist of files in the gem - #33

Open
Fivell wants to merge 4 commits into
masterfrom
chore/trim-packaged-gem
Open

Fivell wants to merge 4 commits into
masterfrom
chore/trim-packaged-gem

Conversation

@Fivell

@Fivell Fivell commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

What

files is now an explicit whitelist, instead of publishing everything tracked minus whatever someone remembered to exclude.

gem.files         = `git ls-files -z -- lib app vendor config exe bin README.md LICENSE.txt`.split("\x0")

A reject list only removes what someone named. That is how CI config, Appraisal matrices ended up in the published gem — each needed its own pattern, and none was added until an audit went looking. A whitelist inverts the default: a new directory does not reach consumers until it is listed.

Every root Rails::Engine loads from is listed, present in this repo or not. A whitelist fails quietly — git ls-files -- config against a tree with no config/ exits 0 and prints nothing — so the day someone adds config/initializers/foo.rb the gem would install, boot, and never run it. Naming the roots up front costs nothing (git ls-files on a missing path is a no-op) and removes that trapdoor.

Selected through git ls-files rather than Dir[...] so the artifact stays tracked-only — an untracked or generated file under lib/ cannot leak into a release — and so files carries no directory entries.

Verified

$ gem build active_admin_role.gemspec
39 files / 16K   ->   26 files / 12K

All 13 files that leave the package:

.github/issue_template.md
.gitignore
.rspec
.rubocop.yml
.rubocop_todo.yml
.travis.yml
Appraisals
Gemfile
Rakefile
active_admin_role.gemspec
gemfiles/5.0.gemfile
gemfiles/5.1.gemfile
gemfiles/5.2.gemfile

Nothing is added. The 24 files under app/, config/, lib/ — the entire runtime payload — are unchanged:

app/models/active_admin_role/can_can/ability.rb
app/models/active_admin/manageable_resource.rb
app/models/active_admin/managed_resource.rb
app/models/active_admin/permission_reloader.rb
app/models/active_admin/permission.rb
config/locales/en.yml
config/locales/ja.yml
lib/active_admin_role.rb
lib/active_admin_role/active_admin/dsl.rb
lib/active_admin_role/active_admin/resource_controller.rb
lib/active_admin_role/config.rb
lib/active_admin_role/dsl.rb
lib/active_admin_role/engine.rb
lib/active_admin_role/role_based_authorizable.rb
lib/active_admin_role/version.rb
lib/generators/active_admin_role/helper.rb
lib/generators/active_admin_role/install_generator.rb
lib/generators/active_admin_role/templates/admin/permissions.tt
lib/generators/active_admin_role/templates/initializer.tt
lib/generators/active_admin_role/templates/migration/add_role_to_admin_users.tt
lib/generators/active_admin_role/templates/migration/create_active_admin_managed_resources.tt
lib/generators/active_admin_role/templates/migration/create_active_admin_permissions.tt
lib/generators/active_admin_role/templates/model/ability.tt
lib/generators/active_admin_role/USAGE

`gemfiles/` are the Appraisal matrices for Rails 5.0/5.1/5.2 and
`.github/issue_template.md` is a GitHub form — neither is reachable
from a consumer's app.

Packaged: 39 files -> 35.
The reject list only removes directories someone remembered to name.
That is how spec/, .github/, screen/ and img/ got published in the
first place — each needed a new pattern, and none was added until an
audit went looking.

A whitelist inverts the default: a new directory in the repo does not
reach consumers until it is listed. Same shape the sibling gems
activeadmin-oidc and credit_card_validations already use.

Drops the remaining dev-only files the reject form kept:

  .gitignore .rspec .rubocop_todo.yml .rubocop.yml .travis.yml active_admin_role.gemspec Appraisals Gemfile Rakefile

Packaged: 35 -> 26 files. The runtime payload — everything
under lib/, app/, vendor/, config/ and exe/ — is byte-identical to
before, verified by diffing the built .gem both ways.

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The whitelist removes nine more tracked files than the four stated in the PR description.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Replaces the gem’s reject-based packaging list with an explicit runtime-file whitelist.

Changes:

  • Packages only runtime directories, README, and license.
  • Excludes development and repository-management files.
File Description
active_admin_role.gemspec Defines an explicit package-file whitelist.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread active_admin_role.gemspec Outdated
Comment on lines +18 to +19
gem.files = Dir["lib/**/*", "app/**/*", "config/**/*",
"README.md", "LICENSE.txt"]
`Dir[...]` globs the working tree, so any untracked or generated file
under lib/, app/ or vendor/ would be published in a release — the build
artifact depended on the releaser's local checkout. The reject form it
replaced was tracked-only; this restores that property while keeping
the whitelist.

`git ls-files -- <paths>` also returns files only, where `Dir["**/*"]`
returns directory entries too, so `files` no longer carries entries
RubyGems just ignores.

Built .gem is byte-for-byte the same file list as the Dir[] version.
@Fivell Fivell changed the title Trim dev-only paths out of the packaged gem Publish only a whitelist of files in the gem Sep 30, 2026
A whitelist fails quietly: `git ls-files -- config` against a tree with
no config/ exits 0 and prints nothing, so the day someone adds
`config/initializers/foo.rb` the gem installs, boots, and the
initializer never runs. Nothing in `gem build` warns.

That is not hypothetical for this family of gems —
active_admin_datetimepicker's Ransack predicates live in exactly such
an initializer, and its filters return no results without them.

So list every root Rails::Engine loads from (lib app vendor config exe
bin) in all of them, present or not, instead of only the ones that
happen to exist today. No package changes: the built .gem is identical
in every gem.
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