Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add package.json exports for public packages (#6458)
- Loading branch information
1 parent
fc2df63
commit d676683
Showing
59 changed files
with
517 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
|
||
export const rules: Record<string, TSESLint.RuleModule<string, unknown[]>>; | ||
export const configs: Record<string, TSESLint.Linter.Config>; | ||
import type rules from './rules'; | ||
|
||
declare const cjsExport: { | ||
configs: Record<string, TSESLint.Linter.Config>; | ||
rules: typeof rules; | ||
}; | ||
export = cjsExport; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
We purposely don't generate types for our plugin because TL;DR: | ||
1) there's no real reason that anyone should do a typed import of our rules, | ||
2) it would require us to change our code so there aren't as many inferred types | ||
This type declaration exists as a hacky way to add a type to the export for our | ||
internal packages that require it. | ||
*** Long reason *** | ||
When you turn on declaration files, TS requires all types to be "fully resolvable" | ||
without changes to the code. | ||
All of our lint rules `export default createRule(...)`, which means they all | ||
implicitly reference the `TSESLint.Rule` type for the export. | ||
TS wants to transpile each rule file to this `.d.ts` file: | ||
```ts | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
declare const _default: TSESLint.RuleModule<TMessageIds, TOptions, TSESLint.RuleListener>; | ||
export default _default; | ||
``` | ||
Because we don't import `TSESLint` in most files, it means that TS would have to | ||
insert a new import during the declaration emit to make this work. | ||
However TS wants to avoid adding new imports to the file because a new module | ||
could have type side-effects (like global augmentation) which could cause weird | ||
type side-effects in the decl file that wouldn't exist in source TS file. | ||
So TS errors on most of our rules with the following error: | ||
``` | ||
The inferred type of 'default' cannot be named without a reference to | ||
'../../../../node_modules/@typescript-eslint/utils/src/ts-eslint/Rule'. | ||
This is likely not portable. A type annotation is necessary. ts(2742) | ||
``` | ||
*/ | ||
|
||
import type { RuleModule } from '@typescript-eslint/utils/ts-eslint'; | ||
|
||
export interface TypeScriptESLintRules { | ||
[ruleName: string]: RuleModule<string, unknown[]>; | ||
} | ||
declare const rules: TypeScriptESLintRules; | ||
export = rules; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/eslint-plugin/tests/fixtures/consistent-type-exports.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type Type1 = 1; | ||
export type Type2 = 1; | ||
export const value1 = 2; | ||
export const value2 = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum Enum { | ||
A = 'A', | ||
B = 'B', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.