From 8002432c6ead21fa182d0aa5386bc5ec34e55f78 Mon Sep 17 00:00:00 2001 From: Hasegawa-Yukihiro Date: Mon, 23 Dec 2024 23:20:15 +0900 Subject: [PATCH 1/2] feat: add support for projects with "type": "module" in package.json --- lib/package-json.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/package-json.ts b/lib/package-json.ts index 797a46c0..00b71bf6 100644 --- a/lib/package-json.ts +++ b/lib/package-json.ts @@ -62,6 +62,10 @@ export async function loadPlugin(path: string): Promise { } } + if (pluginPackageJson.type === 'module' && !exports) { + pluginEntryPoint = pluginPackageJson.main; + } + // If the ESM export doesn't exist, fall back to throwing the CJS error // (if the ESM export does exist, we'll validate it next) if (!pluginEntryPoint) { From 111e5eb452d27cba66978169f7f6956569654ab2 Mon Sep 17 00:00:00 2001 From: Hasegawa-Yukihiro Date: Mon, 23 Dec 2024 23:47:44 +0900 Subject: [PATCH 2/2] test: add test in package-json --- test/lib/generate/package-json-test.ts | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/lib/generate/package-json-test.ts b/test/lib/generate/package-json-test.ts index 1d86d253..1b01099e 100644 --- a/test/lib/generate/package-json-test.ts +++ b/test/lib/generate/package-json-test.ts @@ -355,6 +355,44 @@ describe('generate (package.json)', function () { }); }); + describe("plugin entry point with type: 'module' and main field specified", function () { + beforeEach(function () { + mockFs({ + 'package.json': JSON.stringify({ + name: 'eslint-plugin-test', + main: 'index.js', + type: 'module', + }), + + 'index.js': `export default { + rules: { + 'no-foo': { + meta: { docs: { description: 'disallow foo.' }, }, + create(context) {} + }, + }, + };`, + + 'README.md': + '', + + 'docs/rules/no-foo.md': '', + + // Needed for some of the test infrastructure to work. + node_modules: mockFs.load(PATH_NODE_MODULES), + }); + }); + + afterEach(function () { + mockFs.restore(); + jest.resetModules(); + }); + + it('finds the entry point', async function () { + await expect(generate('.')).resolves.toBeUndefined(); + }); + }); + describe('passing absolute path for plugin root', function () { beforeEach(function () { mockFs({