npm-package-json-lint icon indicating copy to clipboard operation
npm-package-json-lint copied to clipboard

Rule that validates `exports` field

Open mightyiam opened this issue 4 years ago • 3 comments

I have made a mistake specifying values of the exports field. I have used absolute paths. That doesn't seem to be valid. Would a rule regarding validity of the exports field be welcome?

mightyiam avatar Jun 14 '20 14:06 mightyiam

Most certainly! Are you interested in opening a PR?

tclindner avatar Jun 14 '20 17:06 tclindner

Yes, please. Any special advice for this rule?

mightyiam avatar Jun 15 '20 03:06 mightyiam

I have some advice on things to validate for this rule:

  • For each file path, validate the file exists
  • For each path that has an "import" conditional, validate the source is ESM and not commonjs.
  • For each path that has a "require" conditional, validate the source is commonjs and not esm.
  • Validate invalid conditional situations (import and require are mutually exclusive, same with development vs production)
  • For each path that has neither import or require conditions, validate that .js files match the module type specified in type, or if it is missing or not set to type="module", validate .js files are commonjs. (I think)
  • If "types" are present in a dictionary, validate they are the first key (I read about this here; https://nodejs.org/api/packages.html#community-conditions-definitions)

I recognize this issue is pretty old but @mightyiam if you still have plans to implement this, hope this helps.

dzearing avatar Jan 26 '22 16:01 dzearing