eslint-plugin: backwards compatiblity check for packages without exports

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-02-03 16:14:07 +01:00
parent 8b4a758ed2
commit 765b7ee355
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ const manypkg = require('@manypkg/get-packages');
/**
* @typedef ExtendedPackage
* @type {import('@manypkg/get-packages').Package & { packageJson: { exports?: Record<string, string> }}} packageJson
* @type {import('@manypkg/get-packages').Package & { packageJson: { exports?: Record<string, string>, files?: Array<string> }}} packageJson
*/
/**
@@ -41,6 +41,20 @@ module.exports = {
if (exp && (exp[imp.path] || exp['./' + imp.path])) {
return;
}
if (!exp) {
// If there's no exports field, we allow anything listed in files, except dist
const files = imp.package.packageJson.files;
if (
!files ||
files.some(f => !f.startsWith('dist') && imp.path.startsWith(f))
) {
return;
}
// And also package.json
if (imp.path === 'package.json') {
return;
}
}
context.report({
node: node,