UNPKG

@nx/workspace

Version:

The Workspace plugin contains executors and generators that are useful for any Nx workspace. It should be present in every Nx workspace and other plugins build on it.

79 lines (78 loc) 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateOwnersAndConformance = updateOwnersAndConformance; const devkit_1 = require("@nx/devkit"); function updateOwnersAndConformance(tree, schema) { const nxJson = (0, devkit_1.readNxJson)(tree); let changed = false; if (renameProjectInConformanceRules(nxJson, schema.projectName, schema.newProjectName)) { changed = true; } if (renameProjectInOwnersPatterns(nxJson, schema.projectName, schema.newProjectName)) { changed = true; } if (changed) { (0, devkit_1.updateNxJson)(tree, nxJson); } } function renameProjectInConformanceRules(nxJson, oldName, newName) { const conformance = nxJson['conformance']; if (!conformance?.rules) { return false; } let changed = false; for (const rule of conformance.rules) { if (!rule.projects) { continue; } for (let i = 0; i < rule.projects.length; i++) { const entry = rule.projects[i]; if (typeof entry === 'string' && entry === oldName) { rule.projects[i] = newName; changed = true; } else if (typeof entry === 'object' && entry.matcher === oldName) { entry.matcher = newName; changed = true; } } } return changed; } function renameProjectInOwnersPatterns(nxJson, oldName, newName) { const owners = nxJson['owners']; if (typeof owners !== 'object' || !owners) { return false; } let changed = false; if (owners.patterns) { if (renameInPatternsList(owners.patterns, oldName, newName)) { changed = true; } } if (owners.sections) { for (const section of owners.sections) { if (section.patterns) { if (renameInPatternsList(section.patterns, oldName, newName)) { changed = true; } } } } return changed; } function renameInPatternsList(patterns, oldName, newName) { let changed = false; for (const pattern of patterns) { if (!pattern.projects) { continue; } for (let i = 0; i < pattern.projects.length; i++) { if (pattern.projects[i] === oldName) { pattern.projects[i] = newName; changed = true; } } } return changed; }