npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lx-frontend/lixin-commit-prettier-split

v0.0.2

Published

自动拆分 commit 中的格式化与业务逻辑改动

Readme

@lx-frontend/lixin-commit-prettier-split

用于拆分「格式化改动」与「业务逻辑改动」的工具包,包含:

  • lx-commit-split:重组最近一次提交,拆成 style + 业务两条提交
  • pre-push-commit-split.sh:在 push 前检测并提示是否自动拆分

安装

npm i -D @lx-frontend/lixin-commit-prettier-split

命令

手动拆分最近一次提交

lx-commit-split

pre-push hook 使用

ln -sf ./node_modules/@lx-frontend/lixin-commit-prettier-split/pre-push-commit-split.sh .git/hooks/pre-push
chmod +x .git/hooks/pre-push

pre-push-commit-split 流程图(文本版)

  • 初始化与上下文定位

    • 切到仓库根目录
      • cd "$(git rev-parse --show-toplevel)" || exit 1
    • 清理 Git 前缀环境
      • unset GIT_PREFIX
    • 定义常量与状态文件
      • 全零 SHA:z40="0000000000000000000000000000000000000000"
      • 一次性跳过文件:split_skip_file="$(git rev-parse --git-dir)/.pre-push-commit-split-skip-once"
    • 获取当前 HEAD
      • current_head="$(git rev-parse HEAD 2>/dev/null || echo "")"
  • skip-once 快速放行

    • 如果存在 split_skip_file
      • 读取其中的 skip_sha
      • 删除该文件(一次性)
      • skip_sha == current_head
        • 直接 exit 0
        • 作用是避免“刚自动拆分后再次 push”被重复拦截
  • 单组 ref 处理函数 handle_ref_pair

    • 入参
      • local_ref local_sha remote_ref remote_sha
    • 删除分支场景放行
      • if [ "$local_sha" = "$z40" ]; then return 0; fi
    • 获取本次用于检测的文件(仅 M)
      • MODIFIED_FILES=$(git diff-tree --no-commit-id --name-only -r HEAD --diff-filter=M | grep -E "\.(js|ts|vue|jsx|tsx)$" || true)
    • 触发条件判断
      • if [ -n "$MODIFIED_FILES" ] && npx prettier --check $MODIFIED_FILES > /dev/null 2>&1; then
      • 含义:存在修改文件且这些文件已满足 prettier 结果 -> 认为应拆分 style/logic
    • 命中后进入交互
      • 打印告警:检测到已完成 prettier,建议拆分
      • exec < /dev/tty
      • read -p "是否运行 lx-commit-split 自动优化提交历史?[y/N] " yn
    • 用户选择分支
      • 选择 y/Y
        • 执行 npm run commit:split
        • 若成功
          • 记录新 HEADsplit_skip_file
          • 提示“历史已重构,请重新 push”
          • exit 1(中断本次 push,要求用户再 push 一次)
        • 若失败
          • exit 1
      • 其他输入(默认 N)
        • 不做拆分,继续后续流程(最终 exit 0
  • pre-push / 非 pre-push 两种入口

    • 若参数不足($# -lt 2
      • 构造兜底 ref(手动执行场景,避免阻塞)
      • 调一次 handle_ref_pair
    • 否则(真实 pre-push)
      • 循环读取 stdin 每行 ref 对
      • 每组调用 handle_ref_pair
  • 脚本结束

    • exit 0

测试命令

npm test
npm run test:shell
npm run test:shell:coverage