Skip to content

feat(inspector): add side effects indicator for packages - #217

Open
Koa-wang wants to merge 1 commit into
antfu:mainfrom
Koa-wang:feat/show-side-effects-indicator
Open

Koa-wang wants to merge 1 commit into
antfu:mainfrom
Koa-wang:feat/show-side-effects-indicator

Conversation

@Koa-wang

Copy link
Copy Markdown

Display whether a package has side effects declared in package.json, helping users debug tree-shaking issues at a glance.

Closes #100

🔗 Linked issue

Closes #100

🧭 Context

When debugging bundle size issues, one of the first things you check is whether a package is tree-shakeable. The sideEffects field in package.json tells bundlers exactly that — but right now there's no way to see this info in the inspector without digging into each package's package.json manually.

This PR adds a small visual indicator so you can spot side effects at a glance across your entire dependency tree.

📚 Description

Added a SideEffectsBadge component that reads the sideEffects field from each package's package.json and shows an icon next to the package name:

  • Green tree icon when sideEffects: false — safe to tree-shake
  • Amber warning icon when sideEffects: true — has side effects
  • Yellow warning icon when sideEffects: [...] — partially tree-shakeable (hover to see how many file patterns are declared)

The badge shows up in two places: the package details panel and the grid view.

It's gated behind a new "Show side effects badge" toggle in Settings, off by default — didn't want to add visual noise for people who don't need it.

The data layer changes are minimal: just a new normalizePkgSideEffects() function in package-json.ts that gets wired into resolvePackageJsonFields(), same pattern as the existing license/funding/author normalizers. The sideEffects field isn't in the pkg-types PackageJson interface so it's read via a type cast.

Files touched:

  • packages/node-modules-tools/src/types/node.ts — added sideEffects to PackageNode.resolved
  • packages/node-modules-tools/src/utils/package-json.ts — added normalizePkgSideEffects()
  • packages/node-modules-tools/src/resolve-json.ts — wired it into resolvePackageJsonFields()
  • packages/node-modules-inspector/src/shared/types.ts — added showSideEffectsBadge setting type
  • packages/node-modules-inspector/src/app/state/settings.ts — default value (false)
  • packages/node-modules-inspector/src/app/components/display/SideEffectsBadge.vue — new component
  • packages/node-modules-inspector/src/app/components/panel/Settings.vue — toggle in settings
  • packages/node-modules-inspector/src/app/components/panel/PackageDetailsInfo.vue — badge in details panel
  • packages/node-modules-inspector/src/app/components/grid/Item.vue — badge in grid items

Display whether a package has side effects declared in package.json,
helping users debug tree-shaking issues at a glance.

Closes antfu#100
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.

Display Whether a package has side effects or not

1 participant