Skip to content

feat: validate the root package.json against the repository's kind - #49

Merged
kieronlanning merged 1 commit into
mainfrom
feat/package-json-validation
Nov 11, 2026
Merged

kieronlanning merged 1 commit into
mainfrom
feat/package-json-validation

Conversation

@kieronlanning

Copy link
Copy Markdown
Contributor

What

Adds an opt-in package.json validation step, plus a command that runs it in its own right.

  • purview-build package-validate [--format=json] — builds no pipeline, exits 0 when the file passes and 1 when it does not. Needs no configuration.
  • PackageJson:Enabled=true — adds ValidatePackageJsonModule (category Build, depends only on VersionModule) to the pipeline. Enabled for this repository.

Why

Every consuming repository has a root package.json, even a .NET one — it is where the release version lives — but nothing checks what else it declares. This holds it to the content a best-in-class package of the repository's kind should have: a name, a version, a description, a licence, and the details a consumer, a registry and a maintainer need.

How the project type changes the rules

Rules are not one list. The profile decides which apply and how severe a miss is:

Profile Resolved (with Auto) Meaning
DotNetNuGet ProjectType=DotNet, RunPack=true packs NuGet package(s); not published to npm
DotNetSolution ProjectType=DotNet, RunPack=false packs nothing
WebPackage ProjectType=Web, not private published to npm
WebApp ProjectType=Web, private: true an application, never published

So a four-part version is fatal for a published npm package (npm only accepts SemVer 2.0) and merely advisory for a .NET repository, where Version:Strictness=NuGet deliberately allows it. The npm-only rules — engines, entry points, files, keywords — are skipped outright for .NET, and every skipping is reported rather than hidden.

Fourteen permanent PKG0nn rules: name, version, description, licence, repository, author, homepage/bugs, keywords, private intent, engines, entry points, the scripts the run drives, the publish allow-list, plus PackageJson:AdditionalRequiredFields as the per-organisation escape hatch. A file that cannot be read or parsed is reported as PKG000 in the same shape as any other finding, never thrown.

Verification

  • Release build with --warnaserror: 0 warnings, 0 errors; just lint-check passes.
  • Build.UnitTests 1122 passed, Build.IntegrationTests 184 passed, Repository.UnitTests 18 passed (including the skill conformance suite for the new skill).
  • just package-matrix: 32 scenarios, 0 failed through the real CLI.
  • src/tests/fixtures/package-json-scenarios.json is the single specification: the TUnit suite and the CLI matrix read the same file, so the shipped binary and the in-process runner cannot drift apart. AllScenarios_ExerciseEveryRule fails if a rule has no case.

Docs

docs/wiki/Package-Json-Validation.md (new), the Configuration Reference, Pipeline Modules, Architecture, Local Development, Home/Sidebar, README, AGENTS.md (extending the permanent-rule-ID invariant to PKG0nn), the regenerated configuration schema, and a new skills/purview-build-package-json skill.

No version bump, so merging this does not release.

Add ValidatePackageJsonModule, an opt-in pipeline step, and a standalone
`purview-build package-validate` command that checks the root package.json
against the content a best-in-class package of the repository's kind should
declare: a .NET repository that packs NuGet packages, one that packs
nothing, a published npm package, or a web application.

Fourteen permanent PKG0nn rules cover the name, version, description, licence,
repository, author, homepage/bugs, keywords, the `private` flag, engines,
entry points, the scripts the run drives, the publish allow-list, and
repository-configured additional fields. Severity is profile-dependent: a
four-part version is fatal for a published npm package, because npm requires
SemVer 2.0, and merely advisory for a .NET repository, while the npm-only
rules are skipped outright for .NET.

The module is category Build and depends only on VersionModule, so enabling it
can never reorder pack or publish. A file that cannot be read or parsed is
reported as PKG000 in the same shape as any other finding, never thrown.

The declarative fixture src/tests/fixtures/package-json-scenarios.json holds 32
cases and drives both the TUnit suite and `just package-matrix`, which runs
each case through the real CLI, so the shipped binary and the in-process
runner are held to one specification.

Documented in docs/wiki/Package-Json-Validation.md, the Configuration
Reference, the Pipeline Modules page and a new skills/purview-build-package-json
skill; the configuration schema is regenerated and the check is enabled for
this repository.
@kieronlanning
kieronlanning enabled auto-merge (squash) November 11, 2026 17:19
@kieronlanning
kieronlanning merged commit 449654c into main Nov 11, 2026
4 checks passed
@kieronlanning
kieronlanning deleted the feat/package-json-validation branch November 11, 2026 17:20
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.

1 participant