Skip to content

Commit d877991

Browse files
committed
docs(playbook): prefer import.meta.dirname/filename over URL utilities\n\n- Node >=20.11 supports import.meta.dirname and import.meta.filename; prefer them\n- Keep URL utilities as a fallback for non-file URLs or special cases
1 parent 63e1859 commit d877991

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,15 @@ Upgrade a single plugin under `packages/<name>` to publish ESM-only output with
8383

8484
- Replace `require`, `module.exports`, and `__dirname` patterns with ESM equivalents.
8585
- Use `node:` specifiers for built-ins (e.g., `import path from 'node:path'`).
86-
- Prefer URL utilities where needed (`fileURLToPath(new URL('.', import.meta.url))`).
86+
- Prefer the latest ES APIs: use `import.meta.dirname` and `import.meta.filename` (Node ≥20.11) instead of re‑creating them via `fileURLToPath`.
87+
```ts
88+
import path from 'node:path';
89+
90+
const here = import.meta.dirname;
91+
// const file = import.meta.filename;
92+
const pkgJson = path.join(here, 'package.json');
93+
```
94+
Use URL utilities only when specifically needed (e.g., for non‑file module URLs): `fileURLToPath(new URL('.', import.meta.url))`.
8795
- Inline and export public types from `src/index.ts`; avoid separate `types/` unless unavoidable.
8896
- Conversion rules for file types:
8997
- Always convert any `.js` in `src/` to `.ts`.

0 commit comments

Comments
 (0)