notice

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package notice contains the core types and orchestration for the NOTICE generator: the on-disk schema, the Collector interface, and the helpers that ecosystem packages use to assemble entries.

Index

Constants

View Source
const HeaderComment = `# Generated by hack/cmd/notice. DO NOT EDIT.
# Run 'make notice' to regenerate. Source: go.mod + frontend/package.json.
`

HeaderComment is the YAML comment block prepended to the rendered NOTICE.

Variables

This section is empty.

Functions

func Diff

func Diff(got, want string) string

Diff returns a minimal line-by-line summary of the differences between two rendered NOTICE bodies. It is intentionally tiny - just enough to point at what changed without pulling in a diff library.

func Render

func Render(doc *Document) ([]byte, error)

Render serializes the Document as YAML preceded by HeaderComment.

Types

type Collector

type Collector interface {
	// Name is a stable identifier used in the Entry.Ecosystem field and in
	// error messages. Examples: "go", "npm".
	Name() string

	// Precheck verifies the host has what the collector needs (e.g. an
	// installed `go` toolchain, a populated `node_modules`). The returned
	// error message is shown verbatim to the user.
	Precheck(root string) error

	// Collect returns one Entry per direct dependency.
	Collect(root string) ([]Entry, error)
}

Collector enumerates one ecosystem's direct dependencies and produces NOTICE entries. Implementations live under hack/cmd/notice/internal/<ecosystem>/.

Adding a new ecosystem is three steps:

  1. Create internal/<name>/ with a Collector implementation.
  2. Write hermetic tests using internal/testutil for fixtures.
  3. Append <name>.New() to the explicit collectors slice in main.go.

Collect MUST NOT sort its result; Build performs a global sort by Dependency across all collectors.

type Document

type Document struct {
	Notices []Entry `yaml:"notices"`
}

Document is the YAML root of the NOTICE file.

func Build

func Build(root string, collectors []Collector) (*Document, error)

Build runs precheck and collect on every collector and returns a Document with entries sorted alphabetically by Dependency.

type Entry

type Entry struct {
	Dependency string    `yaml:"dependency"`
	Ecosystem  string    `yaml:"ecosystem"`
	Copyright  []string  `yaml:"copyright"`
	License    []License `yaml:"license"`
}

Entry describes one direct dependency.

func AssembleEntry

func AssembleEntry(name, ecosystem, dir, repoBase, ref, declaredLicense string) (Entry, error)

AssembleEntry builds a NOTICE entry by reading the LICENSE file in dir, classifying it, extracting copyright lines, and rendering one License per classified license name pointing at the canonical blob URL.

declaredLicense is an optional ecosystem-supplied SPDX identifier (e.g. from npm's package.json "license" field). When non-empty, its friendly form is prepended to the classifier output if the classifier did not already emit it - this is the npm-recommended source of truth for ambiguous license texts.

Ecosystems compute (repoBase, ref) however they need to and pass them in.

type License

type License struct {
	Name string `yaml:"name"`
	Link string `yaml:"link"`
}

License attributes one license to a dependency, with a stable link to its authoritative text.

Jump to

Keyboard shortcuts

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