Publish Preview

Previews what npm publish will ship from npm pack --dry-run and flags .env files, source maps, tests and missing build output before it goes out.

Stopsnpm publish shipped .env

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/publish-preview.json

The files land in your project. They're yours to edit.

Usage

publish-preview-usage.tsx
import { PublishPreview, type PublishFix } from "@/components/ui/publish-preview"

<PublishPreview
  pack={pack}
  pkg={pkg}
  published={["1.4.0", "1.4.1", "1.4.2"]}
  gitignore={"node_modules\n/dist\ncoverage\n"}
  hasNpmignore={false}
  onFix={onFix}
  onPublish={() => new Promise<void>((resolve) => setTimeout(() => (setLog(`+ ${PKG.name}@${state.version}`), resolve()), 900))}
/>

What it catches

  • .env files and keys in the tarball
  • Source maps, tests and repo config shipped by accident
  • Entry points missing from the build, with the reason (.gitignore fallback, files list, no build)
  • Version already published, with a next version
  • private: true, or no files allowlist

Props

PublishPreview props
PropTypeDefault
pack* (required)

Output of `npm pack --dry-run --json` (string or parsed).

string | PackResult | unknown—
pkg

The package.json (object or text) of the package being checked.

PackageJson | string—
packageName

With `--workspaces` output, which package to check. Defaults to the one named in `pkg`, else the first.

string—
onFix

Called with a change to make; the issue then waits for a fresh `pack` to confirm it.

(fix: PublishFix, issue: PackIssue) => void—
onPublish

Shows the publish button, enabled when nothing blocks. May return a Promise for a pending state.

() => void | Promise<void>—
maxFiles

Files listed before "Show more"; flagged files always come first.

number8
locale

Locale for sizes.

string—
messages

Any visible string.

Partial<PublishPreviewMessages>—

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • File list is a labelled section; the issue list is focusable
  • Fix buttons are real buttons; waiting state has text
  • Icons are aria-hidden

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

This is a UX guard rail. Enforce on the server: Run npm pack checks in CI with a files allowlist and provenance before publishing.

  • Needs the pack output and package.json you pass; it doesn't run npm
  • A fix only counts after a fresh pack
  • Doesn't check the package's runtime behaviour

What it stops

npm publish shipped .env

Also known as

npm publish · npm pack · package.json · files field · .npmignore · tarball · library · semver

Dependencies

Pairs well with