bmish / eslint-doc-generator

Automatic documentation generator for ESLint plugins and rules.
94 stars 7 forks source link

Support ESM #504

Open nirtamir2 opened 1 year ago

nirtamir2 commented 1 year ago

Hi! Thank you for creating this tool! I would like to create ESM only ESLint plugin, and this rule tries to require stuff inside so it's not compatible I would like it to work with ESM.

❯ pnpm run update:eslint-docs

> eslint-doc-generator

require() of ES Module ***/lib/index.mjs not supported.
Instead change the require of ***/lib/index.mjs to a dynamic import() which is available in all CommonJS modules.

Thanks!

bmish commented 1 year ago

Do you have a public example to link to? Is your plugin compiled to CJS? Or are you using flat config? (#376).

nirtamir2 commented 1 year ago

Thank you for your fast response!

Do you have a public example to link to? Is your plugin compiled to CJS? Or are you using flat config? (#376).

https://github.com/nirtamir2/eslint-plugin-default-import-name

https://github.com/nirtamir2/eslint-plugin-default-import-name/commit/7c545cfddbb289f3bffdcedd665eb6c31bbe723d - this is the commit I converted to ESM only. I did not want to lose the eslint-doc-generator so I reverted it later

bmish commented 1 year ago

With ESM, you still have a build command and compiled CJS output, right? If this is the case, then the solution is normally to just ensure the build runs before running eslint-doc-generator: https://github.com/bmish/eslint-doc-generator#build-tools

{
  "build": "tsc",
  "update:eslint-docs": "npm run build && eslint-doc-generator"
}
ljharb commented 1 year ago

Not if they’re using native ESM.

nzakas commented 5 months ago

@bmish I ran into this with a new native ESM project. Because "main" in package.json points to an ESM file, I end up with this error.

You can probably somewhat account for this by checking "exports" field for a CommonJS entrypoint, though at this point, I don't know that you can rely on packages to continue publishing CommonJS entrypoints.

ljharb commented 5 months ago

Those that stop doing so almost universally leave the majority of their users stuck on the last version to do so, so i think that's still something that can be relied on.