Skip to content

Commit 0b47390

Browse files
fix: more CJS compatibility (#4)
- Change package.json type to CJS for more compatibility. - Replace `unbuild` with `tsup` for more default export ergonomics. - `unbuild` was fine as long as we added a patch script to export `default` in CJS. However that's a bit unexpected in CJS; you would expect to just do `const rxjsX = require('eslint-plugin-rxjs-x');` without `.default` tacked onto the end. `tsup` lets us build different output for CJS that's more ergonomic for CJS users. - Had to remove the `assert { type: 'json' }` since `esbuild` doesn't support it combined with named exports. - Only support decamelize v5. - v6 is ESM-only, which would be fine if users use this plugin in an ESM eslint config. However if they're using a CJS eslint config and they install this package, their package manager will likely pull in decamelize v6 and cause a error trying to import it. Downgrading helps avoid that confusion; advanced users who need v6 can use something like yarn resolutions to override.
1 parent 2e82594 commit 0b47390

File tree

6 files changed

+358
-1681
lines changed

6 files changed

+358
-1681
lines changed

build.config.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-rxjs-x",
3-
"type": "module",
3+
"type": "commonjs",
44
"version": "0.1.0",
55
"packageManager": "[email protected]+sha512.341db9396b6e289fecc30cd7ab3af65060e05ebff4b3b47547b278b9e67b08f485ecd8c79006b405446262142c7a38154445ef7f17c1d5d1de7d90bf9ce7054d",
66
"description": "ESLint v9+ plugin for RxJS",
@@ -28,20 +28,20 @@
2828
"default": "./dist/index.mjs"
2929
},
3030
"require": {
31-
"types": "./dist/index.d.cts",
32-
"default": "./dist/index.cjs"
31+
"types": "./dist/index.d.ts",
32+
"default": "./dist/index.js"
3333
}
3434
}
3535
},
36-
"main": "./dist/index.mjs",
36+
"main": "./dist/index.js",
3737
"module": "./dist/index.mjs",
3838
"types": "./dist/index.d.ts",
3939
"files": [
4040
"dist",
4141
"docs"
4242
],
4343
"scripts": {
44-
"build": "unbuild && tsx scripts/postbuild.ts",
44+
"build": "tsup",
4545
"lint": "eslint",
4646
"release": "bumpp && yarn run build",
4747
"test": "vitest",
@@ -52,7 +52,7 @@
5252
"@typescript-eslint/scope-manager": "^8.12.2",
5353
"@typescript-eslint/utils": "^8.12.2",
5454
"common-tags": "^1.8.0",
55-
"decamelize": "^5.0.0 || ^6.0.0",
55+
"decamelize": "^5.0.1",
5656
"ts-api-utils": "^1.3.0",
5757
"tslib": "^2.1.0"
5858
},
@@ -77,10 +77,10 @@
7777
"eslint-plugin-import-x": "^4.4.0",
7878
"eslint-plugin-n": "^17.12.0",
7979
"rxjs": "^7.0.0",
80+
"tsup": "^8.3.5",
8081
"tsx": "^4.19.2",
8182
"typescript": "~5.6.3",
8283
"typescript-eslint": "^8.12.2",
83-
"unbuild": "^2.0.0",
8484
"vitest": "^2.1.4"
8585
},
8686
"engines": {

scripts/postbuild.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TSESLint } from '@typescript-eslint/utils';
2-
import { name, version } from '../package.json' assert { type: 'json' };
2+
import { name, version } from '../package.json';
33
import { createRecommendedConfig } from './configs/recommended';
44

55
import { banObservablesRule } from './rules/ban-observables';

tsup.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from 'tsup';
2+
3+
export default defineConfig({
4+
entry: [
5+
'src/index.ts',
6+
],
7+
clean: true,
8+
dts: true,
9+
cjsInterop: true,
10+
splitting: true,
11+
format: ['cjs', 'esm'],
12+
});

0 commit comments

Comments
 (0)