npm-package-json-lint
npm-package-json-lint copied to clipboard
Rule that validates `exports` field
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?
Most certainly! Are you interested in opening a PR?
Yes, please. Any special advice for this rule?
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
andrequire
are mutually exclusive, same withdevelopment
vsproduction
) - For each path that has neither
import
orrequire
conditions, validate that .js files match the module type specified intype
, or if it is missing or not set totype="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.