eslint-plugin: backwards compatiblity check for packages without exports
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user