-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: add package.json exports for public packages #6458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4f51bc3
feat: add package.json exports for public packages
bradzacher 40ff15f
fixes
bradzacher 99b6dbe
fix test
bradzacher 5b0c7a8
Merge branch 'v6' into 6050-package-exports
bradzacher 6c7b452
fix test
bradzacher 8ef12c9
remove chalk
bradzacher 3cd115a
fix lint
bradzacher bee39d5
Merge branch 'v6' into 6050-package-exports
bradzacher a635863
review fixes
bradzacher 00af53f
ci fixes
bradzacher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
"armano2", | ||
"Jed Fox" | ||
], | ||
"type": "commonjs", | ||
"license": "BSD-2-Clause", | ||
"repository": "typescript-eslint/typescript-eslint", | ||
"bugs": { | ||
|
@@ -121,13 +122,16 @@ | |
"jest-resolve": "^29", | ||
"jest-util": "^29", | ||
"pretty-format": "^29", | ||
"@swc/core-android-arm-eabi": "npm:[email protected]", | ||
"@swc/core-android-arm64": "npm:[email protected]", | ||
"@swc/core-freebsd-x64": "npm:[email protected]", | ||
"@swc/core-linux-arm-gnueabihf": "npm:[email protected]", | ||
"@swc/core-linux-arm64-gnu": "npm:[email protected]", | ||
"@swc/core-linux-arm64-musl": "npm:[email protected]", | ||
"@swc/core-win32-arm64-msvc": "npm:[email protected]", | ||
"@swc/core-win32-ia32-msvc": "npm:[email protected]" | ||
"@swc/core-android-arm-eabi": "file:./tools/dummypkg", | ||
"@swc/core-android-arm64": "file:./tools/dummypkg", | ||
"@swc/core-freebsd-x64": "file:./tools/dummypkg", | ||
"@swc/core-linux-arm-gnueabihf": "file:./tools/dummypkg", | ||
"@swc/core-linux-arm64-gnu": "file:./tools/dummypkg", | ||
"@swc/core-linux-arm64-musl": "file:./tools/dummypkg", | ||
"@swc/core-win32-arm64-msvc": "file:./tools/dummypkg", | ||
"@swc/core-win32-ia32-msvc": "file:./tools/dummypkg", | ||
"@types/eslint": "file:./tools/dummypkg", | ||
"@types/eslint-scope": "file:./tools/dummypkg", | ||
"@types/estree": "file:./tools/dummypkg" | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.