You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So now the presence of a package.json file does not necessarily indicate the root of a package. It could just contain {"type": "module"} to indicate that a subdirectory's files are to be treated as ESM modules.
Could pkg-dir check the contents of package.json files found, and ignore any which don't indicate package root? Perhaps checking for a name field would do the trick.
The text was updated successfully, but these errors were encountered:
Only packages on npm are required to have a name field, so I don’t think that’s a good heuristic. How about if the package.json only contains the type field?
Sorry for very slow reply. Life has been... strange.
In theory at least, package.json can be used for other purposes which don't indicate package root either.
e.g. a directory foo containing package.json reading {"main": "./bar.js"} makes require('./foo') resolve to ./foo/bar.js.
So I'm not sure what fields there are that can be reliably used to assess "rootyness".
Perhaps looking for either name, dependencies, devDependencies or peerDependencies?
If you don't think that's right either, then skipping over a package.json which contains only a type field (as you suggested) would at least deal with the most common case.
IINM, property "name" is required in a top-level package.json – unless "private" is true. Thus, it could be detected by checking if either of these properties is present.
With ESM modules, Node has introduced a 2nd use for
package.json
.So now the presence of a
package.json
file does not necessarily indicate the root of a package. It could just contain{"type": "module"}
to indicate that a subdirectory's files are to be treated as ESM modules.Could
pkg-dir
check the contents ofpackage.json
files found, and ignore any which don't indicate package root? Perhaps checking for aname
field would do the trick.The text was updated successfully, but these errors were encountered: