Commit 39a1998
authored
Export ESM module (#1518)
Allow bundlers to pick the best version, do tree-shaking, …
I checked that the below works with typescript, but I didn’t check if
npmjs.com is smart enough to add the little “TS” icon. I assume so
according to their docs, but if not, we can re-add the old `"types"`
field.
<details>
<summary>Details about <code>exports</code></summary>
According to
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#packagejson-exports-imports-and-self-referencing:
> if you write an import from an ES module, it will look up the import
field, and from a CommonJS module, it will look at the require field. If
it finds them, it will look for a corresponding declaration file. If you
need to point to a different location for your type declarations, you
can add a "types" import condition.
> […]
> It’s important to note that the CommonJS entrypoint and the ES module
entrypoint each needs its own declaration file, even if the contents are
the same between them.
and according to npmjs.com’s [RFC
46](https://github.com/npm/rfcs/blob/6f61e5a2394040fa5843024d799db4ac675378d5/implemented/0046-add-types-metadata-to-package-json.md):
> If there is not the explicit fields: Resolving the main with both
TypeScript and Flow's extra file resolvers (e.g. when
distribution/danger.js look for the files ./distribution/danger.js.flow
and ./distribution/danger.d.ts)
So in summary, TypeScript 4.7+ should find the `.d.ts` files, and
npmjs.com should therefore resolve it to, but others had problems with
that:
browserslist/browserslist-useragent-regexp#1545
</details>1 parent a1513ca commit 39a1998
5 files changed
Lines changed: 309 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
16 | 24 | | |
17 | 25 | | |
18 | 26 | | |
| |||
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
33 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
34 | 44 | | |
35 | 45 | | |
36 | 46 | | |
37 | 47 | | |
38 | 48 | | |
| 49 | + | |
39 | 50 | | |
40 | 51 | | |
41 | 52 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
8 | | - | |
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
0 commit comments