Skip to content

Commit

Permalink
Drop CJS support, make it ESM-only
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Feb 20, 2025
1 parent c18bd5f commit ee81aac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## [Unreleased]

- Drops CJS support in favor of
[ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)

```tsx
// ❌ No longer supported
const { string } = require('decoders');

// ✅ Use import instead
import { string } from 'decoders';
```

- Use `node16` module resolution setting (recommended setting for libraries that run in
both browsers and Node environments)

Expand Down
9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,11 @@
"url": "https://github.com/nvie/decoders/issues"
},
"type": "module",
"main": "./dist/index.cjs",
"types": "./dist/index.d.cts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"module": "./dist/index.js",
"default": "./dist/index.cjs"
}
}
},
Expand All @@ -39,7 +32,7 @@
"docs": "cog -cr docs/*.md",
"lint": "eslint --color --report-unused-disable-directives src/ test/ && prettier --list-different src/ test/ test-d/",
"lint:docs": "cog -c --check docs/*.md || (npm run docs; git diff; echo 'Error: docs not up-to-date, please re-run \"npm docs\" to update them.' && exit 1)",
"lint:package": "publint --strict && attw --pack",
"lint:package": "publint --strict && attw --pack --profile esm-only",
"format": "eslint --color --report-unused-disable-directives --fix src/ test/ ; prettier --write src/ test/ test-d/",
"test": "vitest run --coverage",
"test:completeness": "./bin/check.sh",
Expand Down
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export default defineConfig({
splitting: true,
clean: true,
// target: /* what tsconfig specifies */,
format: ['esm', 'cjs'],
format: ['esm'],
});

0 comments on commit ee81aac

Please sign in to comment.