publint icon indicating copy to clipboard operation
publint copied to clipboard

Publint doesn't respect excluded subfolders in the `exports`

Open filipsobol opened this issue 1 year ago • 1 comments

In our project we have a dist folder with ESM builds for use in projects using npm. Additionally, in dist/browser we have ESM and UMD builds that can be used directly in the browser.

Since we have "type": "module" in package.json, publint throws an error if the file containing require() doesn't have the .cjs extension. However, UMD uses require() and we don't want to change the extension to .cjs, because it won't work in the browser.

Since we use the exports field, I tried using Subpath patterns, which allows you to exclude "private" subfolders using the null target like this:

{
  "exports": {
    "./*": "./dist/*",
    "./browser/*": null
  }
} 

With this configuration, I can't get into the browser folder. However, publint doesn't respect the second rule and throws the following error:

pkg.exports["./*"] matches ./dist/browser/<FILENAME>.umd.js and is written in CJS, but is interpreted as ESM. Consider using the .cjs extension, e.g. ./dist/browser/<FILENAME>.umd.cjs

filipsobol avatar Jul 17 '24 15:07 filipsobol

Thanks! Yeah it doesn't handle null well yet, so this is a bug 👍

bluwy avatar Jul 18 '24 12:07 bluwy