Change Request: Export types from main entry point
- Dominant language
- JavaScript
- Stars
- 348
- Forks
- 51
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 11
Description
### Environment
ESLint version: HEAD
@eslint/json version: HEAD
Node version: 20.19.3
npm version: 10.9.2
Operating System: Windows 11
### What problem do you want to solve?
Hi,
I'm raising this issue based on https://github.com/eslint/markdown/pull/453, https://github.com/eslint/markdown/pull/367#issuecomment-3008282520, and https://github.com/eslint/markdown/pull/367#issuecomment-3028229001.
cc. @JoshuaKGoldberg
---
Currently, the JSON, CSS, and Markdown plugins export their types defined in `types.ts` from the `/types` entry point.
For example:
- JSON: `@eslint/json/types`
- [package.json reference](https://github.com/eslint/json/blob/main/package.json#L20-L27)
- [`types.ts` reference](https://github.com/eslint/json/blob/main/src/types.ts)
https://github.com/eslint/json/blob/bc2b31768b0e7dcde61d456ab34bafa3afce65a8/package.json#L20-L27
- CSS: `@eslint/css/types`
- [package.json reference](https://github.com/eslint/css/blob/main/package.json#L20-L27)
- [`types.ts` reference](https://github.com/eslint/css/blob/main/src/types.ts)
- Markdown: `@eslint/markdown/types`
- [package.json reference](https://github.com/eslint/markdown/blob/main/package.json#L18-L20)
- [`types.ts` reference](https://github.com/eslint/markdown/blob/main/src/types.ts)
---
As mentioned in https://github.com/eslint/markdown/pull/453, https://github.com/eslint/markdown/pull/367#issuecomment-3008282520, and also from my own experience, exporting types from a `/types` entry point is a fairly uncommon pattern in TypeScript.
With this proposal, I'd like to suggest exporting types from the main entry point instead (i.e., `@eslint/json`, `@eslint/css`, and `@eslint/markdown`), rather than from `@eslint/json/types`, `@eslint/css/types`, and `@eslint/markdown/types`.
### What do you think is the correct solution?
There are two possible approaches, depending on whether the build script uses bundling:
- If bundling is used:
Adding `export * from "types.ts"` to the `banner` section in `rollup.config.js` worked well and was the simplest way to achieve this proposal in my tests.
https://github.com/eslint/json/blob/bc2b31768b0e7dcde61d456ab34bafa3afce65a8/rollup.config.js#L14
- If bundling is not used:
The following approach was the cleanest solution I found.
> I've taken another shot at this and wanted to share a different approach.
>
> Here's what I did:
>
> - First, I created an empty `types.js` file at `src/types.js`:
>
> ```js
> export default {};
> ```
>
> - Then, I added `export * from "./types.js";` to the end of `index.js`:
>
> ```diff
> // ...
>
> export default plugin;
> export { MarkdownSourceCode };
> + export * from "./types.js";
> ```
>
> ---
>
> This approach seems to work well, since it allows all types from `src/types.ts` to be imported directly from the `@eslint/markdown` package, rather than from `@eslint/markdown/types`.
>
> 
>
> 
### Participation
- [x] I am willing to submit a pull request for this change.
### Additional comments
This proposal applies to all packages that export their types from `types.ts` using the `@eslint/package-name/types` entry point.
So far, I've only reviewed the JSON, CSS, and Markdown plugins, but I plan to look into the other packages as I continue.
Contributor guide
Assessment
This issue has not been assessed yet.