antfu
Anthony Fu's opinionated tooling and conventions for JavaScript/TypeScript projects. Use when setting up new projects, configuring ESLint/Prettier alternatives, monorepos, library publishing, or when the user mentions Anthony Fu's preferences.
Choose how to use this skill
You do not need every option. Choose the path your AI client supports. The stable page stays the same; versioned files are immutable.
1. Native installer
This listing has no registered native installer command. Use the complete package or source fallback below, depending on what your client supports.
Do not guess an installer command or replace an existing version without reviewing the diff.
2. Complete package recommended
Download the ZIP when available. It includes SKILL.md plus the references, security notes and version metadata.
No complete ProSkills package is published for this listing yet.3. Prompt-only
Copy the prompt above when the agent can read the stable page or when you want to adopt the workflow without installing a skill.
Need only the instruction file?
Download SKILL.md only if your client requires a single file. The complete ZIP is safer for a full installation because it preserves the references and release context.
No path installs or executes anything by itself. Your agent still needs access to the project files. Before updating, compare the installed version and review the diff.
// RATINGS
Not yet listed on ClawHub or SkillsMP
// README
Anthony Fu's Skills
A collection of Agent Skills reflecting Anthony Fu's preferences, experience, and best practices, along with usage documentation for the tools.
[!IMPORTANT] This is a proof-of-concept project for generating agent skills from source documentation and keeping them in sync. I haven't fully tested how well the skills perform in practice, so feedback and contributions are greatly welcome.
Installation
This repo mainly hosts the skills. The recommended way to use them is @antfu/skills, a skills pack installed with skills-npm. Besides my own skills, the pack includes curated skills from other authors, and your package manager keeps them in sync:
pnpm i -D skills-npm @antfu/skills
pnpx skills-npm setup
See antfu/skills-pack for the full list of skills in the pack.
Install From This Repo
To install skills from this repo directly, use the skills CLI:
pnpx skills add antfu/skills --skill='*'
or to install all of them globally:
pnpx skills add antfu/skills --skill='*' -g
Skills
This repo includes skills from different sources with different scopes.
Hand-maintained Skills
Opinionated
Manually maintained by Anthony Fu with his preferred tools, setup conventions, and best practices.
| Skill | Description |
|---|---|
| antfu | Anthony Fu's preferences and best practices for app/library projects (eslint, pnpm, vitest, vue, etc.) |
| antfu-create-pr | Open reviewable PRs: Conventional Commits title, evidence-based body, before/after screenshots via gh --attach (adapted from moeru-ai/airi) |
| antfu-issue-triage | Triage issues and PRs of the current repo: find fixed, duplicate, and spam items, suggest labels, gauge demand, and confirm an action table before acting |
| antfu-query | Interview the user about a plan or decision in rounds via the agent's question tool until reaching shared understanding (adapted from mattpocock/skills) |
| antfu-simplify | Simplify the current PR or changes with an ablation study: keep only what is proven needed, with just-right abstraction, minimal, robust, and universal code |
[!TIP] For design, see antfu/design, which ships the
antfu-designskill alongside the@antfu/designpackage.
Skills Generated from Official Documentation
Unopinionated but with tilted focus (e.g. TypeScript, ESM, Composition API, and other modern stacks)
Generated from official documentation and fine-tuned by Anthony.
| Skill | Description | Source |
|---|---|---|
| vue | Vue.js core - reactivity, components, composition API | vuejs/docs |
| nuxt | Nuxt framework - file-based routing, server routes, modules | nuxt/nuxt |
| pinia | Pinia - intuitive, type-safe state management for Vue | vuejs/pinia |
| vite | Vite build tool - config, plugins, SSR, library mode | vitejs/vite |
| vitepress | VitePress - static site generator powered by Vite | vuejs/vitepress |
| vitest | Vitest - unit testing framework powered by Vite | vitest-dev/vitest |
| unocss | UnoCSS - atomic CSS engine, presets, transformers | unocss/unocss |
| pnpm | pnpm - fast, disk space efficient package manager | pnpm/pnpm.io |
FAQ
What Makes This Collection Different?
This collection is opinionated, but the key difference is that it clones the source documentation locally (into the git-ignored sources/) and generates skills directly from it. This provides more reliable context and allows the skills to stay up-to-date with upstream changes over time.
The project is also designed to be flexible - you can use it as a template to generate your own skills collection.
Skills vs llms.txt vs AGENTS.md
To me, the value of skills lies in being shareable and on-demand.
Being shareable makes prompts easier to manage and reuse across projects. Being on-demand means skills can be pulled in as needed, scaling far beyond what any agent's context window could fit at once.
You might hear people say "AGENTS.md outperforms skills". I think that's true — AGENTS.md loads everything upfront, so agents always respect it, whereas skills can have false negatives where agents don't pull them in when you'd expect. That said, I see this more as a gap in tooling and integration that will improve over time. Skills are really just a standardized format for agents to consume—plain markdown files at the end of the day. Think of them as a knowledge base for agents. If you want certain skills to always apply, you can reference them directly in your AGENTS.md.
Generate Your Own Skills
Fork this project to create your own customized skill collection.
- Fork or clone this repository
- Install dependencies:
pnpm install - Update
meta.tswith your own projects and skill sources - Run
pnpm start cleanupto remove existing sources and skills - Run
pnpm start initto clone the sources - Run
pnpm start syncto pull the latest source docs - Ask your agent to
Generate skills for \<project\>(recommended one at a time to manage token usage)
See AGENTS.md for detailed generation guidelines.
Sponsors
License
Skills and the scripts in this repository are MIT licensed.
// HOW IT'S BUILT
// FILES
7 files shipped with this skill. Inline text is the catalog copy. The upstream link is the source repository.
skills/antfu/SKILL.md7.7 KB148183c6edc2upstream ↗
--- name: antfu description: Anthony Fu's opinionated tooling and conventions for JavaScript/TypeScript projects. Use when setting up new projects, configuring ESLint/Prettier alternatives, monorepos, library publishing, or when the user mentions Anthony Fu's preferences. metadata: author: Anthony Fu version: "2026.09.30" --- > Reference template: [antfu/starter-ts](https://github.com/antfu/starter-ts). When scaffolding a new TypeScript project, mirror its `package.json` scripts, `eslint.config.js`, `knip.json`, `tsdown.config.ts` and workflows rather than inventing a new layout. ## Coding Practices ### Code Organization - **Single responsibility**: Each source file should have a clear, focused scope/purpose - **Split large files**: Break files when they become large or handle too many concerns - **Type separation**: Always separate types and interfaces into `types.ts` or `types/*.ts` - **Constants extraction**: Move constants to a dedicated `constants.ts` file ### Runtime Environment - **Prefer isomorphic code**: Write runtime-agnostic code that works in Node, browser, and workers whenever possible - **Clear runtime indicators**: When code is environment-specific, add a comment at the top of the file: ```ts // @env node // @env browser ``` ### TypeScript - **Explicit return types**: Declare return types explicitly when possible - **Avoid complex inline types**: Extract complex types into dedicated `type` or `interface` declarations ### Explicitness Favor explicit, traceable code over implicit "magic". A reader (human or agent) should be able to follow where every name comes from without running tooling. - **Explicit imports**: Prefer explicit `import` statements. Avoid auto-imports — when a framework provides them (e.g. Nuxt/Nitro), turn them off for new projects (see [app-development](references/app-development.md)). - **No path aliases by default**: Use relative imports (`./foo`, `../bar`). Only use path aliases (`@/`, `~/`, `#imports`, etc.) when they are *already* configured in the project; don't introduce new ones for greenfield code. ### Comments - **Avoid unnecessary comments**: Code should be self-explanatory - **Explain "why" not "how"**: Comments should describe the reasoning or intent, not what the code does ### Testing (Vitest) - Test files: `foo.ts` → `foo.test.ts` (same directory) - Use `describe`/`it` API (not `test`) - Use `toMatchSnapshot` for complex outputs - Use `toMatchFileSnapshot` with explicit path for language-specific snapshots --- ## Tooling Choices ### @antfu/ni Commands | Command | Description | |---------|-------------| | `ni` | Install dependencies | | `ni <pkg>` / `ni -D <pkg>` | Add dependency / dev dependency | | `nr <script>` | Run script | | `nu` | Upgrade dependencies | | `nun <pkg>` | Uninstall dependency | | `nci` | Clean install (`pnpm i --frozen-lockfile`) | | `nlx <pkg>` | Execute package (`npx`) | ### Checking npm Package Versions Use [`fast-npm-meta`](https://github.com/antfu/fast-npm-meta) to look up the latest version of a package — it queries a small metadata endpoint instead of downloading the full registry payload (which can be megabytes per package). ```bash nlx fast-npm-meta version vite # 7.3.1 nlx fast-npm-meta version "nuxt@^3.5" # 3.5.22 — range-aware nlx fast-npm-meta version vite nuxt vue # multiple at once nlx fast-npm-meta version vite --json # JSON for scripting nlx fast-npm-meta full vite # full version list + dist-tags ``` Prefer this over `npm view <pkg> version` when you only need the latest version, and over reading `package.json` from the registry directly. ### TypeScript Config ```json { "compilerOptions": { "target": "ESNext", "module": "ESNext", "moduleResolution": "bundler", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "resolveJsonModule": true, "isolatedModules": true, "noEmit": true } } ``` ### ESLint Setup ```js // eslint.config.js import antfu from '@antfu/eslint-config' export default antfu({ type: 'lib', // or 'app' (default) pnpm: true, // enforce pnpm catalogs in package.json antislop: true, // flag redundant/duplicated AI-style code, ban explicit `any` }) ``` Always enable `antislop: true`. It requires `eslint-plugin-slop` and `eslint-plugin-sonarjs` as dev dependencies. For detailed configuration options: [antfu-eslint-config](references/antfu-eslint-config.md) ### Knip Use [Knip](https://knip.dev) to catch unused files, exports and dependencies — the linter only sees one file at a time. ```json // knip.json { "$schema": "https://unpkg.com/knip@6/schema.json", "project": ["src/**/*.ts"], "ignoreDependencies": [] } ``` Fix what Knip reports by deleting; only add to `ignoreDependencies` for tools invoked outside `package.json` scripts (e.g. `taze`). ### Scripts and the `ci` Gate Every project exposes a `ci` script that runs all checks in one command: ```json { "scripts": { "build": "tsdown", "lint": "eslint --cache", "typecheck": "tsc", "knip": "knip", "test": "pnpm run build && vitest", "ci": "pnpm run lint && pnpm run typecheck && pnpm run knip && pnpm run test --run" } } ``` **Before every commit, run `nr lint --fix` to format, then `nr ci` and make sure it passes.** Do not commit with a failing `ci`; fix the root cause instead of silencing rules or adding ignores. ### Git Hooks `simple-git-hooks` + `nano-staged`. The pre-commit hook runs the full `ci` gate; `prepare` also installs agent skills via `skills-npm`: ```json { "scripts": { "prepare": "git config core.hooksPath .githooks && simple-git-hooks && skills-npm" }, "simple-git-hooks": { "pre-commit": "pnpm i --frozen-lockfile --ignore-scripts --offline && pnpm run ci && pnpx nano-staged" }, "nano-staged": { "*": "eslint --fix --no-warn-ignored" } } ``` Add `.githooks` to `.gitignore` and `simple-git-hooks: true` under `allowBuilds` in `pnpm-workspace.yaml`. ### skills-npm [`skills-npm`](https://github.com/antfu/skills-npm) symlinks agent skills shipped inside installed npm packages (and fetches those declared in a `skills` field) into the agent's skills directory on every install. Install as a dev dependency and wire it into `prepare` as above; add `skills/npm-*` to `.gitignore`. Commit the generated `skills-npm-lock.json`. ### Publishing Prefer npm Trusted Publishing (OIDC) over `NPM_TOKEN` secrets: releases run on CI from a `v*` tag via `release.yml` with `id-token: write`, and `nr release` (`bumpp`) only bumps, tags and pushes. Details: [setting-up](references/setting-up.md#publishing-with-npm-trusted-publishing-oidc). ### pnpm Catalogs Use named catalogs in `pnpm-workspace.yaml` for version management: | Catalog | Purpose | |---------|---------| | `prod` | Production dependencies | | `inlined` | Bundler-inlined dependencies | | `dev` | Dev tools (linter, bundler, testing) | | `frontend` | Frontend libraries | Avoid the default catalog. Catalog names can be adjusted per project needs. --- ## References | Topic | Description | Reference | |-------|-------------|-----------| | ESLint Config | Framework support, antislop, formatters, rule overrides, VS Code settings | [antfu-eslint-config](references/antfu-eslint-config.md) | | Project Setup | .gitignore, GitHub Actions, OIDC trusted publishing, VS Code extensions | [setting-up](references/setting-up.md) | | App Development | Vue/Nuxt/UnoCSS conventions, auto-import control, Storybook component testing | [app-development](references/app-development.md) | | Library Development | tsdown bundling, pure ESM publishing, publint, API snapshots | [library-development](references/library-development.md) | | Monorepo | pnpm workspaces, centralized alias, Turborepo | [monorepo](references/monorepo.md) |skills/antfu/references/antfu-eslint-config.md6.8 KB9bb734d38e8aupstream ↗
--- name: antfu-eslint-config description: Configuring @antfu/eslint-config for framework support, formatters, and rule overrides. Use when adding React/Vue/Svelte/Astro support, customizing rules, or setting up VS Code integration. --- # @antfu/eslint-config Handles both linting and formatting (no Prettier needed). Auto-detects TypeScript and Vue. **Style**: Single quotes, no semicolons, sorted imports, dangling commas. ## Configuration Options ```js import antfu from '@antfu/eslint-config' export default antfu({ // Project type: 'lib' for libraries, 'app' (default) for applications type: 'lib', // Enforce pnpm catalogs / workspace settings in package.json pnpm: true, // Always on: catch redundant, duplicated, AI-style code antislop: true, // Global ignores (extends defaults, doesn't override) ignores: ['**/fixtures', '**/dist'], // Stylistic options stylistic: { indent: 2, // 2, 4, or 'tab' quotes: 'single', // or 'double' }, // Framework support (auto-detected, but can be explicit) typescript: true, vue: true, // Disable specific language support jsonc: false, yaml: false, }) ``` ## Antislop ```js export default antfu({ antislop: true, }) // Requires: pnpm add -D eslint-plugin-slop eslint-plugin-sonarjs ``` Enables [`eslint-plugin-slop`](https://github.com/antfu/eslint-plugin-slop) plus a curated subset of `eslint-plugin-sonarjs` targeting redundant and duplicated code, and bans explicit `any` when TypeScript is enabled. Enable it on every project; when it flags code, simplify the code rather than disabling the rule. To toggle a plugin or scope inspection to recent changes: ```js export default antfu({ antislop: { sonarjs: false, slop: { inspection: { mode: 'recent-changes', tracebackCommits: 5 }, }, }, }) ``` Linters see one file at a time, so pair it with [Knip](https://knip.dev) for unused files/exports/dependencies (and `jscpd` for cross-file duplication when needed). ## Framework Support ### Vue Vue accessibility: ```js export default antfu({ vue: { a11y: true }, }) // Requires: pnpm add -D eslint-plugin-vuejs-accessibility ``` ### React ```js export default antfu({ react: true, }) // Requires: pnpm add -D @eslint-react/eslint-plugin eslint-plugin-react-hooks eslint-plugin-react-refresh ``` ### Next.js ```js export default antfu({ nextjs: true, }) // Requires: pnpm add -D @next/eslint-plugin-next ``` ### Svelte ```js export default antfu({ svelte: true, }) // Requires: pnpm add -D eslint-plugin-svelte ``` ### Astro ```js export default antfu({ astro: true, }) // Requires: pnpm add -D eslint-plugin-astro ``` ### Solid ```js export default antfu({ solid: true, }) // Requires: pnpm add -D eslint-plugin-solid ``` ### UnoCSS ```js export default antfu({ unocss: true, }) // Requires: pnpm add -D @unocss/eslint-plugin ``` ## Formatters (CSS, HTML, Markdown) For files ESLint doesn't handle natively: ```js export default antfu({ formatters: { css: true, // Format CSS, LESS, SCSS (uses Prettier) html: true, // Format HTML (uses Prettier) markdown: 'prettier' // or 'dprint' } }) // Requires: pnpm add -D eslint-plugin-format ``` ## Rule Overrides ### Global overrides ```js export default antfu( { // First argument: antfu config options }, // Additional arguments: ESLint flat configs { rules: { 'style/semi': ['error', 'never'], }, } ) ``` ### Per-integration overrides ```js export default antfu({ vue: { overrides: { 'vue/operator-linebreak': ['error', 'before'], }, }, typescript: { overrides: { 'ts/consistent-type-definitions': ['error', 'interface'], }, }, }) ``` ### File-specific overrides ```js export default antfu( { vue: true, typescript: true }, { files: ['**/*.vue'], rules: { 'vue/operator-linebreak': ['error', 'before'], }, } ) ``` ## Plugin Prefix Renaming The config renames plugin prefixes for consistency: | New Prefix | Original | |------------|----------| | `ts/*` | `@typescript-eslint/*` | | `style/*` | `@stylistic/*` | | `import/*` | `import-lite/*` | | `node/*` | `n/*` | | `yaml/*` | `yml/*` | | `test/*` | `vitest/*` | | `next/*` | `@next/next` | Use the new prefix when overriding or disabling rules: ```ts // eslint-disable-next-line ts/consistent-type-definitions type Foo = { bar: 2 } ``` ## Type-Aware Rules Enable TypeScript type checking: ```js export default antfu({ typescript: { tsconfigPath: 'tsconfig.json', }, }) ``` ## Config Composer API Chain methods for flexible composition: ```js export default antfu() .prepend(/* configs before main */) .override('antfu/stylistic/rules', { rules: { 'style/generator-star-spacing': ['error', { after: true, before: false }], } }) .renamePlugins({ 'old-prefix': 'new-prefix', }) ``` ## Less Opinionated Mode Disable Anthony's most opinionated rules: ```js export default antfu({ lessOpinionated: true }) ``` ## Pre-commit Setup ```json { "scripts": { "prepare": "git config core.hooksPath .githooks && simple-git-hooks && skills-npm" }, "simple-git-hooks": { "pre-commit": "pnpm i --frozen-lockfile --ignore-scripts --offline && pnpm run ci && pnpx nano-staged" }, "nano-staged": { "*": "eslint --fix --no-warn-ignored" } } ``` ```bash pnpm add -D nano-staged simple-git-hooks skills-npm ``` The hook runs the full `ci` script (lint, typecheck, knip, tests) before auto-fixing staged files, so a commit never lands with a red check. ## VS Code Settings Add to `.vscode/settings.json`: ```jsonc { "prettier.enable": false, "editor.formatOnSave": false, "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit", "source.organizeImports": "never" }, "eslint.rules.customizations": [ { "rule": "style/*", "severity": "off", "fixable": true }, { "rule": "format/*", "severity": "off", "fixable": true }, { "rule": "*-indent", "severity": "off", "fixable": true }, { "rule": "*-spacing", "severity": "off", "fixable": true }, { "rule": "*-spaces", "severity": "off", "fixable": true }, { "rule": "*-order", "severity": "off", "fixable": true }, { "rule": "*-dangle", "severity": "off", "fixable": true }, { "rule": "*-newline", "severity": "off", "fixable": true }, { "rule": "*quotes", "severity": "off", "fixable": true }, { "rule": "*semi", "severity": "off", "fixable": true } ], "eslint.validate": [ "javascript", "javascriptreact", "typescript", "typescriptreact", "vue", "html", "markdown", "json", "jsonc", "yaml", "toml", "xml", "astro", "svelte", "css", "less", "scss" ] } ``` <!-- Source references: - https://github.com/antfu/eslint-config - https://raw.githubusercontent.com/antfu/eslint-config/refs/heads/main/README.md -->skills/antfu/references/app-development.md2.6 KB428957d76f93upstream ↗
--- name: app-development description: Vue/Nuxt/UnoCSS application conventions. Use when building web apps, choosing between Vite and Nuxt, or writing Vue components. --- # App Development ## Framework Selection | Use Case | Choice | |----------|--------| | SPA, client-only, library playgrounds | Vite + Vue | | SSR, SSG, SEO-critical, file-based routing, API routes | Nuxt | ## Nuxt Conventions ### Disable Auto-imports (new projects) Prefer explicit imports over auto-imports so every symbol is traceable. For new Nuxt projects, turn off both app-side (Nuxt) and server-side (Nitro) auto-imports in `nuxt.config.ts`: ```ts // nuxt.config.ts export default defineNuxtConfig({ imports: { autoImport: false, // disable composable/util auto-imports }, components: { dirs: [], // disable component auto-imports }, nitro: { imports: false, // disable server-side (Nitro) auto-imports }, }) ``` Framework helpers stay available through the `#imports` alias — import them explicitly: ```ts import { computed, ref } from '#imports' ``` | Option | Effect | |--------|--------| | `imports.autoImport: false` | Stops auto-importing `~/composables` and `~/utils` (and framework APIs like `ref`) | | `components.dirs: []` | Stops auto-importing components from `~/components` | | `nitro.imports: false` | Stops auto-importing in the server (`server/utils`, etc.) | > Standalone Nitro projects already default to `imports: false` — leave server auto-imports off rather than enabling them. ### Path Aliases Nuxt's built-in aliases (`~/`, `@/`, `#imports`) are already configured, so they're fine to use. Don't add custom path aliases for new code — prefer relative imports otherwise. ## Vue Conventions | Convention | Preference | |------------|------------| | Script syntax | Always `<script setup lang="ts">` | | State | Prefer `shallowRef()` over `ref()` | | Objects | Use `ref()`, avoid `reactive()` | | Styling | UnoCSS | | Utilities | VueUse | ### Props and Emits ```vue <script setup lang="ts"> interface Props { title: string count?: number } interface Emits { (e: 'update', value: number): void (e: 'close'): void } const props = withDefaults(defineProps<Props>(), { count: 0, }) const emit = defineEmits<Emits>() </script> ``` ### Storybook for Components Set up Storybook for component development. Expressing each state as a story keeps components side-effect-free and their states predictable. Run the story tests in CI. Prefer the Vitest addon (`@storybook/addon-vitest`) so stories run as part of the existing `vitest` run (see [setting-up](setting-up.md)).skills/antfu/references/library-development.md4.7 KB298477bc6b01upstream ↗
--- name: library-development description: Building and publishing TypeScript libraries with tsdown. Use when creating npm packages, configuring library bundling, or setting up package.json exports. --- # Library Development | Aspect | Choice | |--------|--------| | Bundler | tsdown | | Output | Pure ESM only (no CJS) | | DTS | Generated via tsdown | | Exports | Auto-generated via tsdown | | Package validation | publint (via tsdown) | | Publishing | npm Trusted Publishing (OIDC) from CI | ## tsdown Configuration Use tsdown with these options enabled: ```ts // tsdown.config.ts import { defineConfig } from 'tsdown' export default defineConfig({ entry: ['src/index.ts'], format: ['esm'], dts: true, exports: true, publint: true, }) ``` | Option | Value | Purpose | |--------|-------|---------| | `format` | `['esm']` | Pure ESM, no CommonJS | | `dts` | `true` | Generate `.d.ts` files | | `exports` | `true` | Auto-update `exports` field in `package.json` | | `publint` | `true` | Validate `package.json`/`exports` on every build (requires `publint` dev dependency) | ### Multiple Entry Points ```ts export default defineConfig({ entry: [ 'src/index.ts', 'src/utils.ts', ], format: ['esm'], dts: true, exports: true, }) ``` The `exports: true` option auto-generates the `exports` field in `package.json` when running `tsdown`. --- ## API Stability For published libraries, lock the public API surface so accidental breaking changes appear as a diff in code review. | Tool | Purpose | |------|---------| | [`tsnapi`](https://github.com/antfu/tsnapi) | Snapshots runtime exports + type declarations into committed `.snapshot.js` / `.snapshot.d.ts` files via Vitest | | [`tsdown-stale-guard`](https://github.com/antfu-collective/tsdown-stale-guard) | Records build input/output hashes so tests fail fast when run against a stale build | Install both as dev dependencies. Wire `tsdown-stale-guard` as a tsdown plugin so every build records its hash: ```ts // tsdown.config.ts import { defineConfig } from 'tsdown' import { StaleGuardRecorder } from 'tsdown-stale-guard' export default defineConfig({ entry: ['src/index.ts'], format: ['esm'], dts: true, exports: true, plugins: [ StaleGuardRecorder(), ], }) ``` Snapshot the public API from a Vitest test — prefer the Vitest helpers over the tsdown/Rolldown plugin so build config stays focused on building. Each file gates itself on a fresh build via a per-file `beforeAll(guardStaleBuild)` so the committed `dist/` can never drift from source: ```ts // test/api.test.ts (single package) import { beforeAll } from 'vitest' import { snapshotApiPerEntry } from 'tsnapi/vitest' import { guardStaleBuild } from 'tsdown-stale-guard' beforeAll(async () => { await guardStaleBuild() }) await snapshotApiPerEntry(new URL('..', import.meta.url).pathname) ``` For monorepos, wrap `describePackagesApiSnapshots()` in a `describe` so the per-package suites share a single stale-build gate: ```ts // test/api.test.ts (monorepo, run from root) import { beforeAll, describe } from 'vitest' import { describePackagesApiSnapshots } from 'tsnapi/vitest' import { guardStaleBuild } from 'tsdown-stale-guard' describe('packages api', async () => { beforeAll(async () => { await guardStaleBuild() }) await describePackagesApiSnapshots() }) ``` ### Updating snapshots After an intentional API change, rebuild and update both snapshots in one go: ```bash nr build # regenerates dist/ and the stale-guard hash nr test -u # updates the .snapshot.js / .snapshot.d.ts files ``` --- ## package.json Required fields for pure ESM library: ```json { "type": "module", "sideEffects": false, "types": "./dist/index.d.mts", "files": ["dist"], "scripts": { "build": "tsdown", "dev": "tsdown --watch", "lint": "eslint --cache", "typecheck": "tsc", "knip": "knip", "test": "pnpm run build && vitest", "ci": "pnpm run lint && pnpm run typecheck && pnpm run knip && pnpm run test --run", "prepack": "nr build", "release": "bumpp" } } ``` The `exports` field is managed by tsdown when `exports: true`. Use `bumpp -r` in monorepos. ### prepack Script For each public package, add `"prepack": "nr build"` to `scripts`. This ensures the package is automatically built before publishing (e.g., when running `npm publish` or `pnpm publish`). This prevents accidentally publishing stale or missing build artifacts. ### Releasing Run `nr ci` first — it must pass. Then `nr release`: `bumpp` bumps the version, commits, tags and pushes. The `v*` tag triggers `release.yml`, which builds and publishes via npm Trusted Publishing (OIDC). Do not publish from a local machine after the initial package creation; see [setting-up](setting-up.md#publishing-with-npm-trusted-publishing-oidc).skills/antfu/references/monorepo.md2.7 KB1bfdde5b2c16upstream ↗
--- name: monorepo description: Monorepo setup with pnpm workspaces, centralized aliases, and Turborepo. Use when creating or managing multi-package repositories. --- # Monorepo Setup ## pnpm Workspaces Use pnpm workspaces for monorepo management: ```yaml # pnpm-workspace.yaml packages: - 'packages/*' ``` ## Scripts Convention Have scripts in each package, and use `-r` (recursive) flag at root, Enable ESLint cache for faster linting in monorepos. ```json // root package.json { "scripts": { "build": "pnpm run -r build", "test": "vitest", "lint": "eslint . --cache --concurrency=auto" } } ``` In each package's `package.json`, add the scripts. ```json // packages/*/package.json { "scripts": { "build": "tsdown", "prepack": "pnpm build" } } ``` ## ESLint Cache ```json { "scripts": { "lint": "eslint . --cache --concurrency=auto" } } ``` ## Turborepo (Optional) For monorepos with many packages or long build times, use Turborepo for task orchestration and caching. See the dedicated Turborepo skill for detailed configuration. ## Centralized Alias Path aliases should be explicit and centralized — this is the deliberate "already set up" case. Outside of these configured aliases, prefer relative imports; don't sprinkle ad-hoc aliases across the codebase. For better DX across Vite, Nuxt, Vitest configs, create a centralized `alias.ts` at project root: ```ts // alias.ts import fs from 'node:fs' import { fileURLToPath } from 'node:url' import { join, relative } from 'pathe' const root = fileURLToPath(new URL('.', import.meta.url)) const r = (path: string) => fileURLToPath(new URL(`./packages/${path}`, import.meta.url)) export const alias = { '@myorg/core': r('core/src/index.ts'), '@myorg/utils': r('utils/src/index.ts'), '@myorg/ui': r('ui/src/index.ts'), // Add more aliases as needed } // Auto-update tsconfig.alias.json paths const raw = fs.readFileSync(join(root, 'tsconfig.alias.json'), 'utf-8').trim() const tsconfig = JSON.parse(raw) tsconfig.compilerOptions.paths = Object.fromEntries( Object.entries(alias).map(([key, value]) => [key, [`./${relative(root, value)}`]]), ) const newRaw = JSON.stringify(tsconfig, null, 2) if (newRaw !== raw) fs.writeFileSync(join(root, 'tsconfig.alias.json'), `${newRaw}\n`, 'utf-8') ``` Then update the `tsconfig.json` to use the alias file: ```json { "extends": [ "./tsconfig.alias.json" ] } ``` ### Using Alias in Configs Reference the centralized alias in all config files: ```ts // vite.config.ts import { alias } from './alias' export default defineConfig({ resolve: { alias }, }) ``` ```ts // nuxt.config.ts import { alias } from './alias' export default defineNuxtConfig({ alias, }) ```skills/antfu/references/setting-up.md3.0 KBf4541227c6c7upstream ↗
--- name: setting-up description: Project setup files including .gitignore, GitHub Actions workflows, npm OIDC trusted publishing, and VS Code extensions. Use when initializing new projects or adding CI/editor/release config. --- # Project Setup Start from [antfu/starter-ts](https://github.com/antfu/starter-ts); the files below mirror it. ## .gitignore Create when `.gitignore` is not present: ``` *.log *.tgz .cache .DS_Store .eslintcache .githooks .idea .env .nuxt .temp .output .turbo cache coverage dist lib-cov logs node_modules skills/npm-* temp ``` ## GitHub Actions Add these workflows when setting up a new project. Skip if workflows already exist. All use [sxzz/workflows](https://github.com/sxzz/workflows) reusable workflows. ### Autofix Workflow **`.github/workflows/autofix.yml`** - Auto-fix linting on PRs: ```yaml name: autofix.ci on: [pull_request] jobs: autofix: uses: sxzz/workflows/.github/workflows/autofix.yml@main permissions: contents: read ``` ### CI Workflow **`.github/workflows/ci.yml`** - Run the checks on push/PR: ```yaml name: CI on: push: branches: [main] pull_request: branches: [main] permissions: {} jobs: unit-test: uses: sxzz/workflows/.github/workflows/unit-test.yml@main ``` ### Release Workflow **`.github/workflows/release.yml`** - Publish on tag (library projects only): ```yaml name: Release on: push: tags: - 'v*' jobs: release: uses: sxzz/workflows/.github/workflows/release.yml@main with: publish: true permissions: contents: write id-token: write ``` ## Publishing with npm Trusted Publishing (OIDC) Prefer [npm Trusted Publishing](https://docs.npmjs.com/trusted-publishers) over long-lived `NPM_TOKEN` secrets. The workflow above authenticates with a short-lived GitHub OIDC token (`id-token: write`), so there is nothing to leak or rotate, and every release is built on CI from a tagged commit. One-time setup per package: 1. Run `pnpm publish` locally once so the package exists on npm. 2. Open `https://www.npmjs.com/package/<name>/access` and link the GitHub repository + `release.yml` workflow as a trusted publisher. After that, `nr release` (`bumpp`) bumps the version, commits, tags and pushes; the tag triggers `release.yml`, which publishes. Never add an `NPM_TOKEN` secret to new projects, and don't run `npm publish` from a local machine for subsequent releases. ## VS Code Extensions Configure in `.vscode/extensions.json`: ```json { "recommendations": [ "dbaeumer.vscode-eslint", "antfu.pnpm-catalog-lens", "antfu.iconify", "antfu.unocss", "antfu.slidev", "vue.volar" ] } ``` | Extension | Description | |-----------|-------------| | `dbaeumer.vscode-eslint` | ESLint integration for linting and formatting | | `antfu.pnpm-catalog-lens` | Shows pnpm catalog version hints inline | | `antfu.iconify` | Iconify icon preview and autocomplete | | `antfu.unocss` | UnoCSS IntelliSense and syntax highlighting | | `antfu.slidev` | Slidev preview and syntax highlighting | | `vue.volar` | Vue Language Features |README.mdupstream ↗
Contents are not inlined in the catalog. Open the upstream file.
Plain-text copy, no login: /skill-bundles/antfu-skills-skills-antfu.md