Skip to content

fix: publish only the package's own files - #133

Merged
roderickhsiao merged 1 commit into
mainfrom
packaging-files-allowlist
Sep 4, 2026
Merged

roderickhsiao merged 1 commit into
mainfrom
packaging-files-allowlist

Conversation

@roderickhsiao

Copy link
Copy Markdown
Owner

2.0.0 shipped files consumers have no use for:

migration-storybook.log      16.1kB   ← biggest file in the package
.github/workflows/build.yml
.github/workflows/codeql-analysis.yml
tsconfig.json, tsconfig.publish.json
eslint.config.js, setupTests.ts, .nvmrc

Confirmed against the published tarball, not just locally — npm pack react-aspect-ratio@2.0.0 contains all of the above.

Why it happened

Two compounding reasons, both inherent to .npmignore:

  1. npm ignores .gitignore entirely once .npmignore exists. migration-storybook.log was never tracked by git — .gitignore has *.log — but npm packs the working directory, so it shipped anyway. Any stray build log or scratch file in a maintainer's checkout at publish time lands in the tarball.
  2. A denylist rots. The .npmignore still listed .circleci and .flowconfig, neither of which has existed for years, while never gaining entries for the workflows, tsconfigs or eslint config added since.

The fix

Replaced .npmignore with a files allowlist, which cannot leak a file nobody listed:

"files": ["dist", "aspect-ratio.css", "aspect-ratio.js", "MIGRATION.md"]

package.json, README.md and LICENSE are always included by npm regardless. aspect-ratio.js is kept because it has been published since 1.x and may be imported directly; theme.css / theme.js stay excluded, as they were under .npmignore.

Tarball goes 26 files → 18, and nothing consumers rely on is dropped.

Verification

Packed the tarball and installed it into a clean project on React 19 — this exercises the real published artifact, not the working tree:

check result
require('react-aspect-ratio') renders <div class="react-aspect-ratio-placeholder" style="--aspect-ratio:(16/9)">x</div>
import from dist/es/index.js renders <div class="react-aspect-ratio-placeholder" style="--aspect-ratio:(0.75)">y</div>
react-aspect-ratio/aspect-ratio.css resolves yes
dist/index.d.ts present yes

Plus pnpm run test:ci 6/6 and tsc --noEmit clean.

Version bumped to 2.0.1 so this is publishable as-is — say the word if you would rather batch it with other work and drop the bump.

🤖 Generated with Claude Code

2.0.0 shipped both CI workflows, tsconfig.json, tsconfig.publish.json,
eslint.config.js, setupTests.ts, .nvmrc and a 16kB migration-storybook.log.

The cause is that npm ignores .gitignore entirely whenever .npmignore exists,
so stray working-directory files were packed even though git ignores them —
migration-storybook.log was never tracked at all. A denylist also rots: the
.npmignore still listed .circleci and .flowconfig, neither of which exists.

Replaced it with a files allowlist, which cannot leak a file nobody listed.
npm always adds package.json, README and LICENSE on top.

Tarball goes 26 files -> 18. Verified by installing the packed tarball into a
clean project on React 19: CJS and ESM entry points both render, the CSS
resolves, and dist/index.d.ts is present.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@roderickhsiao
roderickhsiao merged commit 6a64fa9 into main Sep 4, 2026
2 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.

1 participant