File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed
Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -35,8 +35,20 @@ async function loadPackageJson(path: string): Promise<PackageJson> {
3535export async function loadPlugin ( path : string ) : Promise < Plugin > {
3636 const pluginRoot = getPluginRoot ( path ) ;
3737 try {
38- // Try require first which should work for CJS plugins.
39- return require ( pluginRoot ) as Plugin ; // eslint-disable-line import/no-dynamic-require
38+ /**
39+ * Try require first which should work for CJS plugins.
40+ * From Node 22 requiring on ESM module returns the module object
41+ * @see https://github.com/bmish/eslint-doc-generator/issues/615
42+ */
43+ type cjsOrEsmPlugin = Plugin | { __esModule : boolean ; default : Plugin } ;
44+ // eslint-disable-next-line import/no-dynamic-require
45+ const _plugin = require ( pluginRoot ) as cjsOrEsmPlugin ;
46+
47+ /* istanbul ignore next */
48+ if ( '__esModule' in _plugin && _plugin . __esModule && _plugin . default ) {
49+ return _plugin . default ;
50+ }
51+ return _plugin as Plugin ;
4052 } catch ( error ) {
4153 // Otherwise, for ESM plugins, we'll have to try to resolve the exact plugin entry point and import it.
4254 const pluginPackageJson = await loadPackageJson ( path ) ;
Original file line number Diff line number Diff line change @@ -62,11 +62,7 @@ describe('generate (cjs)', function () {
6262
6363 describe ( 'package.json `main` field points to non-existent file' , function ( ) {
6464 it ( 'throws an error' , async function ( ) {
65- const FIXTURE_PATH = join (
66- 'test' ,
67- 'fixtures' ,
68- 'cjs-main-file-does-not-exist' ,
69- ) ;
65+ const FIXTURE_PATH = join ( FIXTURE_ROOT , 'cjs-main-file-does-not-exist' ) ;
7066 await expect ( generate ( FIXTURE_PATH ) ) . rejects . toThrow (
7167 / C a n n o t f i n d m o d u l e / u,
7268 ) ;
You can’t perform that action at this time.
0 commit comments