@toruslabs/torus-scripts

中文文档
9.0.0发布于 2026/11/03MITTypeScriptES Module零依赖

Vite+ build and format presets with a read-only migration diagnostic

原始使用文档
文档目录6 节
  1. Install
  2. Build presets
  3. Format
  4. Lint
  5. Upgrade from the old CLI
  6. TypeScript profiles

@toruslabs/torus-scripts

Vite+ config fragments for libraries, React, and Node packages. The presets do not install framework build plugins.

Install

Install @toruslabs/torus-scripts and vite-plus in your project.

Build presets

  • @toruslabs/torus-scripts/library: libraryPreset({ entry: "src/index.ts" }) for ESM library builds.
  • @toruslabs/torus-scripts/react: reactPreset() selects the automatic JSX runtime. Add @vitejs/plugin-react for Fast Refresh or its transforms.
  • @toruslabs/torus-scripts/node: nodePreset({ entry: "src/index.ts" }) targets Node and keeps dependencies external. Use a separate build for decorator metadata.

Compile Vue single-file components with @vitejs/plugin-vue in your project. Use libraryPreset({ entry: "src/index.ts" }) for the pack.

These fragments do not set CSS injection, browser targets, assets, SSR transforms, or use client. Set these options in your project.

Format

formatPreset() is at @toruslabs/torus-scripts/fmt. It sets 150 columns, double quotes, semicolons, ES5 trailing commas, and import sorting. It does not sort exports.

import { formatPreset } from "@toruslabs/torus-scripts/fmt";
import { defineConfig } from "vite-plus";

export default defineConfig({ fmt: formatPreset() });

Lint

Install one of @toruslabs/oxlint-config-typescript, @toruslabs/oxlint-config-react, @toruslabs/oxlint-config-vue, or @toruslabs/oxlint-config-node. The TypeScript preset checks both JavaScript and TypeScript. React, Vue, and Node extend it. This package does not export /lint or /vue-lint.

The Vue preset enables only the Vize template rules in vueTemplateRules, and fixture tests prove each one. It uses the Vize Oxlint plugin through vp lint and vp check. These commands can skip a .vue file that has no <script> block, so they do not check template-only files. The preset's native no-unused-vars options report unused arguments and caught errors in .ts files, but vp lint does not report that rule for .vue script blocks. Run a separate check for these gaps and verify it in your project.

React and Vue each export an optional tailwindLintPreset({ entryPoint: "src/styles.css" }) fragment. Install oxlint-tailwindcss if you use this fragment. Vue projects import it from @toruslabs/oxlint-config-vue, not the React package.

Do not combine the fragment and a framework preset with a plain object spread. { ...vueLintPreset(), ...tailwindLintPreset({ entryPoint }) } replaces jsPlugins, rules, and settings. This removes the Vize rules and oxlint-plugin-vize, or the React Hooks rules, and lint can still exit 0. Merge each field:

import { tailwindLintPreset, vueLintPreset } from "@toruslabs/oxlint-config-vue";
import { defineConfig } from "vite-plus";

const framework = vueLintPreset();
const tailwind = tailwindLintPreset({ entryPoint: "src/styles.css" });

export default defineConfig({
  lint: {
    ...framework,
    jsPlugins: [...(framework.jsPlugins ?? []), ...(tailwind.jsPlugins ?? [])],
    rules: { ...framework.rules, ...tailwind.rules },
    settings: { ...framework.settings, ...tailwind.settings },
  },
});

For React, import reactLintPreset and tailwindLintPreset from @toruslabs/oxlint-config-react and merge the same fields. Tailwind class checks run on JS, TS, JSX, and TSX, including supported Vue script blocks; they do not check Vue template classes or CSS files.

The old @toruslabs/eslint-config-* packages are removed. Do not treat an Oxlint rule as equal to an old ESLint rule until you test it in your project.

Upgrade from the old CLI

The package includes an agent skill at skills/migrating-to-torus-cli/SKILL.md. In a consumer project, read it at node_modules/@toruslabs/torus-scripts/skills/migrating-to-torus-cli/SKILL.md. To make it available as a project skill in Cursor, copy it to .cursor/skills/migrating-to-torus-cli/SKILL.md in that project. Keep the skill and this README from the same package version.

Run torus-scripts-upgrade <path> to inspect an old project without changing files. It reports unsupported custom behavior and exits nonzero for those cases. Run vp migrate at the workspace root, not inside each package, and review its changes. The diagnostic does not run vp migrate for you.

Replace the old commands:

  • torus-scripts build → define pack in the consumer's vite.config.ts, then run vp pack.
  • torus-scripts lint → select an Oxlint package, set root lint and fmt config, then run vp check.
  • torus-scripts start → set the consumer's Vite+ dev task. No shared dev server ships.
  • torus-scripts release → use Changesets at the repository root.
  • Lerna workspace tasks → run vp run -r build with explicit build tasks.

TypeScript profiles

@toruslabs/config exports tsconfig.base.json, tsconfig.library.json, and tsconfig.node.json. Replace tsconfig.default.json or tsconfig.build.json with the matching profile.

版本与发布记录

@toruslabs/torus-scripts 共发布 97 个版本,首次发布于 2021/11/03;过去 12 个月发布了 4 个版本。

版本发布日期距今
9.0.0latest2026/11/03今天
8.1.02026/05/215 个月前
8.0.12026/03/048 个月前
8.0.02026/01/239 个月前
7.1.62025/04/191.5 年前
7.1.52025/03/261.6 年前

关于 @toruslabs/torus-scripts 的常见问题

@toruslabs/torus-scripts 是什么?

使用只读迁移诊断来构建和格式化预设

如何安装 @toruslabs/torus-scripts?

在项目目录运行 npm install @toruslabs/torus-scripts,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vite-plus(^1.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 torus-scripts-upgrade,可以用 npx torus-scripts-upgrade 直接运行。

@toruslabs/torus-scripts 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@toruslabs/torus-scripts 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@toruslabs/torus-scripts 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.22.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@toruslabs/torus-scripts 可以商用吗?

@toruslabs/torus-scripts 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@toruslabs/torus-scripts 还在维护吗?

最新版本 9.0.0 发布于 2026/11/03(今天);至今共发布 97 个版本,其中过去 12 个月发布了 4 个;首次发布于 2021/11/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。