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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@yinpo/node-scripts

v0.0.12

Published

some common node scripts, like version-check, export-all and etc.

Downloads

29

Readme

node script

installation

npm i -D @yinpo/node-scripts

脚本目录:

version check

检查指定目录下package.json中的version字段是否有更新,如果当前version小于等于线上的version,则会返回错误码1。

防止在npm publish进行自动发布时,被npm拦截。

默认是拉取npm上对应name的包,也可以通过传递target参数指定github url进行对比。

  1. 参数
function versionCheck(projectPathArr: string[], target?: string): void

projectPathArr 表示项目根路径

  1. 引用

在项目指定文件下引入该脚本,例如:

// /script/versionCheck.js
#!/usr/bin/env node

require('@yinpo/node-scripts').versionCheck([__dirname, '..'])

因为脚本路径为 /script/versionCheck.js, 所以传入路劲数组 [__dirname, '..'] 表示的是根路径 /

最终脚本寻找的是/package.json中的version字段

  1. 使用

当定义好了脚本的路径之后,可以在一些自动化工具中使用。

例如在huskypre-push脚本中检查version字段,防止version字段没有更新有推到remote上。

这样能够让github action很安全的执行 npm publish 指令。

#!/bin/sh
while read local_ref local_sha remote_ref remote_sha
do
    branch_name="${remote_ref##refs/heads/}"

    # 如果分支名称为 'main' ,则执行特定逻辑
    if [[ "$branch_name" == "main" ]]; then

        node "scripts/versionCheck.js"
        checkResult=$?

        # 在此处添加你想要运行的其他命令
        if [ $checkResult -eq 1 ]; then
          echo "脚本中止!"
          exit 1
        fi
    fi

done

version check如果识别到remote与local的version字段相同,则会终止脚本并返回状态码1

export all

自动引用指定路径下的所有index.jsindex.ts 文件中导出的内容,整合到根路径下 /index.ts/index.js

  1. 参数
function exportAll(projectPathArr: string[], targetDir: string,  mode?: 'esm' | 'cjs' = "esm"): void

projectPathArr 表示项目根路径

targetDir 在项目根路径的基础下,指定的目标文件夹,会从该路径下扫描所有的导出

mode 表示采用哪种模块化规范输出

  1. 引用

在项目指定文件下引入该脚本,例如:

// /script/exportAll.js
#!/usr/bin/env node

require('@yinpo/node-scripts').exportAll([__dirname, '..'], 'src')

因为脚本路径为 /script/exportAll.js, 所以传入路劲数组 [__dirname, '..'] 表示的是根路径 /

最终脚本扫描的目标路径是/src下的所有文件夹中index.js或index.ts

/src 下的所有文件夹会被取 index.jsindex.ts 的所有导出。只有第一层下才有效,多层文件夹嵌套不会扫描。

/src 下的所有第一层文件会被扫描,然后输出所有导出。

  1. 使用

可以在package.json中定义脚本,然后在自动化处理流程中执行改脚本,例如:

{
  "scripts": {
    "build": "node ./scripts/exportAll.js && rollup -c"
  }
}

然后在一些自动化工具中直接执行 npm run build 即可。