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

@winner-fed/plugin-run

v1.0.1

Published

@winner-fed/plugin-run

Readme

@winner-fed/plugin-run

🚀 一个用于在 WinJS 项目中运行 JavaScript/TypeScript 脚本的插件

功能特性

  • ✅ 支持运行 JavaScript 和 TypeScript 脚本
  • ✅ 内置 TypeScript 支持,无需额外编译
  • ✅ 支持全局导入配置
  • ✅ 支持向脚本传递参数
  • ✅ 使用 tsx 引擎,性能优异

安装

npm install @winner-fed/plugin-run --save-dev
# 或者
yarn add @winner-fed/plugin-run
# 或者
pnpm add @winner-fed/plugin-run

使用方法

基本用法

在项目根目录下的配置文件中注册插件:

// .winrc.ts
export default {
  plugins: ['@winner-fed/plugin-run'],
};

运行脚本

# 运行 JavaScript 脚本
win run scripts/build.js

# 运行 TypeScript 脚本
win run scripts/deploy.ts

# 传递参数给脚本
win run scripts/deploy.ts --env production --force

配置选项

globals

类型:string[]
默认值:[]

配置全局导入的模块,这些模块将在脚本执行前自动导入。

// .winrc.ts
export default {
  plugins: ['@winner-fed/plugin-run'],
  run: {
    globals: [
      'zx/globals',  // 自动导入 zx 的全局方法
      'dotenv/config', // 自动加载环境变量
    ],
  },
};

示例

基本脚本示例

创建一个简单的构建脚本:

// scripts/build.ts
import { execSync } from 'child_process';
import { readFileSync } from 'fs';

console.log('开始构建...');

// 读取 package.json
const pkg = JSON.parse(readFileSync('package.json', 'utf-8'));
console.log(`构建项目: ${pkg.name}@${pkg.version}`);

// 执行构建命令
execSync('npm run build', { stdio: 'inherit' });

console.log('构建完成!');

运行脚本:

win run scripts/build.ts

使用 zx 的脚本示例

配置全局导入 zx:

// .winrc.ts
export default {
  plugins: ['@winner-fed/plugin-run'],
  run: {
    globals: ['zx/globals'],
  },
};

创建使用 zx 的脚本:

// scripts/deploy.ts
// 由于配置了 globals,zx 的方法会自动导入

const environment = argv.env || 'development';
const force = argv.force || false;

console.log(`部署环境: ${environment}`);
console.log(`强制部署: ${force}`);

// 使用 zx 的 $ 方法执行命令
await $`npm run build`;

if (environment === 'production') {
  await $`npm run deploy:prod`;
} else {
  await $`npm run deploy:dev`;
}

console.log('部署完成!');

运行脚本:

win run scripts/deploy.ts --env production --force

带参数的脚本示例

// scripts/version.ts
import { execSync } from 'child_process';

// 获取命令行参数
const [, , version, ...flags] = process.argv;

if (!version) {
  console.error('请指定版本号');
  process.exit(1);
}

console.log(`更新版本到: ${version}`);
console.log(`额外标志: ${flags.join(' ')}`);

// 更新版本
execSync(`npm version ${version} ${flags.join(' ')}`, { stdio: 'inherit' });

console.log('版本更新完成!');

运行脚本:

win run scripts/version.ts 1.2.3 --no-git-tag-version

技术实现

  • 使用 tsx 作为 TypeScript 执行引擎
  • 支持 ES6+ 语法和 TypeScript 特性
  • 通过 child_process.fork 执行脚本
  • 自动处理依赖导入和模块解析

注意事项

  1. 脚本文件必须是 .js.ts 扩展名
  2. 脚本将在项目根目录的上下文中执行
  3. 支持所有 Node.js 内置模块和已安装的 npm 包
  4. 脚本可以通过 process.argvargv(如果使用 zx)访问命令行参数

许可证

MIT