Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export async function loadPlugin(path: string): Promise<Plugin> {
}
}

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) {
Expand Down
38 changes: 38 additions & 0 deletions test/lib/generate/package-json-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
'<!-- begin auto-generated rules list --><!-- end auto-generated rules list -->',

'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({
Expand Down
Loading