Skip to content

Commit

Permalink
Add exports field to package.json (#7307)
Browse files Browse the repository at this point in the history
This commit is necessary for Conditional Exports (ESM and CJS).
See https://nodejs.org/api/packages.html#conditional-exports
  • Loading branch information
ybiquitous committed Nov 9, 2023
1 parent cb0e7d2 commit 310c9ad
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-insects-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": major
---

Changed: `.js` extension to `.mjs` and `.cjs`
5 changes: 5 additions & 0 deletions .changeset/weak-crews-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stylelint": major
---

Added: `exports` field to `package.json` for Conditional Exports (ESM/CJS)
26 changes: 26 additions & 0 deletions docs/migration-guide/to-16.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This release contains breaking changes. We've:

- removed deprecated stylistic rules
- removed support for Node.js less than 18.12.0
- changed `.js` extension to `.mjs` and `.cjs`
- changed Node.js API returned resolved object
- changed CLI to print problems to stderr
- changed CLI exit code for flag errors
Expand All @@ -20,6 +21,31 @@ Node.js 14 and 16 have reached end-of-life. We've removed support for them so th

You should use the 18.12.0 or higher versions of Node.js.

## Changed `.js` extensions to `.mjs` and `.cjs`

We've changed the file extension `.js` to `.mjs` and `.cjs` to support ESM and CJS.

You should modify your code if using `.js` for `import` or `require`. For example:

ESM:

```diff js
-import('stylelint/lib/utils/typeGuards.js');
+import('stylelint/lib/utils/typeGuards.mjs');
```

CJS:

```diff js
-require('stylelint/lib/utils/typeGuards.js');
+require('stylelint/lib/utils/typeGuards.cjs');
```

> [!WARNING]
> We've strongly recommended copying the internal utilities to your project instead of importing them.
> You can unsafely continue to `import` or `require` the files, but we will disallow access to them in the next major release.
> See also [`stylelint.utils`](../developer-guide/plugins.md#stylelintutils) in the developer guide.
## Changed Node.js API returned resolved object

We've changed the resolved object of the Promise returned by `stylelint.lint()` so that:
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
},
"license": "MIT",
"author": "stylelint",
"exports": {
".": {
"import": "./lib/index.mjs",
"require": "./lib/index.cjs"
},
"./package.json": "./package.json",
"./lib/utils/*": "./lib/utils/*"
},
"main": "lib/index.cjs",
"types": "types/stylelint/index.d.ts",
"bin": {
Expand Down

0 comments on commit 310c9ad

Please sign in to comment.