eslint-plugin: add no-relative-monorepo-imports rule

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-02-03 16:42:23 +01:00
parent 11df6f42b9
commit 4753d26b94
4 changed files with 92 additions and 4 deletions
+9 -1
View File
@@ -16,7 +16,7 @@
// @ts-check
/** @type {import('@manypkg/get-packages')} */
const path = require('path');
const manypkg = require('@manypkg/get-packages');
/**
@@ -31,6 +31,7 @@ const manypkg = require('@manypkg/get-packages');
* @property {ExtendedPackage} root
* @property {ExtendedPackage[]} list
* @property {Map<string, ExtendedPackage>} map
* @property {(path: string) => ExtendedPackage | undefined} byPath
*/
// Loads all packages in the monorepo once, and caches the result
@@ -56,6 +57,13 @@ module.exports = (function () {
map: new Map(packages.packages.map(pkg => [pkg.packageJson.name, pkg])),
list: packages.packages,
root: packages.root,
byPath(filePath) {
return packages.packages.find(pkg => {
if (!path.relative(pkg.dir, filePath).startsWith('..')) {
return pkg;
}
});
},
};
lastLoadAt = Date.now();
return result;