Skip to content

Commit

Permalink
feat(eslint-plugin): bundle types
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Nov 16, 2023
1 parent e3023a1 commit e4b2677
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 98 deletions.
5 changes: 4 additions & 1 deletion packages/eslint-plugin-js/configs/disable-legacy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* GENERATED, DO NOT EDIT DIRECTLY */

export default {
import type { Linter } from 'eslint'

const config: Linter.FlatConfig = {
rules: {
'array-bracket-newline': 0,
'array-bracket-spacing': 0,
Expand Down Expand Up @@ -71,3 +73,4 @@ export default {
'yield-star-spacing': 0,
},
}
export default config
4 changes: 2 additions & 2 deletions packages/eslint-plugin-js/dts/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ESLint, Linter } from 'eslint'
import type { Linter, Rule } from 'eslint'
import type { UnprefixedRuleOptions } from './rule-options'

export type * from './rule-options'

export type Rules = {
[K in keyof UnprefixedRuleOptions]: ESLint.RuleModule
[K in keyof UnprefixedRuleOptions]: Rule.RuleModule
}

declare const plugin: {
Expand Down
5 changes: 4 additions & 1 deletion packages/eslint-plugin-jsx/configs/disable-legacy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* GENERATED, DO NOT EDIT DIRECTLY */

export default {
import type { Linter } from 'eslint'

const config: Linter.FlatConfig = {
rules: {
'react/jsx-child-element-spacing': 0,
'react/jsx-closing-bracket-location': 0,
Expand All @@ -22,3 +24,4 @@ export default {
'react/jsx-wrap-multilines': 0,
},
}
export default config
4 changes: 2 additions & 2 deletions packages/eslint-plugin-jsx/dts/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ESLint, Linter } from 'eslint'
import type { Linter, Rule } from 'eslint'
import type { UnprefixedRuleOptions } from './rule-options'

export type * from './rule-options'

export type Rules = {
[K in keyof UnprefixedRuleOptions]: ESLint.RuleModule
[K in keyof UnprefixedRuleOptions]: Rule.RuleModule
}

declare const plugin: {
Expand Down
5 changes: 4 additions & 1 deletion packages/eslint-plugin-ts/configs/disable-legacy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* GENERATED, DO NOT EDIT DIRECTLY */

export default {
import type { Linter } from 'eslint'

const config: Linter.FlatConfig = {
rules: {
'@typescript-eslint/block-spacing': 0,
'@typescript-eslint/brace-style': 0,
Expand All @@ -25,3 +27,4 @@ export default {
'@typescript-eslint/type-annotation-spacing': 0,
},
}
export default config
4 changes: 2 additions & 2 deletions packages/eslint-plugin-ts/dts/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ESLint, Linter } from 'eslint'
import type { Linter, Rule } from 'eslint'
import type { UnprefixedRuleOptions } from './rule-options'

export type * from './rule-options'

export type Rules = {
[K in keyof UnprefixedRuleOptions]: ESLint.RuleModule
[K in keyof UnprefixedRuleOptions]: Rule.RuleModule
}

declare const plugin: {
Expand Down
5 changes: 4 additions & 1 deletion packages/eslint-plugin/configs/disable-legacy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* GENERATED, DO NOT EDIT DIRECTLY */

export default {
import type { Linter } from 'eslint'

const config: Linter.FlatConfig = {
rules: {
'array-bracket-newline': 0,
'array-bracket-spacing': 0,
Expand Down Expand Up @@ -110,3 +112,4 @@ export default {
'react/jsx-wrap-multilines': 0,
},
}
export default config
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import type { ESLint, Linter } from 'eslint'
import type { Rule } from 'eslint'
import type { configs } from '../configs'
import type { UnprefixedRuleOptions } from './rule-options'

export type * from './rule-options'

export type Rules = {
[K in keyof UnprefixedRuleOptions]: ESLint.RuleModule
[K in keyof UnprefixedRuleOptions]: Rule.RuleModule
}

declare const plugin: {
rules: Rules
configs: {
'disable-legacy': Linter.FlatConfig
}
configs: typeof configs
}

export default plugin
9 changes: 4 additions & 5 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@
},
"exports": {
".": {
"types": "./dts/index.d.ts",
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"default": "./dist/index.js"
},
"./define-config-support": {
"types": "./dts/define-config-support.d.ts"
"types": "./dist/dts/define-config-support.d.ts"
},
"./rule-options": {
"types": "./dts/rule-options.d.ts"
"types": "./dist/dts/rule-options.d.ts"
}
},
"main": "./dist/index.js",
"types": "./dts/index.d.ts",
"files": [
"dist",
"dts"
"dist"
],
"scripts": {
"build": "rimraf dist && rollup --config=rollup.config.mts --configPlugin=rollup-plugin-esbuild",
Expand Down
74 changes: 49 additions & 25 deletions packages/eslint-plugin/rollup.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,57 @@ import { basename, dirname } from 'node:path'
import { defineConfig } from 'rollup'
import commonjs from '@rollup/plugin-commonjs'
import esbuild from 'rollup-plugin-esbuild'
import dts from 'rollup-plugin-dts'

const pkg = JSON.parse(await fs.readFile(new URL('./package.json', import.meta.url), 'utf-8'))

export default defineConfig({
input: 'src/index.ts',
output: [
{
dir: 'dist',
format: 'cjs',
manualChunks(id) {
if (id.includes('rules')) {
const name = basename(dirname(id))
if (name !== 'rules')
return name
}
export default defineConfig([
{
input: 'src/index.ts',
output: [
{
dir: 'dist',
format: 'cjs',
manualChunks(id) {
if (id.includes('rules')) {
const name = basename(dirname(id))
if (name !== 'rules')
return name
}
},
chunkFileNames: '[name].js',
},
chunkFileNames: '[name].js',
],
plugins: [
esbuild(),
commonjs(),
],
external: [
...Object.keys(pkg.dependencies || []),
...Object.keys(pkg.peerDependencies || []),
'eslint/package.json',
'@typescript-eslint/utils/ast-utils',
],
},
{
input: [
'./dts/index.ts',
'./dts/define-config-support.d.ts',
'./dts/rule-options.d.ts',
],
output: {
dir: 'dist',
format: 'es',
},
],
plugins: [
esbuild(),
commonjs(),
],
external: [
...Object.keys(pkg.dependencies || []),
...Object.keys(pkg.peerDependencies || []),
'eslint/package.json',
'@typescript-eslint/utils/ast-utils',
],
})
plugins: [
dts({
respectExternal: true,
tsconfig: 'tsconfig.dts.json',
}),
],
external: [
...Object.keys(pkg.dependencies || []),
...Object.keys(pkg.peerDependencies || []),
],
},
])
12 changes: 12 additions & 0 deletions packages/eslint-plugin/tsconfig.dts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true
},
"include": [
"./configs/**/*.ts",
"./dts/**/*.d.ts"
]
}
Loading

0 comments on commit e4b2677

Please sign in to comment.