Skip to content

Commit 6ad0571

Browse files
authored
feat: ship a skill facade in the npm package (#1122)
1 parent 9154732 commit 6ad0571

4 files changed

Lines changed: 69 additions & 1 deletion

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ temp
1111
.DS_Store
1212
.eslintcache
1313
tsdown-*.tgz
14+
.skills-backup
1415

1516
docs/.vitepress/dist
1617
docs/.vitepress/cache

‎npm-skills/tsdown/SKILL.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: tsdown
3+
description: Bundle TypeScript and JavaScript libraries with blazing-fast speed powered by Rolldown. Use when building libraries, generating type declarations, bundling for multiple formats, or migrating from tsup.
4+
---
5+
6+
# tsdown
7+
8+
This package ships only a pointer to the full tsdown skill, which lives on GitHub to keep the npm package small.
9+
10+
## Step 1: Find the installed version
11+
12+
Read the `version` field of `node_modules/tsdown/package.json`.
13+
14+
## Step 2: Read the full skill for that version
15+
16+
Fetch the skill that matches the installed version, replacing `<version>` with it:
17+
18+
```
19+
https://raw.githubusercontent.com/rolldown/tsdown/v<version>/skills/tsdown/SKILL.md
20+
```
21+
22+
Read it completely before writing tsdown config or code. Its links to `references/*.md` are relative to that URL, so fetch them from:
23+
24+
```
25+
https://raw.githubusercontent.com/rolldown/tsdown/v<version>/skills/tsdown/references/<file>.md
26+
```
27+
28+
If the tag does not exist (e.g. a prerelease or local build), use `main` instead of `v<version>`.
29+
30+
To browse the skill: https://github.com/rolldown/tsdown/tree/main/skills/tsdown
31+
32+
## More
33+
34+
- Documentation: https://tsdown.dev
35+
- Documentation for LLMs: https://tsdown.dev/llms.txt
36+
- Migrating from tsup: https://github.com/rolldown/tsdown/tree/main/skills/tsdown-migrate

‎package.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"files": [
4949
"client.d.ts",
5050
"dist",
51-
"esm-shims.js"
51+
"esm-shims.js",
52+
"skills"
5253
],
5354
"publishConfig": {
5455
"access": "public",
@@ -86,6 +87,8 @@
8687
"schema:generate": "node ./scripts/generate-schema.ts",
8788
"schema:check": "node ./scripts/generate-schema.ts -c",
8889
"release": "node ./scripts/release.ts",
90+
"prepack": "node ./scripts/skills-facade.ts prepack",
91+
"postpack": "node ./scripts/skills-facade.ts postpack",
8992
"docs:dev": "pnpm -C docs run dev",
9093
"docs:build": "pnpm -C docs run build",
9194
"docs:preview": "pnpm -C docs run preview",

‎scripts/skills-facade.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// The full skills under `skills/` are too large to ship in the npm package,
2+
// but pnpm only discovers package skills under `skills/`. While packing, swap
3+
// in the lightweight facades from `npm-skills/`, which link to GitHub.
4+
import { rename } from 'node:fs/promises'
5+
import process from 'node:process'
6+
import { fsCopy, fsExists, fsRemove } from '../src/utils/fs.ts'
7+
8+
const SKILLS = 'skills'
9+
const FACADES = 'npm-skills'
10+
const BACKUP = '.skills-backup'
11+
12+
async function restore() {
13+
if (!(await fsExists(BACKUP))) return
14+
await fsRemove(SKILLS)
15+
await rename(BACKUP, SKILLS)
16+
}
17+
18+
const mode = process.argv[2]
19+
if (mode === 'prepack') {
20+
// Recover from a previous pack that did not reach postpack
21+
await restore()
22+
await rename(SKILLS, BACKUP)
23+
await fsCopy(FACADES, SKILLS)
24+
} else if (mode === 'postpack') {
25+
await restore()
26+
} else {
27+
throw new Error(`Unknown mode: ${mode}`)
28+
}

0 commit comments

Comments
 (0)