Skip to content

Add JSR package validation hook #7

@drernie

Description

@drernie

Summary

Add deno-jsr-check built-in hook to validate JSR package metadata and structure before publishing, catching common issues early.

Motivation

Publishing to JSR requires:

  • Specific deno.json structure
  • Valid exports configuration
  • Proper versioning
  • README and documentation
  • License information

Catching these issues in a pre-push hook saves time and prevents publishing failures.

Proposed Solution

hooks:
  pre-push:
    - id: jsr-validate
      run: deno-jsr-check
      config:
        checkExports: true
        checkVersion: true
        checkReadme: true
        checkLicense: true
        checkDocs: true

Implementation

Built-in hook that validates:

  1. Exports field: Ensure deno.json has valid exports
// Check that all export paths exist
const config = JSON.parse(await Deno.readTextFile("deno.json"));
for (const [name, path] of Object.entries(config.exports)) {
  if (!await exists(path)) {
    violations.push(`Export "${name}" points to non-existent ${path}`);
  }
}
  1. Version format: Validate semver in package.json/deno.json
const version = config.version;
if (!version.match(/^\d+\.\d+\.\d+$/)) {
  violations.push(`Invalid version format: ${version}`);
}
  1. README: Ensure README.md exists and has content
  2. License: Check for LICENSE file
  3. Documentation: Verify JSDoc on public exports
  4. Package name: Validate format (@scope/name)

Configuration Options

  • checkExports: Validate exports field (default: true)
  • checkVersion: Validate version format (default: true)
  • checkReadme: Require README.md (default: true)
  • checkLicense: Require LICENSE file (default: true)
  • checkDocs: Validate JSDoc comments (default: false)
  • minReadmeLength: Minimum README length in chars (default: 100)

Example Validations

Missing export:

❌ JSR validation failed:
  - Export "./install" points to non-existent src/install.ts

Invalid version:

❌ JSR validation failed:
  - Invalid version format: "1.0" (expected semver like "1.0.0")

Missing README:

❌ JSR validation failed:
  - README.md not found (required for JSR publishing)

Benefits

  • ✅ Catch publishing issues before push
  • ✅ Ensure JSR package quality
  • Ecosystem play - Help grow JSR adoption
  • Unique to Deno - JSR-specific validation
  • ✅ Save time vs failed publishes

Use Cases

Library authors:

hooks:
  pre-push:
    - id: jsr-ready
      run: deno-jsr-check
      config:
        checkExports: true
        checkVersion: true
        checkReadme: true
        checkLicense: true
        checkDocs: true  # Ensure public APIs documented

Quick projects:

hooks:
  pre-push:
    - id: jsr-basic
      run: deno-jsr-check
      config:
        checkExports: true
        checkVersion: true

Files to Modify

  • src/executor.ts - Add denoJsrCheck built-in hook
  • Create src/jsr-validator.ts - JSR validation logic

Priority

LOW - High marketing value for JSR ecosystem, but niche use case. Good for "Phase 2" features.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions