@nx/eslint
Version:
47 lines (46 loc) • 2.1 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = update;
const devkit_1 = require("@nx/devkit");
async function update(tree) {
const projects = (0, devkit_1.getProjects)(tree);
for (const [projectName, projectConfiguration] of projects) {
let needsUpdate = false;
for (const [targetName, targetConfig] of Object.entries(projectConfiguration.targets ?? {})) {
if (targetConfig.executor !== '@nx/eslint:lint') {
continue;
}
needsUpdate = true;
if (projectConfiguration.targets[targetName].options?.lintFilePatterns) {
const rootPattern = getLintRoot(projectConfiguration);
const nonRootPatterns = projectConfiguration.targets[targetName].options.lintFilePatterns.filter((p) => !p.startsWith(rootPattern) && !p.startsWith('{projectRoot}'));
if (nonRootPatterns.length === 0 &&
rootPattern === projectConfiguration.root) {
// delete the lintFilePatterns option if it's the only option and matches the root of the project
delete projectConfiguration.targets[targetName].options
.lintFilePatterns;
if (Object.keys(projectConfiguration.targets[targetName].options)
.length === 0) {
delete projectConfiguration.targets[targetName].options;
}
}
else {
projectConfiguration.targets[targetName].options.lintFilePatterns = [
rootPattern,
...nonRootPatterns,
];
}
}
}
if (needsUpdate) {
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
}
}
await (0, devkit_1.formatFiles)(tree);
}
function getLintRoot({ root, sourceRoot }) {
if (root === '' || root === '.') {
return sourceRoot || './src';
}
return root;
}
;