bundled

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bundled identifies, and verifies, where each set in the icon-sets-bundled aggregator pack actually came from.

The pack vendors 121,314 icons across 72 sets, and nothing records which upstream any of them came from. The pack config declares `update_command.type: "iconify"`, but the committed files are not Iconify-rendered: measured across the pack there are 26 distinct <svg> attribute signatures -- bootstrap-icons keeps `class="bi bi-alarm"`, heroicons keeps `data-slot`, fontawesome keeps its licence comment -- where anything rendered from @iconify-json/* would have exactly one. Each set is its own upstream's native distribution.

So a refresh has to go back to each set's own upstream, and that needs a manifest that does not exist. This package builds it, and does so by measurement rather than by guessing: a candidate upstream is accepted only when the files it ships reproduce what is already committed.

Index

Constants

View Source
const PackageCoverageFloor = 0.90

PackageCoverageFloor is the name-coverage fraction at which an upstream counts as identified. It matches the refresh's MinRetention on purpose -- see ConfidencePackage.

View Source
const TieBreakMargin = 1.15

TieBreakMargin is how far ahead the closest directory must be before a tie counts as decided.

1.15 was set from the five ties the aggregator pack actually contains. Four are decided by a wide margin -- cryptocurrency-icons 0.97 against 0.64, pepicons 0.98 against 0.19, fontawesome 0.37 against 0.14 -- and ionicons is the closest genuine call at 0.42 against 0.34, a ratio of 1.22. Anything tighter than this is a judgement, and a judgement belongs to a human.

Variables

This section is empty.

Functions

func CandidatePackages

func CandidatePackages(set string) []string

CandidatePackages returns npm package names to try for a set directory.

These are guesses, and they are allowed to be: nothing is accepted on the strength of a name. The scoring decides, and a candidate that ships no matching bytes is rejected however plausible it looked.

Measured against the pack: the bare directory name resolves as an npm package for 46 of the 72 sets, which is why it is tried first.

func ListSets

func ListSets(filesRoot string) ([]string, error)

ListSets returns the set directories in a pack, skipping dotted entries.

The skip is not cosmetic: an untracked `.claude` directory is currently sitting in this pack's files/ tree, and counting it as a set made an earlier survey report 73 where the pack ships 72.

func ManifestPath

func ManifestPath(configDir, packName string) string

ManifestPath is the conventional location beside a pack config.

func Similarity

func Similarity(dir string, fp SetFingerprint) float64

Similarity scores how closely a directory's icons resemble the committed ones, as a mean over the icons the two have in common.

This exists because byte equality answers nothing here. When a package ships sibling variant directories -- black/white/color, solid/outline, pencil/pop/print -- every one of them has the same filenames, so name coverage grades them identically, and when the pack vendored an older release none of them is byte-identical either. The scorer is then choosing by directory-walk order, which is not a choice.

Resemblance separates the common case, where the variants are different drawings: measured on the aggregator pack it settles fontawesome onto svgs rather than svgs-full (FA7's 640x640 geometry against the committed 448x512) and pepicons onto svg/pop rather than svg/print.

It deliberately does not settle everything, and the limit is worth knowing because it is structural rather than a tuning problem. Trigrams over a whole file are dominated by the path data, so two variants that draw the identical shape and differ only in colour attributes score nearly the same. That is exactly cryptocurrency-icons -- svg/black and svg/white share every path and differ by one fill -- and it is why those stay ambiguous rather than being settled by a metric that cannot see the difference. Reporting the tie is the correct outcome there; a threshold tuned until it happened to pick black would be fitting the constant to two cases and would settle the next one wrongly and silently.

func SortResolutions

func SortResolutions(rs []Resolution)

SortResolutions orders a report: the ones needing a human first, because that is the list somebody has to act on.

func Summary

func Summary(rs []Resolution) map[Confidence]int

Summary counts resolutions by confidence.

Types

type Candidate

type Candidate struct {
	// Dir is the path inside the extracted package.
	Dir string

	// Present is how many of the set's icons this directory also has, by name.
	Present int

	// Identical is how many of those are byte-for-byte the same.
	Identical int

	// Extra is how many icons the directory has that the set does not.
	Extra int

	// Depth is the total SVG count in the subtree, used only to prefer the
	// tightest directory among equally good ones.
	Depth int

	// Rivals are directories that scored identically, are not this one seen
	// from a different level, and hold *different bytes*. A non-empty list
	// with no byte matches means the scorer has no basis left for choosing --
	// see rivalsOf.
	Rivals []string

	// Content digests the matched icons, so two directories that tie can be
	// asked whether they actually differ.
	Content string

	// Similarity and Runner record a settled tie: how closely this directory
	// resembles the committed icons, and how closely the next best one did.
	// Both are zero when no tie arose.
	Similarity float64
	Runner     float64
}

Candidate is one directory inside a fetched upstream, scored against a set.

func BestDirectory

func BestDirectory(root string, fp SetFingerprint) (Candidate, error)

BestDirectory walks an extracted package and returns the directory that best reproduces the set.

Every directory holding SVGs is scored, not just the likely ones: upstreams put them in `icons/`, `dist/icons/`, `svg/`, `src/svg/`, `24/solid/` and several other places, and hardcoding that list is how a real source gets reported as unresolved.

func ScoreDirectory

func ScoreDirectory(dir string, fp SetFingerprint) (Candidate, error)

ScoreDirectory compares a directory and everything under it against a set.

Recursive, and that is the point. Several sets keep their upstream's subdirectory structure -- fontawesome ships brands/, regular/ and solid/ and the pack vendors all three -- so the directory that actually corresponds to the set is a *parent* holding no SVGs of its own. Scoring only direct children never sees it, and the best a non-recursive scan could report was one variant: 1,758 of fontawesome's 2,284 icons, graded "partial", when the real answer is svgs/ and covers all of them.

func (Candidate) Score

func (c Candidate) Score() float64

Score ranks candidates: byte-identical matches dominate, then name overlap.

Name overlap alone is not enough to accept a directory. Two icon sets built from the same design language share a great many names -- `home`, `user`, `search` -- so a directory can look like a strong match and be a different project entirely. Only a byte-identical file proves the file came from here.

type Confidence

type Confidence string

Confidence classifies a candidate against the set it was scored on.

const (
	// ConfidenceExact means every committed icon was reproduced byte for byte.
	// The upstream and the path are then established fact, not inference.
	ConfidenceExact Confidence = "exact"

	// ConfidenceStrong means most icons matched byte for byte. Usually the
	// upstream is right and its version has moved on since the pack vendored
	// it, so some icons were redrawn.
	ConfidenceStrong Confidence = "strong"

	// ConfidencePackage means nearly every icon is present by name but the
	// bytes differ -- the upstream is identified, the version is not.
	//
	// The coverage floor is deliberately the same 90% the refresh's retention
	// guard uses. Below that the guard refuses to replace the directory
	// anyway, so a stricter manifest threshold only rejects entries the
	// refresh would have accepted, while admitting none it would refuse.
	// Measured, 95% excluded @mapbox/maki for maki-icons at 198 of 211 --
	// unmistakably the right project, rejected over thirteen retired icons.
	//
	// This tier exists because of what the audit found. ionicons matched
	// 1356 of 1356 names with zero byte-identical files: the committed icons
	// expand what upstream now expresses as CSS classes into explicit
	// fill/stroke attributes, and write path data with comma separators. That
	// is an older release of the same project, not a different project. Grading
	// it "partial" alongside a genuine near-miss would bury the distinction a
	// human most needs: here the remaining work is pinning a version, not
	// identifying a source.
	ConfidencePackage Confidence = "package"

	// ConfidenceAmbiguous means the set was matched, and matched equally well
	// by two or more directories that are not the same icons seen from
	// different depths. Coverage cannot choose between them and no file is
	// byte-identical, so there is nothing left to decide on -- picking one
	// would be picking whichever the directory walk reached last.
	//
	// It is graded separately from "partial" because the remaining work is
	// different in kind. A partial result needs a better candidate package; an
	// ambiguous one has the right package already and needs a human to say
	// which variant the pack vendored.
	ConfidenceAmbiguous Confidence = "ambiguous"

	// ConfidencePartial means some names line up but coverage is incomplete.
	// That is the dangerous middle: two icon sets from the same design
	// language share a great many names, so it may be a different project.
	ConfidencePartial Confidence = "partial"

	// ConfidenceNone means nothing lined up.
	ConfidenceNone Confidence = "none"
)

func Classify

func Classify(c Candidate, setSize int) Confidence

Classify grades a candidate against the set size.

Two independent signals, deliberately kept apart. Byte identity establishes the version as well as the source; name coverage establishes only the source. Collapsing them loses the difference between "found it, needs a version" and "might be the wrong project entirely".

type Fetcher

type Fetcher interface {
	Fetch(ctx context.Context, pkg, dest string) (version string, err error)
}

Fetcher retrieves an npm package into a directory and reports its version.

type Manifest

type Manifest struct {
	// Pack is the composer name, recorded so a manifest cannot be pointed at
	// the wrong pack by being copied.
	Pack string `json:"pack"`

	// Sets maps a vendored set directory to its upstream.
	Sets map[string]SetSource `json:"sets"`
}

Manifest records where each vendored set comes from.

It lives in its own file beside the pack config -- config/<pack>.sets.json -- rather than as a key inside it. That is deliberate and temporary: the Python is still the Docker entrypoint, its PackConfig rejects unknown keys, and a new key in the shipped config would break every Python command for this pack during the overlap. A separate file the Python never opens has no such effect. Fold it in once the Python is gone.

func LoadManifest

func LoadManifest(configDir, packName string) (*Manifest, error)

LoadManifest reads the manifest for a pack.

func ManifestFromResolutions

func ManifestFromResolutions(pack string, rs []Resolution) *Manifest

ManifestFromResolutions builds a manifest from an audit run.

Only entries the audit actually established are included. A `partial` or `none` result is left out rather than written with a warning: a manifest is the input to something that overwrites a set directory, and an entry that is present but wrong replaces a set's icons with another project's. Absent means "not refreshed yet", which is safe; present-but-wrong is not.

func (*Manifest) Save

func (m *Manifest) Save(path string) error

Save writes a manifest, sorted and indented so a diff shows only what moved.

func (*Manifest) SetNames

func (m *Manifest) SetNames() []string

SetNames returns the sets in a stable order.

func (*Manifest) Unresolved

func (m *Manifest) Unresolved(sets []string) []string

Unresolved returns the sets present in the pack but absent from the manifest.

A refresh reports these rather than skipping them silently: an aggregator pack that quietly stops refreshing a third of itself is the failure this whole exercise exists to avoid.

type NpmFetcher

type NpmFetcher struct{ Log *slog.Logger }

NpmFetcher shells out to npm pack, the same way the sources package does.

func (NpmFetcher) Fetch

func (f NpmFetcher) Fetch(ctx context.Context, pkg, dest string) (string, error)

Fetch downloads and extracts a package, returning the version npm resolved.

type Resolution

type Resolution struct {
	Set        string     `json:"set"`
	Icons      int        `json:"icons"`
	Package    string     `json:"package,omitempty"`
	Version    string     `json:"version,omitempty"`
	Path       string     `json:"path,omitempty"`
	Matched    int        `json:"matched"`
	Extra      int        `json:"extra"`
	Rivals     []string   `json:"rivals,omitempty"`
	Identical  int        `json:"identical"`
	Confidence Confidence `json:"confidence"`
	Note       string     `json:"note,omitempty"`
}

Resolution is one set's answer.

func ResolveSet

func ResolveSet(ctx context.Context, setDir string, fetch Fetcher, workDir string, log *slog.Logger, candidates ...string) Resolution

ResolveSet identifies the upstream for one committed set.

Each candidate package is fetched and every directory in it scored against the committed icons. The first candidate that reproduces the set exactly wins immediately; otherwise the best-scoring one across all candidates is reported with its confidence, so a partial match is visible rather than silently accepted.

type SetFingerprint

type SetFingerprint struct {
	Name   string
	Hashes map[string]string // icon name (no extension) -> sha256

	// Root is the committed set directory, kept so a tie between candidate
	// directories can be settled by reading the icons rather than by the order
	// the walk happened to reach them. See Similarity.
	Root string
}

SetFingerprint is what a committed set looks like: its icon names and the content hash of each.

func FingerprintSet

func FingerprintSet(dir string) (SetFingerprint, error)

FingerprintSet reads a committed set directory.

Keyed by the path relative to the set root, not by the leaf name. Several sets keep their upstream's subdirectory structure -- fontawesome vendors brands/, regular/ and solid/ -- and a leaf-name key counts one committed icon once for every variant directory that happens to contain the same name, so fontawesome scored 5,068 matches against a set of 2,284 and the best directory came out as the package root. Relative paths make the comparison structural, and a flat set is the case where the relative path is just the filename, so nothing is lost there.

func (SetFingerprint) Count

func (f SetFingerprint) Count() int

Count returns how many icons the set ships.

type SetSource

type SetSource struct {
	// Package is the npm package the icons come from.
	Package string `json:"package"`

	// Version pins the release. Empty means the registry's `latest`, which is
	// what a refresh normally wants; a pin is for a set whose upstream has
	// changed format and whose migration has not been taken yet.
	Version string `json:"version,omitempty"`

	// Path is the directory inside the extracted package holding the SVGs.
	// Mutually exclusive with Variants.
	Path string `json:"path,omitempty"`

	// Variants merges several upstream directories into one flat set, which
	// is what a pack does when it vendors a multi-variant upstream under one
	// directory and distinguishes the variants by an affix on the filename.
	//
	// A single Path cannot express that, and the failure is not a partial
	// refresh but a destructive one: the sink wipes the set first, so
	// pointing Path at heroicons' 24/solid would refresh a quarter of the
	// icons and delete the other three quarters. Three sets in this pack are
	// this shape -- heroicons, google-material-design-icons and teeny-icons.
	Variants []Variant `json:"variants,omitempty"`

	// Separator normalises the character upstream puts between words when the
	// pack spells them differently. Only google-material-design-icons needs
	// it: upstream ships `18_up_rating` against the pack's `18-up-rating`.
	Separator string `json:"separator,omitempty"`

	// Confidence is how the entry was established, carried over from the audit
	// so a reader can tell a measured entry from an asserted one. An entry
	// written by hand and never verified should say so.
	Confidence Confidence `json:"confidence,omitempty"`

	// Note carries anything a human needs to know before trusting it.
	Note string `json:"note,omitempty"`
}

SetSource is one set's upstream.

type Variant

type Variant struct {
	// Path is the directory inside the extracted package.
	Path string `json:"path"`

	// Prefix and Suffix mark this variant's filenames. A variant carrying
	// neither is the unmarked one, which is how teeny-icons spells `solid`.
	Prefix string `json:"prefix,omitempty"`
	Suffix string `json:"suffix,omitempty"`
}

Variant is one upstream directory inside a flattened set, with the affix that distinguishes its icons once every variant shares a directory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL