Skip to content

Commit 33decd6

Browse files
committed
docs(repo): use explicit '.' export mapping in ESM-only playbook\n\n- Update exports snippet to nest under '.' for better tooling compatibility\n- Adjust verification jq command to match the new exports shape\n\nRefs #1934
1 parent ab232ed commit 33decd6

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

.charlie/playbooks/upgrade-plugin-to-esm-only.md

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,26 @@ Upgrade a single plugin under `packages/<name>` to publish ESM-only output with
1111
## Steps
1212

1313
1. Identify the target package
14-
1514
- Set a shell variable for reuse: `PKG=packages/<name>`.
1615

1716
2. Package metadata: ESM-only and minimums
18-
1917
- Edit `$PKG/package.json`:
20-
- Set `"type": "module"`.
21-
- Replace legacy `main/module/exports.require` with ESM-only exports:
22-
```json
23-
"exports": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
24-
"types": "./dist/index.d.ts"
25-
```
26-
- Set minimums: `"engines": { "node": ">=20.19.0" }` and `"peerDependencies": { "rollup": ">=4.0.0" }`.
27-
- Keep `rollup` as a devDependency only if tests use it. Otherwise remove it.
28-
- Ensure published files include dist but exclude maps:
29-
```json
30-
"files": ["dist", "!dist/**/*.map", "README.md", "LICENSE"]
31-
```
18+
- Set `"type": "module"`.
19+
- Replace legacy `main/module/exports.require` with ESM-only exports:
20+
```json
21+
"exports": {
22+
".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" }
23+
},
24+
"types": "./dist/index.d.ts"
25+
```
26+
- Set minimums: `"engines": { "node": ">=20.19.0" }` and `"peerDependencies": { "rollup": ">=4.0.0" }`.
27+
- Keep `rollup` as a devDependency only if tests use it. Otherwise remove it.
28+
- Ensure published files include dist but exclude maps:
29+
```json
30+
"files": ["dist", "!dist/**/*.map", "README.md", "LICENSE"]
31+
```
3232

3333
3. Build scripts: TypeScript emit to dist
34-
3534
- Prefer a tsc-only build for packages that do not need bundling:
3635
- In `$PKG/package.json`, set scripts:
3736
```json
@@ -44,9 +43,7 @@ Upgrade a single plugin under `packages/<name>` to publish ESM-only output with
4443
- If this package still needs bundling for tests/examples, keep its Rollup config but point inputs at the TypeScript output in `dist/` instead of sources.
4544

4645
4. TypeScript config: emit ESM to `dist/`
47-
4846
- Create or update `$PKG/tsconfig.json` to extend the shared plugin config and emit declarations:
49-
5047
```json
5148
{
5249
"extends": "../../.config/tsconfig.base.json",
@@ -60,18 +57,15 @@ Upgrade a single plugin under `packages/<name>` to publish ESM-only output with
6057
"include": ["src/**/*"]
6158
}
6259
```
63-
6460
- Delete any package-local `rollup` build scripts that produced CJS, and remove any `types/` folder if declarations were hand-authored (they will now be generated).
6561

6662
5. Source: convert to pure ESM and modern Node APIs
67-
6863
- Replace `require`, `module.exports`, and `__dirname` patterns with ESM equivalents.
6964
- Use `node:` specifiers for built-ins (e.g., `import path from 'node:path'`).
7065
- Prefer URL utilities where needed (`fileURLToPath(new URL('.', import.meta.url))`).
7166
- Inline and export public types from `src/index.ts`; avoid separate `types/` unless unavoidable.
7267

7368
6. Tests: drop CJS branches; ESM everywhere
74-
7569
- Remove CJS-specific branches/assertions from tests.
7670
- Keep the existing runner (AVA) if it already handles ESM in Node 20. If the package already uses Vitest in this repo, keep that pattern.
7771
- Ensure Rollup bundles created in tests are `await bundle.close()`-d to avoid leaks.
@@ -90,7 +84,7 @@ Upgrade a single plugin under `packages/<name>` to publish ESM-only output with
9084
```
9185
- Type declarations resolve for consumers:
9286
```bash
93-
jq -r '.types, .exports.types, .exports.import' $PKG/package.json
87+
jq -r '.types, .exports["."]?.types, .exports["."]?.import' $PKG/package.json
9488
```
9589
- Runtime smoke (Node ESM import works):
9690
```bash

0 commit comments

Comments
 (0)