Repository navigation
Conversation
Display whether a package has side effects declared in package.json, helping users debug tree-shaking issues at a glance. Closes antfu#100
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
sideEffectsfield inpackage.jsontells bundlers exactly that — but right now there's no way to see this info in the inspector without digging into each package'spackage.jsonmanually.This PR adds a small visual indicator so you can spot side effects at a glance across your entire dependency tree.
📚 Description
Added a
SideEffectsBadgecomponent that reads thesideEffectsfield from each package'spackage.jsonand shows an icon next to the package name:sideEffects: false— safe to tree-shakesideEffects: true— has side effectssideEffects: [...]— 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 inpackage-json.tsthat gets wired intoresolvePackageJsonFields(), same pattern as the existing license/funding/author normalizers. ThesideEffectsfield isn't in thepkg-typesPackageJsoninterface so it's read via a type cast.Files touched:
packages/node-modules-tools/src/types/node.ts— addedsideEffectstoPackageNode.resolvedpackages/node-modules-tools/src/utils/package-json.ts— addednormalizePkgSideEffects()packages/node-modules-tools/src/resolve-json.ts— wired it intoresolvePackageJsonFields()packages/node-modules-inspector/src/shared/types.ts— addedshowSideEffectsBadgesetting typepackages/node-modules-inspector/src/app/state/settings.ts— default value (false)packages/node-modules-inspector/src/app/components/display/SideEffectsBadge.vue— new componentpackages/node-modules-inspector/src/app/components/panel/Settings.vue— toggle in settingspackages/node-modules-inspector/src/app/components/panel/PackageDetailsInfo.vue— badge in details panelpackages/node-modules-inspector/src/app/components/grid/Item.vue— badge in grid items