Skip to content

Fix JSR bug + Major simplification (v0.3.0)#10

Merged
drernie merged 19 commits intomainfrom
9-jsr-install-path-bug
Dec 15, 2025
Merged

Fix JSR bug + Major simplification (v0.3.0)#10
drernie merged 19 commits intomainfrom
9-jsr-install-path-bug

Conversation

@drernie
Copy link
Contributor

@drernie drernie commented Dec 15, 2025

Summary

This PR includes:

  1. Bug fix for JSR installation paths (issue Hook installation generates invalid file paths from JSR #9)
  2. Version management tooling with dev pre-release support
  3. Major architectural simplification (v0.3.0) - self-contained hooks with simple command arrays

Part 1: Bug Fix (Issue #9)

Changes

  • Fixed JSR installation path generation (src/install.ts)
    • Detects JSR installations with import.meta.url.startsWith("jsr:")
    • For JSR: Uses .href to preserve full jsr:@scope/package@version/path format
    • For local: Uses .pathname for absolute filesystem path
    • Previously generated invalid paths like /@theswanfactory/deno-hooks/0.2.0/src/run.ts
    • Now generates valid paths like jsr:@theswanfactory/deno-hooks@0.2.0/src/run.ts

Test Improvements

  • Strengthened integration test validation to catch path format bugs

Part 2: Version Management

New Features

  • Added comprehensive version management script (scripts/version.ts)

    • deno task version - Display current version
    • deno task version patch/minor/major - Bump version automatically
    • deno task version tag - Create and push release tag
    • deno task version dev - Create dev pre-release tag
  • Dev pre-release workflow for testing JSR installations

    • deno task tag-dev - Runs tests and creates timestamped dev tag
    • deno task tag - Runs tests and creates stable release tag
    • Dev versions use format: 0.3.0-dev.1734197345

Part 3: Major Architectural Simplification (v0.3.0)

Breaking Changes

Simplified Configuration Format

Before (v0.2.x):

hooks:
  pre-commit:
    - id: deno-fmt
      run: deno-fmt
      glob: "*.{ts,js}"
      pass_filenames: true

After (v0.3.0):

hooks:
  pre-commit:
    - deno task fmt
    - deno task lint

Self-Contained Hook Scripts

Generated hooks are now standalone bash scripts with no dependencies on deno-hooks:

#!/bin/sh
# Generated by deno-hooks - DO NOT EDIT
# To update, run: deno task hooks

set -e

deno task fmt
deno task lint

echo "✓ All hooks passed"

What Was Removed

  • ❌ Built-in hooks (deno-fmt, deno-lint, deno-test) - use deno task instead
  • ❌ File glob pattern matching and pass_filenames logic
  • ❌ Runtime execution system (src/run.ts, src/executor.ts, src/files.ts)
  • ❌ Complex hook type definitions (src/hook.ts)
  • ❌ 200+ lines of complex code

What Was Added

  • ✅ Self-contained hook scripts (work without deno-hooks installed)
  • ✅ Support for ANY shell command (not just deno commands)
  • ✅ Success message "✓ All hooks passed"
  • ✅ New examples: advanced.yml and deno-json-config.json
  • ✅ Fail-fast behavior with set -e

Benefits

  1. Simpler: No complex file filtering or built-in hooks
  2. Transparent: Generated hooks are readable shell scripts
  3. Portable: Hooks work without deno-hooks installed
  4. Flexible: Users can run ANY command (deno, npm, custom scripts)
  5. Debuggable: Easy to see what's happening
  6. No Magic: Just runs commands in order

Files Modified

Core implementation:

Files removed:

  • src/run.ts (deleted)
  • src/executor.ts (deleted)
  • src/files.ts (deleted)
  • src/hook.ts (deleted)

Documentation:

Examples:

Tests:

Migration Guide

For Existing Users (v0.2.x → v0.3.0)

  1. Update your configuration file (deno-hooks.yml or deno.json):

    • Change from hook objects to simple command strings
    • Replace built-in hooks (deno-fmt) with deno task fmt
    • Remove glob, pass_filenames, etc.
  2. Define tasks in deno.json:

    {
      "tasks": {
        "fmt": "deno fmt --check",
        "lint": "deno lint",
        "test": "deno test -A"
      }
    }
  3. Run deno task hooks to reinstall with new format

Test Results

All tests passing:

  • ✅ Unit tests: 2/2 passed
  • ✅ Integration tests: 4/4 passed
    • Hook script is self-contained
    • Hooks catch bad formatting
    • Hooks catch lint errors
    • Hooks allow good commits

Closes

Fixes #9


🤖 Generated with Claude Code

- Fix critical bug: JSR installations now generate valid hook paths (fixes #9)
  * Detect JSR installations and use .href instead of .pathname
  * Preserves full jsr:@scope/package@version/path format
- Add comprehensive version management with deno task version command
  * Display current version
  * Bump patch/minor/major versions automatically
  * Create and push release tags
  * Built-in help and validation
- Improve integration test path validation
  * Extract and validate exact path format
  * Reject invalid paths like /@scope/package/...
@drernie drernie linked an issue Dec 15, 2025 that may be closed by this pull request
- Add 'deno task tag-dev' to create timestamped dev pre-releases
- Add 'deno task tag' to create stable releases with tests
- Add 'deno task test-all' combining unit and integration tests
- Update GitHub Actions to publish dev tags (v*.*.*-dev.*)
- Remove duplicate 'install' task from deno.json
- Dev versions use format: 0.2.1-dev.1734197345 (version-dev.timestamp)
- deno.json remains at stable version (no modifications for dev releases)
- Changed from 'deno add' which modifies local config
- Now uses 'deno run -A jsr:@Package@version' for non-invasive testing
- Updated PR description with correct test command
- Dev tags were publishing as stable releases (0.2.1 instead of 0.2.1-dev.*)
- Extract version from git tag and pass to deno publish --set-version
- Only apply --set-version for dev releases (contains '-dev.')
- Stable releases continue using version from deno.json

This fixes the issue where 0.2.1-dev.1765777443 was published as 0.2.1
- Upgrade denoland/setup-deno from v1 to v2
- Change deno-version from v1.x to v2.x
- Deno 2.x supports --set-version flag for dev pre-releases
- Allows publishing dev versions without modifying deno.json
- Change from timestamp-based (x.x.x-dev.timestamp) to incremental (x.x.x-dev.1, x.x.x-dev.2, etc.)
- Update deno.json with dev version before creating tag (JSR requirement)
- Commit version change automatically as part of dev release process
- Push both commit and tag together

This fixes the JSR publish error where version in config must match publish version.
- Add 'deno task version reset' to revert from dev to stable version
- Display warning when running 'deno task version' on dev version
- Prevent creating stable release tag when on dev version
- Auto-commit and push version reset changes
- Update help text with reset command and workflow examples
- Query git tags to find highest existing dev number
- Automatically increment to next available dev version
- Remove tag existence check (no longer needed with auto-increment)
- Example: If v0.2.1-dev.1 exists, automatically create v0.2.1-dev.2

This allows running 'deno task tag-dev' multiple times without manual cleanup.
- Remove git tag querying logic
- Only look at version in deno.json to determine next dev number
- If collision occurs, user will get an error (their responsibility)
- Simpler and more predictable behavior
- Changed from 'git commit -am' to 'git add deno.json && git commit -m'
- The -a flag was staging ALL modified files, bypassing hooks on unstaged changes
- Now only commits the specific file that was modified (deno.json)
- This ensures pre-commit hooks run on all committed code
@drernie drernie changed the title Fix JSR installation bug and add version management (v0.2.1) Fix JSR bug + Major simplification (v0.3.0) Dec 15, 2025
- Delete src/run.ts (no longer need runtime execution)
- Delete src/executor.ts (no more built-in hooks)
- Delete src/files.ts (no more file filtering logic)
- Delete src/hook.ts (no more complex type definitions)

Part of major architectural simplification to self-contained hooks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@drernie drernie merged commit 53ca265 into main Dec 15, 2025
3 checks passed
@drernie drernie deleted the 9-jsr-install-path-bug branch December 15, 2025 07: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.

Hook installation generates invalid file paths from JSR

1 participant