From 82bf823ad0c5a6ebf34bdf37c51026caec03f2ac Mon Sep 17 00:00:00 2001 From: Marco Pasqualetti <24919330+marcalexiei@users.noreply.github.com> Date: Mon, 10 Mar 2025 18:11:28 +0100 Subject: [PATCH 1/8] Fix ESM support in Node 22+ when the package includes the `main` property (#648) * fix(package-json): loadPlugin - check if `require` returns a ESM module * chore(package-json): loadPlugin - add `istanbul ignore next` to avoid coverage error --- lib/package-json.ts | 16 ++++++++++++++-- test/lib/generate/cjs-test.ts | 6 +----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/package-json.ts b/lib/package-json.ts index 00b71bf6..8a447534 100644 --- a/lib/package-json.ts +++ b/lib/package-json.ts @@ -35,8 +35,20 @@ async function loadPackageJson(path: string): Promise { export async function loadPlugin(path: string): Promise { const pluginRoot = getPluginRoot(path); try { - // Try require first which should work for CJS plugins. - return require(pluginRoot) as Plugin; // eslint-disable-line import/no-dynamic-require + /** + * Try require first which should work for CJS plugins. + * From Node 22 requiring on ESM module returns the module object + * @see https://github.com/bmish/eslint-doc-generator/issues/615 + */ + type cjsOrEsmPlugin = Plugin | { __esModule: boolean; default: Plugin }; + // eslint-disable-next-line import/no-dynamic-require + const _plugin = require(pluginRoot) as cjsOrEsmPlugin; + + /* istanbul ignore next */ + if ('__esModule' in _plugin && _plugin.__esModule && _plugin.default) { + return _plugin.default; + } + return _plugin as Plugin; } catch (error) { // Otherwise, for ESM plugins, we'll have to try to resolve the exact plugin entry point and import it. const pluginPackageJson = await loadPackageJson(path); diff --git a/test/lib/generate/cjs-test.ts b/test/lib/generate/cjs-test.ts index 3c824056..a19b806f 100644 --- a/test/lib/generate/cjs-test.ts +++ b/test/lib/generate/cjs-test.ts @@ -62,11 +62,7 @@ describe('generate (cjs)', function () { describe('package.json `main` field points to non-existent file', function () { it('throws an error', async function () { - const FIXTURE_PATH = join( - 'test', - 'fixtures', - 'cjs-main-file-does-not-exist', - ); + const FIXTURE_PATH = join(FIXTURE_ROOT, 'cjs-main-file-does-not-exist'); await expect(generate(FIXTURE_PATH)).rejects.toThrow( /Cannot find module/u, ); From f73317020aa916ca7fa29eeed2edb33fcc7858dd Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Mon, 10 Mar 2025 13:12:47 -0400 Subject: [PATCH 2/8] Release 2.1.1 --- CHANGELOG.md | 10 ++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c451d9b..06e4b27b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,16 @@ + + + +## v2.1.1 (2025-03-10) + +#### :bug: Bug Fix +* [#648](https://github.com/bmish/eslint-doc-generator/pull/648) Fix ESM support in Node 22+ when the package includes the `main` property ([@marcalexiei](https://github.com/marcalexiei)) + +#### Committers: 1 +- Marco Pasqualetti ([@marcalexiei](https://github.com/marcalexiei)) ## v2.1.0 (2025-03-04) diff --git a/package-lock.json b/package-lock.json index f73774bf..35621752 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "eslint-doc-generator", - "version": "2.1.0", + "version": "2.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "eslint-doc-generator", - "version": "2.1.0", + "version": "2.1.1", "license": "ISC", "dependencies": { "@typescript-eslint/utils": "^8.0.0", diff --git a/package.json b/package.json index 852af729..c657d47b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-doc-generator", - "version": "2.1.0", + "version": "2.1.1", "description": "Automatic documentation generator for ESLint plugins and rules.", "keywords": [ "doc", From cb1428007c87cd41c92e12349afeb1ff6a943126 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Mar 2025 19:56:23 +0000 Subject: [PATCH 3/8] chore(deps-dev): Bump eslint from 9.21.0 to 9.22.0 Bumps [eslint](https://github.com/eslint/eslint) from 9.21.0 to 9.22.0. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v9.21.0...v9.22.0) --- updated-dependencies: - dependency-name: eslint dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package-lock.json | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 35621752..e5897154 100644 --- a/package-lock.json +++ b/package-lock.json @@ -678,6 +678,15 @@ "node": "*" } }, + "node_modules/@eslint/config-helpers": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@eslint/config-helpers/-/config-helpers-0.1.0.tgz", + "integrity": "sha512-kLrdPDJE1ckPo94kmPPf9Hfd0DU0Jw6oKYrhe+pwSC0iTUInmTa+w6fw8sGgcfkFJGNdWOUeOaDM4quW4a7OkA==", + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@eslint/core": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.12.0.tgz", @@ -758,9 +767,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.21.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.21.0.tgz", - "integrity": "sha512-BqStZ3HX8Yz6LvsF5ByXYrtigrV5AXADWLAGc7PH/1SxOb7/FIYYMszZZWiUou/GB9P2lXWk2SV4d+Z8h0nknw==", + "version": "9.22.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.22.0.tgz", + "integrity": "sha512-vLFajx9o8d1/oL2ZkpMYbkLv8nDB6yaIwFNt7nI4+I80U/z03SxmfOMsLbvWr3p7C+Wnoh//aOu2pQW8cS0HCQ==", "license": "MIT", "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -4699,17 +4708,18 @@ } }, "node_modules/eslint": { - "version": "9.21.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.21.0.tgz", - "integrity": "sha512-KjeihdFqTPhOMXTt7StsDxriV4n66ueuF/jfPNC3j/lduHwr/ijDwJMsF+wyMJethgiKi5wniIE243vi07d3pg==", + "version": "9.22.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.22.0.tgz", + "integrity": "sha512-9V/QURhsRN40xuHXWjV64yvrzMjcz7ZyNoF2jJFmy9j/SLk0u1OLSZgXi28MrXjymnjEGSR80WCdab3RGMDveQ==", "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.12.1", "@eslint/config-array": "^0.19.2", + "@eslint/config-helpers": "^0.1.0", "@eslint/core": "^0.12.0", "@eslint/eslintrc": "^3.3.0", - "@eslint/js": "9.21.0", + "@eslint/js": "9.22.0", "@eslint/plugin-kit": "^0.2.7", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", @@ -4721,7 +4731,7 @@ "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.2.0", + "eslint-scope": "^8.3.0", "eslint-visitor-keys": "^4.2.0", "espree": "^10.3.0", "esquery": "^1.5.0", @@ -5082,9 +5092,9 @@ } }, "node_modules/eslint-scope": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.2.0.tgz", - "integrity": "sha512-PHlWUfG6lvPc3yvP5A4PNyBL1W8fkDUccmI21JUu/+GKZBoH/W5u6usENXUrWFRsyoW5ACUjFGgAFQp5gUlb/A==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.3.0.tgz", + "integrity": "sha512-pUNxi75F8MJ/GdeKtVLSbYg4ZI34J6C0C7sbL4YOp2exGwen7ZsuBqKzUhXd0qMQ362yET3z+uPwKeg/0C2XCQ==", "license": "BSD-2-Clause", "dependencies": { "esrecurse": "^4.3.0", From c56205fbeeb41efe01b35aac9c75a1e951dec5be Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Mar 2025 19:56:31 +0000 Subject: [PATCH 4/8] chore(deps-dev): Bump @types/node from 22.13.4 to 22.13.10 Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 22.13.4 to 22.13.10. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 35621752..94ce0f60 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2067,9 +2067,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.13.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.4.tgz", - "integrity": "sha512-ywP2X0DYtX3y08eFVx5fNIw7/uIv8hYUKgXoK8oayJlLnKcRfEYCxWMVE1XagUdVtCJlZT1AU4LXEABW+L1Peg==", + "version": "22.13.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.10.tgz", + "integrity": "sha512-I6LPUvlRH+O6VRUqYOcMudhaIdUVWfsjnZavnsraHvpBwaEyMN29ry+0UVJhImYL16xsscu0aske3yA+uPOWfw==", "dev": true, "license": "MIT", "dependencies": { From 990335e966507fcc2c0058e7ea3771b7a2934d91 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Mar 2025 19:56:58 +0000 Subject: [PATCH 5/8] chore(deps-dev): Bump prettier from 3.5.2 to 3.5.3 Bumps [prettier](https://github.com/prettier/prettier) from 3.5.2 to 3.5.3. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/3.5.2...3.5.3) --- updated-dependencies: - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 35621752..e5f27da0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11850,9 +11850,9 @@ } }, "node_modules/prettier": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.2.tgz", - "integrity": "sha512-lc6npv5PH7hVqozBR7lkBNOGXV9vMwROAPlumdBkX0wTbbzPu/U1hk5yL8p2pt4Xoc+2mkT8t/sow2YrV/M5qg==", + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz", + "integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==", "dev": true, "license": "MIT", "bin": { From cc4d7d60f007b61765d5fea732b5d0a75bc297d6 Mon Sep 17 00:00:00 2001 From: Marco Pasqualetti <24919330+marcalexiei@users.noreply.github.com> Date: Tue, 11 Mar 2025 13:34:39 +0100 Subject: [PATCH 6/8] chore: use `.prettierrc.json` instead of eslint `prettier` rule to configure format (#654) --- .prettierrc.json | 5 ++++- eslint.config.js | 7 +------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.prettierrc.json b/.prettierrc.json index 0967ef42..84cc551f 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1 +1,4 @@ -{} +{ + "$schema": "https://json.schemastore.org/prettierrc", + "singleQuote": true +} diff --git a/eslint.config.js b/eslint.config.js index aae7129b..6f4f11ed 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -25,12 +25,7 @@ export default tseslint.config( rules: { 'n/no-missing-import': 'off', // bug with recognizing node: prefix https://github.com/mysticatea/eslint-plugin-node/issues/275 - 'prettier/prettier': [ - 'error', - { - singleQuote: true, - }, - ], + 'prettier/prettier': 'error', // see `.prettierrc.json` for format config // unicorn rules: 'unicorn/expiring-todo-comments': 'off', From d194eaee5fbce1d998636a5d70d06c26a577affb Mon Sep 17 00:00:00 2001 From: Marco Pasqualetti <24919330+marcalexiei@users.noreply.github.com> Date: Sun, 16 Mar 2025 16:51:50 +0100 Subject: [PATCH 7/8] fix(package-json): refine ESM logic to return default export only when it is the only available export (#658) --- lib/package-json.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/package-json.ts b/lib/package-json.ts index 8a447534..f355eae4 100644 --- a/lib/package-json.ts +++ b/lib/package-json.ts @@ -40,12 +40,26 @@ export async function loadPlugin(path: string): Promise { * From Node 22 requiring on ESM module returns the module object * @see https://github.com/bmish/eslint-doc-generator/issues/615 */ - type cjsOrEsmPlugin = Plugin | { __esModule: boolean; default: Plugin }; + type cjsOrEsmPlugin = + | Plugin + | { + __esModule: boolean; + default: Plugin; + /* some plugins might have additional exports besides `default` */ + [key: string]: unknown; + }; // eslint-disable-next-line import/no-dynamic-require const _plugin = require(pluginRoot) as cjsOrEsmPlugin; /* istanbul ignore next */ - if ('__esModule' in _plugin && _plugin.__esModule && _plugin.default) { + if ( + '__esModule' in _plugin && + _plugin.__esModule && + // Ensure that we return only the default key when only a default export is present + // @see https://github.com/bmish/eslint-doc-generator/issues/656#issuecomment-2726745618 + Object.keys(_plugin).length === 2 && + ['__esModule', 'default'].every((it) => Boolean(_plugin[it])) + ) { return _plugin.default; } return _plugin as Plugin; From 680999f16d1c93ff133708024affe97f2fd39cc5 Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Sun, 16 Mar 2025 11:53:32 -0400 Subject: [PATCH 8/8] Release 2.1.2 --- CHANGELOG.md | 13 +++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06e4b27b..a6222958 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,19 @@ + + + +## v2.1.2 (2025-03-16) + +#### :bug: Bug Fix +* [#658](https://github.com/bmish/eslint-doc-generator/pull/658) Fix regression in ESM plugin loading ([@marcalexiei](https://github.com/marcalexiei)) + +#### :house: Internal +* [#654](https://github.com/bmish/eslint-doc-generator/pull/654) Use `.prettierrc.json` instead of `eslint` `prettier` rule to configure format options ([@marcalexiei](https://github.com/marcalexiei)) + +#### Committers: 1 +- Marco Pasqualetti ([@marcalexiei](https://github.com/marcalexiei)) ## v2.1.1 (2025-03-10) diff --git a/package-lock.json b/package-lock.json index 3a969629..a39329ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "eslint-doc-generator", - "version": "2.1.1", + "version": "2.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "eslint-doc-generator", - "version": "2.1.1", + "version": "2.1.2", "license": "ISC", "dependencies": { "@typescript-eslint/utils": "^8.0.0", diff --git a/package.json b/package.json index c657d47b..7612b2ed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-doc-generator", - "version": "2.1.1", + "version": "2.1.2", "description": "Automatic documentation generator for ESLint plugins and rules.", "keywords": [ "doc",