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

sd-release-plus

v1.0.4

Published

Lightweight release script for Front-end project

Readme

sd-release-plus

使用

安装

pnpm add -D  sd-release-plus

根路径新增发布脚本 scripts/release.ts

import defaultMain from sd-release-plus;
defaultMain();

package.json 增加 scripts 钩子

For example:

{
  "scripts": {
    "release": "ts-node ./scripts/release.ts"
  },
  "devDependencies": {
    "sd-release-plus": "^1.0.0"
  }
}

执行脚本

pnpm run release

默认发布流程

  • 选择升级版本 ->
  • 修改 package.json 的版本号 ->
  • 填写 commit 信息(校验格式,不通过终止) ->
  • 推送到代码仓库(推送失败会帮你把 package.json 里的版本回退) ->
  • 生成 changeLog ->
  • build 打包(这里执行的是 pnpm run build 所以你的 scripts 里必须有 build 命令,要不执行失败) ->
  • 发布包(执行的 npm publish --access=public 命令) ->
  • 打 tag 并且推送到 git 仓库

自定义流程

上面几个流程是这个包自带流程顺序,你可以配自己的顺序,

import { getNextVersion, gitPush, setChangelog, build, publishNpm, addTag, compose } from '@mx-design/release';

// getNextVersion 获取下个版本号函数
// updateVersion 修改版本号 返回值是回退版本号的函数
// gitPush push代码函数
// setChangelog 设置changeLog函数
// build 执行npm run build函数
// publish 执行npm publish函数
// addTag 打tag函数
// compose函数组合器

// 使用方法,这些函数顺序可以自己换位置,或者增删减
const middle = [getNextVersion, updateVersion, gitPush, setChangelog, build, publishNpm, addTag];

function execRelease() {
  compose(middle);
}

中间件原理

// compose 函数
export function compose(middleware) {
  // 共享数据仓库,每个函数都可以往里面加数据,所有函数都可以访问到里面的数据
  const otherOptions = {};
  // 函数发射器,一个函数执行完毕调用next(),就执行下一个函数
  function dispatch(index, otherOptions) {
    // 每次从middleware中间件里面选取一个函数执行,直到执行了全部函数
    if (index == middleware.length) return;
    const currMiddleware = middleware[index];
    // 执行函数,传入了一下一个函数的dispatch,已经更新共享数据
    currMiddleware((addOptions) => {
      dispatch(++index, { ...otherOptions, ...addOptions });
    }, otherOptions).catch((error) => {
      console.log('💣 发布失败,失败原因:', error);
    });
  }
  dispatch(0, otherOptions);
}
// middleware 写法

// 获取版本号函数,固定参数第一个是next,表示调用middleware里下一个函数
const getNextVersion = async (next) => {
  // _selectNextVersion会查看你package.json里的version参数是啥版本
  const nextVersion = await _selectNextVersion();
  // 缓存老的package.json数据,为了后面可以回退版本有老版本数据做准备
  const originPackageJson = getOriginPackageJson();
  // next传入的数据都会放到共享数据仓库,下面的函数都可以拿到这些数据
  next({
    nextVersion,
    originVersion: originPackageJson.version,
    originPackageJson,
  });
};

// 更新版本号方法
const updateVersion = async (next, otherOptions) => {
  if (!otherOptions?.nextVersion) {
    throw new Error('请传入package.json新版本号');
  }
  // 返回一个回退版本号的方法,上面的函数共享的originPackageJson数据就是给他用的
  // basicCatchError如果命令执行失败,就打印失败原因,并且返回false
  const backVersionFn = await _updateVersion(otherOptions.nextVersion, otherOptions.originPackageJson).catch(
    basicCatchError,
  );
  // 把回退版本的函数共享出来,给下面需要用的地方自己调用
  next({ backVersionFn });
};
// 调用
compose([getNextVersion, updateVersion]);